[m-rev.] trivial diff: convert termination analyser to 4-space indentation

Julien Fischer juliensf at cs.mu.OZ.AU
Fri Oct 28 23:59:43 AEST 2005


Estimated hours taken: 2
Branches: main

Clean up the termination analysis modules and bring them into line with our
current coding standards.  There are no major changes to any algorithms,
although there are a few minor ones, e.g.  converting if-then-elses into
switches and alike.

compiler/termination.m:
compiler/term_errors.m:
compiler/term_norm.m:
compiler/term_pass1.m:
compiler/term_pass2.m:
compiler/term_traversal.m:
compiler/term_util.m:
	Convert these modules to use 4-space indentation.

	s/Module/ModuleInfo/

	Use unexpected/2 in place of error/1.

	Replace some if-then-elses with switches, and make use of the enhanced
	switch detection capability.

	Rename some predicates where the existing name wasn't clear or where
	it avoids excessive module qualification in importing modules.

	Position comments according to our current coding standards.

	Use a '.' as a module qualifier throughout.

	Delete the comment about how to add support for a new norm, that
	information is now in term_norm and in any case the comment was
	incorrect (it referred types that no longer exist).

	Delete a long obsolete comment that describes the analyser's interface
	to the lp_solve package.

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

Julien.

Index: mercury_compile.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mercury_compile.m,v
retrieving revision 1.357
diff -u -b -r1.357 mercury_compile.m
--- mercury_compile.m	28 Oct 2005 02:10:17 -0000	1.357
+++ mercury_compile.m	28 Oct 2005 06:52:29 -0000
@@ -2903,7 +2903,7 @@
         Termination = yes
     ->
         maybe_write_string(Verbose, "% Detecting termination...\n", !IO),
-        termination__pass(!HLDS, !IO),
+        analyse_termination_in_module(!HLDS, !IO),
         maybe_write_string(Verbose, "% Termination checking done.\n", !IO),
         maybe_report_stats(Stats, !IO)
     ;
Index: post_term_analysis.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/post_term_analysis.m,v
retrieving revision 1.7
diff -u -b -r1.7 post_term_analysis.m
--- post_term_analysis.m	28 Oct 2005 02:10:28 -0000	1.7
+++ post_term_analysis.m	28 Oct 2005 07:20:56 -0000
@@ -1,3 +1,5 @@
+%-----------------------------------------------------------------------------%
+% vim: ft=mercury ts=4 sw=4 et
 %----------------------------------------------------------------------------%
 % Copyright (C) 2005 The University of Melbourne.
 % This file may only be copied under the terms of the GNU General
@@ -24,8 +26,7 @@

 :- import_module io.

-:- pred post_term_analysis.process_module(module_info::in, io::di, io::uo)
-	is det.
+:- pred run_post_term_analysis(module_info::in, io::di, io::uo) is det.

 %----------------------------------------------------------------------------%
 %----------------------------------------------------------------------------%
@@ -58,24 +59,24 @@

 %----------------------------------------------------------------------------%

-post_term_analysis.process_module(ModuleInfo, !IO) :-
+run_post_term_analysis(ModuleInfo, !IO) :-
 	warn_non_term_user_special_preds(ModuleInfo, !IO).

 %----------------------------------------------------------------------------%
 %
-% Warn about user-defined special predicates that do not terminate.
+% Warn about user-defined special predicates that do not terminate
 %

-% We check the termination status of user-defined special predicates by
-% taking the body goal of the compiler generated wrapper predicate and
-% checking if that terminates.  We cannot check the termination status
-% of the compiler generated wrappers directly, because termination analysis
-% always assumes that they terminate.
+% We check the termination status of user-defined special predicates by taking
+% the body goal of the compiler generated wrapper predicate and checking if
+% that terminates.  We cannot check the termination status of the compiler
+% generated wrappers directly, because termination analysis always assumes
+% that they terminate.
 %
-% Since all of the special predicates of interest here have to be defined
-% in the same module as the type that uses them, we only check locally
-% defined types.  The ones for imported types will be checked when the
-% relevant module is compiled and analysed.
+% Since all of the special predicates of interest here have to be defined in
+% the same module as the type that uses them, we only check locally defined
+% types.  The ones for imported types will be checked when the relevant module
+% is compiled and analysed.

 :- pred warn_non_term_user_special_preds(module_info::in, io::di, io::uo)
 	is det.
@@ -84,27 +85,25 @@
 	globals.io_lookup_bool_option(termination, Termination, !IO),
 	globals.io_lookup_bool_option(warn_non_term_special_preds,
 		WarnSpecialPreds, !IO),
-	globals.io_lookup_bool_option(make_optimization_interface,
-		MakeOptInt, !IO),
-	globals.io_lookup_bool_option(transitive_optimization,
-		TransIntermodOpt, !IO),
+    globals.io_lookup_bool_option(make_optimization_interface, MakeOptInt,
+        !IO),
+    globals.io_lookup_bool_option(transitive_optimization, TransIntermodOpt,
+        !IO),
 	(
 		Termination = yes, WarnSpecialPreds = yes,
 		%
-		% Don't run this pass if we are only building the
-		% optimization interface and we are compiling
-		% with `--transitive-intermodule-optimization'
-		% enabled because we'll get more accurate results
-		% when we build the .trans_opt files.  Any warnings
-		% this time around may be spurious.
+        % Don't run this pass if we are only building the optimization
+        % interface and we are compiling with
+        % `--transitive-intermodule-optimization' enabled because we'll get
+        % more accurate results when we build the .trans_opt files.  Any
+        % warnings this time around may be spurious.
 		%
 		not (MakeOptInt = yes, TransIntermodOpt = yes)
 	->
-		module_info_get_special_pred_map(ModuleInfo,
-			SpecialPredMap),
+        module_info_get_special_pred_map(ModuleInfo, SpecialPredMap),
 		module_info_get_type_table(ModuleInfo, TypeTable),
-		map.foldl(warn_non_term_user_special_pred(ModuleInfo,
-			TypeTable), SpecialPredMap, !IO)
+        map.foldl(warn_non_term_user_special_pred(ModuleInfo, TypeTable),
+            SpecialPredMap, !IO)
 	;
 		true
 	).
@@ -116,7 +115,7 @@
 		SpecialPredId - TypeCtor, PredId, !IO) :-
 	%
 	% index predicates cannot be defined by the user and should
-	% always terminate in any case.  Do not perform this
+    % always terminate by design.  Do not perform this
 	% check for builtin types that don't have hlds_type_defns.
 	%
 	BuiltinTypeCtors = builtin_type_ctors_with_no_hlds_type_defn,
@@ -157,11 +156,10 @@
  			PredId, ProcId, _, ProcInfo),
  		proc_info_goal(ProcInfo, BodyGoal),
  		%
- 		% We cannot just look up the the termination_info because
- 		% the termination status of compiler generated wrapper
- 		% predicates for special preds is always set to terminates.
- 		% Instead, we check if the body goal of the generated wrapper
- 		% predicate terminates.
+        % We cannot just look up the the termination_info because the
+        % termination status of compiler generated wrapper predicates for
+        % special preds is always set to terminates.  Instead, we check if the
+        % body of the generated wrapper predicate terminates.
  		%
 		( not goal_cannot_loop(ModuleInfo, BodyGoal) ->
  			get_type_defn_context(TypeDefn, Context),
@@ -174,8 +172,8 @@
 		true
 	).

-	% Succeeds if the specified type of special_pred for this
-	% type needs to have its termination status checked.
+    % Succeeds if the specified type of special_pred for this type needs to
+    % have its termination status checked.
 	%
 :- pred special_pred_needs_term_check(module_info::in,
 	special_pred_id::in, hlds_type_defn::in) is semidet.
@@ -207,9 +205,8 @@
 		)
 	).

-	% Succeeds if the given type has user-defined equality and/or
-	% comparison and returns the relevant information about which
-	% predicates implement it.
+    % Succeeds if the given type has user-defined equality and/or comparison
+    % and returns the relevant information about which predicates implement it.
 	%
 :- pred get_user_unify_compare(module_info::in, hlds_type_body::in,
 	unify_compare::out) is semidet.
@@ -242,7 +239,8 @@
 		unexpected(this_file, "emit_non_term_user_special_" ++
 			"warning/5 index predicate.")
 	),
-	Pieces = [words("Warning: the user-defined "),
+    Pieces = [
+        words("Warning: the user-defined "),
 		  fixed(SpecialPredStr ++ " predicate"),
 		  words("for the type "),
 		  fixed(TypeCtorString),
Index: term_errors.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/term_errors.m,v
retrieving revision 1.32
diff -u -b -r1.32 term_errors.m
--- term_errors.m	28 Oct 2005 02:10:38 -0000	1.32
+++ term_errors.m	28 Oct 2005 07:43:57 -0000
@@ -6,15 +6,15 @@
 % Public License - see the file COPYING in the Mercury distribution.
 %-----------------------------------------------------------------------------%
 %
-% term_errors.m
-% Main author: crs.
+% File: term_errors.m
+% Main author: crs
 %
 % This module prints out the various error messages that are produced by
 % the various modules of termination analysis.
 %
 %-----------------------------------------------------------------------------%

-:- module transform_hlds__term_errors.
+:- module transform_hlds.term_errors.

 :- interface.

@@ -28,6 +28,8 @@
 :- import_module list.
 :- import_module std_util.

+%-----------------------------------------------------------------------------%
+
 :- type termination_error
     --->    pragma_foreign_code
             % The analysis result depends on the change constant
@@ -156,11 +158,15 @@
     %
 :- pred indirect_error(termination_error::in) is semidet.

+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+
 :- implementation.

 :- import_module hlds.hlds_error_util.
 :- import_module hlds.hlds_out.
 :- import_module hlds.passes_aux.
+:- import_module libs.compiler_util.
 :- import_module libs.globals.
 :- import_module libs.options.
 :- import_module parse_tree.error_util.
@@ -177,6 +183,8 @@
 :- import_module term.
 :- import_module varset.

+%-----------------------------------------------------------------------------%
+
 indirect_error(horder_call).
 indirect_error(method_call).
 indirect_error(aditi_call).
@@ -203,18 +211,18 @@
         % XXX This should never happen but for some reason, it often does.
         % error("empty list of errors")
         Pieces2 = [words("not proven, for unknown reason(s).")],
-        list__append(Pieces1, Pieces2, Pieces),
+        list.append(Pieces1, Pieces2, Pieces),
         write_error_pieces(Context, 0, Pieces, !IO)
     ;
         Errors = [Error],
         Pieces2 = [words("not proven for the following reason:")],
-        list__append(Pieces1, Pieces2, Pieces),
+        list.append(Pieces1, Pieces2, Pieces),
         write_error_pieces(Context, 0, Pieces, !IO),
         output_term_error(Error, Single, no, 0, Module, !IO)
     ;
         Errors = [_, _ | _],
         Pieces2 = [words("not proven for the following reasons:")],
-        list__append(Pieces1, Pieces2, Pieces),
+        list.append(Pieces1, Pieces2, Pieces),
         write_error_pieces(Context, 0, Pieces, !IO),
         output_term_errors(Errors, Single, 1, 0, Module, !IO)
     ).
@@ -238,17 +246,17 @@
     Piece2 = words("set to infinity for the following"),
     (
         Errors = [],
-        error("empty list of errors")
+        unexpected(this_file, "empty list of errors")
     ;
         Errors = [Error],
         Piece3 = words("reason:"),
-        list__append(Pieces1, [Piece2, Piece3], Pieces),
+        list.append(Pieces1, [Piece2, Piece3], Pieces),
         write_error_pieces(Context, 0, Pieces, !IO),
         output_term_error(Error, Single, no, 0, Module, !IO)
     ;
         Errors = [_, _ | _],
         Piece3 = words("reasons:"),
-        list__append(Pieces1, [Piece2, Piece3], Pieces),
+        list.append(Pieces1, [Piece2, Piece3], Pieces),
         write_error_pieces(Context, 0, Pieces, !IO),
         output_term_errors(Errors, Single, 1, 0, Module, !IO)
     ).
@@ -269,8 +277,8 @@
 output_term_error(Context - Error, Single, ErrorNum, Indent, Module, !IO) :-
     description(Error, Single, Module, Pieces0, Reason),
     ( ErrorNum = yes(N) ->
-        string__int_to_string(N, Nstr),
-        string__append_list(["Reason ", Nstr, ":"], Preamble),
+        string.int_to_string(N, Nstr),
+        string.append_list(["Reason ", Nstr, ":"], Preamble),
         Pieces = [fixed(Preamble) | Pieces0]
     ;
         Pieces = Pieces0
@@ -283,7 +291,8 @@
             ArgSizePPIdSCC = [InfArgSizePPId],
             report_arg_size_errors(ArgSizePPIdSCC, ArgSizeErrors, Module, !IO)
         ;
-            error("inf arg size procedure does not have inf arg size")
+            unexpected(this_file,
+                "inf arg size procedure does not have inf arg size")
         )
     ;
         true
@@ -303,12 +312,14 @@
     Pieces = [words("It contains an Aditi builtin call.")].

 description(pragma_foreign_code, _, _, Pieces, no) :-
-    Pieces = [words("It depends on the properties of"),
+    Pieces = [
+        words("It depends on the properties of"),
         words("foreign language code included via a"),
         fixed("`:- pragma c_code'"),
         words("or"),
         fixed("`:- pragma foreign'"),
-        words("declaration.")].
+        words("declaration.")
+    ].

 description(inf_call(CallerPPId, CalleePPId),
         Single, Module, Pieces, no) :-
@@ -346,9 +357,11 @@
     Pieces = Pieces1 ++ [Piece2] ++ CalleePieces ++ [Piece3].

 description(imported_pred, _, _, Pieces, no) :-
-    Pieces = [words("It contains one or more"),
+    Pieces = [
+        words("It contains one or more"),
         words("predicates and/or functions"),
-        words("imported from another module.")].
+        words("imported from another module.")
+    ].

 description(horder_args(CallerPPId, CalleePPId), Single, Module,
         Pieces, no) :-
@@ -427,13 +440,13 @@
     proc_info_varset(ProcInfo, Varset),
     term_errors_var_bag_description(OutputSuppliers, Varset,
         OutputSuppliersNames),
-    list__map((pred(OS::in, FOS::out) is det :- FOS = fixed(OS)),
+    list.map((pred(OS::in, FOS::out) is det :- FOS = fixed(OS)),
         OutputSuppliersNames, OutputSuppliersPieces),
     Pieces3 = [words("is not a subset of the head variables")],
     term_errors_var_bag_description(HeadVars, Varset, HeadVarsNames),
-    list__map((pred(HV::in, FHV::out) is det :- FHV = fixed(HV)),
+    list.map((pred(HV::in, FHV::out) is det :- FHV = fixed(HV)),
         HeadVarsNames, HeadVarsPieces),
-    list__condense([Pieces1, OutputSuppliersPieces, Pieces3,
+    list.condense([Pieces1, OutputSuppliersPieces, Pieces3,
         HeadVarsPieces], Pieces).

 description(cycle(_StartPPId, CallSites), _, Module, Pieces, no) :-
@@ -441,8 +454,10 @@
         SitePieces = describe_one_call_site(Module,
             should_module_qualify, DirectCall),
         Pieces = [words("At the recursive call to") | SitePieces] ++
-            [words("the arguments are"),
-            words("not guaranteed to decrease in size.")]
+            [
+                words("the arguments are"),
+                words("not guaranteed to decrease in size.")
+            ]
     ;
         Pieces1 = [words("In the recursive cycle"),
             words("through the calls to")],
@@ -450,20 +465,26 @@
             should_module_qualify, CallSites),
         Pieces2 = [words("the arguments are"),
             words("not guaranteed to decrease in size.")],
-        list__condense([Pieces1, SitePieces, Pieces2], Pieces)
+        list.condense([Pieces1, SitePieces, Pieces2], Pieces)
     ).

 description(too_many_paths, _, _, Pieces, no) :-
-    Pieces = [words("There are too many execution paths"),
-        words("for the analysis to process.")].
+    Pieces = [
+        words("There are too many execution paths"),
+        words("for the analysis to process.")
+    ].

 description(no_eqns, _, _, Pieces, no) :-
-    Pieces = [words("The analysis was unable to form any constraints"),
-        words("between the arguments of this group of procedures.")].
+    Pieces = [
+        words("The analysis was unable to form any constraints"),
+        words("between the arguments of this group of procedures.")
+    ].

 description(solver_failed, _, _, Pieces, no)  :-
-    Pieces = [words("The solver found the constraints produced"),
-        words("by the analysis to be infeasible.")].
+    Pieces = [
+        words("The solver found the constraints produced"),
+        words("by the analysis to be infeasible.")
+    ].

 description(is_builtin(_PredId), _Single, _, Pieces, no) :-
     % XXX require(unify(Single, yes(_)), "builtin not alone in SCC"),
@@ -484,15 +505,16 @@
         Pieces2 = describe_one_pred_name(Module, should_module_qualify,
             PredId) ++ [suffix(".")]
     ),
-    list__append(Pieces1, Pieces2, Pieces).
+    list.append(Pieces1, Pieces2, Pieces).

 description(inconsistent_annotations, _, _, Pieces, no) :-
     Pieces = [words("The termination pragmas are inconsistent.")].

 description(does_not_term_foreign(_), _, _, Pieces, no) :-
-    Piece1 = words("It contains foreign code that"),
-    Piece2 = words("may make one or more calls back to Mercury."),
-    Pieces = [Piece1, Piece2].
+    Pieces = [
+        words("It contains foreign code that"),
+        words("may make one or more calls back to Mercury.")
+    ].

 %----------------------------------------------------------------------------%

@@ -500,7 +522,7 @@
     list(string)::out) is det.

 term_errors_var_bag_description(HeadVars, Varset, Pieces) :-
-    bag__to_assoc_list(HeadVars, HeadVarCountList),
+    bag.to_assoc_list(HeadVars, HeadVarCountList),
     term_errors_var_bag_description_2(HeadVarCountList, Varset, yes,
         Pieces).

@@ -510,31 +532,37 @@
 term_errors_var_bag_description_2([], _, _, ["{}"]).
 term_errors_var_bag_description_2([Var - Count | VarCounts], Varset, First,
         [Piece | Pieces]) :-
-    varset__lookup_name(Varset, Var, VarName),
+    varset.lookup_name(Varset, Var, VarName),
     ( Count > 1 ->
-        string__append(VarName, "*", VarCountPiece0),
-        string__int_to_string(Count, CountStr),
-        string__append(VarCountPiece0, CountStr, VarCountPiece)
+        string.append(VarName, "*", VarCountPiece0),
+        string.int_to_string(Count, CountStr),
+        string.append(VarCountPiece0, CountStr, VarCountPiece)
     ;
         VarCountPiece = VarName
     ),
     (
         First = yes,
-        string__append("{", VarCountPiece, Piece0)
+        string.append("{", VarCountPiece, Piece0)
     ;
         First = no,
         Piece0 = VarCountPiece
     ),
     (
         VarCounts = [],
-        string__append(Piece0, "}.", Piece),
+        string.append(Piece0, "}.", Piece),
         Pieces = []
     ;
-        VarCounts = [_ | _],
+        VarCounts = [_|_],
         Piece = Piece0,
-        term_errors_var_bag_description_2(VarCounts, Varset, First,
-            Pieces)
+        term_errors_var_bag_description_2(VarCounts, Varset, First, Pieces)
     ).

 %----------------------------------------------------------------------------%
+
+:- func this_file = string.
+
+this_file = "term_errors.m".
+
+%----------------------------------------------------------------------------%
+:- end_module term_errors.
 %----------------------------------------------------------------------------%
Index: term_norm.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/term_norm.m,v
retrieving revision 1.14
diff -u -b -r1.14 term_norm.m
--- term_norm.m	28 Oct 2005 02:10:39 -0000	1.14
+++ term_norm.m	28 Oct 2005 13:54:47 -0000
@@ -1,17 +1,19 @@
 %-----------------------------------------------------------------------------%
+% vim: ft=mercury ts=4 sw=4 et
+%-----------------------------------------------------------------------------%
 % Copyright (C) 1997-2005 The University of Melbourne.
 % This file may only be copied under the terms of the GNU General
 % Public License - see the file COPYING in the Mercury distribution.
 %-----------------------------------------------------------------------------%
 %
 % File: term_norm.m
-% Main author: crs.
+% Main author: crs
 %
 % This modules defines predicates for computing functor norms.
 %
 %-----------------------------------------------------------------------------%

-:- module transform_hlds__term_norm.
+:- module transform_hlds.term_norm.

 :- interface.

@@ -25,8 +27,8 @@

 %-----------------------------------------------------------------------------%

-	% The functor_info type contains information about how the weight
-	% of a term is calculated.
+    % The functor_info type contains information about how the weight of a
+    % term is calculated.
 	%
 :- type functor_info.

@@ -35,34 +37,33 @@
 	%
 :- func set_functor_info(globals.termination_norm, module_info) = functor_info.

-	% This predicate computes the weight of a functor and the set of
-	% arguments of that functor whose sizes should be counted towards the
-	% size of the whole term.
+    % This predicate computes the weight of a functor and the set of arguments
+    % of that functor whose sizes should be counted towards the size of the
+    % whole term.
 	%
-	% NOTE: the list of arguments and the list of modes must be the
-	% same length.  They must also *not* contain any type-info
-	% related arguments as this may cause an exception to be thrown
-	% when using the `--num-data-elems' norm.  (This is because the
-	% weight table doesn't keep track of type-info related variables
-	% - it used to but intervening compiler passes tend to do things
-	% to the code in the mean time so the whole lot becomes
-	% inconsistent - in the end it's just easier to ignore them).
+    % NOTE: the list of arguments and the list of modes must be the same
+    % length.  They must also *not* contain any typeinfo related arguments as
+    % this may cause an exception to be thrown when using the
+    % `--num-data-elems' norm.  (This is because the weight table doesn't keep
+    % track of typeinfo related variables - it used to but intervening
+    % compiler passes tend to do things to the code in the mean time so the
+    % whole lot becomes inconsistent - in the end it's just easier to ignore
+    % them).
 	%
 :- pred functor_norm(functor_info::in, type_ctor::in, cons_id::in,
 	module_info::in, int::out, list(prog_var)::in, list(prog_var)::out,
 	list(uni_mode)::in, list(uni_mode)::out) is det.

