[m-rev.] diff: fix inst merge bug with `any' insts

Fergus Henderson fjh at cs.mu.OZ.AU
Fri Mar 30 16:03:48 AEST 2001


Estimated hours taken: 1.5

Fix a bug reported by dgj.

compiler/inst_util.m:
	Fix a bug in inst_merge: it wasn't handling the case where a
	bound inst containing any insts was merged with a ground inst.
	That case should be allowed.

tests/valid/Mmakefile:
tests/valid/any_inst_merge.m:
	A regression test.

Workspace: /home/hg/fjh/mercury
Index: compiler/inst_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/inst_util.m,v
retrieving revision 1.15
diff -u -d -r1.15 inst_util.m
--- compiler/inst_util.m	2000/10/13 13:55:29	1.15
+++ compiler/inst_util.m	2001/03/27 13:16:53
@@ -1382,13 +1382,23 @@
 	merge_uniq(UniqA, UniqB, Uniq),
 	bound_inst_list_merge(ListA, ListB, ModuleInfo0, List, ModuleInfo).
 inst_merge_3(bound(UniqA, ListA), ground(UniqB, _), ModuleInfo,
-		ground(Uniq, none), ModuleInfo) :-
+		Result, ModuleInfo) :-
 	merge_uniq_bound(UniqB, UniqA, ListA, ModuleInfo, Uniq),
-	bound_inst_list_is_ground(ListA, ModuleInfo).
+	( bound_inst_list_is_ground(ListA, ModuleInfo) ->
+		Result = ground(Uniq, none)
+	;
+		bound_inst_list_is_ground_or_any(ListA, ModuleInfo),
+		Result = any(Uniq)
+	).
 inst_merge_3(ground(UniqA, _), bound(UniqB, ListB), ModuleInfo,
-		ground(Uniq, none), ModuleInfo) :-
+		Result, ModuleInfo) :-
 	merge_uniq_bound(UniqA, UniqB, ListB, ModuleInfo, Uniq),
-	bound_inst_list_is_ground(ListB, ModuleInfo).
+	( bound_inst_list_is_ground(ListB, ModuleInfo) ->
+		Result = ground(Uniq, none)
+	;
+		bound_inst_list_is_ground_or_any(ListB, ModuleInfo),
+		Result = any(Uniq)
+	).
 inst_merge_3(ground(UniqA, GroundInstInfoA), ground(UniqB, GroundInstInfoB),
 		ModuleInfo, ground(Uniq, GroundInstInfo), ModuleInfo) :-
 	(
Index: tests/valid/any_inst_merge.m
===================================================================
RCS file: any_inst_merge.m
diff -N any_inst_merge.m
--- /dev/null	Thu Mar 30 14:06:13 2000
+++ any_inst_merge.m	Fri Mar 30 15:13:10 2001
@@ -0,0 +1,18 @@
+% A regression test -- Mercury 0.9.1 and earlier failed this test case,
+% due to a bug in inst_merge.
+
+:- module any_inst_merge.
+
+:- interface.
+
+:- type hpair(A,B)  ---> (A-B).
+
+:- inst hpair(A,B)  = bound(A-B).
+
+:- pred pass(hpair(A,B),hpair(A,B),hpair(A,B)).
+:- mode pass(in,in(hpair(ground,any)),out(any)) is multi.
+
+:- implementation.
+
+pass(X,_,X).
+pass(_,X,X).
Index: tests/valid/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/valid/Mmakefile,v
retrieving revision 1.83
diff -u -d -r1.83 Mmakefile
--- tests/valid/Mmakefile	2001/02/09 03:27:35	1.83
+++ tests/valid/Mmakefile	2001/03/30 06:00:56
@@ -40,6 +40,7 @@
 	aditi_query.m
 
 OTHER_SOURCES= \
+	any_inst_merge.m \
 	common_struct_bug.m \
 	compl_unify_bug.m \
 	complicated_unify.m \

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
                                    |  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