[m-rev.] diff: four-space modecheck_unify

Zoltan Somogyi zs at cs.mu.OZ.AU
Tue Aug 16 17:02:52 AEST 2005


compiler/modecheck_unify.m:
	Convert this modules to four-space indentation to reduce the number
	of bad line breaks. Fix some departures from our coding standards.

compiler/mercury_compile.m:
compiler/simplify.m:
	Fix some formatting.

Zoltan.

cvs diff: Diffing .
Index: mercury_compile.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/mercury_compile.m,v
retrieving revision 1.340
diff -u -b -r1.340 mercury_compile.m
--- mercury_compile.m	8 Aug 2005 02:37:16 -0000	1.340
+++ mercury_compile.m	16 Aug 2005 04:01:12 -0000
@@ -2718,8 +2718,7 @@
         %       mercury_compile.simplify.
         %
         ProfTrans = yes,
-        Simplifications = list.delete_all(Simplifications0,
-            constant_prop)
+        Simplifications = list.delete_all(Simplifications0, constant_prop)
     ;
         ProfTrans = no,
         Simplifications = Simplifications0
Index: modecheck_unify.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/modecheck_unify.m,v
retrieving revision 1.81
diff -u -b -r1.81 modecheck_unify.m
--- modecheck_unify.m	22 Jul 2005 12:31:58 -0000	1.81
+++ modecheck_unify.m	16 Aug 2005 04:04:30 -0000
@@ -1,4 +1,6 @@
 %-----------------------------------------------------------------------------%
+% vim: ft=mercury ts=4 sw=4 et
+%-----------------------------------------------------------------------------%
 % Copyright (C) 1996-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.
@@ -26,13 +28,15 @@
 
 :- import_module io.
 
-	% Modecheck a unification
+    % Modecheck a unification.
+    %
 :- pred modecheck_unification(prog_var::in, unify_rhs::in, unification::in,
 	unify_context::in, hlds_goal_info::in, hlds_goal_expr::out,
 	mode_info::in, mode_info::out, io::di, io::uo) is det.
 
 	% Create a unification between the two given variables.
-	% The goal's mode and determinism information is not filled in.
+    % The goal's mode and determinism information are not filled in.
+    %
 :- pred modecheck_unify__create_var_var_unification(prog_var::in, prog_var::in,
 	(type)::in, mode_info::in, hlds_goal::out) is det.
 
@@ -63,6 +67,7 @@
 :- import_module hlds__make_hlds.
 :- import_module hlds__quantification.
 :- import_module mdbcomp__prim_data.
+:- import_module parse_tree__error_util.
 :- import_module parse_tree__module_qual.
 :- import_module parse_tree__prog_mode.
 :- import_module parse_tree__prog_out.
@@ -120,14 +125,13 @@
 		;
 			BothLive = dead
 		),
-		abstractly_unify_inst(BothLive, InstOfX, InstOfY,
-			real_unify, UnifyInst, Det1, ModuleInfo0, ModuleInfo1),
-		% Don't allow free-free unifications if both variables are
-		% locked.  (Normally the checks for binding locked variables
-		% are done in modecheck_set_var_inst, which is called below,
-		% but that won't catch this case, because the inst of the
-		% variable will remain `free'.  XXX are there other cases
-		% like this one?)
+        abstractly_unify_inst(BothLive, InstOfX, InstOfY, real_unify,
+            UnifyInst, Det1, ModuleInfo0, ModuleInfo1),
+        % Don't allow free-free unifications if both variables are locked.
+        % (Normally the checks for binding locked variables are done in
+        % modecheck_set_var_inst, which is called below, but that won't catch
+        % this case, because the inst of the variable will remain `free'.
+        % XXX are there other cases like this one?)
 		\+ (
 			UnifyInst = free,
 			mode_info_var_is_locked(!.ModeInfo, X, _XLockedReason),
@@ -145,8 +149,7 @@
 		ModeOfX = (InstOfX -> Inst),
 		ModeOfY = (InstOfY -> Inst),
 		categorize_unify_var_var(ModeOfX, ModeOfY, LiveX, LiveY, X, Y,
-			Det, UnifyContext, VarTypes, Unification0, Unify0,
-			!ModeInfo),
+            Det, UnifyContext, VarTypes, Unification0, Unify0, !ModeInfo),
 		(
 			MaybeInitX = no,
 			Unify      = Unify0
@@ -154,22 +157,19 @@
 			MaybeInitX = yes(InitGoal - InitGoalInfo),
 			modes__compute_goal_instmap_delta(InstMap, Unify0,
 				UnifyGoalInfo0, UnifyGoalInfo, !ModeInfo),
-			Unify      = conj([InitGoal - InitGoalInfo,
-					   Unify0 - UnifyGoalInfo])
+            Unify = conj([InitGoal - InitGoalInfo, Unify0 - UnifyGoalInfo])
 		)
 	;
 		set__list_to_set([X, Y], WaitingVars),
-		mode_info_error(WaitingVars, mode_error_unify_var_var(X, Y,
-				InstOfX, InstOfY), !ModeInfo),
-			% If we get an error, set the inst to not_reached
-			% to suppress follow-on errors
-			% But don't call categorize_unification, because
-			% that could cause an invalid call to
-			% `unify_proc__request_unify'
+        mode_info_error(WaitingVars,
+            mode_error_unify_var_var(X, Y, InstOfX, InstOfY), !ModeInfo),
+            % If we get an error, set the inst to not_reached to suppress
+            % follow-on errors. But don't call categorize_unification, because
+            % that could cause an invalid call to `unify_proc__request_unify'
 		Inst = not_reached,
 		modecheck_set_var_inst(X, Inst, no, !ModeInfo),
 		modecheck_set_var_inst(Y, Inst, no, !ModeInfo),
-			% return any old garbage
+            % Return any old garbage.
 		Unification = assign(X, Y),
 		ModeOfX = (InstOfX -> Inst),
 		ModeOfY = (InstOfY -> Inst),
@@ -178,8 +178,7 @@
 	).
 
 modecheck_unification(X0, functor(ConsId0, IsExistConstruction, ArgVars0),
-		Unification0, UnifyContext, GoalInfo0, Goal,
-		!ModeInfo, !IO) :-
+        Unification0, UnifyContext, GoalInfo0, Goal, !ModeInfo, !IO) :-
 	mode_info_get_module_info(!.ModeInfo, ModuleInfo0),
 	mode_info_get_var_types(!.ModeInfo, VarTypes0),
 	map__lookup(VarTypes0, X0, TypeOfX),
@@ -206,9 +205,7 @@
 			PredArgTypes),
 		ConsId0 = pred_const(ShroudedPredProcId, _)
 	->
-		%
-		% convert the pred term to a lambda expression
-		%
+        % Convert the pred term to a lambda expression.
 		mode_info_get_varset(!.ModeInfo, VarSet0),
 		mode_info_get_context(!.ModeInfo, Context),
 		proc(PredId, ProcId) =
