[m-rev.] diff: more make_hlds cleanup

Zoltan Somogyi zs at csse.unimelb.edu.au
Tue Feb 1 06:13:43 AEDT 2011


compiler/add_clause.m:
	Fix some style issues.

	Give some predicate more meaningful and less generic names.
	
compiler/state_var.m:
	Keep the definition of the svar_info type private to the module.

	Keep the predicate that creates a new svar_info predicate pivate,
	since it is not called directly from outside this module.

	Replace a tuple with purpose-specific type.

compiler/superhomogeneous.m:
	Conform to the above changes.

	Resolve an old XXX.

Zoltan.

cvs diff: Diffing .
Index: add_clause.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/add_clause.m,v
retrieving revision 1.62
diff -u -b -r1.62 add_clause.m
--- add_clause.m	29 Dec 2010 04:52:16 -0000	1.62
+++ add_clause.m	31 Jan 2011 10:03:49 -0000
@@ -38,14 +38,17 @@
     list(error_spec)::in, list(error_spec)::out) is det.
 
     % Convert goals from the prog_data `goal' structure into the HLDS
-    % `hlds_goal' structure.  At the same time, convert it to super-homogeneous
-    % form by unravelling all the complex unifications, and annotate those
-    % unifications with a unify_context so that we can still give good error
-    % messages. And also at the same time, apply the given substitution to
-    % the goal, to rename it apart from the other clauses.
+    % `hlds_goal' structure.  At the same time,
     %
-:- pred transform_goal(goal::in, prog_var_renaming::in, hlds_goal::out,
-    int::out, prog_varset::in, prog_varset::out,
+    % - convert it to super-homogeneous form by unravelling all the complex
+    %   unifications, and annotate those unifications with a unify_context
+    %   so that we can still give good error messages;
+    % - apply the given substitution to the goal, to rename it apart
+    %   from the other clauses; and
+    % - expand references to state variables.
+    %
+:- pred transform_goal_expr_context_to_goal(goal::in, prog_var_renaming::in,
+    hlds_goal::out, int::out, prog_varset::in, prog_varset::out,
     module_info::in, module_info::out, qual_info::in, qual_info::out,
     svar_info::in, svar_info::out,
     list(error_spec)::in, list(error_spec)::out) is det.
@@ -124,8 +127,8 @@
                     [s("Attempted to introduce a predicate"),
                     s("for a promise with an identical"),
                     s("name to an existing predicate"),
-                    s(NameString)], String),
-                unexpected(this_file, String)
+                    s(NameString)], UnexpectedMsg),
+                unexpected($module, $pred, UnexpectedMsg)
             ;
                 true
             )
@@ -516,8 +519,7 @@
                     ClauseLang = impl_lang_foreign(_),
                     (
                         ApplProcIds = all_modes,
-                        unexpected(this_file,
-                            "clauses_info_add_clause: all_modes foreign_proc")
+                        unexpected($module, $pred, "all_modes foreign_proc")
                     ;
                         ApplProcIds = selected_modes(ProcIds)
                     )
@@ -593,8 +595,8 @@
                 do_not_attach_in_from_ground_term, HeadGoal1, HeadGoal)
         ),
         svar_prepare_for_body(FinalSVarMap, !VarSet, !SInfo),
-        transform_goal(ParseBody, Renaming, BodyGoal, _, !VarSet, !ModuleInfo,
-            !QualInfo, !SInfo, !Specs),
+        transform_goal_expr_context_to_goal(ParseBody, Renaming, BodyGoal, _,
+            !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs),
         svar_finish_goals(Context, FinalSVarMap, [HeadGoal, BodyGoal], Goal0,
             !.SInfo),
         qual_info_get_var_types(!.QualInfo, VarTypes0),
@@ -613,20 +615,22 @@
 
 %-----------------------------------------------------------------------------%
 
-transform_goal(Goal0 - Context, Renaming, hlds_goal(GoalExpr, GoalInfo),
+transform_goal_expr_context_to_goal(Goal0 - Context, Renaming, Goal,
         NumAdded, !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs) :-
-    transform_goal_2(Goal0, Context, Renaming, hlds_goal(GoalExpr, GoalInfo1),
+    transform_goal_expr_to_goal(Goal0, Context, Renaming, Goal1,
         NumAdded, !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs),
-    goal_info_set_context(Context, GoalInfo1, GoalInfo).
+    Goal1 = hlds_goal(GoalExpr, GoalInfo1),
+    goal_info_set_context(Context, GoalInfo1, GoalInfo),
+    Goal = hlds_goal(GoalExpr, GoalInfo).
 
-:- pred transform_goal_2(goal_expr::in, prog_context::in,
+:- pred transform_goal_expr_to_goal(goal_expr::in, prog_context::in,
     prog_var_renaming::in, hlds_goal::out, num_added_goals::out,
     prog_varset::in, prog_varset::out,
     module_info::in, module_info::out, qual_info::in, qual_info::out,
     svar_info::in, svar_info::out,
     list(error_spec)::in, list(error_spec)::out) is det.
 
-transform_goal_2(Expr, Context, Renaming, Goal, !:NumAdded,
+transform_goal_expr_to_goal(Expr, Context, Renaming, Goal, !:NumAdded,
         !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs) :-
     (
         (
@@ -651,13 +655,13 @@
             TransformedExpr = not_expr(some_state_vars_expr(StateVars,
                 not_expr(Goal0) - Context) - Context)
         ),
-        transform_goal_2(TransformedExpr, Context, Renaming, Goal, !:NumAdded,
-            !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs)
+        transform_goal_expr_to_goal(TransformedExpr, Context, Renaming,
+            Goal, !:NumAdded, !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs)
     ;
         Expr = some_expr(Vars0, SubExpr),
         rename_var_list(need_not_rename, Renaming, Vars0, Vars),
-        transform_goal(SubExpr, Renaming, SubGoal, !:NumAdded,
-            !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs),
+        transform_goal_expr_context_to_goal(SubExpr, Renaming, SubGoal,
+            !:NumAdded, !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs),
         GoalExpr = scope(exist_quant(Vars), SubGoal),
         goal_info_init(GoalInfo),
         Goal = hlds_goal(GoalExpr, GoalInfo)
@@ -666,16 +670,16 @@
         BeforeSInfo = !.SInfo,
         rename_var_list(need_not_rename, Renaming, StateVars0, StateVars),
         prepare_for_local_state_vars(StateVars, !VarSet, !SInfo),
-        transform_goal(SubExpr0, Renaming, SubGoal, !:NumAdded,
-            !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs),
+        transform_goal_expr_context_to_goal(SubExpr0, Renaming, SubGoal,
+            !:NumAdded, !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs),
         finish_local_state_vars(StateVars, Vars, BeforeSInfo, !SInfo),
         GoalExpr = scope(exist_quant(Vars), SubGoal),
         goal_info_init(GoalInfo),
         Goal = hlds_goal(GoalExpr, GoalInfo)
     ;
         Expr = promise_purity_expr(Purity, SubExpr0),
-        transform_goal(SubExpr0, Renaming, SubGoal, !:NumAdded,
-            !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs),
+        transform_goal_expr_context_to_goal(SubExpr0, Renaming, SubGoal,
+            !:NumAdded, !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs),
         GoalExpr = scope(promise_purity(Purity), SubGoal),
         goal_info_init(GoalInfo),
         Goal = hlds_goal(GoalExpr, GoalInfo)
@@ -699,16 +703,16 @@
         Goal = hlds_goal(GoalExpr, GoalInfo)
     ;
         Expr = require_detism_expr(Detism, SubExpr),
-        transform_goal(SubExpr, Renaming, SubGoal, !:NumAdded,
-            !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs),
+        transform_goal_expr_context_to_goal(SubExpr, Renaming, SubGoal,
+            !:NumAdded, !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs),
         GoalExpr = scope(require_detism(Detism), SubGoal),
         goal_info_init(GoalInfo),
         Goal = hlds_goal(GoalExpr, GoalInfo)
     ;
         Expr = require_complete_switch_expr(Var0, SubExpr),
         rename_var(need_not_rename, Renaming, Var0, Var),
-        transform_goal(SubExpr, Renaming, SubGoal, !:NumAdded,
-            !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs),
+        transform_goal_expr_context_to_goal(SubExpr, Renaming, SubGoal,
+            !:NumAdded, !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs),
         GoalExpr = scope(require_complete_switch(Var), SubGoal),
         goal_info_init(GoalInfo),
         Goal = hlds_goal(GoalExpr, GoalInfo)
@@ -751,9 +755,10 @@
             MaybeInnerScopeInfo = no
         ),
         BeforeDisjSInfo = !.SInfo,
-        transform_goal(MainExpr, Renaming, HLDSMainGoal0, !:NumAdded,
-            !VarSet, !ModuleInfo, !QualInfo, BeforeDisjSInfo, SInfo1, !Specs),
-        MainDisjInfo = {HLDSMainGoal0, SInfo1},
+        transform_goal_expr_context_to_goal(MainExpr, Renaming, HLDSMainGoal0,
+            !:NumAdded, !VarSet, !ModuleInfo, !QualInfo,
+            BeforeDisjSInfo, SInfo1, !Specs),
+        MainDisjInfo = hlds_goal_svar_info(HLDSMainGoal0, SInfo1),
         transform_orelse_goals(OrElseExprs, Renaming, OrElseDisjInfos,
             0, OrElseNumAdded, !VarSet, !ModuleInfo, !QualInfo,
             BeforeDisjSInfo, !Specs),
@@ -837,8 +842,8 @@
         BeforeSInfo = !.SInfo,
         rename_var_list(need_not_rename, Renaming, StateVars0, StateVars),
         prepare_for_local_state_vars(StateVars, !VarSet, !SInfo),
-        transform_goal(SubExpr1, Renaming, SubGoal, !:NumAdded,
-            !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs),
+        transform_goal_expr_context_to_goal(SubExpr1, Renaming, SubGoal,
+            !:NumAdded, !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs),
         !:NumAdded =
             list.length(GetExprs) + !.NumAdded + list.length(SetExprs),
         finish_local_state_vars(StateVars, Vars, BeforeSInfo, !SInfo),
@@ -882,17 +887,17 @@
         rename_var_list(need_not_rename, Renaming, Vars0, Vars),
         rename_var_list(need_not_rename, Renaming, StateVars0, StateVars),
         svar_prepare_for_if_then_else_goal(StateVars, !VarSet, !SInfo),
-        transform_goal(Cond0, Renaming, Cond, CondAdded, !VarSet, !ModuleInfo,
-            !QualInfo, !SInfo, !Specs),
+        transform_goal_expr_context_to_goal(Cond0, Renaming, Cond, CondAdded,
+            !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs),
         svar_finish_if_then_else_goal_condition(StateVars,
             BeforeSInfo, !.SInfo, AfterCondSInfo, !:SInfo),
-        transform_goal(Then0, Renaming, Then1, ThenAdded, !VarSet, !ModuleInfo,
-            !QualInfo, !SInfo, !Specs),
+        transform_goal_expr_context_to_goal(Then0, Renaming, Then1, ThenAdded,
+            !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs),
         svar_finish_if_then_else_goal_then_goal(StateVars, BeforeSInfo,
             !SInfo),
         AfterThenSInfo = !.SInfo,
-        transform_goal(Else0, Renaming, Else1, ElseAdded, !VarSet, !ModuleInfo,
-            !QualInfo, BeforeSInfo, !:SInfo, !Specs),
+        transform_goal_expr_context_to_goal(Else0, Renaming, Else1, ElseAdded,
+            !VarSet, !ModuleInfo, !QualInfo, BeforeSInfo, !:SInfo, !Specs),
         !:NumAdded = CondAdded + ThenAdded + ElseAdded,
         goal_info_init(Context, GoalInfo),
         svar_finish_if_then_else(Context, Then1, Then, Else1, Else,
@@ -902,8 +907,8 @@
     ;
         Expr = not_expr(SubExpr0),
         BeforeSInfo = !.SInfo,
-        transform_goal(SubExpr0, Renaming, SubGoal, !:NumAdded,
-            !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs),
+        transform_goal_expr_context_to_goal(SubExpr0, Renaming, SubGoal,
+            !:NumAdded, !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs),
         svar_finish_negation(BeforeSInfo, !SInfo),
         GoalExpr = negation(SubGoal),
         goal_info_init(GoalInfo),
@@ -940,8 +945,8 @@
         % `P => Q' is defined as `not (P, not Q)'
         TransformedExpr = not_expr(conj_expr(P, not_expr(Q) - Context)
             - Context),
