[m-rev.] diff: modes cleanup

Zoltan Somogyi zs at cs.mu.OZ.AU
Thu Nov 6 13:44:59 AEDT 2003


This diff changes modes.m, unique_modes.m and mode_info.m to make them easier
to read and to maintain, but contains no changes in algorithms whatsoever.

compiler/modes.m:
compiler/unique_modes.m:
compiler/mode_info.m:
	Convert these modules to our current coding standards. Use state
	variable notation when appropriate, reordering arguments as necessary.
	Delete predicates whose only purpose was to ease programming with DCGs.

	Remove the IO state from the mode_info structure, and pass it
	separately to the (relatively few) predicates that need it. This
	avoids using complicated (and as yet unsupported) modes or lying
	to the compiler (we used to do the latter), and we are no longer
	forced into that choice by being limited to a single hidden (DCG)
	variable.

	Use more expressive variable names and factor out code as appropriate.

compiler/*.m:
	Conform to the changes in the above two modules.

Zoltan.

cvs diff: Diffing .
cvs diff: Diffing analysis
cvs diff: Diffing bindist
cvs diff: Diffing boehm_gc
cvs diff: Diffing boehm_gc/Mac_files
cvs diff: Diffing boehm_gc/cord
cvs diff: Diffing boehm_gc/cord/private
cvs diff: Diffing boehm_gc/doc
cvs diff: Diffing boehm_gc/include
cvs diff: Diffing boehm_gc/include/private
cvs diff: Diffing boehm_gc/tests
cvs diff: Diffing browser
cvs diff: Diffing bytecode
cvs diff: Diffing compiler
Index: compiler/instmap.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/instmap.m,v
retrieving revision 1.31
diff -u -b -r1.31 instmap.m
--- compiler/instmap.m	25 Jul 2003 02:27:20 -0000	1.31
+++ compiler/instmap.m	5 Nov 2003 22:45:48 -0000
@@ -216,7 +216,7 @@
 	%
 :- pred instmap__merge(set(prog_var), list(instmap), merge_context,
 		mode_info, mode_info).
-:- mode instmap__merge(in, in, in, mode_info_di, mode_info_uo) is det.
+:- mode instmap__merge(in, in, in, in, out) is det.
 
 	% instmap__unify(NonLocalVars, InstMapNonlocalvarPairss):
 	%       Unify the `InstMaps' in the list of pairs resulting
@@ -228,7 +228,7 @@
 	%
 :- pred instmap__unify(set(prog_var), list(pair(instmap, set(prog_var))),
 		mode_info, mode_info).
-:- mode instmap__unify(in, in, mode_info_di, mode_info_uo) is det.
+:- mode instmap__unify(in, in, in, out) is det.
 
 	% instmap__restrict takes an instmap and a set of vars and
 	% returns an instmap with its domain restricted to those
@@ -626,7 +626,7 @@
 		instmap__merge_2(NonLocalsList, InstMapList, VarTypes,	
 			ModuleInfo0, InstMapping0, ModuleInfo, InstMapping,
 			ErrorList),
-		mode_info_set_module_info(ModeInfo0, ModuleInfo, ModeInfo1),
+		mode_info_set_module_info(ModuleInfo, ModeInfo0, ModeInfo1),
 		( ErrorList = [FirstError | _] ->
 			FirstError = Var - _,
 			set__singleton_set(WaitingVars, Var),
@@ -767,7 +767,7 @@
 		instmap__unify_2(NonLocalsList, InstMap0, InstMapList1,
 			ModuleInfo0, InstMapping0, ModuleInfo,
 			InstMapping, ErrorList),
-		mode_info_set_module_info(ModeInfo0, ModuleInfo, ModeInfo1),
+		mode_info_set_module_info(ModuleInfo, ModeInfo0, ModeInfo1),
 			
 			% If there were any errors, then add the error
 			% to the list of possible errors in the mode_info.
Index: compiler/mode_debug.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/mode_debug.m,v
retrieving revision 1.15
diff -u -b -r1.15 mode_debug.m
--- compiler/mode_debug.m	15 Mar 2003 03:09:02 -0000	1.15
+++ compiler/mode_debug.m	5 Nov 2003 22:45:59 -0000
@@ -17,12 +17,13 @@
 :- interface.
 
 :- import_module check_hlds__mode_info.
+:- import_module io.
 
 	% Print a debugging message which includes the port, message string,
 	% and the current instmap (but only if `--debug-modes' was enabled).
 	%
-:- pred mode_checkpoint(port, string, mode_info, mode_info).
-:- mode mode_checkpoint(in, in, mode_info_di, mode_info_uo) is det.
+:- pred mode_checkpoint(port::in, string::in, mode_info::in, mode_info::out,
+	io::di, io::uo) is det.
 
 :- type port
 	--->	enter
@@ -45,90 +46,85 @@
 :- import_module parse_tree__mercury_to_mercury.
 :- import_module parse_tree__prog_data.
 
-:- import_module std_util, list, assoc_list, io, bool, map.
+:- import_module std_util, list, assoc_list, bool, map.
 :- import_module term, varset.
 
 %-----------------------------------------------------------------------------%
 
 	% This code is used to trace the actions of the mode checker.
 
-mode_checkpoint(Port, Msg, ModeInfo0, ModeInfo) :-
-	mode_info_get_module_info(ModeInfo0, ModuleInfo),
+mode_checkpoint(Port, Msg, !ModeInfo, !IO) :-
+	mode_info_get_module_info(!.ModeInfo, ModuleInfo),
 	module_info_globals(ModuleInfo, Globals),
 	globals__lookup_bool_option(Globals, debug_modes, DoCheckPoint),
 	( DoCheckPoint = yes ->
-		mode_info_get_io_state(ModeInfo0, IOState0),
-		mode_info_get_last_checkpoint_insts(ModeInfo0, OldInsts),
-		mode_checkpoint_2(Port, Msg, OldInsts, NewInsts, ModeInfo0,
-			IOState0, IOState),
-		mode_info_set_last_checkpoint_insts(NewInsts, ModeInfo0,
-			ModeInfo1),
-		mode_info_set_io_state(ModeInfo1, IOState, ModeInfo)
+		mode_checkpoint_2(Port, Msg, !ModeInfo, !IO)
 	;
-		ModeInfo = ModeInfo0
+		true
 	).
 
-:- pred mode_checkpoint_2(port, string, assoc_list(prog_var, inst),
-	assoc_list(prog_var, inst), mode_info, io__state, io__state).
-:- mode mode_checkpoint_2(in, in, in, out, mode_info_ui, di, uo) is det.
-
-mode_checkpoint_2(Port, Msg, OldInstList, NewInstList, ModeInfo) -->
-	{ mode_info_get_errors(ModeInfo, Errors) },
-	( { Port = enter } ->
-		io__write_string("Enter "),
-		{ Detail = yes }
-	; { Port = wakeup } ->
-		io__write_string("Wake "),
-		{ Detail = no }
-	; { Errors = [] } ->
-		io__write_string("Exit "),
-		{ Detail = yes }
+:- pred mode_checkpoint_2(port::in, string::in, mode_info::in, mode_info::out,
+	io__state::di, io__state::uo) is det.
+
+mode_checkpoint_2(Port, Msg, !ModeInfo, !IO) :-
+	mode_info_get_last_checkpoint_insts(!.ModeInfo, OldInsts),
+	mode_info_get_errors(!.ModeInfo, Errors),
+	( Port = enter ->
+		io__write_string("Enter ", !IO),
+		Detail = yes
+	; Port = wakeup ->
+		io__write_string("Wake ", !IO),
+		Detail = no
+	; Errors = [] ->
+		io__write_string("Exit ", !IO),
+		Detail = yes
 	;
-		io__write_string("Delay "),
-		{ Detail = no }
+		io__write_string("Delay ", !IO),
+		Detail = no
 	),
-	io__write_string(Msg),
-	( { Detail = yes } ->
-		io__write_string(":\n"),
-		globals__io_lookup_bool_option(statistics, Statistics),
-		maybe_report_stats(Statistics),
-		maybe_flush_output(Statistics),
-		{ mode_info_get_instmap(ModeInfo, InstMap) },
-		( { instmap__is_reachable(InstMap) } ->
-			{ instmap__to_assoc_list(InstMap, NewInstList) },
-			{ mode_info_get_varset(ModeInfo, VarSet) },
-			{ mode_info_get_instvarset(ModeInfo, InstVarSet) },
-			write_var_insts(NewInstList, OldInstList,
-				VarSet, InstVarSet)
+	io__write_string(Msg, !IO),
+	( Detail = yes ->
+		io__write_string(":\n", !IO),
+		globals__io_lookup_bool_option(statistics, Statistics, !IO),
+		maybe_report_stats(Statistics, !IO),
+		maybe_flush_output(Statistics, !IO),
+		mode_info_get_instmap(!.ModeInfo, InstMap),
+		( instmap__is_reachable(InstMap) ->
+			instmap__to_assoc_list(InstMap, NewInsts),
+			mode_info_get_varset(!.ModeInfo, VarSet),
+			mode_info_get_instvarset(!.ModeInfo, InstVarSet),
+			write_var_insts(NewInsts, OldInsts, VarSet, InstVarSet,
+				!IO)
 		;
-			{ NewInstList = [] },
-			io__write_string("\tUnreachable\n")
-		)
+			NewInsts = [],
+			io__write_string("\tUnreachable\n", !IO)
+		),
+		mode_info_set_last_checkpoint_insts(NewInsts, !ModeInfo)
 	;
-		{ NewInstList = OldInstList }
+		true
 	),
-	io__write_string("\n"),
-	io__flush_output.
+	io__write_string("\n", !IO),
+	io__flush_output(!IO).
 
-:- pred write_var_insts(assoc_list(prog_var, inst), assoc_list(prog_var, inst),
-	prog_varset, inst_varset, io__state, io__state).
-:- mode write_var_insts(in, in, in, in, di, uo) is det.
-
-write_var_insts([], _, _, _) --> [].
-write_var_insts([Var - Inst | VarInsts], OldInstList, VarSet, InstVarSet) -->
-	io__write_string("\t"),
-	mercury_output_var(Var, VarSet, no),
-	io__write_string(" ::"),
+:- pred write_var_insts(assoc_list(prog_var, inst)::in,
+	assoc_list(prog_var, inst)::in, prog_varset::in, inst_varset::in,
+	io__state::di, io__state::uo) is det.
+
+write_var_insts([], _, _, _, !IO).
+write_var_insts([Var - Inst | VarInsts], OldInsts, VarSet, InstVarSet, !IO) :-
+	io__write_string("\t", !IO),
+	mercury_output_var(Var, VarSet, no, !IO),
+	io__write_string(" ::", !IO),
 	(
-		{ assoc_list__search(OldInstList, Var, OldInst) },
-		{ Inst = OldInst }
+		assoc_list__search(OldInsts, Var, OldInst),
+		Inst = OldInst
 	->
-		io__write_string(" unchanged\n")
+		io__write_string(" unchanged\n", !IO)
 	;
-		io__write_string("\n"),
-		mercury_output_structured_inst(Inst, 2, InstVarSet)
+		io__write_string("\n", !IO),
+		mercury_output_structured_inst(Inst, 2, InstVarSet, !IO)
 	),
-	write_var_insts(VarInsts, OldInstList, VarSet, InstVarSet).
+	write_var_insts(VarInsts, OldInsts, VarSet, InstVarSet, !IO).
 
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
Index: compiler/mode_errors.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/mode_errors.m,v
retrieving revision 1.76
diff -u -b -r1.76 mode_errors.m
--- compiler/mode_errors.m	24 Oct 2003 06:17:43 -0000	1.76
+++ compiler/mode_errors.m	5 Nov 2003 23:03:22 -0000
@@ -146,45 +146,41 @@
         % If there were any errors recorded in the mode_info,
         % report them to the user now.
         %
-:- pred report_mode_errors(mode_info, mode_info).
-:- mode report_mode_errors(mode_info_di, mode_info_uo) is det.
-
+:- pred report_mode_errors(mode_info::in, mode_info::out,
+	io::di, io::uo) is det.
 
 	% print an error message describing a mode error
 
-:- pred report_mode_error(mode_error, mode_info, io__state, io__state).
-:- mode report_mode_error(in, mode_info_no_io, di, uo) is det.
+:- pred report_mode_error(mode_error::in, mode_info::in,
+	io::di, io::uo) is det.
 
 	% report an error for a predicate with no mode declarations
 	% unless mode inference is enabled and the predicate is local.
 
-:- pred maybe_report_error_no_modes(pred_id, pred_info, module_info,
-				io__state, io__state).
-:- mode maybe_report_error_no_modes(in, in, in, di, uo) is det.
+:- pred maybe_report_error_no_modes(pred_id::in, pred_info::in,
+	module_info::in, io::di, io::uo) is det.
 
 	% initialize the mode_context.
 
-:- pred mode_context_init(mode_context).
-:- mode mode_context_init(out) is det.
+:- pred mode_context_init(mode_context::out) is det.
 
 	% Write out the inferred `mode' declarations for a list of pred_ids.
 	% The bool indicates whether or not to write out determinism
 	% annotations on the modes (it should only be set to `yes' _after_
 	% determinism analysis).
 
-:- pred write_mode_inference_messages(list(pred_id), bool, module_info,
-				io__state, io__state).
-:- mode write_mode_inference_messages(in, in, in, di, uo) is det.
+:- pred write_mode_inference_messages(list(pred_id)::in, bool::in,
+	module_info::in, io__state::di, io__state::uo) is det.
 
 	% report an error for the case when two mode declarations
 	% declare indistinguishable modes
 
-:- pred report_indistinguishable_modes_error(proc_id, proc_id,
-		pred_id, pred_info, module_info, io__state, io__state).
-:- mode report_indistinguishable_modes_error(in, in, in, in, in, di, uo) is det.
+:- pred report_indistinguishable_modes_error(proc_id::in, proc_id::in,
+	pred_id::in, pred_info::in, module_info::in,
+	io__state::di, io__state::uo) is det.
 
-:- pred output_mode_decl(proc_id, pred_info, io__state, io__state).
-:- mode output_mode_decl(in, in, di, uo) is det.
+:- pred output_mode_decl(proc_id::in, pred_info::in,
+	io__state::di, io__state::uo) is det.
 
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
@@ -256,7 +252,7 @@
 
 :- pred report_mode_error_conj(mode_info, list(delayed_goal), schedule_culprit,
 				io__state, io__state).
-:- mode report_mode_error_conj(mode_info_no_io, in, in, di, uo) is det.
+:- mode report_mode_error_conj(in, in, in, di, uo) is det.
 
 report_mode_error_conj(ModeInfo, Errors, Culprit) -->
 	{ mode_info_get_context(ModeInfo, Context) },
@@ -344,7 +340,7 @@
 
 :- pred report_mode_error_conj_2(list(delayed_goal), prog_varset, prog_context,
 				mode_info, io__state, io__state).
-:- mode report_mode_error_conj_2(in, in, in, mode_info_no_io, di, uo) is det.
+:- mode report_mode_error_conj_2(in, in, in, in, di, uo) is det.
 
 report_mode_error_conj_2([], _, _, _) --> [].
 report_mode_error_conj_2([delayed_goal(Vars, Error, Goal) | Rest],
@@ -377,7 +373,7 @@
 
 :- pred report_mode_error_disj(mode_info, merge_context, merge_errors,
 				io__state, io__state).
-:- mode report_mode_error_disj(mode_info_no_io, in, in, di, uo) is det.
+:- mode report_mode_error_disj(in, in, in, di, uo) is det.
 
 report_mode_error_disj(ModeInfo, MergeContext, ErrorList) -->
 	{ mode_info_get_context(ModeInfo, Context) },
@@ -390,7 +386,7 @@
 
 :- pred report_mode_error_par_conj(mode_info, merge_errors,
 				io__state, io__state).
-:- mode report_mode_error_par_conj(mode_info_no_io, in, di, uo) is det.
+:- mode report_mode_error_par_conj(in, in, di, uo) is det.
 
 report_mode_error_par_conj(ModeInfo, ErrorList) -->
 	{ mode_info_get_context(ModeInfo, Context) },
@@ -406,7 +402,7 @@
 	write_merge_error_list(ErrorList, ModeInfo).
 
 :- pred write_merge_error_list(merge_errors, mode_info, io__state, io__state).
-:- mode write_merge_error_list(in, mode_info_no_io, di, uo) is det.
+:- mode write_merge_error_list(in, in, di, uo) is det.
 
 write_merge_error_list([], _) --> [].
 write_merge_error_list([Var - Insts | Errors], ModeInfo) -->
@@ -432,7 +428,7 @@
 
 :- pred report_mode_error_bind_var(mode_info, var_lock_reason, prog_var,
 		inst, inst, io__state, io__state).
-:- mode report_mode_error_bind_var(mode_info_ui, in, in, in, in, di, uo) is det.
+:- mode report_mode_error_bind_var(in, in, in, in, in, di, uo) is det.
 
 report_mode_error_bind_var(ModeInfo, Reason, Var, VarInst, Inst) -->
 	{ mode_info_get_context(ModeInfo, Context) },
@@ -491,7 +487,7 @@
 
 :- pred report_mode_error_non_local_lambda_var(mode_info, prog_var, inst,
 					io__state, io__state).
-:- mode report_mode_error_non_local_lambda_var(mode_info_ui, in, in,
+:- mode report_mode_error_non_local_lambda_var(in, in, in,
 					di, uo) is det.
 
 report_mode_error_non_local_lambda_var(ModeInfo, Var, VarInst) -->
@@ -514,22 +510,22 @@
 :- pred report_mode_error_in_callee(mode_info, list(prog_var),
 		list(inst), pred_id, proc_id, list(mode_error_info),
 		io__state, io__state).
-:- mode report_mode_error_in_callee(mode_info_ui, in, in, in, in, in,
+:- mode report_mode_error_in_callee(in, in, in, in, in, in,
 		di, uo) is det.
 
-report_mode_error_in_callee(ModeInfo, Vars, Insts,
+report_mode_error_in_callee(ModeInfo0, Vars, Insts,
 		CalleePredId, CalleeProcId, CalleeModeErrors) -->
-	{ mode_info_get_module_info(ModeInfo, ModuleInfo) },
-	{ mode_info_get_context(ModeInfo, Context) },
-	{ mode_info_get_varset(ModeInfo, VarSet) },
-	mode_info_write_context(ModeInfo),
+	{ mode_info_get_module_info(ModeInfo0, ModuleInfo) },
+	{ mode_info_get_context(ModeInfo0, Context) },
+	{ mode_info_get_varset(ModeInfo0, VarSet) },
+	mode_info_write_context(ModeInfo0),
 	prog_out__write_context(Context),
 	io__write_string("  mode error: arguments `"),
 	mercury_output_vars(Vars, VarSet, no),
 	io__write_string("'\n"),
 	prog_out__write_context(Context),
 	io__write_string("  have insts `"),
-	output_inst_list(Insts, ModeInfo),
+	output_inst_list(Insts, ModeInfo0),
 	io__write_string("',\n"),
 	prog_out__write_context(Context),
 	io__write_string("  which does not match any of the valid modes for\n"),
@@ -548,8 +544,8 @@
 	( { CalleeModeErrors = [First | _] } ->
 		{ First = mode_error_info(_, CalleeModeError,
 			CalleeContext, CalleeModeContext) },
-		{ mode_info_set_predid(ModeInfo, CalleePredId, ModeInfo1) },
-		{ mode_info_set_procid(ModeInfo1, CalleeProcId, ModeInfo2) },
+		{ mode_info_set_predid(CalleePredId, ModeInfo0, ModeInfo1) },
+		{ mode_info_set_procid(CalleeProcId, ModeInfo1, ModeInfo2) },
 		{ mode_info_set_context(CalleeContext, ModeInfo2, ModeInfo3) },
 		{ mode_info_set_mode_context(CalleeModeContext,
 			ModeInfo3, ModeInfo4) },
@@ -560,7 +556,7 @@
 
 :- pred report_mode_error_no_matching_mode(mode_info, list(prog_var),
 		list(inst), io__state, io__state).
-:- mode report_mode_error_no_matching_mode(mode_info_ui, in, in, di, uo) is det.
+:- mode report_mode_error_no_matching_mode(in, in, in, di, uo) is det.
 
 report_mode_error_no_matching_mode(ModeInfo, Vars, Insts) -->
 	{ mode_info_get_context(ModeInfo, Context) },
@@ -586,7 +582,7 @@
 
 :- pred report_mode_error_higher_order_pred_var(mode_info, pred_or_func,
 		prog_var, inst, arity, io__state, io__state).
-:- mode report_mode_error_higher_order_pred_var(mode_info_ui, in, in, in, in,
+:- mode report_mode_error_higher_order_pred_var(in, in, in, in, in,
 					di, uo) is det.
 
 report_mode_error_higher_order_pred_var(ModeInfo, PredOrFunc, Var, VarInst,
@@ -615,7 +611,7 @@
 
 :- pred report_mode_error_poly_unify(mode_info, prog_var, inst,
 					io__state, io__state).
-:- mode report_mode_error_poly_unify(mode_info_ui, in, in, di, uo) is det.
+:- mode report_mode_error_poly_unify(in, in, in, di, uo) is det.
 
 report_mode_error_poly_unify(ModeInfo, Var, VarInst) -->
 	{ mode_info_get_context(ModeInfo, Context) },
@@ -645,7 +641,7 @@
 
 :- pred report_mode_error_var_is_live(mode_info, prog_var,
 		io__state, io__state).
-:- mode report_mode_error_var_is_live(mode_info_ui, in, di, uo) is det.
+:- mode report_mode_error_var_is_live(in, in, di, uo) is det.
 
 report_mode_error_var_is_live(ModeInfo, Var) -->
 	{ mode_info_get_context(ModeInfo, Context) },
@@ -660,7 +656,7 @@
 
 :- pred report_mode_error_var_has_inst(mode_info, prog_var, inst, inst,
 					io__state, io__state).
-:- mode report_mode_error_var_has_inst(mode_info_ui, in, in, in, di, uo) is det.
+:- mode report_mode_error_var_has_inst(in, in, in, in, di, uo) is det.
 
 report_mode_error_var_has_inst(ModeInfo, Var, VarInst, Inst) -->
 	{ mode_info_get_context(ModeInfo, Context) },
@@ -679,7 +675,7 @@
 
 :- pred report_mode_error_implied_mode(mode_info, prog_var, inst, inst,
 					io__state, io__state).
-:- mode report_mode_error_implied_mode(mode_info_ui, in, in, in, di, uo) is det.
+:- mode report_mode_error_implied_mode(in, in, in, in, di, uo) is det.
 
 report_mode_error_implied_mode(ModeInfo, Var, VarInst, Inst) -->
 		% This "error" message is really a "sorry, not implemented"
@@ -707,7 +703,7 @@
 	).
 
 :- pred report_mode_error_no_mode_decl(mode_info, io__state, io__state).
-:- mode report_mode_error_no_mode_decl(mode_info_ui, di, uo) is det.
+:- mode report_mode_error_no_mode_decl(in, di, uo) is det.
 
 report_mode_error_no_mode_decl(ModeInfo) -->
 	{ mode_info_get_context(ModeInfo, Context) },
@@ -718,7 +714,7 @@
 :- pred report_mode_error_unify_pred(mode_info, prog_var, mode_error_unify_rhs,
 					type, pred_or_func,
 					io__state, io__state).
-:- mode report_mode_error_unify_pred(mode_info_ui, in, in, in, in,
+:- mode report_mode_error_unify_pred(in, in, in, in, in,
 					di, uo) is det.
 
 report_mode_error_unify_pred(ModeInfo, X, RHS, Type, PredOrFunc) -->
@@ -775,7 +771,7 @@
 
 :- pred report_mode_error_unify_var_var(mode_info, prog_var, prog_var,
 		inst, inst, io__state, io__state).
-:- mode report_mode_error_unify_var_var(mode_info_ui, in, in, in, in, di, uo)
+:- mode report_mode_error_unify_var_var(in, in, in, in, in, di, uo)
 	is det.
 
 report_mode_error_unify_var_var(ModeInfo, X, Y, InstX, InstY) -->
@@ -805,7 +801,7 @@
 
 :- pred report_mode_error_unify_var_lambda(mode_info, prog_var, inst, inst,
 					io__state, io__state).
-:- mode report_mode_error_unify_var_lambda(mode_info_ui, in, in, in, di, uo)
+:- mode report_mode_error_unify_var_lambda(in, in, in, in, di, uo)
 	is det.
 
 report_mode_error_unify_var_lambda(ModeInfo, X, InstX, InstY) -->
@@ -831,7 +827,7 @@
 
 :- pred report_mode_error_unify_var_functor(mode_info, prog_var, cons_id,
 		list(prog_var), inst, list(inst), io__state, io__state).
-:- mode report_mode_error_unify_var_functor(mode_info_ui, in, in, in, in, in,
+:- mode report_mode_error_unify_var_functor(in, in, in, in, in, in,
 			di, uo) is det.
 
 report_mode_error_unify_var_functor(ModeInfo, X, ConsId, Args, InstX, ArgInsts)
@@ -872,7 +868,7 @@
 %-----------------------------------------------------------------------------%
 
 :- pred mode_info_write_context(mode_info, io__state, io__state).
-:- mode mode_info_write_context(mode_info_no_io, di, uo) is det.
+:- mode mode_info_write_context(in, di, uo) is det.
 
 mode_info_write_context(ModeInfo) -->
 	{ mode_info_get_module_info(ModeInfo, ModuleInfo) },
@@ -902,7 +898,7 @@
 
 :- pred report_mode_error_final_inst(mode_info, int, prog_var, inst, inst,
 				final_inst_error, io__state, io__state).
-:- mode report_mode_error_final_inst(mode_info_ui, in, in, in, in, in,
+:- mode report_mode_error_final_inst(in, in, in, in, in, in,
 				di, uo) is det.
 
 report_mode_error_final_inst(ModeInfo, ArgNum, Var, VarInst, Inst, Reason) -->
@@ -934,7 +930,6 @@
 	output_inst(Inst, ModeInfo),
 	io__write_string("'.\n").
 
-
 %-----------------------------------------------------------------------------%
 
 mode_context_init(uninitialized).
@@ -994,7 +989,6 @@
 		io__write_string("  "),
 		hlds_out__write_pred_id(ModuleInfo, PredId),
 		io__write_string(".\n")
-	
 	).
 
 %-----------------------------------------------------------------------------%
@@ -1115,25 +1109,22 @@
         % If there were any errors recorded in the mode_info,
         % report them to the user now.
 
-report_mode_errors(ModeInfo0, ModeInfo) :-
-        mode_info_get_errors(ModeInfo0, Errors),
+report_mode_errors(!ModeInfo, !IO) :-
+        mode_info_get_errors(!.ModeInfo, Errors),
         ( Errors = [FirstError | _] ->	% XXX Why do we only report the first?
-                FirstError = mode_error_info(_, ModeError,
-                                                Context, ModeContext),
-                mode_info_set_context(Context, ModeInfo0, ModeInfo1),
-                mode_info_set_mode_context(ModeContext, ModeInfo1, ModeInfo2),
-                mode_info_get_io_state(ModeInfo2, IOState0),
-                report_mode_error(ModeError, ModeInfo2,
-                                IOState0, IOState),
-                mode_info_set_io_state(ModeInfo2, IOState, ModeInfo)
+                FirstError = mode_error_info(_, ModeError, Context,
+			ModeContext),
+                mode_info_set_context(Context, !ModeInfo),
+                mode_info_set_mode_context(ModeContext, !ModeInfo),
+                report_mode_error(ModeError, !.ModeInfo, !IO)
         ;
-                ModeInfo = ModeInfo0
+                true
         ).
 
 %-----------------------------------------------------------------------------%
 
 :- pred output_inst((inst), mode_info, io__state, io__state).
-:- mode output_inst(in, mode_info_ui, di, uo) is det.
+:- mode output_inst(in, in, di, uo) is det.
 
 output_inst(Inst0, ModeInfo) -->
 	{ strip_builtin_qualifiers_from_inst(Inst0, Inst) },
Index: compiler/mode_info.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/mode_info.m,v
retrieving revision 1.63
diff -u -b -r1.63 mode_info.m
--- compiler/mode_info.m	30 May 2003 15:31:12 -0000	1.63
+++ compiler/mode_info.m	5 Nov 2003 23:01:17 -0000
@@ -26,7 +26,7 @@
 :- import_module parse_tree__inst.
 :- import_module parse_tree__prog_data.
 
-:- import_module map, list, set, bool, assoc_list, std_util, io.
+:- import_module map, list, set, bool, assoc_list, std_util.
 
 :- interface.
 
@@ -65,15 +65,13 @@
 	--->	negation
 	;	if_then_else
 	;	lambda(pred_or_func)
-	;	par_conj
-	.
+	;	par_conj.
 
 	% Specify how to process goals - using either
 	% modes.m or unique_modes.m.
 :- type how_to_check_goal
 	--->    check_modes
-	;       check_unique_modes
-	.
+	;       check_unique_modes.
 	
 	% Is mode analysis allowed to change which procedure of a predicate
 	% is called. It may not change the called procedure after deforestation
@@ -90,257 +88,133 @@
 
 :- type mode_info.
 
-:- pred mode_info_init(io__state, module_info, pred_id, proc_id, prog_context,
-		set(prog_var), instmap, how_to_check_goal,
-		may_change_called_proc, mode_info).
-:- mode mode_info_init(di, in, in, in, in, in, in, in, in,
-		mode_info_uo) is det.
+:- pred mode_info_init(module_info::in, pred_id::in,
+	proc_id::in, prog_context::in, set(prog_var)::in, instmap::in,
+	how_to_check_goal::in, may_change_called_proc::in,
+	mode_info::out) is det.
+
+%-----------------------------------------------------------------------------%
+
+:- pred mode_info_get_module_info(mode_info::in, module_info::out) is det.
+:- pred mode_info_get_preds(mode_info::in, pred_table::out) is det.
+:- pred mode_info_get_modes(mode_info::in, mode_table::out) is det.
+:- pred mode_info_get_insts(mode_info::in, inst_table::out) is det.
+:- pred mode_info_get_predid(mode_info::in, pred_id::out) is det.
+:- pred mode_info_get_procid(mode_info::in, proc_id::out) is det.
+:- pred mode_info_get_context(mode_info::in, prog_context::out) is det.
+:- pred mode_info_get_mode_context(mode_info::in, mode_context::out) is det.
+:- pred mode_info_get_instmap(mode_info::in, instmap::out) is det.
+:- pred mode_info_get_locked_vars(mode_info::in, locked_vars::out) is det.
+:- pred mode_info_get_errors(mode_info::in, list(mode_error_info)::out) is det.
+:- pred mode_info_get_num_errors(mode_info::in, int::out) is det.
+:- pred mode_info_get_liveness(mode_info::in, set(prog_var)::out) is det.
+:- pred mode_info_get_varset(mode_info::in, prog_varset::out) is det.
+:- pred mode_info_get_instvarset(mode_info::in, inst_varset::out) is det.
+:- pred mode_info_get_var_types(mode_info::in,
+	map(prog_var, type)::out) is det.
+:- pred mode_info_get_delay_info(mode_info::in, delay_info::out) is det.
+:- pred mode_info_get_live_vars(mode_info::in,
+	list(set(prog_var))::out) is det.
+:- pred mode_info_get_nondet_live_vars(mode_info::in,
+	list(set(prog_var))::out) is det.
+:- pred mode_info_get_last_checkpoint_insts(mode_info::in,
+	assoc_list(prog_var, inst)::out) is det.
+:- pred mode_info_get_parallel_vars(mode_info::in,
+	list(pair(set(prog_var)))::out) is det.
+:- pred mode_info_get_changed_flag(mode_info::in, bool::out) is det.
+:- pred mode_info_get_how_to_check(mode_info::in,
+	how_to_check_goal::out) is det.
+:- pred mode_info_get_may_change_called_proc(mode_info::in,
+	may_change_called_proc::out) is det.
+
+%-----------------------------------------------------------------------------%
+
+:- pred mode_info_set_module_info(module_info::in,
+	mode_info::in, mode_info::out) is det.
+:- pred mode_info_set_predid(pred_id::in,
+	mode_info::in, mode_info::out) is det.
+:- pred mode_info_set_procid(proc_id::in,
+	mode_info::in, mode_info::out) is det.
+:- pred mode_info_set_context(prog_context::in,
+	mode_info::in, mode_info::out) is det.
+:- pred mode_info_set_mode_context(mode_context::in,
+	mode_info::in, mode_info::out) is det.
+:- pred mode_info_set_call_context(call_context::in,
+	mode_info::in, mode_info::out) is det.
+:- pred mode_info_set_call_arg_context(int::in,
+	mode_info::in, mode_info::out) is det.
+:- pred mode_info_unset_call_context(
+	mode_info::in, mode_info::out) is det.
+:- pred mode_info_set_instmap(instmap::in,
+	mode_info::in, mode_info::out) is det.
+:- pred mode_info_set_locked_vars(locked_vars::in,
+	mode_info::in, mode_info::out) is det.
+:- pred mode_info_set_errors(list(mode_error_info)::in,
+	mode_info::in, mode_info::out) is det.
+:- pred mode_info_add_live_vars(set(prog_var)::in,
+	mode_info::in, mode_info::out) is det.
+:- pred mode_info_remove_live_vars(set(prog_var)::in,
+	mode_info::in, mode_info::out) is det.
+:- pred mode_info_set_varset(prog_varset::in,
+	mode_info::in, mode_info::out) is det.
+:- pred mode_info_set_var_types(map(prog_var, type)::in,
+	mode_info::in, mode_info::out) is det.
+:- pred mode_info_set_delay_info(delay_info::in,
+	mode_info::in, mode_info::out) is det.
+:- pred mode_info_set_live_vars(list(set(prog_var))::in,
+	mode_info::in, mode_info::out) is det.
+:- pred mode_info_set_nondet_live_vars(list(set(prog_var))::in,
+	mode_info::in, mode_info::out) is det.
+:- pred mode_info_set_last_checkpoint_insts(assoc_list(prog_var, inst)::in,
+	mode_info::in, mode_info::out) is det.
+:- pred mode_info_set_parallel_vars(list(pair(set(prog_var)))::in,
+	mode_info::in, mode_info::out) is det.
+:- pred mode_info_set_changed_flag(bool::in,
+	mode_info::in, mode_info::out) is det.
+:- pred mode_info_set_how_to_check(how_to_check_goal::in,
+	mode_info::in, mode_info::out) is det.
+:- pred mode_info_set_may_change_called_proc(may_change_called_proc::in,
+	mode_info::in, mode_info::out) is det.
+:- pred mode_info_set_checking_extra_goals(bool::in,
+	mode_info::in, mode_info::out) is det.
+
+%-----------------------------------------------------------------------------%
+
+:- pred mode_info_get_types_of_vars(mode_info::in,
+	list(prog_var)::in, list(type)::out) is det.
 
-:- pred mode_info_get_io_state(mode_info, io__state).
-:- mode mode_info_get_io_state(mode_info_get_io_state, uo) is det.
+:- pred mode_info_lock_vars(var_lock_reason::in, set(prog_var)::in,
+	mode_info::in, mode_info::out) is det.
 
-:- pred mode_info_set_io_state(mode_info, io__state, mode_info).
-:- mode mode_info_set_io_state(mode_info_set_io_state, di, mode_info_uo) is det.
+:- pred mode_info_unlock_vars(var_lock_reason::in, set(prog_var)::in,
+	mode_info::in, mode_info::out) is det.
 
-:- pred mode_info_get_module_info(mode_info, module_info).
-:- mode mode_info_get_module_info(mode_info_ui, out) is det.
-
-:- pred mode_info_set_module_info(mode_info, module_info, mode_info).
-:- mode mode_info_set_module_info(mode_info_di, in, mode_info_uo) is det.
-
-:- pred mode_info_get_preds(mode_info, pred_table).
-:- mode mode_info_get_preds(mode_info_ui, out) is det.
-
-:- pred mode_info_get_modes(mode_info, mode_table).
-:- mode mode_info_get_modes(mode_info_ui, out) is det.
-
-:- pred mode_info_get_insts(mode_info, inst_table).
-:- mode mode_info_get_insts(mode_info_ui, out) is det.
-
-:- pred mode_info_get_predid(mode_info, pred_id).
-:- mode mode_info_get_predid(mode_info_ui, out) is det.
-
-:- pred mode_info_set_predid(mode_info, pred_id, mode_info).
-:- mode mode_info_set_predid(mode_info_ui, in, mode_info_uo) is det.
-
-:- pred mode_info_get_procid(mode_info, proc_id).
-:- mode mode_info_get_procid(mode_info_ui, out) is det.
-
-:- pred mode_info_set_procid(mode_info, proc_id, mode_info).
-:- mode mode_info_set_procid(mode_info_di, in, mode_info_uo) is det.
-
-:- pred mode_info_get_context(mode_info, prog_context).
-:- mode mode_info_get_context(mode_info_ui, out) is det.
-
-:- pred mode_info_set_context(prog_context, mode_info, mode_info).
-:- mode mode_info_set_context(in, mode_info_di, mode_info_uo) is det.
-
-:- pred mode_info_get_mode_context(mode_info, mode_context).
-:- mode mode_info_get_mode_context(mode_info_ui, out) is det.
-
-:- pred mode_info_set_mode_context(mode_context, mode_info, mode_info).
-:- mode mode_info_set_mode_context(in, mode_info_di, mode_info_uo) is det.
-
-:- pred mode_info_set_call_context(call_context, mode_info, mode_info).
-:- mode mode_info_set_call_context(in, mode_info_di, mode_info_uo) is det.
-
-:- pred mode_info_set_call_arg_context(int, mode_info, mode_info).
-:- mode mode_info_set_call_arg_context(in, mode_info_di, mode_info_uo) is det.
-
-:- pred mode_info_unset_call_context(mode_info, mode_info).
-:- mode mode_info_unset_call_context(mode_info_di, mode_info_uo) is det.
-
-:- pred mode_info_get_instmap(mode_info, instmap).
-:- mode mode_info_get_instmap(mode_info_ui, out) is det.
-
-:- pred mode_info_dcg_get_instmap(instmap, mode_info, mode_info).
-:- mode mode_info_dcg_get_instmap(out, mode_info_di, mode_info_uo) is det.
-
-:- pred mode_info_set_instmap(instmap, mode_info, mode_info).
-:- mode mode_info_set_instmap(in, mode_info_di, mode_info_uo) is det.
-
-:- pred mode_info_get_locked_vars(mode_info, locked_vars).
-:- mode mode_info_get_locked_vars(mode_info_ui, out) is det.
-
-:- pred mode_info_set_locked_vars(mode_info, locked_vars, mode_info).
-:- mode mode_info_set_locked_vars(mode_info_di, in, mode_info_uo) is det.
-
-:- pred mode_info_get_errors(mode_info, list(mode_error_info)).
-:- mode mode_info_get_errors(mode_info_ui, out) is det.
-
-:- pred mode_info_get_num_errors(mode_info, int).
-:- mode mode_info_get_num_errors(mode_info_ui, out) is det.
-
-:- pred mode_info_set_errors(list(mode_error_info), mode_info, mode_info).
-:- mode mode_info_set_errors(in, mode_info_di, mode_info_uo) is det.
-
-:- pred mode_info_add_live_vars(set(prog_var), mode_info, mode_info).
-:- mode mode_info_add_live_vars(in, mode_info_di, mode_info_uo) is det.
-
-:- pred mode_info_remove_live_vars(set(prog_var), mode_info, mode_info).
-:- mode mode_info_remove_live_vars(in, mode_info_di, mode_info_uo) is det.
-
-:- pred mode_info_var_list_is_live(list(prog_var), mode_info, list(is_live)).
-:- mode mode_info_var_list_is_live(in, mode_info_ui, out) is det.
-
-:- pred mode_info_var_is_live(mode_info, prog_var, is_live).
-:- mode mode_info_var_is_live(mode_info_ui, in, out) is det.
-
-:- pred mode_info_var_is_nondet_live(mode_info, prog_var, is_live).
-:- mode mode_info_var_is_nondet_live(mode_info_ui, in, out) is det.
-
-:- pred mode_info_get_liveness(mode_info, set(prog_var)).
-:- mode mode_info_get_liveness(mode_info_ui, out) is det.
-
-:- pred mode_info_get_liveness_2(list(set(prog_var)), set(prog_var),
-		set(prog_var)).
-:- mode mode_info_get_liveness_2(in, in, out) is det.
-
-:- pred mode_info_get_varset(mode_info, prog_varset).
-:- mode mode_info_get_varset(mode_info_ui, out) is det.
-
-:- pred mode_info_set_varset(prog_varset, mode_info, mode_info).
-:- mode mode_info_set_varset(in, mode_info_di, mode_info_uo) is det.
-
-:- pred mode_info_get_instvarset(mode_info, inst_varset).
-:- mode mode_info_get_instvarset(mode_info_ui, out) is det.
-
-:- pred mode_info_get_var_types(mode_info, map(prog_var, type)).
-:- mode mode_info_get_var_types(mode_info_ui, out) is det.
-
-:- pred mode_info_set_var_types(map(prog_var, type), mode_info, mode_info).
-:- mode mode_info_set_var_types(in, mode_info_di, mode_info_uo) is det.
-
-:- pred mode_info_get_types_of_vars(mode_info, list(prog_var), list(type)).
-:- mode mode_info_get_types_of_vars(mode_info_ui, in, out) is det.
-
-:- pred mode_info_lock_vars(var_lock_reason, set(prog_var),
-		mode_info, mode_info).
-:- mode mode_info_lock_vars(in, in, mode_info_di, mode_info_uo) is det.
-
-:- pred mode_info_unlock_vars(var_lock_reason, set(prog_var),
-		mode_info, mode_info).
-:- mode mode_info_unlock_vars(in, in, mode_info_di, mode_info_uo) is det.
-
-:- pred mode_info_var_is_locked(mode_info, prog_var, var_lock_reason).
-:- mode mode_info_var_is_locked(mode_info_ui, in, out) is semidet.
-
-:- pred mode_info_var_is_locked_2(locked_vars, prog_var, var_lock_reason).
-:- mode mode_info_var_is_locked_2(in, in, out) is semidet.
-
-:- pred mode_info_get_delay_info(mode_info, delay_info).
-:- mode mode_info_get_delay_info(mode_info_no_io, out) is det.
-
-:- pred mode_info_set_delay_info(delay_info, mode_info, mode_info).
-:- mode mode_info_set_delay_info(in, mode_info_di, mode_info_uo) is det.
-
-:- pred mode_info_get_live_vars(mode_info, list(set(prog_var))).
-:- mode mode_info_get_live_vars(mode_info_ui, out) is det.
-
-:- pred mode_info_set_live_vars(list(set(prog_var)), mode_info, mode_info).
-:- mode mode_info_set_live_vars(in, mode_info_di, mode_info_uo) is det.
-
-:- pred mode_info_get_nondet_live_vars(mode_info, list(set(prog_var))).
-:- mode mode_info_get_nondet_live_vars(mode_info_no_io, out) is det.
-
-:- pred mode_info_set_nondet_live_vars(list(set(prog_var)),
-		mode_info, mode_info).
-:- mode mode_info_set_nondet_live_vars(in, mode_info_di, mode_info_uo) is det.
-
-:- pred mode_info_get_last_checkpoint_insts(mode_info,
-		assoc_list(prog_var, inst)).
-:- mode mode_info_get_last_checkpoint_insts(mode_info_no_io, out) is det.
-
-:- pred mode_info_set_last_checkpoint_insts(assoc_list(prog_var, inst),
-	mode_info, mode_info).
-:- mode mode_info_set_last_checkpoint_insts(in, mode_info_di, mode_info_uo)
-	is det.
-
-:- pred mode_info_get_parallel_vars(list(pair(set(prog_var))), mode_info,
-		mode_info).
-:- mode mode_info_get_parallel_vars(out, mode_info_di, mode_info_uo) is det.
-
-:- pred mode_info_set_parallel_vars(list(pair(set(prog_var))), mode_info,
-		mode_info).
-:- mode mode_info_set_parallel_vars(in, mode_info_di, mode_info_uo) is det.
-
-:- pred mode_info_get_changed_flag(mode_info, bool).
-:- mode mode_info_get_changed_flag(mode_info_no_io, out) is det.
-
-:- pred mode_info_set_changed_flag(bool, mode_info, mode_info).
-:- mode mode_info_set_changed_flag(in, mode_info_di, mode_info_uo) is det.
-
-:- pred mode_info_get_how_to_check(mode_info, how_to_check_goal).
-:- mode mode_info_get_how_to_check(mode_info_ui, out) is det.
-
-:- pred mode_info_set_how_to_check(how_to_check_goal, mode_info, mode_info).
-:- mode mode_info_set_how_to_check(in, mode_info_di, mode_info_uo) is det.
-
-:- pred mode_info_get_may_change_called_proc(mode_info,
-		may_change_called_proc).
-:- mode mode_info_get_may_change_called_proc(mode_info_ui, out) is det.
-
-:- pred mode_info_set_may_change_called_proc(may_change_called_proc,
-		mode_info, mode_info).
-:- mode mode_info_set_may_change_called_proc(in,
-		mode_info_di, mode_info_uo) is det.
-
-:- pred mode_info_set_checking_extra_goals(bool, mode_info, mode_info).
-:- mode mode_info_set_checking_extra_goals(in,
-		mode_info_di, mode_info_uo) is det.
+:- pred mode_info_var_is_locked(mode_info::in, prog_var::in,
+	var_lock_reason::out) is semidet.
 
 	% Find the simple_call_id to use in error messages
 	% for the given pred_id.
-:- pred mode_info_get_call_id(mode_info, pred_id, simple_call_id).
-:- mode mode_info_get_call_id(mode_info_ui, in, out) is det.
+:- pred mode_info_get_call_id(mode_info::in, pred_id::in,
+	simple_call_id::out) is det.
 
-/*
-:- inst uniq_mode_info	=	bound_unique(
-					mode_info(
-						unique,
-						ground, ground, ground,
-						ground, ground, ground, ground,
-						ground, ground, ground, ground,
-						ground, ground, ground, ground,
-						ground
-					)
-				).
-*/
-:- inst uniq_mode_info	=	ground.
+:- pred mode_info_var_list_is_live(mode_info::in, list(prog_var)::in,
+	list(is_live)::out) is det.
 
-:- mode mode_info_uo :: free -> uniq_mode_info.
-:- mode mode_info_ui :: uniq_mode_info -> uniq_mode_info.
-:- mode mode_info_di :: uniq_mode_info -> dead.
+:- pred mode_info_var_is_live(mode_info::in, prog_var::in,
+	is_live::out) is det.
 
-	% Some fiddly modes used when we want to extract
-	% the io_state from a mode_info struct and then put it back again.
-
-/*
-:- inst mode_info_no_io	=	bound_unique(
-					mode_info(
-						dead, ground, ground, ground,
-						ground, ground, ground, ground,
-						ground, ground, ground, ground,
-						ground, ground, ground, ground,
-						ground
-					)
-				).
-*/
-:- inst mode_info_no_io	=	ground.
-
-:- mode mode_info_get_io_state	:: uniq_mode_info -> mode_info_no_io.
-:- mode mode_info_no_io		:: mode_info_no_io -> mode_info_no_io.
-:- mode mode_info_set_io_state	:: mode_info_no_io -> dead.
+:- pred mode_info_var_is_nondet_live(mode_info::in, prog_var::in,
+	is_live::out) is det.
 
 %-----------------------------------------------------------------------------%
 
         % record a mode error (and associated context info) in the mode_info.
 
-:- pred mode_info_error(set(prog_var), mode_error, mode_info, mode_info).
-:- mode mode_info_error(in, in, mode_info_di, mode_info_uo) is det.
+:- pred mode_info_error(set(prog_var)::in, mode_error::in,
+	mode_info::in, mode_info::out) is det.
 
-:- pred mode_info_add_error(mode_error_info, mode_info, mode_info).
-:- mode mode_info_add_error(in, mode_info_di, mode_info_uo) is det.
+:- pred mode_info_add_error(mode_error_info::in,
+	mode_info::in, mode_info::out) is det.
 
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
@@ -351,12 +225,11 @@
 :- import_module check_hlds__mode_errors.
 :- import_module check_hlds__mode_util.
 
-:- import_module term, varset.
+:- import_module string, term, varset.
 :- import_module require, std_util, queue.
 
 :- type mode_info --->
 	mode_info(
-		io_state	:: io__state,
 		module_info	:: module_info,
 		predid		:: pred_id,
 				% The pred we are checking
@@ -456,16 +329,12 @@
 				% extra unifications.
 	).
 
-	% The normal inst of a mode_info struct: ground, with
-	% the io_state and the struct itself unique, but with
-	% multiple references allowed for the other parts.
-
 %-----------------------------------------------------------------------------%
 
 	% Initialize the mode_info
 
-mode_info_init(IOState, ModuleInfo, PredId, ProcId, Context,
-		LiveVars, InstMapping0, HowToCheck, MayChangeProc, ModeInfo) :-
+mode_info_init(ModuleInfo, PredId, ProcId, Context, LiveVars, InstMapping0,
+		HowToCheck, MayChangeProc, ModeInfo) :-
 	mode_context_init(ModeContext),
 	LockedVars = [],
 	delay_info__init(DelayInfo),
@@ -485,82 +354,69 @@
 	Changed = no,
 	CheckingExtraGoals = no,
 
-	ModeInfo = mode_info(
-		IOState, ModuleInfo, PredId, ProcId, VarSet, VarTypes,
+	ModeInfo = mode_info(ModuleInfo, PredId, ProcId, VarSet, VarTypes,
 		Context, ModeContext, InstMapping0, LockedVars, DelayInfo,
-		ErrorList, LiveVarsList, NondetLiveVarsList, InstVarSet, [], [],
-		Changed, HowToCheck, MayChangeProc, CheckingExtraGoals
+		ErrorList, LiveVarsList, NondetLiveVarsList, InstVarSet,
+		[], [], Changed, HowToCheck, MayChangeProc, CheckingExtraGoals
 	).
 
 %-----------------------------------------------------------------------------%
 
-	% Lots of very boring access predicates.
-
-mode_info_get_io_state(ModeInfo, IOState) :-
-	% XXX
-	unsafe_promise_unique(ModeInfo^io_state, IOState).
-
-mode_info_set_io_state(ModeInfo, IOState0, ModeInfo^io_state := IOState) :-
-	% XXX
-	unsafe_promise_unique(IOState0, IOState).
+mode_info_get_module_info(MI, MI ^ module_info).
+mode_info_get_predid(MI, MI ^ predid).
+mode_info_get_procid(MI, MI ^ procid).
+mode_info_get_varset(MI, MI ^ varset).
+mode_info_get_var_types(MI, MI ^ var_types).
+mode_info_get_context(MI, MI ^ context).
+mode_info_get_mode_context(MI, MI ^ mode_context).
+mode_info_get_instmap(MI, MI ^ instmap).
+mode_info_get_locked_vars(MI, MI ^ locked_vars).
+mode_info_get_errors(MI, MI ^ errors).
+mode_info_get_delay_info(MI, MI ^ delay_info).
+mode_info_get_live_vars(MI, MI ^ live_vars).
+mode_info_get_nondet_live_vars(MI, MI ^ nondet_live_vars).
+mode_info_get_last_checkpoint_insts(MI, MI ^ last_checkpoint_insts).
+mode_info_get_parallel_vars(MI, MI ^  parallel_vars).
+mode_info_get_changed_flag(MI, MI ^ changed_flag).
+mode_info_get_how_to_check(MI, MI ^ how_to_check).
+mode_info_get_may_change_called_proc(MI, MI ^ may_change_called_proc).
+
+mode_info_set_module_info(ModuleInfo, MI, MI ^ module_info := ModuleInfo).
+mode_info_set_predid(PredId, MI, MI ^ predid := PredId).
+mode_info_set_procid(ProcId, MI, MI ^ procid := ProcId).
+mode_info_set_varset(VarSet, MI, MI ^ varset := VarSet).
+mode_info_set_var_types(VTypes, MI, MI ^ var_types := VTypes).
+mode_info_set_context(Context, MI, MI ^ context := Context).
+mode_info_set_mode_context(ModeContext, MI, MI ^ mode_context := ModeContext).
+mode_info_set_locked_vars(LockedVars, MI, MI ^ locked_vars := LockedVars).
+mode_info_set_errors(Errors, MI, MI ^ errors := Errors).
+mode_info_set_delay_info(DelayInfo, MI, MI ^ delay_info := DelayInfo).
+mode_info_set_live_vars(LiveVarsList, MI, MI ^ live_vars := LiveVarsList).
+mode_info_set_nondet_live_vars(NondetLiveVars, MI,
+	MI ^ nondet_live_vars := NondetLiveVars).
+mode_info_set_last_checkpoint_insts(LastCheckpointInsts, MI,
+	MI ^ last_checkpoint_insts := LastCheckpointInsts).
+mode_info_set_parallel_vars(PVars, MI, MI ^ parallel_vars := PVars).
+mode_info_set_changed_flag(Changed, MI, MI ^ changed_flag := Changed).
+mode_info_set_how_to_check(How, MI, MI ^ how_to_check := How).
+mode_info_set_may_change_called_proc(MayChange, MI,
+	MI ^ may_change_called_proc := MayChange).
 
 %-----------------------------------------------------------------------------%
 
 mode_info_get_preds(ModeInfo, Preds) :-
-	module_info_preds(ModeInfo^module_info, Preds).
+	module_info_preds(ModeInfo ^ module_info, Preds).
 
 mode_info_get_modes(ModeInfo, Modes) :-
-	module_info_modes(ModeInfo^module_info, Modes).
+	module_info_modes(ModeInfo ^ module_info, Modes).
 
 mode_info_get_insts(ModeInfo, Insts) :-
-	module_info_insts(ModeInfo^module_info, Insts).
+	module_info_insts(ModeInfo ^ module_info, Insts).
 
-mode_info_get_module_info(MI, MI^module_info).
-mode_info_get_predid(MI, MI^predid).
-mode_info_get_procid(MI, MI^procid).
-mode_info_get_varset(MI, MI^varset).
-mode_info_get_var_types(MI, MI^var_types).
-mode_info_get_context(MI, MI^context).
-mode_info_get_mode_context(MI, MI^mode_context).
-mode_info_get_instmap(MI, MI^instmap).
-mode_info_get_locked_vars(MI, MI^locked_vars).
-mode_info_get_errors(MI, MI^errors).
-mode_info_get_delay_info(MI, MI^delay_info).
-mode_info_get_live_vars(MI, MI^live_vars).
-mode_info_get_nondet_live_vars(MI, MI^nondet_live_vars).
-mode_info_get_last_checkpoint_insts(MI, MI^last_checkpoint_insts).
-mode_info_get_parallel_vars(PVars) --> PVars =^ parallel_vars.
-mode_info_get_changed_flag(MI, MI^changed_flag).
-mode_info_get_how_to_check(MI, MI^how_to_check).
-mode_info_get_may_change_called_proc(MI, MI^may_change_called_proc).
-
-mode_info_set_module_info(MI, ModuleInfo, MI^module_info := ModuleInfo).
-mode_info_set_predid(MI, PredId, MI^predid := PredId).
-mode_info_set_procid(MI, ProcId, MI^procid := ProcId).
-mode_info_set_varset(VarSet) --> ^varset := VarSet.
-mode_info_set_var_types(VTypes) --> ^var_types := VTypes.
-mode_info_set_context(Context) --> ^context := Context.
-mode_info_set_mode_context(ModeContext) --> ^mode_context := ModeContext.
-mode_info_set_locked_vars(MI, LockedVars, MI^locked_vars := LockedVars).
-mode_info_set_errors(Errors) --> ^errors := Errors.
-mode_info_set_delay_info(DelayInfo) --> ^delay_info := DelayInfo.
-mode_info_set_live_vars(LiveVarsList) --> ^live_vars := LiveVarsList.
-mode_info_set_nondet_live_vars(NondetLiveVars) -->
-	^nondet_live_vars := NondetLiveVars.
-mode_info_set_last_checkpoint_insts(LastCheckpointInsts) -->
-	^last_checkpoint_insts := LastCheckpointInsts.
-mode_info_set_parallel_vars(PVars) --> ^parallel_vars := PVars.
-mode_info_set_changed_flag(Changed) --> ^changed_flag := Changed.
-mode_info_set_how_to_check(How) --> ^how_to_check := How.
-mode_info_set_may_change_called_proc(MayChange) -->
-	^may_change_called_proc := MayChange.
-
-%-----------------------------------------------------------------------------%
-
-mode_info_set_call_context(unify(UnifyContext)) -->
-	mode_info_set_mode_context(unify(UnifyContext, left)).
-mode_info_set_call_context(call(CallId)) -->
-	mode_info_set_mode_context(call(CallId, 0)).
+mode_info_set_call_context(unify(UnifyContext), !MI) :-
+	mode_info_set_mode_context(unify(UnifyContext, left), !MI).
+mode_info_set_call_context(call(CallId), !MI) :-
+	mode_info_set_mode_context(call(CallId, 0), !MI).
 
 mode_info_set_call_arg_context(ArgNum, ModeInfo0, ModeInfo) :-
 	mode_info_get_mode_context(ModeInfo0, ModeContext0),
@@ -576,31 +432,23 @@
 		error("mode_info_set_call_arg_context")
 	).
 
-mode_info_unset_call_context -->
-	mode_info_set_mode_context(uninitialized).
-
-%-----------------------------------------------------------------------------%
-
-	% mode_info_dcg_get_instmap/3 is the same as mode_info_get_instmap/2
-	% except that it's easier to use inside a DCG.
-
-mode_info_dcg_get_instmap(InstMap, ModeInfo, ModeInfo) :-
-	mode_info_get_instmap(ModeInfo, InstMap).
+mode_info_unset_call_context(!MI) :-
+	mode_info_set_mode_context(uninitialized, !MI).
 
 %-----------------------------------------------------------------------------%
 
-mode_info_set_instmap(InstMap) -->
-	InstMap0 =^ instmap,
-	^instmap := InstMap,
+mode_info_set_instmap(InstMap, !MI) :-
+	InstMap0 = !.MI ^ instmap,
+	!:MI = !.MI ^ instmap := InstMap,
 	(
-		{ instmap__is_unreachable(InstMap) },
-		{ instmap__is_reachable(InstMap0) }
+		instmap__is_unreachable(InstMap),
+		instmap__is_reachable(InstMap0)
 	->
-		DelayInfo0 =^ delay_info,
-		{ delay_info__bind_all_vars(DelayInfo0, DelayInfo) },
-		^delay_info := DelayInfo
+		DelayInfo0 = !.MI ^ delay_info,
+		delay_info__bind_all_vars(DelayInfo0, DelayInfo),
+		!:MI = !.MI ^ delay_info := DelayInfo
 	;
-		[]
+		true
 	).
 
 %-----------------------------------------------------------------------------%
@@ -618,19 +466,19 @@
 	% Add a set of vars to the bag of live vars and
 	% the bag of nondet-live vars.
 
-mode_info_add_live_vars(NewLiveVars) -->
-	LiveVars0 =^ live_vars,
-	NondetLiveVars0 =^ nondet_live_vars,
-	^live_vars := [NewLiveVars | LiveVars0],
-	^nondet_live_vars := [NewLiveVars | NondetLiveVars0].
+mode_info_add_live_vars(NewLiveVars, !MI) :-
+	LiveVars0 = !.MI ^ live_vars,
+	NondetLiveVars0 = !.MI ^ nondet_live_vars,
+	!:MI = !.MI ^ live_vars := [NewLiveVars | LiveVars0],
+	!:MI = !.MI ^ nondet_live_vars := [NewLiveVars | NondetLiveVars0].
 
 	% Remove a set of vars from the bag of live vars and
 	% the bag of nondet-live vars.
 
-mode_info_remove_live_vars(OldLiveVars) -->
-	LiveVars0 =^ live_vars,
-	NondetLiveVars0 =^ nondet_live_vars,
-	{
+mode_info_remove_live_vars(OldLiveVars, !MI) :-
+	LiveVars0 = !.MI ^ live_vars,
+	NondetLiveVars0 = !.MI ^ nondet_live_vars,
+	(
 		list__delete_first(LiveVars0, OldLiveVars, LiveVars1),
 		list__delete_first(NondetLiveVars0, OldLiveVars,
 			NondetLiveVars1)
@@ -639,22 +487,22 @@
 		NondetLiveVars = NondetLiveVars1
 	;
 		error("mode_info_remove_live_vars: failed")
-	},
-	^live_vars := LiveVars,
-	^nondet_live_vars := NondetLiveVars,
+	),
+	!:MI = !.MI ^ live_vars := LiveVars,
+	!:MI = !.MI ^ nondet_live_vars := NondetLiveVars,
 		% when a variable becomes dead, we may be able to wake
 		% up a goal which is waiting on that variable
-	{ set__to_sorted_list(OldLiveVars, VarList) },
-	DelayInfo0 =^ delay_info,
-	{ delay_info__bind_var_list(VarList, DelayInfo0, DelayInfo) },
-	^delay_info := DelayInfo.
+	set__to_sorted_list(OldLiveVars, VarList),
+	DelayInfo0 = !.MI ^ delay_info,
+	delay_info__bind_var_list(VarList, DelayInfo0, DelayInfo),
+	!:MI = !.MI ^ delay_info := DelayInfo.
 
 	% Check whether a list of variables are live or not
 
-mode_info_var_list_is_live([], _, []).
-mode_info_var_list_is_live([Var | Vars], ModeInfo, [Live | Lives]) :-
+mode_info_var_list_is_live(_, [], []).
+mode_info_var_list_is_live(ModeInfo, [Var | Vars], [Live | Lives]) :-
 	mode_info_var_is_live(ModeInfo, Var, Live),
-	mode_info_var_list_is_live(Vars, ModeInfo, Lives).
+	mode_info_var_list_is_live(ModeInfo, Vars, Lives).
 
 	% Check whether a variable is live or not
 
@@ -684,7 +532,10 @@
 
 mode_info_get_liveness(ModeInfo, LiveVars) :-
 	set__init(LiveVars0),
-	mode_info_get_liveness_2(ModeInfo^live_vars, LiveVars0, LiveVars).
+	mode_info_get_liveness_2(ModeInfo ^ live_vars, LiveVars0, LiveVars).
+
+:- pred mode_info_get_liveness_2(list(set(prog_var))::in, set(prog_var)::in,
+	set(prog_var)::out) is det.
 
 mode_info_get_liveness_2([], LiveVars, LiveVars).
 mode_info_get_liveness_2([LiveVarsSet | LiveVarsList], LiveVars0, LiveVars) :-
@@ -693,7 +544,7 @@
 
 %-----------------------------------------------------------------------------%
 
-mode_info_get_instvarset(ModeInfo, ModeInfo^instvarset).
+mode_info_get_instvarset(ModeInfo, ModeInfo ^ instvarset).
 
 mode_info_get_types_of_vars(ModeInfo, Vars, TypesOfVars) :-
 	mode_info_get_var_types(ModeInfo, VarTypes),
@@ -708,13 +559,12 @@
 	% push them on the stack, and to unlock a set of vars, we just
 	% pop them off the stack.  The stack is implemented as a list.
 
-mode_info_lock_vars(Reason, Vars, ModeInfo0, ModeInfo) :-
-	mode_info_get_locked_vars(ModeInfo0, LockedVars),
-	mode_info_set_locked_vars(ModeInfo0, [Reason - Vars | LockedVars],
-			ModeInfo).
+mode_info_lock_vars(Reason, Vars, !ModeInfo) :-
+	mode_info_get_locked_vars(!.ModeInfo, LockedVars),
+	mode_info_set_locked_vars([Reason - Vars | LockedVars], !ModeInfo).
 
-mode_info_unlock_vars(Reason, Vars, ModeInfo0, ModeInfo) :-
-	mode_info_get_locked_vars(ModeInfo0, LockedVars0),
+mode_info_unlock_vars(Reason, Vars, !ModeInfo) :-
+	mode_info_get_locked_vars(!.ModeInfo, LockedVars0),
 	(
 		LockedVars0 = [Reason - TheseVars | LockedVars1],
 		set__equal(TheseVars, Vars)
@@ -723,30 +573,34 @@
 	;
 		error("mode_info_unlock_vars: some kind of nesting error")
 	),
-	mode_info_set_locked_vars(ModeInfo0, LockedVars, ModeInfo).
+	mode_info_set_locked_vars(LockedVars, !ModeInfo).
 
 mode_info_var_is_locked(ModeInfo, Var, Reason) :-
 	mode_info_get_locked_vars(ModeInfo, LockedVarsList),
 	mode_info_var_is_locked_2(LockedVarsList, Var, Reason).
 
+:- pred mode_info_var_is_locked_2(locked_vars::in, prog_var::in,
+	var_lock_reason::out) is semidet.
+
 mode_info_var_is_locked_2([ThisReason - Set | Sets], Var, Reason) :-
-	(
-		set__member(Var, Set)
-	->
+	( set__member(Var, Set) ->
 		Reason = ThisReason
 	;
 		mode_info_var_is_locked_2(Sets, Var, Reason)
 	).
 
-mode_info_set_checking_extra_goals(Checking) -->
-	( yes =^ checking_extra_goals, { Checking = yes } ->
+mode_info_set_checking_extra_goals(Checking, !MI) :-
+	(
+		yes = !.MI ^ checking_extra_goals,
+		Checking = yes
+	->
 		% This should never happen - once the extra goals are
 		% introduced, rechecking the goal should not introduce
 		% more extra goals.
-		{ error(
-		"mode analysis: rechecking extra goals adds more extra goals") }
+		error("mode analysis: rechecking extra goals " ++
+			"adds more extra goals")
 	;
-		^checking_extra_goals := Checking
+		!:MI = !.MI ^ checking_extra_goals := Checking
 	).
 
 %-----------------------------------------------------------------------------%
@@ -758,15 +612,15 @@
 
 %-----------------------------------------------------------------------------%
 
-mode_info_error(Vars, ModeError, ModeInfo0, ModeInfo) :-
-        mode_info_get_context(ModeInfo0, Context),
-        mode_info_get_mode_context(ModeInfo0, ModeContext),
+mode_info_error(Vars, ModeError, !ModeInfo) :-
+        mode_info_get_context(!.ModeInfo, Context),
+        mode_info_get_mode_context(!.ModeInfo, ModeContext),
         ModeErrorInfo = mode_error_info(Vars, ModeError, Context, ModeContext),
-        mode_info_add_error(ModeErrorInfo, ModeInfo0, ModeInfo).
+        mode_info_add_error(ModeErrorInfo, !ModeInfo).
 
-mode_info_add_error(ModeErrorInfo, ModeInfo0, ModeInfo) :-
-        mode_info_get_errors(ModeInfo0, Errors0),
+mode_info_add_error(ModeErrorInfo, !ModeInfo) :-
+        mode_info_get_errors(!.ModeInfo, Errors0),
         list__append(Errors0, [ModeErrorInfo], Errors),
-        mode_info_set_errors(Errors, ModeInfo0, ModeInfo).
+        mode_info_set_errors(Errors, !ModeInfo).
 
 %-----------------------------------------------------------------------------%
Index: compiler/modecheck_call.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/modecheck_call.m,v
retrieving revision 1.47
diff -u -b -r1.47 modecheck_call.m
--- compiler/modecheck_call.m	31 Oct 2003 03:27:26 -0000	1.47
+++ compiler/modecheck_call.m	5 Nov 2003 22:49:26 -0000
@@ -34,24 +34,24 @@
 		maybe(determinism), proc_id, list(prog_var),
 		extra_goals, mode_info, mode_info).
 :- mode modecheck_call_pred(in, in, in, in, out, out, out,
-		mode_info_di, mode_info_uo) is det.
+		in, out) is det.
 
 :- pred modecheck_higher_order_call(pred_or_func, prog_var, list(prog_var),
 		list(mode), determinism, list(prog_var),
 		extra_goals, mode_info, mode_info).
 :- mode modecheck_higher_order_call(in, in, in, out, out, out, out,
-		mode_info_di, mode_info_uo) is det.
+		in, out) is det.
 
 :- pred modecheck_aditi_builtin(aditi_builtin, simple_call_id,
 		list(prog_var), list(mode), determinism,
 		list(prog_var), extra_goals, mode_info, mode_info).
 :- mode modecheck_aditi_builtin(in, in, in, in, out, out, out,
-		mode_info_di, mode_info_uo) is det.
+		in, out) is det.
 
 :- pred modecheck_builtin_cast(list(prog_var), list(mode), determinism,
 		list(prog_var), extra_goals, mode_info, mode_info).
 :- mode modecheck_builtin_cast(in, in, out, out, out,
-		mode_info_di, mode_info_uo) is det.
+		in, out) is det.
 
 	%
 	% Given two modes of a predicate, figure out whether
@@ -177,7 +177,7 @@
 :- pred modecheck_arg_list(int, list(mode), extra_goals,
 		list(prog_var), list(prog_var), mode_info, mode_info).
 :- mode modecheck_arg_list(in, in, out, in, out,
-		mode_info_di, mode_info_uo) is det.
+		in, out) is det.
 
 modecheck_arg_list(ArgOffset, Modes, ExtraGoals, Args0, Args,
 		ModeInfo0, ModeInfo) :-
@@ -340,7 +340,7 @@
 
 :- pred no_matching_modes(pred_id, list(prog_var), maybe(determinism),
 		set(prog_var), proc_id, mode_info, mode_info).
-:- mode no_matching_modes(in, in, in, in, out, mode_info_di, mode_info_uo)
+:- mode no_matching_modes(in, in, in, in, out, in, out)
 	is det.
 
 no_matching_modes(PredId, ArgVars, DeterminismKnown, WaitingVars, TheProcId,
@@ -379,7 +379,7 @@
 		list(prog_var), list(proc_mode), list(proc_mode), set(prog_var),
 		set(prog_var), mode_info, mode_info).
 :- mode modecheck_find_matching_modes(in, in, in, in,
-			in, out, in, out, mode_info_di, mode_info_uo) is det.
+			in, out, in, out, in, out) is det.
 
 modecheck_find_matching_modes([], _PredId, _Procs, _ArgVars,
 			MatchingProcIds, MatchingProcIds,
@@ -456,7 +456,7 @@
 :- pred modecheck_end_of_call(proc_info, list(mode), list(prog_var), int,
 	inst_var_sub, list(prog_var), extra_goals, mode_info, mode_info).
 :- mode modecheck_end_of_call(in, in, in, in, in, out, out,
-				mode_info_di, mode_info_uo) is det.
+				in, out) is det.
 
 modecheck_end_of_call(ProcInfo, ProcArgModes, ArgVars0, ArgOffset, InstVarSub,
 			ArgVars, ExtraGoals, ModeInfo0, ModeInfo) :-
@@ -477,7 +477,7 @@
 
 :- pred insert_new_mode(pred_id, list(prog_var), maybe(determinism), proc_id,
 			mode_info, mode_info).
-:- mode insert_new_mode(in, in, in, out, mode_info_di, mode_info_uo) is det.
+:- mode insert_new_mode(in, in, in, out, in, out) is det.
 
 	% Insert a new inferred mode for a predicate.
 	% The initial insts are determined by using a normalised
@@ -506,7 +506,7 @@
 	unify_proc__request_proc(PredId, Modes, InstVarSet, yes(ArgLives),
 		MaybeDet, Context, ProcId, ModuleInfo0, ModuleInfo),
 
-	mode_info_set_module_info(ModeInfo0, ModuleInfo, ModeInfo1),
+	mode_info_set_module_info(ModuleInfo, ModeInfo0, ModeInfo1),
 
 	% Since we've created a new inferred mode for this predicate,
 	% things have changed, so we will need to do at least one more
@@ -515,7 +515,7 @@
 
 :- pred get_var_insts_and_lives(list(prog_var), mode_info,
 				list(inst), list(is_live)).
-:- mode get_var_insts_and_lives(in, mode_info_ui, out, out) is det.
+:- mode get_var_insts_and_lives(in, in, out, out) is det.
 
 get_var_insts_and_lives([], _, [], []).
 get_var_insts_and_lives([Var | Vars], ModeInfo,
@@ -703,7 +703,7 @@
 :- pred choose_best_match(list(proc_mode), pred_id,
 		proc_table, list(prog_var), proc_id, inst_var_sub, list(mode),
 		mode_info).
-:- mode choose_best_match(in, in, in, in, out, out, out, mode_info_ui) is det.
+:- mode choose_best_match(in, in, in, in, out, out, out, in) is det.
 
 choose_best_match([], _, _, _, _, _, _, _) :-
 	error("choose_best_match: no best match").
@@ -739,7 +739,7 @@
 	%
 :- pred compare_proc(proc_id, proc_id, list(prog_var), match, proc_table,
 		mode_info).
-:- mode compare_proc(in, in, in, out, in, mode_info_ui) is det.
+:- mode compare_proc(in, in, in, out, in, in) is det.
 
 compare_proc(ProcId, OtherProcId, ArgVars, Compare, Procs, ModeInfo) :-
 	map__lookup(Procs, ProcId, ProcInfo),
Index: compiler/modecheck_unify.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/modecheck_unify.m,v
retrieving revision 1.65
diff -u -b -r1.65 modecheck_unify.m
--- compiler/modecheck_unify.m	5 Nov 2003 03:17:41 -0000	1.65
+++ compiler/modecheck_unify.m	5 Nov 2003 23:00:59 -0000
@@ -23,19 +23,17 @@
 :- import_module check_hlds__mode_info.
 :- import_module hlds__hlds_goal.
 :- import_module parse_tree__prog_data.
+:- import_module io.
 
 	% Modecheck a unification
-:- pred modecheck_unification(prog_var, unify_rhs, unification, unify_context,
-			hlds_goal_info, hlds_goal_expr, mode_info, mode_info).
-:- mode modecheck_unification(in, in, in, in, in, out,
-			mode_info_di, mode_info_uo) is det.
+:- 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.
-:- pred modecheck_unify__create_var_var_unification(prog_var, prog_var, type,
-		mode_info, hlds_goal).
-:- mode modecheck_unify__create_var_var_unification(in, in, in,
-		mode_info_ui, out) is det.
+:- pred modecheck_unify__create_var_var_unification(prog_var::in, prog_var::in,
+	(type)::in, mode_info::in, hlds_goal::out) is det.
 
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
@@ -74,13 +72,13 @@
 %-----------------------------------------------------------------------------%
 
 modecheck_unification(X, var(Y), Unification0, UnifyContext, _GoalInfo,
-			Unify, ModeInfo0, ModeInfo) :-
-	mode_info_get_module_info(ModeInfo0, ModuleInfo0),
-	mode_info_get_instmap(ModeInfo0, InstMap0),
+		Unify, !ModeInfo, !IO) :-
+	mode_info_get_module_info(!.ModeInfo, ModuleInfo0),
+	mode_info_get_instmap(!.ModeInfo, InstMap0),
 	instmap__lookup_var(InstMap0, X, InstOfX),
 	instmap__lookup_var(InstMap0, Y, InstOfY),
-	mode_info_var_is_live(ModeInfo0, X, LiveX),
-	mode_info_var_is_live(ModeInfo0, Y, LiveY),
+	mode_info_var_is_live(!.ModeInfo, X, LiveX),
+	mode_info_var_is_live(!.ModeInfo, Y, LiveY),
 	(
 		( LiveX = live, LiveY = live ->
 			BothLive = live
@@ -97,8 +95,8 @@
 		% like this one?)
 		\+ (
 			UnifyInst = free,
-			mode_info_var_is_locked(ModeInfo0, X, _XLockedReason),
-			mode_info_var_is_locked(ModeInfo0, Y, _YLockedReason),
+			mode_info_var_is_locked(!.ModeInfo, X, _XLockedReason),
+			mode_info_var_is_locked(!.ModeInfo, Y, _YLockedReason),
 			% a unification of the form `X = X' doesn't bind X,
 			% and thus should be allowed even if X is locked
 			X \= Y
@@ -106,29 +104,27 @@
 	->
 		Inst = UnifyInst,
 		Det = Det1,
-		mode_info_set_module_info(ModeInfo0, ModuleInfo1, ModeInfo1),
-		modecheck_set_var_inst(X, Inst, yes(InstOfY),
-			ModeInfo1, ModeInfo2),
-		modecheck_set_var_inst(Y, Inst, yes(InstOfX),
-			ModeInfo2, ModeInfo3),
+		mode_info_set_module_info(ModuleInfo1, !ModeInfo),
+		modecheck_set_var_inst(X, Inst, yes(InstOfY), !ModeInfo),
+		modecheck_set_var_inst(Y, Inst, yes(InstOfX), !ModeInfo),
 		ModeOfX = (InstOfX -> Inst),
 		ModeOfY = (InstOfY -> Inst),
-		mode_info_get_var_types(ModeInfo3, VarTypes),
+		mode_info_get_var_types(!.ModeInfo, VarTypes),
 		categorize_unify_var_var(ModeOfX, ModeOfY, LiveX, LiveY, X, Y,
-			Det, UnifyContext, VarTypes, Unification0, ModeInfo3,
-			Unify, ModeInfo)
+			Det, UnifyContext, VarTypes, Unification0, Unify,
+			!ModeInfo)
 	;
 		set__list_to_set([X, Y], WaitingVars),
 		mode_info_error(WaitingVars, mode_error_unify_var_var(X, Y,
-				InstOfX, InstOfY), ModeInfo0, ModeInfo1),
+				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, ModeInfo1, ModeInfo2),
-		modecheck_set_var_inst(Y, Inst, no, ModeInfo2, ModeInfo),
+		modecheck_set_var_inst(X, Inst, no, !ModeInfo),
+		modecheck_set_var_inst(Y, Inst, no, !ModeInfo),
 			% return any old garbage
 		Unification = assign(X, Y),
 		ModeOfX = (InstOfX -> Inst),
@@ -139,9 +135,9 @@
 
 modecheck_unification(X0, functor(ConsId0, IsExistConstruction, ArgVars0),
 			Unification0, UnifyContext, GoalInfo0, Goal,
-			ModeInfo0, ModeInfo) :-
-	mode_info_get_module_info(ModeInfo0, ModuleInfo0),
-	mode_info_get_var_types(ModeInfo0, VarTypes0),
+		!ModeInfo, !IO) :-
+	mode_info_get_module_info(!.ModeInfo, ModuleInfo0),
+	mode_info_get_var_types(!.ModeInfo, VarTypes0),
 	map__lookup(VarTypes0, X0, TypeOfX),
 
 	%
@@ -169,20 +165,20 @@
 		%
 		% convert the pred term to a lambda expression
 		%
-		mode_info_get_varset(ModeInfo0, VarSet0),
-		mode_info_get_context(ModeInfo0, Context),
+		mode_info_get_varset(!.ModeInfo, VarSet0),
+		mode_info_get_context(!.ModeInfo, Context),
 		convert_pred_to_lambda_goal(Purity, EvalMethod,
 			X0, PredId, ProcId, ArgVars0, PredArgTypes,
 			UnifyContext, GoalInfo0, Context,
 			ModuleInfo0, Functor0,
 			VarSet0, VarSet, VarTypes0, VarTypes),
-		mode_info_set_varset(VarSet, ModeInfo0, ModeInfo1),
-		mode_info_set_var_types(VarTypes, ModeInfo1, ModeInfo2),
+		mode_info_set_varset(VarSet, !ModeInfo),
+		mode_info_set_var_types(VarTypes, !ModeInfo),
 		%
 		% modecheck this unification in its new form
 		%
 		modecheck_unification(X0, Functor0, Unification0, UnifyContext,
-				GoalInfo0, Goal, ModeInfo2, ModeInfo)
+			GoalInfo0, Goal, !ModeInfo, !IO)
 	;
 		%
 		% It's not a higher-order pred unification - just
@@ -190,15 +186,14 @@
 		%
 		modecheck_unify_functor(X0, TypeOfX, ConsId0,
 			IsExistConstruction, ArgVars0, Unification0,
-			UnifyContext, GoalInfo0, Goal, ModeInfo0, ModeInfo)
+			UnifyContext, GoalInfo0, Goal, !ModeInfo, !IO)
 	).
 
-modecheck_unification(X, 
-		lambda_goal(Purity, PredOrFunc, EvalMethod, _, ArgVars,
-			Vars, Modes0, Det, Goal0),
+modecheck_unification(X, lambda_goal(Purity, PredOrFunc, EvalMethod, _,
+			ArgVars, Vars, Modes0, Det, Goal0),
 		Unification0, UnifyContext, _GoalInfo, 
 		unify(X, RHS, Mode, Unification, UnifyContext),
-		ModeInfo0, ModeInfo) :-
+		!ModeInfo, !IO) :-
 	%
 	% First modecheck the lambda goal itself:
 	%
@@ -236,12 +231,12 @@
 	% This is safe, but perhaps too conservative.
 	%
 
-	mode_info_get_module_info(ModeInfo0, ModuleInfo0),
-	mode_info_get_how_to_check(ModeInfo0, HowToCheckGoal),
+	mode_info_get_module_info(!.ModeInfo, ModuleInfo0),
+	mode_info_get_how_to_check(!.ModeInfo, HowToCheckGoal),
 
 	( HowToCheckGoal = check_modes ->
 		% This only needs to be done once.
-		mode_info_get_types_of_vars(ModeInfo0, Vars, VarTypes),
+		mode_info_get_types_of_vars(!.ModeInfo, Vars, VarTypes),
 		propagate_types_into_mode_list(VarTypes, ModuleInfo0,
 			Modes0, Modes)
  	;
@@ -252,15 +247,15 @@
 	mode_list_get_initial_insts(Modes, ModuleInfo0, VarInitialInsts),
 	assoc_list__from_corresponding_lists(Vars, VarInitialInsts, VarInstAL),
 	instmap_delta_from_assoc_list(VarInstAL, VarInstMapDelta),
-	mode_info_get_instmap(ModeInfo0, InstMap0),
+	mode_info_get_instmap(!.ModeInfo, InstMap0),
 	instmap__apply_instmap_delta(InstMap0, VarInstMapDelta, InstMap1),
-	mode_info_set_instmap(InstMap1, ModeInfo0, ModeInfo1),
+	mode_info_set_instmap(InstMap1, !ModeInfo),
  
 	% 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, ModeInfo1, ModeInfo2),
+	mode_info_add_live_vars(LiveVars, !ModeInfo),
  
 	% lock the non-locals
 	% (a lambda goal is not allowed to bind any of the non-local
@@ -271,7 +266,7 @@
 	set__delete_list(NonLocals0, Vars, NonLocals),
 	set__to_sorted_list(NonLocals, NonLocalsList),
 	instmap__lookup_vars(NonLocalsList, InstMap1, NonLocalInsts),
-	mode_info_get_module_info(ModeInfo2, ModuleInfo2),
+	mode_info_get_module_info(!.ModeInfo, ModuleInfo2),
 	(
 		% XXX This test is too conservative.
 		%
@@ -305,30 +300,28 @@
 			SharedNonLocalInsts, ModuleInfo3),
 		instmap__set_vars(InstMap1, NonLocalsList, SharedNonLocalInsts,
 			InstMap2),
-		mode_info_set_module_info(ModeInfo2, ModuleInfo3, ModeInfo3),
-		mode_info_set_instmap(InstMap2, ModeInfo3, ModeInfo4),
+		mode_info_set_module_info(ModuleInfo3, !ModeInfo),
+		mode_info_set_instmap(InstMap2, !ModeInfo),
 
-		mode_info_lock_vars(lambda(PredOrFunc), NonLocals,
-			ModeInfo4, ModeInfo5),
+		mode_info_lock_vars(lambda(PredOrFunc), NonLocals, !ModeInfo),
 
-		mode_checkpoint(enter, "lambda goal", ModeInfo5, ModeInfo6),
+		mode_checkpoint(enter, "lambda goal", !ModeInfo, !IO),
 		% 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
 		->
-			unique_modes__check_goal(Goal0, Goal, ModeInfo6,
-				ModeInfo7)
+			unique_modes__check_goal(Goal0, Goal, !ModeInfo, !IO)
 		;
-			modecheck_goal(Goal0, Goal, ModeInfo6, ModeInfo7)
+			modecheck_goal(Goal0, Goal, !ModeInfo, !IO)
 		),
 		mode_list_get_final_insts(Modes, ModuleInfo0, FinalInsts),
-		modecheck_final_insts(Vars, FinalInsts, ModeInfo7, ModeInfo8),
-		mode_checkpoint(exit, "lambda goal", ModeInfo8, ModeInfo9),
+		modecheck_final_insts(Vars, FinalInsts, !ModeInfo),
+		mode_checkpoint(exit, "lambda goal", !ModeInfo, !IO),
 
-		mode_info_remove_live_vars(LiveVars, ModeInfo9, ModeInfo10),
+		mode_info_remove_live_vars(LiveVars, !ModeInfo),
 		mode_info_unlock_vars(lambda(PredOrFunc), NonLocals,
-			ModeInfo10, ModeInfo11),
+			!ModeInfo),
 
 		%
 		% Ensure that the non-local vars are shared OUTSIDE the
@@ -337,7 +330,7 @@
 
 		instmap__set_vars(InstMap0, NonLocalsList, SharedNonLocalInsts,
 			InstMap11),
-		mode_info_set_instmap(InstMap11, ModeInfo11, ModeInfo12),
+		mode_info_set_instmap(InstMap11, !ModeInfo),
 
 		%
 		% Now modecheck the unification of X with the lambda-expression.
@@ -345,9 +338,8 @@
 
 		RHS0 = lambda_goal(Purity, PredOrFunc, EvalMethod,
 			modes_are_ok, ArgVars, Vars, Modes, Det, Goal),
-		modecheck_unify_lambda(X, PredOrFunc, ArgVars, Modes,
-			Det, RHS0, Unification0, Mode,
-			RHS, Unification, ModeInfo12, ModeInfo)
+		modecheck_unify_lambda(X, PredOrFunc, ArgVars, Modes, Det,
+			RHS0, RHS, Unification0, Unification, Mode, !ModeInfo)
 	;
 		list__filter((pred(Var :: in) is semidet :-
 				instmap__lookup_var(InstMap1, Var, Inst),
@@ -359,7 +351,7 @@
 			mode_info_error(WaitingVars,
 				mode_error_non_local_lambda_var(BadVar,
 					BadInst),
-				ModeInfo2, ModeInfo)
+				!ModeInfo)
 		;
 			error("modecheck_unification(lambda): very strange var")
 		),
@@ -370,17 +362,15 @@
 		Unification = Unification0
 	).
 
-:- pred modecheck_unify_lambda(prog_var, pred_or_func, list(prog_var),
-		list(mode), determinism, unify_rhs, unification,
-		pair(mode), unify_rhs, unification, mode_info, mode_info).
-:- mode modecheck_unify_lambda(in, in, in, in, in, in, in,
-		out, out, out, mode_info_di, mode_info_uo) is det.
-
-modecheck_unify_lambda(X, PredOrFunc, ArgVars, LambdaModes, 
-		LambdaDet, RHS0, Unification0, Mode, RHS, Unification, 
-		ModeInfo0, ModeInfo) :-
-	mode_info_get_module_info(ModeInfo0, ModuleInfo0),
-	mode_info_get_instmap(ModeInfo0, InstMap0),
+:- pred modecheck_unify_lambda(prog_var::in, pred_or_func::in,
+	list(prog_var)::in, list(mode)::in, determinism::in,
+	unify_rhs::in, unify_rhs::out, unification::in, unification::out,
+	pair(mode)::out, mode_info::in, mode_info::out) is det.
+
+modecheck_unify_lambda(X, PredOrFunc, ArgVars, LambdaModes, LambdaDet,
+		RHS0, RHS, Unification0, Unification, Mode, !ModeInfo) :-
+	mode_info_get_module_info(!.ModeInfo, ModuleInfo0),
+	mode_info_get_instmap(!.ModeInfo, InstMap0),
 	instmap__lookup_var(InstMap0, X, InstOfX),
 	InstOfY = ground(unique, higher_order(LambdaPredInfo)),
 	LambdaPredInfo = pred_inst_info(PredOrFunc, LambdaModes, LambdaDet),
@@ -389,7 +379,7 @@
 			ModuleInfo0, UnifyInst, _Det, ModuleInfo1)
 	->
 		Inst = UnifyInst,
-		mode_info_set_module_info(ModeInfo0, ModuleInfo1, ModeInfo1),
+		mode_info_set_module_info(ModuleInfo1, !ModeInfo),
 		ModeOfX = (InstOfX -> Inst),
 		ModeOfY = (InstOfY -> Inst),
 		Mode = ModeOfX - ModeOfY,
@@ -398,23 +388,21 @@
 		instmap__lookup_vars(ArgVars, InstMap0, ArgInsts),
 		inst_lists_to_mode_list(ArgInsts, ArgInsts, ArgModes),
 		categorize_unify_var_lambda(ModeOfX, ArgModes,
-				X, ArgVars, PredOrFunc,
-				RHS0, Unification0, ModeInfo1,
-				RHS, Unification, ModeInfo2),
-		modecheck_set_var_inst(X, Inst, no, ModeInfo2, ModeInfo)
+			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),
-			ModeInfo0, ModeInfo1
-		),
+			!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'
 		Inst = not_reached,
-		modecheck_set_var_inst(X, Inst, no, ModeInfo1, ModeInfo),
+		modecheck_set_var_inst(X, Inst, no, !ModeInfo),
 		ModeOfX = (InstOfX -> Inst),
 		ModeOfY = (InstOfY -> Inst),
 		Mode = ModeOfX - ModeOfY,
@@ -423,18 +411,15 @@
 		RHS = RHS0
 	).
 
-:- pred modecheck_unify_functor(prog_var, (type), cons_id,
-		is_existential_construction, list(prog_var),
-		unification, unify_context, hlds_goal_info, hlds_goal_expr,
-		mode_info, mode_info).
-:- mode modecheck_unify_functor(in, in, in, in, in, in, in, in,
-			out, mode_info_di, mode_info_uo) is det.
+:- pred modecheck_unify_functor(prog_var::in, (type)::in, cons_id::in,
+	is_existential_construction::in, list(prog_var)::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.
 
 modecheck_unify_functor(X0, TypeOfX, ConsId0, IsExistConstruction, ArgVars0,
-			Unification0, UnifyContext, GoalInfo0, Goal,
-			ModeInfo0, FinalModeInfo) :-
-	mode_info_get_module_info(ModeInfo0, ModuleInfo0),
-	mode_info_get_how_to_check(ModeInfo0, HowToCheckGoal),
+		Unification0, UnifyContext, GoalInfo0, Goal, !ModeInfo, !IO) :-
+	mode_info_get_module_info(!.ModeInfo, ModuleInfo0),
+	mode_info_get_how_to_check(!.ModeInfo, HowToCheckGoal),
 
 	%
 	% Fully module qualify all cons_ids
@@ -442,10 +427,10 @@
 	%
 	qualify_cons_id(TypeOfX, ArgVars0, ConsId0, ConsId, InstConsId),
 
-	mode_info_get_instmap(ModeInfo0, InstMap0),
+	mode_info_get_instmap(!.ModeInfo, InstMap0),
 	instmap__lookup_var(InstMap0, X0, InstOfX0),
 	instmap__lookup_vars(ArgVars0, InstMap0, InstArgs),
-	mode_info_var_list_is_live(ArgVars0, ModeInfo0, LiveArgs),
+	mode_info_var_list_is_live(!.ModeInfo, ArgVars0, LiveArgs),
 	InstOfY = bound(unique, [functor(InstConsId, InstArgs)]),
 	(
 		% If the unification was originally of the form
@@ -464,14 +449,12 @@
 		
 		InstOfX = free,
 		LiveX = live,
-		make_complicated_sub_unify(X0, X, ExtraGoals0,
-			ModeInfo0, ModeInfo1)
+		make_complicated_sub_unify(X0, X, ExtraGoals0, !ModeInfo)
 	;
 		InstOfX = InstOfX0,
 		X = X0,
-		mode_info_var_is_live(ModeInfo0, X, LiveX),
-		ExtraGoals0 = no_extra_goals,
-		ModeInfo1 = ModeInfo0
+		mode_info_var_is_live(!.ModeInfo, X, LiveX),
+		ExtraGoals0 = no_extra_goals
 	),
 	(
 
@@ -488,8 +471,7 @@
 		mode_info_error(WaitingVars,
 			mode_error_unify_var_functor(X, InstConsId, ArgVars0,
 							InstOfX, InstArgs),
-			ModeInfo1, ModeInfo2
-		),
+			!ModeInfo),
 		Inst = not_reached,
 		Det = erroneous,
 			% If we get an error, set the inst to not_reached
@@ -500,11 +482,10 @@
 		ModeOfX = (InstOfX -> Inst),
 		ModeOfY = (InstOfY -> Inst),
 		Mode = ModeOfX - ModeOfY,
-		modecheck_set_var_inst(X, Inst, no,
-			ModeInfo2, ModeInfo3),
+		modecheck_set_var_inst(X, Inst, no, !ModeInfo),
 		NoArgInsts = list__duplicate(length(ArgVars0), no),
-		( bind_args(Inst, ArgVars0, NoArgInsts, ModeInfo3, ModeInfo4) ->
-			ModeInfo = ModeInfo4
+		( bind_args(Inst, ArgVars0, NoArgInsts, !ModeInfo) ->
+			true
 		;
 			error("bind_args failed")
 		),
@@ -519,7 +500,7 @@
 	->
 		Inst = UnifyInst,
 		Det = Det1,
-		mode_info_set_module_info(ModeInfo1, ModuleInfo1, ModeInfo2),
+		mode_info_set_module_info(ModuleInfo1, !ModeInfo),
 		ModeOfX = (InstOfX -> Inst),
 		ModeOfY = (InstOfY -> Inst),
 		Mode = ModeOfX - ModeOfY,
@@ -541,22 +522,18 @@
 		;
 			error("get_(inst/mode)_of_args failed")
 		),
-		mode_info_get_var_types(ModeInfo2, VarTypes),
+		mode_info_get_var_types(!.ModeInfo, VarTypes),
 		categorize_unify_var_functor(ModeOfX, ModeOfXArgs, ModeArgs,
 				X, ConsId, ArgVars0, VarTypes, UnifyContext,
-				Unification0, ModeInfo2,
-				Unification1, ModeInfo3),
-		split_complicated_subunifies(Unification1, ArgVars0,
-				Unification, ArgVars, ExtraGoals1,
-				ModeInfo3, ModeInfo4),
-		modecheck_set_var_inst(X, Inst, yes(InstOfY),
-			ModeInfo4, ModeInfo5),
+			Unification0, Unification1, !ModeInfo),
+		split_complicated_subunifies(Unification1, Unification,
+			ArgVars0, ArgVars, ExtraGoals1, !ModeInfo),
+		modecheck_set_var_inst(X, Inst, yes(InstOfY), !ModeInfo),
 		UnifyArgInsts = list__map(func(I) = yes(I), InstOfXArgs),
 		(
-			bind_args(Inst, ArgVars, UnifyArgInsts,
-				ModeInfo5, ModeInfo6)
+			bind_args(Inst, ArgVars, UnifyArgInsts, !ModeInfo)
 		->
-			ModeInfo = ModeInfo6
+			true
 		;
 			error("bind_args failed")
 		)
@@ -565,8 +542,7 @@
 		mode_info_error(WaitingVars,
 			mode_error_unify_var_functor(X, InstConsId, ArgVars0,
 							InstOfX, InstArgs),
-			ModeInfo1, ModeInfo2
-		),
+			!ModeInfo),
 			% If we get an error, set the inst to not_reached
 			% to avoid cascading errors
 			% But don't call categorize_unification, because
@@ -577,10 +553,10 @@
 		ModeOfX = (InstOfX -> Inst),
 		ModeOfY = (InstOfY -> Inst),
 		Mode = ModeOfX - ModeOfY,
-		modecheck_set_var_inst(X, Inst, no, ModeInfo2, ModeInfo3),
+		modecheck_set_var_inst(X, Inst, no, !ModeInfo),
 		NoArgInsts = list__duplicate(length(ArgVars0), no),
-		( bind_args(Inst, ArgVars0, NoArgInsts, ModeInfo3, ModeInfo4) ->
-			ModeInfo = ModeInfo4
+		( bind_args(Inst, ArgVars0, NoArgInsts, !ModeInfo) ->
+			true
 		;
 			error("bind_args failed")
 		),
@@ -601,7 +577,9 @@
 		LiveX = dead
 	->
 		Goal = conj([]),
-		FinalModeInfo = ModeInfo
+		!:ModeInfo = !.ModeInfo		% XXX deleting this exposes
+						% a bug in the state variable
+						% transformation
 	;
 		Det = failure
 	->
@@ -612,11 +590,12 @@
 		% Unifying two preds is not erroneous as far as the
 		% mode checker is concerned, but a mode _error_.
 		Goal = disj([]),
-		FinalModeInfo = ModeInfo
+		!:ModeInfo = !.ModeInfo		% XXX deleting this exposes
+						% a bug in the state variable
+						% transformation
 	;
 		Functor = functor(ConsId, IsExistConstruction, ArgVars),
-		Unify = unify(X, Functor, Mode, Unification,
-			UnifyContext),
+		Unify = unify(X, Functor, Mode, Unification, UnifyContext),
 		%
 		% modecheck_unification sometimes needs to introduce
 		% new goals to handle complicated sub-unifications
@@ -632,13 +611,14 @@
 			ExtraGoals \= no_extra_goals,
 			instmap__is_reachable(InstMap0)
 		->
-			error("unique_modes.m: re-modecheck of unification encountered complicated sub-unifies")
+			error("unique_modes.m: re-modecheck of unification " ++
+				"encountered complicated sub-unifies")
 		;
 			true
 		),
 		handle_extra_goals(Unify, ExtraGoals, GoalInfo0,
-			[X0|ArgVars0], [X|ArgVars],
-			InstMap0, Goal, ModeInfo, FinalModeInfo)
+			[X0 | ArgVars0], [X | ArgVars], InstMap0, Goal,
+			!ModeInfo, !IO)
 	).
 
 %-----------------------------------------------------------------------------%
@@ -648,83 +628,78 @@
 	% complicated unifications.  If they are, we split them out
 	% into separate unifications by introducing fresh variables here.
 
-:- pred split_complicated_subunifies(unification, list(prog_var),
-			unification, list(prog_var), extra_goals,
-			mode_info, mode_info).
-:- mode split_complicated_subunifies(in, in, out, out, out,
-			mode_info_di, mode_info_uo) is det.
+:- 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.
 
-split_complicated_subunifies(Unification0, ArgVars0,
-				Unification, ArgVars, ExtraGoals) -->
+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,
-				ArgVars1, ExtraGoals1)
+				ArgVars1, ExtraGoals1, !ModeInfo)
 		->
-			{ ExtraGoals = ExtraGoals1 },
-			{ ArgVars = ArgVars1 },
-			{ Unification = deconstruct(X, ConsId, ArgVars,
-					ArgModes0, Det, CanCGC) }
+			ExtraGoals = ExtraGoals1,
+			ArgVars = ArgVars1,
+			Unification = deconstruct(X, ConsId, ArgVars,
+				ArgModes0, Det, CanCGC)
 		;
-			{ error("split_complicated_subunifies_2 failed") }
+			error("split_complicated_subunifies_2 failed")
 		)
 	;
-		{ Unification = Unification0 },
-		{ ArgVars = ArgVars0 },
-		{ ExtraGoals = no_extra_goals }
+		Unification = Unification0,
+		ArgVars = ArgVars0,
+		ExtraGoals = no_extra_goals
 	).
 
-:- pred split_complicated_subunifies_2(list(prog_var), list(uni_mode),
-		list(prog_var), extra_goals, mode_info, mode_info).
-:- mode split_complicated_subunifies_2(in, in, out, out,
-			mode_info_di, mode_info_uo) is semidet.
+:- pred split_complicated_subunifies_2(list(prog_var)::in, list(uni_mode)::in,
+	list(prog_var)::out, extra_goals::out, mode_info::in, mode_info::out)
+	is semidet.
 
-split_complicated_subunifies_2([], [], [], no_extra_goals) --> [].
+split_complicated_subunifies_2([], [], [], no_extra_goals, !ModeInfo).
 split_complicated_subunifies_2([Var0 | Vars0], [UniMode0 | UniModes0],
-			Vars, ExtraGoals, ModeInfo0, ModeInfo) :-
-	mode_info_get_module_info(ModeInfo0, ModuleInfo),
+		Vars, ExtraGoals, !ModeInfo) :-
+	mode_info_get_module_info(!.ModeInfo, ModuleInfo),
 	UniMode0 = (InitialInstX - InitialInstY -> FinalInstX - FinalInstY),
 	ModeX = (InitialInstX -> FinalInstX),
 	ModeY = (InitialInstY -> FinalInstY),
-	mode_info_get_var_types(ModeInfo0, VarTypes0),
+	mode_info_get_var_types(!.ModeInfo, VarTypes0),
 	map__lookup(VarTypes0, Var0, VarType),
 	(
 		mode_to_arg_mode(ModuleInfo, ModeX, VarType, top_in),
 		mode_to_arg_mode(ModuleInfo, ModeY, VarType, top_in)
 	->
-		make_complicated_sub_unify(Var0, Var, ExtraGoals0,
-				ModeInfo0, ModeInfo1),
+		make_complicated_sub_unify(Var0, Var, ExtraGoals0, !ModeInfo),
 
 		% recursive call to handle the remaining variables...
 		split_complicated_subunifies_2(Vars0, UniModes0,
-				Vars1, ExtraGoals1, ModeInfo1, ModeInfo),
+			Vars1, ExtraGoals1, !ModeInfo),
 		Vars = [Var | Vars1],
 		append_extra_goals(ExtraGoals0, ExtraGoals1, ExtraGoals)
 	;
-		split_complicated_subunifies_2(Vars0, UniModes0,
-				Vars1, ExtraGoals, ModeInfo0, ModeInfo),
+		split_complicated_subunifies_2(Vars0, UniModes0, Vars1,
+			ExtraGoals, !ModeInfo),
 		Vars = [Var0 | Vars1]
 	).
 
 :- pred make_complicated_sub_unify(prog_var::in, prog_var::out,
-		extra_goals::out, mode_info::mode_info_di,
-		mode_info::mode_info_uo) is det.
+	extra_goals::out, mode_info::in, mode_info::out) is det.
 
-make_complicated_sub_unify(Var0, Var, ExtraGoals0, ModeInfo0, ModeInfo) :-
+make_complicated_sub_unify(Var0, Var, ExtraGoals0, !ModeInfo) :-
 	% introduce a new variable `Var'
-	mode_info_get_varset(ModeInfo0, VarSet0),
-	mode_info_get_var_types(ModeInfo0, VarTypes0),
+	mode_info_get_varset(!.ModeInfo, VarSet0),
+	mode_info_get_var_types(!.ModeInfo, VarTypes0),
 	varset__new_var(VarSet0, Var, VarSet),
 	map__lookup(VarTypes0, Var0, VarType),
 	map__set(VarTypes0, Var, VarType, VarTypes),
-	mode_info_set_varset(VarSet, ModeInfo0, ModeInfo1),
-	mode_info_set_var_types(VarTypes, ModeInfo1, ModeInfo),
+	mode_info_set_varset(VarSet, !ModeInfo),
+	mode_info_set_var_types(VarTypes, !ModeInfo),
 
 	modecheck_unify__create_var_var_unification(Var0, Var,
-		VarType, ModeInfo, ExtraGoal),
+		VarType, !.ModeInfo, ExtraGoal),
 
 	% insert the new unification at
 	% the start of the extra goals
@@ -734,7 +709,7 @@
 		Goal - GoalInfo) :-
 	mode_info_get_context(ModeInfo, Context),
 	mode_info_get_mode_context(ModeInfo, ModeContext),
-	mode_context_to_unify_context(ModeContext, ModeInfo, UnifyContext),
+	mode_context_to_unify_context(ModeInfo, ModeContext, UnifyContext),
 	UnifyContext = unify_context(MainContext, SubContexts),
 	
 	create_atomic_unification(Var0, var(Var), Context,
@@ -779,30 +754,27 @@
 %-----------------------------------------------------------------------------%
 
 	% Work out what kind of unification a var-var unification is.
-:- pred categorize_unify_var_var(mode, mode, is_live, is_live, prog_var,
-		prog_var, determinism, unify_context, map(prog_var, type),
-		unification, mode_info, hlds_goal_expr, mode_info).
-:- mode categorize_unify_var_var(in, in, in, in, in, in, in, in, in, in,
-			mode_info_di, out, mode_info_uo) is det.
+:- 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, ModeInfo0,
-		Unify, ModeInfo) :-
-	mode_info_get_module_info(ModeInfo0, ModuleInfo0),
+		UnifyContext, VarTypes, Unification0, Unify, !ModeInfo) :-
+	mode_info_get_module_info(!.ModeInfo, ModuleInfo0),
 	(
 		mode_is_output(ModuleInfo0, ModeOfX)
 	->
-		Unification = assign(X, Y),
-		ModeInfo = ModeInfo0
+		Unification = assign(X, Y)
 	;
 		mode_is_output(ModuleInfo0, ModeOfY)
 	->
-		Unification = assign(Y, X),
-		ModeInfo = ModeInfo0
+		Unification = assign(Y, X)
 	;
 		mode_is_unused(ModuleInfo0, ModeOfX),
 		mode_is_unused(ModuleInfo0, ModeOfY)
@@ -816,8 +788,7 @@
 			Unification = assign(Y, X)
 		;
 			error("categorize_unify_var_var: free-free unify!")
-		),
-		ModeInfo = ModeInfo0
+		)
 	;
 		%
 		% Check for unreachable unifications
@@ -831,8 +802,7 @@
 		% we just need to avoid calling modecheck_complicated_unify,
 		% since that might abort.
 		%
-		Unification = simple_test(X, Y),
-		ModeInfo = ModeInfo0
+		Unification = simple_test(X, Y)
 	;
 		map__lookup(VarTypes, X, Type),
 		(
@@ -840,13 +810,11 @@
 			not type_has_user_defined_equality_pred(ModuleInfo0,
 				Type, _)
 		->
-			Unification = simple_test(X, Y),
-			ModeInfo = ModeInfo0
+			Unification = simple_test(X, Y)
 		;
 			modecheck_complicated_unify(X, Y,
 				Type, ModeOfX, ModeOfY, Det, UnifyContext,
-				Unification0, ModeInfo0,
-				Unification, ModeInfo)
+				Unification0, Unification, !ModeInfo)
 		)
 	),
 	%
@@ -862,7 +830,7 @@
 	%
 	(
 		Unification = assign(AssignTarget, _),
-		mode_info_var_is_live(ModeInfo, AssignTarget, dead)
+		mode_info_var_is_live(!.ModeInfo, AssignTarget, dead)
 	->
 		Unify = conj([])
 	;
@@ -890,18 +858,17 @@
 % for mode-checking complicated unifications.
 %
 
-:- pred modecheck_complicated_unify(prog_var, prog_var,
-		type, mode, mode, determinism, unify_context,
-		unification, mode_info, unification, mode_info).
-:- mode modecheck_complicated_unify(in, in, in, in, in, in, in,
-		in, mode_info_di, out, mode_info_uo) is det.
+:- 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,
+	mode_info::in, mode_info::out) is det.
 
 modecheck_complicated_unify(X, Y, Type, ModeOfX, ModeOfY, Det, UnifyContext,
-		Unification0, ModeInfo0, Unification, ModeInfo) :-
+		Unification0, Unification, !ModeInfo) :-
 	%
 	% Build up the unification
 	%
-	mode_info_get_module_info(ModeInfo0, ModuleInfo0),
+	mode_info_get_module_info(!.ModeInfo, ModuleInfo0),
 	mode_get_insts(ModuleInfo0, ModeOfX, InitialInstX, FinalInstX),
 	mode_get_insts(ModuleInfo0, ModeOfY, InitialInstY, FinalInstY),
 	UniMode = ((InitialInstX - InitialInstY) -> (FinalInstX - FinalInstY)),
@@ -919,30 +886,28 @@
 	%
 	( UnifyTypeInfoVars = [] ->
 		% optimize common case
-		ModeInfo3 = ModeInfo0
+		true
 	;
 		list__length(UnifyTypeInfoVars, NumTypeInfoVars),
 		list__duplicate(NumTypeInfoVars, ground(shared, none),
 			ExpectedInsts),
-		mode_info_set_call_context(unify(UnifyContext),
-			ModeInfo0, ModeInfo1),
+		mode_info_set_call_context(unify(UnifyContext), !ModeInfo),
 		NeedExactMatch = no,
 		InitialArgNum = 0,
 		modecheck_var_has_inst_list(UnifyTypeInfoVars, ExpectedInsts,
-			NeedExactMatch, InitialArgNum, _InstVarSub,
-			ModeInfo1, ModeInfo2),
+			NeedExactMatch, InitialArgNum, _InstVarSub, !ModeInfo),
 			% We can ignore _InstVarSub since type_info variables
 			% should not have variable insts.
-		mode_info_unset_call_context(ModeInfo2, ModeInfo3)
+		mode_info_unset_call_context(!ModeInfo)
 	),
 
-	mode_info_get_module_info(ModeInfo3, ModuleInfo3),
+	mode_info_get_module_info(!.ModeInfo, ModuleInfo3),
 
 	(
-		mode_info_get_errors(ModeInfo3, Errors),
+		mode_info_get_errors(!.ModeInfo, Errors),
 		Errors \= []
 	->
-		ModeInfo = ModeInfo3
+		true
 	;
 		%
 		% Check that we're not trying to do a polymorphic unification
@@ -957,7 +922,7 @@
 		set__singleton_set(WaitingVars, X),
 		mode_info_error(WaitingVars,
 			mode_error_poly_unify(X, InitialInstX),
-			ModeInfo3, ModeInfo)
+			!ModeInfo)
 	;
 		Type = term__variable(_),
 		\+ inst_is_ground_or_any(ModuleInfo3, InitialInstY)
@@ -965,7 +930,7 @@
 		set__singleton_set(WaitingVars, Y),
 		mode_info_error(WaitingVars,
 			mode_error_poly_unify(Y, InitialInstY),
-			ModeInfo3, ModeInfo)
+			!ModeInfo)
 	;
 
 		%
@@ -981,22 +946,21 @@
 		% not_reached is considered bound, so the 
 		% error message would be spurious if the 
 		% instmap is unreachable.
-		mode_info_get_predid(ModeInfo3, PredId),
-		module_info_pred_info(ModuleInfo3, PredId,
-				PredInfo),
-		mode_info_get_instmap(ModeInfo3, InstMap0),
+		mode_info_get_predid(!.ModeInfo, PredId),
+		module_info_pred_info(ModuleInfo3, PredId, PredInfo),
+		mode_info_get_instmap(!.ModeInfo, InstMap0),
 		( 
 			( is_unify_or_compare_pred(PredInfo) 
 			; instmap__is_unreachable(InstMap0)
 			)
 		->
-			ModeInfo = ModeInfo3
+			true
 		;
 			set__init(WaitingVars),
 			mode_info_error(WaitingVars,
 				mode_error_unify_pred(X, error_at_var(Y),
 						Type, PredOrFunc),
-				ModeInfo3, ModeInfo)
+				!ModeInfo)
 		)
 	;
 		%
@@ -1006,31 +970,27 @@
 		%
 		type_to_ctor_and_args(Type, TypeCtor, _)
 	->
-		mode_info_get_context(ModeInfo3, Context),
-		mode_info_get_instvarset(ModeInfo3, InstVarSet),
+		mode_info_get_context(!.ModeInfo, Context),
+		mode_info_get_instvarset(!.ModeInfo, InstVarSet),
 		unify_proc__request_unify(TypeCtor - UniMode, InstVarSet,
 			Det, Context, ModuleInfo3, ModuleInfo),
-		mode_info_set_module_info(ModeInfo3, ModuleInfo,
-			ModeInfo)
+		mode_info_set_module_info(ModuleInfo, !ModeInfo)
 	;
-		ModeInfo = ModeInfo3
+		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.
 
-:- pred categorize_unify_var_lambda(mode, list(mode),
-		prog_var, list(prog_var), pred_or_func, unify_rhs, unification, 
-		mode_info, unify_rhs, unification, mode_info).
-:- mode categorize_unify_var_lambda(in, in, in, in, in, in,
-			in, mode_info_di, out, out, mode_info_uo) is det.
-
-categorize_unify_var_lambda(ModeOfX, ArgModes0, X, ArgVars,
-		PredOrFunc, RHS0, Unification0, ModeInfo0, RHS, 
-		Unification, ModeInfo) :-
+:- pred categorize_unify_var_lambda((mode)::in, list(mode)::in,
+	prog_var::in, list(prog_var)::in, pred_or_func::in,
+	unify_rhs::in, unify_rhs::out, unification::in, unification::out,
+	mode_info::in, mode_info::out) is det.
+
+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
 	list__length(ArgVars, Arity),
 	(
@@ -1049,10 +1009,10 @@
 		MaybeSize = no,
 		ConsId = cons(unqualified("__LambdaGoal__"), Arity)
 	),
-	mode_info_get_module_info(ModeInfo0, ModuleInfo),
+	mode_info_get_module_info(!.ModeInfo, ModuleInfo),
 	mode_util__modes_to_uni_modes(ArgModes0, ArgModes0,
 						ModuleInfo, ArgModes),
-	mode_info_get_instmap(ModeInfo0, InstMap),
+	mode_info_get_instmap(!.ModeInfo, InstMap),
 	(
 		mode_is_output(ModuleInfo, ModeOfX)
 	->
@@ -1093,8 +1053,7 @@
 			RHS = RHS0
 		),
 		Unification = construct(X, ConsId, ArgVars, ArgModes,
-			construct_dynamically, cell_is_unique, MaybeSize),
-		ModeInfo = ModeInfo0
+			construct_dynamically, cell_is_unique, MaybeSize)
 	;
 		instmap__is_reachable(InstMap)
 	->
@@ -1102,18 +1061,17 @@
 		% The error message would be incorrect in unreachable
 		% code, since not_reached is considered bound.
 		set__init(WaitingVars),
-		mode_info_get_var_types(ModeInfo0, VarTypes0),
+		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),
 					Type, PredOrFunc),
-				ModeInfo0, ModeInfo),
+			!ModeInfo),
 		% return any old garbage
 		Unification = Unification0,
 		RHS = RHS0
 	;
-		ModeInfo = ModeInfo0,
 		Unification = Unification0,
 		RHS = RHS0
 	).
@@ -1123,16 +1081,16 @@
 % unification or a deconstruction.  It also works out whether it will
 % be deterministic or semideterministic.
 
-:- pred categorize_unify_var_functor(mode, list(mode), list(mode), prog_var,
-		cons_id, list(prog_var), map(prog_var, type), unify_context,
-		unification, mode_info, unification, mode_info).
-:- mode categorize_unify_var_functor(in, in, in, in, in, in, in, in, in,
-			mode_info_di, out, mode_info_uo) is det.
+:- pred categorize_unify_var_functor((mode)::in, list(mode)::in,
+	list(mode)::in, prog_var::in, cons_id::in, list(prog_var)::in,
+	map(prog_var, type)::in, unify_context::in,
+	unification::in, unification::out,
+	mode_info::in, mode_info::out) is det.
 
 categorize_unify_var_functor(ModeOfX, ModeOfXArgs, ArgModes0,
 		X, NewConsId, ArgVars, VarTypes, UnifyContext,
-		Unification0, ModeInfo0, Unification, ModeInfo) :-
-	mode_info_get_module_info(ModeInfo0, ModuleInfo),
+		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
 	( Unification0 = construct(_, ConsId0, _, _, _, _, MaybeSize0) ->
@@ -1158,7 +1116,7 @@
 		% check that any type_info or type_class_info variables in the
 		% construction are ground.
 		check_type_info_args_are_ground(ArgVars, VarTypes,
-			UnifyContext, ModeInfo0, ModeInfo)
+			UnifyContext, !ModeInfo)
 	;
 		% It's a deconstruction.
 		(
@@ -1176,20 +1134,18 @@
 			InitialInst = bound(_, [_]),
 			FinalInst = bound(_, [_])
 		->
-			CanFail = cannot_fail,
-			ModeInfo = ModeInfo0
+			CanFail = cannot_fail
 		;
 			% If the type has only one constructor,
 			% then the unification cannot fail
 			type_constructors(TypeOfX, ModuleInfo, Constructors),
 			Constructors = [_]
 		->
-			CanFail = cannot_fail,
-			ModeInfo = ModeInfo0
+			CanFail = cannot_fail
 		;
 			% Otherwise, it can fail
 			CanFail = can_fail,
-			mode_info_get_instmap(ModeInfo0, InstMap0),
+			mode_info_get_instmap(!.ModeInfo, InstMap0),
 			( 
 				type_is_higher_order(TypeOfX, _, PredOrFunc,
 					_, _),
@@ -1198,11 +1154,12 @@
 				set__init(WaitingVars),
 				mode_info_error(WaitingVars,
 			mode_error_unify_pred(X,
-					error_at_functor(ConsId, ArgVars),
+						error_at_functor(ConsId,
+							ArgVars),
 					TypeOfX, PredOrFunc),
-					ModeInfo0, ModeInfo)
+					!ModeInfo)
 			;
-				ModeInfo = ModeInfo0
+				true
 			)
 		),
 		Unification = deconstruct(X, ConsId, ArgVars,
@@ -1211,70 +1168,68 @@
 
 	% 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), map(prog_var, type),
-		unify_context, mode_info, mode_info).
-:- mode check_type_info_args_are_ground(in, in, in,
-		mode_info_di, mode_info_uo) is det.
-
-check_type_info_args_are_ground([], _VarTypes, _UnifyContext) --> [].
-check_type_info_args_are_ground([ArgVar | ArgVars], VarTypes, UnifyContext)
-		-->
-	( 
-		{ map__lookup(VarTypes, ArgVar, ArgType) },
-		{ is_introduced_type_info_type(ArgType) }
-	->
-		mode_info_set_call_context(unify(UnifyContext)),
-		{ NeedExactMatch = no },
-		{ InitialArgNum = 0 },
+:- 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.
+
+check_type_info_args_are_ground([], _VarTypes, _UnifyContext, !ModeInfo).
+check_type_info_args_are_ground([ArgVar | ArgVars], VarTypes, UnifyContext,
+		!ModeInfo) :-
+	(
+		map__lookup(VarTypes, ArgVar, ArgType),
+		is_introduced_type_info_type(ArgType)
+	->
+		mode_info_set_call_context(unify(UnifyContext), !ModeInfo),
+		NeedExactMatch = no,
+		InitialArgNum = 0,
 		modecheck_var_has_inst_list([ArgVar], [ground(shared, none)],
-			NeedExactMatch, InitialArgNum, _InstVarSub),
+			NeedExactMatch, InitialArgNum, _InstVarSub, !ModeInfo),
 		check_type_info_args_are_ground(ArgVars, VarTypes,
-			UnifyContext),
-		mode_info_unset_call_context
+			UnifyContext, !ModeInfo),
+		mode_info_unset_call_context(!ModeInfo)
 	;
-		[]
+		true
 	).
 
 %-----------------------------------------------------------------------------%
 
-:- pred bind_args(inst, list(prog_var), list(maybe(inst)),
-		mode_info, mode_info).
-:- mode bind_args(in, in, in, mode_info_di, mode_info_uo) is semidet.
-
-bind_args(not_reached, _, _) -->
-	{ instmap__init_unreachable(InstMap) },
-	mode_info_set_instmap(InstMap).
-bind_args(ground(Uniq, none), Args, UnifyArgInsts) -->
-	ground_args(Uniq, Args, UnifyArgInsts).
-bind_args(bound(_Uniq, List), Args, UnifyArgInsts) -->
-	( { List = [] } ->
+:- pred bind_args((inst)::in, list(prog_var)::in, list(maybe(inst))::in,
+	mode_info::in, mode_info::out) is semidet.
+
+bind_args(not_reached, _, _, !ModeInfo) :-
+	instmap__init_unreachable(InstMap),
+	mode_info_set_instmap(InstMap, !ModeInfo).
+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
-		{ instmap__init_unreachable(InstMap) },
-		mode_info_set_instmap(InstMap)
+		instmap__init_unreachable(InstMap),
+		mode_info_set_instmap(InstMap, !ModeInfo)
 	;
-		{ List = [functor(_, InstList)] },
-		bind_args_2(Args, InstList, UnifyArgInsts)
+		List = [functor(_, InstList)],
+		bind_args_2(Args, InstList, UnifyArgInsts, !ModeInfo)
 	).
-bind_args(constrained_inst_vars(_, Inst), Args, UnifyArgInsts) -->
-	bind_args(Inst, Args, UnifyArgInsts).
+bind_args(constrained_inst_vars(_, Inst), Args, UnifyArgInsts, !ModeInfo) :-
+	bind_args(Inst, Args, UnifyArgInsts, !ModeInfo).
+
+:- pred bind_args_2(list(prog_var)::in, list(inst)::in, list(maybe(inst))::in,
+	mode_info::in, mode_info::out) is semidet.
 
-:- pred bind_args_2(list(prog_var), list(inst), list(maybe(inst)),
-		mode_info, mode_info).
-:- mode bind_args_2(in, in, in, mode_info_di, mode_info_uo) is semidet.
-
-bind_args_2([], [], []) --> [].
-bind_args_2([Arg | Args], [Inst | Insts], [UnifyArgInst | UnifyArgInsts]) -->
-	modecheck_set_var_inst(Arg, Inst, UnifyArgInst),
-	bind_args_2(Args, Insts, UnifyArgInsts).
-
-:- pred ground_args(uniqueness, list(prog_var), list(maybe(inst)),
-		mode_info, mode_info).
-:- mode ground_args(in, in, in, mode_info_di, mode_info_uo) is semidet.
-
-ground_args(_Uniq, [], []) --> [].
-ground_args(Uniq, [Arg | Args], [UnifyArgInst | UnifyArgInsts]) -->
-	modecheck_set_var_inst(Arg, ground(Uniq, none), UnifyArgInst),
-	ground_args(Uniq, Args, UnifyArgInsts).
+bind_args_2([], [], [], !ModeInfo).
+bind_args_2([Arg | Args], [Inst | Insts], [UnifyArgInst | UnifyArgInsts],
+		!ModeInfo) :-
+	modecheck_set_var_inst(Arg, Inst, UnifyArgInst, !ModeInfo),
+	bind_args_2(Args, Insts, UnifyArgInsts, !ModeInfo).
+
+:- pred ground_args(uniqueness::in, list(prog_var)::in, list(maybe(inst))::in,
+	mode_info::in, mode_info::out) is semidet.
+
+ground_args(_Uniq, [], [], !ModeInfo).
+ground_args(Uniq, [Arg | Args], [UnifyArgInst | UnifyArgInsts], !ModeInfo) :-
+	modecheck_set_var_inst(Arg, ground(Uniq, none), UnifyArgInst,
+		!ModeInfo),
+	ground_args(Uniq, Args, UnifyArgInsts, !ModeInfo).
 
 %-----------------------------------------------------------------------------%
 
Index: compiler/modes.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/modes.m,v
retrieving revision 1.274
diff -u -b -r1.274 modes.m
--- compiler/modes.m	31 Oct 2003 03:27:26 -0000	1.274
+++ compiler/modes.m	5 Nov 2003 23:00:44 -0000
@@ -147,30 +147,28 @@
 	% we should therefore not perform determinism-checking, because we
 	% might get internal errors.
 
-:- pred modecheck(module_info, module_info, bool, io__state, io__state).
-:- mode modecheck(in, out, out, di, uo) is det.
+:- pred modecheck(module_info::in, module_info::out, bool::out,
+	io::di, io::uo) is det.
 
 	% Mode-check or unique-mode-check the code for all the predicates
 	% in a module.
-:- pred check_pred_modes(how_to_check_goal, may_change_called_proc,
-		module_info, module_info, bool, io__state, io__state).
-:- mode check_pred_modes(in, in, in, out, out, di, uo) is det.
+:- pred check_pred_modes(how_to_check_goal::in, may_change_called_proc::in,
+	module_info::in, module_info::out, bool::out, io::di, io::uo) is det.
 
 	% Mode-check or unique-mode-check the code for single predicate.
 
-:- pred modecheck_pred_mode(pred_id, pred_info, how_to_check_goal,
-		may_change_called_proc, module_info, module_info,
-		int, io__state, io__state).
-:- mode modecheck_pred_mode(in, in, in, in, in, out, out, di, uo) is det.
+:- pred modecheck_pred_mode(pred_id::in, pred_info::in, how_to_check_goal::in,
+	may_change_called_proc::in, module_info::in, module_info::out,
+	int::out, io::di, io::uo) is det.
 
 	% Mode-check the code for predicate in a given mode.
 	% Returns the number of errs found and a bool `Changed'
 	% which is true iff another pass of fixpoint analysis
 	% may be needed.
 
-:- pred modecheck_proc(proc_id, pred_id, module_info, module_info, int, bool,
-			io__state, io__state).
-:- mode modecheck_proc(in, in, in, out, out, out, di, uo) is det.
+:- pred modecheck_proc(proc_id::in, pred_id::in,
+	module_info::in, module_info::out, int::out, bool::out,
+	io::di, io::uo) is det.
 
 	% Mode-check or unique-mode-check the code for predicate in a
 	% given mode.
@@ -178,16 +176,15 @@
 	% which is true iff another pass of fixpoint analysis
 	% may be needed.
 
-:- pred modecheck_proc(proc_id, pred_id, how_to_check_goal,
-		may_change_called_proc, module_info, module_info, int, bool,
-		io__state, io__state).
-:- mode modecheck_proc(in, in, in, in, in, out, out, out, di, uo) is det.
+:- pred modecheck_proc(proc_id::in, pred_id::in, how_to_check_goal::in,
+	may_change_called_proc::in, module_info::in, module_info::out,
+	int::out, bool::out, io::di, io::uo) is det.
 
 	% Mode-check the code for predicate in a given mode.
 
-:- pred modecheck_proc_info(proc_id, pred_id, module_info, proc_info,
-		module_info, proc_info, int, io__state, io__state).
-:- mode modecheck_proc_info(in, in, in, in, out, out, out, di, uo) is det.
+:- pred modecheck_proc_info(proc_id::in, pred_id::in,
+	module_info::in, module_info::out, proc_info::in, proc_info::out,
+	int::out, io::di, io::uo) is det.
 
 %-----------------------------------------------------------------------------%
 
@@ -200,8 +197,8 @@
 	% Given a list of variables, and a list of livenesses,
 	% select the live variables.
 	%
-:- pred get_live_vars(list(prog_var), list(is_live), list(prog_var)).
-:- mode get_live_vars(in, in, out) is det.
+:- pred get_live_vars(list(prog_var)::in, list(is_live)::in,
+	list(prog_var)::out) is det.
 
 	%
 	% calculate the argument number offset that needs to be passed to
@@ -210,18 +207,15 @@
 	% so that real arguments get positive argument numbers and
 	% type_info arguments get argument numbers less than or equal to 0.
 	%
-:- pred compute_arg_offset(pred_info, int).
-:- mode compute_arg_offset(in, out) is det.
+:- pred compute_arg_offset(pred_info::in, int::out) is det.
 
 	% Given a list of variables and a list of expected liveness, ensure
 	% that the inst of each variable satisfies the corresponding expected
 	% liveness.  If the bool argument is `yes', then require an exact
 	% match.
 	%
-:- pred modecheck_var_list_is_live(list(prog_var), list(is_live), bool, int,
-		mode_info, mode_info).
-:- mode modecheck_var_list_is_live(in, in, in, in, mode_info_di, mode_info_uo)
-	is det.
+:- pred modecheck_var_list_is_live(list(prog_var)::in, list(is_live)::in,
+	bool::in, int::in, mode_info::in, mode_info::out) is det.
 
 	% Given a list of variables and a list of initial insts, ensure
 	% that the inst of each variable matches the corresponding initial
@@ -229,10 +223,9 @@
 	% match (using inst_matches_final), otherwise we allow the var
 	% to be more instantiated than the inst (using inst_matches_initial).
 	%
-:- pred modecheck_var_has_inst_list(list(prog_var), list(inst), bool, int,
-		inst_var_sub, mode_info, mode_info).
-:- mode modecheck_var_has_inst_list(in, in, in, in, out, mode_info_di, mode_info_uo)
-	is det.
+:- pred modecheck_var_has_inst_list(list(prog_var)::in, list(inst)::in,
+	bool::in, int::in, inst_var_sub::out,
+	mode_info::in, mode_info::out) is det.
 
 	% modecheck_set_var_inst(Var, Inst, MaybeUInst, ModeInfo0, ModeInfo).
 	% 	Assign the given Inst to the given Var, after checking that
@@ -245,95 +238,94 @@
 	% 	a negated context).  Where the inst is not the result of an
 	% 	abstract unification then MaybeUInst should be `no'.
 
-:- pred modecheck_set_var_inst(prog_var, inst, maybe(inst),
-			mode_info, mode_info).
-:- mode modecheck_set_var_inst(in, in, in, mode_info_di, mode_info_uo) is det.
-
-:- pred modecheck_set_var_inst_list(list(prog_var), list(inst), list(inst),
-		int, list(prog_var), extra_goals, mode_info, mode_info).
-:- mode modecheck_set_var_inst_list(in, in, in, in, out, out,
-					mode_info_di, mode_info_uo) is det.
+:- pred modecheck_set_var_inst(prog_var::in, (inst)::in, maybe(inst)::in,
+	mode_info::in, mode_info::out) is det.
+
+:- pred modecheck_set_var_inst_list(list(prog_var)::in, list(inst)::in,
+	list(inst)::in, int::in, list(prog_var)::out, extra_goals::out,
+	mode_info::in, mode_info::out) is det.
 
 	% check that the final insts of the head vars of a lambda
 	% goal matches their expected insts
 	%
-:- pred modecheck_final_insts(list(prog_var), list(inst), mode_info, mode_info).
-:- mode modecheck_final_insts(in, in, mode_info_di, mode_info_uo) is det.
+:- pred modecheck_final_insts(list(prog_var)::in, list(inst)::in,
+	mode_info::in, mode_info::out) is det.
 
-:- pred mode_info_add_goals_live_vars(list(hlds_goal), mode_info, mode_info).
-:- mode mode_info_add_goals_live_vars(in, mode_info_di, mode_info_uo) is det.
+:- pred mode_info_add_goals_live_vars(list(hlds_goal)::in,
+	mode_info::in, mode_info::out) is det.
 
-:- pred mode_info_remove_goals_live_vars(list(hlds_goal), mode_info,
-					mode_info).
-:- mode mode_info_remove_goals_live_vars(in, mode_info_di, mode_info_uo) is det.
+:- pred mode_info_remove_goals_live_vars(list(hlds_goal)::in,
+	mode_info::in, mode_info::out) is det.
 
 	% modecheck_functor_test(ConsId, Var):
 	%	update the instmap to reflect the fact that
 	%	Var was bound to ConsId. 
 	% This is used for the functor tests in `switch' statements.
 	%
-:- pred modecheck_functor_test(prog_var, cons_id, mode_info, mode_info).
-:- mode modecheck_functor_test(in, in, mode_info_di, mode_info_uo) is det.
+:- pred modecheck_functor_test(prog_var::in, cons_id::in,
+	mode_info::in, mode_info::out) is det.
 
 	% compute_goal_instmap_delta(InstMap0, Goal,
 	%	GoalInfo0, GoalInfo, ModeInfo0, ModeInfo).
 	%
 	% Work out the instmap_delta for a goal from
 	% the instmaps before and after the goal.
-:- pred compute_goal_instmap_delta(instmap, hlds_goal_expr,
-		hlds_goal_info, hlds_goal_info, mode_info, mode_info).
-:- mode compute_goal_instmap_delta(in, in, in, out,
-		mode_info_di, mode_info_uo) is det.
+:- pred compute_goal_instmap_delta(instmap::in, hlds_goal_expr::in,
+	hlds_goal_info::in, hlds_goal_info::out,
+	mode_info::in, mode_info::out) is det.
 
 %-----------------------------------------------------------------------------%
 
 % The following predicates are used by modecheck_unify.m.
 
-:- pred modecheck_goal(hlds_goal, hlds_goal, mode_info, mode_info).
-:- mode modecheck_goal(in, out, mode_info_di, mode_info_uo) is det.
+:- pred modecheck_goal(hlds_goal::in, hlds_goal::out,
+	mode_info::in, mode_info::out, io::di, io::uo) is det.
 
 	% Mode-check a single goal-expression.
 
-:- pred modecheck_goal_expr(hlds_goal_expr, hlds_goal_info, hlds_goal_expr,
-			mode_info, mode_info).
-:- mode modecheck_goal_expr(in, in, out, mode_info_di, mode_info_uo) is det.
-
+:- pred modecheck_goal_expr(hlds_goal_expr::in, hlds_goal_info::in,
+	hlds_goal_expr::out, mode_info::in, mode_info::out,
+	io::di, io::uo) is det.
 
 :- type extra_goals
 	--->	no_extra_goals
 	;	extra_goals(
-			list(hlds_goal),	% goals to insert before
+			extra_before_main	:: list(hlds_goal),
+						% goals to insert before
 						% the main goal
-			list(hlds_goal)		% goals to append after
+			extra_after_main	:: list(hlds_goal)
+						% goals to append after
 						% the main goal
 				
 		).
+
 :- type after_goals
 	--->	no_after_goals
 	;	after_goals(
-			instmap,		% instmap at end of main goal
-			list(hlds_goal)		% goals to append after
+			after_instmap		:: instmap,
+						% instmap at end of main goal
+			after_goals		:: list(hlds_goal)
+						% goals to append after
 						% the main goal
 		).
 
 	% append_extra_goals inserts adds some goals to the
 	% list of goals to insert before/after the main goal.
 	%
-:- pred append_extra_goals(extra_goals, extra_goals, extra_goals).
-:- mode append_extra_goals(in, in, out) is det.
+:- pred append_extra_goals(extra_goals::in, extra_goals::in,
+	extra_goals::out) is det.
 
 	% handle_extra_goals combines MainGoal and ExtraGoals into a single
 	% hlds_goal_expr, rerunning mode analysis on the entire
 	% conjunction if ExtraGoals is not empty.
 	%
-:- pred handle_extra_goals(hlds_goal_expr, extra_goals,
-		hlds_goal_info, list(prog_var), list(prog_var),
-		instmap, hlds_goal_expr, mode_info, mode_info).
-:- mode handle_extra_goals(in, in, in, in, in, in, out,
-		mode_info_di, mode_info_uo) is det.
+:- pred handle_extra_goals(hlds_goal_expr::in, extra_goals::in,
+	hlds_goal_info::in, list(prog_var)::in, list(prog_var)::in,
+	instmap::in, hlds_goal_expr::out, mode_info::in, mode_info::out,
+	io::di, io::uo) is det.
 
-:- pred mode_context_to_unify_context(mode_context, mode_info, unify_context).
-:- mode mode_context_to_unify_context(in, mode_info_ui, out) is det.
+:- pred mode_context_to_unify_context(mode_info::in, mode_context::in,
+	unify_context::out) is det.
 
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
@@ -373,84 +365,83 @@
 
 %-----------------------------------------------------------------------------%
 
-modecheck(Module0, Module, UnsafeToContinue) -->
-	globals__io_lookup_bool_option(statistics, Statistics),
-	globals__io_lookup_bool_option(verbose, Verbose),
+modecheck(!Module, UnsafeToContinue, !IO) :-
+	globals__io_lookup_bool_option(statistics, Statistics, !IO),
+	globals__io_lookup_bool_option(verbose, Verbose, !IO),
 
-	maybe_write_string(Verbose, "% Mode-checking clauses...\n"),
+	maybe_write_string(Verbose, "% Mode-checking clauses...\n", !IO),
 	check_pred_modes(check_modes, may_change_called_proc,
-		Module0, Module, UnsafeToContinue),
-	maybe_report_stats(Statistics).
+		!Module, UnsafeToContinue, !IO),
+	maybe_report_stats(Statistics, !IO).
 
 %-----------------------------------------------------------------------------%
 	
 	% Mode-check the code for all the predicates in a module.
 
 check_pred_modes(WhatToCheck, MayChangeCalledProc,
-		ModuleInfo0, ModuleInfo, UnsafeToContinue) -->
-	{ module_info_predids(ModuleInfo0, PredIds) },
+		!ModuleInfo, UnsafeToContinue, !IO) :-
+	module_info_predids(!.ModuleInfo, PredIds),
 	globals__io_lookup_int_option(mode_inference_iteration_limit,
-		MaxIterations),
+		MaxIterations, !IO),
 	modecheck_to_fixpoint(PredIds, MaxIterations, WhatToCheck,
-		MayChangeCalledProc, ModuleInfo0, ModuleInfo1,
-		UnsafeToContinue),
-	( { WhatToCheck = check_unique_modes },
-		write_mode_inference_messages(PredIds, yes, ModuleInfo1),
-		check_eval_methods(ModuleInfo1, ModuleInfo2)
-	; { WhatToCheck = check_modes },
-		( { UnsafeToContinue = yes } ->
-			write_mode_inference_messages(PredIds, no, ModuleInfo1)
+		MayChangeCalledProc, !ModuleInfo, UnsafeToContinue, !IO),
+	(
+		WhatToCheck = check_unique_modes,
+		write_mode_inference_messages(PredIds, yes, !.ModuleInfo, !IO),
+		check_eval_methods(!ModuleInfo, !IO)
 		;
-			[]
-		),
-		{ ModuleInfo2 = ModuleInfo1 }
-	),
-	{ ModuleInfo = ModuleInfo2 }.
+		WhatToCheck = check_modes,
+		(
+			UnsafeToContinue = yes,
+			write_mode_inference_messages(PredIds, no,
+				!.ModuleInfo, !IO)
+		;
+			UnsafeToContinue = no
+		)
+	).
 
 	% Iterate over the list of pred_ids in a module.
 
-:- pred modecheck_to_fixpoint(list(pred_id), int, how_to_check_goal,
-		may_change_called_proc, module_info, module_info,
-		bool, io__state, io__state).
-:- mode modecheck_to_fixpoint(in, in, in, in, in, out, out, di, uo) is det.
+:- pred modecheck_to_fixpoint(list(pred_id)::in, int::in,
+	how_to_check_goal::in, may_change_called_proc::in,
+	module_info::in, module_info::out, bool::out,
+	io__state::di, io__state::uo) is det.
 
 modecheck_to_fixpoint(PredIds, MaxIterations, WhatToCheck, MayChangeCalledProc,
-		ModuleInfo0, ModuleInfo, UnsafeToContinue) -->
-	{ ModuleInfo1 = ModuleInfo0 },
-
+		!ModuleInfo, UnsafeToContinue, !IO) :-
 	% save the old procedure bodies so that we can restore them for the
 	% next pass
-	{ module_info_preds(ModuleInfo0, OldPredTable0) },
+	module_info_preds(!.ModuleInfo, OldPredTable0),
 
 	% analyze everything which has the "can-process" flag set to `yes'
-	modecheck_pred_modes_2(PredIds, WhatToCheck, MayChangeCalledProc,
-		ModuleInfo1, ModuleInfo2, no, Changed1, 0, NumErrors),
+	list__foldl4(maybe_modecheck_pred(WhatToCheck, MayChangeCalledProc),
+		PredIds, !ModuleInfo, no, Changed1, 0, NumErrors, !IO),
 
 	% analyze the procedures whose "can-process" flag was no;
 	% those procedures were inserted into the unify requests queue.
 	modecheck_queued_procs(WhatToCheck, OldPredTable0, OldPredTable,
-		ModuleInfo2, ModuleInfo3, Changed2),
-	io__get_exit_status(ExitStatus),
+		!ModuleInfo, Changed2, !IO),
+	io__get_exit_status(ExitStatus, !IO),
 
-	{ bool__or(Changed1, Changed2, Changed) },
+	bool__or(Changed1, Changed2, Changed),
 
 	% stop if we have reached a fixpoint or found any errors
-	( { Changed = no ; NumErrors > 0 ; ExitStatus \= 0 } ->
-		{ ModuleInfo = ModuleInfo3 },
-		{ UnsafeToContinue = Changed }
+	( ( Changed = no ; NumErrors > 0 ; ExitStatus \= 0 ) ->
+		UnsafeToContinue = Changed
 	;
 		% stop if we exceed the iteration limit
-		( { MaxIterations =< 1 } ->
-			report_max_iterations_exceeded,
-			{ ModuleInfo = ModuleInfo3 },
-			{ UnsafeToContinue = yes }
+		( MaxIterations =< 1 ->
+			report_max_iterations_exceeded(!IO),
+			UnsafeToContinue = yes
 		;
-			globals__io_lookup_bool_option(debug_modes, DebugModes),
-			( { DebugModes = yes } ->
+			globals__io_lookup_bool_option(debug_modes, DebugModes,
+				!IO),
+			(
+				DebugModes = yes,
 				write_mode_inference_messages(PredIds, no,
-						ModuleInfo3)
+					!.ModuleInfo, !IO)
 			;
-				[]
+				DebugModes = no
 			),
 
 			%
@@ -464,45 +455,47 @@
 			% Thus we need to restore the old procedure bodies.
 			%
 
-			( { WhatToCheck = check_modes } ->
+			(
+				WhatToCheck = check_modes,
 				% restore the proc_info goals from the
 				% clauses in the pred_info
-				{ copy_module_clauses_to_procs(PredIds,
-					ModuleInfo3, ModuleInfo4) }
+				copy_module_clauses_to_procs(PredIds,
+					!ModuleInfo)
 			;
+				WhatToCheck = check_unique_modes,
 				% restore the proc_info goals from the
 				% proc_infos in the old module_info
-				{ copy_pred_bodies(OldPredTable, PredIds,
-					ModuleInfo3, ModuleInfo4) }
+				copy_pred_bodies(OldPredTable, PredIds,
+					!ModuleInfo)
 			),
 
-			{ MaxIterations1 = MaxIterations - 1 },
+			MaxIterations1 = MaxIterations - 1,
 			modecheck_to_fixpoint(PredIds, MaxIterations1,
 				WhatToCheck, MayChangeCalledProc,
-				ModuleInfo4, ModuleInfo, UnsafeToContinue)
+				!ModuleInfo, UnsafeToContinue, !IO)
 		)
 	).
 
-:- pred report_max_iterations_exceeded(io__state, io__state).
-:- mode report_max_iterations_exceeded(di, uo) is det.
+:- pred report_max_iterations_exceeded(io::di, io::uo) is det.
 
-report_max_iterations_exceeded -->
-	io__set_exit_status(1),
+report_max_iterations_exceeded(!IO) :-
+	io__set_exit_status(1, !IO),
 	io__write_strings([
 	   "Mode analysis iteration limit exceeded.\n",
 	   "You may need to declare the modes explicitly, or use the\n",
 	   "`--mode-inference-iteration-limit' option to increase the limit.\n"
-	]),
+	], !IO),
 	globals__io_lookup_int_option(mode_inference_iteration_limit,
-		MaxIterations),
+		MaxIterations, !IO),
 	io__format("(The current limit is %d iterations.)\n",
-		[i(MaxIterations)]).
+		[i(MaxIterations)], !IO).
 
 % copy_pred_bodies(OldPredTable, ProcId, ModuleInfo0, ModuleInfo):
 %	copy the procedure bodies for all procedures of the specified
 %	PredIds from OldPredTable into ModuleInfo0, giving ModuleInfo.
 :- pred copy_pred_bodies(pred_table, list(pred_id), module_info, module_info).
 :- mode copy_pred_bodies(in, in, in, out) is det.
+
 copy_pred_bodies(OldPredTable, PredIds, !ModuleInfo) :-
 	module_info_preds(!.ModuleInfo, PredTable0),
 	list__foldl(copy_pred_body(OldPredTable), PredIds,
@@ -514,6 +507,7 @@
 %	PredId from OldPredTable into PredTable0, giving PredTable.
 :- pred copy_pred_body(pred_table, pred_id, pred_table, pred_table).
 :- mode copy_pred_body(in, in, in, out) is det.
+
 copy_pred_body(OldPredTable, PredId, PredTable0, PredTable) :-
 	map__lookup(PredTable0, PredId, PredInfo0),
 	(
@@ -539,8 +533,9 @@
 % copy_proc_body(OldProcTable, ProcId, ProcTable0, ProcTable):
 %	copy the body of the specified ProcId from OldProcTable
 %	into ProcTable0, giving ProcTable.
-:- pred copy_proc_body(proc_table, proc_id, proc_table, proc_table).
-:- mode copy_proc_body(in, in, in, out) is det.
+:- pred copy_proc_body(proc_table::in, proc_id::in,
+	proc_table::in, proc_table::out) is det.
+
 copy_proc_body(OldProcTable, ProcId, ProcTable0, ProcTable) :-
 	map__lookup(OldProcTable, ProcId, OldProcInfo),
 	proc_info_goal(OldProcInfo, OldProcBody),
@@ -548,24 +543,16 @@
 	proc_info_set_goal(OldProcBody, ProcInfo0, ProcInfo),
 	map__set(ProcTable0, ProcId, ProcInfo, ProcTable).
 
-:- pred modecheck_pred_modes_2(list(pred_id), how_to_check_goal,
-		may_change_called_proc, module_info, module_info,
-		bool, bool, int, int, io__state, io__state).
-:- mode modecheck_pred_modes_2(in, in, in, in, out, in, out, in, out, di, uo)
-			is det.
+:- func should_modecheck_pred(pred_info) = bool.
 
-modecheck_pred_modes_2([], _, _, !ModuleInfo, !Changed, !NumErrors, !IO).
-modecheck_pred_modes_2([PredId | PredIds], WhatToCheck, MayChangeCalledProc,
-		!ModuleInfo, !Changed, !NumErrors, !IO) :-
-	module_info_preds(!.ModuleInfo, Preds0),
-	map__lookup(Preds0, PredId, PredInfo0),
+should_modecheck_pred(PredInfo) = ShouldModeCheck :-
 	(
 		(
 			%
 			% don't modecheck imported predicates
 			%
-			( pred_info_is_imported(PredInfo0)
-			; pred_info_is_pseudo_imported(PredInfo0)
+			( pred_info_is_imported(PredInfo)
+			; pred_info_is_pseudo_imported(PredInfo)
 			)
 		;
 			%
@@ -573,12 +560,28 @@
 			% are generated already mode-correct and with
 			% correct instmap deltas.
 			%
-			pred_info_get_markers(PredInfo0, PredMarkers),
+			pred_info_get_markers(PredInfo, PredMarkers),
 			check_marker(PredMarkers, class_method)
 		)
 	->
-		true
+		ShouldModeCheck = no
+	;
+		ShouldModeCheck = yes
+	).
+
+:- pred maybe_modecheck_pred(how_to_check_goal::in, may_change_called_proc::in,
+	pred_id::in, module_info::in, module_info::out, bool::in, bool::out,
+	int::in, int::out, io::di, io::uo) is det.
+
+maybe_modecheck_pred(WhatToCheck, MayChangeCalledProc, PredId,
+		!ModuleInfo, !Changed, !NumErrors, !IO) :-
+	module_info_preds(!.ModuleInfo, Preds0),
+	map__lookup(Preds0, PredId, PredInfo0),
+	ShouldModeCheck = should_modecheck_pred(PredInfo0),
+	(
+		ShouldModeCheck = no
 	;
+		ShouldModeCheck = yes,
 		write_modes_progress_message(PredId, PredInfo0, !.ModuleInfo,
 			WhatToCheck, !IO),
 		modecheck_pred_mode_2(PredId, PredInfo0, WhatToCheck,
@@ -594,31 +597,28 @@
 			module_info_remove_predid(PredId, !ModuleInfo)
 		),
 		!:NumErrors = !.NumErrors + ErrsInThisPred
-	),
-	modecheck_pred_modes_2(PredIds, WhatToCheck, MayChangeCalledProc,
-		!ModuleInfo, !Changed, !NumErrors, !IO).
+	).
 
-:- pred write_modes_progress_message(pred_id, pred_info, module_info,
-			how_to_check_goal, io__state, io__state).
-:- mode write_modes_progress_message(in, in, in, in, di, uo) is det.
-	
-write_modes_progress_message(PredId, PredInfo, ModuleInfo, WhatToCheck) -->
-	{ pred_info_get_markers(PredInfo, Markers) },
-	( { check_marker(Markers, infer_modes) } ->
-		(	{ WhatToCheck = check_modes },
+:- pred write_modes_progress_message(pred_id::in, pred_info::in,
+	module_info::in, how_to_check_goal::in, io::di, io::uo) is det.
+
+write_modes_progress_message(PredId, PredInfo, ModuleInfo, WhatToCheck, !IO) :-
+	pred_info_get_markers(PredInfo, Markers),
+	( check_marker(Markers, infer_modes) ->
+		(	WhatToCheck = check_modes,
 			write_pred_progress_message("% Mode-analysing ",
-				PredId, ModuleInfo)
-		;	{ WhatToCheck = check_unique_modes },
+				PredId, ModuleInfo, !IO)
+		;	WhatToCheck = check_unique_modes,
 			write_pred_progress_message("% Unique-mode-analysing ",
-				PredId, ModuleInfo)
+				PredId, ModuleInfo, !IO)
 		)
 	;
-		(	{ WhatToCheck = check_modes },
+		(	WhatToCheck = check_modes,
 			write_pred_progress_message("% Mode-checking ",
-				PredId, ModuleInfo)
-		;	{ WhatToCheck = check_unique_modes },
+				PredId, ModuleInfo, !IO)
+		;	WhatToCheck = check_unique_modes,
 			write_pred_progress_message("% Unique-mode-checking ",
-				PredId, ModuleInfo)
+				PredId, ModuleInfo, !IO)
 		)
 	).
 
@@ -627,9 +627,9 @@
 	% Mode-check the code for single predicate.
 
 modecheck_pred_mode(PredId, PredInfo0, WhatToCheck, MayChangeCalledProc,
-		!ModuleInfo, NumErrors) -->
+		!ModuleInfo, NumErrors, !IO) :-
 	modecheck_pred_mode_2(PredId, PredInfo0, WhatToCheck,
-		MayChangeCalledProc, !ModuleInfo, no, _Changed, NumErrors).
+		MayChangeCalledProc, !ModuleInfo, no, _, NumErrors, !IO).
 
 :- pred modecheck_pred_mode_2(pred_id::in, pred_info::in,
 	how_to_check_goal::in, may_change_called_proc::in,
@@ -638,7 +638,8 @@
 
 modecheck_pred_mode_2(PredId, PredInfo0, WhatToCheck, MayChangeCalledProc,
 		!ModuleInfo, !Changed, NumErrors, !IO) :-
-	( WhatToCheck = check_modes ->
+	(
+		WhatToCheck = check_modes,
 		pred_info_procedures(PredInfo0, ProcTable),
 		(
 			some [ProcInfo] (
@@ -656,7 +657,7 @@
 				!.ModuleInfo, !IO)
 		)
 	;
-		true
+		WhatToCheck = check_unique_modes
 	),
 	% Note that we use pred_info_procids rather than
 	% pred_info_all_procids here, which means that we
@@ -688,14 +689,14 @@
 
 	% Mode-check the code for predicate in a given mode.
 
-modecheck_proc(ProcId, PredId, !ModuleInfo, NumErrors, Changed) -->
+modecheck_proc(ProcId, PredId, !ModuleInfo, NumErrors, Changed, !IO) :-
 	modecheck_proc(ProcId, PredId, check_modes, may_change_called_proc,
-		!ModuleInfo, NumErrors, Changed).
+		!ModuleInfo, NumErrors, Changed, !IO).
 
 modecheck_proc(ProcId, PredId, WhatToCheck, MayChangeCalledProc, !ModuleInfo,
-		NumErrors, Changed) -->
+		NumErrors, Changed, !IO) :-
 	modecheck_proc_2(ProcId, PredId, WhatToCheck, MayChangeCalledProc,
-		!ModuleInfo, no, Changed, NumErrors).
+		!ModuleInfo, no, Changed, NumErrors, !IO).
 
 :- pred modecheck_proc_2(proc_id::in, pred_id::in, how_to_check_goal::in,
 	may_change_called_proc::in, module_info::in, module_info::out,
@@ -724,12 +725,10 @@
 		module_info_set_preds(Preds, !ModuleInfo)
 	).
 
-modecheck_proc_info(ProcId, PredId, ModuleInfo0, ProcInfo0,
-		ModuleInfo, ProcInfo, NumErrors) -->
-	{ WhatToCheck = check_modes },
+modecheck_proc_info(ProcId, PredId, !ModuleInfo, !ProcInfo, NumErrors, !IO) :-
+	WhatToCheck = check_modes,
 	modecheck_proc_3(ProcId, PredId, WhatToCheck, may_change_called_proc,
-		ModuleInfo0, ModuleInfo, ProcInfo0, ProcInfo, no, _Changed,
-		NumErrors).
+		!ModuleInfo, !ProcInfo, no, _Changed, NumErrors, !IO).
 
 :- pred modecheck_proc_3(proc_id::in, pred_id::in, how_to_check_goal::in,
 	may_change_called_proc::in, module_info::in, module_info::out,
@@ -775,16 +774,16 @@
 	set__list_to_set(LiveVarsList, LiveVars),
 
 		% initialize the mode info
-	mode_info_init(!.IO, !.ModuleInfo, PredId, ProcId, Context,
-		LiveVars, InstMap0, WhatToCheck,
-		MayChangeCalledProc, ModeInfo0),
+	mode_info_init(!.ModuleInfo, PredId, ProcId, Context, LiveVars,
+		InstMap0, WhatToCheck, MayChangeCalledProc, ModeInfo0),
 	mode_info_set_changed_flag(!.Changed, ModeInfo0, ModeInfo1),
 
 		% modecheck the procedure body
 	( WhatToCheck = check_unique_modes ->
-		unique_modes__check_goal(Body0, Body, ModeInfo1, ModeInfo2)
+		unique_modes__check_goal(Body0, Body, ModeInfo1, ModeInfo2,
+			!IO)
 	;
-		modecheck_goal(Body0, Body, ModeInfo1, ModeInfo2)
+		modecheck_goal(Body0, Body, ModeInfo1, ModeInfo2, !IO)
 	),
 
 		% check that final insts match those specified in the
@@ -796,8 +795,8 @@
 	;
 		InferModes = no
 	),
-	modecheck_final_insts_2(HeadVars, ArgFinalInsts0, ModeInfo2,
-			InferModes, ArgFinalInsts, ModeInfo3),
+	modecheck_final_insts_2(HeadVars, ArgFinalInsts0, InferModes,
+		ArgFinalInsts, ModeInfo2, ModeInfo3),
 
 	( InferModes = yes ->
 		% For inferred predicates, we don't report the
@@ -811,14 +810,13 @@
 		NumErrors = 0
 	;
 		% report any errors we found
-		report_mode_errors(ModeInfo3, ModeInfo),
+		report_mode_errors(ModeInfo3, ModeInfo, !IO),
 		mode_info_get_num_errors(ModeInfo, NumErrors)
 	),
 	% save away the results
 	inst_lists_to_mode_list(ArgInitialInsts, ArgFinalInsts, ArgModes),
 	mode_info_get_changed_flag(ModeInfo, !:Changed),
 	mode_info_get_module_info(ModeInfo, !:ModuleInfo),
-	mode_info_get_io_state(ModeInfo, !:IO),
 	mode_info_get_varset(ModeInfo, VarSet),
 	mode_info_get_var_types(ModeInfo, VarTypes),
 	proc_info_set_goal(Body, !ProcInfo),
@@ -827,25 +825,23 @@
 	proc_info_set_argmodes(ArgModes, !ProcInfo).
 
 	% modecheck_final_insts for a lambda expression
-modecheck_final_insts(HeadVars, ArgFinalInsts, ModeInfo0, ModeInfo) :-
+modecheck_final_insts(HeadVars, ArgFinalInsts, !ModeInfo) :-
 		% for lambda expressions, modes must always be
 		% declared, we never infer them.
 	InferModes = no,
-	modecheck_final_insts_2(HeadVars, ArgFinalInsts, ModeInfo0,
-			InferModes, _NewFinalInsts, ModeInfo).
+	modecheck_final_insts_2(HeadVars, ArgFinalInsts, InferModes,
+		_NewFinalInsts, !ModeInfo).
 
-:- pred modecheck_final_insts_2(list(prog_var), list(inst), mode_info, bool,
-					list(inst), mode_info).
-:- mode modecheck_final_insts_2(in, in, mode_info_di, in,
-					out, mode_info_uo) is det.
+:- pred modecheck_final_insts_2(list(prog_var)::in, list(inst)::in, bool::in,
+	list(inst)::out, mode_info::in, mode_info::out) is det.
 
 	% check that the final insts of the head vars matches their
 	% expected insts
 	%
-modecheck_final_insts_2(HeadVars, FinalInsts0, ModeInfo0, InferModes,
-			FinalInsts, ModeInfo) :-
-	mode_info_get_module_info(ModeInfo0, ModuleInfo),
-	mode_info_get_errors(ModeInfo0, Errors),
+modecheck_final_insts_2(HeadVars, FinalInsts0, InferModes, FinalInsts,
+		!ModeInfo) :-
+	mode_info_get_module_info(!.ModeInfo, ModuleInfo),
+	mode_info_get_errors(!.ModeInfo, Errors),
 	% If there were any mode errors, use an unreachable instmap.
 	% This ensures that we don't get unwanted flow-on errors.
 	% This is not strictly necessary, since we only report the
@@ -861,9 +857,9 @@
 		instmap__init_unreachable(InstMap)
 	;
 		Changed0 = no,
-		mode_info_get_instmap(ModeInfo0, InstMap)
+		mode_info_get_instmap(!.ModeInfo, InstMap)
 	),
-	mode_info_get_var_types(ModeInfo0, VarTypes),
+	mode_info_get_var_types(!.ModeInfo, VarTypes),
 	instmap__lookup_vars(HeadVars, InstMap, VarFinalInsts1),
 	map__apply_to_list(HeadVars, VarTypes, ArgTypes),
 
@@ -874,29 +870,27 @@
 		% make sure we set the final insts of any variables which
 		% we assumed were dead to `clobbered'.
 		%
-		mode_info_get_preds(ModeInfo0, Preds),
-		mode_info_get_predid(ModeInfo0, PredId),
+		mode_info_get_preds(!.ModeInfo, Preds),
+		mode_info_get_predid(!.ModeInfo, PredId),
 		map__lookup(Preds, PredId, PredInfo),
 		pred_info_procedures(PredInfo, Procs),
-		mode_info_get_procid(ModeInfo0, ProcId),
+		mode_info_get_procid(!.ModeInfo, ProcId),
 		map__lookup(Procs, ProcId, ProcInfo),
 		proc_info_arglives(ProcInfo, ModuleInfo, ArgLives),
 		maybe_clobber_insts(VarFinalInsts2, ArgLives, FinalInsts),
 		check_final_insts(HeadVars, FinalInsts0, FinalInsts,
-			InferModes, 1, ModuleInfo, no, Changed1,
-			ModeInfo0, ModeInfo1),
-		mode_info_get_changed_flag(ModeInfo1, Changed2),
+			InferModes, 1, ModuleInfo, no, Changed1, !ModeInfo),
+		mode_info_get_changed_flag(!.ModeInfo, Changed2),
 		bool__or_list([Changed0, Changed1, Changed2], Changed),
-		mode_info_set_changed_flag(Changed, ModeInfo1, ModeInfo)
+		mode_info_set_changed_flag(Changed, !ModeInfo)
 	;
 		check_final_insts(HeadVars, FinalInsts0, VarFinalInsts1,
-			InferModes, 1, ModuleInfo, no, _Changed1,
-			ModeInfo0, ModeInfo),
+			InferModes, 1, ModuleInfo, no, _Changed1, !ModeInfo),
 		FinalInsts = FinalInsts0
 	).
 
-:- pred maybe_clobber_insts(list(inst), list(is_live), list(inst)).
-:- mode maybe_clobber_insts(in, in, out) is det.
+:- pred maybe_clobber_insts(list(inst)::in, list(is_live)::in,
+	list(inst)::out) is det.
 
 maybe_clobber_insts([], [_|_], _) :-
 	error("maybe_clobber_insts: length mismatch").
@@ -911,54 +905,66 @@
 	),
 	maybe_clobber_insts(Insts0, IsLives, Insts).
 
-:- pred check_final_insts(list(prog_var), list(inst), list(inst), bool, int,
-				module_info, bool, bool, mode_info, mode_info).
-:- mode check_final_insts(in, in, in, in, in, in, in, out, mode_info_di,
-				mode_info_uo) is det.
+:- pred check_final_insts(list(prog_var)::in, list(inst)::in, list(inst)::in,
+	bool::in, int::in, module_info::in, bool::in, bool::out,
+	mode_info::in, mode_info::out) is det.
 
 check_final_insts(Vars, Insts, VarInsts, InferModes, ArgNum, ModuleInfo,
-		Changed0, Changed) -->
-	( { Vars = [], Insts = [], VarInsts = [] } ->
-		{ Changed = Changed0 }
-	; { Vars = [Var|Vars1], Insts = [Inst|Insts1],
-	    VarInsts = [VarInst|VarInsts1] } ->
-		=(ModeInfo),
-		{ mode_info_get_var_types(ModeInfo, VarTypes) },
-		{ map__lookup(VarTypes, Var, Type) },
-		( { inst_matches_final(VarInst, Inst, Type, ModuleInfo) } ->
-			{ Changed1 = Changed0 }
-		;
-			{ Changed1 = yes },
-			( { InferModes = yes } ->
-				% if we're inferring the mode, then don't report
-				% an error, just set changed to yes to make sure
-				% that we will do another fixpoint pass
-				[]
+		!Changed, !ModeInfo) :-
+	(
+		Vars = [],
+		Insts = [],
+		VarInsts = []
+	->
+		true
 			;
+		Vars = [Var | VarsTail],
+		Insts = [Inst | InstsTail],
+		VarInsts = [VarInst | VarInstsTail]
+	->
+		mode_info_get_var_types(!.ModeInfo, VarTypes),
+		map__lookup(VarTypes, Var, Type),
+		( inst_matches_final(VarInst, Inst, Type, ModuleInfo) ->
+			true
+		;
+			!:Changed = yes,
+			(
+				% If we're inferring the mode, then don't
+				% report an error, just set changed to yes
+				% to make sure that we will do another
+				% fixpoint pass.
+				InferModes = yes
+			;
+				InferModes = no,
 				% XXX this might need to be reconsidered now
 				% we have unique modes
-				( { inst_matches_initial(VarInst, Inst,
-					    Type, ModuleInfo) } ->
-					{ Reason = too_instantiated }
-				; { inst_matches_initial(Inst, VarInst,
-					    Type, ModuleInfo) } ->
-					{ Reason = not_instantiated_enough }
+				(
+					inst_matches_initial(VarInst, Inst,
+						Type, ModuleInfo)
+				->
+					Reason = too_instantiated
+				;
+					inst_matches_initial(Inst, VarInst,
+						Type, ModuleInfo)
+				->
+					Reason = not_instantiated_enough
 				;
 					% I don't think this can happen. 
 					% But just in case...
-					{ Reason = wrongly_instantiated }
+					Reason = wrongly_instantiated
 				),
-				{ set__init(WaitingVars) },
+				set__init(WaitingVars),
 				mode_info_error(WaitingVars,
 					mode_error_final_inst(ArgNum,
-					Var, VarInst, Inst, Reason))
+						Var, VarInst, Inst, Reason),
+					!ModeInfo)
 			)
 		),
-		{ ArgNum1 = ArgNum + 1 },
-		check_final_insts(Vars1, Insts1, VarInsts1, InferModes, ArgNum1,
-			ModuleInfo, Changed1, Changed)
+		check_final_insts(VarsTail, InstsTail, VarInstsTail,
+			InferModes, ArgNum + 1, ModuleInfo,
+			!Changed, !ModeInfo)
 	;
-		{ error("check_final_insts: length mismatch") }
+		error("check_final_insts: length mismatch")
 	).
 
 %-----------------------------------------------------------------------------%
@@ -980,31 +986,28 @@
 % Output only:	Error Message(s)
 %			- Output directly to stdout.
 
-modecheck_goal(Goal0 - GoalInfo0, Goal - GoalInfo, ModeInfo0, ModeInfo) :-
+modecheck_goal(Goal0 - GoalInfo0, Goal - GoalInfo, !ModeInfo, !IO) :-
 		%
 		% store the current context in the mode_info
 		%
 	goal_info_get_context(GoalInfo0, Context),
 	term__context_init(EmptyContext),
 	( Context = EmptyContext ->
-		ModeInfo1 = ModeInfo0
+		true
 	;
-		mode_info_set_context(Context, ModeInfo0, ModeInfo1)
+		mode_info_set_context(Context, !ModeInfo)
 	),
 		%
 		% modecheck the goal, and then store the changes in
 		% instantiation of the vars in the delta_instmap
 		% in the goal's goal_info.
 		%
-	mode_info_get_instmap(ModeInfo1, InstMap0),
-
-	modecheck_goal_expr(Goal0, GoalInfo0, Goal, ModeInfo1, ModeInfo2),
-
+	mode_info_get_instmap(!.ModeInfo, InstMap0),
+	modecheck_goal_expr(Goal0, GoalInfo0, Goal, !ModeInfo, !IO),
 	compute_goal_instmap_delta(InstMap0, Goal, GoalInfo0, GoalInfo,
-		ModeInfo2, ModeInfo).
+		!ModeInfo).
 
-compute_goal_instmap_delta(InstMap0, Goal,
-		GoalInfo0, GoalInfo, ModeInfo0, ModeInfo) :-
+compute_goal_instmap_delta(InstMap0, Goal, GoalInfo0, GoalInfo, !ModeInfo) :-
 	( Goal = conj([]) ->
 		%
 		% When modecheck_unify.m replaces a unification with a
@@ -1015,25 +1018,24 @@
 		% resulting in calls to error/1.
 		%
 		instmap_delta_init_reachable(DeltaInstMap),
-		mode_info_set_instmap(InstMap0, ModeInfo0, ModeInfo)
+		mode_info_set_instmap(InstMap0, !ModeInfo)
 	;
-		ModeInfo = ModeInfo0,
 		goal_info_get_nonlocals(GoalInfo0, NonLocals),
-		mode_info_get_instmap(ModeInfo, InstMap),
+		mode_info_get_instmap(!.ModeInfo, InstMap),
 		compute_instmap_delta(InstMap0, InstMap,
 			NonLocals, DeltaInstMap)
 	),
 	goal_info_set_instmap_delta(GoalInfo0, DeltaInstMap, GoalInfo).
 
-modecheck_goal_expr(conj(List0), GoalInfo0, Goal) -->
-	mode_checkpoint(enter, "conj"),
-	( { List0 = [] } ->	% for efficiency, optimize common case
-		{ Goal = conj([]) }
+modecheck_goal_expr(conj(List0), GoalInfo0, Goal, !ModeInfo, !IO) :-
+	mode_checkpoint(enter, "conj", !ModeInfo, !IO),
+	( List0 = [] ->	% for efficiency, optimize common case
+		Goal = conj([])
 	;
-		modecheck_conj_list(List0, List),
-		{ conj_list_to_goal(List, GoalInfo0, Goal - _GoalInfo) }
+		modecheck_conj_list(List0, List, !ModeInfo, !IO),
+		conj_list_to_goal(List, GoalInfo0, Goal - _GoalInfo)
 	),
-	mode_checkpoint(exit, "conj").
+	mode_checkpoint(exit, "conj", !ModeInfo, !IO).
 
 	% To modecheck a parallel conjunction, we modecheck each
 	% conjunct independently (just like for disjunctions).
@@ -1055,64 +1057,68 @@
 	% empty.
 	% A stack of these structures is maintained to handle nested parallel
 	% conjunctions properly.
-modecheck_goal_expr(par_conj(List0), GoalInfo0, par_conj(List)) -->
-	mode_checkpoint(enter, "par_conj"),
-	{ goal_info_get_nonlocals(GoalInfo0, NonLocals) },
-	modecheck_par_conj_list(List0, List, NonLocals, InstMapNonlocalList),
-	instmap__unify(NonLocals, InstMapNonlocalList),
-	mode_checkpoint(exit, "par_conj").
-
-modecheck_goal_expr(disj(List0), GoalInfo0, Goal) -->
-	mode_checkpoint(enter, "disj"),
-	( { List0 = [] } ->	% for efficiency, optimize common case
-		{ Goal = disj(List0) },
-		{ instmap__init_unreachable(InstMap) },
-		mode_info_set_instmap(InstMap)
-	;
-		{ goal_info_get_nonlocals(GoalInfo0, NonLocals) },
-		modecheck_disj_list(List0, List, InstMapList),
-		instmap__merge(NonLocals, InstMapList, disj),
-		{ disj_list_to_goal(List, GoalInfo0, Goal - _GoalInfo) }
-	),
-	mode_checkpoint(exit, "disj").
-
-modecheck_goal_expr(if_then_else(Vs, A0, B0, C0), GoalInfo0, Goal) -->
-	mode_checkpoint(enter, "if-then-else"),
-	{ goal_info_get_nonlocals(GoalInfo0, NonLocals) },
-	{ goal_get_nonlocals(B0, B_Vars) },
-	mode_info_dcg_get_instmap(InstMap0),
+modecheck_goal_expr(par_conj(List0), GoalInfo0, par_conj(List), !ModeInfo,
+		!IO) :-
+	mode_checkpoint(enter, "par_conj", !ModeInfo, !IO),
+	goal_info_get_nonlocals(GoalInfo0, NonLocals),
+	modecheck_par_conj_list(List0, List, NonLocals, InstMapNonlocalList,
+		!ModeInfo, !IO),
+	instmap__unify(NonLocals, InstMapNonlocalList, !ModeInfo),
+	mode_checkpoint(exit, "par_conj", !ModeInfo, !IO).
+
+modecheck_goal_expr(disj(List0), GoalInfo0, Goal, !ModeInfo, !IO) :-
+	mode_checkpoint(enter, "disj", !ModeInfo, !IO),
+	( List0 = [] ->	% for efficiency, optimize common case
+		Goal = disj(List0),
+		instmap__init_unreachable(InstMap),
+		mode_info_set_instmap(InstMap, !ModeInfo)
+	;
+		goal_info_get_nonlocals(GoalInfo0, NonLocals),
+		modecheck_disj_list(List0, List, InstMapList, !ModeInfo, !IO),
+		instmap__merge(NonLocals, InstMapList, disj, !ModeInfo),
+		disj_list_to_goal(List, GoalInfo0, Goal - _GoalInfo)
+	),
+	mode_checkpoint(exit, "disj", !ModeInfo, !IO).
+
+modecheck_goal_expr(if_then_else(Vars, Cond0, Then0, Else0), GoalInfo0, Goal,
+		!ModeInfo, !IO) :-
+	mode_checkpoint(enter, "if-then-else", !ModeInfo, !IO),
+	goal_info_get_nonlocals(GoalInfo0, NonLocals),
+	goal_get_nonlocals(Then0, ThenVars),
+	mode_info_get_instmap(!.ModeInfo, InstMap0),
 	%
 	% We need to lock the non-local variables, to ensure
 	% that the condition of the if-then-else does not bind them.
 	%
-	mode_info_lock_vars(if_then_else, NonLocals),
-	mode_info_add_live_vars(B_Vars),
-	modecheck_goal(A0, A),
-	mode_info_dcg_get_instmap(InstMapA),
-	mode_info_remove_live_vars(B_Vars),
-	mode_info_unlock_vars(if_then_else, NonLocals),
-	( { instmap__is_reachable(InstMapA) } ->
-		modecheck_goal(B0, B),
-		mode_info_dcg_get_instmap(InstMapB)
+	mode_info_lock_vars(if_then_else, NonLocals, !ModeInfo),
+	mode_info_add_live_vars(ThenVars, !ModeInfo),
+	modecheck_goal(Cond0, Cond, !ModeInfo, !IO),
+	mode_info_get_instmap(!.ModeInfo, InstMapCond),
+	mode_info_remove_live_vars(ThenVars, !ModeInfo),
+	mode_info_unlock_vars(if_then_else, NonLocals, !ModeInfo),
+	( instmap__is_reachable(InstMapCond) ->
+		modecheck_goal(Then0, Then, !ModeInfo, !IO),
+		mode_info_get_instmap(!.ModeInfo, InstMapThen)
 	;
 		% We should not mode-analyse the goal, since it is unreachable.
 		% Instead we optimize the goal away, so that later passes
 		% won't complain about it not having mode information.
-		{ true_goal(B) },
-		{ InstMapB = InstMapA }
+		true_goal(Then),
+		InstMapThen = InstMapCond
 	),
-	mode_info_set_instmap(InstMap0),
-	modecheck_goal(C0, C),
-	mode_info_dcg_get_instmap(InstMapC),
-	mode_info_set_instmap(InstMap0),
-	instmap__merge(NonLocals, [InstMapB, InstMapC], if_then_else),
-	{ Goal = if_then_else(Vs, A, B, C) },
-	mode_checkpoint(exit, "if-then-else").
-
-modecheck_goal_expr(not(A0), GoalInfo0, not(A)) -->
-	mode_checkpoint(enter, "not"),
-	{ goal_info_get_nonlocals(GoalInfo0, NonLocals) },
-	mode_info_dcg_get_instmap(InstMap0),
+	mode_info_set_instmap(InstMap0, !ModeInfo),
+	modecheck_goal(Else0, Else, !ModeInfo, !IO),
+	mode_info_get_instmap(!.ModeInfo, InstMapElse),
+	mode_info_set_instmap(InstMap0, !ModeInfo),
+	instmap__merge(NonLocals, [InstMapThen, InstMapElse], if_then_else,
+		!ModeInfo),
+	Goal = if_then_else(Vars, Cond, Then, Else),
+	mode_checkpoint(exit, "if-then-else", !ModeInfo, !IO).
+
+modecheck_goal_expr(not(SubGoal0), GoalInfo0, not(SubGoal), !ModeInfo, !IO) :-
+	mode_checkpoint(enter, "not", !ModeInfo, !IO),
+	goal_info_get_nonlocals(GoalInfo0, NonLocals),
+	mode_info_get_instmap(!.ModeInfo, InstMap0),
 	%
 	% when analyzing a negated goal, nothing is forward-live
 	% (live on forward executution after that goal), because
@@ -1123,143 +1129,139 @@
 	% destructive update on such a variable, it will be caught
 	% later on by unique_modes.m.)
 	%
-	=(ModeInfo),
-	{ mode_info_get_live_vars(ModeInfo, LiveVars0) },
-	mode_info_set_live_vars([]),
+	mode_info_get_live_vars(!.ModeInfo, LiveVars0),
+	mode_info_set_live_vars([], !ModeInfo),
 	%
 	% We need to lock the non-local variables, to ensure
 	% that the negation does not bind them.
 	%
-	mode_info_lock_vars(negation, NonLocals),
-	modecheck_goal(A0, A),
-	mode_info_set_live_vars(LiveVars0),
-	mode_info_unlock_vars(negation, NonLocals),
-	mode_info_set_instmap(InstMap0),
-	mode_checkpoint(exit, "not").
-
-modecheck_goal_expr(some(Vs, CanRemove, G0), _, some(Vs, CanRemove, G)) -->
-	mode_checkpoint(enter, "some"),
-	modecheck_goal(G0, G),
-	mode_checkpoint(exit, "some").
+	mode_info_lock_vars(negation, NonLocals, !ModeInfo),
+	modecheck_goal(SubGoal0, SubGoal, !ModeInfo, !IO),
+	mode_info_set_live_vars(LiveVars0, !ModeInfo),
+	mode_info_unlock_vars(negation, NonLocals, !ModeInfo),
+	mode_info_set_instmap(InstMap0, !ModeInfo),
+	mode_checkpoint(exit, "not", !ModeInfo, !IO).
+
+modecheck_goal_expr(some(Vs, CanRemove, SubGoal0), _,
+		some(Vs, CanRemove, SubGoal), !ModeInfo, !IO) :-
+	mode_checkpoint(enter, "some", !ModeInfo, !IO),
+	modecheck_goal(SubGoal0, SubGoal, !ModeInfo, !IO),
+	mode_checkpoint(exit, "some", !ModeInfo, !IO).
 
 modecheck_goal_expr(call(PredId, ProcId0, Args0, _, Context, PredName),
-		GoalInfo0, Goal) -->
-	{ prog_out__sym_name_to_string(PredName, PredNameString) },
-	{ string__append("call ", PredNameString, CallString) },
-	mode_checkpoint(enter, CallString),
-
-	=(ModeInfo0),
-	{ mode_info_get_call_id(ModeInfo0, PredId, CallId) },
-	mode_info_set_call_context(call(call(CallId))),
-
-	=(ModeInfo1),
-	{ mode_info_get_instmap(ModeInfo1, InstMap0) },
-	{ DeterminismKnown = no },
+		GoalInfo0, Goal, !ModeInfo, !IO) :-
+	prog_out__sym_name_to_string(PredName, PredNameString),
+	string__append("call ", PredNameString, CallString),
+	mode_checkpoint(enter, CallString, !ModeInfo, !IO),
+
+	mode_info_get_call_id(!.ModeInfo, PredId, CallId),
+	mode_info_set_call_context(call(call(CallId)), !ModeInfo),
+
+	mode_info_get_instmap(!.ModeInfo, InstMap0),
+	DeterminismKnown = no,
 	modecheck_call_pred(PredId, ProcId0, Args0, DeterminismKnown,
-				Mode, Args, ExtraGoals),
+		Mode, Args, ExtraGoals, !ModeInfo),
 
-	=(ModeInfo),
-	{ mode_info_get_module_info(ModeInfo, ModuleInfo) },
-	{ mode_info_get_predid(ModeInfo, CallerPredId) },
-	{ Builtin = builtin_state(ModuleInfo, CallerPredId, PredId, Mode) },
-	{ Call = call(PredId, Mode, Args, Builtin, Context, PredName) },
+	mode_info_get_module_info(!.ModeInfo, ModuleInfo),
+	mode_info_get_predid(!.ModeInfo, CallerPredId),
+	Builtin = builtin_state(ModuleInfo, CallerPredId, PredId, Mode),
+	Call = call(PredId, Mode, Args, Builtin, Context, PredName),
 	handle_extra_goals(Call, ExtraGoals, GoalInfo0, Args0, Args,
-				InstMap0, Goal),
+		InstMap0, Goal, !ModeInfo, !IO),
 
-	mode_info_unset_call_context,
-	mode_checkpoint(exit, CallString).
+	mode_info_unset_call_context(!ModeInfo),
+	mode_checkpoint(exit, CallString, !ModeInfo, !IO).
 
 modecheck_goal_expr(generic_call(GenericCall, Args0, Modes0, _),
-		GoalInfo0, Goal) -->
-	mode_checkpoint(enter, "generic_call"),
-	mode_info_dcg_get_instmap(InstMap0),
+		GoalInfo0, Goal, !ModeInfo, !IO) :-
+	mode_checkpoint(enter, "generic_call", !ModeInfo, !IO),
+	mode_info_get_instmap(!.ModeInfo, InstMap0),
 
-	{ hlds_goal__generic_call_id(GenericCall, CallId) },
-	mode_info_set_call_context(call(CallId)),
+	hlds_goal__generic_call_id(GenericCall, CallId),
+	mode_info_set_call_context(call(CallId), !ModeInfo),
 	(
-		{ GenericCall = higher_order(PredVar, _, PredOrFunc, _) },
+		GenericCall = higher_order(PredVar, _, PredOrFunc, _),
 		modecheck_higher_order_call(PredOrFunc, PredVar,
-			Args0, Modes, Det, Args, ExtraGoals),
-		{ AllArgs0 = [PredVar | Args0] },
-		{ AllArgs = [PredVar | Args] }
+			Args0, Modes, Det, Args, ExtraGoals, !ModeInfo),
+		AllArgs0 = [PredVar | Args0],
+		AllArgs = [PredVar | Args]
 	;
 		% Class method calls are added by polymorphism.m.
 		% XXX We should probably fill this in so that
 		% rerunning mode analysis works on code with typeclasses.
-		{ GenericCall = class_method(_, _, _, _) },
-		{ error("modecheck_goal_expr: class_method_call") }
+		GenericCall = class_method(_, _, _, _),
+		error("modecheck_goal_expr: class_method_call")
 	;
-		{ GenericCall = unsafe_cast },
-		modecheck_builtin_cast(Args0, Modes0, Det, Args, ExtraGoals),
-		{ Modes = Modes0 },
-		{ AllArgs0 = Args0 },
-		{ AllArgs = Args }
+		GenericCall = unsafe_cast,
+		modecheck_builtin_cast(Args0, Modes0, Det, Args, ExtraGoals,
+			!ModeInfo),
+		Modes = Modes0,
+		AllArgs0 = Args0,
+		AllArgs = Args
 	;
-		{ GenericCall = aditi_builtin(AditiBuiltin, UpdatedCallId) },
+		GenericCall = aditi_builtin(AditiBuiltin, UpdatedCallId),
 		modecheck_aditi_builtin(AditiBuiltin, UpdatedCallId,
-			Args0, Modes0, Det, Args, ExtraGoals),
-		{ Modes = Modes0 },
-		{ AllArgs0 = Args0 },
-		{ AllArgs = Args }
+			Args0, Modes0, Det, Args, ExtraGoals, !ModeInfo),
+		Modes = Modes0,
+		AllArgs0 = Args0,
+		AllArgs = Args
 	),
 
-	{ Goal1 = generic_call(GenericCall, Args, Modes, Det) },
+	Goal1 = generic_call(GenericCall, Args, Modes, Det),
 	handle_extra_goals(Goal1, ExtraGoals, GoalInfo0, AllArgs0, AllArgs,
-		InstMap0, Goal),
+		InstMap0, Goal, !ModeInfo, !IO),
 		
-	mode_info_unset_call_context,
-	mode_checkpoint(exit, "generic_call").
+	mode_info_unset_call_context(!ModeInfo),
+	mode_checkpoint(exit, "generic_call", !ModeInfo, !IO).
 
-modecheck_goal_expr(unify(A0, B0, _, UnifyInfo0, UnifyContext), GoalInfo0, Goal)
-		-->
-	mode_checkpoint(enter, "unify"),
-	mode_info_set_call_context(unify(UnifyContext)),
-	modecheck_unification(A0, B0, UnifyInfo0, UnifyContext, GoalInfo0,
-		Goal),
-	mode_info_unset_call_context,
-	mode_checkpoint(exit, "unify").
+modecheck_goal_expr(unify(LHS0, RHS0, _, UnifyInfo0, UnifyContext), GoalInfo0,
+		Goal, !ModeInfo, !IO) :-
+	mode_checkpoint(enter, "unify", !ModeInfo, !IO),
+	mode_info_set_call_context(unify(UnifyContext), !ModeInfo),
+	modecheck_unification(LHS0, RHS0, UnifyInfo0, UnifyContext, GoalInfo0,
+		Goal, !ModeInfo, !IO),
+	mode_info_unset_call_context(!ModeInfo),
+	mode_checkpoint(exit, "unify", !ModeInfo, !IO).
 
 modecheck_goal_expr(switch(Var, CanFail, Cases0), GoalInfo0,
-		switch(Var, CanFail, Cases)) -->
-	mode_checkpoint(enter, "switch"),
-	( { Cases0 = [] } ->
-		{ Cases = [] },
-		{ instmap__init_unreachable(InstMap) },
-		mode_info_set_instmap(InstMap)
-	;
-		{ goal_info_get_nonlocals(GoalInfo0, NonLocals) },
-		modecheck_case_list(Cases0, Var, Cases, InstMapList),
-		instmap__merge(NonLocals, InstMapList, disj)
+		switch(Var, CanFail, Cases), !ModeInfo, !IO) :-
+	mode_checkpoint(enter, "switch", !ModeInfo, !IO),
+	( Cases0 = [] ->
+		Cases = [],
+		instmap__init_unreachable(InstMap),
+		mode_info_set_instmap(InstMap, !ModeInfo)
+	;
+		goal_info_get_nonlocals(GoalInfo0, NonLocals),
+		modecheck_case_list(Cases0, Var, Cases, InstMapList,
+			!ModeInfo, !IO),
+		instmap__merge(NonLocals, InstMapList, disj, !ModeInfo)
 	),
-	mode_checkpoint(exit, "switch").
+	mode_checkpoint(exit, "switch", !ModeInfo, !IO).
 
 	% to modecheck a pragma_c_code, we just modecheck the proc for 
 	% which it is the goal.
 modecheck_goal_expr(foreign_proc(Attributes, PredId, ProcId0,
 		Args0, ArgNameMap, OrigArgTypes, PragmaCode),
-		GoalInfo, Goal) -->
-	mode_checkpoint(enter, "pragma_foreign_code"),
-
-	=(ModeInfo0),
-	{ mode_info_get_call_id(ModeInfo0, PredId, CallId) },
-
-	{ mode_info_get_instmap(ModeInfo0, InstMap0) },
-	{ DeterminismKnown = no },
-	mode_info_set_call_context(call(call(CallId))),
+		GoalInfo, Goal, !ModeInfo, !IO) :-
+	mode_checkpoint(enter, "pragma_foreign_code", !ModeInfo, !IO),
+	mode_info_get_call_id(!.ModeInfo, PredId, CallId),
+	mode_info_get_instmap(!.ModeInfo, InstMap0),
+	DeterminismKnown = no,
+	mode_info_set_call_context(call(call(CallId)), !ModeInfo),
 	modecheck_call_pred(PredId, ProcId0, Args0, DeterminismKnown,
-				ProcId, Args, ExtraGoals),
+		ProcId, Args, ExtraGoals, !ModeInfo),
 
-	{ Pragma = foreign_proc(Attributes, PredId, ProcId,
-			Args0, ArgNameMap, OrigArgTypes, PragmaCode) },
+	Pragma = foreign_proc(Attributes, PredId, ProcId, Args0, ArgNameMap,
+		OrigArgTypes, PragmaCode),
 	handle_extra_goals(Pragma, ExtraGoals, GoalInfo, Args0, Args,
-			InstMap0, Goal),
+		InstMap0, Goal, !ModeInfo, !IO),
 
-	mode_info_unset_call_context,
-	mode_checkpoint(exit, "pragma_foreign_code").
+	mode_info_unset_call_context(!ModeInfo),
+	mode_checkpoint(exit, "pragma_foreign_code", !ModeInfo, !IO).
 
-modecheck_goal_expr(shorthand(_), _, _) -->
+modecheck_goal_expr(shorthand(_), _, _, !ModeInfo, !IO) :-
 	% these should have been expanded out by now
-	{ error("modecheck_goal_expr: unexpected shorthand") }.
+	error("modecheck_goal_expr: unexpected shorthand").
 
 append_extra_goals(no_extra_goals, ExtraGoals, ExtraGoals).
 append_extra_goals(extra_goals(BeforeGoals, AfterGoals),
@@ -1271,10 +1273,10 @@
 	list__append(AfterGoals0, AfterGoals1, AfterGoals).
 
 handle_extra_goals(MainGoal, no_extra_goals, _GoalInfo0, _Args0, _Args,
-		_InstMap0, MainGoal, ModeInfo, ModeInfo).
+		_InstMap0, MainGoal, !ModeInfo, !IO).
 handle_extra_goals(MainGoal, extra_goals(BeforeGoals0, AfterGoals0),
-		GoalInfo0, Args0, Args, InstMap0, Goal, ModeInfo0, ModeInfo) :-
-	mode_info_get_errors(ModeInfo0, Errors),
+		GoalInfo0, Args0, Args, InstMap0, Goal, !ModeInfo, !IO) :-
+	mode_info_get_errors(!.ModeInfo, Errors),
 	(
 		% There's no point adding extra goals if the code is
 		% unreachable anyway.
@@ -1315,19 +1317,19 @@
 		handle_extra_goals_contexts(AfterGoals0, Context, AfterGoals),
 		list__append(BeforeGoals, [Goal0 | AfterGoals], GoalList0),
 
-		mode_info_get_may_change_called_proc(ModeInfo0,
+		mode_info_get_may_change_called_proc(!.ModeInfo,
 			MayChangeCalledProc0),
 
 		% Make sure we don't go into an infinite loop if
 		% there is a bug in the code to add extra goals.
-		mode_info_set_checking_extra_goals(yes, ModeInfo0, ModeInfo1),
+		mode_info_set_checking_extra_goals(yes, !ModeInfo),
 
 		% We've already worked out which procedure should be called,
 		% we don't need to do it again.
 		mode_info_set_may_change_called_proc(
-			may_not_change_called_proc, ModeInfo1, ModeInfo2),
+			may_not_change_called_proc, !ModeInfo),
 
-		mode_info_set_instmap(InstMap0, ModeInfo2, ModeInfo3),
+		mode_info_set_instmap(InstMap0, !ModeInfo),
 
 		% Recheck the goals to compute the instmap_deltas.
 		%
@@ -1341,21 +1343,19 @@
 		% is not, the main unification will be delayed until after the
 		% argument unifications, which turns them into assignments,
 		% and we end up repeating the process forever.
-		mode_info_add_goals_live_vars(GoalList0, ModeInfo3, ModeInfo4),
+		mode_info_add_goals_live_vars(GoalList0, !ModeInfo),
 		modecheck_conj_list_no_delay(GoalList0, GoalList,
-			ModeInfo4, ModeInfo5),
+			!ModeInfo, !IO),
 		Goal = conj(GoalList),
-		mode_info_set_checking_extra_goals(no, ModeInfo5, ModeInfo6),
+		mode_info_set_checking_extra_goals(no, !ModeInfo),
 		mode_info_set_may_change_called_proc(MayChangeCalledProc0,
-			ModeInfo6, ModeInfo)
+			!ModeInfo)
 	;
-		Goal = MainGoal,
-		ModeInfo = ModeInfo0
+		Goal = MainGoal
 	).
 
-:- pred handle_extra_goals_contexts(list(hlds_goal), prog_context,
-	list(hlds_goal)).
-:- mode handle_extra_goals_contexts(in, in, out) is det.
+:- pred handle_extra_goals_contexts(list(hlds_goal)::in, prog_context::in,
+	list(hlds_goal)::out) is det.
 
 handle_extra_goals_contexts([], _Context, []).
 handle_extra_goals_contexts([Goal0 | Goals0], Context, [Goal | Goals]) :-
@@ -1368,87 +1368,82 @@
 
 	% Modecheck a conjunction without doing any reordering.
 	% This is used by handle_extra_goals above.
-:- pred modecheck_conj_list_no_delay(list(hlds_goal), list(hlds_goal),
-				mode_info, mode_info).
-:- mode modecheck_conj_list_no_delay(in, out,
-				mode_info_di, mode_info_uo) is det.
-
-modecheck_conj_list_no_delay([], []) --> [].
-modecheck_conj_list_no_delay([Goal0 | Goals0], [Goal | Goals]) -->
-	{ goal_get_nonlocals(Goal0, NonLocals) },
-	mode_info_remove_live_vars(NonLocals),
-	modecheck_goal(Goal0, Goal),
-	mode_info_dcg_get_instmap(InstMap),
-	( { instmap__is_unreachable(InstMap) } ->
+:- pred modecheck_conj_list_no_delay(list(hlds_goal)::in, list(hlds_goal)::out,
+	mode_info::in, mode_info::out, io::di, io::uo) is det.
+
+modecheck_conj_list_no_delay([], [], !ModeInfo, !IO).
+modecheck_conj_list_no_delay([Goal0 | Goals0], [Goal | Goals], !ModeInfo,
+		!IO) :-
+	goal_get_nonlocals(Goal0, NonLocals),
+	mode_info_remove_live_vars(NonLocals, !ModeInfo),
+	modecheck_goal(Goal0, Goal, !ModeInfo, !IO),
+	mode_info_get_instmap(!.ModeInfo, InstMap),
+	( instmap__is_unreachable(InstMap) ->
 		% We should not mode-analyse the remaining goals, since they
 		% are unreachable.  Instead we optimize them away, so that
 		% later passes won't complain about them not having mode
 		% information.
-		mode_info_remove_goals_live_vars(Goals0),
-		{ Goals  = [] }
+		mode_info_remove_goals_live_vars(Goals0, !ModeInfo),
+		Goals  = []
 	;
-		modecheck_conj_list_no_delay(Goals0, Goals)
+		modecheck_conj_list_no_delay(Goals0, Goals, !ModeInfo, !IO)
 	).
 
 %-----------------------------------------------------------------------------%
 
-:- pred modecheck_conj_list(list(hlds_goal), list(hlds_goal),
-				mode_info, mode_info).
-:- mode modecheck_conj_list(in, out, mode_info_di, mode_info_uo) is det.
-
-modecheck_conj_list(Goals0, Goals) -->
-	=(ModeInfo0),
-	{ mode_info_get_errors(ModeInfo0, OldErrors) },
-	mode_info_set_errors([]),
-
-	=(ModeInfo1),
-	{ mode_info_get_live_vars(ModeInfo1, LiveVars1) },
-	{ mode_info_get_delay_info(ModeInfo1, DelayInfo1) },
-	{ delay_info__enter_conj(DelayInfo1, DelayInfo2) },
-	mode_info_set_delay_info(DelayInfo2),
-	mode_info_add_goals_live_vars(Goals0),
+:- pred modecheck_conj_list(list(hlds_goal)::in, list(hlds_goal)::out,
+	mode_info::in, mode_info::out, io::di, io::uo) is det.
 
-	modecheck_conj_list_2(Goals0, [], Goals, RevImpurityErrors),
+modecheck_conj_list(Goals0, Goals, !ModeInfo, !IO) :-
+	mode_info_get_errors(!.ModeInfo, OldErrors),
+	mode_info_set_errors([], !ModeInfo),
+
+	mode_info_get_live_vars(!.ModeInfo, LiveVars1),
+	mode_info_get_delay_info(!.ModeInfo, DelayInfo1),
+	delay_info__enter_conj(DelayInfo1, DelayInfo2),
+	mode_info_set_delay_info(DelayInfo2, !ModeInfo),
+	mode_info_add_goals_live_vars(Goals0, !ModeInfo),
+
+	modecheck_conj_list_2(Goals0, Goals, [], RevImpurityErrors,
+		!ModeInfo, !IO),
+
+	mode_info_get_errors(!.ModeInfo, NewErrors),
+	list__append(OldErrors, NewErrors, Errors),
+	mode_info_set_errors(Errors, !ModeInfo),
+
+	mode_info_get_delay_info(!.ModeInfo, DelayInfo4),
+	delay_info__leave_conj(DelayInfo4, DelayedGoals, DelayInfo5),
+	mode_info_set_delay_info(DelayInfo5, !ModeInfo),
 
-	=(ModeInfo3),
-	{ mode_info_get_errors(ModeInfo3, NewErrors) },
-	{ list__append(OldErrors, NewErrors, Errors) },
-	mode_info_set_errors(Errors),
-
-	=(ModeInfo4),
-	{ mode_info_get_delay_info(ModeInfo4, DelayInfo4) },
-	{ delay_info__leave_conj(DelayInfo4, DelayedGoals, DelayInfo5) },
-	mode_info_set_delay_info(DelayInfo5),
-
-	( { DelayedGoals \= [] } ->
+	( DelayedGoals \= [] ->
 		% the variables in the delayed goals should not longer
 		% be considered live (the conjunction itself will
 		% delay, and its nonlocals will be made live)
-		mode_info_set_live_vars(LiveVars1)
+		mode_info_set_live_vars(LiveVars1, !ModeInfo)
 	;
-		[]
+		true
 	),
 	% we only report impurity errors if there were no other errors
-	( { DelayedGoals = [] } ->
+	( DelayedGoals = [] ->
 		%
 		% report all the impurity errors
 		% (making sure we report the errors in the correct order)
 		%
-		{ list__reverse(RevImpurityErrors, ImpurityErrors) },
-		=(ModeInfo5),
-		{ mode_info_get_errors(ModeInfo5, Errors5) },
-		{ list__append(Errors5, ImpurityErrors, Errors6) },
-		mode_info_set_errors(Errors6)
-	; { DelayedGoals = [delayed_goal(_DVars, Error, _DGoal)] } ->
-		mode_info_add_error(Error)
+		list__reverse(RevImpurityErrors, ImpurityErrors),
+		mode_info_get_errors(!.ModeInfo, Errors5),
+		list__append(Errors5, ImpurityErrors, Errors6),
+		mode_info_set_errors(Errors6, !ModeInfo)
+	; DelayedGoals = [delayed_goal(_DVars, Error, _DGoal)] ->
+		mode_info_add_error(Error, !ModeInfo)
 	;
-		{ get_all_waiting_vars(DelayedGoals, Vars) },
+		get_all_waiting_vars(DelayedGoals, Vars),
 		mode_info_error(Vars,
-			mode_error_conj(DelayedGoals, conj_floundered))
+			mode_error_conj(DelayedGoals, conj_floundered),
+			!ModeInfo)
 	).
 
-mode_info_add_goals_live_vars([]) --> [].
-mode_info_add_goals_live_vars([Goal | Goals]) -->
+mode_info_add_goals_live_vars([], !ModeInfo).
+mode_info_add_goals_live_vars([Goal | Goals], !ModeInfo) :-
 	% We add the live vars for the goals in the goal list
 	% in reverse order, because this ensures that in the
 	% common case (where there is no delaying), when we come
@@ -1456,23 +1451,21 @@
 	% they will have been added last and will thus be
 	% at the start of the list of live vars sets, which
 	% makes them cheaper to remove.
-	mode_info_add_goals_live_vars(Goals),
-	{ goal_get_nonlocals(Goal, NonLocals) },
-	mode_info_add_live_vars(NonLocals).
-
-mode_info_remove_goals_live_vars([]) --> [].
-mode_info_remove_goals_live_vars([Goal | Goals]) -->
-	{ goal_get_nonlocals(Goal, NonLocals) },
-	mode_info_remove_live_vars(NonLocals),
-	mode_info_remove_goals_live_vars(Goals).
+	mode_info_add_goals_live_vars(Goals, !ModeInfo),
+	goal_get_nonlocals(Goal, NonLocals),
+	mode_info_add_live_vars(NonLocals, !ModeInfo).
+
+mode_info_remove_goals_live_vars([], !ModeInfo).
+mode_info_remove_goals_live_vars([Goal | Goals], !ModeInfo) :-
+	goal_get_nonlocals(Goal, NonLocals),
+	mode_info_remove_live_vars(NonLocals, !ModeInfo),
+	mode_info_remove_goals_live_vars(Goals, !ModeInfo).
 
 :- type impurity_errors == list(mode_error_info).
 
-:- pred modecheck_conj_list_2(list(hlds_goal), impurity_errors,
-			list(hlds_goal), impurity_errors,
-			mode_info, mode_info).
-:- mode modecheck_conj_list_2(in, in, out, out, mode_info_di, mode_info_uo)
-	is det.
+:- pred modecheck_conj_list_2(list(hlds_goal)::in, list(hlds_goal)::out,
+	impurity_errors::in, impurity_errors::out,
+	mode_info::in, mode_info::out, io::di, io::uo) is det.
 
 	% Schedule a conjunction.
 	% If it's empty, then there is nothing to do.
@@ -1481,97 +1474,90 @@
 	% pending goal (if any), and if not, we delay the goal.  Then we
 	% continue attempting to schedule all the rest of the goals.
 
-modecheck_conj_list_2([], ImpurityErrors, [], ImpurityErrors) --> [].
-modecheck_conj_list_2([Goal0 | Goals0], ImpurityErrors0,
-		Goals, ImpurityErrors) -->
-
-	{ Goal0 = _GoalExpr - GoalInfo0 },
-	( { goal_info_is_impure(GoalInfo0) } ->
-		{ Impure = yes },
-		check_for_impurity_error(Goal0, ImpurityErrors0,
-					 ImpurityErrors1)
+modecheck_conj_list_2([], [], !ImpurityErrors, !ModeInfo, !IO).
+modecheck_conj_list_2([Goal0 | Goals0], Goals, !ImpurityErrors, !ModeInfo,
+		!IO) :-
+	Goal0 = _GoalExpr - GoalInfo0,
+	( goal_info_is_impure(GoalInfo0) ->
+		Impure = yes,
+		check_for_impurity_error(Goal0, !ImpurityErrors, !ModeInfo)
 	;
-		{ Impure = no },
-		{ ImpurityErrors1 = ImpurityErrors0 }
+		Impure = no
 	),
 
 		% Hang onto the original instmap, delay_info, and live_vars
-	mode_info_dcg_get_instmap(InstMap0),
-	=(ModeInfo0),
-	{ mode_info_get_delay_info(ModeInfo0, DelayInfo0) },
+	mode_info_get_instmap(!.ModeInfo, InstMap0),
+	mode_info_get_delay_info(!.ModeInfo, DelayInfo0),
 
 		% Modecheck the goal, noting first that the non-locals
 		% which occur in the goal might not be live anymore.
-	{ goal_get_nonlocals(Goal0, NonLocalVars) },
-	mode_info_remove_live_vars(NonLocalVars),
-	modecheck_goal(Goal0, Goal),
+	goal_get_nonlocals(Goal0, NonLocalVars),
+	mode_info_remove_live_vars(NonLocalVars, !ModeInfo),
+	modecheck_goal(Goal0, Goal, !ModeInfo, !IO),
 
 		% Now see whether the goal was successfully scheduled.
 		% If we didn't manage to schedule the goal, then we
 		% restore the original instmap, delay_info and livevars
 		% here, and delay the goal.
-	=(ModeInfo1),
-	{ mode_info_get_errors(ModeInfo1, Errors) },
-	(   { Errors = [ FirstErrorInfo | _] } ->
-		mode_info_set_errors([]),
-		mode_info_set_instmap(InstMap0),
-		mode_info_add_live_vars(NonLocalVars),
-		{ delay_info__delay_goal(DelayInfo0, FirstErrorInfo,
-					 Goal0, DelayInfo1) },
+	mode_info_get_errors(!.ModeInfo, Errors),
+	(
+		Errors = [FirstErrorInfo | _],
+		mode_info_set_errors([], !ModeInfo),
+		mode_info_set_instmap(InstMap0, !ModeInfo),
+		mode_info_add_live_vars(NonLocalVars, !ModeInfo),
+		delay_info__delay_goal(DelayInfo0, FirstErrorInfo,
+			Goal0, DelayInfo1),
 		%  delaying an impure goal is an impurity error
-		( { Impure = yes } ->
-			{ FirstErrorInfo = mode_error_info(Vars, _, _, _) },
-			{ ImpureError = mode_error_conj(
+		( Impure = yes ->
+			FirstErrorInfo = mode_error_info(Vars, _, _, _),
+			ImpureError = mode_error_conj(
 				[delayed_goal(Vars, FirstErrorInfo, Goal0)],
-				goal_itself_was_impure) },
-			=(ModeInfo2),
-			{ mode_info_get_context(ModeInfo2, Context) },
-			{ mode_info_get_mode_context(ModeInfo2, ModeContext) },
-			{ ImpureErrorInfo = mode_error_info( Vars, ImpureError,
-						Context, ModeContext) },
-			{ ImpurityErrors2 = [ImpureErrorInfo |
-						ImpurityErrors1] }
+				goal_itself_was_impure),
+			mode_info_get_context(!.ModeInfo, Context),
+			mode_info_get_mode_context(!.ModeInfo, ModeContext),
+			ImpureErrorInfo = mode_error_info(Vars, ImpureError,
+				Context, ModeContext),
+			!:ImpurityErrors = [ImpureErrorInfo | !.ImpurityErrors]
 		;   
-			{ ImpurityErrors2 = ImpurityErrors1 }
+			true
 		)
 	;   
-		{ mode_info_get_delay_info(ModeInfo1, DelayInfo1) },
-		{ ImpurityErrors2 = ImpurityErrors1 }
+		Errors = [],
+		mode_info_get_delay_info(!.ModeInfo, DelayInfo1)
 	),
 
 		% Next, we attempt to wake up any pending goals,
 		% and then continue scheduling the rest of the goal.
-	{ delay_info__wakeup_goals(DelayInfo1, WokenGoals, DelayInfo) },
-	{ list__append(WokenGoals, Goals0, Goals1) },
-	( { WokenGoals = [] } ->
-		[]
-	; { WokenGoals = [_] } ->
-		mode_checkpoint(wakeup, "goal")
-	;
-		mode_checkpoint(wakeup, "goals")
-	),
-	mode_info_set_delay_info(DelayInfo),
-	mode_info_dcg_get_instmap(InstMap),
-	( { instmap__is_unreachable(InstMap) } ->
+	delay_info__wakeup_goals(DelayInfo1, WokenGoals, DelayInfo),
+	list__append(WokenGoals, Goals0, Goals1),
+	( WokenGoals = [] ->
+		true
+	; WokenGoals = [_] ->
+		mode_checkpoint(wakeup, "goal", !ModeInfo, !IO)
+	;
+		mode_checkpoint(wakeup, "goals", !ModeInfo, !IO)
+	),
+	mode_info_set_delay_info(DelayInfo, !ModeInfo),
+	mode_info_get_instmap(!.ModeInfo, InstMap),
+	( instmap__is_unreachable(InstMap) ->
 		% We should not mode-analyse the remaining goals, since they
 		% are unreachable.  Instead we optimize them away, so that
 		% later passes won't complain about them not having mode
 		% information.
-		mode_info_remove_goals_live_vars(Goals1),
-		{ Goals2  = [] },
-		{ ImpurityErrors = ImpurityErrors2 }
+		mode_info_remove_goals_live_vars(Goals1, !ModeInfo),
+		Goals2  = []
 	;
-		modecheck_conj_list_2(Goals1, ImpurityErrors2,
-				      Goals2, ImpurityErrors)
+		modecheck_conj_list_2(Goals1, Goals2, !ImpurityErrors,
+			!ModeInfo, !IO)
 	),
 
-	( { Errors = [] } ->
+	( Errors = [] ->
 		% we successfully scheduled this goal, so insert
 		% it in the list of successfully scheduled goals
-		{ Goals = [Goal | Goals2] }
+		Goals = [Goal | Goals2]
 	;
 		% we delayed this goal -- it will be stored in the delay_info
-		{ Goals = Goals2 }
+		Goals = Goals2
 	).
 
 %  check whether there are any delayed goals (other than headvar unifications)
@@ -1580,42 +1566,40 @@
 %  case of output arguments, they cannot be scheduled until the variable value
 %  is known.  If headvar unifications couldn't be delayed past impure goals,
 %  impure predicates wouldn't be able to have outputs!
-:- pred check_for_impurity_error(hlds_goal, impurity_errors, impurity_errors,
-		mode_info, mode_info).
-:- mode check_for_impurity_error(in, in, out, mode_info_di, mode_info_uo)
-	is det.
-check_for_impurity_error(Goal, ImpurityErrors0, ImpurityErrors) -->
-	=(ModeInfo0),
-	{ mode_info_get_delay_info(ModeInfo0, DelayInfo0) },
-	{ delay_info__leave_conj(DelayInfo0, DelayedGoals,
-				 DelayInfo1) },
-	{ delay_info__enter_conj(DelayInfo1, DelayInfo) },
-	{ mode_info_get_module_info(ModeInfo0, ModuleInfo) },
-	{ mode_info_get_predid(ModeInfo0, PredId) },
-	{ module_info_pred_info(ModuleInfo, PredId, PredInfo) },
-	{ pred_info_clauses_info(PredInfo, ClausesInfo) },
-	{ clauses_info_headvars(ClausesInfo, HeadVars) },
-	(   { no_non_headvar_unification_goals(DelayedGoals, HeadVars) } ->
-		{ ImpurityErrors = ImpurityErrors0 }
-	;
-		mode_info_set_delay_info(DelayInfo),
-		{ get_all_waiting_vars(DelayedGoals, Vars) },
-		{ ModeError = mode_error_conj(DelayedGoals,
-					goals_followed_by_impure_goal(Goal)) },
-		=(ModeInfo1),
-		{ mode_info_get_context(ModeInfo1, Context) },
-		{ mode_info_get_mode_context(ModeInfo1, ModeContext) },
-		{ ImpurityError = mode_error_info(Vars, ModeError,
-					Context, ModeContext) },
-		{ ImpurityErrors = [ImpurityError | ImpurityErrors0] }
-	).
 
+:- pred check_for_impurity_error(hlds_goal::in,
+	impurity_errors::in, impurity_errors::out,
+	mode_info::in, mode_info::out) is det.
+
+check_for_impurity_error(Goal, !ImpurityErrors, !ModeInfo) :-
+	mode_info_get_delay_info(!.ModeInfo, DelayInfo0),
+	delay_info__leave_conj(DelayInfo0, DelayedGoals, DelayInfo1),
+	delay_info__enter_conj(DelayInfo1, DelayInfo),
+	mode_info_get_module_info(!.ModeInfo, ModuleInfo),
+	mode_info_get_predid(!.ModeInfo, PredId),
+	module_info_pred_info(ModuleInfo, PredId, PredInfo),
+	pred_info_clauses_info(PredInfo, ClausesInfo),
+	clauses_info_headvars(ClausesInfo, HeadVars),
+	( no_non_headvar_unification_goals(DelayedGoals, HeadVars) ->
+		true
+	;
+		mode_info_set_delay_info(DelayInfo, !ModeInfo),
+		get_all_waiting_vars(DelayedGoals, Vars),
+		ModeError = mode_error_conj(DelayedGoals,
+			goals_followed_by_impure_goal(Goal)),
+		mode_info_get_context(!.ModeInfo, Context),
+		mode_info_get_mode_context(!.ModeInfo, ModeContext),
+		ImpurityError = mode_error_info(Vars, ModeError,
+			Context, ModeContext),
+		!:ImpurityErrors = [ImpurityError | !.ImpurityErrors]
+	).
 	
-:- pred no_non_headvar_unification_goals(list(delayed_goal), list(prog_var)).
-:- mode no_non_headvar_unification_goals(in, in) is semidet.
+:- pred no_non_headvar_unification_goals(list(delayed_goal)::in,
+	list(prog_var)::in) is semidet.
 
 no_non_headvar_unification_goals([], _).
-no_non_headvar_unification_goals([delayed_goal(_,_,Goal-_)|Goals], HeadVars) :-
+no_non_headvar_unification_goals([delayed_goal(_, _, Goal - _) | Goals],
+		HeadVars) :-
 	Goal = unify(Var,Rhs,_,_,_),
 	(   list__member(Var, HeadVars)
 	;   Rhs = var(OtherVar),
@@ -1623,24 +1607,17 @@
 	),
 	no_non_headvar_unification_goals(Goals, HeadVars).
 
-:- pred dcg_set_state(T, T, T).
-:- mode dcg_set_state(in, in, out) is det.
-
-dcg_set_state(Val, _OldVal, Val).
-
 	% Given an association list of Vars - Goals,
 	% combine all the Vars together into a single set.
 
-:- pred get_all_waiting_vars(list(delayed_goal), set(prog_var)).
-:- mode get_all_waiting_vars(in, out) is det.
+:- pred get_all_waiting_vars(list(delayed_goal)::in, set(prog_var)::out)
+	is det.
 
 get_all_waiting_vars(DelayedGoals, Vars) :-
-	set__init(Vars0),
-	get_all_waiting_vars_2(DelayedGoals, Vars0, Vars).
+	get_all_waiting_vars_2(DelayedGoals, set__init, Vars).
 
-:- pred get_all_waiting_vars_2(list(delayed_goal), set(prog_var),
-		set(prog_var)).
-:- mode get_all_waiting_vars_2(in, in, out) is det.
+:- pred get_all_waiting_vars_2(list(delayed_goal)::in,
+	set(prog_var)::in, set(prog_var)::out) is det.
 
 get_all_waiting_vars_2([], Vars, Vars).
 get_all_waiting_vars_2([delayed_goal(Vars1, _, _) | Rest], Vars0, Vars) :-
@@ -1649,121 +1626,119 @@
 
 %-----------------------------------------------------------------------------%
 
-:- pred modecheck_disj_list(list(hlds_goal), list(hlds_goal), list(instmap),
-				mode_info, mode_info).
-:- mode modecheck_disj_list(in, out, out, mode_info_di, mode_info_uo) is det.
-
-modecheck_disj_list([], [], []) --> [].
-modecheck_disj_list([Goal0 | Goals0], Goals, [InstMap | InstMaps]) -->
-	mode_info_dcg_get_instmap(InstMap0),
-	modecheck_goal(Goal0, Goal),
-	mode_info_dcg_get_instmap(InstMap),
-	mode_info_set_instmap(InstMap0),
-	modecheck_disj_list(Goals0, Goals1, InstMaps),
+:- pred modecheck_disj_list(list(hlds_goal)::in, list(hlds_goal)::out,
+	list(instmap)::out, mode_info::in, mode_info::out,
+	io::di, io::uo) is det.
+
+modecheck_disj_list([], [], [], !ModeInfo, !IO).
+modecheck_disj_list([Goal0 | Goals0], Goals, [InstMap | InstMaps],
+		!ModeInfo, !IO) :-
+	mode_info_get_instmap(!.ModeInfo, InstMap0),
+	modecheck_goal(Goal0, Goal, !ModeInfo, !IO),
+	mode_info_get_instmap(!.ModeInfo, InstMap),
+	mode_info_set_instmap(InstMap0, !ModeInfo),
+	modecheck_disj_list(Goals0, Goals1, InstMaps, !ModeInfo, !IO),
 	%
 	% If Goal is a nested disjunction,
 	% then merge it with the outer disjunction.
 	% If Goal is `fail', this will delete it.
 	%
-	{ goal_to_disj_list(Goal, DisjList) },
-	{ list__append(DisjList, Goals1, Goals) }.
-
-:- pred modecheck_case_list(list(case), prog_var, list(case), list(instmap),
-				mode_info, mode_info).
-:- mode modecheck_case_list(in, in, out, out, mode_info_di, mode_info_uo)
-	is det.
+	goal_to_disj_list(Goal, DisjList),
+	list__append(DisjList, Goals1, Goals).
 
-modecheck_case_list([], _Var, [], []) --> [].
-modecheck_case_list([Case0 | Cases0], Var,
-			[Case | Cases], [InstMap | InstMaps]) -->
-	{ Case0 = case(ConsId, Goal0) },
-	{ Case = case(ConsId, Goal) },
-	mode_info_dcg_get_instmap(InstMap0),
+:- pred modecheck_case_list(list(case)::in, prog_var::in, list(case)::out,
+	list(instmap)::out, mode_info::in, mode_info::out,
+	io::di, io::uo) is det.
+
+modecheck_case_list([], _Var, [], [], !ModeInfo, !IO).
+modecheck_case_list([Case0 | Cases0], Var, [Case | Cases],
+		[InstMap | InstMaps], !ModeInfo, !IO) :-
+	Case0 = case(ConsId, Goal0),
+	Case = case(ConsId, Goal),
+	mode_info_get_instmap(!.ModeInfo, InstMap0),
 
 	% record the fact that Var was bound to ConsId in the
 	% instmap before processing this case
-	modecheck_functor_test(Var, ConsId),
+	modecheck_functor_test(Var, ConsId, !ModeInfo),
 
 	% modecheck this case (if it is reachable)
-	mode_info_dcg_get_instmap(InstMap1),
-	( { instmap__is_reachable(InstMap1) } ->
-		modecheck_goal(Goal0, Goal1),
-		mode_info_dcg_get_instmap(InstMap)
+	mode_info_get_instmap(!.ModeInfo, InstMap1),
+	( instmap__is_reachable(InstMap1) ->
+		modecheck_goal(Goal0, Goal1, !ModeInfo, !IO),
+		mode_info_get_instmap(!.ModeInfo, InstMap)
 	;
 		% We should not mode-analyse the goal, since it is unreachable.
 		% Instead we optimize the goal away, so that later passes
 		% won't complain about it not having mode information.
-		{ true_goal(Goal1) },
-		{ InstMap = InstMap1 }
+		true_goal(Goal1),
+		InstMap = InstMap1
 	),
 
 	% Don't lose the information added by the functor test above.
-	{ fixup_switch_var(Var, InstMap0, InstMap, Goal1, Goal) },
+	fixup_switch_var(Var, InstMap0, InstMap, Goal1, Goal),
 
-	mode_info_set_instmap(InstMap0),
-	modecheck_case_list(Cases0, Var, Cases, InstMaps).
+	mode_info_set_instmap(InstMap0, !ModeInfo),
+	modecheck_case_list(Cases0, Var, Cases, InstMaps, !ModeInfo, !IO).
 
 	% modecheck_functor_test(ConsId, Var):
 	%	update the instmap to reflect the fact that
 	%	Var was bound to ConsId. 
 	% This is used for the functor tests in `switch' statements.
 	%
-modecheck_functor_test(Var, ConsId) -->
+modecheck_functor_test(Var, ConsId, !ModeInfo) :-
 		% figure out the arity of this constructor,
 		% _including_ any type-infos or typeclass-infos
 		% inserted for existential data types.
-	=(ModeInfo0),
-	{ mode_info_get_module_info(ModeInfo0, ModuleInfo) },
-	{ mode_info_get_var_types(ModeInfo0, VarTypes) },
-	{ map__lookup(VarTypes, Var, Type) },
-	{ AdjustedArity = cons_id_adjusted_arity(ModuleInfo, Type, ConsId) },
+	mode_info_get_module_info(!.ModeInfo, ModuleInfo),
+	mode_info_get_var_types(!.ModeInfo, VarTypes),
+	map__lookup(VarTypes, Var, Type),
+	AdjustedArity = cons_id_adjusted_arity(ModuleInfo, Type, ConsId),
 
 		% record the fact that Var was bound to ConsId in the instmap
-	{ list__duplicate(AdjustedArity, free, ArgInsts) },
-	modecheck_set_var_inst(Var,
-		bound(unique, [functor(ConsId, ArgInsts)]), no).
+	list__duplicate(AdjustedArity, free, ArgInsts),
+	modecheck_set_var_inst(Var, bound(unique, [functor(ConsId, ArgInsts)]),
+		no, !ModeInfo).
 
 %-----------------------------------------------------------------------------%
 
-:- pred modecheck_par_conj_list(list(hlds_goal), list(hlds_goal),
-		set(prog_var), list(pair(instmap, set(prog_var))),
-		mode_info, mode_info).
-:- mode modecheck_par_conj_list(in, out, in, out,
-		mode_info_di, mode_info_uo) is det.
+:- pred modecheck_par_conj_list(list(hlds_goal)::in, list(hlds_goal)::out,
+	set(prog_var)::in, list(pair(instmap, set(prog_var)))::out,
+	mode_info::in, mode_info::out, io::di, io::uo) is det.
 
-modecheck_par_conj_list([], [], _NonLocals, []) --> [].
+modecheck_par_conj_list([], [], _NonLocals, [], !ModeInfo, !IO).
 modecheck_par_conj_list([Goal0 | Goals0], [Goal|Goals], NonLocals, 
-		[InstMap - GoalNonLocals | InstMaps]) -->
-	mode_info_dcg_get_instmap(InstMap0),
-	{ Goal0 = _ - GoalInfo },
-	{ goal_info_get_nonlocals(GoalInfo, GoalNonLocals) },
-	mode_info_get_parallel_vars(PVars0),
-	{ set__init(Bound0) },
-	mode_info_set_parallel_vars([NonLocals - Bound0|PVars0]),
-
-	modecheck_goal(Goal0, Goal),
-	mode_info_get_parallel_vars(PVars1),
-	(
-		{ PVars1 = [_ - Bound1|PVars2] },
-		(
-			{ PVars2 = [OuterNonLocals - OuterBound0|PVars3] },
-			{ set__intersect(OuterNonLocals, Bound1, Bound) },
-			{ set__union(OuterBound0, Bound, OuterBound) },
-			{ PVars = [OuterNonLocals - OuterBound|PVars3] },
-			mode_info_set_parallel_vars(PVars)
-		;
-			{ PVars2 = [] },
-			mode_info_set_parallel_vars(PVars2)
-		)
-	;
-		{ PVars1 = [] },
-		{ error("lost parallel vars") }
-	),
-	mode_info_dcg_get_instmap(InstMap),
-	mode_info_set_instmap(InstMap0),
-	mode_info_lock_vars(par_conj, Bound1),
-	modecheck_par_conj_list(Goals0, Goals, NonLocals, InstMaps),
-	mode_info_unlock_vars(par_conj, Bound1).
+		[InstMap - GoalNonLocals | InstMaps], !ModeInfo, !IO) :-
+	mode_info_get_instmap(!.ModeInfo, InstMap0),
+	Goal0 = _ - GoalInfo,
+	goal_info_get_nonlocals(GoalInfo, GoalNonLocals),
+	mode_info_get_parallel_vars(!.ModeInfo, PVars0),
+	set__init(Bound0),
+	mode_info_set_parallel_vars([NonLocals - Bound0 | PVars0], !ModeInfo),
+
+	modecheck_goal(Goal0, Goal, !ModeInfo, !IO),
+	mode_info_get_parallel_vars(!.ModeInfo, PVars1),
+	(
+		PVars1 = [_ - Bound1 | PVars2],
+		(
+			PVars2 = [OuterNonLocals - OuterBound0|PVars3],
+			set__intersect(OuterNonLocals, Bound1, Bound),
+			set__union(OuterBound0, Bound, OuterBound),
+			PVars = [OuterNonLocals - OuterBound|PVars3],
+			mode_info_set_parallel_vars(PVars, !ModeInfo)
+		;
+			PVars2 = [],
+			mode_info_set_parallel_vars(PVars2, !ModeInfo)
+		)
+	;
+		PVars1 = [],
+		error("lost parallel vars")
+	),
+	mode_info_get_instmap(!.ModeInfo, InstMap),
+	mode_info_set_instmap(InstMap0, !ModeInfo),
+	mode_info_lock_vars(par_conj, Bound1, !ModeInfo),
+	modecheck_par_conj_list(Goals0, Goals, NonLocals, InstMaps,
+		!ModeInfo, !IO),
+	mode_info_unlock_vars(par_conj, Bound1, !ModeInfo).
 
 %-----------------------------------------------------------------------------%
 
@@ -1786,20 +1761,21 @@
 	% ensure the liveness of each variable satisfies the corresponding
 	% expected liveness.
 
-modecheck_var_list_is_live([_|_], [], _, _) -->
-	{ error("modecheck_var_list_is_live: length mismatch") }.
-modecheck_var_list_is_live([], [_|_], _, _) -->
-	{ error("modecheck_var_list_is_live: length mismatch") }.
-modecheck_var_list_is_live([], [], _NeedExactMatch, _ArgNum) --> [].
-modecheck_var_list_is_live([Var|Vars], [IsLive|IsLives], NeedExactMatch,
-		ArgNum0) -->
-	{ ArgNum = ArgNum0 + 1 },
-	mode_info_set_call_arg_context(ArgNum),
-	modecheck_var_is_live(Var, IsLive, NeedExactMatch),
-	modecheck_var_list_is_live(Vars, IsLives, NeedExactMatch, ArgNum).
+modecheck_var_list_is_live([_|_], [], _, _, !ModeInfo) :-
+	error("modecheck_var_list_is_live: length mismatch").
+modecheck_var_list_is_live([], [_|_], _, _, !ModeInfo) :-
+	error("modecheck_var_list_is_live: length mismatch").
+modecheck_var_list_is_live([], [], _NeedExactMatch, _ArgNum, !ModeInfo).
+modecheck_var_list_is_live([Var | Vars], [IsLive | IsLives], NeedExactMatch,
+		ArgNum0, !ModeInfo) :-
+	ArgNum = ArgNum0 + 1,
+	mode_info_set_call_arg_context(ArgNum, !ModeInfo),
+	modecheck_var_is_live(Var, IsLive, NeedExactMatch, !ModeInfo),
+	modecheck_var_list_is_live(Vars, IsLives, NeedExactMatch, ArgNum,
+		!ModeInfo).
 
-:- pred modecheck_var_is_live(prog_var, is_live, bool, mode_info, mode_info).
-:- mode modecheck_var_is_live(in, in, in, mode_info_di, mode_info_uo) is det.
+:- pred modecheck_var_is_live(prog_var::in, is_live::in, bool::in,
+	mode_info::in, mode_info::out) is det.
 
 	% `live' means possibly used later on, and
 	% `dead' means definitely not used later on.
@@ -1809,9 +1785,8 @@
 	% be dead; the predicate may use destructive update to clobber
 	% the variable, so we must be sure that it is dead after the call.
 
-modecheck_var_is_live(VarId, ExpectedIsLive, NeedExactMatch,
-		ModeInfo0, ModeInfo) :-
-	mode_info_var_is_live(ModeInfo0, VarId, VarIsLive),
+modecheck_var_is_live(VarId, ExpectedIsLive, NeedExactMatch, !ModeInfo) :-
+	mode_info_var_is_live(!.ModeInfo, VarId, VarIsLive),
 	( 
 		( ExpectedIsLive = dead, VarIsLive = live
 		; NeedExactMatch = yes, VarIsLive \= ExpectedIsLive
@@ -1819,9 +1794,9 @@
 	->
 		set__singleton_set(WaitingVars, VarId),
 		mode_info_error(WaitingVars, mode_error_var_is_live(VarId),
-			ModeInfo0, ModeInfo)
+			!ModeInfo)
 	; 
-		ModeInfo = ModeInfo0
+		true
 	).
 
 %-----------------------------------------------------------------------------%
@@ -1830,120 +1805,108 @@
 	% that the inst of each variable matches the corresponding initial
 	% inst.
 
-modecheck_var_has_inst_list(Vars, Insts, NeedEaxctMatch, ArgNum, Subst) -->
-	{ map__init(Subst0) },
+modecheck_var_has_inst_list(Vars, Insts, NeedEaxctMatch, ArgNum, Subst,
+		!ModeInfo) :-
 	modecheck_var_has_inst_list_2(Vars, Insts, NeedEaxctMatch, ArgNum,
-		Subst0, Subst).
+		map__init, Subst, !ModeInfo).
+
+:- pred modecheck_var_has_inst_list_2(list(prog_var)::in, list(inst)::in,
+	bool::in, int::in, inst_var_sub::in, inst_var_sub::out,
+	mode_info::in, mode_info::out) is det.
+
+modecheck_var_has_inst_list_2([_|_], [], _, _, !Subst, !ModeInfo) :-
+	error("modecheck_var_has_inst_list: length mismatch").
+modecheck_var_has_inst_list_2([], [_|_], _, _, !Subst, !ModeInfo) :-
+	error("modecheck_var_has_inst_list: length mismatch").
+modecheck_var_has_inst_list_2([], [], _Exact, _ArgNum, !Subst, !ModeInfo).
+modecheck_var_has_inst_list_2([Var | Vars], [Inst | Insts], NeedExactMatch,
+		ArgNum0, !Subst, !ModeInfo) :-
+	ArgNum = ArgNum0 + 1,
+	mode_info_set_call_arg_context(ArgNum, !ModeInfo),
+	modecheck_var_has_inst(Var, Inst, NeedExactMatch, !Subst, !ModeInfo),
+	modecheck_var_has_inst_list_2(Vars, Insts, NeedExactMatch, ArgNum,
+		!Subst, !ModeInfo).
+
+:- pred modecheck_var_has_inst(prog_var::in, (inst)::in, bool::in,
+	inst_var_sub::in, inst_var_sub::out,
+	mode_info::in, mode_info::out) is det.
 
-:- pred modecheck_var_has_inst_list_2(list(prog_var), list(inst), bool, int,
-		inst_var_sub, inst_var_sub, mode_info, mode_info).
-:- mode modecheck_var_has_inst_list_2(in, in, in, in, in, out,
-		mode_info_di, mode_info_uo) is det.
-
-modecheck_var_has_inst_list_2([_|_], [], _, _, _, _) -->
-	{ error("modecheck_var_has_inst_list: length mismatch") }.
-modecheck_var_has_inst_list_2([], [_|_], _, _, _, _) -->
-	{ error("modecheck_var_has_inst_list: length mismatch") }.
-modecheck_var_has_inst_list_2([], [], _Exact, _ArgNum, Subst, Subst) --> [].
-modecheck_var_has_inst_list_2([Var|Vars], [Inst|Insts],
-		NeedExactMatch, ArgNum0, Subst0, Subst) -->
-	{ ArgNum = ArgNum0 + 1 },
-	mode_info_set_call_arg_context(ArgNum),
-	modecheck_var_has_inst(Var, Inst, NeedExactMatch, Subst0, Subst1),
-	modecheck_var_has_inst_list_2(Vars, Insts,
-		NeedExactMatch, ArgNum, Subst1, Subst).
-
-:- pred modecheck_var_has_inst(prog_var, inst, bool,
-		inst_var_sub, inst_var_sub, mode_info, mode_info).
-:- mode modecheck_var_has_inst(in, in, in,
-		in, out, mode_info_di, mode_info_uo) is det.
-
-modecheck_var_has_inst(VarId, Inst, NeedExactMatch, Subst0, Subst,
-		ModeInfo0, ModeInfo) :-
-	mode_info_get_instmap(ModeInfo0, InstMap),
+modecheck_var_has_inst(VarId, Inst, NeedExactMatch, !Subst, !ModeInfo) :-
+	mode_info_get_instmap(!.ModeInfo, InstMap),
 	instmap__lookup_var(InstMap, VarId, VarInst),
-	mode_info_get_var_types(ModeInfo0, VarTypes),
+	mode_info_get_var_types(!.ModeInfo, VarTypes),
 	map__lookup(VarTypes, VarId, Type),
-
-	mode_info_get_module_info(ModeInfo0, ModuleInfo0),
+	mode_info_get_module_info(!.ModeInfo, ModuleInfo0),
 	(
 		(
 			NeedExactMatch = no,
 			inst_matches_initial(VarInst, Inst, Type, ModuleInfo0,
-				ModuleInfo, Subst0, Subst1)
+				ModuleInfo, !Subst)
 		;
 			NeedExactMatch = yes,
 			inst_matches_initial_no_implied_modes(VarInst, Inst,
-				Type, ModuleInfo0, ModuleInfo, Subst0, Subst1)
+				Type, ModuleInfo0, ModuleInfo, !Subst)
 		)
 	->
-		Subst = Subst1,
-		mode_info_set_module_info(ModeInfo0, ModuleInfo, ModeInfo)
+		mode_info_set_module_info(ModuleInfo, !ModeInfo)
 	;
-		Subst = Subst0,
 		set__singleton_set(WaitingVars, VarId),
 		mode_info_error(WaitingVars,
 			mode_error_var_has_inst(VarId, VarInst, Inst),
-			ModeInfo0, ModeInfo)
+			!ModeInfo)
 	).
 
 %-----------------------------------------------------------------------------%
 
 modecheck_set_var_inst_list(Vars0, InitialInsts, FinalInsts, ArgOffset,
-		Vars, Goals) -->
+		Vars, Goals, !ModeInfo) :-
 	(
 		modecheck_set_var_inst_list_2(Vars0, InitialInsts, FinalInsts,
-			no_extra_goals, ArgOffset, Vars1, Goals1)
+			ArgOffset, Vars1, no_extra_goals, Goals1, !ModeInfo)
 	->
-		{ Vars = Vars1, Goals = Goals1 }
+		Vars = Vars1,
+		Goals = Goals1
 	;
-		{ error("modecheck_set_var_inst_list: length mismatch") }
+		error("modecheck_set_var_inst_list: length mismatch")
 	).
 
-:- pred modecheck_set_var_inst_list_2(list(prog_var), list(inst), list(inst),
-		extra_goals, int, list(prog_var), extra_goals,
-		mode_info, mode_info).
-:- mode modecheck_set_var_inst_list_2(in, in, in, in, in, out, out,
-					mode_info_di, mode_info_uo) is semidet.
+:- pred modecheck_set_var_inst_list_2(list(prog_var)::in, list(inst)::in,
+	list(inst)::in, int::in, list(prog_var)::out,
+	extra_goals::in, extra_goals::out,
+	mode_info::in, mode_info::out) is semidet.
 
-modecheck_set_var_inst_list_2([], [], [], ExtraGoals, _, [], ExtraGoals) -->
-	[].
+modecheck_set_var_inst_list_2([], [], [], _, [], !ExtraGoals, !ModeInfo).
 modecheck_set_var_inst_list_2([Var0 | Vars0], [InitialInst | InitialInsts],
-			[FinalInst | FinalInsts], ExtraGoals0, ArgNum0,
-			[Var | Vars], ExtraGoals) -->
-	{ ArgNum = ArgNum0 + 1 },
-	mode_info_set_call_arg_context(ArgNum),
+		[FinalInst | FinalInsts], ArgNum0, [Var | Vars],
+		!ExtraGoals, !ModeInfo) :-
+	ArgNum = ArgNum0 + 1,
+	mode_info_set_call_arg_context(ArgNum, !ModeInfo),
 	modecheck_set_var_inst(Var0, InitialInst, FinalInst,
-				Var, ExtraGoals0, ExtraGoals1),
-	modecheck_set_var_inst_list_2(Vars0, InitialInsts, FinalInsts,
- 				ExtraGoals1, ArgNum, Vars, ExtraGoals).
-
-:- pred modecheck_set_var_inst(prog_var, inst, inst, prog_var, extra_goals,
-		extra_goals, mode_info, mode_info).
-:- mode modecheck_set_var_inst(in, in, in, out, in, out,
-				mode_info_di, mode_info_uo) is det.
-
-modecheck_set_var_inst(Var0, InitialInst, FinalInst, Var,
-		ExtraGoals0, ExtraGoals, ModeInfo0, ModeInfo) :-
-	mode_info_get_instmap(ModeInfo0, InstMap0),
+		Var, !ExtraGoals, !ModeInfo),
+	modecheck_set_var_inst_list_2(Vars0, InitialInsts, FinalInsts, ArgNum,
+		Vars, !ExtraGoals, !ModeInfo).
+
+:- pred modecheck_set_var_inst(prog_var::in, (inst)::in, (inst)::in,
+	prog_var::out, extra_goals::in, extra_goals::out,
+	mode_info::in, mode_info::out) is det.
+
+modecheck_set_var_inst(Var0, InitialInst, FinalInst, Var, !ExtraGoals,
+		!ModeInfo) :-
+	mode_info_get_instmap(!.ModeInfo, InstMap0),
 	( instmap__is_reachable(InstMap0) ->
 		% The new inst must be computed by unifying the
 		% old inst and the proc's final inst
 		instmap__lookup_var(InstMap0, Var0, VarInst0),
-		handle_implied_mode(Var0, VarInst0, InitialInst,
-		 	Var, ExtraGoals0, ExtraGoals, ModeInfo0, ModeInfo1),
-		modecheck_set_var_inst(Var0, FinalInst, no,
-			ModeInfo1, ModeInfo2),
+		handle_implied_mode(Var0, VarInst0, InitialInst, Var,
+			!ExtraGoals, !ModeInfo),
+		modecheck_set_var_inst(Var0, FinalInst, no, !ModeInfo),
 		( Var = Var0 ->
-			ModeInfo = ModeInfo2
+			true
 		;
-			modecheck_set_var_inst(Var, FinalInst, no,
-				ModeInfo2, ModeInfo)
+			modecheck_set_var_inst(Var, FinalInst, no, !ModeInfo)
 		)
 	;
-		Var = Var0,
-		ExtraGoals = ExtraGoals0,
-		ModeInfo = ModeInfo0
+		Var = Var0
 	).
 
 	% Note that there are two versions of modecheck_set_var_inst,
@@ -1951,14 +1914,14 @@
 	% The former is used for predicate calls, where we may need
 	% to introduce unifications to handle calls to implied modes.
 
-modecheck_set_var_inst(Var0, FinalInst, MaybeUInst, ModeInfo00, ModeInfo) :-
-	mode_info_get_instmap(ModeInfo0, InstMap0),
-	mode_info_get_parallel_vars(PVars0, ModeInfo00, ModeInfo0),
+modecheck_set_var_inst(Var0, FinalInst, MaybeUInst, !ModeInfo) :-
+	mode_info_get_parallel_vars(!.ModeInfo, PVars0),
+	mode_info_get_instmap(!.ModeInfo, InstMap0),
 	( instmap__is_reachable(InstMap0) ->
 		% The new inst must be computed by unifying the
 		% old inst and the proc's final inst
 		instmap__lookup_var(InstMap0, Var0, Inst0),
-		mode_info_get_module_info(ModeInfo0, ModuleInfo0),
+		mode_info_get_module_info(!.ModeInfo, ModuleInfo0),
 		(
 			abstractly_unify_inst(dead, Inst0, FinalInst,
 				fake_unify, ModuleInfo0,
@@ -1969,8 +1932,8 @@
 		;
 			error("modecheck_set_var_inst: unify_inst failed")
 		),
-		mode_info_set_module_info(ModeInfo0, ModuleInfo, ModeInfo1),
-		mode_info_get_var_types(ModeInfo1, VarTypes),
+		mode_info_set_module_info(ModuleInfo, !ModeInfo),
+		mode_info_get_var_types(!.ModeInfo, VarTypes),
 		map__lookup(VarTypes, Var0, Type),
 		(
 			% if the top-level inst of the variable is not_reached,
@@ -1978,7 +1941,7 @@
 			inst_expand(ModuleInfo, Inst, not_reached)
 		->
 			instmap__init_unreachable(InstMap),
-			mode_info_set_instmap(InstMap, ModeInfo1, ModeInfo3)
+			mode_info_set_instmap(InstMap, !ModeInfo)
 		;
 			% If we haven't added any information and
 			% we haven't bound any part of the var, then
@@ -1986,7 +1949,7 @@
 			inst_matches_initial(Inst0, Inst, Type, ModuleInfo)
 		->
 			instmap__set(InstMap0, Var0, Inst, InstMap),
-			mode_info_set_instmap(InstMap, ModeInfo1, ModeInfo3)
+			mode_info_set_instmap(InstMap, !ModeInfo)
 		;
 			% We must have either added some information,
 			% lost some uniqueness, or bound part of the var.
@@ -1996,7 +1959,7 @@
 
 			% We've bound part of the var.  If the var was locked,
 			% then we need to report an error...
-			mode_info_var_is_locked(ModeInfo1, Var0, Reason0),
+			mode_info_var_is_locked(!.ModeInfo, Var0, Reason0),
 			\+ (
 				% ...unless the goal is a unification and the
 				% var was unified with something no more
@@ -2017,22 +1980,20 @@
 			set__singleton_set(WaitingVars, Var0),
 			mode_info_error(WaitingVars,
 				mode_error_bind_var(Reason0, Var0, Inst0, Inst),
-				ModeInfo1, ModeInfo3
+				!ModeInfo
 			)
 		;
 			instmap__set(InstMap0, Var0, Inst, InstMap),
-			mode_info_set_instmap(InstMap, ModeInfo1, ModeInfo2),
-			mode_info_get_delay_info(ModeInfo2, DelayInfo0),
+			mode_info_set_instmap(InstMap, !ModeInfo),
+			mode_info_get_delay_info(!.ModeInfo, DelayInfo0),
 			delay_info__bind_var(DelayInfo0, Var0, DelayInfo),
-			mode_info_set_delay_info(DelayInfo,
-						ModeInfo2, ModeInfo3)
+			mode_info_set_delay_info(DelayInfo, !ModeInfo)
 		)
 	;
-		ModeInfo3 = ModeInfo0
+		true
 	),
 	(
-		PVars0 = [],
-		ModeInfo = ModeInfo3
+		PVars0 = []
 	;
 		PVars0 = [NonLocals - Bound0|PVars1],
 		( set__member(Var0, NonLocals) ->
@@ -2041,25 +2002,23 @@
 		;
 			PVars = PVars0
 		),
-		mode_info_set_parallel_vars(PVars, ModeInfo3, ModeInfo)
+		mode_info_set_parallel_vars(PVars, !ModeInfo)
 	).
 
-
 % If this was a call to an implied mode for that variable, then we need to
 % introduce a fresh variable.
 
-:- pred handle_implied_mode(prog_var, inst, inst, prog_var,
-		extra_goals, extra_goals, mode_info, mode_info).
-:- mode handle_implied_mode(in, in, in, out, in, out,
-		mode_info_di, mode_info_uo) is det.
-
-handle_implied_mode(Var0, VarInst0, InitialInst0, Var,
-		ExtraGoals0, ExtraGoals, ModeInfo0, ModeInfo) :-
-	mode_info_get_module_info(ModeInfo0, ModuleInfo0),
+:- pred handle_implied_mode(prog_var::in, (inst)::in, (inst)::in,
+	prog_var::out, extra_goals::in, extra_goals::out,
+	mode_info::in, mode_info::out) is det.
+
+handle_implied_mode(Var0, VarInst0, InitialInst0, Var, !ExtraGoals,
+		!ModeInfo) :-
+	mode_info_get_module_info(!.ModeInfo, ModuleInfo0),
 	inst_expand(ModuleInfo0, InitialInst0, InitialInst),
 	inst_expand(ModuleInfo0, VarInst0, VarInst1),
 
-	mode_info_get_var_types(ModeInfo0, VarTypes0),
+	mode_info_get_var_types(!.ModeInfo, VarTypes0),
 	map__lookup(VarTypes0, Var0, VarType),
 	(
 		% If the initial inst of the variable matches_final
@@ -2069,9 +2028,7 @@
 		inst_matches_initial_no_implied_modes(VarInst1, InitialInst,
 			VarType, ModuleInfo0)
 	->
-		Var = Var0,
-		ExtraGoals = ExtraGoals0,
-		ModeInfo = ModeInfo0
+		Var = Var0
 	;
 		% This is the implied mode case.
 		% We do not yet handle implied modes for partially
@@ -2094,14 +2051,15 @@
 			% XXX We ought to use a more elegant method
 			% XXX than hard-coding the name `<foo>_init_any'.
 
-			mode_info_get_context(ModeInfo0, Context),
-			mode_info_get_mode_context(ModeInfo0, ModeContext),
-			mode_context_to_unify_context(ModeContext, ModeInfo0,
-				UnifyContext),
+			mode_info_get_context(!.ModeInfo, Context),
+			mode_info_get_mode_context(!.ModeInfo, ModeContext),
+			mode_context_to_unify_context(!.ModeInfo,
+				ModeContext, UnifyContext),
 			CallUnifyContext = yes(call_unify_context(
 						Var, var(Var), UnifyContext)),
 			( 
-				type_to_ctor_and_args(VarType, TypeCtor, _TypeArgs),
+				type_to_ctor_and_args(VarType, TypeCtor,
+					_TypeArgs),
 				TypeCtor = qualified(TypeModule, TypeName) -
 						_TypeArity,
 				string__append(TypeName, "_init_any", PredName),
@@ -2119,19 +2077,17 @@
 					InstmapDelta, GoalInfo),
 				NewExtraGoal = extra_goals(
 					[BeforeGoal - GoalInfo], []),
-				append_extra_goals(ExtraGoals0, NewExtraGoal,
-					ExtraGoals),
-				ModeInfo0 = ModeInfo
+				append_extra_goals(!.ExtraGoals, NewExtraGoal,
+					!:ExtraGoals)
 			;
 				% If the type is a type variable,
 				% or there isn't any <mod>:<type>_init_any/1
 				% predicate, then give up.
-				ExtraGoals = ExtraGoals0,
 				set__singleton_set(WaitingVars, Var0),
 				mode_info_error(WaitingVars,
 					mode_error_implied_mode(Var0, VarInst0,
 					InitialInst),
-					ModeInfo0, ModeInfo
+					!ModeInfo
 				)
 			)
 		;
@@ -2139,40 +2095,38 @@
 		->
 			% This is the case we can't handle
 			Var = Var0,
-			ExtraGoals = ExtraGoals0,
 			set__singleton_set(WaitingVars, Var0),
 			mode_info_error(WaitingVars,
 				mode_error_implied_mode(Var0, VarInst0,
 				InitialInst),
-				ModeInfo0, ModeInfo
+				!ModeInfo
 			)
 		;
 			% This is the simple case of implied modes,
 			% where the declared mode was free -> ...
 
 			% Introduce a new variable
-			mode_info_get_varset(ModeInfo0, VarSet0),
+			mode_info_get_varset(!.ModeInfo, VarSet0),
 			varset__new_var(VarSet0, Var, VarSet),
 			map__set(VarTypes0, Var, VarType, VarTypes),
-			mode_info_set_varset(VarSet, ModeInfo0, ModeInfo1),
-			mode_info_set_var_types(VarTypes, ModeInfo1, ModeInfo),
+			mode_info_set_varset(VarSet, !ModeInfo),
+			mode_info_set_var_types(VarTypes, !ModeInfo),
 
 			% Construct the code to do the unification
 			modecheck_unify__create_var_var_unification(Var0, Var,
-				VarType, ModeInfo, ExtraGoal),
+				VarType, !.ModeInfo, ExtraGoal),
 
 			% append the goals together in the appropriate order:
 			% ExtraGoals0, then NewUnify
 			NewUnifyExtraGoal = extra_goals([], [ExtraGoal]),
-			append_extra_goals(ExtraGoals0, NewUnifyExtraGoal,
-				ExtraGoals)
+			append_extra_goals(!.ExtraGoals, NewUnifyExtraGoal,
+				!:ExtraGoals)
 		)
 	).
 
-:- pred modes__build_call(module_name, string, list(prog_var),
-		prog_context, maybe(call_unify_context), module_info,
-		hlds_goal).
-:- mode modes__build_call(in, in, in, in, in, in, out) is semidet.
+:- pred modes__build_call(module_name::in, string::in, list(prog_var)::in,
+	prog_context::in, maybe(call_unify_context)::in, module_info::in,
+	hlds_goal::out) is semidet.
 
 modes__build_call(Module, Name, ArgVars, Context, CallUnifyContext, ModuleInfo,
 		Goal) :-
@@ -2189,10 +2143,10 @@
 
 %-----------------------------------------------------------------------------%
 
-mode_context_to_unify_context(unify(UnifyContext, _), _, UnifyContext).
-mode_context_to_unify_context(call(CallId, Arg), _ModeInfo,
+mode_context_to_unify_context(_, unify(UnifyContext, _), UnifyContext).
+mode_context_to_unify_context(_, call(CallId, Arg),
 		unify_context(call(CallId, Arg), [])).
-mode_context_to_unify_context(uninitialized, _, _) :-
+mode_context_to_unify_context(_, uninitialized, _) :-
 	error("mode_context_to_unify_context: uninitialized context").
 
 %-----------------------------------------------------------------------------%
@@ -2201,68 +2155,66 @@
 % check that the evaluation method is OK for the given mode(s).
 % we also check the mode of main/2 here.
 
-:- pred check_eval_methods(module_info, module_info, io__state, io__state).
-:- mode check_eval_methods(in, out, di, uo) is det.
+:- pred check_eval_methods(module_info::in, module_info::out,
+	io__state::di, io__state::uo) is det.
+
+check_eval_methods(!ModuleInfo, !IO) :-
+	module_info_predids(!.ModuleInfo, PredIds),
+	pred_check_eval_methods(PredIds, !ModuleInfo, !IO).
+
+:- pred pred_check_eval_methods(list(pred_id)::in,
+	module_info::in, module_info::out,
+	io__state::di, io__state::uo) is det.
+
+pred_check_eval_methods([], !ModuleInfo, !IO).
+pred_check_eval_methods([PredId|Rest], !ModuleInfo, !IO) :-
+	module_info_preds(!.ModuleInfo, Preds),
+	map__lookup(Preds, PredId, PredInfo),
+	ProcIds = pred_info_procids(PredInfo),
+	proc_check_eval_methods(ProcIds, PredId, !ModuleInfo, !IO),
+	pred_check_eval_methods(Rest, !ModuleInfo, !IO).
+
+:- pred proc_check_eval_methods(list(proc_id)::in, pred_id::in,
+	module_info::in, module_info::out,
+	io__state::di, io__state::uo) is det.
 
-check_eval_methods(ModuleInfo0, ModuleInfo) -->
-	{ module_info_predids(ModuleInfo0, PredIds) },
-	pred_check_eval_methods(PredIds, ModuleInfo0, ModuleInfo).
-
-:- pred pred_check_eval_methods(list(pred_id), module_info, module_info,
-		io__state, io__state).
-:- mode pred_check_eval_methods(in, in, out, di, uo) is det.
-
-pred_check_eval_methods([], M, M) --> [].
-pred_check_eval_methods([PredId|Rest], ModuleInfo0, ModuleInfo) --> 
-	{ module_info_preds(ModuleInfo0, Preds) },
-	{ map__lookup(Preds, PredId, PredInfo) },
-	{ ProcIds = pred_info_procids(PredInfo) },
-	proc_check_eval_methods(ProcIds, PredId, ModuleInfo0, ModuleInfo1),
-	pred_check_eval_methods(Rest, ModuleInfo1, ModuleInfo).	
-
-:- pred proc_check_eval_methods(list(proc_id), pred_id, module_info, 
-		module_info, io__state, io__state).
-:- mode proc_check_eval_methods(in, in, in, out, di, uo) is det.
-
-proc_check_eval_methods([], _, M, M) --> [].
-proc_check_eval_methods([ProcId|Rest], PredId, ModuleInfo0, ModuleInfo) --> 
-	{ module_info_pred_proc_info(ModuleInfo0, PredId, ProcId, 
-		PredInfo, ProcInfo) },
-	{ proc_info_eval_method(ProcInfo, EvalMethod) },
-	{ proc_info_argmodes(ProcInfo, Modes) },
+proc_check_eval_methods([], _, !ModuleInfo, !IO).
+proc_check_eval_methods([ProcId|Rest], PredId, !ModuleInfo, !IO) :-
+	module_info_pred_proc_info(!.ModuleInfo, PredId, ProcId,
+		PredInfo, ProcInfo),
+	proc_info_eval_method(ProcInfo, EvalMethod),
+	proc_info_argmodes(ProcInfo, Modes),
 	( 
-		{ eval_method_requires_ground_args(EvalMethod) = yes },
-		\+ { only_fully_in_out_modes(Modes, ModuleInfo0) } 
+		eval_method_requires_ground_args(EvalMethod) = yes,
+		\+ only_fully_in_out_modes(Modes, !.ModuleInfo)
 	->
 		report_eval_method_requires_ground_args(ProcInfo,
-			ModuleInfo0, ModuleInfo1)
+			!ModuleInfo, !IO)
 	;
-		{ ModuleInfo1 = ModuleInfo0 }	
+		true
 	),	
 	( 
-		{ eval_method_destroys_uniqueness(EvalMethod) = yes },
-		\+ { only_nonunique_modes(Modes, ModuleInfo1) } 
+		eval_method_destroys_uniqueness(EvalMethod) = yes,
+		\+ only_nonunique_modes(Modes, !.ModuleInfo)
 	->
 		report_eval_method_destroys_uniqueness(ProcInfo,
-			ModuleInfo1, ModuleInfo2)
+			!ModuleInfo, !IO)
 	;
-		{ ModuleInfo2 = ModuleInfo1 }	
+		true
 	),
 	(
-		{ pred_info_name(PredInfo) = "main" },
-		{ pred_info_arity(PredInfo) = 2 },
-		{ pred_info_is_exported(PredInfo) },
-		{ \+ check_mode_of_main(Modes, ModuleInfo2) }
+		pred_info_name(PredInfo) = "main",
+		pred_info_arity(PredInfo) = 2,
+		pred_info_is_exported(PredInfo),
+		\+ check_mode_of_main(Modes, !.ModuleInfo)
 	->
-		report_wrong_mode_for_main(ProcInfo,
-			ModuleInfo2, ModuleInfo3)
+		report_wrong_mode_for_main(ProcInfo, !ModuleInfo, !IO)
 	;
-		{ ModuleInfo3 = ModuleInfo2 }
+		true
 	),
-	proc_check_eval_methods(Rest, PredId, ModuleInfo3, ModuleInfo).
+	proc_check_eval_methods(Rest, PredId, !ModuleInfo, !IO).
 
-:- pred only_fully_in_out_modes(list(mode), module_info).
-:- mode only_fully_in_out_modes(in, in) is semidet.
+:- pred only_fully_in_out_modes(list(mode)::in, module_info::in) is semidet.
 
 only_fully_in_out_modes([], _).
 only_fully_in_out_modes([Mode|Rest], ModuleInfo) :-
@@ -2279,8 +2231,7 @@
 	),
 	only_fully_in_out_modes(Rest, ModuleInfo).
 
-:- pred only_nonunique_modes(list(mode), module_info).
-:- mode only_nonunique_modes(in, in) is semidet.
+:- pred only_nonunique_modes(list(mode)::in, module_info::in) is semidet.
 
 only_nonunique_modes([], _).
 only_nonunique_modes([Mode|Rest], ModuleInfo) :-
@@ -2289,8 +2240,7 @@
 	inst_is_not_partly_unique(ModuleInfo, FinalInst),
 	only_nonunique_modes(Rest, ModuleInfo).
 
-:- pred check_mode_of_main(list(mode), module_info).
-:- mode check_mode_of_main(in, in) is semidet.
+:- pred check_mode_of_main(list(mode)::in, module_info::in) is semidet.
 
 check_mode_of_main([Di, Uo], ModuleInfo) :-
 	mode_get_insts(ModuleInfo, Di, DiInitialInst, DiFinalInst),
@@ -2309,71 +2259,72 @@
 	( Free = free ; Free = free(_Type) ),
 	inst_expand(ModuleInfo, UoFinalInst, ground(unique, none)).
 
-:- pred report_eval_method_requires_ground_args(proc_info,
-		module_info, module_info, io__state, io__state).
-:- mode report_eval_method_requires_ground_args(in, in, out, di, uo) is det.
-
-report_eval_method_requires_ground_args(ProcInfo, ModuleInfo0, ModuleInfo) -->
-	{ proc_info_eval_method(ProcInfo, EvalMethod) },
-	{ proc_info_context(ProcInfo, Context) },
-	{ EvalMethodS = eval_method_to_string(EvalMethod) },
-	globals__io_lookup_bool_option(verbose_errors, VerboseErrors),
-	prog_out__write_context(Context),
-	io__write_string("Sorry, not implemented: `pragma "),
-	io__write_string(EvalMethodS),
-	io__write_string("'\n"),
-	prog_out__write_context(Context),
-	io__write_string(
-	    "  declaration not allowed for procedure with\n"),
-	prog_out__write_context(Context),
-	io__write_string(
-	    "  partially instantiated modes.\n"), 
-	( { VerboseErrors = yes } ->
+:- pred report_eval_method_requires_ground_args(proc_info::in,
+	module_info::in, module_info::out,
+	io__state::di, io__state::uo) is det.
+
+report_eval_method_requires_ground_args(ProcInfo, !ModuleInfo, !IO) :-
+	proc_info_eval_method(ProcInfo, EvalMethod),
+	proc_info_context(ProcInfo, Context),
+	EvalMethodS = eval_method_to_string(EvalMethod),
+	globals__io_lookup_bool_option(verbose_errors, VerboseErrors, !IO),
+	prog_out__write_context(Context, !IO),
+	io__write_string("Sorry, not implemented: `pragma ", !IO),
+	io__write_string(EvalMethodS, !IO),
+	io__write_string("'\n", !IO),
+	prog_out__write_context(Context, !IO),
+	io__write_string("  declaration not allowed for procedure with\n",
+		!IO),
+	prog_out__write_context(Context, !IO),
+	io__write_string("  partially instantiated modes.\n", !IO),
+	(
+		VerboseErrors = yes,
 		io__write_string(
 "	Tabling of predicates/functions with partially instantiated modes
-	is not currently implemented.\n")
+	is not currently implemented.\n", !IO)
 	;
-		[]
+		VerboseErrors = no
 	),
-	{ module_info_incr_errors(ModuleInfo0, ModuleInfo) }.
+	module_info_incr_errors(!ModuleInfo).
+
+:- pred report_eval_method_destroys_uniqueness(proc_info::in,
+	module_info::in, module_info::out,
+	io__state::di, io__state::uo) is det.
 
-:- pred report_eval_method_destroys_uniqueness(proc_info,
-		module_info, module_info, io__state, io__state).
-:- mode report_eval_method_destroys_uniqueness(in, in, out, di, uo) is det.
-
-report_eval_method_destroys_uniqueness(ProcInfo, ModuleInfo0, ModuleInfo) -->
-	{ proc_info_eval_method(ProcInfo, EvalMethod) },
-	{ proc_info_context(ProcInfo, Context) },
-	{ EvalMethodS = eval_method_to_string(EvalMethod) },
-	globals__io_lookup_bool_option(verbose_errors, VerboseErrors),
-	prog_out__write_context(Context),
-	io__write_string("Error: `pragma "),
-	io__write_string(EvalMethodS),
-	io__write_string("'\n"),
-	prog_out__write_context(Context),
+report_eval_method_destroys_uniqueness(ProcInfo, !ModuleInfo, !IO) :-
+	proc_info_eval_method(ProcInfo, EvalMethod),
+	proc_info_context(ProcInfo, Context),
+	EvalMethodS = eval_method_to_string(EvalMethod),
+	globals__io_lookup_bool_option(verbose_errors, VerboseErrors, !IO),
+	prog_out__write_context(Context, !IO),
+	io__write_string("Error: `pragma ", !IO),
+	io__write_string(EvalMethodS, !IO),
+	io__write_string("'\n", !IO),
+	prog_out__write_context(Context, !IO),
 	io__write_string(
-	    "  declaration not allowed for procedure with\n"),
-	prog_out__write_context(Context),
-	io__write_string("  unique modes.\n"), 
-	( { VerboseErrors = yes } ->
+	    "  declaration not allowed for procedure with\n", !IO),
+	prog_out__write_context(Context, !IO),
+	io__write_string("  unique modes.\n", !IO),
+	(
+		VerboseErrors = yes,
 		io__write_string(
 "	Tabling of predicates/functions with unique modes is not allowed
 	as this would lead to a copying of the unique arguments which 
-	would result in them no longer being unique.\n")
+	would result in them no longer being unique.\n", !IO)
 	;
-		[]
+		VerboseErrors = no
 	),
-	{ module_info_incr_errors(ModuleInfo0, ModuleInfo) }.
+	module_info_incr_errors(!ModuleInfo).
 
-:- pred report_wrong_mode_for_main(proc_info,
-		module_info, module_info, io__state, io__state).
-:- mode report_wrong_mode_for_main(in, in, out, di, uo) is det.
+:- pred report_wrong_mode_for_main(proc_info::in,
+	module_info::in, module_info::out,
+	io__state::di, io__state::uo) is det.
 
-report_wrong_mode_for_main(ProcInfo, ModuleInfo0, ModuleInfo) -->
-	{ proc_info_context(ProcInfo, Context) },
-	prog_out__write_context(Context),
-	io__write_string("Error: main/2 must have mode `(di, uo)'.\n"),
-	{ module_info_incr_errors(ModuleInfo0, ModuleInfo) }.
+report_wrong_mode_for_main(ProcInfo, !ModuleInfo, !IO) :-
+	proc_info_context(ProcInfo, Context),
+	prog_out__write_context(Context, !IO),
+	io__write_string("Error: main/2 must have mode `(di, uo)'.\n", !IO),
+	module_info_incr_errors(!ModuleInfo).
 
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
@@ -2400,11 +2351,10 @@
 	% detect the error; if they are, it will probably go into
 	% an infinite loop).
 
-:- pred check_circular_modes(module_info, module_info, io__state, io__state).
-:- mode check_circular_modes(in, out, di, uo) is det.
+:- pred check_circular_modes(module_info::in, module_info::out,
+	io__state::di, io__state::uo) is det.
 
-check_circular_modes(Module0, Module) -->
-	{ Module = Module0 }.
+check_circular_modes(!Module, !IO).
 
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
Index: compiler/pd_util.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/pd_util.m,v
retrieving revision 1.29
diff -u -b -r1.29 pd_util.m
--- compiler/pd_util.m	5 Nov 2003 03:17:42 -0000	1.29
+++ compiler/pd_util.m	5 Nov 2003 21:25:20 -0000
@@ -292,16 +292,18 @@
 	% procedures, since that could cause a less efficient version to
 	% be chosen.
 	{ MayChangeCalledProc = may_not_change_called_proc },
-	{ mode_info_init(IO0, ModuleInfo1, PredId, ProcId, Context,
+	{ mode_info_init(ModuleInfo1, PredId, ProcId, Context,
 		LiveVars, InstMap0, check_unique_modes,
 		MayChangeCalledProc, ModeInfo0) },
 
-	{ unique_modes__check_goal(Goal0, Goal, ModeInfo0, ModeInfo1) },
+	{ unique_modes__check_goal(Goal0, Goal, ModeInfo0, ModeInfo1,
+		IO0, IO1) },
 	pd_info_lookup_bool_option(debug_pd, Debug),
 	{ Debug = yes ->
-		report_mode_errors(ModeInfo1, ModeInfo)
+		report_mode_errors(ModeInfo1, ModeInfo, IO1, IO)
 	;
-		ModeInfo = ModeInfo1
+		ModeInfo = ModeInfo1,
+		IO = IO1
 	},
 	{ mode_info_get_errors(ModeInfo, Errors) },
 
@@ -309,7 +311,6 @@
 	% Deconstruct the mode_info.
 	%
 	{ mode_info_get_module_info(ModeInfo, ModuleInfo) },
-	{ mode_info_get_io_state(ModeInfo, IO) },
 	{ mode_info_get_varset(ModeInfo, VarSet) },
 	{ mode_info_get_var_types(ModeInfo, VarTypes) },
 	pd_info_set_module_info(ModuleInfo),
Index: compiler/transform.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/transform.m,v
retrieving revision 1.16
diff -u -b -r1.16 transform.m
--- compiler/transform.m	15 Mar 2003 03:09:12 -0000	1.16
+++ compiler/transform.m	5 Nov 2003 22:45:20 -0000
@@ -38,11 +38,11 @@
 
 %:- pred unfold__in_proc(pred_id, proc_id, hlds_goal_expr,
 %			mode_info, mode_info).
-%:- mode unfold__in_proc(in, in, out, mode_info_di, module_info_uo) is det.
+%:- mode unfold__in_proc(in, in, out, in, out) is det.
 
 :- pred transform__reschedule_conj(list(hlds_goal), list(hlds_goal), 
 			mode_info, mode_info).
-:- mode transform__reschedule_conj(in, out, mode_info_di, mode_info_uo) is det.
+:- mode transform__reschedule_conj(in, out, in, out) is det.
 
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
Index: compiler/unique_modes.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/unique_modes.m,v
retrieving revision 1.77
diff -u -b -r1.77 unique_modes.m
--- compiler/unique_modes.m	18 Mar 2003 02:43:43 -0000	1.77
+++ compiler/unique_modes.m	5 Nov 2003 23:16:47 -0000
@@ -44,18 +44,16 @@
 :- import_module io, bool.
 
 	% check every predicate in a module
-:- pred unique_modes__check_module(module_info, module_info,
-					io__state, io__state).
-:- mode unique_modes__check_module(in, out, di, uo) is det.
+:- pred unique_modes__check_module(module_info::in, module_info::out,
+	io__state::di, io__state::uo) is det.
 
 	% just check a single procedure
-:- pred unique_modes__check_proc(proc_id, pred_id, module_info,
-				module_info, bool, io__state, io__state).
-:- mode unique_modes__check_proc(in, in, in, out, out, di, uo) is det.
+:- pred unique_modes__check_proc(proc_id::in, pred_id::in, module_info::in,
+	module_info::out, bool::out, io__state::di, io__state::uo) is det.
 
 	% just check a single goal
-:- pred unique_modes__check_goal(hlds_goal, hlds_goal, mode_info, mode_info).
-:- mode unique_modes__check_goal(in, out, mode_info_di, mode_info_uo) is det.
+:- pred unique_modes__check_goal(hlds_goal::in, hlds_goal::out,
+	mode_info::in, mode_info::out, io::di, io::uo) is det.
 
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
@@ -87,25 +85,24 @@
 
 %-----------------------------------------------------------------------------%
 
-unique_modes__check_module(ModuleInfo0, ModuleInfo) -->
+unique_modes__check_module(!ModuleInfo, !IO) :-
 	check_pred_modes(check_unique_modes, may_change_called_proc,
-			ModuleInfo0, ModuleInfo, _UnsafeToContinue).
+		!ModuleInfo, _UnsafeToContinue, !IO).
 
-unique_modes__check_proc(ProcId, PredId, ModuleInfo0, ModuleInfo, Changed) -->
-	modecheck_proc(ProcId, PredId,
-		check_unique_modes, may_change_called_proc,
-		ModuleInfo0, ModuleInfo, NumErrors, Changed),
-	( { NumErrors \= 0 } ->
-		io__set_exit_status(1)
+unique_modes__check_proc(ProcId, PredId, !ModuleInfo, Changed, !IO) :-
+	modecheck_proc(ProcId, PredId, check_unique_modes,
+		may_change_called_proc, !ModuleInfo, NumErrors, Changed, !IO),
+	( NumErrors \= 0 ->
+		io__set_exit_status(1, !IO)
 	;
-		[]
+		true
 	).
 
 	% XXX we currently make the conservative assumption that
 	% any non-local variable in a disjunction or nondet call
 	% is nondet-live - and stays nondet-live.
 
-unique_modes__check_goal(Goal0, Goal, ModeInfo0, ModeInfo) :-
+unique_modes__check_goal(Goal0, Goal, !ModeInfo, !IO) :-
 	%
 	% store the current context in the mode_info
 	%
@@ -113,20 +110,20 @@
 	goal_info_get_context(GoalInfo0, Context),
 	term__context_init(EmptyContext),
 	( Context = EmptyContext ->
-		ModeInfo1 = ModeInfo0
+		true
 	;
-		mode_info_set_context(Context, ModeInfo0, ModeInfo1)
+		mode_info_set_context(Context, !ModeInfo)
 	),
 
 	%
 	% Grab the original instmap
 	%
-	mode_info_get_instmap(ModeInfo1, InstMap0),
+	mode_info_get_instmap(!.ModeInfo, InstMap0),
 
 	% 
 	% Grab the original bag of nondet-live vars
 	%
-	mode_info_get_nondet_live_vars(ModeInfo1, NondetLiveVars0),
+	mode_info_get_nondet_live_vars(!.ModeInfo, NondetLiveVars0),
 
 	% 
 	% If the goal is not nondet, then nothing is nondet-live,
@@ -134,36 +131,35 @@
 	%
 	goal_info_get_determinism(GoalInfo0, Detism),
 	( determinism_components(Detism, _, at_most_many) ->
-		ModeInfo2 = ModeInfo1
+		true
 	;
-		mode_info_set_nondet_live_vars([], ModeInfo1, ModeInfo2)
+		mode_info_set_nondet_live_vars([], !ModeInfo)
 	),
 
 	%
 	% Modecheck the goal
 	%
 	unique_modes__check_goal_2(GoalExpr0, GoalInfo0, GoalExpr,
-		ModeInfo2, ModeInfo3),
+		!ModeInfo, !IO),
 
 	% 
 	% Restore the original bag of nondet-live vars
 	%
-	mode_info_set_nondet_live_vars(NondetLiveVars0, ModeInfo3, ModeInfo4),
+	mode_info_set_nondet_live_vars(NondetLiveVars0, !ModeInfo),
 
 	%
 	% Grab the final instmap, compute the change in insts
 	% over this goal, and save that instmap_delta in the goal_info.
 	%
-	compute_goal_instmap_delta(InstMap0, GoalExpr,
-		GoalInfo0, GoalInfo, ModeInfo4, ModeInfo),
+	compute_goal_instmap_delta(InstMap0, GoalExpr, GoalInfo0, GoalInfo,
+		!ModeInfo),
 
 	Goal = GoalExpr - GoalInfo.
 
 	% Make all nondet-live variables whose current inst
 	% is `unique' become `mostly_unique'.
 	%
-:- pred make_all_nondet_live_vars_mostly_uniq(mode_info, mode_info).
-:- mode make_all_nondet_live_vars_mostly_uniq(mode_info_di, mode_info_uo)
+:- pred make_all_nondet_live_vars_mostly_uniq(mode_info::in, mode_info::out)
 	is det.
 
 make_all_nondet_live_vars_mostly_uniq(ModeInfo0, ModeInfo) :-
@@ -176,8 +172,8 @@
 		ModeInfo = ModeInfo0
 	).
 
-:- pred select_live_vars(list(prog_var), mode_info, list(prog_var)).
-:- mode select_live_vars(in, mode_info_ui, out) is det.
+:- pred select_live_vars(list(prog_var)::in, mode_info::in,
+	list(prog_var)::out) is det.
 
 select_live_vars([], _, []).
 select_live_vars([Var|Vars], ModeInfo, LiveVars) :-
@@ -188,8 +184,8 @@
 		select_live_vars(Vars, ModeInfo, LiveVars)
 	).
 
-:- pred select_nondet_live_vars(list(prog_var), mode_info, list(prog_var)).
-:- mode select_nondet_live_vars(in, mode_info_ui, out) is det.
+:- pred select_nondet_live_vars(list(prog_var)::in, mode_info::in,
+	list(prog_var)::out) is det.
 
 select_nondet_live_vars([], _, []).
 select_nondet_live_vars([Var|Vars], ModeInfo, NondetLiveVars) :-
@@ -205,9 +201,8 @@
 	% (other than changes which just add information,
 	% e.g. `ground -> bound(42)'.)
 	%
-:- pred select_changed_inst_vars(list(prog_var), instmap_delta, mode_info,
-		list(prog_var)).
-:- mode select_changed_inst_vars(in, in, mode_info_ui, out) is det.
+:- pred select_changed_inst_vars(list(prog_var)::in, instmap_delta::in,
+	mode_info::in, list(prog_var)::out) is det.
 
 select_changed_inst_vars([], _DeltaInstMap, _ModeInfo, []).
 select_changed_inst_vars([Var | Vars], DeltaInstMap, ModeInfo, ChangedVars) :-
@@ -229,20 +224,20 @@
 			ChangedVars)
 	).
 
-:- pred make_var_list_mostly_uniq(list(prog_var), mode_info, mode_info).
-:- mode make_var_list_mostly_uniq(in, mode_info_di, mode_info_uo) is det.
+:- pred make_var_list_mostly_uniq(list(prog_var)::in,
+	mode_info::in, mode_info::out) is det.
 
-make_var_list_mostly_uniq([], ModeInfo, ModeInfo).
-make_var_list_mostly_uniq([Var | Vars], ModeInfo0, ModeInfo) :-
-	make_var_mostly_uniq(Var, ModeInfo0, ModeInfo1),
-	make_var_list_mostly_uniq(Vars, ModeInfo1, ModeInfo).
-
-:- pred make_var_mostly_uniq(prog_var, mode_info, mode_info).
-:- mode make_var_mostly_uniq(in, mode_info_di, mode_info_uo) is det.
-
-make_var_mostly_uniq(Var, ModeInfo0, ModeInfo) :-
-	mode_info_get_instmap(ModeInfo0, InstMap0),
-	mode_info_get_module_info(ModeInfo0, ModuleInfo0),
+make_var_list_mostly_uniq([], !ModeInfo).
+make_var_list_mostly_uniq([Var | Vars], !ModeInfo) :-
+	make_var_mostly_uniq(Var, !ModeInfo),
+	make_var_list_mostly_uniq(Vars, !ModeInfo).
+
+:- pred make_var_mostly_uniq(prog_var::in,
+	mode_info::in, mode_info::out) is det.
+
+make_var_mostly_uniq(Var, !ModeInfo) :-
+	mode_info_get_instmap(!.ModeInfo, InstMap0),
+	mode_info_get_module_info(!.ModeInfo, ModuleInfo0),
 	(
 		%
 		% only variables which are `unique' need to be changed
@@ -258,48 +253,50 @@
 		)
 	->
 		make_mostly_uniq_inst(Inst0, ModuleInfo0, Inst, ModuleInfo),
-		mode_info_set_module_info(ModeInfo0, ModuleInfo, ModeInfo1),
+		mode_info_set_module_info(ModuleInfo, !ModeInfo),
 		instmap__set(InstMap0, Var, Inst, InstMap),
-		mode_info_set_instmap(InstMap, ModeInfo1, ModeInfo)
+		mode_info_set_instmap(InstMap, !ModeInfo)
 	;
-		ModeInfo = ModeInfo0
+		true
 	).
 
-:- pred unique_modes__check_goal_2(hlds_goal_expr, hlds_goal_info,
-		hlds_goal_expr, mode_info, mode_info).
-:- mode unique_modes__check_goal_2(in, in, out, mode_info_di, mode_info_uo)
-		is det.
-
-unique_modes__check_goal_2(conj(List0), _GoalInfo0, conj(List)) -->
-	mode_checkpoint(enter, "conj"),
-	( { List0 = [] } ->	% for efficiency, optimize common case
-		{ List = [] }
-	;
-		mode_info_add_goals_live_vars(List0),
-		unique_modes__check_conj(List0, List)
-	),
-	mode_checkpoint(exit, "conj").
-
-unique_modes__check_goal_2(par_conj(List0), GoalInfo0,
-		par_conj(List)) -->
-	mode_checkpoint(enter, "par_conj"),
-	{ goal_info_get_nonlocals(GoalInfo0, NonLocals) },
-	mode_info_add_live_vars(NonLocals),
+:- pred unique_modes__check_goal_2(hlds_goal_expr::in, hlds_goal_info::in,
+	hlds_goal_expr::out, mode_info::in, mode_info::out,
+	io::di, io::uo) is det.
+
+unique_modes__check_goal_2(conj(List0), _GoalInfo0, conj(List), !ModeInfo,
+		!IO) :-
+	mode_checkpoint(enter, "conj", !ModeInfo, !IO),
+	( List0 = [] ->	% for efficiency, optimize common case
+		List = []
+	;
+		mode_info_add_goals_live_vars(List0, !ModeInfo),
+		unique_modes__check_conj(List0, List, !ModeInfo, !IO)
+	),
+	mode_checkpoint(exit, "conj", !ModeInfo, !IO).
+
+unique_modes__check_goal_2(par_conj(List0), GoalInfo0, par_conj(List),
+		!ModeInfo, !IO) :-
+	mode_checkpoint(enter, "par_conj", !ModeInfo, !IO),
+	goal_info_get_nonlocals(GoalInfo0, NonLocals),
+	mode_info_add_live_vars(NonLocals, !ModeInfo),
 		% Build a multiset of the nonlocals of the conjuncts
 		% so that we can figure out which variables must be
 		% made shared at the start of the parallel conjunction.
-	{ make_par_conj_nonlocal_multiset(List0, NonLocalsBag) },
-	unique_modes__check_par_conj(List0, NonLocalsBag, List, InstMapList),
-	instmap__unify(NonLocals, InstMapList),
-	mode_info_remove_live_vars(NonLocals),
-	mode_checkpoint(exit, "par_conj").
-
-unique_modes__check_goal_2(disj(List0), GoalInfo0, disj(List)) -->
-	mode_checkpoint(enter, "disj"),
-	( { List0 = [] } ->
-		{ List = [] },
-		{ instmap__init_unreachable(InstMap) },
-		mode_info_set_instmap(InstMap)
+	make_par_conj_nonlocal_multiset(List0, NonLocalsBag),
+	unique_modes__check_par_conj(List0, NonLocalsBag, List, InstMapList,
+		!ModeInfo, !IO),
+	instmap__unify(NonLocals, InstMapList, !ModeInfo),
+	mode_info_remove_live_vars(NonLocals, !ModeInfo),
+	mode_checkpoint(exit, "par_conj", !ModeInfo, !IO).
+
+unique_modes__check_goal_2(disj(List0), GoalInfo0, disj(List), !ModeInfo,
+		!IO) :-
+	mode_checkpoint(enter, "disj", !ModeInfo, !IO),
+	( List0 = [] ->
+		List = [],
+		instmap__init_unreachable(InstMap),
+		mode_info_set_instmap(InstMap, !ModeInfo)
 	;
 		%
 		% If the disjunction creates a choice point (i.e. is model_non),
@@ -314,15 +311,15 @@
 		% disjuncts.  But we handle that seperately for each
 		% disjunct, in unique_modes__check_disj.
 		%
-		{ goal_info_get_nonlocals(GoalInfo0, NonLocals) },
-		{ goal_info_get_determinism(GoalInfo0, Determinism) },
+		goal_info_get_nonlocals(GoalInfo0, NonLocals),
+		goal_info_get_determinism(GoalInfo0, Determinism),
 		% does this disjunction create a choice point?
-		( { determinism_components(Determinism, _, at_most_many) } ->
-			mode_info_add_live_vars(NonLocals),
-			make_all_nondet_live_vars_mostly_uniq,
-			mode_info_remove_live_vars(NonLocals)
+		( determinism_components(Determinism, _, at_most_many) ->
+			mode_info_add_live_vars(NonLocals, !ModeInfo),
+			make_all_nondet_live_vars_mostly_uniq(!ModeInfo),
+			mode_info_remove_live_vars(NonLocals, !ModeInfo)
 		;
-			[]
+			true
 		),
 
 		%
@@ -330,20 +327,20 @@
 		% merge the resulting instmaps.
 		%
 		unique_modes__check_disj(List0, Determinism, NonLocals,
-			List, InstMapList),
-		instmap__merge(NonLocals, InstMapList, disj)
+			List, InstMapList, !ModeInfo, !IO),
+		instmap__merge(NonLocals, InstMapList, disj, !ModeInfo)
 	),
-	mode_checkpoint(exit, "disj").
+	mode_checkpoint(exit, "disj", !ModeInfo, !IO).
 
-unique_modes__check_goal_2(if_then_else(Vs, Cond0, Then0, Else0),
-		GoalInfo0, Goal) -->
-	mode_checkpoint(enter, "if-then-else"),
-	{ goal_info_get_nonlocals(GoalInfo0, NonLocals) },
-	{ goal_get_nonlocals(Cond0, Cond_Vars) },
-	{ goal_get_nonlocals(Then0, Then_Vars) },
-	{ goal_get_nonlocals(Else0, Else_Vars) },
-	mode_info_dcg_get_instmap(InstMap0),
-	mode_info_lock_vars(if_then_else, NonLocals),
+unique_modes__check_goal_2(if_then_else(Vars, Cond0, Then0, Else0), GoalInfo0,
+		Goal, !ModeInfo, !IO) :-
+	mode_checkpoint(enter, "if-then-else", !ModeInfo, !IO),
+	goal_info_get_nonlocals(GoalInfo0, NonLocals),
+	goal_get_nonlocals(Cond0, Cond_Vars),
+	goal_get_nonlocals(Then0, Then_Vars),
+	goal_get_nonlocals(Else0, Else_Vars),
+	mode_info_get_instmap(!.ModeInfo, InstMap0),
+	mode_info_lock_vars(if_then_else, NonLocals, !ModeInfo),
 
 	%
 	% At this point, we should set the inst of any `unique'
@@ -372,43 +369,44 @@
 	%		use(Var)
 	%	).
 	%
-	mode_info_add_live_vars(Else_Vars),
-	=(ModeInfo),
-	{ set__to_sorted_list(Cond_Vars, Cond_Vars_List) },
-	{ select_live_vars(Cond_Vars_List, ModeInfo, Cond_Live_Vars) },
-	{ Cond0 = _ - Cond0_GoalInfo },
-	{ goal_info_get_instmap_delta(Cond0_GoalInfo, Cond0_DeltaInstMap) },
-	{ select_changed_inst_vars(Cond_Live_Vars, Cond0_DeltaInstMap,
-		ModeInfo, ChangedVars) },
-	make_var_list_mostly_uniq(ChangedVars),
-	mode_info_remove_live_vars(Else_Vars),
-
-	mode_info_add_live_vars(Then_Vars),
-	unique_modes__check_goal(Cond0, Cond),
-	mode_info_remove_live_vars(Then_Vars),
-	mode_info_unlock_vars(if_then_else, NonLocals),
-	mode_info_dcg_get_instmap(InstMapCond),
-	( { instmap__is_reachable(InstMapCond) } ->
-		unique_modes__check_goal(Then0, Then),
-		mode_info_dcg_get_instmap(InstMapThen)
+	mode_info_add_live_vars(Else_Vars, !ModeInfo),
+	set__to_sorted_list(Cond_Vars, Cond_Vars_List),
+	select_live_vars(Cond_Vars_List, !.ModeInfo, Cond_Live_Vars),
+	Cond0 = _ - Cond0_GoalInfo,
+	goal_info_get_instmap_delta(Cond0_GoalInfo, Cond0_DeltaInstMap),
+	select_changed_inst_vars(Cond_Live_Vars, Cond0_DeltaInstMap,
+		!.ModeInfo, ChangedVars),
+	make_var_list_mostly_uniq(ChangedVars, !ModeInfo),
+	mode_info_remove_live_vars(Else_Vars, !ModeInfo),
+
+	mode_info_add_live_vars(Then_Vars, !ModeInfo),
+	unique_modes__check_goal(Cond0, Cond, !ModeInfo, !IO),
+	mode_info_remove_live_vars(Then_Vars, !ModeInfo),
+	mode_info_unlock_vars(if_then_else, NonLocals, !ModeInfo),
+	mode_info_get_instmap(!.ModeInfo, InstMapCond),
+	( instmap__is_reachable(InstMapCond) ->
+		unique_modes__check_goal(Then0, Then, !ModeInfo, !IO),
+		mode_info_get_instmap(!.ModeInfo, InstMapThen)
 	;
 		% We should not mode-analyse the goal, since it is unreachable.
 		% Instead we optimize the goal away, so that later passes
 		% won't complain about it not having unique mode information.
-		{ true_goal(Then) },
-		{ InstMapThen = InstMapCond }
+		true_goal(Then),
+		InstMapThen = InstMapCond
 	),
-	mode_info_set_instmap(InstMap0),
-	unique_modes__check_goal(Else0, Else),
-	mode_info_dcg_get_instmap(InstMapElse),
-	mode_info_set_instmap(InstMap0),
-	instmap__merge(NonLocals, [InstMapThen, InstMapElse], if_then_else),
-	{ Goal = if_then_else(Vs, Cond, Then, Else) },
-	mode_checkpoint(exit, "if-then-else").
-
-unique_modes__check_goal_2(not(A0), GoalInfo0, not(A)) -->
-	mode_checkpoint(enter, "not"),
-	mode_info_dcg_get_instmap(InstMap0),
+	mode_info_set_instmap(InstMap0, !ModeInfo),
+	unique_modes__check_goal(Else0, Else, !ModeInfo, !IO),
+	mode_info_get_instmap(!.ModeInfo, InstMapElse),
+	mode_info_set_instmap(InstMap0, !ModeInfo),
+	instmap__merge(NonLocals, [InstMapThen, InstMapElse], if_then_else,
+		!ModeInfo),
+	Goal = if_then_else(Vars, Cond, Then, Else),
+	mode_checkpoint(exit, "if-then-else", !ModeInfo, !IO).
+
+unique_modes__check_goal_2(not(SubGoal0), GoalInfo0, not(SubGoal),
+		!ModeInfo, !IO) :-
+	mode_checkpoint(enter, "not", !ModeInfo, !IO),
+	mode_info_get_instmap(!.ModeInfo, InstMap0),
 	%
 	% We need to mark all the variables which are live
 	% after the negation as nondet-live for the negated
@@ -416,48 +414,45 @@
 	% negation will succeed, and so these variables
 	% can be accessed again after backtracking.
 	%
-	{ goal_info_get_nonlocals(GoalInfo0, NonLocals) },
-	{ set__to_sorted_list(NonLocals, NonLocalsList) },
-	=(ModeInfo0),
-	{ select_live_vars(NonLocalsList, ModeInfo0, LiveNonLocals) },
-	make_var_list_mostly_uniq(LiveNonLocals),
+	goal_info_get_nonlocals(GoalInfo0, NonLocals),
+	set__to_sorted_list(NonLocals, NonLocalsList),
+	select_live_vars(NonLocalsList, !.ModeInfo, LiveNonLocals),
+	make_var_list_mostly_uniq(LiveNonLocals, !ModeInfo),
 	%
 	% But nothing is forward-live for the negated goal, since
 	% if the goal succeeds then execution will immediately backtrack.
 	% So we need to set the live variables set to empty here.
 	%
-	=(ModeInfo),
-	{ mode_info_get_live_vars(ModeInfo, LiveVars0) },
-	mode_info_set_live_vars([]),
+	mode_info_get_live_vars(!.ModeInfo, LiveVars0),
+	mode_info_set_live_vars([], !ModeInfo),
 	%
 	% We need to lock the non-local variables, to ensure
 	% that the negation does not bind them.
 	%
-	mode_info_lock_vars(negation, NonLocals),
-	unique_modes__check_goal(A0, A),
-	mode_info_unlock_vars(negation, NonLocals),
-	mode_info_set_live_vars(LiveVars0),
-	mode_info_set_instmap(InstMap0),
-	mode_checkpoint(exit, "not").
-
-unique_modes__check_goal_2(some(Vs, CanRemove, G0), _,
-		some(Vs, CanRemove, G)) -->
-	mode_checkpoint(enter, "some"),
-	unique_modes__check_goal(G0, G),
-	mode_checkpoint(exit, "some").
+	mode_info_lock_vars(negation, NonLocals, !ModeInfo),
+	unique_modes__check_goal(SubGoal0, SubGoal, !ModeInfo, !IO),
+	mode_info_unlock_vars(negation, NonLocals, !ModeInfo),
+	mode_info_set_live_vars(LiveVars0, !ModeInfo),
+	mode_info_set_instmap(InstMap0, !ModeInfo),
+	mode_checkpoint(exit, "not", !ModeInfo, !IO).
+
+unique_modes__check_goal_2(some(Vars, CanRemove, SubGoal0), _,
+		some(Vars, CanRemove, SubGoal), !ModeInfo, !IO) :-
+	mode_checkpoint(enter, "some", !ModeInfo, !IO),
+	unique_modes__check_goal(SubGoal0, SubGoal, !ModeInfo, !IO),
+	mode_checkpoint(exit, "some", !ModeInfo, !IO).
 
 unique_modes__check_goal_2(generic_call(GenericCall, Args, Modes, Det),
-		_GoalInfo0, Goal) -->
-	mode_checkpoint(enter, "generic_call"),
-	{ hlds_goal__generic_call_id(GenericCall, CallId) },
-	mode_info_set_call_context(call(CallId)),
-	{ determinism_components(Det, _, at_most_zero) ->
+		_GoalInfo0, Goal, !ModeInfo, !IO) :-
+	mode_checkpoint(enter, "generic_call", !ModeInfo, !IO),
+	hlds_goal__generic_call_id(GenericCall, CallId),
+	mode_info_set_call_context(call(CallId), !ModeInfo),
+	( determinism_components(Det, _, at_most_zero) ->
 		NeverSucceeds = yes
 	;
 		NeverSucceeds = no
-	},
-
-	{
+	),
+	(
 		GenericCall = higher_order(_, _, _, _),
 		ArgOffset = 1
 	;
@@ -473,92 +468,83 @@
 	;
 		GenericCall = aditi_builtin(_, _),
 		ArgOffset = 0
-	},
-
-	unique_modes__check_call_modes(Args, Modes, ArgOffset,
-		Det, NeverSucceeds),
-	{ Goal = generic_call(GenericCall, Args, Modes, Det) },
-	mode_info_unset_call_context,
-	mode_checkpoint(exit, "generic_call").
+	),
+	unique_modes__check_call_modes(Args, Modes, ArgOffset, Det,
+		NeverSucceeds, !ModeInfo),
+	Goal = generic_call(GenericCall, Args, Modes, Det),
+	mode_info_unset_call_context(!ModeInfo),
+	mode_checkpoint(exit, "generic_call", !ModeInfo, !IO).
 
 unique_modes__check_goal_2(call(PredId, ProcId0, Args, Builtin, CallContext,
-		PredName), _GoalInfo0, Goal) -->
-	{ prog_out__sym_name_to_string(PredName, PredNameString) },
-	{ string__append("call ", PredNameString, CallString) },
-	mode_checkpoint(enter, CallString),
-
-	=(ModeInfo),
-	{ mode_info_get_call_id(ModeInfo, PredId, CallId) },
-	mode_info_set_call_context(call(call(CallId))),
-
-	unique_modes__check_call(PredId, ProcId0, Args, ProcId),
-	{ Goal = call(PredId, ProcId, Args, Builtin, CallContext, PredName) },
-	mode_info_unset_call_context,
-	mode_checkpoint(exit, "call").
-
-unique_modes__check_goal_2(unify(A0, B0, _, UnifyInfo0, UnifyContext),
-		GoalInfo0, Goal) -->
-	mode_checkpoint(enter, "unify"),
-	mode_info_set_call_context(unify(UnifyContext)),
-
-	modecheck_unification(A0, B0, UnifyInfo0, UnifyContext, GoalInfo0,
-		Goal),
-
-	mode_info_unset_call_context,
-	mode_checkpoint(exit, "unify").
+		PredName), _GoalInfo0, Goal, !ModeInfo, !IO) :-
+	prog_out__sym_name_to_string(PredName, PredNameString),
+	string__append("call ", PredNameString, CallString),
+	mode_checkpoint(enter, CallString, !ModeInfo, !IO),
+	mode_info_get_call_id(!.ModeInfo, PredId, CallId),
+	mode_info_set_call_context(call(call(CallId)), !ModeInfo),
+	unique_modes__check_call(PredId, ProcId0, Args, ProcId, !ModeInfo),
+	Goal = call(PredId, ProcId, Args, Builtin, CallContext, PredName),
+	mode_info_unset_call_context(!ModeInfo),
+	mode_checkpoint(exit, "call", !ModeInfo, !IO).
+
+unique_modes__check_goal_2(unify(LHS0, RHS0, _, UnifyInfo0, UnifyContext),
+		GoalInfo0, Goal, !ModeInfo, !IO) :-
+	mode_checkpoint(enter, "unify", !ModeInfo, !IO),
+	mode_info_set_call_context(unify(UnifyContext), !ModeInfo),
+	modecheck_unification(LHS0, RHS0, UnifyInfo0, UnifyContext, GoalInfo0,
+		Goal, !ModeInfo, !IO),
+	mode_info_unset_call_context(!ModeInfo),
+	mode_checkpoint(exit, "unify", !ModeInfo, !IO).
 
 unique_modes__check_goal_2(switch(Var, CanFail, Cases0), GoalInfo0,
-		switch(Var, CanFail, Cases)) -->
-	mode_checkpoint(enter, "switch"),
-	( { Cases0 = [] } ->
-		{ Cases = [] },
-		{ instmap__init_unreachable(InstMap) },
-		mode_info_set_instmap(InstMap)
-	;
-		{ goal_info_get_nonlocals(GoalInfo0, NonLocals) },
-		unique_modes__check_case_list(Cases0, Var, Cases, InstMapList),
-		instmap__merge(NonLocals, InstMapList, disj)
+		switch(Var, CanFail, Cases), !ModeInfo, !IO) :-
+	mode_checkpoint(enter, "switch", !ModeInfo, !IO),
+	( Cases0 = [] ->
+		Cases = [],
+		instmap__init_unreachable(InstMap),
+		mode_info_set_instmap(InstMap, !ModeInfo)
+	;
+		goal_info_get_nonlocals(GoalInfo0, NonLocals),
+		unique_modes__check_case_list(Cases0, Var, Cases, InstMapList,
+			!ModeInfo, !IO),
+		instmap__merge(NonLocals, InstMapList, disj, !ModeInfo)
 	),
-	mode_checkpoint(exit, "switch").
+	mode_checkpoint(exit, "switch", !ModeInfo, !IO).
 
 	% to modecheck a pragma_c_code, we just modecheck the proc for 
 	% which it is the goal.
-unique_modes__check_goal_2(foreign_proc(Attributes,
-		PredId, ProcId0, Args, ArgNameMap, OrigArgTypes, PragmaCode),
-		_GoalInfo, Goal) -->
-	mode_checkpoint(enter, "foreign_proc"),
-	=(ModeInfo),
-	{ mode_info_get_call_id(ModeInfo, PredId, CallId) },
-	mode_info_set_call_context(call(call(CallId))),
-	unique_modes__check_call(PredId, ProcId0, Args, ProcId),
-	{ Goal = foreign_proc(Attributes, PredId, ProcId, Args,
-			ArgNameMap, OrigArgTypes, PragmaCode) },
-	mode_info_unset_call_context,
-	mode_checkpoint(exit, "foreign_proc").
+unique_modes__check_goal_2(foreign_proc(Attributes, PredId, ProcId0,
+		Args, ArgNameMap, OrigArgTypes, PragmaCode), _GoalInfo, Goal,
+		!ModeInfo, !IO) :-
+	mode_checkpoint(enter, "foreign_proc", !ModeInfo, !IO),
+	mode_info_get_call_id(!.ModeInfo, PredId, CallId),
+	mode_info_set_call_context(call(call(CallId)), !ModeInfo),
+	unique_modes__check_call(PredId, ProcId0, Args, ProcId, !ModeInfo),
+	Goal = foreign_proc(Attributes, PredId, ProcId, Args, ArgNameMap,
+		OrigArgTypes, PragmaCode),
+	mode_info_unset_call_context(!ModeInfo),
+	mode_checkpoint(exit, "foreign_proc", !ModeInfo, !IO).
 
-unique_modes__check_goal_2(shorthand(_), _, _) -->
+unique_modes__check_goal_2(shorthand(_), _, _, !ModeInfo, !IO) :-
 	% these should have been expanded out by now
-	{ error("unique_modes__check_goal_2: unexpected shorthand") }.
+	error("unique_modes__check_goal_2: unexpected shorthand").
 
-:- pred unique_modes__check_call(pred_id, proc_id, list(prog_var), proc_id, 
-			mode_info, mode_info).
-:- mode unique_modes__check_call(in, in, in, out,
-			mode_info_di, mode_info_uo) is det.
+:- pred unique_modes__check_call(pred_id::in, proc_id::in, list(prog_var)::in,
+	proc_id::out, mode_info::in, mode_info::out) is det.
 
-unique_modes__check_call(PredId, ProcId0, ArgVars, ProcId,
-		ModeInfo0, ModeInfo) :-
+unique_modes__check_call(PredId, ProcId0, ArgVars, ProcId, !ModeInfo) :-
 	%
 	% set the error list to empty for use below
 	% (saving the old error list and instmap in variables)
 	%
-	mode_info_get_errors(ModeInfo0, OldErrors),
-	mode_info_get_instmap(ModeInfo0, InstMap0),
-	mode_info_set_errors([], ModeInfo0, ModeInfo1),
+	mode_info_get_errors(!.ModeInfo, OldErrors),
+	mode_info_get_instmap(!.ModeInfo, InstMap0),
+	mode_info_set_errors([], !ModeInfo),
 
 	%
 	% first off, try using the existing mode
 	%
-	mode_info_get_module_info(ModeInfo0, ModuleInfo),
+	mode_info_get_module_info(!.ModeInfo, ModuleInfo),
 	module_info_pred_proc_info(ModuleInfo, PredId, ProcId0,
 			PredInfo, ProcInfo),
 	compute_arg_offset(PredInfo, ArgOffset),
@@ -566,38 +552,36 @@
 	proc_info_interface_determinism(ProcInfo, InterfaceDeterminism),
 	proc_info_never_succeeds(ProcInfo, NeverSucceeds),
 	unique_modes__check_call_modes(ArgVars, ProcArgModes0, ArgOffset,
-			InterfaceDeterminism, NeverSucceeds,
-			ModeInfo1, ModeInfo2),
+		InterfaceDeterminism, NeverSucceeds, !ModeInfo),
 	( ProcInfo ^ mode_errors = [_|_] ->
 		% mode error in callee for this mode
 		WaitingVars = set__list_to_set(ArgVars),
-		mode_info_get_instmap(ModeInfo2, InstMap),
+		mode_info_get_instmap(!.ModeInfo, InstMap),
 		instmap__lookup_vars(ArgVars, InstMap, ArgInsts),
 		mode_info_error(WaitingVars,
 			mode_error_in_callee(ArgVars, ArgInsts,
 				PredId, ProcId0,
 				ProcInfo ^ mode_errors),
-			ModeInfo2, ModeInfo3)
+			!ModeInfo)
 	;
-		ModeInfo3 = ModeInfo2
+		true
 	),
 
 	%
 	% see whether or not that worked
 	% (and restore the old error list)
 	%
-	mode_info_get_errors(ModeInfo3, Errors),
-	mode_info_set_errors(OldErrors, ModeInfo3, ModeInfo4),
-	mode_info_get_may_change_called_proc(ModeInfo4, MayChangeCalledProc),
+	mode_info_get_errors(!.ModeInfo, Errors),
+	mode_info_set_errors(OldErrors, !ModeInfo),
+	mode_info_get_may_change_called_proc(!.ModeInfo, MayChangeCalledProc),
 	( Errors = [] ->
-		ProcId = ProcId0,
-		ModeInfo = ModeInfo4
+		ProcId = ProcId0
 	; MayChangeCalledProc = may_not_change_called_proc ->
 		% We're not allowed to try a different procedure
 		% here, so just return all the errors.
 		ProcId = ProcId0,
 		list__append(OldErrors, Errors, AllErrors),
-		mode_info_set_errors(AllErrors, ModeInfo4, ModeInfo)
+		mode_info_set_errors(AllErrors, !ModeInfo)
 	;
 		%
 		% If it didn't work, restore the original instmap,
@@ -613,10 +597,10 @@
 		% as a result of unique mode analysis.  That is OK,
 		% because uniqueness should not affect determinism.
 		%
-		mode_info_set_instmap(InstMap0, ModeInfo4, ModeInfo5),
+		mode_info_set_instmap(InstMap0, !ModeInfo),
 		proc_info_inferred_determinism(ProcInfo, Determinism),
 		modecheck_call_pred(PredId, ProcId0, ArgVars, yes(Determinism),
-			ProcId, NewArgVars, ExtraGoals, ModeInfo5, ModeInfo),
+			ProcId, NewArgVars, ExtraGoals, !ModeInfo),
 		
 		( NewArgVars = ArgVars, ExtraGoals = no_extra_goals ->
 			true
@@ -635,24 +619,22 @@
 	% argument if the variable is nondet-live and the required initial
 	% inst was unique.
 
-:- pred unique_modes__check_call_modes(list(prog_var), list(mode), int,
-		determinism, bool, mode_info, mode_info).
-:- mode unique_modes__check_call_modes(in, in, in, in, in,
-			mode_info_di, mode_info_uo) is det.
+:- pred unique_modes__check_call_modes(list(prog_var)::in, list(mode)::in,
+	int::in, determinism::in, bool::in, mode_info::in, mode_info::out)
+	is det.
 
 unique_modes__check_call_modes(ArgVars, ProcArgModes, ArgOffset,
-		Determinism, NeverSucceeds, ModeInfo0, ModeInfo) :-
-	mode_info_get_module_info(ModeInfo0, ModuleInfo),
+		Determinism, NeverSucceeds, !ModeInfo) :-
+	mode_info_get_module_info(!.ModeInfo, ModuleInfo),
 	mode_list_get_initial_insts(ProcArgModes, ModuleInfo,
 			InitialInsts),
 	NeedExactMatch = no,
 	modecheck_var_has_inst_list(ArgVars, InitialInsts,
-			NeedExactMatch, ArgOffset, InstVarSub,
-			ModeInfo0, ModeInfo1),
+		NeedExactMatch, ArgOffset, InstVarSub, !ModeInfo),
 	mode_list_get_final_insts(ProcArgModes, ModuleInfo, FinalInsts0),
 	inst_list_apply_substitution(FinalInsts0, InstVarSub, FinalInsts),
 	modecheck_set_var_inst_list(ArgVars, InitialInsts, FinalInsts,
-		ArgOffset, NewArgVars, ExtraGoals, ModeInfo1, ModeInfo2),
+		ArgOffset, NewArgVars, ExtraGoals, !ModeInfo),
 	( NewArgVars = ArgVars, ExtraGoals = no_extra_goals ->
 		true
 	;	
@@ -662,7 +644,7 @@
 	),
 	( NeverSucceeds = yes ->
 		instmap__init_unreachable(InstMap),
-		mode_info_set_instmap(InstMap, ModeInfo2, ModeInfo)
+		mode_info_set_instmap(InstMap, !ModeInfo)
 	;
 		%
 		% Check whether we are at a call to a nondet predicate.
@@ -670,37 +652,35 @@
 		% whose inst is `unique' as instead being only `mostly_unique'.
 		%
 		( determinism_components(Determinism, _, at_most_many) ->
-			make_all_nondet_live_vars_mostly_uniq(ModeInfo2,
-				ModeInfo)
+			make_all_nondet_live_vars_mostly_uniq(!ModeInfo)
 		;
-			ModeInfo = ModeInfo2
+			true
 		)
 	).
 
 %-----------------------------------------------------------------------------%
 
-:- pred unique_modes__check_conj(list(hlds_goal), list(hlds_goal),
-		mode_info, mode_info).
-:- mode unique_modes__check_conj(in, out, mode_info_di, mode_info_uo) is det.
+:- pred unique_modes__check_conj(list(hlds_goal)::in, list(hlds_goal)::out,
+	mode_info::in, mode_info::out, io::di, io::uo) is det.
 
 	% Just process each conjunct in turn.
 	% Note that we don't do any reordering of conjuncts here.
 
-unique_modes__check_conj([], []) --> [].
-unique_modes__check_conj([Goal0 | Goals0], [Goal | Goals]) -->
-	{ goal_get_nonlocals(Goal0, NonLocals) },
-	mode_info_remove_live_vars(NonLocals),
-	unique_modes__check_goal(Goal0, Goal),
-	mode_info_dcg_get_instmap(InstMap),
-	( { instmap__is_unreachable(InstMap) } ->
+unique_modes__check_conj([], [], !ModeInfo, !IO).
+unique_modes__check_conj([Goal0 | Goals0], [Goal | Goals], !ModeInfo, !IO) :-
+	goal_get_nonlocals(Goal0, NonLocals),
+	mode_info_remove_live_vars(NonLocals, !ModeInfo),
+	unique_modes__check_goal(Goal0, Goal, !ModeInfo, !IO),
+	mode_info_get_instmap(!.ModeInfo, InstMap),
+	( instmap__is_unreachable(InstMap) ->
 		% We should not mode-analyse the remaining goals, since they
 		% are unreachable.  Instead we optimize them away, so that
 		% later passes won't complain about them not having
 		% unique mode information.
-		mode_info_remove_goals_live_vars(Goals0),
-		{ Goals  = [] }
+		mode_info_remove_goals_live_vars(Goals0, !ModeInfo),
+		Goals  = []
 	;
-		unique_modes__check_conj(Goals0, Goals)
+		unique_modes__check_conj(Goals0, Goals, !ModeInfo, !IO)
 	).
 
 %-----------------------------------------------------------------------------%
@@ -728,55 +708,55 @@
 	% because otherwise it would be possible to make them become clobbered
 	% which would introduce an implicit dependency between the conjuncts
 	% which we do not allow.
-:- pred unique_modes__check_par_conj(list(hlds_goal), bag(prog_var),
-		list(hlds_goal), list(pair(instmap, set(prog_var))),
-		mode_info, mode_info).
-:- mode unique_modes__check_par_conj(in, in, out, out,
-		mode_info_di, mode_info_uo) is det.
-
-unique_modes__check_par_conj(Goals0, NonLocalVarsBag, Goals, Instmaps) -->
-	unique_modes__check_par_conj_0(NonLocalVarsBag),
-	unique_modes__check_par_conj_1(Goals0, Goals, Instmaps).
+:- pred unique_modes__check_par_conj(list(hlds_goal)::in, bag(prog_var)::in,
+	list(hlds_goal)::out, list(pair(instmap, set(prog_var)))::out,
+	mode_info::in, mode_info::out, io::di, io::uo) is det.
+
+unique_modes__check_par_conj(Goals0, NonLocalVarsBag, Goals, Instmaps,
+		!ModeInfo, !IO) :-
+	unique_modes__check_par_conj_0(NonLocalVarsBag, !ModeInfo),
+	unique_modes__check_par_conj_1(Goals0, Goals, Instmaps, !ModeInfo,
+		!IO).
 
 		% Figure out which variables occur in more than one
 		% conjunct and make them shared.
-:- pred unique_modes__check_par_conj_0(bag(prog_var), mode_info, mode_info).
-:- mode unique_modes__check_par_conj_0(in, mode_info_di, mode_info_uo) is det.
+:- pred unique_modes__check_par_conj_0(bag(prog_var)::in,
+	mode_info::in, mode_info::out) is det.
 
-unique_modes__check_par_conj_0(NonLocalVarsBag, ModeInfo0, ModeInfo) :-
+unique_modes__check_par_conj_0(NonLocalVarsBag, !ModeInfo) :-
 	bag__to_assoc_list(NonLocalVarsBag, NonLocalVarsList),
 	list__filter_map((pred(Pair::in, Var::out) is semidet :-
 		Pair = Var - Multiplicity,
 		Multiplicity > 1
 	), NonLocalVarsList, SharedList),
-	mode_info_dcg_get_instmap(InstMap0, ModeInfo0, ModeInfo1),
+	mode_info_get_instmap(!.ModeInfo, InstMap0),
 	instmap__lookup_vars(SharedList, InstMap0, VarInsts),
-	mode_info_get_module_info(ModeInfo1, ModuleInfo0),
+	mode_info_get_module_info(!.ModeInfo, ModuleInfo0),
 	make_shared_inst_list(VarInsts, ModuleInfo0,
 		SharedVarInsts, ModuleInfo1),
-	mode_info_set_module_info(ModeInfo1, ModuleInfo1, ModeInfo2),
+	mode_info_set_module_info(ModuleInfo1, !ModeInfo),
 	instmap__set_vars(InstMap0, SharedList, SharedVarInsts, InstMap1),
-	mode_info_set_instmap(InstMap1, ModeInfo2, ModeInfo).
+	mode_info_set_instmap(InstMap1, !ModeInfo).
 
 	% Just process each conjunct in turn.
 	% Because we have already done modechecking, we know that
 	% there are no attempts to bind a variable in multiple
 	% parallel conjuncts, so we don't need to lock/unlock variables.
 
-:- pred unique_modes__check_par_conj_1(list(hlds_goal), list(hlds_goal),
-		list(pair(instmap, set(prog_var))), mode_info, mode_info).
-:- mode unique_modes__check_par_conj_1(in, out, out,
-		mode_info_di, mode_info_uo) is det.
+:- pred unique_modes__check_par_conj_1(list(hlds_goal)::in,
+	list(hlds_goal)::out, list(pair(instmap, set(prog_var)))::out,
+	mode_info::in, mode_info::out, io::di, io::uo) is det.
 
-unique_modes__check_par_conj_1([], [], []) --> [].
+unique_modes__check_par_conj_1([], [], [], !ModeInfo, !IO).
 unique_modes__check_par_conj_1([Goal0 | Goals0], [Goal | Goals],
-		[InstMap - NonLocals|InstMaps]) -->
-	{ goal_get_nonlocals(Goal0, NonLocals) },
-	mode_info_dcg_get_instmap(InstMap0),
-	unique_modes__check_goal(Goal0, Goal),
-	mode_info_dcg_get_instmap(InstMap),
-	mode_info_set_instmap(InstMap0),
-	unique_modes__check_par_conj_1(Goals0, Goals, InstMaps).
+		[InstMap - NonLocals|InstMaps], !ModeInfo, !IO) :-
+	goal_get_nonlocals(Goal0, NonLocals),
+	mode_info_get_instmap(!.ModeInfo, InstMap0),
+	unique_modes__check_goal(Goal0, Goal, !ModeInfo, !IO),
+	mode_info_get_instmap(!.ModeInfo, InstMap),
+	mode_info_set_instmap(InstMap0, !ModeInfo),
+	unique_modes__check_par_conj_1(Goals0, Goals, InstMaps,
+		!ModeInfo, !IO).
 
 %-----------------------------------------------------------------------------%
 
@@ -784,22 +764,21 @@
 	% the original instmap before processing the next one.
 	% Collect up a list of the resulting instmaps.
 
-:- pred unique_modes__check_disj(list(hlds_goal), determinism, set(prog_var),
-		list(hlds_goal), list(instmap), mode_info, mode_info).
-:- mode unique_modes__check_disj(in, in, in, out, out,
-		mode_info_di, mode_info_uo) is det.
+:- pred unique_modes__check_disj(list(hlds_goal)::in, determinism::in,
+	set(prog_var)::in, list(hlds_goal)::out, list(instmap)::out,
+	mode_info::in, mode_info::out, io::di, io::uo) is det.
 
-unique_modes__check_disj([], _, _, [], []) --> [].
+unique_modes__check_disj([], _, _, [], [], !ModeInfo, !IO).
 unique_modes__check_disj([Goal0 | Goals0], DisjDetism, DisjNonLocals,
-		[Goal | Goals], [InstMap | InstMaps]) -->
-	mode_info_dcg_get_instmap(InstMap0),
+		[Goal | Goals], [InstMap | InstMaps], !ModeInfo, !IO) :-
+	mode_info_get_instmap(!.ModeInfo, InstMap0),
 	(
 		%
 		% If the disjunction was model_nondet, then we already marked
 		% all the non-locals as only being mostly-unique, so we
 		% don't need to do anything special here...
 		%
-		{ \+ determinism_components(DisjDetism, _, at_most_many) },
+		\+ determinism_components(DisjDetism, _, at_most_many),
 
 		%
 		% ... but for model_semi or model_det disjunctions, if the
@@ -807,56 +786,55 @@
 		% disjunct, so again in that case we need to mark all the
 		% non-locals as being only mostly-unique rather than unique.
 		%
-		{ Goal0 = _ - GoalInfo0 },
-		{ goal_info_get_determinism(GoalInfo0, Determinism) },
-		{ determinism_components(Determinism, CanFail, _) },
-		{ CanFail = can_fail }
+		Goal0 = _ - GoalInfo0,
+		goal_info_get_determinism(GoalInfo0, Determinism),
+		determinism_components(Determinism, CanFail, _),
+		CanFail = can_fail
 	->
-		mode_info_add_live_vars(DisjNonLocals),
-		make_all_nondet_live_vars_mostly_uniq,
-		mode_info_remove_live_vars(DisjNonLocals)
-	;
-		[]
-	),
-	unique_modes__check_goal(Goal0, Goal),
-	mode_info_dcg_get_instmap(InstMap),
-	mode_info_set_instmap(InstMap0),
+		mode_info_add_live_vars(DisjNonLocals, !ModeInfo),
+		make_all_nondet_live_vars_mostly_uniq(!ModeInfo),
+		mode_info_remove_live_vars(DisjNonLocals, !ModeInfo)
+	;
+		true
+	),
+	unique_modes__check_goal(Goal0, Goal, !ModeInfo, !IO),
+	mode_info_get_instmap(!.ModeInfo, InstMap),
+	mode_info_set_instmap(InstMap0, !ModeInfo),
 	unique_modes__check_disj(Goals0, DisjDetism, DisjNonLocals,
-		Goals, InstMaps).
+		Goals, InstMaps, !ModeInfo, !IO).
 
 %-----------------------------------------------------------------------------%
 
-:- pred unique_modes__check_case_list(list(case), prog_var, list(case),
-		list(instmap), mode_info, mode_info).
-:- mode unique_modes__check_case_list(in, in, out, out,
-		mode_info_di, mode_info_uo) is det.
-
-unique_modes__check_case_list([], _Var, [], []) --> [].
-unique_modes__check_case_list([Case0 | Cases0], Var,
-			[Case | Cases], [InstMap | InstMaps]) -->
-	{ Case0 = case(ConsId, Goal0) },
-	{ Case = case(ConsId, Goal) },
-	=(ModeInfo0),
-	{ mode_info_get_instmap(ModeInfo0, InstMap0) },
+:- pred unique_modes__check_case_list(list(case)::in, prog_var::in,
+	list(case)::out, list(instmap)::out, mode_info::in, mode_info::out,
+	io::di, io::uo) is det.
+
+unique_modes__check_case_list([], _Var, [], [], !ModeInfo, !IO).
+unique_modes__check_case_list([Case0 | Cases0], Var, [Case | Cases],
+		[InstMap | InstMaps], !ModeInfo, !IO) :-
+	Case0 = case(ConsId, Goal0),
+	Case = case(ConsId, Goal),
+	mode_info_get_instmap(!.ModeInfo, InstMap0),
 
 	% record the fact that Var was bound to ConsId in the
 	% instmap before processing this case
-	modecheck_functor_test(Var, ConsId),
+	modecheck_functor_test(Var, ConsId, !ModeInfo),
 
-	mode_info_dcg_get_instmap(InstMap1),
-	( { instmap__is_reachable(InstMap1) } ->
-		unique_modes__check_goal(Goal0, Goal1)
+	mode_info_get_instmap(!.ModeInfo, InstMap1),
+	( instmap__is_reachable(InstMap1) ->
+		unique_modes__check_goal(Goal0, Goal1, !ModeInfo, !IO)
 	;
 		% We should not mode-analyse the goal, since it is unreachable.
 		% Instead we optimize the goal away, so that later passes
 		% won't complain about it not having unique mode information.
-		{ true_goal(Goal1) }
+		true_goal(Goal1)
 	),
 
-	mode_info_dcg_get_instmap(InstMap),
-	{ fixup_switch_var(Var, InstMap0, InstMap, Goal1, Goal) },
+	mode_info_get_instmap(!.ModeInfo, InstMap),
+	fixup_switch_var(Var, InstMap0, InstMap, Goal1, Goal),
 
-	mode_info_set_instmap(InstMap0),
-	unique_modes__check_case_list(Cases0, Var, Cases, InstMaps).
+	mode_info_set_instmap(InstMap0, !ModeInfo),
+	unique_modes__check_case_list(Cases0, Var, Cases, InstMaps,
+		!ModeInfo, !IO).
 
 %-----------------------------------------------------------------------------%
cvs diff: Diffing compiler/notes
cvs diff: Diffing debian
cvs diff: Diffing deep_profiler
cvs diff: Diffing deep_profiler/notes
cvs diff: Diffing doc
cvs diff: Diffing extras
cvs diff: Diffing extras/aditi
cvs diff: Diffing extras/cgi
cvs diff: Diffing extras/complex_numbers
cvs diff: Diffing extras/complex_numbers/samples
cvs diff: Diffing extras/complex_numbers/tests
cvs diff: Diffing extras/concurrency
cvs diff: Diffing extras/curs
cvs diff: Diffing extras/curs/samples
cvs diff: Diffing extras/curses
cvs diff: Diffing extras/curses/sample
cvs diff: Diffing extras/dynamic_linking
cvs diff: Diffing extras/error
cvs diff: Diffing extras/graphics
cvs diff: Diffing extras/graphics/mercury_opengl
cvs diff: Diffing extras/graphics/mercury_tcltk
cvs diff: Diffing extras/graphics/samples
cvs diff: Diffing extras/graphics/samples/calc
cvs diff: Diffing extras/graphics/samples/maze
cvs diff: Diffing extras/graphics/samples/pent
cvs diff: Diffing extras/lazy_evaluation
cvs diff: Diffing extras/lex
cvs diff: Diffing extras/lex/samples
cvs diff: Diffing extras/lex/tests
cvs diff: Diffing extras/logged_output
cvs diff: Diffing extras/moose
cvs diff: Diffing extras/moose/samples
cvs diff: Diffing extras/morphine
cvs diff: Diffing extras/morphine/non-regression-tests
cvs diff: Diffing extras/morphine/scripts
cvs diff: Diffing extras/morphine/source
cvs diff: Diffing extras/odbc
cvs diff: Diffing extras/posix
cvs diff: Diffing extras/quickcheck
cvs diff: Diffing extras/quickcheck/tutes
cvs diff: Diffing extras/references
cvs diff: Diffing extras/references/samples
cvs diff: Diffing extras/references/tests
cvs diff: Diffing extras/stream
cvs diff: Diffing extras/trailed_update
cvs diff: Diffing extras/trailed_update/samples
cvs diff: Diffing extras/trailed_update/tests
cvs diff: Diffing extras/xml
cvs diff: Diffing extras/xml/samples
cvs diff: Diffing java
cvs diff: Diffing java/library
cvs diff: Diffing java/runtime
cvs diff: Diffing library
cvs diff: Diffing profiler
cvs diff: Diffing robdd
cvs diff: Diffing runtime
cvs diff: Diffing runtime/GETOPT
cvs diff: Diffing runtime/machdeps
cvs diff: Diffing samples
cvs diff: Diffing samples/c_interface
cvs diff: Diffing samples/c_interface/c_calls_mercury
cvs diff: Diffing samples/c_interface/cplusplus_calls_mercury
cvs diff: Diffing samples/c_interface/mercury_calls_c
cvs diff: Diffing samples/c_interface/mercury_calls_cplusplus
cvs diff: Diffing samples/c_interface/mercury_calls_fortran
cvs diff: Diffing samples/c_interface/simpler_c_calls_mercury
cvs diff: Diffing samples/c_interface/simpler_cplusplus_calls_mercury
cvs diff: Diffing samples/diff
cvs diff: Diffing samples/muz
cvs diff: Diffing samples/rot13
cvs diff: Diffing samples/solutions
cvs diff: Diffing samples/tests
cvs diff: Diffing samples/tests/c_interface
cvs diff: Diffing samples/tests/c_interface/c_calls_mercury
cvs diff: Diffing samples/tests/c_interface/cplusplus_calls_mercury
cvs diff: Diffing samples/tests/c_interface/mercury_calls_c
cvs diff: Diffing samples/tests/c_interface/mercury_calls_cplusplus
cvs diff: Diffing samples/tests/c_interface/mercury_calls_fortran
cvs diff: Diffing samples/tests/c_interface/simpler_c_calls_mercury
cvs diff: Diffing samples/tests/c_interface/simpler_cplusplus_calls_mercury
cvs diff: Diffing samples/tests/diff
cvs diff: Diffing samples/tests/muz
cvs diff: Diffing samples/tests/rot13
cvs diff: Diffing samples/tests/solutions
cvs diff: Diffing samples/tests/toplevel
cvs diff: Diffing scripts
cvs diff: Diffing tests
cvs diff: Diffing tests/benchmarks
cvs diff: Diffing tests/debugger
cvs diff: Diffing tests/debugger/declarative
cvs diff: Diffing tests/dppd
cvs diff: Diffing tests/general
cvs diff: Diffing tests/general/accumulator
cvs diff: Diffing tests/general/string_format
cvs diff: Diffing tests/general/structure_reuse
cvs diff: Diffing tests/grade_subdirs
cvs diff: Diffing tests/hard_coded
cvs diff: Diffing tests/hard_coded/exceptions
cvs diff: Diffing tests/hard_coded/purity
cvs diff: Diffing tests/hard_coded/sub-modules
cvs diff: Diffing tests/hard_coded/typeclasses
cvs diff: Diffing tests/invalid
cvs diff: Diffing tests/invalid/purity
cvs diff: Diffing tests/misc_tests
cvs diff: Diffing tests/mmc_make
cvs diff: Diffing tests/mmc_make/lib
cvs diff: Diffing tests/recompilation
cvs diff: Diffing tests/tabling
cvs diff: Diffing tests/term
cvs diff: Diffing tests/valid
cvs diff: Diffing tests/warnings
cvs diff: Diffing tools
cvs diff: Diffing trace
cvs diff: Diffing util
cvs diff: Diffing vim
cvs diff: Diffing vim/after
cvs diff: Diffing vim/ftplugin
cvs diff: Diffing vim/syntax
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list