[m-rev.] for post-commit review: fix compilation of zm_rcpsp_cpx.m

Zoltan Somogyi zs at unimelb.edu.au
Tue Mar 27 16:14:51 AEDT 2012


Apparently my emails to mercury-reviews have been getting lost because
my primary email address is not zs at cs.mu.oz.au anymore. Here is the
first report of such a lost message.

Zoltan.

----- Forwarded message from Zoltan Somogyi <zs at unimelb.edu.au> -----

Date: Mon, 26 Mar 2012 11:50:04 +1100
From: Zoltan Somogyi <zs at unimelb.edu.au>
To: mercury-reviews at cs.mu.OZ.AU
Subject: for post-commit review: fix compilation of zm_rcpsp_cpx.m

Make the compiler able to compile the zm_rcpsp_cpx.m stress test.

There were two problems. First, compilers compiled in hlc.gc
ran out stack before they even started semantic analysis. Second,
compilers compiled in asm_fast.gc ran into horrible worst case
behavior in the mode checker. The reason for that was this line
of code:

	T0_ArrayList = zb_cii1d_array([bc(no), bc(no), bc(no), ... ... ...])

The zb_cii1d_array is a function call, which is why the scope is not
subject to all the special handling I implemented last year. That was
one performance problem. The other was the fact that all the list elements
(of which there are LOTS; that line of code has more than 68,000 columns)
are either bc(no) or bc(yes). This means that the insts of the variables
representing the various partial lists very similar, which makes equality
tests among them (such as those required for tests of set membership)
fail only after doing lots of work.

The changes also make the compiler about 1.5% faster on tools/speedtest.

compiler/modecheck_unify.m:
	Fix the main problem with that stress test, which was the
	VERY expensive but redundant update of the insts of the Ys
	in unifications of the form X = f(Y1, ..., Yn) when X is
	initially free.

	We already avoided such redundant updates inside
	from_ground_term_construct scopes, but in this stress test,
	that scope gets converted into a from_ground_term_other scope
	due to the presence of a function call inside it.

	A much more minor optimization is to push some code into
	one branch of an if-then-else.

compiler/modecheck_util.m:
	The REASON why the above redundant call is so expensive is because
	for large insts, it is very expensive to abstractly unify an inst
	with itself. We therefore now check if two insts being unified
	are the same. This should prevent bad worst-case behavior
	of abstract inst unification even when called from contexts
	other than the one in modecheck_unify.

compiler/modecheck_conj.m:
	Inline the modecheck_conj_list_schedule predicate inside
	the modecheck_conj_list_flatten_and_schedule predicate.
	This allows the modechecking of conjunctions to be tracked
	in the debugger much more easily, because the direct recursion
	of modecheck_conj_list_flatten_and_schedule allows the debugger
	to collapse all the recursive calls, something it cannot do
	for the mutual recursion of the original two predicates.

compiler/superhomogeneous.m:
	Instead of having predicates return num_added_goals results
	that their callers have to add up, thread an num_added_goals
	state variable through those predicates. By avoiding the
	final addition, we can make several calls tail calls
	that weren't tail calls before. This allows the superhomogeneous
	transformation to handle significantly larger terms than before
	without running of stack space.

	Make the predicates that insert and append argument unifications
	work in less stack space by handling the first three arguments
	of each functor WITHOUT looping over them.

	Make the predicates that insert and append argument unifications
	work faster by avoiding the construction of a list for the arguments
	that have been tested for state variable expansion (the replacement
	of e.g. !.X and !:X); instead, we now test each argument just before
	processing it ourselves.

	Avoid unnecessary checking of the conjunctions created for the
	unifications of functor arguments for being hooks for state variable
	renames; since they are not branches in branched goals, they can
	never be such hooks.

	Give some predicates better names.

compiler/field_access.m:
	For efficient interoperation with superhomogeneous.m,
	thread num_added_goals variables through.

compiler/add_clause.m:
compiler/goal_expr_to_goal.m:
	Conform to the changes above.

compiler/prog_data.m:
	Make the rename_vars_in_term predicate work in less stack space
	by renaming the first three arguments of each functor WITHOUT
	looping over them.

compiler/mlds_to_il.m:
compiler/saved_vars.m:
	Rename two predicates to avoid ambiguity.

compiler/polymorphism.m:
	Avoid printing progress messages that generate clutter
	unless asked for.

compiler/modecheck_goal.m:
	Simplify some code.

compiler/purity.m:
	Fix a comment.

Zoltan.

cvs diff: Diffing .
cvs diff: Diffing analysis
cvs diff: Diffing bindist
cvs diff: Diffing boehm_gc
cvs diff: Diffing boehm_gc/Mac_files
cvs diff: Diffing boehm_gc/cord
cvs diff: Diffing boehm_gc/cord/private
cvs diff: Diffing boehm_gc/doc
cvs diff: Diffing boehm_gc/extra
cvs diff: Diffing boehm_gc/include
cvs diff: Diffing boehm_gc/include/extra
cvs diff: Diffing boehm_gc/include/private
cvs diff: Diffing boehm_gc/libatomic_ops
cvs diff: Diffing boehm_gc/libatomic_ops/doc
cvs diff: Diffing boehm_gc/libatomic_ops/src
cvs diff: Diffing boehm_gc/libatomic_ops/src/atomic_ops
cvs diff: Diffing boehm_gc/libatomic_ops/src/atomic_ops/sysdeps
cvs diff: Diffing boehm_gc/libatomic_ops/src/atomic_ops/sysdeps/armcc
cvs diff: Diffing boehm_gc/libatomic_ops/src/atomic_ops/sysdeps/gcc
cvs diff: Diffing boehm_gc/libatomic_ops/src/atomic_ops/sysdeps/hpc
cvs diff: Diffing boehm_gc/libatomic_ops/src/atomic_ops/sysdeps/ibmc
cvs diff: Diffing boehm_gc/libatomic_ops/src/atomic_ops/sysdeps/icc
cvs diff: Diffing boehm_gc/libatomic_ops/src/atomic_ops/sysdeps/msftc
cvs diff: Diffing boehm_gc/libatomic_ops/src/atomic_ops/sysdeps/sunc
cvs diff: Diffing boehm_gc/libatomic_ops/tests
cvs diff: Diffing boehm_gc/libatomic_ops-1.2
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/doc
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/src
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/src/atomic_ops
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/src/atomic_ops/sysdeps
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/tests
cvs diff: Diffing boehm_gc/m4
cvs diff: Diffing boehm_gc/tests
cvs diff: Diffing browser
cvs diff: Diffing bytecode
cvs diff: Diffing compiler
Index: compiler/add_clause.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/add_clause.m,v
retrieving revision 1.68
diff -u -b -r1.68 add_clause.m
--- compiler/add_clause.m	11 Aug 2011 06:38:13 -0000	1.68
+++ compiler/add_clause.m	23 Mar 2012 02:55:37 -0000
@@ -584,7 +584,7 @@
             ArgContext = ac_head(PredOrFunc, Arity),
             HeadGoal0 = true_goal,
             insert_arg_unifications(HeadVarList, Args, Context, ArgContext,
-                HeadGoal0, HeadGoal1, _, !SVarState, !SVarStore, !VarSet,
+                HeadGoal0, HeadGoal1, 0, _, !SVarState, !SVarStore, !VarSet,
                 !ModuleInfo, !QualInfo, !Specs),
             % The only pass that pays attention to the from_head feature,
             % switch_detection, only does so on kinds of hlds_goal_exprs
Index: compiler/field_access.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/field_access.m,v
retrieving revision 1.21
diff -u -b -r1.21 field_access.m
--- compiler/field_access.m	23 May 2011 05:08:02 -0000	1.21
+++ compiler/field_access.m	10 Mar 2012 08:27:00 -0000
@@ -46,7 +46,7 @@
     unify_main_context::in, unify_sub_contexts::in, field_list::in,
     prog_var::in, prog_var::in, prog_var::in, cons_id::out,
     pair(cons_id, unify_sub_contexts)::out, hlds_goal::out,
-    num_added_goals::out,
+    num_added_goals::in, num_added_goals::out,
     svar_state::in, svar_state::out, svar_store::in, svar_store::out,
     prog_varset::in, prog_varset::out,
     module_info::in, module_info::out, qual_info::in, qual_info::out,
@@ -68,7 +68,7 @@
     unify_main_context::in, unify_sub_contexts::in, field_list::in,
     prog_var::in, prog_var::in, prog_var::in, cons_id::out,
     pair(cons_id, unify_sub_contexts)::out, hlds_goal::out,
-    num_added_goals::out,
+    num_added_goals::in, num_added_goals::out,
     svar_state::in, svar_state::out, svar_store::in, svar_store::out,
     prog_varset::in, prog_varset::out,
     module_info::in, module_info::out, qual_info::in, qual_info::out,
@@ -88,7 +88,7 @@
     unify_main_context::in, unify_sub_contexts::in, field_list::in,
     prog_var::in, prog_var::in, purity::in, cons_id::out,
     pair(cons_id, unify_sub_contexts)::out,
-    hlds_goal::out, num_added_goals::out,
+    hlds_goal::out, num_added_goals::in, num_added_goals::out,
     svar_state::in, svar_state::out, svar_store::in, svar_store::out,
     prog_varset::in, prog_varset::out,
     module_info::in, module_info::out, qual_info::in, qual_info::out,
@@ -121,11 +121,11 @@
 
 expand_set_field_function_call(Context, MainContext, SubContext0, FieldNames,
         FieldValueVar, TermInputVar, TermOutputVar, Functor, FieldSubContext,
-        Goal, NumAdded, !SVarState, !SVarStore, !VarSet,
+        Goal, !NumAdded, !SVarState, !SVarStore, !VarSet,
         !ModuleInfo, !QualInfo, !Specs) :-
     expand_set_field_function_call_2(Context, MainContext, SubContext0,
         FieldNames, FieldValueVar, TermInputVar, TermOutputVar, Functor,
-        FieldSubContext, Goals, NumAdded,
+        FieldSubContext, Goals, !NumAdded,
         !SVarState, !SVarStore, !VarSet, !ModuleInfo, !QualInfo, !Specs),
     goal_info_init(Context, GoalInfo),
     conj_list_to_goal(Goals, GoalInfo, Goal).
@@ -134,19 +134,20 @@
     unify_main_context::in, unify_sub_contexts::in, field_list::in,
     prog_var::in, prog_var::in, prog_var::in, cons_id::out,
     pair(cons_id, unify_sub_contexts)::out, list(hlds_goal)::out,
-    num_added_goals::out,
+    num_added_goals::in, num_added_goals::out,
     svar_state::in, svar_state::out, svar_store::in, svar_store::out,
     prog_varset::in, prog_varset::out,
     module_info::in, module_info::out, qual_info::in, qual_info::out,
     list(error_spec)::in, list(error_spec)::out) is det.
 
-expand_set_field_function_call_2(_, _, _, [], _, _, _, _, _, _, _,
+expand_set_field_function_call_2(_, _, _, [], _, _, _, _, _, _, !NumAdded,
         !SVarState, !SVarStore, !VarSet, !ModuleInfo, !QualInfo, !Specs) :-
     unexpected($module, $pred, "empty list of field names").
 expand_set_field_function_call_2(Context, MainContext, SubContext0,
         [FieldName - FieldArgs | FieldNames], FieldValueVar,
-        TermInputVar, TermOutputVar, Functor, FieldSubContext, Goals, NumAdded,
-        !SVarState, !SVarStore, !VarSet, !ModuleInfo, !QualInfo, !Specs) :-
+        TermInputVar, TermOutputVar, Functor, FieldSubContext, Goals,
+        !NumAdded, !SVarState, !SVarStore, !VarSet,
+        !ModuleInfo, !QualInfo, !Specs) :-
     make_fresh_arg_vars(FieldArgs, FieldArgVars, !VarSet, !SVarState, !Specs),
     (
         FieldNames = [_ | _],
@@ -156,14 +157,14 @@
         construct_field_access_function_call(set, Context,
             MainContext, SubContext0, FieldName, TermOutputVar,
             SetArgs, purity_pure, Functor, UpdateGoal, !QualInfo),
-        UpdateAdded = 1,
+        !:NumAdded = !.NumAdded + 1,
 
         % Extract the field containing the field to update.
         construct_field_access_function_call(get, Context,
             MainContext, SubContext0, FieldName, SubTermInputVar,
             FieldArgVars ++ [TermInputVar], purity_pure, _, GetSubFieldGoal,
             !QualInfo),
-        GetSubFieldAdded = 1,
+        !:NumAdded = !.NumAdded + 1,
 
         % Recursively update the field.
         SubTermInputArgNumber = 2 + list.length(FieldArgs),
@@ -171,10 +172,9 @@
         SubContext = [TermInputContext | SubContext0],
         expand_set_field_function_call_2(Context, MainContext,
             SubContext, FieldNames, FieldValueVar, SubTermInputVar,
-            SubTermOutputVar, _, FieldSubContext, Goals0, SetAdded,
+            SubTermOutputVar, _, FieldSubContext, Goals0, !NumAdded,
             !SVarState, !SVarStore, !VarSet, !ModuleInfo, !QualInfo, !Specs),
 
-        FieldAdded = GetSubFieldAdded + SetAdded + UpdateAdded,
         Goals1 = [GetSubFieldGoal | Goals0] ++ [UpdateGoal]
     ;
         FieldNames = [],
@@ -182,7 +182,7 @@
         construct_field_access_function_call(set, Context,
             MainContext, SubContext0, FieldName, TermOutputVar,
             SetArgs, purity_pure, Functor, Goal, !QualInfo),
-        FieldAdded = 1,
+        !:NumAdded = !.NumAdded + 1,
         FieldSubContext = Functor - SubContext0,
         Goals1 = [Goal]
     ),
