[m-rev.] diff: clean up mode_util.m

Julien Fischer juliensf at cs.mu.OZ.AU
Fri Aug 12 12:48:38 AEST 2005


Estimated hours taken: 0.5
Branches: main

Cleanups for mode_util.m.
There are no changes to any algorithms.

compiler/mode_util.m:
	Switch to four-space indentation throughout.

	Reformat comments to conform to our current coding standard.

	For some of the predicates, describe the conditions for
	which they may throw an exception.

	Use unexpected/2 in place of error/1

Julien.

Index: compiler/mode_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mode_util.m,v
retrieving revision 1.167
diff -u -b -r1.167 mode_util.m
--- compiler/mode_util.m	12 Aug 2005 02:33:09 -0000	1.167
+++ compiler/mode_util.m	12 Aug 2005 02:40:44 -0000
@@ -1,12 +1,15 @@
 %-----------------------------------------------------------------------------%
+% vim: ft=mercury ts=4 sw=4 et
+%-----------------------------------------------------------------------------%
 % Copyright (C) 1994-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.
 %-----------------------------------------------------------------------------%

-% mode_util.m - utility predicates dealing with modes and insts.
+% file: mode_util.m
+% main author: fjh

-% Main author: fjh.
+% This module contains utility predicates for dealing with modes and insts.

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

@@ -23,32 +26,45 @@
 :- import_module bool.
 :- import_module list.

-	% mode_get_insts returns the initial instantiatedness and
-	% the final instantiatedness for a given mode, aborting
-	% if the mode is undefined.
+%-----------------------------------------------------------------------------%
+
+    % mode_get_insts returns the initial instantiatedness and the final
+    % instantiatedness for a given mode.
+    % Throw an exception if the mode is undefined.
 	%
 :- pred mode_get_insts(module_info::in, (mode)::in, (inst)::out, (inst)::out)
 	is det.

-	% a version of mode_get_insts which fails if the mode is undefined
+    % A version of mode_get_insts that fails if the mode is undefined.
+    %
 :- pred mode_get_insts_semidet(module_info::in, (mode)::in,
 	(inst)::out, (inst)::out) is semidet.

-	% a mode is considered input if the initial inst is bound
+    % A mode is considered input if the initial inst is bound.
+    % Throws an exception if the mode is undefined.
+    %
 :- pred mode_is_input(module_info::in, (mode)::in) is semidet.

-	% a mode is considered fully input if the initial inst is ground
+    % A mode is considered fully input if the initial inst is ground.
+    % Throws an exception if the mode is undefined.
+    %
 :- pred mode_is_fully_input(module_info::in, (mode)::in) is semidet.

-	% a mode is considered output if the initial inst is free
-	% and the final inst is bound
+    % A mode is considered output if the initial inst is free and the
+    % final inst is bound.
+    % Throws an exception if the mode is undefined.
+    %
 :- pred mode_is_output(module_info::in, (mode)::in) is semidet.

-	% a mode is considered fully output if the initial inst is free and
-	% the final inst is ground
+    % A mode is considered fully output if the initial inst is free and
+    % the final inst is ground.
+    % Throws an exception if the mode is undefined.
+    %
 :- pred mode_is_fully_output(module_info::in, (mode)::in) is semidet.

-	% a mode is considered unused if both initial and final insts are free
+    % A mode is considered unused if both initial and final insts are free.
+    % Throws an exception if the mode is undefined.
+    %
 :- pred mode_is_unused(module_info::in, (mode)::in) is semidet.

 	% Succeeds iff the given mode is undefined.
@@ -79,19 +95,20 @@
 :- pred mode_util__modes_to_uni_modes(list(mode)::in, list(mode)::in,
 	module_info::in, list(uni_mode)::out) is det.

