diff: simplify.m bug fix

Fergus Henderson fjh at hydra.cs.mu.oz.au
Fri Jul 11 21:44:55 AEST 1997


Hi,

Zoltan, can you please review this one?

compiler/hlds_goal.m:
	Add some more documentation about the goal_info fields and
	their invariants.

compiler/simplify.m:
	Ensure that the determinism and instmap delta agree regarding
	unreachability.  This fixes a bug with the test case
	tests/valid/same_length_2.m that was broken by my previous
	change to inlining.m to use the goalinfo from the body of
	the callee rather than the goalinfo from the call.

cvs diff: Diffing .
Index: hlds_goal.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/hlds_goal.m,v
retrieving revision 1.34
diff -u -r1.34 hlds_goal.m
--- hlds_goal.m	1997/06/29 23:10:38	1.34
+++ hlds_goal.m	1997/07/11 11:41:21
@@ -385,26 +385,55 @@
 
 		determinism, 	% the overall determinism of the goal
 				% (computed during determinism analysis)
+				% [because true determinism is undecidable,
+				% this may be a conservative approximation]
+
 		instmap_delta,	% the change in insts over this goal
 				% (computed during mode analysis)
+				% [because true unreachability is undecidable,
+				% the instmap_delta may be reachable even
+				% when the goal really never succeeds]
+				%
+				% The following invariant is required
+				% by the code generator and is enforced
+				% by the final simplification pass:
+				% the determinism specifies at_most_zero solns
+				% iff the instmap_delta is unreachable.
+				%
+				% Before the final simplification pass,
+				% the determinism and instmap_delta
+				% might not be consistent with regard to
+				% unreachability, but both will be
+				% conservative approximations, so if either
+				% says a goal is unreachable then it is.
+
 		term__context,
-		set(var),	% the non-local vars in the goal
+
+		set(var),	% the non-local vars in the goal,
+				% i.e. the variables that occur both inside
+				% and outside of the goal.
 				% (computed by quantification.m)
+				% [in some circumstances, this may be a
+				% conservative approximation: it may be
+				% a superset of the real non-locals]
+
 		maybe(follow_vars),
 				% advisory information about where variables
 				% ought to be put next. The legal range
 				% includes the nonexistent register r(-1),
 				% which indicates any available register.
+
 		set(goal_feature),
 				% The set of used-defined "features" of
 				% this goal, which optimisers may wish
 				% to know about.
+
 		resume_point
 				% If this goal establishes a resumption point,
 				% state what variables need to be saved for
 				% that resumption point, and which entry
 				% labels of the resumption point will be
-				% needed.
+				% needed. (See compiler/notes/allocation.html)
 	).
 
 get_pragma_c_var_names(MaybeVarNames, VarNames) :-
Index: simplify.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/simplify.m,v
retrieving revision 1.35
diff -u -r1.35 simplify.m
--- simplify.m	1997/07/09 05:44:11	1.35
+++ simplify.m	1997/07/11 09:32:41
@@ -200,11 +200,39 @@
 	;
 		Goal1 = Goal0
 	),
-	simplify_info_maybe_clear_structs(before, Goal1,
-		Info0, Info1),
+	simplify_info_maybe_clear_structs(before, Goal1, Info0, Info1),
 	Goal1 = GoalExpr1 - GoalInfo1,
-	simplify__goal_2(GoalExpr1, GoalInfo1, Goal, GoalInfo, Info1, Info2),
-	simplify_info_maybe_clear_structs(after, Goal - GoalInfo, Info2, Info).
+	simplify__goal_2(GoalExpr1, GoalInfo1, Goal, GoalInfo2, Info1, Info2),
+	simplify_info_maybe_clear_structs(after, Goal - GoalInfo2, Info2, Info),
+	simplify__enforce_invariant(GoalInfo2, GoalInfo).
+
+
+:- pred simplify__enforce_invariant(hlds_goal_info, hlds_goal_info).
+:- mode simplify__enforce_invariant(in, out) is det.
+	%
+	% Ensure that the mode information and the determinism
+	% information say consistent things about unreachability.
+	%
+simplify__enforce_invariant(GoalInfo0, GoalInfo) :-
+	goal_info_get_determinism(GoalInfo0, Determinism0),
+	goal_info_get_instmap_delta(GoalInfo0, DeltaInstmap0),
+	determinism_components(Determinism0, CanFail0, NumSolns0),
+	(
+		NumSolns0 = at_most_zero,
+		instmap_delta_is_reachable(DeltaInstmap0)
+	->
+		instmap_delta_init_unreachable(UnreachableInstMapDelta),
+		goal_info_set_instmap_delta(GoalInfo0, UnreachableInstMapDelta,
+			GoalInfo)
+	;
+		instmap_delta_is_unreachable(DeltaInstmap0),
+		NumSolns0 \= at_most_zero
+	->
+		determinism_components(Determinism, CanFail0, at_most_zero),
+		goal_info_set_determinism(GoalInfo0, Determinism, GoalInfo)
+	;
+		GoalInfo = GoalInfo0
+	).
 
 %-----------------------------------------------------------------------------%
 
cvs diff: Diffing notes

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