@@ -190,37 +190,35 @@
     goal_info_init(Context, GoalInfo),
     conj_list_to_goal(Goals1, GoalInfo, Conj0),
     insert_arg_unifications(FieldArgVars, FieldArgs, Context, ArgContext,
-        Conj0, Conj, ArgAdded, !SVarState, !SVarStore, !VarSet,
+        Conj0, Conj, !NumAdded, !SVarState, !SVarStore, !VarSet,
         !ModuleInfo, !QualInfo, !Specs),
-    NumAdded = FieldAdded + ArgAdded,
     svar_goal_to_conj_list(Conj, Goals, !SVarStore).
 
 expand_dcg_field_extraction_goal(Context, MainContext, SubContext, FieldNames,
         FieldValueVar, TermInputVar, TermOutputVar, Functor, FieldSubContext,
-        Goal, NumAdded, !SVarState, !SVarStore, !VarSet,
+        Goal, !NumAdded, !SVarState, !SVarStore, !VarSet,
         !ModuleInfo, !QualInfo, !Specs) :-
     % Unify the DCG input and output variables.
     make_atomic_unification(TermOutputVar, rhs_var(TermInputVar), Context,
         MainContext, SubContext, UnifyDCG, !QualInfo),
-    UnifyAdded = 1,
+    !:NumAdded = !.NumAdded + 1,
 
     % Process the access function as a get function on the output DCG variable.
     expand_get_field_function_call_2(Context, MainContext, SubContext,
         FieldNames, FieldValueVar, TermOutputVar, purity_pure,
-        Functor, FieldSubContext, Goals1, GetAdded,
+        Functor, FieldSubContext, Goals1, !NumAdded,
         !SVarState, !SVarStore, !VarSet, !ModuleInfo, !QualInfo, !Specs),
-    NumAdded = UnifyAdded + GetAdded,
     Goals = [UnifyDCG | Goals1],
     goal_info_init(Context, GoalInfo),
     conj_list_to_goal(Goals, GoalInfo, Goal).
 
 expand_get_field_function_call(Context, MainContext, SubContext0, FieldNames,
         FieldValueVar, TermInputVar, Purity, Functor, FieldSubContext,
-        Goal, NumAdded, !SVarState, !SVarStore, !VarSet,
+        Goal, !NumAdded, !SVarState, !SVarStore, !VarSet,
         !ModuleInfo, !QualInfo, !Specs) :-
     expand_get_field_function_call_2(Context, MainContext, SubContext0,
         FieldNames, FieldValueVar, TermInputVar, Purity, Functor,
-        FieldSubContext, Goals, NumAdded, !SVarState, !SVarStore, !VarSet,
+        FieldSubContext, Goals, !NumAdded, !SVarState, !SVarStore, !VarSet,
         !ModuleInfo, !QualInfo, !Specs),
     goal_info_init(Context, GoalInfo),
     conj_list_to_goal(Goals, GoalInfo, Goal).
@@ -229,18 +227,18 @@
     unify_main_context::in, unify_sub_contexts::in, field_list::in,
     prog_var::in, prog_var::in, purity::in, cons_id::out,
     pair(cons_id, unify_sub_contexts)::out, list(hlds_goal)::out,
-    num_added_goals::out,
+    num_added_goals::in, num_added_goals::out,
     svar_state::in, svar_state::out, svar_store::in, svar_store::out,
     prog_varset::in, prog_varset::out,
     module_info::in, module_info::out, qual_info::in, qual_info::out,
     list(error_spec)::in, list(error_spec)::out) is det.
 
-expand_get_field_function_call_2(_, _, _, [], _, _, _, _, _, _, _,
+expand_get_field_function_call_2(_, _, _, [], _, _, _, _, _, _, !NumAdded,
         !SVarState, !SVarStore, !VarSet, !ModuleInfo, !QualInfo, !Specs) :-
     unexpected($module, $pred, "empty list of field names").
 expand_get_field_function_call_2(Context, MainContext, SubContext0,
         [FieldName - FieldArgs | FieldNames], FieldValueVar, TermInputVar,
-        Purity, Functor, FieldSubContext, Goals, NumAdded,
+        Purity, Functor, FieldSubContext, Goals, !NumAdded,
         !SVarState, !SVarStore, !VarSet, !ModuleInfo, !QualInfo, !Specs) :-
     make_fresh_arg_vars(FieldArgs, FieldArgVars, !VarSet, !SVarState, !Specs),
     GetArgVars = FieldArgVars ++ [TermInputVar],
@@ -250,7 +248,7 @@
         construct_field_access_function_call(get, Context, MainContext,
             SubContext0, FieldName, SubTermInputVar, GetArgVars, Purity,
             Functor, Goal, !QualInfo),
-        CallAdded = 1,
+        !:NumAdded = !.NumAdded + 1,
 
         % Recursively extract until we run out of field names.
         TermInputArgNumber = 1 + list.length(FieldArgVars),
@@ -258,10 +256,9 @@
         SubContext = [TermInputContext | SubContext0],
         expand_get_field_function_call_2(Context, MainContext,
             SubContext, FieldNames, FieldValueVar, SubTermInputVar, Purity,
-            _, FieldSubContext, Goals1, ExtractAdded, !SVarState, !SVarStore,
+            _, FieldSubContext, Goals1, !NumAdded, !SVarState, !SVarStore,
             !VarSet, !ModuleInfo, !QualInfo, !Specs),
-        Goals2 = [Goal | Goals1],
-        FieldAdded = CallAdded + ExtractAdded
+        Goals2 = [Goal | Goals1]
     ;
         FieldNames = [],
         FieldSubContext = Functor - SubContext0,
@@ -269,15 +266,14 @@
             MainContext, SubContext0, FieldName, FieldValueVar,
             GetArgVars, Purity, Functor, Goal, !QualInfo),
         Goals2 = [Goal],
-        FieldAdded = 1
+        !:NumAdded = !.NumAdded + 1
     ),
     ArgContext = ac_functor(Functor, MainContext, SubContext0),
     goal_info_init(Context, GoalInfo),
     conj_list_to_goal(Goals2, GoalInfo, Conj0),
     insert_arg_unifications(FieldArgVars, FieldArgs, Context, ArgContext,
-        Conj0, Conj, ArgAdded, !SVarState, !SVarStore, !VarSet,
+        Conj0, Conj, !NumAdded, !SVarState, !SVarStore, !VarSet,
         !ModuleInfo, !QualInfo, !Specs),
-    NumAdded = FieldAdded + ArgAdded,
     svar_goal_to_conj_list(Conj, Goals, !SVarStore).
 
 :- pred construct_field_access_function_call(field_access_type::in,
Index: compiler/goal_expr_to_goal.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/goal_expr_to_goal.m,v
retrieving revision 1.3
diff -u -b -r1.3 goal_expr_to_goal.m
--- compiler/goal_expr_to_goal.m	13 Feb 2012 00:11:38 -0000	1.3
+++ compiler/goal_expr_to_goal.m	23 Mar 2012 03:01:29 -0000
@@ -13,6 +13,7 @@
 :- import_module hlds.hlds_module.
 :- import_module hlds.make_hlds.qual_info.
 :- import_module hlds.make_hlds.state_var.
+:- import_module hlds.make_hlds.superhomogeneous.
 :- import_module parse_tree.error_util.
 :- import_module parse_tree.prog_data.
 
@@ -35,7 +36,7 @@
     % - expand references to state variables.
     %
 :- pred transform_goal_expr_context_to_goal(loc_kind::in, goal::in,
-    prog_var_renaming::in, hlds_goal::out, int::out,
+    prog_var_renaming::in, hlds_goal::out, num_added_goals::out,
     svar_state::in, svar_state::out, svar_store::in, svar_store::out,
     prog_varset::in, prog_varset::out,
     module_info::in, module_info::out, qual_info::in, qual_info::out,
@@ -62,7 +63,6 @@
 :- import_module hlds.make_hlds.add_pred.
 :- import_module hlds.make_hlds.field_access.
 :- import_module hlds.make_hlds.make_hlds_warn.
-:- import_module hlds.make_hlds.superhomogeneous.
 :- import_module hlds.pred_table.
 :- import_module hlds.quantification.
 :- import_module libs.globals.
@@ -261,7 +261,7 @@
         MainDisjState =
             hlds_goal_svar_state(HLDSMainGoal0, AfterMainSVarState),
         transform_orelse_goals(LocKind, OrElseExprs, Renaming, OrElseDisjStates,
-            0, OrElseNumAdded, BeforeDisjSVarState, !SVarStore, !VarSet,
+            !NumAdded, BeforeDisjSVarState, !SVarStore, !VarSet,
             !ModuleInfo, !QualInfo, !Specs),
         AllDisjStates = [MainDisjState | OrElseDisjStates],
         svar_finish_disjunction(Context, AllDisjStates, HLDSGoals, !VarSet,
@@ -295,7 +295,7 @@
         ;
             MaybeOuterScopeInfo = no
         ),
-        !:NumAdded = !.NumAdded + 1 + OrElseNumAdded,
+        !:NumAdded = !.NumAdded + 1,
         ShortHand = atomic_goal(unknown_atomic_goal_type, Outer, Inner,
             MaybeOutputVars, HLDSMainGoal, HLDSOrElseGoals, []),
         GoalExpr = shorthand(ShortHand),
@@ -489,7 +489,7 @@
         Goal0 = hlds_goal(GoalExpr0, GoalInfo),
         CallId = generic_call_id(gcid_event_call(EventName)),
         insert_arg_unifications(HeadVars, Args, Context, ac_call(CallId),
-            Goal0, Goal, !:NumAdded, !SVarState, !SVarStore, !VarSet,
+            Goal0, Goal, 0, !:NumAdded, !SVarState, !SVarStore, !VarSet,
             !ModuleInfo, !QualInfo, !Specs),
         svar_finish_atomic_goal(LocKind, !SVarState)
     ;
@@ -578,7 +578,7 @@
 
             record_called_pred_or_func(pf_predicate, Name, Arity, !QualInfo),
             insert_arg_unifications(HeadVars, Args, Context, ac_call(CallId),
-                Goal0, Goal, !:NumAdded, !SVarState, !SVarStore, !VarSet,
+                Goal0, Goal, 0, !:NumAdded, !SVarState, !SVarStore, !VarSet,
                 !ModuleInfo, !QualInfo, !Specs)
         ),
         svar_finish_atomic_goal(LocKind, !SVarState)
@@ -598,7 +598,7 @@
             !:NumAdded = 0
         ;
             unravel_unification(A, B, Context, umc_explicit, [], Purity, Goal,
-                !:NumAdded, !SVarState, !SVarStore, !VarSet,
+                0, !:NumAdded, !SVarState, !SVarStore, !VarSet,
                 !ModuleInfo, !QualInfo, !Specs),
             svar_finish_atomic_goal(LocKind, !SVarState)
         )
@@ -758,7 +758,7 @@
             expand_set_field_function_call(Context, umc_explicit, [],
                 FieldNames, FieldValueVar, TermInputVar, TermOutputVar,
                 Functor, InnermostFunctor - InnermostSubContext, Goal0,
-                SetAdded, !SVarState, !SVarStore, !VarSet,
+                0, NumAdded1, !SVarState, !SVarStore, !VarSet,
                 !ModuleInfo, !QualInfo, !Specs),
 
             FieldArgNumber = 2,
@@ -784,16 +784,15 @@
                 OutputTermArgNumber - OutputTermArgContext
             ],
             insert_arg_unifications_with_supplied_contexts(ArgVars, ArgTerms,
-                ArgContexts, Context, Goal0, Goal, ArgAdded,
+                ArgContexts, Context, Goal0, Goal, NumAdded1, NumAdded,
                 !SVarState, !SVarStore, !VarSet,
-                !ModuleInfo, !QualInfo, !Specs),
-            NumAdded = SetAdded + ArgAdded
+                !ModuleInfo, !QualInfo, !Specs)
         ;
             AccessType = get,
             expand_dcg_field_extraction_goal(Context, umc_explicit, [],
                 FieldNames, FieldValueVar, TermInputVar, TermOutputVar,
                 Functor, InnermostFunctor - _InnerSubContext, Goal0,
-                ExtractAdded, !SVarState, !SVarStore, !VarSet,
+                0, NumAdded1, !SVarState, !SVarStore, !VarSet,
                 !ModuleInfo, !QualInfo, !Specs),
             InputTermArgNumber = 1,
             InputTermArgContext = ac_functor(Functor, umc_explicit, []),
@@ -818,10 +817,9 @@
                 OutputTermArgNumber - OutputTermArgContext
             ],
             insert_arg_unifications_with_supplied_contexts(ArgVars, ArgTerms,
-                ArgContexts, Context, Goal0, Goal, ArgAdded,
+                ArgContexts, Context, Goal0, Goal, NumAdded1, NumAdded,
                 !SVarState, !SVarStore, !VarSet,
-                !ModuleInfo, !QualInfo, !Specs),
-            NumAdded = ExtractAdded + ArgAdded
+                !ModuleInfo, !QualInfo, !Specs)
         )
     ;
         unexpected($module, $pred, "arity != 3")
