diff: det_analysis.m bug fix

Fergus Henderson fjh at hydra.cs.mu.oz.au
Fri Nov 14 05:33:32 AEDT 1997


Estimated hours taken: 1

compiler/det_analysis.m:
	Fix a bug where the compiler got an internal error on certain
	determinism-incorrect code.  The problem was that det_infer_goal
	was not enforcing the invariant
		SolnContext \= first_soln => NumSolns \= at_most_many_cc
	which was assumed by det_conjunction_maxsoln.

Index: det_analysis.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/det_analysis.m,v
retrieving revision 1.122
diff -u -u -r1.122 det_analysis.m
--- det_analysis.m	1997/09/01 14:01:06	1.122
+++ det_analysis.m	1997/11/13 18:24:51
@@ -421,37 +421,47 @@
 det_infer_goal_2(call(PredId, ModeId, A, B, C, N), GoalInfo, _, SolnContext,
 		DetInfo, _, _,
 		call(PredId, ModeId, A, B, C, N), Detism, Msgs) :-
-	det_lookup_detism(DetInfo, PredId, ModeId, Detism),
+	det_lookup_detism(DetInfo, PredId, ModeId, Detism0),
 	%
 	% Make sure we don't try to call a committed-choice pred
 	% from a non-committed-choice context.
 	%
-	determinism_components(Detism, _, NumSolns),
+	determinism_components(Detism0, CanFail, NumSolns),
 	(
 		NumSolns = at_most_many_cc,
 		SolnContext \= first_soln
 	->
-		Msgs = [cc_pred_in_wrong_context(GoalInfo, Detism,
-				PredId, ModeId)]
+		Msgs = [cc_pred_in_wrong_context(GoalInfo, Detism0,
+				PredId, ModeId)],
+		% Code elsewhere relies on the assumption that
+		% SolnContext \= first_soln => NumSolns \= at_most_many_cc,
+		% so we need to enforce that here.
+		determinism_components(Detism, CanFail, at_most_many)
 	;
-		Msgs = []
+		Msgs = [],
+		Detism = Detism0
 	).
 
-det_infer_goal_2(higher_order_call(PredVar, ArgVars, Types, Modes, Det,
+det_infer_goal_2(higher_order_call(PredVar, ArgVars, Types, Modes, Det0,
 			IsPredOrFunc),
 		GoalInfo, _InstMap0, SolnContext,
 		_MiscInfo, _NonLocalVars, _DeltaInstMap,
-		higher_order_call(PredVar, ArgVars, Types, Modes, Det,
+		higher_order_call(PredVar, ArgVars, Types, Modes, Det0,
 			IsPredOrFunc),
 		Det, Msgs) :-
-	determinism_components(Det, _, NumSolns),
+	determinism_components(Det0, CanFail, NumSolns),
 	(
 		NumSolns = at_most_many_cc,
 		SolnContext \= first_soln
 	->
-		Msgs = [higher_order_cc_pred_in_wrong_context(GoalInfo, Det)]
+		Msgs = [higher_order_cc_pred_in_wrong_context(GoalInfo, Det)],
+		% Code elsewhere relies on the assumption that
+		% SolnContext \= first_soln => NumSolns \= at_most_many_cc,
+		% so we need to enforce that here.
+		determinism_components(Det, CanFail, at_most_many)
 	;
-		Msgs = []
+		Msgs = [],
+		Det = Det0
 	).
 
 	% unifications are either deterministic or semideterministic.
@@ -593,20 +603,22 @@
 	( Extra = extra_pragma_info(_, _) ->
 		% pragma C codes that specify saved variables and labels
 		% can have more than one solution
-		NumSolns = at_most_many
+		NumSolns1 = at_most_many
 	;
-		NumSolns = NumSolns0
+		NumSolns1 = NumSolns0
 	),
-	determinism_components(Detism, CanFail, NumSolns),
 	(
-		NumSolns = at_most_many_cc,
+		NumSolns1 = at_most_many_cc,
 		SolnContext \= first_soln
 	->
-		Msgs = [cc_pred_in_wrong_context(GoalInfo, Detism,
-				PredId, ProcId)]
+		Msgs = [cc_pred_in_wrong_context(GoalInfo, Detism0,
+				PredId, ProcId)],
+		NumSolns = at_most_many
 	;
-		Msgs = []
-	).
+		Msgs = [],
+		NumSolns = NumSolns1
+	),
+	determinism_components(Detism, CanFail, NumSolns).
 
 %-----------------------------------------------------------------------------%
 

-- 
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