-	% This function computes a lower bound on the weight of a fuctor.
-	% If the lower bound is zero then the weight of that functor is
-	% also zero.  If the lower bound is non-zero then there may be
-	% no upper bound on the size of the functor.  (And if there was
-	% this function wouldn't tell you about it anyhow).
+    % This function computes a lower bound on the weight of a fuctor.  If the
+    % lower bound is zero then the weight of that functor is also zero.  If
+    % the lower bound is non-zero then there may be no upper bound on the size
+    % of the functor.  (And if there were this function wouldn't tell you about
+    % it anyhow).
 	%
 :- func functor_lower_bound(functor_info, type_ctor, cons_id, module_info)
 	= int.

-	% Succeeds if all values of the given type are zero size
-	% (for all norms).
+    % Succeeds if all values of the given type are zero size (for all norms).
 	%
 :- pred zero_size_type(mer_type::in, module_info::in) is semidet.

@@ -86,6 +87,7 @@
 :- import_module require.
 :- import_module std_util.
 :- import_module string.
+:- import_module svmap.

 %-----------------------------------------------------------------------------%

@@ -143,19 +145,19 @@

 find_weights(ModuleInfo, Weights) :-
 	module_info_get_type_table(ModuleInfo, TypeTable),
-	map__to_assoc_list(TypeTable, TypeList),
-	map__init(Weights0),
-	list__foldl(find_weights_for_type, TypeList, Weights0, Weights).
+    map.to_assoc_list(TypeTable, TypeList),
+    map.init(Weights0),
+    list.foldl(find_weights_for_type, TypeList, Weights0, Weights).

 :- pred find_weights_for_type(pair(type_ctor, hlds_type_defn)::in,
 	weight_table::in, weight_table::out) is det.

 find_weights_for_type(TypeCtor - TypeDefn, !Weights) :-
-	hlds_data__get_type_defn_body(TypeDefn, TypeBody),
+    hlds_data.get_type_defn_body(TypeDefn, TypeBody),
 	(
 		Constructors = TypeBody ^ du_type_ctors,
-		hlds_data__get_type_defn_tparams(TypeDefn, TypeParams),
-		list__foldl(find_weights_for_cons(TypeCtor, TypeParams),
+        hlds_data.get_type_defn_tparams(TypeDefn, TypeParams),
+        list.foldl(find_weights_for_cons(TypeCtor, TypeParams),
 			Constructors, !Weights)
 	;
 		% This type does not introduce any functors
@@ -175,20 +177,20 @@
 :- pred find_weights_for_cons(type_ctor::in, list(type_param)::in,
 	constructor::in, weight_table::in, weight_table::out) is det.

-% For existentially typed data items the compiler may insert some
-% type-info related arguments into the functor.  We ignore these
-% arguments when calculating the weight of a functor and we do not
-% include them in the list of counted arguments.
+% For existentially typed data items the compiler may insert some typeinfo
+% related arguments into the functor.  We ignore these arguments when
+% calculating the weight of a functor and we do not include them in the list
+% of counted arguments.

 find_weights_for_cons(TypeCtor, Params, Ctor, !Weights) :-
 	Ctor = ctor(_ExistQVars, _Constraints, SymName, Args),
-	list__length(Args, Arity),
+    list.length(Args, Arity),
 	( Arity > 0 ->
 		find_and_count_nonrec_args(Args, TypeCtor, Params,
 			NumNonRec, ArgInfos0),
 		( NumNonRec = 0 ->
 			Weight = 1,
-			list__duplicate(Arity, yes, ArgInfos)
+            list.duplicate(Arity, yes, ArgInfos)
 		;
 			Weight = NumNonRec,
 			ArgInfos = ArgInfos0
@@ -198,14 +200,14 @@
 		WeightInfo = weight(0, [])
 	),
 	ConsId = cons(SymName, Arity),
-	map__det_insert(!.Weights, TypeCtor - ConsId, WeightInfo, !:Weights).
+    svmap.det_insert(TypeCtor - ConsId, WeightInfo, !Weights).

 :- pred find_weights_for_tuple(arity::in, weight_info::out) is det.

 find_weights_for_tuple(Arity, weight(Weight, ArgInfos)) :-
 	% None of the tuple arguments are recursive.
 	Weight = Arity,
-	list__duplicate(Arity, yes, ArgInfos).
+    list.duplicate(Arity, yes, ArgInfos).

 :- pred find_and_count_nonrec_args(list(constructor_arg)::in,
 	type_ctor::in, list(type_param)::in,
@@ -230,13 +232,13 @@
 	type_to_ctor_and_args(ArgType, ArgTypeCtor, ArgTypeArgs),
 	TypeCtor = ArgTypeCtor,
 	prog_type.type_list_to_var_list(ArgTypeArgs, ArgTypeParams),
-	list__perm(Params, ArgTypeParams).
+    list.perm(Params, ArgTypeParams).

 :- pred search_weight_table(weight_table::in, type_ctor::in, cons_id::in,
 	weight_info::out) is semidet.

 search_weight_table(WeightMap, TypeCtor, ConsId, WeightInfo) :-
-	( map__search(WeightMap, TypeCtor - ConsId, WeightInfo0) ->
+    ( map.search(WeightMap, TypeCtor - ConsId, WeightInfo0) ->
 		WeightInfo = WeightInfo0
 	; type_ctor_is_tuple(TypeCtor) ->
 		TypeCtor = _ - Arity,
@@ -247,12 +249,12 @@

 %-----------------------------------------------------------------------------%

-set_functor_info(total, _Module) = total.
-set_functor_info(simple, _Module) = simple.
-set_functor_info(num_data_elems, Module) = use_map_and_args(WeightMap) :-
-	find_weights(Module, WeightMap).
-set_functor_info(size_data_elems, Module) = use_map(WeightMap) :-
-	find_weights(Module, WeightMap).
+set_functor_info(total, _ModuleInfo) = total.
+set_functor_info(simple, _ModuleInfo) = simple.
+set_functor_info(num_data_elems, ModuleInfo) = use_map_and_args(WeightMap) :-
+    find_weights(ModuleInfo, WeightMap).
+set_functor_info(size_data_elems, ModuleInfo) = use_map(WeightMap) :-
+    find_weights(ModuleInfo, WeightMap).

 %-----------------------------------------------------------------------------%

@@ -289,15 +291,15 @@
 		->
 			true
 		;
-			unexpected(this_file, "Unmatched lists in " ++
-				"functor_norm_filter_args.")
+            unexpected(this_file,
+                "Unmatched lists in functor_norm_filter_args.")
 		)
 	;
 		Int = 0
 	).

-	% This predicate will fail if the length of the input lists are
-	% not matched.
+    % This predicate will fail if the length of the input lists are not
+    % matched.
 	%
 :- pred functor_norm_filter_args(list(bool)::in, list(prog_var)::in,
 	list(prog_var)::out, list(uni_mode)::in, list(uni_mode)::out)
Index: term_pass1.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/term_pass1.m,v
retrieving revision 1.23
diff -u -b -r1.23 term_pass1.m
--- term_pass1.m	28 Oct 2005 02:10:39 -0000	1.23
+++ term_pass1.m	28 Oct 2005 07:52:46 -0000
@@ -1,4 +1,6 @@
 %-----------------------------------------------------------------------------%
+% vim: ft=mercury ts=4 sw=4 et
+%-----------------------------------------------------------------------------%
 % Copyright (C) 1997-1998, 2003-2005 The University of Melbourne.
 % This file may only be copied under the terms of the GNU General
 % Public License - see the file COPYING in the Mercury distribution.
@@ -9,18 +11,17 @@
 % Main author: crs.
 % Significant parts rewritten by zs.
 %
-% This file contains the first pass of the termination analysis,
-% whose job is to discover an upper bound on the difference between
-% the sizes of the output arguments of a procedure on the one hand and
-% the sizes of a selected set of input arguments of the procedure
-% on the other hand. We refer to this selected set of input arguments
-% as the "output suppliers".
+% This file contains the first pass of the termination analysis, whose job is
+% to discover an upper bound on the difference between the sizes of the output
+% arguments of a procedure on the one hand and the sizes of a selected set of
+% input arguments of the procedure on the other hand. We refer to this
+% selected set of input arguments as the "output suppliers".
 %
 % For details, please refer to the papers mentioned in termination.m.
 %
 %-----------------------------------------------------------------------------%

-:- module transform_hlds__term_pass1.
+:- module transform_hlds.term_pass1.

 :- interface.

@@ -33,6 +34,8 @@
 :- import_module list.
 :- import_module std_util.

+%-----------------------------------------------------------------------------%
+
 :- type arg_size_result
 	--->	ok(
 			list(pair(pred_proc_id, int)),
@@ -47,8 +50,8 @@
 		).

 :- pred find_arg_sizes_in_scc(list(pred_proc_id)::in, module_info::in,
-	pass_info::in, arg_size_result::out,
-	list(termination_error_context)::out, io::di, io::uo) is det.
+    pass_info::in, arg_size_result::out, list(termination_error_context)::out,
+    io::di, io::uo) is det.

 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
@@ -73,6 +76,9 @@
 :- import_module require.
 :- import_module set.
 :- import_module string.
+:- import_module svmap.
+:- import_module svset.
+:- import_module svvarset.
 :- import_module term.
 :- import_module varset.

@@ -95,29 +101,34 @@
 			list(termination_error_context)
 		).

-find_arg_sizes_in_scc(SCC, Module, PassInfo, ArgSize, TermErrors, !IO) :-
-	init_output_suppliers(SCC, Module, InitOutputSupplierMap),
-	find_arg_sizes_in_scc_fixpoint(SCC, Module, PassInfo,
+find_arg_sizes_in_scc(SCC, ModuleInfo, PassInfo, ArgSize, TermErrors, !IO) :-
+    init_output_suppliers(SCC, ModuleInfo, InitOutputSupplierMap),
+    find_arg_sizes_in_scc_fixpoint(SCC, ModuleInfo, PassInfo,
 		InitOutputSupplierMap, Result, TermErrors),
 	(
 		Result = ok(Paths, OutputSupplierMap, SubsetErrors),
-
-		( SubsetErrors = [_ | _] ->
+        (
+            SubsetErrors = [_|_],
 			ArgSize = error(SubsetErrors)
-		; Paths = [] ->
-			get_context_from_scc(SCC, Module, Context),
+        ;
+            SubsetErrors = [],
+            (
+                Paths = [],
+                get_context_from_scc(SCC, ModuleInfo, Context),
 			ArgSize = error([Context - no_eqns])
 		;
+                Paths = [_|_],
 			solve_equations(Paths, SCC, MaybeSolution, !IO),
 			(
 				MaybeSolution = yes(Solution),
 				ArgSize = ok(Solution, OutputSupplierMap)
 			;
 				MaybeSolution = no,
-				get_context_from_scc(SCC, Module, Context),
+                    get_context_from_scc(SCC, ModuleInfo, Context),
 				ArgSize = error([Context - solver_failed])
 			)
 		)
+        )
 	;
 		Result = error(Errors),
 		ArgSize = error(Errors)
@@ -125,22 +136,22 @@

 %-----------------------------------------------------------------------------%

-% Initialise the output suppliers map.
-% Initially, we consider that no input arguments contribute their size
-% to the output arguments.
-
+    % Initialise the output suppliers map.
+    % Initially, we consider that no input arguments contribute their size
+    % to the output arguments.
+    %
 :- pred init_output_suppliers(list(pred_proc_id)::in, module_info::in,
 	used_args::out) is det.

-init_output_suppliers([], _Module, InitMap) :-
-	map__init(InitMap).
-init_output_suppliers([PPId | PPIds], Module, OutputSupplierMap) :-
-	init_output_suppliers(PPIds, Module, OutputSupplierMap0),
-	module_info_pred_proc_info(Module, PPId, _, ProcInfo),
+init_output_suppliers([], _, InitMap) :-
+    map.init(InitMap).
+init_output_suppliers([PPId | PPIds], ModuleInfo, OutputSupplierMap) :-
+    init_output_suppliers(PPIds, ModuleInfo, OutputSupplierMap0),
+    module_info_pred_proc_info(ModuleInfo, PPId, _, ProcInfo),
 	proc_info_headvars(ProcInfo, HeadVars),
 	MapToNo = (pred(_HeadVar::in, Bool::out) is det :- Bool = no),
-	list__map(MapToNo, HeadVars, BoolList),
-	map__det_insert(OutputSupplierMap0, PPId, BoolList, OutputSupplierMap).
+    list.map(MapToNo, HeadVars, BoolList),
+    map.det_insert(OutputSupplierMap0, PPId, BoolList, OutputSupplierMap).

 %-----------------------------------------------------------------------------%

@@ -148,12 +159,9 @@
 	module_info::in, pass_info::in, used_args::in, pass1_result::out,
 	list(termination_error_context)::out) is det.

-find_arg_sizes_in_scc_fixpoint(SCC, Module, PassInfo, OutputSupplierMap0,
+find_arg_sizes_in_scc_fixpoint(SCC, ModuleInfo, PassInfo, OutputSupplierMap0,
 		Result, TermErrors) :-
-	% unsafe_perform_io(io__write_string("find_arg_sizes_in_scc_pass\n")),
-	% unsafe_perform_io(io__write(OutputSupplierMap0)),
-	% unsafe_perform_io(io__write_string("\n")),
-	find_arg_sizes_in_scc_pass(SCC, Module, PassInfo,
+    find_arg_sizes_in_scc_pass(SCC, ModuleInfo, PassInfo,
 		OutputSupplierMap0, [], [], Result1, [], TermErrors1),
 	(
 		Result1 = error(_),
@@ -165,9 +173,8 @@
 			Result = Result1,
 			TermErrors = TermErrors1
 		;
-			find_arg_sizes_in_scc_fixpoint(SCC, Module,
-				PassInfo, OutputSupplierMap1,
-				Result, TermErrors)
+            find_arg_sizes_in_scc_fixpoint(SCC, ModuleInfo, PassInfo,
+                OutputSupplierMap1, Result, TermErrors)
 		)
 	).

@@ -180,31 +187,30 @@
 find_arg_sizes_in_scc_pass([], _, _, OutputSupplierMap, Paths, SubsetErrors,
 		Result, !TermErrors) :-
 	Result = ok(Paths, OutputSupplierMap, SubsetErrors).
-find_arg_sizes_in_scc_pass([PPId | PPIds], Module, PassInfo,
+find_arg_sizes_in_scc_pass([PPId | PPIds], ModuleInfo, PassInfo,
 		OutputSupplierMap0, Paths0, SubsetErrors0, Result,
 		!TermErrors) :-
-	find_arg_sizes_pred(PPId, Module, PassInfo, OutputSupplierMap0,
+    find_arg_sizes_pred(PPId, ModuleInfo, PassInfo, OutputSupplierMap0,
 		Result1, ProcTermErrors),
-	list__append(!.TermErrors, ProcTermErrors, !:TermErrors),
+    !:TermErrors = !.TermErrors ++ ProcTermErrors,
 	PassInfo = pass_info(_, MaxErrors, _),
-	list__take_upto(MaxErrors, !TermErrors),
+    list.take_upto(MaxErrors, !TermErrors),
 	(
 		Result1 = error(_),
 		Result  = Result1,
-			% The error does not necessarily mean that this
-			% SCC is nonterminating.  We need to check that
-			% the remainder of this SCC does not make any
-			% nonterminating calls otherwise we might get
-			% a software error during pass 2.
+        % The error does not necessarily mean that this SCC is nonterminating.
+        % We need to check that the remainder of this SCC does not make any
+        % nonterminating calls otherwise we might get a software error during
+        % pass 2.
 			% (See below for details).
-		list__foldl(check_proc_non_term_calls(Module), PPIds, [],
+        list.foldl(check_proc_non_term_calls(ModuleInfo), PPIds, [],
 			OtherTermErrors),
-		list__append(OtherTermErrors, !TermErrors)
+        list.append(OtherTermErrors, !TermErrors)
 	;
 		Result1 = ok(Paths1, OutputSupplierMap1, SubsetErrors1),
-		list__append(Paths0, Paths1, Paths),
-		list__append(SubsetErrors0, SubsetErrors1, SubsetErrors),
-		find_arg_sizes_in_scc_pass(PPIds, Module, PassInfo,
+        Paths = Paths0 ++ Paths1,
+        SubsetErrors = SubsetErrors0 ++ SubsetErrors1,
+        find_arg_sizes_in_scc_pass(PPIds, ModuleInfo, PassInfo,
 			OutputSupplierMap1, Paths, SubsetErrors, Result,
 			!TermErrors)
 	).
@@ -215,36 +221,36 @@
 	pass_info::in, used_args::in, pass1_result::out,
 	list(termination_error_context)::out) is det.

-find_arg_sizes_pred(PPId, Module, PassInfo, OutputSupplierMap0, Result,
+find_arg_sizes_pred(PPId, ModuleInfo, PassInfo, OutputSupplierMap0, Result,
 		TermErrors) :-
-	module_info_pred_proc_info(Module, PPId, PredInfo, ProcInfo),
+    module_info_pred_proc_info(ModuleInfo, PPId, PredInfo, ProcInfo),
 	pred_info_context(PredInfo, Context),
 	proc_info_headvars(ProcInfo, Args),
 	proc_info_argmodes(ProcInfo, ArgModes),
 	proc_info_vartypes(ProcInfo, VarTypes),
 	proc_info_goal(ProcInfo, Goal),
-	map__init(EmptyMap),
+    map.init(EmptyMap),
 	PassInfo = pass_info(FunctorInfo, MaxErrors, MaxPaths),
-	init_traversal_params(Module, FunctorInfo, PPId, Context, VarTypes,
+    init_traversal_params(ModuleInfo, FunctorInfo, PPId, Context, VarTypes,
 		OutputSupplierMap0, EmptyMap, MaxErrors, MaxPaths, Params),

-	partition_call_args(Module, ArgModes, Args, InVars, OutVars),
+    partition_call_args(ModuleInfo, ArgModes, Args, InVars, OutVars),
 	Path0 = path_info(PPId, no, 0, [], OutVars),
-	set__singleton_set(PathSet0, Path0),
+    set.singleton_set(PathSet0, Path0),
 	Info0 = ok(PathSet0, []),
 	traverse_goal(Goal, Params, Info0, Info),

 	(
 		Info = ok(Paths, TermErrors),
-		set__to_sorted_list(Paths, PathList),
+        set.to_sorted_list(Paths, PathList),
 		upper_bound_active_vars(PathList, AllActiveVars),
-		map__lookup(OutputSupplierMap0, PPId,
+        map.lookup(OutputSupplierMap0, PPId,
 			OutputSuppliers0),
 		update_output_suppliers(Args, AllActiveVars,
 			OutputSuppliers0, OutputSuppliers),
-		map__det_update(OutputSupplierMap0, PPId,
+        map.det_update(OutputSupplierMap0, PPId,
 			OutputSuppliers, OutputSupplierMap),
-		( bag__is_subbag(AllActiveVars, InVars) ->
+        ( bag.is_subbag(AllActiveVars, InVars) ->
 			SubsetErrors = []
 		;
 			SubsetErrors = [Context -
@@ -269,7 +275,7 @@
 update_output_suppliers([Arg | Args], ActiveVars,
 		[OutputSupplier0 | OutputSuppliers0],
 		[OutputSupplier | OutputSuppliers]) :-
-	( bag__contains(ActiveVars, Arg) ->
+    ( bag.contains(ActiveVars, Arg) ->
 		OutputSupplier = yes
 	;
 		% This guarantees that the set of output suppliers can only
@@ -282,96 +288,95 @@

 %-----------------------------------------------------------------------------%
 %
-% Check if a procedure makes any nonterminating calls.
+% Check if a procedure makes any nonterminating calls
 %

 % We only use this if we have detected an error at some point during the
-% argument size analysis.  The idea is to quickly analyse a procedure and
-% see if it does anything that would prevent us from running pass 2.
-% We cannot run pass 2 if the procedure contains any calls to nonterminating
-% procedures lower down the call-graph (see term_pass2.m for details).
+% argument size analysis.  The idea is to quickly analyse a procedure and see
+% if it does anything that would prevent us from running pass 2.  We cannot
+% run pass 2 if the procedure contains any calls to nonterminating procedures
+% lower down the call-graph (see term_pass2.m for details).

 :- pred check_proc_non_term_calls(module_info::in, pred_proc_id::in,
 	list(termination_error_context)::in,
 	list(termination_error_context)::out) is det.

-check_proc_non_term_calls(Module, PPId, !Errors) :-
-	module_info_pred_proc_info(Module, PPId, _, ProcInfo),
+check_proc_non_term_calls(ModuleInfo, PPId, !Errors) :-
+    module_info_pred_proc_info(ModuleInfo, PPId, _, ProcInfo),
 	proc_info_goal(ProcInfo, Goal),
 	proc_info_vartypes(ProcInfo, VarTypes),
-	check_goal_non_term_calls(Module, PPId, VarTypes, Goal, !Errors).
+    check_goal_non_term_calls(ModuleInfo, PPId, VarTypes, Goal, !Errors).

-:- pred check_goal_non_term_calls(module_info::in,
-	pred_proc_id::in, vartypes::in, hlds_goal::in,
-	list(termination_error_context)::in,
-	list(termination_error_context)::out) is det.
-
-check_goal_non_term_calls(Module, PPId, VarTypes, GoalExpr - GoalInfo,
-		!Errors) :-
-	check_goal_expr_non_term_calls(Module, PPId, VarTypes, GoalExpr,
-		GoalInfo, !Errors).
+:- pred check_goal_non_term_calls(module_info::in, pred_proc_id::in,
+    vartypes::in, hlds_goal::in,
+    list(termination_error_context)::in, list(termination_error_context)::out)
+    is det.
+
+check_goal_non_term_calls(ModuleInfo, PPId, VarTypes, Goal, !Errors) :-
+    Goal = GoalExpr - GoalInfo,
+    check_goal_expr_non_term_calls(ModuleInfo, PPId, VarTypes, GoalExpr, GoalInfo,
+        !Errors).

 :- pred check_goal_expr_non_term_calls(module_info::in, pred_proc_id::in,
 	vartypes::in, hlds_goal_expr::in, hlds_goal_info::in,
-	list(termination_error_context)::in,
-	list(termination_error_context)::out) is det.
+    list(termination_error_context)::in, list(termination_error_context)::out)
+    is det.

-check_goal_expr_non_term_calls(Module, PPId, VarTypes, conj(Goals), _,
-		!Errors):-
-	list__foldl(check_goal_non_term_calls(Module, PPId, VarTypes), Goals,
+check_goal_expr_non_term_calls(ModuleInfo, PPId, VarTypes, Goal, _, !Errors):-
+    (
+        Goal = conj(Goals)
+    ;
+        Goal = par_conj(Goals)
+    ;
+        Goal = disj(Goals)
+    ),
+    list.foldl(check_goal_non_term_calls(ModuleInfo, PPId, VarTypes), Goals,
 		!Errors).
-check_goal_expr_non_term_calls(Module, PPId, VarTypes,
-		call(CallPredId, CallProcId, Args, _, _, _), GoalInfo,
+check_goal_expr_non_term_calls(ModuleInfo, PPId, VarTypes, Goal, GoalInfo,
 		!Errors) :-
+    Goal = call(CallPredId, CallProcId, Args, _, _, _),
 	CallPPId = proc(CallPredId, CallProcId),
-	module_info_pred_proc_info(Module, CallPPId, _, ProcInfo),
+    module_info_pred_proc_info(ModuleInfo, CallPPId, _, ProcInfo),
 	proc_info_get_maybe_termination_info(ProcInfo, TerminationInfo),
 	goal_info_get_context(GoalInfo, Context),
 	(
-		TerminationInfo = yes(can_loop(_))
-	->
+        TerminationInfo = yes(can_loop(_)),
 		TermError = Context - can_loop_proc_called(PPId, CallPPId),
-		!:Errors = [ TermError | !.Errors ]
+        list.cons(TermError, !Errors)
 	;
-		true
+        ( TerminationInfo = yes(cannot_loop(_))
+        ; TerminationInfo = no)
 	),
 	(
 		horder_vars(Args, VarTypes)
 	->
 		HigherOrderError = Context - horder_args(PPId, CallPPId),
-		!:Errors = [ HigherOrderError | !.Errors ]
+        list.cons(HigherOrderError, !Errors)
 	;
 		true
 	).
-check_goal_expr_non_term_calls(_, _, _, generic_call(_,_,_,_), GoalInfo,
-		!Errors) :-
+check_goal_expr_non_term_calls(_, _, _, Goal, GoalInfo, !Errors) :-
+    Goal = generic_call(_, _, _, _),
 	goal_info_get_context(GoalInfo, Context),
-	!:Errors = [ Context - horder_call | !.Errors ].
-check_goal_expr_non_term_calls(Module, PPId, VarTypes, switch(_, _, Cases), _,
-		!Errors) :-
-	list__foldl(check_cases_non_term_calls(Module, PPId, VarTypes), Cases,
-		!Errors).
-check_goal_expr_non_term_calls(_, _, _, unify(_,_,_,_,_), _, !Errors).
-check_goal_expr_non_term_calls(Module, PPId, VarTypes, disj(Goals), _,
-		!Errors) :-
-	list__foldl(check_goal_non_term_calls(Module, PPId, VarTypes), Goals,
+    list.cons(Context - horder_call, !Errors).
+check_goal_expr_non_term_calls(ModuleInfo, PPId, VarTypes, Goal, _, !Errors) :-
+    Goal = switch(_, _, Cases),
+    list.foldl(check_cases_non_term_calls(ModuleInfo, PPId, VarTypes), Cases,
 		!Errors).
-check_goal_expr_non_term_calls(Module, PPId, VarTypes, not(Goal), _,
-		!Errors) :-
-	check_goal_non_term_calls(Module, PPId, VarTypes, Goal, !Errors).
-check_goal_expr_non_term_calls(Module, PPId, VarTypes, scope(_, Goal), _,
+check_goal_expr_non_term_calls(_, _, _, unify(_, _, _, _, _), _, !Errors).
+check_goal_expr_non_term_calls(ModuleInfo, PPId, VarTypes, not(Goal), _,
 		!Errors) :-
-	check_goal_non_term_calls(Module, PPId, VarTypes, Goal, !Errors).
-check_goal_expr_non_term_calls(Module, PPId, VarTypes,
-		if_then_else(_, Cond, Then, Else), _, !Errors) :-
-	list__foldl(check_goal_non_term_calls(Module, PPId, VarTypes),
-		[Cond, Then, Else], !Errors).
-check_goal_expr_non_term_calls(_, _, _, foreign_proc(_, _, _, _, _, _),
-		_, !Errors).
-check_goal_expr_non_term_calls(Module, PPId, VarTypes, par_conj(Goals), _,
-		!Errors) :-
-	list__foldl(check_goal_non_term_calls(Module, PPId, VarTypes), Goals,
+    check_goal_non_term_calls(ModuleInfo, PPId, VarTypes, Goal, !Errors).
+check_goal_expr_non_term_calls(ModuleInfo, PPId, VarTypes, Goal, _, !Errors) :-
+    Goal = scope(_, ScopeGoal),
+    check_goal_non_term_calls(ModuleInfo, PPId, VarTypes, ScopeGoal, !Errors).
+check_goal_expr_non_term_calls(ModuleInfo, PPId, VarTypes, Goal, _, !Errors) :-
+    Goal = if_then_else(_, Cond, Then, Else),
+    Goals = [ Cond, Then, Else ],
+    list.foldl(check_goal_non_term_calls(ModuleInfo, PPId, VarTypes), Goals,
 		!Errors).
+check_goal_expr_non_term_calls(_, _, _, Goal, _, !Errors) :-
+        Goal = foreign_proc(_, _, _, _, _, _).
 check_goal_expr_non_term_calls(_, _, _, shorthand(_), _, _, _) :-
 	unexpected(this_file,
 		"shorthand goal encountered during termination analysis.").
@@ -381,83 +386,59 @@
 	list(termination_error_context)::in,
 	list(termination_error_context)::out) is det.

-check_cases_non_term_calls(Module, PPId, VarTypes, case(_, Goal), !Errors) :-
-	check_goal_non_term_calls(Module, PPId, VarTypes, Goal, !Errors).
+check_cases_non_term_calls(ModuleInfo, PPId, VarTypes, case(_, Goal), !Errors) :-
+    check_goal_non_term_calls(ModuleInfo, PPId, VarTypes, Goal, !Errors).

 %-----------------------------------------------------------------------------%
-%-----------------------------------------------------------------------------%
-
+%
 % Solve the list of constraints
-
-% output is of the form required by lp_solve.
-% which is given the input = [eqn(Const, PPid, [PPidList])]
-% max: .......
-% c1: PPid - (PPidList) > Const;
-% c2: PPid - (PPidList) > Const;
-% where PPid (proc(PredId, ProcId)) is printed as ' aPredId_ProcId - b '
-% The choice of the letter `a' is arbitrary, and is chosen as lp_solve does
-% not allow variables to start with digits.
-% The variable `b' is used as lp_solve will only solve for positive values
-% of variables.  replacing each variable occurance with ` a#_# - b ', this
-% avoids the problem of only allowing positive variables as  a#_# - b can
-% be negative even when a#_# and b are both positive.
+%

 :- pred solve_equations(list(path_info)::in, list(pred_proc_id)::in,
 	maybe(list(pair(pred_proc_id, int)))::out, io::di, io::uo) is det.

 solve_equations(Paths, PPIds, Result, !IO) :-
 	(
-		convert_equations(Paths, Varset, Equations,
-			Objective, PPVars)
+        convert_equations(Paths, Varset, Equations, Objective, PPVars)
 	->
-		map__values(PPVars, AllVars0),
-		list__sort_and_remove_dups(AllVars0, AllVars),
-		% unsafe_perform_io(io__write_string("before\n")),
-		% unsafe_perform_io(io__write(Equations)),
-		% unsafe_perform_io(io__write_string("\n")),
-		% unsafe_perform_io(io__write(Objective)),
-		% unsafe_perform_io(io__write_string("\n")),
-		% unsafe_perform_io(io__write(AllVars)),
-		% unsafe_perform_io(io__write_string("\n")),
-		lp_solve(Equations, min, Objective, Varset, AllVars, Soln,
-			!IO),
-		% unsafe_perform_io(io__write_string("after\n")),
+        map.values(PPVars, AllVars0),
+        list.sort_and_remove_dups(AllVars0, AllVars),
+        lp_solve(Equations, min, Objective, Varset, AllVars, Soln, !IO),
 		(
 			Soln = unsatisfiable,
 			Result = no
 		;
 			Soln = satisfiable(_ObjVal, SolnVal),
-			list__map(lookup_coeff(PPVars, SolnVal), PPIds,
-				SolutionList),
+            list.map(lookup_coeff(PPVars, SolnVal), PPIds, SolutionList),
 			Result = yes(SolutionList)
 		)
 	;
 		Result = no
 	).

-:- pred convert_equations(list(path_info)::in, varset::out, lp__equations::out,
+:- pred convert_equations(list(path_info)::in, varset::out, lp.equations::out,
 	objective::out, map(pred_proc_id, var)::out) is semidet.

 convert_equations(Paths, Varset, Equations, Objective, PPVars) :-
-	varset__init(Varset0),
-	map__init(PPVars0),
-	set__init(EqnSet0),
+    varset.init(Varset0),
+    map.init(PPVars0),
+    set.init(EqnSet0),
 	convert_equations_2(Paths, PPVars0, PPVars, Varset0, Varset,
 		EqnSet0, EqnSet),
-	set__to_sorted_list(EqnSet, Equations),
-	map__values(PPVars, Vars),
+    set.to_sorted_list(EqnSet, Equations),
+    map.values(PPVars, Vars),
 	Convert = (pred(Var::in, Coeff::out) is det :- Coeff = Var - 1.0),
-	list__map(Convert, Vars, Objective).
+    list.map(Convert, Vars, Objective).

 :- pred convert_equations_2(list(path_info)::in,
 	map(pred_proc_id, var)::in, map(pred_proc_id, var)::out,
 	varset::in, varset::out,
-	set(lp__equation)::in, set(lp__equation)::out) is semidet.
+    set(lp.equation)::in, set(lp.equation)::out) is semidet.

 convert_equations_2([], !PPVars, !Varset, !Eqns).
 convert_equations_2([Path | Paths], !PPVars, !Varset, !Eqns) :-
 	Path = path_info(ThisPPId, _, IntGamma, PPIds, _),
-	FloatGamma = float__float(IntGamma),
+    FloatGamma = float(IntGamma),
 	Eqn = eqn(Coeffs, (>=), FloatGamma),
 	pred_proc_var(ThisPPId, ThisVar, !Varset, !PPVars),
 	Coeffs = [ThisVar - 1.0 | RestCoeffs],
@@ -466,27 +447,27 @@
 		pred_proc_var(PPId, Var, !VS, !PPV),
 		Coeff = Var - (-1.0)
 	),
-	list__map_foldl2(Convert, PPIds, RestCoeffs, !Varset, !PPVars),
-	set__insert(!.Eqns, Eqn, !:Eqns),
+    list.map_foldl2(Convert, PPIds, RestCoeffs, !Varset, !PPVars),
+    svset.insert(Eqn, !Eqns),
 	convert_equations_2(Paths, !PPVars, !Varset, !Eqns).

 :- pred lookup_coeff(map(pred_proc_id, var)::in, map(var, float)::in,
 	pred_proc_id::in, pair(pred_proc_id, int)::out) is det.

 lookup_coeff(PPIds, Soln, PPId, PPId - ICoeff) :-
-	map__lookup(PPIds, PPId, Var),
-	map__lookup(Soln, Var, Coeff),
-	ICoeff = float__ceiling_to_int(Coeff).
+    map.lookup(PPIds, PPId, Var),
+    map.lookup(Soln, Var, Coeff),
+    ICoeff = float.ceiling_to_int(Coeff).

 :- pred pred_proc_var(pred_proc_id::in, var::out, varset::in, varset::out,
 	map(pred_proc_id, var)::in, map(pred_proc_id, var)::out) is det.

 pred_proc_var(PPId, Var, !Varset, !PPVars) :-
-	( map__search(!.PPVars, PPId, Var0) ->
+    ( map.search(!.PPVars, PPId, Var0) ->
 		Var = Var0
 	;
-		varset__new_var(!.Varset, Var, !:Varset),
-		map__det_insert(!.PPVars, PPId, Var, !:PPVars)
+        svvarset.new_var(Var, !Varset),
+        svmap.det_insert(PPId, Var, !PPVars)
 	).

 %-----------------------------------------------------------------------------%
Index: term_pass2.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/term_pass2.m,v
retrieving revision 1.21
diff -u -b -r1.21 term_pass2.m
--- term_pass2.m	28 Oct 2005 02:10:39 -0000	1.21
+++ term_pass2.m	28 Oct 2005 07:50:13 -0000
@@ -1,4 +1,6 @@
 %-----------------------------------------------------------------------------%
+% vim: ft=mercury ts=4 sw=4 et
+%-----------------------------------------------------------------------------%
 % Copyright (C) 1997-1998, 2003-2005 The University of Melbourne.
 % This file may only be copied under the terms of the GNU General
 % Public License - see the file COPYING in the Mercury distribution.
@@ -14,7 +16,7 @@
 % For details, please refer to the papers mentioned in termination.m.
 %-----------------------------------------------------------------------------%

-:- module transform_hlds__term_pass2.
+:- module transform_hlds.term_pass2.

 :- interface.

@@ -24,9 +26,10 @@

 :- import_module list.

-	% NOTE: This code assumes that the SCC does not call any
-	% nonterminating procedures.  If it does then that fact
-	% should have been detected during pass 1.
+    % NOTE: This code assumes that the SCC does not call any nonterminating
+    % procedures.  If it does then that fact should have been detected
+    % during pass 1.
+    %
 :- pred prove_termination_in_scc(list(pred_proc_id)::in, module_info::in,
 	pass_info::in, int::in, termination_info::out) is det.

@@ -54,6 +57,8 @@
 :- import_module string.
 :- import_module term.

+%-----------------------------------------------------------------------------%
+
 :- type fixpoint_dir
 	--->	up
 	;	down.
@@ -61,7 +66,6 @@
 :- type call_weight_info
 	==	pair(list(termination_error_context), call_weight_graph).

-
 :- type call_weight_graph
 	==	map(pred_proc_id,		% The max noninfinite weight
 						% call from this proc
@@ -75,33 +79,33 @@
 			call_weight_info,
 			used_args
 		)
+
 	;	error(
 			list(termination_error_context)
 		).

-%-----------------------------------------------------------------------------%
+%------------------------------------------------------------------------------%

-prove_termination_in_scc(SCC, Module, PassInfo, SingleArgs, Termination) :-
-	init_rec_input_suppliers(SCC, Module, InitRecSuppliers),
-	prove_termination_in_scc_trial(SCC, InitRecSuppliers, down,
-		Module, PassInfo, Termination1),
+prove_termination_in_scc(SCC, ModuleInfo, PassInfo, SingleArgs, Termination) :-
+    init_rec_input_suppliers(SCC, ModuleInfo, InitRecSuppliers),
+    prove_termination_in_scc_trial(SCC, InitRecSuppliers, down, ModuleInfo,
+        PassInfo, Termination1),
 	(
 		Termination1 = can_loop(Errors),
 		(
-			% On large SCCs, single arg analysis can require
-			% many iterations, so we allow the user to limit
-			% the size of the SCCs we will try it on.
-			list__length(SCC, ProcCount),
+            % On large SCCs, single arg analysis can require many iterations,
+            % so we allow the user to limit the size of the SCCs we will try it
+            % on.
+            list.length(SCC, ProcCount),
 			ProcCount =< SingleArgs,

-			% Don't try single arg analysis if it cannot cure
-			% the reason for the failure of the main analysis.
+            % Don't try single arg analysis if it cannot cure the reason for
+            % the failure of the main analysis.
 			\+ (
-				list__member(Error, Errors),
+                list.member(Error, Errors),
 				Error = _ - imported_pred
 			),
-			prove_termination_in_scc_single_arg(SCC,
-				Module, PassInfo)
+            prove_termination_in_scc_single_arg(SCC, ModuleInfo, PassInfo)
 		->
 			Termination = cannot_loop(unit)
 		;
@@ -112,102 +116,103 @@
 		Termination = Termination1
 	).

-	% Initialise the set of recursive input suppliers to be the set
-	% of all input variables in all procedures of the SCC.
-
+    % Initialise the set of recursive input suppliers to be the set of all
+    % input variables in all procedures of the SCC.
+    %
 :- pred init_rec_input_suppliers(list(pred_proc_id)::in, module_info::in,
 	used_args::out) is det.

 init_rec_input_suppliers([], _, InitMap) :-
-	map__init(InitMap).
-init_rec_input_suppliers([PPId | PPIds], Module, RecSupplierMap) :-
-	init_rec_input_suppliers(PPIds, Module, RecSupplierMap0),
-	module_info_pred_proc_info(Module, PPId, _, ProcInfo),
+    map.init(InitMap).
+init_rec_input_suppliers([PPId | PPIds], ModuleInfo, RecSupplierMap) :-
+    init_rec_input_suppliers(PPIds, ModuleInfo, RecSupplierMap0),
+    module_info_pred_proc_info(ModuleInfo, PPId, _, ProcInfo),
 	proc_info_headvars(ProcInfo, HeadVars),
 	proc_info_argmodes(ProcInfo, ArgModes),
-	partition_call_args(Module, ArgModes, HeadVars, InArgs, _OutVars),
+    partition_call_args(ModuleInfo, ArgModes, HeadVars, InArgs, _OutVars),
 	MapIsInput = (pred(HeadVar::in, Bool::out) is det :-
-		( bag__contains(InArgs, HeadVar) ->
+        ( bag.contains(InArgs, HeadVar) ->
 			Bool = yes
 		;
 			Bool = no
 		)
 	),
-	list__map(MapIsInput, HeadVars, BoolList),
-	map__det_insert(RecSupplierMap0, PPId, BoolList, RecSupplierMap).
+    list.map(MapIsInput, HeadVars, BoolList),
+    map.det_insert(RecSupplierMap0, PPId, BoolList, RecSupplierMap).

 %-----------------------------------------------------------------------------%

 	% Perform single arg analysis on the SCC.
 	%
-	% We pick one procedure in the SCC (one of those with minimal arity).
-	% We set the recursive input suppliers of this procedure to contain
-	% only the first input argument, and the recursive input suppliers
-	% of the other procedures to the empty set, and try a fixpoint
-	% iteration. If it works, great, if not, try again with the next
-	% input arg of the selected procedure, until we run out of input
-	% arguments of that procedure.
-	%
-	% While the fixpoint iteration in the main algorithm looks for the
-	% greatest fixpoint, in which the recursive input supplier sets
-	% cannot increase, in single arg analysis we are looking for a
-	% smallest fixpoint starting from a given location, so we must
-	% make sure that the recursive input supplier sets cannot decrease.
-
+    % We pick one procedure in the SCC (one of those with minimal arity).  We
+    % set the recursive input suppliers of this procedure to contain only the
+    % first input argument, and the recursive input suppliers of the other
+    % procedures to the empty set, and try a fixpoint iteration. If it works,
+    % great, if not, try again with the next input arg of the selected
+    % procedure, until we run out of input arguments of that procedure.
+    %
+    % While the fixpoint iteration in the main algorithm looks for the greatest
+    % fixpoint, in which the recursive input supplier sets cannot increase, in
+    % single arg analysis we are looking for a smallest fixpoint starting from
+    % a given location, so we must make sure that the recursive input supplier
+    % sets cannot decrease.
+    %
 :- pred prove_termination_in_scc_single_arg(list(pred_proc_id)::in,
 	module_info::in, pass_info::in) is semidet.

-prove_termination_in_scc_single_arg(SCC, Module, PassInfo) :-
-	( SCC = [FirstPPId | LaterPPIds] ->
-		lookup_proc_arity(FirstPPId, Module, FirstArity),
-		find_min_arity_proc(LaterPPIds, FirstPPId, FirstArity, Module,
+prove_termination_in_scc_single_arg(SCC, ModuleInfo, PassInfo) :-
+    (
+        SCC = [FirstPPId | LaterPPIds],
+        lookup_proc_arity(FirstPPId, ModuleInfo, FirstArity),
+        find_min_arity_proc(LaterPPIds, FirstPPId, FirstArity, ModuleInfo,
 			TrialPPId, RestSCC),
 		prove_termination_in_scc_single_arg_2(TrialPPId, RestSCC, 1,
-			Module, PassInfo)
+            ModuleInfo, PassInfo)
 	;
-
+        SCC = [],
 		unexpected(this_file,
 			"prove_termination_in_scc_single_arg/3: empty SCC.")
 	).

-	% Find a procedure of minimum arity among the given list and the
-	% tentative guess.
-
+    % Find a procedure of minimum arity among the given list and the tentative
+    % guess.
+    %
 :- pred find_min_arity_proc(list(pred_proc_id)::in, pred_proc_id::in, int::in,
 	module_info::in, pred_proc_id::out, list(pred_proc_id)::out) is det.

 find_min_arity_proc([], BestSofarPPId, _, _, BestSofarPPId, []).
-find_min_arity_proc([PPId | PPIds], BestSofarPPId, BestSofarArity, Module,
+find_min_arity_proc([PPId | PPIds], BestSofarPPId, BestSofarArity, ModuleInfo,
 		BestPPId, RestSCC) :-
-	lookup_proc_arity(PPId, Module, Arity),
+    lookup_proc_arity(PPId, ModuleInfo, Arity),
 	( Arity < BestSofarArity ->
-		find_min_arity_proc(PPIds, PPId, Arity,
-			Module, BestPPId, RestSCC0),
+        find_min_arity_proc(PPIds, PPId, Arity, ModuleInfo, BestPPId,
+            RestSCC0),
 		RestSCC = [BestSofarPPId | RestSCC0]
 	;
-		find_min_arity_proc(PPIds, BestSofarPPId, BestSofarArity,
-			Module, BestPPId, RestSCC0),
+        find_min_arity_proc(PPIds, BestSofarPPId, BestSofarArity, ModuleInfo,
+            BestPPId, RestSCC0),
 		RestSCC = [PPId | RestSCC0]
 	).

 	% Perform single arg analysis on the SCC.
-
+    %
 :- pred prove_termination_in_scc_single_arg_2(pred_proc_id::in,
 	list(pred_proc_id)::in, int::in, module_info::in, pass_info::in)
 	is semidet.

 prove_termination_in_scc_single_arg_2(TrialPPId, RestSCC, ArgNum0,
-		Module, PassInfo) :-
+        ModuleInfo, PassInfo) :-
 	init_rec_input_suppliers_single_arg(TrialPPId, RestSCC,
-		ArgNum0, Module, InitRecSuppliers),
+        ArgNum0, ModuleInfo, InitRecSuppliers),
 	prove_termination_in_scc_trial([TrialPPId | RestSCC], InitRecSuppliers,
-		up, Module, PassInfo, Termination),
-	( Termination = cannot_loop(unit) ->
-		true
+        up, ModuleInfo, PassInfo, Termination),
+    (
+        Termination = cannot_loop(unit)
 	;
+        Termination = can_loop(_),
 		ArgNum1 = ArgNum0 + 1,
 		prove_termination_in_scc_single_arg_2(TrialPPId, RestSCC,
-			ArgNum1, Module, PassInfo)
+            ArgNum1, ModuleInfo, PassInfo)
 	).

 :- pred init_rec_input_suppliers_single_arg(pred_proc_id::in,
@@ -220,8 +225,8 @@
 	proc_info_argmodes(ProcInfo, ArgModes),
 	init_rec_input_suppliers_add_single_arg(ArgModes, ArgNum,
 		Module, TrialPPIdRecSuppliers),
-	map__init(RecSupplierMap0),
-	map__det_insert(RecSupplierMap0, TrialPPId, TrialPPIdRecSuppliers,
+    map.init(RecSupplierMap0),
+    map.det_insert(RecSupplierMap0, TrialPPId, TrialPPIdRecSuppliers,
 		RecSupplierMap1),
 	init_rec_input_suppliers_single_arg_others(RestSCC, Module,
 		RecSupplierMap1, RecSupplierMap).
@@ -235,7 +240,7 @@
 		mode_is_input(Module, Mode),
 		ArgNum = 1
 	->
-		list__map(map_to_no, Modes, BoolList1),
+        list.map(map_to_no, Modes, BoolList1),
 		BoolList = [yes | BoolList1]
 	;
 		(
@@ -266,8 +271,8 @@
 		!RecSupplierMap) :-
 	module_info_pred_proc_info(Module, PPId, _, ProcInfo),
 	proc_info_headvars(ProcInfo, HeadVars),
-	list__map(map_to_no, HeadVars, BoolList),
-	map__det_insert(!.RecSupplierMap, PPId, BoolList, !:RecSupplierMap),
+    list.map(map_to_no, HeadVars, BoolList),
+    map.det_insert(!.RecSupplierMap, PPId, BoolList, !:RecSupplierMap),
 	init_rec_input_suppliers_single_arg_others(PPIds, Module,
 		!RecSupplierMap).

@@ -276,7 +281,7 @@
 lookup_proc_arity(PPId, Module, Arity) :-
 	module_info_pred_proc_info(Module, PPId, _, ProcInfo),
 	proc_info_headvars(ProcInfo, HeadVars),
-	list__length(HeadVars, Arity).
+    list.length(HeadVars, Arity).

 %-----------------------------------------------------------------------------%

@@ -284,9 +289,9 @@
 	fixpoint_dir::in, module_info::in, pass_info::in,
 	termination_info::out) is det.

-prove_termination_in_scc_trial(SCC, InitRecSuppliers, FixDir, Module,
+prove_termination_in_scc_trial(SCC, InitRecSuppliers, FixDir, ModuleInfo,
 		PassInfo, Termination) :-
-	prove_termination_in_scc_fixpoint(SCC, FixDir, Module, PassInfo,
+    prove_termination_in_scc_fixpoint(SCC, FixDir, ModuleInfo, PassInfo,
 		InitRecSuppliers, Result),
 	(
 		Result = ok(CallInfo, _),
@@ -295,15 +300,14 @@
 			InfCalls \= []
 		->
 			PassInfo = pass_info(_, MaxErrors, _),
-			list__take_upto(MaxErrors, InfCalls, ReportedInfCalls),
+            list.take_upto(MaxErrors, InfCalls, ReportedInfCalls),
 			Termination = can_loop(ReportedInfCalls)
 		;
-			zero_or_positive_weight_cycles(CallWeights, Module,
-				Cycles),
+            zero_or_positive_weight_cycles(CallWeights, ModuleInfo, Cycles),
 			Cycles \= []
 		->
 			PassInfo = pass_info(_, MaxErrors, _),
-			list__take_upto(MaxErrors, Cycles, ReportedCycles),
+            list.take_upto(MaxErrors, Cycles, ReportedCycles),
 			Termination = can_loop(ReportedCycles)
 		;
 			Termination = cannot_loop(unit)
@@ -319,15 +323,12 @@
 	fixpoint_dir::in, module_info::in, pass_info::in, used_args::in,
 	pass2_result::out) is det.

-prove_termination_in_scc_fixpoint(SCC, FixDir, Module, PassInfo,
+prove_termination_in_scc_fixpoint(SCC, FixDir, ModuleInfo, PassInfo,
 		RecSupplierMap0, Result) :-
-	% unsafe_perform_io(io__write_string("prove_termination_in_scc\n")),
-	% unsafe_perform_io(io__write(RecSupplierMap0)),
-	% unsafe_perform_io(io__write_string("\n")),
-	map__init(NewRecSupplierMap0),
-	map__init(CallWeightGraph0),
+    map.init(NewRecSupplierMap0),
+    map.init(CallWeightGraph0),
 	CallInfo0 = [] - CallWeightGraph0,
-	prove_termination_in_scc_pass(SCC, FixDir, Module, PassInfo,
+    prove_termination_in_scc_pass(SCC, FixDir, ModuleInfo, PassInfo,
 		RecSupplierMap0, NewRecSupplierMap0, CallInfo0, Result1),
 	(
 		Result1 = ok(_, RecSupplierMap1),
@@ -337,7 +338,7 @@
 			Result = Result1
 		;
 			prove_termination_in_scc_fixpoint(SCC, FixDir,
-				Module, PassInfo, RecSupplierMap1, Result)
+                ModuleInfo, PassInfo, RecSupplierMap1, Result)
 		)
 	;
 		Result1 = error(_),
@@ -348,46 +349,43 @@

 	% Process a whole SCC, to determine the termination property of each
 	% procedure in that SCC.
-
+    %
 :- pred prove_termination_in_scc_pass(list(pred_proc_id)::in, fixpoint_dir::in,
 	module_info::in, pass_info::in, used_args::in, used_args::in,
 	call_weight_info::in, pass2_result::out) is det.

 prove_termination_in_scc_pass([], _, _, _, _, NewRecSupplierMap, CallInfo,
 		ok(CallInfo, NewRecSupplierMap)).
-prove_termination_in_scc_pass([PPId | PPIds], FixDir, Module, PassInfo,
+prove_termination_in_scc_pass([PPId | PPIds], FixDir, ModuleInfo, PassInfo,
 		RecSupplierMap, NewRecSupplierMap0, CallInfo0, Result) :-
-	% Get the goal info.
-	module_info_pred_proc_info(Module, PPId, PredInfo, ProcInfo),
+    module_info_pred_proc_info(ModuleInfo, PPId, PredInfo, ProcInfo),
 	pred_info_context(PredInfo, Context),
 	proc_info_goal(ProcInfo, Goal),
 	proc_info_vartypes(ProcInfo, VarTypes),
-	map__init(EmptyMap),
+    map.init(EmptyMap),
 	PassInfo = pass_info(FunctorInfo, MaxErrors, MaxPaths),
-	init_traversal_params(Module, FunctorInfo, PPId, Context, VarTypes,
+    init_traversal_params(ModuleInfo, FunctorInfo, PPId, Context, VarTypes,
 		EmptyMap, RecSupplierMap, MaxErrors, MaxPaths, Params),
-	set__init(PathSet0),
+    set.init(PathSet0),
 	Info0 = ok(PathSet0, []),
 	traverse_goal(Goal, Params, Info0, Info),
 	(
 		Info = ok(Paths, CanLoop),
 		require(unify(CanLoop, []),
 			"can_loop detected in pass2 but not pass1"),
-		set__to_sorted_list(Paths, PathList),
+        set.to_sorted_list(Paths, PathList),
 		upper_bound_active_vars(PathList, ActiveVars),
-		map__lookup(RecSupplierMap, PPId, RecSuppliers0),
+        map.lookup(RecSupplierMap, PPId, RecSuppliers0),
 		proc_info_headvars(ProcInfo, Args),
-		bag__init(EmptyBag),
+        bag.init(EmptyBag),
 		update_rec_input_suppliers(Args, ActiveVars, FixDir,
 			RecSuppliers0, RecSuppliers,
 			EmptyBag, RecSuppliers0Bag),
-		map__det_insert(NewRecSupplierMap0, PPId, RecSuppliers,
+        map.det_insert(NewRecSupplierMap0, PPId, RecSuppliers,
 			NewRecSupplierMap1),
-		add_call_arcs(PathList, RecSuppliers0Bag,
-			CallInfo0, CallInfo1),
-		prove_termination_in_scc_pass(PPIds, FixDir, Module,
-			PassInfo, RecSupplierMap,
-			NewRecSupplierMap1, CallInfo1, Result)
+        add_call_arcs(PathList, RecSuppliers0Bag, CallInfo0, CallInfo1),
+        prove_termination_in_scc_pass(PPIds, FixDir, ModuleInfo,
+            PassInfo, RecSupplierMap, NewRecSupplierMap1, CallInfo1, Result)
 	;
 		Info = error(Errors, CanLoop),
 		require(unify(CanLoop, []),
@@ -413,7 +411,7 @@
 		[RecInputSupplier | RecInputSuppliers], !RecBag) :-
 	(
 		RecInputSupplier0 = yes,
-		bag__insert(!.RecBag, Arg, !:RecBag)
+        bag.insert(!.RecBag, Arg, !:RecBag)
 	;
 		RecInputSupplier0 = no
 	),
@@ -421,7 +419,7 @@
 		FixDir = down,
 		% This guarantees that the set of rec input suppliers
 		% can only decrease.
-		( bag__contains(ActiveVars, Arg) ->
+        ( bag.contains(ActiveVars, Arg) ->
 			RecInputSupplier = RecInputSupplier0
 		;
 			RecInputSupplier = no
@@ -430,7 +428,7 @@
 		FixDir = up,
 		% This guarantees that the set of rec input suppliers
 		% can only increase.
-		( bag__contains(ActiveVars, Arg) ->
+        ( bag.contains(ActiveVars, Arg) ->
 			RecInputSupplier = yes
 		;
 			RecInputSupplier = RecInputSupplier0
@@ -441,15 +439,15 @@

 %-----------------------------------------------------------------------------%

-% This adds the information from a stage 2 traversal to the graph.
-% The graph's nodes are the procedures in the current SCC.
-% The graph's edges represent calls from one procedure in the SCC to another.
-% The number attached to the edge from p to q shows the upper bound
-% on the difference between the size of the recursive input supplier arguments
-% in the call to q and the size of the recursive input supplier arguments
-% in the head of p. If there is no finite upper bound, then we insert the
-% details of the call into the list of "infinite" calls.
-
+    % This adds the information from a stage 2 traversal to the graph.  The
+    % graph's nodes are the procedures in the current SCC.  The graph's edges
+    % represent calls from one procedure in the SCC to another.  The number
+    % attached to the edge from p to q shows the upper bound on the difference
+    % between the size of the recursive input supplier arguments in the call to
+    % q and the size of the recursive input supplier arguments in the head of
+    % p. If there is no finite upper bound, then we insert the details of the
+    % call into the list of "infinite" calls.
+    %
 :- pred add_call_arcs(list(path_info)::in, bag(prog_var)::in,
 	call_weight_info::in, call_weight_info::out) is det.

@@ -470,28 +468,28 @@
 			"add_call_arc/4: gamma variables in path in stage 2.")
 	),
 	!.CallInfo = InfCalls0 - CallWeights0,
-	( bag__is_subbag(ActiveVars, RecInputSuppliers) ->
-		( map__search(CallWeights0, PPId, NeighbourMap0) ->
-			( map__search(NeighbourMap0, CallPPId, OldEdgeInfo) ->
+    ( bag.is_subbag(ActiveVars, RecInputSuppliers) ->
+        ( map.search(CallWeights0, PPId, NeighbourMap0) ->
+            ( map.search(NeighbourMap0, CallPPId, OldEdgeInfo) ->
 				OldEdgeInfo = _OldContext - OldWeight,
 				( OldWeight >= GammaConst ->
 					EdgeInfo = OldEdgeInfo
 				;
 					EdgeInfo = Context - GammaConst
 				),
-				map__det_update(NeighbourMap0, CallPPId,
+                map.det_update(NeighbourMap0, CallPPId,
 					EdgeInfo, NeighbourMap)
 			;
-				map__det_insert(NeighbourMap0, CallPPId,
+                map.det_insert(NeighbourMap0, CallPPId,
 					Context - GammaConst, NeighbourMap)
 			),
-			map__det_update(CallWeights0, PPId, NeighbourMap,
+            map.det_update(CallWeights0, PPId, NeighbourMap,
 				CallWeights1)
 		;
-			map__init(NeighbourMap0),
-			map__det_insert(NeighbourMap0, CallPPId,
+            map.init(NeighbourMap0),
+            map.det_insert(NeighbourMap0, CallPPId,
 				Context - GammaConst, NeighbourMap),
-			map__det_insert(CallWeights0, PPId, NeighbourMap,
+            map.det_insert(CallWeights0, PPId, NeighbourMap,
 				CallWeights1)
 		),
 		!:CallInfo = InfCalls0 - CallWeights1
@@ -503,22 +501,21 @@

 %-----------------------------------------------------------------------------%

-	% We use a simple depth first search to find and return the list
-	% of all cycles in the call graph of the SCC where the change in
-	% the size of the recursive input supplier arguments of the procedure
-	% that serves as the start and end point of the circularity are
-	% not guaranteed to decrease.
-	%
-	% Finding one such cycle is enough for us to conclude that we
-	% cannot prove termination of the procedures in the SCC; we collect
-	% all cycles because it may be useful to print them out (if not
-	% all, then maybe a limited set).
-
+    % We use a simple depth first search to find and return the list of all
+    % cycles in the call graph of the SCC where the change in the size of the
+    % recursive input supplier arguments of the procedure that serves as the
+    % start and end point of the circularity are not guaranteed to decrease.
+    %
+    % Finding one such cycle is enough for us to conclude that we cannot prove
+    % termination of the procedures in the SCC; we collect all cycles because
+    % it may be useful to print them out (if not all, then maybe a limited
+    % set).
+    %
 :- pred zero_or_positive_weight_cycles(call_weight_graph::in,
 	module_info::in, list(termination_error_context)::out) is det.

 zero_or_positive_weight_cycles(CallWeights, Module, Cycles) :-
-	map__keys(CallWeights, PPIds),
+    map.keys(CallWeights, PPIds),
 	zero_or_positive_weight_cycles_2(PPIds, CallWeights, Module, Cycles).

 :- pred zero_or_positive_weight_cycles_2(list(pred_proc_id)::in,
@@ -529,15 +526,15 @@
 zero_or_positive_weight_cycles_2([PPId | PPIds], CallWeights, Module, Cycles) :-
 	zero_or_positive_weight_cycles_from(PPId, CallWeights, Module, Cycles1),
 	zero_or_positive_weight_cycles_2(PPIds, CallWeights, Module, Cycles2),
-	list__append(Cycles1, Cycles2, Cycles).
+    list.append(Cycles1, Cycles2, Cycles).

 :- pred zero_or_positive_weight_cycles_from(pred_proc_id::in,
 	call_weight_graph::in, module_info::in,
 	list(termination_error_context)::out) is det.

 zero_or_positive_weight_cycles_from(PPId, CallWeights, Module, Cycles) :-
-	map__lookup(CallWeights, PPId, NeighboursMap),
-	map__to_assoc_list(NeighboursMap, NeighboursList),
+    map.lookup(CallWeights, PPId, NeighboursMap),
+    map.to_assoc_list(NeighboursMap, NeighboursList),
 	PPId = proc(PredId, _ProcId),
 	module_info_pred_info(Module, PredId, PredInfo),
 	pred_info_context(PredInfo, Context),
@@ -557,7 +554,7 @@
 		Context, WeightSoFar, VisitedCalls, CallWeights, Cycles1),
 	zero_or_positive_weight_cycles_from_neighbours(Neighbours, LookforPPId,
 		Context, WeightSoFar, VisitedCalls, CallWeights, Cycles2),
-	list__append(Cycles1, Cycles2, Cycles).
+    list.append(Cycles1, Cycles2, Cycles).

 :- pred zero_or_positive_weight_cycles_from_neighbour(pair(pred_proc_id,
 	pair(prog_context, int))::in, pred_proc_id::in, prog_context::in,
@@ -574,25 +571,23 @@
 		% We have a cycle on the looked for ppid.
 		( WeightSoFar1 >= 0 ->
 			FinalVisitedCalls = [CurPPId - Context | VisitedCalls],
-			list__reverse(FinalVisitedCalls, RevFinalVisitedCalls),
-			Cycles = [ProcContext -
-				cycle(LookforPPId, RevFinalVisitedCalls)]
+            list.reverse(FinalVisitedCalls, RevFinalVisitedCalls),
+            Cycles = [ProcContext - cycle(LookforPPId, RevFinalVisitedCalls)]
 		;
 			Cycles = []
 		)
 	;
-		assoc_list__keys(VisitedCalls, VisitedPPIds),
-		list__member(CurPPId, VisitedPPIds)
+        assoc_list.keys(VisitedCalls, VisitedPPIds),
+        list.member(CurPPId, VisitedPPIds)
 	->
-		% We have a cycle, but not on the looked for ppid.
-		% We ignore it here; it will be picked up when we process
-		% that ppid.
+        % We have a cycle, but not on the looked for pred_proc_id.  We ignore
+        % it here; it will be picked up when we process that pred_proc_id.
 		Cycles = []
 	;
 		% No cycle; try all possible edges from this node.
 		NewVisitedCalls = [CurPPId - Context | VisitedCalls],
-		map__lookup(CallWeights, CurPPId, NeighboursMap),
-		map__to_assoc_list(NeighboursMap, NeighboursList),
+        map.lookup(CallWeights, CurPPId, NeighboursMap),
+        map.to_assoc_list(NeighboursMap, NeighboursList),
 		zero_or_positive_weight_cycles_from_neighbours(NeighboursList,
 			LookforPPId, ProcContext, WeightSoFar1,
 			NewVisitedCalls, CallWeights, Cycles)
Index: term_traversal.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/term_traversal.m,v
retrieving revision 1.39
diff -u -b -r1.39 term_traversal.m
--- term_traversal.m	28 Oct 2005 02:10:39 -0000	1.39
+++ term_traversal.m	28 Oct 2005 07:30:04 -0000
@@ -211,17 +211,17 @@
     traverse_goal(Else, Params, !.Info, ElseInfo),
     combine_paths(CondThenInfo, ElseInfo, Params, !:Info).

-traverse_goal_2(foreign_proc(Attributes, CallPredId, CallProcId, Args, _, _),
-        GoalInfo, Params, !Info) :-
-    params_get_module_info(Params, Module),
-    module_info_pred_proc_info(Module, CallPredId, CallProcId, _,
+traverse_goal_2(Goal, GoalInfo, Params, !Info) :-
+    Goal = foreign_proc(Attributes, CallPredId, CallProcId, Args, _, _),
+    params_get_module_info(Params, ModuleInfo),
+    module_info_pred_proc_info(ModuleInfo, CallPredId, CallProcId, _,
         CallProcInfo),
     proc_info_argmodes(CallProcInfo, CallArgModes),
     ArgVars = list.map(foreign_arg_var, Args),
-    partition_call_args(Module, CallArgModes, ArgVars, _InVars, OutVars),
+    partition_call_args(ModuleInfo, CallArgModes, ArgVars, _InVars, OutVars),
     goal_info_get_context(GoalInfo, Context),

-    ( is_termination_known(Module, proc(CallPredId, CallProcId)) ->
+    ( is_termination_known(ModuleInfo, proc(CallPredId, CallProcId)) ->
         error_if_intersect(OutVars, Context, pragma_foreign_code, !Info)
     ;
         ( attributes_imply_termination(Attributes) ->
@@ -231,7 +231,8 @@
         )
     ).

-traverse_goal_2(generic_call(Details, Args, ArgModes, _), GoalInfo, Params, !Info) :-
+traverse_goal_2(Goal, GoalInfo, Params, !Info) :-
+    Goal = generic_call(Details, Args, ArgModes, _),
     goal_info_get_context(GoalInfo, Context),
     (
         Details = higher_order(Var, _, _, _),
@@ -242,14 +243,14 @@
         % anything about the size of the arguments of the higher-order call,
         % so we assume that they are unbounded.
         %
-        params_get_module_info(Params, Module),
+        params_get_module_info(Params, ModuleInfo),
         ( ClosureValues0 = ClosureValueMap ^ elem(Var) ->
             ClosureValues = set.to_sorted_list(ClosureValues0),
-            list.filter(terminates(Module), ClosureValues,
+            list.filter(terminates(ModuleInfo), ClosureValues,
                 Terminating, NonTerminating),
             (
                 NonTerminating = [],
-                partition_call_args(Module, ArgModes, Args, _InVars, OutVars),
+                partition_call_args(ModuleInfo, ArgModes, Args, _InVars, OutVars),
                 params_get_ppid(Params, PPId),
                 Error = ho_inf_termination_const(PPId, Terminating),
                 error_if_intersect(OutVars, Context, Error, !Info)
@@ -265,11 +266,10 @@
     ;
         Details = class_method(_, _, _, _),
         %
-        % For class method calls, we could probably analyse
-        % further than this, since we know that the method being
-        % called must come from one of the instance
-        % declarations, and we could potentially (globally)
-        % analyse these.
+        % For class method calls, we could probably analyse further than this,
+        % since we know that the method being called must come from one of the
+        % instance declarations, and we could potentially (globally) analyse
+        % these.
         %
         add_error(Context, method_call, Params, !Info)
     ;
@@ -287,20 +287,20 @@
         add_error(Context, aditi_call, Params, !Info)
     ).

-traverse_goal_2(call(CallPredId, CallProcId, Args, _, _, _),
-        GoalInfo, Params, !Info) :-
+traverse_goal_2(Goal, GoalInfo, Params, !Info) :-
+    Goal = call(CallPredId, CallProcId, Args, _, _, _),
     goal_info_get_context(GoalInfo, Context),
-    params_get_module_info(Params, Module),
+    params_get_module_info(Params, ModuleInfo),
     params_get_ppid(Params, PPId),
     CallPPId = proc(CallPredId, CallProcId),

-    module_info_pred_proc_info(Module, CallPredId, CallProcId, _,
+    module_info_pred_proc_info(ModuleInfo, CallPredId, CallProcId, _,
         CallProcInfo),
     proc_info_argmodes(CallProcInfo, CallArgModes),
     proc_info_get_maybe_arg_size_info(CallProcInfo, CallArgSizeInfo),
     proc_info_get_maybe_termination_info(CallProcInfo, CallTerminationInfo),

-    partition_call_args(Module, CallArgModes, Args, InVars, OutVars),
+    partition_call_args(ModuleInfo, CallArgModes, Args, InVars, OutVars),

     % Handle existing paths
     (
@@ -367,7 +367,7 @@

 %-----------------------------------------------------------------------------%

-    % Traverse_conj should be invoked with a reversed list of goals.
+    % traverse_conj should be invoked with a reversed list of goals.
     % This is to keep stack consumption down.
     %
 :- pred traverse_conj(list(hlds_goal)::in, traversal_params::in,
@@ -519,11 +519,11 @@
     map.lookup(VarTypes, OutVar, Type),
     \+ type_is_higher_order(Type, _, _, _, _),
     ( type_to_ctor_and_args(Type, TypeCtor, _) ->
-        params_get_module_info(Params, Module),
+        params_get_module_info(Params, ModuleInfo),
         filter_args_and_modes(VarTypes, Args0, Args1, Modes0, Modes1),
-        functor_norm(FunctorInfo, TypeCtor, ConsId, Module,
+        functor_norm(FunctorInfo, TypeCtor, ConsId, ModuleInfo,
             Gamma, Args1, Args, Modes1, Modes),
-        split_unification_vars(Args, Modes, Module, InVars, OutVars)
+        split_unification_vars(Args, Modes, ModuleInfo, InVars, OutVars)
     ;
         unexpected(this_file, "unify_change/8: variable type.")
     ).
Index: term_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/term_util.m,v
retrieving revision 1.44
diff -u -b -r1.44 term_util.m
--- term_util.m	28 Oct 2005 02:10:39 -0000	1.44
+++ term_util.m	28 Oct 2005 07:16:44 -0000
@@ -1,4 +1,6 @@
 %-----------------------------------------------------------------------------%
+% vim: ft=mercury ts=4 sw=4 et
+%-----------------------------------------------------------------------------%
 % Copyright (C) 1997-2005 The University of Melbourne.
 % This file may only be copied under the terms of the GNU General
 % Public License - see the file COPYING in the Mercury distribution.
@@ -14,7 +16,7 @@
 %
 %-----------------------------------------------------------------------------%

-:- module transform_hlds__term_util.
+:- module transform_hlds.term_util.

 :- interface.

@@ -34,34 +36,34 @@

 %-----------------------------------------------------------------------------%
 %
-% The types `arg_size_info' and `termination_info' hold information
-% about procedures which is used for termination analysis.
-% These types are stored as fields in the HLDS proc_info.
-% For cross-module analysis, the information is written out as
-% `pragma termination_info(...)' declarations in the
-% `.opt' and `.trans_opt' files.  The module prog_data.m defines
-% types similar to these two (but without the
-% `list(termination_error_context)') which are used when parsing
-% `termination_info' pragmas.
-%
-
-% The arg size info defines an upper bound on the difference
-% between the sizes of the output arguments of a procedure and the sizes
-% of the input arguments:
-%
-% | input arguments | + constant >= | output arguments |
+% The `arg_size_info' and `termination_info' structures
 %
-% where | | represents a semilinear norm.

+% The types `arg_size_info' and `termination_info' hold information about
+% procedures which is used for termination analysis.  These types are stored
+% as fields in the HLDS proc_info.  For intermodule analysis, the information
+% is written out as `pragma termination_info(...)' declarations in the `.opt'
+% and `.trans_opt' files.  The module prog_data.m defines types similar to
+% these two (but without the `list(termination_error_context)') which are used
+% when parsing `termination_info' pragmas.
+
+    % The arg size info defines an upper bound on the difference between the
+    % sizes of the output arguments of a procedure and the sizes of the input
+    % arguments:
+    %
+    % | input arguments | + constant >= | output arguments |
+    %
+    % where | | represents a semilinear norm.
+    %
 :- type arg_size_info ==
 	generic_arg_size_info(list(termination_error_context)).

 :- type termination_info ==
 	generic_termination_info(unit, list(termination_error_context)).

-% The type `used_args' holds a mapping which specifies for each procedure
-% which of its arguments are used.
-
+    % The type `used_args' holds a mapping which specifies for each procedure
+    % which of its arguments are used.
+    %
 :- type used_args	==	map(pred_proc_id, list(bool)).

 :- type pass_info
@@ -73,46 +75,47 @@

 %-----------------------------------------------------------------------------%

-% This predicate partitions the arguments of a call into a list of input
-% variables and a list of output variables,
-
-:- pred partition_call_args(module_info::in, list(mer_mode)::in, list(prog_var)::in,
-	bag(prog_var)::out, bag(prog_var)::out) is det.
-
-% Given a list of variables from a unification, this predicate divides the
-% list into a bag of input variables, and a bag of output variables.
+    % This predicate partitions the arguments of a call into a list of input
+    % variables and a list of output variables.
+    %
+:- pred partition_call_args(module_info::in, list(mer_mode)::in,
+    list(prog_var)::in, bag(prog_var)::out, bag(prog_var)::out) is det.

+    % Given a list of variables from a unification, this predicate divides the
+    % list into a bag of input variables, and a bag of output variables.
+    %
 :- pred split_unification_vars(list(prog_var)::in, list(uni_mode)::in,
 	module_info::in, bag(prog_var)::out, bag(prog_var)::out) is det.

-%  Used to create lists of boolean values, which are used for used_args.
-%  make_bool_list(HeadVars, BoolIn, BoolOut) creates a bool list which is
-%  (length(HeadVars) - length(BoolIn)) `no' followed by BoolIn.  This is
-%  used to set the used args for compiler generated predicates.  The no's
-%  at the start are because the Type infos are not used. length(BoolIn)
-%  should equal the arity of the predicate, and the difference in length
-%  between the arity of the procedure and the arity of the predicate is
-%  the number of type infos.
-
-:- pred term_util__make_bool_list(list(_T)::in, list(bool)::in,
-	list(bool)::out) is det.
-
-% Removes variables from the InVarBag that are not used in the call.
-% remove_unused_args(InVarBag0, VarList, BoolList, InVarBag)
-% VarList and BoolList are corresponding lists.  Any variable in VarList
-% that has a `no' in the corresponding place in the BoolList is removed
-% from InVarBag.
+    % Used to create lists of boolean values, which are used for used_args.
+    % make_bool_list(HeadVars, BoolIn, BoolOut) creates a bool list which is
+    % (length(HeadVars) - length(BoolIn)) `no' followed by BoolIn.  This is
+    % used to set the used args for compiler generated predicates.  The no's
+    % at the start are because the Type infos are not used. length(BoolIn)
+    % should equal the arity of the predicate, and the difference in length
+    % between the arity of the procedure and the arity of the predicate is
+    % the number of typeinfos.
+    %
+:- pred make_bool_list(list(_T)::in, list(bool)::in, list(bool)::out) is det.

+    % Removes variables from the InVarBag that are not used in the call.
+    % remove_unused_args(InVarBag0, VarList, BoolList, InVarBag) VarList and
+    % BoolList are corresponding lists.  Any variable in VarList that has a
+    % `no' in the corresponding place in the BoolList is removed from
+    % InVarBag.
+    %
 :- pred remove_unused_args(bag(prog_var)::in, list(prog_var)::in,
 	list(bool)::in, bag(prog_var)::out) is det.

-% This predicate sets the argument size info of a given a list of procedures.
-
+    % This predicate sets the argument size info of a given a list of
+    % procedures.
+    %
 :- pred set_pred_proc_ids_arg_size_info(list(pred_proc_id)::in,
 	arg_size_info::in, module_info::in, module_info::out) is det.

-% This predicate sets the termination info of a given a list of procedures.
-
+    % This predicate sets the termination info of a given a list of
+    % procedures.
+    %
 :- pred set_pred_proc_ids_termination_info(list(pred_proc_id)::in,
 	termination_info::in, module_info::in, module_info::out) is det.

@@ -123,36 +126,38 @@
 	maybe(arg_size_info)::out) is det.

 	% Succeeds if one or more variables in the list are higher order.
+    %
 :- pred horder_vars(list(prog_var)::in , vartypes::in) is semidet.

 :- pred get_context_from_scc(list(pred_proc_id)::in, module_info::in,
 	prog_context::out) is det.

 	% Succeeds if the termination status of a procedure is known.
+    %
 :- pred is_termination_known(module_info::in, pred_proc_id::in) is semidet.

-	% Succeeds if the foreign proc attributes imply that a procedure
-	% is terminating.
+    % Succeeds if the foreign proc attributes imply that a procedure is
+    % terminating.
+    %
 :- pred attributes_imply_termination(pragma_foreign_proc_attributes::in)
 	is semidet.

-	% terminates(Module, PPId).
-	% Succeeds iff the procedure given by 'PPId' has been
-	% proven to terminate.
+    % terminates(ModuleInfo, PPId).
+    % Succeeds iff the procedure given by 'PPId' has been proven to terminate.
 	%
 :- pred terminates(module_info::in, pred_proc_id::in) is semidet.

 %-----------------------------------------------------------------------------%

-	% Convert a prog_data__pragma_termination_info into a
-	% term_util__termination_info, by adding the appropriate context.
-
+    % Convert a pragma_termination_info into a termination_info, by adding the
+    % appropriate context.
+    %
 :- pred add_context_to_termination_info(maybe(pragma_termination_info)::in,
 	prog_context::in, maybe(termination_info)::out) is det.

-	% Convert a prog_data__pragma_arg_size_info into a
-	% term_util__arg_size_info, by adding the appropriate context.
-
+    % Convert a pragma_arg_size_info into a arg_size_info, by adding the
+    % appropriate context.
+    %
 :- pred add_context_to_arg_size_info(maybe(pragma_arg_size_info)::in,
 	prog_context::in, maybe(arg_size_info)::out) is det.

@@ -177,10 +182,10 @@
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%

-partition_call_args(Module, ArgModes, Args, InVarsBag, OutVarsBag) :-
-	partition_call_args_2(Module, ArgModes, Args, InVars, OutVars),
-	bag__from_list(InVars, InVarsBag),
-	bag__from_list(OutVars, OutVarsBag).
+partition_call_args(ModuleInfo, ArgModes, Args, InVarsBag, OutVarsBag) :-
+    partition_call_args_2(ModuleInfo, ArgModes, Args, InVars, OutVars),
+    bag.from_list(InVars, InVarsBag),
+    bag.from_list(OutVars, OutVarsBag).

 :- pred partition_call_args_2(module_info::in, list(mer_mode)::in,
 	list(prog_var)::in, list(prog_var)::out, list(prog_var)::out) is det.
@@ -205,27 +210,29 @@
 		OutputArgs = OutputArgs1
 	).

-% For these next two predicates (split_unification_vars and
-% partition_call_args) there is a problem of what needs to be done for
-% partially instantiated data structures.  The correct answer is that the
-% system shoud use a norm such that the size of the uninstantiated parts of
-% a partially instantiated structure have no effect on the size of the data
-% structure according to the norm.  For example when finding the size of a
-% list-skeleton, list-length norm should be used.  Therefore, the size of
-% any term must be given by
-% sizeof(term) = constant + sum of the size of each
-% 			(possibly partly) instantiated subterm.
-% It is probably easiest to implement this by modifying term_weights.
-% The current implementation does not correctly handle partially
-% instantiated data structures.
-
-split_unification_vars([], Modes, _ModuleInfo, Vars, Vars) :-
-	bag__init(Vars),
-	( Modes = [] ->
-		true
+    % For these next two predicates (split_unification_vars and
+    % partition_call_args) there is a problem of what needs to be done for
+    % partially instantiated data structures.  The correct answer is that the
+    % system shoud use a norm such that the size of the uninstantiated parts
+    % of a partially instantiated structure have no effect on the size of the
+    % data structure according to the norm.  For example when finding the size
+    % of a list-skeleton, list-length norm should be used.  Therefore, the
+    % size of any term must be given by:
+    %
+    % sizeof(term) = constant + sum of the size of each
+    %           (possibly partly) instantiated subterm.
+    %
+    % It is probably easiest to implement this by modifying term_weights.  The
+    % current implementation does not correctly handle partially instantiated
+    % data structures.
+    %
+split_unification_vars([], Modes, _, Vars, Vars) :-
+    bag.init(Vars),
+    (
+        Modes = []
 	;
-		unexpected(this_file,
-			"split_unification_vars/5: unmatched variables.")
+        Modes = [_|_],
+        unexpected(this_file, "split_unification_vars/5: unmatched variables.")
 	).
 split_unification_vars([Arg | Args], Modes, ModuleInfo,
 		InVars, OutVars):-
@@ -237,7 +244,7 @@
 			inst_is_bound(ModuleInfo, ArgInit)
 		->
 			% Variable is an input variable
-			bag__insert(InVars0, Arg, InVars),
+            bag.insert(InVars0, Arg, InVars),
 			OutVars = OutVars0
 		;
 			inst_is_free(ModuleInfo, ArgInit),
@@ -245,21 +252,20 @@
 		->
 			% Variable is an output variable
 			InVars = InVars0,
-			bag__insert(OutVars0, Arg, OutVars)
+            bag.insert(OutVars0, Arg, OutVars)
 		;
 			InVars = InVars0,
 			OutVars = OutVars0
 		)
 	;
-		unexpected(this_file,
-			"split_unification_vars/5: unmatched variables.")
+        unexpected(this_file, "split_unification_vars/5: unmatched variables.")
 	).

 %-----------------------------------------------------------------------------%

 make_bool_list(HeadVars0, Bools, Out) :-
-	list__length(Bools, Arity),
-	( list__drop(Arity, HeadVars0, HeadVars1) ->
+    list.length(Bools, Arity),
+    ( list.drop(Arity, HeadVars0, HeadVars1) ->
 		HeadVars = HeadVars1
 	;
 		unexpected(this_file, "make_bool_list/3: unmatched variables.")
@@ -278,62 +284,64 @@
 remove_unused_args(Vars, [_X | _Xs], [], Vars) :-
 	unexpected(this_file, "remove_unused_args/4: unmatched variables.").
 remove_unused_args(Vars0, [ Arg | Args ], [ UsedVar | UsedVars ], Vars) :-
-	( UsedVar = yes ->
+    (
 		% The variable is used, so leave it
+        UsedVar = yes,
 		remove_unused_args(Vars0, Args, UsedVars, Vars)
 	;
-		% The variable is not used in producing output vars, so
-		% dont include it as an input variable.
-		bag__delete(Vars0, Arg, Vars1),
+        % The variable is not used in producing output vars, so don't include
+        % it as an input variable.
+        UsedVar = no,
+        bag.delete(Vars0, Arg, Vars1),
 		remove_unused_args(Vars1, Args, UsedVars, Vars)
 	).

 %-----------------------------------------------------------------------------%

-set_pred_proc_ids_arg_size_info([], _ArgSize, !Module).
-set_pred_proc_ids_arg_size_info([PPId | PPIds], ArgSize, !Module) :-
+set_pred_proc_ids_arg_size_info([], _ArgSize, !ModuleInfo).
+set_pred_proc_ids_arg_size_info([PPId | PPIds], ArgSize, !ModuleInfo) :-
 	PPId = proc(PredId, ProcId),
-	module_info_preds(!.Module, PredTable0),
-	map__lookup(PredTable0, PredId, PredInfo0),
+    module_info_preds(!.ModuleInfo, PredTable0),
+    map.lookup(PredTable0, PredId, PredInfo0),
 	pred_info_procedures(PredInfo0, ProcTable0),
-	map__lookup(ProcTable0, ProcId, ProcInfo0),
+    map.lookup(ProcTable0, ProcId, ProcInfo0),

 	proc_info_set_maybe_arg_size_info(yes(ArgSize), ProcInfo0, ProcInfo),

-	map__det_update(ProcTable0, ProcId, ProcInfo, ProcTable),
+    map.det_update(ProcTable0, ProcId, ProcInfo, ProcTable),
 	pred_info_set_procedures(ProcTable, PredInfo0, PredInfo),
-	map__det_update(PredTable0, PredId, PredInfo, PredTable),
-	module_info_set_preds(PredTable, !Module),
-	set_pred_proc_ids_arg_size_info(PPIds, ArgSize, !Module).
+    map.det_update(PredTable0, PredId, PredInfo, PredTable),
+    module_info_set_preds(PredTable, !ModuleInfo),
+    set_pred_proc_ids_arg_size_info(PPIds, ArgSize, !ModuleInfo).

-set_pred_proc_ids_termination_info([], _Termination, !Module).
-set_pred_proc_ids_termination_info([PPId | PPIds], Termination, !Module) :-
+set_pred_proc_ids_termination_info([], _Termination, !ModuleInfo).
+set_pred_proc_ids_termination_info([PPId | PPIds], Termination, !ModuleInfo) :-
 	PPId = proc(PredId, ProcId),
-	module_info_preds(!.Module, PredTable0),
-	map__lookup(PredTable0, PredId, PredInfo0),
+    module_info_preds(!.ModuleInfo, PredTable0),
+    map.lookup(PredTable0, PredId, PredInfo0),
 	pred_info_procedures(PredInfo0, ProcTable0),
-	map__lookup(ProcTable0, ProcId, ProcInfo0),
+    map.lookup(ProcTable0, ProcId, ProcInfo0),

 	proc_info_set_maybe_termination_info(yes(Termination),
 		ProcInfo0, ProcInfo),

-	map__det_update(ProcTable0, ProcId, ProcInfo, ProcTable),
+    map.det_update(ProcTable0, ProcId, ProcInfo, ProcTable),
 	pred_info_set_procedures(ProcTable, PredInfo0, PredInfo),
-	map__det_update(PredTable0, PredId, PredInfo, PredTable),
-	module_info_set_preds(PredTable, !Module),
-	set_pred_proc_ids_termination_info(PPIds, Termination, !Module).
+    map.det_update(PredTable0, PredId, PredInfo, PredTable),
+    module_info_set_preds(PredTable, !ModuleInfo),
+    set_pred_proc_ids_termination_info(PPIds, Termination, !ModuleInfo).

-lookup_proc_termination_info(Module, PPId, MaybeTermination) :-
-	module_info_pred_proc_info(Module, PPId, _, ProcInfo),
+lookup_proc_termination_info(ModuleInfo, PPId, MaybeTermination) :-
+    module_info_pred_proc_info(ModuleInfo, PPId, _, ProcInfo),
 	proc_info_get_maybe_termination_info(ProcInfo, MaybeTermination).

-lookup_proc_arg_size_info(Module, PPId, MaybeArgSize) :-
-	module_info_pred_proc_info(Module, PPId, _, ProcInfo),
+lookup_proc_arg_size_info(ModuleInfo, PPId, MaybeArgSize) :-
+    module_info_pred_proc_info(ModuleInfo, PPId, _, ProcInfo),
 	proc_info_get_maybe_arg_size_info(ProcInfo, MaybeArgSize).

 horder_vars([Arg | Args], VarType) :-
 	(
-		map__lookup(VarType, Arg, Type),
+        map.lookup(VarType, Arg, Type),
 		type_is_higher_order(Type, _, _, _, _)
 	;
 		horder_vars(Args, VarType)
@@ -341,11 +349,13 @@

 %-----------------------------------------------------------------------------%

-get_context_from_scc(SCC, Module, Context) :-
-	( SCC = [proc(PredId, _) | _] ->
-		module_info_pred_info(Module, PredId, PredInfo),
+get_context_from_scc(SCC, ModuleInfo, Context) :-
+    (
+        SCC = [proc(PredId, _) | _],
+        module_info_pred_info(ModuleInfo, PredId, PredInfo),
 		pred_info_context(PredInfo, Context)
 	;
+        SCC = [],
 		unexpected(this_file, "get_context_from_scc/3: empty SCC.")
 	).

@@ -364,8 +374,8 @@

 %-----------------------------------------------------------------------------%

-is_termination_known(Module, PPId) :-
-	module_info_pred_proc_info(Module, PPId, _, ProcInfo),
+is_termination_known(ModuleInfo, PPId) :-
+    module_info_pred_proc_info(ModuleInfo, PPId, _, ProcInfo),
 	proc_info_get_maybe_termination_info(ProcInfo, yes(_)).

 attributes_imply_termination(Attributes) :-
@@ -378,8 +388,8 @@

 %-----------------------------------------------------------------------------%

-terminates(Module, PPId) :-
-	module_info_pred_proc_info(Module, PPId, _, ProcInfo),
+terminates(ModuleInfo, PPId) :-
+    module_info_pred_proc_info(ModuleInfo, PPId, _, ProcInfo),
 	proc_info_get_maybe_termination_info(ProcInfo, TerminationInfo),
 	TerminationInfo = yes(cannot_loop(_)).

Index: termination.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/termination.m,v
retrieving revision 1.56
diff -u -b -r1.56 termination.m
--- termination.m	28 Oct 2005 02:10:39 -0000	1.56
+++ termination.m	28 Oct 2005 07:56:25 -0000
@@ -1,4 +1,6 @@
-%----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+% vim: ft=mercury ts=4 sw=4 et
+%-----------------------------------------------------------------------------%
 % Copyright (C) 1997-2001, 2003-2005 The University of Melbourne.
 % This file may only be copied under the terms of the GNU General
 % Public License - see the file COPYING in the Mercury distribution.
@@ -11,38 +13,24 @@
 %
 % This termination analysis is based on the algorithm given by Gerhard Groeger
 % and Lutz Plumer in their paper "Handling of Mutual Recursion in Automatic
-% Termination Proofs for Logic Programs"  which was printed in JICSLP '92
-% (the proceedings of the Joint International Conference and Symposium on
-% Logic Programming 1992) pages 336 - 350.
+% Termination Proofs for Logic Programs"  which was printed in JICSLP '92 (the
+% proceedings of the Joint International Conference and Symposium on Logic
+% Programming 1992) pages 336 - 350.
 %
 % Details about this implementation are covered in:
 % Chris Speirs, Zoltan Somogyi, and Harald Sondergaard. Termination
 % analysis for Mercury. In P. Van Hentenryck, editor, Static Analysis:
 % Proceedings of the 4th International Symposium, Lecture Notes in Computer
 % Science. Springer, 1997.  A more detailed version is available for
-% download from http://www.cs.mu.oz.au/publications/tr_db/mu_97_09.ps.gz
-%
-% It also fails to prove termination for any predicate that involves higher
-% order calls.
+% download from <http://www.cs.mu.oz.au/publications/tr_db/mu_97_09.ps.gz>
 %
 % The termination analysis may use a number of different norms to calculate
 % the size of a term.  These are set by using the --termination-norm string
-% option.  To add a new norm, the following files must be modified:
-%
-% globals.m 		To change the termination_norm type and
-% 			convert_termination_norm predicate.
-%
-% handle_options.m 	To change the error message that is produced when
-% 			an incorrect argument is given to --termination-norm.
-%
-% term_norm.m		To change the functor_norm predicate and change the
-% 			functor_alg type.
+% option.
 %
-% termination.m		To change the set_functor_info predicate.
-%
-%----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%

-:- module transform_hlds__termination.
+:- module transform_hlds.termination.

 :- interface.

@@ -52,18 +40,19 @@
 :- import_module io.

 	% Perform termination analysis on the module.
-
-:- pred termination__pass(module_info::in, module_info::out,
+    %
+:- pred analyse_termination_in_module(module_info::in, module_info::out,
 	io::di, io::uo) is det.

-	% Write out a termination_info pragma for the predicate if it
-	% is exported, it is not a builtin and it is not a predicate used
-	% to force type specialization.
-:- pred termination__write_pred_termination_info(module_info::in, pred_id::in,
+    % Write out a termination_info pragma for the predicate if it is exported,
+    % it is not a builtin and it is not a predicate used to force type
+    % specialization.
+    %
+:- pred write_pred_termination_info(module_info::in, pred_id::in,
 	io::di, io::uo) is det.

-%----------------------------------------------------------------------------%
-%----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%

 :- implementation.

@@ -109,55 +98,59 @@
 :- import_module term.
 :- import_module varset.

-%----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%

-termination__pass(!Module, !IO) :-
-
-		% Find out what norm we should use, and set up for using it
-	globals__io_get_termination_norm(TermNorm, !IO),
-	FunctorInfo = set_functor_info(TermNorm, !.Module),
-	globals__io_lookup_int_option(termination_error_limit, MaxErrors, !IO),
-	globals__io_lookup_int_option(termination_path_limit, MaxPaths, !IO),
+analyse_termination_in_module(!ModuleInfo, !IO) :-
+    globals.io_get_termination_norm(TermNorm, !IO),
+    FunctorInfo = set_functor_info(TermNorm, !.ModuleInfo),
+    globals.io_lookup_int_option(termination_error_limit, MaxErrors, !IO),
+    globals.io_lookup_int_option(termination_path_limit, MaxPaths, !IO),
 	PassInfo = pass_info(FunctorInfo, MaxErrors, MaxPaths),
-
-		% Process builtin and compiler-generated predicates,
-		% and user-supplied pragmas.
-	module_info_predids(!.Module, PredIds),
-	check_preds(PredIds, !Module, !IO),
-
+    %
+    % Process builtin and compiler-generated predicates, and user-supplied
+    % pragmas.
+    %
+    module_info_predids(!.ModuleInfo, PredIds),
+    check_preds(PredIds, !ModuleInfo, !IO),
+    %
 		% Process all the SCCs of the call graph in a bottom up order.
-	module_info_ensure_dependency_info(!Module),
-	module_info_dependency_info(!.Module, DepInfo),
+    %
+    module_info_ensure_dependency_info(!ModuleInfo),
+    module_info_dependency_info(!.ModuleInfo, DepInfo),
 	hlds_dependency_info_get_dependency_ordering(DepInfo, SCCs),
+    %
+    % Set the termination status of foreign_procs based on the foreign code
+    % attributes.
+    %
+    check_foreign_code_attributes(SCCs, !ModuleInfo, !IO),
+    %
+    % Ensure that termination pragmas for a procedure do not conflict with
+    % termination pragmas for other procedures in the SCC.
+    %
+    check_pragmas_are_consistent(SCCs, !ModuleInfo, !IO),

-		% Set the termination status of foreign_procs.
-	check_foreign_code_attributes(SCCs, !Module, !IO),
-
-		% Ensure that termination pragmas for a proc. do conflict
-		% with termination pragmas for other procs. in the same SCC.
-	check_pragmas_are_consistent(SCCs, !Module, !IO),
-
-	list__foldl2(process_scc(PassInfo), SCCs, !Module, !IO),
+    list.foldl2(analyse_termination_in_scc(PassInfo), SCCs, !ModuleInfo, !IO),

-	globals__io_lookup_bool_option(make_optimization_interface,
-		MakeOptInt, !IO),
-	( MakeOptInt = yes ->
-		termination__make_opt_int(PredIds, !.Module, !IO)
+    globals.io_lookup_bool_option(make_optimization_interface, MakeOptInt,
+        !IO),
+    (
+        MakeOptInt = yes,
+        make_termination_opt_int(PredIds, !.ModuleInfo, !IO)
 	;
-		true
+        MakeOptInt = no
 	),
-	post_term_analysis__process_module(!.Module, !IO).
+    run_post_term_analysis(!.ModuleInfo, !IO).

 %----------------------------------------------------------------------------%
 %
-% Handle foreign code attributes.
+% Handle foreign code attributes
 %

-% Set the termination status for any procedures implemented using the
-% foreign language interface.  If the terminates/does_not_terminate
-% attribute has been set then we set the termination status of the procedure
-% accordingly.  Otherwise the procedure is considered to be terminating
-% if it does not call Mercury and non-terminating if it does.
+% Set the termination status for any procedures implemented using the foreign
+% language interface.  If the terminates/does_not_terminate attribute has been
+% set then we set the termination status of the procedure accordingly.
+% Otherwise the procedure is considered to be terminating if it does not call
+% Mercury and non-terminating if it does.
 %
 % We also check that the foreign code attributes do not conflict with any
 % termination pragmas that have been supplied for the procedure.
@@ -165,60 +158,56 @@
 :- pred check_foreign_code_attributes(list(list(pred_proc_id))::in,
 	module_info::in, module_info::out, io::di, io::uo) is det.

-check_foreign_code_attributes(SCCs, !Module, !IO) :-
-	list__foldl2(check_foreign_code_attributes_2, SCCs, !Module, !IO).
+check_foreign_code_attributes(SCCs, !ModuleInfo, !IO) :-
+    list.foldl2(check_foreign_code_attributes_2, SCCs, !ModuleInfo, !IO).

 :- pred check_foreign_code_attributes_2(list(pred_proc_id)::in, module_info::in,
 	module_info::out, io::di, io::uo) is det.

-	% This case shouldn't happen.
 check_foreign_code_attributes_2([], _, _, _, _) :-
 	unexpected(this_file, "check_foreign_code_attributes_2/5: empty SCC.").
-check_foreign_code_attributes_2([PPId], !Module, !IO) :-
-	module_info_pred_proc_info(!.Module, PPId, PredInfo, ProcInfo0),
+check_foreign_code_attributes_2([PPId], !ModuleInfo, !IO) :-
+    some [!ProcInfo] (
+        module_info_pred_proc_info(!.ModuleInfo, PPId, PredInfo, !:ProcInfo),
 	(
-		proc_info_goal(ProcInfo0, Goal),
-		fst(Goal) = foreign_proc(Attributes, _, _, _, _, _)
+            proc_info_goal(!.ProcInfo, Goal),
+            Goal = foreign_proc(Attributes, _, _, _, _, _) - _GoalInfo
 	->
-		proc_info_get_maybe_termination_info(ProcInfo0,
-			MaybeTermination),
-		proc_info_context(ProcInfo0, Context),
+            proc_info_get_maybe_termination_info(!.ProcInfo, MaybeTermination),
+            proc_info_context(!.ProcInfo, Context),
 		(
 			MaybeTermination = no,
 			( attributes_imply_termination(Attributes) ->
-				proc_info_set_maybe_termination_info(
-					yes(cannot_loop(unit)),
-					ProcInfo0, ProcInfo)
+                    TermStatus = yes(cannot_loop(unit)),
+                    proc_info_set_maybe_termination_info(TermStatus, !ProcInfo)
 			;
 				TermErr = Context - does_not_term_foreign(PPId),
-				proc_info_set_maybe_termination_info(
-					yes(can_loop([TermErr])), ProcInfo0,
-					ProcInfo)
+                    TermStatus = yes(can_loop([TermErr])),
+                    proc_info_set_maybe_termination_info(TermStatus, !ProcInfo)
 			)
 		;
-			% If there was a `pragma terminates' declaration
-			% for this procedure then check that the foreign
-			% code attributes do not contradict this.
+                % If there was a `:- pragma terminates' declaration for this
+                % procedure then check that the foreign code attributes do not
+                % contradict this.
 			MaybeTermination = yes(cannot_loop(_)),
 			( terminates(Attributes) = does_not_terminate ->
 				TermErr = Context - inconsistent_annotations,
-				proc_info_set_maybe_termination_info(
-					yes(can_loop([TermErr])), ProcInfo0,
-					ProcInfo),
-				ProcNamePieces =
-					describe_one_proc_name(!.Module,
+                    TermStatus = yes(can_loop([TermErr])),
+                    proc_info_set_maybe_termination_info(TermStatus,
+                        !ProcInfo),
+                    ProcNamePieces = describe_one_proc_name(!.ModuleInfo,
 						should_module_qualify, PPId),
-				Piece1 = words("has a `pragma terminates'"),
-				Piece2 = words("declaration but also has the"),
-				Piece3 = words("`does_not_terminate' foreign"),
-				Piece4 = words("code attribute set."),
-				Components = [words("Warning:")] ++
-					ProcNamePieces ++
-					[Piece1, Piece2, Piece3, Piece4],
-				error_util__report_warning(Context, 0,
-					Components, !IO)
+                    Components =
+                        [ words("Warning:") | ProcNamePieces ] ++
+                        [
+                            words("has a `pragma terminates'"),
+                            words("declaration but also has the"),
+                            words("`does_not_terminate' foreign"),
+                            words("code attribute set.")
+                        ],
+                    report_warning(Context, 0, Components, !IO)
 			;
-				ProcInfo = ProcInfo0
+                    true
 			)
 		;
 			% In this case there was a `pragma does_not_terminate'
@@ -228,32 +217,37 @@
 			( terminates(Attributes) = terminates ->
 			    TermErr = Context - inconsistent_annotations,
 			    TermErrs = [TermErr | TermErrs0 ],
-			    proc_info_set_maybe_termination_info(
-			        yes(can_loop(TermErrs)),
-			        ProcInfo0, ProcInfo),
-			    ProcNamePieces = describe_one_proc_name(!.Module,
+                    TermStatus =  yes(can_loop(TermErrs)),
+                    proc_info_set_maybe_termination_info(TermStatus,
+                        !ProcInfo),
+                    ProcNamePieces = describe_one_proc_name(!.ModuleInfo,
 				    should_module_qualify, PPId),
-			    Piece1 = words("has a `pragma does_not_terminate'"),
-			    Piece2 = words("declaration but also has the"),
-			    Piece3 = words("`terminates' foreign code"),
-			    Piece4 = words("attribute set."),
-			    Components = [words("Warning:")] ++
-			    	ProcNamePieces ++
-				[Piece1, Piece2, Piece3, Piece4],
-			    error_util__report_warning(Context, 0, Components,
-			        !IO)
+                    Components =
+                        [ words("Warning:") | ProcNamePieces ] ++
+                        [
+                            words("has a `pragma does_not_terminate'"),
+                            words("declaration but also has the"),
+                            words("`terminates' foreign code"),
+                            words("attribute set.")
+                        ],
+                    report_warning(Context, 0, Components, !IO)
 			;
-			    ProcInfo = ProcInfo0
+                    true
 			)
 		),
-		module_info_set_pred_proc_info(PPId, PredInfo, ProcInfo,
-			!Module)
+            module_info_set_pred_proc_info(PPId, PredInfo, !.ProcInfo,
+                !ModuleInfo)
 	;
 		true
+        )
 	).
-check_foreign_code_attributes_2([_, _ | _], !Module, !IO).
+check_foreign_code_attributes_2([_, _ | _], !ModuleInfo, !IO).

 %----------------------------------------------------------------------------%
+%
+% Check termination pragmas for consistency
+%
+
 % Check that any user-supplied termination information (from pragma
 % terminates/does_not_terminate) is consistent for each SCC in the program.
 %
@@ -265,28 +259,28 @@
 %     unknown.  (We check this after checking for the first case, so the
 %     termination info. for the known procs. will be consistent.)
 %
-% In the first case set the termination for all procs. in the SCC to
-% can_loop and emit a warning.  In the second, set the termination of any
-% procs. whose termination status is unknown to be the same as those whose
+% In the first case set the termination for all procs. in the SCC to can_loop
+% and emit a warning.  In the second, set the termination of any procedures
+% whose termination status is unknown to be the same as those whose
 % termination status is known.

 :- pred check_pragmas_are_consistent(list(list(pred_proc_id))::in,
 	module_info::in, module_info::out, io::di, io::uo) is det.

-check_pragmas_are_consistent(SCCs, !Module, !IO) :-
-	list__foldl2(check_scc_pragmas_are_consistent, SCCs, !Module, !IO).
+check_pragmas_are_consistent(SCCs, !ModuleInfo, !IO) :-
+    list.foldl2(check_scc_pragmas_are_consistent, SCCs, !ModuleInfo, !IO).

 :- pred check_scc_pragmas_are_consistent(list(pred_proc_id)::in,
 	module_info::in, module_info::out, io::di, io::uo) is det.

-check_scc_pragmas_are_consistent(SCC, !Module, !IO) :-
-	list__filter(is_termination_known(!.Module), SCC, SCCTerminationKnown,
+check_scc_pragmas_are_consistent(SCC, !ModuleInfo, !IO) :-
+    list.filter(is_termination_known(!.ModuleInfo), SCC, SCCTerminationKnown,
 		SCCTerminationUnknown),
 	(
 		SCCTerminationKnown = []
 	;
 		SCCTerminationKnown = [KnownPPId | _],
-		module_info_pred_proc_info(!.Module, KnownPPId, _,
+        module_info_pred_proc_info(!.ModuleInfo, KnownPPId, _,
 			KnownProcInfo),
 		proc_info_get_maybe_termination_info(KnownProcInfo,
 			MaybeKnownTerm),
@@ -297,47 +291,47 @@
 			MaybeKnownTerm  = yes(KnownTermStatus)
 		),
 		(
-			check_procs_known_term(KnownTermStatus,
-				SCCTerminationKnown, !.Module)
+            check_procs_known_term(KnownTermStatus, SCCTerminationKnown,
+                !.ModuleInfo)
 		->
-			    % Force any procs. in the SCC whose termination
-			    % status is unknown to have the same termination
-			    % status as those that are known.
-			set_termination_infos(SCCTerminationUnknown,
-				KnownTermStatus, !Module)
-		;
-			    % There is a conflict between the user-supplied
-			    % termination information for two or more procs.
-			    % in this SCC.  Emit a warning and then assume
-			    % that they all loop.
-			get_context_from_scc(SCCTerminationKnown, !.Module,
+            % Force any procedures in the SCC whose termination status is
+            % unknown to have the same termination status as those that are
+            % known.
+            set_termination_infos(SCCTerminationUnknown, KnownTermStatus,
+                !ModuleInfo)
+        ;
+            % There is a conflict between the user-supplied termination
+            % information for two or more procedures in this SCC.  Emit a
+            % warning and then assume that they all loop.
+            %
+            get_context_from_scc(SCCTerminationKnown, !.ModuleInfo,
 				Context),
-			NewTermStatus =
-				can_loop([Context - inconsistent_annotations]),
-			set_termination_infos(SCC, NewTermStatus, !Module),
+            NewTermStatus = can_loop([Context - inconsistent_annotations]),
+            set_termination_infos(SCC, NewTermStatus, !ModuleInfo),

-			PredIds = list__map((func(proc(PredId, _)) = PredId),
+            PredIds = list.map((func(proc(PredId, _)) = PredId),
 				SCCTerminationKnown),
-			PredNamesPieces = describe_several_pred_names(!.Module,
+            PredNamePieces = describe_several_pred_names(!.ModuleInfo,
 				should_module_qualify, PredIds),
-			Piece1 = words(
-				"are mutually recursive but some of their"),
-			Piece2 = words(
-				"termination pragmas are inconsistent."),
-			Components = [words("Warning:")] ++ PredNamesPieces ++
-				[Piece1, Piece2],
-			error_util__report_warning(Context, 0, Components, !IO)
+            Components =
+                [ words("Warning:") | PredNamePieces ] ++
+                [
+                    words("are mutually recursive but some of their"),
+                    words( "termination pragmas are inconsistent.")
+                ],
+            report_warning(Context, 0, Components, !IO)
 		)
 	).

 	% Check that all procedures in an SCC whose termination status is known
 	% have the same termination status.
+    %
 :- pred check_procs_known_term(termination_info::in, list(pred_proc_id)::in,
 	module_info::in) is semidet.

 check_procs_known_term(_, [], _).
-check_procs_known_term(Status, [PPId | PPIds], Module) :-
-	module_info_pred_proc_info(Module, PPId, _, ProcInfo),
+check_procs_known_term(Status, [PPId | PPIds], ModuleInfo) :-
+    module_info_pred_proc_info(ModuleInfo, PPId, _, ProcInfo),
 	proc_info_get_maybe_termination_info(ProcInfo, MaybeTerm),
 	(
 		MaybeTerm = no,
@@ -352,50 +346,55 @@
 		Status = can_loop(_),
 		PPIdStatus = can_loop(_)
 	),
-	check_procs_known_term(Status, PPIds, Module).
-
-%----------------------------------------------------------------------------%
+    check_procs_known_term(Status, PPIds, ModuleInfo).

-	% For each SCC, we first find out the relationships among
-	% the sizes of the arguments of the procedures of the SCC,
-	% and then attempt to prove termination of the procedures.
+%-----------------------------------------------------------------------------%
+%
+% Run termination analysis on a single SCC
+%

-:- pred termination__process_scc(pass_info::in, list(pred_proc_id)::in,
+    % For each SCC, we first find out the relationships among the sizes of the
+    % arguments of the procedures of the SCC, and then attempt to prove
+    % termination of the procedures.
+    %
+:- pred analyse_termination_in_scc(pass_info::in, list(pred_proc_id)::in,
 	module_info::in, module_info::out, io::di, io::uo) is det.

-termination__process_scc(PassInfo, SCC, !Module, !IO) :-
+analyse_termination_in_scc(PassInfo, SCC, !ModuleInfo, !IO) :-
 	IsArgSizeKnown = (pred(PPId::in) is semidet :-
-		module_info_pred_proc_info(!.Module, PPId, _, ProcInfo),
+        module_info_pred_proc_info(!.ModuleInfo, PPId, _, ProcInfo),
 		proc_info_get_maybe_arg_size_info(ProcInfo, yes(_))
 	),
-	list__filter(IsArgSizeKnown, SCC, _SCCArgSizeKnown, SCCArgSizeUnknown),
-	( SCCArgSizeUnknown = [] ->
+    list.filter(IsArgSizeKnown, SCC, _SCCArgSizeKnown, SCCArgSizeUnknown),
+    (
+        SCCArgSizeUnknown = [],
 		ArgSizeErrors = [],
 		TermErrors = []
 	;
-		find_arg_sizes_in_scc(SCCArgSizeUnknown, !.Module, PassInfo,
+        SCCArgSizeUnknown = [_|_],
+        find_arg_sizes_in_scc(SCCArgSizeUnknown, !.ModuleInfo, PassInfo,
 			ArgSizeResult, TermErrors, !IO),
 		(
 			ArgSizeResult = ok(Solutions, OutputSupplierMap),
 			set_finite_arg_size_infos(Solutions,
-				OutputSupplierMap, !Module),
+                OutputSupplierMap, !ModuleInfo),
 			ArgSizeErrors = []
 		;
 			ArgSizeResult = error(Errors),
 			set_infinite_arg_size_infos(SCCArgSizeUnknown,
-				infinite(Errors), !Module),
+                infinite(Errors), !ModuleInfo),
 			ArgSizeErrors = Errors
 		)
 	),
-	list__filter(is_termination_known(!.Module), SCC,
+    list.filter(is_termination_known(!.ModuleInfo), SCC,
 		_SCCTerminationKnown, SCCTerminationUnknown),
-	( SCCTerminationUnknown = [] ->
-			%
+    (
 			% We may possibly have encountered inconsistent
-			% terminates/does_not_terminate pragmas for this SCC,
-			% so we need to report errors here as well.
-		true
+        % terminates/does_not_terminate pragmas for this SCC, so we need to
+        % report errors here as well.
+        SCCTerminationUnknown = []
 	;
+        SCCTerminationUnknown = [_|_],
 		IsFatal = (pred(ContextError::in) is semidet :-
 			ContextError = _Context - Error,
 			( Error = horder_call
@@ -403,45 +402,48 @@
 			; Error = imported_pred
 			)
 		),
-		list__filter(IsFatal, ArgSizeErrors, FatalErrors),
-		list__append(TermErrors, FatalErrors, BothErrors),
-		( BothErrors = [_ | _] ->
+        list.filter(IsFatal, ArgSizeErrors, FatalErrors),
+        BothErrors = TermErrors ++ FatalErrors,
+        (
+            BothErrors = [_|_],
 			% These errors prevent pass 2 from proving termination
 			% in any case, so we may as well not prove it quickly.
 			PassInfo = pass_info(_, MaxErrors, _),
-			list__take_upto(MaxErrors, BothErrors,
+            list.take_upto(MaxErrors, BothErrors,
 				ReportedErrors),
 			TerminationResult = can_loop(ReportedErrors)
 		;
-			globals__io_lookup_int_option(termination_single_args,
+            BothErrors = [],
+            globals.io_lookup_int_option(termination_single_args,
 				SingleArgs, !IO),
 			prove_termination_in_scc(SCCTerminationUnknown,
-				!.Module, PassInfo, SingleArgs,
+                !.ModuleInfo, PassInfo, SingleArgs,
 				TerminationResult)
 		),
-		set_termination_infos(SCCTerminationUnknown,
-			TerminationResult, !Module),
-		( TerminationResult = can_loop(TerminationErrors) ->
+        set_termination_infos(SCCTerminationUnknown, TerminationResult,
+            !ModuleInfo),
+        (
+            TerminationResult = can_loop(TerminationErrors),
 			report_termination_errors(SCC, TerminationErrors,
-				!Module, !IO)
+                !ModuleInfo, !IO)
 		;
-			true
+            TerminationResult = cannot_loop(_)
 		)
 	).

-%----------------------------------------------------------------------------%
-
-% This predicate takes the results from solve_equations
-% and inserts these results into the module info.
+%-----------------------------------------------------------------------------%

+    % This predicate takes the results from solve_equations and inserts these
+    % results into the module info.
+    %
 :- pred set_finite_arg_size_infos(list(pair(pred_proc_id, int))::in,
 	used_args::in, module_info::in, module_info::out) is det.

-set_finite_arg_size_infos([], _, !Module).
-set_finite_arg_size_infos([Soln | Solns], OutputSupplierMap, !Module) :-
+set_finite_arg_size_infos([], _, !ModuleInfo).
+set_finite_arg_size_infos([Soln | Solns], OutputSupplierMap, !ModuleInfo) :-
 	Soln = PPId - Gamma,
 	PPId = proc(PredId, ProcId),
-	module_info_preds(!.Module, PredTable0),
+	module_info_preds(!.ModuleInfo, PredTable0),
 	map__lookup(PredTable0, PredId, PredInfo),
 	pred_info_procedures(PredInfo, ProcTable),
 	map__lookup(ProcTable, ProcId, ProcInfo),
@@ -452,78 +454,78 @@
 	map__set(ProcTable, ProcId, ProcInfo1, ProcTable1),
 	pred_info_set_procedures(ProcTable1, PredInfo, PredInfo1),
 	map__set(PredTable0, PredId, PredInfo1, PredTable),
-	module_info_set_preds(PredTable, !Module),
-	set_finite_arg_size_infos(Solns, OutputSupplierMap, !Module).
+	module_info_set_preds(PredTable, !ModuleInfo),
+	set_finite_arg_size_infos(Solns, OutputSupplierMap, !ModuleInfo).

 :- pred set_infinite_arg_size_infos(list(pred_proc_id)::in,
 	arg_size_info::in, module_info::in, module_info::out) is det.

-set_infinite_arg_size_infos([], _, !Module).
-set_infinite_arg_size_infos([PPId | PPIds], ArgSizeInfo, !Module) :-
+set_infinite_arg_size_infos([], _, !ModuleInfo).
+set_infinite_arg_size_infos([PPId | PPIds], ArgSizeInfo, !ModuleInfo) :-
 	PPId = proc(PredId, ProcId),
-	module_info_preds(!.Module, PredTable0),
-	map__lookup(PredTable0, PredId, PredInfo),
+    module_info_preds(!.ModuleInfo, PredTable0),
+    map.lookup(PredTable0, PredId, PredInfo),
 	pred_info_procedures(PredInfo, ProcTable),
-	map__lookup(ProcTable, ProcId, ProcInfo),
+    map.lookup(ProcTable, ProcId, ProcInfo),
 	proc_info_set_maybe_arg_size_info(yes(ArgSizeInfo),
 		ProcInfo, ProcInfo1),
-	map__set(ProcTable, ProcId, ProcInfo1, ProcTable1),
+    map.set(ProcTable, ProcId, ProcInfo1, ProcTable1),
 	pred_info_set_procedures(ProcTable1, PredInfo, PredInfo1),
-	map__set(PredTable0, PredId, PredInfo1, PredTable),
-	module_info_set_preds(PredTable, !Module),
-	set_infinite_arg_size_infos(PPIds, ArgSizeInfo, !Module).
+    map.set(PredTable0, PredId, PredInfo1, PredTable),
+    module_info_set_preds(PredTable, !ModuleInfo),
+    set_infinite_arg_size_infos(PPIds, ArgSizeInfo, !ModuleInfo).

-%----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%

 :- pred set_termination_infos(list(pred_proc_id)::in, termination_info::in,
 	module_info::in, module_info::out) is det.

-set_termination_infos([], _, !Module).
-set_termination_infos([PPId | PPIds], TerminationInfo, !Module) :-
+set_termination_infos([], _, !ModuleInfo).
+set_termination_infos([PPId | PPIds], TerminationInfo, !ModuleInfo) :-
 	PPId = proc(PredId, ProcId),
-	module_info_preds(!.Module, PredTable0),
-	map__lookup(PredTable0, PredId, PredInfo0),
+    module_info_preds(!.ModuleInfo, PredTable0),
+    map.lookup(PredTable0, PredId, PredInfo0),
 	pred_info_procedures(PredInfo0, ProcTable0),
-	map__lookup(ProcTable0, ProcId, ProcInfo0),
+    map.lookup(ProcTable0, ProcId, ProcInfo0),
 	proc_info_set_maybe_termination_info(yes(TerminationInfo),
 		ProcInfo0, ProcInfo),
-	map__det_update(ProcTable0, ProcId, ProcInfo, ProcTable),
+    map.det_update(ProcTable0, ProcId, ProcInfo, ProcTable),
 	pred_info_set_procedures(ProcTable, PredInfo0, PredInfo),
-	map__det_update(PredTable0, PredId, PredInfo, PredTable),
-	module_info_set_preds(PredTable, !Module),
-	set_termination_infos(PPIds, TerminationInfo, !Module).
+    map.det_update(PredTable0, PredId, PredInfo, PredTable),
+    module_info_set_preds(PredTable, !ModuleInfo),
+    set_termination_infos(PPIds, TerminationInfo, !ModuleInfo).

 :- pred report_termination_errors(list(pred_proc_id)::in,
 	list(termination_error_context)::in,
 	module_info::in, module_info::out, io::di, io::uo) is det.

-report_termination_errors(SCC, Errors, !Module, !IO) :-
-	globals__io_lookup_bool_option(check_termination,
+report_termination_errors(SCC, Errors, !ModuleInfo, !IO) :-
+    globals.io_lookup_bool_option(check_termination,
 		NormalErrors, !IO),
-	globals__io_lookup_bool_option(verbose_check_termination,
+    globals.io_lookup_bool_option(verbose_check_termination,
 		VerboseErrors, !IO),
 	(
 		IsCheckTerm = (pred(PPId::in) is semidet :-
-			module_info_pred_proc_info(!.Module, PPId, PredInfo, _),
+            module_info_pred_proc_info(!.ModuleInfo, PPId, PredInfo, _),
 			\+ pred_info_is_imported(PredInfo),
 			pred_info_get_markers(PredInfo, Markers),
 			check_marker(Markers, check_termination)
 		),
-		list__filter(IsCheckTerm, SCC, CheckTermPPIds),
+        list.filter(IsCheckTerm, SCC, CheckTermPPIds),
 		CheckTermPPIds = [_ | _]
 	->
 		% If any procedure in the SCC has a check_terminates pragma,
 		% print out one error message for the whole SCC and indicate
 		% an error.
-		term_errors__report_term_errors(SCC, Errors, !.Module, !IO),
-		io__set_exit_status(1, !IO),
-		module_info_incr_errors(!Module)
+        report_term_errors(SCC, Errors, !.ModuleInfo, !IO),
+        io.set_exit_status(1, !IO),
+        module_info_incr_errors(!ModuleInfo)
 	;
 		IsNonImported = (pred(PPId::in) is semidet :-
-			module_info_pred_proc_info(!.Module, PPId, PredInfo, _),
+            module_info_pred_proc_info(!.ModuleInfo, PPId, PredInfo, _),
 			\+ pred_info_is_imported(PredInfo)
 		),
-		list__filter(IsNonImported, SCC, NonImportedPPIds),
+        list.filter(IsNonImported, SCC, NonImportedPPIds),
 		NonImportedPPIds = [_ | _],

 		% Don't emit non-termination warnings for the compiler
@@ -532,7 +534,7 @@
 		% can do about it anyway - the problem is with the
 		% initialisation predicate specified by the user, not the
 		% wrapper.
-		list__all_false(is_solver_init_wrapper_pred(!.Module), SCC),
+        list.all_false(is_solver_init_wrapper_pred(!.ModuleInfo), SCC),

 		% Only output warnings of non-termination for direct
 		% errors.  If there are no direct errors then output
@@ -549,18 +551,16 @@
 				ContextError = _Context - Error,
 				\+ indirect_error(Error)
 			),
-			list__filter(IsNonSimple, Errors, PrintErrors0),
-				% If there were no direct errors then use
-				% the indirect errors.
-			( if 	PrintErrors0 = []
-			  then	PrintErrors = Errors
-			  else	PrintErrors = PrintErrors0
-			)
+            list.filter(IsNonSimple, Errors, PrintErrors0),
+            % If there were no direct errors then use the indirect errors.
+            % This prevents warnings that report termination could not be
+            % proved for unknown reasons.
+            PrintErrors = ( PrintErrors0 = [] -> Errors ; PrintErrors0 )
 		;
 			fail
 		)
 	->
-		term_errors__report_term_errors(SCC, PrintErrors, !.Module, !IO)
+        report_term_errors(SCC, PrintErrors, !.ModuleInfo, !IO)
 	;
 		true
 	).
@@ -598,13 +598,13 @@
 :- pred check_preds(list(pred_id)::in, module_info::in, module_info::out,
 	io::di, io::uo) is det.

-check_preds([], !Module, !IO).
-check_preds([PredId | PredIds], !Module, !IO) :-
-	write_pred_progress_message("% Checking ", PredId, !.Module, !IO),
-	globals__io_lookup_bool_option(make_optimization_interface,
+check_preds([], !ModuleInfo, !IO).
+check_preds([PredId | PredIds], !ModuleInfo, !IO) :-
+    write_pred_progress_message("% Checking ", PredId, !.ModuleInfo, !IO),
+    globals.io_lookup_bool_option(make_optimization_interface,
 		MakeOptInt, !IO),
-	module_info_preds(!.Module, PredTable0),
-	map__lookup(PredTable0, PredId, PredInfo0),
+    module_info_preds(!.ModuleInfo, PredTable0),
+    map.lookup(PredTable0, PredId, PredInfo0),
 	pred_info_import_status(PredInfo0, ImportStatus),
 	pred_info_context(PredInfo0, Context),
 	pred_info_procedures(PredInfo0, ProcTable0),
@@ -615,7 +615,7 @@
 		% predicates to be imported or locally defined, so they
 		% must be covered here, separately.
 		set_compiler_gen_terminates(PredInfo0, ProcIds, PredId,
-			!.Module, ProcTable0, ProcTable1)
+            !.ModuleInfo, ProcTable0, ProcTable1)
 	->
 		ProcTable2 = ProcTable1
 	;
@@ -668,29 +668,30 @@
 		ProcTable = ProcTable2
 	),
 	pred_info_set_procedures(ProcTable, PredInfo0, PredInfo),
-	map__set(PredTable0, PredId, PredInfo, PredTable),
-	module_info_set_preds(PredTable, !Module),
-	check_preds(PredIds, !Module, !IO).
+    map.set(PredTable0, PredId, PredInfo, PredTable),
+    module_info_set_preds(PredTable, !ModuleInfo),
+    check_preds(PredIds, !ModuleInfo, !IO).

 %----------------------------------------------------------------------------%

 % This predicate checks each ProcId in the list to see if it is a compiler
-% generated predicate, or a predicate from builtin.m or private_builtin.m.
-% If it is, then the compiler sets the termination property of the ProcIds
+% generated predicate, or a predicate from builtin.m or private_builtin.m.  If
+% it is, then the compiler sets the termination property of the ProcIds
 % accordingly.

-% We assume that user-defined special predicates terminate.  This
-% assumption is checked later during the post_term_analysis pass.
+% We assume that user-defined special predicates terminate.  This assumption
+% is checked later during the post_term_analysis pass.

 :- pred set_compiler_gen_terminates(pred_info::in, list(proc_id)::in,
 	pred_id::in, module_info::in, proc_table::in, proc_table::out)
 	is semidet.

-set_compiler_gen_terminates(PredInfo, ProcIds, PredId, Module, !ProcTable) :-
+set_compiler_gen_terminates(PredInfo, ProcIds, PredId, ModuleInfo,
+        !ProcTable) :-
 	(
 		pred_info_is_builtin(PredInfo)
 	->
-		set_builtin_terminates(ProcIds, PredId, PredInfo, Module,
+        set_builtin_terminates(ProcIds, PredId, PredInfo, ModuleInfo,
 			!ProcTable)
 	;
 		(
@@ -722,7 +723,7 @@
 	% argument size information anyway.
 	%
 	( SpecialPredId \= spec_pred_init ->
-		map__lookup(!.ProcTable, ProcId, ProcInfo0),
+        map.lookup(!.ProcTable, ProcId, ProcInfo0),
 		proc_info_headvars(ProcInfo0, HeadVars),
 		special_pred_id_to_termination(SpecialPredId, HeadVars,
 			ArgSize, Termination),
@@ -730,7 +731,7 @@
 			ProcInfo1),
 		proc_info_set_maybe_termination_info(yes(Termination),
 			ProcInfo1, ProcInfo),
-		svmap__det_update(ProcId, ProcInfo, !ProcTable)
+        svmap.det_update(ProcId, ProcInfo, !ProcTable)
 	;
 		true
 	),
@@ -744,17 +745,17 @@

 special_pred_id_to_termination(spec_pred_compare, HeadVars, ArgSize,
 		Termination) :-
-	term_util__make_bool_list(HeadVars, [no, no, no], OutList),
+    term_util.make_bool_list(HeadVars, [no, no, no], OutList),
 	ArgSize = finite(0, OutList),
 	Termination = cannot_loop(unit).
 special_pred_id_to_termination(spec_pred_unify, HeadVars, ArgSize,
 		Termination) :-
-	term_util__make_bool_list(HeadVars, [yes, yes], OutList),
+    term_util.make_bool_list(HeadVars, [yes, yes], OutList),
 	ArgSize = finite(0, OutList),
 	Termination = cannot_loop(unit).
 special_pred_id_to_termination(spec_pred_index, HeadVars, ArgSize,
 		Termination) :-
-	term_util__make_bool_list(HeadVars, [no, no], OutList),
+    term_util.make_bool_list(HeadVars, [no, no], OutList),
 	ArgSize = finite(0, OutList),
 	Termination = cannot_loop(unit).
 special_pred_id_to_termination(spec_pred_init, _, _, _) :-
@@ -768,15 +769,15 @@
 	module_info::in, proc_table::in, proc_table::out) is det.

 set_builtin_terminates([], _, _, _, !ProcTable).
-set_builtin_terminates([ProcId | ProcIds], PredId, PredInfo, Module,
+set_builtin_terminates([ProcId | ProcIds], PredId, PredInfo, ModuleInfo,
 		!ProcTable) :-
-	map__lookup(!.ProcTable, ProcId, ProcInfo0),
-	( all_args_input_or_zero_size(Module, PredInfo, ProcInfo0) ->
-		% The size of the output arguments will all be 0,
-		% independent of the size of the input variables.
+    map.lookup(!.ProcTable, ProcId, ProcInfo0),
+    ( all_args_input_or_zero_size(ModuleInfo, PredInfo, ProcInfo0) ->
+        % The size of the output arguments will all be 0, independent of the
+        % size of the input variables.
 		% UsedArgs should be set to yes([no, no, ...]).
 		proc_info_headvars(ProcInfo0, HeadVars),
-		term_util__make_bool_list(HeadVars, [], UsedArgs),
+        term_util.make_bool_list(HeadVars, [], UsedArgs),
 		ArgSizeInfo = yes(finite(0, UsedArgs))
 	;
 		pred_info_context(PredInfo, Context),
@@ -786,16 +787,16 @@
 	proc_info_set_maybe_arg_size_info(ArgSizeInfo, ProcInfo0, ProcInfo1),
 	proc_info_set_maybe_termination_info(yes(cannot_loop(unit)),
 		ProcInfo1, ProcInfo),
-	map__det_update(!.ProcTable, ProcId, ProcInfo, !:ProcTable),
-	set_builtin_terminates(ProcIds, PredId, PredInfo, Module, !ProcTable).
+    map.det_update(!.ProcTable, ProcId, ProcInfo, !:ProcTable),
+    set_builtin_terminates(ProcIds, PredId, PredInfo, ModuleInfo, !ProcTable).

 :- pred all_args_input_or_zero_size(module_info::in, pred_info::in,
 	proc_info::in) is semidet.

-all_args_input_or_zero_size(Module, PredInfo, ProcInfo) :-
+all_args_input_or_zero_size(ModuleInfo, PredInfo, ProcInfo) :-
 	pred_info_arg_types(PredInfo, TypeList),
 	proc_info_argmodes(ProcInfo, ModeList),
-	all_args_input_or_zero_size_2(TypeList, ModeList, Module).
+    all_args_input_or_zero_size_2(TypeList, ModeList, ModuleInfo).

 :- pred all_args_input_or_zero_size_2(list(mer_type)::in, list(mer_mode)::in,
 	module_info::in) is semidet.
@@ -805,35 +806,34 @@
 	unexpected(this_file, "all_args_input_or_size_2/3 - unmatched lists.").
 all_args_input_or_zero_size_2([_|_], [], _) :-
 	unexpected(this_file, "all_args_input_or_size_2/3 - unmatched lists.").
-all_args_input_or_zero_size_2([Type | Types], [Mode | Modes], Module) :-
-	( mode_is_input(Module, Mode) ->
-		% The variable is an input variables, so its size is
-		% irrelevant.
-		all_args_input_or_zero_size_2(Types, Modes, Module)
+all_args_input_or_zero_size_2([Type | Types], [Mode | Modes], ModuleInfo) :-
+    ( mode_is_input(ModuleInfo, Mode) ->
+        % The variable is an input variables, so its size is irrelevant.
+        all_args_input_or_zero_size_2(Types, Modes, ModuleInfo)
 	;
-		zero_size_type(Type, Module),
-		all_args_input_or_zero_size_2(Types, Modes, Module)
+        zero_size_type(Type, ModuleInfo),
+        all_args_input_or_zero_size_2(Types, Modes, ModuleInfo)
 	).

 %----------------------------------------------------------------------------%

-% This predicate sets the arg_size_info property of the given list
-% of procedures.
-%
-% change_procs_arg_size_info(ProcList, Override, TerminationInfo,
-% 		ProcTable, ProcTable)
-%
-% If Override is yes, then this predicate overrides any existing arg_size
-% information. If Override is no, then it leaves the proc_info of a procedure
-% unchanged unless the proc_info had no arg_size information (i.e. the
-% maybe(arg_size_info) field was set to "no").
-
+    % This predicate sets the arg_size_info property of the given list of
+    % procedures.
+    %
+    % change_procs_arg_size_info(ProcList, Override, TerminationInfo,
+    %       ProcTable, ProcTable)
+    %
+    % If Override is yes, then this predicate overrides any existing arg_size
+    % information. If Override is no, then it leaves the proc_info of a
+    % procedure unchanged unless the proc_info had no arg_size information
+    % (i.e. the maybe(arg_size_info) field was set to "no").
+    %
 :- pred change_procs_arg_size_info(list(proc_id)::in, bool::in,
 	arg_size_info::in, proc_table::in, proc_table::out) is det.

 change_procs_arg_size_info([], _, _, !ProcTable).
 change_procs_arg_size_info([ProcId | ProcIds], Override, ArgSize, !ProcTable) :-
-	map__lookup(!.ProcTable, ProcId, ProcInfo0),
+    map.lookup(!.ProcTable, ProcId, ProcInfo0),
 	(
 		(
 			Override = yes
@@ -841,32 +841,31 @@
 			proc_info_get_maybe_arg_size_info(ProcInfo0, no)
 		)
 	->
-		proc_info_set_maybe_arg_size_info(yes(ArgSize),
-			ProcInfo0, ProcInfo),
-		map__det_update(!.ProcTable, ProcId, ProcInfo, !:ProcTable)
+        proc_info_set_maybe_arg_size_info(yes(ArgSize), ProcInfo0, ProcInfo),
+        svmap.det_update(ProcId, ProcInfo, !ProcTable)
 	;
 		true
 	),
 	change_procs_arg_size_info(ProcIds, Override, ArgSize, !ProcTable).

-% This predicate sets the termination_info property of the given list
-% of procedures.
-%
-% change_procs_termination_info(ProcList, Override, TerminationInfo,
-% 		ProcTable, ProcTable)
-%
-% If Override is yes, then this predicate overrides any existing termination
-% information. If Override is no, then it leaves the proc_info of a procedure
-% unchanged unless the proc_info had no termination information (i.e. the
-% maybe(termination_info) field was set to "no").
-
+    % This predicate sets the termination_info property of the given list of
+    % procedures.
+    %
+    % change_procs_termination_info(ProcList, Override, TerminationInfo,
+    %       ProcTable, ProcTable)
+    %
+    % If Override is yes, then this predicate overrides any existing
+    % termination information. If Override is no, then it leaves the proc_info
+    % of a procedure unchanged unless the proc_info had no termination
+    % information (i.e. the maybe(termination_info) field was set to "no").
+    %
 :- pred change_procs_termination_info(list(proc_id)::in, bool::in,
 	termination_info::in, proc_table::in, proc_table::out) is det.

 change_procs_termination_info([], _, _, !ProcTable).
 change_procs_termination_info([ProcId | ProcIds], Override, Termination,
 		!ProcTable) :-
-	map__lookup(!.ProcTable, ProcId, ProcInfo0),
+    map.lookup(!.ProcTable, ProcId, ProcInfo0),
 	(
 		(
 			Override = yes
@@ -876,57 +875,51 @@
 	->
 		proc_info_set_maybe_termination_info(yes(Termination),
 			ProcInfo0, ProcInfo),
-		map__det_update(!.ProcTable, ProcId, ProcInfo, !:ProcTable)
+        svmap.det_update(ProcId, ProcInfo, !ProcTable)
 	;
 		true
 	),
-	change_procs_termination_info(ProcIds, Override, Termination,
-		!ProcTable).
+    change_procs_termination_info(ProcIds, Override, Termination, !ProcTable).

-%----------------------------------------------------------------------------%
-%----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%

-% These predicates are used to add the termination_info pragmas to the .opt
-% file.  It is often better to use the .trans_opt file, as it gives
-% much better accuracy.  The two files are not mutually exclusive, and
-% termination information may be stored in both.
-
-:- pred termination__make_opt_int(list(pred_id)::in, module_info::in,
+    % These predicates are used to add the termination_info pragmas to the
+    % .opt and .trans_opt files.
+    %
+:- pred make_termination_opt_int(list(pred_id)::in, module_info::in,
 	io::di, io::uo) is det.

-termination__make_opt_int(PredIds, Module, !IO) :-
-	module_info_get_name(Module, ModuleName),
+make_termination_opt_int(PredIds, ModuleInfo, !IO) :-
+    module_info_get_name(ModuleInfo, ModuleName),
 	module_name_to_file_name(ModuleName, ".opt.tmp", no, OptFileName, !IO),
-	globals__io_lookup_bool_option(verbose, Verbose, !IO),
-	maybe_write_string(Verbose,
-		"% Appending termination_info pragmas to `", !IO),
+    globals.io_lookup_bool_option(verbose, Verbose, !IO),
+    maybe_write_string(Verbose, "% Appending termination_info pragmas to `",
+        !IO),
 	maybe_write_string(Verbose, OptFileName, !IO),
 	maybe_write_string(Verbose, "'...", !IO),
 	maybe_flush_output(Verbose, !IO),

-	io__open_append(OptFileName, OptFileRes, !IO),
+    io.open_append(OptFileName, OptFileRes, !IO),
 	(
 		OptFileRes = ok(OptFile),
-		io__set_output_stream(OptFile, OldStream, !IO),
-		list__foldl(termination__write_pred_termination_info(Module),
-			PredIds, !IO),
-		io__set_output_stream(OldStream, _, !IO),
-		io__close_output(OptFile, !IO),
+        io.set_output_stream(OptFile, OldStream, !IO),
+        list.foldl(write_pred_termination_info(ModuleInfo), PredIds, !IO),
+        io.set_output_stream(OldStream, _, !IO),
+        io.close_output(OptFile, !IO),
 		maybe_write_string(Verbose, " done.\n", !IO)
 	;
 		OptFileRes = error(IOError),
-		% failed to open the .opt file for processing
 		maybe_write_string(Verbose, " failed!\n", !IO),
-		io__error_message(IOError, IOErrorMessage),
-		io__write_strings(["Error opening file `",
+        io.error_message(IOError, IOErrorMessage),
+        io.write_strings(["Error opening file `",
 			OptFileName, "' for output: ", IOErrorMessage], !IO),
-		io__set_exit_status(1, !IO)
+        io.set_exit_status(1, !IO)
 	).

-termination__write_pred_termination_info(Module, PredId, !IO) :-
-	module_info_pred_info(Module, PredId, PredInfo),
+write_pred_termination_info(ModuleInfo, PredId, !IO) :-
+    module_info_pred_info(ModuleInfo, PredId, PredInfo),
 	pred_info_import_status(PredInfo, ImportStatus),
-	module_info_get_type_spec_info(Module, TypeSpecInfo),
+    module_info_get_type_spec_info(ModuleInfo, TypeSpecInfo),
 	TypeSpecInfo = type_spec_info(_, TypeSpecForcePreds, _, _),

 	(
@@ -941,7 +934,7 @@
 		% declaration for the specialized predicate is not produced
 		% before the termination pragmas are read in, resulting
 		% in an undefined predicate error.
-		\+ set__member(PredId, TypeSpecForcePreds)
+        \+ set.member(PredId, TypeSpecForcePreds)
 	->
 		PredName = pred_info_name(PredInfo),
 		ProcIds = pred_info_procids(PredInfo),
@@ -950,27 +943,27 @@
 		pred_info_procedures(PredInfo, ProcTable),
 		pred_info_context(PredInfo, Context),
 		SymName = qualified(ModuleName, PredName),
-		termination__make_opt_int_procs(PredId, ProcIds, ProcTable,
+        write_proc_termination_info(PredId, ProcIds, ProcTable,
 			PredOrFunc, SymName, Context, !IO)
 	;
 		true
 	).

-:- pred termination__make_opt_int_procs(pred_id::in, list(proc_id)::in,
+:- pred write_proc_termination_info(pred_id::in, list(proc_id)::in,
 	proc_table::in, pred_or_func::in, sym_name::in, prog_context::in,
 	io::di, io::uo) is det.

-termination__make_opt_int_procs(_PredId, [], _, _, _, _, !IO).
-termination__make_opt_int_procs(PredId, [ ProcId | ProcIds ], ProcTable,
+write_proc_termination_info(_, [], _, _, _, _, !IO).
+write_proc_termination_info(PredId, [ ProcId | ProcIds ], ProcTable,
 		PredOrFunc, SymName, Context, !IO) :-
-	map__lookup(ProcTable, ProcId, ProcInfo),
+    map.lookup(ProcTable, ProcId, ProcInfo),
 	proc_info_get_maybe_arg_size_info(ProcInfo, ArgSize),
 	proc_info_get_maybe_termination_info(ProcInfo, Termination),
 	proc_info_declared_argmodes(ProcInfo, ModeList),
-	write_pragma_termination_info(PredOrFunc, SymName,
-		ModeList, Context, ArgSize, Termination, !IO),
-	termination__make_opt_int_procs(PredId, ProcIds, ProcTable,
-		PredOrFunc, SymName, Context, !IO).
+    write_pragma_termination_info(PredOrFunc, SymName, ModeList, Context,
+        ArgSize, Termination, !IO),
+    write_proc_termination_info(PredId, ProcIds, ProcTable, PredOrFunc,
+        SymName, Context, !IO).

 %----------------------------------------------------------------------------%


--------------------------------------------------------------------------
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