@@ -220,27 +217,23 @@
 			VarSet0, VarSet, VarTypes0, VarTypes),
 		mode_info_set_varset(VarSet, !ModeInfo),
 		mode_info_set_var_types(VarTypes, !ModeInfo),
-		%
-		% modecheck this unification in its new form
-		%
+
+        % Modecheck this unification in its new form.
 		modecheck_unification(X0, Functor0, Unification0, UnifyContext,
 			GoalInfo0, Goal, !ModeInfo, !IO)
 	;
-		%
 		% It's not a higher-order pred unification - just
 		% call modecheck_unify_functor to do the ordinary thing.
-		%
 		modecheck_unify_functor(X0, TypeOfX, ConsId0,
 			IsExistConstruction, ArgVars0, Unification0,
 			UnifyContext, GoalInfo0, Goal, !ModeInfo, !IO)
 	).
 
-modecheck_unification(X, lambda_goal(Purity, PredOrFunc, EvalMethod, _,
+modecheck_unification(X, LambdaGoal, Unification0, UnifyContext, _GoalInfo,
+        unify(X, RHS, Mode, Unification, UnifyContext), !ModeInfo, !IO) :-
+    LambdaGoal = lambda_goal(Purity, PredOrFunc, EvalMethod, _,
 			ArgVars, Vars, Modes0, Det, Goal0),
-		Unification0, UnifyContext, _GoalInfo,
-		unify(X, RHS, Mode, Unification, UnifyContext),
-		!ModeInfo, !IO) :-
-	%
+
 	% First modecheck the lambda goal itself:
 	%
 	% initialize the initial insts of the lambda variables,
@@ -256,26 +249,24 @@
 	%
 	% XXX or should we merge the original and the final instmaps???
 	%
-	% The reason that we need to merge the original and final instmaps
-	% is as follows.  The lambda goal will not have bound any variables
-	% (since they were locked), but it may have added some information
-	% or lost some uniqueness.  We cannot use the final instmap,
-	% because that may have too much information.  If we use the
-	% initial instmap, variables will be considered as unique
-	% even if they become shared or clobbered in the lambda goal!
-	%
-	% However even this may not be enough.  If a unique non-local
-	% variable is used in its unique inst (e.g. it's used in a ui
-	% mode) and then shared within the lambda body, this is unsound.
-	% This variable should be marked as shared at the _top_ of the
-	% lambda goal.  As for implementing this, it probably means that
-	% the lambda goal should be re-modechecked, or even modechecked
-	% to a fixpoint.
-	%
-	% For the moment, since doing all that properly seems too hard,
-	% we just share all non-local variables at the top of the lambda goal.
-	% This is safe, but perhaps too conservative.
-	%
+    % The reason that we need to merge the original and final instmaps is
+    % as follows. The lambda goal will not have bound any variables (since
+    % they were locked), but it may have added some information or lost some
+    % uniqueness. We cannot use the final instmap, because that may have
+    % too much information. If we use the initial instmap, variables will be
+    % considered as unique even if they become shared or clobbered in the
+    % lambda goal!
+    %
+    % However even this may not be enough.  If a unique non-local variable
+    % is used in its unique inst (e.g. it's used in a ui mode) and then shared
+    % within the lambda body, this is unsound. This variable should be marked
+    % as shared at the _top_ of the lambda goal. As for implementing this,
+    % it probably means that the lambda goal should be re-modechecked,
+    % or even modechecked to a fixpoint.
+    %
+    % For the moment, since doing all that properly seems too hard, we just
+    % share all non-local variables at the top of the lambda goal. This is
+    % safe, but perhaps too conservative.
 
 	mode_info_get_module_info(!.ModeInfo, ModuleInfo0),
 	mode_info_get_how_to_check(!.ModeInfo, HowToCheckGoal),
@@ -283,13 +274,12 @@
 	( HowToCheckGoal = check_modes ->
 		% This only needs to be done once.
 		mode_info_get_types_of_vars(!.ModeInfo, Vars, VarTypes),
-		propagate_types_into_mode_list(VarTypes, ModuleInfo0,
-			Modes0, Modes)
+        propagate_types_into_mode_list(VarTypes, ModuleInfo0, Modes0, Modes)
 	;
 		Modes = Modes0
 	),
 
-	% initialize the initial insts of the lambda variables
+    % Initialize the initial insts of the lambda variables.
 	mode_list_get_initial_insts(Modes, ModuleInfo0, VarInitialInsts),
 	assoc_list__from_corresponding_lists(Vars, VarInitialInsts, VarInstAL),
 	instmap_delta_from_assoc_list(VarInstAL, VarInstMapDelta),
@@ -297,15 +287,14 @@
 	instmap__apply_instmap_delta(InstMap0, VarInstMapDelta, InstMap1),
 	mode_info_set_instmap(InstMap1, !ModeInfo),
 
-	% mark the non-clobbered lambda variables as live
+    % Mark the non-clobbered lambda variables as live.
 	get_arg_lives(Modes, ModuleInfo0, ArgLives),
 	get_live_vars(Vars, ArgLives, LiveVarsList),
 	set__list_to_set(LiveVarsList, LiveVars),
 	mode_info_add_live_vars(LiveVars, !ModeInfo),
 
-	% lock the non-locals
-	% (a lambda goal is not allowed to bind any of the non-local
-	% variables, since it could get called more than once, or
+    % Lock the non-locals. (A lambda goal is not allowed to bind any of the
+    % non-local variables, since it could get called more than once, or
 	% from inside a negation)
 	Goal0 = _ - GoalInfo0,
 	goal_info_get_nonlocals(GoalInfo0, NonLocals0),
@@ -316,28 +305,24 @@
 	(
 		% XXX This test is too conservative.
 		%
-		%     We should allow non-local variables to be non-ground
-		%     sometimes, possibly dependent on whether or not they
-		%     are dead after this unification.  In addition, we
-		%     should not "share" a unique non-local variable if
-		%     these two conditions hold:
+        % We should allow non-local variables to be non-ground sometimes,
+        % possibly dependent on whether or not they are dead after this
+        % unification. In addition, we should not "share" a unique non-local
+        % variable if these two conditions hold:
 		%
 		%	- It is dead after this unification.
 		%	- It is not shared within the lambda body.
 		%
-		%     Unfortunately, we can't test the latter condition
-		%     until after we've mode-checked the lambda body.
-		%     (See the above comment on merging the initial and
-		%     final instmaps.)
+        % Unfortunately, we can't test the latter condition until after
+        % we've mode-checked the lambda body. (See the above comment on
+        % merging the initial and final instmaps.)
 
 		% XXX This test is also not conservative enough!
 		%
-		%     We should not allow non-local vars to have inst `any';
-		%     because that can lead to unsoundness.
-		%     However, disallowing that idiom would break
-		%     extras/trailed_update/samples/vqueens.m, and
-		%     would make freeze/3 basically useless...
-		%     so for now at least, let's not disallow it,
+        % We should not allow non-local vars to have inst `any'; because that
+        % can lead to unsoundness. However, disallowing that idiom would break
+        % extras/trailed_update/samples/vqueens.m, and would make freeze/3
+        % basically useless... so for now at least, let's not disallow it,
 		%     even though it is unsafe.
 
 		inst_list_is_ground_or_any(NonLocalInsts, ModuleInfo2)
@@ -352,7 +337,7 @@
 		mode_info_lock_vars(lambda(PredOrFunc), NonLocals, !ModeInfo),
 
 		mode_checkpoint(enter, "lambda goal", !ModeInfo, !IO),
-		% if we're being called from unique_modes.m, then we need to
+        % If we're being called from unique_modes.m, then we need to
 		% call unique_modes__check_goal rather than modecheck_goal.
 		(
 			HowToCheckGoal = check_unique_modes
@@ -362,26 +347,20 @@
 			modecheck_goal(Goal0, Goal1, !ModeInfo, !IO)
 		),
 		mode_list_get_final_insts(Modes, ModuleInfo0, FinalInsts),
-		modecheck_lambda_final_insts(Vars, FinalInsts, Goal1, Goal,
-			!ModeInfo),
+        modecheck_lambda_final_insts(Vars, FinalInsts, Goal1, Goal, !ModeInfo),
 		mode_checkpoint(exit, "lambda goal", !ModeInfo, !IO),
 
 		mode_info_remove_live_vars(LiveVars, !ModeInfo),
-		mode_info_unlock_vars(lambda(PredOrFunc), NonLocals,
-			!ModeInfo),
+        mode_info_unlock_vars(lambda(PredOrFunc), NonLocals, !ModeInfo),
 
-		%
 		% Ensure that the non-local vars are shared OUTSIDE the
 		% lambda unification as well as inside.
-		%
 
 		instmap__set_vars(InstMap0, NonLocalsList, SharedNonLocalInsts,
 			InstMap11),
 		mode_info_set_instmap(InstMap11, !ModeInfo),
 
-		%
 		% Now modecheck the unification of X with the lambda-expression.
-		%
 
 		RHS0 = lambda_goal(Purity, PredOrFunc, EvalMethod,
 			modes_are_ok, ArgVars, Vars, Modes, Det, Goal),
@@ -396,13 +375,11 @@
 			instmap__lookup_var(InstMap1, BadVar, BadInst),
 			set__singleton_set(WaitingVars, BadVar),
 			mode_info_error(WaitingVars,
-				mode_error_non_local_lambda_var(BadVar,
-					BadInst),
-				!ModeInfo)
+                mode_error_non_local_lambda_var(BadVar, BadInst), !ModeInfo)
 		;
 			error("modecheck_unification(lambda): very strange var")
 		),
-			% return any old garbage
+            % Return any old garbage.
 		RHS = lambda_goal(Purity, PredOrFunc, EvalMethod, modes_are_ok,
 			ArgVars, Vars, Modes0, Det, Goal0),
 		Mode = (free -> free) - (free -> free),
@@ -434,26 +411,23 @@
 		% from their current insts to the same inst
 		instmap__lookup_vars(ArgVars, InstMap0, ArgInsts),
 		inst_lists_to_mode_list(ArgInsts, ArgInsts, ArgModes),
-		categorize_unify_var_lambda(ModeOfX, ArgModes,
-			X, ArgVars, PredOrFunc, RHS0, RHS,
-			Unification0, Unification, !ModeInfo),
+        categorize_unify_var_lambda(ModeOfX, ArgModes, X, ArgVars, PredOrFunc,
+            RHS0, RHS, Unification0, Unification, !ModeInfo),
 		modecheck_set_var_inst(X, Inst, no, !ModeInfo)
 	;
 		set__list_to_set([X], WaitingVars),
 		mode_info_error(WaitingVars,
 			mode_error_unify_var_lambda(X, InstOfX, InstOfY),
 			!ModeInfo),
-			% If we get an error, set the inst to not_reached
-			% to avoid cascading errors
-			% But don't call categorize_unification, because
-			% that could cause an invalid call to
-			% `unify_proc__request_unify'
+        % If we get an error, set the inst to not_reached to avoid cascading
+        % errors. But don't call categorize_unification, because that could
+        % cause an invalid call to `unify_proc__request_unify'
 		Inst = not_reached,
 		modecheck_set_var_inst(X, Inst, no, !ModeInfo),
 		ModeOfX = (InstOfX -> Inst),
 		ModeOfY = (InstOfY -> Inst),
 		Mode = ModeOfX - ModeOfY,
-			% return any old garbage
+            % Return any old garbage.
 		Unification = Unification0,
 		RHS = RHS0
 	).
