simplify.m bug fix

Fergus Henderson fjh at cs.mu.oz.au
Sat Aug 9 11:29:45 AEST 1997


compiler/simplify.m:
	Fix a bug where the code generator complained about `nondet
	model in semidet context':  If a model_det or model_semi
	if-then-else has a model_nondet condition, then change the
	determinism of the if-then-else as a whole to nondet and put it
	inside a `some'.  (This can only happen if the `then' part
	has determinism `erroneous' or `failure'.)  The treatment
	of this problem for if-then-elses is similar to the way we
	treat the analgous problem for conjunctions.

tests/valid/Mmake:
tests/valid/tricky_ite.m:
	Regression test for the above bug fix.


Index: simplify.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/simplify.m,v
retrieving revision 1.39
diff -u -r1.39 simplify.m
--- simplify.m	1997/07/14 06:03:20	1.39
+++ simplify.m	1997/08/09 01:17:35
@@ -554,9 +554,9 @@
 		GoalInfo0, Goal, GoalInfo, Info0, Info) :-
 	Cond0 = _ - CondInfo0,
 
-	goal_info_get_determinism(CondInfo0, CondDetism),
-	determinism_components(CondDetism, CondCanFail, CondSolns),
-	( CondCanFail = cannot_fail ->
+	goal_info_get_determinism(CondInfo0, CondDetism0),
+	determinism_components(CondDetism0, CondCanFail0, CondSolns0),
+	( CondCanFail0 = cannot_fail ->
 		goal_to_conj_list(Cond0, CondList),
 		goal_to_conj_list(Then0, ThenList),
 		list__append(CondList, ThenList, List),
@@ -565,9 +565,9 @@
 		goal_info_get_context(GoalInfo, Context),
 		simplify_info_add_msg(Info1, ite_cond_cannot_fail(Context),
 			Info)
-	; CondSolns = at_most_zero ->
+	; CondSolns0 = at_most_zero ->
 		% Optimize away the condition and the `then' part.
-		det_negation_det(CondDetism, MaybeNegDetism),
+		det_negation_det(CondDetism0, MaybeNegDetism),
 		( Cond0 = not(NegCond) - _ ->
 			Cond = NegCond
 		;
@@ -625,7 +625,30 @@
 		goal_info_get_instmap_delta(ElseInfo, ElseDelta),
 		simplify_info_create_branch_info(Info0, Info6,
 			[ElseDelta, CondThenDelta], Info),
-		Goal = if_then_else(Vars, Cond, Then, Else, SM),
+		IfThenElse = if_then_else(Vars, Cond, Then, Else, SM),
+		%
+		% If-then-elses that are det or semidet may nevertheless
+		% contain nondet or multidet conditions. If this happens, the
+		% if-then-else must be put inside a `some' to appease the code
+		% generator.
+		%
+		goal_info_get_determinism(GoalInfo0, IfThenElseDetism0),
+		determinism_components(IfThenElseDetism0, IfThenElseCanFail,
+			IfThenElseNumSolns),
+		(
+			simplify_do_once(Info),
+			goal_info_get_determinism(CondInfo, CondDetism),
+			determinism_components(CondDetism, _, at_most_many),
+			IfThenElseNumSolns \= at_most_many
+		->
+			determinism_components(InnerDetism, IfThenElseCanFail,
+				at_most_many),
+			goal_info_set_determinism(GoalInfo0, InnerDetism,
+				InnerInfo),
+			Goal = some([], IfThenElse - InnerInfo)
+		;
+			Goal = IfThenElse
+		),
 		GoalInfo = GoalInfo0
 	).
 



-- 
Fergus Henderson <fjh at cs.mu.oz.au>   |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>   |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3         |     -- the last words of T. S. Garp.



More information about the developers mailing list