[m-rev.] diff: renaming to reduce ambiguities

Zoltan Somogyi zs at csse.unimelb.edu.au
Mon Oct 16 09:25:56 AEST 2006


browser/*.m:
compiler/*.m:
	Rename a bunch of predicates and function symbols to eliminate
	ambiguities.

	The only real change is factoring out some common code in the mlds
	and llds code generators, replacing them with single definitions
	in switch_util.m.

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
Index: browser/browse.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/browser/browse.m,v
retrieving revision 1.63
diff -u -r1.63 browse.m
--- browser/browse.m	25 Sep 2006 01:56:13 -0000	1.63
+++ browser/browse.m	13 Oct 2006 08:23:36 -0000
@@ -604,11 +604,11 @@
         run_param_command(Debugger, ParamCmd, yes, !Info, !IO),
         Quit = no
     ;
-        Command = cd,
+        Command = cd_no_path,
         set_path(root_rel([]), !Info),
         Quit = no
     ;
-        Command = cd(Path),
+        Command = cd_path(Path),
         change_dir(!.Info ^ dirs, Path, NewPwd),
         deref_subterm(!.Info ^ term, NewPwd, [], Result),
         (
Index: browser/browser_info.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/browser/browser_info.m,v
retrieving revision 1.30
diff -u -r1.30 browser_info.m
--- browser/browser_info.m	31 Aug 2006 11:09:47 -0000	1.30
+++ browser/browser_info.m	13 Oct 2006 07:06:22 -0000
@@ -147,20 +147,20 @@
             ).
 
 :- type setting
-    --->    depth(int)
-    ;       size(int)
-    ;       width(int)
-    ;       lines(int)
-    ;       format(portray_format).
+    --->    setting_depth(int)
+    ;       setting_size(int)
+    ;       setting_width(int)
+    ;       setting_lines(int)
+    ;       setting_format(portray_format).
 
-    % Initialise a new browser_info.  The optional portray_format
+    % Initialise a new browser_info. The optional portray_format
     % overrides the default format.
     %
 :- func init(browser_term, browse_caller_type,
     maybe(portray_format), maybe(browser_mode_func),
     browser_persistent_state) = browser_info.
 
-    % Get the format to use for the given caller type.  The optional
+    % Get the format to use for the given caller type. The optional
     % portray_format overrides the current default.
     %
 :- pred get_format(browser_info::in, browse_caller_type::in,
@@ -364,7 +364,8 @@
     "ML_BROWSE_set_depth_from_mdb").
 
 set_depth_from_mdb(P, B, A, F, Pr, V, NPr, Depth, !Browser) :-
-    set_browser_param(no, P, B, A, F, Pr, V, NPr,  depth(Depth), !Browser).
+    set_browser_param(no, P, B, A, F, Pr, V, NPr, setting_depth(Depth),
+        !Browser).
 
 :- pred set_size_from_mdb(bool::in, bool::in, bool::in, bool::in,
     bool::in, bool::in, bool::in, int::in,
@@ -374,7 +375,8 @@
     "ML_BROWSE_set_size_from_mdb").
 
 set_size_from_mdb(P, B, A, F, Pr, NPr, V, Size, !Browser) :-
-    set_browser_param(no, P, B, A, F, Pr, V, NPr, size(Size), !Browser).
+    set_browser_param(no, P, B, A, F, Pr, V, NPr, setting_size(Size),
+        !Browser).
 
 :- pred set_width_from_mdb(bool::in, bool::in, bool::in,
     bool::in, bool::in, bool::in, bool::in, int::in,
@@ -384,7 +386,8 @@
     "ML_BROWSE_set_width_from_mdb").
 
 set_width_from_mdb(P, B, A, F, Pr, V, NPr, Width, !Browser) :-
-    set_browser_param(no, P, B, A, F, Pr, V, NPr, width(Width), !Browser).
+    set_browser_param(no, P, B, A, F, Pr, V, NPr, setting_width(Width),
+        !Browser).
 
 :- pred set_lines_from_mdb(bool::in, bool::in, bool::in,
     bool::in, bool::in, bool::in, bool::in, int::in,
@@ -394,7 +397,8 @@
     "ML_BROWSE_set_lines_from_mdb").
 
 set_lines_from_mdb(P, B, A, F, Pr, V, NPr, Lines, !Browser) :-
-    set_browser_param(no, P, B, A, F, Pr, V, NPr, lines(Lines), !Browser).
+    set_browser_param(no, P, B, A, F, Pr, V, NPr, setting_lines(Lines),
+        !Browser).
 
 info_set_browse_param(OptionTable, Setting, !Info) :-
     PersistentState0 = !.Info ^ state,
@@ -426,7 +430,8 @@
 
 set_format_from_mdb(P, B, A, Format, !Browser) :-
     % Any format flags are ignored for this parameter.
-    set_browser_param(no, P, B, A, no, no, no, no, format(Format), !Browser).
+    set_browser_param(no, P, B, A, no, no, no, no, setting_format(Format),
+        !Browser).
 
 :- pragma foreign_export("C",
     get_num_io_actions(in, out),
@@ -768,7 +773,7 @@
 
 maybe_set_param(no, _, _, _, _, _, !Params).
 maybe_set_param(yes, F, Pr, V, NPr, Setting, !Params) :-
-    ( Setting = format(NewFormat) ->
+    ( Setting = setting_format(NewFormat) ->
         !:Params = !.Params ^ default_format := NewFormat
     ;
         Format0 = !.Params ^ default_format,
@@ -788,12 +793,12 @@
     format_params::in, format_params::out) is det.
 
 maybe_set_param_2(no, _, Params, Params).
-maybe_set_param_2(yes, depth(D), Params, Params ^ depth := D).
-maybe_set_param_2(yes, size(S), Params, Params ^ size := S).
-maybe_set_param_2(yes, format(_), _, _) :-
+maybe_set_param_2(yes, setting_depth(D), Params, Params ^ depth := D).
+maybe_set_param_2(yes, setting_size(S), Params, Params ^ size := S).
+maybe_set_param_2(yes, setting_format(_), _, _) :-
     error("maybe_set_param_2: cannot set format here").
-maybe_set_param_2(yes, width(W), Params, Params ^ width := W).
-maybe_set_param_2(yes, lines(L), Params, Params ^ lines := L).
+maybe_set_param_2(yes, setting_width(W), Params, Params ^ width := W).
+maybe_set_param_2(yes, setting_lines(L), Params, Params ^ lines := L).
 
 :- pred get_caller_params(browser_persistent_state::in, browse_caller_type::in,
     caller_params::out) is det.
Index: browser/declarative_oracle.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/browser/declarative_oracle.m,v
retrieving revision 1.54
diff -u -r1.54 declarative_oracle.m
--- browser/declarative_oracle.m	2 Oct 2006 05:21:03 -0000	1.54
+++ browser/declarative_oracle.m	13 Oct 2006 08:27:27 -0000
@@ -306,33 +306,36 @@
     oracle_kb_init(Old),
     user_state_init(InStr, OutStr, Browser, HelpSystem, User),
     % Trust the standard library by default.
-    bimap.set(bimap.init, standard_library, 0, Trusted),
+    bimap.set(bimap.init, trusted_standard_library, 0, Trusted),
     counter.init(1, Counter),
     Oracle = oracle(Current, Old, User, Trusted, Counter).
     
 %-----------------------------------------------------------------------------%
 
 :- type trusted_object
-    --->    module(module_name)
+    --->    trusted_module(module_name)
             % all predicates/functions in a module
 
-    ;       predicate(
+    ;       trusted_predicate(
                 module_name,
                 string,     % pred name
                 int         % arity
             )
 
-    ;       function(
+    ;       trusted_function(
                 module_name,
                 string,     % function name
                 int         % arity including return value
             )
 
-    ;       standard_library.
+    ;       trusted_standard_library.
 
 add_trusted_module(ModuleName, !Oracle) :-
     counter.allocate(Id, !.Oracle ^ trusted_id_counter, Counter),
-    ( bimap.insert(!.Oracle ^ trusted, module(ModuleName), Id, Trusted) ->
+    (
+        bimap.insert(!.Oracle ^ trusted, trusted_module(ModuleName), Id,
+            Trusted)
+    ->
         !:Oracle = !.Oracle ^ trusted := Trusted,
         !:Oracle = !.Oracle ^ trusted_id_counter := Counter
     ;
@@ -353,11 +356,11 @@
         (
             PredOrFunc = predicate,
             bimap.insert(!.Oracle ^ trusted,
-                predicate(ModuleName, Name, Arity), Id, Trusted)
+                trusted_predicate(ModuleName, Name, Arity), Id, Trusted)
         ;
             PredOrFunc = function,
             bimap.insert(!.Oracle ^ trusted,
-                function(ModuleName, Name, Arity), Id, Trusted)
+                trusted_function(ModuleName, Name, Arity), Id, Trusted)
         )
     ->
         !:Oracle = !.Oracle ^ trusted := Trusted,
@@ -368,7 +371,10 @@
 
 trust_standard_library(!Oracle) :-
     counter.allocate(Id, !.Oracle ^ trusted_id_counter, Counter),
-    ( bimap.insert(!.Oracle ^ trusted, standard_library, Id, Trusted) ->
+    (
+        bimap.insert(!.Oracle ^ trusted, trusted_standard_library, Id,
+            Trusted)
+    ->
         !:Oracle = !.Oracle ^ trusted_id_counter := Counter,
         !:Oracle = !.Oracle ^ trusted := Trusted
     ;
@@ -396,38 +402,40 @@
 :- pred format_trust_command(trusted_object::in, string::in, string::out)
     is det.
 
-format_trust_command(module(ModuleName),
+format_trust_command(trusted_module(ModuleName),
         S, S ++ "trust " ++ ModuleNameStr ++ "\n") :-
     ModuleNameStr = sym_name_to_string(ModuleName).
-format_trust_command(predicate(ModuleName, Name, Arity), S, S ++ Command) :-
+format_trust_command(trusted_predicate(ModuleName, Name, Arity),
+        S, S ++ Command) :-
     ArityStr = int_to_string(Arity),
     ModuleNameStr = sym_name_to_string(ModuleName),
     Command = "trust pred*" ++ ModuleNameStr ++ "." ++ Name ++ "/"
         ++ ArityStr ++ "\n".
-format_trust_command(function(ModuleName, Name, Arity), S, S ++ Command) :-
+format_trust_command(trusted_function(ModuleName, Name, Arity),
+        S, S ++ Command) :-
     ArityStr = int_to_string(Arity - 1),
     ModuleNameStr = sym_name_to_string(ModuleName),
     Command = "trust func*" ++ ModuleNameStr ++ "." ++ Name ++ "/"
         ++ ArityStr ++ "\n".
-format_trust_command(standard_library, S, S ++ "trust std lib\n").
+format_trust_command(trusted_standard_library, S, S ++ "trust std lib\n").
 
 :- pred format_trust_display(int::in, trusted_object::in, string::in, 
     string::out) is det.
 
-format_trust_display(Id, module(ModuleName), S, S ++ Display) :-
+format_trust_display(Id, trusted_module(ModuleName), S, S ++ Display) :-
     ModuleNameStr = sym_name_to_string(ModuleName),
     Display = int_to_string(Id) ++ ": module " ++ ModuleNameStr ++ "\n".
-format_trust_display(Id, predicate(ModuleName, Name, Arity),
+format_trust_display(Id, trusted_predicate(ModuleName, Name, Arity),
         S, S ++ Display) :-
     ModuleNameStr = sym_name_to_string(ModuleName),
     Display = int_to_string(Id) ++ ": predicate " ++ ModuleNameStr ++ "." 
         ++ Name ++ "/" ++ int_to_string(Arity) ++ "\n".
-format_trust_display(Id, function(ModuleName, Name, Arity),
+format_trust_display(Id, trusted_function(ModuleName, Name, Arity),
         S, S ++ Display) :-
     ModuleNameStr = sym_name_to_string(ModuleName),
     Display = int_to_string(Id) ++ ": function " ++ ModuleNameStr ++ "." ++
         Name ++ "/" ++ int_to_string(Arity - 1) ++ "\n".
-format_trust_display(Id, standard_library, S, S ++ Display) :-
+format_trust_display(Id, trusted_standard_library, S, S ++ Display) :-
     Display = int_to_string(Id) ++ ": the Mercury standard library\n".
         
 %-----------------------------------------------------------------------------%
@@ -523,7 +531,7 @@
     (
         ProcLabel = ordinary_proc_label(Module, PredOrFunc, _, Name, Arity, _),
         (
-            bimap.search(Trusted, standard_library, _),
+            bimap.search(Trusted, trusted_standard_library, _),
             (
                 Module = qualified(_, ModuleNameStr)
             ;
@@ -531,13 +539,13 @@
             ),
             mercury_std_library_module(ModuleNameStr)
         ;
-            bimap.search(Trusted, module(Module), _)
+            bimap.search(Trusted, trusted_module(Module), _)
         ;
             PredOrFunc = predicate,
-            bimap.search(Trusted, predicate(Module, Name, Arity), _)
+            bimap.search(Trusted, trusted_predicate(Module, Name, Arity), _)
         ;
             PredOrFunc = function,
-            bimap.search(Trusted, function(Module, Name, Arity), _)
+            bimap.search(Trusted, trusted_function(Module, Name, Arity), _)
         )
     ;
         ProcLabel = special_proc_label(_, _, _, _, _, _)
Index: browser/name_mangle.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/browser/name_mangle.m,v
retrieving revision 1.13
diff -u -r1.13 name_mangle.m
--- browser/name_mangle.m	20 Sep 2006 09:42:01 -0000	1.13
+++ browser/name_mangle.m	13 Oct 2006 08:35:49 -0000
@@ -5,12 +5,12 @@
 % This file may only be copied under the terms of the GNU Library General
 % Public License - see the file COPYING.LIB in the Mercury distribution.
 %-----------------------------------------------------------------------------%
-% 
+%
 % File: name_mangle.m.
 % Purpose: name mangling support.
 % Main author: fjh.
 % Stability: low.
-% 
+%
 % This module provides the proc_name_mangle/1 function, which takes a value of
 % type `mercury_proc' and returns a string which is the symbol name for
 % specified procedure, and which is suitable for use in a call to dl.sym.
@@ -20,7 +20,7 @@
 % in different Mercury implementations.  Any code which creates or
 % examines values of that type should be carefully isolated so that
 % it can be easily changed if the representation of `mercury_proc' changes.
-% 
+%
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
 
@@ -84,14 +84,14 @@
     ;
         llds_proc_name_mangle(MercuryProc)
     ).
-        
+
 :- func llds_proc_name_mangle(mercury_proc) = string.
 
 llds_proc_name_mangle(MercuryProc) = LabelName :-
     MercuryProc = mercury_proc(PredOrFunc, Module, Name0, Arity, ModeNum),
     sym_name_mangle(Module, ModuleName),
     (
-        ( 
+        (
             Module = unqualified("builtin")
         ;
             Name0 = "main",
@@ -163,7 +163,7 @@
     sym_name_mangle(ModuleName, MangledModuleName),
     name_mangle(PlainName, MangledPlainName),
     qualify_name(MangledModuleName, MangledPlainName, MangledName).
-    
+
     % Convert a Mercury predicate name into something that can form
     % part of a C identifier.  This predicate is necessary because
     % quoted names such as 'name with embedded spaces' are valid
@@ -188,7 +188,7 @@
 
 :- pred convert_to_valid_c_identifier(string::in, string::out) is det.
 
-convert_to_valid_c_identifier(String, Name) :-  
+convert_to_valid_c_identifier(String, Name) :-
     ( name_conversion_table(String, Name0) ->
         Name = Name0
     ;
@@ -201,8 +201,8 @@
 qualify_name(Module0, Name0, Name) :-
     string.append_list([Module0, "__", Name0], Name).
 
-    % A table used to convert Mercury functors into
-    % C identifiers.  Feel free to add any new translations you want.
+    % A table used to convert Mercury functors into C identifiers.
+    % Feel free to add any new translations you want.
     % The C identifiers should start with "f_",
     % to avoid introducing name clashes.
     % If the functor name is not found in the table, then
@@ -236,7 +236,7 @@
     %
 :- pred convert_to_valid_c_identifier_2(string::in, string::out) is det.
 
-convert_to_valid_c_identifier_2(String, Name) :-    
+convert_to_valid_c_identifier_2(String, Name) :-
     ( string.first_char(String, Char, Rest) ->
         char.to_int(Char, Code),
         string.int_to_string(Code, CodeString),
@@ -250,7 +250,8 @@
 
 :- pred use_asm_labels is semidet.
 
-:- pragma foreign_proc("C", use_asm_labels,
+:- pragma foreign_proc("C",
+    use_asm_labels,
     [will_not_call_mercury, promise_pure, thread_safe],
 "
 #ifdef MR_USE_ASM_LABELS
Index: browser/parse.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/browser/parse.m,v
retrieving revision 1.32
diff -u -r1.32 parse.m
--- browser/parse.m	20 Sep 2006 09:42:01 -0000	1.32
+++ browser/parse.m	13 Oct 2006 08:22:33 -0000
@@ -130,8 +130,8 @@
 
 :- type command
     --->    print(maybe(maybe_option_table(format_option)), maybe(path))
-    ;       cd(path)
-    ;       cd
+    ;       cd_path(path)
+    ;       cd_no_path
     ;       track(how_track_subterm, should_assert_invalid, maybe(path))
     ;       mode_query(path)
     ;       mode_query
@@ -388,11 +388,13 @@
         ; CmdToken = (^)
         )
     ->
-        ( ArgTokens = [] ->
-            Command = cd
+        (
+            ArgTokens = [],
+            Command = cd_no_path
         ;
+            ArgTokens = [_ | _],
             parse_path(ArgTokens, Path),
-            Command = cd(Path)
+            Command = cd_path(Path)
         )
     ;
         CmdToken = name("cdr")
@@ -401,7 +403,7 @@
         list.duplicate(Repetitions, TokenPath, DupTokenPath),
         list.condense(DupTokenPath, RepeatedTokenPath),
         parse_path(RepeatedTokenPath, RepeatedPath),
-        Command = cd(RepeatedPath)
+        Command = cd_path(RepeatedPath)
     ;
         CmdToken = name("pwd")
     ->
@@ -570,7 +572,8 @@
         OptionOps = option_ops_multi(short_format_param_cmd_option,
             long_format_param_cmd_option, format_param_cmd_option_defaults),
         getopt.process_options(OptionOps, [], _, MaybeOptionTable),
-        Command = param_command(format_param(MaybeOptionTable, depth(Depth)))
+        Command = param_command(format_param(MaybeOptionTable,
+            setting_depth(Depth)))
     ;
         fail
     ).
@@ -578,10 +581,10 @@
 :- pred param_cmd_to_setting(format_param_cmd::in, int::in, setting::out)
     is det.
 
-param_cmd_to_setting(param_depth, N, depth(N)).
-param_cmd_to_setting(param_size,  N, size(N)).
-param_cmd_to_setting(param_width, N, width(N)).
-param_cmd_to_setting(param_lines, N, lines(N)).
+param_cmd_to_setting(param_depth, N, setting_depth(N)).
+param_cmd_to_setting(param_size,  N, setting_size(N)).
+param_cmd_to_setting(param_width, N, setting_width(N)).
+param_cmd_to_setting(param_lines, N, setting_lines(N)).
 
 :- pred parse_path(list(token)::in, path::out) is semidet.
 
@@ -627,13 +630,13 @@
 
 parse_format([Fmt], Setting) :-
     ( Fmt = name("flat") ->
-        Setting = format(flat)
+        Setting = setting_format(flat)
     ; Fmt = name("raw_pretty") ->
-        Setting = format(raw_pretty)
+        Setting = setting_format(raw_pretty)
     ; Fmt = name("verbose") ->
-        Setting = format(verbose)
+        Setting = setting_format(verbose)
     ; Fmt = name("pretty") ->
-        Setting = format(pretty)
+        Setting = setting_format(pretty)
     ;
         fail
     ).
@@ -643,16 +646,16 @@
 parse_format_param([Token | Tokens], Setting) :-
     ( Token = name("depth") ->
         Tokens = [num(Depth)],
-        Setting = depth(Depth)
+        Setting = setting_depth(Depth)
     ; Token = name("size") ->
         Tokens = [num(Size)],
-        Setting = size(Size)
+        Setting = setting_size(Size)
     ; Token = name("width") ->
         Tokens = [num(X)],
-        Setting = width(X)
+        Setting = setting_width(X)
     ; Token = name("lines") ->
         Tokens = [num(Y)],
-        Setting = lines(Y)
+        Setting = setting_lines(Y)
     ;
         fail
     ).
@@ -752,11 +755,11 @@
 %   io.nl.
 % show_command(ls) -->
 %   io.write_string("ls\n").
-% show_command(cd(Path)) -->
+% show_command(cd_path(Path)) -->
 %   io.write_string("cd "),
 %   show_path(Path),
 %   io.nl.
-% show_command(cd) -->
+% show_command(cd_no_path) -->
 %   io.write_string("cd\n").
 % show_command(track(Path)) -->
 %   io.write_string("track "),
cvs diff: Diffing bytecode
cvs diff: Diffing compiler
Index: compiler/accumulator.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/accumulator.m,v
retrieving revision 1.63
diff -u -r1.63 accumulator.m
--- compiler/accumulator.m	22 Aug 2006 05:03:37 -0000	1.63
+++ compiler/accumulator.m	13 Oct 2006 07:35:54 -0000
@@ -1224,7 +1224,7 @@
         % Swap the arguments.
         [A, B] = set.to_sorted_list(Vars),
         map.from_assoc_list([A-B, B-A], Subst),
-        goal_util.rename_vars_in_goal(Subst, Goal, SwappedGoal),
+        goal_util.rename_some_vars_in_goal(Subst, Goal, SwappedGoal),
         CSGoal = SwappedGoal - InstMap
     ),
 
@@ -1565,7 +1565,7 @@
     U = create_new_orig_recursive_goals(UpdateBase, Update,
         HeadToCallSubst, UpdateSubst, C),
 
-    goal_util.rename_vars_in_goal(CallToHeadSubst, Call, BaseCall),
+    goal_util.rename_some_vars_in_goal(CallToHeadSubst, Call, BaseCall),
     Cbefore = goal_list(set.to_sorted_list(Before), C),
     Uupdate = goal_list(set.to_sorted_list(UpdateBase) ++
         set.to_sorted_list(Update), U),
@@ -1588,7 +1588,7 @@
     BaseIds = base(_UpdateBase, AssocBase, OtherBase),
     Sets = sets(Before, Assoc, ConstructAssoc, Construct, Update, _Reject),
 
-    goal_util.rename_vars_in_goal(RecCallSubst, Call, RecCall),
+    goal_util.rename_some_vars_in_goal(RecCallSubst, Call, RecCall),
 
     Cbefore = goal_list(set.to_sorted_list(Before), C),
 
@@ -1792,7 +1792,7 @@
     list.foldl(
         (pred(Id::in, GS0::in, GS::out) is det :-
             goal_store_lookup(From, Id, Goal0 - InstMap),
-            goal_util.rename_vars_in_goal(Subst, Goal0, Goal),
+            goal_util.rename_some_vars_in_goal(Subst, Goal0, Goal),
             goal_store_det_insert(Id, Goal - InstMap, GS0, GS)
         ), Ids, Initial, Final).
 
Index: compiler/basic_block.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/basic_block.m,v
retrieving revision 1.28
diff -u -r1.28 basic_block.m
--- compiler/basic_block.m	31 Jul 2006 08:31:28 -0000	1.28
+++ compiler/basic_block.m	13 Oct 2006 09:24:26 -0000
@@ -134,7 +134,7 @@
         RestInstrs = OrigInstrs0
     ;
         counter.allocate(N, !C),
-        Label = internal(N, ProcLabel),
+        Label = internal_label(N, ProcLabel),
         svset.insert(Label, !NewLabels),
         LabelInstr = label(Label) - "",
         RestInstrs = [OrigInstr0 | OrigInstrs0]
Index: compiler/call_gen.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/call_gen.m,v
retrieving revision 1.183
diff -u -r1.183 call_gen.m
--- compiler/call_gen.m	29 Sep 2006 06:34:47 -0000	1.183
+++ compiler/call_gen.m	13 Oct 2006 10:03:52 -0000
@@ -107,15 +107,14 @@
 
     % Make the call.
     code_info.get_module_info(!.CI, ModuleInfo),
-    Address = code_info.make_entry_label(!.CI, ModuleInfo,
-        PredId, ProcId, yes),
+    Address = make_proc_entry_label(!.CI, ModuleInfo, PredId, ProcId, yes),
     code_info.get_next_label(ReturnLabel, !CI),
     call_gen.call_comment(CodeModel, CallComment),
     goal_info_get_context(GoalInfo, Context),
     goal_info_get_goal_path(GoalInfo, GoalPath),
     CallCode = node([
         livevals(LiveVals) - "",
-        llcall(Address, label(ReturnLabel), ReturnLiveLvalues, Context,
+        llcall(Address, code_label(ReturnLabel), ReturnLiveLvalues, Context,
             GoalPath, CallModel) - CallComment,
         label(ReturnLabel) - "continuation label"
     ]),
@@ -228,7 +227,7 @@
 
     CallCode = node([
         livevals(LiveVals) - "",
-        llcall(CodeAddr, label(ReturnLabel), ReturnLiveLvalues,
+        llcall(CodeAddr, code_label(ReturnLabel), ReturnLiveLvalues,
             Context, GoalPath, CallModel) - "Setup and call",
         label(ReturnLabel) - "Continuation label"
     ]),
@@ -425,7 +424,7 @@
         ;
             code_info.get_next_label(ContLab, !CI),
             FailTestCode = node([
-                if_val(lval(reg(reg_r, 1)), label(ContLab))
+                if_val(lval(reg(reg_r, 1)), code_label(ContLab))
                     - "test for success"
             ]),
             code_info.generate_failure(FailCode, !CI),
Index: compiler/clause_to_proc.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/clause_to_proc.m,v
retrieving revision 1.72
diff -u -r1.72 clause_to_proc.m
--- compiler/clause_to_proc.m	1 Oct 2006 04:57:29 -0000	1.72
+++ compiler/clause_to_proc.m	13 Oct 2006 07:34:00 -0000
@@ -467,8 +467,8 @@
         make_new_exist_cast_var(HeadVar0, HeadVar, !VarSet),
         svmap.det_insert(HeadVar, ExternalType, !VarTypes),
         mode_get_insts(ModuleInfo, ArgMode, _, Inst),
-        generate_cast(exists_cast, HeadVar0, HeadVar, Inst, Inst, Context,
-            ExtraGoal),
+        generate_cast_with_insts(exists_cast, HeadVar0, HeadVar, Inst, Inst,
+            Context, ExtraGoal),
         !:ExtraGoals = [ExtraGoal | !.ExtraGoals]
     ;
         HeadVar = HeadVar0
Index: compiler/code_info.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/code_info.m,v
retrieving revision 1.332
diff -u -r1.332 code_info.m
--- compiler/code_info.m	29 Sep 2006 06:34:47 -0000	1.332
+++ compiler/code_info.m	13 Oct 2006 10:50:24 -0000
@@ -471,7 +471,7 @@
         MaybeFailVars = no,
         EffLiveness = Liveness
     ),
-    var_locn.init_state(ArgList, EffLiveness, VarSet, VarTypes, StackSlots,
+    init_var_locn_state(ArgList, EffLiveness, VarSet, VarTypes, StackSlots,
         FollowVars, Options, VarLocnInfo),
     stack.init(ResumePoints),
     globals.lookup_bool_option(Globals, allow_hijacks, AllowHijack),
@@ -682,7 +682,7 @@
     % type of the constructor), determine correct tag (representation)
     % of that constructor.
     %
-:- func cons_id_to_tag(code_info, prog_var, cons_id) = cons_tag.
+:- func cons_id_to_tag_for_var(code_info, prog_var, cons_id) = cons_tag.
 
     % Get the code model of the current procedure.
     %
@@ -726,7 +726,7 @@
     % we do not yet know which procedures will be put into the same
     % C functions, and so we cannot do this.
     %
-:- func make_entry_label(code_info, module_info, pred_id, proc_id, bool)
+:- func make_proc_entry_label(code_info, module_info, pred_id, proc_id, bool)
     = code_addr.
 
     % Generate the next local label in sequence.
@@ -768,19 +768,19 @@
 
 get_stack_slots(CI, StackSlots) :-
     get_var_locn_info(CI, VarLocnInfo),
-    var_locn.get_stack_slots(VarLocnInfo, StackSlots).
+    var_locn_get_stack_slots(VarLocnInfo, StackSlots).
 
 get_follow_var_map(CI, FollowVarMap) :-
     get_var_locn_info(CI, VarLocnInfo),
-    var_locn.get_follow_var_map(VarLocnInfo, FollowVarMap).
+    var_locn_get_follow_var_map(VarLocnInfo, FollowVarMap).
 
 get_next_non_reserved(CI, NextNonReserved) :-
     get_var_locn_info(CI, VarLocnInfo),
-    var_locn.get_next_non_reserved(VarLocnInfo, NextNonReserved).
+    var_locn_get_next_non_reserved(VarLocnInfo, NextNonReserved).
 
 set_follow_vars(FollowVars, !CI) :-
     get_var_locn_info(!.CI, VarLocnInfo0),
-    var_locn.set_follow_vars(FollowVars, VarLocnInfo0, VarLocnInfo),
+    var_locn_set_follow_vars(FollowVars, VarLocnInfo0, VarLocnInfo),
     set_var_locn_info(VarLocnInfo, !CI).
 
 %-----------------------------------------------------------------------------%
@@ -858,7 +858,7 @@
     module_info_get_type_table(ModuleInfo, TypeTable),
     map.lookup(TypeTable, TypeCtor, TypeDefn).
 
-cons_id_to_tag(CI, Var, ConsId) = ConsTag :-
+cons_id_to_tag_for_var(CI, Var, ConsId) = ConsTag :-
     get_module_info(CI, ModuleInfo),
     ConsTag = cons_id_to_tag(ConsId, variable_type(CI, Var), ModuleInfo).
 
@@ -899,20 +899,19 @@
 
 %---------------------------------------------------------------------------%
 
-make_entry_label(CI, ModuleInfo, PredId, ProcId, Immed0) = PredAddress :-
+make_proc_entry_label(CI, ModuleInfo, PredId, ProcId, Immed0) = CodeAddr :-
     (
         Immed0 = no,
         Immed = no
     ;
         Immed0 = yes,
         get_globals(CI, Globals),
-        globals.lookup_int_option(Globals, procs_per_c_function,
-            ProcsPerFunc),
+        globals.lookup_int_option(Globals, procs_per_c_function, ProcsPerFunc),
         get_pred_id(CI, CurPredId),
         get_proc_id(CI, CurProcId),
         Immed = yes(ProcsPerFunc - proc(CurPredId, CurProcId))
     ),
-    make_entry_label(ModuleInfo, PredId, ProcId, Immed, PredAddress).
+    CodeAddr = make_entry_label(ModuleInfo, PredId, ProcId, Immed).
 
 get_next_label(Label, !CI) :-
     get_module_info(!.CI, ModuleInfo),
@@ -921,7 +920,7 @@
     get_label_counter(!.CI, C0),
     counter.allocate(N, C0, C),
     set_label_counter(C, !CI),
-    make_internal_label(ModuleInfo, PredId, ProcId, N, Label).
+    Label = make_internal_label(ModuleInfo, PredId, ProcId, N).
 
 succip_is_used(!CI) :-
     set_succip_used(yes, !CI).
@@ -932,9 +931,9 @@
     Exec = yes(trace_port_layout_info(Context, Port, IsHidden, Path,
         MaybeSolverEventInfo, Layout)),
     (
-        Label = internal(LabelNum, _)
+        Label = internal_label(LabelNum, _)
     ;
-        Label = entry(_, _),
+        Label = entry_label(_, _),
         unexpected(this_file, "add_trace_layout_for_label: entry")
     ),
     ( map.search(Internals0, LabelNum, Internal0) ->
@@ -958,9 +957,9 @@
     get_layout_info(!.CI, Internals0),
     Resume = yes(LayoutInfo),
     (
-        Label = internal(LabelNum, _)
+        Label = internal_label(LabelNum, _)
     ;
-        Label = entry(_, _),
+        Label = entry_label(_, _),
         unexpected(this_file, "add_trace_layout_for_label: entry")
     ),
     ( map.search(Internals0, LabelNum, Internal0) ->
@@ -1188,7 +1187,7 @@
     map.to_assoc_list(StoreMap, VarLocns),
     VarLvals = assoc_list.map_values(key_abs_locn_to_lval, VarLocns),
     get_var_locn_info(!.CI, VarLocnInfo0),
-    var_locn.reinit_state(VarLvals, VarLocnInfo0, VarLocnInfo),
+    reinit_var_locn_state(VarLvals, VarLocnInfo0, VarLocnInfo),
     set_var_locn_info(VarLocnInfo, !CI).
 
 save_hp_in_branch(Code, Slot, Pos0, Pos) :-
@@ -2044,7 +2043,7 @@
 
     get_next_label(SuccLabel, !CI),
     GotoSuccLabel = node([
-        goto(label(SuccLabel)) - "Jump to success continuation"
+        goto(code_label(SuccLabel)) - "Jump to success continuation"
     ]),
     SuccLabelCode = node([
         label(SuccLabel) - "Success continuation"
@@ -2194,7 +2193,7 @@
             remember_position(!.CI, CurPos),
             pick_and_place_vars(AssocList, _, PlaceCode, !CI),
             reset_to_position(CurPos, !CI),
-            SuccessAddress = label(SuccessLabel),
+            SuccessAddress = code_label(SuccessLabel),
             % We branch away if the test *fails*, therefore if the test
             % succeeds, we branch around the code that moves variables to
             % their failure locations and branches away to the failure
@@ -2376,14 +2375,14 @@
     (
         CodeModel = model_det,
         get_next_label(ResumeLabel, !CI),
-        ResumeAddress = label(ResumeLabel),
+        ResumeAddress = code_label(ResumeLabel),
         ResumeKnown = resume_point_unknown,
         CurfrMaxfr = may_be_different
     ;
         CodeModel = model_semi,
         % The resume point for this label will be part of the procedure epilog.
         get_next_label(ResumeLabel, !CI),
-        ResumeAddress = label(ResumeLabel),
+        ResumeAddress = code_label(ResumeLabel),
         ResumeKnown = resume_point_known(wont_be_done),
         CurfrMaxfr = may_be_different
     ;
@@ -2391,7 +2390,7 @@
         (
             MaybeFailVars = yes(_),
             get_next_label(ResumeLabel, !CI),
-            ResumeAddress = label(ResumeLabel)
+            ResumeAddress = code_label(ResumeLabel)
         ;
             MaybeFailVars = no,
             ResumeAddress = do_fail
@@ -2429,29 +2428,29 @@
     (
         ResumeLocs = resume_locs_orig_only,
         get_next_label(OrigLabel, !CI),
-        OrigAddr = label(OrigLabel),
+        OrigAddr = code_label(OrigLabel),
         ResumePoint = orig_only(OrigMap, OrigAddr)
     ;
         ResumeLocs = resume_locs_stack_only,
         make_stack_resume_map(ResumeVars, StackSlots, StackMap),
         get_next_label(StackLabel, !CI),
-        StackAddr = label(StackLabel),
+        StackAddr = code_label(StackLabel),
         ResumePoint = stack_only(StackMap, StackAddr)
     ;
         ResumeLocs = resume_locs_orig_and_stack,
         make_stack_resume_map(ResumeVars, StackSlots, StackMap),
         get_next_label(OrigLabel, !CI),
-        OrigAddr = label(OrigLabel),
+        OrigAddr = code_label(OrigLabel),
         get_next_label(StackLabel, !CI),
-        StackAddr = label(StackLabel),
+        StackAddr = code_label(StackLabel),
         ResumePoint = orig_and_stack(OrigMap, OrigAddr, StackMap, StackAddr)
     ;
         ResumeLocs = resume_locs_stack_and_orig,
         make_stack_resume_map(ResumeVars, StackSlots, StackMap),
         get_next_label(StackLabel, !CI),
-        StackAddr = label(StackLabel),
+        StackAddr = code_label(StackLabel),
         get_next_label(OrigLabel, !CI),
-        OrigAddr = label(OrigLabel),
+        OrigAddr = code_label(OrigLabel),
         ResumePoint = stack_and_orig(StackMap, StackAddr, OrigMap, OrigAddr)
     ).
 
@@ -2556,7 +2555,7 @@
 :- pred extract_label_from_code_addr(code_addr::in, label::out) is det.
 
 extract_label_from_code_addr(CodeAddr, Label) :-
-    ( CodeAddr = label(Label0) ->
+    ( CodeAddr = code_label(Label0) ->
         Label = Label0
     ;
         unexpected(this_file, "extract_label_from_code_addr: non-label!")
@@ -2592,7 +2591,7 @@
     map.to_assoc_list(Map, LvalList0),
     flatten_varlval_list(LvalList0, LvalList),
     get_var_locn_info(!.CI, VarLocnInfo0),
-    var_locn.reinit_state(LvalList, VarLocnInfo0, VarLocnInfo),
+    reinit_var_locn_state(LvalList, VarLocnInfo0, VarLocnInfo),
     set_var_locn_info(VarLocnInfo, !CI).
 
 :- pred flatten_varlval_list(assoc_list(prog_var, set(lval))::in,
@@ -2678,21 +2677,21 @@
     ;
         ResumePoint0 = stack_only(Map1, _),
         get_next_label(Label1, !CI),
-        Addr1 = label(Label1),
+        Addr1 = code_label(Label1),
         ResumePoint = stack_only(Map1, Addr1)
     ;
         ResumePoint0 = stack_and_orig(Map1, _, Map2, _),
         get_next_label(Label1, !CI),
-        Addr1 = label(Label1),
+        Addr1 = code_label(Label1),
         get_next_label(Label2, !CI),
-        Addr2 = label(Label2),
+        Addr2 = code_label(Label2),
         ResumePoint = stack_and_orig(Map1, Addr1, Map2, Addr2)
     ;
         ResumePoint0 = orig_and_stack(Map1, _, Map2, _),
         get_next_label(Label2, !CI),
-        Addr2 = label(Label2),
+        Addr2 = code_label(Label2),
         get_next_label(Label1, !CI),
-        Addr1 = label(Label1),
+        Addr1 = code_label(Label1),
         ResumePoint = stack_and_orig(Map2, Addr2, Map1, Addr1)
     ).
 
@@ -2773,13 +2772,13 @@
         find_unused_reg(!.VarLocnInfo, N0, N1),
         Lval = reg(reg_r, N1)
     ),
-    var_locn.set_magic_var_location(Var, Lval, !VarLocnInfo),
+    var_locn_set_magic_var_location(Var, Lval, !VarLocnInfo),
     make_vars_forward_live_2(Vars, StackSlots, N1, !VarLocnInfo).
 
 :- pred find_unused_reg(var_locn_info::in, int::in, int::out) is det.
 
 find_unused_reg(VLI, N0, N) :-
-    ( var_locn.lval_in_use(VLI, reg(reg_r, N0)) ->
+    ( var_locn_lval_in_use(VLI, reg(reg_r, N0)) ->
         find_unused_reg(VLI, N0 + 1, N)
     ;
         N = N0
@@ -2807,7 +2806,7 @@
 maybe_make_vars_forward_dead_2([], _, !CI).
 maybe_make_vars_forward_dead_2([V | Vs], FirstTime, !CI) :-
     get_var_locn_info(!.CI, VarLocnInfo0),
-    var_locn.var_becomes_dead(V, FirstTime, VarLocnInfo0, VarLocnInfo),
+    var_locn_var_becomes_dead(V, FirstTime, VarLocnInfo0, VarLocnInfo),
     set_var_locn_info(VarLocnInfo, !CI),
     maybe_make_vars_forward_dead_2(Vs, FirstTime, !CI).
 
@@ -3220,7 +3219,7 @@
 
 variable_locations(CI, Lvals) :-
     get_var_locn_info(CI, VarLocnInfo),
-    var_locn.get_var_locations(VarLocnInfo, Lvals).
+    var_locn_get_var_locations(VarLocnInfo, Lvals).
 
 :- func rval_map_to_lval_map(prog_var, set(rval)) = set(lval).
 
@@ -3233,26 +3232,26 @@
 
 set_var_location(Var, Lval, !CI) :-
     get_var_locn_info(!.CI, VarLocnInfo0),
-    var_locn.check_and_set_magic_var_location(Var, Lval,
+    var_locn_check_and_set_magic_var_location(Var, Lval,
         VarLocnInfo0, VarLocnInfo),
     set_var_locn_info(VarLocnInfo, !CI).
 
 assign_var_to_var(Var, AssignedVar, !CI) :-
     get_var_locn_info(!.CI, VarLocnInfo0),
-    var_locn.assign_var_to_var(Var, AssignedVar, VarLocnInfo0, VarLocnInfo),
+    var_locn_assign_var_to_var(Var, AssignedVar, VarLocnInfo0, VarLocnInfo),
     set_var_locn_info(VarLocnInfo, !CI).
 
 assign_lval_to_var(Var, Lval, Code, !CI) :-
     get_var_locn_info(!.CI, VarLocnInfo0),
     get_static_cell_info(!.CI, StaticCellInfo),
     get_module_info(!.CI, ModuleInfo),
-    var_locn.assign_lval_to_var(ModuleInfo, Var, Lval, StaticCellInfo, Code,
+    var_locn_assign_lval_to_var(ModuleInfo, Var, Lval, StaticCellInfo, Code,
         VarLocnInfo0, VarLocnInfo),
     set_var_locn_info(VarLocnInfo, !CI).
 
 assign_const_to_var(Var, ConstRval, !CI) :-
     get_var_locn_info(!.CI, VarLocnInfo0),
-    var_locn.assign_const_to_var(Var, ConstRval, VarLocnInfo0, VarLocnInfo),
+    var_locn_assign_const_to_var(Var, ConstRval, VarLocnInfo0, VarLocnInfo),
     set_var_locn_info(VarLocnInfo, !CI).
 
 assign_expr_to_var(Var, Rval, Code, !CI) :-
@@ -3261,7 +3260,7 @@
         code_util.lvals_in_rval(Rval, Lvals),
         Lvals = []
     ->
-        var_locn.assign_expr_to_var(Var, Rval, Code,
+        var_locn_assign_expr_to_var(Var, Rval, Code,
         VarLocnInfo0, VarLocnInfo)
     ;
         unexpected(this_file, "assign_expr_to_var: non-var lvals")
@@ -3273,7 +3272,7 @@
     get_var_locn_info(!.CI, VarLocnInfo0),
     get_static_cell_info(!.CI, StaticCellInfo0),
     get_module_info(!.CI, ModuleInfo),
-    var_locn.assign_cell_to_var(ModuleInfo, Var, ReserveWordAtStart, Ptag,
+    var_locn_assign_cell_to_var(ModuleInfo, Var, ReserveWordAtStart, Ptag,
         Vector, MaybeSize, TypeMsg, MayUseAtomic, Code,
         StaticCellInfo0, StaticCellInfo, VarLocnInfo0, VarLocnInfo),
     set_static_cell_info(StaticCellInfo, !CI),
@@ -3282,7 +3281,7 @@
 place_var(Var, Lval, Code, !CI) :-
     get_var_locn_info(!.CI, VarLocnInfo0),
     get_module_info(!.CI, ModuleInfo),
-    var_locn.place_var(ModuleInfo, Var, Lval, Code,
+    var_locn_place_var(ModuleInfo, Var, Lval, Code,
         VarLocnInfo0, VarLocnInfo),
     set_var_locn_info(VarLocnInfo, !CI).
 
@@ -3316,34 +3315,34 @@
 place_vars(VarLocs, Code, !CI) :-
     get_var_locn_info(!.CI, VarLocnInfo0),
     get_module_info(!.CI, ModuleInfo),
-    var_locn.place_vars(ModuleInfo, VarLocs, Code, VarLocnInfo0, VarLocnInfo),
+    var_locn_place_vars(ModuleInfo, VarLocs, Code, VarLocnInfo0, VarLocnInfo),
     set_var_locn_info(VarLocnInfo, !CI).
 
 produce_variable(Var, Code, Rval, !CI) :-
     get_var_locn_info(!.CI, VarLocnInfo0),
     get_module_info(!.CI, ModuleInfo),
-    var_locn.produce_var(ModuleInfo, Var, Rval, Code,
+    var_locn_produce_var(ModuleInfo, Var, Rval, Code,
         VarLocnInfo0, VarLocnInfo),
     set_var_locn_info(VarLocnInfo, !CI).
 
 produce_variable_in_reg(Var, Code, Lval, !CI) :-
     get_var_locn_info(!.CI, VarLocnInfo0),
     get_module_info(!.CI, ModuleInfo),
-    var_locn.produce_var_in_reg(ModuleInfo, Var, Lval, Code,
+    var_locn_produce_var_in_reg(ModuleInfo, Var, Lval, Code,
         VarLocnInfo0, VarLocnInfo),
     set_var_locn_info(VarLocnInfo, !CI).
 
 produce_variable_in_reg_or_stack(Var, Code, Lval, !CI) :-
     get_var_locn_info(!.CI, VarLocnInfo0),
     get_module_info(!.CI, ModuleInfo),
-    var_locn.produce_var_in_reg_or_stack(ModuleInfo, Var, Lval, Code,
+    var_locn_produce_var_in_reg_or_stack(ModuleInfo, Var, Lval, Code,
         VarLocnInfo0, VarLocnInfo),
     set_var_locn_info(VarLocnInfo, !CI).
 
 materialize_vars_in_lval(Lval0, Lval, Code, !CI) :-
     get_var_locn_info(!.CI, VarLocnInfo0),
     get_module_info(!.CI, ModuleInfo),
-    var_locn.materialize_vars_in_lval(ModuleInfo, Lval0, Lval, Code,
+    var_locn_materialize_vars_in_lval(ModuleInfo, Lval0, Lval, Code,
         VarLocnInfo0, VarLocnInfo),
     set_var_locn_info(VarLocnInfo, !CI).
 
@@ -3356,12 +3355,12 @@
         PrefLocn = abs_reg(PrefRegNum),
         PrefRegNum >= 1
     ->
-        var_locn.acquire_reg_prefer_given(PrefRegNum, Lval,
+        var_locn_acquire_reg_prefer_given(PrefRegNum, Lval,
         VarLocnInfo0, VarLocnInfo)
     ;
         % XXX We should only get a register if the map.search
         % succeeded; otherwise we should put the var in its stack slot.
-        var_locn.acquire_reg_start_at_given(NextNonReserved, Lval,
+        var_locn_acquire_reg_start_at_given(NextNonReserved, Lval,
             VarLocnInfo0, VarLocnInfo)
     ),
     set_var_locn_info(VarLocnInfo, !CI).
@@ -3369,7 +3368,7 @@
 acquire_reg_not_in_storemap(StoreMap, Lval, !CI) :-
     map.foldl(record_highest_used_reg, StoreMap, 0, HighestUsedRegNum),
     get_var_locn_info(!.CI, VarLocnInfo0),
-    var_locn.acquire_reg_start_at_given(HighestUsedRegNum + 1, Lval,
+    var_locn_acquire_reg_start_at_given(HighestUsedRegNum + 1, Lval,
         VarLocnInfo0, VarLocnInfo),
     set_var_locn_info(VarLocnInfo, !CI).
 
@@ -3397,25 +3396,25 @@
 acquire_reg(Type, Lval, !CI) :-
     get_var_locn_info(!.CI, VarLocnInfo0),
     expect(unify(Type, reg_r), this_file, "acquire_reg: unknown reg type"),
-    var_locn.acquire_reg(Lval, VarLocnInfo0, VarLocnInfo),
+    var_locn_acquire_reg(Lval, VarLocnInfo0, VarLocnInfo),
     set_var_locn_info(VarLocnInfo, !CI).
 
 release_reg(Lval, !CI) :-
     get_var_locn_info(!.CI, VarLocnInfo0),
-    var_locn.release_reg(Lval, VarLocnInfo0, VarLocnInfo),
+    var_locn_release_reg(Lval, VarLocnInfo0, VarLocnInfo),
     set_var_locn_info(VarLocnInfo, !CI).
 
 reserve_r1(Code, !CI) :-
     get_var_locn_info(!.CI, VarLocnInfo0),
     get_module_info(!.CI, ModuleInfo),
-    var_locn.clear_r1(ModuleInfo, Code, VarLocnInfo0, VarLocnInfo1),
-    var_locn.acquire_reg_require_given(reg(reg_r, 1),
+    var_locn_clear_r1(ModuleInfo, Code, VarLocnInfo0, VarLocnInfo1),
+    var_locn_acquire_reg_require_given(reg(reg_r, 1),
         VarLocnInfo1, VarLocnInfo),
     set_var_locn_info(VarLocnInfo, !CI).
 
 clear_r1(empty, !CI) :-
     get_var_locn_info(!.CI, VarLocnInfo0),
-    var_locn.release_reg(reg(reg_r, 1), VarLocnInfo0, VarLocnInfo),
+    var_locn_release_reg(reg(reg_r, 1), VarLocnInfo0, VarLocnInfo),
     set_var_locn_info(VarLocnInfo, !CI).
 
 %---------------------------------------------------------------------------%
@@ -3460,7 +3459,7 @@
     get_var_locn_info(!.CI, VarLocnInfo0),
     var_arg_info_to_lval(InArgInfos, InArgLocs),
     list.append(RealStackVarLocs, InArgLocs, AllRealLocs),
-    var_locn.place_vars(ModuleInfo, DummyStackVarLocs ++ AllRealLocs, Code,
+    var_locn_place_vars(ModuleInfo, DummyStackVarLocs ++ AllRealLocs, Code,
         VarLocnInfo0, VarLocnInfo),
     set_var_locn_info(VarLocnInfo, !CI),
     assoc_list.values(AllRealLocs, LiveLocList),
@@ -3497,7 +3496,7 @@
     var_arg_info_to_lval(ArgsInfos, ArgsLocns),
     get_module_info(!.CI, ModuleInfo),
     get_var_locn_info(!.CI, VarLocnInfo0),
-    var_locn.place_vars(ModuleInfo, ArgsLocns, Code,
+    var_locn_place_vars(ModuleInfo, ArgsLocns, Code,
         VarLocnInfo0, VarLocnInfo1),
     set_var_locn_info(VarLocnInfo1, !CI),
     assoc_list.values(ArgsLocns, LiveLocList),
@@ -3541,22 +3540,22 @@
 
 lock_regs(N, Exceptions, !CI) :-
     get_var_locn_info(!.CI, VarLocnInfo0),
-    var_locn.lock_regs(N, Exceptions, VarLocnInfo0, VarLocnInfo),
+    var_locn_lock_regs(N, Exceptions, VarLocnInfo0, VarLocnInfo),
     set_var_locn_info(VarLocnInfo, !CI).
 
 unlock_regs(!CI) :-
     get_var_locn_info(!.CI, VarLocnInfo0),
-    var_locn.unlock_regs(VarLocnInfo0, VarLocnInfo),
+    var_locn_unlock_regs(VarLocnInfo0, VarLocnInfo),
     set_var_locn_info(VarLocnInfo, !CI).
 
 clear_all_registers(OkToDeleteAny, !CI) :-
     get_var_locn_info(!.CI, VarLocnInfo0),
-    var_locn.clobber_all_regs(OkToDeleteAny, VarLocnInfo0, VarLocnInfo),
+    var_locn_clobber_all_regs(OkToDeleteAny, VarLocnInfo0, VarLocnInfo),
     set_var_locn_info(VarLocnInfo, !CI).
 
 clobber_regs(Regs, !CI) :-
     get_var_locn_info(!.CI, VarLocnInfo0),
-    var_locn.clobber_regs(Regs, VarLocnInfo0, VarLocnInfo),
+    var_locn_clobber_regs(Regs, VarLocnInfo0, VarLocnInfo),
     set_var_locn_info(VarLocnInfo, !CI).
 
 save_variables(OutArgs, SavedLocs, Code, !CI) :-
@@ -3593,7 +3592,7 @@
 
 max_reg_in_use(CI, Max) :-
     get_var_locn_info(CI, VarLocnInfo),
-    var_locn.max_reg_in_use(VarLocnInfo, Max).
+    var_locn_max_reg_in_use(VarLocnInfo, Max).
 
 magically_put_var_in_unused_reg(Var, !CI) :-
     get_var_locn_info(!.CI, VarLocnInfo0),
Index: compiler/code_util.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/code_util.m,v
retrieving revision 1.175
diff -u -r1.175 code_util.m
--- compiler/code_util.m	26 Sep 2006 03:53:14 -0000	1.175
+++ compiler/code_util.m	13 Oct 2006 11:06:18 -0000
@@ -25,6 +25,7 @@
 :- import_module parse_tree.prog_data.
 
 :- import_module assoc_list.
+:- import_module bool.
 :- import_module list.
 :- import_module maybe.
 :- import_module pair.
@@ -40,11 +41,9 @@
     % the current procedure may make jumps more efficient.
     %
 :- type immed == maybe(pair(int, pred_proc_id)).
-:- pred make_entry_label(module_info::in, pred_id::in, proc_id::in, immed::in,
-    code_addr::out) is det.
+:- func make_entry_label(module_info, pred_id, proc_id, immed) = code_addr.
 
-:- pred make_entry_label_from_rtti(rtti_proc_label::in, immed::in,
-    code_addr::out) is det.
+:- func make_entry_label_from_rtti(rtti_proc_label, immed) = code_addr.
 
     % Create a label which holds the address of the specified procedure,
     % which must be defined in the current module (procedures that are
@@ -52,23 +51,20 @@
     % not as labels, since their address is not known at C compilation time).
     % The fourth argument has the same meaning as for make_entry_label.
     %
-:- pred make_local_entry_label(module_info::in, pred_id::in, proc_id::in,
-    immed::in, label::out) is det.
+:- func make_local_entry_label(module_info, pred_id, proc_id, immed) = label.
 
     % Create a label internal to a Mercury procedure.
     %
-:- pred make_internal_label(module_info::in, pred_id::in, proc_id::in, int::in,
-    label::out) is det.
+:- func make_internal_label(module_info, pred_id, proc_id, int) = label.
 
-:- pred extract_proc_label_from_code_addr(code_addr::in, proc_label::out)
-    is det.
+:- func extract_proc_label_from_code_addr(code_addr) = proc_label.
 
 :- pred arg_loc_to_register(arg_loc::in, lval::out) is det.
 
 :- pred max_mentioned_reg(list(lval)::in, int::out) is det.
 :- pred max_mentioned_abs_reg(list(abs_locn)::in, int::out) is det.
 
-:- pred goal_may_alloc_temp_frame(hlds_goal::in) is semidet.
+:- pred goal_may_alloc_temp_frame(hlds_goal::in, bool::out) is det.
 
     % Negate a condition.
     % This is used mostly just to make the generated code more readable.
@@ -106,7 +102,6 @@
 :- import_module libs.options.
 :- import_module parse_tree.prog_util.
 
-:- import_module bool.
 :- import_module char.
 :- import_module int.
 :- import_module set.
@@ -116,27 +111,26 @@
 
 %---------------------------------------------------------------------------%
 
-make_entry_label(ModuleInfo, PredId, ProcId, Immed, ProcAddr) :-
+make_entry_label(ModuleInfo, PredId, ProcId, Immed) = ProcAddr :-
     RttiProcLabel = rtti.make_rtti_proc_label(ModuleInfo, PredId, ProcId),
-    make_entry_label_from_rtti(RttiProcLabel, Immed, ProcAddr).
+    ProcAddr = make_entry_label_from_rtti(RttiProcLabel, Immed).
 
-make_entry_label_from_rtti(RttiProcLabel, Immed, ProcAddr) :-
+make_entry_label_from_rtti(RttiProcLabel, Immed) = ProcAddr :-
     ( RttiProcLabel ^ proc_is_imported = yes ->
         ProcLabel = make_proc_label_from_rtti(RttiProcLabel),
-        ProcAddr = imported(ProcLabel)
+        ProcAddr = code_imported_proc(ProcLabel)
     ;
-        make_local_entry_label_from_rtti(RttiProcLabel, Immed, Label),
-        ProcAddr = label(Label)
+        Label = make_local_entry_label_from_rtti(RttiProcLabel, Immed),
+        ProcAddr = code_label(Label)
     ).
 
-make_local_entry_label(ModuleInfo, PredId, ProcId, Immed, Label) :-
+make_local_entry_label(ModuleInfo, PredId, ProcId, Immed) = Label :-
     RttiProcLabel = rtti.make_rtti_proc_label(ModuleInfo, PredId, ProcId),
-    make_local_entry_label_from_rtti(RttiProcLabel, Immed, Label).
+    Label = make_local_entry_label_from_rtti(RttiProcLabel, Immed).
 
-:- pred make_local_entry_label_from_rtti(rtti_proc_label::in,
-    immed::in, label::out) is det.
+:- func make_local_entry_label_from_rtti(rtti_proc_label, immed) = label.
 
-make_local_entry_label_from_rtti(RttiProcLabel, Immed, Label) :-
+make_local_entry_label_from_rtti(RttiProcLabel, Immed) = Label :-
     ProcLabel = make_proc_label_from_rtti(RttiProcLabel),
     (
         Immed = no,
@@ -148,19 +142,18 @@
         ;
             EntryType = entry_label_local
         ),
-        Label = entry(EntryType, ProcLabel)
+        Label = entry_label(EntryType, ProcLabel)
     ;
         Immed = yes(ProcsPerFunc - proc(CurPredId, CurProcId)),
-        choose_local_label_type(ProcsPerFunc, CurPredId, CurProcId,
-            RttiProcLabel^pred_id, RttiProcLabel^proc_id,
-            ProcLabel, Label)
+        Label = choose_local_label_type(ProcsPerFunc, CurPredId, CurProcId,
+            RttiProcLabel ^ pred_id, RttiProcLabel ^ proc_id, ProcLabel)
     ).
 
-:- pred choose_local_label_type(int::in, pred_id::in, proc_id::in,
-    pred_id::in, proc_id::in, proc_label::in, label::out) is det.
+:- func choose_local_label_type(int, pred_id, proc_id, pred_id, proc_id,
+        proc_label) = label.
 
 choose_local_label_type(ProcsPerFunc, CurPredId, CurProcId,
-        PredId, ProcId, ProcLabel, Label) :-
+        PredId, ProcId, ProcLabel) = Label :-
     (
         % If we want to branch to the label now, we prefer a form that is
         % usable only within the current C module, since it is likely to be
@@ -176,18 +169,18 @@
     ;
         EntryType = entry_label_local
     ),
-    Label = entry(EntryType, ProcLabel).
+    Label = entry_label(EntryType, ProcLabel).
 
 %-----------------------------------------------------------------------------%
 
-make_internal_label(ModuleInfo, PredId, ProcId, LabelNum, Label) :-
+make_internal_label(ModuleInfo, PredId, ProcId, LabelNum) = Label :-
     ProcLabel = make_proc_label(ModuleInfo, PredId, ProcId),
-    Label = internal(LabelNum, ProcLabel).
+    Label = internal_label(LabelNum, ProcLabel).
 
-extract_proc_label_from_code_addr(CodeAddr, ProcLabel) :-
-    ( CodeAddr = label(Label) ->
+extract_proc_label_from_code_addr(CodeAddr) = ProcLabel :-
+    ( CodeAddr = code_label(Label) ->
         ProcLabel = get_proc_label(Label)
-    ; CodeAddr = imported(ProcLabelPrime) ->
+    ; CodeAddr = code_imported_proc(ProcLabelPrime) ->
         ProcLabel = ProcLabelPrime
     ;
         unexpected(this_file, "extract_label_from_code_addr failed")
@@ -229,11 +222,6 @@
 
 %-----------------------------------------------------------------------------%
 
-goal_may_alloc_temp_frame(Goal) :-
-    goal_may_alloc_temp_frame(Goal, yes).
-
-:- pred goal_may_alloc_temp_frame(hlds_goal::in, bool::out) is det.
-
 goal_may_alloc_temp_frame(Goal - _GoalInfo, May) :-
     goal_may_alloc_temp_frame_2(Goal, May).
 
Index: compiler/constraint.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/constraint.m,v
retrieving revision 1.81
diff -u -r1.81 constraint.m
--- compiler/constraint.m	1 Oct 2006 04:57:29 -0000	1.81
+++ compiler/constraint.m	13 Oct 2006 07:38:23 -0000
@@ -550,9 +550,9 @@
         !:Info = !.Info ^ varset := VarSet,
         !:Info = !.Info ^ vartypes := VarTypes,
         map.from_assoc_list([ConstructVar - NewVar], Subn),
-        rename_vars_in_goal(Subn, Construct0, Construct),
+        rename_some_vars_in_goal(Subn, Construct0, Construct),
         Constructs = [Construct | Constructs0],
-        rename_vars_in_goal(Subn, ConstraintGoal0, ConstraintGoal),
+        rename_some_vars_in_goal(Subn, ConstraintGoal0, ConstraintGoal),
         Constraint = constraint(ConstraintGoal, ChangedVars,
             IncompatibleInstVars, Constructs)
     ;
Index: compiler/continuation_info.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/continuation_info.m,v
retrieving revision 1.81
diff -u -r1.81 continuation_info.m
--- compiler/continuation_info.m	29 Sep 2006 06:34:48 -0000	1.81
+++ compiler/continuation_info.m	13 Oct 2006 09:24:46 -0000
@@ -440,7 +440,7 @@
     global_data_get_proc_layout(!.GlobalData, PredProcId, ProcLayoutInfo0),
     Internals0 = ProcLayoutInfo0^internal_map,
     GetCallInfo = (pred(Instr::in, Call::out) is semidet :-
-        Instr = llcall(Target, label(ReturnLabel), LiveInfo, Context,
+        Instr = llcall(Target, code_label(ReturnLabel), LiveInfo, Context,
             GoalPath, _) - _Comment,
         Call = call_info(ReturnLabel, Target, LiveInfo, Context, GoalPath)
     ),
@@ -468,9 +468,9 @@
     % but also that it belongs to the current procedure, but this would be
     % serious paranoia.
     (
-        ReturnLabel = internal(ReturnLabelNum, _)
+        ReturnLabel = internal_label(ReturnLabelNum, _)
     ;
-        ReturnLabel = entry(_, _),
+        ReturnLabel = entry_label(_, _),
         unexpected(this_file, "process_continuation: bad return")
     ),
     ( map.search(!.Internals, ReturnLabelNum, Internal0) ->
Index: compiler/cse_detection.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/cse_detection.m,v
retrieving revision 1.104
diff -u -r1.104 cse_detection.m
--- compiler/cse_detection.m	27 Sep 2006 06:16:50 -0000	1.104
+++ compiler/cse_detection.m	13 Oct 2006 07:34:21 -0000
@@ -594,7 +594,7 @@
         create_parallel_subterms(Args, Context, Ucontext, !CseInfo,
             OldNewVars, Replacements),
         map.from_assoc_list(OldNewVars, Sub),
-        goal_util.rename_vars_in_goal(Sub, GoalExpr1 - GoalInfo, HoistedGoal)
+        rename_some_vars_in_goal(Sub, GoalExpr1 - GoalInfo, HoistedGoal)
     ;
         unexpected(this_file, "non-unify goal in construct_common_unify")
     ).
Index: compiler/deep_profiling.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/deep_profiling.m,v
retrieving revision 1.56
diff -u -r1.56 deep_profiling.m
--- compiler/deep_profiling.m	2 Oct 2006 05:21:09 -0000	1.56
+++ compiler/deep_profiling.m	13 Oct 2006 11:00:43 -0000
@@ -576,21 +576,21 @@
 
     (
         MaybeActivationPtr = yes(ActivationPtr1),
-        generate_call(ModuleInfo, "det_call_port_code_sr", 4,
+        generate_deep_det_call(ModuleInfo, "det_call_port_code_sr", 4,
             [ProcStaticVar, TopCSD, MiddleCSD, ActivationPtr1],
             [TopCSD, MiddleCSD, ActivationPtr1], CallPortCode0),
         goal_add_feature(feature_save_deep_excp_vars,
             CallPortCode0, CallPortCode),
-        generate_call(ModuleInfo, "det_exit_port_code_sr", 3,
+        generate_deep_det_call(ModuleInfo, "det_exit_port_code_sr", 3,
             [TopCSD, MiddleCSD, ActivationPtr1], [], ExitPortCode)
     ;
         MaybeActivationPtr = no,
-        generate_call(ModuleInfo, "det_call_port_code_ac", 3,
+        generate_deep_det_call(ModuleInfo, "det_call_port_code_ac", 3,
             [ProcStaticVar, TopCSD, MiddleCSD],
             [TopCSD, MiddleCSD], CallPortCode0),
         goal_add_feature(feature_save_deep_excp_vars,
             CallPortCode0, CallPortCode),
-        generate_call(ModuleInfo, "det_exit_port_code_ac", 2,
+        generate_deep_det_call(ModuleInfo, "det_exit_port_code_ac", 2,
             [TopCSD, MiddleCSD], [], ExitPortCode)
     ),
 
@@ -670,27 +670,27 @@
 
     (
         MaybeActivationPtr = yes(ActivationPtr1),
-        generate_call(ModuleInfo, "semi_call_port_code_sr", 4,
+        generate_deep_det_call(ModuleInfo, "semi_call_port_code_sr", 4,
             [ProcStaticVar, TopCSD, MiddleCSD, ActivationPtr1],
             [TopCSD, MiddleCSD, ActivationPtr1], CallPortCode0),
         goal_add_feature(feature_save_deep_excp_vars,
             CallPortCode0, CallPortCode),
-        generate_call(ModuleInfo, "semi_exit_port_code_sr", 3,
+        generate_deep_det_call(ModuleInfo, "semi_exit_port_code_sr", 3,
             [TopCSD, MiddleCSD, ActivationPtr1], [], ExitPortCode),
-        generate_call(ModuleInfo, "semi_fail_port_code_sr", 3,
+        generate_deep_call(ModuleInfo, "semi_fail_port_code_sr", 3,
             [TopCSD, MiddleCSD, ActivationPtr1], no, detism_failure,
             FailPortCode),
         NewNonlocals = list_to_set([TopCSD, MiddleCSD, ActivationPtr1])
     ;
         MaybeActivationPtr = no,
-        generate_call(ModuleInfo, "semi_call_port_code_ac", 3,
+        generate_deep_det_call(ModuleInfo, "semi_call_port_code_ac", 3,
             [ProcStaticVar, TopCSD, MiddleCSD],
             [TopCSD, MiddleCSD], CallPortCode0),
         goal_add_feature(feature_save_deep_excp_vars,
             CallPortCode0, CallPortCode),
-        generate_call(ModuleInfo, "semi_exit_port_code_ac", 2,
+        generate_deep_det_call(ModuleInfo, "semi_exit_port_code_ac", 2,
             [TopCSD, MiddleCSD], [], ExitPortCode),
-        generate_call(ModuleInfo, "semi_fail_port_code_ac", 2,
+        generate_deep_call(ModuleInfo, "semi_fail_port_code_ac", 2,
             [TopCSD, MiddleCSD], no, detism_failure, FailPortCode),
         NewNonlocals = list_to_set([TopCSD, MiddleCSD])
     ),
@@ -774,36 +774,36 @@
 
     (
         MaybeOldActivationPtr = yes(OldOutermostProcDyn2),
-        generate_call(ModuleInfo, "non_call_port_code_sr", 5,
+        generate_deep_det_call(ModuleInfo, "non_call_port_code_sr", 5,
             [ProcStaticVar, TopCSD, MiddleCSD,
             OldOutermostProcDyn2, NewOutermostProcDyn],
             [TopCSD, MiddleCSD, OldOutermostProcDyn2, NewOutermostProcDyn],
             CallPortCode0),
         goal_add_feature(feature_save_deep_excp_vars,
             CallPortCode0, CallPortCode),
-        generate_call(ModuleInfo, "non_exit_port_code_sr", 3,
+        generate_deep_det_call(ModuleInfo, "non_exit_port_code_sr", 3,
             [TopCSD, MiddleCSD, OldOutermostProcDyn2], [],
             ExitPortCode),
-        generate_call(ModuleInfo, "non_fail_port_code_sr", 3,
+        generate_deep_call(ModuleInfo, "non_fail_port_code_sr", 3,
             [TopCSD, MiddleCSD, OldOutermostProcDyn2], no,
             detism_failure, FailPortCode),
-        generate_call(ModuleInfo, "non_redo_port_code_sr", 2,
+        generate_deep_call(ModuleInfo, "non_redo_port_code_sr", 2,
             [MiddleCSD, NewOutermostProcDyn], no,
             detism_failure, RedoPortCode0),
         NewNonlocals = list_to_set([TopCSD, MiddleCSD, OldOutermostProcDyn2])
     ;
         MaybeOldActivationPtr = no,
-        generate_call(ModuleInfo, "non_call_port_code_ac", 4,
+        generate_deep_det_call(ModuleInfo, "non_call_port_code_ac", 4,
             [ProcStaticVar, TopCSD, MiddleCSD, NewOutermostProcDyn],
             [TopCSD, MiddleCSD, NewOutermostProcDyn],
             CallPortCode0),
         goal_add_feature(feature_save_deep_excp_vars,
             CallPortCode0, CallPortCode),
-        generate_call(ModuleInfo, "non_exit_port_code_ac", 2,
+        generate_deep_det_call(ModuleInfo, "non_exit_port_code_ac", 2,
             [TopCSD, MiddleCSD], [], ExitPortCode),
-        generate_call(ModuleInfo, "non_fail_port_code_ac", 2,
+        generate_deep_call(ModuleInfo, "non_fail_port_code_ac", 2,
             [TopCSD, MiddleCSD], no, detism_failure, FailPortCode),
-        generate_call(ModuleInfo, "non_redo_port_code_ac", 2,
+        generate_deep_call(ModuleInfo, "non_redo_port_code_ac", 2,
             [MiddleCSD, NewOutermostProcDyn], no,
             detism_failure, RedoPortCode0),
         NewNonlocals = list_to_set([TopCSD, MiddleCSD])
@@ -1107,10 +1107,10 @@
     (
         CallKind = normal(PredProcId),
         ( set.member(feature_tailcall, GoalFeatures) ->
-            generate_call(ModuleInfo, "prepare_for_tail_call", 1,
+            generate_deep_det_call(ModuleInfo, "prepare_for_tail_call", 1,
                 [SiteNumVar], [], PrepareGoal)
         ;
-            generate_call(ModuleInfo, "prepare_for_normal_call", 1,
+            generate_deep_det_call(ModuleInfo, "prepare_for_normal_call", 1,
                 [SiteNumVar], [], PrepareGoal)
         ),
         PredProcId = proc(PredId, ProcId),
@@ -1142,7 +1142,7 @@
         Goal2 = Goal1
     ;
         CallKind = special(_PredProcId, TypeInfoVar),
-        generate_call(ModuleInfo, "prepare_for_special_call", 2,
+        generate_deep_det_call(ModuleInfo, "prepare_for_special_call", 2,
             [SiteNumVar, TypeInfoVar], [], PrepareGoal),
         CallSite = special_call(FileName, LineNumber, GoalPath),
         Goal2 = Goal1
@@ -1150,7 +1150,7 @@
         CallKind = generic(Generic),
         (
             Generic = higher_order(ClosureVar, _, _, _),
-            generate_call(ModuleInfo, "prepare_for_ho_call", 2,
+            generate_deep_det_call(ModuleInfo, "prepare_for_ho_call", 2,
                 [SiteNumVar, ClosureVar], [], PrepareGoal),
             CallSite = higher_order_call(FileName, LineNumber, GoalPath)
         ;
@@ -1162,7 +1162,7 @@
                 MethodNumVarGoal),
             !:DeepInfo = ((!.DeepInfo ^ vars := VarSet2)
                 ^ var_types := VarTypes2),
-            generate_call(ModuleInfo, "prepare_for_method_call", 3,
+            generate_deep_det_call(ModuleInfo, "prepare_for_method_call", 3,
                 [SiteNumVar, TypeClassInfoVar, MethodNumVar],
                 [], PrepareCallGoal),
             PrepareCallGoal = _ - PrepareCallGoalInfo,
@@ -1284,14 +1284,14 @@
         !:DeepInfo = !.DeepInfo ^ var_types := VarTypes,
         ExtraNonLocals = set.list_to_set([SavedCountVar, SavedPtrVar]),
 
-        generate_call(!.DeepInfo ^ module_info,
+        generate_deep_det_call(!.DeepInfo ^ module_info,
             "save_and_zero_activation_info_ac", 2,
             [SavedCountVar, SavedPtrVar],
             [SavedCountVar, SavedPtrVar], SaveStuff),
-        generate_call(!.DeepInfo ^ module_info,
+        generate_deep_det_call(!.DeepInfo ^ module_info,
             "reset_activation_info_ac", 2,
             [SavedCountVar, SavedPtrVar], [], RestoreStuff),
-        generate_call(!.DeepInfo ^ module_info,
+        generate_deep_det_call(!.DeepInfo ^ module_info,
             "rezero_activation_info_ac", 0,
             [], [], ReZeroStuff)
     ;
@@ -1301,13 +1301,13 @@
         !:DeepInfo = !.DeepInfo ^ var_types := VarTypes1,
         ExtraNonLocals = set.list_to_set([SavedPtrVar]),
 
-        generate_call(!.DeepInfo ^ module_info,
+        generate_deep_det_call(!.DeepInfo ^ module_info,
             "save_and_zero_activation_info_sr", 1,
             [SavedPtrVar], [SavedPtrVar], SaveStuff),
-        generate_call(!.DeepInfo ^ module_info,
+        generate_deep_det_call(!.DeepInfo ^ module_info,
             "reset_activation_info_sr", 1,
             [SavedPtrVar], [], RestoreStuff),
-        generate_call(!.DeepInfo ^ module_info,
+        generate_deep_det_call(!.DeepInfo ^ module_info,
             "rezero_activation_info_sr", 0,
             [], [], ReZeroStuff)
     ),
@@ -1388,7 +1388,7 @@
     map.set(!.DeepInfo ^ var_types, SiteNumVar, int_type, VarTypes),
     generate_unify(int_const(SiteNum), SiteNumVar, SiteNumVarGoal),
 
-    generate_call(ModuleInfo, "prepare_for_callback", 1,
+    generate_deep_det_call(ModuleInfo, "prepare_for_callback", 1,
         [SiteNumVar], [], PrepareGoal),
 
     goal_info_get_context(GoalInfo0, Context),
@@ -1515,11 +1515,11 @@
     FailPredName = string.format("restore_recursion_depth_fail_%d",
         [i(Length)]),
     ModuleInfo = !.DeepInfo ^ module_info,
-    generate_call(ModuleInfo, CallPredName, Length + 2,
+    generate_deep_det_call(ModuleInfo, CallPredName, Length + 2,
         [CSDVar, CallCellVar | DepthVars], DepthVars, CallCellGoal),
-    generate_call(ModuleInfo, ExitPredName, Length + 2,
+    generate_deep_det_call(ModuleInfo, ExitPredName, Length + 2,
         [CSDVar, ExitCellVar | DepthVars], [], ExitCellGoal),
-    generate_call(ModuleInfo, FailPredName, Length + 2,
+    generate_deep_det_call(ModuleInfo, FailPredName, Length + 2,
         [CSDVar, FailCellVar | DepthVars], [], FailCellGoal),
 
     generate_recursion_counter_saves_and_restores_2(Chunks, CSDVar,
@@ -1596,17 +1596,18 @@
     !:DeepInfo = !.DeepInfo ^ var_types := VarTypes,
     generate_unify(int_const(CSN), CSNVar, UnifyGoal).
 
-:- pred generate_call(module_info::in, string::in, int::in,
+:- pred generate_deep_det_call(module_info::in, string::in, int::in,
     list(prog_var)::in, list(prog_var)::in, hlds_goal::out) is det.
 
-generate_call(ModuleInfo, Name, Arity, ArgVars, OutputVars, Goal) :-
-    generate_call(ModuleInfo, Name, Arity, ArgVars, yes(OutputVars),
+generate_deep_det_call(ModuleInfo, Name, Arity, ArgVars, OutputVars, Goal) :-
+    generate_deep_call(ModuleInfo, Name, Arity, ArgVars, yes(OutputVars),
         detism_det, Goal).
 
-:- pred generate_call(module_info::in, string::in, int::in, list(prog_var)::in,
-    maybe(list(prog_var))::in, determinism::in, hlds_goal::out) is det.
+:- pred generate_deep_call(module_info::in, string::in, int::in,
+    list(prog_var)::in, maybe(list(prog_var))::in, determinism::in,
+    hlds_goal::out) is det.
 
-generate_call(ModuleInfo, Name, Arity, ArgVars, MaybeOutputVars, Detism,
+generate_deep_call(ModuleInfo, Name, Arity, ArgVars, MaybeOutputVars, Detism,
         Goal) :-
     get_deep_profile_builtin_ppid(ModuleInfo, Name, Arity, PredId, ProcId),
     NonLocals = list_to_set(ArgVars),
@@ -1621,9 +1622,10 @@
         MaybeOutputVars = no,
         instmap_delta_init_unreachable(InstMapDelta)
     ),
+    SymName = unqualified(Name),
+    GoalExpr = plain_call(PredId, ProcId, ArgVars, not_builtin, no, SymName),
     GoalInfo = impure_init_goal_info(NonLocals, InstMapDelta, Detism),
-    Goal = plain_call(PredId, ProcId, ArgVars, not_builtin, no,
-        unqualified(Name)) - GoalInfo.
+    Goal = GoalExpr - GoalInfo.
 
 :- pred generate_unify(cons_id::in, prog_var::in, hlds_goal::out) is det.
 
Index: compiler/deforest.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/deforest.m,v
retrieving revision 1.75
diff -u -r1.75 deforest.m
--- compiler/deforest.m	13 Oct 2006 04:52:17 -0000	1.75
+++ compiler/deforest.m	13 Oct 2006 07:44:48 -0000
@@ -879,7 +879,7 @@
         ( list.member(OtherGoal, BetweenGoals)
         ; MaybeLaterGoal = yes(LaterGoal), OtherGoal = LaterGoal
         ),
-        \+ goal_util.reordering_maintains_termination(ModuleInfo,
+        \+ goal_util.reordering_maintains_termination_old(ModuleInfo,
             FullyStrict, EarlierGoal, OtherGoal)
     ->
         pd_debug_message("interleaving execution could change " ++
Index: compiler/dense_switch.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/dense_switch.m,v
retrieving revision 1.63
diff -u -r1.63 dense_switch.m
--- compiler/dense_switch.m	22 Aug 2006 05:03:42 -0000	1.63
+++ compiler/dense_switch.m	13 Oct 2006 10:45:59 -0000
@@ -32,8 +32,9 @@
     % (we may convert locally semidet switches into locally det
     % switches by adding extra cases whose body is just `fail').
     %
-:- pred is_dense_switch(code_info::in, prog_var::in, cases_list::in,
-    can_fail::in, int::in, int::out, int::out, can_fail::out) is semidet.
+:- pred cases_list_is_dense_switch(code_info::in, prog_var::in,
+    cases_list::in, can_fail::in, int::in, int::out, int::out, can_fail::out)
+    is semidet.
 
     % Generate code for a switch using a dense jump table.
     %
@@ -44,10 +45,6 @@
 
     % Also used by lookup_switch.
     %
-:- pred calc_density(int::in, int::in, int::out) is det.
-
-    % Also used by lookup_switch.
-    %
 :- pred type_range(code_info::in, type_category::in, mer_type::in, int::out)
     is semidet.
 
@@ -74,7 +71,7 @@
 
 %-----------------------------------------------------------------------------%
 
-is_dense_switch(CI, CaseVar, TaggedCases, CanFail0, ReqDensity,
+cases_list_is_dense_switch(CI, CaseVar, TaggedCases, CanFail0, ReqDensity,
         FirstVal, LastVal, CanFail) :-
     list.length(TaggedCases, NumCases),
     NumCases > 2,
@@ -84,7 +81,7 @@
     LastCase = extended_case(_, int_tag(LastCaseVal), _, _),
     Span = LastCaseVal - FirstCaseVal,
     Range = Span + 1,
-    dense_switch.calc_density(NumCases, Range, Density),
+    Density = switch_density(NumCases, Range),
     Density > ReqDensity,
     ( CanFail0 = can_fail ->
         % For semidet switches, we normally need to check that the variable
@@ -96,7 +93,7 @@
         classify_type(ModuleInfo, Type) = TypeCategory,
         (
             dense_switch.type_range(CI, TypeCategory, Type, TypeRange),
-            dense_switch.calc_density(NumCases, TypeRange, DetDensity),
+            DetDensity = switch_density(NumCases, TypeRange),
             DetDensity > ReqDensity
         ->
             CanFail = cannot_fail,
@@ -115,14 +112,6 @@
 
 %---------------------------------------------------------------------------%
 
-    % Calculate the percentage density given the range and the number of cases.
-    %
-calc_density(NumCases, Range, Density) :-
-    N1 = NumCases * 100,
-    Density = N1 // Range.
-
-%---------------------------------------------------------------------------%
-
     % Determine the range of an atomic type. Fail if the type isn't the sort
     % of type that has a range or if the type's range is to big to switch on
     % (e.g. int).
@@ -190,7 +179,7 @@
             label(ThisLabel) - Comment
         ]),
         JumpCode = node([
-            goto(label(EndLabel)) - "branch to end of dense switch"
+            goto(code_label(EndLabel)) - "branch to end of dense switch"
         ]),
         % Generate the rest of the cases.
         NextVal1 = NextVal + 1,
Index: compiler/dep_par_conj.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/dep_par_conj.m,v
retrieving revision 1.11
diff -u -r1.11 dep_par_conj.m
--- compiler/dep_par_conj.m	31 Aug 2006 08:43:33 -0000	1.11
+++ compiler/dep_par_conj.m	13 Oct 2006 07:36:16 -0000
@@ -1561,9 +1561,8 @@
     set.difference(DontRename0, Intersect) = DontRename,
 
     create_variables(set.to_sorted_list(DoRename),
-        !.VarSet, !.VarTypes,
-        !VarSet, !VarTypes, map.init, Renaming),
-    rename_vars_in_goal(Renaming, Goal0, Goal).
+        !.VarSet, !.VarTypes, !VarSet, !VarTypes, map.init, Renaming),
+    rename_some_vars_in_goal(Renaming, Goal0, Goal).
 
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
Index: compiler/det_analysis.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/det_analysis.m,v
retrieving revision 1.201
diff -u -r1.201 det_analysis.m
--- compiler/det_analysis.m	13 Oct 2006 04:52:17 -0000	1.201
+++ compiler/det_analysis.m	13 Oct 2006 08:14:51 -0000
@@ -221,7 +221,7 @@
             io.write_string("% Inferred " ++ ChangeStr ++ " detism ", !IO),
             mercury_output_det(NewDetism, !IO),
             io.write_string(" for ", !IO),
-            hlds_out.write_pred_proc_id(!.ModuleInfo, PredId, ProcId, !IO),
+            write_pred_proc_id_pair(!.ModuleInfo, PredId, ProcId, !IO),
             io.write_string("\n", !IO)
         )
     ;
Index: compiler/disj_gen.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/disj_gen.m,v
retrieving revision 1.97
diff -u -r1.97 disj_gen.m
--- compiler/disj_gen.m	18 Sep 2006 03:16:01 -0000	1.97
+++ compiler/disj_gen.m	13 Oct 2006 08:41:08 -0000
@@ -271,7 +271,7 @@
             SaveCode, !CI),
 
         BranchCode = node([
-            goto(label(EndLabel)) - "skip to end of nondet disj"
+            goto(code_label(EndLabel)) - "skip to end of nondet disj"
         ]),
 
         disj_gen.generate_disjuncts(Goals, CodeModel, FullResumeMap,
Index: compiler/dupelim.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/dupelim.m,v
retrieving revision 1.84
diff -u -r1.84 dupelim.m
--- compiler/dupelim.m	26 Sep 2006 03:53:14 -0000	1.84
+++ compiler/dupelim.m	13 Oct 2006 08:41:59 -0000
@@ -295,8 +295,8 @@
     standardize_instrs(Instrs0, Uinstrs1),
     (
         MaybeFallThrough = yes(Label),
-        Goto = goto(label(Label)),
-        list.append(Uinstrs1, [Goto], Uinstrs)
+        Goto = goto(code_label(Label)),
+        Uinstrs = Uinstrs1 ++ [Goto]
     ;
         MaybeFallThrough = no,
         Uinstrs = Uinstrs1
@@ -516,12 +516,12 @@
         MaybeFallThrough = yes(Label),
         (
             list.last(Instrs, LastInstr),
-            LastInstr = goto(label(Label)) - _
+            LastInstr = goto(code_label(Label)) - _
         ->
             StdInstrs = Instrs
         ;
-            Goto = goto(label(Label)) - "",
-            list.append(Instrs, [Goto], StdInstrs)
+            Goto = goto(code_label(Label)) - "",
+            StdInstrs = Instrs ++ [Goto]
         )
     ;
         MaybeFallThrough = no,
@@ -543,7 +543,7 @@
     % can delete comments from its input instruction sequences,
     % it cannot delete executable instructions.
     list.last_det(Instrs, LastInstr),
-    ( LastInstr = goto(label(Label)) - _ ->
+    ( LastInstr = goto(code_label(Label)) - _ ->
         MaybeFallThrough = yes(Label)
     ;
         MaybeFallThrough = no
Index: compiler/dupproc.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/dupproc.m,v
retrieving revision 1.13
diff -u -r1.13 dupproc.m
--- compiler/dupproc.m	26 Sep 2006 03:53:15 -0000	1.13
+++ compiler/dupproc.m	13 Oct 2006 09:25:11 -0000
@@ -121,7 +121,7 @@
 maybe_redirect_proc(Proc0, Target, MaybeProc) :-
     Instrs0 = Proc0 ^ cproc_code,
     get_prologue(Instrs0, LabelInstr, _Comments, LaterInstrs),
-    Redirect = goto(label(entry(entry_label_local, Target))) -
+    Redirect = goto(code_label(entry_label(entry_label_local, Target))) -
         "Redirect to procedure with identical body",
     list.filter(disallowed_instr, LaterInstrs, DisallowedInstrs),
     list.length(LaterInstrs, NumLaterInstrs),
@@ -303,13 +303,13 @@
 
 standardize_label(Label, StdLabel, DupProcMap) :-
     (
-        Label = internal(Num, ProcLabel),
+        Label = internal_label(Num, ProcLabel),
         standardize_proc_label(ProcLabel, StdProcLabel, DupProcMap),
-        StdLabel = internal(Num, StdProcLabel)
+        StdLabel = internal_label(Num, StdProcLabel)
     ;
-        Label = entry(Type, ProcLabel),
+        Label = entry_label(Type, ProcLabel),
         standardize_proc_label(ProcLabel, StdProcLabel, DupProcMap),
-        StdLabel = entry(Type, StdProcLabel)
+        StdLabel = entry_label(Type, StdProcLabel)
     ).
 
     % Compute the standard form of a list(label).
@@ -329,15 +329,15 @@
 
 standardize_code_addr(CodeAddr, StdCodeAddr, DupProcMap) :-
     (
-        CodeAddr = label(Label),
+        CodeAddr = code_label(Label),
         standardize_label(Label, StdLabel, DupProcMap),
-        StdCodeAddr = label(StdLabel)
+        StdCodeAddr = code_label(StdLabel)
     ;
-        CodeAddr = imported(ProcLabel),
+        CodeAddr = code_imported_proc(ProcLabel),
         standardize_proc_label(ProcLabel, StdProcLabel, DupProcMap),
-        StdCodeAddr = imported(StdProcLabel)
+        StdCodeAddr = code_imported_proc(StdProcLabel)
     ;
-        CodeAddr = succip,
+        CodeAddr = code_succip,
         StdCodeAddr = CodeAddr
     ;
         CodeAddr = do_succeed(_),
Index: compiler/equiv_type.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/equiv_type.m,v
retrieving revision 1.71
diff -u -r1.71 equiv_type.m
--- compiler/equiv_type.m	13 Oct 2006 04:52:18 -0000	1.71
+++ compiler/equiv_type.m	13 Oct 2006 08:04:21 -0000
@@ -68,20 +68,24 @@
     equiv_type_info::in, equiv_type_info::out) is det.
 
 :- pred replace_in_prog_constraints(eqv_map::in,
-    prog_constraints::in, prog_constraints::out,
-    tvarset::in, tvarset::out, equiv_type_info::in, equiv_type_info::out)
-    is det.
+    prog_constraints::in, prog_constraints::out, tvarset::in, tvarset::out,
+    equiv_type_info::in, equiv_type_info::out) is det.
 
 :- pred replace_in_prog_constraint(eqv_map::in,
     prog_constraint::in, prog_constraint::out, tvarset::in, tvarset::out,
     equiv_type_info::in, equiv_type_info::out) is det.
 
 :- pred replace_in_ctors(eqv_map::in,
-    list(constructor)::in, list(constructor)::out,
-    tvarset::in, tvarset::out, equiv_type_info::in, equiv_type_info::out)
-    is det.
+    list(constructor)::in, list(constructor)::out, tvarset::in, tvarset::out,
+    equiv_type_info::in, equiv_type_info::out) is det.
+
+:- type eqv_type_body
+    --->    eqv_type_body(
+                tvarset,
+                list(type_param),
+                mer_type
+            ).
 
-:- type eqv_type_body ---> eqv_type_body(tvarset, list(type_param), mer_type).
 :- type eqv_map == map(type_ctor, eqv_type_body).
 
 :- type equiv_type_info == maybe(expanded_item_set).
@@ -126,11 +130,10 @@
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
 
-:- type location
-    --->    out_of_module
-    ;       module_interface
-    ;       module_implementation
-    .
+:- type eqv_type_location
+    --->    eqv_type_out_of_module
+    ;       eqv_type_in_interface
+    ;       eqv_type_in_implementation.
 
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
@@ -143,7 +146,7 @@
     map.init(EqvMap0),
     map.init(EqvInstMap0),
     build_eqv_map(Items0, EqvMap0, EqvMap, EqvInstMap0, EqvInstMap),
-    replace_in_item_list(ModuleName, out_of_module, Items0,
+    replace_in_item_list(ModuleName, eqv_type_out_of_module, Items0,
         EqvMap, EqvInstMap, [], RevItems, [], ErrorList, !Info,
         used_modules_init, UsedModules),
     list.reverse(RevItems, Items),
@@ -165,6 +168,7 @@
                 list(inst_var),
                 mer_inst
             ).
+
 :- type eqv_inst_map == map(inst_id, eqv_inst_body).
 
 :- type pred_or_func_decl_type
@@ -185,20 +189,14 @@
 
 build_eqv_map([], !EqvMap, !EqvInstMap).
 build_eqv_map([Item - _Context | Items0], !EqvMap, !EqvInstMap) :-
-    (
-        Item = item_module_defn(_, md_abstract_imported)
-    ->
+    ( Item = item_module_defn(_, md_abstract_imported) ->
         skip_abstract_imported_items(Items0, Items)
-    ;
-        Item = item_type_defn(VarSet, Name, Args, parse_tree_eqv_type(Body), _)
-    ->
+    ; Item = item_type_defn(VarSet, Name, Args, parse_tree_eqv_type(Body), _) ->
         Items = Items0,
         list.length(Args, Arity),
         TypeCtor = type_ctor(Name, Arity),
         svmap.set(TypeCtor, eqv_type_body(VarSet, Args, Body), !EqvMap)
-    ;
-        Item = item_inst_defn(VarSet, Name, Args, eqv_inst(Body), _)
-    ->
+    ; Item = item_inst_defn(VarSet, Name, Args, eqv_inst(Body), _) ->
         Items = Items0,
         list.length(Args, Arity),
         InstId = inst_id(Name, Arity),
@@ -247,7 +245,7 @@
     % predicates that follow perform substitution of equivalence types
     % on <foo>s.
     %
-:- pred replace_in_item_list(module_name::in, location::in,
+:- pred replace_in_item_list(module_name::in, eqv_type_location::in,
     list(item_and_context)::in, eqv_map::in, eqv_inst_map::in,
     list(item_and_context)::in, list(item_and_context)::out,
     list(eqv_error)::in, list(eqv_error)::out,
@@ -260,12 +258,12 @@
     ItemAndContext0 = Item0 - Context,
     ( Item0 = item_module_defn(_, ModuleDefn) ->
         ( ModuleDefn = md_interface,
-            Location = module_interface
+            Location = eqv_type_in_interface
         ;
             ( ModuleDefn = md_implementation
             ; ModuleDefn = md_private_interface
             ),
-            Location = module_implementation
+            Location = eqv_type_in_implementation
         ;
 
             ( ModuleDefn = md_imported(_)
@@ -273,13 +271,12 @@
             ; ModuleDefn = md_abstract_imported
             ; ModuleDefn = md_opt_imported
             ; ModuleDefn = md_transitively_imported
-                % XXX I'm not sure what these two are
-                % so they may not signify that we've
-                % finished processing the module.
+                % XXX I'm not sure what these two are so they may not signify
+                % that we've finished processing the module.
             ; ModuleDefn = md_external(_, _)
             ; ModuleDefn = md_export(_)
             ),
-            Location = out_of_module
+            Location = eqv_type_out_of_module
         ; 
             ( ModuleDefn = md_module(_)
             ; ModuleDefn = md_end_module(_)
@@ -314,7 +311,7 @@
     replace_in_item_list(ModuleName, Location, Items0, EqvMap, EqvInstMap,
         !ReplItems, !Errors, !Info, !UsedModules).
 
-:- pred replace_in_item(module_name::in, location::in, item::in,
+:- pred replace_in_item(module_name::in, eqv_type_location::in, item::in,
     prog_context::in, eqv_map::in, eqv_inst_map::in, item::out,
     list(eqv_error)::out,
     maybe(recompilation_info)::in, maybe(recompilation_info)::out,
@@ -439,7 +436,7 @@
     replace_in_prog_constraint_list(Location, EqvMap,
         Constraints0, Constraints, VarSet0, VarSet1,
         UsedTypeCtors0, UsedTypeCtors1, !UsedModules),
-    replace_in_type_list(Location, EqvMap, Ts0, Ts, _, _,
+    replace_in_type_list_location_circ(Location, EqvMap, Ts0, Ts, _, _,
         VarSet1, VarSet, UsedTypeCtors1, UsedTypeCtors, !UsedModules),
     list.length(Ts0, Arity),
     ItemId = item_id(typeclass_item, item_name(ClassName, Arity)),
@@ -485,7 +482,7 @@
             UserSharing0 = user_sharing(Sharing0, MaybeTypes0),
             MaybeTypes0 = yes(user_type_info(Types0, TVarset0))
         ->
-            replace_in_type_list(Location,
+            replace_in_type_list_location(Location,
                 EqvMap, Types0, Types, _AnythingChanged, 
                 TVarset0, TVarset, !EquivTypeInfo, !UsedModules),
             replace_in_structure_sharing_domain(Location,
@@ -510,15 +507,14 @@
     QualName = qualified(ModuleName, MutName),
     maybe_record_expanded_items(ModuleName, QualName, !.Info, ExpandedItems0),
     TVarSet0 = varset.init,
-    replace_in_type(Location,
-        EqvMap, Type0, Type, _TypeChanged, TVarSet0, _TVarSet,
-        ExpandedItems0, ExpandedItems1, !UsedModules),
+    replace_in_type_location(Location, EqvMap, Type0, Type, _TypeChanged,
+        TVarSet0, _TVarSet, ExpandedItems0, ExpandedItems1, !UsedModules),
     replace_in_inst(Location, Inst0, EqvInstMap, Inst,
         ExpandedItems1, ExpandedItems, !UsedModules),
     ItemId = item_id(mutable_item, item_name(QualName, 0)),
     finish_recording_expanded_items(ItemId, ExpandedItems, !Info).
 
-:- pred replace_in_type_defn(location::in, eqv_map::in, type_ctor::in,
+:- pred replace_in_type_defn(eqv_type_location::in, eqv_map::in, type_ctor::in,
     type_defn::in, type_defn::out, bool::out, tvarset::in, tvarset::out,
     equiv_type_info::in, equiv_type_info::out,
     used_modules::in, used_modules::out) is semidet.
@@ -526,14 +522,14 @@
 replace_in_type_defn(Location, EqvMap, TypeCtor, parse_tree_eqv_type(TBody0),
         parse_tree_eqv_type(TBody), ContainsCirc,
         !VarSet, !Info, !UsedModules) :-
-    replace_in_type_2(Location, EqvMap, [TypeCtor], TBody0, TBody,
+    replace_in_type_location_2(Location, EqvMap, [TypeCtor], TBody0, TBody,
         _, ContainsCirc, !VarSet, !Info, !UsedModules).
 
 replace_in_type_defn(Location, EqvMap, _,
         parse_tree_du_type(TBody0, EqPred),
         parse_tree_du_type(TBody, EqPred), no, !VarSet, !Info, !UsedModules) :-
-    replace_in_ctors(Location,
-            EqvMap, TBody0, TBody, !VarSet, !Info, !UsedModules).
+    replace_in_ctors_location(Location, EqvMap, TBody0, TBody, !VarSet, !Info,
+        !UsedModules).
 
 replace_in_type_defn(Location, EqvMap, TypeCtor,
         parse_tree_solver_type(SolverTypeDetails0, MaybeUserEqComp),
@@ -541,7 +537,7 @@
         ContainsCirc, !VarSet, !Info, !UsedModules) :-
     SolverTypeDetails0 = solver_type_details(RepresentationType0, InitPred,
         GroundInst, AnyInst, MutableItems),
-    replace_in_type_2(Location, EqvMap, [TypeCtor], 
+    replace_in_type_location_2(Location, EqvMap, [TypeCtor], 
         RepresentationType0, RepresentationType,
         _, ContainsCirc, !VarSet, !Info, !UsedModules),
     SolverTypeDetails = solver_type_details(RepresentationType, InitPred,
@@ -550,54 +546,52 @@
 %-----------------------------------------------------------------------------%
 
 replace_in_prog_constraints(EqvMap, Cs0, Cs, !VarSet, !Info) :-
-    replace_in_prog_constraints(out_of_module,
-            EqvMap, Cs0, Cs, !VarSet, !Info, used_modules_init, _).
+    replace_in_prog_constraints_location(eqv_type_out_of_module, EqvMap,
+        Cs0, Cs, !VarSet, !Info, used_modules_init, _).
 
-:- pred replace_in_prog_constraints(location::in, eqv_map::in,
-    prog_constraints::in, prog_constraints::out,
+:- pred replace_in_prog_constraints_location(eqv_type_location::in,
+    eqv_map::in, prog_constraints::in, prog_constraints::out,
     tvarset::in, tvarset::out, equiv_type_info::in, equiv_type_info::out,
     used_modules::in, used_modules::out) is det.
 
-replace_in_prog_constraints(Location,
-        EqvMap, Cs0, Cs, !VarSet, !Info, !UsedModules) :-
+replace_in_prog_constraints_location(Location, EqvMap, Cs0, Cs, !VarSet, !Info,
+        !UsedModules) :-
     Cs0 = constraints(UnivCs0, ExistCs0),
     Cs = constraints(UnivCs, ExistCs),
-    replace_in_prog_constraint_list(Location,
-            EqvMap, UnivCs0, UnivCs, !VarSet, !Info, !UsedModules),
-    replace_in_prog_constraint_list(Location,
-            EqvMap, ExistCs0, ExistCs, !VarSet, !Info, !UsedModules).
+    replace_in_prog_constraint_list(Location, EqvMap, UnivCs0, UnivCs,
+        !VarSet, !Info, !UsedModules),
+    replace_in_prog_constraint_list(Location, EqvMap, ExistCs0, ExistCs,
+        !VarSet, !Info, !UsedModules).
 
-:- pred replace_in_prog_constraint_list(location::in, eqv_map::in,
+:- pred replace_in_prog_constraint_list(eqv_type_location::in, eqv_map::in,
     list(prog_constraint)::in, list(prog_constraint)::out,
     tvarset::in, tvarset::out, equiv_type_info::in, equiv_type_info::out,
-    used_modules::in, used_modules::out)
-    is det.
+    used_modules::in, used_modules::out) is det.
 
-replace_in_prog_constraint_list(Location,
-        EqvMap, !Cs, !VarSet, !Info, !UsedModules) :-
-    list.map_foldl3(replace_in_prog_constraint(Location, EqvMap),
-            !Cs, !VarSet, !Info, !UsedModules).
+replace_in_prog_constraint_list(Location, EqvMap, !Cs, !VarSet, !Info,
+        !UsedModules) :-
+    list.map_foldl3(replace_in_prog_constraint_location(Location, EqvMap),
+        !Cs, !VarSet, !Info, !UsedModules).
 
 replace_in_prog_constraint(EqvMap, Constraint0, Constraint, !VarSet, !Info) :-
-    replace_in_prog_constraint(out_of_module, 
-            EqvMap, Constraint0, Constraint, !VarSet, !Info,
-            used_modules_init, _).
+    replace_in_prog_constraint_location(eqv_type_out_of_module, EqvMap,
+        Constraint0, Constraint, !VarSet, !Info, used_modules_init, _).
 
-:- pred replace_in_prog_constraint(location::in, eqv_map::in,
+:- pred replace_in_prog_constraint_location(eqv_type_location::in, eqv_map::in,
     prog_constraint::in, prog_constraint::out, tvarset::in, tvarset::out,
     equiv_type_info::in, equiv_type_info::out,
     used_modules::in, used_modules::out) is det.
 
-replace_in_prog_constraint(Location,
-        EqvMap, Constraint0, Constraint, !VarSet, !Info, !UsedModules) :-
+replace_in_prog_constraint_location(Location, EqvMap, Constraint0, Constraint,
+        !VarSet, !Info, !UsedModules) :-
     Constraint0 = constraint(ClassName, Ts0),
-    replace_in_type_list(Location,
-            EqvMap, Ts0, Ts, _, _, !VarSet, !Info, !UsedModules),
+    replace_in_type_list_location_circ(Location, EqvMap, Ts0, Ts, _, _,
+        !VarSet, !Info, !UsedModules),
     Constraint = constraint(ClassName, Ts).
 
 %-----------------------------------------------------------------------------%
 
-:- pred replace_in_class_interface(location::in, class_methods::in,
+:- pred replace_in_class_interface(eqv_type_location::in, class_methods::in,
     eqv_map::in, eqv_inst_map::in, class_methods::out,
     list(eqv_error)::in, list(eqv_error)::out,
     equiv_type_info::in, equiv_type_info::out,
@@ -608,8 +602,8 @@
     list.map_foldl3(replace_in_class_method(Location, EqvMap, EqvInstMap),
         ClassInterface0, ClassInterface, !Errors, !Info, !UsedModules).
 
-:- pred replace_in_class_method(location::in, eqv_map::in, eqv_inst_map::in,
-    class_method::in, class_method::out,
+:- pred replace_in_class_method(eqv_type_location::in,
+    eqv_map::in, eqv_inst_map::in, class_method::in, class_method::out,
     list(eqv_error)::in, list(eqv_error)::out,
     equiv_type_info::in, equiv_type_info::out,
     used_modules::in, used_modules::out) is det.
@@ -637,8 +631,8 @@
         !Errors, !Info, !UsedModules) :-
     replace_in_pred_mode(Location, PredName, length(Modes0), Context,
         mode_decl, EqvInstMap, MaybePredOrFunc0, MaybePredOrFunc,
-        ExtraModes, WithInst0, WithInst, Det0, Det,
-        !Info, !UsedModules, NewErrors),
+        ExtraModes, WithInst0, WithInst, Det0, Det, !Info, !UsedModules,
+        NewErrors),
     (
         ExtraModes = [],
         Modes = Modes0
@@ -650,7 +644,7 @@
 
 %-----------------------------------------------------------------------------%
 
-:- pred replace_in_subst(location::in, eqv_map::in,
+:- pred replace_in_subst(eqv_type_location::in, eqv_map::in,
     assoc_list(tvar, mer_type)::in, assoc_list(tvar, mer_type)::out,
     tvarset::in, tvarset::out, equiv_type_info::in, equiv_type_info::out,
     used_modules::in, used_modules::out) is det.
@@ -658,27 +652,28 @@
 replace_in_subst(_Location, _EqvMap, [], [], !VarSet, !Info, !UsedModules).
 replace_in_subst(Location, EqvMap, [Var - Type0 | Subst0],
         [Var - Type | Subst], !VarSet, !Info, !UsedModules) :-
-    replace_in_type(Location,
-            EqvMap, Type0, Type, _, !VarSet, !Info, !UsedModules),
-    replace_in_subst(Location,
-            EqvMap, Subst0, Subst, !VarSet, !Info, !UsedModules).
+    replace_in_type_location(Location, EqvMap, Type0, Type, _, !VarSet, !Info,
+        !UsedModules),
+    replace_in_subst(Location, EqvMap, Subst0, Subst, !VarSet, !Info,
+        !UsedModules).
 
 %-----------------------------------------------------------------------------%
 
 replace_in_ctors(EqvMap, !Ctors, !VarSet, !Info) :-
-    replace_in_ctors(out_of_module, EqvMap,
-            !Ctors, !VarSet, !Info, used_modules_init, _).
+    replace_in_ctors_location(eqv_type_out_of_module, EqvMap, !Ctors, !VarSet,
+        !Info, used_modules_init, _).
 
-:- pred replace_in_ctors(location::in, eqv_map::in,
+:- pred replace_in_ctors_location(eqv_type_location::in, eqv_map::in,
     list(constructor)::in, list(constructor)::out,
     tvarset::in, tvarset::out, equiv_type_info::in, equiv_type_info::out,
     used_modules::in, used_modules::out) is det.
 
-replace_in_ctors(Location, EqvMap, !Ctors, !VarSet, !Info, !UsedModules) :-
-    list.map_foldl3(replace_in_ctor(Location, EqvMap),
-            !Ctors, !VarSet, !Info, !UsedModules).
+replace_in_ctors_location(Location, EqvMap, !Ctors, !VarSet, !Info,
+        !UsedModules) :-
+    list.map_foldl3(replace_in_ctor(Location, EqvMap), !Ctors, !VarSet, !Info,
+        !UsedModules).
 
-:- pred replace_in_ctor(location::in, eqv_map::in,
+:- pred replace_in_ctor(eqv_type_location::in, eqv_map::in,
     constructor::in, constructor::out, tvarset::in, tvarset::out,
     equiv_type_info::in, equiv_type_info::out,
     used_modules::in, used_modules::out) is det.
@@ -688,50 +683,52 @@
         ctor(ExistQVars, Constraints, TName, Targs),
         !VarSet, !Info, !UsedModules) :-
     replace_in_ctor_arg_list(Location,
-            EqvMap, Targs0, Targs, _, !VarSet, !Info, !UsedModules),
+        EqvMap, Targs0, Targs, _, !VarSet, !Info, !UsedModules),
     replace_in_prog_constraint_list(Location, EqvMap,
-            Constraints0, Constraints, !VarSet, !Info, !UsedModules).
+        Constraints0, Constraints, !VarSet, !Info, !UsedModules).
 
 %-----------------------------------------------------------------------------%
 
 replace_in_type_list(EqvMap, !Ts, Changed, !VarSet, !Info) :-
-    replace_in_type_list(out_of_module,
-            EqvMap, !Ts, Changed, !VarSet, !Info, used_modules_init, _).
+    replace_in_type_list_location(eqv_type_out_of_module, EqvMap, !Ts, Changed,
+        !VarSet, !Info, used_modules_init, _).
 
-:- pred replace_in_type_list(location::in, eqv_map::in,
+:- pred replace_in_type_list_location(eqv_type_location::in, eqv_map::in,
     list(mer_type)::in, list(mer_type)::out, bool::out,
     tvarset::in, tvarset::out,
     equiv_type_info::in, equiv_type_info::out,
     used_modules::in, used_modules::out) is det.
 
-replace_in_type_list(Location,
-        EqvMap, !Ts, Changed, !VarSet, !Info, !UsedModules) :-
-    replace_in_type_list_2(Location,
-            EqvMap, [], !Ts, Changed, no, _, !VarSet, !Info, !UsedModules).
+replace_in_type_list_location(Location, EqvMap, !Ts, Changed, !VarSet, !Info,
+        !UsedModules) :-
+    replace_in_type_list_location_circ_2(Location, EqvMap, [], !Ts, Changed,
+        no, _, !VarSet, !Info, !UsedModules).
 
-:- pred replace_in_type_list(location::in, eqv_map::in,
+:- pred replace_in_type_list_location_circ(eqv_type_location::in, eqv_map::in,
     list(mer_type)::in, list(mer_type)::out, bool::out, bool::out,
     tvarset::in, tvarset::out, equiv_type_info::in, equiv_type_info::out,
     used_modules::in, used_modules::out) is det.
 
-replace_in_type_list(Location,
-        EqvMap, !Ts, Changed, ContainsCirc, !VarSet, !Info, !UsedModules) :-
-    replace_in_type_list_2(Location, EqvMap, [], !Ts, Changed, no,
-        ContainsCirc, !VarSet, !Info, !UsedModules).
-
-:- pred replace_in_type_list_2(location::in, eqv_map::in, list(type_ctor)::in,
-    list(mer_type)::in, list(mer_type)::out, bool::out, bool::in, bool::out,
-    tvarset::in, tvarset::out, equiv_type_info::in, equiv_type_info::out,
+replace_in_type_list_location_circ(Location, EqvMap, !Ts,
+        Changed, ContainsCirc, !VarSet, !Info, !UsedModules) :-
+    replace_in_type_list_location_circ_2(Location, EqvMap, [], !Ts,
+        Changed, no, ContainsCirc, !VarSet, !Info, !UsedModules).
+
+:- pred replace_in_type_list_location_circ_2(eqv_type_location::in,
+    eqv_map::in, list(type_ctor)::in, list(mer_type)::in, list(mer_type)::out,
+    bool::out, bool::in, bool::out, tvarset::in, tvarset::out,
+    equiv_type_info::in, equiv_type_info::out,
     used_modules::in, used_modules::out) is det.
 
-replace_in_type_list_2(_Location, _EqvMap, _Seen, [], [], no,
+replace_in_type_list_location_circ_2(_Location, _EqvMap, _Seen, [], [], no,
         !ContainsCirc, !VarSet, !Info, !UsedModules).
-replace_in_type_list_2(Location, EqvMap, Seen, List0 @ [T0 | Ts0], List,
-        Changed, !Circ, !VarSet, !Info, !UsedModules) :-
-    replace_in_type_2(Location, EqvMap, Seen, T0, T, Changed0, ContainsCirc,
-        !VarSet, !Info, !UsedModules),
+replace_in_type_list_location_circ_2(Location, EqvMap, Seen,
+        List0 @ [T0 | Ts0], List, Changed, !Circ, !VarSet, !Info,
+        !UsedModules) :-
+    replace_in_type_location_2(Location, EqvMap, Seen, T0, T, Changed0,
+        ContainsCirc, !VarSet, !Info, !UsedModules),
     !:Circ = ContainsCirc `or` !.Circ,
-    replace_in_type_list_2(Location, EqvMap, Seen, Ts0, Ts,
+    replace_in_type_list_location_circ_2(Location, EqvMap, Seen, Ts0, Ts,
         Changed1, !Circ, !VarSet, !Info, !UsedModules),
     (
         ( Changed0 = yes
@@ -747,7 +744,7 @@
 
 %-----------------------------------------------------------------------------%
 
-:- pred replace_in_ctor_arg_list(location::in, eqv_map::in,
+:- pred replace_in_ctor_arg_list(eqv_type_location::in, eqv_map::in,
     list(constructor_arg)::in, list(constructor_arg)::out, bool::out,
     tvarset::in, tvarset::out, equiv_type_info::in, equiv_type_info::out,
     used_modules::in, used_modules::out) is det.
@@ -757,7 +754,7 @@
     replace_in_ctor_arg_list_2(Location, EqvMap, [], !As, no, ContainsCirc,
         !VarSet, !Info, !UsedModules).
 
-:- pred replace_in_ctor_arg_list_2(location::in,
+:- pred replace_in_ctor_arg_list_2(eqv_type_location::in,
     eqv_map::in, list(type_ctor)::in,
     list(constructor_arg)::in, list(constructor_arg)::out,
     bool::in, bool::out, tvarset::in, tvarset::out,
@@ -769,40 +766,38 @@
 replace_in_ctor_arg_list_2(Location,
         EqvMap, Seen, [N - T0 | As0], [N - T | As],
         !Circ, !VarSet, !Info, !UsedModules) :-
-    replace_in_type_2(Location, EqvMap,
-            Seen, T0, T, _, ContainsCirc, !VarSet, !Info, !UsedModules),
+    replace_in_type_location_2(Location, EqvMap, Seen, T0, T, _, ContainsCirc,
+        !VarSet, !Info, !UsedModules),
     !:Circ = !.Circ `or` ContainsCirc,
     replace_in_ctor_arg_list_2(Location, EqvMap,
-            Seen, As0, As, !Circ, !VarSet, !Info, !UsedModules).
+        Seen, As0, As, !Circ, !VarSet, !Info, !UsedModules).
 
 %-----------------------------------------------------------------------------%
 
 replace_in_type(EqvMap, Type0, Type, Changed, !VarSet, !Info) :-
-    replace_in_type(out_of_module,
-            EqvMap, Type0, Type, Changed,
-            !VarSet, !Info, used_modules_init, _).
-
-:- pred replace_in_type(location::in,
-    eqv_map::in, mer_type::in, mer_type::out,
-    bool::out, tvarset::in, tvarset::out,
+    replace_in_type_location(eqv_type_out_of_module, EqvMap, Type0, Type,
+        Changed, !VarSet, !Info, used_modules_init, _).
+
+:- pred replace_in_type_location(eqv_type_location::in, eqv_map::in,
+    mer_type::in, mer_type::out, bool::out, tvarset::in, tvarset::out,
     equiv_type_info::in, equiv_type_info::out,
     used_modules::in, used_modules::out) is det.
 
-replace_in_type(Location,
-        EqvMap, Type0, Type, Changed, !VarSet, !Info, !UsedModules) :-
-    replace_in_type_2(Location,
-        EqvMap, [], Type0, Type, Changed, _, !VarSet, !Info, !UsedModules).
+replace_in_type_location(Location, EqvMap, Type0, Type, Changed, !VarSet,
+        !Info, !UsedModules) :-
+    replace_in_type_location_2(Location, EqvMap, [], Type0, Type, Changed, _,
+        !VarSet, !Info, !UsedModules).
 
     % Replace all equivalence types in a given type, detecting
     % any circularities.
     %
-:- pred replace_in_type_2(location::in, eqv_map::in, list(type_ctor)::in,
-    mer_type::in, mer_type::out, bool::out, bool::out,
+:- pred replace_in_type_location_2(eqv_type_location::in, eqv_map::in,
+    list(type_ctor)::in, mer_type::in, mer_type::out, bool::out, bool::out,
     tvarset::in, tvarset::out, equiv_type_info::in, equiv_type_info::out,
     used_modules::in, used_modules::out) is det.
 
-replace_in_type_2(Location, EqvMap, TypeCtorsAlreadyExpanded, Type0, Type,
-        Changed, Circ, !VarSet, !Info, !UsedModules) :-
+replace_in_type_location_2(Location, EqvMap, TypeCtorsAlreadyExpanded,
+        Type0, Type, Changed, Circ, !VarSet, !Info, !UsedModules) :-
     (
         Type0 = type_variable(Var, Kind),
         Type = type_variable(Var, Kind),
@@ -810,8 +805,8 @@
         Circ = no
     ;
         Type0 = defined_type(SymName, TArgs0, Kind),
-        replace_in_type_list_2(Location, EqvMap, TypeCtorsAlreadyExpanded,
-            TArgs0, TArgs, ArgsChanged, no, Circ0,
+        replace_in_type_list_location_circ_2(Location, EqvMap,
+            TypeCtorsAlreadyExpanded, TArgs0, TArgs, ArgsChanged, no, Circ0,
             !VarSet, !Info, !UsedModules),
         Arity = list.length(TArgs),
         TypeCtor = type_ctor(SymName, Arity),
@@ -825,13 +820,14 @@
         Circ = no
     ;
         Type0 = higher_order_type(Args0, MaybeRet0, Purity, EvalMethod),
-        replace_in_type_list_2(Location, EqvMap, TypeCtorsAlreadyExpanded,
-            Args0, Args, ArgsChanged, no, ArgsCirc,
+        replace_in_type_list_location_circ_2(Location, EqvMap,
+            TypeCtorsAlreadyExpanded, Args0, Args, ArgsChanged, no, ArgsCirc,
             !VarSet, !Info, !UsedModules),
         (
             MaybeRet0 = yes(Ret0),
-            replace_in_type_2(Location, EqvMap, TypeCtorsAlreadyExpanded,
-                Ret0, Ret, RetChanged, RetCirc, !VarSet, !Info, !UsedModules),
+            replace_in_type_location_2(Location, EqvMap,
+                TypeCtorsAlreadyExpanded, Ret0, Ret, RetChanged, RetCirc,
+                !VarSet, !Info, !UsedModules),
             MaybeRet = yes(Ret),
             Changed = bool.or(ArgsChanged, RetChanged),
             Circ = bool.or(ArgsCirc, RetCirc)
@@ -850,8 +846,9 @@
         )
     ;
         Type0 = tuple_type(Args0, Kind),
-        replace_in_type_list_2(Location, EqvMap, TypeCtorsAlreadyExpanded,
-            Args0, Args, Changed, no, Circ, !VarSet, !Info, !UsedModules),
+        replace_in_type_list_location_circ_2(Location, EqvMap,
+            TypeCtorsAlreadyExpanded, Args0, Args, Changed, no, Circ,
+            !VarSet, !Info, !UsedModules),
         (
             Changed = yes,
             Type = tuple_type(Args, Kind)
@@ -861,8 +858,9 @@
         )
     ;
         Type0 = apply_n_type(Var, Args0, Kind),
-        replace_in_type_list_2(Location, EqvMap, TypeCtorsAlreadyExpanded,
-            Args0, Args, Changed, no, Circ, !VarSet, !Info, !UsedModules),
+        replace_in_type_list_location_circ_2(Location, EqvMap,
+            TypeCtorsAlreadyExpanded, Args0, Args, Changed, no, Circ,
+            !VarSet, !Info, !UsedModules),
         (
             Changed = yes,
             Type = apply_n_type(Var, Args, Kind)
@@ -872,7 +870,7 @@
         )
     ;
         Type0 = kinded_type(RawType0, Kind),
-        replace_in_type_2(Location, EqvMap, TypeCtorsAlreadyExpanded,
+        replace_in_type_location_2(Location, EqvMap, TypeCtorsAlreadyExpanded,
             RawType0, RawType, Changed, Circ, !VarSet, !Info, !UsedModules),
         (
             Changed = yes,
@@ -883,15 +881,15 @@
         )
     ).
 
-:- pred replace_type_ctor(location::in, eqv_map::in, list(type_ctor)::in,
-    mer_type::in, type_ctor::in, list(mer_type)::in, kind::in, mer_type::out,
-    bool::in, bool::out, bool::in, bool::out, tvarset::in, tvarset::out,
-    equiv_type_info::in, equiv_type_info::out,
+:- pred replace_type_ctor(eqv_type_location::in, eqv_map::in,
+    list(type_ctor)::in, mer_type::in, type_ctor::in, list(mer_type)::in,
+    kind::in, mer_type::out, bool::in, bool::out, bool::in, bool::out,
+    tvarset::in, tvarset::out, equiv_type_info::in, equiv_type_info::out,
     used_modules::in, used_modules::out) is det.
 
 replace_type_ctor(Location, EqvMap, TypeCtorsAlreadyExpanded, Type0,
-        TypeCtor, TArgs, Kind, Type,
-        !Changed, !Circ, !VarSet, !Info, !UsedModules) :-
+        TypeCtor, TArgs, Kind, Type, !Changed, !Circ, !VarSet, !Info,
+        !UsedModules) :-
     ( list.member(TypeCtor, TypeCtorsAlreadyExpanded) ->
         AlreadyExpanded = yes
     ;
@@ -922,8 +920,8 @@
         record_expanded_item(item_id(type_item, TypeCtorItem), !Info),
         map.from_corresponding_lists(Args, TArgs, Subst),
         apply_subst_to_type(Subst, Body1, Body),
-        replace_in_type_2(Location,
-            EqvMap, [TypeCtor | TypeCtorsAlreadyExpanded], Body,
+        replace_in_type_location_2(Location, EqvMap,
+            [TypeCtor | TypeCtorsAlreadyExpanded], Body,
             Type, _, !:Circ, !VarSet, !Info, !UsedModules)
     ;
         (
@@ -937,34 +935,34 @@
         bool.or(AlreadyExpanded, !Circ)
     ).
 
-:- pred type_ctor_used_modules(location::in, type_ctor::in,
+:- pred type_ctor_used_modules(eqv_type_location::in, type_ctor::in,
     used_modules::in, used_modules::out) is det.
 
-type_ctor_used_modules(out_of_module, _, !UsedModules).
-type_ctor_used_modules(module_interface, type_ctor(Name, _), !UsedModules) :-
+type_ctor_used_modules(eqv_type_out_of_module, _, !UsedModules).
+type_ctor_used_modules(eqv_type_in_interface, type_ctor(Name, _),
+        !UsedModules) :-
     add_sym_name_module(visibility_public, Name, !UsedModules).
-type_ctor_used_modules(module_implementation,
-        type_ctor(Name, _), !UsedModules) :-
+type_ctor_used_modules(eqv_type_in_implementation, type_ctor(Name, _),
+        !UsedModules) :-
     add_sym_name_module(visibility_private, Name, !UsedModules).
 
-:- pred replace_in_inst(location::in,
+:- pred replace_in_inst(eqv_type_location::in,
     mer_inst::in, eqv_inst_map::in, mer_inst::out,
     equiv_type_info::in, equiv_type_info::out,
     used_modules::in, used_modules::out) is det.
 
 replace_in_inst(Location, Inst0, EqvInstMap, Inst, !Info, !UsedModules) :-
-    replace_in_inst(Location,
-            Inst0, EqvInstMap, set.init, Inst, !Info, !UsedModules).
+    replace_in_inst_location(Location, Inst0, EqvInstMap, set.init, Inst,
+        !Info, !UsedModules).
 
-:- pred replace_in_inst(location::in, mer_inst::in, eqv_inst_map::in,
-    set(inst_id)::in, mer_inst::out,
+:- pred replace_in_inst_location(eqv_type_location::in, mer_inst::in,
+    eqv_inst_map::in, set(inst_id)::in, mer_inst::out,
     equiv_type_info::in, equiv_type_info::out,
     used_modules::in, used_modules::out) is det.
 
-replace_in_inst(Location,
-        Inst0, EqvInstMap, ExpandedInstIds, Inst, !Info, !UsedModules) :-
-
-        % XXX Need to record the used modules
+replace_in_inst_location(Location, Inst0, EqvInstMap, ExpandedInstIds, Inst,
+        !Info, !UsedModules) :-
+    % XXX Need to record the used modules
     ( Inst0 = defined_inst(user_inst(SymName, ArgInsts)) ->
         InstId = inst_id(SymName, length(ArgInsts)),
         (
@@ -972,13 +970,13 @@
         ->
             Inst = Inst0
         ;
-            map.search(EqvInstMap, InstId,
-                eqv_inst_body(_, EqvInstParams, EqvInst))
+            map.search(EqvInstMap, InstId, EqvInstBody),
+            EqvInstBody = eqv_inst_body(_, EqvInstParams, EqvInst)
         ->
             inst_substitute_arg_list(EqvInstParams, ArgInsts, EqvInst, Inst1),
             InstIdItem = inst_id_to_item_name(InstId),
             record_expanded_item(item_id(inst_item, InstIdItem), !Info),
-            replace_in_inst(Location, Inst1, EqvInstMap,
+            replace_in_inst_location(Location, Inst1, EqvInstMap,
                 set.insert(ExpandedInstIds, InstId), Inst, !Info, !UsedModules)
         ;
             Inst = Inst0
@@ -989,8 +987,8 @@
 
 %-----------------------------------------------------------------------------%
 
-:- pred replace_in_pred_type(location::in, sym_name::in, pred_or_func::in,
-    prog_context::in, eqv_map::in, eqv_inst_map::in,
+:- pred replace_in_pred_type(eqv_type_location::in, sym_name::in,
+    pred_or_func::in, prog_context::in, eqv_map::in, eqv_inst_map::in,
     prog_constraints::in, prog_constraints::out,
     list(type_and_mode)::in, list(type_and_mode)::out,
     tvarset::in, tvarset::out,
@@ -1001,20 +999,19 @@
     used_modules::in, used_modules::out,
     list(eqv_error)::out) is det.
 
-replace_in_pred_type(Location,
-        PredName, PredOrFunc, Context, EqvMap, EqvInstMap,
-        ClassContext0, ClassContext, TypesAndModes0, TypesAndModes,
-        !TypeVarSet, MaybeWithType0, MaybeWithType,
-        MaybeWithInst0, MaybeWithInst,
+replace_in_pred_type(Location, PredName, PredOrFunc, Context,
+        EqvMap, EqvInstMap, ClassContext0, ClassContext,
+        TypesAndModes0, TypesAndModes, !TypeVarSet,
+        MaybeWithType0, MaybeWithType, MaybeWithInst0, MaybeWithInst,
         Det0, Det, !Info, !UsedModules, Errors) :-
-    replace_in_prog_constraints(Location, EqvMap, ClassContext0, ClassContext,
-        !TypeVarSet, !Info, !UsedModules),
+    replace_in_prog_constraints_location(Location, EqvMap,
+        ClassContext0, ClassContext, !TypeVarSet, !Info, !UsedModules),
     replace_in_tms(Location, EqvMap,
-            TypesAndModes0, TypesAndModes1, !TypeVarSet, !Info, !UsedModules),
+        TypesAndModes0, TypesAndModes1, !TypeVarSet, !Info, !UsedModules),
     (
         MaybeWithType0 = yes(WithType0),
-        replace_in_type(Location, EqvMap,
-                WithType0, WithType, _, !TypeVarSet, !Info, !UsedModules),
+        replace_in_type_location(Location, EqvMap, WithType0, WithType, _,
+            !TypeVarSet, !Info, !UsedModules),
         (
             type_is_higher_order_details(WithType, _Purity, PredOrFunc,
                 _EvalMethod, ExtraTypes0)
@@ -1079,7 +1076,7 @@
         TypesAndModes = TypesAndModes1 ++ ExtraTypesAndModes
     ).
 
-:- pred replace_in_pred_mode(location::in, sym_name::in, arity::in,
+:- pred replace_in_pred_mode(eqv_type_location::in, sym_name::in, arity::in,
     prog_context::in, pred_or_func_decl_type::in, eqv_inst_map::in,
     maybe(pred_or_func)::in, maybe(pred_or_func)::out,
     list(mer_mode)::out, maybe(mer_inst)::in, maybe(mer_inst)::out,
@@ -1094,8 +1091,8 @@
         !Info, !UsedModules, Errors) :-
     (
         MaybeWithInst0 = yes(WithInst0),
-        replace_in_inst(Location,
-                WithInst0, EqvInstMap, WithInst, !Info, !UsedModules),
+        replace_in_inst(Location, WithInst0, EqvInstMap, WithInst, !Info,
+            !UsedModules),
         (
             WithInst = ground(_, higher_order(pred_inst_info(
                 PredOrFunc, ExtraModes0, DetPrime))),
@@ -1136,33 +1133,33 @@
         ExtraModes = []
     ).
 
-:- pred replace_in_tms(location::in, eqv_map::in,
+:- pred replace_in_tms(eqv_type_location::in, eqv_map::in,
     list(type_and_mode)::in, list(type_and_mode)::out,
     tvarset::in, tvarset::out, equiv_type_info::in, equiv_type_info::out,
     used_modules::in, used_modules::out) is det.
 
 replace_in_tms(Location, EqvMap, !TMs, !VarSet, !Info, !UsedModules) :-
-    list.map_foldl3(replace_in_tm(Location, EqvMap),
-            !TMs, !VarSet, !Info, !UsedModules).
+    list.map_foldl3(replace_in_tm(Location, EqvMap), !TMs, !VarSet, !Info,
+        !UsedModules).
 
-:- pred replace_in_tm(location::in, eqv_map::in,
+:- pred replace_in_tm(eqv_type_location::in, eqv_map::in,
     type_and_mode::in, type_and_mode::out, tvarset::in, tvarset::out,
     equiv_type_info::in, equiv_type_info::out,
     used_modules::in, used_modules::out) is det.
 
 replace_in_tm(Location, EqvMap, type_only(Type0),
         type_only(Type), !VarSet, !Info, !UsedModules) :-
-    replace_in_type(Location,
-            EqvMap, Type0, Type, _, !VarSet, !Info, !UsedModules).
+    replace_in_type_location(Location, EqvMap, Type0, Type, _, !VarSet, !Info,
+        !UsedModules).
 
 replace_in_tm(Location, EqvMap, type_and_mode(Type0, Mode),
         type_and_mode(Type, Mode), !VarSet, !Info, !UsedModules) :-
-    replace_in_type(Location,
-            EqvMap, Type0, Type, _, !VarSet, !Info, !UsedModules).
+    replace_in_type_location(Location, EqvMap, Type0, Type, _, !VarSet, !Info,
+        !UsedModules).
 
 %-----------------------------------------------------------------------------%
 %
-:- pred replace_in_structure_sharing_domain(location::in, eqv_map::in, 
+:- pred replace_in_structure_sharing_domain(eqv_type_location::in, eqv_map::in, 
     structure_sharing_domain::in, structure_sharing_domain::out, 
     tvarset::in, equiv_type_info::in, equiv_type_info::out,
     used_modules::in, used_modules::out) is det.
@@ -1179,7 +1176,7 @@
         replace_in_structure_sharing_pair(Location, EqvMap, TVarset), 
         SharingPairs0, SharingPairs, !EquivTypeInfo, !UsedModules).
 
-:- pred replace_in_structure_sharing_pair(location::in,
+:- pred replace_in_structure_sharing_pair(eqv_type_location::in,
     eqv_map::in, tvarset::in, 
     structure_sharing_pair::in, structure_sharing_pair::out,
     equiv_type_info::in, equiv_type_info::out,
@@ -1187,24 +1184,24 @@
 
 replace_in_structure_sharing_pair(Location, EqvMap, TVarset, Data10 - Data20, 
         Data1 - Data2, !EquivTypeInfo, !UsedModules) :- 
-    replace_in_datastruct(Location,
-            EqvMap, TVarset, Data10, Data1, !EquivTypeInfo, !UsedModules),
-    replace_in_datastruct(Location,
-            EqvMap, TVarset, Data20, Data2, !EquivTypeInfo, !UsedModules).
+    replace_in_datastruct(Location, EqvMap, TVarset, Data10, Data1,
+        !EquivTypeInfo, !UsedModules),
+    replace_in_datastruct(Location, EqvMap, TVarset, Data20, Data2,
+        !EquivTypeInfo, !UsedModules).
 
-:- pred replace_in_datastruct(location::in,
+:- pred replace_in_datastruct(eqv_type_location::in,
     eqv_map::in, tvarset::in, datastruct::in,
     datastruct::out, equiv_type_info::in, equiv_type_info::out,
     used_modules::in, used_modules::out) is det.
 
-replace_in_datastruct(Location,
-        EqvMap, TVarset, Data0, Data, !EquivTypeInfo, !UsedModules) :- 
+replace_in_datastruct(Location, EqvMap, TVarset, Data0, Data, !EquivTypeInfo,
+        !UsedModules) :- 
     Sel0 = Data0 ^ sc_selector,
     list.map_foldl2(replace_in_unit_selector(Location, EqvMap, TVarset),
-            Sel0, Sel, !EquivTypeInfo, !UsedModules), 
+        Sel0, Sel, !EquivTypeInfo, !UsedModules), 
     Data = Data0 ^ sc_selector := Sel.
 
-:- pred replace_in_unit_selector(location::in,
+:- pred replace_in_unit_selector(eqv_type_location::in,
     eqv_map::in, tvarset::in, unit_selector::in,
     unit_selector::out, equiv_type_info::in, equiv_type_info::out,
     used_modules::in, used_modules::out) is det.
@@ -1212,16 +1209,15 @@
 replace_in_unit_selector(_, _, _, X @ termsel(_, _), X, !EquivTypeInfo, !UMs).
 replace_in_unit_selector(Location, EqvMap, TVarset,
         typesel(Type0), typesel(Type), !EquivTypeInfo, !UsedModules) :-
-    replace_in_type(Location,
-            EqvMap, Type0, Type, _, TVarset, _, !EquivTypeInfo, !UsedModules).
+    replace_in_type_location(Location, EqvMap, Type0, Type, _, TVarset, _,
+        !EquivTypeInfo, !UsedModules).
 
 %-----------------------------------------------------------------------------%
 
 :- type expanded_item_set == pair(module_name, set(item_id)).
 
 maybe_record_expanded_items(_, _, no, no).
-maybe_record_expanded_items(ModuleName, SymName, yes(_),
-        MaybeInfo) :-
+maybe_record_expanded_items(ModuleName, SymName, yes(_), MaybeInfo) :-
     ( SymName = qualified(ModuleName, _) ->
         MaybeInfo = no
     ;
Index: compiler/exprn_aux.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/exprn_aux.m,v
retrieving revision 1.76
diff -u -r1.76 exprn_aux.m
--- compiler/exprn_aux.m	26 Sep 2006 03:53:12 -0000	1.76
+++ compiler/exprn_aux.m	13 Oct 2006 09:25:14 -0000
@@ -169,13 +169,13 @@
 
 :- pred addr_is_constant(code_addr::in, exprn_opts::in, bool::out) is det.
 
-addr_is_constant(label(Label), ExprnOpts, IsConst) :-
+addr_is_constant(code_label(Label), ExprnOpts, IsConst) :-
     ExprnOpts = nlg_asm_sgt_ubf(NonLocalGotos, AsmLabels, _SGT, _UBF),
     label_is_constant(Label, NonLocalGotos, AsmLabels, IsConst).
-addr_is_constant(imported(_), ExprnOpts, IsConst) :-
+addr_is_constant(code_imported_proc(_), ExprnOpts, IsConst) :-
     ExprnOpts = nlg_asm_sgt_ubf(NonLocalGotos, AsmLabels, _SGT, _UBF),
     globals.imported_is_constant(NonLocalGotos, AsmLabels, IsConst).
-addr_is_constant(succip, _, no).
+addr_is_constant(code_succip, _, no).
 addr_is_constant(do_succeed(_), _, no).
 addr_is_constant(do_redo, _, no).
 addr_is_constant(do_fail, _, no).
@@ -187,15 +187,15 @@
 
 :- pred label_is_constant(label::in, bool::in, bool::in, bool::out) is det.
 
-label_is_constant(entry(entry_label_exported, _), NonLocalGotos, AsmLabels,
-        IsConst) :-
+label_is_constant(entry_label(entry_label_exported, _),
+        NonLocalGotos, AsmLabels, IsConst) :-
     globals.imported_is_constant(NonLocalGotos, AsmLabels, IsConst).
-label_is_constant(entry(entry_label_local, _), NonLocalGotos, AsmLabels,
-        IsConst) :-
+label_is_constant(entry_label(entry_label_local, _),
+        NonLocalGotos, AsmLabels, IsConst) :-
     globals.imported_is_constant(NonLocalGotos, AsmLabels, IsConst).
-label_is_constant(entry(entry_label_c_local, _), _NonLocalGotos, _AsmLabels,
-        yes).
-label_is_constant(internal(_, _), _NonLocalGotos, _AsmLabels, yes).
+label_is_constant(entry_label(entry_label_c_local, _),
+        _NonLocalGotos, _AsmLabels, yes).
+label_is_constant(internal_label(_, _), _NonLocalGotos, _AsmLabels, yes).
 
 %-----------------------------------------------------------------------------%
 
Index: compiler/frameopt.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/frameopt.m,v
retrieving revision 1.105
diff -u -r1.105 frameopt.m
--- compiler/frameopt.m	20 Sep 2006 09:42:04 -0000	1.105
+++ compiler/frameopt.m	13 Oct 2006 09:25:17 -0000
@@ -293,7 +293,7 @@
         MkframeInstr = MkframeUinstr - MkframeComment,
         find_succeed_labels(Instrs1, map.init, SuccMap),
         counter.allocate(KeepFrameLabelNum, !C),
-        KeepFrameLabel = internal(KeepFrameLabelNum, ProcLabel),
+        KeepFrameLabel = internal_label(KeepFrameLabelNum, ProcLabel),
         keep_nondet_frame(Remain, Instrs2, ProcLabel, KeepFrameLabel,
             MkframeUinstr, SuccMap, LayoutLabels, no, yes)
     ->
@@ -345,8 +345,8 @@
     (
         % Look for nondet style tailcalls which do not need
         % a runtime check.
-        Uinstr0 = llcall(label(entry(_, ProcLabel)), label(RetLabel),
-            _, _, _, CallModel),
+        Uinstr0 = llcall(code_label(entry_label(_, ProcLabel)),
+            code_label(RetLabel), _, _, _, CallModel),
         CallModel = call_model_nondet(unchecked_tail_call),
         map.search(SuccMap, RetLabel, BetweenIncl),
         BetweenIncl = [livevals(_) - _, goto(_) - _],
@@ -359,7 +359,7 @@
         NewComment = Comment ++ " (nondet tailcall)",
         Instrs = [
             livevals(Livevals) - "",
-            goto(label(KeepFrameLabel)) - NewComment
+            goto(code_label(KeepFrameLabel)) - NewComment
             | Instrs1
         ]
     ;
@@ -530,7 +530,7 @@
                 Instrs = [Instr0 | Instrs1]
             ;
                 counter.allocate(N, !C),
-                NewLabel = internal(N, ProcLabel),
+                NewLabel = internal_label(N, ProcLabel),
                 NewInstr = label(NewLabel) - "",
                 divide_into_basic_blocks(Instrs0, ProcLabel, Instrs1, !C),
                 Instrs = [Instr0, NewInstr | Instrs1]
@@ -555,7 +555,7 @@
     (
         list.split_last(BlockInstrs, MostInstrs, LastInstr),
         Labels = [NextLabel | _],
-        LastInstr = goto(label(NextLabel)) - _
+        LastInstr = goto(code_label(NextLabel)) - _
     ->
         % Optimize away the redundant goto, which we probably introduced.
         % The next invocation of jumpopt would also do this, but doing it here
@@ -626,10 +626,11 @@
             % updating LabelSeq and BlockMap.
 
             counter.allocate(EmptyN, !C),
-            EmptyLabel = internal(EmptyN, ProcLabel),
+            EmptyLabel = internal_label(EmptyN, ProcLabel),
 
             % The fb_jump_dests and fb_fall_dest fields are only dummies.
-            FallThroughToEmptyInstr = goto(label(EmptyLabel)) - "fall through",
+            FallThroughToEmptyInstr = goto(code_label(EmptyLabel))
+                - "fall through",
             BlockInfo = frame_block_info(Label,
                 [Instr0 | EntryInstrs] ++ [FallThroughToEmptyInstr],
                 FallInto, [], no, entry_block(EntryInfo)),
@@ -645,14 +646,14 @@
                 Instrs2 = Instrs1
             ;
                 counter.allocate(N, !C),
-                NextLabel = internal(N, ProcLabel),
+                NextLabel = internal_label(N, ProcLabel),
                 NextLabelInstr = label(NextLabel) - "",
                 Instrs2 = [NextLabelInstr | Instrs1]
             ),
 
             EmptyLabelInstr = label(EmptyLabel) - "",
             FallThroughFromEmptyInstr =
-                goto(label(NextLabel)) - "fall through",
+                goto(code_label(NextLabel)) - "fall through",
             % The fb_jump_dests and fb_fall_dest fields are only dummies.
             EmptyBlockType = ordinary_block(block_doesnt_need_frame,
                 is_post_entry_dummy),
@@ -697,10 +698,10 @@
             % comment, we don't substitute labels used as code addresses
             % in assignments to redoip slots.
             counter.allocate(N, !C),
-            ExitLabel = internal(N, ProcLabel),
+            ExitLabel = internal_label(N, ProcLabel),
 
             compute_block_needs_frame(Label, Extra, NeedsFrame),
-            FallThroughInstr = goto(label(ExitLabel)) - "fall through",
+            FallThroughInstr = goto(code_label(ExitLabel)) - "fall through",
             % The fb_jump_dests and fb_fall_dest fields are only dummies.
             (
                 Extra = [],
@@ -954,8 +955,8 @@
         % maxfr and succip.
         Maxfr = [MaxfrInstr],
         SuccipRestore = [SuccipRestoreInstr],
-        ( GotoTarget = label(entry(_, _))
-        ; GotoTarget = imported(_)
+        ( GotoTarget = code_label(entry_label(_, _))
+        ; GotoTarget = code_imported_proc(_)
         ),
         ExitInfo = nondet_teardown_exit(SuccipRestoreInstr,
             MaxfrInstr, CurfrInstr, Livevals, Goto)
@@ -1241,7 +1242,7 @@
             MaybeFallThrough = no
         ),
         (
-            LastUinstr = goto(label(GotoLabel)),
+            LastUinstr = goto(code_label(GotoLabel)),
             matching_label_ref(FirstLabel, GotoLabel)
         ->
             !:JumpToStart = yes
@@ -1259,8 +1260,8 @@
 
 :- pred local_label(proc_label::in, label::in) is semidet.
 
-local_label(ProcLabel, entry(_, ProcLabel)).
-local_label(ProcLabel, internal(_, ProcLabel)).
+local_label(ProcLabel, entry_label(_, ProcLabel)).
+local_label(ProcLabel, internal_label(_, ProcLabel)).
 
     % The form of a label used in a tailcall may be different from
     % the form used in the initial label. The initial label may be
@@ -1275,8 +1276,8 @@
 :- pred matching_label_ref(label::in, label::in) is semidet.
 
 matching_label_ref(FirstLabel, GotoLabel) :-
-    FirstLabel = entry(FirstLabelType, ProcLabel),
-    GotoLabel = entry(GotoLabelType, ProcLabel),
+    FirstLabel = entry_label(FirstLabelType, ProcLabel),
+    GotoLabel = entry_label(GotoLabelType, ProcLabel),
     matching_entry_type(FirstLabelType, GotoLabelType).
 
 :- pred matching_entry_type(entry_label_type::in, entry_label_type::in)
@@ -1297,7 +1298,7 @@
     Instr = Uinstr - _,
     (
         Uinstr = assign(redoip_slot(_),
-            const(llconst_code_addr(label(Label)))),
+            const(llconst_code_addr(code_label(Label)))),
         get_proc_label(Label) = ProcLabel
     ->
         !:RedoipLabels = [Label | !.RedoipLabels]
@@ -1369,7 +1370,7 @@
     (
         BlockInfo0 = frame_block_info(Label, OrigInstrs, FallInto, [_], no,
             exit_block(det_exit(Succip, Livevals, Goto))),
-        Goto = goto(label(GotoLabel)) - Comment,
+        Goto = goto(code_label(GotoLabel)) - Comment,
         matching_label_ref(FirstLabel, GotoLabel)
     ->
         (
@@ -1382,7 +1383,7 @@
                 "keep_frame_transform: block does not begin with label")
         ),
         string.append(Comment, " (keeping frame)", NewComment),
-        NewGoto = goto(label(SecondLabel)) - NewComment,
+        NewGoto = goto(code_label(SecondLabel)) - NewComment,
         LivevalsGoto = Livevals ++ [NewGoto],
         (
             CanClobberSuccip = yes,
@@ -1925,7 +1926,7 @@
         ( FallThroughLabel = FallThroughLabel0 ->
             RedirectFallThrough = []
         ;
-            RedirectFallThrough = [goto(label(FallThroughLabel))
+            RedirectFallThrough = [goto(code_label(FallThroughLabel))
                 - "redirect fallthrough"]
             % We can expect this jump to be optimized away in most cases.
         )
@@ -2083,7 +2084,7 @@
         (
             PrevNeedsFrame = block_needs_frame(Reasons),
             counter.allocate(N, !C),
-            JumpAroundLabel = internal(N, ProcLabel),
+            JumpAroundLabel = internal_label(N, ProcLabel),
             % By not including a label instruction at the start of
             % JumpAroundCode, we are breaking an invariant of frame_block_maps.
             % However, we don't execute any code during or after
@@ -2091,7 +2092,7 @@
             % including the label saves memory and reduces the amount of work
             % labelopt has to do. (The label *would* be optimized away, since
             % it can't be referred to from anywhere.)
-            JumpAroundCode = [goto(label(Label0)) - "jump around setup"],
+            JumpAroundCode = [goto(code_label(Label0)) - "jump around setup"],
             Labels = [JumpAroundLabel, SetupLabel, Label0 | Labels1],
             JumpAroundReason = jump_around(Label0, Reasons),
             JumpAroundBlockInfo = frame_block_info(JumpAroundLabel,
@@ -2163,7 +2164,7 @@
 :- func nondet_non_teardown_exit_code(nondet_exit_info) = list(instruction).
 
 nondet_non_teardown_exit_code(nondet_plain_exit(Livevals, _Goto)) =
-    Livevals ++ [goto(succip) - ""].
+    Livevals ++ [goto(code_succip) - ""].
 nondet_non_teardown_exit_code(nondet_teardown_exit(_, _, _, Livevals, Goto)) =
     Livevals ++ [Goto].
 
@@ -2181,7 +2182,7 @@
         ParallelLabel = OldParallel
     ;
         counter.allocate(N, !C),
-        NewParallel = internal(N, ProcLabel),
+        NewParallel = internal_label(N, ProcLabel),
         ParallelLabel = NewParallel,
         map.det_insert(ParMap0, Label, NewParallel, ParMap),
         !:SetupParMap = setup_par_map(ParMap)
@@ -2199,7 +2200,7 @@
         ParallelLabel = OldParallel
     ;
         counter.allocate(N, !C),
-        NewParallel = internal(N, ProcLabel),
+        NewParallel = internal_label(N, ProcLabel),
         ParallelLabel = NewParallel,
         map.det_insert(ParMap0, Label, NewParallel, ParMap),
         !:ExitParMap = exit_par_map(ParMap)
Index: compiler/goal_util.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/goal_util.m,v
retrieving revision 1.138
diff -u -r1.138 goal_util.m
--- compiler/goal_util.m	20 Sep 2006 09:42:04 -0000	1.138
+++ compiler/goal_util.m	13 Oct 2006 07:42:29 -0000
@@ -67,10 +67,11 @@
 % occur as a key in the mapping, then the variable is left unsubstituted.
 
     % rename_vars_in_goals(MustRename, Substitution, GoalList, NewGoalList).
+    %
 :- pred rename_vars_in_goals(bool::in, prog_var_renaming::in,
     hlds_goals::in, hlds_goals::out) is det.
 
-:- pred rename_vars_in_goal(prog_var_renaming::in,
+:- 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,
@@ -268,7 +269,8 @@
     hlds_goal::in, instmap::in, hlds_goal::in, bool::out,
     module_info::in, module_info::out, io::di, io::uo) is det.
 
-    % reordering_maintains_termination(ModuleInfo, FullyStrict, Goal1, Goal2).
+    % reordering_maintains_termination_old(ModuleInfo, FullyStrict,
+    %   Goal1, Goal2).
     %
     % Succeeds if any possible change in termination behaviour from reordering
     % the goals is allowed according to the semantics options.
@@ -278,7 +280,7 @@
     % NOTE: this version is deprecated; new code should use the following
     %       version because it supports the intermodule-analysis framework.
     %
-:- pred reordering_maintains_termination(module_info::in, bool::in,
+:- pred reordering_maintains_termination_old(module_info::in, bool::in,
     hlds_goal::in, hlds_goal::in) is semidet.
 
     % reordering_maintains_termination(FullyStrict, Goal1, Goal2, Result,
@@ -343,7 +345,7 @@
     % be necessary when casting, say, solver type values with inst
     % any, or casting between enumeration types and ints.
     %
-:- pred generate_cast(cast_kind::in, prog_var::in, prog_var::in,
+:- pred generate_cast_with_insts(cast_kind::in, prog_var::in, prog_var::in,
     mer_inst::in, mer_inst::in, prog_context::in, hlds_goal::out) is det.
 
 %-----------------------------------------------------------------------------%
@@ -490,7 +492,7 @@
 
 %-----------------------------------------------------------------------------%
 
-rename_vars_in_goal(Subn, Goal0, Goal) :-
+rename_some_vars_in_goal(Subn, Goal0, Goal) :-
     rename_vars_in_goal(no, Subn, Goal0, Goal).
 
 must_rename_vars_in_goal(Subn, Goal0, Goal) :-
@@ -1417,7 +1419,7 @@
     EarlierTrace = contains_no_trace_goal,
     LaterTrace = contains_no_trace_goal,
 
-    reordering_maintains_termination(ModuleInfo, FullyStrict,
+    reordering_maintains_termination_old(ModuleInfo, FullyStrict,
         EarlierGoal, LaterGoal),
 
     % Don't reorder the goals if the later goal depends on the outputs
@@ -1485,7 +1487,7 @@
         )
     ).
 
-reordering_maintains_termination(ModuleInfo, FullyStrict,
+reordering_maintains_termination_old(ModuleInfo, FullyStrict,
         EarlierGoal, LaterGoal) :-
     EarlierGoal = _ - EarlierGoalInfo,
     LaterGoal = _ - LaterGoalInfo,
@@ -1634,9 +1636,11 @@
 
 generate_cast(CastType, InArg, OutArg, Context, Goal) :-
     Ground = ground_inst,
-    generate_cast(CastType, InArg, OutArg, Ground, Ground, Context, Goal).
+    generate_cast_with_insts(CastType, InArg, OutArg, Ground, Ground, Context,
+        Goal).
 
-generate_cast(CastType, InArg, OutArg, InInst, OutInst, Context, Goal) :-
+generate_cast_with_insts(CastType, InArg, OutArg, InInst, OutInst, Context,
+        Goal) :-
     set.list_to_set([InArg, OutArg], NonLocals),
     instmap_delta_from_assoc_list([OutArg - OutInst], InstMapDelta),
     goal_info_init(NonLocals, InstMapDelta, detism_det, purity_pure, Context,
Index: compiler/hlds_out.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/hlds_out.m,v
retrieving revision 1.407
diff -u -r1.407 hlds_out.m
--- compiler/hlds_out.m	13 Oct 2006 04:52:18 -0000	1.407
+++ compiler/hlds_out.m	13 Oct 2006 08:19:32 -0000
@@ -71,9 +71,9 @@
     is det.
 :- func pred_proc_id_to_string(module_info, pred_proc_id) = string.
 
-:- pred write_pred_proc_id(module_info::in, pred_id::in, proc_id::in,
+:- pred write_pred_proc_id_pair(module_info::in, pred_id::in, proc_id::in,
     io::di, io::uo) is det.
-:- func pred_proc_id_to_string(module_info, pred_id, proc_id) = string.
+:- func pred_proc_id_pair_to_string(module_info, pred_id, proc_id) = string.
 
 :- pred write_call_id(call_id::in, io::di, io::uo) is det.
 :- func call_id_to_string(call_id) = string.
@@ -398,15 +398,16 @@
     ).
 
 write_pred_proc_id(ModuleInfo, proc(PredId, ProcId), !IO) :-
-    write_pred_proc_id(ModuleInfo, PredId, ProcId, !IO).
+    write_pred_proc_id_pair(ModuleInfo, PredId, ProcId, !IO).
 
 pred_proc_id_to_string(ModuleInfo, proc(PredId, ProcId)) =
-    pred_proc_id_to_string(ModuleInfo, PredId, ProcId).
+    pred_proc_id_pair_to_string(ModuleInfo, PredId, ProcId).
 
-write_pred_proc_id(ModuleInfo, PredId, ProcId, !IO) :-
-    io.write_string(pred_proc_id_to_string(ModuleInfo, PredId, ProcId), !IO).
+write_pred_proc_id_pair(ModuleInfo, PredId, ProcId, !IO) :-
+    io.write_string(pred_proc_id_pair_to_string(ModuleInfo, PredId, ProcId),
+        !IO).
 
-pred_proc_id_to_string(ModuleInfo, PredId, ProcId) = Str :-
+pred_proc_id_pair_to_string(ModuleInfo, PredId, ProcId) = Str :-
     proc_id_to_int(ProcId, ModeNum),
     Str = pred_id_to_string(ModuleInfo, PredId)
         ++ " mode " ++ int_to_string(ModeNum).
@@ -1734,8 +1735,8 @@
             ),
             write_indent(Indent, !IO),
             write_purity_prefix(Purity, !IO),
-            write_functor(term.atom("call"),
-                [PredVar | ArgVars], VarSet, AppendVarNums, !IO)
+            write_functor(term.atom("call"), [PredVar | ArgVars], VarSet,
+                AppendVarNums, !IO)
         ;
             PredOrFunc = function,
             ( string.contains_char(Verbose, 'l') ->
@@ -2616,31 +2617,31 @@
             AppendVarNums, !IO)
     ;
         PredName = unqualified(Name),
-        write_functor(term.atom(Name), ArgVars, VarSet, AppendVarNums,
-            next_to_graphic_token, !IO)
+        write_functor_maybe_needs_quotes(term.atom(Name), ArgVars, VarSet,
+            AppendVarNums, next_to_graphic_token, !IO)
     ).
 
 write_functor(Functor, ArgVars, VarSet, AppendVarNums, !IO) :-
-    write_functor(Functor, ArgVars, VarSet, AppendVarNums,
+    write_functor_maybe_needs_quotes(Functor, ArgVars, VarSet, AppendVarNums,
         not_next_to_graphic_token, !IO).
 
 functor_to_string(Functor, ArgVars, VarSet, AppendVarNums) =
-    functor_to_string(Functor, ArgVars, VarSet, AppendVarNums,
-        not_next_to_graphic_token).
+    functor_to_string_maybe_needs_quotes(Functor, ArgVars, VarSet,
+        AppendVarNums, not_next_to_graphic_token).
 
-:- pred write_functor(const::in, list(prog_var)::in, prog_varset::in,
-    bool::in, needs_quotes::in, io::di, io::uo) is det.
+:- pred write_functor_maybe_needs_quotes(const::in, list(prog_var)::in,
+    prog_varset::in, bool::in, needs_quotes::in, io::di, io::uo) is det.
 
-write_functor(Functor, ArgVars, VarSet, AppendVarNums, NextToGraphicToken,
-        !IO) :-
-    io.write_string(functor_to_string(Functor, ArgVars, VarSet,
-        AppendVarNums, NextToGraphicToken), !IO).
+write_functor_maybe_needs_quotes(Functor, ArgVars, VarSet, AppendVarNums,
+        NextToGraphicToken, !IO) :-
+    io.write_string(functor_to_string_maybe_needs_quotes(Functor, ArgVars,
+        VarSet, AppendVarNums, NextToGraphicToken), !IO).
 
-:- func functor_to_string(const, list(prog_var), prog_varset,
-    bool, needs_quotes) = string.
+:- func functor_to_string_maybe_needs_quotes(const, list(prog_var),
+    prog_varset, bool, needs_quotes) = string.
 
-functor_to_string(Functor, ArgVars, VarSet, AppendVarNums, NextToGraphicToken)
-        = Str :-
+functor_to_string_maybe_needs_quotes(Functor, ArgVars, VarSet, AppendVarNums,
+        NextToGraphicToken) = Str :-
     term.context_init(Context),
     term.var_list_to_term_list(ArgVars, ArgTerms),
     Term = term.functor(Functor, ArgTerms, Context),
@@ -2661,7 +2662,7 @@
 qualified_functor_to_string(ModuleName, Functor, ArgVars, VarSet,
         AppendVarNums) = Str :-
     ModuleNameStr = mercury_bracketed_sym_name_to_string(ModuleName),
-    FunctorStr = functor_to_string(Functor, ArgVars, VarSet,
+    FunctorStr = functor_to_string_maybe_needs_quotes(Functor, ArgVars, VarSet,
         AppendVarNums, next_to_graphic_token),
     Str = ModuleNameStr ++ "." ++ FunctorStr.
 
@@ -2699,8 +2700,8 @@
                 ArgVars, VarSet, AppendVarNums)
         ;
             SymName = unqualified(Name),
-            Str = functor_to_string(term.atom(Name), ArgVars, VarSet,
-                AppendVarNums, next_to_graphic_token)
+            Str = functor_to_string_maybe_needs_quotes(term.atom(Name),
+                ArgVars, VarSet, AppendVarNums, next_to_graphic_token)
         )
     ;
         ConsId = int_const(Int),
@@ -2736,12 +2737,12 @@
             ++ ", " ++ int_to_string(Arity) ++ "), " ++ Instance ++ ")"
     ;
         ConsId = type_info_cell_constructor(_),
-        Str = functor_to_string(
+        Str = functor_to_string_maybe_needs_quotes(
             term.atom("type_info_cell_constructor"),
             ArgVars, VarSet, AppendVarNums, next_to_graphic_token)
     ;
         ConsId = typeclass_info_cell_constructor,
-        Str = functor_to_string(
+        Str = functor_to_string_maybe_needs_quotes(
             term.atom("typeclass_info_cell_constructor"),
             ArgVars, VarSet, AppendVarNums, next_to_graphic_token)
     ;
@@ -3956,26 +3957,28 @@
 
 add_mode_qualifier(Context, HeadTerm - Mode) = AnnotatedTerm :-
     construct_qualified_term(unqualified("::"),
-        [HeadTerm, mode_to_term(Context, Mode)], Context, AnnotatedTerm).
+        [HeadTerm, mode_to_term_with_context(Context, Mode)],
+        Context, AnnotatedTerm).
 
-mode_to_term(Mode) = mode_to_term(term.context_init, Mode).
+mode_to_term(Mode) = mode_to_term_with_context(term.context_init, Mode).
 
-:- func mode_to_term(term.context, mer_mode) = prog_term.
+:- func mode_to_term_with_context(term.context, mer_mode) = prog_term.
 
-mode_to_term(Context, (InstA -> InstB)) = Term :-
+mode_to_term_with_context(Context, (InstA -> InstB)) = Term :-
     (
         % Check for higher-order pred or func modes, and output them
         % in a nice format.
         InstA = ground(_Uniq, higher_order(_)),
         InstB = InstA
     ->
-        Term = inst_to_term(InstA, Context)
+        Term = inst_to_term_with_context(InstA, Context)
     ;
         construct_qualified_term(unqualified(">>"),
-            [inst_to_term(InstA, Context), inst_to_term(InstB, Context)],
+            [inst_to_term_with_context(InstA, Context),
+            inst_to_term_with_context(InstB, Context)],
             Context, Term)
     ).
-mode_to_term(Context, user_defined_mode(Name, Args)) = Term :-
+mode_to_term_with_context(Context, user_defined_mode(Name, Args)) = Term :-
     construct_qualified_term(Name, list.map(map_inst_to_term(Context), Args),
         Context, Term).
 
@@ -3986,40 +3989,40 @@
 
 :- func map_inst_to_term(prog_context, mer_inst) = prog_term.
 
-map_inst_to_term(Context, Inst) = inst_to_term(Inst, Context).
+map_inst_to_term(Context, Inst) = inst_to_term_with_context(Inst, Context).
 
-inst_to_term(Inst) = inst_to_term(Inst, term.context_init).
+inst_to_term(Inst) = inst_to_term_with_context(Inst, term.context_init).
 
-:- func inst_to_term(mer_inst, prog_context) = prog_term.
+:- func inst_to_term_with_context(mer_inst, prog_context) = prog_term.
 
-inst_to_term(any(Uniq), Context) =
+inst_to_term_with_context(any(Uniq), Context) =
     make_atom(any_inst_uniqueness(Uniq), Context).
-inst_to_term(free, Context) =
+inst_to_term_with_context(free, Context) =
     make_atom("free", Context).
-inst_to_term(free(Type), Context) = Term :-
+inst_to_term_with_context(free(Type), Context) = Term :-
     unparse_type(Type, Term0),
     Term1 = term.coerce(Term0),
     Term = term.functor(term.atom("free"), [Term1], Context).
-inst_to_term(bound(Uniq, BoundInsts), Context) = Term :-
+inst_to_term_with_context(bound(Uniq, BoundInsts), Context) = Term :-
     construct_qualified_term(unqualified(inst_uniqueness(Uniq, "bound")),
         [bound_insts_to_term(BoundInsts, Context)], Context, Term).
-inst_to_term(ground(Uniq, GroundInstInfo), Context) = Term :-
+inst_to_term_with_context(ground(Uniq, GroundInstInfo), Context) = Term :-
     (
         GroundInstInfo = higher_order(pred_inst_info(PredOrFunc, Modes, Det)),
         % XXX we ignore Uniq
         (
             PredOrFunc = predicate,
             construct_qualified_term(unqualified("pred"),
-                list.map(mode_to_term(Context), Modes),
+                list.map(mode_to_term_with_context(Context), Modes),
                 Context, ModesTerm)
         ;
             PredOrFunc = function,
             pred_args_to_func_args(Modes, ArgModes, RetMode),
             construct_qualified_term(unqualified("func"),
-                list.map(mode_to_term(Context), ArgModes),
+                list.map(mode_to_term_with_context(Context), ArgModes),
                 Context, ArgModesTerm),
             construct_qualified_term(unqualified("="),
-                [ArgModesTerm, mode_to_term(Context, RetMode)],
+                [ArgModesTerm, mode_to_term_with_context(Context, RetMode)],
                 Context, ModesTerm)
         ),
         construct_qualified_term(unqualified("is"), [
@@ -4028,18 +4031,18 @@
         GroundInstInfo = none,
         Term = make_atom(inst_uniqueness(Uniq, "ground"), Context)
     ).
-inst_to_term(inst_var(Var), _) =
+inst_to_term_with_context(inst_var(Var), _) =
     term.coerce(term.variable(Var)).
-inst_to_term(constrained_inst_vars(Vars, Inst), Context) =
+inst_to_term_with_context(constrained_inst_vars(Vars, Inst), Context) =
     set.fold(func(Var, Term) =
             term.functor(term.atom("=<"),
                 [term.coerce(term.variable(Var)), Term], Context),
-        Vars, inst_to_term(Inst, Context)).
-inst_to_term(abstract_inst(Name, Args), Context) =
+        Vars, inst_to_term_with_context(Inst, Context)).
+inst_to_term_with_context(abstract_inst(Name, Args), Context) =
     inst_name_to_term(user_inst(Name, Args), Context).
-inst_to_term(defined_inst(InstName), Context) =
+inst_to_term_with_context(defined_inst(InstName), Context) =
     inst_name_to_term(InstName, Context).
-inst_to_term(not_reached, Context) =
+inst_to_term_with_context(not_reached, Context) =
     make_atom("not_reached", Context).
 
 :- func inst_name_to_term(inst_name, prog_context) = prog_term.
Index: compiler/interval.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/interval.m,v
retrieving revision 1.23
diff -u -r1.23 interval.m
--- compiler/interval.m	27 Sep 2006 06:16:54 -0000	1.23
+++ compiler/interval.m	13 Oct 2006 07:33:35 -0000
@@ -968,7 +968,7 @@
 record_decisions_in_goal(Goal0, Goal, !VarInfo, !VarRename, _InsertMap,
         _MaybeFeature) :-
     Goal0 = unify(_, _, _, _, _) - _,
-    rename_vars_in_goal(!.VarRename, Goal0, Goal).
+    rename_some_vars_in_goal(!.VarRename, Goal0, Goal).
 
 record_decisions_in_goal(shorthand(_) - _, _, !VarInfo, !VarRename, _, _) :-
     unexpected(this_file, "shorthand in record_decisions_in_goal").
@@ -1033,9 +1033,9 @@
             VarTypes0, VarTypes, map.init, NewRename, map.init, VoidRename),
         !:VarInfo = var_info(VarSet, VarTypes),
         map.old_merge(!.VarRename, NewRename, !:VarRename),
-        % We rename the original goal
-        rename_vars_in_goal(!.VarRename, Goal2, Goal3),
-        rename_vars_in_goal(VoidRename, Goal3, Goal)
+        % We rename the original goal.
+        rename_some_vars_in_goal(!.VarRename, Goal2, Goal3),
+        rename_some_vars_in_goal(VoidRename, Goal3, Goal)
     ;
         unexpected(this_file, "make_inserted_goal: not a deconstruct")
     ).
@@ -1084,7 +1084,7 @@
 record_decisions_at_call_site(Goal0, Goal, !VarInfo, !VarRename,
         MustHaveMap, InsertMap, MaybeFeature) :-
     Goal0 = _ - GoalInfo0,
-    rename_vars_in_goal(!.VarRename, Goal0, Goal1),
+    rename_some_vars_in_goal(!.VarRename, Goal0, Goal1),
     (
         goal_info_maybe_get_maybe_need_across_call(GoalInfo0,
             MaybeNeedAcrossCall),
@@ -1164,7 +1164,7 @@
     ( map.is_empty(Subst) ->
         Goal = Goal0
     ;
-        goal_util.rename_vars_in_goal(Subst, Goal0, Goal)
+        goal_util.rename_some_vars_in_goal(Subst, Goal0, Goal)
     ).
 
 :- pred build_headvar_subst(list(prog_var)::in, rename_map::in,
Index: compiler/ite_gen.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/ite_gen.m,v
retrieving revision 1.93
diff -u -r1.93 ite_gen.m
--- compiler/ite_gen.m	6 Sep 2006 04:02:55 -0000	1.93
+++ compiler/ite_gen.m	13 Oct 2006 08:44:22 -0000
@@ -207,7 +207,7 @@
 
     code_info.get_next_label(EndLabel, !CI),
     JumpToEndCode = node([
-        goto(label(EndLabel)) - "Jump to the end of if-then-else"
+        goto(code_label(EndLabel)) - "Jump to the end of if-then-else"
     ]),
     EndLabelCode = node([
         label(EndLabel) - "end of if-then-else"
Index: compiler/jumpopt.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/jumpopt.m,v
retrieving revision 1.93
diff -u -r1.93 jumpopt.m
--- compiler/jumpopt.m	26 Sep 2006 03:53:16 -0000	1.93
+++ compiler/jumpopt.m	13 Oct 2006 09:25:20 -0000
@@ -197,7 +197,7 @@
         % Put the start of the procedure into Blockmap only after
         % frameopt has had a shot at it.
         (
-            ( Label = internal(_, _)
+            ( Label = internal_label(_, _)
             ; Recjump = yes
             )
         ->
@@ -291,7 +291,7 @@
     (
         Uinstr0 = llcall(Proc, RetAddr, LiveInfos, Context, GoalPath,
             CallModel),
-        ( RetAddr = label(RetLabel) ->
+        ( RetAddr = code_label(RetLabel) ->
             (
                 % Look for det style tailcalls. We look for this even if
                 % the call is semidet, because one of the optimizations below
@@ -352,10 +352,10 @@
                 not set.member(RetLabel, LayoutLabels)
             ->
                 counter.allocate(LabelNum, Counter0, Counter1),
-                NewLabel = internal(LabelNum, ProcLabel),
+                NewLabel = internal_label(LabelNum, ProcLabel),
                 NewInstrs = [
                     if_val(binop(ne, lval(curfr), lval(maxfr)),
-                        label(NewLabel))
+                        code_label(NewLabel))
                         - "branch around if cannot tail call",
                     assign(maxfr, lval(prevfr_slot(lval(curfr))))
                         - "discard this frame",
@@ -381,7 +381,7 @@
                 ( RetLabel = DestLabel ->
                     NewInstrs = [Instr0]
                 ;
-                    NewInstrs = [llcall(Proc, label(DestLabel), LiveInfos,
+                    NewInstrs = [llcall(Proc, code_label(DestLabel), LiveInfos,
                         Context, GoalPath, CallModel)
                         - redirect_comment(Comment0)]
                 ),
@@ -394,7 +394,7 @@
         )
     ;
         Uinstr0 = goto(TargetAddr),
-        ( TargetAddr = label(TargetLabel) ->
+        ( TargetAddr = code_label(TargetLabel) ->
             (
                 % Eliminate the goto if possible.
                 opt_util.is_this_label_next(TargetLabel, Instrs0, _)
@@ -402,7 +402,7 @@
                 NewInstrs = [],
                 NewRemain = specified(NewInstrs, Instrs0)
             ;
-                PrevInstr = if_val(_, label(IfTargetLabel)),
+                PrevInstr = if_val(_, code_label(IfTargetLabel)),
                 opt_util.is_this_label_next(IfTargetLabel, Instrs0, _)
             ->
                 % Eliminating the goto (by the local peephole pass)
@@ -418,14 +418,14 @@
                 map.search(Procmap, TargetLabel, Between0)
             ->
                 jumpopt.adjust_livevals(PrevInstr, Between0, Between),
-                NewInstrs = Between ++ [goto(succip) - "shortcircuit"],
+                NewInstrs = Between ++ [goto(code_succip) - "shortcircuit"],
                 NewRemain = specified(NewInstrs, Instrs0)
             ;
                 % Replace a jump to a semidet epilog with the epilog.
                 map.search(Sdprocmap, TargetLabel, Between0)
             ->
                 jumpopt.adjust_livevals(PrevInstr, Between0, Between),
-                NewInstrs = Between ++ [goto(succip) - "shortcircuit"],
+                NewInstrs = Between ++ [goto(code_succip) - "shortcircuit"],
                 NewRemain = specified(NewInstrs, Instrs0)
             ;
                 % Replace a jump to a nondet epilog with the epilog.
@@ -485,7 +485,7 @@
                     ( TargetLabel = DestLabel ->
                         NewInstrs0 = [Instr0]
                     ;
-                        NewInstrs0 = [goto(label(DestLabel)) - Shorted]
+                        NewInstrs0 = [goto(code_label(DestLabel)) - Shorted]
                     )
                 ),
                 ( map.search(Lvalmap, DestLabel, yes(Lvalinstr)) ->
@@ -514,7 +514,7 @@
         )
     ;
         Uinstr0 = if_val(Cond, TargetAddr),
-        ( TargetAddr = label(TargetLabel) ->
+        ( TargetAddr = code_label(TargetLabel) ->
             (
                 % Attempt to transform code such as
                 %
@@ -547,7 +547,7 @@
                     HaveLabel = no
                 ),
                 GotoInstr = goto(GotoTarget) - GotoComment,
-                ( HaveLabel = no ; GotoTarget = label(_) ),
+                ( HaveLabel = no ; GotoTarget = code_label(_) ),
                 opt_util.skip_comments(AfterGoto, AfterGotoComments),
                 AfterGotoComments = [LabelInstr | _],
                 LabelInstr = label(TargetLabel) - _
@@ -589,7 +589,7 @@
                 Instrs1 = [GotoInstr | AfterGoto],
                 GotoInstr = goto(GotoAddr) - GotoComment,
                 \+ (
-                    GotoAddr = label(GotoLabel),
+                    GotoAddr = code_label(GotoLabel),
                     map.search(Blockmap, GotoLabel, _)
                 )
             ->
@@ -597,7 +597,7 @@
                 NewIfInstr = if_val(NotCond, GotoAddr) - GotoComment,
                 NewInstrs = [NewIfInstr],
                 NewGotoComment = Comment0 ++ " (switched)",
-                NewGotoInstr = goto(label(TargetLabel)) - NewGotoComment,
+                NewGotoInstr = goto(code_label(TargetLabel)) - NewGotoComment,
                 RemainInstrs = [NewGotoInstr | AfterGoto],
                 NewRemain = specified(NewInstrs, RemainInstrs)
             ;
@@ -645,7 +645,7 @@
                         NewAssign = assign(reg(reg_r, 1), NewCond) -
                             "shortcircuit bool computation"
                     ),
-                    Proceed = goto(succip) - "shortcircuit",
+                    Proceed = goto(code_succip) - "shortcircuit",
                     NewInstrs = [NewAssign | Between] ++ [Proceed],
                     NewRemain = specified(NewInstrs, Instrs0)
                 ;
@@ -653,7 +653,8 @@
                     TargetLabel \= DestLabel
                 ->
                     Shorted = "shortcircuited jump: " ++ Comment0,
-                    NewInstrs = [if_val(Cond, label(DestLabel)) - Shorted],
+                    NewInstrs = [if_val(Cond, code_label(DestLabel))
+                        - Shorted],
                     NewRemain = specified(NewInstrs, Instrs0)
                 ;
                     NewRemain = usual_case
@@ -677,13 +678,14 @@
         )
     ;
         Uinstr0 = mkframe(FrameInfo, Redoip),
-        ( Redoip = yes(label(Label0)) ->
+        ( Redoip = yes(code_label(Label0)) ->
             jumpopt.short_label(Instrmap, Label0, Label),
             ( Label = Label0 ->
                 NewRemain = usual_case
             ;
                 Shorted = Comment0 ++ " (some shortcircuits)",
-                NewInstrs = [mkframe(FrameInfo, yes(label(Label))) - Shorted],
+                NewInstrs = [mkframe(FrameInfo, yes(code_label(Label)))
+                    - Shorted],
                 NewRemain = specified(NewInstrs, Instrs0)
             )
         ;
@@ -963,7 +965,7 @@
     (
         SrcInstr = SrcUinstr - _Comment,
         (
-            SrcUinstr = goto(label(TargetLabel))
+            SrcUinstr = goto(code_label(TargetLabel))
         ;
             SrcUinstr = label(TargetLabel)
         ),
@@ -1009,9 +1011,9 @@
         llconst_multi_string(L, S)).
 jumpopt.short_labels_const(Instrmap, llconst_code_addr(CodeAddr0),
         llconst_code_addr(CodeAddr)) :-
-    ( CodeAddr0 = label(Label0) ->
+    ( CodeAddr0 = code_label(Label0) ->
         jumpopt.short_label(Instrmap, Label0, Label),
-        CodeAddr = label(Label)
+        CodeAddr = code_label(Label)
     ;
         CodeAddr = CodeAddr0
     ).
Index: compiler/labelopt.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/labelopt.m,v
retrieving revision 1.33
diff -u -r1.33 labelopt.m
--- compiler/labelopt.m	20 Sep 2006 09:42:06 -0000	1.33
+++ compiler/labelopt.m	13 Oct 2006 09:54:05 -0000
@@ -54,7 +54,7 @@
 
 labelopt_main(Final, LayoutLabelSet, Instrs0, Instrs, Mod) :-
     build_useset(Instrs0, LayoutLabelSet, Useset),
-    instr_list(Instrs0, Instrs1, Useset, Mod),
+    opt_labels_in_instr_list(Instrs0, Instrs1, Useset, Mod),
     (
         Final = yes,
         Mod = yes
@@ -82,29 +82,31 @@
     % preceded by code that cannot fall through.
     %
     % We build up the generated instruction list in reverse order in
-    % instr_list_2, because building it in right order here would make
-    % instr_list not tail recursive, and thus unable to handle very long
-    % instruction lists.
+    % opt_labels_in_instr_list_2, because building it in right order here
+    % would make opt_labels_in_instr_list not tail recursive, and thus unable
+    % to handle very long instruction lists.
     %
-:- pred instr_list(list(instruction)::in, list(instruction)::out,
+:- pred opt_labels_in_instr_list(list(instruction)::in, list(instruction)::out,
     set(label)::in, bool::out) is det.
 
-instr_list(Instrs0, Instrs, Useset, Mod) :-
+opt_labels_in_instr_list(Instrs0, Instrs, Useset, Mod) :-
     Fallthrough = yes,
-    instr_list_2(Instrs0, [], RevInstrs, no, Mod, Fallthrough, Useset),
+    opt_labels_in_instr_list_2(Instrs0, [], RevInstrs, no, Mod, Fallthrough,
+        Useset),
     list.reverse(RevInstrs, Instrs).
 
-:- pred instr_list_2(list(instruction)::in,
+:- pred opt_labels_in_instr_list_2(list(instruction)::in,
     list(instruction)::in, list(instruction)::out,
     bool::in, bool::out, bool::in, set(label)::in) is det.
 
-instr_list_2([], !RevInstrs, !Mod, _Fallthrough, _Useset).
-instr_list_2([Instr0 | Instrs0], !RevInstrs, !Mod, !.Fallthrough, Useset) :-
+opt_labels_in_instr_list_2([], !RevInstrs, !Mod, _Fallthrough, _Useset).
+opt_labels_in_instr_list_2([Instr0 | Instrs0], !RevInstrs, !Mod,
+        !.Fallthrough, Useset) :-
     Instr0 = Uinstr0 - _Comment,
     ( Uinstr0 = label(Label) ->
         (
             (
-                Label = entry(EntryType, _),
+                Label = entry_label(EntryType, _),
                 ( EntryType = entry_label_exported
                 ; EntryType = entry_label_local
                 )
@@ -133,7 +135,8 @@
             !:Fallthrough = no
         )
     ),
-    instr_list_2(Instrs0, !RevInstrs, !Mod, !.Fallthrough, Useset).
+    opt_labels_in_instr_list_2(Instrs0, !RevInstrs, !Mod,
+        !.Fallthrough, Useset).
 
     % Instead of removing eliminated instructions from the instruction list,
     % we can replace them by placeholder comments. The original comment field
Index: compiler/layout_out.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/layout_out.m,v
retrieving revision 1.74
diff -u -r1.74 layout_out.m
--- compiler/layout_out.m	2 Oct 2006 05:21:12 -0000	1.74
+++ compiler/layout_out.m	13 Oct 2006 09:25:31 -0000
@@ -234,20 +234,20 @@
         % This code should be kept in sync with make_label_layout_name/1 above.
         io.write_string(mercury_data_prefix, !IO),
         io.write_string("_label_layout__", !IO),
-        io.write_string(label_to_c_string(internal(LabelNum, ProcLabel), yes),
-            !IO)
+        io.write_string(
+            label_to_c_string(internal_label(LabelNum, ProcLabel), yes), !IO)
     ;
         Data = solver_event_layout(ProcLabel, LabelNum),
         io.write_string(mercury_data_prefix, !IO),
         io.write_string("_solver_event_layout__", !IO),
-        io.write_string(label_to_c_string(internal(LabelNum, ProcLabel), yes),
-            !IO)
+        io.write_string(
+            label_to_c_string(internal_label(LabelNum, ProcLabel), yes), !IO)
     ;
         Data = solver_event_attr_names(ProcLabel, LabelNum),
         io.write_string(mercury_data_prefix, !IO),
         io.write_string("_solver_event_attr_names__", !IO),
-        io.write_string(label_to_c_string(internal(LabelNum, ProcLabel), yes),
-            !IO)
+        io.write_string(
+            label_to_c_string(internal_label(LabelNum, ProcLabel), yes), !IO)
     ;
         Data = proc_layout(RttiProcLabel, _),
         io.write_string(mercury_data_prefix, !IO),
@@ -839,7 +839,7 @@
         _StackSlotCount, _Detism),
     (
         MaybeEntryLabel = yes(EntryLabel),
-        output_code_addr_decls(label(EntryLabel), !DeclSet, !IO)
+        output_code_addr_decls(code_label(EntryLabel), !DeclSet, !IO)
     ;
         MaybeEntryLabel = no
     ).
@@ -853,7 +853,7 @@
     io.write_string("{\n", !IO),
     (
         MaybeEntryLabel = yes(EntryLabel),
-        output_code_addr(label(EntryLabel), !IO)
+        output_code_addr(code_label(EntryLabel), !IO)
     ;
         MaybeEntryLabel = no,
         % The actual code address will be put into the structure
@@ -982,7 +982,7 @@
         proc_layout_exec_trace(RttiProcLabel), yes, !IO),
     io.write_string(" = {\nMR_LABEL_LAYOUT_REF(", !IO),
     ( CallLabelLayout = label_layout(CallProcLabel, CallLabelNum, _) ->
-        output_label(internal(CallLabelNum, CallProcLabel), no, !IO)
+        output_label(internal_label(CallLabelNum, CallProcLabel), no, !IO)
     ;
         unexpected(this_file, "output_layout_exec_trace: bad call layout")
     ),
@@ -1555,7 +1555,7 @@
         DataAddr = layout_addr(LayoutName),
         LayoutName = label_layout(ProcLabel, LabelNum, _)
     ->
-        Label = internal(LabelNum, ProcLabel)
+        Label = internal_label(LabelNum, ProcLabel)
     ;
         unexpected(this_file, "project_label_layout: not label layout")
     ).
@@ -1566,7 +1566,7 @@
 output_label_layout_addrs_in_vector([], !IO).
 output_label_layout_addrs_in_vector([Label | Labels], !IO) :-
     (
-        Label = internal(LabelNum, ProcLabel),
+        Label = internal_label(LabelNum, ProcLabel),
         groupable_labels(ProcLabel, 1, _N, [LabelNum], RevLabelNums,
             Labels, RemainingLabels)
     ->
@@ -1596,7 +1596,7 @@
         !.Labels = [Label | !:Labels],
         MaxChunkSize = 9,
         !.Count < MaxChunkSize, % leave room for the one we're adding
-        Label = internal(LabelNum, ProcLabel)
+        Label = internal_label(LabelNum, ProcLabel)
     ->
         !:Count = !.Count + 1,
         !:RevLabelsNums = [LabelNum | !.RevLabelsNums],
Index: compiler/live_vars.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/live_vars.m,v
retrieving revision 1.126
diff -u -r1.126 live_vars.m
--- compiler/live_vars.m	26 Sep 2006 03:53:13 -0000	1.126
+++ compiler/live_vars.m	13 Oct 2006 10:41:31 -0000
@@ -52,7 +52,7 @@
         T::in, T::out) is det
 ].
 
-:- pred build_live_sets_in_goal(hlds_goal::in, hlds_goal::out,
+:- pred build_live_sets_in_goal_no_par_stack(hlds_goal::in, hlds_goal::out,
     set(prog_var)::in, alloc_data::in, T::in, T::out,
     set(prog_var)::in, set(prog_var)::out,
     set(prog_var)::in, set(prog_var)::out) is det <= stack_alloc_info(T).
@@ -103,12 +103,12 @@
 % traversal of the goal. The liveness information is computed from the liveness
 % delta annotations.
 
-build_live_sets_in_goal(Goal0 - GoalInfo0, Goal - GoalInfo, ResumeVars0,
-        AllocData, !StackAlloc, !Liveness, !NondetLiveness) :-
+build_live_sets_in_goal_no_par_stack(Goal0 - GoalInfo0, Goal - GoalInfo,
+        ResumeVars0, AllocData, !StackAlloc, !Liveness, !NondetLiveness) :-
     ParStackVars0 = parallel_stackvars(set.init, [], set.init),
     build_live_sets_in_goal(Goal0 - GoalInfo0, Goal - GoalInfo, ResumeVars0,
-            AllocData, !StackAlloc, !Liveness, !NondetLiveness,
-            ParStackVars0, _ParStackVars).
+        AllocData, !StackAlloc, !Liveness, !NondetLiveness,
+        ParStackVars0, _ParStackVars).
 
 :- pred build_live_sets_in_goal(hlds_goal::in, hlds_goal::out,
     set(prog_var)::in, alloc_data::in, T::in, T::out,
Index: compiler/livemap.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/livemap.m,v
retrieving revision 1.80
diff -u -r1.80 livemap.m
--- compiler/livemap.m	26 Sep 2006 03:53:16 -0000	1.80
+++ compiler/livemap.m	13 Oct 2006 08:46:47 -0000
@@ -166,7 +166,7 @@
             LivevalsNeeded, Found),
         ( Found = yes ->
             true
-        ; CodeAddr = label(Label) ->
+        ; CodeAddr = code_label(Label) ->
             livemap.insert_label_livevals(!.Livemap, Label,
                 set.init, !:Livevals)
         ;
@@ -207,7 +207,7 @@
         ;
             Found = no,
             livemap.make_live_in_rvals([Rval], !Livevals),
-            ( CodeAddr = label(Label) ->
+            ( CodeAddr = code_label(Label) ->
                 livemap.insert_label_livevals(!.Livemap, Label, !Livevals)
             ;
                 true
@@ -368,9 +368,9 @@
     %
 :- pred livemap.special_code_addr(code_addr::in, maybe(lval)::out) is det.
 
-livemap.special_code_addr(label(_), no).
-livemap.special_code_addr(imported(_), no).
-livemap.special_code_addr(succip, yes(succip)).
+livemap.special_code_addr(code_label(_), no).
+livemap.special_code_addr(code_imported_proc(_), no).
+livemap.special_code_addr(code_succip, yes(succip)).
 livemap.special_code_addr(do_succeed(_), yes(succip_slot(lval(curfr)))).
 livemap.special_code_addr(do_redo, yes(redoip_slot(lval(maxfr)))).
 livemap.special_code_addr(do_trace_redo_fail_shallow, no).
Index: compiler/llds.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/llds.m,v
retrieving revision 1.340
diff -u -r1.340 llds.m
--- compiler/llds.m	26 Sep 2006 03:53:13 -0000	1.340
+++ compiler/llds.m	13 Oct 2006 09:25:35 -0000
@@ -955,13 +955,15 @@
             % proc entry; exported from a Mercury module
 
 :- type label
-    --->    internal(int, proc_label)
-    ;       entry(entry_label_type, proc_label).
+    --->    internal_label(int, proc_label)
+    ;       entry_label(entry_label_type, proc_label).
 
 :- type code_addr
-    --->    label(label)            % A label defined in this Mercury module.
-    ;       imported(proc_label)    % A label from another Mercury module.
-    ;       succip                  % The address in the `succip' register.
+    --->    code_label(label)       % A label defined in this Mercury module.
+    ;       code_imported_proc(proc_label)
+                                    % A label for a procedure from another
+                                    % Mercury module.
+    ;       code_succip             % The address in the `succip' register.
     ;       do_succeed(bool)        % The bool is `yes' if there are any
                                     % alternatives left. If the bool is `no',
                                     % we do a succeed_discard() rather than
@@ -1143,9 +1145,9 @@
 
 break_up_local_label(Label, ProcLabel, LabelNum) :-
     (
-        Label = internal(LabelNum, ProcLabel)
+        Label = internal_label(LabelNum, ProcLabel)
     ;
-        Label = entry(_, _),
+        Label = entry_label(_, _),
         unexpected(this_file, "break_up_local_label: entry label")
     ).
 
@@ -1268,8 +1270,8 @@
 register_type(reg_r, word).
 register_type(reg_f, float).
 
-get_proc_label(entry(_, ProcLabel)) = ProcLabel.
-get_proc_label(internal(_, ProcLabel)) = ProcLabel.
+get_proc_label(entry_label(_, ProcLabel)) = ProcLabel.
+get_proc_label(internal_label(_, ProcLabel)) = ProcLabel.
 
 get_defining_module_name(ordinary_proc_label(ModuleName, _, _, _, _, _))
     = ModuleName.
Index: compiler/llds_out.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/llds_out.m,v
retrieving revision 1.294
diff -u -r1.294 llds_out.m
--- compiler/llds_out.m	4 Oct 2006 07:14:47 -0000	1.294
+++ compiler/llds_out.m	13 Oct 2006 09:29:37 -0000
@@ -1390,7 +1390,7 @@
 group_c_labels_with_layouts(StackLayoutLabels, [Label | Labels],
         !DeclLLMap, !OtherLocalMap, !RevAddrsToDecl, !RevOthers) :-
     (
-        Label = internal(LabelNum, ProcLabel),
+        Label = internal_label(LabelNum, ProcLabel),
         ( map.search(StackLayoutLabels, Label, DataAddr) ->
             (
                 DataAddr = layout_addr(LayoutName),
@@ -1407,7 +1407,7 @@
             svmulti_map.set(ProcLabel, LabelNum, !OtherLocalMap)
         )
     ;
-        Label = entry(_, _),
+        Label = entry_label(_, _),
         !:RevOthers = [Label | !.RevOthers]
     ),
     group_c_labels_with_layouts(StackLayoutLabels, Labels,
@@ -1478,7 +1478,7 @@
     decl_set::in, decl_set::out) is det.
 
 insert_code_addr_decl(ProcLabel, LabelNum, !DeclSet) :-
-    DeclId = decl_code_addr(label(internal(LabelNum, ProcLabel))),
+    DeclId = decl_code_addr(code_label(internal_label(LabelNum, ProcLabel))),
     decl_set_insert(DeclId, !DeclSet).
 
 :- pred output_c_label_decl(map(label, data_addr)::in, label::in,
@@ -1490,7 +1490,7 @@
     %
     ( map.search(StackLayoutLabels, Label, DataAddr) ->
         (
-            Label = internal(LabelNum, ProcLabel),
+            Label = internal_label(LabelNum, ProcLabel),
             DataAddr = layout_addr(LayoutName),
             LayoutName = label_layout(ProcLabel, LabelNum, LabelVars)
         ->
@@ -1524,16 +1524,16 @@
         % Declare the label itself.
         %
         (
-            Label = entry(entry_label_exported, _),
+            Label = entry_label(entry_label_exported, _),
             DeclMacro = "MR_def_extern_entry("
         ;
-            Label = entry(entry_label_local, _),
+            Label = entry_label(entry_label_local, _),
             DeclMacro = "MR_decl_static("
         ;
-            Label = entry(entry_label_c_local, _),
+            Label = entry_label(entry_label_c_local, _),
             DeclMacro = "MR_decl_local("
         ;
-            Label = internal(_, _),
+            Label = internal_label(_, _),
             DeclMacro = "MR_decl_label("
         ),
         io.write_string(DeclMacro, !IO),
@@ -1543,7 +1543,7 @@
     ;
         AlreadyDeclaredLabel = yes
     ),
-    decl_set_insert(decl_code_addr(label(Label)), !DeclSet).
+    decl_set_insert(decl_code_addr(code_label(Label)), !DeclSet).
 
 :- pred output_stack_layout_decl(data_addr::in, decl_set::in, decl_set::out,
     io::di, io::uo) is det.
@@ -1573,14 +1573,14 @@
 group_c_labels(StackLayoutLabels, [Label | Labels], !NoLayoutMap, !LayoutMap,
         !RevOthers) :-
     (
-        Label = internal(LabelNum, ProcLabel),
+        Label = internal_label(LabelNum, ProcLabel),
         ( map.search(StackLayoutLabels, Label, _DataAddr) ->
             svmulti_map.set(ProcLabel, LabelNum, !LayoutMap)
         ;
             svmulti_map.set(ProcLabel, LabelNum, !NoLayoutMap)
         )
     ;
-        Label = entry(_, _),
+        Label = entry_label(_, _),
         !:RevOthers = [Label | !.RevOthers]
     ),
     group_c_labels(StackLayoutLabels, Labels, !NoLayoutMap, !LayoutMap,
@@ -1633,16 +1633,16 @@
         InitProcLayout = no
     ),
     (
-        Label = entry(entry_label_exported, ProcLabel),
+        Label = entry_label(entry_label_exported, ProcLabel),
         TabInitMacro = "\tMR_init_entry1"
     ;
-        Label = entry(entry_label_local, ProcLabel),
+        Label = entry_label(entry_label_local, ProcLabel),
         TabInitMacro = "\tMR_init_entry1"
     ;
-        Label = entry(entry_label_c_local, ProcLabel),
+        Label = entry_label(entry_label_c_local, ProcLabel),
         TabInitMacro = "\tMR_init_local1"
     ;
-        Label = internal(_, _),
+        Label = internal_label(_, _),
         % These should have been separated out by group_c_labels.
         unexpected(this_file, "output_c_label_init: internal/2")
     ),
@@ -1661,8 +1661,8 @@
 
 :- pred label_is_proc_entry(label::in, bool::out) is det.
 
-label_is_proc_entry(internal(_, _), no).
-label_is_proc_entry(entry(_, _), yes).
+label_is_proc_entry(internal_label(_, _), no).
+label_is_proc_entry(entry_label(_, _), yes).
 
 :- pred output_c_procedure_decls(map(label, data_addr)::in, c_procedure::in,
     decl_set::in, decl_set::out, io::di, io::uo) is det.
@@ -1758,10 +1758,10 @@
 find_caller_label([Instr0 - _ | Instrs], CallerLabel) :-
     ( Instr0 = label(Label) ->
         (
-            Label = internal(_, _),
+            Label = internal_label(_, _),
             unexpected(this_file, "caller label is internal label")
         ;
-            Label = entry(_, _),
+            Label = entry_label(_, _),
             CallerLabel = Label
         )
     ;
@@ -1778,14 +1778,14 @@
 find_cont_labels([Instr - _ | Instrs], !ContLabelSet) :-
     (
         (
-            Instr = llcall(_, label(ContLabel), _, _, _, _)
+            Instr = llcall(_, code_label(ContLabel), _, _, _, _)
         ;
-            Instr = mkframe(_, yes(label(ContLabel)))
+            Instr = mkframe(_, yes(code_label(ContLabel)))
         ;
             Instr = join_and_continue(_, ContLabel)
         ;
             Instr = assign(redoip_slot(_), const(Const)),
-            Const = llconst_code_addr(label(ContLabel))
+            Const = llconst_code_addr(code_label(ContLabel))
         )
     ->
         set_tree234.insert(ContLabel, !ContLabelSet)
@@ -1844,9 +1844,9 @@
     ( Instr0 = label(_) ->
         Instrs = [Instr0 - Comment0 | Instrs0]
     ;
-        ( Instr0 = goto(label(Label)) ->
+        ( Instr0 = goto(code_label(Label)) ->
             !:Count = !.Count + 1
-        ; Instr0 = if_val(_, label(Label)) ->
+        ; Instr0 = if_val(_, code_label(Label)) ->
             !:Count = !.Count + 1
         ; Instr0 = block(_, _, BlockInstrs) ->
             count_while_label_in_block(Label, BlockInstrs, !Count)
@@ -1864,9 +1864,9 @@
     ( Instr0 = label(_) ->
         unexpected(this_file, "label in block")
     ;
-        ( Instr0 = goto(label(Label)) ->
+        ( Instr0 = goto(code_label(Label)) ->
             !:Count = !.Count + 1
-        ; Instr0 = if_val(_, label(Label)) ->
+        ; Instr0 = if_val(_, code_label(Label)) ->
             !:Count = !.Count + 1
         ; Instr0 = block(_, _, _) ->
             unexpected(this_file, "block in block")
@@ -1990,10 +1990,10 @@
 output_instr_decls(_, init_sync_term(Lval, _), !DeclSet, !IO) :-
     output_lval_decls(Lval, !DeclSet, !IO).
 output_instr_decls(_, fork(Child), !DeclSet, !IO) :-
-    output_code_addr_decls(label(Child), !DeclSet, !IO).
+    output_code_addr_decls(code_label(Child), !DeclSet, !IO).
 output_instr_decls(_, join_and_continue(Lval, Label), !DeclSet, !IO) :-
     output_lval_decls(Lval, !DeclSet, !IO),
-    output_code_addr_decls(label(Label), !DeclSet, !IO).
+    output_code_addr_decls(code_label(Label), !DeclSet, !IO).
 
 :- pred output_pragma_c_component_decls(pragma_c_component::in,
     decl_set::in, decl_set::out, io::di, io::uo) is det.
@@ -2045,10 +2045,10 @@
         io.write_string("\tbreak; } /* end while */\n", !IO),
         output_instruction_list([Instr0 - Comment0 | Instrs],
             PrintComments, ProfInfo, WhileSet, !IO)
-    ; Instr0 = goto(label(Label)) ->
+    ; Instr0 = goto(code_label(Label)) ->
         io.write_string("\t/* continue */ } /* end while */\n", !IO),
         output_instruction_list(Instrs, PrintComments, ProfInfo, WhileSet, !IO)
-    ; Instr0 = if_val(Rval, label(Label)) ->
+    ; Instr0 = if_val(Rval, code_label(Label)) ->
         io.write_string("\tif (", !IO),
         output_test_rval(Rval, !IO),
         io.write_string(")\n\t\tcontinue;\n", !IO),
@@ -2086,11 +2086,11 @@
         PrintComments, ProfInfo, !IO) :-
     ( Instr0 = label(_) ->
         unexpected(this_file, "label in block")
-    ; Instr0 = goto(label(Label)) ->
+    ; Instr0 = goto(code_label(Label)) ->
         io.write_string("\tcontinue;\n", !IO),
         expect(unify(Instrs, []), this_file,
             "output_instruction_list_while_block: code after goto")
-    ; Instr0 = if_val(Rval, label(Label)) ->
+    ; Instr0 = if_val(Rval, code_label(Label)) ->
         io.write_string("\tif (", !IO),
         output_test_rval(Rval, !IO),
         io.write_string(")\n\t\tcontinue;\n", !IO),
@@ -2152,7 +2152,7 @@
     proc_id_to_int(hlds_pred.initial_proc_id, InitialProcIdInt),
     ProcLabel = ordinary_proc_label(DummyModule, predicate, DummyModule,
         DummyPredName, 0, InitialProcIdInt),
-    ProfInfo = entry(entry_label_local, ProcLabel) - ContLabelSet,
+    ProfInfo = entry_label(entry_label_local, ProcLabel) - ContLabelSet,
     output_instruction_and_comment(Instr, Comment, PrintComments,
         ProfInfo, !IO).
 
@@ -2166,7 +2166,7 @@
     proc_id_to_int(hlds_pred.initial_proc_id, InitialProcIdInt),
     ProcLabel = ordinary_proc_label(DummyModule, predicate, DummyModule,
         DummyPredName, 0, InitialProcIdInt),
-    ProfInfo = entry(entry_label_local, ProcLabel) - ContLabelSet,
+    ProfInfo = entry_label(entry_label_local, ProcLabel) - ContLabelSet,
     output_instruction(Instr, ProfInfo, !IO).
 
 :- pred output_block_start(int::in, int::in, io::di, io::uo) is det.
@@ -3579,22 +3579,22 @@
 
 :- pred need_code_addr_decls(code_addr::in, bool::out, io::di, io::uo) is det.
 
-need_code_addr_decls(label(Label), Need, !IO) :-
+need_code_addr_decls(code_label(Label), Need, !IO) :-
     (
-        Label = entry(entry_label_exported, _),
+        Label = entry_label(entry_label_exported, _),
         Need = yes
     ;
-        Label = entry(entry_label_local, _),
+        Label = entry_label(entry_label_local, _),
         Need = yes
     ;
-        Label = entry(entry_label_c_local, _),
+        Label = entry_label(entry_label_c_local, _),
         Need = no
     ;
-        Label = internal(_, _),
+        Label = internal_label(_, _),
         Need = no
     ).
-need_code_addr_decls(imported(_), yes, !IO).
-need_code_addr_decls(succip, no, !IO).
+need_code_addr_decls(code_imported_proc(_), yes, !IO).
+need_code_addr_decls(code_succip, no, !IO).
 need_code_addr_decls(do_succeed(_), no, !IO).
 need_code_addr_decls(do_redo, NeedDecl, !IO) :-
     globals.io_lookup_bool_option(use_macro_for_redo_fail, UseMacro, !IO),
@@ -3622,13 +3622,13 @@
 
 :- pred output_code_addr_decls(code_addr::in, io::di, io::uo) is det.
 
-output_code_addr_decls(label(Label), !IO) :-
+output_code_addr_decls(code_label(Label), !IO) :-
     output_label_as_code_addr_decls(Label, !IO).
-output_code_addr_decls(imported(ProcLabel), !IO) :-
+output_code_addr_decls(code_imported_proc(ProcLabel), !IO) :-
     io.write_string("MR_decl_entry(", !IO),
     output_proc_label_no_prefix(ProcLabel, !IO),
     io.write_string(");\n", !IO).
-output_code_addr_decls(succip, !IO).
+output_code_addr_decls(code_succip, !IO).
 output_code_addr_decls(do_succeed(_), !IO).
 output_code_addr_decls(do_redo, !IO) :-
     globals.io_lookup_bool_option(use_macro_for_redo_fail, UseMacro, !IO),
@@ -3668,13 +3668,15 @@
 
 :- pred output_label_as_code_addr_decls(label::in, io::di, io::uo) is det.
 
-output_label_as_code_addr_decls(entry(entry_label_exported, ProcLabel), !IO) :-
+output_label_as_code_addr_decls(entry_label(entry_label_exported, ProcLabel),
+        !IO) :-
     io.write_string("MR_decl_entry(", !IO),
-    output_label(entry(entry_label_exported, ProcLabel), no, !IO),
+    output_label(entry_label(entry_label_exported, ProcLabel), no, !IO),
     io.write_string(");\n", !IO).
-output_label_as_code_addr_decls(entry(entry_label_local, _ProcLabel), !IO).
-output_label_as_code_addr_decls(entry(entry_label_c_local, _), !IO).
-output_label_as_code_addr_decls(internal(_, _), !IO).
+output_label_as_code_addr_decls(entry_label(entry_label_local, _ProcLabel),
+        !IO).
+output_label_as_code_addr_decls(entry_label(entry_label_c_local, _), !IO).
+output_label_as_code_addr_decls(internal_label(_, _), !IO).
 
 output_data_addr_decls(DataAddr, !DeclSet, !IO) :-
     output_data_addr_decls_format(DataAddr, "", "", 0, _, !DeclSet, !IO).
@@ -3832,9 +3834,9 @@
     % Note that we do some optimization here: instead of always outputting
     % `MR_GOTO(<label>)', we output different things for each different
     % kind of label.
-output_goto(label(Label), CallerLabel, !IO) :-
+output_goto(code_label(Label), CallerLabel, !IO) :-
     (
-        Label = entry(entry_label_exported, _),
+        Label = entry_label(entry_label_exported, _),
         globals.io_lookup_bool_option(profile_calls, ProfileCalls, !IO),
         (
             ProfileCalls = yes,
@@ -3850,7 +3852,7 @@
             io.write_string(");\n", !IO)
         )
     ;
-        Label = entry(entry_label_local, _),
+        Label = entry_label(entry_label_local, _),
         globals.io_lookup_bool_option(profile_calls, ProfileCalls, !IO),
         (
             ProfileCalls = yes,
@@ -3866,7 +3868,7 @@
             io.write_string(");\n", !IO)
         )
     ;
-        Label = entry(entry_label_c_local, _),
+        Label = entry_label(entry_label_c_local, _),
         globals.io_lookup_bool_option(profile_calls, ProfileCalls, !IO),
         (
             ProfileCalls = yes,
@@ -3882,12 +3884,12 @@
             io.write_string(");\n", !IO)
         )
     ;
-        Label = internal(_, _),
+        Label = internal_label(_, _),
         io.write_string("MR_GOTO_LAB(", !IO),
         output_label(Label, no, !IO),
         io.write_string(");\n", !IO)
     ).
-output_goto(imported(ProcLabel), CallerLabel, !IO) :-
+output_goto(code_imported_proc(ProcLabel), CallerLabel, !IO) :-
     globals.io_lookup_bool_option(profile_calls, ProfileCalls, !IO),
     (
         ProfileCalls = yes,
@@ -3902,7 +3904,7 @@
         output_proc_label_no_prefix(ProcLabel, !IO),
         io.write_string(");\n", !IO)
     ).
-output_goto(succip, _, !IO) :-
+output_goto(code_succip, _, !IO) :-
     io.write_string("MR_proceed();\n", !IO).
 output_goto(do_succeed(Last), _, !IO) :-
     (
@@ -3990,7 +3992,7 @@
         globals.io_lookup_bool_option(profile_calls, ProfileCall, !IO)
     ),
     (
-        Target = label(Label),
+        Target = code_label(Label),
         % We really shouldn't be calling internal labels ...
         label_is_external_to_c_module(Label) = no
     ->
@@ -4037,7 +4039,7 @@
             )
         )
     ;
-        Continuation = label(ContLabel),
+        Continuation = code_label(ContLabel),
         label_is_external_to_c_module(ContLabel) = no
     ->
         (
@@ -4156,7 +4158,7 @@
 :- pred code_addr_to_string_base(code_addr::in, string::out,
     bool::out, wrapper::out) is det.
 
-code_addr_to_string_base(label(Label), BaseStr, yes, Wrapper) :-
+code_addr_to_string_base(code_label(Label), BaseStr, yes, Wrapper) :-
     BaseStr = label_to_c_string(Label, no),
     IsExternal = label_is_external_to_c_module(Label),
     (
@@ -4166,9 +4168,10 @@
         IsExternal = no,
         Wrapper = wrapper_label
     ).
-code_addr_to_string_base(imported(ProcLabel), BaseStr, yes, wrapper_entry) :-
+code_addr_to_string_base(code_imported_proc(ProcLabel), BaseStr, yes,
+        wrapper_entry) :-
     BaseStr = proc_label_to_c_string(ProcLabel, no).
-code_addr_to_string_base(succip, "MR_succip", no, wrapper_none).
+code_addr_to_string_base(code_succip, "MR_succip", no, wrapper_none).
 code_addr_to_string_base(do_succeed(Last), BaseStr, no, wrapper_entry) :-
     (
         Last = no,
@@ -4308,10 +4311,10 @@
 
 :- func label_is_external_to_c_module(label) = bool.
 
-label_is_external_to_c_module(entry(entry_label_exported, _)) = yes.
-label_is_external_to_c_module(entry(entry_label_local, _)) = yes.
-label_is_external_to_c_module(entry(entry_label_c_local, _)) = no.
-label_is_external_to_c_module(internal(_, _)) = no.
+label_is_external_to_c_module(entry_label(entry_label_exported, _)) = yes.
+label_is_external_to_c_module(entry_label(entry_label_local, _)) = yes.
+label_is_external_to_c_module(entry_label(entry_label_c_local, _)) = no.
+label_is_external_to_c_module(internal_label(_, _)) = no.
 
 :- pred label_as_code_addr_to_string(label::in, string::out) is det.
 
@@ -4347,19 +4350,19 @@
 
 :- pred output_label_defn(label::in, io::di, io::uo) is det.
 
-output_label_defn(entry(entry_label_exported, ProcLabel), !IO) :-
+output_label_defn(entry_label(entry_label_exported, ProcLabel), !IO) :-
     io.write_string("MR_define_entry(", !IO),
-    output_label(entry(entry_label_exported, ProcLabel), !IO),
+    output_label(entry_label(entry_label_exported, ProcLabel), !IO),
     io.write_string(");\n", !IO).
-output_label_defn(entry(entry_label_local, ProcLabel), !IO) :-
+output_label_defn(entry_label(entry_label_local, ProcLabel), !IO) :-
     io.write_string("MR_def_static(", !IO),
     output_proc_label_no_prefix(ProcLabel, !IO),
     io.write_string(")\n", !IO).
-output_label_defn(entry(entry_label_c_local, ProcLabel), !IO) :-
+output_label_defn(entry_label(entry_label_c_local, ProcLabel), !IO) :-
     io.write_string("MR_def_local(", !IO),
     output_proc_label_no_prefix(ProcLabel, !IO),
     io.write_string(")\n", !IO).
-output_label_defn(internal(Num, ProcLabel), !IO) :-
+output_label_defn(internal_label(Num, ProcLabel), !IO) :-
     io.write_string("MR_def_label(", !IO),
     output_proc_label_no_prefix(ProcLabel, !IO),
     io.write_string(",", !IO),
@@ -4382,9 +4385,9 @@
     LabelStr = label_to_c_string(Label, AddPrefix),
     io.write_string(LabelStr, !IO).
 
-label_to_c_string(entry(_, ProcLabel), AddPrefix) =
+label_to_c_string(entry_label(_, ProcLabel), AddPrefix) =
     proc_label_to_c_string(ProcLabel, AddPrefix).
-label_to_c_string(internal(Num, ProcLabel), AddPrefix) = LabelStr :-
+label_to_c_string(internal_label(Num, ProcLabel), AddPrefix) = LabelStr :-
     ProcLabelStr = proc_label_to_c_string(ProcLabel, AddPrefix),
     string.int_to_string(Num, NumStr),
     string.append("_i", NumStr, NumSuffix),
Index: compiler/lookup_switch.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/lookup_switch.m,v
retrieving revision 1.70
diff -u -r1.70 lookup_switch.m
--- compiler/lookup_switch.m	22 Aug 2006 05:03:51 -0000	1.70
+++ compiler/lookup_switch.m	13 Oct 2006 10:48:09 -0000
@@ -199,7 +199,7 @@
     LastCase = extended_case(_, int_tag(LastCaseVal), _, _),
     Span = LastCaseVal - FirstCaseVal,
     Range = Span + 1,
-    dense_switch.calc_density(NumCases, Range, Density),
+    Density = switch_density(NumCases, Range),
     Density > ReqDensity,
 
     % If there are going to be no gaps in the lookup table then we won't need
@@ -221,7 +221,7 @@
         classify_type(ModuleInfo, Type) = TypeCategory,
         (
             dense_switch.type_range(!.CI, TypeCategory, Type, TypeRange),
-            dense_switch.calc_density(NumCases, TypeRange, DetDensity),
+            DetDensity = switch_density(NumCases, TypeRange),
             DetDensity > ReqDensity
         ->
             NeedRangeCheck = dont_need_range_check,
@@ -650,7 +650,7 @@
             BranchEndCode, !CI),
         code_info.release_reg(BaseReg, !CI),
         GotoEndCode = node([
-            goto(label(EndLabel)) - "goto end of switch from one_soln"
+            goto(code_label(EndLabel)) - "goto end of switch from one_soln"
         ]),
         KindCode = tree_list([BranchEndCode, GotoEndCode])
     ;
@@ -703,7 +703,7 @@
         code_info.release_reg(BaseReg, !CI),
 
         GotoEndCode = node([
-            goto(label(EndLabel)) - "goto end of switch from several_soln"
+            goto(code_label(EndLabel)) - "goto end of switch from several_soln"
         ]),
 
         code_info.reset_to_position(DisjEntry, !CI),
@@ -721,12 +721,12 @@
             assign(LaterBaseReg, lval(CurSlot))
                 - "Init later base register",
             if_val(binop(int_ge, lval(LaterBaseReg), lval(MaxSlot)),
-                label(UndoLabel))
+                code_label(UndoLabel))
                 - "Jump to undo hijack code if there are no more solutions",
             assign(CurSlot,
                 binop(int_add, lval(CurSlot), const(llconst_int(NumOutVars))))
                 - "Update current slot in the later solution array",
-            goto(label(AfterUndoLabel))
+            goto(code_label(AfterUndoLabel))
                 - "Jump around undo hijack code",
             label(UndoLabel)
                 - "Undo hijack code"
@@ -778,7 +778,7 @@
             lval(field(yes(0), lval(BaseReg), const(llconst_int(0)))),
             const(llconst_int(0))),
         TestCode = node([
-            if_val(TestRval, label(NextKindLabel))
+            if_val(TestRval, code_label(NextKindLabel))
                 - "skip to next kind in several_soln lookup switch",
             comment("This kind is " ++ case_kind_to_string(Kind))
                 - ""
Index: compiler/make.dependencies.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/make.dependencies.m,v
retrieving revision 1.31
diff -u -r1.31 make.dependencies.m
--- compiler/make.dependencies.m	20 Aug 2006 08:21:14 -0000	1.31
+++ compiler/make.dependencies.m	13 Oct 2006 12:43:02 -0000
@@ -30,9 +30,9 @@
     (pred(in, out, out, in, out, di, uo) is det).
 
 :- type dependency_file
-    --->    target(target_file)
+    --->    dep_target(target_file)
                         % A target which could be made.
-    ;       file(file_name, maybe(option)).
+    ;       dep_file(file_name, maybe(option)).
                         % An ordinary file which `mmc --make' does not know
                         % how to rebuild. The option gives a list of
                         % directories in which to search.
@@ -54,8 +54,8 @@
 
 %-----------------------------------------------------------------------------%
 
-    % Find all modules in the current directory which are
-    % reachable (by import) from the given module.
+    % Find all modules in the current directory which are reachable (by import)
+    % from the given module.
     %
 :- pred find_reachable_local_modules(module_name::in, bool::out,
     set(module_name)::out, make_info::in, make_info::out,
@@ -63,10 +63,9 @@
 
 %-----------------------------------------------------------------------------%
 
-    % Find all modules in the current directory which are
-    % reachable (by import) from the given module.
-    % Return a list of `--local-module-id' options suitable for the
-    % command line.
+    % Find all modules in the current directory which are reachable (by import)
+    % from the given module. Return a list of `--local-module-id' options
+    % suitable for the command line.
     %
 :- pred make_local_module_id_options(module_name::in, bool::out,
     list(string)::out, make_info::in, make_info::out, io::di, io::uo) is det.
@@ -79,9 +78,9 @@
 %-----------------------------------------------------------------------------%
 
 :- type dependencies_result
-    --->    up_to_date
-    ;       out_of_date
-    ;       error.
+    --->    deps_up_to_date
+    ;       deps_out_of_date
+    ;       deps_error.
 
     % check_dependencies(TargetFileName, TargetFileTimestamp,
     %   BuildDepsSucceeded, Dependencies, Result)
@@ -175,79 +174,88 @@
         combine_deps(FindDeps, combine_deps_list(FindDepsList))
     ).
 
-target_dependencies(_, source) = no_deps.
-target_dependencies(Globals, errors) = compiled_code_dependencies(Globals).
-target_dependencies(_, private_interface) = interface_file_dependencies.
-target_dependencies(_, long_interface) = interface_file_dependencies.
-target_dependencies(_, short_interface) = interface_file_dependencies.
-target_dependencies(_, unqualified_short_interface) = source `of` self.
-target_dependencies(Globals, c_header(_)) =
-        target_dependencies(Globals, c_code).
-target_dependencies(Globals, c_code) = compiled_code_dependencies(Globals).
-target_dependencies(Globals, il_code) = compiled_code_dependencies(Globals).
-target_dependencies(_, il_asm) =
+target_dependencies(_, module_target_source) = no_deps.
+target_dependencies(Globals, module_target_errors) =
+        compiled_code_dependencies(Globals).
+target_dependencies(_, module_target_private_interface) =
+        interface_file_dependencies.
+target_dependencies(_, module_target_long_interface) =
+        interface_file_dependencies.
+target_dependencies(_, module_target_short_interface) =
+        interface_file_dependencies.
+target_dependencies(_, module_target_unqualified_short_interface) =
+        module_target_source `of` self.
+target_dependencies(Globals, module_target_c_header(_)) =
+        target_dependencies(Globals, module_target_c_code).
+target_dependencies(Globals, module_target_c_code) =
+        compiled_code_dependencies(Globals).
+target_dependencies(Globals, module_target_il_code) =
+        compiled_code_dependencies(Globals).
+target_dependencies(_, module_target_il_asm) =
     combine_deps_list([
-        il_code `of` self
+        module_target_il_code `of` self
     ]).
-target_dependencies(Globals, java_code) = compiled_code_dependencies(Globals).
-target_dependencies(Globals, asm_code(_)) =
+target_dependencies(Globals, module_target_java_code) =
+        compiled_code_dependencies(Globals).
+target_dependencies(Globals, module_target_asm_code(_)) =
         compiled_code_dependencies(Globals).
-target_dependencies(Globals, object_code(PIC)) = Deps :-
+target_dependencies(Globals, module_target_object_code(PIC)) = Deps :-
     globals.get_target(Globals, CompilationTarget),
-    TargetCode = ( CompilationTarget = target_asm -> asm_code(PIC) ; c_code ),
+    TargetCode = ( CompilationTarget = target_asm ->
+        module_target_asm_code(PIC) ; module_target_c_code ),
     globals.lookup_bool_option(Globals, highlevel_code, HighLevelCode),
 
-    %
     % For --highlevel-code, the `.c' file will #include the header
     % file for all imported modules.
-    %
     (
         CompilationTarget = target_c,
         HighLevelCode = yes
     ->
         HeaderDeps = combine_deps_list([
-            c_header(mih) `of` direct_imports,
-            c_header(mih) `of` indirect_imports,
-            c_header(mih) `of` parents,
-            c_header(mih) `of` intermod_imports
+            module_target_c_header(header_mih) `of` direct_imports,
+            module_target_c_header(header_mih) `of` indirect_imports,
+            module_target_c_header(header_mih) `of` parents,
+            module_target_c_header(header_mih) `of` intermod_imports
         ])
     ;
         HeaderDeps = no_deps
     ),
     Deps = combine_deps_list([
         TargetCode `of` self,
-        c_header(mh) `of` foreign_imports,
+        module_target_c_header(header_mh) `of` foreign_imports,
         HeaderDeps
     ]).
-target_dependencies(_, intermodule_interface) =
-        combine_deps_list([
-            source `of` self,
-            private_interface `of` parents,
-            long_interface `of` non_intermod_direct_imports,
-            short_interface `of` non_intermod_indirect_imports
-        ]).
-target_dependencies(_, analysis_registry) =
+target_dependencies(_, module_target_intermodule_interface) =
+    combine_deps_list([
+        module_target_source `of` self,
+        module_target_private_interface `of` parents,
+        module_target_long_interface `of` non_intermod_direct_imports,
+        module_target_short_interface `of` non_intermod_indirect_imports
+    ]).
+target_dependencies(_, module_target_analysis_registry) =
     combine_deps_list([
-        source `of` self,
-        private_interface `of` parents,
-        long_interface `of` non_intermod_direct_imports,
-        short_interface `of` non_intermod_indirect_imports
+        module_target_source `of` self,
+        module_target_private_interface `of` parents,
+        module_target_long_interface `of` non_intermod_direct_imports,
+        module_target_short_interface `of` non_intermod_indirect_imports
     ]).
-target_dependencies(_, foreign_il_asm(_)) =
+target_dependencies(_, module_target_foreign_il_asm(_)) =
     combine_deps_list([
-        il_asm `of` self,
-        il_asm `of` filter(maybe_keep_std_lib_module, direct_imports),
-        il_asm `of` filter(maybe_keep_std_lib_module,
-            foreign_imports(lang_il)),
-        foreign_il_asm(lang_managed_cplusplus) `of`
-            filter(maybe_keep_std_lib_module,
-                foreign_imports(lang_managed_cplusplus)),
-        foreign_il_asm(lang_csharp) `of` filter(maybe_keep_std_lib_module,
-            foreign_imports(lang_csharp))
+        module_target_il_asm `of` self,
+        module_target_il_asm `of` filter_module_names(maybe_keep_std_lib_module,
+            direct_imports),
+        module_target_il_asm `of` filter_module_names(maybe_keep_std_lib_module,
+            foreign_imports_lang(lang_il)),
+        module_target_foreign_il_asm(lang_managed_cplusplus) `of`
+            filter_module_names(maybe_keep_std_lib_module,
+                foreign_imports_lang(lang_managed_cplusplus)),
+        module_target_foreign_il_asm(lang_csharp) `of`
+            filter_module_names(maybe_keep_std_lib_module,
+                foreign_imports_lang(lang_csharp))
     ]).
-target_dependencies(Globals, foreign_object(PIC, _)) =
+target_dependencies(Globals, module_target_foreign_object(PIC, _)) =
     get_foreign_deps(Globals, PIC).
-target_dependencies(Globals, fact_table_object(PIC, _)) =
+target_dependencies(Globals, module_target_fact_table_object(PIC, _)) =
     get_foreign_deps(Globals, PIC).
 
 :- func get_foreign_deps(globals::in, pic::in) =
@@ -255,7 +263,8 @@
 
 get_foreign_deps(Globals, PIC) = Deps :-
     globals.get_target(Globals, CompilationTarget),
-    TargetCode = ( CompilationTarget = target_asm -> asm_code(PIC) ; c_code ),
+    TargetCode = ( CompilationTarget = target_asm ->
+        module_target_asm_code(PIC) ; module_target_c_code ),
     Deps = combine_deps_list([
         TargetCode `of` self
     ]).
@@ -265,10 +274,10 @@
 
 interface_file_dependencies =
     combine_deps_list([
-        source `of` self,
-        private_interface `of` parents,
-        unqualified_short_interface `of` direct_imports,
-        unqualified_short_interface `of` indirect_imports
+        module_target_source `of` self,
+        module_target_private_interface `of` parents,
+        module_target_unqualified_short_interface `of` direct_imports,
+        module_target_unqualified_short_interface `of` indirect_imports
     ]).
 
 :- func compiled_code_dependencies(globals::in) =
@@ -281,21 +290,21 @@
     (
         Intermod = yes,
         Deps0 = combine_deps_list([
-            intermodule_interface `of` self,
-            intermodule_interface `of` intermod_imports,
+            module_target_intermodule_interface `of` self,
+            module_target_intermodule_interface `of` intermod_imports,
             map_find_module_deps(imports,
                 map_find_module_deps(parents, intermod_imports)),
-            compiled_code_dependencies
+            base_compiled_code_dependencies
         ])
     ;
         Intermod = no,
-        Deps0 = compiled_code_dependencies
+        Deps0 = base_compiled_code_dependencies
     ),
     (
         IntermodAnalysis = yes,
         Deps = combine_deps_list([
-            analysis_registry `of` self,
-            analysis_registry `of` direct_imports,
+            module_target_analysis_registry `of` self,
+            module_target_analysis_registry `of` direct_imports,
             Deps0
         ])
     ;
@@ -303,23 +312,23 @@
         Deps = Deps0
     ).
 
-:- func compiled_code_dependencies =
+:- func base_compiled_code_dependencies =
     (find_module_deps(dependency_file)::out(find_module_deps)) is det.
 
-compiled_code_dependencies =
+base_compiled_code_dependencies =
     combine_deps_list([
-        source `of` self,
-        fact_table `files_of` self,
+        module_target_source `of` self,
+        fact_table_files `files_of` self,
         map_find_module_deps(imports, self)
     ]).
 
 :- func imports =
-        (find_module_deps(dependency_file)::out(find_module_deps)) is det.
+    (find_module_deps(dependency_file)::out(find_module_deps)) is det.
 
 imports = combine_deps_list([
-        private_interface `of` parents,
-        long_interface `of` direct_imports,
-        short_interface `of` indirect_imports
+        module_target_private_interface `of` parents,
+        module_target_long_interface `of` direct_imports,
+        module_target_short_interface `of` indirect_imports
     ]).
 
 :- func module_target_type `of` find_module_deps(module_name) =
@@ -369,7 +378,7 @@
         Success = Success0 `and` Success1,
         DepFiles = set.sorted_list_to_set(
             list.map(
-                (func(FileName - Option) = file(FileName, Option)),
+                (func(FileName - Option) = dep_file(FileName, Option)),
                 set.to_sorted_list(FileNames)))
     ).
 
@@ -378,8 +387,8 @@
     module_name::in, bool::out, set(T)::out,
     make_info::in, make_info::out, io::di, io::uo) is det.
 
-map_find_module_deps(FindDeps2, FindDeps1, ModuleName,
-        Success, Result, !Info, !IO) :-
+map_find_module_deps(FindDeps2, FindDeps1, ModuleName, Success, Result,
+        !Info, !IO) :-
     KeepGoing = !.Info ^ keep_going,
     FindDeps1(ModuleName, Success0, Modules0, !Info, !IO),
     (
@@ -427,8 +436,8 @@
     ;
         KeepGoing = !.Info ^ keep_going,
 
-        non_intermod_direct_imports(ModuleName, Success0,
-            Modules0, !Info, !IO),
+        non_intermod_direct_imports(ModuleName, Success0, Modules0,
+            !Info, !IO),
         (
             Success0 = no,
             KeepGoing = no
@@ -436,10 +445,8 @@
             Success = no,
             Modules = set.init
         ;
-            %
-            % We also read `.int' files for the modules for
-            % which we read `.opt' files, and for the modules
-            % imported by those modules.
+            % We also read `.int' files for the modules for which we read
+            % `.opt' files, and for the modules imported by those modules.
             %
             intermod_imports(ModuleName, Success1, IntermodModules, !Info,
                 !IO),
@@ -475,26 +482,22 @@
     (
         MaybeImports = yes(Imports),
 
+        % Find the direct imports of this module (modules for which we will
+        % read the `.int' files).
         %
-        % Find the direct imports of this module (modules
-        % for which we will read the `.int' files).
-        %
-        % Note that we need to do this both for the interface
-        % imports of this module and for the *implementation*
-        % imports of its ancestors.  This is because if this
-        % module is defined in the implementation section of
-        % its parent, then the interface of this module may
-        % depend on things imported only by its parent's
-        % implementation.
-        %
-        % If this module was actually defined in the interface
-        % section of one of its ancestors, then it should only
-        % depend on the interface imports of that ancestor,
-        % so the dependencies added here are in fact more
-        % conservative than they need to be in that case.
-        % However, that should not be a major problem.
-        % (This duplicates how this is handled by modules.m).
+        % Note that we need to do this both for the interface imports of
+        % this module and for the *implementation* imports of its ancestors.
+        % This is because if this module is defined in the implementation
+        % section of its parent, then the interface of this module may depend
+        % on things imported only by its parent's implementation.
         %
+        % If this module was actually defined in the interface section of
+        % one of its ancestors, then it should only depend on the interface
+        % imports of that ancestor, so the dependencies added here are in fact
+        % more conservative than they need to be in that case. However, that
+        % should not be a major problem. (This duplicates how this is handled
+        % by modules.m).
+
         Modules0 = set.union(set.list_to_set(Imports ^ impl_deps),
             set.list_to_set(Imports ^ int_deps)),
         (
@@ -525,8 +528,8 @@
         Success, Modules, !Info, !IO).
 
     % Return the list of modules for which we should read `.int2' files,
-    % ignoring those which need to be read as a result of importing
-    % modules imported by a `.opt' file.
+    % ignoring those which need to be read as a result of importing modules
+    % imported by a `.opt' file.
     %
 :- pred non_intermod_indirect_imports(module_name::in, bool::out,
     set(module_name)::out, make_info::in, make_info::out,
@@ -543,9 +546,9 @@
 indirect_imports_2(FindDirectImports, ModuleName, Success, IndirectImports,
         !Info, !IO) :-
     FindDirectImports(ModuleName, DirectSuccess, DirectImports, !Info, !IO),
-        % XXX The original version of this code by stayl had the line assigning
-        % to KeepGoing textually *before* the call to FindDirectImports, but
-        % looked up the keep_going in the version of !Info *after* that call.
+    % XXX The original version of this code by stayl had the line assigning
+    % to KeepGoing textually *before* the call to FindDirectImports, but
+    % looked up the keep_going in the version of !Info *after* that call.
     KeepGoing = !.Info ^ keep_going,
     (
         DirectSuccess = no,
@@ -598,11 +601,10 @@
     make_info::in, make_info::out, io::di, io::uo) is det.
 
 foreign_imports(ModuleName, Success, Modules, !Info, !IO) :-
-    %
     % The object file depends on the header files for the modules
     % mentioned in `:- pragma foreign_import_module' declarations
     % in the current module and the `.opt' files it imports.
-    %
+
     globals.io_get_globals(Globals, !IO),
     globals.get_backend_foreign_languages(Globals, Languages),
     intermod_imports(ModuleName, IntermodSuccess, IntermodModules, !Info, !IO),
@@ -642,7 +644,7 @@
     (
         MaybeImports = yes(Imports),
         ForeignModules = set.list_to_set(
-            get_foreign_imported_modules(Languages,
+            get_foreign_imported_modules_lang(Languages,
             Imports ^ foreign_import_modules)),
         Success = yes
     ;
@@ -657,10 +659,10 @@
 get_foreign_imported_modules(ForeignImportModules) =
     get_foreign_imported_modules_2(no, ForeignImportModules).
 
-:- func get_foreign_imported_modules(set(foreign_language),
+:- func get_foreign_imported_modules_lang(set(foreign_language),
     foreign_import_module_info_list) = list(module_name).
 
-get_foreign_imported_modules(Languages, ForeignImportModules) =
+get_foreign_imported_modules_lang(Languages, ForeignImportModules) =
     get_foreign_imported_modules_2(yes(Languages), ForeignImportModules).
 
 :- func get_foreign_imported_modules_2(maybe(set(foreign_language)),
@@ -686,17 +688,17 @@
 
 %-----------------------------------------------------------------------------%
 
-    % foreign_imports(Lang, ModuleName, Success, Modules, !Info, !IO)
+    % foreign_imports_lang(Lang, ModuleName, Success, Modules, !Info, !IO)
     %
     % From the module, ModuleName, extract the set of modules, Modules,
     % which are mentioned in foreign_import_module declarations with the
     % specified language, Lang.
     %
-:- pred foreign_imports(foreign_language::in,
+:- pred foreign_imports_lang(foreign_language::in,
     module_name::in, bool::out, set(module_name)::out,
     make_info::in, make_info::out, io::di, io::uo) is det.
 
-foreign_imports(Lang, ModuleName, Success, Modules, !Info, !IO) :-
+foreign_imports_lang(Lang, ModuleName, Success, Modules, !Info, !IO) :-
     get_module_dependencies(ModuleName, MaybeImports, !Info, !IO),
     (
         MaybeImports = yes(Imports),
@@ -714,24 +716,25 @@
 
 %-----------------------------------------------------------------------------%
 
-    % filter(F, P, MN, S, Ms, !Info, !IO)L
-    %   Filter the set of module_names returned from P called with MN,
-    %   as its input arguments with F.  The first argument to F will be MN
-    %   and the second argument be one of the module_names returned from P.
+    % filter(F, P, MN, S, Ms, !Info, !IO):
     %
-:- pred filter(pred(module_name, module_name)::pred(in, in) is semidet,
-        pred(module_name, bool, set(module_name), make_info, make_info,
-            io, io)::pred(in, out, out, in, out, di, uo) is det,
-        module_name::in, bool::out,
-        set(module_name)::out, make_info::in, make_info::out,
-        io::di, io::uo) is det.
+    % Filter the set of module_names returned from P called with MN,
+    % as its input arguments with F.  The first argument to F will be MN
+    % and the second argument be one of the module_names returned from P.
+    %
+:- pred filter_module_names(
+    pred(module_name, module_name)::pred(in, in) is semidet,
+    pred(module_name, bool, set(module_name), make_info, make_info,
+        io, io)::pred(in, out, out, in, out, di, uo) is det,
+    module_name::in, bool::out,
+    set(module_name)::out, make_info::in, make_info::out,
+    io::di, io::uo) is det.
 
-filter(Filter, F, ModuleName, Success, Modules, !Info, !IO) :-
+filter_module_names(Filter, F, ModuleName, Success, Modules, !Info, !IO) :-
     F(ModuleName, Success, Modules0, !Info, !IO),
     Modules = set.filter((pred(M::in) is semidet :- Filter(ModuleName, M)),
         Modules0).
 
-
     % If the current module we are compiling is not in the standard
     % library and the module we are importing is then remove it,
     % otherwise keep it.  When compiling with `--target il', if the
@@ -748,11 +751,11 @@
 
 %-----------------------------------------------------------------------------%
 
-:- pred fact_table(module_name::in,
+:- pred fact_table_files(module_name::in,
     bool::out, set(pair(file_name, maybe(option)))::out,
     make_info::in, make_info::out, io::di, io::uo) is det.
 
-fact_table(ModuleName, Success, Files, !Info, !IO) :-
+fact_table_files(ModuleName, Success, Files, !Info, !IO) :-
     get_module_dependencies(ModuleName, MaybeImports, !Info, !IO),
     (
         MaybeImports = yes(Imports),
@@ -768,11 +771,11 @@
 %-----------------------------------------------------------------------------%
 
 :- type transitive_dependencies_root
-    ---> transitive_dependencies_root(
-            module_name,
-            transitive_dependencies_type,
-            module_locn
-        ).
+    --->    transitive_dependencies_root(
+                module_name,
+                transitive_dependencies_type,
+                module_locn
+            ).
 
 :- type transitive_deps_result == pair(bool, set(module_name)).
 
@@ -862,9 +865,8 @@
             ->
                 (
                     % Parents don't need to be considered here.
-                    % Anywhere the interface of the child module
-                    % is needed, the parent must also have been
-                    % imported.
+                    % Anywhere the interface of the child module is needed,
+                    % the parent must also have been imported.
                     DependenciesType = interface_imports,
                     ImportsToCheck = Imports ^ int_deps
                 ;
@@ -935,13 +937,13 @@
     assoc_list.from_corresponding_lists(DepFiles, DepStatusList, DepStatusAL),
     list.filter(
         (pred((_ - DepStatus)::in) is semidet :-
-            DepStatus \= up_to_date
+            DepStatus \= deps_status_up_to_date
         ), DepStatusAL, UnbuiltDependencies),
     (
         UnbuiltDependencies = [_ | _],
         debug_msg(check_dependencies_debug_unbuilt(TargetFileName,
             UnbuiltDependencies), !IO),
-        DepsResult = error
+        DepsResult = deps_error
     ;
         UnbuiltDependencies = [],
         debug_msg(
@@ -983,7 +985,7 @@
         DepFiles, WriteDepFile, DepTimestamps, DepsResult, !IO) :-
     (
         MaybeTimestamp = error(_),
-        DepsResult = out_of_date,
+        DepsResult = deps_out_of_date,
         debug_msg(io.write_string(TargetFileName ++ " does not exist.\n"), !IO)
     ;
         MaybeTimestamp = ok(Timestamp),
@@ -992,18 +994,18 @@
             list.member(MaybeDepTimestamp1, DepTimestamps),
             MaybeDepTimestamp1 = error(_)
         ->
-            DepsResult = error,
+            DepsResult = deps_error,
             WriteMissingDeps =
                 check_dependencies_timestamps_write_missing_deps(
                     TargetFileName, BuildDepsSucceeded, DepFiles,
                     WriteDepFile, DepTimestamps),
             (
                 BuildDepsSucceeded = yes,
-                %
+
                 % Something has gone wrong -- building the target has
                 % succeeded, but there are some files missing.
                 % Report an error.
-                %
+
                 WriteMissingDeps(!IO)
             ;
                 BuildDepsSucceeded = no,
@@ -1012,12 +1014,10 @@
         ;
             Rebuild = yes
         ->
-            %
-            % With `--rebuild', a target is always considered
-            % to be out-of-date, regardless of the timestamps
-            % of its dependencies.
-            %
-            DepsResult = out_of_date
+            % With `--rebuild', a target is always considered to be
+            % out-of-date, regardless of the timestamps of its dependencies.
+
+            DepsResult = deps_out_of_date
         ;
             list.member(MaybeDepTimestamp2, DepTimestamps),
             MaybeDepTimestamp2 = ok(DepTimestamp),
@@ -1025,9 +1025,9 @@
         ->
             debug_newer_dependencies(TargetFileName, MaybeTimestamp,
                 DepFiles, WriteDepFile, DepTimestamps, !IO),
-            DepsResult = out_of_date
+            DepsResult = deps_out_of_date
         ;
-            DepsResult = up_to_date
+            DepsResult = deps_up_to_date
         )
     ).
 
@@ -1064,7 +1064,7 @@
     io.write_list(NewerDeps, ",\n\t", WriteDepFile, !IO),
     io.nl(!IO).
 
-dependency_status(file(FileName, _) @ Dep, Status, !Info, !IO) :-
+dependency_status(dep_file(FileName, _) @ Dep, Status, !Info, !IO) :-
     (
         Status0 = !.Info ^ dependency_status ^ elem(Dep)
     ->
@@ -1073,10 +1073,10 @@
         get_dependency_timestamp(Dep, MaybeTimestamp, !Info, !IO),
         (
             MaybeTimestamp = ok(_),
-            Status = up_to_date
+            Status = deps_status_up_to_date
         ;
             MaybeTimestamp = error(Error),
-            Status = error,
+            Status = deps_status_error,
             io.write_string("** Error: file `", !IO),
             io.write_string(FileName, !IO),
             io.write_string("' not found: ", !IO),
@@ -1085,34 +1085,33 @@
         ),
         !:Info = !.Info ^ dependency_status ^ elem(Dep) := Status
     ).
-dependency_status(target(Target) @ Dep, Status, !Info, !IO) :-
+dependency_status(dep_target(Target) @ Dep, Status, !Info, !IO) :-
     Target = ModuleName - FileType,
-    ( FileType = source ->
+    ( FileType = module_target_source ->
         % Source files are always up-to-date.
-        maybe_warn_up_to_date_target(ModuleName - module_target(source),
-            !Info, !IO),
-        Status = up_to_date
+        ModuleTarget = module_target(module_target_source),
+        maybe_warn_up_to_date_target(ModuleName - ModuleTarget, !Info, !IO),
+        Status = deps_status_up_to_date
     ; Status0 = !.Info ^ dependency_status ^ elem(Dep) ->
         Status = Status0
     ;
         get_module_dependencies(ModuleName, MaybeImports, !Info, !IO),
         (
             MaybeImports = no,
-            Status = error
+            Status = deps_status_error
         ;
             MaybeImports = yes(Imports),
             ( Imports ^ module_dir \= dir.this_directory ->
-                %
                 % Targets from libraries are always considered to be
                 % up-to-date if they exist.
-                %
+
                 get_target_timestamp(yes, Target, MaybeTimestamp, !Info, !IO),
                 (
                     MaybeTimestamp = ok(_),
-                    Status = up_to_date
+                    Status = deps_status_up_to_date
                 ;
                     MaybeTimestamp = error(Error),
-                    Status = error,
+                    Status = deps_status_error,
                     io.write_string("** Error: file `", !IO),
                     write_target_file(Target, !IO),
                     io.write_string("' not found: ", !IO),
@@ -1120,7 +1119,7 @@
                     io.nl(!IO)
                 )
             ;
-                Status = not_considered
+                Status = deps_status_not_considered
             )
         ),
         !:Info = !.Info ^ dependency_status ^ elem(Dep) := Status
Index: compiler/make.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/make.m,v
retrieving revision 1.39
diff -u -r1.39 make.m
--- compiler/make.m	31 Jul 2006 08:31:47 -0000	1.39
+++ compiler/make.m	13 Oct 2006 12:43:12 -0000
@@ -156,9 +156,9 @@
             ).
 
 :- type make_error
-    --->    target_error(target_file)
-    ;       dependencies_error(module_name)
-    ;       other(string).
+    --->    make_error_target(target_file)
+    ;       make_error_dependencies(module_name)
+    ;       make_error_other(string).
 
 :- type compilation_task == pair(compilation_task_type, module_name).
 
@@ -172,55 +172,55 @@
     ;       fact_table_code_to_object_code(pic, file_name).
 
 :- type module_compilation_task_type
-    --->    errorcheck
-    ;       make_short_interface
-    ;       make_interface
-    ;       make_private_interface
-    ;       make_optimization_interface
-    ;       make_analysis_registry
-    ;       compile_to_target_code.
+    --->    task_errorcheck
+    ;       task_make_short_interface
+    ;       task_make_interface
+    ;       task_make_private_interface
+    ;       task_make_optimization_interface
+    ;       task_make_analysis_registry
+    ;       task_compile_to_target_code.
 
 :- type module_target_type
-    --->    source
-    ;       errors
-    ;       private_interface
-    ;       long_interface
-    ;       short_interface
-    ;       unqualified_short_interface
-    ;       intermodule_interface
-    ;       analysis_registry
-    ;       c_header(c_header_type)
-    ;       c_code
-    ;       il_code
-    ;       il_asm
-    ;       java_code
-    ;       asm_code(pic)
-    ;       object_code(pic)
-    ;       foreign_il_asm(foreign_language)
-    ;       foreign_object(pic, foreign_language)
-    ;       fact_table_object(pic, file_name).
+    --->    module_target_source
+    ;       module_target_errors
+    ;       module_target_private_interface
+    ;       module_target_long_interface
+    ;       module_target_short_interface
+    ;       module_target_unqualified_short_interface
+    ;       module_target_intermodule_interface
+    ;       module_target_analysis_registry
+    ;       module_target_c_header(c_header_type)
+    ;       module_target_c_code
+    ;       module_target_il_code
+    ;       module_target_il_asm
+    ;       module_target_java_code
+    ;       module_target_asm_code(pic)
+    ;       module_target_object_code(pic)
+    ;       module_target_foreign_il_asm(foreign_language)
+    ;       module_target_foreign_object(pic, foreign_language)
+    ;       module_target_fact_table_object(pic, file_name).
 
 :- type c_header_type
-    --->    mh      % For `:- pragma export' declarations.
-    ;       mih.    % Declarations for hlc grades, for compiler use only.
+    --->    header_mh      % For `:- pragma export' declarations.
+    ;       header_mih.    % Declarations for hlc grades, for compiler use only.
 
 % :- type linked_target_type in compile_target_code.m.
 
 :- type misc_target_type
-    --->    clean
-    ;       realclean
-    ;       build_all(module_target_type)
-    ;       build_analyses
-    ;       build_library
-    ;       install_library.
+    --->    misc_target_clean
+    ;       misc_target_realclean
+    ;       misc_target_build_all(module_target_type)
+    ;       misc_target_build_analyses
+    ;       misc_target_build_library
+    ;       misc_target_install_library.
 
 :- type file_timestamps == map(string, maybe_error(timestamp)).
 
 :- type dependency_status
-    --->    not_considered
-    ;       being_built
-    ;       up_to_date
-    ;       error.
+    --->    deps_status_not_considered
+    ;       deps_status_being_built
+    ;       deps_status_up_to_date
+    ;       deps_status_error.
 
 :- type target_file == pair(module_name, module_target_type).
 :- type linked_target_file == pair(module_name, linked_target_type).
@@ -314,12 +314,11 @@
     Target = ModuleName - TargetType,
     (
         TargetType = module_target(ModuleTargetType),
-        make_module_target(target(ModuleName - ModuleTargetType), Success,
+        make_module_target(dep_target(ModuleName - ModuleTargetType), Success,
             !Info, !IO)
     ;
         TargetType = linked_target(ProgramTargetType),
-        make_linked_target(ModuleName - ProgramTargetType, Success,
-            !Info, !IO)
+        make_linked_target(ModuleName - ProgramTargetType, Success, !Info, !IO)
     ;
         TargetType = misc_target(MiscTargetType),
         make_misc_target(ModuleName - MiscTargetType, Success, !Info, !IO)
@@ -348,7 +347,7 @@
     ;
         string.append("lib", ModuleNameStr, FileName)
     ->
-        TargetType = misc_target(build_library),
+        TargetType = misc_target(misc_target_build_library),
         file_name_to_module_name(ModuleNameStr, ModuleName)
     ;
         TargetType = linked_target(executable),
@@ -388,36 +387,36 @@
         yes(Suffix1) = target_extension(Globals, ModuleTargetType),
         % Not yet implemented. `build_all' targets are only used by
         % tools/bootcheck, so it doesn't really matter.
-        ModuleTargetType \= c_header(_)
+        ModuleTargetType \= module_target_c_header(_)
     ->
         ModuleNameStr = ModuleNameStr0,
-        TargetType = misc_target(build_all(ModuleTargetType))
+        TargetType = misc_target(misc_target_build_all(ModuleTargetType))
     ;
         Suffix = ".check"
     ->
         ModuleNameStr = ModuleNameStr0,
-        TargetType = misc_target(build_all(errors))
+        TargetType = misc_target(misc_target_build_all(module_target_errors))
     ;
         Suffix = ".analyse"
     ->
         ModuleNameStr = ModuleNameStr0,
-        TargetType = misc_target(build_analyses)
+        TargetType = misc_target(misc_target_build_analyses)
     ;
         Suffix = ".clean"
     ->
         ModuleNameStr = ModuleNameStr0,
-        TargetType = misc_target(clean)
+        TargetType = misc_target(misc_target_clean)
     ;
         Suffix = ".realclean"
     ->
         ModuleNameStr = ModuleNameStr0,
-        TargetType = misc_target(realclean)
+        TargetType = misc_target(misc_target_realclean)
     ;
         Suffix = ".install",
         string.append("lib", ModuleNameStr1, ModuleNameStr0)
     ->
         ModuleNameStr = ModuleNameStr1,
-        TargetType = misc_target(install_library)
+        TargetType = misc_target(misc_target_install_library)
     ;
         fail
     ),
Index: compiler/make.module_dep_file.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/make.module_dep_file.m,v
retrieving revision 1.24
diff -u -r1.24 make.module_dep_file.m
--- compiler/make.module_dep_file.m	13 Oct 2006 04:52:20 -0000	1.24
+++ compiler/make.module_dep_file.m	13 Oct 2006 12:16:39 -0000
@@ -553,8 +553,10 @@
             % file doesn't depend on anything else.
             %
             ( Error = no_module_errors ->
-                Target = ModuleName - unqualified_short_interface,
-                maybe_make_target_message(OldOutputStream, Target, !IO),
+                Target = ModuleName -
+                    module_target_unqualified_short_interface,
+                maybe_make_target_message_to_stream(OldOutputStream, Target,
+                    !IO),
                 build_with_check_for_interrupt(
                     build_with_module_options(ModuleName,
                         ["--make-short-interface"],
@@ -573,8 +575,10 @@
                         ModuleImportList)
                 ), cleanup_module_dep_files(SubModuleNames), _, !Info, !IO),
 
-            record_made_target(ModuleName - unqualified_short_interface,
-                process_module(make_short_interface), Succeeded, !Info, !IO),
+            record_made_target(
+                ModuleName - module_target_unqualified_short_interface,
+                process_module(task_make_short_interface), Succeeded,
+                !Info, !IO),
             unredirect_output(ModuleName, ErrorStream, !Info, !IO)
         )
     ;
@@ -605,8 +609,8 @@
     list.foldl2(
         (pred(SubModuleName::in, !.Info::in, !:Info::out, !.IO::di, !:IO::uo)
                 is det :-
-            make_remove_target_file(SubModuleName, unqualified_short_interface,
-                !Info, !IO)
+            make_remove_target_file(SubModuleName,
+                module_target_unqualified_short_interface, !Info, !IO)
         ), SubModuleNames, !Info, !IO).
 
 :- pred cleanup_module_dep_files(list(module_name)::in,
Index: compiler/make.module_target.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/make.module_target.m,v
retrieving revision 1.46
diff -u -r1.46 make.module_target.m
--- compiler/make.module_target.m	2 Oct 2006 05:21:13 -0000	1.46
+++ compiler/make.module_target.m	13 Oct 2006 12:43:33 -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: make.module_target.m.
 % Main author: stayl.
-% 
+%
 % Build targets which relate to a single module (e.g. C code, object code,
 % interface files).
-% 
+%
 %-----------------------------------------------------------------------------%
 
 :- module make.module_target.
@@ -19,14 +19,14 @@
 
 %-----------------------------------------------------------------------------%
 
-    % make_module_target(Target, Success, Info0, Info).
+    % make_module_target(Target, Success, !Info).
     %
     % Make a target corresponding to a single module.
     %
 :- pred make_module_target(dependency_file::in, bool::out,
     make_info::in, make_info::out, io::di, io::uo) is det.
 
-    % make_module_target_extra_options(ExtraOpts, Target, Success, Info0, Info)
+    % make_module_target_extra_options(ExtraOpts, Target, Success, !Info)
     %
     % Make a target corresponding to a single module, with extra command line
     % options.
@@ -45,18 +45,18 @@
 :- pred record_made_target(target_file::in, compilation_task_type::in,
     bool::in, make_info::in, make_info::out, io::di, io::uo) is det.
 
-:- type foreign_code_file --->
-    foreign_code_file(
-        foreign_language    :: foreign_language,
-
-                            % Name of the file produced by the Mercury
-                            % compiler, e.g. module_c_code.c.
-        target_file         :: file_name,
-
-                            % Name of the file produced by the foreign
-                            % language compiler, e.g. module_c_code.o.
-        object_file         :: file_name
-    ).
+:- type foreign_code_file
+    --->    foreign_code_file(
+                foreign_language    :: foreign_language,
+
+                target_file         :: file_name,
+                                    % Name of the file produced by the Mercury
+                                    % compiler, e.g. module_c_code.c.
+
+                object_file         :: file_name
+                                    % Name of the file produced by the foreign
+                                    % language compiler, e.g. module_c_code.o.
+            ).
 
     % Find the foreign code files generated when a module is processed.
     % The `pic' field is only used for C foreign code.
@@ -87,21 +87,22 @@
 make_module_target(DepFile, Succeeded, !Info, !IO) :-
     make_module_target_extra_options([], DepFile, Succeeded, !Info, !IO).
 
-make_module_target_extra_options(_ExtraOptions, file(_, _) @ Dep,
+make_module_target_extra_options(_ExtraOptions, dep_file(_, _) @ Dep,
         Succeeded, !Info, !IO) :-
     dependency_status(Dep, Status, !Info, !IO),
-    Succeeded = ( Status = error -> no ; yes ).
-make_module_target_extra_options(ExtraOptions, target(TargetFile) @ Dep,
+    Succeeded = ( Status = deps_status_error -> no ; yes ).
+make_module_target_extra_options(ExtraOptions, dep_target(TargetFile) @ Dep,
         Succeeded, !Info, !IO) :-
     dependency_status(Dep, Status, !Info, !IO),
     (
-        Status = not_considered,
+        Status = deps_status_not_considered,
         TargetFile = ModuleName - FileType,
         get_module_dependencies(ModuleName, MaybeImports, !Info, !IO),
         (
             MaybeImports = no,
             Succeeded = no,
-            !:Info = !.Info ^ dependency_status ^ elem(Dep) := error
+            !:Info = !.Info ^ dependency_status ^ elem(Dep)
+                := deps_status_error
         ;
             MaybeImports = yes(Imports),
             globals.io_get_globals(Globals, !IO),
@@ -115,13 +116,13 @@
                 Imports ^ source_file_module_name \= ModuleName
             ->
                 make_module_target_extra_options(ExtraOptions,
-                    target(Imports ^ source_file_module_name - FileType),
+                    dep_target(Imports ^ source_file_module_name - FileType),
                     Succeeded, !Info, !IO)
             ;
                 CompilationTask = CompilationTaskType - _,
                 touched_files(TargetFile, CompilationTaskType,
                     TouchedTargetFiles, TouchedFiles, !Info, !IO),
-                list.foldl(update_target_status(being_built),
+                list.foldl(update_target_status(deps_status_being_built),
                     TouchedTargetFiles, !Info),
 
                 debug_file_msg(TargetFile, "checking dependencies", !IO),
@@ -136,14 +137,14 @@
                     union_deps(target_dependencies(Globals, FileType)),
                     ModulesToCheck, DepsSuccess, set.init, DepFiles0,
                     !Info, !IO),
-                ( TargetFile = _ - private_interface ->
+                ( TargetFile = _ - module_target_private_interface ->
                     % Avoid circular dependencies (the `.int0' files
                     % for the nested sub-modules depend on this module's
                     % `.int0' file).
                     DepFilesToMake = set.to_sorted_list(
                         set.delete_list(DepFiles0,
                             make_dependency_list(ModulesToCheck,
-                                private_interface)))
+                                module_target_private_interface)))
                 ;
                     DepFilesToMake = set.to_sorted_list(DepFiles0)
                 ),
@@ -163,20 +164,21 @@
                     DepsSuccess = no,
                     KeepGoing = no
                 ->
-                    DepsResult = error
+                    DepsResult = deps_error
                 ;
                     make_dependency_files(TargetFile, DepFilesToMake,
                         TouchedTargetFiles, TouchedFiles, DepsResult0,
                         !Info, !IO),
-                    DepsResult = ( DepsSuccess = yes -> DepsResult0 ; error )
+                    DepsResult =
+                        ( DepsSuccess = yes -> DepsResult0 ; deps_error )
                 ),
                 (
-                    DepsResult = error,
+                    DepsResult = deps_error,
                     Succeeded = no,
-                    list.foldl(update_target_status(error),
+                    list.foldl(update_target_status(deps_status_error),
                         TouchedTargetFiles, !Info)
                 ;
-                    DepsResult = out_of_date,
+                    DepsResult = deps_out_of_date,
                     !:Info = !.Info ^ command_line_targets :=
                         set.delete(!.Info ^ command_line_targets,
                             ModuleName - module_target(FileType)),
@@ -184,23 +186,22 @@
                         TouchedTargetFiles, TouchedFiles, ExtraOptions,
                         Succeeded, !Info, !IO)
                 ;
-                    DepsResult = up_to_date,
+                    DepsResult = deps_up_to_date,
                     maybe_warn_up_to_date_target(
                         ModuleName - module_target(FileType), !Info, !IO),
                     debug_file_msg(TargetFile, "up to date", !IO),
                     Succeeded = yes,
-                    list.foldl(update_target_status(up_to_date),
-                        [TargetFile | TouchedTargetFiles],
-                        !Info)
+                    list.foldl(update_target_status(deps_status_up_to_date),
+                        [TargetFile | TouchedTargetFiles], !Info)
                 )
             )
         )
     ;
-        Status = up_to_date,
+        Status = deps_status_up_to_date,
         Succeeded = yes
     ;
-        Status = being_built,
-        ( TargetFile = _FileName - foreign_il_asm(_Lang) ->
+        Status = deps_status_being_built,
+        ( TargetFile = _FileName - module_target_foreign_il_asm(_Lang) ->
             io.write_string("Error: circular dependency detected " ++
                 "while building\n", !IO),
             io.write_string("  `", !IO),
@@ -215,7 +216,7 @@
         ),
         Succeeded = no
     ;
-        Status = error,
+        Status = deps_status_error,
         Succeeded = no
     ).
 
@@ -241,14 +242,14 @@
         MakeDepsSuccess = no
     ->
         debug_file_msg(TargetFile, "error making dependencies", !IO),
-        DepsResult = error
+        DepsResult = deps_error
     ;
         list.member(error(_), TargetTimestamps)
     ->
         debug_file_msg(TargetFile, "target file does not exist", !IO),
-        DepsResult = out_of_date
+        DepsResult = deps_out_of_date
     ;
-        ( TargetFile = ModuleName - analysis_registry ->
+        ( TargetFile = ModuleName - module_target_analysis_registry ->
             force_reanalysis_of_suboptimal_module(ModuleName, ForceReanalysis,
                 !.Info, !IO)
         ;
@@ -256,13 +257,13 @@
         ),
         (
             ForceReanalysis = yes,
-            DepsResult = out_of_date
+            DepsResult = deps_out_of_date
         ;
             ForceReanalysis = no,
-            %
+
             % Compare the oldest of the timestamps of the touched
             % files with the timestamps of the dependencies.
-            %
+
             list.map_foldl2(get_timestamp_file_timestamp,
                 TouchedTargetFiles, TouchedTargetFileTimestamps, !Info, !IO),
             list.map_foldl2(get_file_timestamp([dir.this_directory]),
@@ -271,7 +272,7 @@
                 TouchedTargetFileTimestamps, ok(newest_timestamp)),
             MaybeOldestTimestamp = list.foldl(find_oldest_timestamp,
                 TouchedFileTimestamps, MaybeOldestTimestamp0),
-    
+
             get_file_name(no, TargetFile, TargetFileName, !Info, !IO),
             check_dependencies(TargetFileName, MaybeOldestTimestamp,
                 MakeDepsSuccess, DepFilesToMake, DepsResult, !Info, !IO)
@@ -280,10 +281,10 @@
 
 :- pred force_reanalysis_of_suboptimal_module(module_name::in, bool::out,
     make_info::in, io::di, io::uo) is det.
-                
+
 force_reanalysis_of_suboptimal_module(ModuleName, ForceReanalysis, Info,
         !IO) :-
-    (if Info ^ reanalysis_passes > 0 then
+    ( Info ^ reanalysis_passes > 0 ->
         ModuleId = module_name_to_module_id(ModuleName),
         analysis.read_module_overall_status(mmc, ModuleId,
             MaybeAnalysisStatus, !IO),
@@ -292,7 +293,7 @@
         ;
             ForceReanalysis = no
         )
-    else
+    ;
         ForceReanalysis = no
     ).
 
@@ -358,15 +359,13 @@
         AllArgs = list.append(AllOptionArgs, [ModuleArg]),
         io.write_string("Invoking command `mmc ", !IO),
         % XXX Don't write the default options.
-        io.write_list(list.map(quote_arg, AllArgs), " ", io.write_string,
-            !IO),
+        io.write_list(list.map(quote_arg, AllArgs), " ", io.write_string, !IO),
         io.write_string("'", !IO),
         io.nl(!IO)
     ;
         Verbose = no
     ),
 
-    %
     % Run compilations to target code in a separate process.
     % This is necessary for `--target asm' because the GCC
     % backend can only be invoked once per process. It's a good
@@ -378,10 +377,11 @@
     % because if type checking gets overloaded by ambiguities
     % it can be difficult to kill the compiler otherwise.
     io.set_output_stream(ErrorStream, OldOutputStream, !IO),
-    ( 
+    (
         forkable_module_compilation_task_type(ModuleTask) = yes
     ->
-        call_in_forked_process(call_mercury_compile_main([ModuleArg]),
+        call_in_forked_process_with_backup(
+            call_mercury_compile_main([ModuleArg]),
             invoke_mmc(ErrorStream, ArgFileName, AllOptionArgs ++ [ModuleArg]),
             Succeeded, !IO)
     ;
@@ -390,13 +390,12 @@
     io.set_output_stream(OldOutputStream, _, !IO),
 
     (
-        ( ModuleTask = compile_to_target_code
-        ; ModuleTask = errorcheck
+        ( ModuleTask = task_compile_to_target_code
+        ; ModuleTask = task_errorcheck
         )
     ->
-        % The `.err_date' file is needed because the `.err'
-        % file is touched by all phases of compilation, including
-        % writing interfaces.
+        % The `.err_date' file is needed because the `.err' file is touched
+        % by all phases of compilation, including writing interfaces.
         touch_interface_datestamp(ModuleName, ".err_date", !IO)
     ;
         true
@@ -406,8 +405,8 @@
         Imports, _, ErrorStream, Succeeded, !Info, !IO) :-
     globals.io_get_target(CompilationTarget, !IO),
 
-    % Run the compilation in a child process so it can
-    % be killed if an interrupt arrives.
+    % Run the compilation in a child process so it can be killed
+    % if an interrupt arrives.
     call_in_forked_process(
         build_object_code(ModuleName, CompilationTarget, PIC, ErrorStream,
             Imports),
@@ -417,8 +416,8 @@
         Imports, _, ErrorStream, Succeeded, !Info, !Io) :-
     foreign_code_file(ModuleName, PIC, Lang, ForeignCodeFile, !Io),
 
-    % Run the compilation in a child process so it can
-    % be killed if an interrupt arrives.
+    % Run the compilation in a child process so it can be killed
+    % if an interrupt arrives.
     call_in_forked_process(
         compile_foreign_code_file(ErrorStream, PIC, Imports, ForeignCodeFile),
         Succeeded, !Io).
@@ -428,8 +427,8 @@
     fact_table_foreign_code_file(ModuleName, PIC, FactTableFile,
         FactTableForeignCode, !IO),
 
-    % Run the compilation in a child process so it can
-    % be killed if an interrupt arrives.
+    % Run the compilation in a child process so it can be killed
+    % if an interrupt arrives.
     call_in_forked_process(
         compile_foreign_code_file(ErrorStream, PIC, Imports,
             FactTableForeignCode),
@@ -487,13 +486,13 @@
 :- func forkable_module_compilation_task_type(module_compilation_task_type)
     = bool.
 
-forkable_module_compilation_task_type(errorcheck) = no.
-forkable_module_compilation_task_type(make_short_interface) = no.
-forkable_module_compilation_task_type(make_interface) = no.
-forkable_module_compilation_task_type(make_private_interface) = no.
-forkable_module_compilation_task_type(make_optimization_interface) = yes.
-forkable_module_compilation_task_type(make_analysis_registry) = yes.
-forkable_module_compilation_task_type(compile_to_target_code) = yes.
+forkable_module_compilation_task_type(task_errorcheck) = no.
+forkable_module_compilation_task_type(task_make_short_interface) = no.
+forkable_module_compilation_task_type(task_make_interface) = no.
+forkable_module_compilation_task_type(task_make_private_interface) = no.
+forkable_module_compilation_task_type(task_make_optimization_interface) = yes.
+forkable_module_compilation_task_type(task_make_analysis_registry) = yes.
+forkable_module_compilation_task_type(task_compile_to_target_code) = yes.
 
 %-----------------------------------------------------------------------------%
 
@@ -636,10 +635,10 @@
         OtherTouchedFiles, !Info, !IO) :-
     (
         Succeeded = yes,
-        TargetStatus = up_to_date
+        TargetStatus = deps_status_up_to_date
     ;
         Succeeded = no,
-        TargetStatus = error,
+        TargetStatus = deps_status_error,
         target_file_error(TargetFile, !IO)
     ),
 
@@ -656,10 +655,10 @@
     list.foldl(DeleteTimestamp, OtherTouchedFiles, !Info).
 
 :- pred update_target_status(dependency_status::in, target_file::in,
-        make_info::in, make_info::out) is det.
+    make_info::in, make_info::out) is det.
 
 update_target_status(TargetStatus, TargetFile, Info,
-    Info ^ dependency_status ^ elem(target(TargetFile)) := TargetStatus).
+    Info ^ dependency_status ^ elem(dep_target(TargetFile)) := TargetStatus).
 
 %-----------------------------------------------------------------------------%
 
@@ -668,46 +667,49 @@
 :- func compilation_task(globals, module_target_type) =
     compilation_task_result.
 
-compilation_task(_, source) = _ :- unexpected(this_file, "compilation_task").
-compilation_task(_, errors) =
-    process_module(errorcheck) - ["--errorcheck-only"].
-compilation_task(_, unqualified_short_interface) =
-    process_module(make_short_interface) - ["--make-short-interface"].
-compilation_task(Globals, short_interface) =
-    compilation_task(Globals, long_interface).
-compilation_task(_, long_interface) =
-    process_module(make_interface) - ["--make-interface"].
-compilation_task(_, private_interface) =
-    process_module(make_private_interface) - ["--make-private-interface"].
-compilation_task(_, intermodule_interface) =
-    process_module(make_optimization_interface) -
+compilation_task(_, module_target_source) = _ :-
+    unexpected(this_file, "compilation_task").
+compilation_task(_, module_target_errors) =
+    process_module(task_errorcheck) - ["--errorcheck-only"].
+compilation_task(_, module_target_unqualified_short_interface) =
+    process_module(task_make_short_interface) - ["--make-short-interface"].
+compilation_task(Globals, module_target_short_interface) =
+    compilation_task(Globals, module_target_long_interface).
+compilation_task(_, module_target_long_interface) =
+    process_module(task_make_interface) - ["--make-interface"].
+compilation_task(_, module_target_private_interface) =
+    process_module(task_make_private_interface) - ["--make-private-interface"].
+compilation_task(_, module_target_intermodule_interface) =
+    process_module(task_make_optimization_interface) -
         ["--make-optimization-interface"].
-compilation_task(_, analysis_registry) =
-    process_module(make_analysis_registry) - ["--make-analysis-registry"].
-compilation_task(Globals, c_header(_)) = compilation_task(Globals, c_code).
-compilation_task(_, c_code) =
-    process_module(compile_to_target_code) - ["--compile-to-c"].
-compilation_task(_, il_code) =
-    process_module(compile_to_target_code) - ["--il-only"].
-compilation_task(_, il_asm) = target_code_to_object_code(non_pic) - [].
-compilation_task(_, java_code) =
-    process_module(compile_to_target_code) - ["--java-only"].
-compilation_task(_, asm_code(PIC)) =
-    process_module(compile_to_target_code) - ( PIC = pic -> ["--pic"] ; [] ).
-compilation_task(_, object_code(PIC)) =
+compilation_task(_, module_target_analysis_registry) =
+    process_module(task_make_analysis_registry) - ["--make-analysis-registry"].
+compilation_task(Globals, module_target_c_header(_)) =
+        compilation_task(Globals, module_target_c_code).
+compilation_task(_, module_target_c_code) =
+    process_module(task_compile_to_target_code) - ["--compile-to-c"].
+compilation_task(_, module_target_il_code) =
+    process_module(task_compile_to_target_code) - ["--il-only"].
+compilation_task(_, module_target_il_asm) =
+        target_code_to_object_code(non_pic) - [].
+compilation_task(_, module_target_java_code) =
+    process_module(task_compile_to_target_code) - ["--java-only"].
+compilation_task(_, module_target_asm_code(PIC)) =
+    process_module(task_compile_to_target_code) -
+        ( PIC = pic -> ["--pic"] ; [] ).
+compilation_task(_, module_target_object_code(PIC)) =
     target_code_to_object_code(PIC) - get_pic_flags(PIC).
-compilation_task(_, foreign_il_asm(Lang)) =
+compilation_task(_, module_target_foreign_il_asm(Lang)) =
     foreign_code_to_object_code(non_pic, Lang) - [].
-compilation_task(_, foreign_object(PIC, Lang)) =
+compilation_task(_, module_target_foreign_object(PIC, Lang)) =
     foreign_code_to_object_code(PIC, Lang) - get_pic_flags(PIC).
-compilation_task(_, fact_table_object(PIC, FactTable)) =
+compilation_task(_, module_target_fact_table_object(PIC, FactTable)) =
     fact_table_code_to_object_code(PIC, FactTable) - get_pic_flags(PIC).
 
 :- func get_pic_flags(pic) = list(string).
 
-% `--pic-reg' is harmless for architectures and grades where
-% it is not needed (it's only needed for grades using
-% GCC global register variables on x86).
+% `--pic-reg' is harmless for architectures and grades where it is not needed
+% (it's only needed for grades using GCC global register variables on x86).
 get_pic_flags(pic) = ["--pic", "--pic-reg"].
 get_pic_flags(link_with_pic) = ["--pic-reg"].
 get_pic_flags(non_pic) = [].
@@ -754,7 +756,7 @@
 
     globals.io_get_target(CompilationTarget, !IO),
     (
-        Task = compile_to_target_code,
+        Task = task_compile_to_target_code,
         CompilationTarget = target_asm
     ->
         % For `--target asm' the code for the nested children is placed
@@ -768,7 +770,7 @@
     % Find out what header files are generated.
     %
     (
-        Task = compile_to_target_code,
+        Task = task_compile_to_target_code,
         list.map_foldl(
             external_foreign_code_files(target_type_to_pic(FileType)),
                 ModuleImportsList, ForeignCodeFileList, !IO),
@@ -786,7 +788,7 @@
                 %
                 HeaderModuleNames = SourceFileModuleNames,
                 HeaderTargets0 = make_target_list(HeaderModuleNames,
-                    c_header(mih))
+                    module_target_c_header(header_mih))
             ;
                 HighLevelCode = no,
                 HeaderTargets0 = []
@@ -803,7 +805,8 @@
                         contains_foreign_code(_) =
                             MImports ^ has_foreign_code
                     ), ModuleImportsList),
-            HeaderTargets0 = make_target_list(HeaderModuleNames, c_header(mih))
+            HeaderTargets0 = make_target_list(HeaderModuleNames,
+                module_target_c_header(header_mih))
         ;
             CompilationTarget = target_il,
             HeaderTargets0 = []
@@ -818,7 +821,8 @@
             )
         ->
             Names = SourceFileModuleNames,
-            HeaderTargets = make_target_list(Names, c_header(mh))
+            HeaderTargets =
+                make_target_list(Names, module_target_c_header(header_mh))
                 ++ HeaderTargets0
         ;
             HeaderTargets = HeaderTargets0
@@ -827,19 +831,20 @@
         TouchedTargetFiles0 = make_target_list(TargetModuleNames, FileType),
         TouchedTargetFiles = TouchedTargetFiles0 ++ HeaderTargets
     ;
-        Task = make_interface,
+        Task = task_make_interface,
         % Both long and short interface files are produced
         % when making the interface.
         ForeignCodeFiles = [],
         TouchedTargetFiles =
-            make_target_list(TargetModuleNames, long_interface) ++
-            make_target_list(TargetModuleNames, short_interface)
-    ;
-        ( Task = errorcheck
-        ; Task = make_short_interface
-        ; Task = make_private_interface
-        ; Task = make_optimization_interface
-        ; Task = make_analysis_registry
+            make_target_list(TargetModuleNames, module_target_long_interface)
+            ++
+            make_target_list(TargetModuleNames, module_target_short_interface)
+    ;
+        ( Task = task_errorcheck
+        ; Task = task_make_short_interface
+        ; Task = task_make_private_interface
+        ; Task = task_make_optimization_interface
+        ; Task = task_make_analysis_registry
         ),
         ForeignCodeFiles = [],
         TouchedTargetFiles = make_target_list(TargetModuleNames, FileType)
@@ -952,9 +957,9 @@
 :- func target_type_to_pic(module_target_type) = pic.
 
 target_type_to_pic(TargetType) = Result :-
-    ( TargetType = asm_code(PIC) ->
+    ( TargetType = module_target_asm_code(PIC) ->
         Result = PIC
-    ; TargetType = object_code(PIC) ->
+    ; TargetType = module_target_object_code(PIC) ->
         Result = PIC
     ;
         Result = non_pic
Index: compiler/make.program_target.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/make.program_target.m,v
retrieving revision 1.52
diff -u -r1.52 make.program_target.m
--- compiler/make.program_target.m	22 Aug 2006 05:03:52 -0000	1.52
+++ compiler/make.program_target.m	13 Oct 2006 12:44:12 -0000
@@ -18,14 +18,14 @@
 
 %-----------------------------------------------------------------------------%
 
-    % make_linked_target(Target, Success, Info0, Info):
+    % make_linked_target(Target, Success, !Info):
     %
     % Build a library or an executable.
     %
 :- pred make_linked_target(linked_target_file::in, bool::out,
     make_info::in, make_info::out, io::di, io::uo) is det.
 
-    % make_misc_target(Target, Success, Info0, Info):
+    % make_misc_target(Target, Success, !Info):
     %
     % Handle miscellaneous target types, including clean-up, library
     % installation, and building all files of a given type for all
@@ -76,7 +76,8 @@
             IntermoduleAnalysis, !IO),
         (
             IntermoduleAnalysis = yes,
-            make_misc_target(MainModuleName - build_analyses,
+            make_misc_target_builder(
+                MainModuleName - misc_target_build_analyses,
                 ExtraOptions, Succeeded0, !Info, !IO)
         ;
             IntermoduleAnalysis = no,
@@ -113,21 +114,21 @@
         globals.io_get_target(CompilationTarget, !IO),
         (
             CompilationTarget = target_c,
-            IntermediateTargetType = c_code,
-            ObjectTargetType = object_code(PIC)
+            IntermediateTargetType = module_target_c_code,
+            ObjectTargetType = module_target_object_code(PIC)
         ;
             CompilationTarget = target_asm,
-            IntermediateTargetType = asm_code(PIC),
-            ObjectTargetType = object_code(PIC)
+            IntermediateTargetType = module_target_asm_code(PIC),
+            ObjectTargetType = module_target_object_code(PIC)
         ;
             CompilationTarget = target_il,
-            IntermediateTargetType = il_code,
-            ObjectTargetType = il_asm
+            IntermediateTargetType = module_target_il_code,
+            ObjectTargetType = module_target_il_asm
         ;
             CompilationTarget = target_java,
-            IntermediateTargetType = java_code,
+            IntermediateTargetType = module_target_java_code,
             % XXX Whoever finishes the Java backend can fill this in.
-            ObjectTargetType = object_code(non_pic)
+            ObjectTargetType = module_target_object_code(non_pic)
         ),
 
         get_target_modules(IntermediateTargetType,
@@ -152,7 +153,7 @@
             ObjTargets, BuildDepsResult, !Info, !IO),
         (
             DepsSuccess = yes,
-            BuildDepsResult \= error
+            BuildDepsResult \= deps_error
         ->
             build_with_check_for_interrupt(
                 build_with_output_redirect(MainModuleName,
@@ -176,16 +177,16 @@
     globals.io_get_target(CompilationTarget, !IO),
     (
         (
-            TargetType = errors
+            TargetType = module_target_errors
         ;
             CompilationTarget = target_asm,
-            ( TargetType = asm_code(_)
-            ; TargetType = object_code(_)
+            ( TargetType = module_target_asm_code(_)
+            ; TargetType = module_target_object_code(_)
             )
         )
     ->
-        % `.err' and `.s' files are only produced for the
-        % top-level module in each source file.
+        % `.err' and `.s' files are only produced for the top-level module
+        % in each source file.
         list.foldl3(get_target_modules_2, AllModules,
             [], TargetModules, !Info, !IO)
     ;
@@ -229,13 +230,14 @@
         set.member(lang_c, Langs)
     ->
         ForeignObjectTargets =
-            [target(ModuleName - foreign_object(PIC, lang_c))]
+            [dep_target(ModuleName
+                - module_target_foreign_object(PIC, lang_c))]
     ;
         CompilationTarget = target_il,
         Imports ^ has_foreign_code = contains_foreign_code(Langs)
     ->
         ForeignObjectTargets = list.map(
-            (func(L) = target(ModuleName - foreign_il_asm(L))
+            (func(L) = dep_target(ModuleName - module_target_foreign_il_asm(L))
             ), set.to_sorted_list(Langs))
     ;
         ForeignObjectTargets = []
@@ -250,7 +252,8 @@
     ->
         FactObjectTargets = list.map(
             (func(FactFile) =
-                target(ModuleName - fact_table_object(PIC, FactFile))
+                dep_target(ModuleName -
+                    module_target_fact_table_object(PIC, FactFile))
             ),
             Imports ^ fact_table_deps),
         ObjectTargets = FactObjectTargets ++ ForeignObjectTargets
@@ -324,7 +327,7 @@
             DepsResult2 = BuildDepsResult
         ;
             InitObjectResult = no,
-            DepsResult2 = error,
+            DepsResult2 = deps_error,
             InitObjects = []
         )
     ;
@@ -336,29 +339,30 @@
 
     % Report errors if any of the extra objects aren't present.
     list.map_foldl2(dependency_status,
-        list.map((func(F) = file(F, no)), ObjectsToCheck),
+        list.map((func(F) = dep_file(F, no)), ObjectsToCheck),
         ExtraObjStatus, !Info, !IO),
 
     DepsResult3 =
-        ( list.member(error, ExtraObjStatus) -> error ; DepsResult2 ),
-    BuildDepsSuccess = ( DepsResult3 \= error -> yes ; no ),
+        ( list.member(deps_status_error, ExtraObjStatus) ->
+            deps_error ; DepsResult2 ),
+    BuildDepsSuccess = ( DepsResult3 \= deps_error -> yes ; no ),
     list.map_foldl2(get_file_timestamp([dir.this_directory]),
         ObjectsToCheck, ExtraObjectTimestamps, !Info, !IO),
     check_dependency_timestamps(OutputFileName, MaybeTimestamp,
         BuildDepsSuccess, ObjectsToCheck, io.write,
         ExtraObjectTimestamps, ExtraObjectDepsResult, !IO),
 
-    DepsResult4 = ( DepsSuccess = yes -> DepsResult3 ; error ),
-    ( DepsResult4 = error, DepsResult = DepsResult4
-    ; DepsResult4 = out_of_date, DepsResult = DepsResult4
-    ; DepsResult4 = up_to_date, DepsResult = ExtraObjectDepsResult
+    DepsResult4 = ( DepsSuccess = yes -> DepsResult3 ; deps_error ),
+    ( DepsResult4 = deps_error, DepsResult = DepsResult4
+    ; DepsResult4 = deps_out_of_date, DepsResult = DepsResult4
+    ; DepsResult4 = deps_up_to_date, DepsResult = ExtraObjectDepsResult
     ),
     (
-        DepsResult = error,
+        DepsResult = deps_error,
         file_error(OutputFileName, !IO),
         Succeeded = no
     ;
-        DepsResult = up_to_date,
+        DepsResult = deps_up_to_date,
         globals.io_lookup_bool_option(use_grade_subdirs, UseGradeSubdirs,
             !IO),
         (
@@ -374,7 +378,7 @@
             Succeeded = yes
         )
     ;
-        DepsResult = out_of_date,
+        DepsResult = deps_out_of_date,
         maybe_make_linked_target_message(OutputFileName, !IO),
 
         % Find the extra object files for externally compiled foreign
@@ -490,18 +494,20 @@
 
 make_misc_target(MainModuleName - TargetType, Succeeded, !Info, !IO) :-
     build_with_module_options(MainModuleName, [],
-        make_misc_target(MainModuleName - TargetType), Succeeded, !Info, !IO).
+        make_misc_target_builder(MainModuleName - TargetType),
+        Succeeded, !Info, !IO).
 
-:- pred make_misc_target(pair(module_name, misc_target_type)::in,
+:- pred make_misc_target_builder(pair(module_name, misc_target_type)::in,
     list(string)::in, bool::out, make_info::in, make_info::out,
     io::di, io::uo) is det.
 
-make_misc_target(MainModuleName - TargetType, _, Succeeded, !Info, !IO) :-
+make_misc_target_builder(MainModuleName - TargetType, _, Succeeded,
+        !Info, !IO) :-
     % Don't rebuild dependencies when cleaning up.
     RebuildDeps = !.Info ^ rebuild_dependencies,
     (
-        ( TargetType = clean
-        ; TargetType = realclean
+        ( TargetType = misc_target_clean
+        ; TargetType = misc_target_realclean
         )
     ->
         !:Info = !.Info ^ rebuild_dependencies := no
@@ -513,17 +519,17 @@
     !:Info = !.Info ^ rebuild_dependencies := RebuildDeps,
     AllModules = set.to_sorted_list(AllModulesSet),
     (
-        TargetType = clean,
+        TargetType = misc_target_clean,
         Succeeded = yes,
         list.foldl2(make_module_clean, AllModules, !Info, !IO),
         remove_init_files(MainModuleName, !Info, !IO)
     ;
-        TargetType = realclean,
+        TargetType = misc_target_realclean,
         Succeeded = yes,
         make_main_module_realclean(MainModuleName, !Info, !IO),
         list.foldl2(make_module_realclean, AllModules, !Info, !IO)
     ;
-        TargetType = build_all(ModuleTargetType),
+        TargetType = misc_target_build_all(ModuleTargetType),
         get_target_modules(ModuleTargetType, AllModules, TargetModules,
             !Info, !IO),
         globals.io_lookup_bool_option(keep_going, KeepGoing, !IO),
@@ -537,19 +543,21 @@
             Succeeded = Succeeded0 `and` Succeeded1
         )
     ;
-        TargetType = build_analyses,
+        TargetType = misc_target_build_analyses,
         build_analysis_files(MainModuleName, AllModules, Succeeded0, Succeeded,
             !Info, !IO)
     ;
-        TargetType = build_library,
+        TargetType = misc_target_build_library,
         ShortInts = make_dependency_list(AllModules,
-            unqualified_short_interface),
-        LongInts = make_dependency_list(AllModules, long_interface),
+            module_target_unqualified_short_interface),
+        LongInts = make_dependency_list(AllModules,
+            module_target_long_interface),
         globals.io_lookup_bool_option(intermodule_optimization,
             Intermod, !IO),
         (
             Intermod = yes,
-            OptFiles = make_dependency_list(AllModules, intermodule_interface)
+            OptFiles = make_dependency_list(AllModules,
+                module_target_intermodule_interface)
         ;
             Intermod = no,
             OptFiles = []
@@ -595,9 +603,9 @@
             Succeeded = no
         )
     ;
-        TargetType = install_library,
-        make_misc_target(MainModuleName - build_library, LibSucceeded,
-            !Info, !IO),
+        TargetType = misc_target_install_library,
+        make_misc_target(MainModuleName - misc_target_build_library,
+            LibSucceeded, !Info, !IO),
         (
             LibSucceeded = yes,
             install_library(MainModuleName, Succeeded, !Info, !IO)
@@ -613,8 +621,8 @@
 
 build_analysis_files(MainModuleName, AllModules, Succeeded0, Succeeded,
         !Info, !IO) :-
-    get_target_modules(analysis_registry, AllModules, TargetModules0,
-        !Info, !IO),
+    get_target_modules(module_target_analysis_registry, AllModules,
+        TargetModules0, !Info, !IO),
     globals.io_lookup_bool_option(keep_going, KeepGoing, !IO),
     ( Succeeded0 = no, KeepGoing = no ->
         Succeeded = no
@@ -645,7 +653,7 @@
     globals.io_lookup_bool_option(keep_going, KeepGoing, !IO),
     foldl2_maybe_stop_at_error(KeepGoing,
         make_module_target_extra_options(LocalModulesOpts),
-        make_dependency_list(TargetModules, analysis_registry),
+        make_dependency_list(TargetModules, module_target_analysis_registry),
         Succeeded1, !Info, !IO),
     % Maybe we should have an option to reanalyse cliques before moving 
     % upwards in the dependency graph?
@@ -754,8 +762,8 @@
     make_info::in, make_info::out) is det.
 
 reset_analysis_registry_dependency_status(ModuleName, Info,
-        Info ^ dependency_status ^ elem(Dep) := not_considered) :-
-    Dep = target(ModuleName - analysis_registry).
+        Info ^ dependency_status ^ elem(Dep) := deps_status_not_considered) :-
+    Dep = dep_target(ModuleName - module_target_analysis_registry).
 
 %-----------------------------------------------------------------------------%
 
@@ -926,14 +934,14 @@
         StatusMap = map.from_assoc_list(list.filter(
             (pred((File - _)::in) is semidet :-
                 \+ (
-                    File = target(_ - Target),
+                    File = dep_target(_ - Target),
                     target_is_grade_or_arch_dependent(Target)
                 )
             ),
             map.to_assoc_list(StatusMap0))),
         Info1 = (Info0 ^ dependency_status := StatusMap)
             ^ option_args := OptionArgs,
-        make_misc_target(ModuleName - build_library, LibSucceeded,
+        make_misc_target(ModuleName - misc_target_build_library, LibSucceeded,
             Info1, Info2, !IO),
         (
             LibSucceeded = yes,
@@ -1256,8 +1264,9 @@
 
 make_module_clean(ModuleName, !Info, !IO) :-
     list.foldl2(make_remove_target_file(ModuleName),
-        [errors, c_code, c_header(mih), il_code, java_code],
-        !Info, !IO),
+        [module_target_errors, module_target_c_code,
+        module_target_c_header(header_mih), module_target_il_code,
+        module_target_java_code], !Info, !IO),
 
     list.foldl2(make_remove_file(ModuleName), [".used", ".prof"], !Info, !IO),
 
@@ -1278,20 +1287,23 @@
         ), FactTableFiles, !Info, !IO),
 
     CCodeModule = foreign_language_module_name(ModuleName, lang_c),
-    make_remove_target_file(CCodeModule, c_code, !Info, !IO),
+    make_remove_target_file(CCodeModule, module_target_c_code, !Info, !IO),
 
     % Remove object and assembler files.
     list.foldl2(
         (pred(PIC::in, !.Info::in, !:Info::out, !.IO::di, !:IO::uo) is det :-
-        make_remove_target_file(ModuleName, object_code(PIC), !Info, !IO),
-        make_remove_target_file(ModuleName, asm_code(PIC), !Info, !IO),
-        make_remove_target_file(ModuleName, foreign_object(PIC, lang_c),
+        make_remove_target_file(ModuleName, module_target_object_code(PIC),
+            !Info, !IO),
+        make_remove_target_file(ModuleName, module_target_asm_code(PIC),
             !Info, !IO),
+        make_remove_target_file(ModuleName,
+            module_target_foreign_object(PIC, lang_c), !Info, !IO),
         list.foldl2(
             (pred(FactTableFile::in, !.Info::in, !:Info::out,
                     !.IO::di, !:IO::uo) is det :-
                 make_remove_target_file(ModuleName,
-                    fact_table_object(PIC, FactTableFile), !Info, !IO)
+                    module_target_fact_table_object(PIC, FactTableFile),
+                    !Info, !IO)
             ), FactTableFiles, !Info, !IO)
         ),
         [pic, link_with_pic, non_pic], !Info, !IO),
@@ -1300,16 +1312,16 @@
     CSharpModule = foreign_language_module_name(ModuleName, lang_csharp),
     make_remove_file(CSharpModule,
         foreign_language_file_extension(lang_csharp), !Info, !IO),
-    make_remove_target_file(CSharpModule, foreign_il_asm(lang_csharp),
-        !Info, !IO),
+    make_remove_target_file(CSharpModule,
+        module_target_foreign_il_asm(lang_csharp), !Info, !IO),
 
     McppModule = foreign_language_module_name(ModuleName,
         lang_managed_cplusplus),
     make_remove_file(McppModule,
         foreign_language_file_extension(lang_managed_cplusplus),
         !Info, !IO),
-    make_remove_target_file(McppModule, foreign_il_asm(lang_managed_cplusplus),
-        !Info, !IO).
+    make_remove_target_file(McppModule,
+        module_target_foreign_il_asm(lang_managed_cplusplus), !Info, !IO).
 
 :- pred make_module_realclean(module_name::in, make_info::in, make_info::out,
     io::di, io::uo) is det.
@@ -1318,13 +1330,13 @@
     make_module_clean(ModuleName, !Info, !IO),
     list.foldl2(make_remove_target_file(ModuleName),
         [
-            private_interface, 
-            long_interface, 
-            short_interface,
-            unqualified_short_interface, 
-            intermodule_interface, 
-            analysis_registry,
-            c_header(mh)
+            module_target_private_interface, 
+            module_target_long_interface, 
+            module_target_short_interface,
+            module_target_unqualified_short_interface, 
+            module_target_intermodule_interface, 
+            module_target_analysis_registry,
+            module_target_c_header(header_mh)
         ],
         !Info, !IO),
     make_remove_file(ModuleName, make_module_dep_file_extension, !Info, !IO),
Index: compiler/make.util.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/make.util.m,v
retrieving revision 1.36
diff -u -r1.36 make.util.m
--- compiler/make.util.m	31 Jul 2006 08:31:47 -0000	1.36
+++ compiler/make.util.m	13 Oct 2006 12:44:33 -0000
@@ -5,12 +5,12 @@
 % This file may only be copied under the terms of the GNU General
 % Public License - see the file COPYING in the Mercury distribution.
 %-----------------------------------------------------------------------------%
-% 
+%
 % File: make.util.m.
 % Main author: stayl.
-% 
+%
 % Assorted predicates used to implement `mmc --make'.
-% 
+%
 %-----------------------------------------------------------------------------%
 
 :- module make.util.
@@ -56,33 +56,29 @@
 :- type build(T) == build(T, make_info).
 :- inst build == (pred(in, out, in, out, di, uo) is det).
 
-    % build_with_module_options(ModuleName, ExtraArgs, Builder,
-    %   Succeeded, !Info).
+    % build_with_module_options(ModuleName, ExtraArgs, Builder, Succeeded,
+    %   !Info).
     %
-    % Perform the given closure after updating the option_table in
-    % the globals in the io.state to contain the module-specific
-    % options for the specified module and the extra options given
-    % in the ExtraArgs.
-    % Adds `--invoked-by-mmc-make' and `--use-subdirs' to the option
-    % list.
+    % Perform the given closure after updating the option_table in the globals
+    % in the io.state to contain the module-specific options for the specified
+    % module and the extra options given in the ExtraArgs.
+    % Adds `--invoked-by-mmc-make' and `--use-subdirs' to the option list.
     % The old option table will be restored afterwards.
     %
 :- pred build_with_module_options(module_name::in,
     list(string)::in, build(list(string))::in(build), bool::out,
     make_info::in, make_info::out, io::di, io::uo) is det.
 
-    % build_with_module_options(ModuleName, OptionsVariables,
+    % build_with_module_options_args(ModuleName, OptionsVariables,
     %   OptionArgs, ExtraArgs, Builder, Succeeded, !Info).
     %
-    % Perform the given closure after updating the option_table in
-    % the globals in the io.state to contain the module-specific
-    % options for the specified module and the extra options given
-    % in ExtraArgs and OptionArgs
-    % Does not add `--invoked-by-mmc-make' and `--use-subdirs'
-    % to the option list.
-    % The old option table will be restored afterwards.
+    % Perform the given closure after updating the option_table in the globals
+    % in the io.state to contain the module-specific options for the specified
+    % module and the extra options given in ExtraArgs and OptionArgs.
+    % Does not add `--invoked-by-mmc-make' and `--use-subdirs' to the
+    % option list. The old option table will be restored afterwards.
     %
-:- pred build_with_module_options(module_name::in, options_variables::in,
+:- pred build_with_module_options_args(module_name::in, options_variables::in,
     list(string)::in, list(string)::in,
     build(list(string), Info1, Info2)::in(build),
     bool::out, Info1::in, maybe(Info2)::out, io::di, io::uo) is det.
@@ -237,8 +233,8 @@
     %
 :- pred maybe_make_target_message(target_file::in, io::di, io::uo) is det.
 
-:- pred maybe_make_target_message(io.output_stream::in, target_file::in,
-    io::di, io::uo) is det.
+:- pred maybe_make_target_message_to_stream(io.output_stream::in,
+    target_file::in, io::di, io::uo) is det.
 
     % Write a message "Reanalysing invalid/suboptimal modules" if
     % `--verbose-make' is set.
@@ -366,27 +362,28 @@
 
 build_with_module_options(ModuleName, ExtraOptions, Build, Succeeded,
         !Info, !IO) :-
-    build_with_module_options(yes, ModuleName, !.Info ^ options_variables,
-        !.Info ^ option_args, ExtraOptions, Build, Succeeded,
-        !.Info, MaybeInfo, !IO),
+    build_with_module_options_args_invoked(yes, ModuleName,
+        !.Info ^ options_variables, !.Info ^ option_args, ExtraOptions, Build,
+        Succeeded, !.Info, MaybeInfo, !IO),
     (
         MaybeInfo = yes(!:Info)
     ;
         MaybeInfo = no
     ).
 
-build_with_module_options(ModuleName, OptionVariables,
+build_with_module_options_args(ModuleName, OptionVariables,
         OptionArgs, ExtraOptions, Build, Succeeded, !Info, !IO) :-
-    build_with_module_options(no, ModuleName, OptionVariables,
+    build_with_module_options_args_invoked(no, ModuleName, OptionVariables,
         OptionArgs, ExtraOptions, Build, Succeeded, !Info, !IO).
 
-:- pred build_with_module_options(bool::in, module_name::in,
+:- pred build_with_module_options_args_invoked(bool::in, module_name::in,
     options_variables::in, list(string)::in, list(string)::in,
     build(list(string), Info1, Info2)::in(build),
     bool::out, Info1::in, maybe(Info2)::out, io::di, io::uo) is det.
 
-build_with_module_options(InvokedByMmcMake, ModuleName, OptionVariables,
-        OptionArgs, ExtraOptions, Build, Succeeded, Info0, MaybeInfo, !IO) :-
+build_with_module_options_args_invoked(InvokedByMmcMake, ModuleName,
+        OptionVariables, OptionArgs, ExtraOptions, Build, Succeeded,
+        Info0, MaybeInfo, !IO) :-
     lookup_mmc_module_options(OptionVariables, ModuleName, OptionsResult, !IO),
     (
         OptionsResult = no,
@@ -547,7 +544,7 @@
     SearchDirs = [dir.this_directory],
     get_file_timestamp(SearchDirs, FileName, MaybeTimestamp, !Info, !IO).
 
-get_dependency_timestamp(file(FileName, MaybeOption), MaybeTimestamp,
+get_dependency_timestamp(dep_file(FileName, MaybeOption), MaybeTimestamp,
         !Info, !IO) :-
     (
         MaybeOption = yes(Option),
@@ -557,10 +554,10 @@
         SearchDirs = [dir.this_directory]
     ),
     get_file_timestamp(SearchDirs, FileName, MaybeTimestamp, !Info, !IO).
-get_dependency_timestamp(target(Target), MaybeTimestamp, !Info, !IO) :-
+get_dependency_timestamp(dep_target(Target), MaybeTimestamp, !Info, !IO) :-
     get_target_timestamp(yes, Target, MaybeTimestamp0, !Info, !IO),
     (
-        Target = _ - c_header(mih),
+        Target = _ - module_target_c_header(header_mih),
         MaybeTimestamp0 = ok(_)
     ->
         % Don't rebuild the `.o' file if an irrelevant part of a
@@ -574,7 +571,7 @@
     ).
 
 get_target_timestamp(Search, Target, MaybeTimestamp, !Info, !IO) :-
-    ( Target = ModuleName - analysis_registry ->
+    ( Target = ModuleName - module_target_analysis_registry ->
         get_target_timestamp_analysis_registry(Search, ModuleName,
             MaybeTimestamp, !Info, !IO)
     ;
@@ -601,8 +598,9 @@
             ( Status = optimal
             ; Status = suboptimal
             ),
-            get_timestamp_file_timestamp(ModuleName - analysis_registry,
-                MaybeTimestamp0, !Info, !IO),
+            get_timestamp_file_timestamp(
+                ModuleName - module_target_analysis_registry, MaybeTimestamp0,
+                !Info, !IO),
             (
                 MaybeTimestamp0 = ok(_),
                 MaybeTimestamp = MaybeTimestamp0
@@ -620,8 +618,9 @@
         )
     ;
         MaybeStatus = no,
-        get_target_timestamp_2(Search, ModuleName - analysis_registry,  
-            MaybeTimestamp, !Info, !IO)
+        get_target_timestamp_2(Search,
+            ModuleName - module_target_analysis_registry, MaybeTimestamp,
+            !Info, !IO)
     ).
 
 :- pred get_target_timestamp_2(bool::in, target_file::in,
@@ -641,8 +640,8 @@
     get_file_timestamp(SearchDirs, FileName, MaybeTimestamp0, !Info, !IO),
     (
         MaybeTimestamp0 = error(_),
-        ( FileType = intermodule_interface
-        ; FileType = analysis_registry
+        ( FileType = module_target_intermodule_interface
+        ; FileType = module_target_analysis_registry
         )
     ->
         % If a `.opt' file in another directory doesn't exist,
@@ -666,7 +665,7 @@
     ).
 
 get_file_name(Search, ModuleName - FileType, FileName, !Info, !IO) :-
-    ( FileType = source ->
+    ( FileType = module_target_source ->
         % In some cases the module name won't match the file name
         % (module mdb.parse might be in parse.m or mdb.m), so we need to
         % look up the file name here.
@@ -695,8 +694,8 @@
             )
         ;
             MaybeExt = no,
-            module_target_to_file_name(ModuleName, FileType, no, Search,
-                FileName, !IO)
+            module_target_to_file_name_maybe_search(ModuleName, FileType, no,
+                Search, FileName, !IO)
         )
     ).
 
@@ -793,34 +792,34 @@
 make_target_list(Ks, V) = list.map((func(K) = K - V), Ks).
 
 make_dependency_list(ModuleNames, FileType) =
-    list.map((func(Module) = target(Module - FileType)), ModuleNames).
+    list.map((func(Module) = dep_target(Module - FileType)), ModuleNames).
 
-target_extension(_, source) = yes(".m").
-target_extension(_, errors) = yes(".err").
-target_extension(_, private_interface) = yes(".int0").
-target_extension(_, long_interface) = yes(".int").
-target_extension(_, short_interface) = yes(".int2").
-target_extension(_, unqualified_short_interface) = yes(".int3").
-target_extension(_, intermodule_interface) = yes(".opt").
-target_extension(_, analysis_registry) = yes(".analysis").
-target_extension(_, c_header(mih)) = yes(".mih").
-target_extension(_, c_header(mh)) = yes(".mh").
-target_extension(_, c_code) = yes(".c").
-target_extension(_, il_code) = yes(".il").
+target_extension(_, module_target_source) = yes(".m").
+target_extension(_, module_target_errors) = yes(".err").
+target_extension(_, module_target_private_interface) = yes(".int0").
+target_extension(_, module_target_long_interface) = yes(".int").
+target_extension(_, module_target_short_interface) = yes(".int2").
+target_extension(_, module_target_unqualified_short_interface) = yes(".int3").
+target_extension(_, module_target_intermodule_interface) = yes(".opt").
+target_extension(_, module_target_analysis_registry) = yes(".analysis").
+target_extension(_, module_target_c_header(header_mih)) = yes(".mih").
+target_extension(_, module_target_c_header(header_mh)) = yes(".mh").
+target_extension(_, module_target_c_code) = yes(".c").
+target_extension(_, module_target_il_code) = yes(".il").
 
     % XXX ".exe" if the module contains main.
-target_extension(_, il_asm) = yes(".dll").
-target_extension(_, java_code) = yes(".java").
-target_extension(_, asm_code(non_pic)) = yes(".s").
-target_extension(_, asm_code(link_with_pic)) = yes(".s").
-target_extension(_, asm_code(pic)) = yes(".pic_s").
-target_extension(Globals, object_code(PIC)) = yes(Ext) :-
+target_extension(_, module_target_il_asm) = yes(".dll").
+target_extension(_, module_target_java_code) = yes(".java").
+target_extension(_, module_target_asm_code(non_pic)) = yes(".s").
+target_extension(_, module_target_asm_code(link_with_pic)) = yes(".s").
+target_extension(_, module_target_asm_code(pic)) = yes(".pic_s").
+target_extension(Globals, module_target_object_code(PIC)) = yes(Ext) :-
     maybe_pic_object_file_extension(Globals, PIC, Ext).
 
     % These all need to be handled as special cases.
-target_extension(_, foreign_object(_, _)) = no.
-target_extension(_, foreign_il_asm(_)) = no.
-target_extension(_, fact_table_object(_, _)) = no.
+target_extension(_, module_target_foreign_object(_, _)) = no.
+target_extension(_, module_target_foreign_il_asm(_)) = no.
+target_extension(_, module_target_fact_table_object(_, _)) = no.
 
 linked_target_file_name(ModuleName, executable, FileName) -->
     globals.io_lookup_string_option(executable_file_extension, Ext),
@@ -838,20 +837,22 @@
     bool::in, file_name::out, io::di, io::uo) is det.
 
 module_target_to_file_name(ModuleName, TargetType, MkDir, FileName, !IO) :-
-    module_target_to_file_name(ModuleName, TargetType, MkDir, no,
+    module_target_to_file_name_maybe_search(ModuleName, TargetType, MkDir, no,
         FileName, !IO).
 
 :- pred module_target_to_search_file_name(module_name::in,
     module_target_type::in, file_name::out, io::di, io::uo) is det.
 
 module_target_to_search_file_name(ModuleName, TargetType, FileName, !IO) :-
-    module_target_to_file_name(ModuleName, TargetType, no, yes, FileName, !IO).
+    module_target_to_file_name_maybe_search(ModuleName, TargetType, no, yes,
+        FileName, !IO).
 
-:- pred module_target_to_file_name(module_name::in, module_target_type::in,
-    bool::in, bool::in, file_name::out, io::di, io::uo) is det.
+:- pred module_target_to_file_name_maybe_search(module_name::in,
+    module_target_type::in, bool::in, bool::in, file_name::out,
+    io::di, io::uo) is det.
 
-module_target_to_file_name(ModuleName, TargetType, MkDir, Search, FileName,
-        !IO) :-
+module_target_to_file_name_maybe_search(ModuleName, TargetType, MkDir, Search,
+        FileName, !IO) :-
     globals.io_get_globals(Globals, !IO),
     target_extension(Globals, TargetType) = MaybeExt,
     (
@@ -865,27 +866,28 @@
         )
     ;
         MaybeExt = no,
-        ( TargetType = foreign_object(PIC, Lang) ->
+        ( TargetType = module_target_foreign_object(PIC, Lang) ->
             (
                 ForeignModuleName =
                     foreign_language_module_name(ModuleName, Lang)
             ->
-                module_target_to_file_name(ForeignModuleName, object_code(PIC),
-                    MkDir, Search, FileName, !IO)
+                module_target_to_file_name_maybe_search(ForeignModuleName,
+                    module_target_object_code(PIC), MkDir, Search, FileName,
+                    !IO)
             ;
                 unexpected(this_file, "module_target_to_file_name_2")
             )
-        ; TargetType = foreign_il_asm(Lang) ->
+        ; TargetType = module_target_foreign_il_asm(Lang) ->
             (
                 ForeignModuleName =
                     foreign_language_module_name(ModuleName, Lang)
             ->
-                module_target_to_file_name(ForeignModuleName, il_asm, MkDir,
-                    Search, FileName, !IO)
+                module_target_to_file_name_maybe_search(ForeignModuleName,
+                    module_target_il_asm, MkDir, Search, FileName, !IO)
             ;
                 unexpected(this_file, "module_target_to_file_name_2")
             )
-        ; TargetType = fact_table_object(PIC, FactFile) ->
+        ; TargetType = module_target_fact_table_object(PIC, FactFile) ->
             maybe_pic_object_file_extension(PIC, Ext, !IO),
             fact_table_file_name(ModuleName, FactFile, Ext, MkDir, FileName,
                 !IO)
@@ -902,70 +904,82 @@
     % can be modified in the process of analysing _another_ module.
     % The timestamp is only updated after actually analysing the module that
     % the `.analysis' file corresponds to.
-timestamp_extension(_, errors) = ".err_date".
-timestamp_extension(_, private_interface) = ".date0".
-timestamp_extension(_, long_interface) = ".date".
-timestamp_extension(_, short_interface) = ".date".
-timestamp_extension(_, unqualified_short_interface) = ".date3".
-timestamp_extension(_, intermodule_interface) = ".optdate".
-timestamp_extension(_, analysis_registry) = ".analysis_date".
-timestamp_extension(_, c_code) = ".c_date".
-timestamp_extension(Globals, c_header(_)) = Ext :-
+timestamp_extension(_, module_target_errors) = ".err_date".
+timestamp_extension(_, module_target_private_interface) = ".date0".
+timestamp_extension(_, module_target_long_interface) = ".date".
+timestamp_extension(_, module_target_short_interface) = ".date".
+timestamp_extension(_, module_target_unqualified_short_interface) = ".date3".
+timestamp_extension(_, module_target_intermodule_interface) = ".optdate".
+timestamp_extension(_, module_target_analysis_registry) = ".analysis_date".
+timestamp_extension(_, module_target_c_code) = ".c_date".
+timestamp_extension(Globals, module_target_c_header(_)) = Ext :-
     globals.get_target(Globals, Target),
     Ext = timestamp_extension(Globals,
-        (Target = target_asm -> asm_code(non_pic) ; c_code)).
-timestamp_extension(_, il_code) = ".il_date".
-timestamp_extension(_, java_code) = ".java_date".
-timestamp_extension(_, asm_code(non_pic)) = ".s_date".
-timestamp_extension(_, asm_code(pic)) = ".pic_s_date".
+        (Target = target_asm ->
+            module_target_asm_code(non_pic) ; module_target_c_code)).
+timestamp_extension(_, module_target_il_code) = ".il_date".
+timestamp_extension(_, module_target_java_code) = ".java_date".
+timestamp_extension(_, module_target_asm_code(non_pic)) = ".s_date".
+timestamp_extension(_, module_target_asm_code(pic)) = ".pic_s_date".
 
 :- func search_for_file_type(module_target_type) = maybe(option).
 
-search_for_file_type(source) = no.
-search_for_file_type(errors) = no.
+search_for_file_type(module_target_source) = no.
+search_for_file_type(module_target_errors) = no.
     % XXX only for inter-module optimization.
-search_for_file_type(private_interface) = yes(search_directories).
-search_for_file_type(long_interface) = yes(search_directories).
-search_for_file_type(short_interface) = yes(search_directories).
-search_for_file_type(unqualified_short_interface) = yes(search_directories).
-search_for_file_type(intermodule_interface) = yes(intermod_directories).
-search_for_file_type(analysis_registry) = yes(intermod_directories).
-search_for_file_type(c_header(_)) = yes(c_include_directory).
-search_for_file_type(c_code) = no.
-search_for_file_type(il_code) = no.
-search_for_file_type(il_asm) = no.
-search_for_file_type(java_code) = no.
-search_for_file_type(asm_code(_)) = no.
-search_for_file_type(object_code(_)) = no.
-search_for_file_type(foreign_object(_, _)) = no.
-search_for_file_type(foreign_il_asm(_)) = no.
-search_for_file_type(fact_table_object(_, _)) = no.
+search_for_file_type(module_target_private_interface) =
+        yes(search_directories).
+search_for_file_type(module_target_long_interface) = yes(search_directories).
+search_for_file_type(module_target_short_interface) = yes(search_directories).
+search_for_file_type(module_target_unqualified_short_interface) =
+        yes(search_directories).
+search_for_file_type(module_target_intermodule_interface) =
+        yes(intermod_directories).
+search_for_file_type(module_target_analysis_registry) =
+        yes(intermod_directories).
+search_for_file_type(module_target_c_header(_)) = yes(c_include_directory).
+search_for_file_type(module_target_c_code) = no.
+search_for_file_type(module_target_il_code) = no.
+search_for_file_type(module_target_il_asm) = no.
+search_for_file_type(module_target_java_code) = no.
+search_for_file_type(module_target_asm_code(_)) = no.
+search_for_file_type(module_target_object_code(_)) = no.
+search_for_file_type(module_target_foreign_object(_, _)) = no.
+search_for_file_type(module_target_foreign_il_asm(_)) = no.
+search_for_file_type(module_target_fact_table_object(_, _)) = no.
 
 target_is_grade_or_arch_dependent(Target) :-
-    target_is_grade_or_arch_dependent(Target, yes).
+    is_target_grade_or_arch_dependent(Target) = yes.
 
-:- pred target_is_grade_or_arch_dependent(module_target_type::in,
-    bool::out) is det.
+:- func is_target_grade_or_arch_dependent(module_target_type) = bool.
 
-target_is_grade_or_arch_dependent(source, no).
-target_is_grade_or_arch_dependent(errors, no).
-target_is_grade_or_arch_dependent(private_interface, no).
-target_is_grade_or_arch_dependent(long_interface, no).
-target_is_grade_or_arch_dependent(short_interface, no).
-target_is_grade_or_arch_dependent(unqualified_short_interface, no).
-target_is_grade_or_arch_dependent(intermodule_interface, yes).
-target_is_grade_or_arch_dependent(analysis_registry, yes).
-target_is_grade_or_arch_dependent(c_header(mh), no).
-target_is_grade_or_arch_dependent(c_header(mih), yes).
-target_is_grade_or_arch_dependent(c_code, yes).
-target_is_grade_or_arch_dependent(il_code, yes).
-target_is_grade_or_arch_dependent(il_asm, yes).
-target_is_grade_or_arch_dependent(java_code, yes).
-target_is_grade_or_arch_dependent(asm_code(_), yes).
-target_is_grade_or_arch_dependent(object_code(_), yes).
-target_is_grade_or_arch_dependent(foreign_object(_, _), yes).
-target_is_grade_or_arch_dependent(foreign_il_asm(_), yes).
-target_is_grade_or_arch_dependent(fact_table_object(_, _), yes).
+is_target_grade_or_arch_dependent(Target) = IsDependent :-
+    (
+        ( Target = module_target_source
+        ; Target = module_target_errors
+        ; Target = module_target_private_interface
+        ; Target = module_target_long_interface
+        ; Target = module_target_short_interface
+        ; Target = module_target_unqualified_short_interface
+        ; Target = module_target_c_header(header_mh)
+        ),
+        IsDependent = no
+    ;
+        ( Target = module_target_intermodule_interface
+        ; Target = module_target_analysis_registry
+        ; Target = module_target_c_header(header_mih)
+        ; Target = module_target_c_code
+        ; Target = module_target_il_code
+        ; Target = module_target_il_asm
+        ; Target = module_target_java_code
+        ; Target = module_target_asm_code(_)
+        ; Target = module_target_object_code(_)
+        ; Target = module_target_foreign_object(_, _)
+        ; Target = module_target_foreign_il_asm(_)
+        ; Target = module_target_fact_table_object(_, _)
+        ),
+        IsDependent = yes
+    ).
 
 %-----------------------------------------------------------------------------%
 
@@ -998,9 +1012,9 @@
             io.nl
         ), !IO).
 
-write_dependency_file(target(TargetFile), !IO) :-
+write_dependency_file(dep_target(TargetFile), !IO) :-
     write_target_file(TargetFile, !IO).
-write_dependency_file(file(FileName, _), !IO) :-
+write_dependency_file(dep_file(FileName, _), !IO) :-
     io.write_string(FileName, !IO).
 
 write_target_file(ModuleName - FileType, !IO) :-
@@ -1017,9 +1031,9 @@
 
 maybe_make_target_message(TargetFile, !IO) :-
     io.output_stream(OutputStream, !IO),
-    maybe_make_target_message(OutputStream, TargetFile, !IO).
+    maybe_make_target_message_to_stream(OutputStream, TargetFile, !IO).
 
-maybe_make_target_message(OutputStream, TargetFile, !IO) :-
+maybe_make_target_message_to_stream(OutputStream, TargetFile, !IO) :-
     verbose_msg(
         (pred(di, uo) is det -->
             io.set_output_stream(OutputStream, OldOutputStream),
Index: compiler/mercury_compile.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/mercury_compile.m,v
retrieving revision 1.409
diff -u -r1.409 mercury_compile.m
--- compiler/mercury_compile.m	13 Oct 2006 04:52:20 -0000	1.409
+++ compiler/mercury_compile.m	13 Oct 2006 11:02:50 -0000
@@ -807,7 +807,8 @@
     globals.io_lookup_bool_option(invoked_by_mmc_make, InvokedByMake, !IO),
     (
         InvokedByMake = no,
-        build_with_module_options(file_or_module_to_module_name(FileOrModule),
+        build_with_module_options_args(
+            file_or_module_to_module_name(FileOrModule),
             OptionVariables, OptionArgs, [],
             process_arg_build(FileOrModule, OptionVariables, OptionArgs),
             _, [], MaybePair, !IO),
@@ -1285,11 +1286,13 @@
         Compile(Succeeded, !IO)
     ;
         InvokedByMake = no,
-        build_with_module_options(ModuleName, OptionVariables, OptionArgs, [],
-            (pred(_::in, Succeeded0::out, X::in, X::out,
-                    IO0::di, IO::uo) is det :-
+        Builder =
+            (pred(_::in, Succeeded0::out, X::in, X::out, IO0::di, IO::uo)
+                    is det :-
                 Compile(Succeeded0, IO0, IO)
-            ), Succeeded, unit, _, !IO)
+            ),
+        build_with_module_options_args(ModuleName, OptionVariables, OptionArgs,
+            [], Builder, Succeeded, unit, _, !IO)
     ).
 
 %-----------------------------------------------------------------------------%
@@ -2594,7 +2597,7 @@
     maybe_goal_paths(Verbose, Stats, !HLDS, !IO),
     maybe_dump_hlds(!.HLDS, 345, "precodegen", !DumpInfo, !IO),
 
-    generate_code(!.HLDS, Verbose, Stats, !GlobalData, LLDS1, !IO),
+    generate_code_for_module(!.HLDS, Verbose, Stats, !GlobalData, LLDS1, !IO),
 
     maybe_generate_stack_layouts(!.HLDS, LLDS1, Verbose, Stats, !GlobalData,
         !IO),
@@ -4111,14 +4114,14 @@
         true
     ).
 
-:- pred generate_code(module_info::in, bool::in, bool::in,
+:- pred generate_code_for_module(module_info::in, bool::in, bool::in,
     global_data::in, global_data::out, list(c_procedure)::out,
     io::di, io::uo) is det.
 
-generate_code(HLDS, Verbose, Stats, !GlobalData, LLDS, !IO) :-
+generate_code_for_module(HLDS, Verbose, Stats, !GlobalData, LLDS, !IO) :-
     maybe_write_string(Verbose, "% Generating code...\n", !IO),
     maybe_flush_output(Verbose, !IO),
-    generate_code(HLDS, !GlobalData, LLDS, !IO),
+    generate_module_code(HLDS, !GlobalData, LLDS, !IO),
     maybe_write_string(Verbose, "% done.\n", !IO),
     maybe_report_stats(Stats, !IO).
 
Index: compiler/middle_rec.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/middle_rec.m,v
retrieving revision 1.123
diff -u -r1.123 middle_rec.m
--- compiler/middle_rec.m	26 Sep 2006 03:53:17 -0000	1.123
+++ compiler/middle_rec.m	13 Oct 2006 10:04:21 -0000
@@ -235,8 +235,7 @@
     code_info.get_module_info(!.CI, ModuleInfo),
     code_info.get_pred_id(!.CI, PredId),
     code_info.get_proc_id(!.CI, ProcId),
-    code_util.make_local_entry_label(ModuleInfo, PredId, ProcId, no,
-        EntryLabel),
+    EntryLabel = make_local_entry_label(ModuleInfo, PredId, ProcId, no),
 
     code_info.pre_goal_update(SwitchGoalInfo, no, !CI),
     unify_gen.generate_tag_test(Var, BaseConsId, branch_on_success,
@@ -303,7 +302,7 @@
                 - "decrement loop counter"],
         TestAuxReg = [
             if_val(binop(int_gt, lval(AuxReg), const(llconst_int(0))),
-                label(Loop2Label))
+                code_label(Loop2Label))
                 - "test on upward loop"]
     ;
         PushMsg = proc_gen.push_msg(ModuleInfo, PredId, ProcId),
@@ -314,7 +313,8 @@
         IncrAuxReg = [],
         DecrAuxReg = [],
         TestAuxReg = [
-            if_val(binop(int_gt, lval(sp), lval(AuxReg)), label(Loop2Label))
+            if_val(binop(int_gt, lval(sp), lval(AuxReg)),
+                code_label(Loop2Label))
                 - "test on upward loop"]
     ),
 
@@ -342,7 +342,7 @@
             BaseList,
             LiveValCode,
             [
-                goto(succip) - "exit from base case"
+                goto(code_succip) - "exit from base case"
             ]
         ], InstrList)
     ;
@@ -378,13 +378,13 @@
             TestAuxReg,
             LiveValCode,
             [
-                goto(succip) - "exit from recursive case",
+                goto(code_succip) - "exit from recursive case",
                 label(BaseLabel) - "start of base case"
             ],
             BaseList,
             LiveValCode,
             [
-                goto(succip) - "exit from base case"
+                goto(code_succip) - "exit from base case"
             ]
         ], InstrList)
     ),
@@ -409,7 +409,8 @@
                 "if_val followed by other instructions")
         ),
         code_util.neg_rval(Test, NewTest),
-        Instrs = [if_val(NewTest, label(Target)) - "test on downward loop"]
+        Instrs = [if_val(NewTest, code_label(Target))
+            - "test on downward loop"]
     ;
         generate_downloop_test(Instrs0, Target, Instrs1),
         Instrs = [Instr0 | Instrs1]
Index: compiler/ml_simplify_switch.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/ml_simplify_switch.m,v
retrieving revision 1.20
diff -u -r1.20 ml_simplify_switch.m
--- compiler/ml_simplify_switch.m	22 Aug 2006 05:03:55 -0000	1.20
+++ compiler/ml_simplify_switch.m	13 Oct 2006 10:48:30 -0000
@@ -37,6 +37,7 @@
 :- implementation.
 
 :- import_module backend_libs.builtin_ops.
+:- import_module backend_libs.switch_util.
 :- import_module libs.compiler_util.
 :- import_module libs.globals.
 :- import_module libs.options.
@@ -133,7 +134,7 @@
     % The switch needs to be dense enough.
     find_first_and_last_case(Cases, FirstCaseVal, LastCaseVal),
     CasesRange = LastCaseVal - FirstCaseVal + 1,
-    Density = calc_density(NumCases, CasesRange),
+    Density = switch_density(NumCases, CasesRange),
     Density > ReqDensity.
 
     % For switches with a default, we normally need to check that
@@ -153,7 +154,7 @@
         Range = range(Min, Max),
         TypeRange = Max - Min + 1,
         NumCases = list.length(Cases),
-        NoDefaultDensity = calc_density(NumCases, TypeRange),
+        NoDefaultDensity = switch_density(NumCases, TypeRange),
         NoDefaultDensity > ReqDensity
     ->
         NeedRangeCheck = no,
@@ -170,13 +171,6 @@
         LastVal = LastCaseVal
     ).
 
-    % Calculate the percentage density given the range and the number of cases.
-    %
-:- func calc_density(int, int) = int.
-
-calc_density(NumCases, Range) = Density :-
-    Density = (NumCases * 100) // Range.
-
 %-----------------------------------------------------------------------------%
 
     % Find the highest and lowest case values in a list of cases.
Index: compiler/opt_debug.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/opt_debug.m,v
retrieving revision 1.178
diff -u -r1.178 opt_debug.m
--- compiler/opt_debug.m	29 Sep 2006 06:34:50 -0000	1.178
+++ compiler/opt_debug.m	13 Oct 2006 10:56:46 -0000
@@ -448,7 +448,7 @@
     Str = "tc_instance(" ++ TypesStr ++ ")".
 
 dump_layout_name(label_layout(ProcLabel, LabelNum, LabelVars)) = Str :-
-    LabelStr = dump_label(internal(LabelNum, ProcLabel)),
+    LabelStr = dump_label(internal_label(LabelNum, ProcLabel)),
     (
         LabelVars = label_has_var_info,
         LabelVarsStr = "label_has_var_info"
@@ -458,10 +458,10 @@
     ),
     Str = "label_layout(" ++ LabelStr ++ ", " ++ LabelVarsStr ++ ")".
 dump_layout_name(solver_event_layout(ProcLabel, LabelNum)) = Str :-
-    LabelStr = dump_label(internal(LabelNum, ProcLabel)),
+    LabelStr = dump_label(internal_label(LabelNum, ProcLabel)),
     Str = "solver_event_layout(" ++ LabelStr ++ ")".
 dump_layout_name(solver_event_attr_names(ProcLabel, LabelNum)) = Str :-
-    LabelStr = dump_label(internal(LabelNum, ProcLabel)),
+    LabelStr = dump_label(internal_label(LabelNum, ProcLabel)),
     Str = "solver_event_attr_names(" ++ LabelStr ++ ")".
 dump_layout_name(proc_layout(RttiProcLabel, _)) =
     "proc_layout(" ++ dump_rttiproclabel(RttiProcLabel) ++ ")".
@@ -531,9 +531,9 @@
         Str = "truncated"
     ).
 
-dump_code_addr(label(Label)) = dump_label(Label).
-dump_code_addr(imported(ProcLabel)) = dump_proclabel(ProcLabel).
-dump_code_addr(succip) = "succip".
+dump_code_addr(code_label(Label)) = dump_label(Label).
+dump_code_addr(code_imported_proc(ProcLabel)) = dump_proclabel(ProcLabel).
+dump_code_addr(code_succip) = "succip".
 dump_code_addr(do_succeed(Last)) = Str :-
     (
         Last = no,
@@ -554,7 +554,7 @@
 dump_code_addr(do_not_reached) = "do_not_reached".
 
 dump_code_addr_for_proc(ProcLabel, CodeAddr) =
-    ( CodeAddr = label(Label) ->
+    ( CodeAddr = code_label(Label) ->
         dump_label_for_proc(ProcLabel, Label)
     ;
         dump_code_addr(CodeAddr)
@@ -569,19 +569,19 @@
     " " ++ dump_code_addr_for_proc(ProcLabel, Addr) ++
         dump_code_addrs_for_proc(ProcLabel, Addrs).
 
-dump_label(internal(N, ProcLabel)) =
+dump_label(internal_label(N, ProcLabel)) =
     dump_proclabel(ProcLabel) ++ "_i" ++ int_to_string(N).
-dump_label(entry(_, ProcLabel)) =
+dump_label(entry_label(_, ProcLabel)) =
     dump_proclabel(ProcLabel).
 
-dump_label_for_proc(CurProcLabel, internal(N, ProcLabel)) = Str :-
+dump_label_for_proc(CurProcLabel, internal_label(N, ProcLabel)) = Str :-
     string.int_to_string(N, N_str),
     ( CurProcLabel = ProcLabel ->
         Str = "local_" ++ N_str
     ;
         Str = dump_proclabel(ProcLabel) ++ "_" ++ N_str
     ).
-dump_label_for_proc(CurProcLabel, entry(_, ProcLabel)) = Str :-
+dump_label_for_proc(CurProcLabel, entry_label(_, ProcLabel)) = Str :-
     ( CurProcLabel = ProcLabel ->
         Str = "CUR_PROC_ENTRY"
     ;
@@ -803,8 +803,8 @@
             ++ dump_maybe_label_for_proc("fix layout:", ProcLabel, MFL)
             ++ dump_maybe_label_for_proc("fix onlylayout:", ProcLabel, MFOL)
             ++ dump_maybe_label_for_proc("nofix:", ProcLabel, MNF)
-            ++ dump_bool("stack slot ref:", SSR)
-            ++ dump_bool("may duplicate:", MD)
+            ++ dump_bool_msg("stack slot ref:", SSR)
+            ++ dump_bool_msg("may duplicate:", MD)
             ++ ")"
     ).
 
@@ -819,10 +819,10 @@
 dump_maybe_label_for_proc(Msg, ProcLabel, yes(Label)) =
     Msg ++ " " ++ dump_label_for_proc(ProcLabel, Label) ++ "\n".
 
-:- func dump_bool(string, bool) = string.
+:- func dump_bool_msg(string, bool) = string.
 
-dump_bool(Msg, no)  = Msg ++ " no\n".
-dump_bool(Msg, yes) = Msg ++ " yes\n".
+dump_bool_msg(Msg, no)  = Msg ++ " no\n".
+dump_bool_msg(Msg, yes) = Msg ++ " yes\n".
 
 :- func dump_may_use_atomic(may_use_atomic_alloc) = string.
 
Index: compiler/opt_util.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/opt_util.m,v
retrieving revision 1.154
diff -u -r1.154 opt_util.m
--- compiler/opt_util.m	26 Sep 2006 03:53:18 -0000	1.154
+++ compiler/opt_util.m	13 Oct 2006 09:25:45 -0000
@@ -493,7 +493,7 @@
     Instr5 = livevals(_) - _,
     skip_comments_labels(Instrs6, Instrs7),
     Instrs7 = [Instr7 | _],
-    Instr7 = goto(succip) - _,
+    Instr7 = goto(code_succip) - _,
     InstrsBetween = [Instr1use, Instr3use, Instr5].
 
 is_sdproceed_next(Instrs0, InstrsBetween) :-
@@ -531,7 +531,7 @@
     Instr7 = livevals(_) - _,
     skip_comments_labels(Instrs8, Instrs9),
     Instrs9 = [Instr9 | _],
-    Instr9 = goto(succip) - _,
+    Instr9 = goto(code_succip) - _,
     InstrsBetween = [Instr1use, Instr3use, Instr5, Instr7].
 
 is_succeed_next(Instrs0, InstrsBetweenIncl) :-
@@ -548,7 +548,7 @@
     Instrs1 = [Instr1 | Instrs2],
     Instr1 = Uinstr1 - _,
     (
-        Uinstr1 = if_val(lval(reg(reg_r, 1)), label(JumpLabel))
+        Uinstr1 = if_val(lval(reg(reg_r, 1)), code_label(JumpLabel))
     ->
         map.search(Sdprocmap, JumpLabel, BetweenJump),
         is_sdproceed_next(Instrs2, BetweenFall),
@@ -558,7 +558,7 @@
         filter_out_livevals(BetweenFalse0, Between)
     ;
         Uinstr1 = if_val(unop(logical_not, lval(reg(reg_r, 1))),
-            label(JumpLabel))
+            code_label(JumpLabel))
     ->
         map.search(Sdprocmap, JumpLabel, BetweenJump),
         is_sdproceed_next(Instrs2, BetweenFall),
@@ -705,9 +705,9 @@
 
 :- func code_addr_refers_to_stack(code_addr) = bool.
 
-code_addr_refers_to_stack(label(_)) = no.
-code_addr_refers_to_stack(imported(_)) = no.
-code_addr_refers_to_stack(succip) = no.
+code_addr_refers_to_stack(code_label(_)) = no.
+code_addr_refers_to_stack(code_imported_proc(_)) = no.
+code_addr_refers_to_stack(code_succip) = no.
 code_addr_refers_to_stack(do_succeed(_)) = yes.
 code_addr_refers_to_stack(do_redo) = yes.
 code_addr_refers_to_stack(do_fail) = yes.
@@ -1146,7 +1146,7 @@
 
 find_label_code_addrs([], Labels, Labels).
 find_label_code_addrs([CodeAddr | Rest], Labels0, Labels) :-
-    ( CodeAddr = label(Label) ->
+    ( CodeAddr = code_label(Label) ->
         Labels1 = [Label | Labels0]
     ;
         Labels1 = Labels0
@@ -1207,7 +1207,7 @@
     unexpected(this_file, "block in possible_targets").
 possible_targets(assign(_, _), [], []).
 possible_targets(llcall(_, Return, _, _, _, _), Labels, CodeAddrs) :-
-    ( Return = label(ReturnLabel) ->
+    ( Return = code_label(ReturnLabel) ->
         Labels = [ReturnLabel],
         CodeAddrs = []
     ;
@@ -1217,7 +1217,7 @@
 possible_targets(mkframe(_, _), [], []).
 possible_targets(label(_), [], []).
 possible_targets(goto(CodeAddr), Labels, CodeAddrs) :-
-    ( CodeAddr = label(Label) ->
+    ( CodeAddr = code_label(Label) ->
         Labels = [Label],
         CodeAddrs = []
     ;
@@ -1227,7 +1227,7 @@
 possible_targets(computed_goto(_, Labels), Labels, []).
 possible_targets(arbitrary_c_code(_, _), [], []).
 possible_targets(if_val(_, CodeAddr), Labels, CodeAddrs) :-
-    ( CodeAddr = label(Label) ->
+    ( CodeAddr = code_label(Label) ->
         Labels = [Label],
         CodeAddrs = []
     ;
@@ -1401,16 +1401,16 @@
     list.append(Labels0, Labels1, Labels),
     list.append(CodeAddrs0, CodeAddrs1, CodeAddrs).
 
-livevals_addr(label(Label), Result) :-
+livevals_addr(code_label(Label), Result) :-
     (
-        Label = internal(_, _),
+        Label = internal_label(_, _),
         Result = no
     ;
-        Label = entry(_, _),
+        Label = entry_label(_, _),
         Result = yes
     ).
-livevals_addr(imported(_), yes).
-livevals_addr(succip, yes).
+livevals_addr(code_imported_proc(_), yes).
+livevals_addr(code_succip, yes).
 livevals_addr(do_succeed(_), yes).
 livevals_addr(do_redo, no).
 livevals_addr(do_fail, no).
@@ -1499,8 +1499,8 @@
 % that uses a temp var without defining it.
 count_temps_rval(_, !R, !F).
 
-format_label(internal(_, ProcLabel)) = format_proc_label(ProcLabel).
-format_label(entry(_, ProcLabel)) = format_proc_label(ProcLabel).
+format_label(internal_label(_, ProcLabel)) = format_proc_label(ProcLabel).
+format_label(entry_label(_, ProcLabel)) = format_proc_label(ProcLabel).
 
 format_proc_label(ordinary_proc_label(_Module, _PredOrFunc, _, Name,
         Arity, Mode)) =
@@ -2102,10 +2102,11 @@
 replace_labels_rval_const(llconst_data_addr(DataAddr, MaybeOffset), _,
         llconst_data_addr(DataAddr, MaybeOffset)).
 
-replace_labels_code_addr(label(Label0), ReplMap, label(Label)) :-
+replace_labels_code_addr(code_label(Label0), ReplMap, code_label(Label)) :-
     replace_labels_label(Label0, ReplMap, Label).
-replace_labels_code_addr(imported(Proc), _, imported(Proc)).
-replace_labels_code_addr(succip, _, succip).
+replace_labels_code_addr(code_imported_proc(Proc), _,
+        code_imported_proc(Proc)).
+replace_labels_code_addr(code_succip, _, code_succip).
 replace_labels_code_addr(do_succeed(Last), _, do_succeed(Last)).
 replace_labels_code_addr(do_redo, _, do_redo).
 replace_labels_code_addr(do_fail, _, do_fail).
Index: compiler/optimize.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/optimize.m,v
retrieving revision 1.57
diff -u -r1.57 optimize.m
--- compiler/optimize.m	27 Jul 2006 05:01:17 -0000	1.57
+++ compiler/optimize.m	13 Oct 2006 11:05:42 -0000
@@ -88,7 +88,8 @@
         ->
             LabelMap = ProcLayout ^ internal_map,
             map.sorted_keys(LabelMap, LayoutLabelNums),
-            LayoutLabels = list.map(make_internal_label(ProcLabel),
+            LayoutLabels = list.map(
+                make_internal_label_for_proc_label(ProcLabel),
                 LayoutLabelNums),
             set.sorted_list_to_set(LayoutLabels, LayoutLabelSet)
         ;
@@ -106,9 +107,10 @@
             ProcLabel, !.C, MayAlterRtti, CGlobalVars)
     ).
 
-:- func make_internal_label(proc_label, int) = label.
+:- func make_internal_label_for_proc_label(proc_label, int) = label.
 
-make_internal_label(ProcLabel, LabelNum) = internal(LabelNum, ProcLabel).
+make_internal_label_for_proc_label(ProcLabel, LabelNum)
+    = internal_label(LabelNum, ProcLabel).
 
 %-----------------------------------------------------------------------------%
 
Index: compiler/options_file.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/options_file.m,v
retrieving revision 1.37
diff -u -r1.37 options_file.m
--- compiler/options_file.m	2 Oct 2006 05:21:19 -0000	1.37
+++ compiler/options_file.m	13 Oct 2006 12:46:39 -0000
@@ -125,19 +125,20 @@
         !IO),
     (
         MaybeVariables = yes(Variables),
-        % Ignore settings in the environment -- the parent
-        % mmc process will have included those in the file.
-        lookup_variable_words(no, Variables, "MCFLAGS", FlagsResult, !IO),
+        % Ignore settings in the environment -- the parent mmc process
+        % will have included those in the file.
+        lookup_variable_words_maybe_env(no, Variables, "MCFLAGS", FlagsResult,
+            !IO),
         (
-            FlagsResult = set(MCFlags),
+            FlagsResult = var_result_set(MCFlags),
             MaybeMCFlags = yes(MCFlags)
         ;
-            FlagsResult = unset,
+            FlagsResult = var_result_unset,
             io.write_string("mercury_compile: internal error: " ++
                 "arguments file does not set MCFLAGS.\n", !IO),
             MaybeMCFlags = no
         ;
-            FlagsResult = error(Msg),
+            FlagsResult = var_result_error(Msg),
             MaybeMCFlags = no,
             io.write_string(Msg, !IO),
             io.nl(!IO)
@@ -779,8 +780,7 @@
         RevWord = RevWord0
     ; Char = '"' ->
         parse_string_chars([], RevStringChars, Chars0, Chars1),
-        get_word_2(RevStringChars ++ RevWord0, RevWord,
-            Chars1, Chars)
+        get_word_2(RevStringChars ++ RevWord0, RevWord, Chars1, Chars)
     ; Char = ('\\') ->
         (
             Chars0 = [],
@@ -808,13 +808,13 @@
     lookup_variable_words_report_error(Vars, "MAIN_TARGET", MainTargetResult,
         !IO),
     (
-        MainTargetResult = set(MainTarget),
+        MainTargetResult = var_result_set(MainTarget),
         MaybeMainTarget = yes(MainTarget)
     ;
-        MainTargetResult = unset,
+        MainTargetResult = var_result_unset,
         MaybeMainTarget = yes([])
     ;
-        MainTargetResult = error(_),
+        MainTargetResult = var_result_error(_),
         MaybeMainTarget = no
     ).
 
@@ -840,10 +840,10 @@
         list.map(
             (pred(VarResult::in, MaybeValue::out) is semidet :-
                 (
-                    VarResult = set(Value),
+                    VarResult = var_result_set(Value),
                     MaybeValue = yes(Value)
                 ;
-                    VarResult = unset,
+                    VarResult = var_result_unset,
                     MaybeValue = no
                 )
             ), Results, Values)
@@ -953,12 +953,13 @@
 
 convert_to_mmc_options(_ - no) = [].
 convert_to_mmc_options(VariableType - yes(VariableValue)) =
-    convert_to_mmc_options(VariableType, VariableValue).
+    convert_to_mmc_options_with_value(VariableType, VariableValue).
 
-:- func convert_to_mmc_options(options_variable_type, list(string))
+:- func convert_to_mmc_options_with_value(options_variable_type, list(string))
     = list(string).
 
-convert_to_mmc_options(VariableType, VariableValue) = OptionsStrings :-
+convert_to_mmc_options_with_value(VariableType, VariableValue)
+        = OptionsStrings :-
     MMCOptionType = mmc_option_type(VariableType),
     (
         MMCOptionType = mmc_flags,
@@ -1009,9 +1010,9 @@
 %-----------------------------------------------------------------------------%
 
 :- type variable_result(T)
-    --->    set(T)
-    ;       unset
-    ;       error(string).
+    --->    var_result_set(T)
+    ;       var_result_unset
+    ;       var_result_error(string).
 
 :- pred lookup_options_variable(options_variables::in,
     options_variable_class::in, options_variable_type::in,
@@ -1023,8 +1024,8 @@
     lookup_variable_words_report_error(Vars, "DEFAULT_" ++ VarName,
         DefaultFlagsResult, !IO),
     ( OptionsVariableClass = default ->
-        FlagsResult = unset,
-        ExtraFlagsResult = unset
+        FlagsResult = var_result_unset,
+        ExtraFlagsResult = var_result_unset
     ;
         lookup_variable_words_report_error(Vars, VarName, FlagsResult, !IO),
         lookup_variable_words_report_error(Vars, "EXTRA_" ++ VarName,
@@ -1039,21 +1040,25 @@
         lookup_variable_words_report_error(Vars, ModuleVarName,
             ModuleFlagsResult, !IO)
     ;
-        ModuleFlagsResult = unset
+        ModuleFlagsResult = var_result_unset
     ),
-    Result = DefaultFlagsResult ++ FlagsResult ++ ExtraFlagsResult
-        ++ ModuleFlagsResult.
-
-:- func variable_result(list(T)) ++ variable_result(list(T)) =
-    variable_result(list(T)).
-
-unset ++ unset = unset.
-unset ++ set(V) = set(V).
-unset ++ error(E) = error(E).
-set(V1) ++ set(V2) = set(V1 ++ V2).
-set(V) ++ unset = set(V).
-set(_) ++ error(E) = error(E).
-error(E) ++ _ = error(E).
+    Result = list.foldl(combine_var_results,
+        [DefaultFlagsResult, FlagsResult, ExtraFlagsResult, ModuleFlagsResult],
+        var_result_unset).
+
+:- func combine_var_results(variable_result(list(T)), variable_result(list(T)))
+    = variable_result(list(T)).
+
+combine_var_results(var_result_unset, var_result_unset) = var_result_unset.
+combine_var_results(var_result_unset, var_result_set(V)) = var_result_set(V).
+combine_var_results(var_result_unset, var_result_error(E)) =
+    var_result_error(E).
+combine_var_results(var_result_set(V1), var_result_set(V2)) =
+    var_result_set(V1 ++ V2).
+combine_var_results(var_result_set(V), var_result_unset) = var_result_set(V).
+combine_var_results(var_result_set(_), var_result_error(E)) =
+    var_result_error(E).
+combine_var_results(var_result_error(E), _) = var_result_error(E).
 
 :- pred lookup_variable_words_report_error(options_variables::in,
     options_variable::in, variable_result(list(string))::out,
@@ -1061,7 +1066,7 @@
 
 lookup_variable_words_report_error(Vars, VarName, Result, !IO) :-
     lookup_variable_words(Vars, VarName, Result, !IO),
-    ( Result = error(Error) ->
+    ( Result = var_result_error(Error) ->
         io.write_string(Error, !IO),
         io.nl(!IO)
     ;
@@ -1071,14 +1076,14 @@
 :- pred lookup_variable_words(options_variables::in, options_variable::in,
     variable_result(list(string))::out, io::di, io::uo) is det.
 
-lookup_variable_words(Vars, VarName, Result) -->
-    lookup_variable_words(yes, Vars, VarName, Result).
+lookup_variable_words(Vars, VarName, Result, !IO) :-
+    lookup_variable_words_maybe_env(yes, Vars, VarName, Result, !IO).
 
-:- pred lookup_variable_words(bool::in, options_variables::in,
+:- pred lookup_variable_words_maybe_env(bool::in, options_variables::in,
     options_variable::in, variable_result(list(string))::out,
     io::di, io::uo) is det.
 
-lookup_variable_words(LookupEnv, Vars, VarName, Result, !IO) :-
+lookup_variable_words_maybe_env(LookupEnv, Vars, VarName, Result, !IO) :-
     (
         LookupEnv = yes,
         io.get_environment_var(VarName, MaybeEnvValue, !IO)
@@ -1086,21 +1091,25 @@
         LookupEnv = no,
         MaybeEnvValue = no
     ),
-    ( MaybeEnvValue = yes(EnvValue) ->
+    (
+        MaybeEnvValue = yes(EnvValue),
         SplitResult = checked_split_into_words(string.to_char_list(EnvValue)),
         (
             SplitResult = ok(EnvWords),
-            Result = set(EnvWords)
+            Result = var_result_set(EnvWords)
         ;
             SplitResult = error(Msg),
-            Result = error("Error: in environment variable `"
+            Result = var_result_error("Error: in environment variable `"
                 ++ VarName ++ "': " ++ Msg)
         )
-    ; map.search(Vars, VarName, MapValue) ->
-        MapValue = options_variable_value(_, Words, _),
-        Result = set(Words)
     ;
-        Result = unset
+        MaybeEnvValue = no,
+        ( map.search(Vars, VarName, MapValue) ->
+            MapValue = options_variable_value(_, Words, _),
+            Result = var_result_set(Words)
+        ;
+            Result = var_result_unset
+        )
     ).
 
 :- pred lookup_variable_chars(options_variables::in, string::in,
Index: compiler/passes_aux.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/passes_aux.m,v
retrieving revision 1.84
diff -u -r1.84 passes_aux.m
--- compiler/passes_aux.m	13 Oct 2006 04:52:23 -0000	1.84
+++ compiler/passes_aux.m	13 Oct 2006 08:14:38 -0000
@@ -397,7 +397,7 @@
     (
         VeryVerbose = yes,
         io.write_string(Message, !IO),
-        hlds_out.write_pred_proc_id(ModuleInfo, PredId, ProcId, !IO),
+        hlds_out.write_pred_proc_id_pair(ModuleInfo, PredId, ProcId, !IO),
         io.write_string("\n", !IO)
     ;
         VeryVerbose = no
Index: compiler/pd_debug.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/pd_debug.m,v
retrieving revision 1.21
diff -u -r1.21 pd_debug.m
--- compiler/pd_debug.m	29 Mar 2006 08:07:13 -0000	1.21
+++ compiler/pd_debug.m	13 Oct 2006 08:19:48 -0000
@@ -161,8 +161,7 @@
     io.nl(!IO),
     io.write_string("Parents: ", !IO),
     set.to_sorted_list(Parents, ParentsList),
-    io.write_list(ParentsList, ", ",
-        pd_debug_write_pred_proc_id(ModuleInfo), !IO),
+    io.write_list(ParentsList, ", ", write_pred_proc_id(ModuleInfo), !IO),
     io.nl(!IO),
     (
         WriteUnfoldedGoal = yes,
@@ -194,14 +193,7 @@
     list(pred_proc_id)::in, io::di, io::uo) is det.
 
 pd_debug_write_pred_proc_id_list_2(ModuleInfo, PredProcIds, !IO) :-
-    io.write_list(PredProcIds, ", ",
-        pd_debug_write_pred_proc_id(ModuleInfo), !IO).
-
-:- pred pd_debug_write_pred_proc_id(module_info::in, pred_proc_id::in,
-    io::di, io::uo) is det.
-
-pd_debug_write_pred_proc_id(ModuleInfo, proc(PredId, ProcId), !IO) :-
-    hlds_out.write_pred_proc_id(ModuleInfo, PredId, ProcId, !IO).
+    io.write_list(PredProcIds, ", ", write_pred_proc_id(ModuleInfo), !IO).
 
 %-----------------------------------------------------------------------------%
 
Index: compiler/pd_util.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/pd_util.m,v
retrieving revision 1.56
diff -u -r1.56 pd_util.m
--- compiler/pd_util.m	13 Oct 2006 04:52:24 -0000	1.56
+++ compiler/pd_util.m	13 Oct 2006 07:44:53 -0000
@@ -1115,7 +1115,7 @@
     EarlierTrace = contains_no_trace_goal,
     LaterTrace = contains_no_trace_goal,
 
-    goal_util.reordering_maintains_termination(ModuleInfo, FullyStrict,
+    goal_util.reordering_maintains_termination_old(ModuleInfo, FullyStrict,
         EarlierGoal, LaterGoal),
 
     % Don't reorder the goals if the later goal depends on the outputs
Index: compiler/peephole.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/peephole.m,v
retrieving revision 1.92
diff -u -r1.92 peephole.m
--- compiler/peephole.m	22 Aug 2006 05:04:02 -0000	1.92
+++ compiler/peephole.m	13 Oct 2006 08:51:39 -0000
@@ -160,7 +160,7 @@
     (
         LabelValsList = [Label - _]
     ->
-        GotoInstr = goto(label(Label)) - Comment,
+        GotoInstr = goto(code_label(Label)) - Comment,
         Instrs = [GotoInstr | Instrs0]
     ;
         LabelValsList = [LabelVals1, LabelVals2],
@@ -169,8 +169,8 @@
     ->
         CondRval = binop(eq, SelectorRval, const(llconst_int(Val))),
         CommentInstr = comment(Comment) - "",
-        BranchInstr = if_val(CondRval, label(OneValLabel)) - "",
-        GotoInstr = goto(label(OtherLabel)) - Comment,
+        BranchInstr = if_val(CondRval, code_label(OneValLabel)) - "",
+        GotoInstr = goto(code_label(OtherLabel)) - Comment,
         Instrs = [CommentInstr, BranchInstr, GotoInstr | Instrs0]
     ;
         fail
@@ -203,7 +203,7 @@
     ->
         Instrs = Instrs0
     ;
-        CodeAddr = label(Label),
+        CodeAddr = code_label(Label),
         opt_util.is_this_label_next(Label, Instrs0, _)
     ->
         Instrs = Instrs0
@@ -280,7 +280,7 @@
                 | Instrs2
             ]
         ;
-            Redoip1 = label(_)
+            Redoip1 = code_label(_)
         ->
             (
                 Target = do_fail
@@ -318,7 +318,7 @@
         Instrs1 = [Instr1 | Instrs2],
         Instr1 = goto(do_succeed(_)) - _
     ->
-        GotoSuccip = goto(succip) - "return from optimized away mkframe",
+        GotoSuccip = goto(code_succip) - "return from optimized away mkframe",
         Instrs = Straight ++ [GotoSuccip | Instrs2]
     ;
         fail
@@ -420,7 +420,7 @@
         Instr2 = decr_sp(N) - _,
         opt_util.skip_comments_livevals(Instrs3, Instrs4),
         Instrs4 = [Instr4 | Instrs5],
-        Instr4 = goto(succip) - Comment
+        Instr4 = goto(code_succip) - Comment
     ->
         NewInstr = decr_sp_and_return(N) - Comment,
         Instrs = [NewInstr | Instrs5]
Index: compiler/pragma_c_gen.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/pragma_c_gen.m,v
retrieving revision 1.97
diff -u -r1.97 pragma_c_gen.m
--- compiler/pragma_c_gen.m	22 Aug 2006 05:04:03 -0000	1.97
+++ compiler/pragma_c_gen.m	13 Oct 2006 10:04:35 -0000
@@ -407,7 +407,7 @@
     code_info.get_next_label(SuccessLabel, !CI),
     code_info.generate_failure(FailCode, !CI),
     CondCode = node([
-        if_val(CondRval, label(SuccessLabel))
+        if_val(CondRval, code_label(SuccessLabel))
             - "environment variable tests"
     ]),
     SuccessLabelCode = node([
@@ -665,7 +665,7 @@
         code_info.get_next_label(SkipLabel, !CI),
         code_info.generate_failure(FailCode, !CI),
         GotoSkipLabelCode = node([
-            goto(label(SkipLabel)) - "Skip past failure code"
+            goto(code_label(SkipLabel)) - "Skip past failure code"
         ]),
         SkipLabelCode = node([label(SkipLabel) - ""]),
         FailLabelCode = node([label(TheFailLabel) - ""]),
@@ -695,10 +695,10 @@
 :- func make_proc_label_string(module_info, pred_id, proc_id) = string.
 
 make_proc_label_string(ModuleInfo, PredId, ProcId) = ProcLabelString :-
-    code_util.make_entry_label(ModuleInfo, PredId, ProcId, no, CodeAddr),
-    ( CodeAddr = imported(ProcLabel) ->
+    CodeAddr = make_entry_label(ModuleInfo, PredId, ProcId, no),
+    ( CodeAddr = code_imported_proc(ProcLabel) ->
         ProcLabelString = proc_label_to_c_string(ProcLabel, yes)
-    ; CodeAddr = label(Label) ->
+    ; CodeAddr = code_label(Label) ->
         ProcLabelString = label_to_c_string(Label, yes)
     ;
         unexpected(this_file, "code_addr in make_proc_label_hash_define")
@@ -764,7 +764,7 @@
     code_info.get_next_label(RetryLabel, !CI),
     ModFrameCode = node([
         assign(redoip_slot(lval(curfr)),
-            const(llconst_code_addr(label(RetryLabel))))
+            const(llconst_code_addr(code_label(RetryLabel))))
             - "Set up backtracking to retry label"
     ]),
     RetryLabelCode = node([
Index: compiler/proc_gen.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/proc_gen.m,v
retrieving revision 1.8
diff -u -r1.8 proc_gen.m
--- compiler/proc_gen.m	2 Oct 2006 05:21:20 -0000	1.8
+++ compiler/proc_gen.m	13 Oct 2006 11:02:24 -0000
@@ -44,7 +44,8 @@
 
     % Translate a HLDS module to LLDS.
     %
-:- pred generate_code(module_info::in, global_data::in, global_data::out,
+:- pred generate_module_code(module_info::in,
+    global_data::in, global_data::out,
     list(c_procedure)::out, io::di, io::uo) is det.
 
     % Translate a HLDS procedure to LLDS, threading through the data structure
@@ -114,7 +115,7 @@
 
 %---------------------------------------------------------------------------%
 
-generate_code(ModuleInfo0, !GlobalData, Procedures, !IO) :-
+generate_module_code(ModuleInfo0, !GlobalData, Procedures, !IO) :-
     % Get a list of all the predicate ids for which we will generate code.
     module_info_predids(ModuleInfo0, PredIds),
     % Check if we want to use parallel code generation.
@@ -398,8 +399,7 @@
         RttiProcLabel = rtti.make_rtti_proc_label(ModuleInfo,
             PredId, ProcId),
         code_info.get_layout_info(CodeInfo, InternalMap),
-        code_util.make_local_entry_label(ModuleInfo, PredId, ProcId,
-            no, EntryLabel),
+        EntryLabel = make_local_entry_label(ModuleInfo, PredId, ProcId, no),
         proc_info_get_eval_method(ProcInfo, EvalMethod),
         proc_info_get_initial_instmap(ProcInfo, ModuleInfo, InstMap0),
         proc_info_get_headvars(ProcInfo, HeadVars),
@@ -706,7 +706,7 @@
     FailCode = node([
         assign(reg(reg_r, 1), const(llconst_false)) - "Fail",
         livevals(FailureLiveRegs) - "",
-        goto(succip) - "Return from procedure call"
+        goto(code_succip) - "Return from procedure call"
     ]),
     code_info.get_maybe_trace_info(!.CI, MaybeTraceInfo),
     (
@@ -808,7 +808,7 @@
                 code_info.get_next_label(SkipLabel, !CI),
                 DiscardTraceTicketCode = node([
                     if_val(unop(logical_not, lval(FromFullSlotLval)),
-                        label(SkipLabel)) - "",
+                        code_label(SkipLabel)) - "",
                     discard_ticket - "discard retry ticket",
                     label(SkipLabel) - ""
                 ])
@@ -874,9 +874,9 @@
     code_info.get_pred_id(CI, PredId),
     code_info.get_proc_id(CI, ProcId),
     code_info.get_module_info(CI, ModuleInfo),
-    code_util.make_local_entry_label(ModuleInfo, PredId, ProcId, no, Entry),
+    EntryLabel = make_local_entry_label(ModuleInfo, PredId, ProcId, no),
     LabelCode = node([
-        label(Entry) - "Procedure entry point"
+        label(EntryLabel) - "Procedure entry point"
     ]),
     code_info.get_succip_used(CI, Used),
     (
@@ -1064,13 +1064,13 @@
                 code_info.get_next_label(SkipLabelCopy, !CI),
                 PruneTraceTicketCode = node([
                     if_val(unop(logical_not, lval(FromFullSlotLval)),
-                        label(SkipLabel)) - "",
+                        code_label(SkipLabel)) - "",
                     prune_ticket - "prune retry ticket",
                     label(SkipLabel) - ""
                 ]),
                 PruneTraceTicketCodeCopy = node([
                     if_val(unop(logical_not, lval(FromFullSlotLval)),
-                        label(SkipLabelCopy)) - "",
+                        code_label(SkipLabelCopy)) - "",
                     prune_ticket - "prune retry ticket",
                     label(SkipLabelCopy) - ""
                 ])
@@ -1129,7 +1129,7 @@
             CodeModel = model_det,
             SuccessCode = node([
                 livevals(LiveLvals) - "",
-                goto(succip) - "Return from procedure call"
+                goto(code_succip) - "Return from procedure call"
             ]),
             AllSuccessCode = tree_list([TraceExitCode, RestoreDeallocCodeCopy,
                 SuccessCode])
@@ -1139,7 +1139,7 @@
             SuccessCode = node([
                 assign(reg(reg_r, 1), const(llconst_true)) - "Succeed",
                 livevals(SuccessLiveRegs) - "",
-                goto(succip) - "Return from procedure call"
+                goto(code_succip) - "Return from procedure call"
             ]),
             AllSuccessCode = tree_list([TraceExitCode, RestoreDeallocCodeCopy,
                 SuccessCode])
@@ -1177,7 +1177,7 @@
         [Instrn - Comment | Instrns]) :-
     (
         Instrn0 = livevals(LiveVals0),
-        Instrns0 \= [goto(succip) - _ | _]
+        Instrns0 \= [goto(code_succip) - _ | _]
         % XXX We should also test for tailcalls
         % once we start generating them directly.
     ->
@@ -1207,7 +1207,7 @@
 
     ModuleName = sym_name_to_string_sep(ModuleSymName, "__"),
 
-    code_util.make_local_entry_label(ModuleInfo, PredId, ProcId, no, Entry),
+    EntryLabel = make_local_entry_label(ModuleInfo, PredId, ProcId, no),
 
     PredName = pred_info_name(PredInfo),
     proc_id_to_int(ProcId, ProcNum),
@@ -1249,7 +1249,7 @@
     ],
 
     BytecodeInstructions = [
-        label(Entry) - "Procedure entry point",
+        label(EntryLabel) - "Procedure entry point",
         pragma_c([], BytecodeInstructionsComponents, proc_may_call_mercury,
             no, no, no, no, no, no) - "Entry stub"
     ].
Index: compiler/process_util.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/process_util.m,v
retrieving revision 1.21
diff -u -r1.21 process_util.m
--- compiler/process_util.m	5 Jun 2006 05:23:26 -0000	1.21
+++ compiler/process_util.m	13 Oct 2006 07:18:03 -0000
@@ -72,8 +72,8 @@
     % If fork() is not supported on the current architecture,
     % `AltP' will be called instead in the current process.
     %
-:- pred call_in_forked_process(io_pred::in(io_pred), io_pred::in(io_pred),
-    bool::out, io::di, io::uo) is det.
+:- pred call_in_forked_process_with_backup(io_pred::in(io_pred),
+    io_pred::in(io_pred), bool::out, io::di, io::uo) is det.
 
     % As above, but if fork() is not available, just call the
     % predicate in the current process.
@@ -270,11 +270,11 @@
 %-----------------------------------------------------------------------------%
 
 call_in_forked_process(P, Success, !IO) :-
-    call_in_forked_process(P, P, Success, !IO).
+    call_in_forked_process_with_backup(P, P, Success, !IO).
 
-call_in_forked_process(P, AltP, Success, !IO) :-
+call_in_forked_process_with_backup(P, AltP, Success, !IO) :-
     ( can_fork ->
-        call_in_forked_process_2(P, ForkStatus, CallStatus, !IO),
+        do_call_in_forked_process(P, ForkStatus, CallStatus, !IO),
         ( ForkStatus = 1 ->
             Success = no
         ;
@@ -307,14 +307,14 @@
 #endif
 ").
 
-:- pred call_in_forked_process_2(io_pred::in(io_pred), int::out, int::out,
+:- pred do_call_in_forked_process(io_pred::in(io_pred), int::out, int::out,
     io::di, io::uo) is det.
 
-call_in_forked_process_2(_::in(io_pred), _::out, _::out, _::di, _::uo) :-
-    unexpected(this_file, "call_in_forked_process_2").
+do_call_in_forked_process(_::in(io_pred), _::out, _::out, _::di, _::uo) :-
+    unexpected(this_file, "do_call_in_forked_process").
 
 :- pragma foreign_proc("C",
-    call_in_forked_process_2(Pred::in(io_pred), ForkStatus::out, Status::out,
+    do_call_in_forked_process(Pred::in(io_pred), ForkStatus::out, Status::out,
         IO0::di, IO::uo),
     [may_call_mercury, promise_pure, tabled_for_io],
 "{
Index: compiler/prog_rep.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/prog_rep.m,v
retrieving revision 1.49
diff -u -r1.49 prog_rep.m
--- compiler/prog_rep.m	2 Oct 2006 05:21:22 -0000	1.49
+++ compiler/prog_rep.m	13 Oct 2006 10:52:09 -0000
@@ -353,33 +353,24 @@
     stack_layout_info::in, stack_layout_info::out, list(int)::out) is det.
 
 cons_id_to_byte_list(SymName, !StackInfo, Bytes) :-
-    string_to_byte_list(cons_id_to_string(SymName), !StackInfo, Bytes).
+    string_to_byte_list(cons_id_rep(SymName), !StackInfo, Bytes).
 
-:- func cons_id_to_string(cons_id) = string.
+:- func cons_id_rep(cons_id) = string.
 
-cons_id_to_string(cons(SymName, _)) =
-    prog_rep.sym_base_name_to_string(SymName).
-cons_id_to_string(int_const(Int)) =
-    string.int_to_string(Int).
-cons_id_to_string(float_const(Float)) =
-    string.float_to_string(Float).
-cons_id_to_string(string_const(String)) =
-    string.append_list(["""", String, """"]).
-cons_id_to_string(pred_const(_, _)) = "$pred_const".
-cons_id_to_string(type_ctor_info_const(_, _, _)) =
-    "$type_ctor_info_const".
-cons_id_to_string(base_typeclass_info_const(_, _, _, _)) =
+cons_id_rep(cons(SymName, _)) = prog_rep.sym_base_name_to_string(SymName).
+cons_id_rep(int_const(Int)) = string.int_to_string(Int).
+cons_id_rep(float_const(Float)) = string.float_to_string(Float).
+cons_id_rep(string_const(String)) = string.append_list(["""", String, """"]).
+cons_id_rep(pred_const(_, _)) = "$pred_const".
+cons_id_rep(type_ctor_info_const(_, _, _)) = "$type_ctor_info_const".
+cons_id_rep(base_typeclass_info_const(_, _, _, _)) =
     "$base_typeclass_info_const".
-cons_id_to_string(type_info_cell_constructor(_)) =
-    "$type_info_cell_constructor".
-cons_id_to_string(typeclass_info_cell_constructor) =
+cons_id_rep(type_info_cell_constructor(_)) = "$type_info_cell_constructor".
+cons_id_rep(typeclass_info_cell_constructor) =
     "$typeclass_info_cell_constructor".
-cons_id_to_string(tabling_info_const(_)) =
-    "$tabling_info_const".
-cons_id_to_string(deep_profiling_proc_layout(_)) =
-    "$deep_profiling_procedure_data".
-cons_id_to_string(table_io_decl(_)) =
-    "$table_io_decl".
+cons_id_rep(tabling_info_const(_)) = "$tabling_info_const".
+cons_id_rep(deep_profiling_proc_layout(_)) = "$deep_profiling_procedure_data".
+cons_id_rep(table_io_decl(_)) = "$table_io_decl".
 
 :- func sym_base_name_to_string(sym_name) = string.
 
Index: compiler/quantification.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/quantification.m,v
retrieving revision 1.108
diff -u -r1.108 quantification.m
--- compiler/quantification.m	20 Aug 2006 08:21:28 -0000	1.108
+++ compiler/quantification.m	13 Oct 2006 07:35:19 -0000
@@ -456,7 +456,7 @@
     ;
         warn_overlapping_scope(RenameVars, Context, !Info),
         rename_apart(RenameVars, RenameMap, Cond0, Cond1, !Info),
-        goal_util.rename_vars_in_goal(RenameMap, Then0, Then1),
+        goal_util.rename_some_vars_in_goal(RenameMap, Then0, Then1),
         goal_util.rename_var_list(no, RenameMap, Vars0, Vars)
     ),
     insert_list(QuantVars, Vars, QuantVars1),
@@ -1338,7 +1338,7 @@
         map.init(RenameMap0),
         goal_util.create_variables(RenameList, Varset0, VarTypes0,
             Varset0, Varset, VarTypes0, VarTypes, RenameMap0, RenameMap),
-        goal_util.rename_vars_in_goal(RenameMap, !Goal),
+        goal_util.rename_some_vars_in_goal(RenameMap, !Goal),
         set_varset(Varset, !Info),
         set_vartypes(VarTypes, !Info)
 
Index: compiler/recompilation.check.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/recompilation.check.m,v
retrieving revision 1.35
diff -u -r1.35 recompilation.check.m
--- compiler/recompilation.check.m	13 Oct 2006 04:52:24 -0000	1.35
+++ compiler/recompilation.check.m	13 Oct 2006 09:50:16 -0000
@@ -186,8 +186,8 @@
     io::di, io::uo) is det.
 
 write_not_found_reasons_message(UsageFileName, ModuleName, !IO) :-
-    Reason = file_error(UsageFileName, "file `" ++ UsageFileName ++
-        "' not found."),
+    Reason = recompile_for_file_error(UsageFileName,
+        "file `" ++ UsageFileName ++ "' not found."),
     write_recompile_reason(ModuleName, Reason, !IO).
 
 :- pred should_recompile_3_try(bool::in,
@@ -227,7 +227,7 @@
     ;
         io.input_stream_name(UsageFileName, !IO),
         throw_syntax_error(
-            file_error(UsageFileName,
+            recompile_for_file_error(UsageFileName,
                 "invalid usage file version number in file `"
                 ++ UsageFileName ++ "'."),
             !.Info)
@@ -257,14 +257,15 @@
                 ModuleTimestamp ^ timestamp := NewTimestamp,
                 Items, Error, FileName, !Info),
             !:Info = !.Info ^ modules_to_recompile := all_modules,
-            record_recompilation_reason(module_changed(FileName), !Info)
+            record_recompilation_reason(recompile_for_module_changed(FileName),
+                !Info)
         ;
             ( Error \= no_module_errors
             ; MaybeNewTimestamp = no
             )
         ->
             throw_syntax_error(
-                file_error(FileName,
+                recompile_for_file_error(FileName,
                     "error reading file `" ++ FileName ++ "'."),
                 !.Info)
         ;
@@ -286,7 +287,7 @@
     ->
         !:Info = !.Info ^ sub_modules := SubModules
     ;
-        Reason1 = syntax_error(get_term_context(SubModulesTerm),
+        Reason1 = recompile_for_syntax_error(get_term_context(SubModulesTerm),
             "error in sub_modules term"),
         throw_syntax_error(Reason1, !.Info)
     ),
@@ -310,7 +311,7 @@
     ->
         !:Info = !.Info ^ used_typeclasses := set.list_to_set(UsedClasses)
     ;
-        Reason3 = syntax_error(get_term_context(UsedClassesTerm),
+        Reason3 = recompile_for_syntax_error(get_term_context(UsedClassesTerm),
             "error in used_typeclasses term"),
         throw_syntax_error(Reason3, !.Info)
     ),
@@ -331,7 +332,7 @@
     ->
         true
     ;
-        Reason = output_file_not_up_to_date(TargetFile),
+        Reason = recompile_for_output_file_not_up_to_date(TargetFile),
         record_recompilation_reason(Reason, !Info)
     ).
 
@@ -364,7 +365,7 @@
         ModuleName = ModuleName0,
         ModuleTimestamp = module_timestamp(Suffix, Timestamp, NeedQualifier)
     ;
-        Reason = syntax_error(get_term_context(Term),
+        Reason = recompile_for_syntax_error(get_term_context(Term),
             "error in module timestamp"),
         throw_syntax_error(Reason, Info)
     ).
@@ -379,7 +380,8 @@
         list.foldl(parse_used_item_set(Info), UsedItemTerms,
             init_item_id_set(map.init, map.init, map.init), UsedItems)
     ;
-        Reason = syntax_error(get_term_context(Term), "error in used items"),
+        Reason = recompile_for_syntax_error(get_term_context(Term),
+            "error in used items"),
         throw_syntax_error(Reason, Info)
     ).
 
@@ -406,12 +408,13 @@
                 ItemTerms, map.init, CtorItems),
             UsedItems = UsedItems0 ^ functors := CtorItems
         ;
-            Reason = syntax_error(get_term_context(Term),
+            Reason = recompile_for_syntax_error(get_term_context(Term),
                 "error in used items: unknown item type: " ++ ItemTypeStr),
             throw_syntax_error(Reason, Info)
         )
     ;
-        Reason = syntax_error(get_term_context(Term), "error in used items"),
+        Reason = recompile_for_syntax_error(get_term_context(Term),
+            "error in used items"),
         throw_syntax_error(Reason, Info)
     ).
 
@@ -429,7 +432,8 @@
             map.init, Matches),
         map.det_insert(Set0, Name - Arity, Matches, Set)
     ;
-        Reason = syntax_error(get_term_context(Term), "error in simple items"),
+        Reason = recompile_for_syntax_error(get_term_context(Term),
+            "error in simple items"),
         throw_syntax_error(Reason, Info)
     ).
 
@@ -452,7 +456,7 @@
     ->
         map.det_insert(Items0, Qualifier, ModuleName, Items)
     ;
-        Reason = syntax_error(get_term_context(Term),
+        Reason = recompile_for_syntax_error(get_term_context(Term),
             "error in simple item match"),
         throw_syntax_error(Reason, Info)
     ).
@@ -488,7 +492,7 @@
     ->
         svmap.det_insert(Qualifier, set.list_to_set(Matches), !Items)
     ;
-        Reason = syntax_error(get_term_context(Term),
+        Reason = recompile_for_syntax_error(get_term_context(Term),
             "error in pred or func match"),
         throw_syntax_error(Reason, Info)
     ).
@@ -512,7 +516,7 @@
         list.map(parse_resolved_functor(Info), MatchesList, Matches),
         svmap.det_insert(Qualifier, set.list_to_set(Matches), !Map)
     ;
-        Reason = syntax_error(get_term_context(Term),
+        Reason = recompile_for_syntax_error(get_term_context(Term),
             "error in functor match"),
         throw_syntax_error(Reason, Info)
     ).
@@ -531,22 +535,23 @@
         ArityTerm = term.functor(term.integer(Arity), [], _)
     ->
         PredId = invalid_pred_id,
-        Ctor = pred_or_func(PredId, ModuleName, PredOrFunc, Arity)
+        Ctor = resolved_functor_pred_or_func(PredId, ModuleName, PredOrFunc,
+            Arity)
     ;
         Term = term.functor(term.atom("ctor"), [NameArityTerm], _),
         parse_name_and_arity(NameArityTerm, TypeName, TypeArity)
     ->
-        Ctor = constructor(item_name(TypeName, TypeArity))
+        Ctor = resolved_functor_constructor(item_name(TypeName, TypeArity))
     ;
         Term = term.functor(term.atom("field"),
             [TypeNameArityTerm, ConsNameArityTerm], _),
         parse_name_and_arity(TypeNameArityTerm, TypeName, TypeArity),
         parse_name_and_arity(ConsNameArityTerm, ConsName, ConsArity)
     ->
-        Ctor = field(item_name(TypeName, TypeArity),
+        Ctor = resolved_functor_field(item_name(TypeName, TypeArity),
             item_name(ConsName, ConsArity))
     ;
-        Reason = syntax_error(get_term_context(Term),
+        Reason = recompile_for_syntax_error(get_term_context(Term),
             "error in functor match"),
         throw_syntax_error(Reason, Info)
     ).
@@ -570,7 +575,7 @@
             MatchTermList, Matches),
         map.det_insert(Set0, Name, Matches, Set)
     ;
-        Reason = syntax_error(get_term_context(Term),
+        Reason = recompile_for_syntax_error(get_term_context(Term),
             "error in resolved item matches"),
         throw_syntax_error(Reason, Info)
     ).
@@ -593,7 +598,7 @@
             ),
             MatchTermList, map.init, MatchMap)
     ;
-        Reason = syntax_error(get_term_context(Term),
+        Reason = recompile_for_syntax_error(get_term_context(Term),
             "error in resolved item matches"),
         throw_syntax_error(Reason, Info)
     ).
@@ -620,7 +625,8 @@
     ;
         TermResult = error(Message, Line),
         io.input_stream_name(FileName, !IO),
-        Reason = syntax_error(term.context(FileName, Line), Message),
+        Reason = recompile_for_syntax_error(term.context(FileName, Line),
+            Message),
         throw_syntax_error(Reason, !.Info)
     ;
         TermResult = eof,
@@ -629,7 +635,7 @@
         % of the `.used' file was not interrupted.
         io.input_stream_name(FileName, !IO),
         io.get_line_number(Line, !IO),
-        Reason = syntax_error(term.context(FileName, Line),
+        Reason = recompile_for_syntax_error(term.context(FileName, Line),
             "unexpected end of file"),
         throw_syntax_error(Reason, !.Info)
     ).
@@ -695,14 +701,15 @@
                 RecordedTimestamp, UsedItemsTerm, VersionNumbers,
                 OtherItems, !Info)
         ;
-            record_recompilation_reason(module_changed(FileName),
+            record_recompilation_reason(recompile_for_module_changed(FileName),
                 !Info)
         )
     ;
         Error \= no_module_errors
     ->
         throw_syntax_error(
-            file_error(FileName, "error reading file `" ++ FileName ++ "'."),
+            recompile_for_file_error(FileName,
+                "error reading file `" ++ FileName ++ "'."),
             !.Info)
     ;
         true
@@ -726,7 +733,8 @@
             Errors = [Msg - ErrorTerm | _],
             % XXX Can Errors contain more than oner error? If so, we should
             % not ignore the tail of the list.
-            Reason = syntax_error(get_term_context(ErrorTerm), Msg),
+            Reason = recompile_for_syntax_error(get_term_context(ErrorTerm),
+                Msg),
             throw_syntax_error(Reason, !.Info)
         )
     ),
@@ -762,7 +770,8 @@
     set.difference(set.intersect(UsedClasses, ModuleInstances),
         UsedInstances, AddedInstances),
     ( [AddedInstance | _] = set.to_sorted_list(AddedInstances) ->
-        Reason1 = changed_or_added_instance(ModuleName, AddedInstance),
+        Reason1 = recompile_for_changed_or_added_instance(ModuleName,
+            AddedInstance),
         record_recompilation_reason(Reason1, !Info)
     ;
         true
@@ -796,12 +805,12 @@
         ( NewVersionNumber = UsedVersionNumber ->
             true
         ;
-            Reason = changed_item(make_item_id(ModuleName, ItemType,
-                NameArity)),
+            Reason = recompile_for_changed_item(make_item_id(ModuleName,
+                ItemType, NameArity)),
             record_recompilation_reason(Reason, !Info)
         )
     ;
-        Reason = removed_item(make_item_id(ModuleName, ItemType,
+        Reason = recompile_for_removed_item(make_item_id(ModuleName, ItemType,
             NameArity)),
         record_recompilation_reason(Reason, !Info)
     ).
@@ -825,11 +834,12 @@
         ( UsedVersionNumber = NewVersionNumber ->
             true
         ;
-            Reason = changed_or_added_instance(ModuleName, ClassId),
+            Reason = recompile_for_changed_or_added_instance(ModuleName,
+                ClassId),
             record_recompilation_reason(Reason, !Info)
         )
     ;
-        Reason = removed_instance(ModuleName, ClassId),
+        Reason = recompile_for_removed_instance(ModuleName, ClassId),
         record_recompilation_reason(Reason, !Info)
     ).
 
@@ -977,7 +987,8 @@
         \+ SymName = qualified(OldMatchingModuleName, _)
     ->
         OldMatchingName = qualified(OldMatchingModuleName, Name),
-        Reason = item_ambiguity(item_id(ItemType, item_name(SymName, Arity)),
+        Reason = recompile_for_item_ambiguity(
+            item_id(ItemType, item_name(SymName, Arity)),
             [item_id(ItemType, item_name(OldMatchingName, Arity))]),
         record_recompilation_reason(Reason, !Info)
     ;
@@ -1023,13 +1034,15 @@
             (
                 WithType = yes(_),
                 % We don't know the actual arity.
-                AritiesToMatch = any
+                AritiesToMatch = match_arity_any
             ;
                 WithType = no,
-                AritiesToMatch = less_than_or_equal(Arity)
+                AritiesToMatch = match_arity_less_than_or_equal(Arity)
             ),
-            check_functor_ambiguities(NeedQualifier, SymName, AritiesToMatch,
-                pred_or_func(PredId, ModuleName, PredOrFunc, Arity), !Info)
+            ResolvedFunctor = resolved_functor_pred_or_func(PredId, ModuleName,
+                PredOrFunc, Arity),
+            check_functor_ambiguities_by_name(NeedQualifier, SymName,
+                AritiesToMatch, ResolvedFunctor, !Info)
         ;
             unexpected(this_file,
                 "check_for_pred_or_func_item_ambiguity: " ++
@@ -1092,8 +1105,8 @@
                 Item = item_id(ItemType, item_name(OldMatchingName, Arity))
             ),
             set.to_sorted_list(OldMatchingModuleNames)),
-        Reason = item_ambiguity(item_id(ItemType, item_name(SymName, Arity)),
-            AmbiguousDecls),
+        Reason = recompile_for_item_ambiguity(item_id(ItemType,
+            item_name(SymName, Arity)), AmbiguousDecls),
         record_recompilation_reason(Reason, !Info)
     ;
         true
@@ -1126,12 +1139,14 @@
 check_functor_ambiguities(NeedQualifier, TypeCtor, ctor(_, _, Name, Args),
         !Info) :-
     TypeCtorItem = type_ctor_to_item_name(TypeCtor),
-    ResolvedCtor = constructor(TypeCtorItem),
+    ResolvedCtor = resolved_functor_constructor(TypeCtorItem),
     Arity = list.length(Args),
-    check_functor_ambiguities(NeedQualifier, Name, exact(Arity),
-        ResolvedCtor, !Info),
-    list.foldl(check_field_ambiguities(NeedQualifier,
-        field(TypeCtorItem, item_name(Name, Arity))), Args, !Info).
+    check_functor_ambiguities_by_name(NeedQualifier, Name,
+        match_arity_exact(Arity), ResolvedCtor, !Info),
+    list.foldl(
+        check_field_ambiguities(NeedQualifier,
+            resolved_functor_field(TypeCtorItem, item_name(Name, Arity))),
+        Args, !Info).
 
 :- pred check_field_ambiguities(need_qualifier::in, resolved_functor::in,
     constructor_arg::in,
@@ -1143,25 +1158,25 @@
     % XXX The arities to match below will need to change if we ever
     % allow taking the address of field access functions.
     field_access_function_name(get, FieldName, ExtractFuncName),
-    check_functor_ambiguities(NeedQualifier, ExtractFuncName,
-        exact(1), ResolvedCtor, !Info),
+    check_functor_ambiguities_by_name(NeedQualifier, ExtractFuncName,
+        match_arity_exact(1), ResolvedCtor, !Info),
     field_access_function_name(set, FieldName, UpdateFuncName),
-    check_functor_ambiguities(NeedQualifier, UpdateFuncName,
-        exact(2), ResolvedCtor, !Info).
+    check_functor_ambiguities_by_name(NeedQualifier, UpdateFuncName,
+        match_arity_exact(2), ResolvedCtor, !Info).
 
     % Predicates and functions used as functors can match any arity
     % less than or equal to the predicate or function's arity.
 :- type functor_match_arity
-    --->    exact(arity)
-    ;       less_than_or_equal(arity)
-    ;       any.
+    --->    match_arity_exact(arity)
+    ;       match_arity_less_than_or_equal(arity)
+    ;       match_arity_any.
 
-:- pred check_functor_ambiguities(need_qualifier::in, sym_name::in,
+:- pred check_functor_ambiguities_by_name(need_qualifier::in, sym_name::in,
     functor_match_arity::in, resolved_functor::in,
     recompilation_check_info::in, recompilation_check_info::out) is det.
 
-check_functor_ambiguities(NeedQualifier, Name, MatchArity, ResolvedCtor,
-        !Info) :-
+check_functor_ambiguities_by_name(NeedQualifier, Name, MatchArity,
+        ResolvedCtor, !Info) :-
     UsedItems = !.Info ^ used_items,
     UnqualName = unqualify_name(Name),
     UsedCtors = UsedItems ^ functors,
@@ -1181,7 +1196,7 @@
 check_functor_ambiguities_2(NeedQualifier, Name, MatchArity,
         ResolvedCtor, [Arity - UsedCtorMap | UsedCtorAL], !Info) :-
     (
-        MatchArity = exact(ArityToMatch),
+        MatchArity = match_arity_exact(ArityToMatch),
         ( ArityToMatch = Arity ->
             Check = yes,
             Continue = no
@@ -1194,7 +1209,7 @@
             )
         )
     ;
-        MatchArity = less_than_or_equal(ArityToMatch),
+        MatchArity = match_arity_less_than_or_equal(ArityToMatch),
         ( Arity =< ArityToMatch ->
             Check = yes,
             Continue = yes
@@ -1203,7 +1218,7 @@
             Continue = no
         )
     ;
-        MatchArity = any,
+        MatchArity = match_arity_any,
         Check = yes,
         Continue = yes
     ),
@@ -1242,7 +1257,7 @@
         match_sym_name(OldName, SymName),
         \+ set.member(ResolvedCtor, OldResolvedCtors)
     ->
-        Reason = functor_ambiguity(
+        Reason = recompile_for_functor_ambiguity(
             module_qualify_name(OldModuleQualifier, Name),
             Arity, ResolvedCtor, set.to_sorted_list(OldResolvedCtors)
         ),
@@ -1267,56 +1282,56 @@
             ).
 
 :- type recompile_exception
-    ---> recompile_exception(
-            recompile_reason,
-            recompilation_check_info
-        ).
+    --->    recompile_exception(
+                recompile_reason,
+                recompilation_check_info
+            ).
 
 :- type recompile_reason
-    --->    file_error(
+    --->    recompile_for_file_error(
                 file_name,
                 string
             )
 
-    ;       output_file_not_up_to_date(
+    ;       recompile_for_output_file_not_up_to_date(
                 file_name
             )
 
-    ;       syntax_error(
+    ;       recompile_for_syntax_error(
                 term.context,
                 string
             )
 
-    ;       module_changed(
+    ;       recompile_for_module_changed(
                 file_name
             )
 
-    ;       item_ambiguity(
+    ;       recompile_for_item_ambiguity(
                 item_id,                % new item.
                 list(item_id)           % ambiguous declarations.
             )
 
-    ;       functor_ambiguity(
+    ;       recompile_for_functor_ambiguity(
                 sym_name,
                 arity,
                 resolved_functor,       % new item.
                 list(resolved_functor)  % ambiguous declarations.
             )
 
-    ;       changed_item(
+    ;       recompile_for_changed_item(
                 item_id
             )
 
-    ;       removed_item(
+    ;       recompile_for_removed_item(
                 item_id
             )
 
-    ;       changed_or_added_instance(
+    ;       recompile_for_changed_or_added_instance(
                 module_name,
                 item_name               % class name
             )
 
-    ;       removed_instance(
+    ;       recompile_for_removed_instance(
                 module_name,
                 item_name               % class name
             ).
@@ -1370,20 +1385,23 @@
 :- pred recompile_reason_message(recompile_reason::in, maybe(context)::out,
     list(format_component)::out) is det.
 
-recompile_reason_message(file_error(_FileName, Msg), no, [words(Msg)]).
-recompile_reason_message(output_file_not_up_to_date(FileName), no,
-        [words("output file"), words(FileName), words("is not up to date.")]).
-recompile_reason_message(syntax_error(Context, Msg), yes(Context),
+recompile_reason_message(recompile_for_file_error(_FileName, Msg), no,
         [words(Msg)]).
-recompile_reason_message(module_changed(FileName), no,
+recompile_reason_message(recompile_for_output_file_not_up_to_date(FileName),
+        no,
+        [words("output file"), words(FileName), words("is not up to date.")]).
+recompile_reason_message(recompile_for_syntax_error(Context, Msg),
+        yes(Context), [words(Msg)]).
+recompile_reason_message(recompile_for_module_changed(FileName), no,
         [words("file"), words("`" ++ FileName ++ "'"), words("has changed.")]).
-recompile_reason_message(item_ambiguity(Item, AmbiguousItems), no, Pieces) :-
+recompile_reason_message(recompile_for_item_ambiguity(Item, AmbiguousItems),
+        no, Pieces) :-
     AmbiguousItemPieces = component_lists_to_pieces(
         list.map(describe_item, AmbiguousItems)),
     Pieces = [words("addition of ") | describe_item(Item)]
         ++ [words("could cause an ambiguity with")]
         ++ AmbiguousItemPieces ++ [suffix(".")].
-recompile_reason_message(functor_ambiguity(SymName, Arity,
+recompile_reason_message(recompile_for_functor_ambiguity(SymName, Arity,
         Functor, AmbiguousFunctors), no, Pieces) :-
     FunctorPieces = describe_functor(SymName, Arity, Functor),
     AmbiguousFunctorPieces = component_lists_to_pieces(
@@ -1391,12 +1409,12 @@
     Pieces = [words("addition of ") | FunctorPieces]
         ++ [words("could cause an ambiguity with")]
         ++ AmbiguousFunctorPieces ++ [suffix(".")].
-recompile_reason_message(changed_item(Item), no,
+recompile_reason_message(recompile_for_changed_item(Item), no,
         list.append(describe_item(Item), [words("was modified.")])).
-recompile_reason_message(removed_item(Item), no,
+recompile_reason_message(recompile_for_removed_item(Item), no,
         list.append(describe_item(Item), [words("was removed.")])).
 recompile_reason_message(
-        changed_or_added_instance(ModuleName,
+        recompile_for_changed_or_added_instance(ModuleName,
             item_name(ClassName, ClassArity)),
         no,
         [
@@ -1407,7 +1425,8 @@
         words("was added or modified.")
         ]).
 recompile_reason_message(
-        removed_instance(ModuleName, item_name(ClassName, ClassArity)),
+        recompile_for_removed_instance(ModuleName,
+            item_name(ClassName, ClassArity)),
         no,
         [
         words("an instance for class "),
@@ -1437,14 +1456,16 @@
     list(format_component).
 
 describe_functor(SymName, _Arity, ResolvedFunctor) = Pieces :-
-    ResolvedFunctor = pred_or_func(_, ModuleName, PredOrFunc, PredArity),
+    ResolvedFunctor = resolved_functor_pred_or_func(_, ModuleName, PredOrFunc,
+        PredArity),
     string_to_item_type(ItemTypeStr, pred_or_func_to_item_type(PredOrFunc)),
     UnqualName = unqualify_name(SymName),
     SymNameAndArityPiece =
         sym_name_and_arity(qualified(ModuleName, UnqualName) / PredArity),
     Pieces = [words(ItemTypeStr), SymNameAndArityPiece].
 describe_functor(SymName, Arity, ResolvedFunctor) = Pieces :-
-    ResolvedFunctor = constructor(item_name(TypeName, TypeArity)),
+    ResolvedFunctor = resolved_functor_constructor(
+        item_name(TypeName, TypeArity)),
     Pieces = [
         words("constructor"),
         sym_name_and_arity(SymName / Arity),
@@ -1452,7 +1473,7 @@
         sym_name_and_arity(TypeName / TypeArity)
     ].
 describe_functor(SymName, Arity, ResolvedFunctor) = Pieces :-
-    ResolvedFunctor = field(item_name(TypeName, TypeArity),
+    ResolvedFunctor = resolved_functor_field(item_name(TypeName, TypeArity),
         item_name(ConsName, ConsArity)),
     Pieces = [
         words("field access function"),
@@ -1475,13 +1496,14 @@
     ;
         TermResult = error(Message, Line),
         io.input_stream_name(FileName, !IO),
-        Reason = syntax_error(term.context(FileName, Line), Message),
+        Reason = recompile_for_syntax_error(term.context(FileName, Line),
+            Message),
         throw_syntax_error(Reason, Info)
     ;
         TermResult = eof,
         io.input_stream_name(FileName, !IO),
         io.get_line_number(Line, !IO),
-        Reason = syntax_error(term.context(FileName, Line),
+        Reason = recompile_for_syntax_error(term.context(FileName, Line),
             "unexpected end of file, expected " ++ Item ++ "."),
         throw_syntax_error(Reason, Info)
     ).
Index: compiler/recompilation.usage.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/recompilation.usage.m,v
retrieving revision 1.39
diff -u -r1.39 recompilation.usage.m
--- compiler/recompilation.usage.m	13 Oct 2006 04:52:25 -0000	1.39
+++ compiler/recompilation.usage.m	13 Oct 2006 09:38:19 -0000
@@ -55,23 +55,22 @@
 :- type resolved_item_map(T) == map(module_qualifier, T).
 
 :- type resolved_functor
-    --->    pred_or_func(
+    --->    resolved_functor_pred_or_func(
                 pred_id,
                 module_name,
                 pred_or_func,
                 arity       % The actual arity of the predicate or function
             )
-    ;       constructor(
+    ;       resolved_functor_constructor(
                 item_name   % type_ctor
             )
-    ;       field(
+    ;       resolved_functor_field(
                 item_name,  % type_ctor
                 item_name   % cons_id
             ).
 
-:- pred write_usage_file(module_info::in,
-    list(module_name)::in, maybe(module_timestamps)::in,
-    io::di, io::uo) is det.
+:- pred write_usage_file(module_info::in, list(module_name)::in,
+    maybe(module_timestamps)::in, io::di, io::uo) is det.
 
     % Changes which modify the format of the `.used' files will increment
     % this number. recompilation_check.m should recompile if the version number
@@ -449,30 +448,41 @@
 
 :- pred write_resolved_functor(resolved_functor::in, io::di, io::uo) is det.
 
-write_resolved_functor(pred_or_func(_, ModuleName, PredOrFunc, Arity), !IO) :-
-    io.write(PredOrFunc, !IO),
-    io.write_string("(", !IO),
-    mercury_output_bracketed_sym_name(ModuleName, !IO),
-    io.write_string(", ", !IO),
-    io.write_int(Arity, !IO),
-    io.write_string(")", !IO).
-write_resolved_functor(constructor(item_name(TypeName, Arity)), !IO) :-
-    io.write_string("ctor(", !IO),
-    mercury_output_bracketed_sym_name(TypeName, next_to_graphic_token, !IO),
-    io.write_string("/", !IO),
-    io.write_int(Arity, !IO),
-    io.write_string(")", !IO).
-write_resolved_functor(field(item_name(TypeName, TypeArity),
-        item_name(ConsName, ConsArity)), !IO) :-
-    io.write_string("field(", !IO),
-    mercury_output_bracketed_sym_name(TypeName, next_to_graphic_token, !IO),
-    io.write_string("/", !IO),
-    io.write_int(TypeArity, !IO),
-    io.write_string(", ", !IO),
-    mercury_output_bracketed_sym_name(ConsName, next_to_graphic_token, !IO),
-    io.write_string("/", !IO),
-    io.write_int(ConsArity, !IO),
-    io.write_string(")", !IO).
+write_resolved_functor(ResolvedFunctor, !IO) :-
+    (
+        ResolvedFunctor = resolved_functor_pred_or_func(_, ModuleName,
+            PredOrFunc, Arity),
+        io.write(PredOrFunc, !IO),
+        io.write_string("(", !IO),
+        mercury_output_bracketed_sym_name(ModuleName, !IO),
+        io.write_string(", ", !IO),
+        io.write_int(Arity, !IO),
+        io.write_string(")", !IO)
+    ;
+        ResolvedFunctor = resolved_functor_constructor(ItemName),
+        ItemName = item_name(TypeName, Arity),
+        io.write_string("ctor(", !IO),
+        mercury_output_bracketed_sym_name(TypeName, next_to_graphic_token,
+            !IO),
+        io.write_string("/", !IO),
+        io.write_int(Arity, !IO),
+        io.write_string(")", !IO)
+    ;
+        ResolvedFunctor = resolved_functor_field(TypeItemName, ConsItemName),
+        TypeItemName = item_name(TypeName, TypeArity),
+        ConsItemName = item_name(ConsName, ConsArity),
+        io.write_string("field(", !IO),
+        mercury_output_bracketed_sym_name(TypeName, next_to_graphic_token,
+            !IO),
+        io.write_string("/", !IO),
+        io.write_int(TypeArity, !IO),
+        io.write_string(", ", !IO),
+        mercury_output_bracketed_sym_name(ConsName, next_to_graphic_token,
+            !IO),
+        io.write_string("/", !IO),
+        io.write_int(ConsArity, !IO),
+        io.write_string(")", !IO)
+    ).
 
 usage_file_version_number = 2.
 
@@ -735,7 +745,8 @@
         list.map(
             (func(ConsDefn) = Ctor :-
                 ConsDefn = hlds_cons_defn(_,_,_, TypeCtor, _),
-                Ctor = constructor(type_ctor_to_item_name(TypeCtor))
+                Ctor = resolved_functor_constructor(
+                    type_ctor_to_item_name(TypeCtor))
             ),
             ConsDefns),
 
@@ -763,7 +774,8 @@
             (func(FieldDefn) = FieldCtor :-
                 FieldDefn = hlds_ctor_field_defn(_, _, TypeCtor, ConsId, _),
                 ( ConsId = cons(ConsName, ConsArity) ->
-                    FieldCtor = field(type_ctor_to_item_name(TypeCtor),
+                    FieldCtor = resolved_functor_field(
+                        type_ctor_to_item_name(TypeCtor),
                         item_name(ConsName, ConsArity))
                 ;
                     unexpected(this_file, "weird cons_id in hlds_field_defn")
@@ -801,7 +813,8 @@
         ; OrigArity = Arity
         )
     ),
-    ResolvedCtor = pred_or_func(PredId, PredModule, PredOrFunc, OrigArity).
+    ResolvedCtor = resolved_functor_pred_or_func(PredId, PredModule,
+        PredOrFunc, OrigArity).
 
 %-----------------------------------------------------------------------------%
 
@@ -1217,14 +1230,15 @@
     recompilation_usage_info::in, recompilation_usage_info::out) is det.
 
 find_items_used_by_functor(Name, _Arity, ResolverFunctor, !Info) :-
-    ResolverFunctor = pred_or_func(PredId, PredModule, PredOrFunc, PredArity),
+    ResolverFunctor = resolved_functor_pred_or_func(PredId, PredModule,
+        PredOrFunc, PredArity),
     find_items_used_by_pred(PredOrFunc, Name - PredArity, PredId - PredModule,
         !Info).
 find_items_used_by_functor(_, _, ResolverFunctor, !Info) :-
-    ResolverFunctor = constructor(TypeCtor),
+    ResolverFunctor = resolved_functor_constructor(TypeCtor),
     maybe_record_item_to_process(type_body_item, TypeCtor, !Info).
 find_items_used_by_functor(_, _, ResolverFunctor, !Info) :-
-    ResolverFunctor = field(TypeCtor, _),
+    ResolverFunctor = resolved_functor_field(TypeCtor, _),
     maybe_record_item_to_process(type_body_item, TypeCtor, !Info).
 
 :- pred find_items_used_by_simple_item_set(item_type::in, simple_item_set::in,
Index: compiler/rtti_out.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/rtti_out.m,v
retrieving revision 1.69
diff -u -r1.69 rtti_out.m
--- compiler/rtti_out.m	2 Oct 2006 05:21:23 -0000	1.69
+++ compiler/rtti_out.m	13 Oct 2006 10:05:44 -0000
@@ -1226,8 +1226,8 @@
 
 :- func make_code_addr(rtti_proc_label) = code_addr.
 
-make_code_addr(ProcLabel) = CodeAddr :-
-    code_util.make_entry_label_from_rtti(ProcLabel, no, CodeAddr).
+make_code_addr(ProcLabel) =
+    make_entry_label_from_rtti(ProcLabel, no).
 
 :- pred output_reserved_address(reserved_address::in, io::di, io::uo) is det.
 
Index: compiler/saved_vars.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/saved_vars.m,v
retrieving revision 1.70
diff -u -r1.70 saved_vars.m
--- compiler/saved_vars.m	22 Aug 2006 05:04:07 -0000	1.70
+++ compiler/saved_vars.m	13 Oct 2006 07:38:04 -0000
@@ -318,32 +318,32 @@
         (
             Goal0Expr = unify(_, _, _, _, _),
             rename_var(Var, _NewVar, Subst, !SlotInfo),
-            goal_util.rename_vars_in_goal(Subst, Construct, NewConstruct),
-            goal_util.rename_vars_in_goal(Subst, Goal0, Goal1),
+            rename_some_vars_in_goal(Subst, Construct, NewConstruct),
+            rename_some_vars_in_goal(Subst, Goal0, Goal1),
             saved_vars_delay_goal(Goals0, Goals1, Construct, Var,
                 IsNonLocal, !SlotInfo),
             Goals = [NewConstruct, Goal1 | Goals1]
         ;
             Goal0Expr = plain_call(_, _, _, _, _, _),
             rename_var(Var, _NewVar, Subst, !SlotInfo),
-            goal_util.rename_vars_in_goal(Subst, Construct, NewConstruct),
-            goal_util.rename_vars_in_goal(Subst, Goal0, Goal1),
+            rename_some_vars_in_goal(Subst, Construct, NewConstruct),
+            rename_some_vars_in_goal(Subst, Goal0, Goal1),
             saved_vars_delay_goal(Goals0, Goals1, Construct, Var,
                 IsNonLocal, !SlotInfo),
             Goals = [NewConstruct, Goal1 | Goals1]
         ;
             Goal0Expr = generic_call(_, _, _, _),
             rename_var(Var, _NewVar, Subst, !SlotInfo),
-            goal_util.rename_vars_in_goal(Subst, Construct, NewConstruct),
-            goal_util.rename_vars_in_goal(Subst, Goal0, Goal1),
+            rename_some_vars_in_goal(Subst, Construct, NewConstruct),
+            rename_some_vars_in_goal(Subst, Goal0, Goal1),
             saved_vars_delay_goal(Goals0, Goals1, Construct, Var,
                 IsNonLocal, !SlotInfo),
             Goals = [NewConstruct, Goal1 | Goals1]
         ;
             Goal0Expr = call_foreign_proc(_, _, _, _, _, _, _),
             rename_var(Var, _NewVar, Subst, !SlotInfo),
-            goal_util.rename_vars_in_goal(Subst, Construct, NewConstruct),
-            goal_util.rename_vars_in_goal(Subst, Goal0, Goal1),
+            rename_some_vars_in_goal(Subst, Construct, NewConstruct),
+            rename_some_vars_in_goal(Subst, Goal0, Goal1),
             saved_vars_delay_goal(Goals0, Goals1, Construct, Var,
                 IsNonLocal, !SlotInfo),
             Goals = [NewConstruct, Goal1 | Goals1]
@@ -366,8 +366,8 @@
         ;
             Goal0Expr = scope(Reason, SomeGoal0),
             rename_var(Var, NewVar, Subst, !SlotInfo),
-            goal_util.rename_vars_in_goal(Subst, Construct, NewConstruct),
-            goal_util.rename_vars_in_goal(Subst, SomeGoal0, SomeGoal1),
+            rename_some_vars_in_goal(Subst, Construct, NewConstruct),
+            rename_some_vars_in_goal(Subst, SomeGoal0, SomeGoal1),
             push_into_goal(SomeGoal1, SomeGoal, NewConstruct, NewVar,
                 !SlotInfo),
             Goal1 = scope(Reason, SomeGoal) - Goal0Info,
@@ -377,8 +377,8 @@
         ;
             Goal0Expr = negation(NegGoal0),
             rename_var(Var, NewVar, Subst, !SlotInfo),
-            goal_util.rename_vars_in_goal(Subst, Construct, NewConstruct),
-            goal_util.rename_vars_in_goal(Subst, NegGoal0, NegGoal1),
+            rename_some_vars_in_goal(Subst, Construct, NewConstruct),
+            rename_some_vars_in_goal(Subst, NegGoal0, NegGoal1),
             push_into_goal(NegGoal1, NegGoal, NewConstruct, NewVar,
                 !SlotInfo),
             Goal1 = negation(NegGoal) - Goal0Info,
@@ -454,8 +454,8 @@
     goal_info_get_nonlocals(GoalInfo0, NonLocals),
     ( set.member(Var, NonLocals) ->
         rename_var(Var, NewVar, Subst, !SlotInfo),
-        goal_util.rename_vars_in_goal(Subst, Construct, NewConstruct),
-        goal_util.rename_vars_in_goal(Subst, Goal0, Goal1),
+        rename_some_vars_in_goal(Subst, Construct, NewConstruct),
+        rename_some_vars_in_goal(Subst, Goal0, Goal1),
         push_into_goal(Goal1, Goal, NewConstruct, NewVar, !SlotInfo)
     ;
         saved_vars_in_goal(Goal0, Goal, !SlotInfo)
Index: compiler/size_prof.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/size_prof.m,v
retrieving revision 1.47
diff -u -r1.47 size_prof.m
--- compiler/size_prof.m	22 Aug 2006 05:04:07 -0000	1.47
+++ compiler/size_prof.m	13 Oct 2006 08:17:12 -0000
@@ -221,7 +221,7 @@
     (
         VeryVerbose = yes,
         io.write_string("% Adding typeinfos in ", !IO),
-        hlds_out.write_pred_proc_id(!.ModuleInfo, PredId, ProcId, !IO),
+        hlds_out.write_pred_proc_id_pair(!.ModuleInfo, PredId, ProcId, !IO),
         io.write_string(": ", !IO),
         process_proc(Transform, PredId, ProcId, ProcInfo0, ProcInfo,
             !ModuleInfo, !IO),
Index: compiler/stack_alloc.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/stack_alloc.m,v
retrieving revision 1.19
diff -u -r1.19 stack_alloc.m
--- compiler/stack_alloc.m	31 Jul 2006 08:32:00 -0000	1.19
+++ compiler/stack_alloc.m	13 Oct 2006 10:42:43 -0000
@@ -90,7 +90,7 @@
     set.init(NondetLiveness0),
     SimpleStackAlloc0 = stack_alloc(set.make_singleton_set(FailVars)),
     proc_info_get_goal(!.ProcInfo, Goal0),
-    build_live_sets_in_goal(Goal0, Goal, FailVars, AllocData,
+    build_live_sets_in_goal_no_par_stack(Goal0, Goal, FailVars, AllocData,
         SimpleStackAlloc0, SimpleStackAlloc, Liveness0, _Liveness,
         NondetLiveness0, _NondetLiveness),
     proc_info_set_goal(Goal, !ProcInfo),
Index: compiler/stack_layout.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/stack_layout.m,v
retrieving revision 1.123
diff -u -r1.123 stack_layout.m
--- compiler/stack_layout.m	29 Sep 2006 06:34:50 -0000	1.123
+++ compiler/stack_layout.m	13 Oct 2006 09:25:50 -0000
@@ -386,7 +386,7 @@
         Return = yes(return_layout_info(TargetsContexts, _)),
         find_valid_return_context(TargetsContexts, Target, Context, _GoalPath)
     ->
-        ( Target = label(TargetLabel) ->
+        ( Target = code_label(TargetLabel) ->
             IsReturn = known_callee(TargetLabel)
         ;
             IsReturn = unknown_callee
@@ -613,9 +613,9 @@
         MaybeTrailSlots, MaybeMaxfrSlot, MaybeCallTableSlot),
     % The label associated with an event must have variable info.
     (
-        CallLabel = internal(CallLabelNum, CallProcLabel)
+        CallLabel = internal_label(CallLabelNum, CallProcLabel)
     ;
-        CallLabel = entry(_, _),
+        CallLabel = entry_label(_, _),
         unexpected(this_file,
             "construct_trace_layout: entry call label")
     ),
@@ -952,7 +952,7 @@
         MaybePort, MaybeIsHidden, LabelNumber, MaybeGoalPath, MaybeSolverData,
         MaybeVarInfo),
     LayoutName = label_layout(ProcLabel, LabelNum, LabelVars),
-    Label = internal(LabelNum, ProcLabel),
+    Label = internal_label(LabelNum, ProcLabel),
     add_internal_layout_data(LayoutData, Label, LayoutName, !Info),
     LabelLayout = {ProcLabel, LabelNum, LabelVars, Internal}.
 
Index: compiler/stack_opt.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/stack_opt.m,v
retrieving revision 1.29
diff -u -r1.29 stack_opt.m
--- compiler/stack_opt.m	22 Aug 2006 05:04:08 -0000	1.29
+++ compiler/stack_opt.m	13 Oct 2006 11:14:40 -0000
@@ -191,7 +191,7 @@
     OptStackAlloc0 = init_opt_stack_alloc,
     set.init(FailVars),
     set.init(NondetLiveness0),
-    build_live_sets_in_goal(Goal2, Goal, FailVars, AllocData,
+    build_live_sets_in_goal_no_par_stack(Goal2, Goal, FailVars, AllocData,
         OptStackAlloc0, OptStackAlloc, Liveness0, _Liveness,
         NondetLiveness0, _NondetLiveness),
     proc_info_set_goal(Goal, !ProcInfo),
@@ -712,52 +712,37 @@
 resume_save_status_requires_close(has_resume_save) = yes.
 resume_save_status_requires_close(has_no_resume_save) = no.
 
-:- pred may_have_no_successor(anchor::in) is semidet.
+:- func may_have_no_successor(anchor) = bool.
 
-may_have_no_successor(Anchor) :-
-    may_have_no_successor(Anchor, yes).
-
-:- pred may_have_no_successor(anchor::in, bool::out) is det.
-
-may_have_no_successor(anchor_proc_start, no).
-may_have_no_successor(anchor_proc_end, yes).
-may_have_no_successor(anchor_branch_start(_, _), no).
-may_have_no_successor(anchor_cond_then(_), no).
-may_have_no_successor(anchor_branch_end(_, _), no).
-may_have_no_successor(anchor_call_site(_), yes).   % if the call cannot succeed
-
-:- pred may_have_one_successor(anchor::in) is semidet.
-
-may_have_one_successor(Anchor) :-
-    may_have_one_successor(Anchor, yes).
-
-:- pred may_have_one_successor(anchor::in, bool::out) is det.
-
-may_have_one_successor(anchor_proc_start, yes).
-may_have_one_successor(anchor_proc_end, no).
-may_have_one_successor(anchor_branch_start(_, _), yes).
-may_have_one_successor(anchor_cond_then(_), yes).
-may_have_one_successor(anchor_branch_end(_, _), yes).
-may_have_one_successor(anchor_call_site(_), yes).
-
-:- pred may_have_more_successors(anchor::in) is semidet.
-
-may_have_more_successors(Anchor) :-
-    may_have_more_successors(Anchor, yes).
-
-:- pred may_have_more_successors(anchor::in, bool::out) is det.
-
-may_have_more_successors(anchor_proc_start, no).
-may_have_more_successors(anchor_proc_end, no).
-may_have_more_successors(anchor_branch_start(BranchType, _), MayHave) :-
+may_have_no_successor(anchor_proc_start) = no.
+may_have_no_successor(anchor_proc_end) = yes.
+may_have_no_successor(anchor_branch_start(_, _)) = no.
+may_have_no_successor(anchor_cond_then(_)) = no.
+may_have_no_successor(anchor_branch_end(_, _)) = no.
+may_have_no_successor(anchor_call_site(_)) = yes. % if the call cannot succeed
+
+:- func may_have_one_successor(anchor) = bool.
+
+may_have_one_successor(anchor_proc_start) = yes.
+may_have_one_successor(anchor_proc_end) = no.
+may_have_one_successor(anchor_branch_start(_, _)) = yes.
+may_have_one_successor(anchor_cond_then(_)) = yes.
+may_have_one_successor(anchor_branch_end(_, _)) = yes.
+may_have_one_successor(anchor_call_site(_)) = yes.
+
+:- func may_have_more_successors(anchor) = bool.
+
+may_have_more_successors(anchor_proc_start) = no.
+may_have_more_successors(anchor_proc_end) = no.
+may_have_more_successors(anchor_branch_start(BranchType, _)) =
     ( BranchType = branch_neg ->
-        MayHave = no
+        no
     ;
-        MayHave = yes
+        yes
     ).
-may_have_more_successors(anchor_cond_then(_), no).
-may_have_more_successors(anchor_branch_end(_, _), no).
-may_have_more_successors(anchor_call_site(_), no).
+may_have_more_successors(anchor_cond_then(_)) = no.
+may_have_more_successors(anchor_branch_end(_, _)) = no.
+may_have_more_successors(anchor_call_site(_)) = no.
 
 %-----------------------------------------------------------------------------%
 
@@ -793,7 +778,7 @@
     map.lookup(IntervalInfo ^ interval_succ, IntervalId, SuccessorIds),
     (
         SuccessorIds = [],
-        expect(may_have_no_successor(End), this_file,
+        expect(unify(may_have_no_successor(End), yes), this_file,
             "find_all_branches: unexpected no successor")
         % expect(unify(MaybeSearchAnchor0, no), this_file,
         %   "find_all_branches: no successor while in search"),
@@ -802,11 +787,11 @@
         SuccessorIds = [SuccessorId | MoreSuccessorIds],
         (
             MoreSuccessorIds = [],
-            expect(may_have_one_successor(End), this_file,
+            expect(unify(may_have_one_successor(End), yes), this_file,
                 "find_all_branches: unexpected one successor")
         ;
             MoreSuccessorIds = [_ | _],
-            expect(may_have_more_successors(End), this_file,
+            expect(unify(may_have_more_successors(End), yes), this_file,
                 "find_all_branches: unexpected more successors")
         ),
         (
Index: compiler/stdlabel.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/stdlabel.m,v
retrieving revision 1.1
diff -u -r1.1 stdlabel.m
--- compiler/stdlabel.m	10 Apr 2006 04:28:22 -0000	1.1
+++ compiler/stdlabel.m	13 Oct 2006 09:25:52 -0000
@@ -56,7 +56,7 @@
     opt_util.get_prologue(Instrs0, LabelInstr, Comments, Instrs1),
     (
         LabelInstr = label(FirstLabel) - _,
-        FirstLabel = entry(_, ProcLabel)
+        FirstLabel = entry_label(_, ProcLabel)
     ->
         build_std_map(Instrs1, ProcLabel, counter.init(1), !:ProcCounter,
             map.init, Map),
@@ -76,7 +76,7 @@
 build_std_map([Instr | Instrs], ProcLabel, !Counter, !Map) :-
     ( Instr = label(Label) - _ ->
         counter.allocate(LabelNum, !Counter),
-        StdLabel = internal(LabelNum, ProcLabel),
+        StdLabel = internal_label(LabelNum, ProcLabel),
         svmap.det_insert(Label, StdLabel, !Map)
     ;
         true
Index: compiler/string_switch.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/string_switch.m,v
retrieving revision 1.59
diff -u -r1.59 string_switch.m
--- compiler/string_switch.m	22 Aug 2006 05:04:08 -0000	1.59
+++ compiler/string_switch.m	13 Oct 2006 08:53:05 -0000
@@ -116,14 +116,15 @@
                     StringTable, lval(SlotReg)))
                 - "lookup the string for this hash slot",
             if_val(binop(logical_and, lval(StringReg),
-                binop(str_eq, lval(StringReg), VarRval)), label(JumpLabel))
+                binop(str_eq, lval(StringReg), VarRval)),
+                code_label(JumpLabel))
                 - "did we find a match?",
             assign(SlotReg,
                 binop(array_index(elem_type_int),
                     NextSlotsTable, lval(SlotReg)))
                 - "not yet, so get next slot in hash chain",
             if_val(binop(int_ge, lval(SlotReg), const(llconst_int(0))),
-                label(LoopLabel))
+                code_label(LoopLabel))
                 - "keep searching until we reach the end of the chain",
             label(FailLabel) - "no match, so fail"
         ])
@@ -192,7 +193,8 @@
         ;
             code_info.reset_to_position(BranchStart, !CI)
         ),
-        FinishCode = node([goto(label(EndLabel)) - "jump to end of switch"]),
+        FinishCode = node([goto(code_label(EndLabel))
+            - "jump to end of switch"]),
         Code = tree_list([LabelCode, TraceCode, GoalCode, SaveCode,
              FinishCode])
     ;
Index: compiler/switch_gen.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/switch_gen.m,v
retrieving revision 1.99
diff -u -r1.99 switch_gen.m
--- compiler/switch_gen.m	22 Aug 2006 05:04:09 -0000	1.99
+++ compiler/switch_gen.m	13 Oct 2006 10:56:16 -0000
@@ -94,7 +94,7 @@
     % CanFail says whether the switch covers all cases.
 
     goal_info_get_store_map(GoalInfo, StoreMap),
-    SwitchCategory = determine_category(!.CI, CaseVar),
+    SwitchCategory = determine_switch_category(!.CI, CaseVar),
     code_info.get_next_label(EndLabel, !CI),
     lookup_tags(!.CI, Cases, CaseVar, TaggedCases0),
     list.sort_and_remove_dups(TaggedCases0, TaggedCases),
@@ -138,8 +138,8 @@
         NumCases >= DenseSize,
         globals.lookup_int_option(Globals, dense_switch_req_density,
             ReqDensity),
-        dense_switch.is_dense_switch(!.CI, CaseVar, TaggedCases,
-            CanFail, ReqDensity, FirstVal, LastVal, CanFail1)
+        cases_list_is_dense_switch(!.CI, CaseVar, TaggedCases, CanFail,
+            ReqDensity, FirstVal, LastVal, CanFail1)
     ->
         generate_dense_switch(TaggedCases, FirstVal, LastVal, CaseVar,
             CodeModel, CanFail1, GoalInfo, EndLabel, no, MaybeEnd, Code, !CI)
@@ -174,9 +174,9 @@
     % We categorize switches according to whether the value being switched on
     % is an atomic type, a string, or something more complicated.
     %
-:- func determine_category(code_info, prog_var) = switch_category.
+:- func determine_switch_category(code_info, prog_var) = switch_category.
 
-determine_category(CI, CaseVar) = SwitchCategory :-
+determine_switch_category(CI, CaseVar) = SwitchCategory :-
     Type = code_info.variable_type(CI, CaseVar),
     code_info.get_module_info(CI, ModuleInfo),
     classify_type(ModuleInfo, Type) = TypeCategory,
@@ -190,7 +190,7 @@
 lookup_tags(_, [], _, []).
 lookup_tags(CI, [Case | Cases], Var, [TaggedCase | TaggedCases]) :-
     Case = case(ConsId, Goal),
-    Tag = code_info.cons_id_to_tag(CI, Var, ConsId),
+    Tag = cons_id_to_tag_for_var(CI, Var, ConsId),
     Priority = switch_util.switch_priority(Tag),
     TaggedCase = extended_case(Priority, Tag, ConsId, Goal),
     lookup_tags(CI, Cases, Var, TaggedCases).
@@ -299,7 +299,7 @@
         code_gen.generate_goal(CodeModel, Goal, GoalCode, !CI),
         code_info.generate_branch_end(StoreMap, !MaybeEnd, SaveCode, !CI),
         ElseCode = node([
-            goto(label(EndLabel)) - "skip to the end of the switch",
+            goto(code_label(EndLabel)) - "skip to the end of the switch",
             label(NextLabel) - "next case"
         ]),
         ThisCaseCode = tree_list([TestCode, TraceCode, GoalCode, SaveCode,
Index: compiler/switch_util.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/switch_util.m,v
retrieving revision 1.35
diff -u -r1.35 switch_util.m
--- compiler/switch_util.m	27 Sep 2006 06:17:05 -0000	1.35
+++ compiler/switch_util.m	13 Oct 2006 10:46:49 -0000
@@ -69,6 +69,10 @@
 :- pred type_range(type_category::in, mer_type::in, module_info::in,
     int::out, int::out) is semidet.
 
+    % Calculate the percentage density given the range and the number of cases.
+    %
+:- func switch_density(int, int) = int.
+
 %-----------------------------------------------------------------------------%
 %
 % Stuff for string hash switches
@@ -80,7 +84,8 @@
 :- pred string_hash_cases(cases_list::in, int::in, map(int, cases_list)::out)
     is det.
 
-:- type hash_slot ---> hash_slot(extended_case, int).
+:- type hash_slot
+    --->    hash_slot(extended_case, int).
 
     % calc_hash_slots(AssocList, HashMap, Map):
     %
@@ -312,6 +317,9 @@
         unexpected(this_file, "type_range: enum type is not d.u. type?")
     ).
 
+switch_density(NumCases, Range) = Density :-
+    Density = (NumCases * 100) // Range.
+
 %-----------------------------------------------------------------------------%
 
 get_ptag_counts(Type, ModuleInfo, MaxPrimary, PtagCountMap) :-
Index: compiler/table_gen.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/table_gen.m,v
retrieving revision 1.123
diff -u -r1.123 table_gen.m
--- compiler/table_gen.m	13 Oct 2006 04:52:25 -0000	1.123
+++ compiler/table_gen.m	13 Oct 2006 07:36:29 -0000
@@ -694,7 +694,7 @@
         goal_info_get_instmap_delta(OrigGoalInfo, InstMapDelta),
         create_renaming(OutputVars, InstMapDelta, !VarSet, !VarTypes,
             Unifies, NewVars, Renaming),
-        rename_vars_in_goal(Renaming, OrigGoal, RenamedOrigGoal),
+        rename_some_vars_in_goal(Renaming, OrigGoal, RenamedOrigGoal),
 
         ThenGoalExpr = conj(plain_conj, Unifies ++ [MarkInactiveGoal]),
         ThenVars = [TableTipVar | OutputVars] ++ NewVars,
@@ -935,7 +935,7 @@
         CodeModel = model_semi,
         create_renaming(OutputVars, OrigInstMapDelta, !VarSet, !VarTypes,
             Unifies, NewVars, Renaming),
-        rename_vars_in_goal(Renaming, OrigGoal, RenamedOrigGoal),
+        rename_some_vars_in_goal(Renaming, OrigGoal, RenamedOrigGoal),
 
         ThenGoalExpr = conj(plain_conj, Unifies ++ SaveAnswerGoals),
         ThenVars = [TableTipVar | OutputVars] ++ NewVars,
Index: compiler/tag_switch.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/tag_switch.m,v
retrieving revision 1.74
diff -u -r1.74 tag_switch.m
--- compiler/tag_switch.m	22 Aug 2006 05:04:10 -0000	1.74
+++ compiler/tag_switch.m	13 Oct 2006 08:54:28 -0000
@@ -353,7 +353,7 @@
         TestRval = binop(ne, TagRval,
             unop(mktag, const(llconst_int(Primary)))),
         TestCode = node([
-            if_val(TestRval, label(ElseLabel)) - "test primary tag only"
+            if_val(TestRval, code_label(ElseLabel)) - "test primary tag only"
         ]),
         generate_primary_tag_code(StagGoalMap, Primary, MaxSecondary, StagLoc,
             VarRval, CodeModel, SwitchGoalInfo, EndLabel, FailLabel, !MaybeEnd,
@@ -373,7 +373,7 @@
             % so this goto will be optimized away (unless the
             % layout of the failcode in the caller changes).
             FailCode = node([
-                goto(label(FailLabel)) -
+                goto(code_label(FailLabel)) -
                     "primary tag with no code to handle it"
             ]),
             Code = tree(ThisTagCode, FailCode)
@@ -414,7 +414,8 @@
         TestRval = binop(eq, TagRval,
             unop(mktag, const(llconst_int(Primary)))),
         TestCode = node([
-            if_val(TestRval, label(ThisPtagLabel)) - "test primary tag only"
+            if_val(TestRval, code_label(ThisPtagLabel))
+                - "test primary tag only"
         ]),
         LabelCode = node([label(ThisPtagLabel) - "this primary tag"]),
         generate_primary_tag_code(StagGoalMap, Primary, MaxSecondary, StagLoc,
@@ -431,7 +432,7 @@
         ;
             PtagGroups = [],
             FailCode = node([
-                goto(label(FailLabel)) -
+                goto(code_label(FailLabel)) -
                     "primary tag with no code to handle it"
             ]),
             Code = tree(PrevTests, tree(FailCode, PrevCases))
@@ -532,7 +533,7 @@
                 CanFail = can_fail,
                 string.int_to_string(CurPrimary, PtagStr),
                 string.append("no code for ptag ", PtagStr, Comment),
-                Code = node([goto(label(FailLabel)) - Comment])
+                Code = node([goto(code_label(FailLabel)) - Comment])
             ;
                 CanFail = cannot_fail,
                 Code = empty
@@ -574,7 +575,7 @@
             " to ", HighEndStr], LabelComment),
         LowRangeEndConst = const(llconst_int(LowRangeEnd)),
         TestRval = binop(int_gt, PtagRval, LowRangeEndConst),
-        IfCode = node([if_val(TestRval, label(NewLabel)) - IfComment]),
+        IfCode = node([if_val(TestRval, code_label(NewLabel)) - IfComment]),
         LabelCode = node([label(NewLabel) - LabelComment]),
 
         code_info.remember_position(!.CI, BranchStart),
@@ -616,7 +617,8 @@
             goal_info_get_store_map(SwitchGoalInfo, StoreMap),
             code_info.generate_branch_end(StoreMap, !MaybeEnd, SaveCode, !CI),
             GotoCode = node([
-                goto(label(EndLabel)) - "skip to end of primary tag switch"
+                goto(code_label(EndLabel))
+                    - "skip to end of primary tag switch"
             ]),
             Code = tree_list([CommentCode, TraceCode, GoalCode, SaveCode,
                 GotoCode])
@@ -746,7 +748,7 @@
         code_info.get_next_label(ElseLabel, !CI),
         TestCode = node([
             if_val(binop(ne, StagRval, const(llconst_int(Secondary))),
-                label(ElseLabel))
+                code_label(ElseLabel))
                 - "test remote sec tag only"
         ]),
         maybe_generate_internal_event_code(Goal, SwitchGoalInfo, TraceCode,
@@ -755,7 +757,7 @@
         code_info.generate_branch_end(StoreMap, !MaybeEnd,
             SaveCode, !CI),
         GotoLabelCode = node([
-            goto(label(EndLabel)) - "skip to end of secondary tag switch",
+            goto(code_label(EndLabel)) - "skip to end of secondary tag switch",
             label(ElseLabel) - "handle next secondary tag"
         ]),
         ThisCode = tree_list([TestCode, CommentCode, TraceCode, GoalCode,
@@ -770,7 +772,7 @@
         ;
             Cases0 = [],
             FailCode = node([
-                goto(label(FailLabel)) - "secondary tag does not match"
+                goto(code_label(FailLabel)) - "secondary tag does not match"
             ]),
             Code = tree(ThisCode, FailCode)
         )
@@ -780,7 +782,7 @@
         code_gen.generate_goal(CodeModel, Goal, GoalCode, !CI),
         code_info.generate_branch_end(StoreMap, !MaybeEnd, SaveCode, !CI),
         GotoCode = node([
-            goto(label(EndLabel)) - "skip to end of secondary tag switch"
+            goto(code_label(EndLabel)) - "skip to end of secondary tag switch"
         ]),
         Code = tree_list([CommentCode, TraceCode, GoalCode, SaveCode,
             GotoCode])
@@ -812,7 +814,7 @@
         code_info.get_next_label(ThisStagLabel, !CI),
         TestCode = node([
             if_val(binop(eq, StagRval, const(llconst_int(Secondary))),
-                label(ThisStagLabel))
+                code_label(ThisStagLabel))
                 - ("test remote sec tag only for " ++ Comment)
         ]),
         LabelCode = node([
@@ -824,7 +826,7 @@
         code_gen.generate_goal(CodeModel, Goal, GoalCode, !CI),
         code_info.generate_branch_end(StoreMap, !MaybeEnd, SaveCode, !CI),
         GotoCode = node([
-            goto(label(EndLabel)) - "skip to end of secondary tag switch"
+            goto(code_label(EndLabel)) - "skip to end of secondary tag switch"
         ]),
         ThisCode = tree_list([LabelCode, TraceCode, GoalCode, SaveCode,
             GotoCode]),
@@ -839,7 +841,7 @@
         ;
             Cases0 = [],
             FailCode = node([
-                goto(label(FailLabel)) -
+                goto(code_label(FailLabel)) -
                     "secondary tag with no code to handle it"
             ]),
             Code = tree(PrevTests, tree(FailCode, PrevCases))
@@ -851,7 +853,7 @@
         code_gen.generate_goal(CodeModel, Goal, GoalCode, !CI),
         code_info.generate_branch_end(StoreMap, !MaybeEnd, SaveCode, !CI),
         GotoCode = node([
-            goto(label(EndLabel)) - "skip to end of secondary tag switch"
+            goto(code_label(EndLabel)) - "skip to end of secondary tag switch"
         ]),
         Code = tree_list([PrevTests0, CommentCode, TraceCode, GoalCode,
             SaveCode, GotoCode, PrevCases0])
@@ -896,7 +898,7 @@
                 code_info.reset_to_position(BranchStart, !CI)
             ),
             GotoCode = node([
-                goto(label(EndLabel)) - "branch to end of tag switch"
+                goto(code_label(EndLabel)) - "branch to end of tag switch"
             ]),
             generate_secondary_jump_table(CaseList1, NextSecondary,
                 MaxSecondary, CodeModel, SwitchGoalInfo, EndLabel, FailLabel,
@@ -936,7 +938,7 @@
                 CanFail = can_fail,
                 string.int_to_string(CurSec, StagStr),
                 string.append("no code for ptag ", StagStr, Comment),
-                Code = node([goto(label(FailLabel)) - Comment])
+                Code = node([goto(code_label(FailLabel)) - Comment])
             ;
                 CanFail = cannot_fail,
                 Code = empty
@@ -978,7 +980,7 @@
             " to ", HighEndStr], LabelComment),
         LowRangeEndConst = const(llconst_int(LowRangeEnd)),
         TestRval = binop(int_gt, StagRval, LowRangeEndConst),
-        IfCode = node([if_val(TestRval, label(NewLabel)) - IfComment]),
+        IfCode = node([if_val(TestRval, code_label(NewLabel)) - IfComment]),
         LabelCode = node([label(NewLabel) - LabelComment ]),
 
         code_info.remember_position(!.CI, BranchStart),
Index: compiler/term_constr_pass2.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/term_constr_pass2.m,v
retrieving revision 1.7
diff -u -r1.7 term_constr_pass2.m
--- compiler/term_constr_pass2.m	20 Aug 2006 08:21:32 -0000	1.7
+++ compiler/term_constr_pass2.m	13 Oct 2006 08:18:27 -0000
@@ -670,8 +670,8 @@
 write_cycle([], _, !IO).
 write_cycle([ Proc | Procs ], ModuleInfo, !IO) :- 
     io.write_string("\t- ", !IO),
-    Proc = real(proc(PredId, ProcId)),
-    hlds_out.write_pred_proc_id(ModuleInfo, PredId, ProcId, !IO),
+    Proc = real(PredProcId),
+    hlds_out.write_pred_proc_id(ModuleInfo, PredProcId, !IO),
     io.nl(!IO),
     write_cycle(Procs, ModuleInfo, !IO).
 
@@ -680,16 +680,16 @@
 
 write_edge(ModuleInfo, Varset, Edge, !IO) :- 
     io.write_string("Edge is:\n\tHead: ", !IO),
-    Edge ^ head = real(proc(PredId, ProcId)),
-    hlds_out.write_pred_proc_id(ModuleInfo, PredId, ProcId, !IO),
+    Edge ^ head = real(PredProcId),
+    hlds_out.write_pred_proc_id(ModuleInfo, PredProcId, !IO),
     io.write_string(" : ", !IO),
     write_size_vars(Varset, Edge ^ head_args, !IO),
     io.write_string(" :- \n", !IO),
     io.write_string("\tConstraints are:  \n", !IO),
     write_polyhedron(Edge ^ label, Varset, !IO),
     io.write_string("\n\tCall is:  ", !IO),
-    Edge ^ callee = real(proc(CallPredId, CallProcId)),
-    hlds_out.write_pred_proc_id(ModuleInfo, CallPredId, CallProcId, !IO),
+    Edge ^ callee = real(CallPredProcId),
+    hlds_out.write_pred_proc_id(ModuleInfo, CallPredProcId, !IO),
     io.write_string(" : ", !IO),
     write_size_vars(Varset, Edge ^ call_args, !IO),
     io.write_string(" :- \n", !IO),
Index: compiler/trace_gen.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/trace_gen.m,v
retrieving revision 1.7
diff -u -r1.7 trace_gen.m
--- compiler/trace_gen.m	29 Sep 2006 06:34:50 -0000	1.7
+++ compiler/trace_gen.m	13 Oct 2006 11:08:06 -0000
@@ -303,7 +303,7 @@
         eff_trace_level_is_none(PredInfo0, !.ProcInfo, TraceLevel) = no,
         CodeModel \= model_non,
         proc_info_get_goal(!.ProcInfo, Goal),
-        code_util.goal_may_alloc_temp_frame(Goal)
+        code_util.goal_may_alloc_temp_frame(Goal, yes)
     ->
         MaxfrFlag = yes
     ;
Index: compiler/transform_llds.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/transform_llds.m,v
retrieving revision 1.28
diff -u -r1.28 transform_llds.m
--- compiler/transform_llds.m	22 Aug 2006 05:04:11 -0000	1.28
+++ compiler/transform_llds.m	13 Oct 2006 09:25:55 -0000
@@ -5,10 +5,10 @@
 % This file may only be copied under the terms of the GNU General
 % Public License - see the file COPYING in the Mercury distribution.
 %-----------------------------------------------------------------------------%
-% 
+%
 % File: transform_llds.
 % Main author: petdr.
-% 
+%
 % This module does source to source transformations of the llds data
 % structure. This is sometimes necessary to avoid limits in some compilers.
 %
@@ -17,7 +17,7 @@
 %
 % If accurate GC is enabled, we also append a module containing an end label
 % to the list of comp_gen_c_modules.
-% 
+%
 %-----------------------------------------------------------------------------%
 
 :- module ll_backend.transform_llds.
@@ -120,7 +120,7 @@
     PredName = "ACCURATE_GC_END_LABEL",
     ProcLabel = ordinary_proc_label(ModuleName, predicate, ModuleName,
         PredName, Arity, proc_id_to_int(ProcId)),
-    Instrs = [label(entry(entry_label_local, ProcLabel)) -
+    Instrs = [label(entry_label(entry_label_local, ProcLabel)) -
         "label to indicate end of previous procedure"],
     DummyProc = c_procedure(PredName, Arity, proc(PredId, ProcId), model_det,
         Instrs, ProcLabel, counter.init(0), must_not_alter_rtti, set.init),
@@ -213,9 +213,9 @@
 
         Index     = binop(int_sub, Rval, const(llconst_int(Mid))),
         Test      = binop(int_ge,  Rval, const(llconst_int(Mid))),
-        ElseAddr  = label(internal(LabelNum, ProcLabel)),
+        ElseAddr  = code_label(internal_label(LabelNum, ProcLabel)),
         IfInstr   = if_val(Test, ElseAddr) - "binary search",
-        ElseInstr = label(internal(LabelNum, ProcLabel)) - "",
+        ElseInstr = label(internal_label(LabelNum, ProcLabel)) - "",
 
         split_computed_goto(Rval, Start, Comment ++ " then",
             ThenInstrs, !C, MaxSize, Mid, ProcLabel),
Index: compiler/tupling.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/tupling.m,v
retrieving revision 1.32
diff -u -r1.32 tupling.m
--- compiler/tupling.m	2 Oct 2006 05:21:28 -0000	1.32
+++ compiler/tupling.m	13 Oct 2006 10:43:11 -0000
@@ -259,9 +259,7 @@
         VeryVerbose = yes,
         io.write_string("% Considering tupling in ", !IO),
         list.foldl((pred(PredProcId::in, IO0::di, IO::uo) is det :-
-            PredProcId = proc(PredId, ProcId),
-            hlds_out.write_pred_proc_id(!.ModuleInfo,
-                PredId, ProcId, IO0, IO)),
+            hlds_out.write_pred_proc_id(!.ModuleInfo, PredProcId, IO0, IO)),
             SCC, !IO),
         io.write_string("\n", !IO)
     ;
@@ -699,7 +697,7 @@
     insert_proc_start_deconstruction(Goal1, Goal2,
         VarSet1, VarSet, VarTypes1, VarTypes,
         RenameMapB, ProcStartInsert),
-    rename_vars_in_goal(RenameMapB, Goal2, Goal3),
+    rename_some_vars_in_goal(RenameMapB, Goal2, Goal3),
 
     map.old_merge(RenameMapA, RenameMapB, RenameMap),
     apply_headvar_correction(set.from_list(HeadVars), RenameMap, Goal3, Goal),
@@ -876,7 +874,7 @@
         OptTupleAlloc0 = opt_tuple_alloc,
         set.init(FailVars),
         set.init(NondetLiveness0),
-        build_live_sets_in_goal(Goal0, Goal, FailVars, AllocData,
+        build_live_sets_in_goal_no_par_stack(Goal0, Goal, FailVars, AllocData,
             OptTupleAlloc0, _OptTupleAlloc, Liveness0, _Liveness,
             NondetLiveness0, _NondetLiveness),
         proc_info_set_goal(Goal, !ProcInfo),
Index: compiler/unify_gen.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/unify_gen.m,v
retrieving revision 1.172
diff -u -r1.172 unify_gen.m
--- compiler/unify_gen.m	2 Oct 2006 05:21:29 -0000	1.172
+++ compiler/unify_gen.m	13 Oct 2006 10:53:43 -0000
@@ -234,14 +234,14 @@
         string.append_list(["checking that ", VarName, " has functor ",
             ConsIdName], Comment),
         CommentCode = node([comment(Comment) - ""]),
-        Tag = code_info.cons_id_to_tag(!.CI, Var, ConsId),
+        Tag = cons_id_to_tag_for_var(!.CI, Var, ConsId),
         generate_tag_test_rval_2(Tag, Rval, TestRval)
     ;
         Reverse = yes(TestConsId),
         string.append_list(["checking that ", VarName, " has functor ",
             ConsIdName, " (inverted test)"], Comment),
         CommentCode = node([comment(Comment) - ""]),
-        Tag = code_info.cons_id_to_tag(!.CI, Var, TestConsId),
+        Tag = cons_id_to_tag_for_var(!.CI, Var, TestConsId),
         generate_tag_test_rval_2(Tag, Rval, NegTestRval),
         code_util.neg_rval(NegTestRval, TestRval)
     ),
@@ -253,7 +253,7 @@
         Sense = branch_on_failure,
         code_util.neg_rval(TestRval, TheRval)
     ),
-    TestCode = node([if_val(TheRval, label(ElseLab)) - "tag test"]),
+    TestCode = node([if_val(TheRval, code_label(ElseLab)) - "tag test"]),
     Code = tree(VarCode, tree(CommentCode, TestCode)).
 
 %---------------------------------------------------------------------------%
@@ -263,7 +263,7 @@
 
 generate_tag_test_rval(Var, ConsId, TestRval, Code, !CI) :-
     code_info.produce_variable(Var, Code, Rval, !CI),
-    Tag = code_info.cons_id_to_tag(!.CI, Var, ConsId),
+    Tag = cons_id_to_tag_for_var(!.CI, Var, ConsId),
     generate_tag_test_rval_2(Tag, Rval, TestRval).
 
 :- pred generate_tag_test_rval_2(cons_tag::in, rval::in, rval::out)
@@ -367,7 +367,7 @@
 
 generate_construction(Var, ConsId, Args, Modes, TakeAddr, MaybeSize, GoalInfo,
         Code, !CI) :-
-    Tag = code_info.cons_id_to_tag(!.CI, Var, ConsId),
+    Tag = cons_id_to_tag_for_var(!.CI, Var, ConsId),
     generate_construction_2(Tag, Var, Args, Modes, TakeAddr, MaybeSize,
         GoalInfo, Code, !CI).
 
@@ -631,7 +631,7 @@
                 % It is possible for the number of hidden arguments to be zero,
                 % in which case the body of this loop should not be executed
                 % at all. This is why we jump to the loop condition test.
-                goto(label(LoopTest))
+                goto(code_label(LoopTest))
                     - ("enter the copy loop at the conceptual top"),
                 label(LoopStart) - "start of loop",
                 assign(field(yes(0), lval(NewClosure), lval(LoopCounter)),
@@ -642,7 +642,7 @@
                 label(LoopTest)
                     - ("do we have more old arguments to copy?"),
                 if_val(binop(int_lt, lval(LoopCounter), lval(NumOldArgs)),
-                    label(LoopStart))
+                    code_label(LoopStart))
                     - "repeat the loop?"
             ]),
             generate_extra_closure_args(CallArgs, LoopCounter, NewClosure,
@@ -655,9 +655,8 @@
                  AssignCode])
         )
     ;
-        CodeAddr = code_info.make_entry_label(!.CI, ModuleInfo,
-            PredId, ProcId, no),
-        code_util.extract_proc_label_from_code_addr(CodeAddr, ProcLabel),
+        CodeAddr = make_proc_entry_label(!.CI, ModuleInfo, PredId, ProcId, no),
+        ProcLabel = extract_proc_label_from_code_addr(CodeAddr),
         CodeAddrRval = const(llconst_code_addr(CodeAddr)),
         continuation_info.generate_closure_layout( ModuleInfo, PredId, ProcId,
             ClosureInfo),
@@ -897,7 +896,7 @@
     code_info::in, code_info::out) is det.
 
 generate_det_deconstruction(Var, Cons, Args, Modes, Code, !CI) :-
-    Tag = code_info.cons_id_to_tag(!.CI, Var, Cons),
+    Tag = cons_id_to_tag_for_var(!.CI, Var, Cons),
     generate_det_deconstruction_2(Var, Cons, Args, Modes, Tag, Code, !CI).
 
 :- pred generate_det_deconstruction_2(prog_var::in, cons_id::in,
Index: compiler/unify_proc.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/unify_proc.m,v
retrieving revision 1.176
diff -u -r1.176 unify_proc.m
--- compiler/unify_proc.m	13 Oct 2006 04:52:27 -0000	1.176
+++ compiler/unify_proc.m	13 Oct 2006 08:15:52 -0000
@@ -418,8 +418,7 @@
         ;
             io.write_string("% Mode-analyzing ", !IO)
         ),
-        PredProcId = proc(PredId, ProcId),
-        hlds_out.write_pred_proc_id(ModuleInfo, PredId, ProcId, !IO),
+        hlds_out.write_pred_proc_id(ModuleInfo, PredProcId, !IO),
         io.write_string("\n", !IO)
 %       /*****
 %       mode_list_get_initial_insts(Modes, ModuleInfo1,
@@ -728,7 +727,8 @@
         InitGoal = InitCall - GoalInfo,
 
         Any = any(shared),
-        generate_cast(equiv_type_cast, X0, X, Any, Any, Context, CastGoal),
+        generate_cast_with_insts(equiv_type_cast, X0, X, Any, Any, Context,
+            CastGoal),
         Goal = conj(plain_conj, [InitGoal, CastGoal]) - GoalInfo,
         quantify_clauses_body([X], Goal, Context, Clauses, !Info)
     ;
Index: compiler/unneeded_code.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/unneeded_code.m,v
retrieving revision 1.37
diff -u -r1.37 unneeded_code.m
--- compiler/unneeded_code.m	22 Aug 2006 05:04:14 -0000	1.37
+++ compiler/unneeded_code.m	13 Oct 2006 08:18:48 -0000
@@ -220,7 +220,7 @@
     (
         VeryVerbose = yes,
         io.write_string("% Removing dead code in ", !IO),
-        hlds_out.write_pred_proc_id(!.ModuleInfo, PredId, ProcId, !IO),
+        hlds_out.write_pred_proc_id_pair(!.ModuleInfo, PredId, ProcId, !IO),
         io.write_string(": ", !IO),
         pre_process_proc(!ProcInfo),
         process_proc(!ProcInfo, !ModuleInfo, Successful),
Index: compiler/var_locn.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/var_locn.m,v
retrieving revision 1.45
diff -u -r1.45 var_locn.m
--- compiler/var_locn.m	29 Sep 2006 06:34:51 -0000	1.45
+++ compiler/var_locn.m	13 Oct 2006 10:36:45 -0000
@@ -40,7 +40,7 @@
 
 :- type var_locn_info.
 
-    % init_state(Arguments, Liveness, VarSet, VarTypes, StackSlots,
+    % init_var_locn_state(Arguments, Liveness, VarSet, VarTypes, StackSlots,
     %   FollowVars, Opts, VarLocnInfo):
     %
     % Produces an initial state of the VarLocnInfo given
@@ -58,11 +58,11 @@
     % the table of options; this is used to decide what expressions
     % are considered constants.
     %
-:- pred init_state(assoc_list(prog_var, lval)::in, set(prog_var)::in,
+:- pred init_var_locn_state(assoc_list(prog_var, lval)::in, set(prog_var)::in,
     prog_varset::in, vartypes::in, stack_slots::in, abs_follow_vars::in,
     option_table::in, var_locn_info::out) is det.
 
-    % reinit_state(VarLocs, !VarLocnInfo):
+    % reinit_var_locn_state(VarLocs, !VarLocnInfo):
     %
     % Produces a new state of the VarLocnInfo in which the static
     % and mostly static information (stack slot map, follow vars map,
@@ -72,90 +72,90 @@
     % association list of variables and lvals. The new state
     % places the given variables at their corresponding locations.
     %
-:- pred reinit_state(assoc_list(prog_var, lval)::in,
+:- pred reinit_var_locn_state(assoc_list(prog_var, lval)::in,
     var_locn_info::in, var_locn_info::out) is det.
 
-    % clobber_all_regs(OkToDeleteAny, !VarLocnInfo):
+    % var_locn_clobber_all_regs(OkToDeleteAny, !VarLocnInfo):
     %
     % Modifies VarLocnInfo to show that all variables stored in registers
     % have been clobbered. Aborts if this deletes the last record of the
     % state of a variable unless OkToDeleteAny is `yes'.
     %
-:- pred clobber_all_regs(bool::in,
+:- pred var_locn_clobber_all_regs(bool::in,
     var_locn_info::in, var_locn_info::out) is det.
 
-    % clobber_regs(Regs, !VarLocnInfo):
+    % var_locn_clobber_regs(Regs, !VarLocnInfo):
     %
     % Modifies VarLocnInfo to show that all variables stored in Regs
     % (a list of lvals which should contain only registers) are clobbered.
     %
-:- pred clobber_regs(list(lval)::in,
+:- pred var_locn_clobber_regs(list(lval)::in,
     var_locn_info::in, var_locn_info::out) is det.
 
-    % set_magic_var_location(Var, Lval, !VarLocnInfo):
+    % var_locn_set_magic_var_location(Var, Lval, !VarLocnInfo):
     %
     % Updates !VarLocnInfo to show that Var is *magically* stored in Lval.
     % Does not care if Lval is already in use; it overwrites it with the
     % new information. Var must not have been previously known. Used to
     % implement the ends of erroneous branches.
     %
-:- pred set_magic_var_location(prog_var::in, lval::in,
+:- pred var_locn_set_magic_var_location(prog_var::in, lval::in,
     var_locn_info::in, var_locn_info::out) is det.
 
-    % check_and_set_magic_var_location(Var, Lval, !VarLocnInfo):
+    % var_locn_check_and_set_magic_var_location(Var, Lval, !VarLocnInfo):
     %
     % Updates VarLocnInfo to show that Var has been *magically* stored in Lval.
     % (The caller usually generates code to perform this magic.) Aborts if Lval
     % is already in use, or if Var was previously known.
     %
-:- pred check_and_set_magic_var_location(prog_var::in, lval::in,
+:- pred var_locn_check_and_set_magic_var_location(prog_var::in, lval::in,
     var_locn_info::in, var_locn_info::out) is det.
 
-    % lval_in_use(VarLocnInfo, Lval):
+    % var_locn_lval_in_use(VarLocnInfo, Lval):
     %
     % Succeeds iff Lval, which should be a register or stack slot,
     % holds (a path to) a variable or is otherwise reserved.
     %
-:- pred lval_in_use(var_locn_info::in, lval::in) is semidet.
+:- pred var_locn_lval_in_use(var_locn_info::in, lval::in) is semidet.
 
-    % var_becomes_dead(Var, FirstTime, !VarLocnInfo):
+    % var_locn_var_becomes_dead(Var, FirstTime, !VarLocnInfo):
     %
     % Frees any code generator resources used by Var in !VarLocnInfo.
     % FirstTime should be no if this same operation may already have been
     % executed on Var; otherwise, var_becomes_dead will throw an exception
     % if it does not know about Var.
     %
-:- pred var_becomes_dead(prog_var::in, bool::in,
+:- pred var_locn_var_becomes_dead(prog_var::in, bool::in,
     var_locn_info::in, var_locn_info::out) is det.
 
-    % assign_var_to_var(Var, AssignedVar, !VarLocnInfo):
+    % var_locn_assign_var_to_var(Var, AssignedVar, !VarLocnInfo):
     %
     % Reflects the effect of the assignment Var := AssignedVar in the
     % state of !VarLocnInfo.
     %
-:- pred assign_var_to_var(prog_var::in, prog_var::in,
+:- pred var_locn_assign_var_to_var(prog_var::in, prog_var::in,
     var_locn_info::in, var_locn_info::out) is det.
 
-    % assign_lval_to_var(ModuleInfo, Var, Lval, StaticCellInfo, Code,
+    % var_locn_assign_lval_to_var(ModuleInfo, Var, Lval, StaticCellInfo, Code,
     %   !VarLocnInfo);
     %
     % Reflects the effect of the assignment Var := lval(Lval) in the
     % state of !VarLocnInfo; any code required to effect the assignment
     % will be returned in Code.
     %
-:- pred assign_lval_to_var(module_info::in, prog_var::in, lval::in,
+:- pred var_locn_assign_lval_to_var(module_info::in, prog_var::in, lval::in,
     static_cell_info::in, code_tree::out,
     var_locn_info::in, var_locn_info::out) is det.
 
-    % assign_const_to_var(Var, ConstRval, !VarLocnInfo):
+    % var_locn_assign_const_to_var(Var, ConstRval, !VarLocnInfo):
     %
     % Reflects the effect of the assignment Var := const(ConstRval)
     % in the state of !VarLocnInfo.
     %
-:- pred assign_const_to_var(prog_var::in, rval::in,
+:- pred var_locn_assign_const_to_var(prog_var::in, rval::in,
     var_locn_info::in, var_locn_info::out) is det.
 
-    % assign_expr_to_var(Var, Rval, Code, !VarLocnInfo):
+    % var_locn_assign_expr_to_var(Var, Rval, Code, !VarLocnInfo):
     %
     % Generates code to execute the assignment Var := Expr, and
     % updates the state of !VarLocnInfo accordingly.
@@ -163,11 +163,12 @@
     % Expr must contain no lvals, although it may (and typically will) refer
     % to the values of other variables through rvals of the form var(_).
     %
-:- pred assign_expr_to_var(prog_var::in, rval::in, code_tree::out,
+:- pred var_locn_assign_expr_to_var(prog_var::in, rval::in, code_tree::out,
     var_locn_info::in, var_locn_info::out) is det.
 
-    % assign_cell_to_var(ModuleInfo, Var, ReserveWordAtStart, Ptag, Vector,
-    %   SizeInfo, TypeMsg, MayUseAtomic, Code, !StaticCellInfo, !VarLocnInfo):
+    % var_locn_assign_cell_to_var(ModuleInfo, Var, ReserveWordAtStart, Ptag,
+    %   Vector, SizeInfo, TypeMsg, MayUseAtomic, Code, !StaticCellInfo,
+    %   !VarLocnInfo):
     %
     % Generates code to assign to Var a pointer, tagged by Ptag, to the cell
     % whose contents are given by the other arguments, and updates the state
@@ -181,29 +182,29 @@
     % and SizeInfo should not be yes / yes(_), because that will cause an
     % obvious conflict.)
     %
-:- pred assign_cell_to_var(module_info::in, prog_var::in, bool::in, tag::in,
-    list(maybe(rval))::in, maybe(term_size_value)::in, string::in,
+:- pred var_locn_assign_cell_to_var(module_info::in, prog_var::in, bool::in,
+    tag::in, list(maybe(rval))::in, maybe(term_size_value)::in, string::in,
     may_use_atomic_alloc::in, code_tree::out,
     static_cell_info::in, static_cell_info::out,
     var_locn_info::in, var_locn_info::out) is det.
 
-    % place_var(ModuleInfo, Var, Lval, Code, !VarLocnInfo):
+    % var_locn_place_var(ModuleInfo, Var, Lval, Code, !VarLocnInfo):
     %
     % Produces Code to place the value of Var in Lval, and update !VarLocnInfo
     % to reflect this.
     %
-:- pred place_var(module_info::in, prog_var::in, lval::in, code_tree::out,
-    var_locn_info::in, var_locn_info::out) is det.
+:- pred var_locn_place_var(module_info::in, prog_var::in, lval::in,
+    code_tree::out, var_locn_info::in, var_locn_info::out) is det.
 
-    % place_vars(ModuleInfo, VarLocns, Code, !VarLocnInfo):
+    % var_locn_place_vars(ModuleInfo, VarLocns, Code, !VarLocnInfo):
     %
     % Produces Code to place the value of each variable mentioned in VarLocns
     % into the corresponding location, and update !VarLocnInfo to reflect this.
     %
-:- pred place_vars(module_info::in, assoc_list(prog_var, lval)::in,
+:- pred var_locn_place_vars(module_info::in, assoc_list(prog_var, lval)::in,
     code_tree::out, var_locn_info::in, var_locn_info::out) is det.
 
-    % produce_var(ModuleInfo, Var, Rval, Code, !VarLocnInfo):
+    % var_locn_produce_var(ModuleInfo, Var, Rval, Code, !VarLocnInfo):
     %
     % Return the preferred way to refer to the value of Var
     % (which may be a const rval, or the value in an lval).
@@ -215,88 +216,89 @@
     % number of operations, from being evaluated several times.) Otherwise,
     % Code will be empty.
     %
-:- pred produce_var(module_info::in, prog_var::in, rval::out, code_tree::out,
-    var_locn_info::in, var_locn_info::out) is det.
+:- pred var_locn_produce_var(module_info::in, prog_var::in, rval::out,
+    code_tree::out, var_locn_info::in, var_locn_info::out) is det.
 
-    % produce_var_in_reg(ModuleInfo, Var, Lval, Code, !VarLocnInfo):
+    % var_locn_produce_var_in_reg(ModuleInfo, Var, Lval, Code, !VarLocnInfo):
     %
     % Produces a code fragment Code to evaluate Var if necessary
     % and provide it as an Lval of the form reg(_).
     %
-:- pred produce_var_in_reg(module_info::in, prog_var::in, lval::out,
+:- pred var_locn_produce_var_in_reg(module_info::in, prog_var::in, lval::out,
     code_tree::out, var_locn_info::in, var_locn_info::out) is det.
 
-    % produce_var_in_reg_or_stack(ModuleInfo, Var, FollowVars, Lval, Code,
-    %   !VarLocnInfo):
+    % var_locn_produce_var_in_reg_or_stack(ModuleInfo, Var, FollowVars, Lval,
+    %   Code, !VarLocnInfo):
     %
     % Produces a code fragment Code to evaluate Var if necessary and provide it
     % as an Lval of the form reg(_), stackvar(_), or framevar(_).
     %
-:- pred produce_var_in_reg_or_stack(module_info::in, prog_var::in, lval::out,
-    code_tree::out, var_locn_info::in, var_locn_info::out) is det.
+:- pred var_locn_produce_var_in_reg_or_stack(module_info::in, prog_var::in,
+    lval::out, code_tree::out, var_locn_info::in, var_locn_info::out) is det.
 
-    % acquire_reg(Lval, !VarLocnInfo):
+    % var_locn_acquire_reg(Lval, !VarLocnInfo):
     %
     % Finds an unused register and marks it as 'in use'.
     %
-:- pred acquire_reg(lval::out,
+:- pred var_locn_acquire_reg(lval::out,
     var_locn_info::in, var_locn_info::out) is det.
 
-    % acquire_reg_require_given(Reg, Lval, !VarLocInfo):
+    % var_locn_acquire_reg_require_given(Reg, Lval, !VarLocInfo):
     %
     % Marks Reg, which must be an unused register, as 'in use'.
     %
-:- pred acquire_reg_require_given(lval::in,
+:- pred var_locn_acquire_reg_require_given(lval::in,
     var_locn_info::in, var_locn_info::out) is det.
 
-    % acquire_reg_prefer_given(Pref, Lval, !VarLocInfo):
+    % var_locn_acquire_reg_prefer_given(Pref, Lval, !VarLocInfo):
     %
     % Finds an unused register, and marks it as 'in use'.
     % If Pref itself is free, assigns that.
     %
-:- pred acquire_reg_prefer_given(int::in, lval::out,
+:- pred var_locn_acquire_reg_prefer_given(int::in, lval::out,
     var_locn_info::in, var_locn_info::out) is det.
 
-    % acquire_reg_start_at_given(Start, Lval, !VarLocInfo):
+    % var_locn_acquire_reg_start_at_given(Start, Lval, !VarLocInfo):
     %
     % Finds an unused register, and marks it as 'in use'.
     % It starts the search at the one numbered Start,
     % continuing towards higher register numbers.
     %
-:- pred acquire_reg_start_at_given(int::in, lval::out,
+:- pred var_locn_acquire_reg_start_at_given(int::in, lval::out,
     var_locn_info::in, var_locn_info::out) is det.
 
-    % release_reg(Lval, !VarLocnInfo):
+    % var_locn_release_reg(Lval, !VarLocnInfo):
     %
     % Marks a previously acquired reg as no longer 'in use'.
     %
-:- pred release_reg(lval::in, var_locn_info::in, var_locn_info::out) is det.
+:- pred var_locn_release_reg(lval::in, var_locn_info::in, var_locn_info::out)
+    is det.
 
-    % lock_regs(N, Exceptions, !VarLocnInfo):
+    % var_locn_lock_regs(N, Exceptions, !VarLocnInfo):
     %
     % Prevents registers r1 through rN from being reused, even if there are
     % no variables referring to them, with the exceptions of the registers
     % named in Exceptions, which however can only be used to store their
     % corresponding variables. Should be followed by a call to unlock_regs.
     %
-:- pred lock_regs(int::in, assoc_list(prog_var, lval)::in,
+:- pred var_locn_lock_regs(int::in, assoc_list(prog_var, lval)::in,
     var_locn_info::in, var_locn_info::out) is det.
 
-    % unlock_regs(!VarLocnInfo):
+    % var_locn_unlock_regs(!VarLocnInfo):
     %
     % Undoes a lock operation.
     %
-:- pred unlock_regs(var_locn_info::in, var_locn_info::out) is det.
+:- pred var_locn_unlock_regs(var_locn_info::in, var_locn_info::out) is det.
 
-    % clear_r1(ModuleInfo, Code, !VarLocnInfo):
+    % var_locn_clear_r1(ModuleInfo, Code, !VarLocnInfo):
     %
     % Produces a code fragment Code to move whatever is in r1 to some other
     % register, if r1 is live. This is used prior to semidet pragma c_codes.
     %
-:- pred clear_r1(module_info::in, code_tree::out,
+:- pred var_locn_clear_r1(module_info::in, code_tree::out,
     var_locn_info::in, var_locn_info::out) is det.
 
-    % materialize_vars_in_lval(ModuleInfo, Lval, FinalLval, Code,
+    % var_locn_materialize_vars_in_lval(ModuleInfo, Lval, FinalLval, Code,
     %   !VarLocnInfo):
     %
     % For every variable in Lval, substitutes the value of the variable and
@@ -305,52 +307,53 @@
     % evaluated again (and again ...), the required code will be returned
     % in Code.
     %
-:- pred materialize_vars_in_lval(module_info::in, lval::in, lval::out,
+:- pred var_locn_materialize_vars_in_lval(module_info::in, lval::in, lval::out,
     code_tree::out, var_locn_info::in, var_locn_info::out) is det.
 
-    % get_var_locations(VarLocnInfo, Locations):
+    % var_locn_get_var_locations(VarLocnInfo, Locations):
     %
     % Returns a map from each live variable that occurs in VarLocnInfo
     % to the set of locations in which it may be found (which may be empty,
     % if the variable's value is either a known constant, or an as-yet
     % unevaluated expression).
     %
-:- pred get_var_locations(var_locn_info::in, map(prog_var, set(lval))::out)
-    is det.
+:- pred var_locn_get_var_locations(var_locn_info::in,
+    map(prog_var, set(lval))::out) is det.
 
-    % get_stack_slots(VarLocnInfo, StackSlots):
+    % var_locn_get_stack_slots(VarLocnInfo, StackSlots):
     %
     % Returns the table mapping each variable to its stack slot (if any).
     %
-:- pred get_stack_slots(var_locn_info::in, stack_slots::out) is det.
+:- pred var_locn_get_stack_slots(var_locn_info::in, stack_slots::out) is det.
 
-    % get_follow_vars(VarLocnInfo, FollowVars):
+    % var_locn_get_follow_var_map(VarLocnInfo, FollowVars):
     %
     % Returns the table mapping each variable to the lval (if any)
     % where it is desired next.
     %
-:- pred get_follow_var_map(var_locn_info::in, abs_follow_vars_map::out) is det.
+:- pred var_locn_get_follow_var_map(var_locn_info::in,
+    abs_follow_vars_map::out) is det.
 
-    % get_next_non_reserved(VarLocnInfo, NonRes):
+    % var_locn_get_next_non_reserved(VarLocnInfo, NonRes):
     %
     % Returns the number of the first register which is free for general use.
     % It does not reserve the register.
     %
-:- pred get_next_non_reserved(var_locn_info::in, int::out) is det.
+:- pred var_locn_get_next_non_reserved(var_locn_info::in, int::out) is det.
 
-    % set_follow_vars(FollowVars):
+    % var_locn_set_follow_vars(FollowVars):
     %
     % Sets the table mapping each variable to the lval (if any) where it is
     % desired next, and the number of the first non-reserved register.
     %
-:- pred set_follow_vars(abs_follow_vars::in,
+:- pred var_locn_set_follow_vars(abs_follow_vars::in,
     var_locn_info::in, var_locn_info::out) is det.
 
-    % max_reg_in_use(MaxReg):
+    % var_locn_max_reg_in_use(MaxReg):
     %
     % Returns the number of the highest numbered rN register in use.
     %
-:- pred max_reg_in_use(var_locn_info::in, int::out) is det.
+:- pred var_locn_max_reg_in_use(var_locn_info::in, int::out) is det.
 
 %----------------------------------------------------------------------------%
 %----------------------------------------------------------------------------%
@@ -375,7 +378,9 @@
 
 %----------------------------------------------------------------------------%
 
-:- type dead_or_alive   --->    dead ; alive.
+:- type dead_or_alive
+    --->    dead
+    ;       alive.
 
     % The state of a variable can be one of three kinds: const, cached
     % and general.
@@ -404,7 +409,7 @@
     %   const_rval and expr_rval will be no.
 
 :- type var_state
-    --->    state(
+    --->    var_state(
                 locs            :: set(lval),
                                 % Must not contain var(_).
 
@@ -492,11 +497,11 @@
 
 %----------------------------------------------------------------------------%
 
-init_state(VarLocs, Liveness, VarSet, VarTypes, StackSlots, FollowVars,
-        Options, VarLocnInfo) :-
+init_var_locn_state(VarLocs, Liveness, VarSet, VarTypes, StackSlots,
+        FollowVars, Options, VarLocnInfo) :-
     map.init(VarStateMap0),
     map.init(LocVarMap0),
-    init_state_2(VarLocs, yes(Liveness), VarStateMap0, VarStateMap,
+    init_var_locn_state_2(VarLocs, yes(Liveness), VarStateMap0, VarStateMap,
         LocVarMap0, LocVarMap),
     exprn_aux.init_exprn_opts(Options, ExprnOpts),
     FollowVars = abs_follow_vars(FollowVarMap, NextNonReserved),
@@ -505,10 +510,10 @@
         FollowVarMap, NextNonReserved, VarStateMap, LocVarMap,
         AcquiredRegs, 0, []).
 
-reinit_state(VarLocs, !VarLocnInfo) :-
+reinit_var_locn_state(VarLocs, !VarLocnInfo) :-
     map.init(VarStateMap0),
     map.init(LocVarMap0),
-    init_state_2(VarLocs, no, VarStateMap0, VarStateMap,
+    init_var_locn_state_2(VarLocs, no, VarStateMap0, VarStateMap,
         LocVarMap0, LocVarMap),
     set.init(AcquiredRegs),
     !.VarLocnInfo = var_locn_info(VarSet, VarTypes, StackSlots, ExprnOpts,
@@ -517,13 +522,15 @@
         FollowVarMap, NextNonReserved, VarStateMap, LocVarMap,
         AcquiredRegs, 0, []).
 
-:- pred init_state_2(assoc_list(prog_var, lval)::in,
+:- pred init_var_locn_state_2(assoc_list(prog_var, lval)::in,
     maybe(set(prog_var))::in, var_state_map::in, var_state_map::out,
     loc_var_map::in, loc_var_map::out) is det.
 
-init_state_2([], _, !VarStateMap, !LocVarMap).
-init_state_2([Var - Lval |  Rest], MaybeLiveness, !VarStateMap, !LocVarMap) :-
-    expect(is_root_lval(Lval), this_file, "init_state_2: unexpected lval"),
+init_var_locn_state_2([], _, !VarStateMap, !LocVarMap).
+init_var_locn_state_2([Var - Lval |  Rest], MaybeLiveness, !VarStateMap,
+        !LocVarMap) :-
+    expect(is_root_lval(Lval), this_file,
+        "init_var_locn_state_2: unexpected lval"),
     (
         MaybeLiveness = yes(Liveness),
         \+ set.member(Var, Liveness)
@@ -541,17 +548,17 @@
         ;
             set.singleton_set(NewLocs, Lval),
             set.init(Using),
-            State = state(NewLocs, no, no, Using, alive),
+            State = var_state(NewLocs, no, no, Using, alive),
             map.det_insert(!.VarStateMap, Var, State, !:VarStateMap)
         ),
         make_var_depend_on_lval_roots(Var, Lval, !LocVarMap)
     ),
-    init_state_2(Rest, MaybeLiveness, !VarStateMap, !LocVarMap).
+    init_var_locn_state_2(Rest, MaybeLiveness, !VarStateMap, !LocVarMap).
 
 %----------------------------------------------------------------------------%
 
-get_var_locations(VLI, VarLocations) :-
-    get_var_state_map(VLI, VarStateMap),
+var_locn_get_var_locations(VLI, VarLocations) :-
+    var_locn_get_var_state_map(VLI, VarStateMap),
     map.to_assoc_list(VarStateMap, VarLocList),
     list.filter_map(convert_live_to_lval_set, VarLocList, LiveVarLocList),
     map.from_assoc_list(LiveVarLocList, VarLocations).
@@ -560,32 +567,32 @@
     pair(prog_var, set(lval))::out) is semidet.
 
 convert_live_to_lval_set(Var - State, Var - Lvals) :-
-    State = state(Lvals, _, _, _, alive).
+    State = var_state(Lvals, _, _, _, alive).
 
 %----------------------------------------------------------------------------%
 
-clobber_all_regs(OkToDeleteAny, !VLI) :-
-    set_acquired(set.init, !VLI),
-    set_locked(0, !VLI),
-    set_exceptions([], !VLI),
-    get_loc_var_map(!.VLI, LocVarMap0),
-    get_var_state_map(!.VLI, VarStateMap0),
+var_locn_clobber_all_regs(OkToDeleteAny, !VLI) :-
+    var_locn_set_acquired(set.init, !VLI),
+    var_locn_set_locked(0, !VLI),
+    var_locn_set_exceptions([], !VLI),
+    var_locn_get_loc_var_map(!.VLI, LocVarMap0),
+    var_locn_get_var_state_map(!.VLI, VarStateMap0),
     map.keys(LocVarMap0, Locs),
     clobber_regs_in_maps(Locs, OkToDeleteAny,
         LocVarMap0, LocVarMap, VarStateMap0, VarStateMap),
-    set_loc_var_map(LocVarMap, !VLI),
-    set_var_state_map(VarStateMap, !VLI).
+    var_locn_set_loc_var_map(LocVarMap, !VLI),
+    var_locn_set_var_state_map(VarStateMap, !VLI).
 
-clobber_regs(Regs, !VLI) :-
-    get_acquired(!.VLI, Acquired0),
+var_locn_clobber_regs(Regs, !VLI) :-
+    var_locn_get_acquired(!.VLI, Acquired0),
     Acquired = set.delete_list(Acquired0, Regs),
-    set_acquired(Acquired, !VLI),
-    get_loc_var_map(!.VLI, LocVarMap0),
-    get_var_state_map(!.VLI, VarStateMap0),
+    var_locn_set_acquired(Acquired, !VLI),
+    var_locn_get_loc_var_map(!.VLI, LocVarMap0),
+    var_locn_get_var_state_map(!.VLI, VarStateMap0),
     clobber_regs_in_maps(Regs, no,
         LocVarMap0, LocVarMap, VarStateMap0, VarStateMap),
-    set_loc_var_map(LocVarMap, !VLI),
-    set_var_state_map(VarStateMap, !VLI).
+    var_locn_set_loc_var_map(LocVarMap, !VLI),
+    var_locn_set_var_state_map(VarStateMap, !VLI).
 
 :- pred clobber_regs_in_maps(list(lval)::in, bool::in,
     loc_var_map::in, loc_var_map::out,
@@ -632,10 +639,10 @@
 try_clobber_lval_in_var_state_map(Lval, OkToDeleteVars, OkToDeleteAny, Var,
         !VarStateMap) :-
     map.lookup(!.VarStateMap, Var, State0),
-    State0 = state(LvalSet0, MaybeConstRval, MaybeExprRval, Using,
+    State0 = var_state(LvalSet0, MaybeConstRval, MaybeExprRval, Using,
         DeadOrAlive),
     LvalSet = set.filter(lval_does_not_support_lval(Lval), LvalSet0),
-    State = state(LvalSet, MaybeConstRval, MaybeExprRval, Using,
+    State = var_state(LvalSet, MaybeConstRval, MaybeExprRval, Using,
         DeadOrAlive),
     (
         nonempty_state(State)
@@ -661,7 +668,7 @@
         list.member(Var, OkToDeleteVars)
     ;
         map.lookup(VarStateMap, Var, State),
-        State = state(_, _, _, Using, DeadOrAlive),
+        State = var_state(_, _, _, Using, DeadOrAlive),
         DeadOrAlive = dead,
         set.to_sorted_list(Using, UsingVars),
         recursive_using_vars_dead_and_ok_to_delete(UsingVars,
@@ -672,41 +679,42 @@
 
 %----------------------------------------------------------------------------%
 
-assign_var_to_var(Var, OldVar, !VLI) :-
+var_locn_assign_var_to_var(Var, OldVar, !VLI) :-
     check_var_is_unknown(!.VLI, Var),
-    get_var_state_map(!.VLI, VarStateMap0),
+    var_locn_get_var_state_map(!.VLI, VarStateMap0),
     map.lookup(VarStateMap0, OldVar, OldState0),
-    OldState0 = state(Lvals, MaybeConstRval, MaybeExprRval,
+    OldState0 = var_state(Lvals, MaybeConstRval, MaybeExprRval,
         Using0, DeadOrAlive),
     (
         MaybeExprRval = yes(_),
-        State = state(Lvals, MaybeConstRval, yes(var(OldVar)), set.init,
+        State = var_state(Lvals, MaybeConstRval, yes(var(OldVar)), set.init,
             alive),
         set.insert(Using0, Var, Using),
-        OldState = state(Lvals, MaybeConstRval, MaybeExprRval, Using,
+        OldState = var_state(Lvals, MaybeConstRval, MaybeExprRval, Using,
             DeadOrAlive),
         map.det_update(VarStateMap0, OldVar, OldState, VarStateMap1)
     ;
         MaybeExprRval = no,
         set.init(Empty),
-        State = state(Lvals, MaybeConstRval, no, Empty, alive),
+        State = var_state(Lvals, MaybeConstRval, no, Empty, alive),
         VarStateMap1 = VarStateMap0
     ),
     map.det_insert(VarStateMap1, Var, State, VarStateMap),
-    set_var_state_map(VarStateMap, !VLI),
+    var_locn_set_var_state_map(VarStateMap, !VLI),
 
-    get_loc_var_map(!.VLI, LocVarMap0),
+    var_locn_get_loc_var_map(!.VLI, LocVarMap0),
     make_var_depend_on_lvals_roots(Var, Lvals, LocVarMap0, LocVarMap),
-    set_loc_var_map(LocVarMap, !VLI).
+    var_locn_set_loc_var_map(LocVarMap, !VLI).
 
 %----------------------------------------------------------------------------%
 
-assign_lval_to_var(ModuleInfo, Var, Lval0, StaticCellInfo, Code, !VLI) :-
+var_locn_assign_lval_to_var(ModuleInfo, Var, Lval0, StaticCellInfo, Code,
+        !VLI) :-
     check_var_is_unknown(!.VLI, Var),
     ( Lval0 = field(yes(Ptag), var(BaseVar), const(llconst_int(Offset))) ->
-        get_var_state_map(!.VLI, VarStateMap0),
+        var_locn_get_var_state_map(!.VLI, VarStateMap0),
         map.lookup(VarStateMap0, BaseVar, BaseState),
-        BaseState = state(BaseVarLvals, MaybeConstBaseVarRval,
+        BaseState = var_state(BaseVarLvals, MaybeConstBaseVarRval,
             _MaybeExprRval, _UsingVars, _DeadOrAlive),
         (
             MaybeConstBaseVarRval = yes(BaseVarRval),
@@ -722,35 +730,35 @@
             Lvals = set.map(add_field_offset(yes(Ptag),
                 const(llconst_int(Offset))), BaseVarLvals),
             set.init(Using),
-            State = state(Lvals, MaybeConstRval, no, Using, alive),
+            State = var_state(Lvals, MaybeConstRval, no, Using, alive),
             map.det_insert(VarStateMap0, Var, State, VarStateMap),
-            set_var_state_map(VarStateMap, !VLI),
+            var_locn_set_var_state_map(VarStateMap, !VLI),
 
-            get_loc_var_map(!.VLI, LocVarMap0),
+            var_locn_get_loc_var_map(!.VLI, LocVarMap0),
             make_var_depend_on_lvals_roots(Var, Lvals, LocVarMap0, LocVarMap),
-            set_loc_var_map(LocVarMap, !VLI)
+            var_locn_set_loc_var_map(LocVarMap, !VLI)
         ;
             set.init(Lvals),
             Expr = lval(Lval0),
             set.init(Using),
-            State = state(Lvals, no, yes(Expr), Using, alive),
+            State = var_state(Lvals, no, yes(Expr), Using, alive),
             map.det_insert(VarStateMap0, Var, State, VarStateMap1),
             add_use_ref(BaseVar, Var, VarStateMap1, VarStateMap),
-            set_var_state_map(VarStateMap, !VLI)
+            var_locn_set_var_state_map(VarStateMap, !VLI)
         ),
         Code = empty
     ;
-        materialize_vars_in_lval(ModuleInfo, Lval0, Lval, Code, !VLI),
+        var_locn_materialize_vars_in_lval(ModuleInfo, Lval0, Lval, Code, !VLI),
 
-        get_var_state_map(!.VLI, VarStateMap0),
+        var_locn_get_var_state_map(!.VLI, VarStateMap0),
         set.singleton_set(LvalSet, Lval),
-        State = state(LvalSet, no, no, set.init, alive),
+        State = var_state(LvalSet, no, no, set.init, alive),
         map.det_insert(VarStateMap0, Var, State, VarStateMap),
-        set_var_state_map(VarStateMap, !VLI),
+        var_locn_set_var_state_map(VarStateMap, !VLI),
 
-        get_loc_var_map(!.VLI, LocVarMap0),
+        var_locn_get_loc_var_map(!.VLI, LocVarMap0),
         make_var_depend_on_lval_roots(Var, Lval, LocVarMap0, LocVarMap),
-        set_loc_var_map(LocVarMap, !VLI)
+        var_locn_set_loc_var_map(LocVarMap, !VLI)
     ).
 
 :- func add_field_offset(maybe(tag), rval, lval) = lval.
@@ -760,32 +768,33 @@
 
 %----------------------------------------------------------------------------%
 
-assign_const_to_var(Var, ConstRval0, !VLI) :-
+var_locn_assign_const_to_var(Var, ConstRval0, !VLI) :-
     check_var_is_unknown(!.VLI, Var),
 
-    get_var_state_map(!.VLI, VarStateMap0),
-    get_exprn_opts(!.VLI, ExprnOpts),
+    var_locn_get_var_state_map(!.VLI, VarStateMap0),
+    var_locn_get_exprn_opts(!.VLI, ExprnOpts),
     ( expr_is_constant(VarStateMap0, ExprnOpts, ConstRval0, ConstRval) ->
-        State = state(set.init, yes(ConstRval), no, set.init, alive),
+        State = var_state(set.init, yes(ConstRval), no, set.init, alive),
         map.det_insert(VarStateMap0, Var, State, VarStateMap),
-        set_var_state_map(VarStateMap, !VLI)
+        var_locn_set_var_state_map(VarStateMap, !VLI)
     ;
-        unexpected(this_file, "set_var_state_map: supposed constant isn't")
+        unexpected(this_file,
+            "var_locn_assign_const_to_var: supposed constant isn't")
     ).
 
 %----------------------------------------------------------------------------%
 
-assign_expr_to_var(Var, Rval, empty, !VLI) :-
+var_locn_assign_expr_to_var(Var, Rval, empty, !VLI) :-
     check_var_is_unknown(!.VLI, Var),
 
-    get_var_state_map(!.VLI, VarStateMap0),
-    State = state(set.init, no, yes(Rval), set.init, alive),
+    var_locn_get_var_state_map(!.VLI, VarStateMap0),
+    State = var_state(set.init, no, yes(Rval), set.init, alive),
     map.det_insert(VarStateMap0, Var, State, VarStateMap1),
 
     exprn_aux.vars_in_rval(Rval, ContainedVars0),
     list.remove_dups(ContainedVars0, ContainedVars),
     add_use_refs(ContainedVars, Var, VarStateMap1, VarStateMap),
-    set_var_state_map(VarStateMap, !VLI).
+    var_locn_set_var_state_map(VarStateMap, !VLI).
 
 :- pred add_use_refs(list(prog_var)::in, prog_var::in,
     var_state_map::in, var_state_map::out) is det.
@@ -800,15 +809,18 @@
 
 add_use_ref(ContainedVar, UsingVar, !VarStateMap) :-
     map.lookup(!.VarStateMap, ContainedVar, State0),
-    State0 = state(Lvals, MaybeConstRval, MaybeExprRval, Using0, DeadOrAlive),
+    State0 = var_state(Lvals, MaybeConstRval, MaybeExprRval, Using0,
+        DeadOrAlive),
     set.insert(Using0, UsingVar, Using),
-    State = state(Lvals, MaybeConstRval, MaybeExprRval, Using, DeadOrAlive),
+    State = var_state(Lvals, MaybeConstRval, MaybeExprRval, Using,
+        DeadOrAlive),
     map.det_update(!.VarStateMap, ContainedVar, State, !:VarStateMap).
 
 %----------------------------------------------------------------------------%
 
-assign_cell_to_var(ModuleInfo, Var, ReserveWordAtStart, Ptag, MaybeRvals0,
-        SizeInfo, TypeMsg, MayUseAtomic, Code, !StaticCellInfo, !VLI) :-
+var_locn_assign_cell_to_var(ModuleInfo, Var, ReserveWordAtStart, Ptag,
+        MaybeRvals0, SizeInfo, TypeMsg, MayUseAtomic, Code, !StaticCellInfo,
+        !VLI) :-
     (
         SizeInfo = yes(SizeSource),
         (
@@ -825,26 +837,27 @@
         MaybeRvals = MaybeRvals0,
         MaybeOffset = no
     ),
-    get_var_state_map(!.VLI, VarStateMap),
-    get_exprn_opts(!.VLI, ExprnOpts),
+    var_locn_get_var_state_map(!.VLI, VarStateMap),
+    var_locn_get_exprn_opts(!.VLI, ExprnOpts),
     ( cell_is_constant(VarStateMap, ExprnOpts, MaybeRvals, RvalsTypes) ->
         add_scalar_static_cell(RvalsTypes, DataAddr, !StaticCellInfo),
         CellPtrConst = const(llconst_data_addr(DataAddr, MaybeOffset)),
         CellPtrRval = mkword(Ptag, CellPtrConst),
-        assign_const_to_var(Var, CellPtrRval, !VLI),
+        var_locn_assign_const_to_var(Var, CellPtrRval, !VLI),
         Code = empty
     ;
-        assign_dynamic_cell_to_var(ModuleInfo, Var, ReserveWordAtStart, Ptag,
-            MaybeRvals, MaybeOffset, TypeMsg, MayUseAtomic, Code, !VLI)
+        var_locn_assign_dynamic_cell_to_var(ModuleInfo, Var,
+            ReserveWordAtStart, Ptag, MaybeRvals, MaybeOffset, TypeMsg,
+            MayUseAtomic, Code, !VLI)
     ).
 
-:- pred assign_dynamic_cell_to_var(module_info::in, prog_var::in, bool::in,
-    tag::in, list(maybe(rval))::in, maybe(int)::in, string::in,
+:- pred var_locn_assign_dynamic_cell_to_var(module_info::in, prog_var::in,
+    bool::in, tag::in, list(maybe(rval))::in, maybe(int)::in, string::in,
     may_use_atomic_alloc::in, code_tree::out,
     var_locn_info::in, var_locn_info::out) is det.
 
-assign_dynamic_cell_to_var(ModuleInfo, Var, ReserveWordAtStart, Ptag, Vector,
-        MaybeOffset, TypeMsg, MayUseAtomic, Code, !VLI) :-
+var_locn_assign_dynamic_cell_to_var(ModuleInfo, Var, ReserveWordAtStart, Ptag,
+        Vector, MaybeOffset, TypeMsg, MayUseAtomic, Code, !VLI) :-
     check_var_is_unknown(!.VLI, Var),
 
     select_preferred_reg_or_stack_check(!.VLI, Var, Lval),
@@ -872,7 +885,7 @@
             const(llconst_int(TotalSize)), TypeMsg, MayUseAtomic)
             - string.append("Allocating heap for ", VarName)
     ]),
-    set_magic_var_location(Var, Lval, !VLI),
+    var_locn_set_magic_var_location(Var, Lval, !VLI),
     (
         MaybeOffset = yes(Offset),
         StartOffset = -Offset
@@ -904,7 +917,7 @@
                 materialize_var(ModuleInfo, Var, no, no, [], Rval, EvalCode,
                     !VLI)
             ),
-            get_vartypes(!.VLI, VarTypes),
+            var_locn_get_vartypes(!.VLI, VarTypes),
             map.lookup(VarTypes, Var, Type),
             ( is_dummy_argument_type(ModuleInfo, Type) ->
                 AssignCode = empty
@@ -939,18 +952,18 @@
     var_locn_info::in, var_locn_info::out) is det.
 
 add_additional_lval_for_var(Var, Lval, !VLI) :-
-    get_loc_var_map(!.VLI, LocVarMap0),
+    var_locn_get_loc_var_map(!.VLI, LocVarMap0),
     make_var_depend_on_lval_roots(Var, Lval, LocVarMap0, LocVarMap),
-    set_loc_var_map(LocVarMap, !VLI),
+    var_locn_set_loc_var_map(LocVarMap, !VLI),
 
-    get_var_state_map(!.VLI, VarStateMap0),
+    var_locn_get_var_state_map(!.VLI, VarStateMap0),
     map.lookup(VarStateMap0, Var, State0),
-    State0 = state(LvalSet0, MaybeConstRval, MaybeExprRval0,
+    State0 = var_state(LvalSet0, MaybeConstRval, MaybeExprRval0,
         Using, DeadOrAlive),
     set.insert(LvalSet0, Lval, LvalSet),
-    State = state(LvalSet, MaybeConstRval, no, Using, DeadOrAlive),
+    State = var_state(LvalSet, MaybeConstRval, no, Using, DeadOrAlive),
     map.det_update(VarStateMap0, Var, State, VarStateMap),
-    set_var_state_map(VarStateMap, !VLI),
+    var_locn_set_var_state_map(VarStateMap, !VLI),
 
     remove_use_refs(MaybeExprRval0, Var, !VLI).
 
@@ -972,22 +985,24 @@
 
 remove_use_refs_2([], _, !VLI).
 remove_use_refs_2([ContainedVar | ContainedVars], UsingVar, !VLI) :-
-    get_var_state_map(!.VLI, VarStateMap0),
+    var_locn_get_var_state_map(!.VLI, VarStateMap0),
     map.lookup(VarStateMap0, ContainedVar, State0),
-    State0 = state(Lvals, MaybeConstRval, MaybeExprRval, Using0, DeadOrAlive),
+    State0 = var_state(Lvals, MaybeConstRval, MaybeExprRval, Using0,
+        DeadOrAlive),
     ( set.remove(Using0, UsingVar, Using1) ->
         Using = Using1
     ;
         unexpected(this_file, "remove_use_refs_2: using ref not present")
     ),
-    State = state(Lvals, MaybeConstRval, MaybeExprRval, Using, DeadOrAlive),
+    State = var_state(Lvals, MaybeConstRval, MaybeExprRval, Using,
+        DeadOrAlive),
     map.det_update(VarStateMap0, ContainedVar, State, VarStateMap),
-    set_var_state_map(VarStateMap, !VLI),
+    var_locn_set_var_state_map(VarStateMap, !VLI),
     (
         set.empty(Using),
         DeadOrAlive = dead
     ->
-        var_becomes_dead(ContainedVar, no, !VLI)
+        var_locn_var_becomes_dead(ContainedVar, no, !VLI)
     ;
         true
     ),
@@ -995,30 +1010,30 @@
 
 %----------------------------------------------------------------------------%
 
-check_and_set_magic_var_location(Var, Lval, !VLI) :-
-    ( lval_in_use(!.VLI, Lval) ->
+var_locn_check_and_set_magic_var_location(Var, Lval, !VLI) :-
+    ( var_locn_lval_in_use(!.VLI, Lval) ->
         unexpected(this_file, "check_and_set_magic_var_location: in use")
     ;
-        set_magic_var_location(Var, Lval, !VLI)
+        var_locn_set_magic_var_location(Var, Lval, !VLI)
     ).
 
-set_magic_var_location(Var, Lval, !VLI) :-
-    get_loc_var_map(!.VLI, LocVarMap0),
+var_locn_set_magic_var_location(Var, Lval, !VLI) :-
+    var_locn_get_loc_var_map(!.VLI, LocVarMap0),
     make_var_depend_on_lval_roots(Var, Lval, LocVarMap0, LocVarMap),
-    set_loc_var_map(LocVarMap, !VLI),
+    var_locn_set_loc_var_map(LocVarMap, !VLI),
 
-    get_var_state_map(!.VLI, VarStateMap0),
+    var_locn_get_var_state_map(!.VLI, VarStateMap0),
     set.singleton_set(LvalSet, Lval),
-    State = state(LvalSet, no, no, set.init, alive),
+    State = var_state(LvalSet, no, no, set.init, alive),
     map.det_insert(VarStateMap0, Var, State, VarStateMap),
-    set_var_state_map(VarStateMap, !VLI).
+    var_locn_set_var_state_map(VarStateMap, !VLI).
 
 %----------------------------------------------------------------------------%
 
 :- pred check_var_is_unknown(var_locn_info::in, prog_var::in) is det.
 
 check_var_is_unknown(VLI, Var) :-
-    get_var_state_map(VLI, VarStateMap0),
+    var_locn_get_var_state_map(VLI, VarStateMap0),
     ( map.search(VarStateMap0, Var, _) ->
         get_var_name(VLI, Var, Name),
         Msg = "assign_to_var: existing definition of variable " ++ Name,
@@ -1029,10 +1044,10 @@
 
 %----------------------------------------------------------------------------%
 
-produce_var(ModuleInfo, Var, Rval, Code, !VLI) :-
-    get_var_state_map(!.VLI, VarStateMap),
+var_locn_produce_var(ModuleInfo, Var, Rval, Code, !VLI) :-
+    var_locn_get_var_state_map(!.VLI, VarStateMap),
     map.lookup(VarStateMap, Var, State),
-    State = state(Lvals, MaybeConstRval, MaybeExprRval, _, _),
+    State = var_state(Lvals, MaybeConstRval, MaybeExprRval, _, _),
     set.to_sorted_list(Lvals, LvalsList),
     (
         maybe_select_lval_or_rval(LvalsList, MaybeConstRval, Rval1)
@@ -1042,7 +1057,7 @@
     ;
         MaybeExprRval = yes(var(ExprVar)),
         map.lookup(VarStateMap, ExprVar, ExprState),
-        ExprState = state(ExprLvals, ExprMaybeConstRval, _, _, _),
+        ExprState = var_state(ExprLvals, ExprMaybeConstRval, _, _, _),
         set.to_sorted_list(ExprLvals, ExprLvalsList),
         maybe_select_lval_or_rval(ExprLvalsList, ExprMaybeConstRval, Rval2)
     ->
@@ -1052,48 +1067,48 @@
         Code = empty
     ;
         select_preferred_reg(!.VLI, Var, Lval),
-        place_var(ModuleInfo, Var, Lval, Code, !VLI),
+        var_locn_place_var(ModuleInfo, Var, Lval, Code, !VLI),
         Rval = lval(Lval)
     ).
 
-produce_var_in_reg(ModuleInfo, Var, Lval, Code, !VLI) :-
-    get_var_state_map(!.VLI, VarStateMap),
+var_locn_produce_var_in_reg(ModuleInfo, Var, Lval, Code, !VLI) :-
+    var_locn_get_var_state_map(!.VLI, VarStateMap),
     map.lookup(VarStateMap, Var, State),
-    State = state(Lvals, _, _, _, _),
+    State = var_state(Lvals, _, _, _, _),
     set.to_sorted_list(Lvals, LvalList),
     ( select_reg_lval(LvalList, SelectLval) ->
         Lval = SelectLval,
         Code = empty
     ;
         select_preferred_reg(!.VLI, Var, Lval),
-        place_var(ModuleInfo, Var, Lval, Code, !VLI)
+        var_locn_place_var(ModuleInfo, Var, Lval, Code, !VLI)
     ).
 
-produce_var_in_reg_or_stack(ModuleInfo, Var, Lval, Code, !VLI) :-
-    get_var_state_map(!.VLI, VarStateMap),
+var_locn_produce_var_in_reg_or_stack(ModuleInfo, Var, Lval, Code, !VLI) :-
+    var_locn_get_var_state_map(!.VLI, VarStateMap),
     map.lookup(VarStateMap, Var, State),
-    State = state(Lvals, _, _, _, _),
+    State = var_state(Lvals, _, _, _, _),
     set.to_sorted_list(Lvals, LvalList),
     ( select_reg_or_stack_lval(LvalList, SelectLval) ->
         Lval = SelectLval,
         Code = empty
     ;
         select_preferred_reg_or_stack_check(!.VLI, Var, Lval),
-        place_var(ModuleInfo, Var, Lval, Code, !VLI)
+        var_locn_place_var(ModuleInfo, Var, Lval, Code, !VLI)
     ).
 
 %----------------------------------------------------------------------------%
 
-clear_r1(ModuleInfo, Code, !VLI) :-
+var_locn_clear_r1(ModuleInfo, Code, !VLI) :-
     free_up_lval(ModuleInfo, reg(reg_r, 1), [], [], Code, !VLI),
-    get_loc_var_map(!.VLI, LocVarMap0),
-    get_var_state_map(!.VLI, VarStateMap0),
+    var_locn_get_loc_var_map(!.VLI, LocVarMap0),
+    var_locn_get_var_state_map(!.VLI, VarStateMap0),
     clobber_regs_in_maps([reg(reg_r, 1)], no,
         LocVarMap0, LocVarMap, VarStateMap0, VarStateMap),
-    set_loc_var_map(LocVarMap, !VLI),
-    set_var_state_map(VarStateMap, !VLI).
+    var_locn_set_loc_var_map(LocVarMap, !VLI),
+    var_locn_set_var_state_map(VarStateMap, !VLI).
 
-place_vars(ModuleInfo, VarLocns, Code, !VLI) :-
+var_locn_place_vars(ModuleInfo, VarLocns, Code, !VLI) :-
     % If we are asked to place several variables, then we must make sure that
     % in the process of freeing up an lval for one variable, we do not save its
     % previous contents to a location that VarLocns assigns to another
@@ -1106,20 +1121,20 @@
     % to the location assigned to it by VarLocns.
     assoc_list.values(VarLocns, Lvals),
     code_util.max_mentioned_reg(Lvals, MaxReg),
-    lock_regs(MaxReg, VarLocns, !VLI),
+    var_locn_lock_regs(MaxReg, VarLocns, !VLI),
     actually_place_vars(ModuleInfo, VarLocns, Code, !VLI),
-    unlock_regs(!VLI).
+    var_locn_unlock_regs(!VLI).
 
 :- pred actually_place_vars(module_info::in, assoc_list(prog_var, lval)::in,
     code_tree::out, var_locn_info::in, var_locn_info::out) is det.
 
 actually_place_vars(_, [], empty, !VLI).
 actually_place_vars(ModuleInfo, [Var - Lval | Rest], Code, !VLI) :-
-    place_var(ModuleInfo, Var, Lval, FirstCode, !VLI),
+    var_locn_place_var(ModuleInfo, Var, Lval, FirstCode, !VLI),
     actually_place_vars(ModuleInfo, Rest, RestCode, !VLI),
     Code = tree(FirstCode, RestCode).
 
-place_var(ModuleInfo, Var, Target, Code, !VLI) :-
+var_locn_place_var(ModuleInfo, Var, Target, Code, !VLI) :-
     actually_place_var(ModuleInfo, Var, Target, [], Code, !VLI).
 
 :- pred actually_place_var(module_info::in, prog_var::in, lval::in,
@@ -1127,15 +1142,15 @@
     is det.
 
 actually_place_var(ModuleInfo, Var, Target, ForbiddenLvals, Code, !VLI) :-
-    get_acquired(!.VLI, Acquired),
+    var_locn_get_acquired(!.VLI, Acquired),
     ( set.member(Target, Acquired) ->
         unexpected(this_file, "actually_place_var: target is acquired reg")
     ;
         true
     ),
-    get_var_state_map(!.VLI, VarStateMap0),
+    var_locn_get_var_state_map(!.VLI, VarStateMap0),
     map.lookup(VarStateMap0, Var, State0),
-    State0 = state(Lvals0, _, _, _, _),
+    State0 = var_state(Lvals0, _, _, _, _),
     ( set.member(Target, Lvals0) ->
         Code = empty
     ;
@@ -1179,7 +1194,7 @@
                 string.append_list(["Placing ", VarName,
                     " (depth ", LengthStr, ")"], Msg)
             ),
-            get_vartypes(!.VLI, VarTypes),
+            var_locn_get_vartypes(!.VLI, VarTypes),
             map.lookup(VarTypes, Var, Type),
             ( is_dummy_argument_type(ModuleInfo, Type) ->
                 AssignCode = empty
@@ -1194,16 +1209,16 @@
     var_locn_info::in, var_locn_info::out) is det.
 
 record_clobbering(Target, Assigns, !VLI) :-
-    get_loc_var_map(!.VLI, LocVarMap1),
+    var_locn_get_loc_var_map(!.VLI, LocVarMap1),
     ( map.search(LocVarMap1, Target, DependentVarsSet) ->
         set.to_sorted_list(DependentVarsSet, DependentVars),
         map.delete(LocVarMap1, Target, LocVarMap),
-        set_loc_var_map(LocVarMap, !VLI),
+        var_locn_set_loc_var_map(LocVarMap, !VLI),
 
-        get_var_state_map(!.VLI, VarStateMap2),
+        var_locn_get_var_state_map(!.VLI, VarStateMap2),
         list.foldl(clobber_lval_in_var_state_map(Target, Assigns, no),
             DependentVars, VarStateMap2, VarStateMap),
-        set_var_state_map(VarStateMap, !VLI)
+        var_locn_set_var_state_map(VarStateMap, !VLI)
     ;
         true
     ).
@@ -1231,10 +1246,10 @@
 
 free_up_lval(ModuleInfo, Lval, ToBeAssignedVars, ForbiddenLvals, Code, !VLI) :-
     (
-        get_loc_var_map(!.VLI, LocVarMap0),
+        var_locn_get_loc_var_map(!.VLI, LocVarMap0),
         map.search(LocVarMap0, Lval, AffectedVarSet),
         set.to_sorted_list(AffectedVarSet, AffectedVars),
-        get_var_state_map(!.VLI, VarStateMap0),
+        var_locn_get_var_state_map(!.VLI, VarStateMap0),
         \+ list.foldl(
             try_clobber_lval_in_var_state_map(Lval, ToBeAssignedVars, no),
             AffectedVars, VarStateMap0, _)
@@ -1269,12 +1284,12 @@
 free_up_lval_with_copy(ModuleInfo, Lval, ToBeAssignedVars, ForbiddenLvals,
         Code, !VLI) :-
     (
-        get_loc_var_map(!.VLI, LocVarMap0),
+        var_locn_get_loc_var_map(!.VLI, LocVarMap0),
         map.search(LocVarMap0, Lval, AffectedVarSet),
         set.delete_list(AffectedVarSet, ToBeAssignedVars, EffAffectedVarSet),
         set.to_sorted_list(EffAffectedVarSet, EffAffectedVars),
 
-        get_var_state_map(!.VLI, VarStateMap0),
+        var_locn_get_var_state_map(!.VLI, VarStateMap0),
         (
             find_one_occupying_var(EffAffectedVars, Lval, VarStateMap0,
                 OccupyingVar, OtherSources)
@@ -1291,7 +1306,7 @@
         select_preferred_reg_or_stack(!.VLI, MovedVar, Pref, CheckInUse),
         \+ Pref = Lval,
         \+ list.member(Pref, ForbiddenLvals),
-        ( \+ lval_in_use(!.VLI, Pref) ->
+        ( \+ var_locn_lval_in_use(!.VLI, Pref) ->
             true
         ;
             % The code generator assumes that values in stack slots don't get
@@ -1332,7 +1347,7 @@
 find_one_occupying_var([Var | Vars], Lval, VarStateMap, OccupyingVar,
         OtherSources) :-
     map.lookup(VarStateMap, Var, State),
-    State = state(LvalSet, _, _, _, _),
+    State = var_state(LvalSet, _, _, _, _),
     ( set.member(Lval, LvalSet) ->
         OccupyingVar = Var,
         set.delete(LvalSet, Lval, OtherSourceSet),
@@ -1346,21 +1361,22 @@
     prog_var::in, var_locn_info::in, var_locn_info::out) is det.
 
 ensure_copies_are_present(OneSource, OtherSources, Var, !VLI) :-
-    get_var_state_map(!.VLI, VarStateMap0),
+    var_locn_get_var_state_map(!.VLI, VarStateMap0),
     map.lookup(VarStateMap0, Var, State0),
-    State0 = state(LvalSet0, MaybeConstRval, MaybeExprRval, Using,
+    State0 = var_state(LvalSet0, MaybeConstRval, MaybeExprRval, Using,
         DeadOrAlive),
     set.to_sorted_list(LvalSet0, Lvals0),
     list.foldl(ensure_copies_are_present_lval(OtherSources, OneSource),
         Lvals0, LvalSet0, LvalSet),
-    State = state(LvalSet, MaybeConstRval, MaybeExprRval, Using, DeadOrAlive),
+    State = var_state(LvalSet, MaybeConstRval, MaybeExprRval, Using,
+        DeadOrAlive),
     map.det_update(VarStateMap0, Var, State, VarStateMap),
-    set_var_state_map(VarStateMap, !VLI),
+    var_locn_set_var_state_map(VarStateMap, !VLI),
 
-    get_loc_var_map(!.VLI, LocVarMap0),
+    var_locn_get_loc_var_map(!.VLI, LocVarMap0),
     record_change_in_root_dependencies(LvalSet0, LvalSet, Var,
         LocVarMap0, LocVarMap),
-    set_loc_var_map(LocVarMap, !VLI).
+    var_locn_set_loc_var_map(LocVarMap, !VLI).
 
 :- pred ensure_copies_are_present_lval(list(lval)::in, lval::in,
     lval::in, set(lval)::in, set(lval)::out) is det.
@@ -1390,24 +1406,27 @@
 
 record_copy(Old, New, !VLI) :-
     expect(is_root_lval(New), this_file, "record_copy: non-root New lval"),
-    get_var_state_map(!.VLI, VarStateMap0),
-    get_loc_var_map(!.VLI, LocVarMap0),
+    var_locn_get_var_state_map(!.VLI, VarStateMap0),
+    var_locn_get_loc_var_map(!.VLI, LocVarMap0),
     set.list_to_set([Old, New], AssignSet),
     get_var_set_roots(AssignSet, NoDupRootLvals),
-        % Convert the list of root lvals to the list of sets of
-        % affected vars; if a root lval is not in LocVarMap0,
-        % then it does not affect any variables.
+
+    % Convert the list of root lvals to the list of sets of affected vars;
+    % if a root lval is not in LocVarMap0, then it does not affect any
+    % variables.
     list.filter_map(map.search(LocVarMap0), NoDupRootLvals,
         AffectedVarSets),
-        % Take the union of the list of sets of affected vars.
+
+    % Take the union of the list of sets of affected vars.
     list.foldl(set.union, AffectedVarSets,
         set.init, AffectedVarSet),
-        % Convert the union set to a list of affected vars.
+
+    % Convert the union set to a list of affected vars.
     set.to_sorted_list(AffectedVarSet, AffectedVars),
     list.foldl2(record_copy_for_var(Old, New), AffectedVars,
         VarStateMap0, VarStateMap, LocVarMap0, LocVarMap),
-    set_loc_var_map(LocVarMap, !VLI),
-    set_var_state_map(VarStateMap, !VLI).
+    var_locn_set_loc_var_map(LocVarMap, !VLI),
+    var_locn_set_var_state_map(VarStateMap, !VLI).
 
     % Record the effect of the assignment New := Old on the state of the given
     % variable.
@@ -1449,14 +1468,14 @@
 
 record_copy_for_var(Old, New, Var, !VarStateMap, !LocVarMap) :-
     map.lookup(!.VarStateMap, Var, State0),
-    State0 = state(LvalSet0, MaybeConstRval, MaybeExprRval,
+    State0 = var_state(LvalSet0, MaybeConstRval, MaybeExprRval,
         Using, DeadOrAlive),
     Token = reg(reg_r, -42),
     LvalSet1 = set.map(substitute_lval_in_lval(Old, Token), LvalSet0),
     set.union(LvalSet0, LvalSet1, LvalSet2),
     LvalSet3 = set.filter(lval_does_not_support_lval(New), LvalSet2),
     LvalSet = set.map(substitute_lval_in_lval(Token, New), LvalSet3),
-    State = state(LvalSet, MaybeConstRval, MaybeExprRval,
+    State = var_state(LvalSet, MaybeConstRval, MaybeExprRval,
         Using, DeadOrAlive),
     expect(nonempty_state(State), this_file,
         "record_copy_for_var: empty state"),
@@ -1498,10 +1517,10 @@
     % we would like to insist on Var being alive (but don't (yet) due to bugs
     % in liveness).
     %
-var_becomes_dead(Var, FirstTime, !VLI) :-
-    get_var_state_map(!.VLI, VarStateMap0),
+var_locn_var_becomes_dead(Var, FirstTime, !VLI) :-
+    var_locn_get_var_state_map(!.VLI, VarStateMap0),
     ( map.search(VarStateMap0, Var, State0) ->
-        State0 = state(Lvals, MaybeConstRval, MaybeExprRval, Using,
+        State0 = var_state(Lvals, MaybeConstRval, MaybeExprRval, Using,
             DeadOrAlive0),
         (
             DeadOrAlive0 = dead,
@@ -1512,19 +1531,20 @@
         ),
         ( set.empty(Using) ->
             map.det_remove(VarStateMap0, Var, _, VarStateMap),
-            set_var_state_map(VarStateMap, !VLI),
+            var_locn_set_var_state_map(VarStateMap, !VLI),
 
-            get_loc_var_map(!.VLI, LocVarMap0),
+            var_locn_get_loc_var_map(!.VLI, LocVarMap0),
             get_var_set_roots(Lvals, NoDupRootLvals),
             list.foldl(make_var_not_depend_on_root_lval(Var),
                 NoDupRootLvals, LocVarMap0, LocVarMap),
-            set_loc_var_map(LocVarMap, !VLI),
+            var_locn_set_loc_var_map(LocVarMap, !VLI),
 
             remove_use_refs(MaybeExprRval, Var, !VLI)
         ;
-            State = state(Lvals, MaybeConstRval, MaybeExprRval, Using, dead),
+            State = var_state(Lvals, MaybeConstRval, MaybeExprRval, Using,
+                dead),
             map.det_update(VarStateMap0, Var, State, VarStateMap),
-            set_var_state_map(VarStateMap, !VLI)
+            var_locn_set_var_state_map(VarStateMap, !VLI)
         )
     ;
         expect(unify(FirstTime, no), this_file,
@@ -1652,7 +1672,7 @@
     bool::in, list(lval)::in, lval::out) is det.
 
 select_preferred_reg(VLI, Var, CheckInUse, Avoid, Lval) :-
-    get_follow_var_map(VLI, FollowVarMap),
+    var_locn_get_follow_var_map(VLI, FollowVarMap),
     (
         map.search(FollowVarMap, Var, PrefLocn),
         ( PrefLocn = abs_reg(_)
@@ -1664,7 +1684,7 @@
             PrefLval = reg(reg_r, N),
             (
                 CheckInUse = yes,
-                \+ lval_in_use(VLI, PrefLval)
+                \+ var_locn_lval_in_use(VLI, PrefLval)
             ;
                 CheckInUse = no
             ),
@@ -1698,7 +1718,7 @@
     prog_var::in, lval::out, bool::in) is det.
 
 select_preferred_reg_or_stack(VLI, Var, Lval, CheckInUse) :-
-    get_follow_var_map(VLI, FollowVarMap),
+    var_locn_get_follow_var_map(VLI, FollowVarMap),
     (
         map.search(FollowVarMap, Var, PrefLocn),
         ( PrefLocn = abs_reg(_)
@@ -1710,7 +1730,7 @@
             PrefLval = reg(reg_r, N),
             (
                 CheckInUse = yes,
-                \+ lval_in_use(VLI, PrefLval)
+                \+ var_locn_lval_in_use(VLI, PrefLval)
             ;
                 CheckInUse = no
             )
@@ -1721,12 +1741,12 @@
         )
     ;
         (
-            get_stack_slots(VLI, StackSlots),
+            var_locn_get_stack_slots(VLI, StackSlots),
             map.search(StackSlots, Var, StackSlotLocn),
             StackSlot = stack_slot_to_lval(StackSlotLocn),
             (
                 CheckInUse = yes,
-                \+ lval_in_use(VLI, StackSlot)
+                \+ var_locn_lval_in_use(VLI, StackSlot)
             ;
                 CheckInUse = no
             )
@@ -1754,13 +1774,13 @@
     lval::out) is det.
 
 get_spare_reg_avoid(VLI, Avoid, Lval) :-
-    get_next_non_reserved(VLI, NextNonReserved),
+    var_locn_get_next_non_reserved(VLI, NextNonReserved),
     get_spare_reg_2(VLI, Avoid, NextNonReserved, Lval).
 
 :- pred get_spare_reg(var_locn_info::in, lval::out) is det.
 
 get_spare_reg(VLI, Lval) :-
-    get_next_non_reserved(VLI, NextNonReserved),
+    var_locn_get_next_non_reserved(VLI, NextNonReserved),
     get_spare_reg_2(VLI, [], NextNonReserved, Lval).
 
 :- pred get_spare_reg_2(var_locn_info::in, list(lval)::in, int::in,
@@ -1768,7 +1788,7 @@
 
 get_spare_reg_2(VLI, Avoid, N0, Lval) :-
     TryLval = reg(reg_r, N0),
-    ( lval_in_use(VLI, TryLval) ->
+    ( var_locn_lval_in_use(VLI, TryLval) ->
         get_spare_reg_2(VLI, Avoid, N0 + 1, Lval)
     ; list.member(TryLval, Avoid) ->
         get_spare_reg_2(VLI, Avoid, N0 + 1, Lval)
@@ -1776,10 +1796,10 @@
         Lval = TryLval
     ).
 
-lval_in_use(VLI, Lval) :-
-    get_loc_var_map(VLI, LocVarMap),
-    get_acquired(VLI, Acquired),
-    get_locked(VLI, Locked),
+var_locn_lval_in_use(VLI, Lval) :-
+    var_locn_get_loc_var_map(VLI, LocVarMap),
+    var_locn_get_acquired(VLI, Acquired),
+    var_locn_get_locked(VLI, Locked),
     (
         map.search(LocVarMap, Lval, UsingVars),
         \+ set.empty(UsingVars)
@@ -1798,79 +1818,79 @@
     is semidet.
 
 reg_is_not_locked_for_var(VLI, RegNum, Var) :-
-    get_acquired(VLI, Acquired),
-    get_locked(VLI, Locked),
-    get_exceptions(VLI, Exceptions),
+    var_locn_get_acquired(VLI, Acquired),
+    var_locn_get_locked(VLI, Locked),
+    var_locn_get_exceptions(VLI, Exceptions),
     Reg = reg(reg_r, RegNum),
     \+ set.member(Reg, Acquired),
     RegNum =< Locked => list.member(Var - Reg, Exceptions).
 
 %----------------------------------------------------------------------------%
 
-acquire_reg(Lval, !VLI) :-
+var_locn_acquire_reg(Lval, !VLI) :-
     get_spare_reg(!.VLI, Lval),
-    get_acquired(!.VLI, Acquired0),
+    var_locn_get_acquired(!.VLI, Acquired0),
     set.insert(Acquired0, Lval, Acquired),
-    set_acquired(Acquired, !VLI).
+    var_locn_set_acquired(Acquired, !VLI).
 
-acquire_reg_require_given(Lval, !VLI) :-
-    ( lval_in_use(!.VLI, Lval) ->
+var_locn_acquire_reg_require_given(Lval, !VLI) :-
+    ( var_locn_lval_in_use(!.VLI, Lval) ->
         unexpected(this_file, "acquire_reg_require_given: lval in use")
     ;
         true
     ),
-    get_acquired(!.VLI, Acquired0),
+    var_locn_get_acquired(!.VLI, Acquired0),
     set.insert(Acquired0, Lval, Acquired),
-    set_acquired(Acquired, !VLI).
+    var_locn_set_acquired(Acquired, !VLI).
 
-acquire_reg_prefer_given(Pref, Lval, !VLI) :-
+var_locn_acquire_reg_prefer_given(Pref, Lval, !VLI) :-
     PrefLval = reg(reg_r, Pref),
-    ( lval_in_use(!.VLI, PrefLval) ->
+    ( var_locn_lval_in_use(!.VLI, PrefLval) ->
         get_spare_reg(!.VLI, Lval)
     ;
         Lval = PrefLval
     ),
-    get_acquired(!.VLI, Acquired0),
+    var_locn_get_acquired(!.VLI, Acquired0),
     set.insert(Acquired0, Lval, Acquired),
-    set_acquired(Acquired, !VLI).
+    var_locn_set_acquired(Acquired, !VLI).
 
-acquire_reg_start_at_given(Start, Lval, !VLI) :-
+var_locn_acquire_reg_start_at_given(Start, Lval, !VLI) :-
     StartLval = reg(reg_r, Start),
-    ( lval_in_use(!.VLI, StartLval) ->
-        acquire_reg_start_at_given(Start + 1, Lval, !VLI)
+    ( var_locn_lval_in_use(!.VLI, StartLval) ->
+        var_locn_acquire_reg_start_at_given(Start + 1, Lval, !VLI)
     ;
         Lval = StartLval,
-        get_acquired(!.VLI, Acquired0),
+        var_locn_get_acquired(!.VLI, Acquired0),
         set.insert(Acquired0, Lval, Acquired),
-        set_acquired(Acquired, !VLI)
+        var_locn_set_acquired(Acquired, !VLI)
     ).
 
-release_reg(Lval, !VLI) :-
-    get_acquired(!.VLI, Acquired0),
+var_locn_release_reg(Lval, !VLI) :-
+    var_locn_get_acquired(!.VLI, Acquired0),
     ( set.member(Lval, Acquired0) ->
         set.delete(Acquired0, Lval, Acquired),
-        set_acquired(Acquired, !VLI)
+        var_locn_set_acquired(Acquired, !VLI)
     ;
         unexpected(this_file, "release_reg: unacquired reg")
     ).
 
 %----------------------------------------------------------------------------%
 
-lock_regs(N, Exceptions, !VLI) :-
-    set_locked(N, !VLI),
-    set_exceptions(Exceptions, !VLI).
+var_locn_lock_regs(N, Exceptions, !VLI) :-
+    var_locn_set_locked(N, !VLI),
+    var_locn_set_exceptions(Exceptions, !VLI).
 
-unlock_regs(!VLI) :-
-    set_locked(0, !VLI),
-    set_exceptions([], !VLI).
+var_locn_unlock_regs(!VLI) :-
+    var_locn_set_locked(0, !VLI),
+    var_locn_set_exceptions([], !VLI).
 
 %----------------------------------------------------------------------------%
 
-max_reg_in_use(VLI, Max) :-
-    get_loc_var_map(VLI, LocVarMap),
+var_locn_max_reg_in_use(VLI, Max) :-
+    var_locn_get_loc_var_map(VLI, LocVarMap),
     map.keys(LocVarMap, VarLocs),
     code_util.max_mentioned_reg(VarLocs, Max1),
-    get_acquired(VLI, Acquired),
+    var_locn_get_acquired(VLI, Acquired),
     set.to_sorted_list(Acquired, AcquiredList),
     code_util.max_mentioned_reg(AcquiredList, Max2),
     int.max(Max1, Max2, Max).
@@ -1910,20 +1930,22 @@
     expr_is_constant(VarStateMap, ExprnOpts, Expr0, Expr).
 expr_is_constant(VarStateMap, ExprnOpts, var(Var), Rval) :-
     map.search(VarStateMap, Var, State),
-    State = state(_, yes(Rval), _, _, _),
+    State = var_state(_, yes(Rval), _, _, _),
     expect(expr_is_constant(VarStateMap, ExprnOpts, Rval, _),
         this_file, "non-constant rval in variable state").
 
 %----------------------------------------------------------------------------%
 
-materialize_vars_in_lval(ModuleInfo, Lval0, Lval, Code, !VLI) :-
-    materialize_vars_in_lval(ModuleInfo, Lval0, [], Lval, Code, !VLI).
+var_locn_materialize_vars_in_lval(ModuleInfo, Lval0, Lval, Code, !VLI) :-
+    var_locn_materialize_vars_in_lval_avoid(ModuleInfo, Lval0, [], Lval, Code,
+        !VLI).
 
-:- pred materialize_vars_in_lval(module_info::in, lval::in, list(lval)::in,
-    lval::out, code_tree::out,
+:- pred var_locn_materialize_vars_in_lval_avoid(module_info::in, lval::in,
+    list(lval)::in, lval::out, code_tree::out,
     var_locn_info::in, var_locn_info::out) is det.
 
-materialize_vars_in_lval(ModuleInfo, Lval0, Avoid, Lval, Code, !VLI) :-
+var_locn_materialize_vars_in_lval_avoid(ModuleInfo, Lval0, Avoid, Lval, Code,
+        !VLI) :-
     (
         ( Lval0 = reg(_, _)
         ; Lval0 = stackvar(_)
@@ -1941,78 +1963,79 @@
         Code = empty
     ;
         Lval0 = succip_slot(Rval0),
-        materialize_vars_in_rval(ModuleInfo, Rval0, no, Avoid, Rval, Code,
-            !VLI),
+        var_locn_materialize_vars_in_rval_avoid(ModuleInfo, Rval0, no, Avoid,
+            Rval, Code, !VLI),
         Lval = succip_slot(Rval)
     ;
         Lval0 = redoip_slot(Rval0),
-        materialize_vars_in_rval(ModuleInfo, Rval0, no, Avoid, Rval, Code,
-            !VLI),
+        var_locn_materialize_vars_in_rval_avoid(ModuleInfo, Rval0, no, Avoid,
+            Rval, Code, !VLI),
         Lval = redoip_slot(Rval)
     ;
         Lval0 = succfr_slot(Rval0),
-        materialize_vars_in_rval(ModuleInfo, Rval0, no, Avoid, Rval, Code,
-            !VLI),
+        var_locn_materialize_vars_in_rval_avoid(ModuleInfo, Rval0, no, Avoid,
+            Rval, Code, !VLI),
         Lval = succfr_slot(Rval)
     ;
         Lval0 = redofr_slot(Rval0),
-        materialize_vars_in_rval(ModuleInfo, Rval0, no, Avoid, Rval, Code,
-            !VLI),
+        var_locn_materialize_vars_in_rval_avoid(ModuleInfo, Rval0, no, Avoid,
+            Rval, Code, !VLI),
         Lval = redofr_slot(Rval)
     ;
         Lval0 = prevfr_slot(Rval0),
-        materialize_vars_in_rval(ModuleInfo, Rval0, no, Avoid, Rval, Code,
-            !VLI),
+        var_locn_materialize_vars_in_rval_avoid(ModuleInfo, Rval0, no, Avoid,
+            Rval, Code, !VLI),
         Lval = prevfr_slot(Rval)
     ;
         Lval0 = mem_ref(Rval0),
-        materialize_vars_in_rval(ModuleInfo, Rval0, no, Avoid, Rval, Code,
-            !VLI),
+        var_locn_materialize_vars_in_rval_avoid(ModuleInfo, Rval0, no, Avoid,
+            Rval, Code, !VLI),
         Lval = mem_ref(Rval)
     ;
         Lval0 = field(Tag, RvalA0, RvalB0),
-        materialize_vars_in_rval(ModuleInfo, RvalA0, no, Avoid, RvalA, CodeA,
-            !VLI),
-        materialize_vars_in_rval(ModuleInfo, RvalB0, no, Avoid, RvalB, CodeB,
-            !VLI),
+        var_locn_materialize_vars_in_rval_avoid(ModuleInfo, RvalA0, no, Avoid,
+            RvalA, CodeA, !VLI),
+        var_locn_materialize_vars_in_rval_avoid(ModuleInfo, RvalB0, no, Avoid,
+            RvalB, CodeB, !VLI),
         Lval = field(Tag, RvalA, RvalB),
         Code = tree(CodeA, CodeB)
     ;
         Lval0 = temp(_, _),
-        unexpected(this_file, "materialize_vars_in_lval: temp")
+        unexpected(this_file, "var_locn_materialize_vars_in_lval_avoid: temp")
     ;
         Lval0 = lvar(_),
-        unexpected(this_file, "materialize_vars_in_lval: lvar")
+        unexpected(this_file, "var_locn_materialize_vars_in_lval_avoid: lvar")
     ).
 
     % Rval is Rval0 with all variables in Rval0 replaced by their values.
     %
-:- pred materialize_vars_in_rval(module_info::in, rval::in, maybe(lval)::in,
-    list(lval)::in, rval::out, code_tree::out,
+:- pred var_locn_materialize_vars_in_rval_avoid(module_info::in,
+    rval::in, maybe(lval)::in, list(lval)::in, rval::out, code_tree::out,
     var_locn_info::in, var_locn_info::out) is det.
 
-materialize_vars_in_rval(ModuleInfo, Rval0, MaybePrefer, Avoid, Rval, Code,
-        !VLI) :-
+var_locn_materialize_vars_in_rval_avoid(ModuleInfo, Rval0, MaybePrefer, Avoid,
+        Rval, Code, !VLI) :-
     (
         Rval0 = lval(Lval0),
-        materialize_vars_in_lval(ModuleInfo, Lval0, Avoid, Lval, Code, !VLI),
+        var_locn_materialize_vars_in_lval_avoid(ModuleInfo, Lval0,
+            Avoid, Lval, Code, !VLI),
         Rval = lval(Lval)
     ;
         Rval0 = mkword(Tag, SubRval0),
-        materialize_vars_in_rval(ModuleInfo, SubRval0, no, Avoid, SubRval,
-            Code, !VLI),
+        var_locn_materialize_vars_in_rval_avoid(ModuleInfo, SubRval0, no,
+            Avoid, SubRval, Code, !VLI),
         Rval = mkword(Tag, SubRval)
     ;
         Rval0 = unop(Unop, SubRval0),
-        materialize_vars_in_rval(ModuleInfo, SubRval0, no, Avoid,
-            SubRval, Code, !VLI),
+        var_locn_materialize_vars_in_rval_avoid(ModuleInfo, SubRval0, no,
+            Avoid, SubRval, Code, !VLI),
         Rval = unop(Unop, SubRval)
     ;
         Rval0 = binop(Binop, SubRvalA0, SubRvalB0),
-        materialize_vars_in_rval(ModuleInfo, SubRvalA0, no, Avoid, SubRvalA,
-            CodeA, !VLI),
-        materialize_vars_in_rval(ModuleInfo, SubRvalB0, no, Avoid, SubRvalB,
-            CodeB, !VLI),
+        var_locn_materialize_vars_in_rval_avoid(ModuleInfo, SubRvalA0, no,
+            Avoid, SubRvalA, CodeA, !VLI),
+        var_locn_materialize_vars_in_rval_avoid(ModuleInfo, SubRvalB0, no,
+            Avoid, SubRvalB, CodeB, !VLI),
         Rval = binop(Binop, SubRvalA, SubRvalB),
         Code = tree(CodeA, CodeB)
     ;
@@ -2021,8 +2044,8 @@
         Code = empty
     ;
         Rval0 = mem_addr(MemRef0),
-        materialize_vars_in_mem_ref(ModuleInfo, MemRef0, MemRef, Avoid, Code,
-            !VLI),
+        var_locn_materialize_vars_in_mem_ref_avoid(ModuleInfo, MemRef0, MemRef,
+            Avoid, Code, !VLI),
         Rval = mem_addr(MemRef)
     ;
         Rval0 = var(Var),
@@ -2032,18 +2055,19 @@
             Code = empty
         ;
             Avail = needs_materialization,
-            materialize_var(ModuleInfo, Var, MaybePrefer, yes, Avoid, Rval,
-                Code, !VLI)
+            materialize_var(ModuleInfo, Var, MaybePrefer, yes,
+                Avoid, Rval, Code, !VLI)
         )
     ).
 
     % MemRef is MemRef0 with all variables in MemRef replaced by their values.
     %
-:- pred materialize_vars_in_mem_ref(module_info::in, mem_ref::in, mem_ref::out,
-    list(lval)::in, code_tree::out,
+:- pred var_locn_materialize_vars_in_mem_ref_avoid(module_info::in,
+    mem_ref::in, mem_ref::out, list(lval)::in, code_tree::out,
     var_locn_info::in, var_locn_info::out) is det.
 
-materialize_vars_in_mem_ref(ModuleInfo, MemRef0, MemRef, Avoid, Code, !VLI) :-
+var_locn_materialize_vars_in_mem_ref_avoid(ModuleInfo, MemRef0, MemRef, Avoid,
+        Code, !VLI) :-
     (
         MemRef0 = stackvar_ref(_),
         MemRef = MemRef0,
@@ -2054,10 +2078,10 @@
         Code = empty
     ;
         MemRef0 = heap_ref(PtrRval0, Ptag, FieldNumRval0),
-        materialize_vars_in_rval(ModuleInfo, PtrRval0, no, Avoid,
-            PtrRval, PtrCode, !VLI),
-        materialize_vars_in_rval(ModuleInfo, FieldNumRval0, no, Avoid,
-            FieldNumRval, FieldNumCode, !VLI),
+        var_locn_materialize_vars_in_rval_avoid(ModuleInfo, PtrRval0, no,
+            Avoid, PtrRval, PtrCode, !VLI),
+        var_locn_materialize_vars_in_rval_avoid(ModuleInfo, FieldNumRval0, no,
+            Avoid, FieldNumRval, FieldNumCode, !VLI),
         Code = tree(PtrCode, FieldNumCode),
         MemRef = heap_ref(PtrRval, Ptag, FieldNumRval)
     ).
@@ -2070,9 +2094,9 @@
     maybe(lval)::in, var_avail::out) is det.
 
 find_var_availability(VLI, Var, MaybePrefer, Avail) :-
-    get_var_state_map(VLI, VarStateMap),
+    var_locn_get_var_state_map(VLI, VarStateMap),
     map.lookup(VarStateMap, Var, State),
-    State = state(Lvals, MaybeConstRval, _, _, _),
+    State = var_state(Lvals, MaybeConstRval, _, _, _),
     set.to_sorted_list(Lvals, LvalsList),
     (
         MaybePrefer = yes(Prefer),
@@ -2094,9 +2118,9 @@
 
 materialize_var(ModuleInfo, Var, MaybePrefer, StoreIfReq, Avoid, Rval, Code,
         !VLI) :-
-    get_var_state_map(!.VLI, VarStateMap),
+    var_locn_get_var_state_map(!.VLI, VarStateMap),
     map.lookup(VarStateMap, Var, State),
-    State = state(_Lvals, _MaybeConstRval, MaybeExprRval, UsingVars,
+    State = var_state(_Lvals, _MaybeConstRval, MaybeExprRval, UsingVars,
         _DeadOrAlive),
     (
         MaybeExprRval = yes(ExprRval)
@@ -2104,15 +2128,15 @@
         MaybeExprRval = no,
         unexpected(this_file, "materialize_var: no expr")
     ),
-    materialize_vars_in_rval(ModuleInfo, ExprRval, MaybePrefer, Avoid, Rval0,
-        ExprCode, !VLI),
+    var_locn_materialize_vars_in_rval_avoid(ModuleInfo, ExprRval, MaybePrefer,
+        Avoid, Rval0, ExprCode, !VLI),
     (
         StoreIfReq = yes,
         set.count(UsingVars, NumUsingVars),
         NumUsingVars > 1
     ->
         select_preferred_reg_avoid(!.VLI, Var, Avoid, Lval),
-        place_var(ModuleInfo, Var, Lval, PlaceCode, !VLI),
+        var_locn_place_var(ModuleInfo, Var, Lval, PlaceCode, !VLI),
         Rval = lval(Lval),
         Code = tree(ExprCode, PlaceCode)
     ;
@@ -2250,16 +2274,17 @@
 
 %----------------------------------------------------------------------------%
 
-set_follow_vars(abs_follow_vars(FollowVarMap, NextNonReserved), !VLI) :-
-    set_follow_var_map(FollowVarMap, !VLI),
-    set_next_non_reserved(NextNonReserved, !VLI).
+var_locn_set_follow_vars(abs_follow_vars(FollowVarMap, NextNonReserved),
+        !VLI) :-
+    var_locn_set_follow_var_map(FollowVarMap, !VLI),
+    var_locn_set_next_non_reserved(NextNonReserved, !VLI).
 
 %----------------------------------------------------------------------------%
 
 :- pred get_var_name(var_locn_info::in, prog_var::in, string::out) is det.
 
 get_var_name(VLI, Var, Name) :-
-    get_varset(VLI, VarSet),
+    var_locn_get_varset(VLI, VarSet),
     varset.lookup_name(VarSet, Var, Name).
 
 %----------------------------------------------------------------------------%
@@ -2267,7 +2292,7 @@
 :- pred nonempty_state(var_state::in) is semidet.
 
 nonempty_state(State) :-
-    State = state(LvalSet, MaybeConstRval, MaybeExprRval, _, _),
+    State = var_state(LvalSet, MaybeConstRval, MaybeExprRval, _, _),
     ( set.non_empty(LvalSet)
     ; MaybeConstRval = yes(_)
     ; MaybeExprRval = yes(_)
@@ -2275,50 +2300,50 @@
 
 %----------------------------------------------------------------------------%
 
-:- pred get_varset(var_locn_info::in, prog_varset::out) is det.
-:- pred get_vartypes(var_locn_info::in, vartypes::out) is det.
-:- pred get_exprn_opts(var_locn_info::in, exprn_opts::out) is det.
-:- pred get_var_state_map(var_locn_info::in, var_state_map::out) is det.
-:- pred get_loc_var_map(var_locn_info::in, loc_var_map::out) is det.
-:- pred get_acquired(var_locn_info::in, set(lval)::out) is det.
-:- pred get_locked(var_locn_info::in, int::out) is det.
-:- pred get_exceptions(var_locn_info::in, assoc_list(prog_var, lval)::out)
+:- pred var_locn_get_varset(var_locn_info::in, prog_varset::out) is det.
+:- pred var_locn_get_vartypes(var_locn_info::in, vartypes::out) is det.
+:- pred var_locn_get_exprn_opts(var_locn_info::in, exprn_opts::out) is det.
+:- pred var_locn_get_var_state_map(var_locn_info::in, var_state_map::out) is det.
+:- pred var_locn_get_loc_var_map(var_locn_info::in, loc_var_map::out) is det.
+:- pred var_locn_get_acquired(var_locn_info::in, set(lval)::out) is det.
+:- pred var_locn_get_locked(var_locn_info::in, int::out) is det.
+:- pred var_locn_get_exceptions(var_locn_info::in, assoc_list(prog_var, lval)::out)
     is det.
 
-:- pred set_follow_var_map(abs_follow_vars_map::in,
+:- pred var_locn_set_follow_var_map(abs_follow_vars_map::in,
     var_locn_info::in, var_locn_info::out) is det.
-:- pred set_next_non_reserved(int::in,
+:- pred var_locn_set_next_non_reserved(int::in,
     var_locn_info::in, var_locn_info::out) is det.
-:- pred set_var_state_map(var_state_map::in,
+:- pred var_locn_set_var_state_map(var_state_map::in,
     var_locn_info::in, var_locn_info::out) is det.
-:- pred set_loc_var_map(loc_var_map::in,
+:- pred var_locn_set_loc_var_map(loc_var_map::in,
     var_locn_info::in, var_locn_info::out) is det.
-:- pred set_acquired(set(lval)::in,
+:- pred var_locn_set_acquired(set(lval)::in,
     var_locn_info::in, var_locn_info::out) is det.
-:- pred set_locked(int::in,
+:- pred var_locn_set_locked(int::in,
     var_locn_info::in, var_locn_info::out) is det.
-:- pred set_exceptions(assoc_list(prog_var, lval)::in,
+:- pred var_locn_set_exceptions(assoc_list(prog_var, lval)::in,
     var_locn_info::in, var_locn_info::out) is det.
 
-get_varset(VI, VI ^ varset).
-get_vartypes(VI, VI ^ vartypes).
-get_stack_slots(VI, VI ^ stack_slots).
-get_exprn_opts(VI, VI ^ exprn_opts).
-get_follow_var_map(VI, VI ^ follow_vars_map).
-get_next_non_reserved(VI, VI ^ next_non_res).
-get_var_state_map(VI, VI ^ var_state_map).
-get_loc_var_map(VI, VI ^ loc_var_map).
-get_acquired(VI, VI ^ acquired).
-get_locked(VI, VI ^ locked).
-get_exceptions(VI, VI ^ exceptions).
+var_locn_get_varset(VI, VI ^ varset).
+var_locn_get_vartypes(VI, VI ^ vartypes).
+var_locn_get_stack_slots(VI, VI ^ stack_slots).
+var_locn_get_exprn_opts(VI, VI ^ exprn_opts).
+var_locn_get_follow_var_map(VI, VI ^ follow_vars_map).
+var_locn_get_next_non_reserved(VI, VI ^ next_non_res).
+var_locn_get_var_state_map(VI, VI ^ var_state_map).
+var_locn_get_loc_var_map(VI, VI ^ loc_var_map).
+var_locn_get_acquired(VI, VI ^ acquired).
+var_locn_get_locked(VI, VI ^ locked).
+var_locn_get_exceptions(VI, VI ^ exceptions).
 
-set_follow_var_map(FVM, VI, VI ^ follow_vars_map := FVM).
-set_next_non_reserved(NNR, VI, VI ^ next_non_res := NNR).
-set_var_state_map(VSM, VI, VI ^ var_state_map := VSM).
-set_loc_var_map(LVM, VI, VI ^ loc_var_map := LVM).
-set_acquired(A, VI, VI ^ acquired := A).
-set_locked(L, VI, VI ^ locked := L).
-set_exceptions(E, VI, VI ^ exceptions := E).
+var_locn_set_follow_var_map(FVM, VI, VI ^ follow_vars_map := FVM).
+var_locn_set_next_non_reserved(NNR, VI, VI ^ next_non_res := NNR).
+var_locn_set_var_state_map(VSM, VI, VI ^ var_state_map := VSM).
+var_locn_set_loc_var_map(LVM, VI, VI ^ loc_var_map := LVM).
+var_locn_set_acquired(A, VI, VI ^ acquired := A).
+var_locn_set_locked(L, VI, VI ^ locked := L).
+var_locn_set_exceptions(E, VI, VI ^ exceptions := E).
 
 %----------------------------------------------------------------------------%
 
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/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/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_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/logged_output
cvs diff: Diffing extras/moose
cvs diff: Diffing extras/moose/samples
cvs diff: Diffing extras/moose/tests
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/odbc
cvs diff: Diffing extras/posix
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/stream
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 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/diff
cvs diff: Diffing samples/muz
cvs diff: Diffing samples/rot13
cvs diff: Diffing samples/solutions
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