@@ -468,26 +442,23 @@
 	mode_info_get_module_info(!.ModeInfo, ModuleInfo0),
 	mode_info_get_how_to_check(!.ModeInfo, HowToCheckGoal),
 
-	%
-	% Fully module qualify all cons_ids
-	% (except for builtins such as ints and characters).
-	%
+    % Fully module qualify all cons_ids (except for builtins such as
+    % ints and characters).
+
 	qualify_cons_id(TypeOfX, ArgVars0, ConsId0, ConsId, InstConsId),
 
 	mode_info_get_instmap(!.ModeInfo, InstMap0),
 	instmap__lookup_var(InstMap0, X0, InstOfX0),
 	(
-		% If the unification was originally of the form
-		% X = 'new f'(Y) it must be classified as a
-		% construction. If it were classified as a
-		% deconstruction, the argument unifications would
-		% be ill-typed.
+        % If the unification was originally of the form X = 'new f'(Y),
+        % it must be classified as a construction. If it were classified as a
+        % deconstruction, the argument unifications would be ill-typed.
 		IsExistConstruction = yes,
 		\+ inst_is_free(ModuleInfo0, InstOfX0)
 	->
-		% To make sure the unification is classified as
-		% a construction, if X is already bound, we must
-		% add a unification with an extra variable:
+        % To make sure the unification is classified as a construction,
+        % if X is already bound, we must add a unification with an extra
+        % variable:
 		%	Z = 'new f'(Y),
 		%	X = Z.
 
@@ -501,17 +472,16 @@
 		ExtraGoals0 = no_extra_goals
 	),
 