-        transform_goal_2(TransformedExpr, Context, Renaming, Goal, !:NumAdded,
-            !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs)
+        transform_goal_expr_to_goal(TransformedExpr, Context, Renaming,
+            Goal, !:NumAdded, !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs)
     ;
         Expr = equivalent_expr(P0, Q0),
         % `P <=> Q' is defined as `(P => Q), (Q => P)',
@@ -950,9 +955,9 @@
         % quantification of the variables inside them.
 
         BeforeSInfo = !.SInfo,
-        transform_goal(P0, Renaming, P, NumAddedP,
+        transform_goal_expr_context_to_goal(P0, Renaming, P, NumAddedP,
             !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs),
-        transform_goal(Q0, Renaming, Q, NumAddedQ,
+        transform_goal_expr_context_to_goal(Q0, Renaming, Q, NumAddedQ,
             !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs),
         svar_finish_equivalence(BeforeSInfo, !SInfo),
         !:NumAdded = NumAddedP + NumAddedQ,
@@ -986,8 +991,9 @@
             svar_prepare_for_call(!SInfo),
             % `LHS \= RHS' is defined as `not (LHS = RHS)'
             TransformedExpr = not_expr(unify_expr(LHS, RHS, Purity) - Context),
-            transform_goal_2(TransformedExpr, Context, Renaming, Goal,
-                !:NumAdded, !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs),
+            transform_goal_expr_to_goal(TransformedExpr, Context, Renaming,
+                Goal, !:NumAdded, !VarSet, !ModuleInfo,
+                !QualInfo, !SInfo, !Specs),
             svar_finish_call(!VarSet, !SInfo)
         ;
             % check for a state var record assignment:
@@ -1008,8 +1014,9 @@
                 FieldListContext),
             RHS = functor(atom(":="), [FieldList, RHS0], Context),
             TransformedExpr = unify_expr(LHS, RHS, Purity),
-            transform_goal_2(TransformedExpr, Context, Renaming, Goal,
-                !:NumAdded, !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs),
+            transform_goal_expr_to_goal(TransformedExpr, Context, Renaming,
+                Goal, !:NumAdded, !VarSet, !ModuleInfo,
+                !QualInfo, !SInfo, !Specs),
             svar_finish_call(!VarSet, !SInfo)
         ;
             % check for a DCG field access goal:
@@ -1136,8 +1143,8 @@
     rename_var_list(need_not_rename, Renaming, DotSVars0, DotSVars1),
     convert_dot_state_vars(Context, DotSVars1, DotSVars, !VarSet,
         !SInfo, !Specs),
-    transform_goal(Goal0, Renaming, Goal, NumAdded, !VarSet, !ModuleInfo,
-        !QualInfo, !SInfo, !Specs),
+    transform_goal_expr_context_to_goal(Goal0, Renaming, Goal, NumAdded,
+        !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs),
     goal_info_init(GoalInfo),
     rename_var_list(need_not_rename, Renaming, ColonSVars0, ColonSVars1),
     convert_dot_state_vars(Context, ColonSVars1, ColonSVars, !VarSet,
@@ -1241,12 +1248,11 @@
 dcg_field_error_context_pieces(AccessType) = ContextPieces :-
     (
         AccessType = set,
-        Action = "update"
+        ContextPieces = [words("In DCG field update goal:"), nl]
     ;
         AccessType = get,
-        Action = "extraction"
-    ),
-    ContextPieces = [words("In DCG field"), words(Action), words("goal:"), nl].
+        ContextPieces = [words("In DCG field extraction goal:"), nl]
+    ).
 
     % Produce an invalid goal.
     %
@@ -1289,7 +1295,7 @@
                 FuncName = FuncNamePrime,
                 FuncArity = FuncArityPrime
             ;
-                unexpected(this_file, "transform_dcg_record_syntax_2")
+                unexpected($module, $pred, "not cons")
             ),
             % DCG arguments should always be distinct variables,
             % so this context should never be used.