Index: compiler/mlds_to_il.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/mlds_to_il.m,v
retrieving revision 1.226
diff -u -b -r1.226 mlds_to_il.m
--- compiler/mlds_to_il.m	6 Sep 2011 05:20:43 -0000	1.226
+++ compiler/mlds_to_il.m	9 Mar 2012 07:47:11 -0000
@@ -606,7 +606,7 @@
         rename_field_id(FieldName), FieldType, PtrType).
 rename_lval(ml_mem_ref(Rval, Type)) = ml_mem_ref(rename_rval(Rval), Type).
 rename_lval(ml_global_var_ref(Ref)) = ml_global_var_ref(Ref).
-rename_lval(ml_var(Var, Type)) = ml_var(rename_var(Var, Type), Type).
+rename_lval(ml_var(Var, Type)) = ml_var(rename_mlds_var(Var, Type), Type).
 
 :- func rename_field_id(mlds_field_id) = mlds_field_id.
 
@@ -638,9 +638,9 @@
 
     % Again append a wrapper class qualifier to the var name.
     %
-:- func rename_var(mlds_var, mlds_type) = mlds_var.
+:- func rename_mlds_var(mlds_var, mlds_type) = mlds_var.
 
-rename_var(qual(ModuleName, _QualKind, Name), _Type)
+rename_mlds_var(qual(ModuleName, _QualKind, Name), _Type)
     = qual(mlds_append_wrapper_class(ModuleName), type_qual, Name).
 
 %-----------------------------------------------------------------------------%
Index: compiler/modecheck_conj.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/modecheck_conj.m,v
retrieving revision 1.8
diff -u -b -r1.8 modecheck_conj.m
--- compiler/modecheck_conj.m	13 Feb 2012 00:11:43 -0000	1.8
+++ compiler/modecheck_conj.m	23 Mar 2012 06:43:44 -0000
@@ -152,21 +152,11 @@
         modecheck_conj_list_flatten_and_schedule(ConjType, Goals1, Goals,
             !ImpurityErrors, !ModeInfo)
     ;
-        modecheck_conj_list_schedule(ConjType, Goal0, Goals0, Goals,
-            !ImpurityErrors, !ModeInfo)
-    ).
+        % We attempt to schedule the first goal in the conjunction.
+        % If successful, we try to wake up pending goals (if any), and if not,
+        % we delay the goal. Then we continue attempting to schedule
+        % all the rest of the conjuncts.
 
-    % We attempt to schedule the first goal in the conjunction. If successful,
-    % we try to wake up pending goals (if any), and if not, we delay the goal.
-    % Then we continue attempting to schedule all the rest of the conjuncts.
-    %
-:- pred modecheck_conj_list_schedule(conj_type::in, hlds_goal::in,
-    list(hlds_goal)::in, list(hlds_goal)::out,
-    impurity_errors::in, impurity_errors::out,
-    mode_info::in, mode_info::out) is det.
-
-modecheck_conj_list_schedule(ConjType, Goal0, Goals0, Goals, !ImpurityErrors,
-        !ModeInfo) :-
     Purity = goal_get_purity(Goal0),
     (
         Purity = purity_impure,
@@ -191,16 +181,17 @@
     mode_info_remove_live_vars(NonLocalVars, !ModeInfo),
     modecheck_goal(Goal0, Goal, !ModeInfo),
 
-    % Now see whether the goal was successfully scheduled. If we didn't manage
-    % to schedule the goal, then we restore the original instmap, delay_info
-    % and livevars here, and delay the goal.
+        % Now see whether the goal was successfully scheduled. If we didn't
+        % manage to schedule the goal, then we restore the original instmap,
+        % delay_info and livevars here, and delay the goal.
     mode_info_get_errors(!.ModeInfo, Errors),
     (
         Errors = [FirstErrorInfo | _],
         mode_info_set_errors([], !ModeInfo),
         mode_info_set_instmap(InstMap0, !ModeInfo),
         mode_info_add_live_vars(NonLocalVars, !ModeInfo),
-        delay_info_delay_goal(FirstErrorInfo, Goal0, DelayInfo0, DelayInfo1),
+            delay_info_delay_goal(FirstErrorInfo, Goal0,
+                DelayInfo0, DelayInfo1),
         % Delaying an impure goal is an impurity error.
         (
             Impure = yes,
@@ -262,6 +253,7 @@
         ;
             Goals = ScheduledSolverGoals ++ [Goal | Goals2]
         )
+        )
     ).
 
     % We may still have some unscheduled goals. This may be because some
Index: compiler/modecheck_goal.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/modecheck_goal.m,v
retrieving revision 1.16
diff -u -b -r1.16 modecheck_goal.m
--- compiler/modecheck_goal.m	13 Feb 2012 00:11:43 -0000	1.16
+++ compiler/modecheck_goal.m	24 Mar 2012 11:48:13 -0000
@@ -150,6 +150,7 @@
 :- import_module pair.
 :- import_module require.
 :- import_module set.
+:- import_module std_util.
 :- import_module string.
 :- import_module term.
 :- import_module varset.
