[m-dev.] for review: fix switch-detection bug

Simon Taylor stayl at cs.mu.OZ.AU
Mon Aug 30 12:22:03 AEST 1999



Estimated hours taken: 0.5

compiler/switch_detection.m:
	Fix a bug - the code was looking for switch deconstructions
	after the first call in each branch. Doing this can remove
	infinite loops, which the strict sequential semantics does
	not allow.

tests/invalid/Mmakefile:
tests/invalid/not_a_switch.m:
	Test case.

Index: compiler/switch_detection.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/switch_detection.m,v
retrieving revision 1.86
diff -u -u -r1.86 switch_detection.m
--- switch_detection.m	1999/07/13 08:53:33	1.86
+++ switch_detection.m	1999/08/26 23:11:12
@@ -508,7 +508,7 @@
 		Substitution = Substitution0,
 		Result = Result0,
 		Info = Info0,
-		Continue = yes
+		Continue = no
 	).
 
 :- pred conj_find_bind_var(prog_var, process_unify(Result, Info), 
Index: tests/invalid/Mmakefile
===================================================================
RCS file: /home/staff/zs/imp/tests/invalid/Mmakefile,v
retrieving revision 1.45
diff -u -u -r1.45 Mmakefile
--- Mmakefile	1999/07/14 17:03:30	1.45
+++ Mmakefile	1999/08/30 01:56:46
@@ -35,6 +35,7 @@
 	multisoln_func.m \
 	nested_impl_in_int.m \
 	no_exports.m \
+	not_a_switch.m \
 	nullary_ho_func_error.m \
 	occurs.m \
 	partial_implied_mode.m \
@@ -79,10 +80,11 @@
Index: tests/invalid/not_a_switch.err_exp
===================================================================
RCS file: not_a_switch.err_exp
diff -N not_a_switch.err_exp
--- /dev/null	Mon Aug 30 12:05:00 1999
+++ not_a_switch.err_exp	Sun Aug 29 14:16:32 1999
@@ -0,0 +1,8 @@
+not_a_switch.m:009: In `not_a_switch(in, out)':
+not_a_switch.m:009:   error: determinism declaration not satisfied.
+not_a_switch.m:009:   Declared `det', inferred `nondet'.
+not_a_switch.m:015:   Unification of `A' and `std_util:yes(Int2)' can fail.
+not_a_switch.m:016:   In argument 1 of clause head:
+not_a_switch.m:016:   unification of `HeadVar__1' and `std_util:no' can fail.
+not_a_switch.m:014:   Disjunction has multiple clauses with solutions.
+For more information, try recompiling with `-E'.
Index: tests/invalid/not_a_switch.m
===================================================================
RCS file: not_a_switch.m
diff -N not_a_switch.m
--- /dev/null	Mon Aug 30 12:05:00 1999
+++ not_a_switch.m	Sun Aug 29 14:08:43 1999
@@ -0,0 +1,16 @@
+% Test that switch_detection's search for deconstruction unifications
+% doesn't go past any calls.
+:- module not_a_switch.
+
+:- interface.
+
+:- import_module int, std_util.
+
+:- pred not_a_switch(maybe(int)::in, int::out) is det.
+
+:- implementation.
+
+not_a_switch(A, Int1 + Int2) :-
+	Int1 = 1 + 1,
+	A = yes(Int2).
+not_a_switch(no, 0).
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list