-	% Given a user-defined or compiler-defined inst name,
-	% lookup the corresponding inst in the inst table.
+    % Given a user-defined or compiler-defined inst name, lookup the
+    % corresponding inst in the inst table.
 	%
 :- pred inst_lookup(module_info::in, inst_name::in, (inst)::out) is det.

 	% Use the instmap deltas for all the atomic sub-goals to recompute
 	% the instmap deltas for all the non-atomic sub-goals of a goal.
-	% Used to ensure that the instmap deltas remain valid after
-	% code has been re-arranged, e.g. by followcode.
-	% This also takes the module_info as input and output since it
-	% may need to insert new merge_insts into the merge_inst table.
-	% If the first argument is yes, the instmap_deltas for calls
-	% and deconstruction unifications are also recomputed.
+    % Used to ensure that the instmap deltas remain valid after code has
+    % been re-arranged, e.g. by followcode.  This also takes the
+    % module_info as input and output since it may need to insert new
+    % merge_insts into the merge_inst table.  If the first argument is
+    % yes, the instmap_deltas for calls and deconstruction unifications
+    % are also recomputed.
+    %
 :- pred recompute_instmap_delta_proc(bool::in, proc_info::in, proc_info::out,
 	module_info::in, module_info::out) is det.

@@ -99,8 +116,8 @@
 	vartypes::in, inst_varset::in, instmap::in, module_info::in,
 	module_info::out) is det.

-	% Given corresponding lists of types and modes, produce a new
-	% list of modes which includes the information provided by the
+    % Given corresponding lists of types and modes, produce a new list
+    % of modes which includes the information provided by the
 	% corresponding types.
 	%
 :- pred propagate_types_into_mode_list(list(type)::in, module_info::in,
@@ -108,34 +125,41 @@

 	% Given corresponding lists of types and insts and a substitution
 	% for the type variables in the type, produce a new list of insts
-	% which includes the information provided by the corresponding types.
+    % which includes the information provided by the corresponding
+    % types.
 	%
 :- pred propagate_types_into_inst_list(list(type)::in, tsubst::in,
 	module_info::in, list(inst)::in, list(inst)::out) is det.

 	% Convert a list of constructors to a list of bound_insts where the
 	% arguments are `ground'.
-	% Note that the list(bound_inst) is not sorted and may contain
+    %
+    % NOTE: the list(bound_inst) is not sorted and may contain
 	% duplicates.
+    %
 :- pred constructors_to_bound_insts(list(constructor)::in, uniqueness::in,
 	module_info::in, list(bound_inst)::out) is det.

 	% Convert a list of constructors to a list of bound_insts where the
 	% arguments are `any'.
-	% Note that the list(bound_inst) is not sorted and may contain
+    %
+    % NOTE: the list(bound_inst) is not sorted and may contain
 	% duplicates.
+    %
 :- pred constructors_to_bound_any_insts(list(constructor)::in, uniqueness::in,
 	module_info::in, list(bound_inst)::out) is det.

-	% Given the mode of a predicate,
-	% work out which arguments are live (might be used again
-	% by the caller of that predicate) and which are dead.
+    % Given the mode of a predicate, work out which arguments are live
+    % (might be used again by the caller of that predicate) and which
+    % are dead.
+    %
 :- pred get_arg_lives(list(mode)::in, module_info::in, list(is_live)::out)
 	is det.

 	% Given the switched on variable and the instmaps before the switch
 	% and after a branch make sure that any information added by the
 	% functor test gets added to the instmap for the case.
+    %
 :- pred fixup_switch_var(prog_var::in, instmap::in, instmap::in,
 	hlds_goal::in, hlds_goal::out) is det.

@@ -150,6 +174,8 @@
 %-----------------------------------------------------------------------------%

 	% Partition a list of arguments into inputs and others.
+    % Throws an exception if one of the modes is undefined.
+    %
 :- pred partition_args(module_info::in, list(mode)::in, list(T)::in,
 	list(T)::out, list(T)::out) is det.

@@ -164,6 +190,7 @@
 :- import_module check_hlds__type_util.
 :- import_module hlds__hlds_data.
 :- import_module mdbcomp__prim_data.
+:- import_module parse_tree__error_util.
 :- import_module parse_tree__prog_io.
 :- import_module parse_tree__prog_mode.
 :- import_module parse_tree__prog_util.
@@ -193,22 +220,20 @@

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

-	% A mode is considered an input mode if the top-level
-	% node is input.
-
+    % A mode is considered an input mode if the top-level node is input.
+    %
 mode_is_input(ModuleInfo, Mode) :-
 	mode_get_insts(ModuleInfo, Mode, InitialInst, _FinalInst),
 	inst_is_bound(ModuleInfo, InitialInst).

 	% A mode is considered fully input if its initial inst is ground.
-
+    %
 mode_is_fully_input(ModuleInfo, Mode) :-
 	mode_get_insts(ModuleInfo, Mode, InitialInst, _FinalInst),
 	inst_is_ground(ModuleInfo, InitialInst).

-	% A mode is considered an output mode if the top-level
-	% node is output.
-
+    % A mode is considered an output mode if the top-level node is output.
+    %
 mode_is_output(ModuleInfo, Mode) :-
 	mode_get_insts(ModuleInfo, Mode, InitialInst, FinalInst),
 	inst_is_free(ModuleInfo, InitialInst),
@@ -216,15 +241,14 @@

 	% A mode is considered fully output if its initial inst is free
 	% and its final insts is ground.
-
+    %
 mode_is_fully_output(ModuleInfo, Mode) :-
 	mode_get_insts(ModuleInfo, Mode, InitialInst, FinalInst),
 	inst_is_free(ModuleInfo, InitialInst),
 	inst_is_ground(ModuleInfo, FinalInst).

-	% A mode is considered a unused mode if it is equivalent
-	% to free->free.
-
+    % A mode is considered a unused mode if it is equivalent to free >> free.
+    %
 mode_is_unused(ModuleInfo, Mode) :-
 	mode_get_insts(ModuleInfo, Mode, InitialInst, FinalInst),
 	inst_is_free(ModuleInfo, InitialInst),
@@ -243,7 +267,7 @@
 		modes_to_arg_modes(ModuleInfo, Modes1, Types1, ArgModes1),
 		ArgModes = [ArgMode | ArgModes1]
 	;
-		error("modes_to_arg_modes: length mismatch")
+        unexpected(this_file, "modes_to_arg_modes: length mismatch")
 	).

 mode_to_arg_mode(ModuleInfo, Mode, Type, ArgMode) :-