@@ -860,19 +861,8 @@
             mode_checkpoint(exit, "from_ground_term scope", !ModeInfo),
             (
                 MaybeKind1AndSubGoal1 = yes(Kind1 - SubGoal1),
-                (
-                    Kind1 = from_ground_term_initial,
-                    unexpected($module, $pred, "from_ground_term_initial")
-                ;
-                    Kind1 = from_ground_term_construct,
-                    Kind2 = from_ground_term_construct
-                ;
-                    Kind1 = from_ground_term_deconstruct,
-                    Kind2 = from_ground_term_deconstruct
-                ;
-                    Kind1 = from_ground_term_other,
-                    Kind2 = from_ground_term_other
-                ),
+                expect(negate(unify(Kind1, from_ground_term_initial)),
+                    $module, $pred, "from_ground_term_initial"),
                 mode_info_set_had_from_ground_term(had_from_ground_term_scope,
                     !ModeInfo),
 
@@ -880,20 +870,23 @@
                     MakeGroundTermsUnique),
                 (
                     MakeGroundTermsUnique = do_not_make_ground_terms_unique,
-                    UpdatedReason2 = from_ground_term(TermVar, Kind2),
-                    GoalExpr = scope(UpdatedReason2, SubGoal1)
+                    UpdatedReason1 = from_ground_term(TermVar, Kind1),
+                    GoalExpr = scope(UpdatedReason1, SubGoal1)
                 ;
                     MakeGroundTermsUnique = make_ground_terms_unique,
                     (
-                        Kind2 = from_ground_term_construct,
+                        Kind1 = from_ground_term_initial,
+                        unexpected($module, $pred, "from_ground_term_initial")
+                    ;
+                        Kind1 = from_ground_term_construct,
                         modecheck_goal_make_ground_term_unique(TermVar,
                             SubGoal1, GoalInfo0, GoalExpr, !ModeInfo)
                     ;
-                        ( Kind2 = from_ground_term_deconstruct
-                        ; Kind2 = from_ground_term_other
+                        ( Kind1 = from_ground_term_deconstruct
+                        ; Kind1 = from_ground_term_other
                         ),
-                        UpdatedReason2 = from_ground_term(TermVar, Kind2),
-                        GoalExpr = scope(UpdatedReason2, SubGoal1)
+                        UpdatedReason1 = from_ground_term(TermVar, Kind1),
+                        GoalExpr = scope(UpdatedReason1, SubGoal1)
                     )
                 )
             ;
@@ -1144,7 +1137,7 @@
             % UnifyTerm cannot succeed until *after* the argument
             % variables become ground.
             %
-            % Putting UnifyTerm after UnifyArgs here is much more efficient
+            % Putting UnifyTerm after UnifyArgs here is MUCH more efficient
             % than letting the usual more ordering algorithm delay it
             % repeatedly: it is linear instead of quadratic.
 
Index: compiler/modecheck_unify.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/modecheck_unify.m,v
retrieving revision 1.143
diff -u -b -r1.143 modecheck_unify.m
--- compiler/modecheck_unify.m	13 Feb 2012 00:11:43 -0000	1.143
+++ compiler/modecheck_unify.m	24 Mar 2012 09:10:58 -0000
@@ -248,7 +248,6 @@
 
 modecheck_unification_functor(X0, ConsId0, IsExistConstruction, ArgVars0,
         Unification0, UnifyContext, GoalInfo0, Goal, !ModeInfo) :-
-    mode_info_get_module_info(!.ModeInfo, ModuleInfo0),
     mode_info_get_var_types(!.ModeInfo, VarTypes0),
     map.lookup(VarTypes0, X0, TypeOfX),
 
@@ -262,18 +261,19 @@
     %       X = lambda [A1::in, A2::out] (list.append(Y, A1, A2))
     %
     % Normally this is done by polymorphism.process_unify_functor,
-    % but if we're re-modechecking goals after lambda.m has been run
+    % but if we are re-modechecking goals after lambda.m has been run
     % (e.g. for deforestation), then we may need to do it again here.
     % Note that any changes to this code here will probably need to be
     % duplicated there too.
 
     (
-        % Check if variable has a higher-order type.
+        % Check if the variable has a higher-order type.
         type_is_higher_order_details(TypeOfX, Purity, _, EvalMethod,
             PredArgTypes),
         ConsId0 = closure_cons(ShroudedPredProcId, _)
     ->
         % Convert the pred term to a lambda expression.
+        mode_info_get_module_info(!.ModeInfo, ModuleInfo0),
         mode_info_get_varset(!.ModeInfo, VarSet0),
         mode_info_get_context(!.ModeInfo, Context),
         proc(PredId, ProcId) = unshroud_pred_proc_id(ShroudedPredProcId),
@@ -287,7 +287,7 @@
         modecheck_unification(X0, Functor0, Unification0, UnifyContext,
             GoalInfo0, Goal, !ModeInfo)
     ;
-        % It's not a higher-order pred unification, so just call
+        % It is not a higher-order pred unification, so just call
         % modecheck_unify_functor to do the ordinary thing.
         modecheck_unify_functor(X0, TypeOfX, ConsId0,
             IsExistConstruction, ArgVars0, Unification0,
@@ -650,8 +650,8 @@
     (
         % The occur check: X = f(X) is considered a mode error unless X is
         % ground. (Actually it wouldn't be that hard to generate code for it
-        % - it always fails! - but it's most likely to be a programming error,
-        % so it's better to report it.)
+        % - it always fails! - but it is most likely to be a programming error,
+        % so it is better to report it.)
 
         list.member(X, ArgVars0),
         \+ inst_is_ground(ModuleInfo0, InstOfX)
@@ -724,24 +724,51 @@
             ArgVars0, ArgVars, ExtraGoals2, !ModeInfo),
         modecheck_set_var_inst(X, Inst, yes(InstOfY), !ModeInfo),
         UnifyArgInsts = list.map(func(I) = yes(I), InstOfXArgs),
+
+        % The call to bind_args below serves to update the insts of the
+        % argument variables on the right hand side of the unification,
+        % putting into them any information we can derive from the original
+        % inst of the variable on the left hand side.
+        %
+        % Unfortunately, the update can be very expensive. For example,
+        % for a ground list with N elements, there will be N variables
+        % bound to the cons cells of the list. Since the average size of the
+        % insts of these variables is on proportional to N/2, the task
+        % of recording all their insts is at least quadratic in N.
+        % In practice, it can  actually be worse, because of the way the code
+        % called by bind_args works. It keeps track of sets of insts seen
+        % so far, and checks new insts for membership of such sets.
+        % If the initial elements of a list are repeated, then the membership
+        % test can try to unify e.g. [a, a, a, a] with [], [a], [a, a]
+        % and [a, a, a]. This means that each step of the quadratic algorithm
+        % is itself quadratic, for an overall complexity of O(n^4).
+        %
+        % It is therefore crucial that we avoid calling bind_args if at all
+        % possible.
+        %
+        % There are two cases in which we definitely know we can avoid
+        % calling bind_args. First, if the variable on the left hand side, X,
+        % is originally free, then it cannot change the already recorded insts
+        % of the variables on the right hand side. Second, in from_ground_term
+        % scopes, the variables on the right hand sides of construct
+        % unifications are all local to the scope of the from_ground_term
+        % scope. We can avoid updating their insts because no part of the
+        % compiler will ever want to see their insts.
+        %
+        % We test for the first case first, because we expect it to be
+        % much more common.
+
+        ( inst_is_free(ModuleInfo0, InstOfX) ->
+            true
+        ;
         mode_info_get_in_from_ground_term(!.ModeInfo, InFromGroundTerm),
         (
             InFromGroundTerm = in_from_ground_term_scope
-            % In the goals that result from the transformation of a unification
-            % of a variable with a ground term, the variables on the right hand
-            % sides of the construct unifications are all local to the scope
-            % of the from_ground_term scope, and their last appearance is in
-            % the construct. Therefore there is no need to update their inst.
-            %
-            % Avoiding the update can be a significant performance win, because
-            % for a ground list with N elements, the size of the inst of the
-            % average intermediate variable is proportional to N. Since there
-            % are N intermediate variables, the complexity of updating their
-            % insts would be quadratic.
         ;
             InFromGroundTerm = not_in_from_ground_term_scope,
             bind_args(Inst, ArgVars, UnifyArgInsts, !ModeInfo)
         )
+        )
     ;
         set_of_var.list_to_set([X | ArgVars0], WaitingVars), % conservative
         ModeError = mode_error_unify_var_functor(X, InstConsId, ArgVars0,
Index: compiler/modecheck_util.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/modecheck_util.m,v
retrieving revision 1.8
diff -u -b -r1.8 modecheck_util.m
--- compiler/modecheck_util.m	16 Aug 2011 03:26:32 -0000	1.8
+++ compiler/modecheck_util.m	24 Mar 2012 11:47:20 -0000
@@ -606,8 +606,8 @@
         !ModeInfo) :-
     mode_info_get_instmap(!.ModeInfo, InstMap0),
     ( instmap_is_reachable(InstMap0) ->
-        % The new inst must be computed by unifying the
-        % old inst and the proc's final inst.
+        % The new inst must be computed by unifying the old inst
+        % and the proc's final inst.
         instmap_lookup_var(InstMap0, Var0, VarInst0),
         handle_implied_mode(Var0, VarInst0, InitialInst, Var, !ExtraGoals,
             !ModeInfo),
@@ -621,21 +621,29 @@
         Var = Var0
     ).
 
+modecheck_set_var_inst(Var0, NewInst, MaybeUInst, !ModeInfo) :-
     % Note that there are two versions of modecheck_set_var_inst,
     % one with arity 8 (suffixed with _call) and one with arity 5.
     % The former is used for predicate calls, where we may need
     % to introduce unifications to handle calls to implied modes.
     %
-modecheck_set_var_inst(Var0, FinalInst, MaybeUInst, !ModeInfo) :-
     mode_info_get_parallel_vars(!.ModeInfo, PVars0),
     mode_info_get_instmap(!.ModeInfo, InstMap0),
     ( instmap_is_reachable(InstMap0) ->
-        % The new inst must be computed by unifying the
-        % old inst and the proc's final inst.
-        instmap_lookup_var(InstMap0, Var0, Inst0),
+        instmap_lookup_var(InstMap0, Var0, OldInst),
         mode_info_get_module_info(!.ModeInfo, ModuleInfo0),
+        % The final new inst must be computed by unifying the old inst
+        % and the tentative new inst. However, unifying a large inst with
+        % itself can be VERY expensive; it can be worse than quadratic.
+        % The OldInst = NewInst here may incrase execution time slightly
+        % in normal cases, but should reduce it greatly in worst cases.
         (
-            abstractly_unify_inst(is_dead, Inst0, FinalInst,
+            OldInst = NewInst
+        ->
+            ModuleInfo = ModuleInfo0,
+            Inst = OldInst
+        ;
+            abstractly_unify_inst(is_dead, OldInst, NewInst,
                 fake_unify, UnifyInst, _Det, ModuleInfo0, ModuleInfo1)
         ->
             ModuleInfo = ModuleInfo1,
@@ -657,7 +665,7 @@
             % If we haven't added any information and
             % we haven't bound any part of the var, then
             % the only thing we can have done is lose uniqueness.
-            inst_matches_initial(Inst0, Inst, Type, ModuleInfo)
+            inst_matches_initial(OldInst, Inst, Type, ModuleInfo)
         ->
             instmap_set_var(Var0, Inst, InstMap0, InstMap),
             mode_info_set_instmap(InstMap, !ModeInfo)
@@ -666,7 +674,7 @@
             % lost some uniqueness, or bound part of the var.
             % The call to inst_matches_binding will succeed
             % only if we haven't bound any part of the var.
-            \+ inst_matches_binding(Inst, Inst0, Type, ModuleInfo),
+            \+ inst_matches_binding(Inst, OldInst, Type, ModuleInfo),
 
             % We've bound part of the var.  If the var was locked,
             % then we need to report an error...
@@ -681,12 +689,12 @@
                 MaybeUInst = yes(UInst),
                 inst_is_at_least_as_instantiated(Inst, UInst, Type,
                     ModuleInfo),
-                inst_matches_binding_allow_any_any(Inst, Inst0, Type,
+                inst_matches_binding_allow_any_any(Inst, OldInst, Type,
                     ModuleInfo)
             )
         ->
             WaitingVars = set_of_var.make_singleton(Var0),
-            ModeError = mode_error_bind_var(Reason0, Var0, Inst0, Inst),
+            ModeError = mode_error_bind_var(Reason0, Var0, OldInst, Inst),
             mode_info_error(WaitingVars, ModeError, !ModeInfo)
         ;
             instmap_set_var(Var0, Inst, InstMap0, InstMap),
Index: compiler/polymorphism.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/polymorphism.m,v
retrieving revision 1.374
diff -u -b -r1.374 polymorphism.m
--- compiler/polymorphism.m	13 Feb 2012 00:11:44 -0000	1.374
+++ compiler/polymorphism.m	24 Mar 2012 12:01:36 -0000
@@ -531,7 +531,13 @@
     module_info::in, module_info::out) is det.
 
 polymorphism_process_pred_msg(PredId, !ModuleInfo) :-
-    trace [io(!IO)] (
+    % Since polymorphism transforms not just the procedures defined
+    % in the module being compiled, but also all the procedures in
+    % all the imported modules, this message can be printed A LOT,
+    % even though it is almost never of interest.
+    % That is why we enable it only when requested.
+
+    trace [compiletime(flag("poly_msgs")), io(!IO)] (
         write_pred_progress_message("% Transforming polymorphism for ",
             PredId, !.ModuleInfo, !IO)
     ),
Index: compiler/prog_data.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/prog_data.m,v
retrieving revision 1.237
diff -u -b -r1.237 prog_data.m
--- compiler/prog_data.m	13 Feb 2012 00:11:45 -0000	1.237
+++ compiler/prog_data.m	9 Mar 2012 08:43:49 -0000
@@ -1422,7 +1422,37 @@
         Term = variable(Var, Context)
     ;
         Term0 = functor(ConsId, Args0, Context),
-        rename_vars_in_term_list(Must, Renaming, Args0, Args),
+        % The mutual non-tail recursion between rename_vars_in_term and
+        % rename_vars_in_term_list means that when given a large Term0,
+        % this predicate may need a LOT of stack frames, and may even run
+        % the program out of stack.
+        %
+        % To try to prevent this in as many cases as possible (though
+        % unfortunately not all), we handle the first three arguments
+        % directly. The most common kind of very large term is a very
+        % long list, and with this approach, we use only one stack frame
+        % per list element, not two.
+        (
+            Args0 = [],
+            Args = []
+        ;
+            Args0 = [Arg1Term0],
+            rename_vars_in_term(Must, Renaming, Arg1Term0, Arg1Term),
+            Args = [Arg1Term]
+        ;
+            Args0 = [Arg1Term0, Arg2Term0],
+            rename_vars_in_term(Must, Renaming, Arg1Term0, Arg1Term),
+            rename_vars_in_term(Must, Renaming, Arg2Term0, Arg2Term),
+            Args = [Arg1Term, Arg2Term]
+        ;
+            Args0 = [Arg1Term0, Arg2Term0, Arg3Term0 | OtherArgTerms0],
+            rename_vars_in_term(Must, Renaming, Arg1Term0, Arg1Term),
+            rename_vars_in_term(Must, Renaming, Arg2Term0, Arg2Term),
+            rename_vars_in_term(Must, Renaming, Arg3Term0, Arg3Term),
+            rename_vars_in_term_list(Must, Renaming,
+                OtherArgTerms0, OtherArgTerms),
+            Args = [Arg1Term, Arg2Term, Arg3Term | OtherArgTerms]
+        ),
         Term = functor(ConsId, Args, Context)
     ).
 
Index: compiler/purity.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/purity.m,v
retrieving revision 1.152
diff -u -b -r1.152 purity.m
--- compiler/purity.m	13 Feb 2012 00:11:46 -0000	1.152
+++ compiler/purity.m	23 Mar 2012 07:18:33 -0000
@@ -653,7 +653,8 @@
             Purity = PromisedPurity,
             Reason = Reason0
         ;
-            % We haven't yet classified from_ground_term scopes into
+            Reason0 = from_ground_term(TermVar, Kind0),
+            % We have not yet classified from_ground_term scopes into
             % from_ground_term_construct and other kinds, which is a pity,
             % since from_ground_term_construct scopes do not need purity
             % checking.
@@ -661,7 +662,6 @@
             % conjunctions of unifications, and we could take advantage of
             % that, e.g. by avoiding repeatedly taking the varset and vartypes
             % out of !Info and just as repeatedly putting it back again.
-            Reason0 = from_ground_term(TermVar, Kind0),
             !Info ^ pi_converted_unify := have_not_converted_unify,
             compute_goal_purity(SubGoal0, SubGoal, Purity, ContainsTrace,
                 !Info),
Index: compiler/saved_vars.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/saved_vars.m,v
retrieving revision 1.98
diff -u -b -r1.98 saved_vars.m
--- compiler/saved_vars.m	13 Feb 2012 00:11:48 -0000	1.98
+++ compiler/saved_vars.m	9 Mar 2012 07:46:36 -0000
@@ -377,7 +377,7 @@
     ( set_of_var.member(Goal0NonLocals, Var) ->
         (
             Goal0Expr = unify(_, _, _, _, _),
-            rename_var(Var, _NewVar, Subst, !SlotInfo),
+            saved_vars_rename_var(Var, _NewVar, Subst, !SlotInfo),
             rename_some_vars_in_goal(Subst, Construct, NewConstruct),
             rename_some_vars_in_goal(Subst, Goal0, Goal1),
             saved_vars_delay_goal(Goals0, Goals1, Construct, Var,
@@ -385,7 +385,7 @@
             Goals = [NewConstruct, Goal1 | Goals1]
         ;
             Goal0Expr = plain_call(_, _, _, _, _, _),
-            rename_var(Var, _NewVar, Subst, !SlotInfo),
+            saved_vars_rename_var(Var, _NewVar, Subst, !SlotInfo),
             rename_some_vars_in_goal(Subst, Construct, NewConstruct),
             rename_some_vars_in_goal(Subst, Goal0, Goal1),
             saved_vars_delay_goal(Goals0, Goals1, Construct, Var,
@@ -393,7 +393,7 @@
             Goals = [NewConstruct, Goal1 | Goals1]
         ;
             Goal0Expr = generic_call(_, _, _, _, _),
-            rename_var(Var, _NewVar, Subst, !SlotInfo),
+            saved_vars_rename_var(Var, _NewVar, Subst, !SlotInfo),
             rename_some_vars_in_goal(Subst, Construct, NewConstruct),
             rename_some_vars_in_goal(Subst, Goal0, Goal1),
             saved_vars_delay_goal(Goals0, Goals1, Construct, Var,
@@ -401,7 +401,7 @@
             Goals = [NewConstruct, Goal1 | Goals1]
         ;
             Goal0Expr = call_foreign_proc(_, _, _, _, _, _, _),
-            rename_var(Var, _NewVar, Subst, !SlotInfo),
+            saved_vars_rename_var(Var, _NewVar, Subst, !SlotInfo),
             rename_some_vars_in_goal(Subst, Construct, NewConstruct),
             rename_some_vars_in_goal(Subst, Goal0, Goal1),
             saved_vars_delay_goal(Goals0, Goals1, Construct, Var,
@@ -425,7 +425,7 @@
             )
         ;
             Goal0Expr = scope(Reason, SomeGoal0),
-            rename_var(Var, NewVar, Subst, !SlotInfo),
+            saved_vars_rename_var(Var, NewVar, Subst, !SlotInfo),
             rename_some_vars_in_goal(Subst, Construct, NewConstruct),
             rename_some_vars_in_goal(Subst, SomeGoal0, SomeGoal1),
             push_into_goal(SomeGoal1, SomeGoal, NewConstruct, NewVar,
@@ -436,7 +436,7 @@
             Goals = [Goal1 | Goals1]
         ;
             Goal0Expr = negation(NegGoal0),
-            rename_var(Var, NewVar, Subst, !SlotInfo),
+            saved_vars_rename_var(Var, NewVar, Subst, !SlotInfo),
             rename_some_vars_in_goal(Subst, Construct, NewConstruct),
             rename_some_vars_in_goal(Subst, NegGoal0, NegGoal1),
             push_into_goal(NegGoal1, NegGoal, NewConstruct, NewVar,
@@ -512,7 +512,7 @@
     Goal0 = hlds_goal(_, GoalInfo0),
     NonLocals = goal_info_get_nonlocals(GoalInfo0),
     ( set_of_var.member(NonLocals, Var) ->
-        rename_var(Var, NewVar, Subst, !SlotInfo),
+        saved_vars_rename_var(Var, NewVar, Subst, !SlotInfo),
         rename_some_vars_in_goal(Subst, Construct, NewConstruct),
         rename_some_vars_in_goal(Subst, Goal0, Goal1),
         push_into_goal(Goal1, Goal, NewConstruct, NewVar, !SlotInfo)
@@ -593,10 +593,10 @@
 final_slot_info(Varset, VarTypes, RttiVarMaps, SlotInfo) :-
     SlotInfo = slot_info(Varset, VarTypes, RttiVarMaps, _).
 
-:- pred rename_var(prog_var::in, prog_var::out, map(prog_var, prog_var)::out,
-    slot_info::in, slot_info::out) is det.
+:- pred saved_vars_rename_var(prog_var::in, prog_var::out,
+    map(prog_var, prog_var)::out, slot_info::in, slot_info::out) is det.
 
-rename_var(Var, NewVar, Substitution, !SlotInfo) :-
+saved_vars_rename_var(Var, NewVar, Substitution, !SlotInfo) :-
     !.SlotInfo = slot_info(Varset0, VarTypes0, RttiVarMaps0, TypeInfoLiveness),
     varset.new_var(NewVar, Varset0, Varset),
     map.from_assoc_list([Var - NewVar], Substitution),
Index: compiler/superhomogeneous.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/superhomogeneous.m,v
retrieving revision 1.48
diff -u -b -r1.48 superhomogeneous.m
--- compiler/superhomogeneous.m	31 Aug 2011 07:59:34 -0000	1.48
+++ compiler/superhomogeneous.m	24 Mar 2012 10:50:19 -0000
@@ -60,7 +60,7 @@
     %
 :- pred insert_arg_unifications(list(prog_var)::in, list(prog_term)::in,
     prog_context::in, arg_context::in, hlds_goal::in, hlds_goal::out,
-    num_added_goals::out,
+    num_added_goals::in, num_added_goals::out,
     svar_state::in, svar_state::out, svar_store::in, svar_store::out,
     prog_varset::in, prog_varset::out,
     module_info::in, module_info::out, qual_info::in, qual_info::out,
@@ -68,7 +68,8 @@
 
 :- pred insert_arg_unifications_with_supplied_contexts(list(prog_var)::in,
     list(prog_term)::in, assoc_list(int, arg_context)::in, prog_context::in,
-    hlds_goal::in, hlds_goal::out, num_added_goals::out,
+    hlds_goal::in, hlds_goal::out,
+    num_added_goals::in, num_added_goals::out,
     svar_state::in, svar_state::out, svar_store::in, svar_store::out,
     prog_varset::in, prog_varset::out, module_info::in, module_info::out,
     qual_info::in, qual_info::out,
@@ -80,7 +81,7 @@
     %
 :- pred append_arg_unifications(list(prog_var)::in, list(prog_term)::in,
     prog_context::in, arg_context::in, hlds_goal::in, hlds_goal::out,
-    num_added_goals::out,
+    num_added_goals::in, num_added_goals::out,
     svar_state::in, svar_state::out, svar_store::in, svar_store::out,
     prog_varset::in, prog_varset::out,
     module_info::in, module_info::out, qual_info::in, qual_info::out,
@@ -88,7 +89,7 @@
 
 :- pred unravel_unification(prog_term::in, prog_term::in, prog_context::in,
     unify_main_context::in, unify_sub_contexts::in, purity::in,
-    hlds_goal::out, num_added_goals::out,
+    hlds_goal::out, num_added_goals::in, num_added_goals::out,
     svar_state::in, svar_state::out, svar_store::in, svar_store::out,
     prog_varset::in, prog_varset::out,
     module_info::in, module_info::out, qual_info::in, qual_info::out,
@@ -146,60 +147,118 @@
 
 %-----------------------------------------------------------------------------%
 
-insert_arg_unifications(HeadVars, Args0, Context, ArgContext, !Goal, NumAdded,
+insert_arg_unifications(HeadVars, Args0, Context, ArgContext, !Goal, !NumAdded,
         !SVarState, !SVarStore, !VarSet, !ModuleInfo, !QualInfo, !Specs) :-
     do_insert_arg_unifications(HeadVars, Args0, Context, ArgContext, !Goal,
-        get_maybe_from_ground_term_threshold, NumAdded,
+        get_maybe_from_ground_term_threshold, !NumAdded,
         !SVarState, !SVarStore, !VarSet, !ModuleInfo, !QualInfo, !Specs).
 
 insert_arg_unifications_with_supplied_contexts(ArgVars, ArgTerms0,
-        ArgContexts, Context, !Goal, NumAdded, !SVarState, !SVarStore, !VarSet,
-        !ModuleInfo, !QualInfo, !Specs) :-
+        ArgContexts, Context, !Goal, !NumAdded, !SVarState, !SVarStore,
+        !VarSet, !ModuleInfo, !QualInfo, !Specs) :-
     do_insert_arg_unifications_with_supplied_contexts(ArgVars, ArgTerms0,
         ArgContexts, Context, !Goal,
-        get_maybe_from_ground_term_threshold, NumAdded,
+        get_maybe_from_ground_term_threshold, !NumAdded,
         !SVarState, !SVarStore, !VarSet, !ModuleInfo, !QualInfo, !Specs).
 
-append_arg_unifications(HeadVars, Args0, Context, ArgContext, !Goal, NumAdded,
+append_arg_unifications(HeadVars, Args0, Context, ArgContext, !Goal, !NumAdded,
         !SVarState, !SVarStore, !VarSet, !ModuleInfo, !QualInfo, !Specs) :-
     do_append_arg_unifications(HeadVars, Args0, Context, ArgContext, !Goal,
-        get_maybe_from_ground_term_threshold, NumAdded,
+        get_maybe_from_ground_term_threshold, !NumAdded,
         !SVarState, !SVarStore, !VarSet, !ModuleInfo, !QualInfo, !Specs).
 
 unravel_unification(LHS0, RHS0, Context, MainContext, SubContext, Purity,
-        Goal, NumAdded, !SVarState, !SVarStore, !VarSet,
+        Goal, !NumAdded, !SVarState, !SVarStore, !VarSet,
         !ModuleInfo, !QualInfo, !Specs) :-
     do_unravel_unification(LHS0, RHS0, Context, MainContext, SubContext,
-        Purity, Goal, get_maybe_from_ground_term_threshold, NumAdded,
+        Purity, Goal, get_maybe_from_ground_term_threshold, !NumAdded,
         !SVarState, !SVarStore, !VarSet, !ModuleInfo, !QualInfo, !Specs).
 
 %-----------------------------------------------------------------------------%
 
 :- pred do_insert_arg_unifications(list(prog_var)::in, list(prog_term)::in,
     prog_context::in, arg_context::in,
-    hlds_goal::in, hlds_goal::out, maybe(int)::in, num_added_goals::out,
+    hlds_goal::in, hlds_goal::out, maybe(int)::in,
+    num_added_goals::in, num_added_goals::out,
     svar_state::in, svar_state::out, svar_store::in, svar_store::out,
     prog_varset::in, prog_varset::out, module_info::in, module_info::out,
     qual_info::in, qual_info::out,
     list(error_spec)::in, list(error_spec)::out) is det.
 
-do_insert_arg_unifications(HeadVars, Args0, Context, ArgContext,
-        !Goal, MaybeThreshold, NumAdded, !SVarState, !SVarStore, !VarSet,
+do_insert_arg_unifications(HeadVars, Args, Context, ArgContext,
+        !Goal, MaybeThreshold, !NumAdded, !SVarState, !SVarStore, !VarSet,
         !ModuleInfo, !QualInfo, !Specs) :-
     (
         HeadVars = [],
-        NumAdded = 0
+        expect(unify(Args, []), $module, $pred, "length mismatch 0")
     ;
-        HeadVars = [_ | _],
+        HeadVars = [HeadVar1 | HeadVarsAfter1],
         !.Goal = hlds_goal(_, GoalInfo0),
-        svar_goal_to_conj_list(!.Goal, Goals0, !SVarStore),
-        substitute_state_var_mappings(Args0, Args, !VarSet, !SVarState,
-            !Specs),
-        do_insert_arg_unifications_loop(HeadVars, Args, Context, ArgContext,
-            1, Goals0, Goals, MaybeThreshold, 0, NumAdded,
-            !SVarState, !SVarStore, !VarSet, !ModuleInfo, !QualInfo, !Specs),
         goal_info_set_context(Context, GoalInfo0, GoalInfo),
+        svar_goal_to_conj_list(!.Goal, Goals0, !SVarStore),
+
+        (
+            Args = [],
+            unexpected($module, $pred, "length mismatch 0")
+        ;
+            Args = [Arg1 | ArgsAfter1],
+            do_arg_unification(HeadVar1, Arg1, Context, ArgContext,
+                1, ArgUnifyConj1, MaybeThreshold, !NumAdded,
+                !SVarState, !SVarStore, !VarSet,
+                !ModuleInfo, !QualInfo, !Specs),
+
+            (
+                HeadVarsAfter1 = [],
+                ArgsAfter1 = [],
+                Goals = ArgUnifyConj1 ++ Goals0,
+                conj_list_to_goal(Goals, GoalInfo, !:Goal)
+            ;
+                HeadVarsAfter1 = [],
+                ArgsAfter1 = [_ | _],
+                unexpected($module, $pred, "length mismatch 1")
+            ;
+                HeadVarsAfter1 = [_ | _],
+                ArgsAfter1 = [],
+                unexpected($module, $pred, "length mismatch 1")
+            ;
+                HeadVarsAfter1 = [HeadVar2 | HeadVarsAfter2],
+                ArgsAfter1 = [Arg2 | ArgsAfter2],
+                do_arg_unification(HeadVar2, Arg2, Context, ArgContext,
+                    2, ArgUnifyConj2, MaybeThreshold,
+                    !NumAdded, !SVarState, !SVarStore,
+                    !VarSet, !ModuleInfo, !QualInfo, !Specs),
+
+                (
+                    HeadVarsAfter2 = [],
+                    ArgsAfter2 = [],
+                    Goals = ArgUnifyConj1 ++ ArgUnifyConj2 ++ Goals0,
+                    conj_list_to_goal(Goals, GoalInfo, !:Goal)
+                ;
+                    HeadVarsAfter2 = [],
+                    ArgsAfter2 = [_ | _],
+                    unexpected($module, $pred, "length mismatch 2")
+                ;
+                    HeadVarsAfter2 = [_ | _],
+                    ArgsAfter2 = [],
+                    unexpected($module, $pred, "length mismatch 2")
+                ;
+                    HeadVarsAfter2 = [HeadVar3 | HeadVarsAfter3],
+                    ArgsAfter2 = [Arg3 | ArgsAfter3],
+                    do_arg_unification(HeadVar3, Arg3, Context, ArgContext,
+                        3, ArgUnifyConj3, MaybeThreshold,
+                        !NumAdded, !SVarState, !SVarStore,
+                        !VarSet, !ModuleInfo, !QualInfo, !Specs),
+
+                    do_insert_arg_unifications_loop(HeadVarsAfter3, ArgsAfter3,
+                        Context, ArgContext, 4, Goals0, Goals4,
+                        MaybeThreshold, !NumAdded, !SVarState, !SVarStore,
+                        !VarSet, !ModuleInfo, !QualInfo, !Specs),
+                    Goals = ArgUnifyConj1 ++ ArgUnifyConj2 ++ ArgUnifyConj3
+                        ++ Goals4,
         conj_list_to_goal(Goals, GoalInfo, !:Goal)
+                )
+            )
+        )
     ).
 
 :- pred do_insert_arg_unifications_loop(list(prog_var)::in,
@@ -222,23 +281,22 @@
 do_insert_arg_unifications_loop([], [], _, _, _, !Goals, _,
         !NumAdded, !SVarState, !SVarStore, !VarSet,
         !ModuleInfo, !QualInfo, !Specs).
-do_insert_arg_unifications_loop([Var | Vars], [Arg | Args],
+do_insert_arg_unifications_loop([HeadVar | HeadVars], [Arg | Args],
         Context, ArgContext, ArgNum, !Goals, MaybeThreshold,
         !NumAdded, !SVarState, !SVarStore, !VarSet,
         !ModuleInfo, !QualInfo, !Specs) :-
-    do_arg_unification(Var, Arg, Context, ArgContext, ArgNum, ArgUnifyConj,
-        MaybeThreshold, ArgAdded, !SVarState, !SVarStore, !VarSet,
+    do_arg_unification(HeadVar, Arg, Context, ArgContext, ArgNum, ArgUnifyConj,
+        MaybeThreshold, !NumAdded, !SVarState, !SVarStore, !VarSet,
         !ModuleInfo, !QualInfo, !Specs),
-    !:NumAdded = !.NumAdded + ArgAdded,
     (
         ArgUnifyConj = [],
         % Allow the recursive call to be tail recursive.
-        do_insert_arg_unifications_loop(Vars, Args, Context, ArgContext,
+        do_insert_arg_unifications_loop(HeadVars, Args, Context, ArgContext,
             ArgNum + 1, !Goals, MaybeThreshold, !NumAdded,
             !SVarState, !SVarStore, !VarSet, !ModuleInfo, !QualInfo, !Specs)
     ;
         ArgUnifyConj = [_ | _],
-        do_insert_arg_unifications_loop(Vars, Args, Context, ArgContext,
+        do_insert_arg_unifications_loop(HeadVars, Args, Context, ArgContext,
             ArgNum + 1, !Goals, MaybeThreshold, !NumAdded,
             !SVarState, !SVarStore, !VarSet, !ModuleInfo, !QualInfo, !Specs),
         !:Goals = ArgUnifyConj ++ !.Goals
@@ -246,27 +304,25 @@
 
 :- pred do_insert_arg_unifications_with_supplied_contexts(list(prog_var)::in,
     list(prog_term)::in, assoc_list(int, arg_context)::in, prog_context::in,
-    hlds_goal::in, hlds_goal::out, maybe(int)::in, num_added_goals::out,
+    hlds_goal::in, hlds_goal::out, maybe(int)::in,
+    num_added_goals::in, num_added_goals::out,
     svar_state::in, svar_state::out, svar_store::in, svar_store::out,
     prog_varset::in, prog_varset::out, module_info::in, module_info::out,
     qual_info::in, qual_info::out,
     list(error_spec)::in, list(error_spec)::out) is det.
 
-do_insert_arg_unifications_with_supplied_contexts(ArgVars, ArgTerms0,
-        ArgContexts, Context, !Goal, MaybeThreshold, NumAdded,
+do_insert_arg_unifications_with_supplied_contexts(ArgVars, ArgTerms,
+        ArgContexts, Context, !Goal, MaybeThreshold, !NumAdded,
         !SVarState, !SVarStore, !VarSet, !ModuleInfo, !QualInfo, !Specs) :-
     (
-        ArgVars = [],
-        NumAdded = 0
+        ArgVars = []
     ;
         ArgVars = [_ | _],
         !.Goal = hlds_goal(_, GoalInfo0),
         svar_goal_to_conj_list(!.Goal, Goals0, !SVarStore),
-        substitute_state_var_mappings(ArgTerms0, ArgTerms, !VarSet,
-            !SVarState, !Specs),
         do_insert_arg_unifications_with_supplied_contexts_loop(ArgVars,
             ArgTerms, ArgContexts, Context, Goals0, Goals,
-            MaybeThreshold, 0, NumAdded, !SVarState, !SVarStore, !VarSet,
+            MaybeThreshold, !NumAdded, !SVarState, !SVarStore, !VarSet,
             !ModuleInfo, !QualInfo, !Specs),
         goal_info_set_context(Context, GoalInfo0, GoalInfo),
         conj_list_to_goal(Goals, GoalInfo, !:Goal)
@@ -296,9 +352,8 @@
         ArgContexts = [ArgNumber - ArgContext | ArgContextsTail]
     ->
         do_arg_unification(Var, Term, Context, ArgContext, ArgNumber,
-            ArgUnifyConj, MaybeThreshold, ArgAdded, !SVarState, !SVarStore,
+            ArgUnifyConj, MaybeThreshold, !NumAdded, !SVarState, !SVarStore,
             !VarSet, !ModuleInfo, !QualInfo, !Specs),
-        !:NumAdded = !.NumAdded + ArgAdded,
         do_insert_arg_unifications_with_supplied_contexts_loop(VarsTail,
             TermsTail, ArgContextsTail, Context, !Goals, MaybeThreshold,
             !NumAdded, !SVarState, !SVarStore,
@@ -310,28 +365,86 @@
 
 :- pred do_append_arg_unifications(list(prog_var)::in, list(prog_term)::in,
     prog_context::in, arg_context::in,
-    hlds_goal::in, hlds_goal::out, maybe(int)::in, num_added_goals::out,
+    hlds_goal::in, hlds_goal::out, maybe(int)::in,
+    num_added_goals::in, num_added_goals::out,
     svar_state::in, svar_state::out, svar_store::in, svar_store::out,
     prog_varset::in, prog_varset::out, module_info::in, module_info::out,
     qual_info::in, qual_info::out,
     list(error_spec)::in, list(error_spec)::out) is det.
 
-do_append_arg_unifications(HeadVars, Args0, Context, ArgContext, !Goal,
-        MaybeThreshold, NumAdded, !SVarState, !SVarStore, !VarSet,
+do_append_arg_unifications(HeadVars, Args, Context, ArgContext, !Goal,
+        MaybeThreshold, !NumAdded, !SVarState, !SVarStore, !VarSet,
         !ModuleInfo, !QualInfo, !Specs) :-
     (
         HeadVars = [],
-        NumAdded = 0
+        expect(unify(Args, []), $module, $pred, "length mismatch 0")
     ;
-        HeadVars = [_ | _],
-        !.Goal = hlds_goal(_, GoalInfo),
+        HeadVars = [HeadVar1 | HeadVarsAfter1],
+        !.Goal = hlds_goal(_, GoalInfo0),
+        goal_info_set_context(Context, GoalInfo0, GoalInfo),
         svar_goal_to_conj_list(!.Goal, Goals0, !SVarStore),
-        substitute_state_var_mappings(Args0, Args, !VarSet, !SVarState,
-            !Specs),
-        do_append_arg_unifications_loop(HeadVars, Args, Context, ArgContext,
-            1, Goals0, Goals, MaybeThreshold, 0, NumAdded,
-            !SVarState, !SVarStore, !VarSet, !ModuleInfo, !QualInfo, !Specs),
+
+        (
+            Args = [],
+            unexpected($module, $pred, "length mismatch 0")
+        ;
+            Args = [Arg1 | ArgsAfter1],
+            do_arg_unification(HeadVar1, Arg1, Context, ArgContext,
+                1, ArgUnifyConj1, MaybeThreshold,
+                !NumAdded, !SVarState, !SVarStore,
+                !VarSet, !ModuleInfo, !QualInfo, !Specs),
+            Goals1 = Goals0 ++ ArgUnifyConj1,
+
+            (
+                HeadVarsAfter1 = [],
+                ArgsAfter1 = [],
+                conj_list_to_goal(Goals1, GoalInfo, !:Goal)
+            ;
+                HeadVarsAfter1 = [],
+                ArgsAfter1 = [_ | _],
+                unexpected($module, $pred, "length mismatch 1")
+            ;
+                HeadVarsAfter1 = [_ | _],
+                ArgsAfter1 = [],
+                unexpected($module, $pred, "length mismatch 1")
+            ;
+                HeadVarsAfter1 = [HeadVar2 | HeadVarsAfter2],
+                ArgsAfter1 = [Arg2 | ArgsAfter2],
+                do_arg_unification(HeadVar2, Arg2, Context, ArgContext,
+                    2, ArgUnifyConj2, MaybeThreshold,
+                    !NumAdded, !SVarState, !SVarStore,
+                    !VarSet, !ModuleInfo, !QualInfo, !Specs),
+                Goals2 = Goals1 ++ ArgUnifyConj2,
+
+                (
+                    HeadVarsAfter2 = [],
+                    ArgsAfter2 = [],
+                    conj_list_to_goal(Goals2, GoalInfo, !:Goal)
+                ;
+                    HeadVarsAfter2 = [],
+                    ArgsAfter2 = [_ | _],
+                    unexpected($module, $pred, "length mismatch 2")
+                ;
+                    HeadVarsAfter2 = [_ | _],
+                    ArgsAfter2 = [],
+                    unexpected($module, $pred, "length mismatch 2")
+                ;
+                    HeadVarsAfter2 = [HeadVar3 | HeadVarsAfter3],
+                    ArgsAfter2 = [Arg3 | ArgsAfter3],
+                    do_arg_unification(HeadVar3, Arg3, Context, ArgContext,
+                        3, ArgUnifyConj3, MaybeThreshold,
+                        !NumAdded, !SVarState, !SVarStore,
+                        !VarSet, !ModuleInfo, !QualInfo, !Specs),
+                    Goals3 = Goals2 ++ ArgUnifyConj3,
+
+                    do_append_arg_unifications_loop(HeadVarsAfter3, ArgsAfter3,
+                        Context, ArgContext, 4, Goals3, Goals,
+                        MaybeThreshold, !NumAdded, !SVarState, !SVarStore,
+                        !VarSet, !ModuleInfo, !QualInfo, !Specs),
         conj_list_to_goal(Goals, GoalInfo, !:Goal)
+                )
+            )
+        )
     ).
 
 :- pred do_append_arg_unifications_loop(list(prog_var)::in, list(prog_term)::in,
@@ -351,66 +464,67 @@
     unexpected($module, $pred, "length mismatch").
 do_append_arg_unifications_loop([], [], _, _, _, !GoalList, _, !NumAdded,
         !SVarState, !SVarStore, !VarSet, !ModuleInfo, !QualInfo, !Specs).
-do_append_arg_unifications_loop([Var | Vars], [Arg | Args],
+do_append_arg_unifications_loop([HeadVar | HeadVars], [Arg | Args],
         Context, ArgContext, ArgNum, !GoalList, MaybeThreshold, !NumAdded,
         !SVarState, !SVarStore, !VarSet, !ModuleInfo, !QualInfo, !Specs) :-
-    do_arg_unification(Var, Arg, Context, ArgContext, ArgNum, ArgUnifyConj,
-        MaybeThreshold, ArgAdded, !SVarState, !SVarStore, !VarSet,
+    do_arg_unification(HeadVar, Arg, Context, ArgContext, ArgNum, ArgUnifyConj,
+        MaybeThreshold, !NumAdded, !SVarState, !SVarStore, !VarSet,
         !ModuleInfo, !QualInfo, !Specs),
-    !:NumAdded = !.NumAdded + ArgAdded,
     !:GoalList = !.GoalList ++ ArgUnifyConj,
-    do_append_arg_unifications_loop(Vars, Args, Context, ArgContext,
+    do_append_arg_unifications_loop(HeadVars, Args, Context, ArgContext,
         ArgNum + 1, !GoalList, MaybeThreshold, !NumAdded,
         !SVarState, !SVarStore, !VarSet, !ModuleInfo, !QualInfo, !Specs).
 
 :- pred do_arg_unification(prog_var::in, prog_term::in,
     prog_context::in, arg_context::in, int::in, list(hlds_goal)::out,
-    maybe(int)::in, num_added_goals::out,
+    maybe(int)::in, num_added_goals::in, num_added_goals::out,
     svar_state::in, svar_state::out, svar_store::in, svar_store::out,
     prog_varset::in, prog_varset::out, module_info::in, module_info::out,
     qual_info::in, qual_info::out,
     list(error_spec)::in, list(error_spec)::out) is det.
 
-do_arg_unification(Var, Arg, Context, ArgContext, ArgNum, ArgUnifyConj,
-        MaybeThreshold, NumAdded, !SVarState, !SVarStore, !VarSet,
+do_arg_unification(Var, Arg0, Context, ArgContext, ArgNum, ArgUnifyConj,
+        MaybeThreshold, !NumAdded, !SVarState, !SVarStore, !VarSet,
         !ModuleInfo, !QualInfo, !Specs) :-
+    substitute_state_var_mapping(Arg0, Arg, !VarSet, !SVarState, !Specs),
     ( Arg = term.variable(Var, _) ->
         % Skip unifications of the form `X = X'.
-        ArgUnifyConj = [],
-        NumAdded = 0
+        ArgUnifyConj = []
     ;
         arg_context_to_unify_context(ArgContext, ArgNum, UnifyMainContext,
             UnifySubContext),
         do_unravel_unification(term.variable(Var, Context), Arg, Context,
             UnifyMainContext, UnifySubContext, purity_pure, Goal,
-            MaybeThreshold, NumAdded, !SVarState, !SVarStore, !VarSet,
+            MaybeThreshold, !NumAdded, !SVarState, !SVarStore, !VarSet,
             !ModuleInfo, !QualInfo, !Specs),
-        svar_goal_to_conj_list(Goal, ArgUnifyConj, !SVarStore)
+        goal_to_conj_list(Goal, ArgUnifyConj)
     ).
 
 %-----------------------------------------------------------------------------%
 
 :- pred do_unravel_unification(prog_term::in, prog_term::in, prog_context::in,
     unify_main_context::in, unify_sub_contexts::in, purity::in,
-    hlds_goal::out, maybe(int)::in, num_added_goals::out,
+    hlds_goal::out, maybe(int)::in, num_added_goals::in, num_added_goals::out,
     svar_state::in, svar_state::out, svar_store::in, svar_store::out,
     prog_varset::in, prog_varset::out, module_info::in, module_info::out,
     qual_info::in, qual_info::out,
     list(error_spec)::in, list(error_spec)::out) is det.
 
 do_unravel_unification(LHS0, RHS0, Context, MainContext, SubContext, Purity,
-        Goal, MaybeThreshold, NumAdded, !SVarState, !SVarStore, !VarSet,
+        Goal, MaybeThreshold, !NumAdded, !SVarState, !SVarStore, !VarSet,
         !ModuleInfo, !QualInfo, !Specs) :-
+    % ZZZ
     substitute_state_var_mapping(LHS0, LHS, !VarSet, !SVarState, !Specs),
     substitute_state_var_mapping(RHS0, RHS, !VarSet, !SVarState, !Specs),
     classify_unravel_unification(LHS, RHS, Context, MainContext, SubContext,
-        Purity, Goal0, NumAdded, !SVarState, !SVarStore, !VarSet,
+        Purity, Goal0, UnifyNumAdded, !SVarState, !SVarStore, !VarSet,
         !ModuleInfo, !QualInfo, !Specs),
+    !:NumAdded = !.NumAdded + UnifyNumAdded,
     (
         MaybeThreshold = yes(Threshold),
-        NumAdded > Threshold,
+        UnifyNumAdded > Threshold,
         LHS = term.variable(LHSVar, _),
-        ground_term(RHS)
+        term_is_ground(RHS)
     ->
         Goal0 = hlds_goal(GoalExpr0, GoalInfo0),
         Kind = from_ground_term_initial,
@@ -489,18 +603,20 @@
         TermX = term.functor(_, _, _),
         TermY = term.functor(_, _, _),
         varset.new_var(TmpVar, !VarSet),
+        NumAdded0 = 0,
         do_unravel_unification(term.variable(TmpVar, Context), TermX,
-            Context, MainContext, SubContext, Purity, GoalX, no, NumAddedX,
+            Context, MainContext, SubContext, Purity, GoalX, no,
+            NumAdded0, NumAdded1,
             !SVarState, !SVarStore, !VarSet, !ModuleInfo, !QualInfo, !Specs),
         do_unravel_unification(term.variable(TmpVar, Context), TermY,
-            Context, MainContext, SubContext, Purity, GoalY, no, NumAddedY,
+            Context, MainContext, SubContext, Purity, GoalY, no,
+            NumAdded1, NumAdded,
             !SVarState, !SVarStore, !VarSet, !ModuleInfo, !QualInfo, !Specs),
         svar_goal_to_conj_list(GoalX, ConjListX, !SVarStore),
         svar_goal_to_conj_list(GoalY, ConjListY, !SVarStore),
         ConjList = ConjListX ++ ConjListY,
         goal_info_init(GoalInfo),
-        conj_list_to_goal(ConjList, GoalInfo, Goal),
-        NumAdded = NumAddedX + NumAddedY
+        conj_list_to_goal(ConjList, GoalInfo, Goal)
     ).
 
     % Given an unification of the form
@@ -569,7 +685,7 @@
             MaybeParsedGoal = ok1(ParsedGoal),
             build_lambda_expression(X, Purity, LambdaPurity, Groundness,
                 PredOrFunc, EvalMethod, Vars1, Modes, Det, ParsedGoal,
-                Context, MainContext, SubContext, Goal, NumAdded,
+                Context, MainContext, SubContext, Goal, 0, NumAdded,
                 !.SVarState, !SVarStore, !VarSet,
                 !ModuleInfo, !QualInfo, !Specs)
         ;
@@ -621,7 +737,8 @@
             (
                 Purity = purity_pure,
                 do_append_arg_unifications(HeadVars, FunctorArgs,
-                    FunctorContext, ArgContext, Goal0, Goal, no, ArgAdded,
+                    FunctorContext, ArgContext, Goal0, Goal, no,
+                    MainFunctorAdded, NumAdded,
                     !SVarState, !SVarStore, !VarSet,
                     !ModuleInfo, !QualInfo, !Specs)
             ;
@@ -632,11 +749,11 @@
                 goal_info_set_purity(Purity, GoalInfo0, GoalInfo1),
                 Goal1 = hlds_goal(GoalExpr0, GoalInfo1),
                 do_insert_arg_unifications(HeadVars, FunctorArgs,
-                    FunctorContext, ArgContext, Goal1, Goal, no, ArgAdded,
+                    FunctorContext, ArgContext, Goal1, Goal, no,
+                    MainFunctorAdded, NumAdded,
                     !SVarState, !SVarStore, !VarSet,
                     !ModuleInfo, !QualInfo, !Specs)
-            ),
-            NumAdded = MainFunctorAdded + ArgAdded
+            )
         )
     ).
 
@@ -688,7 +805,7 @@
             ),
             do_unravel_unification(term.variable(X, Context), RVal,
                 Context, MainContext, SubContext, Purity, Goal, no,
-                NumAdded, !SVarState, !SVarStore, !VarSet,
+                0, NumAdded, !SVarState, !SVarStore, !VarSet,
                 !ModuleInfo, !QualInfo, !Specs)
         )
     ;
@@ -698,14 +815,13 @@
 
         require_det (
             do_unravel_unification(term.variable(X, Context), LVal, Context,
-                MainContext, SubContext, Purity, GoalL, no, NumAddedL,
-                !SVarState, !SVarStore, !VarSet,
+                MainContext, SubContext, Purity, GoalL, no,
+                0, NumAdded1, !SVarState, !SVarStore, !VarSet,
                 !ModuleInfo, !QualInfo, !Specs),
             do_unravel_unification(term.variable(X, Context), RVal, Context,
-                MainContext, SubContext, Purity, GoalR, no, NumAddedR,
-                !SVarState, !SVarStore, !VarSet,
+                MainContext, SubContext, Purity, GoalR, no,
+                NumAdded1, NumAdded, !SVarState, !SVarStore, !VarSet,
                 !ModuleInfo, !QualInfo, !Specs),
-            NumAdded = NumAddedL + NumAddedR,
             goal_info_init(GoalInfo),
             svar_goal_to_conj_list(GoalL, ConjListL, !SVarStore),
             svar_goal_to_conj_list(GoalR, ConjListR, !SVarStore),
@@ -737,14 +853,15 @@
                 svar_prepare_for_local_state_vars(Context, !.VarSet, StateVars,
                     BeforeSVarState, BeforeInsideSVarState, !Specs),
                 map.init(EmptySubst),
+                some [!NumAdded] (
                 transform_goal_expr_context_to_goal(loc_inside_atomic_goal,
-                    CondParseTree, EmptySubst, CondGoal, CondAdded,
+                        CondParseTree, EmptySubst, CondGoal, !:NumAdded,
                     BeforeInsideSVarState, AfterCondInsideSVarState,
                     !SVarStore, !VarSet, !ModuleInfo, !QualInfo, !Specs),
 
                 do_unravel_unification(term.variable(X, Context), ThenTerm,
-                    Context, MainContext, SubContext, Purity, ThenGoal0, no,
-                    ThenAdded,
+                        Context, MainContext, SubContext, Purity, ThenGoal0,
+                        no, !NumAdded,
                     AfterCondInsideSVarState, AfterThenInsideSVarState,
                     !SVarStore, !VarSet, !ModuleInfo, !QualInfo, !Specs),
 
@@ -752,27 +869,28 @@
                     AfterThenInsideSVarState, AfterThenSVarState),
 
                 do_unravel_unification(term.variable(X, Context), ElseTerm,
-                    Context, MainContext, SubContext, Purity, ElseGoal0, no,
-                    ElseAdded, BeforeSVarState, AfterElseSVarState,
+                        Context, MainContext, SubContext, Purity, ElseGoal0,
+                        no, !NumAdded, BeforeSVarState, AfterElseSVarState,
                     !SVarStore, !VarSet, !ModuleInfo, !QualInfo, !Specs),
 
                 svar_finish_if_then_else(loc_inside_atomic_goal, Context,
                     StateVars, ThenGoal0, ThenGoal, ElseGoal0, ElseGoal,
                     BeforeSVarState, AfterCondInsideSVarState,
-                    AfterThenSVarState, AfterElseSVarState, AfterITESVarState,
-                    !VarSet, !SVarStore, !Specs),
+                        AfterThenSVarState, AfterElseSVarState,
+                        AfterITESVarState, !VarSet, !SVarStore, !Specs),
                 !:SVarState = AfterITESVarState,
 
-                NumAdded = CondAdded + ThenAdded + ElseAdded,
                 GoalExpr = if_then_else(StateVars ++ Vars,
                     CondGoal, ThenGoal, ElseGoal),
                 goal_info_init(Context, GoalInfo),
-                Goal = hlds_goal(GoalExpr, GoalInfo)
+                    Goal = hlds_goal(GoalExpr, GoalInfo),
+                    NumAdded = !.NumAdded
+                )
             ;
                 MaybeVarsCond = error3(VarsCondSpecs),
                 !:Specs = VarsCondSpecs ++ !.Specs,
-                NumAdded = 0,
-                Goal = true_goal
+                Goal = true_goal,
+                NumAdded = 0
             )
         )
     ;
@@ -785,16 +903,15 @@
             make_fresh_arg_var(InputTerm, InputTermVar, [],
                 !VarSet, !SVarState, !Specs),
             expand_get_field_function_call(Context, MainContext, SubContext,
-                FieldNames, X, InputTermVar, Purity, Functor, _,
-                Goal0, CallAdded, !SVarState, !SVarStore, !VarSet,
+                FieldNames, X, InputTermVar, Purity, Functor, _, Goal0,
+                0, NumAdded1, !SVarState, !SVarStore, !VarSet,
                 !ModuleInfo, !QualInfo, !Specs),
 
             ArgContext = ac_functor(Functor, MainContext, SubContext),
             do_insert_arg_unifications([InputTermVar], [InputTerm],
-                FunctorContext, ArgContext, Goal0, Goal, no, ArgAdded,
-                !SVarState, !SVarStore, !VarSet,
-                !ModuleInfo, !QualInfo, !Specs),
-            NumAdded = CallAdded + ArgAdded
+                FunctorContext, ArgContext, Goal0, Goal, no,
+                NumAdded1, NumAdded, !SVarState, !SVarStore, !VarSet,
+                !ModuleInfo, !QualInfo, !Specs)
         )
     ;
         % Handle field update expressions.
@@ -812,8 +929,8 @@
 
             expand_set_field_function_call(Context, MainContext, SubContext,
                 FieldNames, FieldValueVar, InputTermVar, X,
-                Functor, InnerFunctor - FieldSubContext, Goal0, CallAdded,
-                !SVarState, !SVarStore, !VarSet,
+                Functor, InnerFunctor - FieldSubContext, Goal0,
+                0, NumAdded1, !SVarState, !SVarStore, !VarSet,
                 !ModuleInfo, !QualInfo, !Specs),
 
             TermArgContext = ac_functor(Functor, MainContext, SubContext),
@@ -825,10 +942,9 @@
                 FieldArgNumber - FieldArgContext],
             do_insert_arg_unifications_with_supplied_contexts(
                 [InputTermVar, FieldValueVar], [InputTerm, FieldValueTerm],
-                ArgContexts, Context, Goal0, Goal, no, ArgAdded,
-                !SVarState, !SVarStore, !VarSet,
-                !ModuleInfo, !QualInfo, !Specs),
-            NumAdded = CallAdded + ArgAdded
+                ArgContexts, Context, Goal0, Goal, no,
+                NumAdded1, NumAdded, !SVarState, !SVarStore, !VarSet,
+                !ModuleInfo, !QualInfo, !Specs)
         )
     ;
         % Handle higher-order dcg pred expressions. They have the same
@@ -853,10 +969,11 @@
                 Vars1 = Vars0 ++
                     [term.variable(DCG0, Context),
                     term.variable(DCGn, Context)],
+                % ZZZ
                 build_lambda_expression(X, Purity, DCGLambdaPurity,
                     Groundness, pf_predicate, EvalMethod, Vars1, Modes, Det,
                     ParsedGoal, Context, MainContext, SubContext,
-                    Goal0, NumAdded, !.SVarState, !SVarStore, !VarSet,
+                    Goal0, 0, NumAdded, !.SVarState, !SVarStore, !VarSet,
                     !ModuleInfo, !QualInfo, !Specs),
                 Goal0 = hlds_goal(GoalExpr, GoalInfo0),
                 goal_info_set_purity(Purity, GoalInfo0, GoalInfo),
@@ -864,8 +981,8 @@
             ;
                 MaybeParsedGoal = error1(ParsedGoalSpecs),
                 !:Specs = ParsedGoalSpecs ++ !.Specs,
-                NumAdded = 0,
-                Goal = true_goal
+                Goal = true_goal,
+                NumAdded = 0
             )
         )
     ).
@@ -897,7 +1014,7 @@
     ho_groundness::in, pred_or_func::in, lambda_eval_method::in,
     list(prog_term)::in, list(mer_mode)::in, determinism::in, goal::in,
     prog_context::in, unify_main_context::in, unify_sub_contexts::in,
-    hlds_goal::out, num_added_goals::out,
+    hlds_goal::out, num_added_goals::in, num_added_goals::out,
     svar_state::in, svar_store::in, svar_store::out,
     prog_varset::in, prog_varset::out,
     module_info::in, module_info::out, qual_info::in, qual_info::out,
@@ -905,7 +1022,7 @@
 
 build_lambda_expression(X, UnificationPurity, LambdaPurity, Groundness,
         PredOrFunc, EvalMethod, Args0, Modes, Det, ParsedGoal,
-        Context, MainContext, SubContext, Goal, NumAdded,
+        Context, MainContext, SubContext, Goal, !NumAdded,
         OutsideSVarState, !SVarStore, !VarSet,
         !ModuleInfo, !QualInfo, !Specs) :-
     % In the parse tree, the lambda arguments can be any terms, but in the HLDS
@@ -949,13 +1066,11 @@
 
     ( illegal_state_var_func_result(PredOrFunc, Args0, StateVar) ->
         report_illegal_func_svar_result(Context, !.VarSet, StateVar, !Specs),
-        Goal = true_goal,
-        NumAdded = 0
+        Goal = true_goal
     ; lambda_args_contain_bang_state_var(Args0, StateVar) ->
         report_illegal_bang_svar_lambda_arg(Context, !.VarSet, StateVar,
             !Specs),
-        Goal = true_goal,
-        NumAdded = 0
+        Goal = true_goal
     ;
         some [!SVarState] (
             svar_prepare_for_lambda_head(Context, Args0, Args, FinalSVarMap,
@@ -996,25 +1111,24 @@
             % input or unused.
             HeadBefore0 = true_goal,
             insert_arg_unifications(NonOutputLambdaVars, NonOutputArgs,
-                Context, ArgContext, HeadBefore0, HeadBefore, NonOutputAdded,
-                !SVarState, !SVarStore, !VarSet,
+                Context, ArgContext, HeadBefore0, HeadBefore,
+                !NumAdded, !SVarState, !SVarStore, !VarSet,
                 !ModuleInfo, !QualInfo, !Specs),
 
             transform_goal_expr_context_to_goal(loc_whole_goal, ParsedGoal,
                 Substitution, Body, BodyAdded, !SVarState, !SVarStore,
                 !VarSet, !ModuleInfo, !QualInfo, !Specs),
+            !:NumAdded = !.NumAdded + BodyAdded,
 
             % Create the unifications that need to come after the body of the
             % lambda expression; those corresponding to args whose mode is
             % output.
             HeadAfter0 = true_goal,
             insert_arg_unifications(OutputLambdaVars, OutputArgs,
-                Context, ArgContext, HeadAfter0, HeadAfter, OutputAdded,
-                !SVarState, !SVarStore, !VarSet,
+                Context, ArgContext, HeadAfter0, HeadAfter,
+                !NumAdded, !SVarState, !SVarStore, !VarSet,
                 !ModuleInfo, !QualInfo, !Specs),
 
-            NumAdded = NonOutputAdded + BodyAdded + OutputAdded,
-
             trace [compiletime(flag("debug-statevar-lambda")), io(!IO)] (
                 io.write_string("\nLAMBDA EXPRESSION\n", !IO),
                 io.write_string("args before:\n", !IO),
@@ -1122,17 +1236,17 @@
 
 %-----------------------------------------------------------------------------%
 
-:- pred ground_term(term(T)::in) is semidet.
+:- pred term_is_ground(term(T)::in) is semidet.
 
-ground_term(term.functor(_, Terms, _)) :-
-    ground_terms(Terms).
+term_is_ground(term.functor(_, Terms, _)) :-
+    terms_are_ground(Terms).
 
-:- pred ground_terms(list(term(T))::in) is semidet.
+:- pred terms_are_ground(list(term(T))::in) is semidet.
 
-ground_terms([]).
-ground_terms([Term | Terms]) :-
-    ground_term(Term),
-    ground_terms(Terms).
+terms_are_ground([]).
+terms_are_ground([Term | Terms]) :-
+    term_is_ground(Term),
+    terms_are_ground(Terms).
 
 :- pred arg_context_to_unify_context(arg_context::in, int::in,
     unify_main_context::out, unify_sub_contexts::out) is det.
@@ -1141,10 +1255,10 @@
     (
         ArgContext = ac_head(PredOrFunc, Arity),
         ( PredOrFunc = pf_function, ArgNum = Arity ->
-            % It's the function result term in the head.
+            % It is the function result term in the head.
             MainContext = umc_head_result
         ;
-            % It's a head argument.
+            % It is a head argument.
             MainContext = umc_head(ArgNum)
         ),
         SubContexts = []
cvs diff: Diffing compiler/notes
cvs diff: Diffing deep_profiler
cvs diff: Diffing deep_profiler/notes
cvs diff: Diffing doc
cvs diff: Diffing extras
cvs diff: Diffing extras/base64
cvs diff: Diffing extras/cgi
cvs diff: Diffing extras/complex_numbers
cvs diff: Diffing extras/complex_numbers/samples
cvs diff: Diffing extras/complex_numbers/tests
cvs diff: Diffing extras/curs
cvs diff: Diffing extras/curs/samples
cvs diff: Diffing extras/curses
cvs diff: Diffing extras/curses/sample
cvs diff: Diffing extras/dynamic_linking
cvs diff: Diffing extras/error
cvs diff: Diffing extras/fixed
cvs diff: Diffing extras/gator
cvs diff: Diffing extras/gator/generations
cvs diff: Diffing extras/gator/generations/1
cvs diff: Diffing extras/graphics
cvs diff: Diffing extras/graphics/easyx
cvs diff: Diffing extras/graphics/easyx/samples
cvs diff: Diffing extras/graphics/mercury_allegro
cvs diff: Diffing extras/graphics/mercury_allegro/examples
cvs diff: Diffing extras/graphics/mercury_allegro/samples
cvs diff: Diffing extras/graphics/mercury_allegro/samples/demo
cvs diff: Diffing extras/graphics/mercury_allegro/samples/mandel
cvs diff: Diffing extras/graphics/mercury_allegro/samples/pendulum2
cvs diff: Diffing extras/graphics/mercury_allegro/samples/speed
cvs diff: Diffing extras/graphics/mercury_cairo
cvs diff: Diffing extras/graphics/mercury_cairo/samples
cvs diff: Diffing extras/graphics/mercury_cairo/samples/data
cvs diff: Diffing extras/graphics/mercury_cairo/tutorial
cvs diff: Diffing extras/graphics/mercury_glut
cvs diff: Diffing extras/graphics/mercury_opengl
cvs diff: Diffing extras/graphics/mercury_tcltk
cvs diff: Diffing extras/graphics/samples
cvs diff: Diffing extras/graphics/samples/calc
cvs diff: Diffing extras/graphics/samples/gears
cvs diff: Diffing extras/graphics/samples/maze
cvs diff: Diffing extras/graphics/samples/pent
cvs diff: Diffing extras/lazy_evaluation
cvs diff: Diffing extras/lex
cvs diff: Diffing extras/lex/samples
cvs diff: Diffing extras/lex/tests
cvs diff: Diffing extras/log4m
cvs diff: Diffing extras/logged_output
cvs diff: Diffing extras/monte
cvs diff: Diffing extras/moose
cvs diff: Diffing extras/moose/samples
cvs diff: Diffing extras/moose/tests
cvs diff: Diffing extras/mopenssl
cvs diff: Diffing extras/morphine
cvs diff: Diffing extras/morphine/non-regression-tests
cvs diff: Diffing extras/morphine/scripts
cvs diff: Diffing extras/morphine/source
cvs diff: Diffing extras/net
cvs diff: Diffing extras/odbc
cvs diff: Diffing extras/posix
cvs diff: Diffing extras/posix/samples
cvs diff: Diffing extras/quickcheck
cvs diff: Diffing extras/quickcheck/tutes
cvs diff: Diffing extras/references
cvs diff: Diffing extras/references/samples
cvs diff: Diffing extras/references/tests
cvs diff: Diffing extras/solver_types
cvs diff: Diffing extras/solver_types/library
cvs diff: Diffing extras/trailed_update
cvs diff: Diffing extras/trailed_update/samples
cvs diff: Diffing extras/trailed_update/tests
cvs diff: Diffing extras/windows_installer_generator
cvs diff: Diffing extras/windows_installer_generator/sample
cvs diff: Diffing extras/windows_installer_generator/sample/images
cvs diff: Diffing extras/xml
cvs diff: Diffing extras/xml/samples
cvs diff: Diffing extras/xml_stylesheets
cvs diff: Diffing java
cvs diff: Diffing java/runtime
cvs diff: Diffing library
cvs diff: Diffing m4
cvs diff: Diffing mdbcomp
cvs diff: Diffing profiler
cvs diff: Diffing robdd
cvs diff: Diffing runtime
cvs diff: Diffing runtime/GETOPT
cvs diff: Diffing runtime/machdeps
cvs diff: Diffing samples
cvs diff: Diffing samples/appengine
cvs diff: Diffing samples/appengine/war
cvs diff: Diffing samples/appengine/war/WEB-INF
cvs diff: Diffing samples/c_interface
cvs diff: Diffing samples/c_interface/c_calls_mercury
cvs diff: Diffing samples/c_interface/cplusplus_calls_mercury
cvs diff: Diffing samples/c_interface/mercury_calls_c
cvs diff: Diffing samples/c_interface/mercury_calls_cplusplus
cvs diff: Diffing samples/c_interface/mercury_calls_fortran
cvs diff: Diffing samples/c_interface/simpler_c_calls_mercury
cvs diff: Diffing samples/c_interface/simpler_cplusplus_calls_mercury
cvs diff: Diffing samples/c_interface/standalone_c
cvs diff: Diffing samples/concurrency
cvs diff: Diffing samples/concurrency/dining_philosophers
cvs diff: Diffing samples/concurrency/midimon
cvs diff: Diffing samples/diff
cvs diff: Diffing samples/java_interface
cvs diff: Diffing samples/java_interface/java_calls_mercury
cvs diff: Diffing samples/java_interface/mercury_calls_java
cvs diff: Diffing samples/lazy_list
cvs diff: Diffing samples/muz
cvs diff: Diffing samples/rot13
cvs diff: Diffing samples/solutions
cvs diff: Diffing samples/solver_types
cvs diff: Diffing samples/tests
cvs diff: Diffing samples/tests/c_interface
cvs diff: Diffing samples/tests/c_interface/c_calls_mercury
cvs diff: Diffing samples/tests/c_interface/cplusplus_calls_mercury
cvs diff: Diffing samples/tests/c_interface/mercury_calls_c
cvs diff: Diffing samples/tests/c_interface/mercury_calls_cplusplus
cvs diff: Diffing samples/tests/c_interface/mercury_calls_fortran
cvs diff: Diffing samples/tests/c_interface/simpler_c_calls_mercury
cvs diff: Diffing samples/tests/c_interface/simpler_cplusplus_calls_mercury
cvs diff: Diffing samples/tests/diff
cvs diff: Diffing samples/tests/muz
cvs diff: Diffing samples/tests/rot13
cvs diff: Diffing samples/tests/solutions
cvs diff: Diffing samples/tests/toplevel
cvs diff: Diffing scripts
cvs diff: Diffing slice
cvs diff: Diffing ssdb
cvs diff: Diffing tests
cvs diff: Diffing tests/analysis
cvs diff: Diffing tests/analysis/ctgc
cvs diff: Diffing tests/analysis/excp
cvs diff: Diffing tests/analysis/ext
cvs diff: Diffing tests/analysis/sharing
cvs diff: Diffing tests/analysis/table
cvs diff: Diffing tests/analysis/trail
cvs diff: Diffing tests/analysis/unused_args
cvs diff: Diffing tests/benchmarks
cvs diff: Diffing tests/debugger
cvs diff: Diffing tests/debugger/declarative
cvs diff: Diffing tests/dppd
cvs diff: Diffing tests/feedback
cvs diff: Diffing tests/feedback/mandelbrot
cvs diff: Diffing tests/feedback/mmc
cvs diff: Diffing tests/general
cvs diff: Diffing tests/general/accumulator
cvs diff: Diffing tests/general/string_format
cvs diff: Diffing tests/general/structure_reuse
cvs diff: Diffing tests/grade_subdirs
cvs diff: Diffing tests/hard_coded
cvs diff: Diffing tests/hard_coded/exceptions
cvs diff: Diffing tests/hard_coded/purity
cvs diff: Diffing tests/hard_coded/sub-modules
cvs diff: Diffing tests/hard_coded/typeclasses
cvs diff: Diffing tests/invalid
cvs diff: Diffing tests/invalid/purity
cvs diff: Diffing tests/misc_tests
cvs diff: Diffing tests/mmc_make
cvs diff: Diffing tests/mmc_make/lib
cvs diff: Diffing tests/par_conj
cvs diff: Diffing tests/recompilation
cvs diff: Diffing tests/stm
cvs diff: Diffing tests/stm/orig
cvs diff: Diffing tests/stm/orig/stm-compiler
cvs diff: Diffing tests/stm/orig/stm-compiler/test1
cvs diff: Diffing tests/stm/orig/stm-compiler/test10
cvs diff: Diffing tests/stm/orig/stm-compiler/test2
cvs diff: Diffing tests/stm/orig/stm-compiler/test3
cvs diff: Diffing tests/stm/orig/stm-compiler/test4
cvs diff: Diffing tests/stm/orig/stm-compiler/test5
cvs diff: Diffing tests/stm/orig/stm-compiler/test6
cvs diff: Diffing tests/stm/orig/stm-compiler/test7
cvs diff: Diffing tests/stm/orig/stm-compiler/test8
cvs diff: Diffing tests/stm/orig/stm-compiler/test9
cvs diff: Diffing tests/stm/orig/stm-compiler-par
cvs diff: Diffing tests/stm/orig/stm-compiler-par/bm1
cvs diff: Diffing tests/stm/orig/stm-compiler-par/bm2
cvs diff: Diffing tests/stm/orig/stm-compiler-par/stmqueue
cvs diff: Diffing tests/stm/orig/stm-compiler-par/test1
cvs diff: Diffing tests/stm/orig/stm-compiler-par/test10
cvs diff: Diffing tests/stm/orig/stm-compiler-par/test11
cvs diff: Diffing tests/stm/orig/stm-compiler-par/test2
cvs diff: Diffing tests/stm/orig/stm-compiler-par/test3
cvs diff: Diffing tests/stm/orig/stm-compiler-par/test4
cvs diff: Diffing tests/stm/orig/stm-compiler-par/test5
cvs diff: Diffing tests/stm/orig/stm-compiler-par/test6
cvs diff: Diffing tests/stm/orig/stm-compiler-par/test7
cvs diff: Diffing tests/stm/orig/stm-compiler-par/test8
cvs diff: Diffing tests/stm/orig/stm-compiler-par/test9
cvs diff: Diffing tests/stm/orig/stm-compiler-par-asm_fast
cvs diff: Diffing tests/stm/orig/stm-compiler-par-asm_fast/test1
cvs diff: Diffing tests/stm/orig/stm-compiler-par-asm_fast/test2
cvs diff: Diffing tests/stm/orig/stm-compiler-par-asm_fast/test3
cvs diff: Diffing tests/stm/orig/stm-compiler-par-asm_fast/test4
cvs diff: Diffing tests/stm/orig/stm-compiler-par-asm_fast/test5
cvs diff: Diffing tests/stm/orig/stm-compiler-par-asm_fast/test6
cvs diff: Diffing tests/stm/orig/stm-compiler-par-asm_fast/test7
cvs diff: Diffing tests/stm/orig/stm-compiler-par-asm_fast/test8
cvs diff: Diffing tests/stm/orig/stm-compiler-par-asm_fast/test9
cvs diff: Diffing tests/tabling
cvs diff: Diffing tests/term
cvs diff: Diffing tests/trailing
cvs diff: Diffing tests/valid
cvs diff: Diffing tests/warnings
cvs diff: Diffing tools
cvs diff: Diffing trace
cvs diff: Diffing util
cvs diff: Diffing vim
cvs diff: Diffing vim/after
cvs diff: Diffing vim/ftplugin
cvs diff: Diffing vim/syntax

----- End forwarded message -----
--------------------------------------------------------------------------
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