@@ -1319,7 +1325,7 @@
                 FuncName = FuncNamePrime,
                 FuncArity = FuncArityPrime
             ;
-                unexpected(this_file, "transform_dcg_record_syntax_2")
+                unexpected($module, $pred, "not cons")
             ),
             FieldArgNumber = 2,
             SimpleCallId = simple_call_id(pf_function, FuncName, FuncArity),
@@ -1340,7 +1346,7 @@
             NumAdded = ExtractAdded + ArgAdded
         )
     ;
-        unexpected(this_file, "do_transform_dcg_record_syntax")
+        unexpected($module, $pred, "arity != 3")
     ).
 
     % get_rev_conj(Goal, Renaming, RevConj0, RevConj) :
@@ -1362,8 +1368,8 @@
         get_rev_conj(B, Renaming, RevConj1, RevConj, !NumAdded,
             !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs)
     ;
-        transform_goal(Goal, Renaming, Goal1, GoalAdded, !VarSet, !ModuleInfo,
-            !QualInfo, !SInfo, !Specs),
+        transform_goal_expr_context_to_goal(Goal, Renaming, Goal1, GoalAdded,
+            !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs),
         !:NumAdded = !.NumAdded + GoalAdded,
         goal_to_conj_list(Goal1, ConjList),
         RevConj = list.reverse(ConjList) ++ RevConj0