-		% This needs to come after make_complicated_sub_unify
-		% because make_complicated_sub_unify may introduce
-		% new variables whose types we need to look-up.
+        % This needs to come after make_complicated_sub_unify because
+        % make_complicated_sub_unify may introduce new variables
+        % whose types we need to look-up.
 		%
 	mode_info_get_var_types(!.ModeInfo, VarTypes),
 	(
-		% If we are allowed to insert solver type initialisation
-		% calls and InstOfX0 is free and all ArgVars0 are either
-		% non-free or have solver types, then we know that this
-		% is going to be a construction, so we can insert the
-		% necessary initialisation calls.
+        % If we are allowed to insert solver type initialisation calls and
+        % InstOfX0 is free and all ArgVars0 are either non-free or have
+        % solver types, then we know that this is going to be a construction,
+        % so we can insert the necessary initialisation calls.
 		ArgVars0 \= [],
 		HowToCheckGoal \= check_unique_modes,
 		inst_match__inst_is_free(ModuleInfo0, InstOfX),
@@ -538,10 +508,9 @@
 	InstOfY = bound(unique, [functor(InstConsId, InstArgs)]),
 	(
 
-		% The occur check: X = f(X) is considered a mode error
-		% unless X is ground.  (Actually it wouldn't be that
-		% hard to generate code for it - it always fails! -
-		% but it's most likely to be a programming error,
+        % The occur check: X = f(X) is considered a mode error unless X is
+        % ground. (Actually it wouldn't be that hard to generate code for it
+        % - it always fails! - but it's most likely to be a programming error,
 		% so it's better to report it.)
 
 		list__member(X, ArgVars0),
@@ -554,11 +523,9 @@
 			!ModeInfo),
 		Inst = not_reached,
 		Det = erroneous,
-			% If we get an error, set the inst to not_reached
-			% to avoid cascading errors
-			% But don't call categorize_unification, because
-			% that could cause an invalid call to
-			% `unify_proc__request_unify'
+            % If we get an error, set the inst to not_reached to avoid
+            % cascading errors. But don't call categorize_unification, because
+            % that could cause an invalid call to `unify_proc__request_unify'.
 		ModeOfX = (InstOfX -> Inst),
 		ModeOfY = (InstOfY -> Inst),
 		Mode = ModeOfX - ModeOfY,
@@ -574,14 +541,13 @@
 		ArgVars = ArgVars0,
 		ExtraGoals2 = no_extra_goals
 	;
-			% XXX We forbid the construction of partially
-			% instantiated structures involving solver
-			% types.  We'd like to forbid all such constructions
-			% here, but that causes trouble with the current
-			% implementation of term.term_to_univ_special_case
-			% which does use partial instantiation (in a rather
-			% horrible way).  This is a hacky solution that gets
-			% us most of what we want w.r.t. solver types.
+            % XXX We forbid the construction of partially instantiated
+            % structures involving solver types. We'd like to forbid all
+            % such constructions here, but that causes trouble with the current
+            % implementation of term.term_to_univ_special_case which does
+            % use partial instantiation (in a rather horrible way). This is
+            % a hacky solution that gets us most of what we want w.r.t.
+            % solver types.
 		not (
 			inst_is_free(ModuleInfo0, InstOfX),
 			list__member(InstArg, InstArgs),
@@ -606,8 +572,8 @@
 			error("get_mode_of_args failed")
 		),
 		(
-			inst_expand_and_remove_constrained_inst_vars(
-				ModuleInfo1, InstOfX, InstOfX1),
+            inst_expand_and_remove_constrained_inst_vars(ModuleInfo1,
+                InstOfX, InstOfX1),
 			list__length(ArgVars0, Arity),
 			get_arg_insts(InstOfX1, InstConsId, Arity,
 				InstOfXArgs0),
@@ -638,11 +604,9 @@
 			mode_error_unify_var_functor(X, InstConsId, ArgVars0,
 				InstOfX, InstArgs),
 			!ModeInfo),
-			% If we get an error, set the inst to not_reached
-			% to avoid cascading errors
-			% But don't call categorize_unification, because
-			% that could cause an invalid call to
-			% `unify_proc__request_unify'
+            % If we get an error, set the inst to not_reached to avoid
+            % cascading errors. But don't call categorize_unification, because
+            % that could cause an invalid call to `unify_proc__request_unify'.
 		Inst = not_reached,
 		Det = erroneous,
 		ModeOfX = (InstOfX -> Inst),
@@ -655,7 +619,7 @@
 		;
 			error("bind_args failed")
 		),
-			% return any old garbage
+            % Return any old garbage.
 		Unification = Unification0,
 		ArgVars = ArgVars0,
 		ExtraGoals2 = no_extra_goals
@@ -675,24 +639,23 @@
 	;
 		Det = failure
 	->
-		% This optimisation is safe because the only way that
-		% we can analyse a unification as having no solutions
-		% is that the unification always fails.
+        % This optimisation is safe because the only way that we can analyse
+        % a unification as having no solutions is that the unification always
+        % fails.
 		%
-		% Unifying two preds is not erroneous as far as the
-		% mode checker is concerned, but a mode _error_.
+        % Unifying two preds is not erroneous as far as the mode checker
+        % is concerned, but a mode _error_.
 		Goal = disj([])
 	;
 		Functor = functor(ConsId, IsExistConstruction, ArgVars),
 		Unify = unify(X, Functor, Mode, Unification, UnifyContext),
 		%
-		% modecheck_unification sometimes needs to introduce
-		% new goals to handle complicated sub-unifications
-		% in deconstructions. The only time this can happen
-		% during unique mode analysis is if the instmap is
-		% unreachable, since inst_is_bound succeeds for not_reached.
-		% (If it did in other cases, the code would be wrong since it
-		% wouldn't have the correct determinism annotations.)
+        % Modecheck_unification sometimes needs to introduce new goals
+        % to handle complicated sub-unifications in deconstructions.
+        % The only time this can happen during unique mode analysis is if
+        % the instmap is unreachable, since inst_is_bound succeeds for
+        % not_reached. (If it did in other cases, the code would be wrong
+        % since it wouldn't have the correct determinism annotations.)
 		%
 		append_extra_goals(ExtraGoals0, ExtraGoals1, ExtraGoals01),
 		append_extra_goals(ExtraGoals01, ExtraGoals2, ExtraGoals),
@@ -701,14 +664,14 @@
 			ExtraGoals \= no_extra_goals,
 			instmap__is_reachable(InstMap1)
 		->
-			error("unique_modes.m: re-modecheck of unification " ++
+            unexpected(this_file,
+                "re-modecheck of unification " ++
 				"encountered complicated sub-unifies")
 		;
 			true
 		),
 		handle_extra_goals(Unify, ExtraGoals, GoalInfo0,
-			[X0 | ArgVars0], [X | ArgVars], InstMap0, Goal,
-			!ModeInfo, !IO)
+            [X0 | ArgVars0], [X | ArgVars], InstMap0, Goal, !ModeInfo, !IO)
 	).
 
 :- pred all_arg_vars_are_non_free_or_solver_vars(list(prog_var)::in,
@@ -727,12 +690,12 @@
 
 all_arg_vars_are_non_free_or_solver_vars([Arg | Args], [Inst | Insts],
 		VarTypes, ModuleInfo, ArgsToInit) :-
-	( if inst_match__inst_is_free(ModuleInfo, Inst) then
+    ( inst_match__inst_is_free(ModuleInfo, Inst) ->
 		type_is_solver_type(ModuleInfo, VarTypes ^ elem(Arg)),
-		ArgsToInit = [Arg | ArgsToInit0],
 		all_arg_vars_are_non_free_or_solver_vars(Args, Insts,
-			VarTypes, ModuleInfo, ArgsToInit0)
-	  else
+            VarTypes, ModuleInfo, ArgsToInit1),
+        ArgsToInit = [Arg | ArgsToInit1]
+    ;
 	  	all_arg_vars_are_non_free_or_solver_vars(Args, Insts,
 			VarTypes, ModuleInfo, ArgsToInit)
 	).
@@ -743,7 +706,7 @@
 	% unification must be simple assignments, they cannot be
 	% complicated unifications.  If they are, we split them out
 	% into separate unifications by introducing fresh variables here.
-
+    %
 :- pred split_complicated_subunifies(unification::in, unification::out,
 	list(prog_var)::in, list(prog_var)::out, extra_goals::out,
 	mode_info::in, mode_info::out) is det.
@@ -751,8 +714,7 @@
 split_complicated_subunifies(Unification0, Unification, ArgVars0, ArgVars,
 		ExtraGoals, !ModeInfo) :-
 	(
-		Unification0 = deconstruct(X, ConsId, ArgVars0, ArgModes0,
-			Det, CanCGC)
+        Unification0 = deconstruct(X, ConsId, ArgVars0, ArgModes0, Det, CanCGC)
 	->
 		(
 			split_complicated_subunifies_2(ArgVars0, ArgModes0,
@@ -760,10 +722,15 @@
 		->
 			ExtraGoals = ExtraGoals1,
 			ArgVars = ArgVars1,
-			Unification = deconstruct(X, ConsId, ArgVars,
-				ArgModes0, Det, CanCGC)
+            Unification = deconstruct(X, ConsId, ArgVars, ArgModes0, Det,
+                CanCGC)
 		;
-			error("split_complicated_subunifies_2 failed")
+/* ### In clause for predicate `check_hlds.modecheck_unify.split_complicated_subunifies/7': */
+/* ###   in argument 1 of call to predicate `unexpected/2': */
+/* ###   error: undefined symbol `this_file/0'. */
+/* ### In clause for predicate `check_hlds.modecheck_unify.split_complicated_subunifies/7': */
+/* ###   error: undefined predicate `unexpected/2'. */
+            unexpected(this_file, "split_complicated_subunifies_2 failed")
 		)
 	;
 		Unification = Unification0,
@@ -790,7 +757,7 @@
 	->
 		make_complicated_sub_unify(Var0, Var, ExtraGoals0, !ModeInfo),
 
-		% recursive call to handle the remaining variables...
+        % Recursive call to handle the remaining variables...
 		split_complicated_subunifies_2(Vars0, UniModes0,
 			Vars1, ExtraGoals1, !ModeInfo),
 		Vars = [Var | Vars1],
@@ -817,8 +784,7 @@
 	modecheck_unify__create_var_var_unification(Var0, Var,
 		VarType, !.ModeInfo, ExtraGoal),
 
-	% insert the new unification at
-	% the start of the extra goals
+    % Insert the new unification at the start of the extra goals.
 	ExtraGoals0 = extra_goals([], [ExtraGoal]).
 
 modecheck_unify__create_var_var_unification(Var0, Var, Type, ModeInfo,
@@ -832,7 +798,7 @@
 		MainContext, SubContexts, Goal0 - GoalInfo0),
 
 	%
-	% compute the goal_info nonlocal vars for the newly created goal
+    % Compute the goal_info nonlocal vars for the newly created goal
 	% (excluding the type_info vars -- they are added below).
 	% N.B. This may overestimate the set of non-locals,
 	% but that shouldn't cause any problems.
@@ -843,7 +809,7 @@
 
 	%
 	% Look up the map(tvar, type_info_locn) in the proc_info,
-	% since it is needed by polymorphism__unification_typeinfos
+    % since it is needed by polymorphism__unification_typeinfos.
 	%
 	mode_info_get_module_info(ModeInfo, ModuleInfo),
 	mode_info_get_predid(ModeInfo, PredId),
@@ -864,22 +830,26 @@
 			Unification0, Unification, GoalInfo2, GoalInfo),
 		Goal = unify(X, Y, Mode, Unification, FinalUnifyContext)
 	;
-		error("modecheck_unify__create_var_var_unification")
+/* ### In clause for predicate `check_hlds.modecheck_unify.create_var_var_unification/5': */
+/* ###   in argument 1 of call to predicate `unexpected/2': */
+/* ###   error: undefined symbol `this_file/0'. */
+/* ### In clause for predicate `check_hlds.modecheck_unify.create_var_var_unification/5': */
+/* ###   error: undefined predicate `unexpected/2'. */
+        unexpected(this_file, "modecheck_unify__create_var_var_unification")
 	).
 
 %-----------------------------------------------------------------------------%
 
-	% Work out what kind of unification a var-var unification is.
+    % categorize_unify_var_var works out which category a unification
+    % between a variable and another variable expression is - whether it is
+    % an assignment, a simple test or a complicated unify.
+    %
 :- pred categorize_unify_var_var((mode)::in, (mode)::in,
 	is_live::in, is_live::in, prog_var::in,
 	prog_var::in, determinism::in, unify_context::in,
 	map(prog_var, type)::in, unification::in, hlds_goal_expr::out,
 	mode_info::in, mode_info::out) is det.
 
-% categorize_unify_var_var works out which category a unification
-% between a variable and another variable expression is - whether it is
-% an assignment, a simple test or a complicated unify.
-
 categorize_unify_var_var(ModeOfX, ModeOfY, LiveX, LiveY, X, Y, Det,
 		UnifyContext, VarTypes, Unification0, Unify, !ModeInfo) :-
 	mode_info_get_module_info(!.ModeInfo, ModuleInfo0),
@@ -896,14 +866,19 @@
 		mode_is_unused(ModuleInfo0, ModeOfY)
 	->
 		% For free-free unifications, we pretend for a moment that they
-		% are an assignment to the dead variable - they will then
+        % are an assignment to the dead variable - they will then.
 		% be optimized away.
 		( LiveX = dead ->
 			Unification = assign(X, Y)
 		; LiveY = dead ->
 			Unification = assign(Y, X)
 		;
-			error("categorize_unify_var_var: free-free unify!")
+/* ### In clause for predicate `check_hlds.modecheck_unify.categorize_unify_var_var/13': */
+/* ###   in argument 1 of call to predicate `unexpected/2': */
+/* ###   error: undefined symbol `this_file/0'. */
+/* ### In clause for predicate `check_hlds.modecheck_unify.categorize_unify_var_var/13': */
+/* ###   error: undefined predicate `unexpected/2'. */
+            unexpected(this_file, "categorize_unify_var_var: free-free unify!")
 		)
 	;
 		%
@@ -923,26 +898,23 @@
 		map__lookup(VarTypes, X, Type),
 		(
 			type_is_atomic(Type, ModuleInfo0),
-			not type_has_user_defined_equality_pred(ModuleInfo0,
-				Type, _)
+            not type_has_user_defined_equality_pred(ModuleInfo0, Type, _)
 		->
 			Unification = simple_test(X, Y)
 		;
-			modecheck_complicated_unify(X, Y,
-				Type, ModeOfX, ModeOfY, Det, UnifyContext,
-				Unification0, Unification, !ModeInfo)
+            modecheck_complicated_unify(X, Y, Type, ModeOfX, ModeOfY, Det,
+                UnifyContext, Unification0, Unification, !ModeInfo)
 		)
 	),
 	%
-	% Optimize away unifications with dead variables
-	% and simple tests that cannot fail
-	% by replacing them with `true'.
-	% (The optimization of simple tests is necessary
-	% because otherwise determinism analysis assumes they can fail.
-	% The optimization of assignments to dead variables may be
+    % Optimize away unifications with dead variables and simple tests that
+    % cannot fail by replacing them with `true'. (The optimization of simple
+    % tests is necessary because otherwise determinism analysis assumes they
+    % can fail. The optimization of assignments to dead variables may be
 	% necessary to stop the code generator from getting confused.)
-	% Optimize away unifications which always fail by replacing
-	% them with `fail'.
+    %
+    % Optimize away unifications which always fail by replacing them with
+    % `fail'.
 	%
 	(
 		Unification = assign(AssignTarget, _),
@@ -957,23 +929,20 @@
 	;
 		Det = failure
 	->
-		% This optimisation is safe because the only way that
-		% we can analyse a unification as having no solutions
-		% is that the unification always fails.
+        % This optimisation is safe because the only way that we can analyse
+        % a unification as having no solutions is that the unification
+        % always fails.
 		%
 		% Unifying two preds is not erroneous as far as the
 		% mode checker is concerned, but a mode _error_.
 		Unify = disj([])
 	;
-		Unify = unify(X, var(Y), ModeOfX - ModeOfY, Unification,
-			UnifyContext)
+        Unify = unify(X, var(Y), ModeOfX - ModeOfY, Unification, UnifyContext)
 	).
 
-%
-% modecheck_complicated_unify does some extra checks that are needed
-% for mode-checking complicated unifications.
-%
-
+    % Modecheck_complicated_unify does some extra checks that are needed
+    % for mode-checking complicated unifications.
+    %
 :- pred modecheck_complicated_unify(prog_var::in, prog_var::in,
 	(type)::in, (mode)::in, (mode)::in, determinism::in, unify_context::in,
 	unification::in, unification::out,
@@ -981,9 +950,7 @@
 
 modecheck_complicated_unify(X, Y, Type, ModeOfX, ModeOfY, Det, UnifyContext,
 		Unification0, Unification, !ModeInfo) :-
-	%
-	% Build up the unification
-	%
+    % Build up the unification.
 	mode_info_get_module_info(!.ModeInfo, ModuleInfo0),
 	mode_get_insts(ModuleInfo0, ModeOfX, InitialInstX, FinalInstX),
 	mode_get_insts(ModuleInfo0, ModeOfY, InitialInstY, FinalInstY),
@@ -992,76 +959,68 @@
 	( Unification0 = complicated_unify(_, _, UnifyTypeInfoVars0) ->
 		UnifyTypeInfoVars = UnifyTypeInfoVars0
 	;
-		error("modecheck_complicated_unify")
+/* ### In clause for predicate `check_hlds.modecheck_unify.modecheck_complicated_unify/11': */
+/* ###   in argument 1 of call to predicate `unexpected/2': */
+/* ###   error: undefined symbol `this_file/0'. */
+/* ### In clause for predicate `check_hlds.modecheck_unify.modecheck_complicated_unify/11': */
+/* ###   error: undefined predicate `unexpected/2'. */
+        unexpected(this_file, "modecheck_complicated_unify")
 	),
 	Unification = complicated_unify(UniMode, CanFail, UnifyTypeInfoVars),
 
-	%
-	% check that all the type_info or type_class_info variables used
+    % Check that all the type_info or type_class_info variables used
 	% by the polymorphic unification are ground.
-	%
-	( UnifyTypeInfoVars = [] ->
-		% optimize common case
-		true
+    (
+        % Optimize common case.
+        UnifyTypeInfoVars = []
 	;
+        UnifyTypeInfoVars = [_ | _],
 		list__length(UnifyTypeInfoVars, NumTypeInfoVars),
-		list__duplicate(NumTypeInfoVars, ground(shared, none),
-			ExpectedInsts),
+        list__duplicate(NumTypeInfoVars, ground(shared, none), ExpectedInsts),
 		mode_info_set_call_context(unify(UnifyContext), !ModeInfo),
 		NeedExactMatch = no,
 		InitialArgNum = 0,
 		modecheck_var_has_inst_list(UnifyTypeInfoVars, ExpectedInsts,
 			NeedExactMatch, InitialArgNum, _InstVarSub, !ModeInfo),
-			% We can ignore _InstVarSub since type_info variables
+            % we can ignore _InstVarSub since type_info variables
 			% should not have variable insts.
 		mode_info_unset_call_context(!ModeInfo)
 	),
-
 	mode_info_get_module_info(!.ModeInfo, ModuleInfo3),
-
 	(
 		mode_info_get_errors(!.ModeInfo, Errors),
 		Errors \= []
 	->
 		true
 	;
-		%
 		% Check that we're not trying to do a polymorphic unification
 		% in a mode other than (in, in).
 		% [Actually we also allow `any' insts, since the (in, in)
 		% mode of unification for types which have `any' insts must
 		% also be able to handle (in(any), in(any)) unifications.]
-		%
 		Type = term__variable(_),
 		\+ inst_is_ground_or_any(ModuleInfo3, InitialInstX)
 	->
 		set__singleton_set(WaitingVars, X),
-		mode_info_error(WaitingVars,
-			mode_error_poly_unify(X, InitialInstX),
+        mode_info_error(WaitingVars, mode_error_poly_unify(X, InitialInstX),
 			!ModeInfo)
 	;
 		Type = term__variable(_),
 		\+ inst_is_ground_or_any(ModuleInfo3, InitialInstY)
 	->
 		set__singleton_set(WaitingVars, Y),
-		mode_info_error(WaitingVars,
-			mode_error_poly_unify(Y, InitialInstY),
+        mode_info_error(WaitingVars, mode_error_poly_unify(Y, InitialInstY),
 			!ModeInfo)
 	;
 
-		%
-		% check that we're not trying to do a higher-order unification
-		%
+        % Check that we're not trying to do a higher-order unification.
 		type_is_higher_order(Type, _, PredOrFunc, _, _)
 	->
-		% We do not want to report this as an error
-		% if it occurs in a compiler-generated
-		% predicate - instead, we delay the error
-		% until runtime so that it only occurs if
-		% the compiler-generated predicate gets called.
-		% not_reached is considered bound, so the
-		% error message would be spurious if the
-		% instmap is unreachable.
+        % We do not want to report this as an error if it occurs in a
+        % compiler-generated predicate - instead, we delay the error
+        % until runtime so that it only occurs if the compiler-generated
+        % predicate gets called. not_reached is considered bound, so the
+        % error message would be spurious if the instmap is unreachable.
 		mode_info_get_predid(!.ModeInfo, PredId),
 		module_info_pred_info(ModuleInfo3, PredId, PredInfo),
 		mode_info_get_instmap(!.ModeInfo, InstMap0),
@@ -1074,16 +1033,12 @@
 		;
 			set__init(WaitingVars),
 			mode_info_error(WaitingVars,
-				mode_error_unify_pred(X, error_at_var(Y),
-					Type, PredOrFunc),
+                mode_error_unify_pred(X, error_at_var(Y), Type, PredOrFunc),
 				!ModeInfo)
 		)
 	;
-		%
-		% Ensure that we will generate code for the unification
-		% procedure that will be used to implement this complicated
-		% unification.
-		%
+        % Ensure that we will generate code for the unification procedure
+        % that will be used to implement this complicated unification.
 		type_to_ctor_and_args(Type, TypeCtor, _)
 	->
 		mode_info_get_context(!.ModeInfo, Context),
@@ -1095,10 +1050,10 @@
 		true
 	).
 
-% categorize_unify_var_lambda works out which category a unification
-% between a variable and a lambda expression is - whether it is a construction
-% unification or a deconstruction.  It also works out whether it will
-% be deterministic or semideterministic.
+    % Categorize_unify_var_lambda works out which category a unification
+    % between a variable and a lambda expression is - whether it is a
+    % construction unification or a deconstruction. It also works out
+    % whether it will be deterministic or semideterministic.
 
 :- pred categorize_unify_var_lambda((mode)::in, list(mode)::in,
 	prog_var::in, list(prog_var)::in, pred_or_func::in,
@@ -1107,7 +1062,7 @@
 
 categorize_unify_var_lambda(ModeOfX, ArgModes0, X, ArgVars, PredOrFunc,
 		RHS0, RHS, Unification0, Unification, !ModeInfo) :-
-	% if we are re-doing mode analysis, preserve the existing cons_id
+    % If we are re-doing mode analysis, preserve the existing cons_id.
 	list__length(ArgVars, Arity),
 	(
 		Unification0 = construct(_, ConsId0, _, _, _, _, MaybeSize0)
@@ -1120,31 +1075,24 @@
 		MaybeSize = no,
 		ConsId = ConsId1
 	;
-		% the real cons_id will be computed by lambda.m;
-		% we just put in a dummy one for now
+        % The real cons_id will be computed by lambda.m;
+        % we just put in a dummy one for now.
 		MaybeSize = no,
 		ConsId = cons(unqualified("__LambdaGoal__"), Arity)
 	),
 	mode_info_get_module_info(!.ModeInfo, ModuleInfo),
-	mode_util__modes_to_uni_modes(ArgModes0, ArgModes0,
-		ModuleInfo, ArgModes),
+    mode_util__modes_to_uni_modes(ArgModes0, ArgModes0, ModuleInfo, ArgModes),
 	mode_info_get_instmap(!.ModeInfo, InstMap),
+    ( mode_is_output(ModuleInfo, ModeOfX) ->
 	(
-		mode_is_output(ModuleInfo, ModeOfX)
-	->
-		(
-			% If pred_consts are present, lambda expansion
-			% has already been done. Rerunning mode analysis
-			% should not produce a lambda_goal which cannot
-			% be directly converted back into a higher-order
-			% predicate constant.
-			% If the instmap is not reachable, the call
-			% may have been handled as an implied mode,
-			% since not_reached is considered to be bound.
-			% In this case the lambda_goal may not be
-			% converted back to a predicate constant, but
-			% that doesn't matter since the code will be
-			% pruned away later by simplify.m.
+            % If pred_consts are present, lambda expansion has already been
+            % done. Rerunning mode analysis should not produce a lambda_goal
+            % which cannot be directly converted back into a higher-order
+            % predicate constant. If the instmap is not reachable, the call
+            % may have been handled as an implied mode, since not_reached
+            % is considered to be bound. In this case the lambda_goal may
+            % not be converted back to a predicate constant, but that doesn't
+            % matter since the code will be pruned away later by simplify.m.
 			ConsId = pred_const(ShroudedPredProcId, EvalMethod),
 			instmap__is_reachable(InstMap)
 		->
@@ -1159,34 +1107,34 @@
 					PredId, PredInfo),
 				PredModule = pred_info_module(PredInfo),
 				PredName = pred_info_name(PredInfo),
-				RHS = functor(
-					cons(qualified(PredModule, PredName),
-						Arity),
+                RHS = functor(cons(qualified(PredModule, PredName), Arity),
 					no, ArgVars)
 			;
-				error("categorize_unify_var_lambda - \
-					reintroduced lambda goal")
+/* ### In clause for predicate `check_hlds.modecheck_unify.categorize_unify_var_lambda/11': */
+/* ###   in argument 1 of call to predicate `unexpected/2': */
+/* ###   error: undefined symbol `this_file/0'. */
+/* ### In clause for predicate `check_hlds.modecheck_unify.categorize_unify_var_lambda/11': */
+/* ###   error: undefined predicate `unexpected/2'. */
+                unexpected(this_file,
+                    "categorize_unify_var_lambda - reintroduced lambda goal")
 			)
 		;
 			RHS = RHS0
 		),
 		Unification = construct(X, ConsId, ArgVars, ArgModes,
 			construct_dynamically, cell_is_unique, MaybeSize)
-	;
-		instmap__is_reachable(InstMap)
-	->
+    ; instmap__is_reachable(InstMap) ->
 		% If it's a deconstruction, it is a mode error.
-		% The error message would be incorrect in unreachable
-		% code, since not_reached is considered bound.
+        % The error message would be incorrect in unreachable code,
+        % since not_reached is considered bound.
 		set__init(WaitingVars),
 		mode_info_get_var_types(!.ModeInfo, VarTypes0),
 		map__lookup(VarTypes0, X, Type),
 		mode_info_error(WaitingVars,
-			mode_error_unify_pred(X,
-				error_at_lambda(ArgVars, ArgModes0),
+            mode_error_unify_pred(X, error_at_lambda(ArgVars, ArgModes0),
 				Type, PredOrFunc),
 			!ModeInfo),
-		% return any old garbage
+        % Return any old garbage.
 		Unification = Unification0,
 		RHS = RHS0
 	;
@@ -1194,10 +1142,10 @@
 		RHS = RHS0
 	).
 
-% categorize_unify_var_functor works out which category a unification
-% between a variable and a functor is - whether it is a construction
-% unification or a deconstruction.  It also works out whether it will
-% be deterministic or semideterministic.
+    % Categorize_unify_var_functor works out which category a unification
+    % between a variable and a functor is - whether it is a construction
+    % unification or a deconstruction. It also works out whether it will be
+    % deterministic or semideterministic.
 
 :- pred categorize_unify_var_functor((mode)::in, list(mode)::in,
 	list(mode)::in, prog_var::in, cons_id::in, list(prog_var)::in,
@@ -1210,7 +1158,7 @@
 		Unification0, Unification, !ModeInfo) :-
 	mode_info_get_module_info(!.ModeInfo, ModuleInfo),
 	map__lookup(VarTypes, X, TypeOfX),
-	% if we are re-doing mode analysis, preserve the existing cons_id
+    % If we are re-doing mode analysis, preserve the existing cons_id.
 	( Unification0 = construct(_, ConsId0, _, _, _, _, MaybeSize0) ->
 		MaybeSize = MaybeSize0,
 		ConsId = ConsId0
@@ -1223,28 +1171,24 @@
 	),
 	mode_util__modes_to_uni_modes(ModeOfXArgs, ArgModes0,
 		ModuleInfo, ArgModes),
-	(
-		mode_is_output(ModuleInfo, ModeOfX)
-	->
+    ( mode_is_output(ModuleInfo, ModeOfX) ->
 		% It's a construction.
 		Unification = construct(X, ConsId, ArgVars, ArgModes,
 			construct_dynamically, cell_is_unique, MaybeSize),
 
-		% For existentially quantified data types,
-		% check that any type_info or type_class_info variables in the
-		% construction are ground.
+        % For existentially quantified data types, check that any type_info
+        % or type_class_info variables in the construction are ground.
 		check_type_info_args_are_ground(ArgVars, VarTypes,
 			UnifyContext, !ModeInfo)
 	;
 		% It's a deconstruction.
 		(
-			% If the variable was already known to be bound
-			% to a single particular functor, then the
-			% unification either always succeeds or always
-			% fails.  In the latter case, the final inst will
-			% be `not_reached' or `bound([])'.  So if both
-			% the initial and final inst are `bound([_])',
-			% then the unification must be deterministic.
+            % If the variable was already known to be bound to a single
+            % particular functor, then the unification either always succeeds
+            % or always fails. In the latter case, the final inst will be
+            % `not_reached' or `bound([])'. So if both the initial and final
+            % inst are `bound([_])', then the unification must be
+            % deterministic.
 			mode_get_insts(ModuleInfo, ModeOfX,
 				InitialInst0, FinalInst0),
 			inst_expand(ModuleInfo, InitialInst0, InitialInst),
@@ -1254,38 +1198,35 @@
 		->
 			CanFail = cannot_fail
 		;
-			% If the type has only one constructor,
-			% then the unification cannot fail
+            % If the type has only one constructor, then the unification
+            % cannot fail.
 			type_constructors(TypeOfX, ModuleInfo, Constructors),
 			Constructors = [_]
 		->
 			CanFail = cannot_fail
 		;
-			% Otherwise, it can fail
+            % Otherwise, it can fail.
 			CanFail = can_fail,
 			mode_info_get_instmap(!.ModeInfo, InstMap0),
 			(
-				type_is_higher_order(TypeOfX, _, PredOrFunc,
-					_, _),
+                type_is_higher_order(TypeOfX, _, PredOrFunc, _, _),
 				instmap__is_reachable(InstMap0)
 			->
 				set__init(WaitingVars),
 				mode_info_error(WaitingVars,
-					mode_error_unify_pred(X,
-						error_at_functor(ConsId,
-							ArgVars),
+                    mode_error_unify_pred(X, error_at_functor(ConsId, ArgVars),
 						TypeOfX, PredOrFunc),
 					!ModeInfo)
 			;
 				true
 			)
 		),
-		Unification = deconstruct(X, ConsId, ArgVars,
-			ArgModes, CanFail, no)
+        Unification = deconstruct(X, ConsId, ArgVars, ArgModes, CanFail, no)
 	).
 
 	% Check that any type_info or type_class_info variables
 	% in the argument list are ground.
+    %
 :- pred check_type_info_args_are_ground(list(prog_var)::in,
 	map(prog_var, type)::in, unify_context::in,
 	mode_info::in, mode_info::out) is det.
@@ -1302,8 +1243,8 @@
 		InitialArgNum = 0,
 		modecheck_var_has_inst_list([ArgVar], [ground(shared, none)],
 			NeedExactMatch, InitialArgNum, _InstVarSub, !ModeInfo),
-		check_type_info_args_are_ground(ArgVars, VarTypes,
-			UnifyContext, !ModeInfo),
+        check_type_info_args_are_ground(ArgVars, VarTypes, UnifyContext,
+            !ModeInfo),
 		mode_info_unset_call_context(!ModeInfo)
 	;
 		true
@@ -1320,11 +1261,13 @@
 bind_args(ground(Uniq, none), Args, UnifyArgInsts, !ModeInfo) :-
 	ground_args(Uniq, Args, UnifyArgInsts, !ModeInfo).
 bind_args(bound(_Uniq, List), Args, UnifyArgInsts, !ModeInfo) :-
-	( List = [] ->
-		% the code is unreachable
+    (
+        List = [],
+        % The code is unreachable.
 		instmap__init_unreachable(InstMap),
 		mode_info_set_instmap(InstMap, !ModeInfo)
 	;
+        List = [_ | _],
 		List = [functor(_, InstList)],
 		bind_args_2(Args, InstList, UnifyArgInsts, !ModeInfo)
 	).
@@ -1351,12 +1294,12 @@
 
 %-----------------------------------------------------------------------------%
 
-% get_mode_of_args(FinalInst, InitialArgInsts, ArgModes):
-%       for a var-functor unification,
-%       given the final inst of the var
-%       and the initial insts of the functor arguments,
-%       compute the modes of the functor arguments
-
+    % get_mode_of_args(FinalInst, InitialArgInsts, ArgModes):
+    %
+    % For a var-functor unification, given the final inst of the var
+    % and the initial insts of the functor arguments, compute the modes
+    % of the functor arguments.
+    %
 :- pred get_mode_of_args((inst)::in, list(inst)::in, list(mode)::out)
 	is semidet.
 
@@ -1367,10 +1310,12 @@
 get_mode_of_args(ground(Uniq, none), ArgInsts, ArgModes) :-
 	mode_set_args(ArgInsts, ground(Uniq, none), ArgModes).
 get_mode_of_args(bound(_Uniq, List), ArgInstsA, ArgModes) :-
-	( List = [] ->
-		% the code is unreachable
+    (
+        List = [],
+        % The code is unreachable.
 		mode_set_args(ArgInstsA, not_reached, ArgModes)
 	;
+        List = [_ | _],
 		List = [functor(_Name, ArgInstsB)],
 		get_mode_of_args_2(ArgInstsA, ArgInstsB, ArgModes)
 	).
@@ -1393,4 +1338,9 @@
 	mode_set_args(Insts, FinalInst, Modes).
 
 %-----------------------------------------------------------------------------%
+
+:- func this_file = string.
+
+this_file = "modecheck_unify.m".
+
 %-----------------------------------------------------------------------------%
Index: simplify.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/simplify.m,v
retrieving revision 1.146
diff -u -b -r1.146 simplify.m
--- simplify.m	15 Aug 2005 07:18:30 -0000	1.146
+++ simplify.m	16 Aug 2005 04:01:48 -0000
@@ -172,8 +172,7 @@
     (
         !.MaybeMsgs = yes(AnyModeMsgSet0 - AllModeMsgSet0),
         set__union(AnyModeMsgSet0, ProcAnyModeMsgSet, AnyModeMsgSet),
-        set__intersect(AllModeMsgSet0, ProcAllModeMsgSet,
-            AllModeMsgSet),
+        set__intersect(AllModeMsgSet0, ProcAllModeMsgSet, AllModeMsgSet),
         !:MaybeMsgs = yes(AllModeMsgSet - AnyModeMsgSet)
     ;
         !.MaybeMsgs = no,
cvs diff: Diffing notes
--------------------------------------------------------------------------
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