[m-rev.] diff: renaming vars

Zoltan Somogyi zs at csse.unimelb.edu.au
Fri Sep 28 13:09:35 AEST 2007


In several places, we used to use substitutions in which the substituted terms
had to be variables. This diff replaces those substitutions with simple
variable renamings, which can be used without the gymnatics that used to
be required to convert the resulting terms back into variables.

library/varset.m:
	Supplement predicates that return substitutions in which the
	replacement terms are always variables with predicates that return
	the same information as variable renamings. Add a comment asking people
	to use the new versions. (They aren't marked as obsolete yet).

compiler/prog_util.m:
	Remove the substitute_vars predicate, which applied substitutions
	whose range was restricted to variables.

compiler/prog_data.m:
	Move predicates for applying renamings to non-HLDS data structures
	here from hlds_goal.m, and add other predicates for performing
	renamings to replace the functionality deleted from prog_util.m.

	Replace a bool specifying whether every variable needs to be renamed
	with a purpose-specific type.

compiler/hlds_goal.m:
	Delete the predicates moved to prog_data.m.

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

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/include
cvs diff: Diffing boehm_gc/include/private
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/src/atomic_ops/sysdeps/gcc
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/src/atomic_ops/sysdeps/hpc
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/src/atomic_ops/sysdeps/ibmc
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/src/atomic_ops/sysdeps/icc
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/src/atomic_ops/sysdeps/msftc
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/src/atomic_ops/sysdeps/sunc
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/tests
cvs diff: Diffing boehm_gc/tests
cvs diff: Diffing boehm_gc/windows-untested
cvs diff: Diffing boehm_gc/windows-untested/vc60
cvs diff: Diffing boehm_gc/windows-untested/vc70
cvs diff: Diffing boehm_gc/windows-untested/vc71
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.44
diff -u -r1.44 add_clause.m
--- compiler/add_clause.m	1 Jun 2007 12:54:11 -0000	1.44
+++ compiler/add_clause.m	27 Sep 2007 13:33:19 -0000
@@ -44,7 +44,7 @@
     % messages. And also at the same time, apply the given substitution to
     % the goal, to rename it apart from the other clauses.
     %
-:- pred transform_goal(goal::in, prog_substitution::in, hlds_goal::out,
+:- pred transform_goal(goal::in, prog_var_renaming::in, hlds_goal::out,
     int::out, prog_varset::in, prog_varset::out,
     module_info::in, module_info::out, qual_info::in, qual_info::out,
     svar_info::in, svar_info::out,
@@ -489,8 +489,8 @@
     ),
     update_qual_info(TVarNameMap, TVarSet0, ExplicitVarTypes0, Status,
         !QualInfo),
-    varset.merge_subst(VarSet0, CVarSet, VarSet1, Subst),
-    add_clause_transform(Subst, HeadVars, Args, Body, Context, PredOrFunc,
+    varset.merge_renaming(VarSet0, CVarSet, VarSet1, Renaming),
+    add_clause_transform(Renaming, HeadVars, Args, Body, Context, PredOrFunc,
         Arity, GoalType, Goal0, VarSet1, VarSet, Warnings, !ModuleInfo,
         !QualInfo, !Specs),
     qual_info_get_tvarset(!.QualInfo, TVarSet),
@@ -538,7 +538,7 @@
             HasForeignClauses)
     ).
 
-:- pred add_clause_transform(prog_substitution::in,
+:- pred add_clause_transform(prog_var_renaming::in,
     proc_arg_vector(prog_var)::in, list(prog_term)::in, goal::in,
     prog_context::in, pred_or_func::in, arity::in, goal_type::in,
     hlds_goal::out, prog_varset::in, prog_varset::out,
@@ -546,13 +546,13 @@
     qual_info::in, qual_info::out,
     list(error_spec)::in, list(error_spec)::out) is det.
 
-add_clause_transform(Subst, HeadVars, Args0, ParseBody, Context, PredOrFunc,
+add_clause_transform(Renaming, HeadVars, Args0, ParseBody, Context, PredOrFunc,
         Arity, GoalType, Goal, !VarSet, Warnings, !ModuleInfo,
         !QualInfo, !Specs) :-
     some [!SInfo] (
         HeadVarList = proc_arg_vector_to_list(HeadVars),
         prepare_for_head(!:SInfo),
-        term.apply_substitution_to_list(Args0, Subst, Args1),
+        rename_vars_in_term_list(need_not_rename, Renaming, Args0, Args1),
         substitute_state_var_mappings(Args1, Args, !VarSet, !SInfo, !Specs),
         HeadGoal0 = true_goal,
         ( GoalType = goal_type_promise(_) ->
@@ -566,7 +566,7 @@
                 HeadGoal1, HeadGoal)
         ),
         prepare_for_body(FinalSVarMap, !VarSet, !SInfo),
-        transform_goal(ParseBody, Subst, BodyGoal, _, !VarSet, !ModuleInfo,
+        transform_goal(ParseBody, Renaming, BodyGoal, _, !VarSet, !ModuleInfo,
             !QualInfo, !SInfo, !Specs),
         finish_goals(Context, FinalSVarMap, [HeadGoal, BodyGoal], Goal0,
             !.SInfo),
@@ -583,14 +583,14 @@
 
 %-----------------------------------------------------------------------------%
 
-transform_goal(Goal0 - Context, Subst, hlds_goal(GoalExpr, GoalInfo),
+transform_goal(Goal0 - Context, Renaming, hlds_goal(GoalExpr, GoalInfo),
         NumAdded, !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs) :-
-    transform_goal_2(Goal0, Context, Subst, hlds_goal(GoalExpr, GoalInfo1),
+    transform_goal_2(Goal0, Context, Renaming, hlds_goal(GoalExpr, GoalInfo1),
         NumAdded, !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs),
     goal_info_set_context(Context, GoalInfo1, GoalInfo).
 
 :- pred transform_goal_2(goal_expr::in, prog_context::in,
-    prog_substitution::in, hlds_goal::out, num_added_goals::out,
+    prog_var_renaming::in, hlds_goal::out, num_added_goals::out,
     prog_varset::in, prog_varset::out,
     module_info::in, module_info::out, qual_info::in, qual_info::out,
     svar_info::in, svar_info::out,
@@ -604,82 +604,82 @@
         !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs) :-
     goal_info_init(GoalInfo),
     prepare_for_next_conjunct(set.init, !VarSet, !SInfo).
-transform_goal_2(all_expr(Vars0, Goal0), Context, Subst, Goal, NumAdded,
+transform_goal_2(all_expr(Vars0, Goal0), Context, Renaming, Goal, NumAdded,
         !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs) :-
     % Convert `all [Vars] Goal' into `not some [Vars] not Goal'.
     TransformedGoal = not_expr(some_expr(Vars0, not_expr(Goal0) - Context)
         - Context),
-    transform_goal_2(TransformedGoal, Context, Subst, Goal, NumAdded,
+    transform_goal_2(TransformedGoal, Context, Renaming, Goal, NumAdded,
         !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs).
-transform_goal_2(all_state_vars_expr(StateVars, Goal0), Context, Subst,
+transform_goal_2(all_state_vars_expr(StateVars, Goal0), Context, Renaming,
         Goal, NumAdded, !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs) :-
     transform_goal_2(
         not_expr(some_state_vars_expr(StateVars,
             not_expr(Goal0) - Context) - Context),
-        Context, Subst, Goal, NumAdded, !VarSet, !ModuleInfo, !QualInfo,
+        Context, Renaming, Goal, NumAdded, !VarSet, !ModuleInfo, !QualInfo,
         !SInfo, !Specs).
-transform_goal_2(some_expr(Vars0, Goal0), _, Subst,
+transform_goal_2(some_expr(Vars0, Goal0), _, Renaming,
         hlds_goal(scope(exist_quant(Vars), Goal), GoalInfo), NumAdded,
         !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs) :-
-    substitute_vars(Vars0, Subst, Vars),
-    transform_goal(Goal0, Subst, Goal, NumAdded, !VarSet, !ModuleInfo,
+    rename_var_list(need_not_rename, Renaming, Vars0, Vars),
+    transform_goal(Goal0, Renaming, Goal, NumAdded, !VarSet, !ModuleInfo,
         !QualInfo, !SInfo, !Specs),
     goal_info_init(GoalInfo).
-transform_goal_2(some_state_vars_expr(StateVars0, Goal0), _, Subst,
+transform_goal_2(some_state_vars_expr(StateVars0, Goal0), _, Renaming,
         hlds_goal(scope(exist_quant(Vars), Goal), GoalInfo), NumAdded,
         !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs) :-
     BeforeSInfo = !.SInfo,
-    substitute_vars(StateVars0, Subst, StateVars),
+    rename_var_list(need_not_rename, Renaming, StateVars0, StateVars),
     prepare_for_local_state_vars(StateVars, !VarSet, !SInfo),
-    transform_goal(Goal0, Subst, Goal, NumAdded, !VarSet, !ModuleInfo,
+    transform_goal(Goal0, Renaming, Goal, NumAdded, !VarSet, !ModuleInfo,
         !QualInfo, !SInfo, !Specs),
     finish_local_state_vars(StateVars, Vars, BeforeSInfo, !SInfo),
     goal_info_init(GoalInfo).
-transform_goal_2(promise_purity_expr(Implicit, Purity, Goal0), _, Subst,
+transform_goal_2(promise_purity_expr(Implicit, Purity, Goal0), _, Renaming,
         hlds_goal(
             scope(promise_purity(Implicit, Purity), Goal),
             GoalInfo),
         NumAdded, !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs) :-
-    transform_goal(Goal0, Subst, Goal, NumAdded, !VarSet, !ModuleInfo,
+    transform_goal(Goal0, Renaming, Goal, NumAdded, !VarSet, !ModuleInfo,
         !QualInfo, !SInfo, !Specs),
     goal_info_init(GoalInfo).
 transform_goal_2(
         promise_equivalent_solutions_expr(Vars0, DotSVars0, ColonSVars0,
             Goal0),
-        Context, Subst,
+        Context, Renaming,
         hlds_goal(
             scope(promise_solutions(Vars, equivalent_solutions), Goal),
             GoalInfo),
         NumAdded, !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs) :-
-    transform_promise_eqv_goal(Vars0, DotSVars0, ColonSVars0, Subst, Context,
-        Vars, Goal0, Goal, GoalInfo, NumAdded, !VarSet, !ModuleInfo,
-        !QualInfo, !SInfo, !Specs).
+    transform_promise_eqv_goal(Vars0, DotSVars0, ColonSVars0,
+        Context, Renaming, Vars, Goal0, Goal, GoalInfo, NumAdded,
+        !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs).
 transform_goal_2(
         promise_equivalent_solution_sets_expr(Vars0, DotSVars0, ColonSVars0,
             Goal0),
-        Context, Subst,
+        Context, Renaming,
         hlds_goal(
             scope(promise_solutions(Vars, equivalent_solution_sets), Goal),
             GoalInfo),
         NumAdded, !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs) :-
-    transform_promise_eqv_goal(Vars0, DotSVars0, ColonSVars0, Subst, Context,
-        Vars, Goal0, Goal, GoalInfo, NumAdded, !VarSet, !ModuleInfo,
-        !QualInfo, !SInfo, !Specs).
+    transform_promise_eqv_goal(Vars0, DotSVars0, ColonSVars0,
+        Context, Renaming, Vars, Goal0, Goal, GoalInfo, NumAdded,
+        !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs).
 transform_goal_2(
         promise_equivalent_solution_arbitrary_expr(Vars0,
             DotSVars0, ColonSVars0, Goal0),
-        Context, Subst,
+        Context, Renaming,
         hlds_goal(
             scope(promise_solutions(Vars, equivalent_solution_sets_arbitrary),
                 Goal),
             GoalInfo),
         NumAdded, !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs) :-
-    transform_promise_eqv_goal(Vars0, DotSVars0, ColonSVars0, Subst, Context,
-        Vars, Goal0, Goal, GoalInfo, NumAdded, !VarSet, !ModuleInfo,
-        !QualInfo, !SInfo, !Specs).
+    transform_promise_eqv_goal(Vars0, DotSVars0, ColonSVars0,
+        Context, Renaming, Vars, Goal0, Goal, GoalInfo, NumAdded,
+        !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs).
 transform_goal_2(
         trace_expr(MaybeCompileTime, MaybeRunTime, MaybeIO, Mutables, Goal0),
-        Context, Subst, hlds_goal(scope(Reason, Goal), GoalInfo), NumAdded,
+        Context, Renaming, hlds_goal(scope(Reason, Goal), GoalInfo), NumAdded,
         !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs) :-
     list.map4(extract_trace_mutable_var(Context, !.VarSet), Mutables,
         MutableHLDSs, MutableStateVars, MutableGetGoals, MutableSetGoals),
@@ -700,9 +700,9 @@
     ),
     Goal1 = goal_list_to_conj(Context, GetGoals ++ [Goal0] ++ SetGoals),
     BeforeSInfo = !.SInfo,
-    substitute_vars(StateVars0, Subst, StateVars),
+    rename_var_list(need_not_rename, Renaming, StateVars0, StateVars),
     prepare_for_local_state_vars(StateVars, !VarSet, !SInfo),
-    transform_goal(Goal1, Subst, Goal, NumAdded1, !VarSet, !ModuleInfo,
+    transform_goal(Goal1, Renaming, Goal, NumAdded1, !VarSet, !ModuleInfo,
         !QualInfo, !SInfo, !Specs),
     NumAdded = list.length(GetGoals) + NumAdded1 + list.length(SetGoals),
     finish_local_state_vars(StateVars, Vars, BeforeSInfo, !SInfo),
@@ -710,69 +710,69 @@
         MutableHLDSs, Vars),
     goal_info_init(GoalInfo).
 transform_goal_2(if_then_else_expr(Vars0, StateVars0, Cond0, Then0, Else0),
-        Context, Subst,
+        Context, Renaming,
         hlds_goal(if_then_else(Vars, Cond, Then, Else), GoalInfo),
         NumAdded, !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs) :-
     BeforeSInfo = !.SInfo,
-    substitute_vars(Vars0, Subst, Vars),
-    substitute_vars(StateVars0, Subst, StateVars),
+    rename_var_list(need_not_rename, Renaming, Vars0, Vars),
+    rename_var_list(need_not_rename, Renaming, StateVars0, StateVars),
     prepare_for_if_then_else_goal(StateVars, !VarSet, !SInfo),
-    transform_goal(Cond0, Subst, Cond, CondAdded, !VarSet, !ModuleInfo,
+    transform_goal(Cond0, Renaming, Cond, CondAdded, !VarSet, !ModuleInfo,
         !QualInfo, !SInfo, !Specs),
     finish_if_then_else_goal_condition(StateVars,
         BeforeSInfo, !.SInfo, AfterCondSInfo, !:SInfo),
-    transform_goal(Then0, Subst, Then1, ThenAdded, !VarSet, !ModuleInfo,
+    transform_goal(Then0, Renaming, Then1, ThenAdded, !VarSet, !ModuleInfo,
         !QualInfo, !SInfo, !Specs),
     finish_if_then_else_goal_then_goal(StateVars, BeforeSInfo, !SInfo),
     AfterThenSInfo = !.SInfo,
-    transform_goal(Else0, Subst, Else1, ElseAdded, !VarSet, !ModuleInfo,
+    transform_goal(Else0, Renaming, Else1, ElseAdded, !VarSet, !ModuleInfo,
         !QualInfo, BeforeSInfo, !:SInfo, !Specs),
     NumAdded = CondAdded + ThenAdded + ElseAdded,
     goal_info_init(Context, GoalInfo),
     finish_if_then_else(Context, Then1, Then, Else1, Else,
         BeforeSInfo, AfterCondSInfo, AfterThenSInfo, !SInfo, !VarSet).
-transform_goal_2(not_expr(SubGoal0), _, Subst,
+transform_goal_2(not_expr(SubGoal0), _, Renaming,
         hlds_goal(negation(SubGoal), GoalInfo),
         NumAdded, !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs) :-
     BeforeSInfo = !.SInfo,
-    transform_goal(SubGoal0, Subst, SubGoal, NumAdded, !VarSet, !ModuleInfo,
+    transform_goal(SubGoal0, Renaming, SubGoal, NumAdded, !VarSet, !ModuleInfo,
         !QualInfo, !SInfo, !Specs),
     goal_info_init(GoalInfo),
     finish_negation(BeforeSInfo, !SInfo).
-transform_goal_2(conj_expr(A0, B0), _, Subst, Goal, NumAdded, !VarSet,
+transform_goal_2(conj_expr(A0, B0), _, Renaming, Goal, NumAdded, !VarSet,
         !ModuleInfo, !QualInfo, !SInfo, !Specs) :-
-    get_rev_conj(A0, Subst, [], R0, 0, NumAddedA,
+    get_rev_conj(A0, Renaming, [], R0, 0, NumAddedA,
         !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs),
-    get_rev_conj(B0, Subst, R0, R,  NumAddedA, NumAdded,
+    get_rev_conj(B0, Renaming, R0, R,  NumAddedA, NumAdded,
         !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs),
     L = list.reverse(R),
     goal_info_init(GoalInfo),
     conj_list_to_goal(L, GoalInfo, Goal).
-transform_goal_2(par_conj_expr(A0, B0), _, Subst, Goal, NumAdded, !VarSet,
+transform_goal_2(par_conj_expr(A0, B0), _, Renaming, Goal, NumAdded, !VarSet,
         !ModuleInfo, !QualInfo, !SInfo, !Specs) :-
-    get_rev_par_conj(A0, Subst, [], R0, 0, NumAddedA,
+    get_rev_par_conj(A0, Renaming, [], R0, 0, NumAddedA,
         !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs),
-    get_rev_par_conj(B0, Subst, R0, R,  NumAddedA, NumAdded,
+    get_rev_par_conj(B0, Renaming, R0, R,  NumAddedA, NumAdded,
         !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs),
     L = list.reverse(R),
     goal_info_init(GoalInfo),
     par_conj_list_to_goal(L, GoalInfo, Goal).
-transform_goal_2(disj_expr(A0, B0), Context, Subst, Goal, NumAdded, !VarSet,
+transform_goal_2(disj_expr(A0, B0), Context, Renaming, Goal, NumAdded, !VarSet,
         !ModuleInfo, !QualInfo, !SInfo, !Specs) :-
-    get_disj(B0, Subst, [], L0, 0, NumAddedB,
+    get_disj(B0, Renaming, [], L0, 0, NumAddedB,
         !VarSet, !ModuleInfo, !QualInfo, !.SInfo, !Specs),
-    get_disj(A0, Subst, L0, L1, NumAddedB, NumAdded,
+    get_disj(A0, Renaming, L0, L1, NumAddedB, NumAdded,
         !VarSet, !ModuleInfo, !QualInfo, !.SInfo, !Specs),
     finish_disjunction(Context, !.VarSet, L1, L, !:SInfo),
     goal_info_init(Context, GoalInfo),
     disj_list_to_goal(L, GoalInfo, Goal).
-transform_goal_2(implies_expr(P, Q), Context, Subst, Goal, NumAdded, !VarSet,
-        !ModuleInfo, !QualInfo, !SInfo, !Specs) :-
+transform_goal_2(implies_expr(P, Q), Context, Renaming, Goal, NumAdded,
+        !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs) :-
         % `P => Q' is defined as `not (P, not Q)'
     TransformedGoal = not_expr(conj_expr(P, not_expr(Q) - Context) - Context),
-    transform_goal_2(TransformedGoal, Context, Subst, Goal, NumAdded, !VarSet,
-        !ModuleInfo, !QualInfo, !SInfo, !Specs).
-transform_goal_2(equivalent_expr(P0, Q0), _, Subst, Goal, NumAdded, !VarSet,
+    transform_goal_2(TransformedGoal, Context, Renaming, Goal, NumAdded,
+        !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs).
+transform_goal_2(equivalent_expr(P0, Q0), _, Renaming, Goal, NumAdded, !VarSet,
         !ModuleInfo, !QualInfo, !SInfo, !Specs) :-
     % `P <=> Q' is defined as `(P => Q), (Q => P)',
     % but that transformation must not be done until
@@ -782,18 +782,18 @@
 
     BeforeSInfo = !.SInfo,
     goal_info_init(GoalInfo),
-    transform_goal(P0, Subst, P, NumAddedP, !VarSet, !ModuleInfo, !QualInfo,
+    transform_goal(P0, Renaming, P, NumAddedP, !VarSet, !ModuleInfo, !QualInfo,
         !SInfo, !Specs),
-    transform_goal(Q0, Subst, Q, NumAddedQ, !VarSet, !ModuleInfo, !QualInfo,
+    transform_goal(Q0, Renaming, Q, NumAddedQ, !VarSet, !ModuleInfo, !QualInfo,
         !SInfo, !Specs),
     NumAdded = NumAddedP + NumAddedQ,
     Goal = hlds_goal(shorthand(bi_implication(P, Q)), GoalInfo),
     finish_equivalence(BeforeSInfo, !SInfo).
-transform_goal_2(event_expr(EventName, Args0), Context, Subst, Goal,
+transform_goal_2(event_expr(EventName, Args0), Context, Renaming, Goal,
         NumAdded, !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs) :-
     Args1 = expand_bang_state_var_args(Args0),
     prepare_for_call(!SInfo),
-    term.apply_substitution_to_list(Args1, Subst, Args),
+    rename_vars_in_term_list(need_not_rename, Renaming, Args1, Args),
     make_fresh_arg_vars(Args, HeadVars, !VarSet, !SInfo, !Specs),
     list.length(HeadVars, Arity),
     list.duplicate(Arity, in_mode, Modes),
@@ -806,7 +806,7 @@
         Goal0, Goal, NumAdded, !VarSet, !ModuleInfo, !QualInfo,
         !SInfo, !Specs),
     finish_call(!VarSet, !SInfo).
-transform_goal_2(call_expr(Name, Args0, Purity), Context, Subst, Goal,
+transform_goal_2(call_expr(Name, Args0, Purity), Context, Renaming, Goal,
         NumAdded, !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs) :-
     Args1 = expand_bang_state_var_args(Args0),
     (
@@ -816,7 +816,7 @@
         prepare_for_call(!SInfo),
         % `LHS \= RHS' is defined as `not (LHS = RHS)'
         transform_goal_2(not_expr(unify_expr(LHS, RHS, Purity) - Context),
-            Context, Subst, Goal, NumAdded, !VarSet, !ModuleInfo, !QualInfo,
+            Context, Renaming, Goal, NumAdded, !VarSet, !ModuleInfo, !QualInfo,
             !SInfo, !Specs),
         finish_call(!VarSet, !SInfo)
     ;
@@ -836,7 +836,7 @@
                 FieldListContext),
         RHS = functor(atom(":="), [FieldList, RHS0], Context),
         transform_goal_2(unify_expr(LHS, RHS, Purity),
-            Context, Subst, Goal, NumAdded, !VarSet, !ModuleInfo, !QualInfo,
+            Context, Renaming, Goal, NumAdded, !VarSet, !ModuleInfo, !QualInfo,
             !SInfo, !Specs),
         finish_call(!VarSet, !SInfo)
     ;
@@ -849,13 +849,13 @@
         )
     ->
         prepare_for_call(!SInfo),
-        term.apply_substitution_to_list(Args1, Subst, Args2),
+        rename_vars_in_term_list(need_not_rename, Renaming, Args1, Args2),
         transform_dcg_record_syntax(Operator, Args2, Context, Goal, NumAdded,
             !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs),
         finish_call(!VarSet, !SInfo)
     ;
         prepare_for_call(!SInfo),
-        term.apply_substitution_to_list(Args1, Subst, Args),
+        rename_vars_in_term_list(need_not_rename, Renaming, Args1, Args),
         make_fresh_arg_vars(Args, HeadVars, !VarSet, !SInfo, !Specs),
         list.length(Args, Arity),
         (
@@ -894,7 +894,7 @@
             !SInfo, !Specs),
         finish_call(!VarSet, !SInfo)
     ).
-transform_goal_2(unify_expr(A0, B0, Purity), Context, Subst, Goal,
+transform_goal_2(unify_expr(A0, B0, Purity), Context, Renaming, Goal,
         NumAdded, !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs) :-
     % It is an error for the left or right hand side of a
     % unification to be !X (it may be !.X or !:X, however).
@@ -908,8 +908,8 @@
         NumAdded = 0
     ;
         prepare_for_call(!SInfo),
-        term.apply_substitution(A0, Subst, A),
-        term.apply_substitution(B0, Subst, B),
+        rename_vars_in_term(need_not_rename, Renaming, A0, A),
+        rename_vars_in_term(need_not_rename, Renaming, B0, B),
         unravel_unification(A, B, Context, umc_explicit, [], Purity, Goal,
             NumAdded, !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs),
         finish_call(!VarSet, !SInfo)
@@ -948,23 +948,23 @@
     SetGoal = call_expr(SetPredName, [UseVar], SetPurity) - Context.
 
 :- pred transform_promise_eqv_goal(prog_vars::in, prog_vars::in, prog_vars::in,
-    prog_substitution::in, prog_context::in, prog_vars::out,
+    prog_context::in, prog_var_renaming::in, prog_vars::out,
     goal::in, hlds_goal::out, hlds_goal_info::out, int::out,
     prog_varset::in, prog_varset::out, module_info::in, module_info::out,
     qual_info::in, qual_info::out, svar_info::in, svar_info::out,
     list(error_spec)::in, list(error_spec)::out) is det.
 
-transform_promise_eqv_goal(Vars0, DotSVars0, ColonSVars0, Subst, Context, Vars,
-        Goal0, Goal, GoalInfo, NumAdded, !VarSet, !ModuleInfo, !QualInfo,
+transform_promise_eqv_goal(Vars0, DotSVars0, ColonSVars0, Context, Renaming,
+        Vars, Goal0, Goal, GoalInfo, NumAdded, !VarSet, !ModuleInfo, !QualInfo,
         !SInfo, !Specs) :-
-    substitute_vars(Vars0, Subst, Vars1),
-    substitute_vars(DotSVars0, Subst, DotSVars1),
+    rename_var_list(need_not_rename, Renaming, Vars0, Vars1),
+    rename_var_list(need_not_rename, Renaming, DotSVars0, DotSVars1),
     convert_dot_state_vars(Context, DotSVars1, DotSVars, !VarSet,
         !SInfo, !Specs),
-    transform_goal(Goal0, Subst, Goal, NumAdded, !VarSet, !ModuleInfo,
+    transform_goal(Goal0, Renaming, Goal, NumAdded, !VarSet, !ModuleInfo,
         !QualInfo, !SInfo, !Specs),
     goal_info_init(GoalInfo),
-    substitute_vars(ColonSVars0, Subst, ColonSVars1),
+    rename_var_list(need_not_rename, Renaming, ColonSVars0, ColonSVars1),
     convert_dot_state_vars(Context, ColonSVars1, ColonSVars, !VarSet,
         !SInfo, !Specs),
     Vars = Vars1 ++ DotSVars ++ ColonSVars.
@@ -1176,78 +1176,78 @@
         unexpected(this_file, "do_transform_dcg_record_syntax")
     ).
 
-    % get_rev_conj(Goal, Subst, RevConj0, RevConj) :
+    % get_rev_conj(Goal, Renaming, RevConj0, RevConj) :
     %
-    % Goal is a tree of conjuncts. Flatten it into a list (applying Subst),
+    % Goal is a tree of conjuncts. Flatten it into a list (applying Renaming),
     % reverse it, append RevConj0, and return the result in RevConj.
     %
-:- pred get_rev_conj(goal::in, prog_substitution::in,
+:- pred get_rev_conj(goal::in, prog_var_renaming::in,
     list(hlds_goal)::in, list(hlds_goal)::out, int::in, int::out,
     prog_varset::in, prog_varset::out, module_info::in, module_info::out,
     qual_info::in, qual_info::out, svar_info::in, svar_info::out,
     list(error_spec)::in, list(error_spec)::out) is det.
 
-get_rev_conj(Goal, Subst, RevConj0, RevConj, !NumAdded, !VarSet, !ModuleInfo,
-        !QualInfo, !SInfo, !Specs) :-
+get_rev_conj(Goal, Renaming, RevConj0, RevConj, !NumAdded, !VarSet,
+        !ModuleInfo, !QualInfo, !SInfo, !Specs) :-
     ( Goal = conj_expr(A, B) - _Context ->
-        get_rev_conj(A, Subst, RevConj0, RevConj1, !NumAdded,
+        get_rev_conj(A, Renaming, RevConj0, RevConj1, !NumAdded,
             !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs),
-        get_rev_conj(B, Subst, RevConj1, RevConj, !NumAdded,
+        get_rev_conj(B, Renaming, RevConj1, RevConj, !NumAdded,
             !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs)
     ;
-        transform_goal(Goal, Subst, Goal1, GoalAdded, !VarSet, !ModuleInfo,
+        transform_goal(Goal, Renaming, Goal1, GoalAdded, !VarSet, !ModuleInfo,
             !QualInfo, !SInfo, !Specs),
         !:NumAdded = !.NumAdded + GoalAdded,
         goal_to_conj_list(Goal1, ConjList),
         RevConj = list.reverse(ConjList) ++ RevConj0
     ).
 
-    % get_rev_par_conj(Goal, Subst, RevParConj0, RevParConj) :
+    % get_rev_par_conj(Goal, Renaming, RevParConj0, RevParConj) :
     %
-    % Goal is a tree of conjuncts.  Flatten it into a list (applying Subst),
+    % Goal is a tree of conjuncts.  Flatten it into a list (applying Renaming),
     % reverse it, append RevParConj0, and return the result in RevParConj.
     %
-:- pred get_rev_par_conj(goal::in, prog_substitution::in,
+:- pred get_rev_par_conj(goal::in, prog_var_renaming::in,
     list(hlds_goal)::in, list(hlds_goal)::out, int::in, int::out,
     prog_varset::in, prog_varset::out, module_info::in, module_info::out,
     qual_info::in, qual_info::out, svar_info::in, svar_info::out,
     list(error_spec)::in, list(error_spec)::out) is det.
 
-get_rev_par_conj(Goal, Subst, RevParConj0, RevParConj, !NumAdded, !VarSet,
+get_rev_par_conj(Goal, Renaming, RevParConj0, RevParConj, !NumAdded, !VarSet,
         !ModuleInfo, !QualInfo, !SInfo, !Specs) :-
     ( Goal = par_conj_expr(A, B) - _Context ->
-        get_rev_par_conj(A, Subst, RevParConj0, RevParConj1, !NumAdded,
+        get_rev_par_conj(A, Renaming, RevParConj0, RevParConj1, !NumAdded,
             !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs),
-        get_rev_par_conj(B, Subst, RevParConj1, RevParConj, !NumAdded,
+        get_rev_par_conj(B, Renaming, RevParConj1, RevParConj, !NumAdded,
             !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs)
     ;
-        transform_goal(Goal, Subst, Goal1, GoalAdded, !VarSet, !ModuleInfo,
+        transform_goal(Goal, Renaming, Goal1, GoalAdded, !VarSet, !ModuleInfo,
             !QualInfo, !SInfo, !Specs),
         !:NumAdded = !.NumAdded + GoalAdded,
         goal_to_par_conj_list(Goal1, ParConjList),
         RevParConj = list.reverse(ParConjList) ++ RevParConj0
     ).
 
-    % get_disj(Goal, Subst, Disj0, Disj):
+    % get_disj(Goal, Renaming, Disj0, Disj):
     %
-    % Goal is a tree of disjuncts.  Flatten it into a list (applying Subst),
+    % Goal is a tree of disjuncts.  Flatten it into a list (applying Renaming),
     % append Disj0, and return the result in Disj.
     %
-:- pred get_disj(goal::in, prog_substitution::in,
+:- pred get_disj(goal::in, prog_var_renaming::in,
     hlds_goal_svar_infos::in, hlds_goal_svar_infos::out, int::in, int::out,
     prog_varset::in, prog_varset::out, module_info::in, module_info::out,
     qual_info::in, qual_info::out, svar_info::in,
     list(error_spec)::in, list(error_spec)::out) is det.
 
-get_disj(Goal, Subst, Disj0, Disj, !NumAdded, !VarSet, !ModuleInfo, !QualInfo,
-        SInfo, !Specs) :-
+get_disj(Goal, Renaming, Disj0, Disj, !NumAdded, !VarSet, !ModuleInfo,
+        !QualInfo, SInfo, !Specs) :-
     ( Goal = disj_expr(A, B) - _Context ->
-        get_disj(B, Subst, Disj0, Disj1, !NumAdded, !VarSet, !ModuleInfo,
+        get_disj(B, Renaming, Disj0, Disj1, !NumAdded, !VarSet, !ModuleInfo,
             !QualInfo, SInfo, !Specs),
-        get_disj(A, Subst, Disj1, Disj,  !NumAdded, !VarSet, !ModuleInfo,
+        get_disj(A, Renaming, Disj1, Disj,  !NumAdded, !VarSet, !ModuleInfo,
             !QualInfo, SInfo, !Specs)
     ;
-        transform_goal(Goal, Subst, Goal1, GoalAdded, !VarSet, !ModuleInfo,
+        transform_goal(Goal, Renaming, Goal1, GoalAdded, !VarSet, !ModuleInfo,
             !QualInfo, SInfo, SInfo1, !Specs),
         !:NumAdded = !.NumAdded + GoalAdded,
         Disj = [{Goal1, SInfo1} | Disj0]
Index: compiler/ctgc.util.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/ctgc.util.m,v
retrieving revision 1.12
diff -u -r1.12 ctgc.util.m
--- compiler/ctgc.util.m	2 Aug 2007 01:23:58 -0000	1.12
+++ compiler/ctgc.util.m	26 Sep 2007 06:47:45 -0000
@@ -16,7 +16,6 @@
 :- module transform_hlds.ctgc.util.
 :- interface.
 
-:- import_module hlds.hlds_goal.
 :- import_module hlds.hlds_module.
 :- import_module hlds.hlds_pred.
 :- import_module parse_tree.prog_data.
@@ -109,11 +108,11 @@
 
     (
         type_list_subsumes(FormalTypes, ActualTypes, TypeSubstitution0)
-    -> 
+    ->
         TypeSubstitution = TypeSubstitution0
-    ; 
+    ;
         % XXX Sharing analysis of compiler generated procedures fails due
-        % to the fact that type_list_subsumes fails; I assume that the 
+        % to the fact that type_list_subsumes fails; I assume that the
         % same reasoning as in inlining.get_type_substitution/5 is applicable
         % here: "The head types should always be unifiable with the actual
         % argument types, otherwise it is a type error that should have
Index: compiler/delay_partial_inst.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/delay_partial_inst.m,v
retrieving revision 1.2
diff -u -r1.2 delay_partial_inst.m
--- compiler/delay_partial_inst.m	7 Aug 2007 07:09:50 -0000	1.2
+++ compiler/delay_partial_inst.m	28 Sep 2007 01:24:17 -0000
@@ -446,8 +446,7 @@
     VarTypes0 = !.DelayInfo ^ dpi_vartypes,
     create_variables(OrigVars, VarSet0, VarTypes0,
         VarSet0, VarSet, VarTypes0, VarTypes, map.init, Subn),
-    MustRename = yes,
-    rename_var_list(MustRename, Subn, OrigVars, CanonVars),
+    rename_var_list(must_rename, Subn, OrigVars, CanonVars),
     !DelayInfo ^ dpi_varset := VarSet,
     !DelayInfo ^ dpi_vartypes := VarTypes.
 
Index: compiler/equiv_type_hlds.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/equiv_type_hlds.m,v
retrieving revision 1.44
diff -u -r1.44 equiv_type_hlds.m
--- compiler/equiv_type_hlds.m	25 Sep 2007 04:56:37 -0000	1.44
+++ compiler/equiv_type_hlds.m	27 Sep 2007 11:58:07 -0000
@@ -859,8 +859,8 @@
         !:Info = !.Info ^ module_info := ModuleInfo,
         !:Info = !.Info ^ tvarset := TVarSet,
 
-        rename_vars_in_goals(no, map.from_assoc_list([TypeInfoVar - Var]),
-            Goals0, Goals),
+        rename_vars_in_goals(need_not_rename,
+            map.from_assoc_list([TypeInfoVar - Var]), Goals0, Goals),
         ( Goals = [hlds_goal(GoalExpr1, _)] ->
             GoalExpr = GoalExpr1
         ;
Index: compiler/headvar_names.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/headvar_names.m,v
retrieving revision 1.4
diff -u -r1.4 headvar_names.m
--- compiler/headvar_names.m	7 Aug 2007 07:09:53 -0000	1.4
+++ compiler/headvar_names.m	28 Sep 2007 01:24:35 -0000
@@ -78,7 +78,8 @@
                 VarSet0, VarSet, map.init, Subst, [], RevConj),
 
             NonLocals0 = goal_info_get_nonlocals(GoalInfo0),
-            rename_vars_in_var_set(no, Subst, NonLocals0, NonLocals),
+            rename_vars_in_var_set(need_not_rename, Subst,
+                NonLocals0, NonLocals),
             goal_info_set_nonlocals(NonLocals, GoalInfo0, GoalInfo),
             conj_list_to_goal(list.reverse(RevConj), GoalInfo, Goal),
 
Index: compiler/hlds_goal.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/hlds_goal.m,v
retrieving revision 1.181
diff -u -r1.181 hlds_goal.m
--- compiler/hlds_goal.m	6 Sep 2007 12:45:23 -0000	1.181
+++ compiler/hlds_goal.m	27 Sep 2007 11:45:50 -0000
@@ -1262,32 +1262,21 @@
 % the structure of hlds_goal_infos, which makes accidentally forgetting to
 % update that predicate after modifying the hlds_goal_info type much harder.
 
-:- type prog_var_renaming == map(prog_var, prog_var).
-
 :- pred rename_some_vars_in_goal(prog_var_renaming::in,
     hlds_goal::in, hlds_goal::out) is det.
 
 :- pred must_rename_vars_in_goal(prog_var_renaming::in,
     hlds_goal::in, hlds_goal::out) is det.
 
-:- pred rename_vars_in_goals(bool::in, prog_var_renaming::in,
+:- pred rename_vars_in_goals(must_rename::in, prog_var_renaming::in,
     hlds_goals::in, hlds_goals::out) is det.
 
-:- pred rename_vars_in_goal_expr(bool::in, prog_var_renaming::in,
+:- pred rename_vars_in_goal_expr(must_rename::in, prog_var_renaming::in,
     hlds_goal_expr::in, hlds_goal_expr::out) is det.
 
-:- pred rename_vars_in_goal_info(bool::in, prog_var_renaming::in,
+:- pred rename_vars_in_goal_info(must_rename::in, prog_var_renaming::in,
     hlds_goal_info::in, hlds_goal_info::out) is det.
 
-:- pred rename_vars_in_var_set(bool::in, prog_var_renaming::in,
-    set(prog_var)::in, set(prog_var)::out) is det.
-
-:- pred rename_var_list(bool::in, map(var(T), var(T))::in,
-    list(var(T))::in, list(var(T))::out) is det.
-
-:- pred rename_var(bool::in, map(var(V), var(V))::in,
-    var(V)::in, var(V)::out) is det.
-
 %-----------------------------------------------------------------------------%
 %
 % Miscellaneous utility procedures for dealing with HLDS goals.
@@ -2066,12 +2055,12 @@
 %
 
 rename_some_vars_in_goal(Subn, Goal0, Goal) :-
-    rename_vars_in_goal(no, Subn, Goal0, Goal).
+    rename_vars_in_goal(need_not_rename, Subn, Goal0, Goal).
 
 must_rename_vars_in_goal(Subn, Goal0, Goal) :-
-    rename_vars_in_goal(yes, Subn, Goal0, Goal).
+    rename_vars_in_goal(must_rename, Subn, Goal0, Goal).
 
-:- pred rename_vars_in_goal(bool::in, prog_var_renaming::in,
+:- pred rename_vars_in_goal(must_rename::in, prog_var_renaming::in,
     hlds_goal::in, hlds_goal::out) is det.
 
 rename_vars_in_goal(Must, Subn, Goal0, Goal) :-
@@ -2170,7 +2159,7 @@
         Expr = shorthand(ShorthandGoal)
     ).
 
-:- pred rename_vars_in_shorthand(bool::in, prog_var_renaming::in,
+:- pred rename_vars_in_shorthand(must_rename::in, prog_var_renaming::in,
     shorthand_goal_expr::in, shorthand_goal_expr::out) is det.
 
 rename_vars_in_shorthand(Must, Subn,
@@ -2178,7 +2167,7 @@
     rename_vars_in_goal(Must, Subn, LHS0, LHS),
     rename_vars_in_goal(Must, Subn, RHS0, RHS).
 
-:- pred rename_arg_list(bool::in, prog_var_renaming::in,
+:- pred rename_arg_list(must_rename::in, prog_var_renaming::in,
     list(foreign_arg)::in, list(foreign_arg)::out) is det.
 
 rename_arg_list(_Must, _Subn, [], []).
@@ -2186,7 +2175,7 @@
     rename_arg(Must, Subn, Arg0, Arg),
     rename_arg_list(Must, Subn, Args0, Args).
 
-:- pred rename_arg(bool::in, prog_var_renaming::in,
+:- pred rename_arg(must_rename::in, prog_var_renaming::in,
     foreign_arg::in, foreign_arg::out) is det.
 
 rename_arg(Must, Subn, Arg0, Arg) :-
@@ -2194,7 +2183,7 @@
     rename_var(Must, Subn, Var0, Var),
     Arg = foreign_arg(Var, B, C, D).
 
-:- pred rename_vars_in_cases(bool::in, prog_var_renaming::in,
+:- pred rename_vars_in_cases(must_rename::in, prog_var_renaming::in,
     list(case)::in, list(case)::out) is det.
 
 rename_vars_in_cases(_Must, _Subn, [], []).
@@ -2203,7 +2192,7 @@
     rename_vars_in_goal(Must, Subn, G0, G),
     rename_vars_in_cases(Must, Subn, Gs0, Gs).
 
-:- pred rename_unify_rhs(bool::in, prog_var_renaming::in,
+:- pred rename_unify_rhs(must_rename::in, prog_var_renaming::in,
     unify_rhs::in, unify_rhs::out) is det.
 
 rename_unify_rhs(Must, Subn, rhs_var(Var0), rhs_var(Var)) :-
@@ -2220,7 +2209,7 @@
     rename_var_list(Must, Subn, Vars0, Vars),
     rename_vars_in_goal(Must, Subn, Goal0, Goal).
 
-:- pred rename_unify(bool::in, prog_var_renaming::in,
+:- pred rename_unify(must_rename::in, prog_var_renaming::in,
     unification::in, unification::out) is det.
 
 rename_unify(Must, Subn, Unify0, Unify) :-
@@ -2287,7 +2276,7 @@
         Unify = complicated_unify(Modes, Cat, TypeInfoVars)
     ).
 
-:- pred rename_generic_call(bool::in, prog_var_renaming::in,
+:- pred rename_generic_call(must_rename::in, prog_var_renaming::in,
     generic_call::in, generic_call::out) is det.
 
 rename_generic_call(Must, Subn, Call0, Call) :-
@@ -2386,7 +2375,7 @@
     !:GoalInfo = goal_info(Detism, InstMapDelta, NonLocals, Purity,
         Features, GoalPath, CodeGenInfo, ExtraInfo).
 
-:- pred rename_vars_in_short_reuse_desc(bool::in, prog_var_renaming::in,
+:- pred rename_vars_in_short_reuse_desc(must_rename::in, prog_var_renaming::in,
     short_reuse_description::in, short_reuse_description::out) is det.
 
 rename_vars_in_short_reuse_desc(Must, Subn, ShortReuseDesc0, ShortReuseDesc) :-
@@ -2403,7 +2392,7 @@
             FieldNeedUpdates)
     ).
 
-:- pred rename_var_maps(bool::in, prog_var_renaming::in,
+:- pred rename_var_maps(must_rename::in, prog_var_renaming::in,
     map(prog_var, T)::in, map(prog_var, T)::out) is det.
 
 rename_var_maps(Must, Subn, Map0, Map) :-
@@ -2411,7 +2400,7 @@
     rename_var_maps_2(Must, Subn, AssocList0, AssocList),
     map.from_assoc_list(AssocList, Map).
 
-:- pred rename_var_maps_2(bool::in, map(var(V), var(V))::in,
+:- pred rename_var_maps_2(must_rename::in, map(var(V), var(V))::in,
     assoc_list(var(V), T)::in, assoc_list(var(V), T)::out) is det.
 
 rename_var_maps_2(_Must, _Subn, [], []).
@@ -2419,12 +2408,7 @@
     rename_var(Must, Subn, V, N),
     rename_var_maps_2(Must, Subn, Vs, Ns).
 
-rename_vars_in_var_set(Must, Subn, Vars0, Vars) :-
-    set.to_sorted_list(Vars0, VarsList0),
-    rename_var_list(Must, Subn, VarsList0, VarsList),
-    set.list_to_set(VarsList, Vars).
-
-:- pred rename_var_pair_list(bool::in, prog_var_renaming::in,
+:- pred rename_var_pair_list(must_rename::in, prog_var_renaming::in,
     assoc_list(prog_var, T)::in, list(pair(prog_var, T))::out) is det.
 
 rename_var_pair_list(_Must, _Subn, [], []).
@@ -2432,27 +2416,6 @@
     rename_var(Must, Subn, V, N),
     rename_var_pair_list(Must, Subn, VDs, NDs).
 
-rename_var_list(_Must, _Subn, [], []).
-rename_var_list(Must, Subn, [V | Vs], [N | Ns]) :-
-    rename_var(Must, Subn, V, N),
-    rename_var_list(Must, Subn, Vs, Ns).
-
-rename_var(Must, Subn, V, N) :-
-    ( map.search(Subn, V, N0) ->
-        N = N0
-    ;
-        (
-            Must = no,
-            N = V
-        ;
-            Must = yes,
-            term.var_to_int(V, VInt),
-            string.format("rename_var: no substitute for var %i", [i(VInt)],
-                Msg),
-            unexpected(this_file, Msg)
-        )
-    ).
-
 %-----------------------------------------------------------------------------%
 %
 % Miscellaneous utility procedures for dealing with HLDS goals.
Index: compiler/hlds_llds.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/hlds_llds.m,v
retrieving revision 1.19
diff -u -r1.19 hlds_llds.m
--- compiler/hlds_llds.m	7 Aug 2007 07:09:54 -0000	1.19
+++ compiler/hlds_llds.m	28 Sep 2007 01:25:04 -0000
@@ -256,13 +256,15 @@
 
 %-----------------------------------------------------------------------------%
 
-    % rename_vars_in_llds_code_gen_info(Must, Subn, Details0, Details):
-    % Renames all the variables in Details0 according to the substitution
-    % Subn, yielding Details. If Must is yes, then require every variable
-    % in Details0 to be in the domain of Subn. If Must is no, then leave
-    % variables not in the domain of Subn unchanged.
+    % rename_vars_in_llds_code_gen_info(Must, Rename, Details0, Details):
     %
-:- pred rename_vars_in_llds_code_gen_info(bool::in,
+    % Rename all the variables in Details0 according to the substitution
+    % Rename, yielding Details. If Must is must_rename, then require every
+    % variable in Details0 to be in the domain of Rename. If Must is
+    % need_not_rename, then leave variables not in the domain of Rename
+    % unchanged.
+    %
+:- pred rename_vars_in_llds_code_gen_info(must_rename::in,
     map(prog_var, prog_var)::in,
     llds_code_gen_details::in, llds_code_gen_details::out) is det.
 
@@ -687,7 +689,8 @@
         PreDeaths, PostDeaths, MaybeFollowVars, StoreMap,
         ResumePoint, MaybeNeed).
 
-:- pred rename_vars_in_var_locn_map(bool::in, map(prog_var, prog_var)::in,
+:- pred rename_vars_in_var_locn_map(must_rename::in,
+    map(prog_var, prog_var)::in,
     map(prog_var, abs_locn)::in, map(prog_var, abs_locn)::out) is det.
 
 rename_vars_in_var_locn_map(Must, Subn, VarLocnMap0, VarLocnMap) :-
@@ -695,9 +698,10 @@
     rename_vars_in_var_locn_list(Must, Subn, VarLocnList0, VarLocnList),
     map.from_assoc_list(VarLocnList, VarLocnMap).
 
-:- pred rename_vars_in_var_locn_list(bool::in, map(prog_var, prog_var)::in,
-    assoc_list(prog_var, abs_locn)::in,
-    assoc_list(prog_var, abs_locn)::out) is det.
+:- pred rename_vars_in_var_locn_list(must_rename::in,
+    map(prog_var, prog_var)::in,
+    assoc_list(prog_var, abs_locn)::in, assoc_list(prog_var, abs_locn)::out)
+    is det.
 
 rename_vars_in_var_locn_list(_Must, _Subn, [], []).
 rename_vars_in_var_locn_list(Must, Subn,
Index: compiler/instmap.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/instmap.m,v
retrieving revision 1.59
diff -u -r1.59 instmap.m
--- compiler/instmap.m	27 Aug 2007 06:22:13 -0000	1.59
+++ compiler/instmap.m	27 Sep 2007 11:56:01 -0000
@@ -27,7 +27,6 @@
 :- import_module parse_tree.prog_data.
 
 :- import_module assoc_list.
-:- import_module bool.
 :- import_module list.
 :- import_module map.
 :- import_module set.
@@ -280,16 +279,17 @@
 
 %-----------------------------------------------------------------------------%
 
-    % `instmap_delta_apply_sub(Must, Sub, InstmapDelta0, InstmapDelta)'
-    % the variable substitution Sub to InstmapDelta0 to get the new
-    % instmap_delta InstmapDelta.  If there is a variable in
-    % InstmapDelta0 which does not appear in Sub, it is ignored if
-    % Must is set to no, otherwise it is an error.
+    % instmap_delta_apply_sub(Must, Renaming, InstmapDelta0, InstmapDelta):
+    %
+    % Apply the variable renaming Renaming to InstmapDelta0 to get the new
+    % instmap_delta InstmapDelta.  If there is a variable in InstmapDelta0
+    % which does not appear in Renaming, it is ignored if Must is set to
+    % need_not_rename, otherwise it is an error.
     %
-:- pred instmap_delta_apply_sub(bool::in, map(prog_var, prog_var)::in,
+:- pred instmap_delta_apply_sub(must_rename::in, map(prog_var, prog_var)::in,
     instmap_delta::in, instmap_delta::out) is det.
 
-:- pred apply_sub(bool::in, map(prog_var, prog_var)::in,
+:- pred apply_sub(must_rename::in, map(prog_var, prog_var)::in,
     instmap::in, instmap::out) is det.
 
 %-----------------------------------------------------------------------------%
@@ -335,6 +335,7 @@
 :- import_module libs.compiler_util.
 :- import_module parse_tree.prog_data.
 
+:- import_module bool.
 :- import_module int.
 :- import_module maybe.
 :- import_module pair.
@@ -1196,38 +1197,30 @@
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
 
-instmap_delta_apply_sub(_Must, _Sub, unreachable, unreachable).
-instmap_delta_apply_sub(Must, Sub,
+instmap_delta_apply_sub(_Must, _Renaming, unreachable, unreachable).
+instmap_delta_apply_sub(Must, Renaming,
         reachable(OldInstMapping), reachable(InstMapping)) :-
     map.to_assoc_list(OldInstMapping, InstMappingAL),
-    instmap_delta_apply_sub_2(InstMappingAL, Must, Sub,
+    instmap_delta_apply_sub_2(InstMappingAL, Must, Renaming,
         map.init, InstMapping).
 
-apply_sub(Must, Sub, InstMap0, InstMap) :-
-    instmap_delta_apply_sub(Must, Sub, InstMap0, InstMap).
+apply_sub(Must, Renaming, InstMap0, InstMap) :-
+    instmap_delta_apply_sub(Must, Renaming, InstMap0, InstMap).
 
-:- pred instmap_delta_apply_sub_2(assoc_list(prog_var, mer_inst)::in, bool::in,
-    map(prog_var, prog_var)::in, instmapping::in, instmapping::out) is det.
-
-instmap_delta_apply_sub_2([], _Must, _Sub, IM, IM).
-instmap_delta_apply_sub_2([V - I | AL], Must, Sub, IM0, IM) :-
-    ( map.search(Sub, V, N0) ->
-        N = N0
-    ;
-        (
-            Must = no,
-            N = V
-        ;
-            Must = yes,
-            unexpected(this_file, "instmap_delta_apply_sub_2: no substitute")
-        )
-    ),
+:- pred instmap_delta_apply_sub_2(assoc_list(prog_var, mer_inst)::in,
+    must_rename::in, map(prog_var, prog_var)::in,
+    instmapping::in, instmapping::out) is det.
+
+instmap_delta_apply_sub_2([], _Must, _Renaming, !Instmapping).
+instmap_delta_apply_sub_2([Var0 - Inst | VarInsts0], Must, Renaming,
+        !Instmapping) :-
+    rename_var(Must, Renaming, Var0, Var),
     % XXX temporary hack alert XXX
-    % This should be a call to to map.det_insert, rather than a call
-    % to map.set. However, if we do that, then the compiler breaks,
-    % due to a problem with excess.m not preserving super-homogenous form.
-    map.set(IM0, N, I, IM1),
-    instmap_delta_apply_sub_2(AL, Must, Sub, IM1, IM).
+    % This should be a call to map.det_insert, rather than to map.set.
+    % However, if we do that, then the compiler breaks, due to a problem
+    % with excess.m not preserving super-homogenous form.
+    map.set(!.Instmapping, Var, Inst, !:Instmapping),
+    instmap_delta_apply_sub_2(VarInsts0, Must, Renaming, !Instmapping).
 
 %-----------------------------------------------------------------------------%
 
Index: compiler/interval.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/interval.m,v
retrieving revision 1.32
diff -u -r1.32 interval.m
--- compiler/interval.m	7 Aug 2007 07:09:56 -0000	1.32
+++ compiler/interval.m	28 Sep 2007 01:25:19 -0000
@@ -885,7 +885,7 @@
         GoalExpr0 = switch(Var0, Det, Cases0),
         record_decisions_in_cases(Cases0, Cases, !VarInfo, !.VarRename,
             InsertMap, MaybeFeature),
-        rename_var(no, !.VarRename, Var0, Var),
+        rename_var(need_not_rename, !.VarRename, Var0, Var),
         Goal1 = hlds_goal(switch(Var, Det, Cases), GoalInfo0),
         construct_anchors(branch_switch, Goal0, _StartAnchor, EndAnchor),
         lookup_inserts(InsertMap, EndAnchor, Inserts),
@@ -904,7 +904,7 @@
     ;
         GoalExpr0 = if_then_else(Vars0, Cond0, Then0, Else0),
         construct_anchors(branch_ite, Goal0, StartAnchor, EndAnchor),
-        rename_var_list(no, !.VarRename, Vars0, Vars),
+        rename_var_list(need_not_rename, !.VarRename, Vars0, Vars),
         record_decisions_in_goal(Cond0, Cond, !VarInfo, !VarRename, InsertMap,
             MaybeFeature),
         record_decisions_in_goal(Then0, Then, !VarInfo, !.VarRename, _,
@@ -925,7 +925,7 @@
         GoalExpr0 = scope(Reason0, SubGoal0),
         (
             Reason0 = exist_quant(Vars0),
-            rename_var_list(no, !.VarRename, Vars0, Vars),
+            rename_var_list(need_not_rename, !.VarRename, Vars0, Vars),
             Reason = exist_quant(Vars)
         ;
             Reason0 = promise_purity(_, _),
@@ -941,7 +941,7 @@
             Reason = Reason0
         ;
             Reason0 = from_ground_term(Var0),
-            rename_var(no, !.VarRename, Var0, Var),
+            rename_var(need_not_rename, !.VarRename, Var0, Var),
             Reason = from_ground_term(Var)
         ;
             Reason0 = trace_goal(_, _, _, _, _),
Index: compiler/lco.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/lco.m,v
retrieving revision 1.46
diff -u -r1.46 lco.m
--- compiler/lco.m	7 Aug 2007 07:09:57 -0000	1.46
+++ compiler/lco.m	27 Sep 2007 11:58:15 -0000
@@ -741,7 +741,7 @@
                 RHS0 = rhs_functor(RHSConsId, IsExistConstr, RHSVars0),
                 expect(unify(ConsId, RHSConsId), this_file,
                     "update_construct: cons_id mismatch"),
-                rename_var_list(no, Subst, RHSVars0, RHSVars),
+                rename_var_list(need_not_rename, Subst, RHSVars0, RHSVars),
                 RHS = rhs_functor(RHSConsId, IsExistConstr, RHSVars)
             ;
                 RHS0 = rhs_lambda_goal(_, _, _, _, _, _, _, _),
Index: compiler/prog_data.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/prog_data.m,v
retrieving revision 1.195
diff -u -r1.195 prog_data.m
--- compiler/prog_data.m	25 Sep 2007 04:56:40 -0000	1.195
+++ compiler/prog_data.m	28 Sep 2007 02:51:52 -0000
@@ -974,6 +974,7 @@
 :- type prog_var    ==  var(prog_var_type).
 :- type prog_varset ==  varset(prog_var_type).
 :- type prog_substitution ==    substitution(prog_var_type).
+:- type prog_var_renaming == map(prog_var, prog_var).
 :- type prog_term   ==  term(prog_var_type).
 :- type prog_vars   ==  list(prog_var).
 
@@ -981,6 +982,25 @@
     %
 :- type prog_context    ==  term.context.
 
+:- type must_rename
+    --->    must_rename
+    ;       need_not_rename.
+
+:- pred rename_vars_in_term(must_rename::in, map(var(V), var(V))::in,
+    term(V)::in, term(V)::out) is det.
+
+:- pred rename_vars_in_term_list(must_rename::in, map(var(V), var(V))::in,
+    list(term(V))::in, list(term(V))::out) is det.
+
+:- pred rename_vars_in_var_set(must_rename::in, prog_var_renaming::in,
+    set(prog_var)::in, set(prog_var)::out) is det.
+
+:- pred rename_var_list(must_rename::in, map(var(T), var(T))::in,
+    list(var(T))::in, list(var(T))::out) is det.
+
+:- pred rename_var(must_rename::in, map(var(V), var(V))::in,
+    var(V)::in, var(V)::out) is det.
+
 %-----------------------------------------------------------------------------%
 %
 % Cons ids
@@ -1992,6 +2012,56 @@
 
 %-----------------------------------------------------------------------------%
 %
+% Renaming
+%
+% The predicates here are similar to the "apply_variable_renaming" family of
+% predicates in library/term.m, but they allow the caller to specify that all
+% variables in the data structure being updated must appear in the renaming.
+
+rename_vars_in_term(Must, Renaming, Term0, Term) :-
+    (
+        Term0 = variable(Var0, Context),
+        rename_var(Must, Renaming, Var0, Var),
+        Term = variable(Var, Context)
+    ;
+        Term0 = functor(ConsId, Args0, Context),
+        rename_vars_in_term_list(Must, Renaming, Args0, Args),
+        Term = functor(ConsId, Args, Context)
+    ).
+
+rename_vars_in_term_list(_Must, _Renaming, [], []).
+rename_vars_in_term_list(Must, Renaming, [Term0 | Terms0], [Term | Terms]) :-
+    rename_vars_in_term(Must, Renaming, Term0, Term),
+    rename_vars_in_term_list(Must, Renaming, Terms0, Terms).
+
+rename_vars_in_var_set(Must, Renaming, Vars0, Vars) :-
+    set.to_sorted_list(Vars0, VarsList0),
+    rename_var_list(Must, Renaming, VarsList0, VarsList),
+    set.list_to_set(VarsList, Vars).
+
+rename_var_list(_Must, _Renaming, [], []).
+rename_var_list(Must, Renaming, [Var0 | Vars0], [Var | Vars]) :-
+    rename_var(Must, Renaming, Var0, Var),
+    rename_var_list(Must, Renaming, Vars0, Vars).
+
+rename_var(Must, Renaming, Var0, Var) :-
+    ( map.search(Renaming, Var0, VarPrime) ->
+        Var = VarPrime
+    ;
+        (
+            Must = need_not_rename,
+            Var = Var0
+        ;
+            Must = must_rename,
+            term.var_to_int(Var0, Var0Int),
+            string.format("rename_var: no substitute for var %i", [i(Var0Int)],
+                Msg),
+            unexpected(this_file, Msg)
+        )
+    ).
+
+%-----------------------------------------------------------------------------%
+%
 % Purity
 %
 
Index: compiler/prog_util.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/prog_util.m,v
retrieving revision 1.100
diff -u -r1.100 prog_util.m
--- compiler/prog_util.m	19 Jan 2007 07:04:28 -0000	1.100
+++ compiler/prog_util.m	26 Sep 2007 06:47:15 -0000
@@ -5,13 +5,13 @@
 % This file may only be copied under the terms of the GNU General
 % Public License - see the file COPYING in the Mercury distribution.
 %-----------------------------------------------------------------------------%
-% 
+%
 % File: prog_util.
 % Main author: fjh.
-% 
+%
 % Various utility predicates acting on the parse tree data structure defined
 % in prog_data.m and prog_item.m
-% 
+%
 %-----------------------------------------------------------------------------%
 
 :- module parse_tree.prog_util.
@@ -150,7 +150,7 @@
     ;       newpred_type_subst(tvarset, type_subst)
     ;       newpred_unused_args(list(int))
     ;       newpred_parallel_args(list(int))
-    ;       newpred_distance_granularity(int).          % Distance       
+    ;       newpred_distance_granularity(int).          % Distance
 
 %-----------------------------------------------------------------------------%
 
@@ -259,14 +259,6 @@
     tvar_name_map::in, tvar_name_map::out,
     tvar_renaming::in, tvar_renaming::out) is det.
 
-    % substitute_vars(Vars0, Subst, Vars):
-    %
-    % Apply substitution `Subst' (which must only rename vars) to `Vars0',
-    % and return the result in `Vars'.
-    %
-:- pred substitute_vars(list(var(T))::in, substitution(T)::in,
-    list(var(T))::out) is det.
-
 %-----------------------------------------------------------------------------%
 
     % We need to "unparse" the sym_name to construct the properly
@@ -788,21 +780,6 @@
 
 %-----------------------------------------------------------------------------%
 
-substitute_vars(Vars0, Subst, Vars) :-
-    Vars = list.map(substitute_var(Subst), Vars0).
-
-:- func substitute_var(substitution(T), var(T)) = var(T).
-
-substitute_var(Subst, Var0) = Var :-
-    term.apply_substitution(term.variable(Var0, context_init), Subst, Term),
-    ( Term = term.variable(Var1, _) ->
-        Var = Var1
-    ;
-        unexpected(this_file, "substitute_var: invalid substitution")
-    ).
-
-%-----------------------------------------------------------------------------%
-
 sym_name_and_args_to_term(unqualified(Name), Xs, Context) =
     term.functor(term.atom(Name), Xs, Context).
 
Index: compiler/quantification.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/quantification.m,v
retrieving revision 1.120
diff -u -r1.120 quantification.m
--- compiler/quantification.m	7 Aug 2007 07:10:03 -0000	1.120
+++ compiler/quantification.m	28 Sep 2007 01:23:54 -0000
@@ -375,10 +375,11 @@
         Context = goal_info_get_context(GoalInfo0),
         warn_overlapping_scope(RenameVars, Context, !Info),
         rename_apart(RenameVars, RenameMap, Goal0, Goal1, !Info),
-        rename_var_list(no, RenameMap, Vars0, Vars),
+        rename_var_list(need_not_rename, RenameMap, Vars0, Vars),
         (
             Reason1 = promise_solutions(PromiseVars0, Kind),
-            rename_var_list(no, RenameMap, PromiseVars0, PromiseVars),
+            rename_var_list(need_not_rename, RenameMap,
+                PromiseVars0, PromiseVars),
             Reason = promise_solutions(PromiseVars, Kind)
         ;
             Reason1 = exist_quant(_),
@@ -472,7 +473,7 @@
         warn_overlapping_scope(RenameVars, Context, !Info),
         rename_apart(RenameVars, RenameMap, Cond0, Cond1, !Info),
         rename_some_vars_in_goal(RenameMap, Then0, Then1),
-        rename_var_list(no, RenameMap, Vars0, Vars)
+        rename_var_list(need_not_rename, RenameMap, Vars0, Vars)
     ),
     insert_list(QuantVars, Vars, QuantVars1),
     get_nonlocals_to_recompute(!.Info, NonLocalsToRecompute),
@@ -752,7 +753,7 @@
 
     union(RenameVars0, RenameVars1, RenameVars),
     rename_apart(RenameVars, RenameMap, Goal0, Goal1, !Info),
-    rename_var_list(no, RenameMap, LambdaVars0, LambdaVars),
+    rename_var_list(need_not_rename, RenameMap, LambdaVars0, LambdaVars),
 
     % Quantified variables cannot be pushed inside a lambda goal,
     % so we insert the quantified vars into the outside vars set,
Index: compiler/simplify.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/simplify.m,v
retrieving revision 1.216
diff -u -r1.216 simplify.m
--- compiler/simplify.m	9 Aug 2007 05:28:26 -0000	1.216
+++ compiler/simplify.m	27 Sep 2007 11:45:08 -0000
@@ -2684,8 +2684,7 @@
         ;
             renaming_transitive_closure(Subn1, Subn),
             list.reverse(RevGoals, Goals1),
-            MustSub = no,
-            rename_vars_in_goals(MustSub, Subn, Goals1, Goals),
+            rename_vars_in_goals(need_not_rename, Subn, Goals1, Goals),
             map.keys(Subn0, RemovedVars),
             varset.delete_vars(VarSet0, RemovedVars, VarSet),
             simplify_info_set_varset(VarSet, !Info),
Index: compiler/structure_reuse.domain.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/structure_reuse.domain.m,v
retrieving revision 1.8
diff -u -r1.8 structure_reuse.domain.m
--- compiler/structure_reuse.domain.m	2 Aug 2007 01:24:01 -0000	1.8
+++ compiler/structure_reuse.domain.m	26 Sep 2007 06:47:26 -0000
@@ -17,7 +17,6 @@
 :- module transform_hlds.ctgc.structure_reuse.domain.
 :- interface.
 
-:- import_module hlds.hlds_goal.
 :- import_module hlds.hlds_module.
 :- import_module hlds.hlds_pred.
 :- import_module parse_tree.prog_data.
Index: compiler/unused_args.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/unused_args.m,v
retrieving revision 1.144
diff -u -r1.144 unused_args.m
--- compiler/unused_args.m	7 Aug 2007 07:10:09 -0000	1.144
+++ compiler/unused_args.m	27 Sep 2007 11:58:21 -0000
@@ -1516,7 +1516,7 @@
             ExtraArgs0, ExtraArgs, Subst1, Subst, !Info, ArgsChanged, Changed),
         GoalExpr = call_foreign_proc(Attributes, PredId, ProcId,
             Args, ExtraArgs, MaybeTraceRuntimeCond, Impl),
-        rename_vars_in_goal_info(no, Subst, GoalInfo0, GoalInfo),
+        rename_vars_in_goal_info(need_not_rename, Subst, GoalInfo0, GoalInfo),
         Goal = hlds_goal(GoalExpr, GoalInfo)
     ;
         GoalExpr0 = shorthand(_),
cvs diff: Diffing compiler/notes
cvs diff: Diffing debian
cvs diff: Diffing debian/patches
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/concurrency
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_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/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
Index: library/varset.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/varset.m,v
retrieving revision 1.81
diff -u -r1.81 varset.m
--- library/varset.m	21 Mar 2007 22:30:27 -0000	1.81
+++ library/varset.m	27 Sep 2007 11:17:06 -0000
@@ -141,35 +141,54 @@
 :- pred varset.lookup_vars(varset(T)::in, substitution(T)::out) is det.
 
     % Combine two different varsets, renaming apart:
-    % varset.merge(VarSet0, NewVarSet, VarSet, Subst) is
-    % true iff VarSet is the varset that results from joining
-    % a suitably renamed version of NewVarSet to VarSet0.
-    % (Any bindings in NewVarSet are ignored.)
-    % Subst is a substitution which maps the variables in NewVarSet
-    % into the corresponding fresh variable in VarSet.
+    % varset.merge_renaming(VarSet0, NewVarSet, VarSet, Subst) is true
+    % iff VarSet is the varset that results from joining a suitably renamed
+    % version of NewVarSet to VarSet0. (Any bindings in NewVarSet are ignored.)
+    % Renaming map the variables in NewVarSet into the corresponding
+    % fresh variable in VarSet.
+    %
+:- pred varset.merge_renaming(varset(T)::in, varset(T)::in, varset(T)::out,
+    map(var(T), var(T))::out) is det.
+
+    % Does the same job as varset.merge_renaming, but returns the renaming
+    % as a general substitution in which all the terms in the range happen
+    % to be variables.
+    %
+    % Consider using varset.merge_renaming instead.
     %
 :- pred varset.merge_subst(varset(T)::in, varset(T)::in, varset(T)::out,
     substitution(T)::out) is det.
 
     % varset.merge(VarSet0, NewVarSet, Terms0, VarSet, Terms):
-    % As varset.merge_subst, except instead of returning the substitution,
+    %
+    % As varset.merge_renaming, except instead of returning the renaming,
     % this predicate applies it to the given list of terms.
     %
 :- pred varset.merge(varset(T)::in, varset(T)::in, list(term(T))::in,
     varset(T)::out, list(term(T))::out) is det.
 
+    % Same as varset.merge_renaming, except that the names of variables
+    % in NewVarSet are not included in the final varset.
+    % This is useful if varset.create_name_var_map needs to be used
+    % on the resulting varset.
+    %
+:- pred varset.merge_renaming_without_names(varset(T)::in,
+    varset(T)::in, varset(T)::out, map(var(T), var(T))::out) is det.
+
     % Same as varset.merge_subst, except that the names of variables
     % in NewVarSet are not included in the final varset.
-    % This is useful if varset.create_name_var_map needs
-    % to be used on the resulting varset.
+    % This is useful if varset.create_name_var_map needs to be used
+    % on the resulting varset.
+    %
+    % Consider using varset.merge_renaming_without_names instead.
     %
 :- pred varset.merge_subst_without_names(varset(T)::in,
     varset(T)::in, varset(T)::out, substitution(T)::out) is det.
 
     % Same as varset.merge, except that the names of variables
     % in NewVarSet are not included in the final varset.
-    % This is useful if varset.create_name_var_map needs
-    % to be used on the resulting varset.
+    % This is useful if varset.create_name_var_map needs to be used
+    % on the resulting varset.
     %
 :- pred varset.merge_without_names(varset(T)::in, varset(T)::in,
     list(term(T))::in, varset(T)::out, list(term(T))::out) is det.
@@ -449,38 +468,92 @@
 
 varset.merge(VarSetA, VarSetB, TermList0, VarSet, TermList) :-
     IncludeNames = yes,
-    varset.merge_subst(IncludeNames, VarSetA, VarSetB, VarSet, Subst),
+    varset.merge_subst_inc(IncludeNames, VarSetA, VarSetB, VarSet, Subst),
     term.apply_substitution_to_list(TermList0, Subst, TermList).
 
 varset.merge_without_names(VarSetA, VarSetB, TermList0, VarSet, TermList) :-
     IncludeNames = no,
-    varset.merge_subst(IncludeNames, VarSetA, VarSetB, VarSet, Subst),
+    varset.merge_subst_inc(IncludeNames, VarSetA, VarSetB, VarSet, Subst),
     term.apply_substitution_to_list(TermList0, Subst, TermList).
 
+%-----------------------------------------------------------------------------%
+%
+% The structure of this code is identical to the structure of the code
+% in the next block.
+
+varset.merge_renaming(VarSetA, VarSetB, VarSet, Subst) :-
+    IncludeNames = yes,
+    varset.merge_renaming_inc(IncludeNames, VarSetA, VarSetB, VarSet, Subst).
+
+varset.merge_renaming_without_names(VarSetA, VarSetB, VarSet, Subst) :-
+    IncludeNames = no,
+    varset.merge_renaming_inc(IncludeNames, VarSetA, VarSetB, VarSet, Subst).
+
+:- pred varset.merge_renaming_inc(bool::in, varset(T)::in, varset(T)::in,
+    varset(T)::out, map(var(T), var(T))::out) is det.
+
+varset.merge_renaming_inc(IncludeNames, VarSetA, VarSetB, VarSet, Renaming) :-
+    VarSetB = varset(MaxId, Names, Values),
+    term.init_var_supply(N),
+    map.init(Renaming0),
+    varset.merge_renaming_inc_2(IncludeNames, N, MaxId, Names, Values,
+        VarSetA, VarSet, Renaming0, Renaming).
+
+:- pred varset.merge_renaming_inc_2(bool::in, var_supply(T)::in,
+    var_supply(T)::in, map(var(T), string)::in,
+    map(var(T), term(T))::in, varset(T)::in, varset(T)::out,
+    map(var(T), var(T))::in, map(var(T), var(T))::out) is det.
+
+varset.merge_renaming_inc_2(IncludeNames, N, Max, Names, Values, !VarSet,
+        !Renaming) :-
+    ( N = Max ->
+        true
+    ;
+        varset.new_var(!.VarSet, VarId, !:VarSet),
+        term.create_var(N, VarN, N1),
+        (
+            IncludeNames = yes,
+            map.search(Names, VarN, Name)
+        ->
+            varset.name_var(!.VarSet, VarId, Name, !:VarSet)
+        ;
+            true
+        ),
+        map.set(!.Renaming, VarN, VarId, !:Renaming),
+        varset.merge_renaming_inc_2(IncludeNames, N1, Max, Names, Values,
+            !VarSet, !Renaming)
+    ).
+
+%-----------------------------------------------------------------------------%
+%
+% The structure of this code is identical to the structure of the code
+% in the previous block.
+
 varset.merge_subst(VarSetA, VarSetB, VarSet, Subst) :-
     IncludeNames = yes,
-    varset.merge_subst(IncludeNames, VarSetA, VarSetB, VarSet, Subst).
+    varset.merge_subst_inc(IncludeNames, VarSetA, VarSetB, VarSet, Subst).
 
 varset.merge_subst_without_names(VarSetA, VarSetB, VarSet, Subst) :-
     IncludeNames = no,
-    varset.merge_subst(IncludeNames, VarSetA, VarSetB, VarSet, Subst).
+    varset.merge_subst_inc(IncludeNames, VarSetA, VarSetB, VarSet, Subst).
 
-:- pred varset.merge_subst(bool::in, varset(T)::in, varset(T)::in,
+:- pred varset.merge_subst_inc(bool::in, varset(T)::in, varset(T)::in,
     varset(T)::out, substitution(T)::out) is det.
 
-varset.merge_subst(IncludeNames, VarSetA, VarSetB, VarSet, Subst) :-
+varset.merge_subst_inc(IncludeNames, VarSetA, VarSetB, VarSet, Subst) :-
     VarSetB = varset(MaxId, Names, Values),
     term.init_var_supply(N),
     map.init(Subst0),
-    varset.merge_subst_2(IncludeNames, N, MaxId, Names, Values,
+    varset.merge_subst_inc_2(IncludeNames, N, MaxId, Names, Values,
         VarSetA, VarSet, Subst0, Subst).
 
-:- pred varset.merge_subst_2(bool::in, var_supply(T)::in,
+:- pred varset.merge_subst_inc_2(bool::in, var_supply(T)::in,
     var_supply(T)::in, map(var(T), string)::in,
     map(var(T), term(T))::in, varset(T)::in, varset(T)::out,
     substitution(T)::in, substitution(T)::out) is det.
 
-varset.merge_subst_2(IncludeNames, N, Max, Names, Values, !VarSet, !Subst) :-
+varset.merge_subst_inc_2(IncludeNames, N, Max, Names, Values, !VarSet,
+        !Subst) :-
     ( N = Max ->
         true
     ;
@@ -495,7 +568,7 @@
             true
         ),
         map.set(!.Subst, VarN, term.variable(VarId, context_init), !:Subst),
-        varset.merge_subst_2(IncludeNames, N1, Max, Names, Values,
+        varset.merge_subst_inc_2(IncludeNames, N1, Max, Names, Values,
             !VarSet, !Subst)
     ).
 
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/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/diff
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 tests
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/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/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
--------------------------------------------------------------------------
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