[m-rev.] diff: more cleanups

Zoltan Somogyi zs at cs.mu.OZ.AU
Tue Oct 11 13:13:06 AEST 2005


compiler/simplify.m:
	Change the names of some predicates so that they are meaningful without
	the module name as prefix. Delete module prefixes to shorten some
	lines.

compiler/magic.m:
compiler/mercury_compile.m:
compiler/size_prof.m:
	Conform to the new names of simplify's predicates.

compiler/typecheck.m:
	Misc cleanups.

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/tests
cvs diff: Diffing browser
cvs diff: Diffing bytecode
cvs diff: Diffing compiler
Index: compiler/magic.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/magic.m,v
retrieving revision 1.57
diff -u -b -r1.57 magic.m
--- compiler/magic.m	30 Sep 2005 08:08:25 -0000	1.57
+++ compiler/magic.m	10 Oct 2005 12:29:00 -0000
@@ -222,7 +222,7 @@
 	% nested explicit quantifications.
 	%
 	globals__io_get_globals(Globals),
-	{ simplify__find_simplifications(no, Globals, Simplifications) },
+	{ find_simplifications(no, Globals, Simplifications) },
 	process_matching_nonimported_procs(
 		update_module_io(
 			magic__ite_to_disj_and_simplify(Simplifications)),
@@ -330,8 +330,7 @@
 		true
 	},
 
-	simplify__proc(Simplifications, PredId, ProcId,
-		!ModuleInfo, !ProcInfo),
+	simplify_proc(Simplifications, PredId, ProcId, !ModuleInfo, !ProcInfo),
 
 	%
 	% Run saved_vars so that constructions of constants are close
Index: compiler/mercury_compile.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/mercury_compile.m,v
retrieving revision 1.353
diff -u -b -r1.353 mercury_compile.m
--- compiler/mercury_compile.m	5 Oct 2005 06:33:43 -0000	1.353
+++ compiler/mercury_compile.m	10 Oct 2005 12:29:00 -0000
@@ -2669,7 +2669,7 @@
     ;
         true
     ),
-    simplify__find_simplifications(no, Globals, Simplifications0),
+    find_simplifications(no, Globals, Simplifications0),
 
     globals.lookup_bool_option(Globals, profile_deep, DeepProf),
     globals.lookup_bool_option(Globals, record_term_sizes_as_words, TSWProf),
@@ -2690,7 +2690,7 @@
         Simplifications = Simplifications0
     ),
       
-    simplify__proc([do_once | Simplifications], PredId, ProcId,
+    simplify_proc([do_once | Simplifications], PredId, ProcId,
         !HLDS, !ProcInfo, !IO),
     write_proc_progress_message("% Computing liveness in ", PredId, ProcId,
         !.HLDS, !IO),
@@ -3094,7 +3094,7 @@
                 ),
                 list.cons(do_once, !Simplifications)
             ),