@@ -1388,8 +1394,8 @@
         get_rev_par_conj(B, Renaming, RevParConj1, RevParConj, !NumAdded,
             !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs)
     ;
-        transform_goal(Goal, Renaming, Goal1, GoalAdded, !VarSet, !ModuleInfo,
-            !QualInfo, !SInfo, !Specs),
+        transform_goal_expr_context_to_goal(Goal, Renaming, Goal1, GoalAdded,
+            !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs),
         !:NumAdded = !.NumAdded + GoalAdded,
         goal_to_par_conj_list(Goal1, ParConjList),
         RevParConj = list.reverse(ParConjList) ++ RevParConj0
@@ -1419,10 +1425,11 @@
         get_disj(A, Renaming, DisjInfos1, DisjInfos,  !NumAdded, !VarSet,
             !ModuleInfo, !QualInfo, SInfo0, !Specs)
     ;
-        transform_goal(Goal, Renaming, HLDSGoal, GoalAdded, !VarSet,
-            !ModuleInfo, !QualInfo, SInfo0, SInfo1, !Specs),
+        transform_goal_expr_context_to_goal(Goal, Renaming,
+            HLDSGoal, GoalAdded, !VarSet, !ModuleInfo,
+            !QualInfo, SInfo0, SInfo1, !Specs),
         !:NumAdded = !.NumAdded + GoalAdded,
