[m-rev.] For review: fix a bug with any/ground inst matching
Ralph Becket
rafe at cs.mu.OZ.AU
Tue Sep 6 17:50:46 AEST 2005
Estimated hours taken: 3
Branches: main
Fix a bug where an inst any list containing a solver type was being
passed without complaint to list.member, which clearly expected it
to have inst ground.
compiler/inst_match.m:
Fix a bug where under certain situations inst_is_ground_1/5 would
erroneously add any(_) to the set of insts it would treat as
ground.
tests/invalid/Mmakefile:
tests/invalid/any_passed_as_ground.err_exp:
tests/invalid/any_passed_as_ground.m:
tests/invalid/any_to_ground_in_ite_cond.err_exp:
tests/invalid/any_to_ground_in_ite_cond.m:
Add test cases covering some any/ground situations.
Index: compiler/inst_match.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/inst_match.m,v
retrieving revision 1.64
diff -u -r1.64 inst_match.m
--- compiler/inst_match.m 27 Aug 2005 09:41:55 -0000 1.64
+++ compiler/inst_match.m 6 Sep 2005 06:47:52 -0000
@@ -1358,7 +1358,11 @@
( set__member(Inst, !.Expansions) ->
true
;
- svset__insert(Inst, !Expansions),
+ ( Inst \= any(_) ->
+ svset__insert(Inst, !Expansions)
+ ;
+ true
+ ),
inst_is_ground_2(ModuleInfo, MaybeType, Inst,
!Expansions)
).
Index: tests/invalid/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/invalid/Mmakefile,v
retrieving revision 1.174
diff -u -r1.174 Mmakefile
--- tests/invalid/Mmakefile 5 Sep 2005 03:45:59 -0000 1.174
+++ tests/invalid/Mmakefile 6 Sep 2005 07:28:03 -0000
@@ -35,7 +35,9 @@
ambiguous_method \
ambiguous_method_2 \
any_mode \
+ any_passed_as_ground \
any_should_not_match_bound \
+ any_to_ground_in_ite_cond \
assert_in_interface \
bad_initialise_decl \
bad_instance \
Index: tests/invalid/any_passed_as_ground.err_exp
===================================================================
RCS file: tests/invalid/any_passed_as_ground.err_exp
diff -N tests/invalid/any_passed_as_ground.err_exp
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ tests/invalid/any_passed_as_ground.err_exp 6 Sep 2005 07:02:22 -0000
@@ -0,0 +1,13 @@
+any_passed_as_ground.m:036: In clause for `main(di, uo)':
+any_passed_as_ground.m:036: in call to predicate `list.member/2':
+any_passed_as_ground.m:036: mode error: arguments `TypeInfo_16, V_11, Xs'
+any_passed_as_ground.m:036: have the following insts:
+any_passed_as_ground.m:036: unique(private_builtin.type_info(unique(<type_ctor_info
+any_passed_as_ground.m:036: for std_util.pair/2>), unique(<type_ctor_info
+any_passed_as_ground.m:036: for .int/0>), unique(<type_ctor_info for
+any_passed_as_ground.m:036: any_passed_as_ground.st/0>))),
+any_passed_as_ground.m:036: free,
+any_passed_as_ground.m:036: any
+any_passed_as_ground.m:036: which does not match any of the modes for
+any_passed_as_ground.m:036: predicate `list.member/2'.
+For more information, try recompiling with `-E'.
Index: tests/invalid/any_passed_as_ground.m
===================================================================
RCS file: tests/invalid/any_passed_as_ground.m
diff -N tests/invalid/any_passed_as_ground.m
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ tests/invalid/any_passed_as_ground.m 6 Sep 2005 07:01:00 -0000
@@ -0,0 +1,48 @@
+%-----------------------------------------------------------------------------%
+% any_passed_as_ground.m
+% Ralph Becket <rafe at cs.mu.oz.au>
+% Mon Sep 5 15:28:33 EST 2005
+% vim: ft=mercury ts=4 sw=4 et wm=0 tw=0
+%
+%-----------------------------------------------------------------------------%
+
+:- module any_passed_as_ground.
+
+:- interface.
+
+:- import_module io.
+
+
+
+:- pred main(io :: di, io :: uo) is cc_multi.
+
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+
+:- implementation.
+
+:- import_module int, list, std_util.
+
+:- solver type st where representation is int, initialisation is i.
+
+%-----------------------------------------------------------------------------%
+
+% We shouldn't be able to pass Xs to member/2 because
+% member/2 expects Xs to be ground. The compiler should
+% report an error.
+%
+main(!IO) :-
+ p(Xs),
+ ( if member((X - _), Xs) then Y = X else Y = 0 ),
+ io.write_int(Y, !IO).
+
+:- pred i(st::oa) is det.
+
+i(X) :- promise_pure(impure X = 'representation to any st/0'(42)).
+
+:- pred p(list(pair(int, st))::oa) is det.
+
+p([1 - _, 2 - _, 3 - _]).
+
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
Index: tests/invalid/any_to_ground_in_ite_cond.err_exp
===================================================================
RCS file: tests/invalid/any_to_ground_in_ite_cond.err_exp
diff -N tests/invalid/any_to_ground_in_ite_cond.err_exp
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ tests/invalid/any_to_ground_in_ite_cond.err_exp 6 Sep 2005 07:27:35 -0000
@@ -0,0 +1,12 @@
+Making Mercury/int3s/any_to_ground_in_ite_cond.int3
+Making Mercury/cs/any_to_ground_in_ite_cond.c
+any_to_ground_in_ite_cond.m:035: In clause for `main(di, uo)':
+any_to_ground_in_ite_cond.m:035: in argument 1 of call to predicate
+any_to_ground_in_ite_cond.m:035: `any_to_ground_in_ite_cond.p/1':
+any_to_ground_in_ite_cond.m:035: scope error: attempt to bind a non-local
+any_to_ground_in_ite_cond.m:035: variable inside the condition of an
+any_to_ground_in_ite_cond.m:035: if-then-else.
+any_to_ground_in_ite_cond.m:035: Variable `X' has instantiatedness `any',
+any_to_ground_in_ite_cond.m:035: expected instantiatedness was `ground'.
+For more information, try recompiling with `-E'.
+** Error making `Mercury/cs/any_to_ground_in_ite_cond.c'.
Index: tests/invalid/any_to_ground_in_ite_cond.m
===================================================================
RCS file: tests/invalid/any_to_ground_in_ite_cond.m
diff -N tests/invalid/any_to_ground_in_ite_cond.m
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ tests/invalid/any_to_ground_in_ite_cond.m 6 Sep 2005 07:27:17 -0000
@@ -0,0 +1,51 @@
+%-----------------------------------------------------------------------------%
+% any_to_ground_in_ite_cond.m
+% Ralph Becket <rafe at cs.mu.oz.au>
+% Mon Sep 5 15:28:33 EST 2005
+% vim: ft=mercury ts=4 sw=4 et wm=0 tw=0
+%
+%-----------------------------------------------------------------------------%
+
+:- module any_to_ground_in_ite_cond.
+
+:- interface.
+
+:- import_module io.
+
+
+
+:- pred main(io :: di, io :: uo) is det.
+
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+
+:- implementation.
+
+:- import_module int, list, std_util.
+
+:- solver type st where representation is int, initialisation is i.
+
+%-----------------------------------------------------------------------------%
+
+% We shouldn't be able to ground a solver variable in the
+% condition of an if-then-else.
+%
+main(!IO) :-
+ i(X),
+ ( if p(X) then
+ io.write_string("aye\n", !IO)
+ else
+ io.write_string("nay\n", !IO)
+ ).
+
+:- pred i(st::oa) is det.
+
+i(X) :- promise_pure(impure X = 'representation to any st/0'(42)).
+
+:- pred p(st::(any >> ground)) is semidet.
+
+:- pragma foreign_proc("C", p(_X::(any >> ground)), [promise_pure],
+ "SUCCESS_INDICATOR = MR_TRUE;").
+
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
--------------------------------------------------------------------------
mercury-reviews mailing list
post: mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the reviews
mailing list