[m-rev.] diff: fix solver type pruning bug

Fergus Henderson fjh at cs.mu.OZ.AU
Fri Dec 5 12:43:16 AEDT 2003


Estimated hours taken: 1
Branches: main

Fix a bug where we were incorrectly pruning nondet goals with a non-local
variable of inst "any" whose type contained a solver type in one of
its fields.

compiler/inst_match.m:
	Fix a bug: when memoizing the results of previous calls to
	inst_matches_*, include the maybe(type) argument in the key
	of the memo table, since that argument can effect the result.

tests/valid/Mmakefile:
tests/valid/Mercury.options:
tests/valid/solver_type_bug.m:
	Add a regression test for the above-mentioned bug.

Workspace: /home/jupiter/fjh/ws-jupiter/mercury
Index: compiler/inst_match.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/inst_match.m,v
retrieving revision 1.56
diff -u -d -r1.56 inst_match.m
--- compiler/inst_match.m	20 Oct 2003 07:29:06 -0000	1.56
+++ compiler/inst_match.m	5 Dec 2003 01:24:11 -0000
@@ -367,7 +367,8 @@
 	ModuleInfo = Info^module_info,
 	MaybeSub = Info ^ maybe_sub.
 
-:- type expansions == set(pair(inst)).
+:- type inst_match_inputs ---> inst_match_inputs(inst, inst, maybe(type)).
+:- type expansions == set(inst_match_inputs).
 
 	% The uniqueness_comparison type is used by the predicate
 	% compare_uniqueness to determine what order should be used for
@@ -446,8 +447,8 @@
 :- pred inst_matches_initial_2 `with_type` inst_matches_pred.
 :- mode inst_matches_initial_2 `with_inst` inst_matches_pred.
 
-inst_matches_initial_2(InstA, InstB, Type, Info0, Info) :-
-	ThisExpansion = InstA - InstB,
+inst_matches_initial_2(InstA, InstB, MaybeType, Info0, Info) :-
+	ThisExpansion = inst_match_inputs(InstA, InstB, MaybeType),
 	( set__member(ThisExpansion, Info0^expansions) ->
 		Info = Info0
 
@@ -456,7 +457,7 @@
 		inst_expand(Info0^module_info, InstB, InstB2),
 		set__insert(Info0^expansions, ThisExpansion, Expansions1),
 		handle_inst_var_subs(inst_matches_initial_2,
-			inst_matches_initial_4, InstA2, InstB2, Type, 
+			inst_matches_initial_4, InstA2, InstB2, MaybeType, 
 			Info0^expansions := Expansions1, Info)
 	).
 
@@ -946,7 +947,7 @@
 :- mode inst_matches_final_2 `with_inst` inst_matches_pred.
 
 inst_matches_final_2(InstA, InstB, MaybeType, Info0, Info) :-
-	ThisExpansion = InstA - InstB,
+	ThisExpansion = inst_match_inputs(InstA, InstB, MaybeType),
 	( set__member(ThisExpansion, Info0^expansions) ->
 		Info = Info0
 	; InstA = InstB ->
@@ -1119,7 +1120,7 @@
 :- mode inst_matches_binding_2 `with_inst` inst_matches_pred.
 
 inst_matches_binding_2(InstA, InstB, MaybeType, Info0, Info) :-
-	ThisExpansion = InstA - InstB,
+	ThisExpansion = inst_match_inputs(InstA, InstB, MaybeType),
 	( set__member(ThisExpansion, Info0^expansions) ->
 		Info = Info0
 	;
Index: tests/valid/Mercury.options
===================================================================
RCS file: /home/mercury1/repository/tests/valid/Mercury.options,v
retrieving revision 1.10
diff -u -d -r1.10 Mercury.options
--- tests/valid/Mercury.options	13 Oct 2003 02:29:41 -0000	1.10
+++ tests/valid/Mercury.options	5 Dec 2003 01:32:49 -0000
@@ -85,6 +85,7 @@
 MCFLAGS-simplify_bug2		= -O3
 MCFLAGS-spurious_purity_warning	= --halt-at-warn
 MCFLAGS-solv			= --halt-at-warn
+MCFLAGS-solver_type_bug		= --halt-at-warn
 MCFLAGS-tuple_eqv               = --smart-recompilation
 MCFLAGS-two_way_unif		= -O-1
 MCFLAGS-type_inf_ambig_test	= --infer-all
Index: tests/valid/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/valid/Mmakefile,v
retrieving revision 1.135
diff -u -d -r1.135 Mmakefile
--- tests/valid/Mmakefile	6 Nov 2003 11:11:47 -0000	1.135
+++ tests/valid/Mmakefile	5 Dec 2003 01:33:27 -0000
@@ -164,6 +164,7 @@
 	simplify_bug2 \
 	soln_context \
 	solv \
+	solver_type_bug \
 	some_switch \
 	spurious_purity_warning \
 	stack_alloc \
Index: tests/valid/solver_type_bug.m
===================================================================
RCS file: tests/valid/solver_type_bug.m
diff -N tests/valid/solver_type_bug.m
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/valid/solver_type_bug.m	5 Dec 2003 01:35:26 -0000
@@ -0,0 +1,34 @@
+% This is a regression test.
+% Previous versions of the Mercury compiler would
+% incorrectly infer the determinism of p2 as semidet,
+% resulting in a warning (and invalid code generation).
+
+:- module solver_type_bug.
+:- interface.
+
+:- solver type foo1.
+:- pragma foreign_type("C", foo1, "int").
+:- pragma foreign_type("IL", foo1, "int32").
+:- pragma foreign_type("Java", foo1, "int").
+
+:- type foo2 ---> foo2(foo1).
+
+:- pred p1(foo1).
+:- mode p1(in(any)) is nondet.
+
+:- pred p2(foo2).
+:- mode p2(in(any)) is nondet.
+
+:- implementation.
+
+p1(X) :- q1(X).
+
+p2(X) :- q2(X).
+
+:- pred q1(foo1).
+:- mode q1(in(any)) is nondet.
+:- external(q1/1).
+
+:- pred q2(foo2).
+:- mode q2(in(any)) is nondet.
+:- external(q2/1).

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
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