@@ -262,16 +286,16 @@
 	% will get optimized away.
 	%
 	(
-		% is this a no_tag type?
+        % Is this a no_tag type?
 		type_is_no_tag_type(ModuleInfo, Type, FunctorName, ArgType),
-		% avoid infinite recursion
+        % Avoid infinite recursion.
 		type_to_ctor_and_args(Type, TypeCtor, _TypeArgs),
 		\+ list__member(TypeCtor, ContainingTypes)
 	->
-		% the arg_mode will be determined by the mode and
-		% type of the functor's argument,
-		% so we figure out the mode and type of the argument,
-		% and then recurse
+        % The arg_mode will be determined by the mode and type of the
+        % functor's argument, so we figure out the mode and type of the
+        % argument, and then recurse.
+        %
 		mode_get_insts(ModuleInfo, Mode, InitialInst, FinalInst),
 		ConsId = cons(FunctorName, 1),
 		get_single_arg_inst(InitialInst, ModuleInfo, ConsId,
@@ -301,9 +325,9 @@
 %-----------------------------------------------------------------------------%

 	% get_single_arg_inst(Inst, ConsId, Arity, ArgInsts):
-	% Given an inst `Inst', figure out what the inst of the
-	% argument would be, assuming that the functor is
-	% the one given by the specified ConsId, whose arity is 1.
+    % Given an inst `Inst', figure out what the inst of the argument
+    % would be, assuming that the functor is the one given by the
+    % specified ConsId, whose arity is 1.
 	%
 :- pred get_single_arg_inst((inst)::in, module_info::in, cons_id::in,
 	(inst)::out) is det.
@@ -324,9 +348,10 @@
 get_single_arg_inst(free(_Type), _, _, free).	% XXX loses type info
 get_single_arg_inst(any(Uniq), _, _, any(Uniq)).
 get_single_arg_inst(abstract_inst(_, _), _, _, _) :-
-	error("get_single_arg_inst: abstract insts not supported").
+    unexpected(this_file,
+        "get_single_arg_inst: abstract insts not supported").
 get_single_arg_inst(inst_var(_), _, _, _) :-
-	error("get_single_arg_inst: inst_var").
+    unexpected(this_file, "get_single_arg_inst: inst_var").
 get_single_arg_inst(constrained_inst_vars(_, Inst), ModuleInfo, ConsId,
 		ArgInst) :-
 	get_single_arg_inst(Inst, ModuleInfo, ConsId, ArgInst).
@@ -343,14 +368,14 @@

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

-	% Given two lists of modes (inst mappings) of equal length,
-	% convert them into a single list of inst pair mappings.
-
+    % Given two lists of modes (inst mappings) of equal length, convert
+    % them into a single list of inst pair mappings.
+    %
 mode_util__modes_to_uni_modes([], [], _ModuleInfo, []).
 mode_util__modes_to_uni_modes([], [_|_], _, _) :-
-	error("mode_util__modes_to_uni_modes: length mismatch").
+    unexpected(this_file, "mode_util.modes_to_uni_modes: length mismatch").
 mode_util__modes_to_uni_modes([_|_], [], _, _) :-
-	error("mode_util__modes_to_uni_modes: length mismatch").
+    unexpected(this_file, "mode_util.modes_to_uni_modes: length mismatch").
 mode_util__modes_to_uni_modes([X|Xs], [Y|Ys], ModuleInfo, [A|As]) :-
 	mode_get_insts(ModuleInfo, X, InitialX, FinalX),
 	mode_get_insts(ModuleInfo, Y, InitialY, FinalY),
@@ -451,16 +476,18 @@
 	% Given corresponding lists of types and modes, produce a new
 	% list of modes which includes the information provided by the
 	% corresponding types.
-
+    %
 propagate_types_into_mode_list([], _, [], []).
 propagate_types_into_mode_list([Type | Types], ModuleInfo, [Mode0 | Modes0],
 		[Mode | Modes]) :-
 	propagate_type_into_mode(Type, ModuleInfo, Mode0, Mode),
 	propagate_types_into_mode_list(Types, ModuleInfo, Modes0, Modes).
 propagate_types_into_mode_list([], _, [_|_], []) :-
-	error("propagate_types_into_mode_list: length mismatch").
+    unexpected(this_file,
+        "propagate_types_into_mode_list: length mismatch").
 propagate_types_into_mode_list([_|_], _, [], []) :-
-	error("propagate_types_into_mode_list: length mismatch").
+    unexpected(this_file,
+        "propagate_types_into_mode_list: length mismatch").

 propagate_types_into_inst_list([], _, _, [], []).
 propagate_types_into_inst_list([Type | Types], Subst, ModuleInfo,
@@ -468,13 +495,15 @@
 	propagate_type_into_inst(Type, Subst, ModuleInfo, Inst0, Inst),
 	propagate_types_into_inst_list(Types, Subst, ModuleInfo, Insts0, Insts).
 propagate_types_into_inst_list([], _, _, [_|_], []) :-
-	error("propagate_types_into_inst_list: length mismatch").
+    unexpected(this_file,
+        "propagate_types_into_inst_list: length mismatch").
 propagate_types_into_inst_list([_|_], _, _, [], []) :-
-	error("propagate_types_into_inst_list: length mismatch").
-
-	% Given a type and a mode, produce a new mode which includes
-	% the information provided by the type.
+    unexpected(this_file,
+        "propagate_types_into_inst_list: length mismatch").

+    % Given a type and a mode, produce a new mode that includes the
+    % information provided by the type.
+    %
 :- pred propagate_type_into_mode((type)::in, module_info::in,
 	(mode)::in, (mode)::out) is det.

@@ -488,8 +517,8 @@
 	Mode = (InitialInst -> FinalInst).

 	% Given a type, an inst and a substitution for the type variables in
-	% the type, produce a new inst which includes the information provided
-	% by the type.
+    % the type, produce a new inst that includes the information
+    % provided by the type.
 	%
 	% There are three sorts of information added:
 	%	1.  Module qualifiers.
@@ -502,15 +531,15 @@
 	% Currently #2 is not yet implemented, due to unsolved
 	% efficiency problems.  (See the XXX's below.)
 	%
-	% There are two versions, an "eager" one and a "lazy" one.
-	% In general eager expansion is to be preferred, because
-	% the expansion is done just once, whereas with lazy expansion
-	% the work will be done N times.
-	% However, for recursive insts we must use lazy expansion
-	% (otherwise we would get infinite regress).
-	% Also, usually many of the imported procedures will not be called,
-	% so for the insts in imported mode declarations N is often zero.
-
+    % There are two versions, an "eager" one and a "lazy" one.  In
+    % general eager expansion is to be preferred, because the expansion
+    % is done just once, whereas with lazy expansion the work will be
+    % done N times.
+    % However, for recursive insts we must use lazy expansion (otherwise
+    % we would get infinite regress).  Also, usually many of the
+    % imported procedures will not be called, so for the insts in
+    % imported mode declarations N is often zero.
+    %
 :- pred propagate_type_into_inst((type)::in, tsubst::in, module_info::in,
 	(inst)::in, (inst)::out) is det.

@@ -548,7 +577,8 @@
 propagate_ctor_info(free, _Type, _, _, free).	% XXX temporary hack

 propagate_ctor_info(free(_), _, _, _, _) :-
-	error("propagate_ctor_info: type info already present").
+    unexpected(this_file,
+        "propagate_ctor_info: type info already present").
 propagate_ctor_info(bound(Uniq, BoundInsts0), Type, _Constructors, ModuleInfo,
 		Inst) :-
 	propagate_ctor_info_2(BoundInsts0, Type, ModuleInfo, BoundInsts),
@@ -581,10 +611,10 @@
 		propagate_types_into_mode_list(ArgTypes, ModuleInfo,
 			Modes0, Modes)
 	;
-		% The inst is not a valid inst for the type,
-		% so leave it alone. This can only happen if the user
-		% has made a mistake.  A mode error should hopefully
-		% be reported if anything tries to match with the inst.
+        % The inst is not a valid inst for the type, so leave it alone.
+        % This can only happen if the user has made a mistake.  A mode
+        % error should hopefully be reported if anything tries to match
+        % with the inst.
 		Modes = Modes0
 	).
 propagate_ctor_info(not_reached, _Type, _Constructors, _ModuleInfo,
@@ -840,9 +870,10 @@
 		abstract_inst(Name, Args)).

 %-----------------------------------------------------------------------------%
+
 	% mode_get_insts returns the initial instantiatedness and
 	% the final instantiatedness for a given mode.
-
+    %
 mode_get_insts_semidet(_ModuleInfo, (InitialInst -> FinalInst),
 		InitialInst, FinalInst).
 mode_get_insts_semidet(ModuleInfo, user_defined_mode(Name, Args),
@@ -857,12 +888,12 @@
 	mode_substitute_arg_list(Mode0, Params, Args, Mode),
 	mode_get_insts_semidet(ModuleInfo, Mode, Initial, Final).

-mode_get_insts(ModuleInfo, Mode, Inst1, Inst2) :-
-	( mode_get_insts_semidet(ModuleInfo, Mode, Inst1a, Inst2a) ->
-		Inst1 = Inst1a,
-		Inst2 = Inst2a
+mode_get_insts(ModuleInfo, Mode, InstA, InstB) :-
+    ( mode_get_insts_semidet(ModuleInfo, Mode, InstA0, InstB0) ->
+        InstA = InstA0,
+        InstB = InstB0
 	;
-		error("mode_get_insts_semidet failed")
+        unexpected(this_file, "mode_get_insts_semidet failed")
 	).

 %-----------------------------------------------------------------------------%
@@ -876,7 +907,7 @@
 	% instmap deltas for atomic goals, since more outputs of calls
 	% and deconstructions may become non-local (XXX does this require
 	% rerunning mode analysis rather than just recompute_instmap_delta?).
-
+    %
 recompute_instmap_delta_proc(RecomputeAtomic, !ProcInfo, !ModuleInfo) :-
 	proc_info_get_initial_instmap(!.ProcInfo, !.ModuleInfo, InstMap0),
 	proc_info_vartypes(!.ProcInfo, VarTypes),
@@ -936,6 +967,7 @@
 	% update_module_info(P, R, RI0, RI) will call predicate P, passing it
 	% the module_info from RI0 and placing the output module_info in RI.
 	% The output of P's first argument is returned in R.
+    %
 :- pred update_module_info(
 	pred(T, module_info, module_info)::in(pred(out, in, out) is det),
 	T::out, recompute_info::in, recompute_info::out) is det.
@@ -1072,7 +1104,8 @@

 recompute_instmap_delta_2(_, shorthand(_), _, _, _, _, _, !RI) :-
 	% these should have been expanded out by now
-	error("recompute_instmap_delta_2: unexpected shorthand").
+    unexpected(this_file,
+        "recompute_instmap_delta_2: unexpected shorthand").

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

@@ -1191,9 +1224,9 @@
 		mode_list_apply_substitution(ArgModes1, InstVarSub,
 			ArgModes2),

-		% Calculate the final insts of the argument variables
-		% from their initial insts and the final insts of the called
-		% procedure (with inst_var substitutions applied).
+        % Calculate the final insts of the argument variables from their
+        % initial insts and the final insts of the called procedure
+        % (with inst_var substitutions applied).
 		update_module_info(recompute_instmap_delta_call_2(Args, InstMap,
 			ArgModes2), ArgModes, !RI),
 		instmap_delta_from_mode_list(Args, ArgModes,
@@ -1206,9 +1239,9 @@

 compute_inst_var_sub([], _, _, [], !Sub, !ModuleInfo).
 compute_inst_var_sub([_|_], _, _, [], !Sub, !ModuleInfo) :-
-	error("compute_inst_var_sub").
+    unexpected(this_file, "compute_inst_var_sub").
 compute_inst_var_sub([], _, _, [_|_], !Sub, !ModuleInfo) :-
-	error("compute_inst_var_sub").
+    unexpected(this_file, "compute_inst_var_sub").
 compute_inst_var_sub([Arg | Args], VarTypes, InstMap, [Inst | Insts],
 		!Sub, !ModuleInfo) :-
 	% This is similar to modecheck_var_has_inst.
@@ -1245,9 +1278,9 @@

 recompute_instmap_delta_call_2([], _, [], [], !ModuleInfo).
 recompute_instmap_delta_call_2([_ | _], _, [], _, !ModuleInfo) :-
-	error("recompute_instmap_delta_call_2").
+    unexpected(this_file, "recompute_instmap_delta_call_2").
 recompute_instmap_delta_call_2([], _, [_ | _], _, !ModuleInfo) :-
-	error("recompute_instmap_delta_call_2").
+    unexpected(this_file, "recompute_instmap_delta_call_2").
 recompute_instmap_delta_call_2([Arg | Args], InstMap, [Mode0 | Modes0],
 		[Mode | Modes], !ModuleInfo) :-
 	% This is similar to modecheck_set_var_inst.
@@ -1260,7 +1293,8 @@
 		->
 			Mode = (ArgInst0 -> UnifyInst)
 		;
-			error("recompute_instmap_delta_call_2: " ++
+            unexpected(this_file,
+                "recompute_instmap_delta_call_2: " ++
 				"unify_inst failed")
 		)
 	;
@@ -1275,15 +1309,15 @@

 recompute_instmap_delta_unify(Uni, UniMode0, UniMode, GoalInfo,
 		InstMap, InstMapDelta, RI) :-
-	% Deconstructions are the only types of unifications
-	% that can require updating of the instmap_delta after simplify.m
-	% has been run.
+    % Deconstructions are the only types of unifications that can require
+    % updating of the instmap_delta after simplify.m has been run.
 	ModuleInfo = RI ^ module_info,
 	(
 		Uni = deconstruct(Var, _ConsId, Vars, UniModes, _, _CanCGC)
 	->
-		% Get the final inst of the deconstructed var, which
-		% will be the same as in the old instmap.
+        % Get the final inst of the deconstructed var, which will be the same
+        % as in the old instmap.
+        %
 		goal_info_get_instmap_delta(GoalInfo, OldInstMapDelta),
 		instmap__lookup_var(InstMap, Var, InitialInst),
 		( instmap_delta_search_var(OldInstMapDelta, Var, FinalInst1) ->
@@ -1295,7 +1329,7 @@
 			% we don't return that.
 			FinalInst = FinalInst1
 		;
-			% it wasn't in the instmap_delta, so the inst didn't
+            % It wasn't in the instmap_delta, so the inst didn't
 			% change.
 			FinalInst = InitialInst
 		),
@@ -1317,7 +1351,7 @@

 	% Arguments with final inst `clobbered' are dead, any
 	% others are assumed to be live.
-
+    %
 get_arg_lives([], _, []).
 get_arg_lives([Mode|Modes], ModuleInfo, [IsLive|IsLives]) :-
 	mode_get_insts(ModuleInfo, Mode, _InitialInst, FinalInst),
@@ -1332,19 +1366,19 @@
 %-----------------------------------------------------------------------------%

 normalise_insts([], [], _, []).
+normalise_insts([], [_|_], _, _) :-
+    unexpected(this_file, "normalise_insts: length mismatch").
+normalise_insts([_|_], [], _, _) :-
+    unexpected(this_file, "normalise_insts: length mismatch").
 normalise_insts([Inst0|Insts0], [Type|Types], ModuleInfo, [Inst|Insts]) :-
 	normalise_inst(Inst0, Type, ModuleInfo, Inst),
 	normalise_insts(Insts0, Types, ModuleInfo, Insts).
-normalise_insts([], [_|_], _, _) :-
-	error("normalise_insts: length mismatch").
-normalise_insts([_|_], [], _, _) :-
-	error("normalise_insts: length mismatch").

 	% This is a bit of a hack.
 	% The aim is to avoid non-termination due to the creation
 	% of ever-expanding insts.
 	% XXX should also normalise partially instantiated insts.
-
+    %
 normalise_inst(Inst0, Type, ModuleInfo, NormalisedInst) :-
 	inst_expand(ModuleInfo, Inst0, Inst),
 	( Inst = bound(_, _) ->
@@ -1401,10 +1435,8 @@

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

-partition_args(_, [], [_|_], _, _) :-
-	error("partition_args").
-partition_args(_, [_|_], [], _, _) :-
-	error("partition_args").
+partition_args(_, [], [_|_], _, _) :- unexpected(this_file, "partition_args").
+partition_args(_, [_|_], [], _, _) :- unexpected(this_file, "partition_args").
 partition_args(_, [], [], [], []).
 partition_args(ModuleInfo, [ArgMode | ArgModes], [Arg | Args],
 		InputArgs, OutputArgs) :-
@@ -1418,4 +1450,11 @@
 	).

 %-----------------------------------------------------------------------------%
+
+:- func this_file = string.
+
+this_file = "mode_util.m".
+
+%-----------------------------------------------------------------------------%
+:- end_module mode_util.
 %-----------------------------------------------------------------------------%

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