-        DisjInfo = {HLDSGoal, SInfo1},
+        DisjInfo = hlds_goal_svar_info(HLDSGoal, SInfo1),
         DisjInfos = [DisjInfo | DisjInfos0]
     ).
 
@@ -1436,9 +1443,9 @@
         !NumAdded, !VarSet, !ModuleInfo, !QualInfo, _SInfo0, !Specs).
 transform_orelse_goals([Goal | Goals], Renaming, [DisjInfo | DisjInfos],
         !NumAdded, !VarSet, !ModuleInfo, !QualInfo, SInfo0, !Specs) :-
-    transform_goal(Goal, Renaming, HLDSGoal, NumAddedGoal,
+    transform_goal_expr_context_to_goal(Goal, Renaming, HLDSGoal, NumAddedGoal,
         !VarSet, !ModuleInfo, !QualInfo, SInfo0, SInfo1, !Specs),
-    DisjInfo = {HLDSGoal, SInfo1},
+    DisjInfo = hlds_goal_svar_info(HLDSGoal, SInfo1),
     !:NumAdded = !.NumAdded + NumAddedGoal,
     transform_orelse_goals(Goals, Renaming, DisjInfos,
         !NumAdded, !VarSet, !ModuleInfo, !QualInfo, SInfo0, !Specs).
@@ -1492,8 +1499,8 @@
     % Make the call to magic_exception_result.
     CallMagic0 = call_expr(magic_exception_result_sym_name, [ResultVarTerm],
         purity_pure) - Context,
-    transform_goal(CallMagic0, Renaming, CallMagic, NumAddedA,
-        !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs),
+    transform_goal_expr_context_to_goal(CallMagic0, Renaming, CallMagic,
+        NumAddedA, !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs),
 
     % Get the variable for !.IO before the (eventual) try_io call.
     svar_dot(Context, IOStateVar, IOStateVarBefore, !VarSet, !SInfo, !Specs),
@@ -1507,8 +1514,9 @@
             exception_functor("succeeded", NullTupleTerm, Context),
             purity_pure
         ) - Context,
