[m-rev.] For review: allow unifications to be delayed across impure goals

Ralph Becket rafe at cs.mu.OZ.AU
Wed Oct 12 15:59:43 AEST 2005


Estimated hours taken: 1
Branches: main

Allow unifications to be delayed across impure goals.  Previously this
was disallowed which made it impossible to have deconstruction unifications
in impure pred calls, which was unnecessarily awkward.

It is safe to reorder unifications across an impure goal because they cannot
be affected by the impure goal (unifications are pure).

compiler/modes.m:
	check_for_impurity_error now filters out all delayed unifications,
	not just headvar unifications, before testing for an error.

Index: compiler/modes.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/modes.m,v
retrieving revision 1.316
diff -u -r1.316 modes.m
--- compiler/modes.m	7 Oct 2005 04:44:58 -0000	1.316
+++ compiler/modes.m	11 Oct 2005 07:58:19 -0000
@@ -2572,7 +2572,8 @@
 hlds_goal_from_delayed_goal(delayed_goal(_WaitingVars, _ModeError, Goal)) =
     Goal.
 
-    % Check whether there are any delayed goals (other than headvar
+    % Check whether there are any delayed goals (other than 
     % unifications) at the point where we are about to schedule an impure goal.
     % If so, that is an error. Headvar unifications are allowed to be delayed
     % because in the case of output arguments, they cannot be scheduled
@@ -2589,26 +2590,21 @@
     mode_info_get_delay_info(!.ModeInfo, DelayInfo0),
     delay_info__leave_conj(DelayInfo0, DelayedGoals0, DelayInfo1),
     mode_info_set_delay_info(DelayInfo1, !ModeInfo),
-    mode_info_get_module_info(!.ModeInfo, ModuleInfo),
-    mode_info_get_predid(!.ModeInfo, PredId),
-    module_info_pred_info(ModuleInfo, PredId, PredInfo),
-    pred_info_clauses_info(PredInfo, ClausesInfo),
-    clauses_info_headvars(ClausesInfo, HeadVars),
-    filter_headvar_unification_goals(HeadVars, DelayedGoals0,
-        HeadVarUnificationGoals, NonHeadVarUnificationGoals0),
+    filter_unification_goals(DelayedGoals0,
+        UnificationGoals, NonUnificationGoals0),
     modecheck_delayed_solver_goals(Goals,
-        NonHeadVarUnificationGoals0, NonHeadVarUnificationGoals,
+        NonUnificationGoals0, NonUnificationGoals,
         !ImpurityErrors, !ModeInfo, !IO),
     mode_info_get_delay_info(!.ModeInfo, DelayInfo2),
     delay_info__enter_conj(DelayInfo2, DelayInfo3),
-    redelay_goals(HeadVarUnificationGoals, DelayInfo3, DelayInfo),
+    redelay_goals(UnificationGoals, DelayInfo3, DelayInfo),
     mode_info_set_delay_info(DelayInfo, !ModeInfo),
     (
-        NonHeadVarUnificationGoals = []
+        NonUnificationGoals = []
     ;
-        NonHeadVarUnificationGoals = [_ | _],
-        get_all_waiting_vars(NonHeadVarUnificationGoals, Vars),
-        ModeError = mode_error_conj(NonHeadVarUnificationGoals,
+        NonUnificationGoals = [_ | _],
+        get_all_waiting_vars(NonUnificationGoals, Vars),
+        ModeError = mode_error_conj(NonUnificationGoals,
             goals_followed_by_impure_goal(Goal)),
         mode_info_get_context(!.ModeInfo, Context),
         mode_info_get_mode_context(!.ModeInfo, ModeContext),
@@ -2616,26 +2612,19 @@
         !:ImpurityErrors = [ImpurityError | !.ImpurityErrors]
     ).
 
-:- pred filter_headvar_unification_goals(list(prog_var)::in,
-    list(delayed_goal)::in, list(delayed_goal)::out,
+:- pred filter_unification_goals(list(delayed_goal)::in,
+    list(delayed_goal)::out,
     list(delayed_goal)::out) is det.
 
-filter_headvar_unification_goals(HeadVars, DelayedGoals,
-        HeadVarUnificationGoals, NonHeadVarUnificationGoals) :-
-    list__filter(is_headvar_unification_goal(HeadVars), DelayedGoals,
-        HeadVarUnificationGoals, NonHeadVarUnificationGoals).
+filter_unification_goals(DelayedGoals, UnificationGoals,
+        NonUnificationGoals) :-
+    list__filter(is_unification_goal, DelayedGoals,
+        UnificationGoals, NonUnificationGoals).
 
-:- pred is_headvar_unification_goal(list(prog_var)::in, delayed_goal::in)
-    is semidet.
+:- pred is_unification_goal(delayed_goal::in) is semidet.
 
-is_headvar_unification_goal(HeadVars, delayed_goal(_, _, Goal - _)) :-
-    Goal = unify(Var, RHS, _, _, _),
-    (
-        list__member(Var, HeadVars)
-    ;
-        RHS = var(OtherVar),
-        list__member(OtherVar, HeadVars)
-    ).
+is_unification_goal(delayed_goal(_, _, Goal - _)) :-
+    Goal = unify(_, _, _, _, _).
 
     % Given an association list of Vars - Goals,
     % combine all the Vars together into a single set.
--------------------------------------------------------------------------
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