-            Process(update_pred_error(simplify.pred(!.Simplifications)), !HLDS,
+            Process(update_pred_error(simplify_pred(!.Simplifications)), !HLDS,
                 !IO),
     
             maybe_write_string(Verbose, "% done.\n", !IO),
Index: compiler/simplify.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/simplify.m,v
retrieving revision 1.155
diff -u -b -r1.155 simplify.m
--- compiler/simplify.m	5 Oct 2005 06:33:53 -0000	1.155
+++ compiler/simplify.m	10 Oct 2005 12:29:00 -0000
@@ -46,27 +46,27 @@
 :- import_module list.
 :- import_module map.
 
-:- pred simplify__pred(list(simplification)::in, pred_id::in,
+:- pred simplify_pred(list(simplification)::in, pred_id::in,
     module_info::in, module_info::out, pred_info::in, pred_info::out,
     int::out, int::out, io::di, io::uo) is det.
 
-:- pred simplify__proc(list(simplification)::in, pred_id::in, proc_id::in,
+:- pred simplify_proc(list(simplification)::in, pred_id::in, proc_id::in,
     module_info::in, module_info::out, proc_info::in, proc_info::out,
     io::di, io::uo) is det.
 
-:- pred simplify__proc_return_msgs(list(simplification)::in, pred_id::in,
+:- pred simplify_proc_return_msgs(list(simplification)::in, pred_id::in,
     proc_id::in, module_info::in, module_info::out,
     proc_info::in, proc_info::out, set(det_msg)::out) is det.
 
-:- pred simplify__process_goal(hlds_goal::in, hlds_goal::out,
+:- pred process_goal(hlds_goal::in, hlds_goal::out,
     simplify_info::in, simplify_info::out) is det.
 
     % Find out which simplifications should be run from the options table
     % stored in the globals. The first argument states whether warnings
     % should be issued during this pass of simplification.
     %
-:- pred simplify__find_simplifications(bool::in, globals::in,
-    list(simplification)::out) is det.
+:- pred find_simplifications(bool::in, globals::in, list(simplification)::out)
+    is det.
 
 :- type simplification
     --->    warn_simple_code        % --warn-simple-code
@@ -105,6 +105,7 @@
 :- import_module libs__options.
 :- import_module libs__trace_params.
 :- import_module mdbcomp__prim_data.
+:- import_module parse_tree__error_util.
 :- import_module parse_tree__prog_data.
 :- import_module parse_tree__prog_mode.
 :- import_module parse_tree__prog_util.
@@ -122,7 +123,7 @@
 
 %-----------------------------------------------------------------------------%
 
-simplify__pred(Simplifications0, PredId, !ModuleInfo, !PredInfo,
+simplify_pred(Simplifications0, PredId, !ModuleInfo, !PredInfo,
         WarnCnt, ErrCnt, !IO) :-
     write_pred_progress_message("% Simplifying ", PredId, !.ModuleInfo, !IO),
     ProcIds = pred_info_non_imported_procids(!.PredInfo),
@@ -136,7 +137,7 @@
         Simplifications = Simplifications0
     ),
     MaybeMsgs0 = no,
-    simplify__procs(Simplifications, PredId, ProcIds, !ModuleInfo, !PredInfo,
+    simplify_procs(Simplifications, PredId, ProcIds, !ModuleInfo, !PredInfo,
         MaybeMsgs0, MaybeMsgs),
     (
         MaybeMsgs = yes(Msgs0 - Msgs1),
@@ -149,17 +150,17 @@
         ErrCnt = 0
     ).
 
-:- pred simplify__procs(list(simplification)::in, pred_id::in,
+:- pred simplify_procs(list(simplification)::in, pred_id::in,
     list(proc_id)::in, module_info::in, module_info::out,
     pred_info::in, pred_info::out,
     maybe(pair(set(det_msg)))::in, maybe(pair(set(det_msg)))::out) is det.
 
-simplify__procs(_, _, [], !ModuleInfo, !PredInfo, !Msgs).
-simplify__procs(Simplifications, PredId, [ProcId | ProcIds], !ModuleInfo,
+simplify_procs(_, _, [], !ModuleInfo, !PredInfo, !Msgs).
+simplify_procs(Simplifications, PredId, [ProcId | ProcIds], !ModuleInfo,
         !PredInfo, !MaybeMsgs) :-
     pred_info_procedures(!.PredInfo, Procs0),
     map__lookup(Procs0, ProcId, Proc0),
-    simplify__proc_return_msgs(Simplifications, PredId, ProcId,
+    simplify_proc_return_msgs(Simplifications, PredId, ProcId,
         !ModuleInfo, Proc0, Proc, ProcMsgSet),
     map__det_update(Procs0, ProcId, Proc, Procs),
     pred_info_set_procedures(Procs, !PredInfo),
@@ -178,15 +179,15 @@
         !.MaybeMsgs = no,
         !:MaybeMsgs = yes(ProcAnyModeMsgSet - ProcAllModeMsgSet)
     ),
-    simplify__procs(Simplifications, PredId, ProcIds, !ModuleInfo, !PredInfo,
+    simplify_procs(Simplifications, PredId, ProcIds, !ModuleInfo, !PredInfo,
         !MaybeMsgs).
 
-simplify__proc(Simplifications, PredId, ProcId, !ModuleInfo, !Proc, !IO)  :-
+simplify_proc(Simplifications, PredId, ProcId, !ModuleInfo, !Proc, !IO)  :-
     write_pred_progress_message("% Simplifying ", PredId, !.ModuleInfo, !IO),
-    simplify__proc_return_msgs(Simplifications, PredId, ProcId, !ModuleInfo,
+    simplify_proc_return_msgs(Simplifications, PredId, ProcId, !ModuleInfo,
         !Proc, _).
 
-simplify__proc_return_msgs(Simplifications, PredId, ProcId, !ModuleInfo,
+simplify_proc_return_msgs(Simplifications, PredId, ProcId, !ModuleInfo,
         !ProcInfo, Msgs) :-
     module_info_get_globals(!.ModuleInfo, Globals),
     proc_info_vartypes(!.ProcInfo, VarTypes0),
@@ -211,7 +212,7 @@
         Goal1 = Goal0
     ),
 
-    simplify__process_goal(Goal1, Goal, Info0, Info),
+    process_goal(Goal1, Goal, Info0, Info),
 
     simplify_info_get_varset(Info, VarSet),
     simplify_info_get_var_types(Info, VarTypes),
@@ -223,7 +224,7 @@
     simplify_info_get_module_info(Info, !:ModuleInfo),
     simplify_info_get_msgs(Info, Msgs).
 
-simplify__process_goal(Goal0, Goal, !Info) :-
+process_goal(Goal0, Goal, !Info) :-
     simplify_info_get_simplifications(!.Info, Simplifications0),
     simplify_info_get_instmap(!.Info, InstMap0),
 
@@ -238,7 +239,7 @@
         set__delete_list(Simplifications0, NotOnFirstPass, Simplifications1),
         simplify_info_set_simplifications(Simplifications1, !Info),
 
-        simplify__do_process_goal(Goal0, Goal1, !Info),
+        do_process_goal(Goal0, Goal1, !Info),
 
         NotOnSecondPass = [warn_simple_code, warn_duplicate_calls,
             common_struct, duplicate_calls],
@@ -247,16 +248,16 @@
     ;
         Goal1 = Goal0
     ),
-        % On the second pass do excess assignment elimination and
-        % some cleaning up after the common structure pass.
-    simplify__do_process_goal(Goal1, Goal, !Info).
+    % On the second pass do excess assignment elimination and some cleaning up
+    % after the common structure pass.
+    do_process_goal(Goal1, Goal, !Info).
 
-:- pred simplify__do_process_goal(hlds_goal::in, hlds_goal::out,
+:- pred do_process_goal(hlds_goal::in, hlds_goal::out,
     simplify_info::in, simplify_info::out) is det.
 
-simplify__do_process_goal(Goal0, Goal, !Info) :-
+do_process_goal(Goal0, Goal, !Info) :-
     simplify_info_get_instmap(!.Info, InstMap0),
-    simplify__goal(Goal0, Goal1, !Info),
+    simplify_goal(Goal0, Goal1, !Info),
     simplify_info_get_varset(!.Info, VarSet0),
     simplify_info_get_var_types(!.Info, VarTypes0),
     ( simplify_info_requantify(!.Info) ->
@@ -311,48 +312,45 @@
 
 %-----------------------------------------------------------------------------%
 
-simplify__find_simplifications(WarnThisPass, Globals, Simps) :-
-    simplify__find_simplifications_2(WarnThisPass, Globals, [], Simps).
+find_simplifications(WarnThisPass, Globals, Simps) :-
+    find_simplifications_2(WarnThisPass, Globals, [], Simps).
 
-:- pred simplify__find_simplifications_2(bool::in, globals::in,
+:- pred find_simplifications_2(bool::in, globals::in,
     list(simplification)::in, list(simplification)::out) is det.
 
-simplify__find_simplifications_2(WarnThisPass, Globals, !Simps) :-
-    ( WarnThisPass = yes ->
-        simplify__lookup_option(Globals, warn_duplicate_calls,
+find_simplifications_2(WarnThisPass, Globals, !Simps) :-
+    (
+        WarnThisPass = yes,
+        lookup_option(Globals, warn_duplicate_calls,
             warn_duplicate_calls, !Simps),
-        simplify__lookup_option(Globals, warn_simple_code,
+        lookup_option(Globals, warn_simple_code,
             warn_simple_code, !Simps)
     ;
-        true
+        WarnThisPass = no
     ),
-    simplify__lookup_option(Globals, excess_assign, excess_assigns, !Simps),
-    simplify__lookup_option(Globals, common_struct, common_struct, !Simps),
-    simplify__lookup_option(Globals, optimize_duplicate_calls,
-        duplicate_calls, !Simps),
-    simplify__lookup_option(Globals, constant_propagation,
-        constant_prop, !Simps).
+    lookup_option(Globals, excess_assign, excess_assigns, !Simps),
+    lookup_option(Globals, common_struct, common_struct, !Simps),
+    lookup_option(Globals, optimize_duplicate_calls, duplicate_calls, !Simps),
+    lookup_option(Globals, constant_propagation, constant_prop, !Simps).
 
-:- pred simplify__lookup_option(globals::in, option::in, simplification::in,
+:- pred lookup_option(globals::in, option::in, simplification::in,
     list(simplification)::in, list(simplification)::out) is det.
 
-simplify__lookup_option(Globals, Option, Simplification,
-        Simplifications0, Simplifications) :-
+lookup_option(Globals, Option, Simplification, !Simplifications) :-
     globals__lookup_bool_option(Globals, Option, Result),
     (
         Result = yes,
-        Simplifications = [Simplification | Simplifications0]
+        !:Simplifications = [Simplification | !.Simplifications]
     ;
-        Result = no,
-        Simplifications = Simplifications0
+        Result = no
     ).
 
 %-----------------------------------------------------------------------------%
 
-:- pred simplify__goal(hlds_goal::in, hlds_goal::out,
+:- pred simplify_goal(hlds_goal::in, hlds_goal::out,
     simplify_info::in, simplify_info::out) is det.
 
-simplify__goal(Goal0, Goal - GoalInfo, !Info) :-
+simplify_goal(Goal0, Goal - GoalInfo, !Info) :-
     Goal0 = _ - GoalInfo0,
     goal_info_get_determinism(GoalInfo0, Detism),
     simplify_info_get_det_info(!.Info, DetInfo),
@@ -469,23 +467,23 @@
     % out whether the goal can cause a stack flush.
     %
     ( Goal1 = scope(Reason, SomeGoal1) - GoalInfo1 ->
-        simplify__nested_scopes(Reason, SomeGoal1, GoalInfo1, Goal2)
+        nested_scopes(Reason, SomeGoal1, GoalInfo1, Goal2)
     ;
         Goal2 = Goal1
     ),
     simplify_info_maybe_clear_structs(before, Goal2, !Info),
     Goal2 = GoalExpr2 - GoalInfo2,
-    simplify__goal_2(GoalExpr2, Goal, GoalInfo2, GoalInfo3, !Info),
+    simplify_goal_2(GoalExpr2, Goal, GoalInfo2, GoalInfo3, !Info),
     simplify_info_maybe_clear_structs(after, Goal - GoalInfo3, !Info),
-    simplify__enforce_invariant(GoalInfo3, GoalInfo, !Info).
+    enforce_invariant(GoalInfo3, GoalInfo, !Info).
 
     % Ensure that the mode information and the determinism
     % information say consistent things about unreachability.
     %
-:- pred simplify__enforce_invariant(hlds_goal_info::in, hlds_goal_info::out,
+:- pred enforce_invariant(hlds_goal_info::in, hlds_goal_info::out,
     simplify_info::in, simplify_info::out) is det.
 
-simplify__enforce_invariant(GoalInfo0, GoalInfo, !Info) :-
+enforce_invariant(GoalInfo0, GoalInfo, !Info) :-
     goal_info_get_determinism(GoalInfo0, Determinism0),
     goal_info_get_instmap_delta(GoalInfo0, DeltaInstmap0),
     determinism_components(Determinism0, CanFail0, NumSolns0),
@@ -510,14 +508,14 @@
 
 %-----------------------------------------------------------------------------%
 
-:- pred simplify__goal_2(hlds_goal_expr::in, hlds_goal_expr::out,
+:- pred simplify_goal_2(hlds_goal_expr::in, hlds_goal_expr::out,
     hlds_goal_info::in, hlds_goal_info::out,
     simplify_info::in, simplify_info::out) is det.
 
-simplify__goal_2(conj(Goals0), Goal, GoalInfo0, GoalInfo, !Info) :-
+simplify_goal_2(conj(Goals0), Goal, GoalInfo0, GoalInfo, !Info) :-
     simplify_info_get_instmap(!.Info, InstMap0),
-    simplify__excess_assigns_in_conj(GoalInfo0, Goals0, Goals1, !Info),
-    simplify__conj(Goals1, [], Goals, GoalInfo0, !Info),
+    excess_assigns_in_conj(GoalInfo0, Goals0, Goals1, !Info),
+    simplify_conj(Goals1, [], Goals, GoalInfo0, !Info),
     simplify_info_set_instmap(InstMap0, !Info),
     (
         Goals = [],
@@ -526,8 +524,8 @@
     ;
         Goals = [SingleGoal - SingleGoalInfo],
         % a singleton conjunction is equivalent to the goal itself
-        simplify__maybe_wrap_goal(GoalInfo0, SingleGoalInfo,
-            SingleGoal, Goal, GoalInfo, !Info)
+        maybe_wrap_goal(GoalInfo0, SingleGoalInfo, SingleGoal, Goal, GoalInfo,
+            !Info)
     ;
         Goals = [_, _ | _],
         %
@@ -539,7 +537,7 @@
         (
             simplify_do_once(!.Info),
             determinism_components(Detism, CanFail, at_most_zero),
-            simplify__contains_multisoln_goal(Goals)
+            contains_multisoln_goal(Goals)
         ->
             determinism_components(InnerDetism, CanFail, at_most_many),
             goal_info_set_determinism(InnerDetism, GoalInfo0, InnerInfo),
@@ -551,27 +549,26 @@
         GoalInfo = GoalInfo0
     ).
 
-simplify__goal_2(par_conj(Goals0), Goal, GoalInfo0, GoalInfo, !Info) :-
+simplify_goal_2(par_conj(Goals0), Goal, GoalInfo0, GoalInfo, !Info) :-
     (
         Goals0 = [],
         goal_info_get_context(GoalInfo0, Context),
         true_goal(Context, Goal - GoalInfo)
     ;
         Goals0 = [SingleGoal0],
-        simplify__goal(SingleGoal0, SingleGoal - SingleGoalInfo,
-            !Info),
-        simplify__maybe_wrap_goal(GoalInfo0, SingleGoalInfo,
-            SingleGoal, Goal, GoalInfo, !Info)
+        simplify_goal(SingleGoal0, SingleGoal - SingleGoalInfo, !Info),
+        maybe_wrap_goal(GoalInfo0, SingleGoalInfo, SingleGoal, Goal, GoalInfo,
+            !Info)
     ;
         Goals0 = [_, _ | _],
         GoalInfo = GoalInfo0,
-        simplify__par_conj(Goals0, Goals, !.Info, !Info),
+        simplify_par_conj(Goals0, Goals, !.Info, !Info),
         Goal = par_conj(Goals)
     ).
 
-simplify__goal_2(disj(Disjuncts0), Goal, GoalInfo0, GoalInfo, !Info) :-
+simplify_goal_2(disj(Disjuncts0), Goal, GoalInfo0, GoalInfo, !Info) :-
     simplify_info_get_instmap(!.Info, InstMap0),
-    simplify__disj(Disjuncts0, [], Disjuncts, [], InstMaps, !.Info, !Info),
+    simplify_disj(Disjuncts0, [], Disjuncts, [], InstMaps, !.Info, !Info),
     (
         Disjuncts = [],
         goal_info_get_context(GoalInfo0, Context),
@@ -580,8 +577,7 @@
         Disjuncts = [SingleGoal],
         % A singleton disjunction is equivalent to the goal itself.
         SingleGoal = Goal1 - GoalInfo1,
-        simplify__maybe_wrap_goal(GoalInfo0, GoalInfo1, Goal1, Goal, GoalInfo,
-            !Info)
+        maybe_wrap_goal(GoalInfo0, GoalInfo1, Goal1, Goal, GoalInfo, !Info)
     ;
         Disjuncts = [_, _ | _],
         Goal = disj(Disjuncts),
@@ -617,7 +613,7 @@
         true
     ).
 
-simplify__goal_2(switch(Var, SwitchCanFail0, Cases0), Goal,
+simplify_goal_2(switch(Var, SwitchCanFail0, Cases0), Goal,
         GoalInfo0, GoalInfo, !Info) :-
     simplify_info_get_instmap(!.Info, InstMap0),
     simplify_info_get_module_info(!.Info, ModuleInfo0),
@@ -631,7 +627,7 @@
         Cases1 = Cases0,
         MaybeConsIds = no
     ),
-    simplify__switch(Var, Cases1, [], Cases, [], InstMaps,
+    simplify_switch(Var, Cases1, [], Cases, [], InstMaps,
         SwitchCanFail0, SwitchCanFail, !.Info, !Info),
     (
         Cases = [],
@@ -649,12 +645,11 @@
             SwitchCanFail = can_fail,
             MaybeConsIds \= yes([ConsId])
         ->
-            %
             % Don't optimize in the case of an existentially typed constructor
-            % because currently simplify__create_test_unification does not
-            % handle the existential type variables in the types of the
-            % constructor arguments or their typeinfos.
-            %
+            % because currently create_test_unification does not handle the
+            % existential type variables in the types of the constructor
+            % arguments or their typeinfos.
+
             simplify_info_get_var_types(!.Info, VarTypes1),
             map__lookup(VarTypes1, Var, Type),
             simplify_info_get_module_info(!.Info, ModuleInfo1),
@@ -667,8 +662,7 @@
                 simplify_info_set_module_info(ModuleInfo2, !Info),
                 goal_info_set_instmap_delta(NewDelta, GoalInfo0, GoalInfo)
             ;
-                simplify__create_test_unification(Var, ConsId, Arity,
-                    UnifyGoal, !Info),
+                create_test_unification(Var, ConsId, Arity, UnifyGoal, !Info),
 
                 % Conjoin the test and the rest of the case.
                 goal_to_conj_list(SingleGoal, SingleGoalConj),
@@ -738,7 +732,7 @@
         true
     ).
 
-simplify__goal_2(Goal0, Goal, GoalInfo, GoalInfo, !Info) :-
+simplify_goal_2(Goal0, Goal, GoalInfo, GoalInfo, !Info) :-
     Goal0 = generic_call(GenericCall, Args, Modes, Det),
     (
         simplify_do_calls(!.Info),
@@ -765,7 +759,7 @@
         Goal = Goal0
     ).
 
-simplify__goal_2(Goal0, Goal, GoalInfo0, GoalInfo, !Info) :-
+simplify_goal_2(Goal0, Goal, GoalInfo0, GoalInfo, !Info) :-
     Goal0 = call(PredId, ProcId, Args, IsBuiltin, _, _),
     simplify_info_get_module_info(!.Info, ModuleInfo),
     module_info_pred_info(ModuleInfo, PredId, PredInfo),
@@ -783,14 +777,14 @@
         ; Name = "@>",  Inequality = ">", Invert = no
         )
     ->
-        simplify__inequality_goal(TI, X, Y, Inequality, Invert,
-            GoalInfo0, Goal, GoalInfo, !Info)
+        inequality_goal(TI, X, Y, Inequality, Invert, GoalInfo0,
+            Goal, GoalInfo, !Info)
     ;
-        simplify__call_goal(PredId, ProcId, Args, IsBuiltin,
-            Goal0, Goal, GoalInfo0, GoalInfo, !Info)
+        call_goal(PredId, ProcId, Args, IsBuiltin, Goal0, Goal,
+            GoalInfo0, GoalInfo, !Info)
     ).
 
-simplify__goal_2(Goal0, Goal, GoalInfo0, GoalInfo, !Info) :-
+simplify_goal_2(Goal0, Goal, GoalInfo0, GoalInfo, !Info) :-
     Goal0 = unify(LT0, RT0, M, U0, C),
     (
         % A unification of the form X = X can be safely
@@ -818,7 +812,7 @@
         simplify_info_set_common_info(common_info_init, !Info),
 
         % Don't attempt to pass structs out of lambda_goals.
-        simplify__goal(LambdaGoal0, LambdaGoal, !Info),
+        simplify_goal(LambdaGoal0, LambdaGoal, !Info),
         simplify_info_set_common_info(Common1, !Info),
         simplify_info_set_instmap(InstMap1, !Info),
         RT = lambda_goal(Purity, PredOrFunc, EvalMethod, FixModes,
@@ -830,11 +824,11 @@
         U0 = complicated_unify(UniMode, CanFail, TypeInfoVars)
     ->
         ( RT0 = var(V) ->
-            simplify__process_compl_unify(LT0, V, UniMode, CanFail,
-                TypeInfoVars, C, GoalInfo0, Goal1, !Info),
+            process_compl_unify(LT0, V, UniMode, CanFail, TypeInfoVars, C,
+                GoalInfo0, Goal1, !Info),
             Goal1 = Goal - GoalInfo
         ;
-            error("simplify.m: invalid RHS for complicated unify")
+            unexpected(this_file, "invalid RHS for complicated unify")
         )
     ;
         simplify_do_common(!.Info)
@@ -860,7 +854,7 @@
         GoalInfo = GoalInfo0
     ).
 
-simplify__goal_2(if_then_else(Vars, Cond0, Then0, Else0), Goal,
+simplify_goal_2(if_then_else(Vars, Cond0, Then0, Else0), Goal,
         GoalInfo0, GoalInfo, !Info) :-
     % (A -> B ; C) is logically equivalent to (A, B ; ~A, C).
     % If the determinism of A means that one of these disjuncts
@@ -894,7 +888,7 @@
         goal_to_conj_list(Cond0, CondList),
         goal_to_conj_list(Then0, ThenList),
         list__append(CondList, ThenList, List),
-        simplify__goal(conj(List) - GoalInfo0, Goal - GoalInfo, !Info),
+        simplify_goal(conj(List) - GoalInfo0, Goal - GoalInfo, !Info),
         goal_info_get_context(GoalInfo0, Context),
         simplify_info_add_msg(ite_cond_cannot_fail(Context), !Info),
         simplify_info_set_requantify(!Info),
@@ -926,7 +920,7 @@
                 NegDetism = NegDetism1,
                 NegInstMapDelta = NegInstMapDelta1
             ;
-                error("simplify__goal_2: cannot get negated determinism")
+                unexpected(this_file, "goal_2: cannot get negated determinism")
             ),
             goal_info_set_determinism(NegDetism, CondInfo0, NegCondInfo0),
             goal_info_set_instmap_delta(NegInstMapDelta,
@@ -935,7 +929,7 @@
         ),
         goal_to_conj_list(Else0, ElseList),
         List = [Cond | ElseList],
-        simplify__goal(conj(List) - GoalInfo0, Goal - GoalInfo, !Info),
+        simplify_goal(conj(List) - GoalInfo0, Goal - GoalInfo, !Info),
         goal_info_get_context(GoalInfo0, Context),
         simplify_info_add_msg(ite_cond_cannot_succeed(Context), !Info),
         simplify_info_set_requantify(!Info),
@@ -945,7 +939,7 @@
         goal_to_conj_list(Cond0, CondList),
         goal_to_conj_list(Then0, ThenList),
         list__append(CondList, ThenList, List),
-        simplify__goal(conj(List) - GoalInfo0, Goal - GoalInfo, !Info),
+        simplify_goal(conj(List) - GoalInfo0, Goal - GoalInfo, !Info),
         simplify_info_set_requantify(!Info),
         simplify_info_set_rerun_det(!Info)
     ;
@@ -955,11 +949,11 @@
         %
         Info0 = !.Info,
         simplify_info_get_instmap(!.Info, InstMap0),
-        simplify__goal(Cond0, Cond, !Info),
+        simplify_goal(Cond0, Cond, !Info),
         simplify_info_update_instmap(Cond, !Info),
-        simplify__goal(Then0, Then, !Info),
+        simplify_goal(Then0, Then, !Info),
         simplify_info_post_branch_update(Info0, !Info),
-        simplify__goal(Else0, Else, !Info),
+        simplify_goal(Else0, Else, !Info),
         simplify_info_post_branch_update(Info0, !Info),
         Cond = _ - CondInfo,
         goal_info_get_instmap_delta(CondInfo, CondDelta),
@@ -996,7 +990,7 @@
             )
         ->
             simplify_info_undo_goal_updates(Info0, !Info),
-            simplify__goal_2(IfThenElse, Goal, GoalInfo1, GoalInfo, !Info)
+            simplify_goal_2(IfThenElse, Goal, GoalInfo1, GoalInfo, !Info)
         ;
             (
                 % If-then-elses that are det or semidet may nevertheless
@@ -1021,11 +1015,11 @@
         )
     ).
 
-simplify__goal_2(not(Goal0), Goal, GoalInfo0, GoalInfo, !Info) :-
+simplify_goal_2(not(Goal0), Goal, GoalInfo0, GoalInfo, !Info) :-
     % Can't use calls or unifications seen within a negation,
     % since non-local variables may not be bound within the negation.
     simplify_info_get_common_info(!.Info, Common),
-    simplify__goal(Goal0, Goal1, !Info),
+    simplify_goal(Goal0, Goal1, !Info),
     simplify_info_set_common_info(Common, !Info),
     Goal1 = _ - GoalInfo1,
     goal_info_get_determinism(GoalInfo1, Detism),
@@ -1057,18 +1051,17 @@
         % For now I've just disabled the optimization.
         semidet_fail
     ->
-        simplify__maybe_wrap_goal(GoalInfo0, SubGoalInfo, SubGoal,
-            Goal, GoalInfo, !Info)
+        maybe_wrap_goal(GoalInfo0, SubGoalInfo, SubGoal, Goal, GoalInfo, !Info)
     ;
         Goal = not(Goal1),
         GoalInfo = GoalInfo0
     ).
 
-simplify__goal_2(scope(Reason0, Goal1), GoalExpr, SomeInfo, GoalInfo,
+simplify_goal_2(scope(Reason0, Goal1), GoalExpr, SomeInfo, GoalInfo,
         !Info) :-
     simplify_info_get_common_info(!.Info, Common),
-    simplify__goal(Goal1, Goal2, !Info),
-    simplify__nested_scopes(Reason0, Goal2, SomeInfo, Goal),
+    simplify_goal(Goal1, Goal2, !Info),
+    nested_scopes(Reason0, Goal2, SomeInfo, Goal),
     Goal = GoalExpr - GoalInfo,
     ( Goal = scope(FinalReason, _) - _ ->
         (
@@ -1113,7 +1106,7 @@
         true
     ).
 
-simplify__goal_2(Goal0, Goal, GoalInfo, GoalInfo, !Info) :-
+simplify_goal_2(Goal0, Goal, GoalInfo, GoalInfo, !Info) :-
     Goal0 = foreign_proc(_, PredId, ProcId, Args, ExtraArgs, _),
     (
         simplify_do_calls(!.Info),
@@ -1127,34 +1120,30 @@
         Goal = Goal0
     ).
 
-simplify__goal_2(shorthand(_), _, _, _, !Info) :-
-    % these should have been expanded out by now
-    error("simplify__goal_2: unexpected shorthand").
+simplify_goal_2(shorthand(_), _, _, _, !Info) :-
+    % These should have been expanded out by now.
+    unexpected(this_file, "goal_2: unexpected shorthand").
 
 %-----------------------------------------------------------------------------%
 
-:- pred simplify__inequality_goal(prog_var::in, prog_var::in, prog_var::in,
-    string::in, bool::in, hlds_goal_info::in,
-    hlds_goal_expr::out, hlds_goal_info::out,
+:- pred inequality_goal(prog_var::in, prog_var::in, prog_var::in, string::in,
+    bool::in, hlds_goal_info::in, hlds_goal_expr::out, hlds_goal_info::out,
     simplify_info::in, simplify_info::out) is det.
 
-simplify__inequality_goal(TI, X, Y, Inequality, Invert,
-        GoalInfo, GoalExpr, GoalInfo, !Info) :-
+inequality_goal(TI, X, Y, Inequality, Invert, GoalInfo, GoalExpr, GoalInfo,
+        !Info) :-
 
         % Construct the variable to hold the comparison result.
-        %
     VarSet0 = !.Info ^ varset,
     varset__new_var(VarSet0, R, VarSet),
     !:Info = !.Info ^ varset := VarSet,
 
         % We have to add the type of R to the var_types.
-        %
     simplify_info_get_var_types(!.Info, VarTypes0),
     VarTypes = VarTypes0 ^ elem(R) := comparison_result_type,
     simplify_info_set_var_types(VarTypes, !Info),
 
         % Construct the call to compare/3.
-        %
     mercury_public_builtin_module(BuiltinModule),
     hlds_goal__goal_info_get_context(GoalInfo, Context),
     Args     = [TI, R, X, Y],
@@ -1181,7 +1170,6 @@
     CmpGoal  = CmpExpr - CmpInfo,
 
         % Construct the unification R = Inequality.
-        %
     ConsId   = cons(qualified(BuiltinModule, Inequality), 0),
     Bound    = bound(shared,  [functor(ConsId, [])]),
     UMode    = ((Unique -> Bound) - (Bound -> Bound)),
@@ -1204,27 +1192,25 @@
 
 %-----------------------------------------------------------------------------%
 
-:- pred simplify__call_goal(pred_id::in, proc_id::in, list(prog_var)::in,
+:- pred call_goal(pred_id::in, proc_id::in, list(prog_var)::in,
     builtin_state::in, hlds_goal_expr::in, hlds_goal_expr::out,
     hlds_goal_info::in, hlds_goal_info::out,
     simplify_info::in, simplify_info::out) is det.
 
-simplify__call_goal(PredId, ProcId, Args, IsBuiltin, Goal0, Goal,
-        GoalInfo0, GoalInfo, !Info) :-
+call_goal(PredId, ProcId, Args, IsBuiltin, Goal0, Goal, GoalInfo0, GoalInfo,
+        !Info) :-
     simplify_info_get_module_info(!.Info, ModuleInfo),
     module_info_pred_proc_info(ModuleInfo, PredId, ProcId, PredInfo, ProcInfo),
-    %
     % Check for calls to predicates with `pragma obsolete' declarations.
-    %
     (
         simplify_do_warn(!.Info),
         pred_info_get_markers(PredInfo, Markers),
         check_marker(Markers, obsolete),
-        %
+
         % Don't warn about directly recursive calls. (That would cause
         % spurious warnings, particularly with builtin predicates,
         % or preds defined using foreign_procs.)
-        %
+
         simplify_info_get_det_info(!.Info, DetInfo0),
         det_info_get_pred_id(DetInfo0, ThisPredId),
         PredId \= ThisPredId
@@ -1236,50 +1222,37 @@
         true
     ),
 
-    %
     % Check for recursive calls with the same input arguments,
     % and warn about them (since they will lead to infinite loops).
-    %
     (
         simplify_do_warn(!.Info),
 
-        %
-        % Is this a (directly) recursive call,
-        % i.e. is the procedure being called the same as the
-        % procedure we're analyzing?
-        %
+        % Is this a (directly) recursive call, i.e. is the procedure being
+        % called the same as the procedure we're analyzing?
         simplify_info_get_det_info(!.Info, DetInfo),
         det_info_get_pred_id(DetInfo, PredId),
         det_info_get_proc_id(DetInfo, ProcId),
 
-        %
-        % Don't count inline builtins.
-        % (The compiler generates code for builtins that looks
-        % recursive, so that you can take their address, but since
-        % the recursive call actually expands into inline
-        % instructions, it is not infinite recursion.)
-        %
+        % Don't count inline builtins. (The compiler generates code for
+        % builtins that looks recursive, so that you can take their address,
+        % but since the recursive call actually expands into inline code,
+        % it is not infinite recursion.)
         IsBuiltin \= inline_builtin,
 
-        %
-        % Don't warn if we're inside a lambda goal, because the
-        % recursive call may not be executed.
-        %
+        % Don't warn if we're inside a lambda goal, because the recursive call
+        % may not be executed.
         \+ simplify_info_inside_lambda(!.Info),
 
-        %
         % Are the input arguments the same (or equivalent)?
-        %
         simplify_info_get_module_info(!.Info, ModuleInfo1),
         module_info_pred_proc_info(ModuleInfo1, PredId, ProcId,
             PredInfo1, ProcInfo1),
         proc_info_headvars(ProcInfo1, HeadVars),
         proc_info_argmodes(ProcInfo1, ArgModes),
         simplify_info_get_common_info(!.Info, CommonInfo1),
-        simplify__input_args_are_equiv(Args, HeadVars, ArgModes,
+        input_args_are_equiv(Args, HeadVars, ArgModes,
             CommonInfo1, ModuleInfo1),
 
-        %
         % Don't warn if the input arguments' modes initial insts
         % contain `any' insts, since the arguments might have become
         % more constrained before the recursive call, in which case
@@ -1294,7 +1267,6 @@
         % definite nontermination here, not possible nontermination;
         % warnings about possible nontermination should only be given
         % if the termination analysis pass is enabled.
-        %
         all [ArgMode] (
             (list__member(ArgMode, ArgModes),
              mode_is_input(ModuleInfo1, ArgMode))
@@ -1302,10 +1274,8 @@
             mode_is_fully_input(ModuleInfo1, ArgMode)
         ),
 
-        %
         % Don't count procs using minimal evaluation as they should always
         % terminate if they have a finite number of answers.
-        %
         \+ proc_info_eval_method(ProcInfo, eval_minimal(_)),
 
         % Don't warn about impure procedures, since they may modify the state
@@ -1367,13 +1337,12 @@
 
 %-----------------------------------------------------------------------------%
 
-:- pred simplify__process_compl_unify(prog_var::in, prog_var::in,
-    uni_mode::in, can_fail::in, list(prog_var)::in, unify_context::in,
-    hlds_goal_info::in, hlds_goal::out,
-    simplify_info::in, simplify_info::out) is det.
+:- pred process_compl_unify(prog_var::in, prog_var::in, uni_mode::in,
+    can_fail::in, list(prog_var)::in, unify_context::in, hlds_goal_info::in,
+    hlds_goal::out, simplify_info::in, simplify_info::out) is det.
 
-simplify__process_compl_unify(XVar, YVar, UniMode, CanFail, _OldTypeInfoVars,
-        Context, GoalInfo0, Goal, !Info) :-
+process_compl_unify(XVar, YVar, UniMode, CanFail, _OldTypeInfoVars, Context,
+        GoalInfo0, Goal, !Info) :-
     simplify_info_get_module_info(!.Info, ModuleInfo),
     simplify_info_get_var_types(!.Info, VarTypes),
     map__lookup(VarTypes, XVar, Type),
@@ -1385,10 +1354,9 @@
         % where TypeInfoVar is the type_info variable associated with
         % the type of the variables that are being unified.
         %
-        simplify__type_info_locn(TypeVar, Kind, TypeInfoVar, ExtraGoals,
-            !Info),
-        simplify__call_generic_unify(TypeInfoVar, XVar, YVar, ModuleInfo,
-            !.Info, Context, GoalInfo0, Call)
+        type_info_locn(TypeVar, Kind, TypeInfoVar, ExtraGoals, !Info),
+        call_generic_unify(TypeInfoVar, XVar, YVar, ModuleInfo, !.Info,
+            Context, GoalInfo0, Call)
 
     ; type_is_higher_order(Type, _, _, _, _) ->
         % Convert higher-order unifications into calls to
@@ -1397,7 +1365,7 @@
         generate_simple_call(mercury_private_builtin_module,
             "builtin_unify_pred", predicate, mode_no(0), semidet,
             [XVar, YVar], [], [], ModuleInfo, GContext, Call0 - _),
-        simplify__goal_2(Call0, Call1, GoalInfo0, GoalInfo, !Info),
+        simplify_goal_2(Call0, Call1, GoalInfo0, GoalInfo, !Info),
         Call = Call1 - GoalInfo,
         ExtraGoals = []
     ;
@@ -1405,7 +1373,7 @@
             TypeCtor = TypeCtorPrime,
             TypeArgs = TypeArgsPrime
         ;
-            error("simplify: type_to_ctor_and_args failed")
+            unexpected(this_file, "type_to_ctor_and_args failed")
         ),
         determinism_components(Det, CanFail, at_most_one),
         unify_proc__lookup_mode_num(ModuleInfo, TypeCtor, UniMode, Det,
@@ -1427,52 +1395,49 @@
                 special_pred_is_generated_lazily(ModuleInfo, TypeCtor)
             )
         ->
-            simplify__make_type_info_vars([Type], TypeInfoVars,
-                ExtraGoals, !Info),
+            make_type_info_vars([Type], TypeInfoVars, ExtraGoals, !Info),
             ( TypeInfoVars = [TypeInfoVarPrime] ->
                 TypeInfoVar = TypeInfoVarPrime
             ;
-                error("simplify__process_compl_unify: " ++
+                unexpected(this_file, "process_compl_unify: " ++
                     "more than one typeinfo for one type var")
             ),
-            simplify__call_generic_unify(TypeInfoVar, XVar, YVar,
-                ModuleInfo, !.Info, Context, GoalInfo0, Call)
+            call_generic_unify(TypeInfoVar, XVar, YVar, ModuleInfo, !.Info,
+                Context, GoalInfo0, Call)
         ;
             % Convert other complicated unifications into calls to
             % specific unification predicates, inserting extra typeinfo
             % arguments if necessary.
-            simplify__make_type_info_vars(TypeArgs, TypeInfoVars, ExtraGoals,
-                !Info),
-            simplify__call_specific_unify(TypeCtor, TypeInfoVars, XVar, YVar,
-                ProcId, ModuleInfo, Context, GoalInfo0, Call0, CallGoalInfo0),
-            simplify__goal_2(Call0, Call1, CallGoalInfo0, CallGoalInfo1,
-                !Info),
+            make_type_info_vars(TypeArgs, TypeInfoVars, ExtraGoals, !Info),
+            call_specific_unify(TypeCtor, TypeInfoVars, XVar, YVar, ProcId,
+                ModuleInfo, Context, GoalInfo0, Call0, CallGoalInfo0),
+            simplify_goal_2(Call0, Call1, CallGoalInfo0, CallGoalInfo1, !Info),
             Call = Call1 - CallGoalInfo1
         )
     ),
     list__append(ExtraGoals, [Call], ConjList),
     conj_list_to_goal(ConjList, GoalInfo0, Goal).
 
-:- pred simplify__call_generic_unify(prog_var::in, prog_var::in,  prog_var::in,
+:- pred call_generic_unify(prog_var::in, prog_var::in,  prog_var::in,
     module_info::in, simplify_info::in, unify_context::in,
     hlds_goal_info::in, hlds_goal::out) is det.
 
-simplify__call_generic_unify(TypeInfoVar, XVar, YVar, ModuleInfo, _,
-        _, GoalInfo, Call) :-
+call_generic_unify(TypeInfoVar, XVar, YVar, ModuleInfo, _, _, GoalInfo,
+        Call) :-
     ArgVars = [TypeInfoVar, XVar, YVar],
     goal_info_get_context(GoalInfo, Context),
     goal_util__generate_simple_call(mercury_public_builtin_module,
         "unify", predicate, mode_no(0), semidet, ArgVars, [], [],
         ModuleInfo, Context, Call).
 
-:- pred simplify__call_specific_unify(type_ctor::in, list(prog_var)::in,
+:- pred call_specific_unify(type_ctor::in, list(prog_var)::in,
     prog_var::in, prog_var::in, proc_id::in,
     module_info::in, unify_context::in, hlds_goal_info::in,
     hlds_goal_expr::out, hlds_goal_info::out) is det.
 
-simplify__call_specific_unify(TypeCtor, TypeInfoVars, XVar, YVar, ProcId,
-        ModuleInfo, Context, GoalInfo0, CallExpr, CallGoalInfo) :-
-    % create the new call goal
+call_specific_unify(TypeCtor, TypeInfoVars, XVar, YVar, ProcId, ModuleInfo,
+        Context, GoalInfo0, CallExpr, CallGoalInfo) :-
+    % Create the new call goal.
     list__append(TypeInfoVars, [XVar, YVar], ArgVars),
     module_info_get_special_pred_map(ModuleInfo, SpecialPredMap),
     map__lookup(SpecialPredMap, spec_pred_unify - TypeCtor, PredId),
@@ -1484,15 +1449,15 @@
     CallExpr = call(PredId, ProcId, ArgVars, not_builtin,
         yes(CallContext), SymName),
 
-    % add the extra type_info vars to the nonlocals for the call
+    % Add the extra type_info vars to the nonlocals for the call.
     goal_info_get_nonlocals(GoalInfo0, NonLocals0),
     set__insert_list(NonLocals0, TypeInfoVars, NonLocals),
     goal_info_set_nonlocals(NonLocals, GoalInfo0, CallGoalInfo).
 
-:- pred simplify__make_type_info_vars(list(type)::in, list(prog_var)::out,
+:- pred make_type_info_vars(list(type)::in, list(prog_var)::out,
     list(hlds_goal)::out, simplify_info::in, simplify_info::out) is det.
 
-simplify__make_type_info_vars(Types, TypeInfoVars, TypeInfoGoals, !Info) :-
+make_type_info_vars(Types, TypeInfoVars, TypeInfoGoals, !Info) :-
     % Extract the information from simplify_info.
     simplify_info_get_det_info(!.Info, DetInfo0),
     simplify_info_get_varset(!.Info, VarSet0),
@@ -1541,10 +1506,10 @@
     ),
     simplify_info_set_module_info(ModuleInfo, !Info).
 
-:- pred simplify__type_info_locn(tvar::in, kind::in, prog_var::out,
+:- pred type_info_locn(tvar::in, kind::in, prog_var::out,
     list(hlds_goal)::out, simplify_info::in, simplify_info::out) is det.
 
-simplify__type_info_locn(TypeVar, Kind, TypeInfoVar, Goals, !Info) :-
+type_info_locn(TypeVar, Kind, TypeInfoVar, Goals, !Info) :-
     simplify_info_get_rtti_varmaps(!.Info, RttiVarMaps),
     rtti_lookup_type_info_locn(RttiVarMaps, TypeVar, TypeInfoLocn),
     (
@@ -1554,16 +1519,16 @@
     ;
         % If the typeinfo is in a typeclass_info then we need to extract it.
         TypeInfoLocn = typeclass_info(TypeClassInfoVar, Index),
-        simplify__extract_type_info(TypeVar, Kind, TypeClassInfoVar, Index,
-            Goals, TypeInfoVar, !Info)
+        extract_type_info(TypeVar, Kind, TypeClassInfoVar, Index, Goals,
+            TypeInfoVar, !Info)
     ).
 
-:- pred simplify__extract_type_info(tvar::in, kind::in, prog_var::in, int::in,
+:- pred extract_type_info(tvar::in, kind::in, prog_var::in, int::in,
     list(hlds_goal)::out, prog_var::out,
     simplify_info::in, simplify_info::out) is det.
 
-simplify__extract_type_info(TypeVar, Kind, TypeClassInfoVar, Index,
-        Goals, TypeInfoVar, !Info) :-
+extract_type_info(TypeVar, Kind, TypeClassInfoVar, Index, Goals, TypeInfoVar,
+        !Info) :-
     simplify_info_get_module_info(!.Info, ModuleInfo),
     simplify_info_get_varset(!.Info, VarSet0),
     simplify_info_get_var_types(!.Info, VarTypes0),
@@ -1579,37 +1544,35 @@
 
 %-----------------------------------------------------------------------------%
 
-    % simplify__input_args_are_equiv(Args, HeadVars, Modes,
-    %       CommonInfo, ModuleInfo1):
+    % input_args_are_equiv(Args, HeadVars, Modes, CommonInfo, ModuleInfo1):
     %
     % Succeeds if all the input arguments (determined by looking at `Modes')
     % in `Args' are equivalent (according to the equivalence class specified
     % by `CommonInfo') to the corresponding variables in HeadVars.
     % HeadVars, Modes, and Args should all be lists of the same length.
     %
-:- pred simplify__input_args_are_equiv(list(prog_var)::in, list(prog_var)::in,
+:- pred input_args_are_equiv(list(prog_var)::in, list(prog_var)::in,
     list(mode)::in, common_info::in, module_info::in) is semidet.
 
-simplify__input_args_are_equiv([], [], _, _, _).
-simplify__input_args_are_equiv([Arg | Args], [HeadVar | HeadVars],
-        [Mode | Modes], CommonInfo, ModuleInfo) :-
+input_args_are_equiv([], [], _, _, _).
+input_args_are_equiv([Arg | Args], [HeadVar | HeadVars], [Mode | Modes],
+        CommonInfo, ModuleInfo) :-
     ( mode_is_input(ModuleInfo, Mode) ->
         common__vars_are_equivalent(Arg, HeadVar, CommonInfo)
     ;
         true
     ),
-    simplify__input_args_are_equiv(Args, HeadVars, Modes, CommonInfo,
-        ModuleInfo).
+    input_args_are_equiv(Args, HeadVars, Modes, CommonInfo, ModuleInfo).
 
 %-----------------------------------------------------------------------------%
 
     % replace nested `scope's with a single `scope',
     %
-:- pred simplify__nested_scopes(scope_reason::in, hlds_goal::in,
+:- pred nested_scopes(scope_reason::in, hlds_goal::in,
     hlds_goal_info::in, hlds_goal::out) is det.
 
-simplify__nested_scopes(Reason0, InnerGoal0, OuterGoalInfo, Goal) :-
-    simplify__nested_scopes_2(Reason0, Reason, InnerGoal0, InnerGoal),
+nested_scopes(Reason0, InnerGoal0, OuterGoalInfo, Goal) :-
+    nested_scopes_2(Reason0, Reason, InnerGoal0, InnerGoal),
     InnerGoal = _ - GoalInfo,
     (
         Reason = exist_quant(_),
@@ -1622,10 +1585,10 @@
         Goal = scope(Reason, InnerGoal) - OuterGoalInfo
     ).
 
-:- pred simplify__nested_scopes_2(scope_reason::in, scope_reason::out,
+:- pred nested_scopes_2(scope_reason::in, scope_reason::out,
     hlds_goal::in, hlds_goal::out) is det.
 
-simplify__nested_scopes_2(Reason0, Reason, Goal0, Goal) :-
+nested_scopes_2(Reason0, Reason, Goal0, Goal) :-
     (
         Goal0 = scope(Reason1, Goal1) - _GoalInfo0,
         (
@@ -1672,7 +1635,7 @@
             fail
         )
     ->
-        simplify__nested_scopes_2(Reason2, Reason, Goal1, Goal)
+        nested_scopes_2(Reason2, Reason, Goal1, Goal)
     ;
         Reason = Reason0,
         Goal = Goal0
@@ -1687,12 +1650,11 @@
     % if the inner and outer determinisms are not the same. It probably
     % won't happen that often.
     %
-:- pred simplify__maybe_wrap_goal(hlds_goal_info::in, hlds_goal_info::in,
+:- pred maybe_wrap_goal(hlds_goal_info::in, hlds_goal_info::in,
     hlds_goal_expr::in, hlds_goal_expr::out, hlds_goal_info::out,
     simplify_info::in, simplify_info::out)  is det.
 
-simplify__maybe_wrap_goal(OuterGoalInfo, InnerGoalInfo,
-        Goal1, Goal, GoalInfo, !Info) :-
+maybe_wrap_goal(OuterGoalInfo, InnerGoalInfo, Goal1, Goal, GoalInfo, !Info) :-
     (
         goal_info_get_determinism(InnerGoalInfo, Det),
         goal_info_get_determinism(OuterGoalInfo, Det)
@@ -1707,27 +1669,27 @@
 
 %-----------------------------------------------------------------------------%
 
-:- pred simplify__conj(list(hlds_goal)::in, list(hlds_goal)::in,
+:- pred simplify_conj(list(hlds_goal)::in, list(hlds_goal)::in,
     list(hlds_goal)::out, hlds_goal_info::in,
     simplify_info::in, simplify_info::out) is det.
 
-simplify__conj([], RevGoals, Goals, _, !Info) :-
+simplify_conj([], RevGoals, Goals, _, !Info) :-
     list__reverse(RevGoals, Goals).
-simplify__conj([Goal0 | Goals0], !.RevGoals, Goals, ConjInfo, !Info) :-
+simplify_conj([Goal0 | Goals0], !.RevGoals, Goals, ConjInfo, !Info) :-
     Info0 = !.Info,
     % Flatten conjunctions.
     ( Goal0 = conj(SubGoals) - _ ->
         list__append(SubGoals, Goals0, Goals1),
-        simplify__conj(Goals1, !.RevGoals, Goals, ConjInfo, !Info)
+        simplify_conj(Goals1, !.RevGoals, Goals, ConjInfo, !Info)
     ;
-        simplify__goal(Goal0, Goal1, !Info),
+        simplify_goal(Goal0, Goal1, !Info),
         (
             % Flatten conjunctions.
             Goal1 = conj(SubGoals1) - _
         ->
             simplify_info_undo_goal_updates(Info0, !Info),
             list__append(SubGoals1, Goals0, Goals1),
-            simplify__conj(Goals1, !.RevGoals, Goals, ConjInfo, !Info)
+            simplify_conj(Goals1, !.RevGoals, Goals, ConjInfo, !Info)
         ;
             % Delete unreachable goals.
             (
@@ -1739,7 +1701,7 @@
                 determinism_components(Detism1, _, at_most_zero)
             )
         ->
-            simplify__conjoin_goal_and_rev_goal_list(Goal1, !RevGoals),
+            conjoin_goal_and_rev_goal_list(Goal1, !RevGoals),
             (
                 ( Goal1 = disj([]) - _
                 ; Goals0 = []
@@ -1758,20 +1720,20 @@
                 Goal0 = _ - GoalInfo0,
                 goal_info_get_context(GoalInfo0, Context),
                 fail_goal(Context, Fail),
-                simplify__conjoin_goal_and_rev_goal_list(Fail, !RevGoals)
+                conjoin_goal_and_rev_goal_list(Fail, !RevGoals)
             ),
             list__reverse(!.RevGoals, Goals)
         ;
-            simplify__conjoin_goal_and_rev_goal_list(Goal1, !RevGoals),
+            conjoin_goal_and_rev_goal_list(Goal1, !RevGoals),
             simplify_info_update_instmap(Goal1, !Info),
-            simplify__conj(Goals0, !.RevGoals, Goals, ConjInfo, !Info)
+            simplify_conj(Goals0, !.RevGoals, Goals, ConjInfo, !Info)
         )
     ).
 
-:- pred simplify__conjoin_goal_and_rev_goal_list(hlds_goal::in,
+:- pred conjoin_goal_and_rev_goal_list(hlds_goal::in,
     hlds_goals::in, hlds_goals::out) is det.
 
-simplify__conjoin_goal_and_rev_goal_list(Goal, RevGoals0, RevGoals) :-
+conjoin_goal_and_rev_goal_list(Goal, RevGoals0, RevGoals) :-
     ( Goal = conj(Goals) - _ ->
         list__reverse(Goals, Goals1),
         list__append(Goals1, RevGoals0, RevGoals)
@@ -1781,22 +1743,22 @@
 
 %-----------------------------------------------------------------------------%
 
-:- pred simplify__par_conj(list(hlds_goal)::in, list(hlds_goal)::out,
+:- pred simplify_par_conj(list(hlds_goal)::in, list(hlds_goal)::out,
     simplify_info::in, simplify_info::in, simplify_info::out) is det.
 
-simplify__par_conj([], [], _, !Info).
-simplify__par_conj([Goal0 |Goals0], [Goal | Goals], Info0, !Info) :-
-    simplify__goal(Goal0, Goal, !Info),
+simplify_par_conj([], [], _, !Info).
+simplify_par_conj([Goal0 |Goals0], [Goal | Goals], Info0, !Info) :-
+    simplify_goal(Goal0, Goal, !Info),
     simplify_info_post_branch_update(Info0, !Info),
-    simplify__par_conj(Goals0, Goals, Info0, !Info).
+    simplify_par_conj(Goals0, Goals, Info0, !Info).
 
 %-----------------------------------------------------------------------------%
 
-:- pred simplify__excess_assigns_in_conj(hlds_goal_info::in,
+:- pred excess_assigns_in_conj(hlds_goal_info::in,
     list(hlds_goal)::in, list(hlds_goal)::out,
     simplify_info::in, simplify_info::out) is det.
 
-simplify__excess_assigns_in_conj(ConjInfo, Goals0, Goals, !Info) :-
+excess_assigns_in_conj(ConjInfo, Goals0, Goals, !Info) :-
     ( simplify_do_excess_assigns(!.Info) ->
         goal_info_get_nonlocals(ConjInfo, ConjNonLocals),
         map__init(Subn0),
@@ -1805,7 +1767,7 @@
         globals__get_trace_level(Globals, TraceLevel),
         globals__lookup_bool_option(Globals, trace_optimized, TraceOptimized),
         simplify_info_get_varset(!.Info, VarSet0),
-        simplify__find_excess_assigns_in_conj(TraceLevel, TraceOptimized,
+        find_excess_assigns_in_conj(TraceLevel, TraceOptimized,
             VarSet0, ConjNonLocals, Goals0, [], RevGoals, Subn0, Subn1),
         ( map__is_empty(Subn1) ->
             Goals = Goals0
@@ -1828,14 +1790,14 @@
 
 :- type var_renaming == map(prog_var, prog_var).
 
-:- pred simplify__find_excess_assigns_in_conj(trace_level::in, bool::in,
+:- pred find_excess_assigns_in_conj(trace_level::in, bool::in,
     prog_varset::in, set(prog_var)::in, list(hlds_goal)::in,
     list(hlds_goal)::in, list(hlds_goal)::out,
     var_renaming::in, var_renaming::out) is det.
 
-simplify__find_excess_assigns_in_conj(_, _, _, _, [], !RevGoals, !Subn).
-simplify__find_excess_assigns_in_conj(Trace, TraceOptimized, VarSet,
-        ConjNonLocals, [Goal | Goals], !RevGoals, !Subn) :-
+find_excess_assigns_in_conj(_, _, _, _, [], !RevGoals, !Subn).
+find_excess_assigns_in_conj(Trace, TraceOptimized, VarSet, ConjNonLocals,
+        [Goal | Goals], !RevGoals, !Subn) :-
     (
         goal_is_excess_assign(Trace, TraceOptimized, VarSet, ConjNonLocals,
             Goal, !Subn)
@@ -1844,8 +1806,8 @@
     ;
         !:RevGoals = [Goal | !.RevGoals]
     ),
-    simplify__find_excess_assigns_in_conj(Trace, TraceOptimized, VarSet,
-        ConjNonLocals, Goals, !RevGoals, !Subn).
+    find_excess_assigns_in_conj(Trace, TraceOptimized, VarSet, ConjNonLocals,
+        Goals, !RevGoals, !Subn).
 
 :- pred goal_is_excess_assign(trace_level::in, bool::in, prog_varset::in,
     set(prog_var)::in, hlds_goal::in, var_renaming::in,
@@ -1924,14 +1886,14 @@
 
 %-----------------------------------------------------------------------------%
 
-:- pred simplify__switch(prog_var::in, list(case)::in, list(case)::in,
+:- pred simplify_switch(prog_var::in, list(case)::in, list(case)::in,
     list(case)::out, list(instmap_delta)::in, list(instmap_delta)::out,
     can_fail::in, can_fail::out, simplify_info::in,
     simplify_info::in, simplify_info::out) is det.
 
-simplify__switch(_, [], RevCases, Cases, !InstMaps, !CanFail, _, !Info) :-
+simplify_switch(_, [], RevCases, Cases, !InstMaps, !CanFail, _, !Info) :-
     list__reverse(RevCases, Cases).
-simplify__switch(Var, [Case0 | Cases0], RevCases0, Cases, !InstMaps,
+simplify_switch(Var, [Case0 | Cases0], RevCases0, Cases, !InstMaps,
         !CanFail, Info0, !Info) :-
     simplify_info_get_instmap(Info0, InstMap0),
     Case0 = case(ConsId, Goal0),
@@ -1942,7 +1904,7 @@
         ModuleInfo0, ModuleInfo1),
     simplify_info_set_module_info(ModuleInfo1, !Info),
     simplify_info_set_instmap(InstMap1, !Info),
-    simplify__goal(Goal0, Goal, !Info),
+    simplify_goal(Goal0, Goal, !Info),
 
         % Remove failing branches.
     ( Goal = disj([]) - _ ->
@@ -1970,18 +1932,18 @@
     ),
 
     simplify_info_post_branch_update(Info0, !Info),
-    simplify__switch(Var, Cases0, RevCases, Cases, !InstMaps, !CanFail,
-        Info0, !Info).
+    simplify_switch(Var, Cases0, RevCases, Cases, !InstMaps, !CanFail, Info0,
+        !Info).
 
     % Create a semidet unification at the start of a singleton case
     % in a can_fail switch.
     % This will abort if the cons_id is existentially typed.
     %
-:- pred simplify__create_test_unification(prog_var::in, cons_id::in, int::in,
+:- pred create_test_unification(prog_var::in, cons_id::in, int::in,
     hlds_goal::out, simplify_info::in, simplify_info::out) is det.
 
-simplify__create_test_unification(Var, ConsId, ConsArity,
-        ExtraGoal - ExtraGoalInfo, !Info) :-
+create_test_unification(Var, ConsId, ConsArity, ExtraGoal - ExtraGoalInfo,
+        !Info) :-
     simplify_info_get_varset(!.Info, VarSet0),
     simplify_info_get_var_types(!.Info, VarTypes0),
     varset__new_vars(VarSet0, ConsArity, ArgVars, VarSet),
@@ -2001,7 +1963,7 @@
     ->
         ArgInsts = ArgInsts1
     ;
-        error("simplify__goal_2 - get_arg_insts failed")
+        unexpected(this_file, "create_test_unification - get_arg_insts failed")
     ),
     InstToUniMode =
         (pred(ArgInst::in, ArgUniMode::out) is det :-
@@ -2022,16 +1984,16 @@
 
 %-----------------------------------------------------------------------------%
 
-:- pred simplify__disj(list(hlds_goal)::in, list(hlds_goal)::in,
+:- pred simplify_disj(list(hlds_goal)::in, list(hlds_goal)::in,
     list(hlds_goal)::out,
     list(instmap_delta)::in, list(instmap_delta)::out,
     simplify_info::in, simplify_info::in, simplify_info::out) is det.
 
-simplify__disj([], RevGoals, Goals, !PostBranchInstMaps, _, !Info) :-
+simplify_disj([], RevGoals, Goals, !PostBranchInstMaps, _, !Info) :-
     list__reverse(RevGoals, Goals).
-simplify__disj([Goal0 | Goals0], RevGoals0, Goals, !PostBranchInstMaps,
+simplify_disj([Goal0 | Goals0], RevGoals0, Goals, !PostBranchInstMaps,
         Info0, !Info) :-
-    simplify__goal(Goal0, Goal, !Info),
+    simplify_goal(Goal0, Goal, !Info),
     Goal = _ - GoalInfo,
 
     (
@@ -2078,8 +2040,7 @@
     ),
 
     simplify_info_post_branch_update(Info0, !Info),
-    simplify__disj(Goals0, RevGoals1, Goals, !PostBranchInstMaps,
-        Info0, !Info).
+    simplify_disj(Goals0, RevGoals1, Goals, !PostBranchInstMaps, Info0, !Info).
 
     % Disjunctions that cannot succeed more than once when viewed from the
     % outside generally need some fixing up, and/or some warnings to be issued.
@@ -2105,18 +2066,17 @@
     %       ;
     %           OutputVars = yes
     %       ),
-    %       simplify__fixup_disj(Disjuncts, Detism, OutputVars,
-    %           GoalInfo, InstMap0, DetInfo, Goal,
-    %           MsgsA, Msgs)
+    %       fixup_disj(Disjuncts, Detism, OutputVars, GoalInfo, InstMap0,
+    %           DetInfo, Goal, MsgsA, Msgs)
     %   ;
     %
-:- pred simplify__fixup_disj(list(hlds_goal)::in, determinism::in, bool::in,
+:- pred fixup_disj(list(hlds_goal)::in, determinism::in, bool::in,
     hlds_goal_info::in, hlds_goal_expr::out,
     simplify_info::in, simplify_info::out) is det.
 
-simplify__fixup_disj(Disjuncts, _, _OutputVars, GoalInfo, Goal, !Info) :-
+fixup_disj(Disjuncts, _, _OutputVars, GoalInfo, Goal, !Info) :-
     det_disj_to_ite(Disjuncts, GoalInfo, IfThenElse),
-    simplify__goal(IfThenElse, Simplified, !Info),
+    simplify_goal(IfThenElse, Simplified, !Info),
     Simplified = Goal - _.
 
     % det_disj_to_ite is used to transform disjunctions that occur
@@ -2140,7 +2100,7 @@
     hlds_goal::out) is det.
 
 det_disj_to_ite([], _GoalInfo, _) :-
-    error("reached base case of det_disj_to_ite").
+    unexpected(this_file, "reached base case of det_disj_to_ite").
 det_disj_to_ite([Disjunct | Disjuncts], GoalInfo, Goal) :-
     (
         Disjuncts = [],
@@ -2183,9 +2143,9 @@
 
 %-----------------------------------------------------------------------------%
 
-:- pred simplify__contains_multisoln_goal(list(hlds_goal)::in) is semidet.
+:- pred contains_multisoln_goal(list(hlds_goal)::in) is semidet.
 
-simplify__contains_multisoln_goal(Goals) :-
+contains_multisoln_goal(Goals) :-
     list__member(_Goal - GoalInfo, Goals),
     goal_info_get_determinism(GoalInfo, Detism),
     determinism_components(Detism, _, at_most_many).
@@ -2385,7 +2345,7 @@
     ( LambdaCount1 >= 0 ->
         LambdaCount = LambdaCount1
     ;
-        error("simplify_info_leave_lambda: Left too many lambdas")
+        unexpected(this_file, "simplify_info_leave_lambda: Left too many lambdas")
     ).
 simplify_info_inside_lambda(Info) :-
     Info ^ lambdas > 0.
@@ -2557,7 +2517,7 @@
 will_flush(scope(_, _), _) = no.
 will_flush(shorthand(_), _) = _ :-
     % These should have been expanded out by now.
-    error("will_flush: unexpected shorthand").
+    unexpected(this_file, "will_flush: unexpected shorthand").
 
     % Reset the instmap and seen calls for the next branch.
 :- pred simplify_info_post_branch_update(simplify_info::in, simplify_info::in,
@@ -2569,8 +2529,9 @@
     simplify_info_get_common_info(PreBranchInfo, Common),
     simplify_info_set_common_info(Common, PostBranchInfo1, Info).
 
-    % Undo updates to the simplify_info before redoing
-    % simplification on a goal.
+    % Undo updates to the simplify_info before redoing simplification
+    % on a goal.
+    %
 :- pred simplify_info_undo_goal_updates(simplify_info::in, simplify_info::in,
     simplify_info::out) is det.
 
@@ -2579,5 +2540,11 @@
     simplify_info_set_common_info(CommonInfo0, !Info),
     simplify_info_get_instmap(Info0, InstMap),
     simplify_info_set_instmap(InstMap, !Info).
+
+%-----------------------------------------------------------------------------%
+
+:- func this_file = string.
+
+this_file = "simplify.m".
 
 %-----------------------------------------------------------------------------%
Index: compiler/size_prof.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/size_prof.m,v
retrieving revision 1.25
diff -u -b -r1.25 size_prof.m
--- compiler/size_prof.m	5 Oct 2005 06:33:53 -0000	1.25
+++ compiler/size_prof.m	10 Oct 2005 12:29:00 -0000
@@ -237,7 +237,7 @@
 
 process_proc(Transform, PredId, ProcId, !ProcInfo, !ModuleInfo) :-
     Simplifications = [],
-    simplify__proc_return_msgs(Simplifications, PredId, ProcId,
+    simplify_proc_return_msgs(Simplifications, PredId, ProcId,
         !ModuleInfo, !ProcInfo, _Msgs),
 
     proc_info_goal(!.ProcInfo, Goal0),
Index: compiler/stack_opt.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/stack_opt.m,v
retrieving revision 1.19
diff -u -b -r1.19 stack_opt.m
--- compiler/stack_opt.m	30 Sep 2005 08:08:34 -0000	1.19
+++ compiler/stack_opt.m	10 Oct 2005 12:29:00 -0000
@@ -169,7 +169,7 @@
 	% This simplication is necessary to fix some bad inputs from
 	% getting to the liveness computation.
 	% (see tests/valid/stack_opt_simplify.m)
-	simplify__proc([], PredId, ProcId, !ModuleInfo, !ProcInfo, !IO),
+	simplify_proc([], PredId, ProcId, !ModuleInfo, !ProcInfo, !IO),
 	detect_liveness_proc(PredId, ProcId, !.ModuleInfo, !ProcInfo, !IO),
 	initial_liveness(!.ProcInfo, PredId, !.ModuleInfo, Liveness0),
 	module_info_get_globals(!.ModuleInfo, Globals),
Index: compiler/typecheck.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/typecheck.m,v
retrieving revision 1.378
diff -u -b -r1.378 typecheck.m
--- compiler/typecheck.m	5 Oct 2005 06:33:59 -0000	1.378
+++ compiler/typecheck.m	10 Oct 2005 13:21:08 -0000
@@ -197,15 +197,20 @@
         FoundError, ExceededIterationLimit, !IO) :-
     typecheck_module_one_iteration(Iteration, PredIds, !Module,
         no, FoundError1, no, Changed, !IO),
-    ( ( Changed = no ; FoundError1 = yes ) ->
+    (
+        ( Changed = no
+        ; FoundError1 = yes
+        )
+    ->
         FoundError = FoundError1,
         ExceededIterationLimit = no
     ;
         globals__io_lookup_bool_option(debug_types, DebugTypes, !IO),
-        ( DebugTypes = yes ->
+        (
+            DebugTypes = yes,
             write_inference_messages(PredIds, !.Module, !IO)
         ;
-            true
+            DebugTypes = no
         ),
         ( Iteration < NumIterations ->
             typecheck_to_fixpoint(Iteration + 1, NumIterations, PredIds,
@@ -236,7 +241,7 @@
 %-----------------------------------------------------------------------------%
 
     % Iterate over the list of pred_ids in a module.
-
+    %
 :- pred typecheck_module_one_iteration(int::in, list(pred_id)::in,
     module_info::in, module_info::out, bool::in, bool::out,
     bool::in, bool::out, io::di, io::uo) is det.
@@ -296,13 +301,12 @@
 typecheck_pred_if_needed(Iteration, PredId, !PredInfo, !ModuleInfo,
         Error, Changed, !IO) :-
     (
-        % Compiler-generated predicates are created already
-        % type-correct, so there's no need to typecheck them.
-        % The same is true for builtins. But, compiler-generated
-        % unify predicates are not guaranteed to be type-correct
-        % if they call a user-defined equality or comparison predicate
-        % or if it is a special pred for an existentially typed data
-        % type.
+        % Compiler-generated predicates are created already type-correct,
+        % so there's no need to typecheck them. The same is true for builtins.
+        % But, compiler-generated unify predicates are not guaranteed to be
+        % type-correct if they call a user-defined equality or comparison
+        % predicate or if it is a special pred for an existentially typed
+        % data type.
         (
             is_unify_or_compare_pred(!.PredInfo),
             \+ special_pred_needs_typecheck(!.PredInfo, !.ModuleInfo)
@@ -394,10 +398,9 @@
                 map__from_corresponding_lists(HeadVars, ArgTypes0, VarTypes),
                 clauses_info_set_vartypes(VarTypes, !ClausesInfo),
                 pred_info_set_clauses_info(!.ClausesInfo, !PredInfo),
-                    % We also need to set the head_type_params field
-                    % to indicate that all the existentially quantified tvars
-                    % in the head of this pred are indeed bound by this
-                    % predicate.
+                % We also need to set the head_type_params field to indicate
+                % that all the existentially quantified tvars in the head
+                % of this pred are indeed bound by this predicate.
                 prog_type__vars_list(ArgTypes0, HeadVarsIncludingExistentials),
                 pred_info_set_head_type_params(HeadVarsIncludingExistentials,
                     !PredInfo),
@@ -418,12 +421,11 @@
             pred_info_typevarset(!.PredInfo, TypeVarSet0),
             pred_info_import_status(!.PredInfo, Status),
             ( check_marker(Markers0, infer_type) ->
-                % For a predicate whose type is inferred,
-                % the predicate is allowed to bind the type
-                % variables in the head of the predicate's
-                % type declaration.  Such predicates are given an
-                % initial type declaration of
-                % `pred foo(T1, T2, ..., TN)' by make_hlds.m.
+                % For a predicate whose type is inferred, the predicate is
+                % allowed to bind the type variables in the head of the
+                % predicate's type declaration. Such predicates are given an
+                % initial type declaration of `pred foo(T1, T2, ..., TN)'
+                % by make_hlds.m.
                 Inferring = yes,
                 write_pred_progress_message("% Inferring type of ",
                     PredId, !.ModuleInfo, !IO),
@@ -471,9 +473,7 @@
             map__optimize(InferredVarTypes0, InferredVarTypes),
             clauses_info_set_vartypes(InferredVarTypes, !ClausesInfo),
 
-            %
             % Apply substitutions to the explicit vartypes.
-            %
             (
                 ExistQVars0 = [],
                 ExplicitVarTypes1 = ExplicitVarTypes0
@@ -492,49 +492,39 @@
             pred_info_set_constraint_proofs(ConstraintProofs, !PredInfo),
             pred_info_set_constraint_map(ConstraintMap, !PredInfo),
 
-            %
-            % Split the inferred type class constraints into those
-            % that apply only to the head variables, and those that
-            % apply to type variables which occur only in the body.
-            %
+            % Split the inferred type class constraints into those that
+            % apply only to the head variables, and those that apply to
+            % type variables which occur only in the body.
             map__apply_to_list(HeadVars, InferredVarTypes, ArgTypes),
             prog_type__vars_list(ArgTypes, ArgTypeVars),
             restrict_to_head_vars(InferredTypeConstraints0, ArgTypeVars,
                 InferredTypeConstraints, UnprovenBodyConstraints),
 
-            %
-            % If there are any as-yet-unproven constraints on type
-            % variables in the body, then save these in the pred_info.
-            % If it turns out that this pass was the last pass of type
-            % inference, the post_typecheck.m will report an error.
-            % But we can't report an error now, because a later pass
-            % of type inference could cause some type variables to become
-            % bound in to types that make the constraints satisfiable,
-            % causing the error to go away.
-            %
+            % If there are any as-yet-unproven constraints on type variables
+            % in the body, then save these in the pred_info. If it turns out
+            % that this pass was the last pass of type inference, the
+            % post_typecheck.m will report an error. But we can't report
+            % an error now, because a later pass of type inference could cause
+            % some type variables to become bound to types that make the
+            % constraints satisfiable, causing the error to go away.
             pred_info_set_unproven_body_constraints(UnprovenBodyConstraints,
                 !PredInfo),
 
             (
                 Inferring = yes,
-                %
-                % We need to infer which of the head variable
-                % types must be existentially quantified
-                %
+                % We need to infer which of the head variable types must be
+                % existentially quantified.
                 infer_existential_types(ArgTypeVars, ExistQVars,
                     !HeadTypeParams),
 
-                %
                 % Now save the information we inferred in the pred_info
-                %
                 pred_info_set_head_type_params(!.HeadTypeParams, !PredInfo),
                 pred_info_set_arg_types(TypeVarSet, ExistQVars, ArgTypes,
                     !PredInfo),
                 pred_info_get_class_context(!.PredInfo, OldTypeConstraints),
                 pred_info_set_class_context(InferredTypeConstraints, !PredInfo),
-                %
-                % Check if anything changed
-                %
+
+                % Check if anything changed.
                 (
                     % If the argument types and the type constraints are
                     % identical up to renaming, then nothing has changed.
@@ -552,21 +542,17 @@
                 pred_info_set_head_type_params(!.HeadTypeParams, !PredInfo),
                 pred_info_get_origin(!.PredInfo, Origin0),
 
-                %
-                % leave the original argtypes etc., but
-                % apply any substititions that map existentially
-                % quantified type variables to other type vars,
-                % and then rename them all to match the new typevarset,
-                % so that the type variables names match up
-                % (e.g. with the type variables in the
-                % constraint_proofs)
-                %
+                % Leave the original argtypes etc., but apply any substititions
+                % that map existentially quantified type variables to other
+                % type vars, and then rename them all to match the new
+                % typevarset, so that the type variables names match up
+                % (e.g. with the type variables in the constraint_proofs)
 
-                % apply any type substititions that map existentially
-                % quantified type variables to other type vars
+                % Apply any type substititions that map existentially
+                % quantified type variables to other type vars.
                 (
                     ExistQVars0 = [],
-                    % optimize common case
+                    % Optimize common case.
                     ExistQVars1 = [],
                     ArgTypes1 = ArgTypes0,
                     PredConstraints1 = PredConstraints,
@@ -583,7 +569,7 @@
                         Origin0, Origin1)
                 ),
 
-                % rename them all to match the new typevarset
+                % Rename them all to match the new typevarset.
                 apply_var_renaming_to_var_list(ExistQVars1,
                     TVarRenaming, ExistQVars),
                 apply_variable_renaming_to_type_list(TVarRenaming, ArgTypes1,
@@ -593,7 +579,7 @@
                 rename_instance_method_constraints(TVarRenaming,
                     Origin1, Origin),
 
-                % save the results in the pred_info
+                % Save the results in the pred_info.
                 pred_info_set_arg_types(TypeVarSet, ExistQVars,
                     RenamedOldArgTypes, !PredInfo),
                 pred_info_set_class_context(RenamedOldConstraints, !PredInfo),
@@ -623,23 +609,18 @@
     module_info::in, clause::out, prog_varset::in, prog_varset::out) is det.
 
 generate_stub_clause(PredName, !PredInfo, ModuleInfo, StubClause, !VarSet) :-
-    %
     % Mark the predicate as a stub
     % (i.e. record that it originally had no clauses)
-    %
     pred_info_get_markers(!.PredInfo, Markers0),
     add_marker(stub, Markers0, Markers),
     pred_info_set_markers(Markers, !PredInfo),
 
-    %
-    % Generate `PredName = "<PredName>"'
-    %
+    % Generate `PredName = "<PredName>"'.
     varset__new_named_var(!.VarSet, "PredName", PredNameVar, !:VarSet),
     make_string_const_construction(PredNameVar, PredName, UnifyGoal),
-    %
+
     % Generate `private_builtin.no_clauses(PredName)'
     % or `private_builtin.sorry(PredName)'
-    %
     ModuleName = pred_info_module(!.PredInfo),
     ( mercury_std_library_module_name(ModuleName) ->
         CalleeName = "sorry"
@@ -650,9 +631,8 @@
     generate_simple_call(mercury_private_builtin_module, CalleeName,
         predicate, only_mode, det, [PredNameVar], [], [], ModuleInfo,
         Context, CallGoal),
-    %
-    % Combine the unification and call into a conjunction
-    %
+
+    % Combine the unification and call into a conjunction.
     goal_info_init(Context, GoalInfo),
     Body = conj([UnifyGoal, CallGoal]) - GoalInfo,
     StubClause = clause([], Body, mercury, Context).
@@ -677,27 +657,20 @@
         Origin = Origin0
     ).
 
-    %
-    % infer which of the head variable
-    % types must be existentially quantified
+    % Infer which of the head variable types must be existentially quantified.
     %
 :- pred infer_existential_types(list(tvar)::in, existq_tvars::out,
     head_type_params::in, head_type_params::out) is det.
 
 infer_existential_types(ArgTypeVars, ExistQVars,
         HeadTypeParams0, HeadTypeParams) :-
-    %
-    % First, infer which of the head variable
-    % types must be existentially quantified:
-    % anything that was inserted into the HeadTypeParams0
-    % set must have been inserted due to an existential
-    % type in something we called, and thus must be
-    % existentially quantified.
-    % (Note that concrete types are "more general" than
-    % existentially quantified types, so we prefer to
-    % infer a concrete type if we can rather than an
-    % existential type.)
-    %
+    % First, infer which of the head variable types must be existentially
+    % quantified: anything that was inserted into the HeadTypeParams0 set must
+    % have been inserted due to an existential type in something we called,
+    % and thus must be existentially quantified. (Note that concrete types
+    % are "more general" than existentially quantified types, so we prefer to
+    % infer a concrete type if we can rather than an existential type.)
+
     set__list_to_set(ArgTypeVars, ArgTypeVarsSet),
     set__list_to_set(HeadTypeParams0, HeadTypeParamsSet),
     set__intersect(ArgTypeVarsSet, HeadTypeParamsSet, ExistQVarsSet),
@@ -705,24 +678,21 @@
     set__to_sorted_list(ExistQVarsSet, ExistQVars),
     set__to_sorted_list(UnivQVarsSet, UnivQVars),
 
-    %
-    % Then we need to insert the universally
-    % quantified head variable types into the
-    % HeadTypeParams set, which will now contain
-    % all the type variables that are produced
-    % either by stuff we call or by our caller.
-    % This is needed so that it has the right
-    % value when post_typecheck.m uses it to
-    % check for unbound type variables.
-    %
+    % Then we need to insert the universally quantified head variable types
+    % into the HeadTypeParams set, which will now contain all the type
+    % variables that are produced either by stuff we call or by our caller.
+    % This is needed so that it has the right value when post_typecheck.m
+    % uses it to check for unbound type variables.
+
     list__append(UnivQVars, HeadTypeParams0, HeadTypeParams).
 
     % restrict_to_head_vars(Constraints0, HeadVarTypes, Constraints,
     %       UnprovenConstraints):
-    %   Constraints is the subset of Constraints0 which contain
-    %   no type variables other than those in HeadVarTypes.
-    %   UnprovenConstraints is any unproven (universally quantified)
-    %   type constraints on variables not in HeadVarTypes.
+    %
+    % Constraints is the subset of Constraints0 which contain no type variables
+    % other than those in HeadVarTypes. UnprovenConstraints is any unproven
+    % (universally quantified) type constraints on variables not in
+    % HeadVarTypes.
     %
 :- pred restrict_to_head_vars(prog_constraints::in, list(tvar)::in,
     prog_constraints::out, list(prog_constraint)::out) is det.
@@ -775,7 +745,7 @@
         TypesListB),
     identical_up_to_renaming(TypesListA, TypesListB).
 
-    % check if two sets of type class constraints have the same structure
+    % Check if two sets of type class constraints have the same structure
     % (i.e. they specify the same list of type classes with the same
     % arities) and if so, concatenate the argument types for all the
     % type classes in each set of type class constraints and return them.
@@ -818,9 +788,9 @@
     type_list_subsumes(TypesList2, TypesList1, _).
 
     % A compiler-generated predicate only needs type checking if
-    %   (a) it is a user-defined equality pred
-    % or    (b) it is the unification or comparison predicate for an
-    %       existially quantified type.
+    % (a) it is a user-defined equality pred, or
+    % (b) it is the unification or comparison predicate for an existially
+    %     quantified type.
     %
     % In case (b), we need to typecheck it to fill in the head_type_params
     % field in the pred_info.
@@ -829,22 +799,17 @@
     is semidet.
 
 special_pred_needs_typecheck(PredInfo, ModuleInfo) :-
-        %
-        % check if the predicate is a compiler-generated special
-        % predicate, and if so, for which type
-        %
+    % Check if the predicate is a compiler-generated special
+    % predicate, and if so, for which type.
     pred_info_get_origin(PredInfo, Origin),
     Origin = special_pred(SpecialPredId - TypeCtor),
-        %
-        % check that the special pred isn't one of the builtin
-        % types which don't have a hlds_type_defn
-        %
+
+    % Check that the special pred isn't one of the builtin types which don't
+    % have a hlds_type_defn.
     \+ list__member(TypeCtor, builtin_type_ctors_with_no_hlds_type_defn),
-        %
-        % check whether that type is a type for which there is
-        % a user-defined equality predicate, or which is existentially
-        % typed.
-        %
+
+    % Check whether that type is a type for which there is a user-defined
+    % equality predicate, or which is existentially typed.
     module_info_get_type_table(ModuleInfo, TypeTable),
     map__lookup(TypeTable, TypeCtor, TypeDefn),
     hlds_data__get_type_defn_body(TypeDefn, Body),
@@ -855,9 +820,8 @@
     % For a field access function for which the user has supplied
     % a declaration but no clauses, add a clause
     % 'foo :='(X, Y) = 'foo :='(X, Y).
-    % As for the default clauses added for builtins, this is not a
-    % recursive call -- post_typecheck.m will expand the body into
-    % unifications.
+    % As for the default clauses added for builtins, this is not a recursive
+    % call -- post_typecheck.m will expand the body into unifications.
     %
 :- pred maybe_add_field_access_function_clause(module_info::in,
     pred_info::in, pred_info::out) is det.
@@ -945,11 +909,8 @@
         clauses_info_set_varset(VarSet, ClausesInfo2, ClausesInfo),
         pred_info_set_clauses_info(ClausesInfo, !PredInfo)
     ;
-        %
-        % If a headvar is assigned to a variable with the
-        % same name (or no name) in every clause, rename
-        % it to have that name.
-        %
+        % If a headvar is assigned to a variable with the same name
+        % (or no name) in every clause, rename it to have that name.
         list__foldl2(find_headvar_names_in_clause(VarSet0, HeadVars0),
             Clauses0, map__init, HeadVarNames, yes, _),
         map__foldl(maybe_update_headvar_name, HeadVarNames, VarSet0, VarSet),
@@ -978,14 +939,11 @@
 improve_single_clause_headvars([Goal | Conj0], HeadVars, SeenVars0,
         !VarSet, !Subst, !RevConj) :-
     ( goal_is_headvar_unification(HeadVars, Goal, HeadVar, OtherVar) ->
-        %
-        % If the headvar doesn't appear elsewhere the
-        % unification can be removed.
-        %
+        % If the headvar doesn't appear elsewhere the unification
+        % can be removed.
         (
-            % The headvars must be distinct variables, so check
-            % that this variable doesn't already appear in the
-            % argument list.
+            % The headvars must be distinct variables, so check that this
+            % variable doesn't already appear in the argument list.
             \+ list__member(OtherVar, HeadVars),
             \+ list__member(OtherVar, SeenVars0),
 
@@ -1001,10 +959,7 @@
             SeenVars = [OtherVar | SeenVars0],
             !:Subst = map__det_insert(!.Subst, HeadVar, OtherVar),
 
-            %
-            % If the variable wasn't named, use the
-            % `HeadVar__n' name.
-            %
+            % If the variable wasn't named, use the `HeadVar__n' name.
             (
                 \+ varset__search_name(!.VarSet, OtherVar, _),
                 varset__search_name(!.VarSet, HeadVar, HeadVarName)
@@ -1017,16 +972,11 @@
             !:RevConj = [Goal | !.RevConj],
             SeenVars = SeenVars0,
             ( varset__search_name(!.VarSet, OtherVar, OtherVarName) ->
-                %
                 % The unification can't be eliminated,
                 % so just rename the head variable.
-                %
                 varset__name_var(!.VarSet, HeadVar, OtherVarName, !:VarSet)
             ; varset__search_name(!.VarSet, HeadVar, HeadVarName) ->
-                %
-                % If the variable wasn't named, use the
-                % `HeadVar__n' name.
-                %
+                % If the variable wasn't named, use the `HeadVar__n' name.
                 varset__name_var(!.VarSet, OtherVar, HeadVarName, !:VarSet)
             ;
                 true
@@ -1139,34 +1089,30 @@
 
     % Type-check a single clause.
 
-    % As we go through a clause, we determine the possible
-    % type assignments for the clause.  A type assignment
-    % is an assignment of a type to each variable in the
-    % clause.
-    %
-    % Note that this may cause exponential time & space usage
-    % in the presence of overloading of predicates and/or
-    % functors.  This is a potentially serious problem, but
-    % there's no easy solution apparent.
-    %
-    % It would be more natural to use non-determinism to write
-    % this code, and perhaps even more efficient.
-    % But doing it nondeterministically would make good error
-    % messages very difficult.
-
-    % we should perhaps do manual garbage collection here
-
+    % As we go through a clause, we determine the possible type assignments
+    % for the clause. A type assignment is an assignment of a type to each
+    % variable in the clause.
+    %
+    % Note that this may cause exponential time & space usage in the presence
+    % of overloading of predicates and/or functors. This is a potentially
+    % serious problem, but there's no easy solution apparent.
+    %
+    % It would be more natural to use non-determinism to write this code,
+    % and perhaps even more efficient. But doing it nondeterministically
+    % would make good error messages very difficult.
+    %
+    % We should perhaps do manual garbage collection here.
+    %
 :- pred typecheck_clause(list(prog_var)::in, list(type)::in,
     clause::in, clause::out,
     typecheck_info::in, typecheck_info::out, io::di, io::uo) is det.
 
 typecheck_clause(HeadVars, ArgTypes, !Clause, !Info, !IO) :-
-        % XXX abstract clause/3
     Body0 = !.Clause ^ clause_body,
     Context = !.Clause ^clause_context,
     typecheck_info_set_context(Context, !Info),
-        % typecheck the clause - first the head unification, and
-        % then the body
+
+    % Typecheck the clause - first the head unification, and then the body.
     typecheck_var_has_type_list(HeadVars, ArgTypes, 1, !Info, !IO),
     typecheck_goal(Body0, Body, !Info, !IO),
     checkpoint("end of clause", !Info, !IO),
@@ -1180,7 +1126,6 @@
     % If there are multiple type assignments,
     % then we issue an error message here.
 
-    %
     % If stuff-to-check = whole_pred, report an error for any ambiguity,
     % and also check for unbound type variables.
     % But if stuff-to-check = clause_only, then only report
@@ -1200,26 +1145,25 @@
 typecheck_check_for_ambiguity(StuffToCheck, HeadVars, !Info, !IO) :-
     typecheck_info_get_type_assign_set(!.Info, TypeAssignSet),
     (
-        % there should always be a type assignment, because
-        % if there is an error somewhere, instead of setting
-        % the current type assignment set to the empty set,
-        % the type-checker should continue with the previous
-        % type assignment set (so that it can detect other
-        % errors in the same clause).
+        % There should always be a type assignment, because if there is
+        % an error somewhere, instead of setting the current type assignment
+        % set to the empty set, the type-checker should continue with the
+        % previous type assignment set (so that it can detect other errors
+        % in the same clause).
         TypeAssignSet = [],
         error("internal error in typechecker: no type-assignment")
     ;
         TypeAssignSet = [_SingleTypeAssign]
     ;
         TypeAssignSet = [TypeAssign1, TypeAssign2 | _],
-        %
-        % we only report an ambiguity error if
-        % (a) we haven't encountered any other errors
-        % and if StuffToCheck = clause_only(_),
-        % also (b) the ambiguity occurs only in the body,
-        % rather than in the head variables (and hence
-        % can't be resolved by looking at later clauses).
-        %
+
+        % We only report an ambiguity error if
+        % (a) we haven't encountered any other errors and if
+        %     StuffToCheck = clause_only(_), and also
+        % (b) the ambiguity occurs only in the body, rather than in the
+        %     head variables (and hence can't be resolved by looking at
+        %     later clauses).
+
         typecheck_info_get_found_error(!.Info, FoundError),
         (
             FoundError = no,
@@ -1227,11 +1171,10 @@
                 StuffToCheck = whole_pred
             ;
                 StuffToCheck = clause_only,
-                %
-                % only report an error if the headvar types
-                % are identical (which means that the ambiguity
-                % must have occurred in the body)
-                %
+
+                % Only report an error if the headvar types are identical
+                % (which means that the ambiguity must have occurred
+                % in the body)
                 type_assign_get_var_types(TypeAssign1, VarTypes1),
                 type_assign_get_var_types(TypeAssign2, VarTypes2),
                 type_assign_get_type_bindings(TypeAssign1, TypeBindings1),
@@ -1274,7 +1217,6 @@
         GoalInfo = GoalInfo0,
         typecheck_info_set_context(Context, !Info)
     ),
-        % type-check the goal
     typecheck_goal_2(Goal0, Goal, GoalInfo, !Info, !IO),
     check_warn_too_much_overloading(!Info, !IO).
 
@@ -1376,7 +1318,7 @@
 
 typecheck_goal_2(Goal @ foreign_proc(_, PredId, _, Args, _, _), Goal, GoalInfo,
         !Info, !IO) :-
-    % foreign_procs are automatically generated, so they will
+    % Foreign_procs are automatically generated, so they will
     % always be type-correct, but we need to do the type analysis in order
     % to correctly compute the HeadTypeParams that result from
     % existentially typed foreign_procs. (We could probably do that
@@ -1413,7 +1355,6 @@
 
 %-----------------------------------------------------------------------------%
 
-    % ensure_vars_have_a_type(Vars):
     %   Ensure that each variable in Vars has been assigned a type.
     %
 :- pred ensure_vars_have_a_type(list(prog_var)::in,
@@ -1458,6 +1399,7 @@
 
     % higher_order_pred_type(Purity, N, EvalMethod,
     %   TypeVarSet, PredType, ArgTypes):
+    %
     % Given an arity N, let TypeVarSet = {T1, T2, ..., TN},
     % PredType = `Purity EvalMethod pred(T1, T2, ..., TN)', and
     % ArgTypes = [T1, T2, ..., TN].
@@ -1476,6 +1418,7 @@
 
     % higher_order_func_type(Purity, N, EvalMethod, TypeVarSet,
     %   FuncType, ArgTypes, RetType):
+    %
     % Given an arity N, let TypeVarSet = {T0, T1, T2, ..., TN},
     % FuncType = `Purity EvalMethod func(T1, T2, ..., TN) = T0',
     % ArgTypes = [T1, T2, ..., TN], and
@@ -1503,7 +1446,7 @@
     % to the clauses_info if it contains Aditi updates with the
     % wrong number of arguments.
     get_state_args_det(Args, OtherArgs, State0, State),
-    % XXX using the old version of !Builtin in typecheck_aditi_state_args
+    % XXX Using the old version of !Builtin in typecheck_aditi_state_args
     % looks wrong; it should be documented or fixed - zs
     Builtin0 = !.Builtin,
     typecheck_aditi_builtin_2(CallId, OtherArgs, GoalPath, !Builtin, !Info,
@@ -1561,6 +1504,7 @@
     % Check that there is only one argument (other than the `aditi__state'
     % arguments) passed to an `aditi_delete', `aditi_bulk_insert',
     % `aditi_bulk_delete' or `aditi_modify', then typecheck that argument.
+    %
 :- pred typecheck_aditi_builtin_closure(simple_call_id::in,
     list(prog_var)::in, goal_path::in,
     adjust_arg_types::in(adjust_arg_types),
@@ -1618,11 +1562,10 @@
     typecheck_call_pred_adjust_arg_types(CallId, Args, GoalPath, assign,
         PredId, !Info, !IO).
 
-    % A closure of this type performs a transformation on
-    % the argument types of the called predicate. It is used to
-    % convert the argument types of the base relation for an Aditi
-    % update builtin to the type of the higher-order argument of
-    % the update predicate. For an ordinary predicate call,
+    % A closure of this type performs a transformation on the argument types
+    % of the called predicate. It is used to convert the argument types of the
+    % base relation for an Aditi update builtin to the type of the higher-order
+    % argument of the update predicate. For an ordinary predicate call,
     % the types are not transformed.
     %
 :- type adjust_arg_types == pred(list(type), list(type)).
@@ -1641,7 +1584,7 @@
         PredId, !Info, !IO) :-
     typecheck_info_get_type_assign_set(!.Info, OrigTypeAssignSet),
 
-        % look up the called predicate's arg types
+    % Look up the called predicate's arg types.
     typecheck_info_get_module_info(!.Info, ModuleInfo),
     module_info_get_predicate_table(ModuleInfo, PredicateTable),
     (
@@ -1650,9 +1593,9 @@
             calls_are_fully_qualified(!.Info ^ pred_markers),
             PorF, SymName, Arity, PredIdList)
     ->
-        % handle the case of a non-overloaded predicate specially
+        % Handle the case of a non-overloaded predicate specially
         % (so that we can optimize the case of a non-overloaded,
-        % non-polymorphic predicate)
+        % non-polymorphic predicate).
         ( PredIdList = [PredId0] ->
             PredId = PredId0,
             typecheck_call_pred_id_adjust_arg_types(PredId, Args,
@@ -1661,25 +1604,19 @@
             typecheck_call_overloaded_pred(PredIdList, Args,
                 GoalPath, AdjustArgTypes, !Info, !IO),
 
-            %
-            % In general, we can't figure out which
-            % predicate it is until after we have
-            % resolved any overloading, which may
-            % require type-checking the entire clause.
-            % Hence, for the moment, we just record an
-            % invalid pred_id in the HLDS.  This will be
-            % rectified by modes.m during mode-checking;
-            % at that point, enough information is
-            % available to determine which predicate it is.
-            %
+            % In general, we can't figure out which predicate it is until
+            % after we have resolved any overloading, which may require
+            % type-checking the entire clause. Hence, for the moment, we just
+            % record an invalid pred_id in the HLDS. This will be rectified
+            % by modes.m during mode-checking; at that point, enough
+            % information is available to determine which predicate it is.
             PredId = invalid_pred_id
         ),
 
-            % Arguably, we could do context reduction at
-            % a different point. See the paper:
-            % "Type classes: an exploration of the design
-            % space", S. Peyton-Jones, M. Jones 1997.
-            % for a discussion of some of the issues.
+        % Arguably, we could do context reduction at a different point.
+        % See the paper: "Type classes: an exploration of the design space",
+        % S. Peyton-Jones, M. Jones 1997, for a discussion of some of the
+        % issues.
         perform_context_reduction(OrigTypeAssignSet, !Info, !IO)
 
     ;
@@ -1715,12 +1652,11 @@
         PredArgTypes0),
     AdjustArgTypes(PredArgTypes0, PredArgTypes),
     pred_info_get_class_context(PredInfo, PredClassContext),
-    %
+
     % Rename apart the type variables in the called predicate's arg types
     % and then unify the types of the call arguments with the called
-    % predicates' arg types (optimize for the common case of a
-    % non-polymorphic, non-constrained predicate).
-    %
+    % predicates' arg types (optimize for the common case of a non-polymorphic,
+    % non-constrained predicate).
     (
         varset__is_empty(PredTypeVarSet),
         PredClassContext = constraints([], [])
@@ -1739,12 +1675,9 @@
 
 typecheck_call_overloaded_pred(PredIdList, Args, GoalPath, AdjustArgTypes,
         !Info, !IO) :-
-    %
-    % Let the new arg_type_assign_set be the cross-product
-    % of the current type_assign_set and the set of possible
-    % lists of argument types for the overloaded predicate,
-    % suitable renamed apart.
-    %
+    % Let the new arg_type_assign_set be the cross-product of the current
+    % type_assign_set and the set of possible lists of argument types
+    % for the overloaded predicate, suitable renamed apart.
     typecheck_info_get_module_info(!.Info, ModuleInfo),
     module_info_get_class_table(ModuleInfo, ClassTable),
     module_info_get_predicate_table(ModuleInfo, PredicateTable),
@@ -1752,10 +1685,9 @@
     typecheck_info_get_type_assign_set(!.Info, TypeAssignSet0),
     get_overloaded_pred_arg_types(PredIdList, Preds, ClassTable, GoalPath,
         AdjustArgTypes, TypeAssignSet0, [], ArgsTypeAssignSet),
-    %
+
     % Then unify the types of the call arguments with the
     % called predicates' arg types.
-    %
     typecheck_var_has_arg_type_list(Args, 1, ArgsTypeAssignSet, !Info, !IO).
 
 :- pred get_overloaded_pred_arg_types(list(pred_id)::in, pred_table::in,
@@ -1782,12 +1714,12 @@
 
 %-----------------------------------------------------------------------------%
 
+typecheck__resolve_pred_overloading(ModuleInfo, CallerMarkers,
+        ArgTypes, TVarSet, PredName0, PredName, PredId) :-
     % Note: calls to preds declared in `.opt' files should always be
     % module qualified, so they should not be considered
     % when resolving overloading.
 
-typecheck__resolve_pred_overloading(ModuleInfo, CallerMarkers,
-        ArgTypes, TVarSet, PredName0, PredName, PredId) :-
     module_info_get_predicate_table(ModuleInfo, PredTable),
     (
         predicate_table_search_pred_sym(PredTable,
@@ -1798,11 +1730,8 @@
         PredIds = []
     ),
 
-    %
-    % Check if there any of the candidate pred_ids
-    % have argument/return types which subsume the actual
-    % argument/return types of this function call
-    %
+    % Check if there any of the candidate pred_ids have argument/return types
+    % which subsume the actual argument/return types of this function call.
     (
         typecheck__find_matching_pred_id(PredIds, ModuleInfo,
             TVarSet, ArgTypes, PredId1, PredName1)
@@ -1810,19 +1739,17 @@
         PredId = PredId1,
         PredName = PredName1
     ;
-        % if there is no matching predicate for this call,
+        % If there is no matching predicate for this call,
         % then this predicate must have a type error which
         % should have been caught by typechecking.
-        error("type error in pred call: no matching pred")
+        unexpected(this_file, "type error in pred call: no matching pred")
     ).
 
 typecheck__find_matching_pred_id([PredId | PredIds], ModuleInfo,
         TVarSet, ArgTypes, ThePredId, PredName) :-
     (
-        %
         % Lookup the argument types of the candidate predicate
-        % (or the argument types + return type of the candidate
-        % function).
+        % (or the argument types + return type of the candidate function).
         %
         module_info_pred_info(ModuleInfo, PredId, PredInfo),
         pred_info_arg_types(PredInfo, PredTVarSet, PredExistQVars0,
@@ -1832,10 +1759,9 @@
         arg_type_list_subsumes(TVarSet, ArgTypes, PredTVarSet, PredKindMap,
             PredExistQVars0, PredArgTypes0)
     ->
-        %
         % We've found a matching predicate.
         % Was there was more than one matching predicate/function?
-        %
+
         PName = pred_info_name(PredInfo),
         Module = pred_info_module(PredInfo),
         PredName = qualified(Module, PName),
@@ -1845,7 +1771,7 @@
         ->
             % XXX this should report an error properly, not
             % via error/1
-            error("Type error in predicate call: " ++
+            unexpected(this_file, "Type error in predicate call: " ++
                 "unresolvable predicate overloading. " ++
                 "You need to use an explicit " ++
                 "module qualifier. " ++
@@ -1886,9 +1812,7 @@
 rename_apart([], _, _, _, _, !ArgTypeAssigns).
 rename_apart([TypeAssign0 | TypeAssigns0], PredTypeVarSet, PredExistQVars,
         PredArgTypes, PredConstraints, !ArgTypeAssigns) :-
-    %
-    % rename everything apart
-    %
+    % Rename everything apart.
     type_assign_rename_apart(TypeAssign0, PredTypeVarSet, PredArgTypes,
         TypeAssign1, ParentArgTypes, Renaming),
     apply_variable_renaming_to_tvar_list(Renaming, PredExistQVars,
@@ -1896,17 +1820,14 @@
     apply_variable_renaming_to_constraints(Renaming, PredConstraints,
         ParentConstraints),
 
-    %
-    % insert the existentially quantified type variables for the called
+    % Insert the existentially quantified type variables for the called
     % predicate into HeadTypeParams (which holds the set of type
     % variables which the caller is not allowed to bind).
-    %
     type_assign_get_head_type_params(TypeAssign1, HeadTypeParams0),
     list__append(ParentExistQVars, HeadTypeParams0, HeadTypeParams),
     type_assign_set_head_type_params(HeadTypeParams, TypeAssign1, TypeAssign),
-    %
-    % save the results and recurse
-    %
+
+    % Save the results and recurse.
     NewArgTypeAssign = args(TypeAssign, ParentArgTypes, ParentConstraints),
     !:ArgTypeAssigns = [NewArgTypeAssign | !.ArgTypeAssigns],
     rename_apart(TypeAssigns0, PredTypeVarSet, PredExistQVars,
@@ -1925,9 +1846,9 @@
 
 %-----------------------------------------------------------------------------%
 
-    % Given a list of variables and a list of types, ensure
-    % that each variable has the corresponding type.
-
+    % Given a list of variables and a list of types, ensure that each variable
+    % has the corresponding type.
+    %
 :- pred typecheck_var_has_arg_type_list(list(prog_var)::in, int::in,
     args_type_assign_set::in,
     typecheck_info::in, typecheck_info::out, io::di, io::uo) is det.
@@ -2047,7 +1968,7 @@
         TypeAssignSet),
     (
         TypeAssignSet = [],
-        TypeAssignSet0 \= []
+        TypeAssignSet0 = [_ | _]
     ->
         report_error_var(!.Info, Var, Type, TypeAssignSet0, !IO),
         typecheck_info_set_found_error(yes, !Info)
@@ -2069,12 +1990,8 @@
 
 type_assign_var_has_type(TypeAssign0, Var, Type, !TypeAssignSet) :-
     type_assign_get_var_types(TypeAssign0, VarTypes0),
-    ( %%% if some [VarType]
-        map__search(VarTypes0, Var, VarType)
-    ->
-        ( %%% if some [TypeAssign1]
-            type_assign_unify_type(TypeAssign0, VarType, Type, TypeAssign1)
-        ->
+    ( map__search(VarTypes0, Var, VarType) ->
+        ( type_assign_unify_type(TypeAssign0, VarType, Type, TypeAssign1) ->
             !:TypeAssignSet = [TypeAssign1 | !.TypeAssignSet]
         ;
             !:TypeAssignSet = !.TypeAssignSet
@@ -2099,9 +2016,9 @@
     type_assign_set::in, type_assign_set::out) is det.
 
 type_assign_var_has_type_list([], [_ | _], _, _, _, _) :-
-    error("type_assign_var_has_type_list: length mis-match").
+    unexpected(this_file, "type_assign_var_has_type_list: length mis-match").
 type_assign_var_has_type_list([_ | _], [], _, _, _, _) :-
-    error("type_assign_var_has_type_list: length mis-match").
+    unexpected(this_file, "type_assign_var_has_type_list: length mis-match").
 type_assign_var_has_type_list([], [], TypeAssign, _,
         TypeAssignSet, [TypeAssign | TypeAssignSet]).
 type_assign_var_has_type_list([Arg | Args], [Type | Types], TypeAssign0,
@@ -2116,7 +2033,7 @@
     %       for which the types of the Terms unify with
     %       their respective Types },
     % list__append(TAs, TypeAssignSet0, TypeAssignSet).
-
+    %
 :- pred type_assign_list_var_has_type_list(type_assign_set::in,
     list(prog_var)::in, list(type)::in, typecheck_info::in,
     type_assign_set::in, type_assign_set::out) is det.
@@ -2200,10 +2117,8 @@
     typecheck_info::in, typecheck_info::out, io::di, io::uo) is det.
 
 typecheck_unify_var_functor(Var, Functor, Args, GoalPath, !Info, !IO) :-
-    %
     % Get the list of possible constructors that match this functor/arity.
     % If there aren't any, report an undefined constructor error.
-    %
     list__length(Args, Arity),
     typecheck_info_get_ctor_list(!.Info, Functor, Arity, GoalPath,
         ConsDefnList, InvalidConsDefnList),
@@ -2214,10 +2129,9 @@
         typecheck_info_set_found_error(yes, !Info)
     ;
         ConsDefnList = [_ | _],
-        %
+
         % Produce the ConsTypeAssignSet, which is essentially the
         % cross-product of the TypeAssignSet0 and the ConsDefnList.
-        %
         typecheck_info_get_type_assign_set(!.Info, TypeAssignSet0),
         typecheck_unify_var_functor_get_ctors(TypeAssignSet0,
             !.Info, ConsDefnList, [], ConsTypeAssignSet),
@@ -2227,15 +2141,13 @@
         ->
             % This should never happen, since undefined ctors
             % should be caught by the check just above.
-            error("typecheck_unify_var_functor: undefined cons?")
+            unexpected(this_file,
+                "typecheck_unify_var_functor: undefined cons?")
         ;
             true
         ),
 
-        %
-        % Check that the type of the functor matches the type
-        % of the variable.
-        %
+        % Check that the type of the functor matches the type of the variable.
         typecheck_functor_type(ConsTypeAssignSet, Var, [],
             ArgsTypeAssignSet),
         (
@@ -2249,10 +2161,8 @@
             true
         ),
 
-        %
         % Check that the type of the arguments of the functor matches
         % their expected type for this functor.
-        %
         typecheck_functor_arg_types(ArgsTypeAssignSet, Args, !.Info,
             [], TypeAssignSet),
         (
@@ -2265,10 +2175,9 @@
         ;
             true
         ),
-        %
+
         % If we encountered an error, continue checking with the
         % original type assign set.
-        %
         (
             TypeAssignSet = [],
             typecheck_info_set_type_assign_set(TypeAssignSet0, !Info)
@@ -2393,8 +2302,7 @@
             (
                 type_assign_unify_type(TypeAssign0, TypeX, TypeY, TypeAssign3)
             ->
-                !:TypeAssignSet = [TypeAssign3 |
-                    !.TypeAssignSet]
+                !:TypeAssignSet = [TypeAssign3 | !.TypeAssignSet]
             ;
                 !:TypeAssignSet = !.TypeAssignSet
             )
@@ -2436,20 +2344,12 @@
 
 type_assign_check_functor_type(ConsType, ArgTypes, Y, TypeAssign1,
         !TypeAssignSet) :-
-
         % Unify the type of Var with the type of the constructor.
     type_assign_get_var_types(TypeAssign1, VarTypes0),
-    ( %%% if some [TypeY]
-        map__search(VarTypes0, Y, TypeY)
-    ->
-        ( %%% if some [TypeAssign2]
-            type_assign_unify_type(TypeAssign1, ConsType, TypeY,
-                TypeAssign2)
-        ->
-                % The constraints are empty here because
-                % none are added by unification with a
-                % functor.
-                %
+    ( map__search(VarTypes0, Y, TypeY) ->
+        ( type_assign_unify_type(TypeAssign1, ConsType, TypeY, TypeAssign2) ->
+            % The constraints are empty here because none are added by
+            % unification with a functor.
             empty_hlds_constraints(EmptyConstraints),
             ArgsTypeAssign = args(TypeAssign2, ArgTypes, EmptyConstraints),
             !:TypeAssignSet = [ArgsTypeAssign | !.TypeAssignSet]
@@ -2457,10 +2357,8 @@
             true
         )
     ;
-            % The constraints are empty here because
-            % none are added by unification with a
-            % functor.
-            %
+        % The constraints are empty here because none are added by
+        % unification with a functor.
         map__det_insert(VarTypes0, Y, ConsType, VarTypes),
         type_assign_set_var_types(VarTypes, TypeAssign1, TypeAssign3),
         empty_hlds_constraints(EmptyConstraints),
@@ -2481,11 +2379,9 @@
     ConsDefn = cons_type_info(ConsTypeVarSet, ConsExistQVars0,
         ConsType0, ArgTypes0, ClassConstraints0),
 
-        %
         % Rename apart the type vars in the type of the constructor
         % and the types of its arguments.
         % (Optimize the common case of a non-polymorphic type)
-        %
     ( varset__is_empty(ConsTypeVarSet) ->
         ConsType = ConsType0,
         ArgTypes = ArgTypes0,
@@ -2510,15 +2406,15 @@
     ;
         error("get_cons_stuff: type_assign_rename_apart failed")
     ),
-        %
-        % Add the constraints for this functor to the current
-        % constraint set.  Note that there can still be (ground)
-        % constraints even if the varset is empty.
-        %
-        % For functors which are data constructors, the fact that we
-        % don't take the dual corresponds to assuming that they will
-        % be used as deconstructors rather than as constructors.
-        %
+
+    % Add the constraints for this functor to the current constraint set.
+    % Note that there can still be (ground) constraints even if the varset
+    % is empty.
+    %
+    % For functors which are data constructors, the fact that we don't take
+    % the dual corresponds to assuming that they will be used as deconstructors
+    % rather than as constructors.
+
     type_assign_get_typeclass_constraints(TypeAssign2, OldConstraints),
     merge_hlds_constraints(ConstraintsToAdd, OldConstraints, ClassConstraints),
     type_assign_set_typeclass_constraints(ClassConstraints, TypeAssign2,
@@ -2550,9 +2446,9 @@
 
 %-----------------------------------------------------------------------------%
 
-    % typecheck_lambda_var_has_type(Var, ArgVars, ...)
-    % Check that `Var' has type `pred(T1, T2, ...)' where
-    % T1, T2, ... are the types of the `ArgVars'.
+    % typecheck_lambda_var_has_type(Var, ArgVars, ...):
+    %
+    % Check that `Var' has type `pred(T1, T2, ...)' where T1, T2, ... are the types of the `ArgVars'.
     %
 :- pred typecheck_lambda_var_has_type(purity::in, pred_or_func::in,
     lambda_eval_method::in, prog_var::in, list(prog_var)::in,
@@ -2565,7 +2461,7 @@
         EvalMethod, Var, ArgVars, [], TypeAssignSet),
     (
         TypeAssignSet = [],
-        TypeAssignSet0 \= []
+        TypeAssignSet0 = [_ | _]
     ->
         report_error_lambda_var(!.Info, PredOrFunc, EvalMethod,
             Var, ArgVars, TypeAssignSet0, !IO),
@@ -2631,9 +2527,8 @@
 
     % builtin_atomic_type(Const, TypeName):
     %
-    % If Const is a constant of a builtin atomic type,
-    % instantiates TypeName to the name of that type,
-    % otherwise fails.
+    % If Const is a constant of a builtin atomic type, instantiates TypeName
+    % to the name of that type, otherwise fails.
     %
 :- pred builtin_atomic_type(cons_id::in, string::out) is semidet.
 
@@ -2705,9 +2600,8 @@
     (
         IsPredOrFunc = predicate,
         PredArity >= FuncArity,
-        % we don't support first-class polymorphism,
-        % so you can't take the address of an existentially
-        % quantified predicate
+        % We don't support first-class polymorphism, so you can't take the
+        % address of an existentially quantified predicate.
         PredExistQVars = []
     ->
         (
@@ -2722,10 +2616,9 @@
                 PredType, ArgTypes, PredConstraints),
             !:ConsInfos = [ConsInfo | !.ConsInfos],
 
-            % If the predicate has an Aditi marker,
-            % we also add the `aditi pred(...)' type,
-            % which is used for inputs to the Aditi bulk update
-            % operations and also to Aditi aggregates.
+            % If the predicate has an Aditi marker, we also add the
+            % `aditi pred(...)' type, which is used for inputs to the
+            % Aditi bulk update operations and also to Aditi aggregates.
             pred_info_get_markers(PredInfo, Markers),
             ( check_marker(Markers, aditi) ->
                 construct_higher_order_pred_type(Purity,
@@ -2743,10 +2636,9 @@
         IsPredOrFunc = function,
         PredAsFuncArity = PredArity - 1,
         PredAsFuncArity >= FuncArity,
-        % We don't support first-class polymorphism,
-        % so you can't take the address of an existentially
-        % quantified function.  You can however call such
-        % a function, so long as you pass *all* the parameters.
+        % We don't support first-class polymorphism, so you can't take
+        % the address of an existentially quantified function. You can however
+        % call such a function, so long as you pass *all* the parameters.
         ( PredExistQVars = [] ; PredAsFuncArity = FuncArity )
     ->
         (
@@ -2755,9 +2647,11 @@
             pred_args_to_func_args(FuncTypeParams,
                 FuncArgTypeParams, FuncReturnTypeParam)
         ->
-            ( FuncArgTypeParams = [] ->
+            (
+                FuncArgTypeParams = [],
                 FuncType = FuncReturnTypeParam
             ;
+                FuncArgTypeParams = [_ | _],
                 construct_higher_order_func_type(Purity, normal,
                     FuncArgTypeParams, FuncReturnTypeParam, FuncType)
             ),
@@ -2774,6 +2668,7 @@
     ).
 
     % builtin_apply_type(Info, Functor, Arity, ConsTypeInfos):
+    %
     % Succeed if Functor is the builtin apply/N or ''/N (N>=2),
     % which is used to invoke higher-order functions.
     % If so, bind ConsTypeInfos to a singleton list containing
@@ -2801,6 +2696,7 @@
 
     % builtin_field_access_function_type(Info, GoalPath, Functor,
     %   Arity, ConsTypeInfos):
+    %
     % Succeed if Functor is the name of one the automatically
     % generated field access functions (fieldname, '<fieldname> :=').
     %
@@ -2809,11 +2705,8 @@
 
 builtin_field_access_function_type(Info, GoalPath, Functor, Arity,
         MaybeConsTypeInfos) :-
-    %
-    % Taking the address of automatically generated field access
-    % functions is not allowed, so currying does have to be
-    % considered here.
-    %
+    % Taking the address of automatically generated field access functions
+    % is not allowed, so currying does have to be considered here.
     Functor = cons(Name, Arity),
     typecheck_info_get_module_info(Info, ModuleInfo),
     is_field_access_function_name(ModuleInfo, Name, Arity, AccessType,
@@ -2858,12 +2751,11 @@
     FieldDefn = hlds_ctor_field_defn(_, _, TypeCtor, ConsId, _),
     TypeCtor = qualified(TypeModule, _) - _,
 
-    %
     % If the user has supplied a declaration, we use that instead
     % of the automatically generated version, unless we are typechecking
     % the clause introduced for the user-supplied declaration.
     % The user-declared version will be picked up by builtin_pred_type.
-    %
+
     typecheck_info_get_module_info(Info, ModuleInfo),
     module_info_get_predicate_table(ModuleInfo, PredTable),
     unqualify_name(FuncName, UnqualFuncName),
@@ -2898,12 +2790,10 @@
 
 :- pred convert_field_access_cons_type_info(class_table::in,
     field_access_type::in, ctor_field_name::in, hlds_ctor_field_defn::in,
-    cons_type_info::in, existq_tvars::in, maybe_cons_type_info::out)
-    is det.
+    cons_type_info::in, existq_tvars::in, maybe_cons_type_info::out) is det.
 
 convert_field_access_cons_type_info(ClassTable, AccessType, FieldName,
-        FieldDefn, FunctorConsTypeInfo, OrigExistTVars,
-        ConsTypeInfo) :-
+        FieldDefn, FunctorConsTypeInfo, OrigExistTVars, ConsTypeInfo) :-
     FunctorConsTypeInfo = cons_type_info(TVarSet0, ExistQVars0,
         FunctorType, ConsArgTypes, Constraints0),
     FieldDefn = hlds_ctor_field_defn(_, _, _, _, FieldNumber),
@@ -2920,21 +2810,17 @@
     ;
         AccessType = set,
 
-        %
-        % A `'field :='/2' function has no existentially
-        % quantified type variables - the values of all
-        % type variables in the field are supplied by
-        % the caller, all the others are supplied by
-        % the input term.
-        %
+        % A `'field :='/2' function has no existentially quantified type
+        % variables - the values of all type variables in the field are
+        % supplied by the caller, all the others are supplied by the
+        % input term.
+
         ExistQVars = [],
 
-        %
-        % When setting a polymorphic field, the type of the
-        % field in the result is not necessarily the
-        % same as in the input.
-        % If a type variable occurs only in the field being set,
-        % create a new type variable for it in the result type.
+        % When setting a polymorphic field, the type of the field in the result
+        % is not necessarily the same as in the input. If a type variable
+        % occurs only in the field being set, create a new type variable for it
+        % in the result type.
         %
         % This allows code such as
         % :- type pair(T, U)
@@ -2942,7 +2828,7 @@
         %
         %   Pair0 = 1 - 'a',
         %   Pair = Pair0 ^ snd := 2.
-        %
+
         prog_type__vars(FieldType, TVarsInField),
         (
             TVarsInField = [],
@@ -2950,34 +2836,29 @@
             RetType = FunctorType,
             ArgTypes = [FunctorType, FieldType],
 
-            %
-            % Remove any existential constraints (which are in
-            % the unproven field, since this is a construction).
-            % The typeclass-infos supplied by the input term
-            % are local to the set function, so they don't
-            % have to be considered here.
-            %
+            % Remove any existential constraints (which are in the unproven
+            % field, since this is a construction). The typeclass-infos
+            % supplied by the input term are local to the set function,
+            % so they don't have to be considered here.
+
             Constraints = Constraints0 ^ unproven := [],
             ConsTypeInfo = ok(cons_type_info(TVarSet, ExistQVars,
                 RetType, ArgTypes, Constraints))
         ;
             TVarsInField = [_ | _],
-            %
-            % XXX This demonstrates a problem - if a
-            % type variable occurs in the types of multiple
-            % fields, any predicates changing values of
-            % one of these fields cannot change their types.
-            % This especially a problem for existentially typed
-            % fields, because setting the field always changes
-            % the type.
-            %
-            % Haskell gets around this problem by allowing
-            % multiple fields to be set by the same expression.
-            % Haskell doesn't handle all cases -- it is not
-            % possible to get multiple existentially typed fields
-            % using record syntax and pass them to a function
-            % whose type requires that the fields are of the
-            % same type. It probably won't come up too often.
+
+            % XXX This demonstrates a problem - if a type variable occurs
+            % in the types of multiple fields, any predicates changing values
+            % of one of these fields cannot change their types. This especially
+            % a problem for existentially typed fields, because setting the
+            % field always changes the type.
+            %
+            % Haskell gets around this problem by allowing multiple fields
+            % to be set by the same expression. Haskell doesn't handle all
+            % cases -- it is not possible to get multiple existentially typed
+            % fields using record syntax and pass them to a function whose type
+            % requires that the fields are of the same type. It probably won't
+            % come up too often.
             %
             list__replace_nth_det(ConsArgTypes, FieldNumber, int_type,
                 ArgTypesWithoutField),
@@ -2990,12 +2871,9 @@
                 ),
                 ExistQVarsInFieldAndOthers),
             ( set__empty(ExistQVarsInFieldAndOthers) ->
-                %
-                % Rename apart type variables occurring only
-                % in the field to be replaced - the values of
-                % those type variables will be supplied by the
-                % replacement field value.
-                %
+                % Rename apart type variables occurring only in the field
+                % to be replaced - the values of those type variables will be
+                % supplied by the replacement field value.
                 list__delete_elems(TVarsInField,
                     TVarsInOtherArgs, TVarsOnlyInField0),
                 list__sort_and_remove_dups(TVarsOnlyInField0,
@@ -3009,13 +2887,10 @@
                 apply_variable_renaming_to_type(TVarRenaming, FunctorType,
                     OutputFunctorType),
 
-                %
-                % Rename the class constraints, projecting
-                % the constraints onto the set of type variables
-                % occuring in the types of the arguments of
-                % the call to `'field :='/2'.  Note that we
-                % have already flipped the constraints.
-                %
+                % Rename the class constraints, projecting the constraints
+                % onto the set of type variables occuring in the types of the
+                % arguments of the call to `'field :='/2'. Note that we have
+                % already flipped the constraints.
                 prog_type__vars_list([FunctorType, FieldType], CallTVars0),
                 set__list_to_set(CallTVars0, CallTVars),
                 project_and_rename_constraints(ClassTable, TVarSet, CallTVars,
@@ -3026,14 +2901,10 @@
                 ConsTypeInfo = ok(cons_type_info(TVarSet, ExistQVars,
                     RetType, ArgTypes, Constraints))
             ;
-                %
-                % This field cannot be set. Pass out some
-                % information so that we can give a better
-                % error message. Errors involving changing
-                % the types of universally quantified type
-                % variables will be caught by
-                % typecheck_functor_arg_types.
-                %
+                % This field cannot be set. Pass out some information so that
+                % we can give a better error message. Errors involving changing
+                % the types of universally quantified type variables will be
+                % caught by typecheck_functor_arg_types.
                 set__to_sorted_list(ExistQVarsInFieldAndOthers,
                     ExistQVarsInFieldAndOthers1),
                 ConsTypeInfo = error(invalid_field_update(FieldName,
@@ -3054,24 +2925,20 @@
         !Constraints) :-
     !.Constraints = constraints(Unproven0, Assumed, _),
 
-    %
     % XXX We currently don't allow universal constraints on types or
-    % data constructors (but we should). When we implement handling
-    % of those, they will need to be renamed here as well.  (The
-    % constraints have already been flipped at this point, which is why
-    % we test the assumed constraints here.)
-    %
+    % data constructors (but we should). When we implement handling ofthose,
+    % they will need to be renamed here as well. (The constraints have already
+    % been flipped at this point, which is why we test the assumed constraints
+    % here.)
     (
         Assumed = []
     ;
         Assumed = [_ | _],
-        error("project_and_rename_constraints: universal constraints")
+        unexpected(this_file,
+            "project_and_rename_constraints: universal constraints")
     ),
 
-    %
-    % Project the constraints down onto the list of tvars
-    % in the call.
-    %
+    % Project the constraints down onto the list of tvars in the call.
     list.filter(project_constraint(CallTVars), Unproven0, Unproven1),
     list.filter_map(rename_constraint(TVarRenaming), Unproven1, Unproven),
     update_redundant_constraints(ClassTable, TVarSet, Unproven,
@@ -3115,15 +2982,11 @@
 typecheck_info_get_ctor_list(Info, Functor, Arity, GoalPath, ConsInfoList,
         ConsErrors) :-
     (
-        %
-        % If we're typechecking the clause added for
-        % a field access function for which the user
-        % has supplied type or mode declarations, the
-        % goal should only contain an application of the
-        % field access function, not constructor applications
-        % or function calls. The clauses in `.opt' files will
-        % already have been expanded into unifications.
-        %
+        % If we're typechecking the clause added for a field access function
+        % for which the user has supplied type or mode declarations, the goal
+        % should only contain an application of the field access function,
+        % not constructor applications or function calls. The clauses in
+        % `.opt' files will already have been expanded into unifications.
         Info ^ is_field_access_function = yes,
         Info ^ import_status \= opt_imported
     ->
@@ -3197,10 +3060,8 @@
         MaybeConsInfoList1 = MaybeConsInfoList0
     ),
 
-    %
-    % Check if Functor is a field access function for which the
-    % user has not supplied a declaration.
-    %
+    % Check if Functor is a field access function for which the user
+    % has not supplied a declaration.
     (
         builtin_field_access_function_type(Info, GoalPath, Functor,
             Arity, FieldAccessConsInfoList)
@@ -3213,9 +3074,9 @@
 
     split_cons_errors(MaybeConsInfoList, ConsInfoList1, ConsErrors),
 
-    % Check if Functor is a constant of one of the builtin atomic
-    % types (string, float, int, character).  If so, insert
-    % the resulting cons_type_info at the start of the list.
+    % Check if Functor is a constant of one of the builtin atomic types
+    % (string, float, int, character). If so, insert the resulting
+    % cons_type_info at the start of the list.
     (
         Arity = 0,
         builtin_atomic_type(Functor, BuiltInTypeName)
@@ -3229,17 +3090,14 @@
         ConsInfoList2 = ConsInfoList1
     ),
 
-    %
     % Check if Functor is a tuple constructor.
-    %
     (
         Functor = cons(unqualified("{}"), TupleArity)
     ->
-        %
         % Make some fresh type variables for the argument types.  These have
         % kind `star' since there are values (namely the arguments of the
-        % tuplpe constructor) which have these types.
-        %
+        % tuple constructor) which have these types.
+
         varset__init(TupleConsTypeVarSet0),
         varset__new_vars(TupleConsTypeVarSet0, TupleArity, TupleArgTVars,
             TupleConsTypeVarSet),
@@ -3268,9 +3126,7 @@
         ConsInfoList4 = ConsInfoList3
     ),
 
-    %
-    % Check for higher-order function calls
-    %
+    % Check for higher-order function calls.
     ( builtin_apply_type(Info, Functor, Arity, ApplyConsInfoList) ->
         ConsInfoList = list__append(ConsInfoList4, ApplyConsInfoList)
     ;
@@ -3281,10 +3137,8 @@
     list(cons_type_info)::out, list(cons_error)::out) is det.
 
 split_cons_errors(MaybeConsInfoList, ConsInfoList, ConsErrors) :-
-    %
-    % Filter out the errors (they aren't actually reported as
-    % errors unless there was no other matching constructor).
-    %
+    % Filter out the errors (they aren't actually reported as errors
+    % unless there was no other matching constructor).
     list__filter_map(
         (pred(ok(ConsInfo)::in, ConsInfo::out) is semidet),
         MaybeConsInfoList, ConsInfoList, ConsErrors0),
@@ -3328,7 +3182,6 @@
     hlds_data__get_type_defn_kind_map(TypeDefn, ConsTypeKinds),
     hlds_data__get_type_defn_body(TypeDefn, Body),
 
-    %
     % If this type has `:- pragma foreign_type' declarations, we
     % can only use its constructors in predicates which have foreign
     % clauses and in the unification and comparison predicates for
@@ -3387,12 +3240,9 @@
                 ExistProgConstraints),
             ExistQVars = ExistQVars0
         ;
-                %
-                % Make the existential constraints into
-                % universal ones, and discard the existentially
-                % quantified variables (since they are now
+            % Make the existential constraints into universal ones, and discard
+            % the existentially quantified variables (since they are now
                 % universally quantified).
-                %
             ProgConstraints = constraints(ExistProgConstraints,
                 UnivProgConstraints),
             ExistQVars = []
@@ -3404,5 +3254,9 @@
     ).
 
 %-----------------------------------------------------------------------------%
-:- end_module typecheck.
+
+:- func this_file = string.
+
+this_file = "typecheck.m".
+
 %-----------------------------------------------------------------------------%
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/aditi
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/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/xml
cvs diff: Diffing extras/xml/samples
cvs diff: Diffing extras/xml_stylesheets
cvs diff: Diffing java
cvs diff: Diffing java/runtime
cvs diff: Diffing library
Index: library/rtti_implementation.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/rtti_implementation.m,v
retrieving revision 1.59
diff -u -b -r1.59 rtti_implementation.m
--- library/rtti_implementation.m	5 Oct 2005 06:34:12 -0000	1.59
+++ library/rtti_implementation.m	10 Oct 2005 11:45:16 -0000
@@ -1,13 +1,15 @@
 %-----------------------------------------------------------------------------%
+% vim: ft=mercury ts=4 sw=4 et wm=0 tw=0
+%-----------------------------------------------------------------------------%
 % Copyright (C) 2001-2005 The University of Melbourne.
 % 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: rtti_implementation.m.
 % Main author: trd, petdr.
 % Stability: low.
-
+%
 % This file is intended to provide portable RTTI functionality by implementing
 % most of Mercury's RTTI functionality in Mercury.
 %
@@ -31,8 +33,7 @@
 % of the low-level procedures have yet to be implemented for the Java back-end.
 %
 % XXX Also, the existing Java code needs to be reviewed.
-
-%-----------------------------------------------------------------------------%
+%
 %-----------------------------------------------------------------------------%
 
 :- module rtti_implementation.
@@ -74,6 +75,7 @@
 
 	% This is useful in a few places, so we'd like to share the code, but
 	% it's better to put it into an implementation module such as this one.
+    %
 :- func unsafe_cast(T1::in) = (T2::out) is det.
 
 %-----------------------------------------------------------------------------%
@@ -100,7 +102,7 @@
 :- import_module require.
 :- import_module string.
 
-	% std_util has a lot of types and functions with the same names,
+    % Std_util has a lot of types and functions with the same names,
 	% so we prefer to keep the namespace separate.
 :- use_module std_util.
 
@@ -498,11 +500,9 @@
 get_functor_du(TypeCtorRep, TypeInfo, TypeCtorInfo, FunctorNumber,
 		FunctorName, Arity, TypeDescList, Names) :-
 	TypeFunctors = TypeCtorInfo ^ type_ctor_functors,
-	DuFunctorDesc = TypeFunctors ^
-		du_functor_desc(TypeCtorRep, FunctorNumber),
+    DuFunctorDesc = TypeFunctors ^ du_functor_desc(TypeCtorRep, FunctorNumber),
 
-		% XXX We don't handle functors with existentially quantified
-		% arguments.
+    % XXX We don't handle functors with existentially quantified arguments.
 	not (_ = DuFunctorDesc ^ du_functor_exist_info),
 
 	FunctorName = DuFunctorDesc ^ du_functor_name,
@@ -511,30 +511,27 @@
 	ArgTypes = DuFunctorDesc ^ du_functor_arg_types,
 	F = (func(I) = ArgTypeDesc :-
 		PseudoTypeInfo = get_pti_from_arg_types(ArgTypes, I),
-			% XXX we can pass 0 instead of an instance of the
-			% functor because that is only needed for functors
-			% with existentially quantified arguments.
-			%
-		get_arg_type_info(TypeInfo, PseudoTypeInfo, 0,
-				DuFunctorDesc, ArgTypeInfo),
+            % XXX we can pass 0 instead of an instance of the functor because
+            % that is only needed for functors with existentially quantified
+            % arguments.
+        get_arg_type_info(TypeInfo, PseudoTypeInfo, 0, DuFunctorDesc,
+            ArgTypeInfo),
 		ArgTypeDesc = unsafe_cast(ArgTypeInfo)
 	),
 	TypeDescList = iterate(0, Arity - 1, F),
 
 	( ArgNames = DuFunctorDesc ^ du_functor_arg_names ->
-		Names = iterate(0, Arity - 1,
-			(func(I) = ArgNames ^ unsafe_index(I)))
+        Names = iterate(0, Arity - 1, (func(I) = ArgNames ^ unsafe_index(I)))
 	;
 		Names = list__duplicate(Arity, null_string)
 	).
 
-:- pred get_functor_enum(type_ctor_rep::in(enum),
-		type_ctor_info::in, int::in, string::out, int::out,
-		list(type_desc__type_desc)::out,
-		list(string)::out) is det.
+:- pred get_functor_enum(type_ctor_rep::in(enum), type_ctor_info::in, int::in,
+    string::out, int::out, list(type_desc__type_desc)::out, list(string)::out)
+    is det.
 
-get_functor_enum(TypeCtorRep, TypeCtorInfo, FunctorNumber,
-		FunctorName, Arity, TypeDescList, Names) :-
+get_functor_enum(TypeCtorRep, TypeCtorInfo, FunctorNumber, FunctorName, Arity,
+        TypeDescList, Names) :-
 	TypeFunctors = TypeCtorInfo ^ type_ctor_functors,
 	EnumFunctorDesc = TypeFunctors ^
 		enum_functor_desc(TypeCtorRep, FunctorNumber),
@@ -544,12 +541,12 @@
 	TypeDescList = [],
 	Names = [].
 
-:- pred get_functor_notag(type_ctor_rep::in(notag),
-	type_ctor_info::in, int::in, string::out, int::out,
-	list(type_desc__type_desc)::out, list(string)::out) is det.
+:- pred get_functor_notag(type_ctor_rep::in(notag), type_ctor_info::in,
+    int::in, string::out, int::out, list(type_desc__type_desc)::out,
+    list(string)::out) is det.
 
-get_functor_notag(TypeCtorRep, TypeCtorInfo, FunctorNumber,
-		FunctorName, Arity, TypeDescList, Names) :-
+get_functor_notag(TypeCtorRep, TypeCtorInfo, FunctorNumber, FunctorName, Arity,
+        TypeDescList, Names) :-
 	TypeFunctors = TypeCtorInfo ^ type_ctor_functors,
 	NoTagFunctorDesc = TypeFunctors ^
 		notag_functor_desc(TypeCtorRep, FunctorNumber),
@@ -626,8 +623,7 @@
 	;
 		( TypeCtorRep = (pred) ; TypeCtorRep = (func) )
 	->
-		error("rtti_implementation.m: unimplemented: "
-			++ "higher order comparisons")
+        error("rtti_implementation.m: unimplemented: higher order comparisons")
 	;
 		Arity = TypeCtorInfo ^ type_ctor_arity,
 		ComparePred = TypeCtorInfo ^ type_ctor_compare_pred,
@@ -678,8 +674,7 @@
 	;
 		( TypeCtorRep = (pred) ; TypeCtorRep = (func) )
 	->
-		error("rtti_implementation.m: unimplemented: " ++
-			"higher order unifications")
+        error("rtti_implementation.m: unimplemented: higher order unification")
 	;
 		Arity = TypeCtorInfo ^ type_ctor_arity,
 		UnifyPred = TypeCtorInfo ^ type_ctor_unify_pred,
@@ -719,8 +714,6 @@
 		)
 	).
 
-	% check for tuple and higher order cases
-
 :- pred unify_tuple(type_info::in, T::in, T::in) is semidet.
 
 unify_tuple(TypeInfo, TermA, TermB) :-
@@ -765,8 +758,8 @@
 
 		generic_compare(SubResult, SubTermA, unsafe_cast(SubTermB)),
 		( SubResult = (=) ->
-			compare_tuple_pos(Loc + 1, TupleArity, TypeInfo,
-				Result, TermA, TermB)
+            compare_tuple_pos(Loc + 1, TupleArity, TypeInfo, Result,
+                TermA, TermB)
 		;
 			Result = SubResult
 		)
@@ -869,16 +862,14 @@
 	[will_not_call_mercury, promise_pure, thread_safe],
 "
 	SUCCESS_INDICATOR =
-		mercury.runtime.GenericCall.semidet_call_6(Pred, A, B, C,
-			X, Y);
+        mercury.runtime.GenericCall.semidet_call_6(Pred, A, B, C, X, Y);
 ").
 :- pragma foreign_proc("C#",
 	semidet_call_7(Pred::in, A::in, B::in, C::in, D::in, X::in, Y::in),
 	[will_not_call_mercury, promise_pure, thread_safe],
 "
 	SUCCESS_INDICATOR =
-		mercury.runtime.GenericCall.semidet_call_7(Pred, A, B, C, D,
-			X, Y);
+        mercury.runtime.GenericCall.semidet_call_7(Pred, A, B, C, D, X, Y);
 ").
 :- pragma foreign_proc("C#",
 	semidet_call_8(Pred::in, A::in, B::in, C::in, D::in, E::in,
@@ -886,8 +877,7 @@
 	[will_not_call_mercury, promise_pure, thread_safe],
 "
 	SUCCESS_INDICATOR =
-		mercury.runtime.GenericCall.semidet_call_8(Pred, A, B, C, D,
-			E, X, Y);
+        mercury.runtime.GenericCall.semidet_call_8(Pred, A, B, C, D, E, X, Y);
 ").
 
 :- pragma foreign_proc("C#",
@@ -919,16 +909,15 @@
 	result_call_8(Pred::in, Res::out, A::in, B::in, C::in, D::in, X::in, Y::in),
 	[will_not_call_mercury, promise_pure, thread_safe],
 "
-	mercury.runtime.GenericCall.result_call_8(Pred, A, B, C, D,
-		ref Res, X, Y);
+    mercury.runtime.GenericCall.result_call_8(Pred, A, B, C, D, ref Res, X, Y);
 ").
 :- pragma foreign_proc("C#",
 	result_call_9(Pred::in, Res::out, A::in, B::in, C::in, D::in, E::in,
 		X::in, Y::in),
 	[will_not_call_mercury, promise_pure, thread_safe],
 "
-	mercury.runtime.GenericCall.result_call_9(Pred,
-		A, B, C, D, E, ref Res, X, Y);
+    mercury.runtime.GenericCall.result_call_9(Pred, A, B, C, D, E, ref Res,
+        X, Y);
 ").
 
 %-----------------------------------------------------------------------------%
@@ -954,8 +943,8 @@
 	TypeCtorInfo1 = get_type_ctor_info(TypeInfo1),
 	TypeCtorInfo2 = get_type_ctor_info(TypeInfo2),
 
-		% The comparison here is arbitrary.
-		% In the past we just compared pointers of the type_c
+    % The comparison here is arbitrary. In the past we just compared pointers
+    % to the type_ctor_infos.
 	compare(NameRes, TypeCtorInfo1 ^ type_ctor_name,
 		TypeCtorInfo2 ^ type_ctor_name),
 	( NameRes = (=) ->
@@ -970,8 +959,8 @@
 			Arity2 = get_var_arity_typeinfo_arity(TypeInfo2),
 			compare(ArityRes, Arity1, Arity2),
 			( ArityRes = (=) ->
-				compare_var_arity_typeinfos(1, Arity1,
-					Res, TypeInfo1, TypeInfo2)
+                compare_var_arity_typeinfos(1, Arity1, Res,
+                    TypeInfo1, TypeInfo2)
 			;
 				Res = ArityRes
 			)
@@ -992,8 +981,7 @@
 		SubTypeInfoA = TypeInfoA ^ var_arity_type_info_index(Loc),
 		SubTypeInfoB = TypeInfoB ^ var_arity_type_info_index(Loc),
 
-		compare_collapsed_type_infos(SubResult,
-			SubTypeInfoA, SubTypeInfoB),
+        compare_collapsed_type_infos(SubResult, SubTypeInfoA, SubTypeInfoB),
 		( SubResult = (=) ->
 			compare_var_arity_typeinfos(Loc + 1, Arity, Result,
 				TypeInfoA, TypeInfoB)
@@ -1003,6 +991,7 @@
 	).
 
 :- pred type_ctor_is_variable_arity(type_ctor_info::in) is semidet.
+
 type_ctor_is_variable_arity(TypeCtorInfo) :-
 	( TypeCtorInfo ^ type_ctor_rep = (pred)
 	; TypeCtorInfo ^ type_ctor_rep = (func)
@@ -1017,7 +1006,7 @@
 	% intermodule optimization, which will collapse them for us).
 	%
 	% XXX For other backends this code may have to be completed.
-
+    %
 :- func collapse_equivalences(type_info) = type_info.
 
 collapse_equivalences(TypeInfo) = NewTypeInfo :-
@@ -1071,15 +1060,15 @@
 		Results = []
 	).
 
-:- pred iterate_foldl(int, int, pred(int, T, T), T, T).
-:- mode iterate_foldl(in, in, pred(in, in, out) is det, in, out) is det.
+:- pred iterate_foldl(int::in, int::in,
+    pred(int, T, T)::in(pred(in, in, out) is det), T::in, T::out) is det.
 
-iterate_foldl(Start, Max, Pred) -->
-	( { Start =< Max } ->
-		Pred(Start),
-		iterate_foldl(Start + 1, Max, Pred)
+iterate_foldl(Start, Max, Pred, !Acc) :-
+    ( Start =< Max ->
+        Pred(Start, !Acc),
+        iterate_foldl(Start + 1, Max, Pred, !Acc)
 	;
-		[]
+        true
 	).
 
 %-----------------------------------------------------------------------------%
@@ -1089,8 +1078,8 @@
 	TypeInfo = get_type_info(Term),
 	TypeCtorInfo = get_type_ctor_info(TypeInfo),
 	TypeCtorRep = type_ctor_rep(TypeCtorInfo),
-	deconstruct(Term, TypeInfo, TypeCtorInfo, TypeCtorRep,
-			NonCanon, Functor, Arity, Arguments).
+    deconstruct(Term, TypeInfo, TypeCtorInfo, TypeCtorRep, NonCanon,
+        Functor, Arity, Arguments).
 
 :- pred deconstruct(T, type_info, type_ctor_info, type_ctor_rep,
 	noncanon_handling, string, int, list(std_util__univ)).
@@ -1106,8 +1095,8 @@
 	% immediately useful (e.g. called by io__write) have been implemented
 	% so far.
 
-deconstruct(Term, TypeInfo, TypeCtorInfo, TypeCtorRep,
-		NonCanon, Functor, Arity, Arguments) :-
+deconstruct(Term, TypeInfo, TypeCtorInfo, TypeCtorRep, NonCanon,
+        Functor, Arity, Arguments) :-
 	(
 		TypeCtorRep = enum_usereq,
 		handle_usereq_type(Term, TypeInfo, TypeCtorInfo, TypeCtorRep,
@@ -1123,8 +1112,7 @@
 	;
 		TypeCtorRep = dummy,
 		TypeFunctors = type_ctor_functors(TypeCtorInfo),
-		EnumFunctorDesc = enum_functor_desc(TypeCtorRep,
-			0, TypeFunctors),
+        EnumFunctorDesc = enum_functor_desc(TypeCtorRep, 0, TypeFunctors),
 		Functor = enum_functor_name(EnumFunctorDesc),
 		Arity = 0,
 		Arguments = []
@@ -1146,8 +1134,7 @@
 			Arity = FunctorDesc ^ du_functor_arity,
 			Arguments = iterate(0, Arity - 1,
 				(func(X) = std_util__univ(
-					get_arg(Term, X, SecTagLocn,
-						FunctorDesc, TypeInfo))
+                    get_arg(Term, X, SecTagLocn, FunctorDesc, TypeInfo))
 				))
 		;
 			SecTagLocn = local,
@@ -1157,14 +1144,12 @@
 		;
 			SecTagLocn = remote,
 			SecTag = get_remote_secondary_tag(Term),
-			FunctorDesc = PTagEntry ^
-				du_sectag_alternatives(SecTag),
+            FunctorDesc = PTagEntry ^ du_sectag_alternatives(SecTag),
 			Functor = FunctorDesc ^ du_functor_name,
 			Arity = FunctorDesc ^ du_functor_arity,
 			Arguments = iterate(0, Arity - 1,
 				(func(X) = std_util__univ(
-					get_arg(Term, X, SecTagLocn,
-						FunctorDesc, TypeInfo))
+                    get_arg(Term, X, SecTagLocn, FunctorDesc, TypeInfo))
 				))
 		;
 			SecTagLocn = variable,
@@ -1174,8 +1159,8 @@
 		)
 	;
 		TypeCtorRep = notag_usereq,
-		handle_usereq_type(Term, TypeInfo, TypeCtorInfo, TypeCtorRep,
-			NonCanon, Functor, Arity, Arguments)
+        handle_usereq_type(Term, TypeInfo, TypeCtorInfo, TypeCtorRep, NonCanon,
+            Functor, Arity, Arguments)
 	;
 		TypeCtorRep = notag,
 		Functor = "some_notag",
@@ -1183,8 +1168,8 @@
 		Arguments = []
 	;
 		TypeCtorRep = notag_ground_usereq,
-		handle_usereq_type(Term, TypeInfo, TypeCtorInfo, TypeCtorRep,
-			NonCanon, Functor, Arity, Arguments)
+        handle_usereq_type(Term, TypeInfo, TypeCtorInfo, TypeCtorRep, NonCanon,
+            Functor, Arity, Arguments)
 	;
 		TypeCtorRep = notag_ground,
 		Functor = "some_notag_ground",
@@ -1303,8 +1288,7 @@
 		Functor = "<<array>>",
 		Arity = array__size(Array),
 		Arguments = array__foldr(
-			(func(Elem, List) =
-				[std_util__univ(Elem) | List]),
+            (func(Elem, List) = [std_util__univ(Elem) | List]),
 			Array, [])
 	;
 		TypeCtorRep = succip,
@@ -1354,8 +1338,8 @@
 		Arguments = []
 	;
 		TypeCtorRep = reserved_addr_usereq,
-		handle_usereq_type(Term, TypeInfo, TypeCtorInfo, TypeCtorRep,
-			NonCanon, Functor, Arity, Arguments)
+        handle_usereq_type(Term, TypeInfo, TypeCtorInfo, TypeCtorRep, NonCanon,
+            Functor, Arity, Arguments)
 	;
 		% XXX noncanonical term
 		TypeCtorRep = type_ctor_info,
@@ -1414,6 +1398,7 @@
 	std_util__det_univ_to_type(Univ, Actual).
 
 :- pred same_array_elem_type(array(T)::unused, T::unused) is det.
+
 same_array_elem_type(_, _).
 
 :- inst usereq == bound(enum_usereq; du_usereq; notag_usereq;
@@ -1459,11 +1444,12 @@
 			TypeCtorRep = reserved_addr_usereq,
 			BaseTypeCtorRep = reserved_addr
 		),
-		deconstruct(Term, TypeInfo, TypeCtorInfo, BaseTypeCtorRep,
-			NonCanon, Functor, Arity, Arguments)
+        deconstruct(Term, TypeInfo, TypeCtorInfo, BaseTypeCtorRep, NonCanon,
+            Functor, Arity, Arguments)
 	).
 
 	% MR_expand_type_name from mercury_deconstruct.c
+    %
 :- func expand_type_name(type_ctor_info, bool) = string.
 
 expand_type_name(TypeCtorInfo, Wrap) = Name :-
@@ -1472,13 +1458,13 @@
 	;
 		FmtStr = "%s.%s/%d"
 	),
-	Name = string__format(FmtStr, [s(TypeCtorInfo ^ type_ctor_module_name),
+    Name = string__format(FmtStr,
+        [s(TypeCtorInfo ^ type_ctor_module_name),
 		s(TypeCtorInfo ^ type_ctor_name),
 		i(TypeCtorInfo ^ type_ctor_arity)]).
 
-	% Retrieve an argument number from a term, given the functor
-	% descriptor.
-
+    % Retrieve an argument number from a term, given the functor descriptor.
+    %
 :- some [T] func get_arg(U, int, sectag_locn, du_functor_desc, type_info) = T.
 
 get_arg(Term, Index, SecTagLocn, FunctorDesc, TypeInfo) = (Arg) :-
@@ -1529,13 +1515,13 @@
 :- pred get_arg_type_info(type_info::in, P::in, T::in,
 	du_functor_desc::in, type_info::out) is det.
 
-get_arg_type_info(TypeInfoParams, PseudoTypeInfo, Term,
-		FunctorDesc, ArgTypeInfo) :-
+get_arg_type_info(TypeInfoParams, PseudoTypeInfo, Term, FunctorDesc,
+        ArgTypeInfo) :-
 	(
 		typeinfo_is_variable(PseudoTypeInfo, VarNum)
 	->
-		get_type_info_for_var(TypeInfoParams,
-			VarNum, Term, FunctorDesc, ExpandedTypeInfo),
+        get_type_info_for_var(TypeInfoParams, VarNum, Term, FunctorDesc,
+            ExpandedTypeInfo),
 		( typeinfo_is_variable(ExpandedTypeInfo, _) ->
 			error("get_arg_type_info: unbound type variable")
 		;
@@ -1547,8 +1533,7 @@
 		(
 			type_ctor_is_variable_arity(TypeCtorInfo)
 		->
-			Arity = pseudotypeinfo_get_higher_order_arity(
-				CastTypeInfo),
+            Arity = pseudotypeinfo_get_higher_order_arity(CastTypeInfo),
 			StartRegionSize = 2
 		;
 			Arity = TypeCtorInfo ^ type_ctor_arity,
@@ -1559,48 +1544,47 @@
 
 		iterate_foldl(StartRegionSize, UpperBound,
 			(pred(I::in, TI0::in, TI::out) is det :-
-
 				PTI = get_pti_from_type_info(CastTypeInfo, I),
-				get_arg_type_info(TypeInfoParams, PTI,
-					Term, FunctorDesc, ETypeInfo),
+                get_arg_type_info(TypeInfoParams, PTI, Term, FunctorDesc,
+                    ETypeInfo),
 				(
-					same_pointer_value_untyped(
-						ETypeInfo, PTI)
+                    same_pointer_value_untyped(ETypeInfo, PTI)
 				->
 					TI = TI0
 				;
 					TI0 = std_util__yes(TypeInfo0)
 				->
-					unsafe_promise_unique(TypeInfo0,
-						TypeInfo1),
-					update_type_info_index(I,
-						ETypeInfo, TypeInfo1, TypeInfo),
+                    unsafe_promise_unique(TypeInfo0, TypeInfo1),
+                    update_type_info_index(I, ETypeInfo, TypeInfo1, TypeInfo),
 					TI = std_util__yes(TypeInfo)
 				;
-					NewTypeInfo0 = new_type_info(
-						CastTypeInfo, UpperBound),
-					update_type_info_index(I,
-						ETypeInfo, NewTypeInfo0,
+                    NewTypeInfo0 = new_type_info(CastTypeInfo, UpperBound),
+                    update_type_info_index(I, ETypeInfo, NewTypeInfo0,
 						NewTypeInfo),
 					TI = std_util__yes(NewTypeInfo)
 				)
 			), ArgTypeInfo0, MaybeArgTypeInfo),
-		( MaybeArgTypeInfo = std_util__yes(ArgTypeInfo1) ->
+        (
+            MaybeArgTypeInfo = std_util__yes(ArgTypeInfo1),
 			ArgTypeInfo = ArgTypeInfo1
 		;
+            MaybeArgTypeInfo = std_util__no,
 			ArgTypeInfo = CastTypeInfo
 		)
 	).
 
-	% XXX this is completely unimplemented.
+    % XXX This is completely unimplemented.
+    %
 :- func pseudotypeinfo_get_higher_order_arity(type_info) = int.
+
 pseudotypeinfo_get_higher_order_arity(_) = 1 :-
 	det_unimplemented("pseudotypeinfo_get_higher_order_arity").
 
 	% Make a new type-info with the given arity, using the given type_info
 	% as the basis.
-
+    %
 :- func new_type_info(type_info::in, int::in) = (type_info::uo) is det.
+
 new_type_info(TypeInfo::in, _::in) = (NewTypeInfo::uo) :-
 	unsafe_promise_unique(TypeInfo, NewTypeInfo),
 	det_unimplemented("new_type_info").
@@ -1614,7 +1598,7 @@
 ").
 
 	% Get the pseudo-typeinfo at the given index from the argument types.
-
+    %
 :- some [T] func get_pti_from_arg_types(arg_types, int) = T.
 
 get_pti_from_arg_types(_::in, _::in) = (42::out) :-
@@ -1631,13 +1615,13 @@
 ").
 
 :- pragma foreign_proc("C#",
-	get_pti_from_arg_types(ArgTypes::in, Index::in) =
-		(ArgTypeInfo::out), [promise_pure], "
+    get_pti_from_arg_types(ArgTypes::in, Index::in) = (ArgTypeInfo::out),
+    [promise_pure], "
 	ArgTypeInfo = ArgTypes[Index];
 ").
 
 	% Get the pseudo-typeinfo at the given index from a type-info.
-
+    %
 :- some [T] func get_pti_from_type_info(type_info, int) = T.
 
 get_pti_from_type_info(_::in, _::in) = (42::out) :-
@@ -1653,8 +1637,8 @@
 	% Get the type info for a particular type variable number
 	% (it might be in the type_info or in the term itself).
 	%
-	% XXX existentially quantified vars are not yet handled.
-
+    % XXX Existentially quantified vars are not yet handled.
+    %
 :- pred get_type_info_for_var( type_info::in, int::in, T::in,
 	du_functor_desc::in, type_info::out) is det.
 
@@ -1677,28 +1661,26 @@
 		( Offset < 0 ->
 			ArgTypeInfo = SlotMaybeTypeInfo
 		;
-			ArgTypeInfo = typeclass_info_type_info(
-				SlotMaybeTypeInfo, Offset)
+            ArgTypeInfo = typeclass_info_type_info(SlotMaybeTypeInfo, Offset)
 		)
 	).
 
 	% An unchecked cast to type_info (for pseudo-typeinfos).
-
+    %
 :- func type_info_cast(T) = type_info.
 
 type_info_cast(X) = unsafe_cast(X).
 
-	% Get a subterm term, given its type_info, the original term, its
-	% index and the start region size.
-
+    % Get a subterm term, given its type_info, the original term, its index
+    % and the start region size.
+    %
 :- some [T] func get_subterm(type_info, U, int, int) = T.
 
 get_subterm(_::in, _::in, _::in, _::in) = (42::out) :-
 	det_unimplemented("get_subterm").
 
 :- pragma foreign_proc("C#",
-	get_subterm(TypeInfo::in, Term::in, Index::in, ExtraArgs::in)
-		= (Arg::out),
+    get_subterm(TypeInfo::in, Term::in, Index::in, ExtraArgs::in) = (Arg::out),
 	[promise_pure],
 "
 	int i = Index + ExtraArgs;
@@ -1713,7 +1695,7 @@
 ").
 
 	% Test whether a type info is variable.
-
+    %
 :- pred typeinfo_is_variable(T::in, int::out) is semidet.
 
 typeinfo_is_variable(_::in, 42::out) :-
@@ -1736,12 +1718,11 @@
 	typeinfo_is_variable(TypeInfo::in, VarNum::out),
 	[will_not_call_mercury, promise_pure],
 "
-	succeeded = (TypeInfo.getClass() ==
-		mercury.runtime.PseudoTypeInfo.class);
+    succeeded = (TypeInfo.getClass() == mercury.runtime.PseudoTypeInfo.class);
 	if (succeeded) {
 		// This number is used to index into an array, hence the -1
-		VarNum = ((mercury.runtime.PseudoTypeInfo)TypeInfo).
-			variable_number - 1;
+        VarNum = ((mercury.runtime.PseudoTypeInfo)TypeInfo).variable_number
+            - 1;
 	} else {
 		VarNum = -1; // just to keep the compiler happy
 	}
@@ -2021,8 +2002,7 @@
 	det_unimplemented("sectag_alternatives").
 
 :- pragma foreign_proc("C#",
-	du_sectag_alternatives(X::in, PTagEntry::in) =
-		(FunctorDescriptor::out),
+    du_sectag_alternatives(X::in, PTagEntry::in) = (FunctorDescriptor::out),
 	[promise_pure],
 "
 	object[] sectag_alternatives;
@@ -2032,8 +2012,7 @@
 ").
 
 :- pragma foreign_proc("Java",
-	du_sectag_alternatives(X::in, PTagEntry::in) =
-		(FunctorDescriptor::out),
+    du_sectag_alternatives(X::in, PTagEntry::in) = (FunctorDescriptor::out),
 	[promise_pure],
 "
 	FunctorDescriptor = PTagEntry.sectag_alternatives[X];
@@ -2062,8 +2041,7 @@
 	[promise_pure],
 "
 	TypeInfosPlain = (int)
-		ExistInfo[(int)
-			exist_info_field_nums.typeinfos_plain];
+        ExistInfo[(int) exist_info_field_nums.typeinfos_plain];
 ").
 
 :- func exist_info_tcis(exist_info) = int.
@@ -2075,8 +2053,7 @@
 	exist_info_tcis(ExistInfo::in) = (TCIs::out),
 	[promise_pure],
 "
-	TCIs = (int) ExistInfo[(int)
-		exist_info_field_nums.tcis];
+    TCIs = (int) ExistInfo[(int) exist_info_field_nums.tcis];
 ").
 
 :- func exist_arg_num(typeinfo_locn) = int.
@@ -2118,8 +2095,7 @@
 		TypeInfo = (object[]) ((object[]) Term)[Index];
 	} catch (System.InvalidCastException) {
 		// try high level data
-		TypeInfo = (object[])
-			Term.GetType().GetFields()[Index].GetValue(Term);
+        TypeInfo = (object[]) Term.GetType().GetFields()[Index].GetValue(Term);
 	}
 ").
 
@@ -2127,10 +2103,8 @@
 
 typeclass_info_type_info(TypeClassInfo, Index) = unsafe_cast(TypeInfo) :-
 	private_builtin__type_info_from_typeclass_info(
-		unsafe_cast(TypeClassInfo)
-			`with_type` private_builtin__typeclass_info,
-		Index, TypeInfo
-			`with_type` private_builtin__type_info).
+        unsafe_cast(TypeClassInfo) `with_type` private_builtin__typeclass_info,
+        Index, TypeInfo `with_type` private_builtin__type_info).
 
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
@@ -2142,18 +2116,16 @@
 
 :- func type_info_index(int, type_info) = type_info.
 
+type_info_index(_::in, TypeInfo::in) = (TypeInfo::out) :-
 	% This is an "unimplemented" definition in Mercury, which will be
 	% used by default.
-
-type_info_index(_::in, TypeInfo::in) = (TypeInfo::out) :-
 	det_unimplemented("type_info_index").
 
 :- pragma foreign_proc("Java",
 	type_info_index(X::in, TypeInfo::in) = (TypeInfoAtIndex::out),
 	[will_not_call_mercury, promise_pure],
 "
-	TypeInfoAtIndex = (TypeInfo_Struct)
-		((TypeInfo_Struct) TypeInfo).args[X];
+    TypeInfoAtIndex = (TypeInfo_Struct) ((TypeInfo_Struct) TypeInfo).args[X];
 ").
 
 :- pragma foreign_proc("C#",
@@ -2170,8 +2142,8 @@
 	det_unimplemented("type_info_index").
 
 :- pragma foreign_proc("C#",
-	update_type_info_index(X::in, NewValue::in, OldTypeInfo::di,
-		NewTypeInfo::uo),
+    update_type_info_index(X::in, NewValue::in,
+        OldTypeInfo::di, NewTypeInfo::uo),
 	[will_not_call_mercury, promise_pure],
 "
 	OldTypeInfo[X] = NewValue;
@@ -2273,8 +2245,7 @@
 	[will_not_call_mercury, promise_pure, thread_safe],
 "
 	int rep;
-	rep = (int) TypeCtorInfo[
-		(int) type_ctor_info_field_nums.type_ctor_rep];
+    rep = (int) TypeCtorInfo[(int) type_ctor_info_field_nums.type_ctor_rep];
 	TypeCtorRep = mercury.runtime.LowLevelData.make_enum(rep);
 ").
 :- pragma foreign_proc("Java",
@@ -2304,8 +2275,7 @@
 	[will_not_call_mercury, promise_pure, thread_safe],
 "
 	Name = (string)
-		TypeCtorInfo[(int)
-		type_ctor_info_field_nums.type_ctor_module_name];
+        TypeCtorInfo[(int) type_ctor_info_field_nums.type_ctor_module_name];
 ").
 
 :- pragma foreign_proc("Java",
@@ -2649,6 +2619,7 @@
 
 :- func notag_functor_desc(type_ctor_rep, int, type_functors)
 	= notag_functor_desc.
+
 :- mode notag_functor_desc(in(notag), in, in) = out is det.
 
 notag_functor_desc(_, Num, TypeFunctors) = NoTagFunctorDesc :-
@@ -2673,9 +2644,9 @@
 	Name = NotagFunctorDesc.no_tag_functor_name;
 ").
 
-	% XXX This is a bug.  This function should actually return a
-	% PseudoTypeInfo.  The Java code below should work once this is
-	% corrected.
+    % XXX This is a bug. This function should actually return a PseudoTypeInfo.
+    % The Java code below should work once this is corrected.
+    %
 :- func notag_functor_arg_type(notag_functor_desc) = type_info.
 
 notag_functor_arg_type(NoTagFunctorDesc) = NoTagFunctorDesc ^ unsafe_index(1).
@@ -2798,5 +2769,4 @@
 	% matching foreign_proc version.
 	private_builtin__sorry("rtti_implementation__unsafe_get_enum_value/1").
 
-%-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
Index: library/store.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/store.m,v
retrieving revision 1.48
diff -u -b -r1.48 store.m
--- library/store.m	16 Jun 2005 04:08:05 -0000	1.48
+++ library/store.m	10 Oct 2005 15:27:55 -0000
@@ -1,4 +1,6 @@
 %-----------------------------------------------------------------------------%
+% vim: ft=mercury ts=4 sw=4 et wm=0 tw=0
+%-----------------------------------------------------------------------------%
 % Copyright (C) 1994-1997, 2000-2005 The University of Melbourne.
 % 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.
@@ -57,14 +59,12 @@
 :- type io_mutvar(T) == generic_mutvar(T, io__state).
 :- type store_mutvar(T, S) == generic_mutvar(T, store(S)).
 
-	% Create a new mutable variable,
-	% initialized with the specified value.
+    % Create a new mutable variable, initialized with the specified value.
 	%
 :- pred store__new_mutvar(T::in, generic_mutvar(T, S)::out, S::di, S::uo)
 	is det <= store(S).
 
-	% copy_mutvar(OldMutvar, NewMutvar, S0, S)
-	% is equivalent to the sequence
+    % copy_mutvar(OldMutvar, NewMutvar, S0, S) is equivalent to the sequence
 	% 	get_mutvar(OldMutvar, Value, S0, S1),
 	% 	new_mutvar(NewMutvar, Value, S1, S )
 	% 	
@@ -82,7 +82,8 @@
 	S::di, S::uo) is det <= store(S).
 
 	% new_cyclic_mutvar(Func, Mutvar):
-	% create a new mutable variable, whose value is initialized
+    %
+    % Create a new mutable variable, whose value is initialized
 	% with the value returned from the specified function `Func'.
 	% The argument passed to the function is the mutvar itself,
 	% whose value has not yet been initialized (this is safe
@@ -111,13 +112,16 @@
 %
 
 	% generic_ref(T, S):
-	% a reference to value of type T in store S
+    %
+    % A reference to value of type T in store S.
+    %
 :- type generic_ref(T, S).
 :- type io_ref(T, S) == generic_ref(T, io__state).
 :- type store_ref(T, S) == generic_ref(T, store(S)).
 
 	% new_ref(Val, Ref):
 	%	/* In C: Ref = malloc(...); *Ref = Val; */
+    %
 	% Given a value of any type `T', insert a copy of the term
 	% into the store and return a new reference to that term.
 	% (This does not actually perform a copy, it just returns a view
@@ -129,6 +133,7 @@
 	S::di, S::uo) is det <= store(S).
 
 	% ref_functor(Ref, Functor, Arity):
+    %
 	% Given a reference to a term, return the functor and arity
 	% of that term.
 	%
@@ -137,6 +142,7 @@
 
 	% arg_ref(Ref, ArgNum, ArgRef):
 	%	/* Pseudo-C code: ArgRef = &Ref[ArgNum]; */
+    %
 	% Given a reference to a term, return a reference to
 	% the specified argument (field) of that term
 	% (argument numbers start from zero).
@@ -148,6 +154,7 @@
 
 	% new_arg_ref(Val, ArgNum, ArgRef):
 	%	/* Pseudo-C code: ArgRef = &Val[ArgNum]; */
+    %
 	% Equivalent to `new_ref(Val, Ref), arg_ref(Ref, ArgNum, ArgRef)',
 	% except that it is more efficient.
 	% It is an error if the argument number is out of range,
@@ -158,6 +165,7 @@
 
 	% set_ref(Ref, ValueRef):
 	%	/* Pseudo-C code: *Ref = *ValueRef; */
+    %
 	% Given a reference to a term (Ref),
 	% a reference to another term (ValueRef),
 	% update the store so that the term referred to by Ref
@@ -168,6 +176,7 @@
 
 	% set_ref_value(Ref, Value):
 	%	/* Pseudo-C code: *Ref = Value; */
+    %
 	% Given a reference to a term (Ref), and a value (Value),
 	% update the store so that the term referred to by Ref
 	% is replaced with Value.
@@ -184,8 +193,7 @@
 :- pred store__copy_ref_value(generic_ref(T, S)::in, T::uo,
 	S::di, S::uo) is det <= store(S).
 
-	% Same as above, but without making a copy.
-	% Destroys the store.
+    % Same as above, but without making a copy. Destroys the store.
 	%
 :- pred store__extract_ref_value(S::di, generic_ref(T, S)::in, T::out)
 	is det <= store(S).
@@ -239,9 +247,8 @@
 % The store type itself is just a dummy type,
 % with no real representation.
 
-	% XXX we use `mkstore' here rather than `store' to work
-	%     around a bug with the Java back-end: it generates
-	%     invalid Java code if we use `store'.
+    % XXX We use `mkstore' here rather than `store' to work around a bug
+    % with the Java back-end: it generates invalid Java code if we use `store'.
 :- type store(S) ---> mkstore(c_pointer)
 	where equality is store_equal, comparison is store_compare.
 
@@ -256,11 +263,9 @@
 store_compare(_, _, _) :-
 	error("attempt to compare two stores").
 
-% Mutvars and references are each represented as a pointer to a single word
-% on the heap.
-
+    % Mutvars and references are each represented as a pointer to a single word
+    % on the heap.
 :- type generic_mutvar(T, S) ---> mutvar(private_builtin.ref(T)).
-
 :- type generic_ref(T, S) ---> ref(private_builtin.ref(T)).
 
 store__new(S) :-
@@ -275,22 +280,20 @@
 :- pragma foreign_proc("Java", store__do_init(_S0::uo),
 	[will_not_call_mercury, promise_pure], "").
 
-/*
-Note -- the syntax for the operations on stores
-might be nicer if we used some new operators, e.g.
-
-	:- op(.., xfx, ('<-')).
-	:- op(.., fy, ('!')).
-	:- op(.., xfx, (':=')).
-
-Then we could do something like this:
-
-	Ptr <- new(Val)	  -->	new_mutvar(Val, Ptr).
-	Val <- !Ptr 	  -->	get_mutvar(Ptr, Val).
-	!Ptr := Val	  -->	set_mutvar(Ptr, Val).
-
-I wonder whether it is worth it?  Hmm, probably not.
-*/
+% Note -- the syntax for the operations on stores
+% might be nicer if we used some new operators, e.g.
+% 
+%   :- op(.., xfx, ('<-')).
+%   :- op(.., fy, ('!')).
+%   :- op(.., xfx, (':=')).
+% 
+% Then we could do something like this:
+% 
+%   Ptr <- new(Val)   -->   new_mutvar(Val, Ptr).
+%   Val <- !Ptr       -->   get_mutvar(Ptr, Val).
+%   !Ptr := Val   -->   set_mutvar(Ptr, Val).
+% 
+% I wonder whether it is worth it?  Hmm, probably not.
 
 :- pragma foreign_proc("C",
 	new_mutvar(Val::in, Mutvar::out, S0::di, S::uo),
@@ -342,9 +345,9 @@
 	Mutvar.object = Val;
 ").
 
-copy_mutvar(Mutvar, Copy) -->
-	get_mutvar(Mutvar, Value),
-	new_mutvar(Value, Copy).
+copy_mutvar(Mutvar, Copy, !S) :-
+    get_mutvar(Mutvar, Value, !S),
+    new_mutvar(Value, Copy, !S).
 
 :- pred store__unsafe_new_uninitialized_mutvar(generic_mutvar(T, S)::out,
 	S::di, S::uo) is det <= store(S).
@@ -397,19 +400,16 @@
 		// Set the field according to a given index.
 		public void setField(int num) {
 			try {
-				field = object.getClass().
-						getDeclaredFields()[num];
+                field = object.getClass().getDeclaredFields()[num];
 			} catch (java.lang.SecurityException se) {
 				throw new java.lang.RuntimeException(
-						""Security manager denied "" +
-						""access to object fields"");
+                    ""Security manager denied access to object fields"");
 			} catch (java.lang.ArrayIndexOutOfBoundsException e) {
 			  	throw new java.lang.RuntimeException(
 						""No such field in object"");
 			} catch (java.lang.Exception e) {
 				throw new java.lang.RuntimeException(
-						""Unable to set field: "" +
-						e.getMessage());
+                    ""Unable to set field: "" + e.getMessage());
 			}
 		}
 
@@ -422,21 +422,17 @@
 					return field.get(object);
 				} catch (java.lang.IllegalAccessException e) {
 					throw new java.lang.RuntimeException(
-							""Field "" +
-							""inaccessible"");
+                        ""Field inaccessible"");
 				} catch (java.lang.IllegalArgumentException e)
 				{
 					throw new java.lang.RuntimeException(
-							""Field-object "" +
-							""mismatch"");
+                        ""Field-object mismatch"");
 				} catch (java.lang.NullPointerException e) {
 					throw new java.lang.RuntimeException(
 							""Object is null"");
 				} catch (java.lang.Exception e) {
 					throw new java.lang.RuntimeException(
-							""Unable to access "" +
-							""field: "" +
-							e.getMessage());
+                        ""Unable to access field: "" + e.getMessage());
 				}
 			}
 		}
@@ -446,18 +442,15 @@
 			try {
 				field.set(object, value);
 			} catch (java.lang.IllegalAccessException e) {
-				throw new java.lang.RuntimeException(
-						""Field inaccessible"");
+                throw new java.lang.RuntimeException(""Field inaccessible"");
 			} catch (java.lang.IllegalArgumentException e) {
 				throw new java.lang.RuntimeException(
 						""Field-object mismatch"");
 			} catch (java.lang.NullPointerException e) {
-				throw new java.lang.RuntimeException(
-						""Object is null"");
+                throw new java.lang.RuntimeException(""Object is null"");
 			} catch (java.lang.Exception e) {
 				throw new java.lang.RuntimeException(
-						""Unable to access field: "" +
-						e.getMessage());
+                        ""Unable to access field: "" + e.getMessage());
 			}
 		}
 	} // class Ref
@@ -482,13 +475,13 @@
 ").
 
 copy_ref_value(Ref, Val) -->
-	/* XXX need to deep-copy non-atomic types */
+    % XXX Need to deep-copy non-atomic types.
 	unsafe_ref_value(Ref, Val).
 
-	% unsafe_ref_value extracts the value that a reference
-	% refers to, without making a copy; it is unsafe because
-	% the store could later be modified, changing the returned
-	% value.
+    % Unsafe_ref_value extracts the value that a reference refers to, without
+    % making a copy; it is unsafe because the store could later be modified,
+    % changing the returned value.
+    %
 :- pred store__unsafe_ref_value(generic_ref(T, S)::in, T::uo,
 	S::di, S::uo) is det <= store(S).
 
@@ -536,8 +529,7 @@
 	if (!MR_arg(type_info, (MR_Word *) Ref, ArgNum, &arg_type_info,
 		&arg_ref, MR_NONCANON_ABORT))
 	{
-		MR_fatal_error(
-			""store__arg_ref: argument number out of range"");
+        MR_fatal_error(""store__arg_ref: argument number out of range"");
 	}
 
 	if (MR_compare_type_info(arg_type_info, exp_arg_type_info) !=
@@ -558,8 +550,8 @@
 "
 	/*
 	** XXX Some dynamic type-checking should be done here to check that
-	**     the type of the specified Arg matches the type supplied by the
-	**     caller.  This will require RTTI.
+    ** the type of the specified Arg matches the type supplied by the caller.
+    ** This will require RTTI.
 	*/
 
 	ArgRef = new mercury.store.Ref(Ref.getValue(), ArgNum);
@@ -582,15 +574,13 @@
 	if (!MR_arg(type_info, (MR_Word *) &Val, ArgNum, &arg_type_info,
 		&arg_ref, MR_NONCANON_ABORT))
 	{
-		MR_fatal_error(
-			""store__new_arg_ref: argument number out of range"");
+        MR_fatal_error(""store__new_arg_ref: argument number out of range"");
 	}
 
 	if (MR_compare_type_info(arg_type_info, exp_arg_type_info) !=
 		MR_COMPARE_EQUAL)
 	{
-		MR_fatal_error(
-			""store__new_arg_ref: argument has wrong type"");
+        MR_fatal_error(""store__new_arg_ref: argument has wrong type"");
 	}
 
 	MR_restore_transient_registers();
@@ -619,8 +609,8 @@
 "
 	/*
 	** XXX Some dynamic type-checking should be done here to check that
-	**     the type of the specified Arg matches the type supplied by the
-	**     caller.  This will require RTTI.
+    ** the type of the specified Arg matches the type supplied by the caller.
+    ** This will require RTTI.
 	*/
 
 	ArgRef = new mercury.store.Ref(Val, ArgNum);
@@ -677,7 +667,9 @@
 	[will_not_call_mercury, promise_pure],
 "{
 	/* unsafe - does not check type & arity, won't handle no_tag types */
-	MR_Word *Ptr = (MR_Word *) MR_strip_tag((MR_Word) Ref);
+    MR_Word *Ptr;
+
+    Ptr = (MR_Word *) MR_strip_tag((MR_Word) Ref);
 	ArgRef = (MR_Word) &Ptr[Arg];
 	S = S0;
 }").
@@ -694,7 +686,9 @@
 	[will_not_call_mercury, promise_pure],
 "{
 	/* unsafe - does not check type & arity, won't handle no_tag types */
-	MR_Word *Ptr = (MR_Word *) MR_strip_tag((MR_Word) Val);
+    MR_Word *Ptr;
+
+    Ptr = (MR_Word *) MR_strip_tag((MR_Word) Val);
 	ArgRef = (MR_Word) &Ptr[Arg];
 	S = S0;
 }").
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/recompilation
cvs diff: Diffing tests/tabling
cvs diff: Diffing tests/term
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:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list