-    transform_goal(ResultIsSucceededUnify0, Renaming, ResultIsSucceededUnify,
-        NumAddedB, !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs),
+    transform_goal_expr_context_to_goal(ResultIsSucceededUnify0, Renaming,
+        ResultIsSucceededUnify, NumAddedB, !VarSet, !ModuleInfo,
+        !QualInfo, !SInfo, !Specs),
 
     % Build "some [] ( !:IO = !.IO, Goal )".
     %
@@ -1521,16 +1529,16 @@
         purity_pure
     ) - Context,
     ScopedGoal0 = some_expr([], conj_expr(IOUnify, Goal0) - Context) - Context,
-    transform_goal(ScopedGoal0, Renaming, ScopedGoal, NumAddedC,
-        !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs),
+    transform_goal_expr_context_to_goal(ScopedGoal0, Renaming, ScopedGoal,
+        NumAddedC, !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs),
 
     % Remember the variable for !.IO after the (eventual) try_io Goal.
     svar_dot(Context, IOStateVar, IOStateVarAfter, !VarSet, !SInfo, !Specs),
 
     % Build "some [] ( Then )".
     ScopedThen0 = some_expr([], Then0) - Context,
-    transform_goal(ScopedThen0, Renaming, ScopedThen, NumAddedD,
-        !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs),
+    transform_goal_expr_context_to_goal(ScopedThen0, Renaming, ScopedThen,
+        NumAddedD, !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs),
 
     % Build:
     %
@@ -1547,7 +1555,7 @@
     % Build the disjunct for "TryResult = exception(Excp), ...".
     make_exception_handling_disjunct(ResultVarTerm, ExcpVarTerm, Catches0,
         MaybeCatchAny0, Context, ResultIsExceptionDisjunct0),
-    transform_goal(ResultIsExceptionDisjunct0, Renaming,
+    transform_goal_expr_context_to_goal(ResultIsExceptionDisjunct0, Renaming,
         ResultIsExceptionDisjunct, NumAddedE,
         !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs),
 
@@ -1555,8 +1563,10 @@
 
     % Get the disjuncts.
     DisjunctSInfos = [
-        {ResultIsSucceededDisjunct, SInfoAfterResultIsSucceededDisjunct},
-        {ResultIsExceptionDisjunct, SInfoAfterResultIsExceptionDisjunct}
+        hlds_goal_svar_info(ResultIsSucceededDisjunct,
+            SInfoAfterResultIsSucceededDisjunct),
+        hlds_goal_svar_info(ResultIsExceptionDisjunct,
+            SInfoAfterResultIsExceptionDisjunct)
     ],
     svar_finish_disjunction(Context, !.VarSet, DisjunctSInfos,
         Disjuncts, !:SInfo),
@@ -1660,7 +1670,7 @@
                 ResultIsExceptionDisjunct0
             ) - Context
         ) - Context,
-    transform_goal(CallMagicThenDisjunction0, Renaming,
+    transform_goal_expr_context_to_goal(CallMagicThenDisjunction0, Renaming,
         CallMagicThenDisjunction, NumAdded,
         !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs),
 
@@ -1740,9 +1750,3 @@
         [Arg], Context, Term).
 
 %----------------------------------------------------------------------------%
-
-:- func this_file = string.
-
-this_file = "add_clause.m".
-
-%----------------------------------------------------------------------------%
Index: state_var.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/state_var.m,v
retrieving revision 1.34
diff -u -b -r1.34 state_var.m
--- state_var.m	31 Jan 2011 09:04:29 -0000	1.34
+++ state_var.m	31 Jan 2011 19:06:22 -0000
@@ -51,45 +51,26 @@
     ;       in_atom(
                 % In the context of an atomic goal at the level of the
                 % source code.
+
+                % The set of state variables X that have been referenced as !:X
+                % in the parameters of the atomic goal.
                 had_colon_reference :: svar_set,
-                                    % The set of state variables X that
-                                    % have been referenced as !:X in the
-                                    % parameters of the atomic goal.
+
+                % The parent svar_info, used to keep track of nesting
+                % in subterms of an atomic formula.
                 parent_svar_info    :: svar_info
-                                    % The parent svar_info, used to keep
-                                    % track of nesting in subterms of
-                                    % an atomic formula.
             ).
 
