[m-rev.] diff: fix handling of error/1 in optimization passes

Simon Taylor stayl at cs.mu.OZ.AU
Fri Nov 28 13:22:52 AEDT 2003


Estimated hours taken: 0.5
Branches: main

compiler/constraint.m:
compiler/deforest.m:
compiler/goal_util.m:
compiler/simplify.m:
compiler/rl.m:
	s/goal_cannot_loop/goal_cannot_loop_or_throw/ throughout
	the optimization passes.  This is needed to avoid optimizing
	away calls to error/1 now that it is marked as terminating.

compiler/pd_util.m:
	Remove a duplicate of goal_util__reordering_maintains_termination.

Index: compiler/constraint.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/constraint.m,v
retrieving revision 1.52
diff -u -u -r1.52 constraint.m
--- compiler/constraint.m	5 Nov 2003 03:17:35 -0000	1.52
+++ compiler/constraint.m	27 Nov 2003 13:54:32 -0000
@@ -417,7 +417,7 @@
 		{ goal_info_is_pure(GoalInfo) },
 
 		% Don't propagate goals that can loop. 
-		{ goal_cannot_loop(ModuleInfo, Goal) }
+		{ goal_cannot_loop_or_throw(Goal) }
 	->
 		% It's a constraint, add it to the list of constraints
 		% to be attached to goals earlier in the conjunction.