-:- type svar_info
-    --->    svar_info(
-                svar_ctxt           ::  svar_ctxt,
-
-                % This is used to number state variables and is incremented
-                % for each source-level conjunct.
-                svar_num            ::  int,
-
-                % The "read only" state variables in scope (e.g. external state
-                % variables visible from within a lambda body or condition
-                % of an if-then-else expression.)
-                svar_readonly_dot   ::  svar_map,
-
-                % The "read/write" state variables in scope.
-                svar_dot            ::  svar_map,
-                svar_colon          ::  svar_map
-            ).
+:- type svar_info.
 
     % When collecting the arms of a disjunction we also need to
     % collect the resulting svar_infos.
     %
-:- type hlds_goal_svar_info == {hlds_goal, svar_info}.
+:- type hlds_goal_svar_info
+    --->    hlds_goal_svar_info(hlds_goal, svar_info).
 
 :- type hlds_goal_svar_infos == list(hlds_goal_svar_info).
 
-    % Create a new svar_info set up to start processing a clause head.
-    %
-:- func new_svar_info = svar_info.
-
     % Obtain the mapping for a !.X state variable reference and
     % update the svar_info.
     %
@@ -361,12 +342,35 @@
 
 %-----------------------------------------------------------------------------%
 
-new_svar_info = svar_info(in_head, 0, map.init, map.init, map.init).
+:- type svar_info
+    --->    svar_info(
+                svar_ctxt           ::  svar_ctxt,
+
+                % This is used to number state variables and is incremented
+                % for each source-level conjunct.
+                svar_num            ::  int,
+
+                % The "read only" state variables in scope (e.g. external state
+                % variables visible from within a lambda body or condition
+                % of an if-then-else expression.)
+                svar_readonly_dot   ::  svar_map,
+
+                % The "read/write" state variables in scope.
+                svar_dot            ::  svar_map,
+                svar_colon          ::  svar_map
+            ).
+
+    % Create a new svar_info set up to start processing a clause head.
+    %
+:- func new_svar_info = svar_info.
+
+new_svar_info =
+    svar_info(in_head, 0, map.init, map.init, map.init).
 
 :- pred has_svar_colon_mapping_for(svar_info::in, svar::in) is semidet.
 
 has_svar_colon_mapping_for(SInfo, StateVar) :-
-    SInfo ^ svar_colon `contains` StateVar.
+    map.contains(SInfo ^ svar_colon, StateVar).
 has_svar_colon_mapping_for(SInfo, StateVar) :-
     SInfo ^ svar_ctxt = in_atom(_, ParentSInfo),
     has_svar_colon_mapping_for(ParentSInfo, StateVar).
@@ -740,13 +744,16 @@
     conj_list_to_goal(Thens, GoalInfo, Then1),
 
     % Calculate the svar_info with the highest numbered mappings from each arm.
-    DisjSInfos = [{Then1, SInfoT}, {Else0, SInfoE}],
+    DisjSInfos = [hlds_goal_svar_info(Then1, SInfoT),
+        hlds_goal_svar_info(Else0, SInfoE)],
     SInfo      = reconcile_disj_svar_info(!.VarSet, DisjSInfos),
 
     % Add unifiers to each arm to ensure they both construct the same
     % final state variable mappings.
-    Then = add_disj_unifiers(Context, SInfo, StateVars, {Then1, SInfoT}),
-    Else = add_disj_unifiers(Context, SInfo, StateVars, {Else0, SInfoE}).
+    Then = add_disj_unifiers(Context, SInfo, StateVars,
+        hlds_goal_svar_info(Then1, SInfoT)),
+    Else = add_disj_unifiers(Context, SInfo, StateVars,
+        hlds_goal_svar_info(Else0, SInfoE)).
 
     % If a new mapping was produced for state variable X in the condition-goal
     % (i.e. the condition refers to !:X), but not in the then-goal, then
@@ -837,7 +844,7 @@
     % We compute the set of final !. and !: state variables over the whole
     % disjunction (not all arms will necessarily include !. and !: mappings
     % for all state variables).
-    DisjSInfo = {_, SInfo0},
+    DisjSInfo = hlds_goal_svar_info(_, SInfo0),
     Dots0   = set.sorted_list_to_set(map.keys(SInfo0 ^ svar_dot)),
     Colons0 = set.sorted_list_to_set(map.keys(SInfo0 ^ svar_colon)),
     union_dot_colon_svars(DisjSInfos, Dots0, Dots, Colons0, Colons),