@@ -473,7 +473,7 @@
 	;
 		% Don't move goals which can fail before a goal which
 		% can loop if `--fully-strict' is set.
-		{ \+ goal_cannot_loop(ModuleInfo, Goal) },
+		{ \+ goal_cannot_loop_or_throw(Goal) },
 		{ module_info_globals(ModuleInfo, Globals) },
 		{ globals__lookup_bool_option(Globals, fully_strict, yes) }
 	->
Index: compiler/deforest.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/deforest.m,v
retrieving revision 1.34
diff -u -u -r1.34 deforest.m
--- compiler/deforest.m	11 Nov 2003 03:23:25 -0000	1.34
+++ compiler/deforest.m	27 Nov 2003 13:55:26 -0000
@@ -887,7 +887,7 @@
 		{ list__member(OtherGoal, BetweenGoals)
 		; MaybeLaterGoal = yes(LaterGoal), OtherGoal = LaterGoal
 		},
-		\+ { pd_util__reordering_maintains_termination(ModuleInfo,
+		\+ { goal_util__reordering_maintains_termination(ModuleInfo,
 			FullyStrict, EarlierGoal, OtherGoal) }
 	->
 		pd_debug__message(
Index: compiler/goal_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/goal_util.m,v
retrieving revision 1.91
diff -u -u -r1.91 goal_util.m
--- compiler/goal_util.m	11 Nov 2003 03:23:25 -0000	1.91
+++ compiler/goal_util.m	27 Nov 2003 13:54:21 -0000
@@ -1116,7 +1116,7 @@
 		InstmapBeforeLaterGoal, VarTypes, ModuleInfo).
 
 
-goal_util__reordering_maintains_termination(ModuleInfo, FullyStrict, 
+goal_util__reordering_maintains_termination(_ModuleInfo, FullyStrict, 
 		EarlierGoal, LaterGoal) :-
 	EarlierGoal = _ - EarlierGoalInfo,
 	LaterGoal = _ - LaterGoalInfo,
@@ -1130,7 +1130,7 @@
 		% (can_loop, can_fail) into (can_fail, can_loop). 
 	( 
 		FullyStrict = yes, 
-		\+ goal_cannot_loop(ModuleInfo, EarlierGoal)
+		\+ goal_cannot_loop_or_throw(EarlierGoal)
 	->
 		LaterCanFail = cannot_fail
 	;
@@ -1140,7 +1140,7 @@
 		% (can_loop, can_fail), since this could worsen 
 		% the termination properties of the program.
 	( EarlierCanFail = can_fail ->
-		goal_cannot_loop(ModuleInfo, LaterGoal)
+		goal_cannot_loop_or_throw(LaterGoal)
 	;
 		true
 	).
Index: compiler/pd_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/pd_util.m,v
retrieving revision 1.30
diff -u -u -r1.30 pd_util.m
--- compiler/pd_util.m	6 Nov 2003 03:42:36 -0000	1.30
+++ compiler/pd_util.m	27 Nov 2003 13:55:57 -0000
@@ -133,15 +133,6 @@
 :- pred pd_util__can_reorder_goals(module_info::in, bool::in, hlds_goal::in,
 		hlds_goal::in) is semidet.
 
-	% pd_util__reordering_maintains_termination(FullyStrict, Goal1, Goal2)
-	%
-	% Succeeds if any possible change in termination behaviour from
-	% reordering the goals is allowed according to the semantics options.
-	% The information computed by termination analysis is used when
-	% making this decision.
-:- pred pd_util__reordering_maintains_termination(module_info::in, bool::in, 
-		hlds_goal::in, hlds_goal::in) is semidet.
-
 %-----------------------------------------------------------------------------%
 :- implementation.
 
@@ -1175,7 +1166,7 @@
 	\+ goal_info_is_impure(EarlierGoalInfo),
 	\+ goal_info_is_impure(LaterGoalInfo),
 
-	pd_util__reordering_maintains_termination(ModuleInfo, FullyStrict, 
+	goal_util__reordering_maintains_termination(ModuleInfo, FullyStrict, 
 		EarlierGoal, LaterGoal),
 
 	%
@@ -1201,35 +1192,6 @@
 	goal_info_get_nonlocals(GoalInfo2, NonLocals2),
 	set__intersect(ChangedVars1, NonLocals2, Intersection),
 	\+ set__empty(Intersection).
-
-pd_util__reordering_maintains_termination(ModuleInfo, FullyStrict, 
-		EarlierGoal, LaterGoal) :-
-	EarlierGoal = _ - EarlierGoalInfo,
-	LaterGoal = _ - LaterGoalInfo,
-
-	goal_info_get_determinism(EarlierGoalInfo, EarlierDetism),
-	determinism_components(EarlierDetism, EarlierCanFail, _),
-	goal_info_get_determinism(LaterGoalInfo, LaterDetism),
-	determinism_components(LaterDetism, LaterCanFail, _),
-
-		% If --fully-strict was specified, don't convert 
-		% (can_loop, can_fail) into (can_fail, can_loop). 
-	( 
-		FullyStrict = yes, 
-		\+ goal_cannot_loop(ModuleInfo, EarlierGoal)
-	->
-		LaterCanFail = cannot_fail
-	;
-		true
-	),
-		% Don't convert (can_fail, can_loop) into 
-		% (can_loop, can_fail), since this could worsen 
-		% the termination properties of the program.
-	( EarlierCanFail = can_fail ->
-		goal_cannot_loop(ModuleInfo, LaterGoal)
-	;
-		true
-	).
 
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
Index: compiler/rl.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/rl.m,v
retrieving revision 1.26
diff -u -u -r1.26 rl.m
--- compiler/rl.m	5 Nov 2003 03:17:42 -0000	1.26
+++ compiler/rl.m	28 Nov 2003 00:49:48 -0000
@@ -948,7 +948,7 @@
 		all [Goal] (	
 			list__member(Goal, Goals)
 		=>
-			goal_cannot_loop(ModuleInfo, Goal)
+			goal_cannot_loop_or_throw(Goal)
 		)
 	).
 
Index: compiler/simplify.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/simplify.m,v
retrieving revision 1.124
diff -u -u -r1.124 simplify.m
--- compiler/simplify.m	5 Nov 2003 03:17:43 -0000	1.124
+++ compiler/simplify.m	28 Nov 2003 00:54:46 -0000
@@ -338,7 +338,6 @@
 	Goal0 = _ - GoalInfo0,
 	goal_info_get_determinism(GoalInfo0, Detism),
 	simplify_info_get_det_info(Info0, DetInfo),
-	simplify_info_get_module_info(Info0, ModuleInfo),
 	(
 		%
 		% if --no-fully-strict,
@@ -348,7 +347,7 @@
 		% ensure goal is pure or semipure
 		\+ goal_info_is_impure(GoalInfo0),
 		( det_info_get_fully_strict(DetInfo, no)
-		; goal_cannot_loop(ModuleInfo, Goal0)
+		; goal_cannot_loop_or_throw(Goal0)
 		)
 	->
 		% warn about this, unless the goal was an explicit
@@ -398,7 +397,7 @@
 		% ensure goal is pure or semipure
 		\+ goal_info_is_impure(GoalInfo0),
 		( det_info_get_fully_strict(DetInfo, no)
-		; goal_cannot_loop(ModuleInfo, Goal0)
+		; goal_cannot_loop_or_throw(Goal0)
 		)
 	->
 /******************
--------------------------------------------------------------------------
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