@@ -852,7 +859,7 @@
 
 union_dot_colon_svars([], !Dots, !Colons).
 union_dot_colon_svars([DisjSInfo | DisjSInfos], !Dots, !Colons) :-
-    DisjSInfo = {_, SInfo},
+    DisjSInfo = hlds_goal_svar_info(_, SInfo),
     set.union(set.sorted_list_to_set(map.keys(SInfo ^ svar_dot)), !Dots),
     set.union(set.sorted_list_to_set(map.keys(SInfo ^ svar_colon)), !Colons),
     union_dot_colon_svars(DisjSInfos, !Dots, !Colons).
@@ -860,7 +867,8 @@
 :- pred reconcile_svar_infos(prog_varset::in, svar_set::in, svar_set::in,
     hlds_goal_svar_info::in, svar_info::in, svar_info::out) is det.
 
-reconcile_svar_infos(VarSet, Dots, Colons, {_, SInfoX}, !SInfo) :-
+reconcile_svar_infos(VarSet, Dots, Colons, GoalSInfoX, !SInfo) :-
+    GoalSInfoX = hlds_goal_svar_info(_, SInfoX),
     InitNum = !.SInfo ^ svar_num,
     XNum = SInfoX ^ svar_num,
     set.fold(reconcile_svar_infos_dots(VarSet, SInfoX), Dots, !SInfo),
@@ -922,7 +930,8 @@
 :- func add_disj_unifiers(prog_context, svar_info, svars, hlds_goal_svar_info)
     = hlds_goal.
 
-add_disj_unifiers(Context, SInfo, StateVars, {GoalX, SInfoX}) = Goal :-
+add_disj_unifiers(Context, SInfo, StateVars, GoalSInfoX) = Goal :-
+    GoalSInfoX = hlds_goal_svar_info(GoalX, SInfoX),
     Unifiers0 = [],
     list.foldl(add_disj_unifier(Context, SInfo, SInfoX), StateVars,
         Unifiers0, Unifiers),
Index: superhomogeneous.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/superhomogeneous.m,v
retrieving revision 1.40
diff -u -b -r1.40 superhomogeneous.m
--- superhomogeneous.m	31 Jan 2011 09:04:29 -0000	1.40
+++ superhomogeneous.m	31 Jan 2011 10:08:11 -0000
@@ -544,8 +544,7 @@
         NumAdded = NumAddedPrime
     ;
         % Handle higher-order pred and func expressions.
-        % XXX Why do we use Arg1 instead of Args here?
-        RHS = term.functor(F, Args1, FunctorContext),
+        RHS = term.functor(F, Args, FunctorContext),
         parse_rule_term(Context, RHS, HeadTerm0, GoalTerm1),
         term.coerce(HeadTerm0, HeadTerm1),
         parse_purity_annotation(HeadTerm1, LambdaPurity, HeadTerm),
@@ -731,7 +730,7 @@
                 svar_prepare_for_if_then_else_expr(StateVars, !VarSet, !SInfo),
 
                 map.init(EmptySubst),
-                transform_goal(CondParseTree, EmptySubst,
+                transform_goal_expr_context_to_goal(CondParseTree, EmptySubst,
                     CondGoal, CondAdded, !VarSet, !ModuleInfo,
                     !QualInfo, !SInfo, !Specs),
 
@@ -987,8 +986,8 @@
 
         svar_prepare_for_body(FinalSVarMap, !VarSet, !SInfo),
 
-        transform_goal(ParsedGoal, Substitution, Body, BodyAdded,
-            !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs),
+        transform_goal_expr_context_to_goal(ParsedGoal, Substitution, Body,
+            BodyAdded, !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs),
         NumAdded = NonOutputAdded + OutputAdded + BodyAdded,
 
         % Fix up any state variable unifications.
@@ -1012,9 +1011,9 @@
             scope(exist_quant(QuantifiedVars), HLDS_Goal0),
             GoalInfo),
 
-        % We set the lambda nonlocals here to anything that could
-        % possibly be nonlocal.  Quantification will reduce this down to
-        % the proper set of nonlocal arguments.
+        % We set the lambda nonlocals here to anything that could possibly be
+        % nonlocal. Quantification will reduce this down to the proper set
+        % of nonlocal arguments.
 
         some [!LambdaGoalVars] (
             goal_util.goal_vars(HLDS_Goal, !:LambdaGoalVars),
cvs diff: Diffing notes
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list