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

Zoltan Somogyi zs at cs.mu.OZ.AU
Mon Oct 27 16:42:21 AEDT 2003


This diff makes code_info.m and many callers of its predicates easier to read
and to maintain, but contains no changes in algorithms whatsoever.

compiler/code_info.m:
	Bring this module into line with our current coding standards.
	Use predmode declarations, functions, and state variable syntax
	when appropriate.

	Reorder arguments of predicates where necessary for the use of state
	variable syntax, and where this improves readability.

	Where a predicate returned its input code_info unchanged, purely
	to allow the convenient use of DCG notation in the caller, delete the
	unnecessary output argument. This should make the caller somewhat more
	efficient, since it can avoid updating the stack slot holding the
	current code_info.

	Replace old-style lambdas with new-style lambdas or with partially
	applied named procedures.

compiler/*.m:
	Conform to the changes in code_info.m. This mostly means using the
	new argument orders of predicates exported by hlds_pred.m, and
	using state variable notation.

Zoltan.

cvs diff: Diffing .
Index: call_gen.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/call_gen.m,v
retrieving revision 1.156
diff -u -b -r1.156 call_gen.m
--- call_gen.m	26 May 2003 08:59:50 -0000	1.156
+++ call_gen.m	22 Oct 2003 08:19:16 -0000
@@ -76,28 +76,31 @@
 
 %---------------------------------------------------------------------------%
 
-call_gen__generate_call(CodeModel, PredId, ProcId, ArgVars, GoalInfo, Code) -->
+call_gen__generate_call(CodeModel, PredId, ProcId, ArgVars, GoalInfo, Code,
+		!CI) :-
 
 		% Find out which arguments are input and which are output.
-	code_info__get_pred_proc_arginfo(PredId, ProcId, ArgInfo),
-	{ assoc_list__from_corresponding_lists(ArgVars, ArgInfo, ArgsInfos) },
+	ArgInfo = code_info__get_pred_proc_arginfo(!.CI, PredId, ProcId),
+	assoc_list__from_corresponding_lists(ArgVars, ArgInfo, ArgsInfos),
 
 		% Save the necessary vars on the stack and move the input args
 		% to their registers.
-	code_info__setup_call(GoalInfo, ArgsInfos, LiveVals, SetupCode),
-	call_gen__kill_dead_input_vars(ArgsInfos, GoalInfo, NonLiveOutputs),
+	code_info__setup_call(GoalInfo, ArgsInfos, LiveVals, SetupCode, !CI),
+	call_gen__kill_dead_input_vars(ArgsInfos, GoalInfo, NonLiveOutputs,
+		!CI),
 
 		% Figure out what the call model is.
-	call_gen__prepare_for_call(CodeModel, CallModel, TraceCode),
+	call_gen__prepare_for_call(CodeModel, CallModel, TraceCode, !CI),
 
 		% Make the call.
-	code_info__get_module_info(ModuleInfo),
-	code_info__make_entry_label(ModuleInfo, PredId, ProcId, yes, Address),
-	code_info__get_next_label(ReturnLabel),
-	{ call_gen__call_comment(CodeModel, CallComment) },
-	{ goal_info_get_context(GoalInfo, Context) },
-	{ goal_info_get_goal_path(GoalInfo, GoalPath) },
-	{ CallCode = node([
+	code_info__get_module_info(!.CI, ModuleInfo),
+	Address = code_info__make_entry_label(!.CI, ModuleInfo,	
+		PredId, ProcId, yes),
+	code_info__get_next_label(ReturnLabel, !CI),
+	call_gen__call_comment(CodeModel, CallComment),
+	goal_info_get_context(GoalInfo, Context),
+	goal_info_get_goal_path(GoalInfo, GoalPath),
+	CallCode = node([
 		livevals(LiveVals)
 			- "",
 		call(Address, label(ReturnLabel), ReturnLiveLvalues, Context,
@@ -105,30 +108,29 @@
 			- CallComment,
 		label(ReturnLabel)
 			- "continuation label"
-	]) },
+	]),
 
 		% Figure out what variables will be live at the return point,
 		% and where, for use in the accurate garbage collector, and
 		% in the debugger.
-	code_info__get_instmap(InstMap),
-	{ goal_info_get_instmap_delta(GoalInfo, InstMapDelta) },
-	{ instmap__apply_instmap_delta(InstMap, InstMapDelta, ReturnInstMap) },
+	code_info__get_instmap(!.CI, InstMap),
+	goal_info_get_instmap_delta(GoalInfo, InstMapDelta),
+	instmap__apply_instmap_delta(InstMap, InstMapDelta, ReturnInstMap),
 
 		% Update the code generator state to reflect the situation
 		% after the call.
 	call_gen__handle_return(ArgsInfos, GoalInfo, NonLiveOutputs,
-		ReturnInstMap, ReturnLiveLvalues),
+		ReturnInstMap, ReturnLiveLvalues, !CI),
 
 		% If the call can fail, generate code to check for and
 		% handle the failure.
-	call_gen__handle_failure(CodeModel, GoalInfo, FailHandlingCode),
+	call_gen__handle_failure(CodeModel, GoalInfo, FailHandlingCode, !CI),
 
-	{ Code =
+	Code =
 		tree(SetupCode,
 		tree(TraceCode,
 		tree(CallCode,
-		     FailHandlingCode)))
-	}.
+		     FailHandlingCode))).
 
 %---------------------------------------------------------------------------%
 
@@ -142,74 +144,74 @@
 	%
 
 call_gen__generate_generic_call(OuterCodeModel, GenericCall, Args0,
-		Modes0, Det, GoalInfo, Code) -->
+		Modes0, Det, GoalInfo, Code, !CI) :-
 	% `unsafe_cast' differs from the other generic call types in
 	% that there is no address. Also, live_vars.m assumes that
 	% unsafe_casts do not require live variables to be saved to the stack.
-	( { GenericCall = unsafe_cast } ->
-		( { Args0 = [InputArg, OutputArg] } ->
+	( GenericCall = unsafe_cast ->
+		( Args0 = [InputArg, OutputArg] ->
 			call_gen__generate_assign_builtin(OutputArg,
-				leaf(InputArg), Code)
+				leaf(InputArg), Code, !CI)
 		;
-			{ error(
-		"call_gen__generate_generic_call: invalid unsafe_cast call") }
+			error(
+		"call_gen__generate_generic_call: invalid unsafe_cast call")
 		)
 	;
 		call_gen__generate_generic_call_2(OuterCodeModel,
-			GenericCall, Args0, Modes0, Det, GoalInfo, Code)
+			GenericCall, Args0, Modes0, Det, GoalInfo, Code, !CI)
 	).	
 
-:- pred call_gen__generate_generic_call_2(code_model, generic_call,
-			list(prog_var), list(mode), determinism,
-			hlds_goal_info, code_tree, code_info, code_info).
-:- mode call_gen__generate_generic_call_2(in, in, in, in, in, in,
-			out, in, out) is det.
+:- pred call_gen__generate_generic_call_2(code_model::in, generic_call::in,
+	list(prog_var)::in, list(mode)::in, determinism::in,
+	hlds_goal_info::in, code_tree::out, code_info::in, code_info::out)
+	is det.
 
 call_gen__generate_generic_call_2(_OuterCodeModel, GenericCall, Args,
-		Modes, Det, GoalInfo, Code) -->
-	list__map_foldl(code_info__variable_type, Args, Types),
+		Modes, Det, GoalInfo, Code, !CI) :-
+	Types = list__map(code_info__variable_type(!.CI), Args),
 
-	{ determinism_to_code_model(Det, CodeModel) },
-	{ call_gen__generic_call_info(CodeModel, GenericCall,
-		CodeAddr, SpecifierArgInfos, FirstImmInput) },
-	{ CodeModel = model_semi ->
+	determinism_to_code_model(Det, CodeModel),
+	call_gen__generic_call_info(CodeModel, GenericCall,
+		CodeAddr, SpecifierArgInfos, FirstImmInput),
+	( CodeModel = model_semi ->
 		FirstOutput = 2
 	;
 		FirstOutput = 1
-	},
+	),
 
-	code_info__get_module_info(ModuleInfo),
-	{ arg_info__compute_in_and_out_vars(ModuleInfo, Args, Modes, Types,
-		InVars, OutVars) },
-	{ call_gen__give_vars_consecutive_arg_infos(InVars, FirstImmInput,
-		top_in, InVarArgInfos) },
-	{ call_gen__give_vars_consecutive_arg_infos(OutVars, FirstOutput,
-		top_out, OutArgsInfos) },
-	{ list__append(SpecifierArgInfos, InVarArgInfos, InArgInfos) },
-	{ list__append(InArgInfos, OutArgsInfos, ArgInfos) },
+	code_info__get_module_info(!.CI, ModuleInfo),
+	arg_info__compute_in_and_out_vars(ModuleInfo, Args, Modes, Types,
+		InVars, OutVars),
+	call_gen__give_vars_consecutive_arg_infos(InVars, FirstImmInput,
+		top_in, InVarArgInfos),
+	call_gen__give_vars_consecutive_arg_infos(OutVars, FirstOutput,
+		top_out, OutArgsInfos),
+	list__append(SpecifierArgInfos, InVarArgInfos, InArgInfos),
+	list__append(InArgInfos, OutArgsInfos, ArgInfos),
 
 		% Save the necessary vars on the stack and move the input args
 		% defined by variables to their registers.
-	code_info__setup_call(GoalInfo, ArgInfos, LiveVals0, SetupCode),
-	call_gen__kill_dead_input_vars(ArgInfos, GoalInfo, NonLiveOutputs),
+	code_info__setup_call(GoalInfo, ArgInfos, LiveVals0, SetupCode, !CI),
+	call_gen__kill_dead_input_vars(ArgInfos, GoalInfo, NonLiveOutputs,
+		!CI),
 
 		% Move the input args not defined by variables to their
 		% registers. Setting up these arguments last results in
 		% slightly more efficient code, since we can use their
 		% registers when placing the variables.
 	call_gen__generic_call_nonvar_setup(GenericCall, InVars, OutVars,
-		NonVarCode),
+		NonVarCode, !CI),
 
-	{ call_gen__extra_livevals(FirstImmInput, ExtraLiveVals) },
-	{ set__insert_list(LiveVals0, ExtraLiveVals, LiveVals) },
+	call_gen__extra_livevals(FirstImmInput, ExtraLiveVals),
+	set__insert_list(LiveVals0, ExtraLiveVals, LiveVals),
 
-	call_gen__prepare_for_call(CodeModel, CallModel, TraceCode),
+	call_gen__prepare_for_call(CodeModel, CallModel, TraceCode, !CI),
 
 		% Make the call.
-	code_info__get_next_label(ReturnLabel),
-	{ goal_info_get_context(GoalInfo, Context) },
-	{ goal_info_get_goal_path(GoalInfo, GoalPath) },
-	{ CallCode = node([
+	code_info__get_next_label(ReturnLabel, !CI),
+	goal_info_get_context(GoalInfo, Context),
+	goal_info_get_goal_path(GoalInfo, GoalPath),
+	CallCode = node([
 		livevals(LiveVals)
 			- "",
 		call(CodeAddr, label(ReturnLabel), ReturnLiveLvalues,
@@ -217,31 +219,30 @@
 			- "Setup and call",
 		label(ReturnLabel)
 			- "Continuation label"
-	]) },
+	]),
 
 		% Figure out what variables will be live at the return point,
 		% and where, for use in the accurate garbage collector, and
 		% in the debugger.
-	code_info__get_instmap(InstMap),
-	{ goal_info_get_instmap_delta(GoalInfo, InstMapDelta) },
-	{ instmap__apply_instmap_delta(InstMap, InstMapDelta, ReturnInstMap) },
+	code_info__get_instmap(!.CI, InstMap),
+	goal_info_get_instmap_delta(GoalInfo, InstMapDelta),
+	instmap__apply_instmap_delta(InstMap, InstMapDelta, ReturnInstMap),
 
 		% Update the code generator state to reflect the situation
 		% after the call.
 	call_gen__handle_return(OutArgsInfos, GoalInfo, NonLiveOutputs,
-		ReturnInstMap, ReturnLiveLvalues),
+		ReturnInstMap, ReturnLiveLvalues, !CI),
 
 		% If the call can fail, generate code to check for and
 		% handle the failure.
-	call_gen__handle_failure(CodeModel, GoalInfo, FailHandlingCode),
+	call_gen__handle_failure(CodeModel, GoalInfo, FailHandlingCode, !CI),
 
-	{ Code =
+	Code =
 		tree(SetupCode,
 		tree(NonVarCode,
 		tree(TraceCode,
 		tree(CallCode,
-		     FailHandlingCode))))
-	}.
+		     FailHandlingCode)))).
 
 %---------------------------------------------------------------------------%
 
@@ -289,83 +290,82 @@
 	code_info::in, code_info::out) is det.
 
 call_gen__generic_call_nonvar_setup(higher_order(_, _, _, _),
-		InVars, OutVars, Code) -->
-	code_info__clobber_regs([reg(r, 2), reg(r, 3)]),
-	{ list__length(InVars, NInVars) },
-	{ list__length(OutVars, NOutVars) },
-	{ Code = node([
+		InVars, OutVars, Code, !CI) :-
+	code_info__clobber_regs([reg(r, 2), reg(r, 3)], !CI),
+	list__length(InVars, NInVars),
+	list__length(OutVars, NOutVars),
+	Code = node([
 		assign(reg(r, 2), const(int_const(NInVars))) -
 			"Assign number of immediate input arguments",
 		assign(reg(r, 3), const(int_const(NOutVars))) -
 			"Assign number of output arguments"
-	]) }.
+	]).
 call_gen__generic_call_nonvar_setup(class_method(_, Method, _, _),
-		InVars, OutVars, Code) -->
-	code_info__clobber_regs([reg(r, 2), reg(r, 3), reg(r, 4)]),
-	{ list__length(InVars, NInVars) },
-	{ list__length(OutVars, NOutVars) },
-	{ Code = node([
+		InVars, OutVars, Code, !CI) :-
+	code_info__clobber_regs([reg(r, 2), reg(r, 3), reg(r, 4)], !CI),
+	list__length(InVars, NInVars),
+	list__length(OutVars, NOutVars),
+	Code = node([
 		assign(reg(r, 2), const(int_const(Method))) -
 			"Index of class method in typeclass info",
 		assign(reg(r, 3), const(int_const(NInVars))) -
 			"Assign number of immediate input arguments",
 		assign(reg(r, 4), const(int_const(NOutVars))) -
 			"Assign number of output arguments"
-	]) }.
-call_gen__generic_call_nonvar_setup(unsafe_cast, _, _, _) -->
-	{ error("call_gen__generic_call_nonvar_setup: unsafe_cast") }.
-call_gen__generic_call_nonvar_setup(aditi_builtin(_, _), _, _, _) -->
+	]).
+call_gen__generic_call_nonvar_setup(unsafe_cast, _, _, _, !CI) :-
+	error("call_gen__generic_call_nonvar_setup: unsafe_cast").
+call_gen__generic_call_nonvar_setup(aditi_builtin(_, _), _, _, _, !CI) :-
 	% These should have been transformed into normal calls.
-	{ error("call_gen__generic_call_info: aditi_builtin") }.
+	error("call_gen__generic_call_info: aditi_builtin").
 
 %---------------------------------------------------------------------------%
 
 :- pred call_gen__prepare_for_call(code_model::in, call_model::out,
 	code_tree::out, code_info::in, code_info::out) is det.
 
-call_gen__prepare_for_call(CodeModel, CallModel, TraceCode) -->
-	code_info__succip_is_used,
+call_gen__prepare_for_call(CodeModel, CallModel, TraceCode, !CI) :-
+	code_info__succip_is_used(!CI),
 	(
-		{ CodeModel = model_det },
-		{ CallModel = det }
+		CodeModel = model_det,
+		CallModel = det
 	;
-		{ CodeModel = model_semi },
-		{ CallModel = semidet }
+		CodeModel = model_semi,
+		CallModel = semidet
 	;
-		{ CodeModel = model_non },
-		code_info__may_use_nondet_tailcall(TailCallStatus),
-		{ CallModel = nondet(TailCallStatus) },
-		code_info__set_resume_point_and_frame_to_unknown
+		CodeModel = model_non,
+		code_info__may_use_nondet_tailcall(!.CI, TailCallStatus),
+		CallModel = nondet(TailCallStatus),
+		code_info__set_resume_point_and_frame_to_unknown(!CI)
 	),
-	trace__prepare_for_call(TraceCode).
+	trace__prepare_for_call(!.CI, TraceCode).
 
 :- pred call_gen__handle_failure(code_model::in, hlds_goal_info::in,
 	code_tree::out, code_info::in, code_info::out) is det.
 
-call_gen__handle_failure(CodeModel, GoalInfo, FailHandlingCode) -->
-	( { CodeModel = model_semi } ->
-		{ goal_info_get_determinism(GoalInfo, Detism) },
-		( { Detism = failure } ->
-			code_info__generate_failure(FailHandlingCode)
+call_gen__handle_failure(CodeModel, GoalInfo, FailHandlingCode, !CI) :-
+	( CodeModel = model_semi ->
+		goal_info_get_determinism(GoalInfo, Detism),
+		( Detism = failure ->
+			code_info__generate_failure(FailHandlingCode, !CI)
 		;
-			code_info__get_next_label(ContLab),
-			{ FailTestCode = node([
+			code_info__get_next_label(ContLab, !CI),
+			FailTestCode = node([
 				if_val(lval(reg(r, 1)), label(ContLab))
 					- "test for success"
-			]) },
-			code_info__generate_failure(FailCode),
-			{ ContLabelCode = node([
+			]),
+			code_info__generate_failure(FailCode, !CI),
+			ContLabelCode = node([
 				label(ContLab)
 					- ""
-			]) },
-			{ FailHandlingCode =
+			]),
+			FailHandlingCode =
 				tree(FailTestCode,
 				tree(FailCode,
 				     ContLabelCode))
-			}
 		)
 	;
-		{ FailHandlingCode = empty }
+		FailHandlingCode = empty
 	).
 
 :- pred call_gen__call_comment(code_model::in, string::out) is det.
@@ -399,31 +399,31 @@
 	hlds_goal_info::in, set(prog_var)::out,
 	code_info::in, code_info::out) is det.
 
-call_gen__kill_dead_input_vars(ArgsInfos, GoalInfo, NonLiveOutputs) -->
-	code_info__get_forward_live_vars(Liveness),
-	{ call_gen__find_nonlive_outputs(ArgsInfos, Liveness,
-		set__init, NonLiveOutputs) },
-	{ goal_info_get_post_deaths(GoalInfo, PostDeaths) },
-	{ set__difference(PostDeaths, NonLiveOutputs, ImmediatePostDeaths) },
-	code_info__make_vars_forward_dead(ImmediatePostDeaths).
+call_gen__kill_dead_input_vars(ArgsInfos, GoalInfo, NonLiveOutputs, !CI) :-
+	code_info__get_forward_live_vars(!.CI, Liveness),
+	call_gen__find_nonlive_outputs(ArgsInfos, Liveness,
+		set__init, NonLiveOutputs),
+	goal_info_get_post_deaths(GoalInfo, PostDeaths),
+	set__difference(PostDeaths, NonLiveOutputs, ImmediatePostDeaths),
+	code_info__make_vars_forward_dead(ImmediatePostDeaths, !CI).
 
 :- pred call_gen__handle_return(assoc_list(prog_var, arg_info)::in,
 	hlds_goal_info::in, set(prog_var)::in, instmap::in,
 	list(liveinfo)::out, code_info::in, code_info::out) is det.
 
 call_gen__handle_return(ArgsInfos, GoalInfo, _NonLiveOutputs, ReturnInstMap,
-		ReturnLiveLvalues) -->
-	{ goal_info_get_instmap_delta(GoalInfo, InstMapDelta) },
-	{ instmap_delta_is_reachable(InstMapDelta) ->
+		ReturnLiveLvalues, !CI) :-
+	goal_info_get_instmap_delta(GoalInfo, InstMapDelta),
+	( instmap_delta_is_reachable(InstMapDelta) ->
 		OkToDeleteAny = no
 	;
 		OkToDeleteAny = yes
-	},
-	code_info__clear_all_registers(OkToDeleteAny),
-	code_info__get_forward_live_vars(Liveness),
-	call_gen__rebuild_registers(ArgsInfos, Liveness, OutputArgLocs),
-	code_info__generate_return_live_lvalues(OutputArgLocs, ReturnInstMap,
-		OkToDeleteAny, ReturnLiveLvalues).
+	),
+	code_info__clear_all_registers(OkToDeleteAny, !CI),
+	code_info__get_forward_live_vars(!.CI, Liveness),
+	call_gen__rebuild_registers(ArgsInfos, Liveness, OutputArgLocs, !CI),
+	code_info__generate_return_live_lvalues(!.CI, OutputArgLocs,
+		ReturnInstMap, OkToDeleteAny, ReturnLiveLvalues).
 
 :- pred call_gen__find_nonlive_outputs(assoc_list(prog_var, arg_info)::in,
 	set(prog_var)::in, set(prog_var)::in, set(prog_var)::out) is det.
@@ -447,28 +447,28 @@
 	set(prog_var)::in, assoc_list(prog_var, arg_loc)::out,
 	code_info::in, code_info::out) is det.
 
-call_gen__rebuild_registers([], _, []) --> [].
+call_gen__rebuild_registers([], _, [], !CI).
 call_gen__rebuild_registers([Var - arg_info(ArgLoc, Mode) | Args], Liveness,
-		OutputArgLocs) -->
-	call_gen__rebuild_registers(Args, Liveness, OutputArgLocs1),
+		OutputArgLocs, !CI) :-
+	call_gen__rebuild_registers(Args, Liveness, OutputArgLocs1, !CI),
 	(
-		{ Mode = top_out },
-		{ set__member(Var, Liveness) }
+		Mode = top_out,
+		set__member(Var, Liveness)
 	->
-		{ code_util__arg_loc_to_register(ArgLoc, Register) },
-		code_info__set_var_location(Var, Register),
-		{ OutputArgLocs = [Var - ArgLoc | OutputArgLocs1] }
+		code_util__arg_loc_to_register(ArgLoc, Register),
+		code_info__set_var_location(Var, Register, !CI),
+		OutputArgLocs = [Var - ArgLoc | OutputArgLocs1]
 	;
-		{ OutputArgLocs = OutputArgLocs1 }
+		OutputArgLocs = OutputArgLocs1
 	).
 
 %---------------------------------------------------------------------------%
 
-call_gen__generate_builtin(CodeModel, PredId, ProcId, Args, Code) -->
-	code_info__get_module_info(ModuleInfo),
-	{ predicate_module(ModuleInfo, PredId, ModuleName) },
-	{ predicate_name(ModuleInfo, PredId, PredName) },
-	{
+call_gen__generate_builtin(CodeModel, PredId, ProcId, Args, Code, !CI) :-
+	code_info__get_module_info(!.CI, ModuleInfo),
+	predicate_module(ModuleInfo, PredId, ModuleName),
+	predicate_name(ModuleInfo, PredId, PredName),
+	(
 		builtin_ops__translate_builtin(ModuleName, PredName,
 			ProcId, Args, SimpleCode0)
 	->
@@ -478,44 +478,44 @@
 		format("Unknown builtin predicate: %s/%d",
 			[s(PredName), i(Arity)], Msg),
 		error(Msg)
-	},
+	),
 	(
-		{ CodeModel = model_det },
+		CodeModel = model_det,
 		(
-			{ SimpleCode = assign(Var, AssignExpr) }
+			SimpleCode = assign(Var, AssignExpr)
 		->
 			call_gen__generate_assign_builtin(Var,
-				AssignExpr, Code)
+				AssignExpr, Code, !CI)
 		;
-			{ error("Malformed det builtin predicate") }
+			error("Malformed det builtin predicate")
 		)
 	;
-		{ CodeModel = model_semi },
+		CodeModel = model_semi,
 		(
-			{ SimpleCode = test(TestExpr) }
+			SimpleCode = test(TestExpr)
 		->
 			call_gen__generate_simple_test(TestExpr, Rval,
-				ArgCode),
-			code_info__fail_if_rval_is_false(Rval, TestCode),
-			{ Code = tree(ArgCode, TestCode) }
+				ArgCode, !CI),
+			code_info__fail_if_rval_is_false(Rval, TestCode, !CI),
+			Code = tree(ArgCode, TestCode)
 		;
-			{ error("Malformed semi builtin predicate") }
+			error("Malformed semi builtin predicate")
 		)
 	;
-		{ CodeModel = model_non },
-		{ error("Nondet builtin predicate") }
+		CodeModel = model_non,
+		error("Nondet builtin predicate")
 	).
 
-:- pred call_gen__generate_assign_builtin(prog_var, simple_expr(prog_var),
-		code_tree, code_info, code_info).
-:- mode call_gen__generate_assign_builtin(in, in, out, in, out) is det.
-
-call_gen__generate_assign_builtin(Var, AssignExpr, Code) -->
-	( code_info__variable_is_forward_live(Var) ->
-		{ Rval = convert_simple_expr(AssignExpr) },
-		code_info__assign_expr_to_var(Var, Rval, Code)
+:- pred call_gen__generate_assign_builtin(prog_var::in,
+	simple_expr(prog_var)::in, code_tree::out,
+	code_info::in, code_info::out) is det.
+
+call_gen__generate_assign_builtin(Var, AssignExpr, Code, !CI) :-
+	( code_info__variable_is_forward_live(!.CI, Var) ->
+		Rval = convert_simple_expr(AssignExpr),
+		code_info__assign_expr_to_var(Var, Rval, Code, !CI)
 	;
-		{ Code = empty }
+		Code = empty
 	).
 
 :- func convert_simple_expr(simple_expr(prog_var)) = rval.
@@ -532,31 +532,31 @@
 	simple_expr(prog_var)::in(simple_test_expr), rval::out,
 	code_tree::out, code_info::in, code_info::out) is det.
 
-call_gen__generate_simple_test(TestExpr, Rval, ArgCode) -->
+call_gen__generate_simple_test(TestExpr, Rval, ArgCode, !CI) :-
 	(
-		{ TestExpr = binary(BinOp, X0, Y0) },
-		{ X1 = convert_simple_expr(X0) },
-		{ Y1 = convert_simple_expr(Y0) },
-		call_gen__generate_builtin_arg(X1, X, CodeX),
-		call_gen__generate_builtin_arg(Y1, Y, CodeY),
-		{ Rval = binop(BinOp, X, Y) },
-		{ ArgCode = tree(CodeX, CodeY) }
-	;
-		{ TestExpr = unary(UnOp, X0) },
-		{ X1 = convert_simple_expr(X0) },
-		call_gen__generate_builtin_arg(X1, X, ArgCode),
-		{ Rval = unop(UnOp, X) }
+		TestExpr = binary(BinOp, X0, Y0),
+		X1 = convert_simple_expr(X0),
+		Y1 = convert_simple_expr(Y0),
+		call_gen__generate_builtin_arg(X1, X, CodeX, !CI),
+		call_gen__generate_builtin_arg(Y1, Y, CodeY, !CI),
+		Rval = binop(BinOp, X, Y),
+		ArgCode = tree(CodeX, CodeY)
+	;
+		TestExpr = unary(UnOp, X0),
+		X1 = convert_simple_expr(X0),
+		call_gen__generate_builtin_arg(X1, X, ArgCode, !CI),
+		Rval = unop(UnOp, X)
 	).
 
 :- pred call_gen__generate_builtin_arg(rval::in, rval::out, code_tree::out,
 	code_info::in, code_info::out) is det.
 
-call_gen__generate_builtin_arg(Rval0, Rval, Code) -->
-	( { Rval0 = var(Var) } ->
-		code_info__produce_variable(Var, Code, Rval)
+call_gen__generate_builtin_arg(Rval0, Rval, Code, !CI) :-
+	( Rval0 = var(Var) ->
+		code_info__produce_variable(Var, Code, Rval, !CI)
 	;
-		{ Rval = Rval0 },
-		{ Code = empty }
+		Rval = Rval0,
+		Code = empty
 	).
 
 %---------------------------------------------------------------------------%
@@ -586,12 +586,12 @@
 	set(prog_var)::in, code_tree::out,
 	code_info::in, code_info::out) is det.
 
-call_gen__generate_call_vn_livevals(InputArgLocs, OutputArgs, Code) -->
-	code_info__generate_call_vn_livevals(InputArgLocs, OutputArgs,
+call_gen__generate_call_vn_livevals(InputArgLocs, OutputArgs, Code, !CI) :-
+	code_info__generate_call_vn_livevals(!.CI, InputArgLocs, OutputArgs,
 		LiveVals),
-	{ Code = node([
+	Code = node([
 		livevals(LiveVals) - ""
-	]) }.
+	]).
 
 %---------------------------------------------------------------------------%
 
Index: code_aux.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/code_aux.m,v
retrieving revision 1.66
diff -u -b -r1.66 code_aux.m
--- code_aux.m	15 Mar 2003 03:08:43 -0000	1.66
+++ code_aux.m	22 Oct 2003 05:20:52 -0000
@@ -78,9 +78,9 @@
 code_aux__is_recursive_call(Goal, CodeInfo) :-
 	Goal = call(CallPredId, CallProcId, _, BuiltinState, _, _),
 	BuiltinState = not_builtin,
-	code_info__get_pred_id(PredId, CodeInfo, _),
+	code_info__get_pred_id(CodeInfo, PredId),
 	PredId = CallPredId,
-	code_info__get_proc_id(ProcId, CodeInfo, _),
+	code_info__get_proc_id(CodeInfo, ProcId),
 	ProcId = CallProcId.
 
 %-----------------------------------------------------------------------------%
Index: code_gen.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/code_gen.m,v
retrieving revision 1.116
diff -u -b -r1.116 code_gen.m
--- code_gen.m	24 Oct 2003 06:17:35 -0000	1.116
+++ code_gen.m	24 Oct 2003 06:27:04 -0000
@@ -113,13 +113,13 @@
 
 %---------------------------------------------------------------------------%
 
-generate_code(ModuleInfo0, !GlobalData, Procedures) -->
+generate_code(ModuleInfo0, !GlobalData, Procedures, !IO) :-
 		% get a list of all the predicate ids
 		% for which we are going to generate code.
-	{ module_info_predids(ModuleInfo0, PredIds) },
+	module_info_predids(ModuleInfo0, PredIds),
 		% now generate the code for each predicate
 	generate_pred_list_code(ModuleInfo0, !GlobalData, PredIds,
-		Procedures).
+		Procedures, !IO).
 
 	% Translate a list of HLDS predicates to LLDS.
 
@@ -128,14 +128,14 @@
 	list(pred_id)::in, list(c_procedure)::out,
 	io__state::di, io__state::uo) is det.
 
-generate_pred_list_code(_ModuleInfo, !GlobalData, [], []) --> [].
+generate_pred_list_code(_ModuleInfo, !GlobalData, [], [], !IO).
 generate_pred_list_code(ModuleInfo, !GlobalData, [PredId | PredIds],
-		Predicates) -->
+		Predicates, !IO) :-
 	generate_maybe_pred_code(ModuleInfo, !GlobalData, PredId,
-		Predicates0),
+		Predicates0, !IO),
 	generate_pred_list_code(ModuleInfo, !GlobalData, PredIds,
-		Predicates1),
-	{ list__append(Predicates0, Predicates1, Predicates) }.
+		Predicates1, !IO),
+	list__append(Predicates0, Predicates1, Predicates).
 
 :- pred generate_maybe_pred_code(module_info::in,
 	global_data::in, global_data::out, pred_id::in,
@@ -200,10 +200,9 @@
 	pred_id::in, pred_info::in, list(proc_id)::in, list(c_procedure)::out)
 	is det.
 
-generate_pred_code(ModuleInfo, GlobalData0, GlobalData,
-		PredId, PredInfo, ProcIds, Code) :-
+generate_pred_code(ModuleInfo, !GlobalData, PredId, PredInfo, ProcIds, Code) :-
 	generate_proc_list_code(ProcIds, PredId, PredInfo, ModuleInfo,
-		GlobalData0, GlobalData, [], Code).
+		!GlobalData, [], Code).
 
 	% Translate all the procedures of a HLDS predicate to LLDS.
 
@@ -212,15 +211,16 @@
 	list(c_procedure)::in, list(c_procedure)::out) is det.
 
 generate_proc_list_code([], _PredId, _PredInfo, _ModuleInfo,
-		GlobalData, GlobalData, Procs, Procs).
+		!GlobalData, !Procs).
 generate_proc_list_code([ProcId | ProcIds], PredId, PredInfo, ModuleInfo0,
-		GlobalData0, GlobalData, Procs0, Procs) :-
+		!GlobalData, !Procs) :-
 	pred_info_procedures(PredInfo, ProcInfos),
 	map__lookup(ProcInfos, ProcId, ProcInfo),
 	generate_proc_code(PredInfo, ProcInfo, ProcId, PredId, ModuleInfo0,
-		GlobalData0, GlobalData1, Proc),
+		!GlobalData, Proc),
+	!:Procs = [Proc | !.Procs],
 	generate_proc_list_code(ProcIds, PredId, PredInfo, ModuleInfo0,
-		GlobalData1, GlobalData, [Proc | Procs0], Procs).
+		!GlobalData, !Procs).
 
 %---------------------------------------------------------------------------%
 
@@ -280,12 +280,12 @@
 	generate_category_code(CodeModel, Goal, OutsideResumePoint,
 		TraceSlotInfo, CodeTree, MaybeTraceCallLabel, FrameInfo,
 		CodeInfo0, CodeInfo),
-	code_info__get_max_reg_in_use_at_trace(MaxTraceReg, CodeInfo, _),
-	code_info__get_static_cell_info(StaticCellInfo, CodeInfo, _),
+	code_info__get_max_reg_in_use_at_trace(CodeInfo, MaxTraceReg),
+	code_info__get_static_cell_info(CodeInfo, StaticCellInfo),
 	global_data_set_static_cell_info(StaticCellInfo, !GlobalData),
 
 	globals__get_trace_level(Globals, TraceLevel),
-	code_info__get_created_temp_frame(CreatedTempFrame, CodeInfo, _),
+	code_info__get_created_temp_frame(CodeInfo, CreatedTempFrame),
 
 	EffTraceIsNone = eff_trace_level_is_none(PredInfo, ProcInfo,
 		TraceLevel),
@@ -336,7 +336,7 @@
 			% Create the procedure layout structure.
 		RttiProcLabel = rtti__make_rtti_proc_label(ModuleInfo,
 			PredId, ProcId),
-		code_info__get_layout_info(InternalMap, CodeInfo, _),
+		code_info__get_layout_info(CodeInfo, InternalMap),
 		code_util__make_local_entry_label(ModuleInfo, PredId, ProcId,
 			no, EntryLabel),
 		proc_info_eval_method(ProcInfo, EvalMethod),
@@ -368,7 +368,7 @@
 		true
 	),
 
-	code_info__get_closure_layouts(ClosureLayouts, CodeInfo, _),
+	code_info__get_closure_layouts(CodeInfo, ClosureLayouts),
 	global_data_add_new_closure_layouts(ClosureLayouts, !GlobalData),
 	ProcLabel = make_proc_label(ModuleInfo, PredId, ProcId),
 	maybe_add_tabling_pointer_var(ModuleInfo, PredId, ProcId, ProcInfo,
@@ -377,7 +377,7 @@
 	Name = pred_info_name(PredInfo),
 	Arity = pred_info_arity(PredInfo),
 
-	code_info__get_label_counter(LabelCounter, CodeInfo, _),
+	code_info__get_label_counter(CodeInfo, LabelCounter),
 	(
 		EffTraceIsNone = yes,
 		MayAlterRtti = may_alter_rtti
@@ -481,95 +481,94 @@
 	is det.
 
 generate_category_code(model_det, Goal, ResumePoint, TraceSlotInfo, Code,
-		MaybeTraceCallLabel, FrameInfo) -->
+		MaybeTraceCallLabel, FrameInfo, !CI) :-
 		% generate the code for the body of the clause
 	(
-		code_info__get_globals(Globals),
-		{ globals__lookup_bool_option(Globals, middle_rec, yes) },
-		middle_rec__match_and_generate(Goal, MiddleRecCode)
+		code_info__get_globals(!.CI, Globals),
+		globals__lookup_bool_option(Globals, middle_rec, yes),
+		middle_rec__match_and_generate(Goal, MiddleRecCode, !CI)
 	->
-		{ Code = MiddleRecCode },
-		{ MaybeTraceCallLabel = no },
-		{ FrameInfo = frame(0, no, no) }
-	;
-		{ Goal = _ - GoalInfo },
-		{ goal_info_get_context(GoalInfo, BodyContext) },
-		code_info__get_maybe_trace_info(MaybeTraceInfo),
-		( { MaybeTraceInfo = yes(TraceInfo) } ->
+		Code = MiddleRecCode,
+		MaybeTraceCallLabel = no,
+		FrameInfo = frame(0, no, no)
+	;
+		Goal = _ - GoalInfo,
+		goal_info_get_context(GoalInfo, BodyContext),
+		code_info__get_maybe_trace_info(!.CI, MaybeTraceInfo),
+		( MaybeTraceInfo = yes(TraceInfo) ->
 			trace__generate_external_event_code(call, TraceInfo,
-				BodyContext, MaybeCallExternalInfo),
-			{
+				BodyContext, MaybeCallExternalInfo, !CI),
+			(
 				MaybeCallExternalInfo = yes(CallExternalInfo),
 				CallExternalInfo = external_event_info(
 					TraceCallLabel, _, TraceCallCode)
 			;
 				MaybeCallExternalInfo = no,
 				error("generate_category_code: call events suppressed")
-			},
-			{ MaybeTraceCallLabel = yes(TraceCallLabel) }
+			),
+			MaybeTraceCallLabel = yes(TraceCallLabel)
 		;
-			{ TraceCallCode = empty },
-			{ MaybeTraceCallLabel = no }
+			TraceCallCode = empty,
+			MaybeTraceCallLabel = no
 		),
-		code_gen__generate_goal(model_det, Goal, BodyCode),
-		code_gen__generate_entry(model_det, Goal, ResumePoint,
+		code_gen__generate_goal(model_det, Goal, BodyCode, !CI),
+		code_gen__generate_entry(!.CI, model_det, Goal, ResumePoint,
 			FrameInfo, EntryCode),
 		code_gen__generate_exit(model_det, FrameInfo, TraceSlotInfo,
-			BodyContext, _, ExitCode),
-		{ Code =
+			BodyContext, _, ExitCode, !CI),
+		Code =
 			tree(EntryCode,
 			tree(TraceCallCode,
 			tree(BodyCode,
 			     ExitCode)))
-		}
 	).
 
 generate_category_code(model_semi, Goal, ResumePoint, TraceSlotInfo, Code,
-		MaybeTraceCallLabel, FrameInfo) -->
-	{ set__singleton_set(FailureLiveRegs, reg(r, 1)) },
-	{ FailCode = node([
+		MaybeTraceCallLabel, FrameInfo, !CI) :-
+	set__singleton_set(FailureLiveRegs, reg(r, 1)),
+	FailCode = node([
 		assign(reg(r, 1), const(false)) - "Fail",
 		livevals(FailureLiveRegs) - "",
 		goto(succip) - "Return from procedure call"
-	]) },
-	{ Goal = _ - GoalInfo },
-	{ goal_info_get_context(GoalInfo, BodyContext) },
-	code_info__get_maybe_trace_info(MaybeTraceInfo),
-	( { MaybeTraceInfo = yes(TraceInfo) } ->
+	]),
+	Goal = _ - GoalInfo,
+	goal_info_get_context(GoalInfo, BodyContext),
+	code_info__get_maybe_trace_info(!.CI, MaybeTraceInfo),
+	( MaybeTraceInfo = yes(TraceInfo) ->
 		trace__generate_external_event_code(call, TraceInfo,
-			BodyContext, MaybeCallExternalInfo),
-		{
+			BodyContext, MaybeCallExternalInfo, !CI),
+		(
 			MaybeCallExternalInfo = yes(CallExternalInfo),
 			CallExternalInfo = external_event_info(
 				TraceCallLabel, _, TraceCallCode)
 		;
 			MaybeCallExternalInfo = no,
 			error("generate_category_code: call events suppressed")
-		},
-		{ MaybeTraceCallLabel = yes(TraceCallLabel) },
-		code_gen__generate_goal(model_semi, Goal, BodyCode),
-		code_gen__generate_entry(model_semi, Goal, ResumePoint,
+		),
+		MaybeTraceCallLabel = yes(TraceCallLabel),
+		code_gen__generate_goal(model_semi, Goal, BodyCode, !CI),
+		code_gen__generate_entry(!.CI, model_semi, Goal, ResumePoint,
 			FrameInfo, EntryCode),
 		code_gen__generate_exit(model_semi, FrameInfo, TraceSlotInfo,
-			BodyContext, RestoreDeallocCode, ExitCode),
+			BodyContext, RestoreDeallocCode, ExitCode, !CI),
 
-		code_info__generate_resume_point(ResumePoint, ResumeCode),
-		{ code_info__resume_point_vars(ResumePoint, ResumeVarList) },
-		{ set__list_to_set(ResumeVarList, ResumeVars) },
-		code_info__set_forward_live_vars(ResumeVars),
+		code_info__generate_resume_point(ResumePoint, ResumeCode, !CI),
+		code_info__resume_point_vars(ResumePoint, ResumeVarList),
+		set__list_to_set(ResumeVarList, ResumeVars),
+		code_info__set_forward_live_vars(ResumeVars, !CI),
 			% XXX A context that gives the end of the procedure
 			% definition would be better than BodyContext.
 		trace__generate_external_event_code(fail, TraceInfo,
-			BodyContext, MaybeFailExternalInfo),
-		{
+			BodyContext, MaybeFailExternalInfo, !CI),
+		(
 			MaybeFailExternalInfo = yes(FailExternalInfo),
 			FailExternalInfo = external_event_info(
 				_, _, TraceFailCode)
 		;
 			MaybeFailExternalInfo = no,
 			TraceFailCode = empty
-		},
-		{ Code =
+		),
+		Code =
 			tree(EntryCode,
 			tree(TraceCallCode,
 			tree(BodyCode,
@@ -578,96 +577,94 @@
 			tree(TraceFailCode,
 			tree(RestoreDeallocCode,
 			     FailCode)))))))
-		}
 	;
-		{ MaybeTraceCallLabel = no },
-		code_gen__generate_goal(model_semi, Goal, BodyCode),
-		code_gen__generate_entry(model_semi, Goal, ResumePoint,
+		MaybeTraceCallLabel = no,
+		code_gen__generate_goal(model_semi, Goal, BodyCode, !CI),
+		code_gen__generate_entry(!.CI, model_semi, Goal, ResumePoint,
 			FrameInfo, EntryCode),
 		code_gen__generate_exit(model_semi, FrameInfo, TraceSlotInfo,
-			BodyContext, RestoreDeallocCode, ExitCode),
-		code_info__generate_resume_point(ResumePoint, ResumeCode),
-		{ Code =
+			BodyContext, RestoreDeallocCode, ExitCode, !CI),
+		code_info__generate_resume_point(ResumePoint, ResumeCode, !CI),
+		Code =
 			tree(EntryCode,
 			tree(BodyCode,
 			tree(ExitCode,
 			tree(ResumeCode,
 			tree(RestoreDeallocCode,
 			     FailCode)))))
-		}
 	).
 
 generate_category_code(model_non, Goal, ResumePoint, TraceSlotInfo, Code,
-		MaybeTraceCallLabel, FrameInfo) -->
-	code_info__get_maybe_trace_info(MaybeTraceInfo),
-	{ Goal = _ - GoalInfo },
-	{ goal_info_get_context(GoalInfo, BodyContext) },
-	( { MaybeTraceInfo = yes(TraceInfo) } ->
+		MaybeTraceCallLabel, FrameInfo, !CI) :-
+	code_info__get_maybe_trace_info(!.CI, MaybeTraceInfo),
+	Goal = _ - GoalInfo,
+	goal_info_get_context(GoalInfo, BodyContext),
+	( MaybeTraceInfo = yes(TraceInfo) ->
 		trace__generate_external_event_code(call, TraceInfo,
-			BodyContext, MaybeCallExternalInfo),
-		{
+			BodyContext, MaybeCallExternalInfo, !CI),
+		(
 			MaybeCallExternalInfo = yes(CallExternalInfo),
 			CallExternalInfo = external_event_info(
 				TraceCallLabel, _, TraceCallCode)
 		;
 			MaybeCallExternalInfo = no,
 			error("generate_category_code: call events suppressed")
-		},
-		{ MaybeTraceCallLabel = yes(TraceCallLabel) },
-		code_gen__generate_goal(model_non, Goal, BodyCode),
-		code_gen__generate_entry(model_non, Goal, ResumePoint,
+		),
+		MaybeTraceCallLabel = yes(TraceCallLabel),
+		code_gen__generate_goal(model_non, Goal, BodyCode, !CI),
+		code_gen__generate_entry(!.CI, model_non, Goal, ResumePoint,
 			FrameInfo, EntryCode),
 		code_gen__generate_exit(model_non, FrameInfo, TraceSlotInfo,
-			BodyContext, _, ExitCode),
+			BodyContext, _, ExitCode, !CI),
 
-		code_info__generate_resume_point(ResumePoint, ResumeCode),
-		{ code_info__resume_point_vars(ResumePoint, ResumeVarList) },
-		{ set__list_to_set(ResumeVarList, ResumeVars) },
-		code_info__set_forward_live_vars(ResumeVars),
+		code_info__generate_resume_point(ResumePoint, ResumeCode, !CI),
+		code_info__resume_point_vars(ResumePoint, ResumeVarList),
+		set__list_to_set(ResumeVarList, ResumeVars),
+		code_info__set_forward_live_vars(ResumeVars, !CI),
 			% XXX A context that gives the end of the procedure
 			% definition would be better than BodyContext.
 		trace__generate_external_event_code(fail, TraceInfo,
-			BodyContext, MaybeFailExternalInfo),
-		{
+			BodyContext, MaybeFailExternalInfo, !CI),
+		(
 			MaybeFailExternalInfo = yes(FailExternalInfo),
 			FailExternalInfo = external_event_info(
 				_, _, TraceFailCode)
 		;
 			MaybeFailExternalInfo = no,
 			TraceFailCode = empty
-		},
-		( { TraceSlotInfo ^ slot_trail = yes(_) } ->
-			( { TraceSlotInfo ^ slot_from_full =
-				yes(FromFullSlot) }
+		),
+		( TraceSlotInfo ^ slot_trail = yes(_) ->
+			( TraceSlotInfo ^ slot_from_full =
+				yes(FromFullSlot)
 			->
 				%
 				% Generate code which discards the ticket
 				% only if it was allocated, i.e. only if
 				% MR_trace_from_full was true on entry.
 				%
-				{ FromFullSlotLval =
+				FromFullSlotLval =
 					llds__stack_slot_num_to_lval(
-						model_non, FromFullSlot) },
-				code_info__get_next_label(SkipLabel),
-				{ DiscardTraceTicketCode = node([
+						model_non, FromFullSlot),
+				code_info__get_next_label(SkipLabel, !CI),
+				DiscardTraceTicketCode = node([
 					if_val(unop(not,
 						lval(FromFullSlotLval)),
 						label(SkipLabel)) - "",
 					discard_ticket - "discard retry ticket",
 					label(SkipLabel) - ""
-				]) }
+				])
 			;
-				{ DiscardTraceTicketCode = node([
+				DiscardTraceTicketCode = node([
 					discard_ticket - "discard retry ticket"
-				]) }
+				])
 			)
 		;
-			{ DiscardTraceTicketCode = empty }
+			DiscardTraceTicketCode = empty
 		),
-		{ FailCode = node([
+		FailCode = node([
 			goto(do_fail) - "fail after fail trace port"
-		]) },
-		{ Code =
+		]),
+		Code =
 			tree(EntryCode,
 			tree(TraceCallCode,
 			tree(BodyCode,
@@ -676,19 +673,17 @@
 			tree(TraceFailCode,
 			tree(DiscardTraceTicketCode,
 			     FailCode)))))))
-		}
 	;
-		{ MaybeTraceCallLabel = no },
-		code_gen__generate_goal(model_non, Goal, BodyCode),
-		code_gen__generate_entry(model_non, Goal, ResumePoint,
+		MaybeTraceCallLabel = no,
+		code_gen__generate_goal(model_non, Goal, BodyCode, !CI),
+		code_gen__generate_entry(!.CI, model_non, Goal, ResumePoint,
 			FrameInfo, EntryCode),
 		code_gen__generate_exit(model_non, FrameInfo, TraceSlotInfo,
-			BodyContext, _, ExitCode),
-		{ Code =
+			BodyContext, _, ExitCode, !CI),
+		Code =
 			tree(EntryCode,
 			tree(BodyCode,
 			     ExitCode))
-		}
 	).
 
 %---------------------------------------------------------------------------%
@@ -712,122 +707,116 @@
 	% need a stack frame, and if the procedure is nondet, then the code
 	% to fill in the succip slot is subsumed by the mkframe.
 
-:- pred code_gen__generate_entry(code_model::in, hlds_goal::in,
-	resume_point_info::in, frame_info::out, code_tree::out,
-	code_info::in, code_info::out) is det.
+:- pred code_gen__generate_entry(code_info::in, code_model::in, hlds_goal::in,
+	resume_point_info::in, frame_info::out, code_tree::out) is det.
 
-code_gen__generate_entry(CodeModel, Goal, OutsideResumePoint, FrameInfo,
-		EntryCode) -->
-	code_info__get_stack_slots(StackSlots),
-	code_info__get_varset(VarSet),
-	{ code_aux__explain_stack_slots(StackSlots, VarSet, SlotsComment) },
-	{ StartComment = node([
+code_gen__generate_entry(CI, CodeModel, Goal, OutsideResumePoint, FrameInfo,
+		EntryCode) :-
+	code_info__get_stack_slots(CI, StackSlots),
+	code_info__get_varset(CI, VarSet),
+	code_aux__explain_stack_slots(StackSlots, VarSet, SlotsComment),
+	StartComment = node([
 		comment("Start of procedure prologue") - "",
 		comment(SlotsComment) - ""
-	]) },
-	code_info__get_total_stackslot_count(MainSlots),
-	code_info__get_pred_id(PredId),
-	code_info__get_proc_id(ProcId),
-	code_info__get_module_info(ModuleInfo),
-	{ code_util__make_local_entry_label(ModuleInfo, PredId, ProcId, no,
-		Entry) },
-	{ LabelCode = node([
+	]),
+	code_info__get_total_stackslot_count(CI, MainSlots),
+	code_info__get_pred_id(CI, PredId),
+	code_info__get_proc_id(CI, ProcId),
+	code_info__get_module_info(CI, ModuleInfo),
+	code_util__make_local_entry_label(ModuleInfo, PredId, ProcId, no,
+		Entry),
+	LabelCode = node([
 		label(Entry) - "Procedure entry point"
-	]) },
-	code_info__get_succip_used(Used),
+	]),
+	code_info__get_succip_used(CI, Used),
 	(
 		% Do we need to save the succip across calls?
-		{ Used = yes },
+		Used = yes,
 		% Do we need to use a general slot for storing succip?
-		{ CodeModel \= model_non }
+		CodeModel \= model_non
 	->
-		{ SuccipSlot = MainSlots + 1 },
-		{ SaveSuccipCode = node([
+		SuccipSlot = MainSlots + 1,
+		SaveSuccipCode = node([
 			assign(stackvar(SuccipSlot), lval(succip)) -
 				"Save the success ip"
-		]) },
-		{ TotalSlots = SuccipSlot },
-		{ MaybeSuccipSlot = yes(SuccipSlot) }
+		]),
+		TotalSlots = SuccipSlot,
+		MaybeSuccipSlot = yes(SuccipSlot)
 	;
-		{ SaveSuccipCode = empty },
-		{ TotalSlots = MainSlots },
-		{ MaybeSuccipSlot = no }
+		SaveSuccipCode = empty,
+		TotalSlots = MainSlots,
+		MaybeSuccipSlot = no
 	),
-	code_info__get_maybe_trace_info(MaybeTraceInfo),
-	( { MaybeTraceInfo = yes(TraceInfo) } ->
-		trace__generate_slot_fill_code(TraceInfo, TraceFillCode)
+	code_info__get_maybe_trace_info(CI, MaybeTraceInfo),
+	( MaybeTraceInfo = yes(TraceInfo) ->
+		trace__generate_slot_fill_code(CI, TraceInfo, TraceFillCode)
 	;
-		{ TraceFillCode = empty }
+		TraceFillCode = empty
 	),
-	{ module_info_pred_info(ModuleInfo, PredId, PredInfo) },
-	{ ModuleName = pred_info_module(PredInfo) },
-	{ PredName = pred_info_name(PredInfo) },
-	{ Arity = pred_info_arity(PredInfo) },
+	module_info_pred_info(ModuleInfo, PredId, PredInfo),
+	ModuleName = pred_info_module(PredInfo),
+	PredName = pred_info_name(PredInfo),
+	Arity = pred_info_arity(PredInfo),
 
-	{ PushMsg = code_gen__push_msg(ModuleInfo, PredId, ProcId) },
-	(
-		{ CodeModel = model_non }
+	PushMsg = code_gen__push_msg(ModuleInfo, PredId, ProcId),
+	( CodeModel = model_non ->
+		code_info__resume_point_stack_addr(OutsideResumePoint,
+			OutsideResumeAddress),
+		(
+			Goal = foreign_proc(_, _, _, _, _, _,
+				PragmaCode) - _,
+			PragmaCode = nondet(Fields, FieldsContext,
+				_,_,_,_,_,_,_)
 	->
-		{ code_info__resume_point_stack_addr(OutsideResumePoint,
-			OutsideResumeAddress) },
-		(
-			{ Goal = foreign_proc(_, _, _, _, _, _,
-				PragmaCode) - _},
-			{ PragmaCode = nondet(Fields, FieldsContext,
-				_,_,_,_,_,_,_) }
-		->
-			{ pragma_c_gen__struct_name(ModuleName, PredName,
-				Arity, ProcId, StructName) },
-			{ Struct = pragma_c_struct(StructName,
-				Fields, FieldsContext) },
-			{ string__format("#define\tMR_ORDINARY_SLOTS\t%d\n",
-				[i(TotalSlots)], DefineStr) },
-			{ DefineComponents = [pragma_c_raw_code(DefineStr,
-				live_lvals_info(set__init))] },
-			{ NondetFrameInfo = ordinary_frame(PushMsg, TotalSlots,
-				yes(Struct)) },
-			{ AllocCode = node([
+			pragma_c_gen__struct_name(ModuleName, PredName,
+				Arity, ProcId, StructName),
+			Struct = pragma_c_struct(StructName,
+				Fields, FieldsContext),
+			string__format("#define\tMR_ORDINARY_SLOTS\t%d\n",
+				[i(TotalSlots)], DefineStr),
+			DefineComponents = [pragma_c_raw_code(DefineStr,
+				live_lvals_info(set__init))],
+			NondetFrameInfo = ordinary_frame(PushMsg, TotalSlots,
+				yes(Struct)),
+			AllocCode = node([
 				mkframe(NondetFrameInfo, OutsideResumeAddress)
 					- "Allocate stack frame",
 				pragma_c([], DefineComponents,
 					will_not_call_mercury, no, no, no, no,
 					no)
 					- ""
-			]) },
-			{ NondetPragma = yes }
+			]),
+			NondetPragma = yes
 		;
-			{ NondetFrameInfo = ordinary_frame(PushMsg, TotalSlots,
-				no) },
-			{ AllocCode = node([
+			NondetFrameInfo = ordinary_frame(PushMsg, TotalSlots,
+				no),
+			AllocCode = node([
 				mkframe(NondetFrameInfo, OutsideResumeAddress)
 					- "Allocate stack frame"
-			]) },
-			{ NondetPragma = no }
+			]),
+			NondetPragma = no
 		)
-	;
-		{ TotalSlots > 0 }
-	->
-		{ AllocCode = node([
+	; TotalSlots > 0 ->
+		AllocCode = node([
 			incr_sp(TotalSlots, PushMsg) -
 				"Allocate stack frame"
-		]) },
-		{ NondetPragma = no }
+		]),
+		NondetPragma = no
 	;
-		{ AllocCode = empty },
-		{ NondetPragma = no }
+		AllocCode = empty,
+		NondetPragma = no
 	),
-	{ FrameInfo = frame(TotalSlots, MaybeSuccipSlot, NondetPragma) },
-	{ EndComment = node([
+	FrameInfo = frame(TotalSlots, MaybeSuccipSlot, NondetPragma),
+	EndComment = node([
 		comment("End of procedure prologue") - ""
-	]) },
-	{ EntryCode =
+	]),
+	EntryCode =
 		tree(StartComment,
 		tree(LabelCode,
 		tree(AllocCode,
 		tree(SaveSuccipCode,
 		tree(TraceFillCode,
-		     EndComment)))))
-	}.
+		     EndComment))))).
 
 %---------------------------------------------------------------------------%
 
@@ -865,70 +854,60 @@
 	code_info::in, code_info::out) is det.
 
 code_gen__generate_exit(CodeModel, FrameInfo, TraceSlotInfo, BodyContext,
-		RestoreDeallocCode, ExitCode) -->
-	{ StartComment = node([
+		RestoreDeallocCode, ExitCode, !CI) :-
+	StartComment = node([
 		comment("Start of procedure epilogue") - ""
-	]) },
-	{ EndComment = node([
+	]),
+	EndComment = node([
 		comment("End of procedure epilogue") - ""
-	]) },
-	{ FrameInfo = frame(TotalSlots, MaybeSuccipSlot, NondetPragma) },
-	( { NondetPragma = yes } ->
-		{ UndefStr = "#undef\tMR_ORDINARY_SLOTS\n" },
-		{ UndefComponents = [pragma_c_raw_code(UndefStr,
-			live_lvals_info(set__init))] },
-		{ UndefCode = node([
+	]),
+	FrameInfo = frame(TotalSlots, MaybeSuccipSlot, NondetPragma),
+	( NondetPragma = yes ->
+		UndefStr = "#undef\tMR_ORDINARY_SLOTS\n",
+		UndefComponents = [pragma_c_raw_code(UndefStr,
+			live_lvals_info(set__init))],
+		UndefCode = node([
 			pragma_c([], UndefComponents,
 				will_not_call_mercury, no, no, no, no, no)
 				- ""
-		]) },
-		{ RestoreDeallocCode = empty },	% always empty for nondet code
-		{ ExitCode =
+		]),
+		RestoreDeallocCode = empty,	% always empty for nondet code
+		ExitCode =
 			tree(StartComment,
 			tree(UndefCode,
 			     EndComment))
-		}
 	;
-		code_info__get_instmap(Instmap),
-		code_info__get_arginfo(ArgModes),
-		code_info__get_headvars(HeadVars),
-		{ assoc_list__from_corresponding_lists(HeadVars, ArgModes,
-			Args)},
-		(
-			{ instmap__is_unreachable(Instmap) }
-		->
-			{ OutLvals = set__init },
-			{ FlushCode = empty }
+		code_info__get_instmap(!.CI, Instmap),
+		ArgModes = code_info__get_arginfo(!.CI),
+		HeadVars = code_info__get_headvars(!.CI),
+		assoc_list__from_corresponding_lists(HeadVars, ArgModes,
+			Args),
+		( instmap__is_unreachable(Instmap) ->
+			OutLvals = set__init,
+			FlushCode = empty
 		;
-			code_info__setup_return(Args, OutLvals, FlushCode)
+			code_info__setup_return(Args, OutLvals, FlushCode, !CI)
 		),
-		{
-			MaybeSuccipSlot = yes(SuccipSlot)
-		->
+		( MaybeSuccipSlot = yes(SuccipSlot) ->
 			RestoreSuccipCode = node([
 				assign(succip, lval(stackvar(SuccipSlot))) -
 					"restore the success ip"
 			])
 		;
 			RestoreSuccipCode = empty
-		},
-		{
-			( TotalSlots = 0 ; CodeModel = model_non )
-		->
+		),
+		( ( TotalSlots = 0 ; CodeModel = model_non ) ->
 			DeallocCode = empty
 		;
 			DeallocCode = node([
 				decr_sp(TotalSlots) - "Deallocate stack frame"
 			])
-		},
-		(
-			{ TraceSlotInfo ^ slot_trail = yes(_) },
-			{ CodeModel \= model_non }
-		->
+		),
 			(
-				{ TraceSlotInfo ^ slot_from_full =
-					yes(FromFullSlot) }
+			TraceSlotInfo ^ slot_trail = yes(_),
+			CodeModel \= model_non
 			->
+			( TraceSlotInfo ^ slot_from_full = yes(FromFullSlot) ->
 				%
 				% Generate code which prunes the ticket
 				% only if it was allocated, i.e. only if
@@ -941,56 +920,55 @@
 				% copy in the success epilogue and one copy
 				% in the failure epilogue
 				%
-				{ FromFullSlotLval =
+				FromFullSlotLval =
 					llds__stack_slot_num_to_lval(
-						CodeModel, FromFullSlot) },
-				code_info__get_next_label(SkipLabel),
-				code_info__get_next_label(SkipLabelCopy),
-				{ PruneTraceTicketCode = node([
+						CodeModel, FromFullSlot),
+				code_info__get_next_label(SkipLabel, !CI),
+				code_info__get_next_label(SkipLabelCopy, !CI),
+				PruneTraceTicketCode = node([
 					if_val(unop(not,
 						lval(FromFullSlotLval)),
 						label(SkipLabel)) - "",
 					prune_ticket - "prune retry ticket",
 					label(SkipLabel) - ""
-				]) },
-				{ PruneTraceTicketCodeCopy = node([
+				]),
+				PruneTraceTicketCodeCopy = node([
 					if_val(unop(not,
 						lval(FromFullSlotLval)),
 						label(SkipLabelCopy)) - "",
 					prune_ticket - "prune retry ticket",
 					label(SkipLabelCopy) - ""
-				]) }
+				])
 			;
-				{ PruneTraceTicketCode = node([
+				PruneTraceTicketCode = node([
 					prune_ticket - "prune retry ticket"
-				]) },
-				{ PruneTraceTicketCodeCopy =
-					PruneTraceTicketCode }
+				]),
+				PruneTraceTicketCodeCopy =
+					PruneTraceTicketCode
 			)
 		;
-			{ PruneTraceTicketCode = empty },
-			{ PruneTraceTicketCodeCopy = empty }
+			PruneTraceTicketCode = empty,
+			PruneTraceTicketCodeCopy = empty
 		),
 
-		{ RestoreDeallocCode =
+		RestoreDeallocCode =
 			tree(RestoreSuccipCode,
 			tree(PruneTraceTicketCode,
-			     DeallocCode))
-		},
-		{ RestoreDeallocCodeCopy =
+			     DeallocCode)),
+		RestoreDeallocCodeCopy =
 			tree(RestoreSuccipCode,
 			tree(PruneTraceTicketCodeCopy,
-			     DeallocCode))
-		},
+			     DeallocCode)),
 
-		code_info__get_maybe_trace_info(MaybeTraceInfo),
-		( { MaybeTraceInfo = yes(TraceInfo) } ->
+		code_info__get_maybe_trace_info(!.CI, MaybeTraceInfo),
+		(
+			MaybeTraceInfo = yes(TraceInfo),
 				% XXX A context that gives the end of the
 				% procedure definition would be better than
 				% CallContext.
 			trace__generate_external_event_code(exit, TraceInfo,
-				BodyContext, MaybeExitExternalInfo),
-			{
+				BodyContext, MaybeExitExternalInfo, !CI),
+			(
 				MaybeExitExternalInfo = yes(ExitExternalInfo),
 				ExitExternalInfo = external_event_info(
 					_, TypeInfoDatas, TraceExitCode)
@@ -998,9 +976,9 @@
 				MaybeExitExternalInfo = no,
 				TypeInfoDatas = map__init,
 				TraceExitCode = empty
-			},
-			{ map__values(TypeInfoDatas, TypeInfoLocnSets) },
-			{ FindBaseLvals = lambda([Lval::out] is nondet, (
+			),
+			map__values(TypeInfoDatas, TypeInfoLocnSets),
+			FindBaseLvals = (pred(Lval::out) is nondet :-
 				list__member(LocnSet, TypeInfoLocnSets),
 				set__member(Locn, LocnSet),
 				(
@@ -1008,64 +986,61 @@
 				;
 					Locn = indirect(Lval, _)
 				)
-			)) },
-			{ solutions(FindBaseLvals, TypeInfoLvals) },
-			{ set__insert_list(OutLvals, TypeInfoLvals,
-				LiveLvals) }
-		;
-			{ TraceExitCode = empty },
-			{ LiveLvals = OutLvals }
+			),
+			solutions(FindBaseLvals, TypeInfoLvals),
+			set__insert_list(OutLvals, TypeInfoLvals,
+				LiveLvals)
+		;
+			MaybeTraceInfo = no,
+			TraceExitCode = empty,
+			LiveLvals = OutLvals
 		),
 
 		(
-			{ CodeModel = model_det },
-			{ SuccessCode = node([
+			CodeModel = model_det,
+			SuccessCode = node([
 				livevals(LiveLvals) - "",
 				goto(succip) - "Return from procedure call"
-			]) },
-			{ AllSuccessCode =
+			]),
+			AllSuccessCode =
 				tree(TraceExitCode,
 				tree(RestoreDeallocCodeCopy,
 				     SuccessCode))
-			}
 		;
-			{ CodeModel = model_semi },
-			{ set__insert(LiveLvals, reg(r, 1), SuccessLiveRegs) },
-			{ SuccessCode = node([
+			CodeModel = model_semi,
+			set__insert(LiveLvals, reg(r, 1), SuccessLiveRegs),
+			SuccessCode = node([
 				assign(reg(r, 1), const(true)) - "Succeed",
 				livevals(SuccessLiveRegs) - "",
 				goto(succip) - "Return from procedure call"
-			]) },
-			{ AllSuccessCode =
+			]),
+			AllSuccessCode =
 				tree(TraceExitCode,
 				tree(RestoreDeallocCodeCopy,
 				     SuccessCode))
-			}
 		;
-			{ CodeModel = model_non },
-			{ MaybeTraceInfo = yes(TraceInfo2) ->
+			CodeModel = model_non,
+			( MaybeTraceInfo = yes(TraceInfo2) ->
 				trace__maybe_setup_redo_event(TraceInfo2,
 					SetupRedoCode)
 			;
 				SetupRedoCode = empty
-			},
-			{ SuccessCode = node([
+			),
+			SuccessCode = node([
 				livevals(LiveLvals) - "",
 				goto(do_succeed(no))
 					- "Return from procedure call"
-			]) },
-			{ AllSuccessCode =
+			]),
+			AllSuccessCode =
 				tree(SetupRedoCode,
 				tree(TraceExitCode,
 				     SuccessCode))
-			}
 		),
-		{ ExitCode =
+		ExitCode =
 			tree(StartComment,
 			tree(FlushCode,
 			tree(AllSuccessCode,
 			     EndComment)))
-		}
 	).
 
 %---------------------------------------------------------------------------%
@@ -1082,7 +1057,7 @@
 		IsAtomic = no
 	),
 	code_info__pre_goal_update(GoalInfo, IsAtomic, !CI),
-	code_info__get_instmap(Instmap, !CI),
+	code_info__get_instmap(!.CI, Instmap),
 	( instmap__is_reachable(Instmap) ->
 		goal_info_get_code_model(GoalInfo, CodeModel),
 
@@ -1123,11 +1098,11 @@
 		(
 			goal_info_get_features(GoalInfo, Features),
 			set__member(call_table_gen, Features),
-			code_info__get_proc_info(ProcInfo, !CI),
+			code_info__get_proc_info(!.CI, ProcInfo),
 			proc_info_get_call_table_tip(ProcInfo,
 				MaybeCallTableVar),
 			MaybeCallTableVar = yes(CallTableVar),
-			code_info__get_maybe_trace_info(yes(_), !CI)
+			code_info__get_maybe_trace_info(!.CI, yes(_))
 		->
 			code_info__save_variables_on_stack([CallTableVar],
 				SaveCode, !CI),
@@ -1149,52 +1124,54 @@
 :- pred code_gen__generate_goal_2(hlds_goal_expr::in, hlds_goal_info::in,
 	code_model::in, code_tree::out, code_info::in, code_info::out) is det.
 
-code_gen__generate_goal_2(unify(_, _, _, Uni, _), GoalInfo, CodeModel, Code)
-		-->
-	unify_gen__generate_unification(CodeModel, Uni, GoalInfo, Code).
-code_gen__generate_goal_2(conj(Goals), _GoalInfo, CodeModel, Code) -->
-	code_gen__generate_goals(Goals, CodeModel, Code).
-code_gen__generate_goal_2(par_conj(Goals), GoalInfo, CodeModel, Code) -->
-	par_conj_gen__generate_par_conj(Goals, GoalInfo, CodeModel, Code).
-code_gen__generate_goal_2(disj(Goals), GoalInfo, CodeModel, Code) -->
-	disj_gen__generate_disj(CodeModel, Goals, GoalInfo, Code).
-code_gen__generate_goal_2(not(Goal), GoalInfo, CodeModel, Code) -->
-	ite_gen__generate_negation(CodeModel, Goal, GoalInfo, Code).
+code_gen__generate_goal_2(unify(_, _, _, Uni, _), GoalInfo, CodeModel, Code,
+		!CI) :-
+	unify_gen__generate_unification(CodeModel, Uni, GoalInfo, Code, !CI).
+code_gen__generate_goal_2(conj(Goals), _GoalInfo, CodeModel, Code, !CI) :-
+	code_gen__generate_goals(Goals, CodeModel, Code, !CI).
+code_gen__generate_goal_2(par_conj(Goals), GoalInfo, CodeModel, Code, !CI) :-
+	par_conj_gen__generate_par_conj(Goals, GoalInfo, CodeModel, Code, !CI).
+code_gen__generate_goal_2(disj(Goals), GoalInfo, CodeModel, Code, !CI) :-
+	disj_gen__generate_disj(CodeModel, Goals, GoalInfo, Code, !CI).
+code_gen__generate_goal_2(not(Goal), GoalInfo, CodeModel, Code, !CI) :-
+	ite_gen__generate_negation(CodeModel, Goal, GoalInfo, Code, !CI).
 code_gen__generate_goal_2(if_then_else(_Vars, Cond, Then, Else),
-		GoalInfo, CodeModel, Code) -->
-	ite_gen__generate_ite(CodeModel, Cond, Then, Else, GoalInfo, Code).
+		GoalInfo, CodeModel, Code, !CI) :-
+	ite_gen__generate_ite(CodeModel, Cond, Then, Else, GoalInfo, Code,
+		!CI).
 code_gen__generate_goal_2(switch(Var, CanFail, CaseList),
-		GoalInfo, CodeModel, Code) -->
+		GoalInfo, CodeModel, Code, !CI) :-
 	switch_gen__generate_switch(CodeModel, Var, CanFail, CaseList,
-		GoalInfo, Code).
-code_gen__generate_goal_2(some(_Vars, _, Goal), _GoalInfo, CodeModel, Code) -->
-	commit_gen__generate_commit(CodeModel, Goal, Code).
+		GoalInfo, Code, !CI).
+code_gen__generate_goal_2(some(_Vars, _, Goal), _GoalInfo, CodeModel, Code,
+		!CI) :-
+	commit_gen__generate_commit(CodeModel, Goal, Code, !CI).
 code_gen__generate_goal_2(generic_call(GenericCall, Args, Modes, Det),
-		GoalInfo, CodeModel, Code) -->
+		GoalInfo, CodeModel, Code, !CI) :-
 	call_gen__generate_generic_call(CodeModel, GenericCall, Args,
-		Modes, Det, GoalInfo, Code).
+		Modes, Det, GoalInfo, Code, !CI).
 code_gen__generate_goal_2(call(PredId, ProcId, Args, BuiltinState, _,_),
-		GoalInfo, CodeModel, Code) -->
-	( { BuiltinState = not_builtin } ->
+		GoalInfo, CodeModel, Code, !CI) :-
+	( BuiltinState = not_builtin ->
 		call_gen__generate_call(CodeModel, PredId, ProcId, Args,
-			GoalInfo, Code)
+			GoalInfo, Code, !CI)
 	;
 		call_gen__generate_builtin(CodeModel, PredId, ProcId, Args,
-			Code)
+			Code, !CI)
 	).
 code_gen__generate_goal_2(foreign_proc(Attributes, PredId, ProcId,
 		Args, ArgNames, OrigArgTypes, PragmaCode),
-		GoalInfo, CodeModel, Code) -->
-	( { foreign_language(Attributes, c) } ->
+		GoalInfo, CodeModel, Code, !CI) :-
+	( foreign_language(Attributes, c) ->
 		pragma_c_gen__generate_pragma_c_code(CodeModel, Attributes,
 			PredId, ProcId, Args, ArgNames, OrigArgTypes,
-			GoalInfo, PragmaCode, Code)
+			GoalInfo, PragmaCode, Code, !CI)
 	;
-		{ error("code_gen__generate_goal_2: foreign code other than C unexpected") }
+		error("code_gen__generate_goal_2: foreign code other than C unexpected")
 	).
-code_gen__generate_goal_2(shorthand(_), _, _, _) -->
+code_gen__generate_goal_2(shorthand(_), _, _, _, !CI) :-
 	% these should have been expanded out by now
-	{ error("code_gen__generate_goal_2: unexpected shorthand") }.
+	error("code_gen__generate_goal_2: unexpected shorthand").
 
 %---------------------------------------------------------------------------%
 
@@ -1205,17 +1182,17 @@
 :- pred code_gen__generate_goals(hlds_goals::in, code_model::in,
 	code_tree::out, code_info::in, code_info::out) is det.
 
-code_gen__generate_goals([], _, empty) --> [].
-code_gen__generate_goals([Goal | Goals], CodeModel, Instr) -->
-	code_gen__generate_goal(CodeModel, Goal, Instr1),
-	code_info__get_instmap(Instmap),
+code_gen__generate_goals([], _, empty, !CI).
+code_gen__generate_goals([Goal | Goals], CodeModel, Instr, !CI) :-
+	code_gen__generate_goal(CodeModel, Goal, Instr1, !CI),
+	code_info__get_instmap(!.CI, Instmap),
 	(
-		{ instmap__is_unreachable(Instmap) }
+		instmap__is_unreachable(Instmap)
 	->
-		{ Instr = Instr1 }
+		Instr = Instr1
 	;
-		code_gen__generate_goals(Goals, CodeModel, Instr2),
-		{ Instr = tree(Instr1, Instr2) }
+		code_gen__generate_goals(Goals, CodeModel, Instr2, !CI),
+		Instr = tree(Instr1, Instr2)
 	).
 
 %---------------------------------------------------------------------------%
Index: code_info.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/code_info.m,v
retrieving revision 1.279
diff -u -b -r1.279 code_info.m
--- code_info.m	20 Oct 2003 07:29:04 -0000	1.279
+++ code_info.m	22 Oct 2003 05:06:39 -0000
@@ -93,40 +93,33 @@
 	code_info::out) is det.
 
 		% Get the globals table.
-:- pred code_info__get_globals(globals::out,
-	code_info::in, code_info::out) is det.
+:- pred code_info__get_globals(code_info::in, globals::out) is det.
 
 		% Get the HLDS of the entire module.
-:- pred code_info__get_module_info(module_info::out,
-	code_info::in, code_info::out) is det.
+:- pred code_info__get_module_info(code_info::in, module_info::out) is det.
 
 		% Get the id of the predicate we are generating code for.
-:- pred code_info__get_pred_id(pred_id::out,
-	code_info::in, code_info::out) is det.
+:- pred code_info__get_pred_id(code_info::in, pred_id::out) is det.
 
 		% Get the id of the procedure we are generating code for.
-:- pred code_info__get_proc_id(proc_id::out,
-	code_info::in, code_info::out) is det.
+:- pred code_info__get_proc_id(code_info::in, proc_id::out) is det.
 
 		% Get the HLDS of the procedure we are generating code for.
-:- pred code_info__get_proc_info(proc_info::out,
-	code_info::in, code_info::out) is det.
+:- pred code_info__get_proc_info(code_info::in, proc_info::out) is det.
 
 		% Get the HLDS of the predicate containing the procedure
 		% we are generating code for.
-:- pred code_info__get_pred_info(pred_info::out,
-	code_info::in, code_info::out) is det.
+:- pred code_info__get_pred_info(code_info::in, pred_info::out) is det.
 
 		% Get the variables for the current procedure.
-:- pred code_info__get_varset(prog_varset::out,
-	code_info::in, code_info::out) is det.
+:- pred code_info__get_varset(code_info::in, prog_varset::out) is det.
 
-:- pred code_info__get_maybe_trace_info(maybe(trace_info)::out,
-	code_info::in, code_info::out) is det.
+:- pred code_info__get_maybe_trace_info(code_info::in, maybe(trace_info)::out)
+	is det.
 
 		% Get the set of currently forward-live variables.
-:- pred code_info__get_forward_live_vars(set(prog_var)::out,
-	code_info::in, code_info::out) is det.
+:- pred code_info__get_forward_live_vars(code_info::in, set(prog_var)::out)
+	is det.
 
 		% Set the set of currently forward-live variables.
 :- pred code_info__set_forward_live_vars(set(prog_var)::in,
@@ -134,8 +127,7 @@
 
 		% Get the table mapping variables to the current
 		% instantiation states.
-:- pred code_info__get_instmap(instmap::out,
-	code_info::in, code_info::out) is det.
+:- pred code_info__get_instmap(code_info::in, instmap::out) is det.
 
 		% Set the table mapping variables to the current
 		% instantiation states.
@@ -143,36 +135,32 @@
 	code_info::in, code_info::out) is det.
 
 		% The number of the last local label allocated.
-:- pred code_info__get_label_counter(counter::out,
-	code_info::in, code_info::out) is det.
+:- pred code_info__get_label_counter(code_info::in, counter::out) is det.
 
 		% Get the flag that indicates whether succip is used or not.
-:- pred code_info__get_succip_used(bool::out,
-	code_info::in, code_info::out) is det.
+:- pred code_info__get_succip_used(code_info::in, bool::out) is det.
 
 		% Get the label layout information created by tracing
 		% during code generation.
-:- pred code_info__get_layout_info(map(label, internal_layout_info)::out,
-	code_info::in, code_info::out) is det.
+:- pred code_info__get_layout_info(code_info::in,
+	map(label, internal_layout_info)::out) is det.
 
 		% Get the global static data structures that have
 		% been created during code generation for closure layouts.
-:- pred code_info__get_closure_layouts(list(comp_gen_c_data)::out,
-	code_info::in, code_info::out) is det.
+:- pred code_info__get_closure_layouts(code_info::in,
+	list(comp_gen_c_data)::out) is det.
 
-:- pred code_info__get_max_reg_in_use_at_trace(int::out,
-	code_info::in, code_info::out) is det.
+:- pred code_info__get_max_reg_in_use_at_trace(code_info::in, int::out) is det.
 
 :- pred code_info__set_max_reg_in_use_at_trace(int::in,
 	code_info::in, code_info::out) is det.
 
 		% Get the flag which is true iff the procedure has so far
 		% emitted code that creates a temporary nondet stack frame.
-:- pred code_info__get_created_temp_frame(bool::out,
-	code_info::in, code_info::out) is det.
+:- pred code_info__get_created_temp_frame(code_info::in, bool::out) is det.
 
-:- pred code_info__get_static_cell_info(static_cell_info::out,
-	code_info::in, code_info::out) is det.
+:- pred code_info__get_static_cell_info(code_info::in, static_cell_info::out)
+	is det.
 
 :- pred code_info__set_static_cell_info(static_cell_info::in,
 	code_info::in, code_info::out) is det.
@@ -181,35 +169,29 @@
 
 :- implementation.
 
-:- pred code_info__get_var_slot_count(int::out,
-	code_info::in, code_info::out) is det.
+:- pred code_info__get_var_slot_count(code_info::in, int::out) is det.
 
 :- pred code_info__set_maybe_trace_info(maybe(trace_info)::in,
 	code_info::in, code_info::out) is det.
 
-:- pred code_info__get_opt_no_return_calls(bool::out,
-	code_info::in, code_info::out) is det.
+:- pred code_info__get_opt_no_return_calls(code_info::in, bool::out) is det.
 
-:- pred code_info__get_zombies(set(prog_var)::out,
-	code_info::in, code_info::out) is det.
+:- pred code_info__get_zombies(code_info::in, set(prog_var)::out) is det.
 
 :- pred code_info__set_zombies(set(prog_var)::in,
 	code_info::in, code_info::out) is det.
 
-:- pred code_info__get_var_locn_info(var_locn_info::out,
-	code_info::in, code_info::out) is det.
+:- pred code_info__get_var_locn_info(code_info::in, var_locn_info::out) is det.
 
 :- pred code_info__set_var_locn_info(var_locn_info::in,
 	code_info::in, code_info::out) is det.
 
-:- pred code_info__get_temps_in_use(set(lval)::out,
-	code_info::in, code_info::out) is det.
+:- pred code_info__get_temps_in_use(code_info::in, set(lval)::out) is det.
 
 :- pred code_info__set_temps_in_use(set(lval)::in,
 	code_info::in, code_info::out) is det.
 
-:- pred code_info__get_fail_info(fail_info::out,
-	code_info::in, code_info::out) is det.
+:- pred code_info__get_fail_info(code_info::in, fail_info::out) is det.
 
 :- pred code_info__set_fail_info(fail_info::in,
 	code_info::in, code_info::out) is det.
@@ -223,14 +205,13 @@
 :- pred code_info__set_layout_info(map(label, internal_layout_info)::in,
 	code_info::in, code_info::out) is det.
 
-:- pred code_info__get_max_temp_slot_count(int::out,
-	code_info::in, code_info::out) is det.
+:- pred code_info__get_max_temp_slot_count(code_info::in, int::out) is det.
 
 :- pred code_info__set_max_temp_slot_count(int::in,
 	code_info::in, code_info::out) is det.
 
-:- pred code_info__get_temp_content_map(map(lval, slot_contents)::out,
-	code_info::in, code_info::out) is det.
+:- pred code_info__get_temp_content_map(code_info::in,
+	map(lval, slot_contents)::out) is det.
 
 :- pred code_info__set_temp_content_map(map(lval, slot_contents)::in,
 	code_info::in, code_info::out) is det.
@@ -238,8 +219,7 @@
 :- pred code_info__set_closure_layouts(list(comp_gen_c_data)::in,
 	code_info::in, code_info::out) is det.
 
-:- pred code_info__get_closure_seq_counter(counter::out,
-	code_info::in, code_info::out) is det.
+:- pred code_info__get_closure_seq_counter(code_info::in, counter::out) is det.
 
 :- pred code_info__set_closure_seq_counter(counter::in,
 	code_info::in, code_info::out) is det.
@@ -463,82 +443,106 @@
 	code_info::in, code_info::out) is det.
 
 code_info__init_maybe_trace_info(TraceLevel, Globals, ModuleInfo, PredInfo,
-		ProcInfo, TraceSlotInfo) -->
-	( { eff_trace_level_is_none(PredInfo, ProcInfo, TraceLevel) = no } ->
+		ProcInfo, TraceSlotInfo, !CI) :-
+	( eff_trace_level_is_none(PredInfo, ProcInfo, TraceLevel) = no ->
 		trace__setup(ModuleInfo, PredInfo, ProcInfo, Globals,
-			TraceSlotInfo, TraceInfo),
-		code_info__set_maybe_trace_info(yes(TraceInfo))
+			TraceSlotInfo, TraceInfo, !CI),
+		code_info__set_maybe_trace_info(yes(TraceInfo), !CI)
 	;
-		{ TraceSlotInfo = trace_slot_info(no, no, no, no, no) }
+		TraceSlotInfo = trace_slot_info(no, no, no, no, no)
 	).
 
 %---------------------------------------------------------------------------%
 
-code_info__get_globals(CI^code_info_static^globals, CI, CI).
-code_info__get_module_info(CI^code_info_static^module_info, CI, CI).
-code_info__get_pred_id(CI^code_info_static^pred_id, CI, CI).
-code_info__get_proc_id(CI^code_info_static^proc_id, CI, CI).
-code_info__get_proc_info(CI^code_info_static^proc_info, CI, CI).
-code_info__get_pred_info(CI^code_info_static^pred_info, CI, CI).
-code_info__get_varset(CI^code_info_static^varset, CI, CI).
-code_info__get_var_slot_count(CI^code_info_static^var_slot_count, CI, CI).
-code_info__get_maybe_trace_info(CI^code_info_static^maybe_trace_info, CI, CI).
-code_info__get_opt_no_return_calls(CI^code_info_static^opt_no_resume_calls,
-	CI, CI).
-code_info__get_forward_live_vars(CI^code_info_loc_dep^forward_live_vars,
-	CI, CI).
-code_info__get_instmap(CI^code_info_loc_dep^instmap, CI, CI).
-code_info__get_zombies(CI^code_info_loc_dep^zombies, CI, CI).
-code_info__get_var_locn_info(CI^code_info_loc_dep^var_locn_info, CI, CI).
-code_info__get_temps_in_use(CI^code_info_loc_dep^temps_in_use, CI, CI).
-code_info__get_fail_info(CI^code_info_loc_dep^fail_info, CI, CI).
-code_info__get_label_counter(CI^code_info_persistent^label_num_src, CI, CI).
-code_info__get_succip_used(CI^code_info_persistent^store_succip, CI, CI).
-code_info__get_layout_info(CI^code_info_persistent^label_info, CI, CI).
-code_info__get_max_temp_slot_count(CI^code_info_persistent^stackslot_max,
-	CI, CI).
-code_info__get_temp_content_map(CI^code_info_persistent^temp_contents, CI, CI).
-code_info__get_closure_seq_counter(CI^code_info_persistent^closure_layout_seq,
-	CI, CI).
-code_info__get_closure_layouts(CI^code_info_persistent^closure_layouts,
-	CI, CI).
-code_info__get_max_reg_in_use_at_trace(CI^code_info_persistent^max_reg_used,
-	CI, CI).
-code_info__get_created_temp_frame(CI^code_info_persistent^created_temp_frame,
-	CI, CI).
-code_info__get_static_cell_info(CI^code_info_persistent^static_cell_info,
-	CI, CI).
+code_info__get_globals(CI,
+	CI ^ code_info_static ^ globals).
+code_info__get_module_info(CI,
+	CI ^ code_info_static ^ module_info).
+code_info__get_pred_id(CI,
+	CI ^ code_info_static ^ pred_id).
+code_info__get_proc_id(CI,
+	CI ^ code_info_static ^ proc_id).
+code_info__get_proc_info(CI,
+	CI ^ code_info_static ^ proc_info).
+code_info__get_pred_info(CI,
+	CI ^ code_info_static ^ pred_info).
+code_info__get_varset(CI,
+	CI ^ code_info_static ^ varset).
+code_info__get_var_slot_count(CI,
+	CI ^ code_info_static ^ var_slot_count).
+code_info__get_maybe_trace_info(CI,
+	CI ^ code_info_static ^ maybe_trace_info).
+code_info__get_opt_no_return_calls(CI,
+	CI ^ code_info_static ^ opt_no_resume_calls).
+code_info__get_forward_live_vars(CI,
+	CI ^ code_info_loc_dep ^ forward_live_vars).
+code_info__get_instmap(CI,
+	CI ^ code_info_loc_dep ^ instmap).
+code_info__get_zombies(CI,
+	CI ^ code_info_loc_dep ^ zombies).
+code_info__get_var_locn_info(CI,
+	CI ^ code_info_loc_dep ^ var_locn_info).
+code_info__get_temps_in_use(CI,
+	CI ^ code_info_loc_dep ^ temps_in_use).
+code_info__get_fail_info(CI,
+	CI ^ code_info_loc_dep ^ fail_info).
+code_info__get_label_counter(CI,
+	CI ^ code_info_persistent ^ label_num_src).
+code_info__get_succip_used(CI,
+	CI ^ code_info_persistent ^ store_succip).
+code_info__get_layout_info(CI,
+	CI ^ code_info_persistent ^ label_info).
+code_info__get_max_temp_slot_count(CI,
+	CI ^ code_info_persistent ^ stackslot_max).
+code_info__get_temp_content_map(CI,
+	CI ^ code_info_persistent ^ temp_contents).
+code_info__get_closure_seq_counter(CI,
+	CI ^ code_info_persistent ^ closure_layout_seq).
+code_info__get_closure_layouts(CI,
+	CI ^ code_info_persistent ^ closure_layouts).
+code_info__get_max_reg_in_use_at_trace(CI,
+	CI ^ code_info_persistent ^ max_reg_used).
+code_info__get_created_temp_frame(CI,
+	CI ^ code_info_persistent ^ created_temp_frame).
+code_info__get_static_cell_info(CI,
+	CI ^ code_info_persistent ^ static_cell_info).
 
 %---------------------------------------------------------------------------%
 
 code_info__set_maybe_trace_info(TI, CI,
-	CI^code_info_static^maybe_trace_info := TI).
+	CI ^ code_info_static ^ maybe_trace_info := TI).
 code_info__set_forward_live_vars(LV, CI,
-	CI^code_info_loc_dep^forward_live_vars := LV).
-code_info__set_instmap(IM, CI, CI^code_info_loc_dep^instmap := IM).
-code_info__set_zombies(Zs, CI, CI^code_info_loc_dep^zombies := Zs).
+	CI ^ code_info_loc_dep ^ forward_live_vars := LV).
+code_info__set_instmap(IM, CI,
+	CI ^ code_info_loc_dep ^ instmap := IM).
+code_info__set_zombies(Zs, CI,
+	CI ^ code_info_loc_dep ^ zombies := Zs).
 code_info__set_var_locn_info(EI, CI,
-	CI^code_info_loc_dep^var_locn_info := EI).
-code_info__set_temps_in_use(TI, CI, CI^code_info_loc_dep^temps_in_use := TI).
-code_info__set_fail_info(FI, CI, CI^code_info_loc_dep^fail_info := FI).
+	CI ^ code_info_loc_dep ^ var_locn_info := EI).
+code_info__set_temps_in_use(TI, CI,
+	CI ^ code_info_loc_dep ^ temps_in_use := TI).
+code_info__set_fail_info(FI, CI,
+	CI ^ code_info_loc_dep ^ fail_info := FI).
 code_info__set_label_counter(LC, CI,
-	CI^code_info_persistent^label_num_src := LC).
-code_info__set_succip_used(SU, CI, CI^code_info_persistent^store_succip := SU).
-code_info__set_layout_info(LI, CI, CI^code_info_persistent^label_info := LI).
+	CI ^ code_info_persistent ^ label_num_src := LC).
+code_info__set_succip_used(SU, CI,
+	CI ^ code_info_persistent ^ store_succip := SU).
+code_info__set_layout_info(LI, CI,
+	CI ^ code_info_persistent ^ label_info := LI).
 code_info__set_max_temp_slot_count(TM, CI,
-	CI^code_info_persistent^stackslot_max := TM).
+	CI ^ code_info_persistent ^ stackslot_max := TM).
 code_info__set_temp_content_map(CM, CI,
-	CI^code_info_persistent^temp_contents := CM).
+	CI ^ code_info_persistent ^ temp_contents := CM).
 code_info__set_closure_seq_counter(CLS, CI,
-	CI^code_info_persistent^closure_layout_seq := CLS).
+	CI ^ code_info_persistent ^ closure_layout_seq := CLS).
 code_info__set_closure_layouts(CG, CI,
-	CI^code_info_persistent^closure_layouts := CG).
+	CI ^ code_info_persistent ^ closure_layouts := CG).
 code_info__set_max_reg_in_use_at_trace(MR, CI,
-	CI^code_info_persistent^max_reg_used := MR).
+	CI ^ code_info_persistent ^ max_reg_used := MR).
 code_info__set_created_temp_frame(MR, CI,
-	CI^code_info_persistent^created_temp_frame := MR).
+	CI ^ code_info_persistent ^ created_temp_frame := MR).
 code_info__set_static_cell_info(SCI, CI,
-	CI^code_info_persistent^static_cell_info := SCI).
+	CI ^ code_info_persistent ^ static_cell_info := SCI).
 
 %---------------------------------------------------------------------------%
 %---------------------------------------------------------------------------%
@@ -548,81 +552,66 @@
 :- interface.
 
 		% Get the hlds mapping from variables to stack slots
-:- pred code_info__get_stack_slots(stack_slots, code_info, code_info).
-:- mode code_info__get_stack_slots(out, in, out) is det.
+:- pred code_info__get_stack_slots(code_info::in, stack_slots::out) is det.
 
 		% Get the table that contains advice about where
 		% variables should be put.
-:- pred code_info__get_follow_var_map(follow_vars_map, code_info, code_info).
-:- mode code_info__get_follow_var_map(out, in, out) is det.
+:- pred code_info__get_follow_var_map(code_info::in, follow_vars_map::out)
+	is det.
 
 		% Get the integer that gives the number of the next
 		% non-reserved register.
-:- pred code_info__get_next_non_reserved(int, code_info, code_info).
-:- mode code_info__get_next_non_reserved(out, in, out) is det.
+:- pred code_info__get_next_non_reserved(code_info::in, int::out) is det.
 
 		% Set the table that contains advice about where
 		% variables should be put.
-:- pred code_info__set_follow_vars(follow_vars, code_info, code_info).
-:- mode code_info__set_follow_vars(in, in, out) is det.
+:- pred code_info__set_follow_vars(follow_vars::in,
+	code_info::in, code_info::out) is det.
 
 	% code_info__pre_goal_update(GoalInfo, Atomic, OldCodeInfo, NewCodeInfo)
 	% updates OldCodeInfo to produce NewCodeInfo with the changes
 	% specified by GoalInfo.
-:- pred code_info__pre_goal_update(hlds_goal_info, bool, code_info, code_info).
-:- mode code_info__pre_goal_update(in, in, in, out) is det.
+:- pred code_info__pre_goal_update(hlds_goal_info::in, bool::in,
+	code_info::in, code_info::out) is det.
 
 	% code_info__post_goal_update(GoalInfo, OldCodeInfo, NewCodeInfo)
 	% updates OldCodeInfo to produce NewCodeInfo with the changes described
 	% by GoalInfo.
-:- pred code_info__post_goal_update(hlds_goal_info, code_info, code_info).
-:- mode code_info__post_goal_update(in, in, out) is det.
+:- pred code_info__post_goal_update(hlds_goal_info::in,
+	code_info::in, code_info::out) is det.
 
 	% Find out whether the body of the current procedure should use
 	% typeinfo liveness.
-:- pred code_info__body_typeinfo_liveness(bool::out,
-	code_info::in, code_info::out) is det.
+:- func code_info__body_typeinfo_liveness(code_info) = bool.
 
 	% Find out the type of the given variable.
-:- pred code_info__variable_type(prog_var, type, code_info, code_info).
-:- mode code_info__variable_type(in, out, in, out) is det.
+:- func code_info__variable_type(code_info, prog_var) = (type).
 
-:- pred code_info__lookup_type_defn(type, hlds_type_defn,
-	code_info, code_info).
-:- mode code_info__lookup_type_defn(in, out, in, out) is det.
+:- func code_info__lookup_type_defn(code_info, (type)) = hlds_type_defn.
 
 	% Given a constructor id, and a variable (so that we can work out the
 	% type of the constructor), determine correct tag (representation)
 	% of that constructor.
-:- pred code_info__cons_id_to_tag(prog_var, cons_id, cons_tag,
-		code_info, code_info).
-:- mode code_info__cons_id_to_tag(in, in, out, in, out) is det.
+:- func code_info__cons_id_to_tag(code_info, prog_var, cons_id) = cons_tag.
 
 	% Get the code model of the current procedure.
-:- pred code_info__get_proc_model(code_model, code_info, code_info).
-:- mode code_info__get_proc_model(out, in, out) is det.
+:- func code_info__get_proc_model(code_info) = code_model.
 
 	% Get the list of the head variables of the current procedure.
-:- pred code_info__get_headvars(list(prog_var), code_info, code_info).
-:- mode code_info__get_headvars(out, in, out) is det.
+:- func code_info__get_headvars(code_info) = list(prog_var).
 
 	% Get the call argument information for the current procedure
-:- pred code_info__get_arginfo(list(arg_info), code_info, code_info).
-:- mode code_info__get_arginfo(out, in, out) is det.
+:- func code_info__get_arginfo(code_info) = list(arg_info).
 
 	% Get the call argument info for a given mode of a given predicate
-:- pred code_info__get_pred_proc_arginfo(pred_id, proc_id, list(arg_info),
-	code_info, code_info).
-:- mode code_info__get_pred_proc_arginfo(in, in, out, in, out) is det.
+:- func code_info__get_pred_proc_arginfo(code_info, pred_id, proc_id)
+	= list(arg_info).
 
 	% Get the set of variables currently needed by the resume
 	% points of enclosing goals.
-:- pred code_info__current_resume_point_vars(set(prog_var),
-		code_info, code_info).
-:- mode code_info__current_resume_point_vars(out, in, out) is det.
+:- func code_info__current_resume_point_vars(code_info) = set(prog_var).
 
-:- pred code_info__variable_to_string(prog_var, string, code_info, code_info).
-:- mode code_info__variable_to_string(in, out, in, out) is det.
+:- func code_info__variable_to_string(code_info, prog_var) = string.
 
 	% Create a code address which holds the address of the specified
 	% procedure.
@@ -642,32 +631,28 @@
 	% the same C function. However, at the time of code generation,
 	% we do not yet know which procedures will be put into the same
 	% C functions, and so we cannot do this.
-:- pred code_info__make_entry_label(module_info, pred_id, proc_id, bool,
-	code_addr, code_info, code_info).
-:- mode code_info__make_entry_label(in, in, in, in, out, in, out) is det.
+:- func code_info__make_entry_label(code_info, module_info, pred_id, proc_id,
+	bool) = code_addr.
 
 	% Generate the next local label in sequence.
-:- pred code_info__get_next_label(label, code_info, code_info).
-:- mode code_info__get_next_label(out, in, out) is det.
+:- pred code_info__get_next_label(label::out, code_info::in, code_info::out)
+	is det.
 
 	% Note that the succip slot is used, and thus cannot be
 	% optimized away.
-:- pred code_info__succip_is_used(code_info, code_info).
-:- mode code_info__succip_is_used(in, out) is det.
+:- pred code_info__succip_is_used(code_info::in, code_info::out) is det.
 
-:- pred code_info__add_trace_layout_for_label(label, term__context,
-	trace_port, bool, goal_path, layout_label_info, code_info, code_info).
-:- mode code_info__add_trace_layout_for_label(in, in, in, in, in, in, in, out)
-	is det.
+:- pred code_info__add_trace_layout_for_label(label::in, term__context::in,
+	trace_port::in, bool::in, goal_path::in, layout_label_info::in,
+	code_info::in, code_info::out) is det.
 
-:- pred code_info__get_cur_proc_label(proc_label, code_info, code_info).
-:- mode code_info__get_cur_proc_label(out, in, out) is det.
+:- pred code_info__get_cur_proc_label(code_info::in, proc_label::out) is det.
 
-:- pred code_info__get_next_closure_seq_no(int, code_info, code_info).
-:- mode code_info__get_next_closure_seq_no(out, in, out) is det.
+:- pred code_info__get_next_closure_seq_no(int::out,
+	code_info::in, code_info::out) is det.
 
-:- pred code_info__add_closure_layout(comp_gen_c_data, code_info, code_info).
-:- mode code_info__add_closure_layout(in, in, out) is det.
+:- pred code_info__add_closure_layout(comp_gen_c_data::in,
+	code_info::in, code_info::out) is det.
 
 :- pred code_info__add_static_cell(assoc_list(rval, llds_type)::in,
 	data_addr::out, code_info::in, code_info::out) is det.
@@ -679,187 +664,184 @@
 
 :- implementation.
 
-:- pred code_info__add_resume_layout_for_label(label, layout_label_info,
-	code_info, code_info).
-:- mode code_info__add_resume_layout_for_label(in, in, in, out) is det.
-
-code_info__get_stack_slots(StackSlots, CI, CI) :-
-	code_info__get_var_locn_info(VarLocnInfo, CI, _),
-	var_locn__get_stack_slots(StackSlots, VarLocnInfo, _).
-
-code_info__get_follow_var_map(FollowVarMap, CI, CI) :-
-	code_info__get_var_locn_info(VarLocnInfo, CI, _),
-	var_locn__get_follow_var_map(FollowVarMap, VarLocnInfo, _).
-
-code_info__get_next_non_reserved(NextNonReserved, CI, CI) :-
-	code_info__get_var_locn_info(VarLocnInfo, CI, _),
-	var_locn__get_next_non_reserved(NextNonReserved, VarLocnInfo, _).
+:- pred code_info__add_resume_layout_for_label(label::in,
+	layout_label_info::in, code_info::in, code_info::out) is det.
+
+code_info__get_stack_slots(CI, StackSlots) :-
+	code_info__get_var_locn_info(CI, VarLocnInfo),
+	var_locn__get_stack_slots(VarLocnInfo, StackSlots).
+
+code_info__get_follow_var_map(CI, FollowVarMap) :-
+	code_info__get_var_locn_info(CI, VarLocnInfo),
+	var_locn__get_follow_var_map(VarLocnInfo, FollowVarMap).
+
+code_info__get_next_non_reserved(CI, NextNonReserved) :-
+	code_info__get_var_locn_info(CI, VarLocnInfo),
+	var_locn__get_next_non_reserved(VarLocnInfo, NextNonReserved).
 
-code_info__set_follow_vars(FollowVars, CI0, CI) :-
-	code_info__get_var_locn_info(VarLocnInfo0, CI0, _),
+code_info__set_follow_vars(FollowVars, !CI) :-
+	code_info__get_var_locn_info(!.CI, VarLocnInfo0),
 	var_locn__set_follow_vars(FollowVars, VarLocnInfo0, VarLocnInfo),
-	code_info__set_var_locn_info(VarLocnInfo, CI0, CI).
+	code_info__set_var_locn_info(VarLocnInfo, !CI).
 
 %-----------------------------------------------------------------------------%
 
 	% Update the code info structure to be consistent
 	% immediately prior to generating a goal.
-code_info__pre_goal_update(GoalInfo, Atomic) -->
+code_info__pre_goal_update(GoalInfo, Atomic, !CI) :-
 	% The liveness pass puts resume_point annotations on some kinds
 	% of goals. The parts of the code generator that handle those kinds
 	% of goals should handle the resume point annotation as well;
 	% when they do, they remove the annotation. The following code
 	% is a sanity check to make sure that this has in fact been done.
-	{ goal_info_get_resume_point(GoalInfo, ResumePoint) },
+	goal_info_get_resume_point(GoalInfo, ResumePoint),
 	(
-		{ ResumePoint = no_resume_point }
+		ResumePoint = no_resume_point
 	;
-		{ ResumePoint = resume_point(_, _) },
-		{ error("pre_goal_update with resume point") }
+		ResumePoint = resume_point(_, _),
+		error("pre_goal_update with resume point")
 	),
-	{ goal_info_get_follow_vars(GoalInfo, MaybeFollowVars) },
+	goal_info_get_follow_vars(GoalInfo, MaybeFollowVars),
 	(
-		{ MaybeFollowVars = yes(FollowVars) },
-		code_info__set_follow_vars(FollowVars)
+		MaybeFollowVars = yes(FollowVars),
+		code_info__set_follow_vars(FollowVars, !CI)
 	;
-		{ MaybeFollowVars = no }
+		MaybeFollowVars = no
 	),
 	% note: we must be careful to apply deaths before births
-	{ goal_info_get_pre_deaths(GoalInfo, PreDeaths) },
-	code_info__rem_forward_live_vars(PreDeaths),
-	code_info__maybe_make_vars_forward_dead(PreDeaths, no),
-	{ goal_info_get_pre_births(GoalInfo, PreBirths) },
-	code_info__add_forward_live_vars(PreBirths),
-	( { Atomic = yes } ->
-		{ goal_info_get_post_deaths(GoalInfo, PostDeaths) },
-		code_info__rem_forward_live_vars(PostDeaths)
+	goal_info_get_pre_deaths(GoalInfo, PreDeaths),
+	code_info__rem_forward_live_vars(PreDeaths, !CI),
+	code_info__maybe_make_vars_forward_dead(PreDeaths, no, !CI),
+	goal_info_get_pre_births(GoalInfo, PreBirths),
+	code_info__add_forward_live_vars(PreBirths, !CI),
+	( Atomic = yes ->
+		goal_info_get_post_deaths(GoalInfo, PostDeaths),
+		code_info__rem_forward_live_vars(PostDeaths, !CI)
 	;
-		[]
+		true
 	).
 
 	% Update the code info structure to be consistent
 	% immediately after generating a goal.
-code_info__post_goal_update(GoalInfo) -->
+code_info__post_goal_update(GoalInfo, !CI) :-
 	% note: we must be careful to apply deaths before births
-	{ goal_info_get_post_deaths(GoalInfo, PostDeaths) },
-	code_info__rem_forward_live_vars(PostDeaths),
-	code_info__maybe_make_vars_forward_dead(PostDeaths, no),
-	{ goal_info_get_post_births(GoalInfo, PostBirths) },
-	code_info__add_forward_live_vars(PostBirths),
-	code_info__make_vars_forward_live(PostBirths),
-	{ goal_info_get_instmap_delta(GoalInfo, InstMapDelta) },
-	code_info__get_instmap(InstMap0),
-	{ instmap__apply_instmap_delta(InstMap0, InstMapDelta, InstMap) },
-	code_info__set_instmap(InstMap).
+	goal_info_get_post_deaths(GoalInfo, PostDeaths),
+	code_info__rem_forward_live_vars(PostDeaths, !CI),
+	code_info__maybe_make_vars_forward_dead(PostDeaths, no, !CI),
+	goal_info_get_post_births(GoalInfo, PostBirths),
+	code_info__add_forward_live_vars(PostBirths, !CI),
+	code_info__make_vars_forward_live(PostBirths, !CI),
+	goal_info_get_instmap_delta(GoalInfo, InstMapDelta),
+	code_info__get_instmap(!.CI, InstMap0),
+	instmap__apply_instmap_delta(InstMap0, InstMapDelta, InstMap),
+	code_info__set_instmap(InstMap, !CI).
 
 %---------------------------------------------------------------------------%
 
-code_info__body_typeinfo_liveness(TypeInfoLiveness) -->
-	code_info__get_module_info(ModuleInfo),
-	code_info__get_pred_id(PredId),
-	{ module_info_pred_info(ModuleInfo, PredId, PredInfo) },
-	code_info__get_globals(Globals),
-	{ body_should_use_typeinfo_liveness(PredInfo, Globals,
-		TypeInfoLiveness) }.
-
-:- pred code_info__get_var_types(map(prog_var, type), code_info, code_info).
-:- mode code_info__get_var_types(out, in, out) is det.
-
-code_info__get_var_types(VarTypes) -->
-	code_info__get_proc_info(ProcInfo),
-	{ proc_info_vartypes(ProcInfo, VarTypes) }.
-
-code_info__variable_type(Var, Type) -->
-	code_info__get_var_types(VarTypes),
-	{ map__lookup(VarTypes, Var, Type) }.
-
-code_info__lookup_type_defn(Type, TypeDefn) -->
-	code_info__get_module_info(ModuleInfo),
-	{ type_to_ctor_and_args(Type, TypeCtorPrime, _) ->
+code_info__body_typeinfo_liveness(CI) = TypeInfoLiveness :-
+	code_info__get_module_info(CI, ModuleInfo),
+	code_info__get_pred_id(CI, PredId),
+	module_info_pred_info(ModuleInfo, PredId, PredInfo),
+	code_info__get_globals(CI, Globals),
+	body_should_use_typeinfo_liveness(PredInfo, Globals, TypeInfoLiveness).
+
+:- func code_info__get_var_types(code_info) = map(prog_var, type).
+
+code_info__get_var_types(CI) = VarTypes :-
+	code_info__get_proc_info(CI, ProcInfo),
+	proc_info_vartypes(ProcInfo, VarTypes).
+
+code_info__variable_type(CI, Var) = Type :-
+	map__lookup(code_info__get_var_types(CI), Var, Type).
+
+code_info__lookup_type_defn(CI, Type) = TypeDefn :-
+	code_info__get_module_info(CI, ModuleInfo),
+	( type_to_ctor_and_args(Type, TypeCtorPrime, _) ->
 		TypeCtor = TypeCtorPrime
 	;
 		error("unknown type in code_info__lookup_type_defn")
-	},
-	{ module_info_types(ModuleInfo, TypeTable) },
-	{ map__lookup(TypeTable, TypeCtor, TypeDefn) }.
-
-code_info__cons_id_to_tag(Var, ConsId, ConsTag) -->
-	code_info__variable_type(Var, Type),
-	code_info__get_module_info(ModuleInfo),
-	{ ConsTag = cons_id_to_tag(ConsId, Type, ModuleInfo) }.
-
-%---------------------------------------------------------------------------%
-
-code_info__get_proc_model(CodeModel) -->
-	code_info__get_proc_info(ProcInfo),
-	{ proc_info_interface_code_model(ProcInfo, CodeModel) }.
-
-code_info__get_headvars(HeadVars) -->
-	code_info__get_module_info(ModuleInfo),
-	code_info__get_pred_id(PredId),
-	code_info__get_proc_id(ProcId),
-	{ module_info_pred_proc_info(ModuleInfo, PredId, ProcId, _, ProcInfo) },
-	{ proc_info_headvars(ProcInfo, HeadVars) }.
-
-code_info__get_arginfo(ArgInfo) -->
-	code_info__get_pred_id(PredId),
-	code_info__get_proc_id(ProcId),
-	code_info__get_pred_proc_arginfo(PredId, ProcId, ArgInfo).
-
-code_info__get_pred_proc_arginfo(PredId, ProcId, ArgInfo) -->
-	code_info__get_module_info(ModuleInfo),
-	{ module_info_pred_proc_info(ModuleInfo, PredId, ProcId, _, ProcInfo) },
-	{ proc_info_arg_info(ProcInfo, ArgInfo) }.
-
-code_info__current_resume_point_vars(ResumeVars) -->
-	code_info__get_fail_info(FailInfo),
-	{ FailInfo = fail_info(ResumePointStack, _, _, _, _) },
-	{ stack__top_det(ResumePointStack, ResumePointInfo) },
-	{ code_info__pick_first_resume_point(ResumePointInfo, ResumeMap, _) },
-	{ map__keys(ResumeMap, ResumeMapVarList) },
-	{ set__list_to_set(ResumeMapVarList, ResumeVars) }.
-
-code_info__variable_to_string(Var, Name) -->
-	code_info__get_varset(Varset),
-	{ varset__lookup_name(Varset, Var, Name) }.
-
-%---------------------------------------------------------------------------%
-
-code_info__make_entry_label(ModuleInfo, PredId, ProcId, Immed0, PredAddress) -->
-	(
-		{ Immed0 = no },
-		{ Immed = no }
-	;
-		{ Immed0 = yes },
-		code_info__get_globals(Globals),
-		{ globals__lookup_int_option(Globals, procs_per_c_function,
-			ProcsPerFunc) },
-		code_info__get_pred_id(CurPredId),
-		code_info__get_proc_id(CurProcId),
-		{ Immed = yes(ProcsPerFunc - proc(CurPredId, CurProcId)) }
-	),
-	{ code_util__make_entry_label(ModuleInfo, PredId, ProcId, Immed,
-		PredAddress) }.
-
-code_info__get_next_label(Label) -->
-	code_info__get_module_info(ModuleInfo),
-	code_info__get_pred_id(PredId),
-	code_info__get_proc_id(ProcId),
-	code_info__get_label_counter(C0),
-	{ counter__allocate(N, C0, C) },
-	code_info__set_label_counter(C),
-	{ code_util__make_internal_label(ModuleInfo, PredId, ProcId, N,
-		Label) }.
+	),
+	module_info_types(ModuleInfo, TypeTable),
+	map__lookup(TypeTable, TypeCtor, TypeDefn).
 
-code_info__succip_is_used -->
-	code_info__set_succip_used(yes).
+code_info__cons_id_to_tag(CI, Var, ConsId) = ConsTag :-
+	code_info__get_module_info(CI, ModuleInfo),
+	ConsTag = cons_id_to_tag(ConsId, code_info__variable_type(CI, Var),
+		ModuleInfo).
+
+%---------------------------------------------------------------------------%
+
+code_info__get_proc_model(CI) = CodeModel :-
+	code_info__get_proc_info(CI, ProcInfo),
+	proc_info_interface_code_model(ProcInfo, CodeModel).
+
+code_info__get_headvars(CI) = HeadVars :-
+	code_info__get_module_info(CI, ModuleInfo),
+	code_info__get_pred_id(CI, PredId),
+	code_info__get_proc_id(CI, ProcId),
+	module_info_pred_proc_info(ModuleInfo, PredId, ProcId, _, ProcInfo),
+	proc_info_headvars(ProcInfo, HeadVars).
+
+code_info__get_arginfo(CI) = ArgInfo :-
+	code_info__get_pred_id(CI, PredId),
+	code_info__get_proc_id(CI, ProcId),
+	ArgInfo = code_info__get_pred_proc_arginfo(CI, PredId, ProcId).
+
+code_info__get_pred_proc_arginfo(CI, PredId, ProcId) = ArgInfo :-
+	code_info__get_module_info(CI, ModuleInfo),
+	module_info_pred_proc_info(ModuleInfo, PredId, ProcId, _, ProcInfo),
+	proc_info_arg_info(ProcInfo, ArgInfo).
+
+code_info__current_resume_point_vars(CI) = ResumeVars :-
+	code_info__get_fail_info(CI, FailInfo),
+	FailInfo = fail_info(ResumePointStack, _, _, _, _),
+	stack__top_det(ResumePointStack, ResumePointInfo),
+	code_info__pick_first_resume_point(ResumePointInfo, ResumeMap, _),
+	map__keys(ResumeMap, ResumeMapVarList),
+	set__list_to_set(ResumeMapVarList, ResumeVars).
+
+code_info__variable_to_string(CI, Var) = Name :-
+	code_info__get_varset(CI, Varset),
+	varset__lookup_name(Varset, Var, Name).
+
+%---------------------------------------------------------------------------%
+
+code_info__make_entry_label(CI, ModuleInfo, PredId, ProcId, Immed0) =
+		PredAddress :-
+	(
+		Immed0 = no,
+		Immed = no
+	;
+		Immed0 = yes,
+		code_info__get_globals(CI, Globals),
+		globals__lookup_int_option(Globals, procs_per_c_function,
+			ProcsPerFunc),
+		code_info__get_pred_id(CI, CurPredId),
+		code_info__get_proc_id(CI, CurProcId),
+		Immed = yes(ProcsPerFunc - proc(CurPredId, CurProcId))
+	),
+	code_util__make_entry_label(ModuleInfo, PredId, ProcId, Immed,
+		PredAddress).
+
+code_info__get_next_label(Label, !CI) :-
+	code_info__get_module_info(!.CI, ModuleInfo),
+	code_info__get_pred_id(!.CI, PredId),
+	code_info__get_proc_id(!.CI, ProcId),
+	code_info__get_label_counter(!.CI, C0),
+	counter__allocate(N, C0, C),
+	code_info__set_label_counter(C, !CI),
+	code_util__make_internal_label(ModuleInfo, PredId, ProcId, N,
+		Label).
+
+code_info__succip_is_used(!CI) :-
+	code_info__set_succip_used(yes, !CI).
 
 code_info__add_trace_layout_for_label(Label, Context, Port, IsHidden, Path,
-		Layout) -->
-	code_info__get_layout_info(Internals0),
-	{ Exec = yes(trace_port_layout_info(Context, Port, IsHidden,
-		Path, Layout)) },
-	{ map__search(Internals0, Label, Internal0) ->
+		Layout, !CI) :-
+	code_info__get_layout_info(!.CI, Internals0),
+	Exec = yes(trace_port_layout_info(Context, Port, IsHidden,
+		Path, Layout)),
+	( map__search(Internals0, Label, Internal0) ->
 		Internal0 = internal_layout_info(Exec0, Resume, Return),
 		( Exec0 = no ->
 			true
@@ -871,13 +853,13 @@
 	;
 		Internal = internal_layout_info(Exec, no, no),
 		map__det_insert(Internals0, Label, Internal, Internals)
-	},
-	code_info__set_layout_info(Internals).
+	),
+	code_info__set_layout_info(Internals, !CI).
 
-code_info__add_resume_layout_for_label(Label, LayoutInfo) -->
-	code_info__get_layout_info(Internals0),
-	{ Resume = yes(LayoutInfo) },
-	{ map__search(Internals0, Label, Internal0) ->
+code_info__add_resume_layout_for_label(Label, LayoutInfo, !CI) :-
+	code_info__get_layout_info(!.CI, Internals0),
+	Resume = yes(LayoutInfo),
+	( map__search(Internals0, Label, Internal0) ->
 		Internal0 = internal_layout_info(Exec, Resume0, Return),
 		( Resume0 = no ->
 			true
@@ -889,45 +871,44 @@
 	;
 		Internal = internal_layout_info(no, Resume, no),
 		map__det_insert(Internals0, Label, Internal, Internals)
-	},
-	code_info__set_layout_info(Internals).
+	),
+	code_info__set_layout_info(Internals, !CI).
 
-:- pred code_info__get_active_temps_data(assoc_list(lval, slot_contents),
-	code_info, code_info).
-:- mode code_info__get_active_temps_data(out, in, out) is det.
-
-code_info__get_active_temps_data(Temps) -->
-	code_info__get_temps_in_use(TempsInUse),
-	code_info__get_temp_content_map(TempContentMap),
-	{ map__select(TempContentMap, TempsInUse, TempsInUseContentMap) },
-	{ map__to_assoc_list(TempsInUseContentMap, Temps) }.
-
-code_info__get_cur_proc_label(ProcLabel) -->
-	code_info__get_module_info(ModuleInfo),
-	code_info__get_pred_id(PredId),
-	code_info__get_proc_id(ProcId),
-	{ ProcLabel = make_proc_label(ModuleInfo, PredId, ProcId) }.
-
-code_info__get_next_closure_seq_no(SeqNo) -->
-	code_info__get_closure_seq_counter(C0),
-	{ counter__allocate(SeqNo, C0, C) },
-	code_info__set_closure_seq_counter(C).
-
-code_info__add_closure_layout(ClosureLayout) -->
-	code_info__get_closure_layouts(ClosureLayouts),
-	code_info__set_closure_layouts([ClosureLayout | ClosureLayouts]).
-
-code_info__add_static_cell(RvalsTypes, DataAddr) -->
-	code_info__get_static_cell_info(StaticCellInfo0),
-	{ add_static_cell(RvalsTypes, DataAddr,
-		StaticCellInfo0, StaticCellInfo) },
-	code_info__set_static_cell_info(StaticCellInfo).
-
-code_info__add_static_cell_natural_types(Rvals, DataAddr) -->
-	code_info__get_static_cell_info(StaticCellInfo0),
-	{ add_static_cell_natural_types(Rvals, DataAddr,
-		StaticCellInfo0, StaticCellInfo) },
-	code_info__set_static_cell_info(StaticCellInfo).
+:- pred code_info__get_active_temps_data(code_info::in,
+	assoc_list(lval, slot_contents)::out) is det.
+
+code_info__get_active_temps_data(CI, Temps) :-
+	code_info__get_temps_in_use(CI, TempsInUse),
+	code_info__get_temp_content_map(CI, TempContentMap),
+	map__select(TempContentMap, TempsInUse, TempsInUseContentMap),
+	map__to_assoc_list(TempsInUseContentMap, Temps).
+
+code_info__get_cur_proc_label(CI, ProcLabel) :-
+	code_info__get_module_info(CI, ModuleInfo),
+	code_info__get_pred_id(CI, PredId),
+	code_info__get_proc_id(CI, ProcId),
+	ProcLabel = make_proc_label(ModuleInfo, PredId, ProcId).
+
+code_info__get_next_closure_seq_no(SeqNo, !CI) :-
+	code_info__get_closure_seq_counter(!.CI, C0),
+	counter__allocate(SeqNo, C0, C),
+	code_info__set_closure_seq_counter(C, !CI).
+
+code_info__add_closure_layout(ClosureLayout, !CI) :-
+	code_info__get_closure_layouts(!.CI, ClosureLayouts),
+	code_info__set_closure_layouts([ClosureLayout | ClosureLayouts], !CI).
+
+code_info__add_static_cell(RvalsTypes, DataAddr, !CI) :-
+	code_info__get_static_cell_info(!.CI, StaticCellInfo0),
+	add_static_cell(RvalsTypes, DataAddr,
+		StaticCellInfo0, StaticCellInfo),
+	code_info__set_static_cell_info(StaticCellInfo, !CI).
+
+code_info__add_static_cell_natural_types(Rvals, DataAddr, !CI) :-
+	code_info__get_static_cell_info(!.CI, StaticCellInfo0),
+	add_static_cell_natural_types(Rvals, DataAddr,
+		StaticCellInfo0, StaticCellInfo),
+	code_info__set_static_cell_info(StaticCellInfo, !CI).
 
 %---------------------------------------------------------------------------%
 %---------------------------------------------------------------------------%
@@ -941,26 +922,22 @@
 
 :- type branch_end	==	maybe(branch_end_info).
 
-:- pred code_info__remember_position(position_info, code_info, code_info).
-:- mode code_info__remember_position(out, in, out) is det.
+:- pred code_info__remember_position(code_info::in, position_info::out) is det.
+
+:- pred code_info__reset_to_position(position_info::in,
+	code_info::in, code_info::out) is det.
+
+:- pred code_info__reset_resume_known(position_info::in,
+	code_info::in, code_info::out) is det.
 
-:- pred code_info__reset_to_position(position_info, code_info, code_info).
-:- mode code_info__reset_to_position(in, in, out) is det.
+:- pred code_info__generate_branch_end(store_map::in, branch_end::in,
+	branch_end::out, code_tree::out, code_info::in, code_info::out) is det.
 
-:- pred code_info__reset_resume_known(position_info, code_info, code_info).
-:- mode code_info__reset_resume_known(in, in, out) is det.
+:- pred code_info__after_all_branches(store_map::in, branch_end::in,
+	code_info::in, code_info::out) is det.
 
-:- pred code_info__generate_branch_end(store_map, branch_end, branch_end,
-	code_tree, code_info, code_info).
-:- mode code_info__generate_branch_end(in, in, out, out, in, out) is det.
-
-:- pred code_info__after_all_branches(store_map, branch_end,
-	code_info, code_info).
-:- mode code_info__after_all_branches(in, in, in, out) is det.
-
-:- pred code_info__save_hp_in_branch(code_tree, lval, position_info,
-	position_info).
-:- mode code_info__save_hp_in_branch(out, out, in, out) is det.
+:- pred code_info__save_hp_in_branch(code_tree::out, lval::out,
+	position_info::in, position_info::out) is det.
 
 :- implementation.
 
@@ -975,40 +952,40 @@
 			code_info	% The code_info at the end of a branch.
 		).
 
-code_info__remember_position(position_info(C), C, C).
+code_info__remember_position(CI, position_info(CI)).
 
 code_info__reset_to_position(position_info(PosCI), CurCI, NextCI) :-
 	PosCI  = code_info(_, LocDep, _),
 	CurCI  = code_info(Static, _, Persistent),
 	NextCI = code_info(Static, LocDep, Persistent).
 
-code_info__reset_resume_known(BranchStart) -->
-	{ BranchStart = position_info(BranchStartCI) },
-	{ code_info__get_fail_info(BranchStartFailInfo, BranchStartCI, _) },
-	{ BranchStartFailInfo = fail_info(_, BSResumeKnown, _, _, _) },
-	code_info__get_fail_info(CurFailInfo),
-	{ CurFailInfo = fail_info(CurFailStack, _,
-		CurCurfMaxfr, CurCondEnv, CurHijack) },
-	{ NewFailInfo = fail_info(CurFailStack, BSResumeKnown,
-		CurCurfMaxfr, CurCondEnv, CurHijack) },
-	code_info__set_fail_info(NewFailInfo).
+code_info__reset_resume_known(BranchStart, !CI) :-
+	BranchStart = position_info(BranchStartCI),
+	code_info__get_fail_info(BranchStartCI, BranchStartFailInfo),
+	BranchStartFailInfo = fail_info(_, BSResumeKnown, _, _, _),
+	code_info__get_fail_info(!.CI, CurFailInfo),
+	CurFailInfo = fail_info(CurFailStack, _,
+		CurCurfMaxfr, CurCondEnv, CurHijack),
+	NewFailInfo = fail_info(CurFailStack, BSResumeKnown,
+		CurCurfMaxfr, CurCondEnv, CurHijack),
+	code_info__set_fail_info(NewFailInfo, !CI).
 
-code_info__generate_branch_end(StoreMap, MaybeEnd0, MaybeEnd, Code) -->
+code_info__generate_branch_end(StoreMap, MaybeEnd0, MaybeEnd, Code, !CI) :-
 		% The code generator generates better code
 			% if it knows in advance where each variable should
 			% go. We don't need to reset the follow_vars
 			% afterwards, since every goal following a branched
 			% control structure must in any case be annotated with
 			% its own follow_var set.
-	{ map__to_assoc_list(StoreMap, VarLocs) },
-		{ map__from_assoc_list(VarLocs, FollowVarsMap) },
-		{ assoc_list__values(VarLocs, Locs) },
-		{ code_util__max_mentioned_reg(Locs, MaxMentionedReg) },
-		code_info__set_follow_vars(follow_vars(FollowVarsMap,
-		MaxMentionedReg + 1)),
-	code_info__get_instmap(InstMap),
-	( { instmap__is_reachable(InstMap) } ->
-		code_info__place_vars(VarLocs, Code)
+	map__to_assoc_list(StoreMap, VarLocs),
+	map__from_assoc_list(VarLocs, FollowVarsMap),
+	assoc_list__values(VarLocs, Locs),
+	code_util__max_mentioned_reg(Locs, MaxMentionedReg),
+	code_info__set_follow_vars(
+		follow_vars(FollowVarsMap, MaxMentionedReg + 1), !CI),
+	code_info__get_instmap(!.CI, InstMap),
+	( instmap__is_reachable(InstMap) ->
+		code_info__place_vars(VarLocs, Code, !CI)
 	;
 		% With --opt-no-return-call, the variables that we would have
 		% saved across a call that cannot return have had the last
@@ -1017,11 +994,11 @@
 		% pretending that all the variables are where the store map
 		% says they should be is perfectly fine, since we can never
 		% reach the end of *this* branch anyway.
-		code_info__remake_with_store_map(StoreMap),
-		{ Code = empty }
+		code_info__remake_with_store_map(StoreMap, !CI),
+		Code = empty
 	),
-	=(EndCodeInfo1),
-	{
+	EndCodeInfo1 = !.CI,
+	(
 		MaybeEnd0 = no,
 		EndCodeInfo = EndCodeInfo1
 	;
@@ -1029,8 +1006,8 @@
 
 			% Make sure the left context we leave the
 			% branched structure with is valid for all branches.
-		code_info__get_fail_info(FailInfo0, EndCodeInfo0, _),
-		code_info__get_fail_info(FailInfo1, EndCodeInfo1, _),
+		code_info__get_fail_info(EndCodeInfo0, FailInfo0),
+		code_info__get_fail_info(EndCodeInfo1, FailInfo1),
 		FailInfo0 = fail_info(_, ResumeKnown0, CurfrMaxfr0,
 			CondEnv0, Hijack0),
 		FailInfo1 = fail_info(R, ResumeKnown1, CurfrMaxfr1,
@@ -1070,21 +1047,21 @@
 			% Make sure the "temps in use" set at the end of the
 			% branched control structure includes every slot
 			% in use at the end of any branch.
-		code_info__get_temps_in_use(TempsInUse0, EndCodeInfo0, _),
-		code_info__get_temps_in_use(TempsInUse1, EndCodeInfo1, _),
+		code_info__get_temps_in_use(EndCodeInfo0, TempsInUse0),
+		code_info__get_temps_in_use(EndCodeInfo1, TempsInUse1),
 		set__union(TempsInUse0, TempsInUse1, TempsInUse),
 		code_info__set_temps_in_use(TempsInUse, EndCodeInfoA,
 			EndCodeInfo)
-	},
-	{ MaybeEnd = yes(branch_end_info(EndCodeInfo)) }.
+	),
+	MaybeEnd = yes(branch_end_info(EndCodeInfo)).
 
-code_info__after_all_branches(StoreMap, MaybeEnd, CI0, CI) :-
+code_info__after_all_branches(StoreMap, MaybeEnd, !CI) :-
 	(
 		MaybeEnd = yes(BranchEnd),
 		BranchEnd = branch_end_info(BranchEndCodeInfo),
 		code_info__reset_to_position(position_info(BranchEndCodeInfo),
-			CI0, CI1),
-		code_info__remake_with_store_map(StoreMap, CI1, CI)
+			!CI),
+		code_info__remake_with_store_map(StoreMap, !CI)
 	;
 		MaybeEnd = no,
 		error("no branches in branched control structure")
@@ -1097,14 +1074,14 @@
 	% in the store map, and will believe they are where the store map
 	% says they are.
 
-:- pred code_info__remake_with_store_map(store_map, code_info, code_info).
-:- mode code_info__remake_with_store_map(in, in, out) is det.
+:- pred code_info__remake_with_store_map(store_map::in,
+	code_info::in, code_info::out) is det.
 
-code_info__remake_with_store_map(StoreMap) -->
-	{ map__to_assoc_list(StoreMap, VarLvals) },
-	code_info__get_var_locn_info(VarLocnInfo0),
-	{ var_locn__reinit_state(VarLvals, VarLocnInfo0, VarLocnInfo) },
-	code_info__set_var_locn_info(VarLocnInfo).
+code_info__remake_with_store_map(StoreMap, !CI) :-
+	map__to_assoc_list(StoreMap, VarLvals),
+	code_info__get_var_locn_info(!.CI, VarLocnInfo0),
+	var_locn__reinit_state(VarLvals, VarLocnInfo0, VarLocnInfo),
+	code_info__set_var_locn_info(VarLocnInfo, !CI).
 
 code_info__save_hp_in_branch(Code, Slot, Pos0, Pos) :-
 	Pos0 = position_info(CodeInfo0),
@@ -1223,8 +1200,8 @@
 	% Return the details of the resume point currently on top of the
 	% failure continuation stack.
 
-:- pred code_info__top_resume_point(resume_point_info::out,
-	code_info::in, code_info::out) is det.
+:- pred code_info__top_resume_point(code_info::in, resume_point_info::out)
+	is det.
 
 	% Call this predicate to say "we have just left a disjunction;
 	% we don't know what address the following code will need to
@@ -1257,16 +1234,16 @@
 	% Checks whether the appropriate code for failure in the current
 	% failure environment is a direct branch.
 
-:- pred code_info__failure_is_direct_branch(code_addr::out,
-	code_info::in, code_info::out) is semidet.
+:- pred code_info__failure_is_direct_branch(code_info::in, code_addr::out)
+	is semidet.
 
 	% Checks under what circumstances the current failure environment
 	% would allow a model_non call at this point to be turned into a
 	% tail call, provided of course that the return from the call is
 	% followed immediately by succeed().
 
-:- pred code_info__may_use_nondet_tailcall(nondet_tail_call::out,
-	code_info::in, code_info::out) is det.
+:- pred code_info__may_use_nondet_tailcall(code_info::in,
+	nondet_tail_call::out) is det.
 
 	% Materialize the given variables into registers or stack slots.
 
@@ -1375,118 +1352,118 @@
 					% the value of the hijacked redofr.
 		).
 
-code_info__prepare_for_disj_hijack(CodeModel, HijackInfo, Code) -->
-	code_info__get_fail_info(FailInfo),
-	{ FailInfo = fail_info(_, ResumeKnown, CurfrMaxfr, CondEnv, Allow) },
+code_info__prepare_for_disj_hijack(CodeModel, HijackInfo, Code, !CI) :-
+	code_info__get_fail_info(!.CI, FailInfo),
+	FailInfo = fail_info(_, ResumeKnown, CurfrMaxfr, CondEnv, Allow),
 	(
-		{ CodeModel \= model_non }
+		CodeModel \= model_non
 	->
-		{ HijackInfo = disj_no_hijack },
-		{ Code = node([
+		HijackInfo = disj_no_hijack,
+		Code = node([
 			comment("disj no hijack")
 				- ""
-		]) }
+		])
 	;
-		{ Allow = not_allowed ; CondEnv = inside_non_condition }
+		( Allow = not_allowed ; CondEnv = inside_non_condition )
 	->
-		{ HijackInfo = disj_temp_frame },
+		HijackInfo = disj_temp_frame,
 		code_info__create_temp_frame(do_fail,
-			"prepare for disjunction", Code)
+			"prepare for disjunction", Code, !CI)
 	;
-		{ CurfrMaxfr = must_be_equal },
-		{ ResumeKnown = resume_point_known(has_been_done) }
+		CurfrMaxfr = must_be_equal,
+		ResumeKnown = resume_point_known(has_been_done)
 	->
-		{ HijackInfo = disj_quarter_hijack },
-		{ Code = node([
+		HijackInfo = disj_quarter_hijack,
+		Code = node([
 			comment("disj quarter hijack")
 				- ""
-		]) }
+		])
 	;
-		{ CurfrMaxfr = must_be_equal }
+		CurfrMaxfr = must_be_equal
 	->
 		% Here ResumeKnown must be resume_point_unknown
 		% or resume_point_known(wont_be_done).
 		code_info__acquire_temp_slot(lval(redoip(lval(curfr))),
-			RedoipSlot),
-		{ HijackInfo = disj_half_hijack(RedoipSlot) },
-		{ Code = node([
+			RedoipSlot, !CI),
+		HijackInfo = disj_half_hijack(RedoipSlot),
+		Code = node([
 			assign(RedoipSlot, lval(redoip(lval(curfr))))
 				- "prepare for half disj hijack"
-		]) }
+		])
 	;
 		% Here CurfrMaxfr must be may_be_different.
 		code_info__acquire_temp_slot(lval(redoip(lval(maxfr))),
-			RedoipSlot),
+			RedoipSlot, !CI),
 		code_info__acquire_temp_slot(lval(redofr(lval(maxfr))),
-			RedofrSlot),
-		{ HijackInfo = disj_full_hijack(RedoipSlot, RedofrSlot) },
-		{ Code = node([
+			RedofrSlot, !CI),
+		HijackInfo = disj_full_hijack(RedoipSlot, RedofrSlot),
+		Code = node([
 			assign(RedoipSlot, lval(redoip(lval(maxfr))))
 				- "prepare for full disj hijack",
 			assign(RedofrSlot, lval(redofr(lval(maxfr))))
 				- "prepare for full disj hijack",
 			assign(redofr(lval(maxfr)), lval(curfr))
 				- "prepare for full disj hijack"
-		]) }
+		])
 	).
 
-code_info__undo_disj_hijack(HijackInfo, Code) -->
-	code_info__get_fail_info(FailInfo0),
-	{ FailInfo0 = fail_info(ResumePoints, ResumeKnown, CurfrMaxfr,
-		CondEnv, Allow) },
+code_info__undo_disj_hijack(HijackInfo, Code, !CI) :-
+	code_info__get_fail_info(!.CI, FailInfo0),
+	FailInfo0 = fail_info(ResumePoints, ResumeKnown, CurfrMaxfr,
+		CondEnv, Allow),
 	(
-		{ HijackInfo = disj_no_hijack },
-		{ Code = empty }
+		HijackInfo = disj_no_hijack,
+		Code = empty
 	;
-		{ HijackInfo = disj_temp_frame },
-		{ Code = node([
+		HijackInfo = disj_temp_frame,
+		Code = node([
 			assign(maxfr, lval(prevfr(lval(maxfr))))
 				- "restore maxfr for temp frame disj"
-		]) }
+		])
 	;
-		{ HijackInfo = disj_quarter_hijack },
-		{ require(unify(CurfrMaxfr, must_be_equal),
-			"maxfr may differ from curfr in disj_quarter_hijack") },
-		{ stack__top_det(ResumePoints, ResumePoint) },
-		{ code_info__pick_stack_resume_point(ResumePoint,
-			_, StackLabel) },
-		{ LabelConst = const(code_addr_const(StackLabel)) },
-		{ Code = node([
+		HijackInfo = disj_quarter_hijack,
+		require(unify(CurfrMaxfr, must_be_equal),
+			"maxfr may differ from curfr in disj_quarter_hijack"),
+		stack__top_det(ResumePoints, ResumePoint),
+		code_info__pick_stack_resume_point(ResumePoint,
+			_, StackLabel),
+		LabelConst = const(code_addr_const(StackLabel)),
+		Code = node([
 			assign(redoip(lval(curfr)), LabelConst)
 				- "restore redoip for quarter disj hijack"
-		]) }
+		])
 	;
-		{ HijackInfo = disj_half_hijack(RedoipSlot) },
-		{ require(unify(ResumeKnown, resume_point_unknown),
-			"resume point known in disj_half_hijack") },
-		{ require(unify(CurfrMaxfr, must_be_equal),
-			"maxfr may differ from curfr in disj_half_hijack") },
-		{ Code = node([
+		HijackInfo = disj_half_hijack(RedoipSlot),
+		require(unify(ResumeKnown, resume_point_unknown),
+			"resume point known in disj_half_hijack"),
+		require(unify(CurfrMaxfr, must_be_equal),
+			"maxfr may differ from curfr in disj_half_hijack"),
+		Code = node([
 			assign(redoip(lval(curfr)), lval(RedoipSlot))
 				- "restore redoip for half disj hijack"
-		]) }
+		])
 	;
-		{ HijackInfo = disj_full_hijack(RedoipSlot, RedofrSlot) },
-		{ require(unify(CurfrMaxfr, may_be_different),
-			"maxfr same as curfr in disj_full_hijack") },
-		{ Code = node([
+		HijackInfo = disj_full_hijack(RedoipSlot, RedofrSlot),
+		require(unify(CurfrMaxfr, may_be_different),
+			"maxfr same as curfr in disj_full_hijack"),
+		Code = node([
 			assign(redoip(lval(maxfr)), lval(RedoipSlot))
 				- "restore redoip for full disj hijack",
 			assign(redofr(lval(maxfr)), lval(RedofrSlot))
 				- "restore redofr for full disj hijack"
-		]) }
+		])
 	),
 	(
 			% HijackInfo \= disj_no_hijack if and only if
 			% the disjunction is model_non.
-		{ HijackInfo \= disj_no_hijack },
-		{ CondEnv = inside_non_condition }
+		HijackInfo \= disj_no_hijack,
+		CondEnv = inside_non_condition
 	->
-		{ FailInfo = fail_info(ResumePoints, resume_point_unknown,
-			CurfrMaxfr, CondEnv, Allow) },
-		code_info__set_fail_info(FailInfo)
+		FailInfo = fail_info(ResumePoints, resume_point_unknown,
+			CurfrMaxfr, CondEnv, Allow),
+		code_info__set_fail_info(FailInfo, !CI)
 	;
-		[]
+		true
 	).
 
 %---------------------------------------------------------------------------%
@@ -1518,60 +1495,60 @@
 					% the value of maxfr.
 		).
 
-code_info__prepare_for_ite_hijack(EffCodeModel, HijackInfo, Code) -->
-	code_info__get_fail_info(FailInfo),
-	{ FailInfo = fail_info(_, ResumeKnown, CurfrMaxfr, CondEnv, Allow) },
+code_info__prepare_for_ite_hijack(EffCodeModel, HijackInfo, Code, !CI) :-
+	code_info__get_fail_info(!.CI, FailInfo),
+	FailInfo = fail_info(_, ResumeKnown, CurfrMaxfr, CondEnv, Allow),
 	(
-		{ EffCodeModel \= model_non }
+		EffCodeModel \= model_non
 	->
-		{ HijackType = ite_no_hijack },
-		{ Code = node([
+		HijackType = ite_no_hijack,
+		Code = node([
 			comment("ite no hijack")
 				- ""
-		]) }
+		])
 	;
-		{ Allow = not_allowed ; CondEnv = inside_non_condition }
+		( Allow = not_allowed ; CondEnv = inside_non_condition )
 	->
-		code_info__acquire_temp_slot(lval(maxfr), MaxfrSlot),
-		{ HijackType = ite_temp_frame(MaxfrSlot) },
+		code_info__acquire_temp_slot(lval(maxfr), MaxfrSlot, !CI),
+		HijackType = ite_temp_frame(MaxfrSlot),
 		code_info__create_temp_frame(do_fail, "prepare for ite",
-			TempFrameCode),
-		{ MaxfrCode = node([
+			TempFrameCode, !CI),
+		MaxfrCode = node([
 			assign(MaxfrSlot, lval(maxfr))
 				- "prepare for ite"
-		]) },
-		{ Code = tree(TempFrameCode, MaxfrCode) }
+		]),
+		Code = tree(TempFrameCode, MaxfrCode)
 	;
-		{ CurfrMaxfr = must_be_equal },
-		{ ResumeKnown = resume_point_known(_) }
+		CurfrMaxfr = must_be_equal,
+		ResumeKnown = resume_point_known(_)
 	->
-		{ HijackType = ite_quarter_hijack },
-		{ Code = node([
+		HijackType = ite_quarter_hijack,
+		Code = node([
 			comment("ite quarter hijack")
 				- ""
-		]) }
+		])
 	;
-		{ CurfrMaxfr = must_be_equal }
+		CurfrMaxfr = must_be_equal
 	->
 		% Here ResumeKnown must be resume_point_unknown.
 		code_info__acquire_temp_slot(lval(redoip(lval(curfr))),
-			RedoipSlot),
-		{ HijackType = ite_half_hijack(RedoipSlot) },
-		{ Code = node([
+			RedoipSlot, !CI),
+		HijackType = ite_half_hijack(RedoipSlot),
+		Code = node([
 			assign(RedoipSlot, lval(redoip(lval(curfr))))
 				- "prepare for half ite hijack"
-		]) }
+		])
 	;
 		% Here CurfrMaxfr must be may_be_different.
 		code_info__acquire_temp_slot(lval(redoip(lval(maxfr))),
-			RedoipSlot),
+			RedoipSlot, !CI),
 		code_info__acquire_temp_slot(lval(redofr(lval(maxfr))),
-			RedofrSlot),
+			RedofrSlot, !CI),
 		code_info__acquire_temp_slot(lval(maxfr),
+			MaxfrSlot, !CI),
+		HijackType = ite_full_hijack(RedoipSlot, RedofrSlot,
 			MaxfrSlot),
-		{ HijackType = ite_full_hijack(RedoipSlot, RedofrSlot,
-			MaxfrSlot) },
-		{ Code = node([
+		Code = node([
 			assign(MaxfrSlot, lval(maxfr))
 				- "prepare for full ite hijack",
 			assign(RedoipSlot, lval(redoip(lval(maxfr))))
@@ -1580,22 +1557,22 @@
 				- "prepare for full ite hijack",
 			assign(redofr(lval(maxfr)), lval(curfr))
 				- "prepare for full ite hijack"
-		]) }
+		])
 	),
-	{ HijackInfo = ite_info(ResumeKnown, CondEnv, HijackType) },
-	( { EffCodeModel = model_non } ->
-		code_info__inside_non_condition
-	;
-		[]
-	).
-
-code_info__ite_enter_then(HijackInfo, ThenCode, ElseCode) -->
-	code_info__get_fail_info(FailInfo0),
-	{ FailInfo0 = fail_info(ResumePoints0, ResumeKnown0, CurfrMaxfr,
-		_, Allow) },
-	{ stack__pop_det(ResumePoints0, _, ResumePoints) },
-	{ HijackInfo = ite_info(HijackResumeKnown, OldCondEnv, HijackType) },
-	{
+	HijackInfo = ite_info(ResumeKnown, CondEnv, HijackType),
+	( EffCodeModel = model_non ->
+		code_info__inside_non_condition(!CI)
+	;
+		true
+	).
+
+code_info__ite_enter_then(HijackInfo, ThenCode, ElseCode, !CI) :-
+	code_info__get_fail_info(!.CI, FailInfo0),
+	FailInfo0 = fail_info(ResumePoints0, ResumeKnown0, CurfrMaxfr,
+		_, Allow),
+	stack__pop_det(ResumePoints0, _, ResumePoints),
+	HijackInfo = ite_info(HijackResumeKnown, OldCondEnv, HijackType),
+	(
 		HijackType = ite_no_hijack,
 		ThenCode = empty,
 		ElseCode = ThenCode
@@ -1651,22 +1628,22 @@
 			assign(redofr(lval(maxfr)), lval(RedofrSlot))
 				- "restore redofr for full ite hijack"
 		])
-	},
-	{ ResumeKnown0 = resume_point_unknown ->
+	),
+	( ResumeKnown0 = resume_point_unknown ->
 		ResumeKnown = resume_point_unknown
 	;
 		ResumeKnown = HijackResumeKnown
-	},
-	{ FailInfo = fail_info(ResumePoints, ResumeKnown, CurfrMaxfr,
-		OldCondEnv, Allow) },
-	code_info__set_fail_info(FailInfo).
+	),
+	FailInfo = fail_info(ResumePoints, ResumeKnown, CurfrMaxfr,
+		OldCondEnv, Allow),
+	code_info__set_fail_info(FailInfo, !CI).
 
 %---------------------------------------------------------------------------%
 
 :- type simple_neg_info		==	fail_info.
 
-code_info__enter_simple_neg(ResumeVars, GoalInfo, FailInfo0) -->
-	code_info__get_fail_info(FailInfo0),
+code_info__enter_simple_neg(ResumeVars, GoalInfo, FailInfo0, !CI) :-
+	code_info__get_fail_info(!.CI, FailInfo0),
 		% The only reason why we push a resume point at all
 		% is to protect the variables in ResumeVars from becoming
 		% unknown; by including them in the domain of the resume point,
@@ -1676,18 +1653,18 @@
 		% is the set of variables in the resume map; the other
 		% parts of ResumePoint (the locations, the code address)
 		% will not be referenced.
-	{ set__to_sorted_list(ResumeVars, ResumeVarList) },
-	{ map__init(ResumeMap0) },
-	{ code_info__make_fake_resume_map(ResumeVarList,
-		ResumeMap0, ResumeMap) },
-	{ ResumePoint = orig_only(ResumeMap, do_redo) },
-	code_info__effect_resume_point(ResumePoint, model_semi, Code),
-	{ require(unify(Code, empty), "nonempty code for simple neg") },
-	code_info__pre_goal_update(GoalInfo, yes).
-
-code_info__leave_simple_neg(GoalInfo, FailInfo) -->
-	code_info__post_goal_update(GoalInfo),
-	code_info__set_fail_info(FailInfo).
+	set__to_sorted_list(ResumeVars, ResumeVarList),
+	map__init(ResumeMap0),
+	code_info__make_fake_resume_map(ResumeVarList,
+		ResumeMap0, ResumeMap),
+	ResumePoint = orig_only(ResumeMap, do_redo),
+	code_info__effect_resume_point(ResumePoint, model_semi, Code, !CI),
+	require(unify(Code, empty), "nonempty code for simple neg"),
+	code_info__pre_goal_update(GoalInfo, yes, !CI).
+
+code_info__leave_simple_neg(GoalInfo, FailInfo, !CI) :-
+	code_info__post_goal_update(GoalInfo, !CI),
+	code_info__set_fail_info(FailInfo, !CI).
 
 :- pred code_info__make_fake_resume_map(list(prog_var)::in,
 	map(prog_var, set(lval))::in, map(prog_var, set(lval))::out) is det.
@@ -1708,45 +1685,45 @@
 						% counter and trail pointer.
 		).
 
-code_info__prepare_for_det_commit(DetCommitInfo, Code) -->
-	code_info__get_fail_info(FailInfo0),
-	{ FailInfo0 = fail_info(_, _, CurfrMaxfr, _, _) },
-	(
-		{ CurfrMaxfr = may_be_different },
-		code_info__acquire_temp_slot(lval(maxfr), MaxfrSlot),
-		{ SaveMaxfrCode = node([
+code_info__prepare_for_det_commit(DetCommitInfo, Code, !CI) :-
+	code_info__get_fail_info(!.CI, FailInfo0),
+	FailInfo0 = fail_info(_, _, CurfrMaxfr, _, _),
+	(
+		CurfrMaxfr = may_be_different,
+		code_info__acquire_temp_slot(lval(maxfr), MaxfrSlot, !CI),
+		SaveMaxfrCode = node([
 			assign(MaxfrSlot, lval(maxfr))
 				- "save the value of maxfr"
-		]) },
-		{ MaybeMaxfrSlot = yes(MaxfrSlot) }
+		]),
+		MaybeMaxfrSlot = yes(MaxfrSlot)
 	;
-		{ CurfrMaxfr = must_be_equal },
-		{ SaveMaxfrCode = empty },
-		{ MaybeMaxfrSlot = no }
-	),
-	code_info__maybe_save_trail_info(MaybeTrailSlots, SaveTrailCode),
-	{ DetCommitInfo = det_commit_info(MaybeMaxfrSlot, MaybeTrailSlots) },
-	{ Code = tree(SaveMaxfrCode, SaveTrailCode) }.
+		CurfrMaxfr = must_be_equal,
+		SaveMaxfrCode = empty,
+		MaybeMaxfrSlot = no
+	),
+	code_info__maybe_save_trail_info(MaybeTrailSlots, SaveTrailCode, !CI),
+	DetCommitInfo = det_commit_info(MaybeMaxfrSlot, MaybeTrailSlots),
+	Code = tree(SaveMaxfrCode, SaveTrailCode).
 
-code_info__generate_det_commit(DetCommitInfo, Code) -->
-	{ DetCommitInfo = det_commit_info(MaybeMaxfrSlot, MaybeTrailSlots) },
+code_info__generate_det_commit(DetCommitInfo, Code, !CI) :-
+	DetCommitInfo = det_commit_info(MaybeMaxfrSlot, MaybeTrailSlots),
 	(
-		{ MaybeMaxfrSlot = yes(MaxfrSlot) },
-		{ RestoreMaxfrCode = node([
+		MaybeMaxfrSlot = yes(MaxfrSlot),
+		RestoreMaxfrCode = node([
 			assign(maxfr, lval(MaxfrSlot))
 				- "restore the value of maxfr - perform commit"
-		]) },
-		code_info__release_temp_slot(MaxfrSlot)
+		]),
+		code_info__release_temp_slot(MaxfrSlot, !CI)
 	;
-		{ MaybeMaxfrSlot = no },
-		{ RestoreMaxfrCode = node([
+		MaybeMaxfrSlot = no,
+		RestoreMaxfrCode = node([
 			assign(maxfr, lval(curfr))
 				- "restore the value of maxfr - perform commit"
-		]) }
+		])
 	),
 	code_info__maybe_restore_trail_info(MaybeTrailSlots,
-		CommitTrailCode, _),
-	{ Code = tree(RestoreMaxfrCode, CommitTrailCode) }.
+		CommitTrailCode, _, !CI),
+	Code = tree(RestoreMaxfrCode, CommitTrailCode).
 
 %---------------------------------------------------------------------------%
 
@@ -1780,34 +1757,34 @@
 					% the value of maxfr.
 		).
 
-code_info__prepare_for_semi_commit(SemiCommitInfo, Code) -->
-	code_info__get_fail_info(FailInfo0),
-	{ FailInfo0 = fail_info(ResumePoints0, ResumeKnown, CurfrMaxfr,
-		CondEnv, Allow) },
-	{ stack__top_det(ResumePoints0, TopResumePoint) },
-	code_info__clone_resume_point(TopResumePoint, NewResumePoint),
-	{ stack__push(ResumePoints0, NewResumePoint, ResumePoints) },
-	{ FailInfo = fail_info(ResumePoints, resume_point_known(has_been_done),
-		CurfrMaxfr, CondEnv, Allow) },
-	code_info__set_fail_info(FailInfo),
+code_info__prepare_for_semi_commit(SemiCommitInfo, Code, !CI) :-
+	code_info__get_fail_info(!.CI, FailInfo0),
+	FailInfo0 = fail_info(ResumePoints0, ResumeKnown, CurfrMaxfr,
+		CondEnv, Allow),
+	stack__top_det(ResumePoints0, TopResumePoint),
+	code_info__clone_resume_point(TopResumePoint, NewResumePoint, !CI),
+	stack__push(ResumePoints0, NewResumePoint, ResumePoints),
+	FailInfo = fail_info(ResumePoints, resume_point_known(has_been_done),
+		CurfrMaxfr, CondEnv, Allow),
+	code_info__set_fail_info(FailInfo, !CI),
 
-	{ code_info__pick_stack_resume_point(NewResumePoint, _, StackLabel) },
-	{ StackLabelConst = const(code_addr_const(StackLabel)) },
+	code_info__pick_stack_resume_point(NewResumePoint, _, StackLabel),
+	StackLabelConst = const(code_addr_const(StackLabel)),
 	(
-		{ Allow = not_allowed ; CondEnv = inside_non_condition }
+		( Allow = not_allowed ; CondEnv = inside_non_condition )
 	->
-		code_info__acquire_temp_slot(lval(maxfr), MaxfrSlot),
-		{ MaxfrCode = node([
+		code_info__acquire_temp_slot(lval(maxfr), MaxfrSlot, !CI),
+		MaxfrCode = node([
 			assign(MaxfrSlot, lval(maxfr))
 				- "prepare for temp frame commit"
-		]) },
+		]),
 		code_info__create_temp_frame(StackLabel,
-			"prepare for temp frame commit", TempFrameCode),
-		code_info__get_globals(Globals),
-		{ globals__lookup_bool_option(Globals, use_minimal_model,
-			UseMinimalModel) },
-		{ HijackInfo = commit_temp_frame(MaxfrSlot, UseMinimalModel) },
-		{
+			"prepare for temp frame commit", TempFrameCode, !CI),
+		code_info__get_globals(!.CI, Globals),
+		globals__lookup_bool_option(Globals, use_minimal_model,
+			UseMinimalModel),
+		HijackInfo = commit_temp_frame(MaxfrSlot, UseMinimalModel),
+		(
 			UseMinimalModel = yes,
 			% If the code we are committing across starts but
 			% does not complete the evaluation of a tabled subgoal,
@@ -1837,42 +1814,42 @@
 		;
 			UseMinimalModel = no,
 			MarkCode = empty
-		},
-		{ HijackCode = tree(MaxfrCode, tree(TempFrameCode, MarkCode)) }
+		),
+		HijackCode = tree(MaxfrCode, tree(TempFrameCode, MarkCode))
 	;
-		{ ResumeKnown = resume_point_known(has_been_done) },
-		{ CurfrMaxfr = must_be_equal }
+		ResumeKnown = resume_point_known(has_been_done),
+		CurfrMaxfr = must_be_equal
 	->
-		{ HijackInfo = commit_quarter_hijack },
-		{ HijackCode = node([
+		HijackInfo = commit_quarter_hijack,
+		HijackCode = node([
 			assign(redoip(lval(curfr)), StackLabelConst)
 				- "hijack the redofr slot"
-		]) }
+		])
 	;
-		{ CurfrMaxfr = must_be_equal }
+		CurfrMaxfr = must_be_equal
 	->
 		% Here ResumeKnown must be resume_point_unknown or
 		% resume_point_known(wont_be_done).
 
 		code_info__acquire_temp_slot(lval(redoip(lval(curfr))),
-			RedoipSlot),
-		{ HijackInfo = commit_half_hijack(RedoipSlot) },
-		{ HijackCode = node([
+			RedoipSlot, !CI),
+		HijackInfo = commit_half_hijack(RedoipSlot),
+		HijackCode = node([
 			assign(RedoipSlot, lval(redoip(lval(curfr))))
 				- "prepare for half commit hijack",
 			assign(redoip(lval(curfr)), StackLabelConst)
 				- "hijack the redofr slot"
-		]) }
+		])
 	;
 		% Here CurfrMaxfr must be may_be_different.
 		code_info__acquire_temp_slot(lval(redoip(lval(maxfr))),
-			RedoipSlot),
+			RedoipSlot, !CI),
 		code_info__acquire_temp_slot(lval(redofr(lval(maxfr))),
-			RedofrSlot),
-		code_info__acquire_temp_slot(lval(maxfr), MaxfrSlot),
-		{ HijackInfo = commit_full_hijack(RedoipSlot, RedofrSlot,
-			MaxfrSlot) },
-		{ HijackCode = node([
+			RedofrSlot, !CI),
+		code_info__acquire_temp_slot(lval(maxfr), MaxfrSlot, !CI),
+		HijackInfo = commit_full_hijack(RedoipSlot, RedofrSlot,
+			MaxfrSlot),
+		HijackCode = node([
 			assign(RedoipSlot, lval(redoip(lval(maxfr))))
 				- "prepare for full commit hijack",
 			assign(RedofrSlot, lval(redofr(lval(maxfr))))
@@ -1883,26 +1860,26 @@
 				- "hijack the redofr slot",
 			assign(redoip(lval(maxfr)), StackLabelConst)
 				- "hijack the redoip slot"
-		]) }
+		])
 	),
-	code_info__maybe_save_trail_info(MaybeTrailSlots, SaveTrailCode),
-	{ SemiCommitInfo = semi_commit_info(FailInfo0, NewResumePoint,
-		HijackInfo, MaybeTrailSlots) },
-	{ Code = tree(HijackCode, SaveTrailCode) }.
-
-code_info__generate_semi_commit(SemiCommitInfo, Code) -->
-	{ SemiCommitInfo = semi_commit_info(FailInfo, ResumePoint,
-		HijackInfo, MaybeTrailSlots) },
+	code_info__maybe_save_trail_info(MaybeTrailSlots, SaveTrailCode, !CI),
+	SemiCommitInfo = semi_commit_info(FailInfo0, NewResumePoint,
+		HijackInfo, MaybeTrailSlots),
+	Code = tree(HijackCode, SaveTrailCode).
+
+code_info__generate_semi_commit(SemiCommitInfo, Code, !CI) :-
+	SemiCommitInfo = semi_commit_info(FailInfo, ResumePoint,
+		HijackInfo, MaybeTrailSlots),
 
-	code_info__set_fail_info(FailInfo),
+	code_info__set_fail_info(FailInfo, !CI),
 	% XXX should release the temp slots in each arm of the switch
 	(
-		{ HijackInfo = commit_temp_frame(MaxfrSlot, UseMinimalModel) },
-		{ MaxfrCode = node([
+		HijackInfo = commit_temp_frame(MaxfrSlot, UseMinimalModel),
+		MaxfrCode = node([
 			assign(maxfr, lval(MaxfrSlot))
 				- "restore maxfr for temp frame hijack"
-		]) },
-		{
+		]),
+		(
 			UseMinimalModel = yes,
 			% See the comment in prepare_for_semi_commit above.
 			Components = [
@@ -1917,130 +1894,125 @@
 		;
 			UseMinimalModel = no,
 			CutCode = empty
-		},
-		{ SuccessUndoCode = tree(MaxfrCode, CutCode) },
-		{ FailureUndoCode = tree(MaxfrCode, CutCode) }
-	;
-		{ HijackInfo = commit_quarter_hijack },
-		{ FailInfo = fail_info(ResumePoints, _, _, _, _) },
-		{ stack__top_det(ResumePoints, TopResumePoint) },
-		{ code_info__pick_stack_resume_point(TopResumePoint,
-			_, StackLabel) },
-		{ StackLabelConst = const(code_addr_const(StackLabel)) },
-		{ SuccessUndoCode = node([
+		),
+		SuccessUndoCode = tree(MaxfrCode, CutCode),
+		FailureUndoCode = tree(MaxfrCode, CutCode)
+	;
+		HijackInfo = commit_quarter_hijack,
+		FailInfo = fail_info(ResumePoints, _, _, _, _),
+		stack__top_det(ResumePoints, TopResumePoint),
+		code_info__pick_stack_resume_point(TopResumePoint,
+			_, StackLabel),
+		StackLabelConst = const(code_addr_const(StackLabel)),
+		SuccessUndoCode = node([
 			assign(maxfr, lval(curfr))
 				- "restore maxfr for quarter commit hijack",
 			assign(redoip(lval(maxfr)), StackLabelConst)
 				- "restore redoip for quarter commit hijack"
-		]) },
-		{ FailureUndoCode = node([
+		]),
+		FailureUndoCode = node([
 			assign(redoip(lval(maxfr)), StackLabelConst)
 				- "restore redoip for quarter commit hijack"
-		]) }
+		])
 	;
-		{ HijackInfo = commit_half_hijack(RedoipSlot) },
-		{ SuccessUndoCode = node([
+		HijackInfo = commit_half_hijack(RedoipSlot),
+		SuccessUndoCode = node([
 			assign(maxfr, lval(curfr))
 				- "restore maxfr for half commit hijack",
 			assign(redoip(lval(maxfr)), lval(RedoipSlot))
 				- "restore redoip for half commit hijack"
-		]) },
-		{ FailureUndoCode = node([
+		]),
+		FailureUndoCode = node([
 			assign(redoip(lval(maxfr)), lval(RedoipSlot))
 				- "restore redoip for half commit hijack"
-		]) }
+		])
 	;
-		{ HijackInfo = commit_full_hijack(RedoipSlot, RedofrSlot,
-			MaxfrSlot) },
-		{ SuccessUndoCode = node([
+		HijackInfo = commit_full_hijack(RedoipSlot, RedofrSlot,
+			MaxfrSlot),
+		SuccessUndoCode = node([
 			assign(maxfr, lval(MaxfrSlot))
 				- "restore maxfr for full commit hijack",
 			assign(redoip(lval(maxfr)), lval(RedoipSlot))
 				- "restore redoip for full commit hijack",
 			assign(redofr(lval(maxfr)), lval(RedofrSlot))
 				- "restore redofr for full commit hijack"
-		]) },
-		{ FailureUndoCode = node([
+		]),
+		FailureUndoCode = node([
 			assign(redoip(lval(maxfr)), lval(RedoipSlot))
 				- "restore redoip for full commit hijack",
 			assign(redofr(lval(maxfr)), lval(RedofrSlot))
 				- "restore redofr for full commit hijack"
-		]) }
+		])
 	),
 
-	code_info__remember_position(AfterCommit),
-	code_info__generate_resume_point(ResumePoint, ResumePointCode),
-	code_info__generate_failure(FailCode),
-	code_info__reset_to_position(AfterCommit),
+	code_info__remember_position(!.CI, AfterCommit),
+	code_info__generate_resume_point(ResumePoint, ResumePointCode, !CI),
+	code_info__generate_failure(FailCode, !CI),
+	code_info__reset_to_position(AfterCommit, !CI),
 
 	code_info__maybe_restore_trail_info(MaybeTrailSlots,
-		CommitTrailCode, RestoreTrailCode),
+		CommitTrailCode, RestoreTrailCode, !CI),
 
-	code_info__get_next_label(SuccLabel),
-	{ GotoSuccLabel = node([
+	code_info__get_next_label(SuccLabel, !CI),
+	GotoSuccLabel = node([
 		goto(label(SuccLabel)) - "Jump to success continuation"
-	]) },
-	{ SuccLabelCode = node([
+	]),
+	SuccLabelCode = node([
 		label(SuccLabel) - "Success continuation"
-	]) },
-	{ SuccessCode =
+	]),
+	SuccessCode =
 		tree(SuccessUndoCode,
-		     CommitTrailCode)
-	},
-	{ FailureCode =
+		     CommitTrailCode),
+	FailureCode =
 		tree(ResumePointCode,
 		tree(FailureUndoCode,
 		tree(RestoreTrailCode,
-		     FailCode)))
-	},
-	{ Code =
+		     FailCode))),
+	Code =
 		tree(SuccessCode,
 		tree(GotoSuccLabel,
 		tree(FailureCode,
-		     SuccLabelCode)))
-	}.
+		     SuccLabelCode))).
 
 %---------------------------------------------------------------------------%
 
 :- pred code_info__inside_non_condition(code_info::in, code_info::out) is det.
 
-code_info__inside_non_condition -->
-	code_info__get_fail_info(FailInfo0),
-	{ FailInfo0 = fail_info(ResumePoints, ResumeKnown, CurfrMaxfr,
-		_, Allow) },
-	{ FailInfo = fail_info(ResumePoints, ResumeKnown, CurfrMaxfr,
-		inside_non_condition, Allow) },
-	code_info__set_fail_info(FailInfo).
+code_info__inside_non_condition(!CI) :-
+	code_info__get_fail_info(!.CI, FailInfo0),
+	FailInfo0 = fail_info(ResumePoints, ResumeKnown, CurfrMaxfr,
+		_, Allow),
+	FailInfo = fail_info(ResumePoints, ResumeKnown, CurfrMaxfr,
+		inside_non_condition, Allow),
+	code_info__set_fail_info(FailInfo, !CI).
 
 :- pred code_info__create_temp_frame(code_addr::in, string::in, code_tree::out,
 	code_info::in, code_info::out) is det.
 
-code_info__create_temp_frame(Redoip, Comment, Code) -->
-	code_info__get_proc_model(ProcModel),
-	{ ProcModel = model_non ->
+code_info__create_temp_frame(Redoip, Comment, Code, !CI) :-
+	( code_info__get_proc_model(!.CI) = model_non ->
 		Kind = nondet_stack_proc
 	;
 		Kind = det_stack_proc
-	},
-	{ Code = node([
+	),
+	Code = node([
 		mkframe(temp_frame(Kind), Redoip)
 			- Comment
-	]) },
-	code_info__set_created_temp_frame(yes),
-	code_info__get_fail_info(FailInfo0),
-	{ FailInfo0 = fail_info(ResumePoints, ResumeKnown, _, CondEnv, Allow) },
-	{ FailInfo = fail_info(ResumePoints, ResumeKnown, may_be_different,
-		CondEnv, Allow) },
-	code_info__set_fail_info(FailInfo).
+	]),
+	code_info__set_created_temp_frame(yes, !CI),
+	code_info__get_fail_info(!.CI, FailInfo0),
+	FailInfo0 = fail_info(ResumePoints, ResumeKnown, _, CondEnv, Allow),
+	FailInfo = fail_info(ResumePoints, ResumeKnown, may_be_different,
+		CondEnv, Allow),
+	code_info__set_fail_info(FailInfo, !CI).
 
 %---------------------------------------------------------------------------%
 
-code_info__effect_resume_point(ResumePoint, CodeModel, Code) -->
-	code_info__get_fail_info(FailInfo0),
-	{ FailInfo0 = fail_info(ResumePoints0, _ResumeKnown, CurfrMaxfr,
-		CondEnv, Allow) },
-
-	{ stack__top(ResumePoints0, OldResumePoint) ->
+code_info__effect_resume_point(ResumePoint, CodeModel, Code, !CI) :-
+	code_info__get_fail_info(!.CI, FailInfo0),
+	FailInfo0 = fail_info(ResumePoints0, _ResumeKnown, CurfrMaxfr,
+		CondEnv, Allow),
+	( stack__top(ResumePoints0, OldResumePoint) ->
 		code_info__pick_first_resume_point(OldResumePoint, OldMap, _),
 		code_info__pick_first_resume_point(ResumePoint, NewMap, _),
 		map__keys(OldMap, OldKeys),
@@ -2051,151 +2023,150 @@
 			"non-nested resume point variable sets")
 	;
 		true
-	},
-
-	{ stack__push(ResumePoints0, ResumePoint, ResumePoints) },
-	( { CodeModel = model_non } ->
-		{ code_info__pick_stack_resume_point(ResumePoint,
-			_, StackLabel) },
-		{ LabelConst = const(code_addr_const(StackLabel)) },
-		{ Code = node([
+	),
+	stack__push(ResumePoints0, ResumePoint, ResumePoints),
+	( CodeModel = model_non ->
+		code_info__pick_stack_resume_point(ResumePoint,
+			_, StackLabel),
+		LabelConst = const(code_addr_const(StackLabel)),
+		Code = node([
 			assign(redoip(lval(maxfr)), LabelConst)
 				- "hijack redoip to effect resume point"
-		]) },
-		{ RedoipUpdate = has_been_done }
+		]),
+		RedoipUpdate = has_been_done
 	;
-		{ Code = empty },
-		{ RedoipUpdate = wont_be_done }
+		Code = empty,
+		RedoipUpdate = wont_be_done
 	),
-	{ FailInfo = fail_info(ResumePoints, resume_point_known(RedoipUpdate),
-		CurfrMaxfr, CondEnv, Allow) },
-	code_info__set_fail_info(FailInfo).
-
-code_info__pop_resume_point -->
-	code_info__get_fail_info(FailInfo0),
-	{ FailInfo0 = fail_info(ResumePoints0, ResumeKnown, CurfrMaxfr,
-		CondEnv, Allow) },
-	{ stack__pop_det(ResumePoints0, _, ResumePoints) },
-	{ FailInfo = fail_info(ResumePoints, ResumeKnown, CurfrMaxfr,
-		CondEnv, Allow) },
-	code_info__set_fail_info(FailInfo).
+	FailInfo = fail_info(ResumePoints, resume_point_known(RedoipUpdate),
+		CurfrMaxfr, CondEnv, Allow),
+	code_info__set_fail_info(FailInfo, !CI).
+
+code_info__pop_resume_point(!CI) :-
+	code_info__get_fail_info(!.CI, FailInfo0),
+	FailInfo0 = fail_info(ResumePoints0, ResumeKnown, CurfrMaxfr,
+		CondEnv, Allow),
+	stack__pop_det(ResumePoints0, _, ResumePoints),
+	FailInfo = fail_info(ResumePoints, ResumeKnown, CurfrMaxfr,
+		CondEnv, Allow),
+	code_info__set_fail_info(FailInfo, !CI).
 
 %---------------------------------------------------------------------------%
 
-code_info__top_resume_point(ResumePoint) -->
-	code_info__get_fail_info(FailInfo),
-	{ FailInfo = fail_info(ResumePoints, _, _, _, _) },
-	{ stack__top_det(ResumePoints, ResumePoint) }.
-
-code_info__set_resume_point_to_unknown -->
-	code_info__get_fail_info(FailInfo0),
-	{ FailInfo0 = fail_info(ResumePoints, _, CurfrMaxfr, CondEnv, Allow) },
-	{ FailInfo = fail_info(ResumePoints, resume_point_unknown,
-		CurfrMaxfr, CondEnv, Allow) },
-	code_info__set_fail_info(FailInfo).
-
-code_info__set_resume_point_and_frame_to_unknown -->
-	code_info__get_fail_info(FailInfo0),
-	{ FailInfo0 = fail_info(ResumePoints, _, _, CondEnv, Allow) },
-	{ FailInfo = fail_info(ResumePoints, resume_point_unknown,
-		may_be_different, CondEnv, Allow) },
-	code_info__set_fail_info(FailInfo).
+code_info__top_resume_point(CI, ResumePoint) :-
+	code_info__get_fail_info(CI, FailInfo),
+	FailInfo = fail_info(ResumePoints, _, _, _, _),
+	stack__top_det(ResumePoints, ResumePoint).
+
+code_info__set_resume_point_to_unknown(!CI) :-
+	code_info__get_fail_info(!.CI, FailInfo0),
+	FailInfo0 = fail_info(ResumePoints, _, CurfrMaxfr, CondEnv, Allow),
+	FailInfo = fail_info(ResumePoints, resume_point_unknown,
+		CurfrMaxfr, CondEnv, Allow),
+	code_info__set_fail_info(FailInfo, !CI).
+
+code_info__set_resume_point_and_frame_to_unknown(!CI) :-
+	code_info__get_fail_info(!.CI, FailInfo0),
+	FailInfo0 = fail_info(ResumePoints, _, _, CondEnv, Allow),
+	FailInfo = fail_info(ResumePoints, resume_point_unknown,
+		may_be_different, CondEnv, Allow),
+	code_info__set_fail_info(FailInfo, !CI).
 
 %---------------------------------------------------------------------------%
 
-code_info__generate_failure(Code) -->
-	code_info__get_fail_info(FailInfo),
-	{ FailInfo = fail_info(ResumePoints, ResumeKnown, _, _, _) },
+code_info__generate_failure(Code, !CI) :-
+	code_info__get_fail_info(!.CI, FailInfo),
+	FailInfo = fail_info(ResumePoints, ResumeKnown, _, _, _),
 	(
-		{ ResumeKnown = resume_point_known(_) },
-		{ stack__top_det(ResumePoints, TopResumePoint) },
+		ResumeKnown = resume_point_known(_),
+		stack__top_det(ResumePoints, TopResumePoint),
 		(
-			code_info__pick_matching_resume_addr(TopResumePoint,
-				FailureAddress0)
+			code_info__pick_matching_resume_addr(!.CI,
+				TopResumePoint, FailureAddress0)
 		->
-			{ FailureAddress = FailureAddress0 },
-			{ PlaceCode = empty }
+			FailureAddress = FailureAddress0,
+			PlaceCode = empty
 		;
-			{ code_info__pick_first_resume_point(TopResumePoint,
-				Map, FailureAddress) },
-			{ map__to_assoc_list(Map, AssocList) },
-			code_info__remember_position(CurPos),
+			code_info__pick_first_resume_point(TopResumePoint,
+				Map, FailureAddress),
+			map__to_assoc_list(Map, AssocList),
+			code_info__remember_position(!.CI, CurPos),
 			code_info__pick_and_place_vars(AssocList, _,
-				PlaceCode),
-			code_info__reset_to_position(CurPos)
+				PlaceCode, !CI),
+			code_info__reset_to_position(CurPos, !CI)
 		),
-		{ BranchCode = node([goto(FailureAddress) - "fail"]) },
-		{ Code = tree(PlaceCode, BranchCode) }
+		BranchCode = node([goto(FailureAddress) - "fail"]),
+		Code = tree(PlaceCode, BranchCode)
 	;
-		{ ResumeKnown = resume_point_unknown },
-		{ Code = node([goto(do_redo) - "fail"]) }
+		ResumeKnown = resume_point_unknown,
+		Code = node([goto(do_redo) - "fail"])
 	).
 
-code_info__fail_if_rval_is_false(Rval0, Code) -->
-	code_info__get_fail_info(FailInfo),
-	{ FailInfo = fail_info(ResumePoints, ResumeKnown, _, _, _) },
+code_info__fail_if_rval_is_false(Rval0, Code, !CI) :-
+	code_info__get_fail_info(!.CI, FailInfo),
+	FailInfo = fail_info(ResumePoints, ResumeKnown, _, _, _),
 	(
-		{ ResumeKnown = resume_point_known(_) },
-		{ stack__top_det(ResumePoints, TopResumePoint) },
+		ResumeKnown = resume_point_known(_),
+		stack__top_det(ResumePoints, TopResumePoint),
 		(
-			code_info__pick_matching_resume_addr(TopResumePoint,
-				FailureAddress0)
+			code_info__pick_matching_resume_addr(!.CI,
+				TopResumePoint, FailureAddress0)
 		->
 				% We branch away if the test *fails*
-			{ code_util__neg_rval(Rval0, Rval) },
-			{ Code = node([
+			code_util__neg_rval(Rval0, Rval),
+			Code = node([
 				if_val(Rval, FailureAddress0) -
 					"Test for failure"
-			]) }
+			])
 		;
-			{ code_info__pick_first_resume_point(TopResumePoint,
-				Map, FailureAddress) },
-			{ map__to_assoc_list(Map, AssocList) },
-			code_info__get_next_label(SuccessLabel),
-			code_info__remember_position(CurPos),
+			code_info__pick_first_resume_point(TopResumePoint,
+				Map, FailureAddress),
+			map__to_assoc_list(Map, AssocList),
+			code_info__get_next_label(SuccessLabel, !CI),
+			code_info__remember_position(!.CI, CurPos),
 			code_info__pick_and_place_vars(AssocList, _,
-				PlaceCode),
-			code_info__reset_to_position(CurPos),
-			{ SuccessAddress = label(SuccessLabel) },
+				PlaceCode, !CI),
+			code_info__reset_to_position(CurPos, !CI),
+			SuccessAddress = label(SuccessLabel),
 				% We branch away if the test *fails*,
 				% therefore if the test succeeds, we branch
 				% around the code that moves variables to
 				% their failure locations and branches away
 				% to the failure continuation
-			{ TestCode = node([
+			TestCode = node([
 				if_val(Rval0, SuccessAddress) -
 					"Test for failure"
-			]) },
-			{ TailCode = node([
+			]),
+			TailCode = node([
 				goto(FailureAddress) -
 					"Goto failure",
 				label(SuccessLabel) -
 					"Success continuation"
-			]) },
-			{ Code = tree(TestCode, tree(PlaceCode, TailCode)) }
+			]),
+			Code = tree(TestCode, tree(PlaceCode, TailCode))
 		)
 	;
-		{ ResumeKnown = resume_point_unknown },
+		ResumeKnown = resume_point_unknown,
 			% We branch away if the test *fails*
-		{ code_util__neg_rval(Rval0, Rval) },
-		{ Code = node([
+		code_util__neg_rval(Rval0, Rval),
+		Code = node([
 			if_val(Rval, do_redo) -
 				"Test for failure"
-		]) }
+		])
 	).
 
 %---------------------------------------------------------------------------%
 
-code_info__failure_is_direct_branch(CodeAddr) -->
-	code_info__get_fail_info(FailInfo),
-	{ FailInfo = fail_info(ResumePoints, resume_point_known(_), _, _, _) },
-	{ stack__top(ResumePoints, TopResumePoint) },
-	code_info__pick_matching_resume_addr(TopResumePoint, CodeAddr).
-
-code_info__may_use_nondet_tailcall(TailCallStatus) -->
-	code_info__get_fail_info(FailInfo),
-	{ FailInfo = fail_info(ResumePoints0, ResumeKnown, _, _, _) },
-	{
+code_info__failure_is_direct_branch(CI, CodeAddr) :-
+	code_info__get_fail_info(CI, FailInfo),
+	FailInfo = fail_info(ResumePoints, resume_point_known(_), _, _, _),
+	stack__top(ResumePoints, TopResumePoint),
+	code_info__pick_matching_resume_addr(CI, TopResumePoint, CodeAddr).
+
+code_info__may_use_nondet_tailcall(CI, TailCallStatus) :-
+	code_info__get_fail_info(CI, FailInfo),
+	FailInfo = fail_info(ResumePoints0, ResumeKnown, _, _, _),
+	(
 		stack__pop(ResumePoints0, ResumePoint1, ResumePoints1),
 		stack__is_empty(ResumePoints1),
 		ResumePoint1 = stack_only(_, do_fail)
@@ -2209,7 +2180,7 @@
 		)
 	;
 		TailCallStatus = no_tail_call
-	}.
+	).
 
 %---------------------------------------------------------------------------%
 
@@ -2217,12 +2188,12 @@
 	% associated with any of the options in the given failure map.
 	% If yes, return the code_addr of that option.
 
-:- pred code_info__pick_matching_resume_addr(resume_point_info::in,
-	code_addr::out, code_info::in, code_info::out) is semidet.
+:- pred code_info__pick_matching_resume_addr(code_info::in,
+	resume_point_info::in, code_addr::out) is semidet.
 
-code_info__pick_matching_resume_addr(ResumeMaps, Addr) -->
-	code_info__variable_locations(CurLocs),
-	{
+code_info__pick_matching_resume_addr(CI, ResumeMaps, Addr) :-
+	code_info__variable_locations(CI, CurLocs),
+	(
 		ResumeMaps = orig_only(Map1, Addr1),
 		( code_info__match_resume_loc(Map1, CurLocs) ->
 			Addr = Addr1
@@ -2254,7 +2225,7 @@
 		;
 			fail
 		)
-	}.
+	).
 
 :- pred code_info__match_resume_loc(resume_map::in, resume_map::in) is semidet.
 
@@ -2301,124 +2272,125 @@
 
 %---------------------------------------------------------------------------%
 
-code_info__produce_vars(Vars, Map, Code) -->
-	{ set__to_sorted_list(Vars, VarList) },
-	code_info__produce_vars_2(VarList, Map, Code).
+code_info__produce_vars(Vars, Map, Code, !CI) :-
+	set__to_sorted_list(Vars, VarList),
+	code_info__produce_vars_2(VarList, Map, Code, !CI).
 
 :- pred code_info__produce_vars_2(list(prog_var)::in,
 	map(prog_var, set(lval))::out,
 	code_tree::out, code_info::in, code_info::out) is det.
 
-code_info__produce_vars_2([], Map, empty) -->
-	{ map__init(Map) }.
-code_info__produce_vars_2([V | Vs], Map, Code) -->
-	code_info__produce_vars_2(Vs, Map0, Code0),
-	code_info__produce_variable_in_reg_or_stack(V, Code1, Lval),
-	{ set__singleton_set(Lvals, Lval) },
-	{ map__set(Map0, V, Lvals, Map) },
-	{ Code = tree(Code0, Code1) }.
-
-code_info__flush_resume_vars_to_stack(Code) -->
-	code_info__compute_resume_var_stack_locs(VarLocs),
-	code_info__place_vars(VarLocs, Code).
-
-:- pred compute_resume_var_stack_locs(assoc_list(prog_var, lval)::out,
-	code_info::in, code_info::out) is det.
-
-code_info__compute_resume_var_stack_locs(VarLocs) -->
-	code_info__get_fail_info(FailInfo),
-	{ FailInfo = fail_info(ResumePointStack, _, _, _, _) },
-	{ stack__top_det(ResumePointStack, ResumePoint) },
-	{ code_info__pick_stack_resume_point(ResumePoint, StackMap, _) },
-	{ map__to_assoc_list(StackMap, VarLocSets) },
-	{ code_info__pick_var_places(VarLocSets, VarLocs) }.
+code_info__produce_vars_2([], Map, empty, !CI) :-
+	map__init(Map).
+code_info__produce_vars_2([V | Vs], Map, Code, !CI) :-
+	code_info__produce_vars_2(Vs, Map0, Code0, !CI),
+	code_info__produce_variable_in_reg_or_stack(V, Code1, Lval, !CI),
+	set__singleton_set(Lvals, Lval),
+	map__set(Map0, V, Lvals, Map),
+	Code = tree(Code0, Code1).
+
+code_info__flush_resume_vars_to_stack(Code, !CI) :-
+	code_info__compute_resume_var_stack_locs(!.CI, VarLocs),
+	code_info__place_vars(VarLocs, Code, !CI).
+
+:- pred compute_resume_var_stack_locs(code_info::in,
+	assoc_list(prog_var, lval)::out) is det.
+
+code_info__compute_resume_var_stack_locs(CI, VarLocs) :-
+	code_info__get_fail_info(CI, FailInfo),
+	FailInfo = fail_info(ResumePointStack, _, _, _, _),
+	stack__top_det(ResumePointStack, ResumePoint),
+	code_info__pick_stack_resume_point(ResumePoint, StackMap, _),
+	map__to_assoc_list(StackMap, VarLocSets),
+	code_info__pick_var_places(VarLocSets, VarLocs).
 
 %---------------------------------------------------------------------------%
 
 :- pred code_info__init_fail_info(code_model::in, maybe(set(prog_var))::in,
 	resume_point_info::out, code_info::in, code_info::out) is det.
 
-code_info__init_fail_info(CodeModel, MaybeFailVars, ResumePoint) -->
+code_info__init_fail_info(CodeModel, MaybeFailVars, ResumePoint, !CI) :-
 	(
-		{ CodeModel = model_det },
-		code_info__get_next_label(ResumeLabel),
-		{ ResumeAddress = label(ResumeLabel) },
-		{ ResumeKnown = resume_point_unknown },
-		{ CurfrMaxfr = may_be_different }
+		CodeModel = model_det,
+		code_info__get_next_label(ResumeLabel, !CI),
+		ResumeAddress = label(ResumeLabel),
+		ResumeKnown = resume_point_unknown,
+		CurfrMaxfr = may_be_different
 	;
-		{ CodeModel = model_semi },
+		CodeModel = model_semi,
 			% The resume point for this label
 			% will be part of the procedure epilog.
-		code_info__get_next_label(ResumeLabel),
-		{ ResumeAddress = label(ResumeLabel) },
-		{ ResumeKnown = resume_point_known(wont_be_done) },
-		{ CurfrMaxfr = may_be_different }
-	;
-		{ CodeModel = model_non },
-		( { MaybeFailVars = yes(_) } ->
-			code_info__get_next_label(ResumeLabel),
-			{ ResumeAddress = label(ResumeLabel) }
-		;
-			{ ResumeAddress = do_fail }
-		),
-		{ ResumeKnown = resume_point_known(has_been_done) },
-		{ CurfrMaxfr = must_be_equal }
-	),
-	( { MaybeFailVars = yes(FailVars) } ->
-		code_info__get_stack_slots(StackSlots),
-		{ map__select(StackSlots, FailVars, StackMap0) },
-		{ map__to_assoc_list(StackMap0, StackList0) },
-		{ code_info__make_singleton_sets(StackList0, StackList) },
-		{ map__from_assoc_list(StackList, StackMap) }
-	;
-		{ map__init(StackMap) }
-	),
-	{ ResumePoint = stack_only(StackMap, ResumeAddress) },
-	{ stack__init(ResumeStack0) },
-	{ stack__push(ResumeStack0, ResumePoint, ResumeStack) },
-	code_info__get_fail_info(FailInfo0),
-	{ FailInfo0 = fail_info(_, _, _, _, Allow) },
-	{ FailInfo = fail_info(ResumeStack, ResumeKnown, CurfrMaxfr,
-		not_inside_non_condition, Allow) },
-	code_info__set_fail_info(FailInfo).
-
-%---------------------------------------------------------------------------%
-
-code_info__make_resume_point(ResumeVars, ResumeLocs, FullMap, ResumePoint) -->
-	code_info__get_stack_slots(StackSlots),
-	{ map__select(FullMap, ResumeVars, OrigMap) },
-	(
-		{ ResumeLocs = orig_only },
-		code_info__get_next_label(OrigLabel),
-		{ OrigAddr = label(OrigLabel) },
-		{ ResumePoint = orig_only(OrigMap, OrigAddr) }
-	;
-		{ ResumeLocs = stack_only },
-		{ code_info__make_stack_resume_map(ResumeVars,
-			StackSlots, StackMap) },
-		code_info__get_next_label(StackLabel),
-		{ StackAddr = label(StackLabel) },
-		{ ResumePoint = stack_only(StackMap, StackAddr) }
-	;
-		{ ResumeLocs = orig_and_stack },
-		{ code_info__make_stack_resume_map(ResumeVars,
-			StackSlots, StackMap) },
-		code_info__get_next_label(OrigLabel),
-		{ OrigAddr = label(OrigLabel) },
-		code_info__get_next_label(StackLabel),
-		{ StackAddr = label(StackLabel) },
-		{ ResumePoint = orig_and_stack(OrigMap, OrigAddr,
-			StackMap, StackAddr) }
-	;
-		{ ResumeLocs = stack_and_orig },
-		{ code_info__make_stack_resume_map(ResumeVars,
-			StackSlots, StackMap) },
-		code_info__get_next_label(StackLabel),
-		{ StackAddr = label(StackLabel) },
-		code_info__get_next_label(OrigLabel),
-		{ OrigAddr = label(OrigLabel) },
-		{ ResumePoint = stack_and_orig(StackMap, StackAddr,
-			OrigMap, OrigAddr) }
+		code_info__get_next_label(ResumeLabel, !CI),
+		ResumeAddress = label(ResumeLabel),
+		ResumeKnown = resume_point_known(wont_be_done),
+		CurfrMaxfr = may_be_different
+	;
+		CodeModel = model_non,
+		( MaybeFailVars = yes(_) ->
+			code_info__get_next_label(ResumeLabel, !CI),
+			ResumeAddress = label(ResumeLabel)
+		;
+			ResumeAddress = do_fail
+		),
+		ResumeKnown = resume_point_known(has_been_done),
+		CurfrMaxfr = must_be_equal
+	),
+	( MaybeFailVars = yes(FailVars) ->
+		code_info__get_stack_slots(!.CI, StackSlots),
+		map__select(StackSlots, FailVars, StackMap0),
+		map__to_assoc_list(StackMap0, StackList0),
+		code_info__make_singleton_sets(StackList0, StackList),
+		map__from_assoc_list(StackList, StackMap)
+	;
+		map__init(StackMap)
+	),
+	ResumePoint = stack_only(StackMap, ResumeAddress),
+	stack__init(ResumeStack0),
+	stack__push(ResumeStack0, ResumePoint, ResumeStack),
+	code_info__get_fail_info(!.CI, FailInfo0),
+	FailInfo0 = fail_info(_, _, _, _, Allow),
+	FailInfo = fail_info(ResumeStack, ResumeKnown, CurfrMaxfr,
+		not_inside_non_condition, Allow),
+	code_info__set_fail_info(FailInfo, !CI).
+
+%---------------------------------------------------------------------------%
+
+code_info__make_resume_point(ResumeVars, ResumeLocs, FullMap, ResumePoint,
+		!CI) :-
+	code_info__get_stack_slots(!.CI, StackSlots),
+	map__select(FullMap, ResumeVars, OrigMap),
+	(
+		ResumeLocs = orig_only,
+		code_info__get_next_label(OrigLabel, !CI),
+		OrigAddr = label(OrigLabel),
+		ResumePoint = orig_only(OrigMap, OrigAddr)
+	;
+		ResumeLocs = stack_only,
+		code_info__make_stack_resume_map(ResumeVars,
+			StackSlots, StackMap),
+		code_info__get_next_label(StackLabel, !CI),
+		StackAddr = label(StackLabel),
+		ResumePoint = stack_only(StackMap, StackAddr)
+	;
+		ResumeLocs = orig_and_stack,
+		code_info__make_stack_resume_map(ResumeVars,
+			StackSlots, StackMap),
+		code_info__get_next_label(OrigLabel, !CI),
+		OrigAddr = label(OrigLabel),
+		code_info__get_next_label(StackLabel, !CI),
+		StackAddr = label(StackLabel),
+		ResumePoint = orig_and_stack(OrigMap, OrigAddr,
+			StackMap, StackAddr)
+	;
+		ResumeLocs = stack_and_orig,
+		code_info__make_stack_resume_map(ResumeVars,
+			StackSlots, StackMap),
+		code_info__get_next_label(StackLabel, !CI),
+		StackAddr = label(StackLabel),
+		code_info__get_next_label(OrigLabel, !CI),
+		OrigAddr = label(OrigLabel),
+		ResumePoint = stack_and_orig(StackMap, StackAddr,
+			OrigMap, OrigAddr)
 	).
 
 :- pred code_info__make_stack_resume_map(set(prog_var)::in, stack_slots::in,
@@ -2468,60 +2440,60 @@
 	% in the other order (e.g. because the code after the resumption point
 	% needs most of the variables in their stack slots).
 
-code_info__generate_resume_point(ResumePoint, Code) -->
+code_info__generate_resume_point(ResumePoint, Code, !CI) :-
 	(
-		{ ResumePoint = orig_only(Map1, Addr1) },
-		{ extract_label_from_code_addr(Addr1, Label1) },
-		{ Code = node([
+		ResumePoint = orig_only(Map1, Addr1),
+		extract_label_from_code_addr(Addr1, Label1),
+		Code = node([
 			label(Label1) -
 				"orig only failure continuation"
-		]) },
-		code_info__set_var_locations(Map1)
+		]),
+		code_info__set_var_locations(Map1, !CI)
 	;
-		{ ResumePoint = stack_only(Map1, Addr1) },
-		{ extract_label_from_code_addr(Addr1, Label1) },
-		{ Code = node([
+		ResumePoint = stack_only(Map1, Addr1),
+		extract_label_from_code_addr(Addr1, Label1),
+		Code = node([
 			label(Label1) -
 				"stack only failure continuation"
-		]) },
-		code_info__set_var_locations(Map1),
-		code_info__generate_resume_layout(Label1, Map1)
-	;
-		{ ResumePoint = stack_and_orig(Map1, Addr1, Map2, Addr2) },
-		{ extract_label_from_code_addr(Addr1, Label1) },
-		{ extract_label_from_code_addr(Addr2, Label2) },
-		{ Label1Code = node([
+		]),
+		code_info__set_var_locations(Map1, !CI),
+		code_info__generate_resume_layout(Label1, Map1, !CI)
+	;
+		ResumePoint = stack_and_orig(Map1, Addr1, Map2, Addr2),
+		extract_label_from_code_addr(Addr1, Label1),
+		extract_label_from_code_addr(Addr2, Label2),
+		Label1Code = node([
 			label(Label1) -
 				"stack failure continuation before orig"
-		]) },
-		code_info__set_var_locations(Map1),
-		code_info__generate_resume_layout(Label1, Map1),
-		{ map__to_assoc_list(Map2, AssocList2) },
-		code_info__place_resume_vars(AssocList2, PlaceCode),
-		{ Label2Code = node([
+		]),
+		code_info__set_var_locations(Map1, !CI),
+		code_info__generate_resume_layout(Label1, Map1, !CI),
+		map__to_assoc_list(Map2, AssocList2),
+		code_info__place_resume_vars(AssocList2, PlaceCode, !CI),
+		Label2Code = node([
 			label(Label2) -
 				"orig failure continuation after stack"
-		]) },
-		code_info__set_var_locations(Map2),
-		{ Code = tree(Label1Code, tree(PlaceCode, Label2Code)) }
-	;
-		{ ResumePoint = orig_and_stack(Map1, Addr1, Map2, Addr2) },
-		{ extract_label_from_code_addr(Addr1, Label1) },
-		{ extract_label_from_code_addr(Addr2, Label2) },
-		{ Label1Code = node([
+		]),
+		code_info__set_var_locations(Map2, !CI),
+		Code = tree(Label1Code, tree(PlaceCode, Label2Code))
+	;
+		ResumePoint = orig_and_stack(Map1, Addr1, Map2, Addr2),
+		extract_label_from_code_addr(Addr1, Label1),
+		extract_label_from_code_addr(Addr2, Label2),
+		Label1Code = node([
 			label(Label1) -
 				"orig failure continuation before stack"
-		]) },
-		code_info__set_var_locations(Map1),
-		{ map__to_assoc_list(Map2, AssocList2) },
-		code_info__place_resume_vars(AssocList2, PlaceCode),
-		{ Label2Code = node([
+		]),
+		code_info__set_var_locations(Map1, !CI),
+		map__to_assoc_list(Map2, AssocList2),
+		code_info__place_resume_vars(AssocList2, PlaceCode, !CI),
+		Label2Code = node([
 			label(Label2) -
 				"stack failure continuation after orig"
-		]) },
-		code_info__set_var_locations(Map2),
-		code_info__generate_resume_layout(Label2, Map2),
-		{ Code = tree(Label1Code, tree(PlaceCode, Label2Code)) }
+		]),
+		code_info__set_var_locations(Map2, !CI),
+		code_info__generate_resume_layout(Label2, Map2, !CI),
+		Code = tree(Label1Code, tree(PlaceCode, Label2Code))
 	).
 
 :- pred extract_label_from_code_addr(code_addr::in, label::out) is det.
@@ -2536,21 +2508,21 @@
 :- pred code_info__place_resume_vars(assoc_list(prog_var, set(lval))::in,
 	code_tree::out, code_info::in, code_info::out) is det.
 
-code_info__place_resume_vars([], empty) --> [].
-code_info__place_resume_vars([Var - TargetSet | Rest], Code) -->
-	{ set__to_sorted_list(TargetSet, Targets) },
-	code_info__place_resume_var(Var, Targets, FirstCode),
-	{ Code = tree(FirstCode, RestCode) },
-	code_info__place_resume_vars(Rest, RestCode).
+code_info__place_resume_vars([], empty, !CI).
+code_info__place_resume_vars([Var - TargetSet | Rest], Code, !CI) :-
+	set__to_sorted_list(TargetSet, Targets),
+	code_info__place_resume_var(Var, Targets, FirstCode, !CI),
+	Code = tree(FirstCode, RestCode),
+	code_info__place_resume_vars(Rest, RestCode, !CI).
 
 :- pred code_info__place_resume_var(prog_var::in, list(lval)::in,
 	code_tree::out, code_info::in, code_info::out) is det.
 
-code_info__place_resume_var(_Var, [], empty) --> [].
-code_info__place_resume_var(Var, [Target | Targets], Code) -->
-	code_info__place_var(Var, Target, FirstCode),
-	code_info__place_resume_var(Var, Targets, RestCode),
-	{ Code = tree(FirstCode, RestCode) }.
+code_info__place_resume_var(_Var, [], empty, !CI).
+code_info__place_resume_var(Var, [Target | Targets], Code, !CI) :-
+	code_info__place_var(Var, Target, FirstCode, !CI),
+	code_info__place_resume_var(Var, Targets, RestCode, !CI),
+	Code = tree(FirstCode, RestCode).
 
 	% Reset the code generator's database of what is where.
 	% Remember that the variables in the map are available in their
@@ -2559,12 +2531,12 @@
 :- pred code_info__set_var_locations(resume_map::in,
 	code_info::in, code_info::out) is det.
 
-code_info__set_var_locations(Map) -->
-	{ map__to_assoc_list(Map, LvalList0) },
-	{ code_info__flatten_varlval_list(LvalList0, LvalList) },
-	code_info__get_var_locn_info(VarLocnInfo0),
-	{ var_locn__reinit_state(LvalList, VarLocnInfo0, VarLocnInfo) },
-	code_info__set_var_locn_info(VarLocnInfo).
+code_info__set_var_locations(Map, !CI) :-
+	map__to_assoc_list(Map, LvalList0),
+	code_info__flatten_varlval_list(LvalList0, LvalList),
+	code_info__get_var_locn_info(!.CI, VarLocnInfo0),
+	var_locn__reinit_state(LvalList, VarLocnInfo0, VarLocnInfo),
+	code_info__set_var_locn_info(VarLocnInfo, !CI).
 
 :- pred code_info__flatten_varlval_list(assoc_list(prog_var, set(lval))::in,
 	assoc_list(prog_var, lval)::out) is det.
@@ -2595,49 +2567,49 @@
 :- pred code_info__maybe_save_trail_info(maybe(pair(lval))::out,
 	code_tree::out, code_info::in, code_info::out) is det.
 
-code_info__maybe_save_trail_info(MaybeTrailSlots, SaveTrailCode) -->
-	code_info__get_globals(Globals),
-	{ globals__lookup_bool_option(Globals, use_trail, UseTrail) },
-	( { UseTrail = yes } ->
-		code_info__acquire_temp_slot(ticket_counter, CounterSlot),
-		code_info__acquire_temp_slot(ticket, TrailPtrSlot),
-		{ MaybeTrailSlots = yes(CounterSlot - TrailPtrSlot) },
-		{ SaveTrailCode = node([
+code_info__maybe_save_trail_info(MaybeTrailSlots, SaveTrailCode, !CI) :-
+	code_info__get_globals(!.CI, Globals),
+	globals__lookup_bool_option(Globals, use_trail, UseTrail),
+	( UseTrail = yes ->
+		code_info__acquire_temp_slot(ticket_counter, CounterSlot, !CI),
+		code_info__acquire_temp_slot(ticket, TrailPtrSlot, !CI),
+		MaybeTrailSlots = yes(CounterSlot - TrailPtrSlot),
+		SaveTrailCode = node([
 			mark_ticket_stack(CounterSlot)
 				- "save the ticket counter",
 			store_ticket(TrailPtrSlot)
 				- "save the trail pointer"
-		]) }
+		])
 	;
-		{ MaybeTrailSlots = no },
-		{ SaveTrailCode = empty }
+		MaybeTrailSlots = no,
+		SaveTrailCode = empty
 	).
 
 :- pred code_info__maybe_restore_trail_info(maybe(pair(lval))::in,
 	code_tree::out, code_tree::out, code_info::in, code_info::out) is det.
 
 code_info__maybe_restore_trail_info(MaybeTrailSlots,
-		CommitCode, RestoreCode) -->
+		CommitCode, RestoreCode, !CI) :-
 	(
-		{ MaybeTrailSlots = no },
-		{ CommitCode = empty },
-		{ RestoreCode = empty }
+		MaybeTrailSlots = no,
+		CommitCode = empty,
+		RestoreCode = empty
 	;
-		{ MaybeTrailSlots = yes(CounterSlot - TrailPtrSlot) },
-		{ CommitCode = node([
+		MaybeTrailSlots = yes(CounterSlot - TrailPtrSlot),
+		CommitCode = node([
 			reset_ticket(lval(TrailPtrSlot), commit)
 				- "discard trail entries and restore trail ptr",
 			prune_tickets_to(lval(CounterSlot))
 				- "restore ticket counter (but not high water mark)"
-		]) },
-		{ RestoreCode = node([
+		]),
+		RestoreCode = node([
 			reset_ticket(lval(TrailPtrSlot), undo)
 				- "apply trail entries and restore trail ptr",
 			discard_ticket
 				- "restore ticket counter and high water mark"
-		]) },
-		code_info__release_temp_slot(CounterSlot),
-		code_info__release_temp_slot(TrailPtrSlot)
+		]),
+		code_info__release_temp_slot(CounterSlot, !CI),
+		code_info__release_temp_slot(TrailPtrSlot, !CI)
 	).
 
 %---------------------------------------------------------------------------%
@@ -2645,29 +2617,29 @@
 :- pred code_info__clone_resume_point(resume_point_info::in,
 	resume_point_info::out, code_info::in, code_info::out) is det.
 
-code_info__clone_resume_point(ResumePoint0, ResumePoint) -->
+code_info__clone_resume_point(ResumePoint0, ResumePoint, !CI) :-
 	(
-		{ ResumePoint0 = orig_only(_, _) },
-		{ error("cloning orig_only resume point") }
+		ResumePoint0 = orig_only(_, _),
+		error("cloning orig_only resume point")
 	;
-		{ ResumePoint0 = stack_only(Map1, _) },
-		code_info__get_next_label(Label1),
-		{ Addr1 = label(Label1) },
-		{ ResumePoint = stack_only(Map1, Addr1) }
-	;
-		{ ResumePoint0 = stack_and_orig(Map1, _, Map2, _) },
-		code_info__get_next_label(Label1),
-		{ Addr1 = label(Label1) },
-		code_info__get_next_label(Label2),
-		{ Addr2 = label(Label2) },
-		{ ResumePoint = stack_and_orig(Map1, Addr1, Map2, Addr2) }
-	;
-		{ ResumePoint0 = orig_and_stack(Map1, _, Map2, _) },
-		code_info__get_next_label(Label2),
-		{ Addr2 = label(Label2) },
-		code_info__get_next_label(Label1),
-		{ Addr1 = label(Label1) },
-		{ ResumePoint = stack_and_orig(Map2, Addr2, Map1, Addr1) }
+		ResumePoint0 = stack_only(Map1, _),
+		code_info__get_next_label(Label1, !CI),
+		Addr1 = label(Label1),
+		ResumePoint = stack_only(Map1, Addr1)
+	;
+		ResumePoint0 = stack_and_orig(Map1, _, Map2, _),
+		code_info__get_next_label(Label1, !CI),
+		Addr1 = label(Label1),
+		code_info__get_next_label(Label2, !CI),
+		Addr2 = label(Label2),
+		ResumePoint = stack_and_orig(Map1, Addr1, Map2, Addr2)
+	;
+		ResumePoint0 = orig_and_stack(Map1, _, Map2, _),
+		code_info__get_next_label(Label2, !CI),
+		Addr2 = label(Label2),
+		code_info__get_next_label(Label1, !CI),
+		Addr1 = label(Label1),
+		ResumePoint = stack_and_orig(Map2, Addr2, Map1, Addr1)
 	).
 
 %---------------------------------------------------------------------------%
@@ -2680,121 +2652,119 @@
 
 :- interface.
 
-:- pred code_info__get_known_variables(list(prog_var), code_info, code_info).
-:- mode code_info__get_known_variables(out, in, out) is det.
+:- pred code_info__get_known_variables(code_info::in, list(prog_var)::out)
+	is det.
 
-:- pred code_info__variable_is_forward_live(prog_var, code_info, code_info).
-:- mode code_info__variable_is_forward_live(in, in, out) is semidet.
+:- pred code_info__variable_is_forward_live(code_info::in, prog_var::in)
+	is semidet.
 
-:- pred code_info__make_vars_forward_dead(set(prog_var), code_info, code_info).
-:- mode code_info__make_vars_forward_dead(in, in, out) is det.
+:- pred code_info__make_vars_forward_dead(set(prog_var)::in,
+	code_info::in, code_info::out) is det.
 
-:- pred code_info__pickup_zombies(set(prog_var), code_info, code_info).
-:- mode code_info__pickup_zombies(out, in, out) is det.
+:- pred code_info__pickup_zombies(set(prog_var)::out,
+	code_info::in, code_info::out) is det.
 
 %---------------------------------------------------------------------------%
 
 :- implementation.
 
-:- pred code_info__add_forward_live_vars(set(prog_var), code_info, code_info).
-:- mode code_info__add_forward_live_vars(in, in, out) is det.
+:- pred code_info__add_forward_live_vars(set(prog_var)::in,
+	code_info::in, code_info::out) is det.
 
-:- pred code_info__rem_forward_live_vars(set(prog_var), code_info, code_info).
-:- mode code_info__rem_forward_live_vars(in, in, out) is det.
+:- pred code_info__rem_forward_live_vars(set(prog_var)::in,
+	code_info::in, code_info::out) is det.
 
 	% Make these variables appear magically live.
 	% We don't care where they are put.
 
-:- pred code_info__make_vars_forward_live(set(prog_var), code_info, code_info).
-:- mode code_info__make_vars_forward_live(in, in, out) is det.
+:- pred code_info__make_vars_forward_live(set(prog_var)::in,
+	code_info::in, code_info::out) is det.
 
-code_info__get_known_variables(VarList) -->
-	code_info__get_forward_live_vars(ForwardLiveVars),
-	code_info__current_resume_point_vars(ResumeVars),
-	{ set__union(ForwardLiveVars, ResumeVars, Vars) },
-	{ set__to_sorted_list(Vars, VarList) }.
-
-code_info__variable_is_forward_live(Var) -->
-	code_info__get_forward_live_vars(Liveness),
-	{ set__member(Var, Liveness) }.
-
-code_info__add_forward_live_vars(Births) -->
-	code_info__get_forward_live_vars(Liveness0),
-	{ set__union(Liveness0, Births, Liveness) },
-	code_info__set_forward_live_vars(Liveness).
-
-code_info__rem_forward_live_vars(Deaths) -->
-	code_info__get_forward_live_vars(Liveness0),
-	{ set__difference(Liveness0, Deaths, Liveness) },
-	code_info__set_forward_live_vars(Liveness).
-
-code_info__make_vars_forward_live(Vars) -->
-	code_info__get_stack_slots(StackSlots),
-	code_info__get_var_locn_info(VarLocnInfo0),
-	{ set__to_sorted_list(Vars, VarList) },
-	{ code_info__make_vars_forward_live_2(VarList, StackSlots, 1,
-		VarLocnInfo0, VarLocnInfo) },
-	code_info__set_var_locn_info(VarLocnInfo).
+code_info__get_known_variables(CI, VarList) :-
+	code_info__get_forward_live_vars(CI, ForwardLiveVars),
+	ResumeVars = code_info__current_resume_point_vars(CI),
+	set__union(ForwardLiveVars, ResumeVars, Vars),
+	set__to_sorted_list(Vars, VarList).
+
+code_info__variable_is_forward_live(CI, Var) :-
+	code_info__get_forward_live_vars(CI, Liveness),
+	set__member(Var, Liveness).
+
+code_info__add_forward_live_vars(Births, !CI) :-
+	code_info__get_forward_live_vars(!.CI, Liveness0),
+	set__union(Liveness0, Births, Liveness),
+	code_info__set_forward_live_vars(Liveness, !CI).
+
+code_info__rem_forward_live_vars(Deaths, !CI) :-
+	code_info__get_forward_live_vars(!.CI, Liveness0),
+	set__difference(Liveness0, Deaths, Liveness),
+	code_info__set_forward_live_vars(Liveness, !CI).
+
+code_info__make_vars_forward_live(Vars, !CI) :-
+	code_info__get_stack_slots(!.CI, StackSlots),
+	code_info__get_var_locn_info(!.CI, VarLocnInfo0),
+	set__to_sorted_list(Vars, VarList),
+	code_info__make_vars_forward_live_2(VarList, StackSlots, 1,
+		VarLocnInfo0, VarLocnInfo),
+	code_info__set_var_locn_info(VarLocnInfo, !CI).
 
 :- pred code_info__make_vars_forward_live_2(list(prog_var)::in,
-	stack_slots::in, int::in, var_locn_info::in, var_locn_info::out) is det.
+	stack_slots::in, int::in, var_locn_info::in, var_locn_info::out)
+	is det.
 
-code_info__make_vars_forward_live_2([], _, _, VarLocnInfo, VarLocnInfo).
+code_info__make_vars_forward_live_2([], _, _, !VarLocnInfo).
 code_info__make_vars_forward_live_2([Var | Vars], StackSlots, N0,
-		VarLocnInfo0, VarLocnInfo) :-
+		!VarLocnInfo) :-
 	( map__search(StackSlots, Var, Lval0) ->
 		Lval = Lval0,
 		N1 = N0
 	;
-		code_info__find_unused_reg(N0, VarLocnInfo0, N1),
+		code_info__find_unused_reg(!.VarLocnInfo, N0, N1),
 		Lval = reg(r, N1)
 	),
-	var_locn__set_magic_var_location(Var, Lval, VarLocnInfo0, VarLocnInfo1),
+	var_locn__set_magic_var_location(Var, Lval, !VarLocnInfo),
 	code_info__make_vars_forward_live_2(Vars, StackSlots, N1,
-		VarLocnInfo1, VarLocnInfo).
+		!VarLocnInfo).
 
-:- pred code_info__find_unused_reg(int::in, var_locn_info::in, int::out) is det.
+:- pred code_info__find_unused_reg(var_locn_info::in, int::in, int::out) is det.
 
-code_info__find_unused_reg(N0, Exprn0, N) :-
-	( var_locn__lval_in_use(reg(r, N0), Exprn0, _) ->
-		code_info__find_unused_reg(N0 + 1, Exprn0, N)
+code_info__find_unused_reg(VLI, N0, N) :-
+	( var_locn__lval_in_use(VLI, reg(r, N0)) ->
+		code_info__find_unused_reg(VLI, N0 + 1, N)
 	;
 		N = N0
 	).
 
-code_info__make_vars_forward_dead(Vars) -->
-	code_info__maybe_make_vars_forward_dead(Vars, yes).
+code_info__make_vars_forward_dead(Vars, !CI) :-
+	code_info__maybe_make_vars_forward_dead(Vars, yes, !CI).
 
-:- pred code_info__maybe_make_vars_forward_dead(set(prog_var), bool,
-	code_info, code_info).
-:- mode code_info__maybe_make_vars_forward_dead(in, in, in, out) is det.
-
-code_info__maybe_make_vars_forward_dead(Vars0, FirstTime) -->
-	code_info__current_resume_point_vars(ResumeVars),
-	{ set__intersect(Vars0, ResumeVars, FlushVars) },
-	code_info__get_zombies(Zombies0),
-	{ set__union(Zombies0, FlushVars, Zombies) },
-	code_info__set_zombies(Zombies),
-	{ set__difference(Vars0, Zombies, Vars) },
-	{ set__to_sorted_list(Vars, VarList) },
-	code_info__maybe_make_vars_forward_dead_2(VarList, FirstTime).
-
-:- pred code_info__maybe_make_vars_forward_dead_2(list(prog_var), bool,
-	code_info, code_info).
-:- mode code_info__maybe_make_vars_forward_dead_2(in, in, in, out) is det.
-
-code_info__maybe_make_vars_forward_dead_2([], _) --> [].
-code_info__maybe_make_vars_forward_dead_2([V | Vs], FirstTime) -->
-	code_info__get_var_locn_info(VarLocnInfo0),
-	{ var_locn__var_becomes_dead(V, FirstTime,
-		VarLocnInfo0, VarLocnInfo) },
-	code_info__set_var_locn_info(VarLocnInfo),
-	code_info__maybe_make_vars_forward_dead_2(Vs, FirstTime).
-
-code_info__pickup_zombies(Zombies) -->
-	code_info__get_zombies(Zombies),
-	{ set__init(Empty) },
-	code_info__set_zombies(Empty).
+:- pred code_info__maybe_make_vars_forward_dead(set(prog_var)::in, bool::in,
+	code_info::in, code_info::out) is det.
+
+code_info__maybe_make_vars_forward_dead(Vars0, FirstTime, !CI) :-
+	ResumeVars = code_info__current_resume_point_vars(!.CI),
+	set__intersect(Vars0, ResumeVars, FlushVars),
+	code_info__get_zombies(!.CI, Zombies0),
+	set__union(Zombies0, FlushVars, Zombies),
+	code_info__set_zombies(Zombies, !CI),
+	set__difference(Vars0, Zombies, Vars),
+	set__to_sorted_list(Vars, VarList),
+	code_info__maybe_make_vars_forward_dead_2(VarList, FirstTime, !CI).
+
+:- pred code_info__maybe_make_vars_forward_dead_2(list(prog_var)::in, bool::in,
+	code_info::in, code_info::out) is det.
+
+code_info__maybe_make_vars_forward_dead_2([], _, !CI).
+code_info__maybe_make_vars_forward_dead_2([V | Vs], FirstTime, !CI) :-
+	code_info__get_var_locn_info(!.CI, VarLocnInfo0),
+	var_locn__var_becomes_dead(V, FirstTime,
+		VarLocnInfo0, VarLocnInfo),
+	code_info__set_var_locn_info(VarLocnInfo, !CI),
+	code_info__maybe_make_vars_forward_dead_2(Vs, FirstTime, !CI).
+
+code_info__pickup_zombies(Zombies, !CI) :-
+	code_info__get_zombies(!.CI, Zombies),
+	code_info__set_zombies(set__init, !CI).
 
 %---------------------------------------------------------------------------%
 %---------------------------------------------------------------------------%
@@ -2804,244 +2774,225 @@
 
 :- interface.
 
-:- pred code_info__save_hp(code_tree, lval, code_info, code_info).
-:- mode code_info__save_hp(out, out, in, out) is det.
+:- pred code_info__save_hp(code_tree::out, lval::out,
+	code_info::in, code_info::out) is det.
 
-:- pred code_info__restore_hp(lval, code_tree, code_info, code_info).
-:- mode code_info__restore_hp(in, out, in, out) is det.
+:- pred code_info__restore_hp(lval::in, code_tree::out) is det.
 
-:- pred code_info__release_hp(lval, code_info, code_info).
-:- mode code_info__release_hp(in, in, out) is det.
+:- pred code_info__release_hp(lval::in,
+	code_info::in, code_info::out) is det.
 
-:- pred code_info__restore_and_release_hp(lval, code_tree,
-	code_info, code_info).
-:- mode code_info__restore_and_release_hp(in, out, in, out) is det.
+:- pred code_info__restore_and_release_hp(lval::in, code_tree::out,
+	code_info::in, code_info::out) is det.
 
-:- pred code_info__maybe_save_hp(bool, code_tree, maybe(lval),
-	code_info, code_info).
-:- mode code_info__maybe_save_hp(in, out, out, in, out) is det.
+:- pred code_info__maybe_save_hp(bool::in, code_tree::out, maybe(lval)::out,
+	code_info::in, code_info::out) is det.
 
-:- pred code_info__maybe_restore_hp(maybe(lval), code_tree,
-	code_info, code_info).
-:- mode code_info__maybe_restore_hp(in, out, in, out) is det.
+:- pred code_info__maybe_restore_hp(maybe(lval)::in, code_tree::out) is det.
 
-:- pred code_info__maybe_release_hp(maybe(lval), code_info, code_info).
-:- mode code_info__maybe_release_hp(in, in, out) is det.
+:- pred code_info__maybe_release_hp(maybe(lval)::in,
+	code_info::in, code_info::out) is det.
 
-:- pred code_info__maybe_restore_and_release_hp(maybe(lval), code_tree,
-	code_info, code_info).
-:- mode code_info__maybe_restore_and_release_hp(in, out, in, out) is det.
+:- pred code_info__maybe_restore_and_release_hp(maybe(lval)::in,
+	code_tree::out, code_info::in, code_info::out) is det.
 
-:- pred code_info__save_ticket(code_tree, lval, code_info, code_info).
-:- mode code_info__save_ticket(out, out, in, out) is det.
+:- pred code_info__save_ticket(code_tree::out, lval::out,
+	code_info::in, code_info::out) is det.
 
-:- pred code_info__reset_ticket(lval, reset_trail_reason, code_tree,
-	code_info, code_info).
-:- mode code_info__reset_ticket(in, in, out, in, out) is det.
+:- pred code_info__reset_ticket(lval::in, reset_trail_reason::in,
+	code_tree::out) is det.
 
-:- pred code_info__release_ticket(lval, code_info, code_info).
-:- mode code_info__release_ticket(in, in, out) is det.
+:- pred code_info__release_ticket(lval::in,
+	code_info::in, code_info::out) is det.
 
-:- pred code_info__reset_and_prune_ticket(lval, reset_trail_reason,
-	code_tree, code_info, code_info).
-:- mode code_info__reset_and_prune_ticket(in, in, out, in, out) is det.
+:- pred code_info__reset_and_prune_ticket(lval::in, reset_trail_reason::in,
+	code_tree::out) is det.
 
-:- pred code_info__reset_prune_and_release_ticket(lval, reset_trail_reason,
-	code_tree, code_info, code_info).
-:- mode code_info__reset_prune_and_release_ticket(in, in, out, in, out)
-	is det.
+:- pred code_info__reset_prune_and_release_ticket(lval::in,
+	reset_trail_reason::in, code_tree::out,
+	code_info::in, code_info::out) is det.
 
-:- pred code_info__reset_and_discard_ticket(lval, reset_trail_reason,
-	code_tree, code_info, code_info).
-:- mode code_info__reset_and_discard_ticket(in, in, out, in, out) is det.
-
-:- pred code_info__reset_discard_and_release_ticket(lval, reset_trail_reason,
-	code_tree, code_info, code_info).
-:- mode code_info__reset_discard_and_release_ticket(in, in, out, in, out)
-	is det.
+:- pred code_info__reset_and_discard_ticket(lval::in, reset_trail_reason::in,
+	code_tree::out) is det.
 
-:- pred code_info__maybe_save_ticket(bool, code_tree, maybe(lval),
-	code_info, code_info).
-:- mode code_info__maybe_save_ticket(in, out, out, in, out) is det.
-
-:- pred code_info__maybe_reset_ticket(maybe(lval), reset_trail_reason,
-	code_tree, code_info, code_info).
-:- mode code_info__maybe_reset_ticket(in, in, out, in, out) is det.
-
-:- pred code_info__maybe_release_ticket(maybe(lval), code_info, code_info).
-:- mode code_info__maybe_release_ticket(in, in, out) is det.
-
-:- pred code_info__maybe_reset_and_prune_ticket(maybe(lval),
-	reset_trail_reason, code_tree, code_info, code_info).
-:- mode code_info__maybe_reset_and_prune_ticket(in, in, out, in, out) is det.
-
-:- pred code_info__maybe_reset_prune_and_release_ticket(maybe(lval),
-	reset_trail_reason, code_tree, code_info, code_info).
-:- mode code_info__maybe_reset_prune_and_release_ticket(in, in, out, in, out)
-	is det.
+:- pred code_info__reset_discard_and_release_ticket(lval::in,
+	reset_trail_reason::in, code_tree::out,
+	code_info::in, code_info::out) is det.
 
-:- pred code_info__maybe_reset_and_discard_ticket(maybe(lval),
-	reset_trail_reason, code_tree, code_info, code_info).
-:- mode code_info__maybe_reset_and_discard_ticket(in, in, out, in, out) is det.
-
-:- pred code_info__maybe_reset_discard_and_release_ticket(maybe(lval),
-	reset_trail_reason, code_tree, code_info, code_info).
-:- mode code_info__maybe_reset_discard_and_release_ticket(in, in, out, in, out)
-	is det.
+:- pred code_info__maybe_save_ticket(bool::in, code_tree::out,
+	maybe(lval)::out, code_info::in, code_info::out) is det.
+
+:- pred code_info__maybe_reset_ticket(maybe(lval)::in, reset_trail_reason::in,
+	code_tree::out) is det.
+
+:- pred code_info__maybe_release_ticket(maybe(lval)::in,
+	code_info::in, code_info::out) is det.
+
+:- pred code_info__maybe_reset_and_prune_ticket(maybe(lval)::in,
+	reset_trail_reason::in, code_tree::out) is det.
+
+:- pred code_info__maybe_reset_prune_and_release_ticket(maybe(lval)::in,
+	reset_trail_reason::in, code_tree::out,
+	code_info::in, code_info::out) is det.
+
+:- pred code_info__maybe_reset_and_discard_ticket(maybe(lval)::in,
+	reset_trail_reason::in, code_tree::out) is det.
+
+:- pred code_info__maybe_reset_discard_and_release_ticket(maybe(lval)::in,
+	reset_trail_reason::in, code_tree::out,
+	code_info::in, code_info::out) is det.
 
 %---------------------------------------------------------------------------%
 
 :- implementation.
 
-code_info__save_hp(Code, HpSlot) -->
-	code_info__acquire_temp_slot(lval(hp), HpSlot),
-	{ Code = node([
+code_info__save_hp(Code, HpSlot, !CI) :-
+	code_info__acquire_temp_slot(lval(hp), HpSlot, !CI),
+	Code = node([
 		mark_hp(HpSlot) - "Save heap pointer"
-	]) }.
+	]).
 
-code_info__restore_hp(HpSlot, Code) -->
-	{ Code = node([
+code_info__restore_hp(HpSlot, Code) :-
+	Code = node([
 		restore_hp(lval(HpSlot)) - "Restore heap pointer"
-	]) }.
+	]).
 
-code_info__release_hp(HpSlot) -->
-	code_info__release_temp_slot(HpSlot).
+code_info__release_hp(HpSlot, !CI) :-
+	code_info__release_temp_slot(HpSlot, !CI).
 
-code_info__restore_and_release_hp(HpSlot, Code) -->
-	{ Code = node([
-		restore_hp(lval(HpSlot)) - "Release heap pointer"
-	]) },
-	code_info__release_hp(HpSlot).
+code_info__restore_and_release_hp(HpSlot, Code, !CI) :-
+	code_info__restore_hp(HpSlot, Code),
+	code_info__release_hp(HpSlot, !CI).
 
 %---------------------------------------------------------------------------%
 
-code_info__maybe_save_hp(Maybe, Code, MaybeHpSlot) -->
-	( { Maybe = yes } ->
-		code_info__save_hp(Code, HpSlot),
-		{ MaybeHpSlot = yes(HpSlot) }
+code_info__maybe_save_hp(Maybe, Code, MaybeHpSlot, !CI) :-
+	( Maybe = yes ->
+		code_info__save_hp(Code, HpSlot, !CI),
+		MaybeHpSlot = yes(HpSlot)
 	;
-		{ Code = empty },
-		{ MaybeHpSlot = no }
+		Code = empty,
+		MaybeHpSlot = no
 	).
 
-code_info__maybe_restore_hp(MaybeHpSlot, Code) -->
-	( { MaybeHpSlot = yes(HpSlot) } ->
+code_info__maybe_restore_hp(MaybeHpSlot, Code) :-
+	( MaybeHpSlot = yes(HpSlot) ->
 		code_info__restore_hp(HpSlot, Code)
 	;
-		{ Code = empty }
+		Code = empty
 	).
 
-code_info__maybe_release_hp(MaybeHpSlot) -->
-	( { MaybeHpSlot = yes(HpSlot) } ->
-		code_info__release_hp(HpSlot)
+code_info__maybe_release_hp(MaybeHpSlot, !CI) :-
+	( MaybeHpSlot = yes(HpSlot) ->
+		code_info__release_hp(HpSlot, !CI)
 	;
-		[]
+		true
 	).
 
-code_info__maybe_restore_and_release_hp(MaybeHpSlot, Code) -->
-	( { MaybeHpSlot = yes(HpSlot) } ->
-		code_info__restore_and_release_hp(HpSlot, Code)
+code_info__maybe_restore_and_release_hp(MaybeHpSlot, Code, !CI) :-
+	( MaybeHpSlot = yes(HpSlot) ->
+		code_info__restore_and_release_hp(HpSlot, Code, !CI)
 	;
-		{ Code = empty }
+		Code = empty
 	).
 
 %---------------------------------------------------------------------------%
 
-code_info__save_ticket(Code, TicketSlot) -->
-	code_info__acquire_temp_slot(ticket, TicketSlot),
-	{ Code = node([
+code_info__save_ticket(Code, TicketSlot, !CI) :-
+	code_info__acquire_temp_slot(ticket, TicketSlot, !CI),
+	Code = node([
 		store_ticket(TicketSlot) - "Save trail state"
-	]) }.
+	]).
 
-code_info__reset_ticket(TicketSlot, Reason, Code) -->
-	{ Code = node([
+code_info__reset_ticket(TicketSlot, Reason, Code) :-
+	Code = node([
 		reset_ticket(lval(TicketSlot), Reason) - "Reset trail"
-	]) }.
+	]).
 
-code_info__release_ticket(TicketSlot) -->
-	code_info__release_temp_slot(TicketSlot).
+code_info__release_ticket(TicketSlot, !CI) :-
+	code_info__release_temp_slot(TicketSlot, !CI).
 
-code_info__reset_and_prune_ticket(TicketSlot, Reason, Code) -->
-	{ Code = node([
+code_info__reset_and_prune_ticket(TicketSlot, Reason, Code) :-
+	Code = node([
 		reset_ticket(lval(TicketSlot), Reason) - "Restore trail",
 		prune_ticket - "Prune ticket stack"
-	]) }.
+	]).
 
-code_info__reset_prune_and_release_ticket(TicketSlot, Reason, Code) -->
-	{ Code = node([
+code_info__reset_prune_and_release_ticket(TicketSlot, Reason, Code, !CI) :-
+	Code = node([
 		reset_ticket(lval(TicketSlot), Reason) - "Release trail",
 		prune_ticket - "Prune ticket stack"
-	]) },
-	code_info__release_temp_slot(TicketSlot).
+	]),
+	code_info__release_temp_slot(TicketSlot, !CI).
 
-code_info__reset_and_discard_ticket(TicketSlot, Reason, Code) -->
-	{ Code = node([
+code_info__reset_and_discard_ticket(TicketSlot, Reason, Code) :-
+	Code = node([
 		reset_ticket(lval(TicketSlot), Reason) - "Restore trail",
 		discard_ticket - "Pop ticket stack"
-	]) }.
+	]).
 
-code_info__reset_discard_and_release_ticket(TicketSlot, Reason, Code) -->
-	{ Code = node([
+code_info__reset_discard_and_release_ticket(TicketSlot, Reason, Code, !CI) :-
+	Code = node([
 		reset_ticket(lval(TicketSlot), Reason) - "Release trail",
 		discard_ticket - "Pop ticket stack"
-	]) },
-	code_info__release_temp_slot(TicketSlot).
+	]),
+	code_info__release_temp_slot(TicketSlot, !CI).
 
 %---------------------------------------------------------------------------%
 
-code_info__maybe_save_ticket(Maybe, Code, MaybeTicketSlot) -->
-	( { Maybe = yes } ->
-		code_info__save_ticket(Code, TicketSlot),
-		{ MaybeTicketSlot = yes(TicketSlot) }
+code_info__maybe_save_ticket(Maybe, Code, MaybeTicketSlot, !CI) :-
+	( Maybe = yes ->
+		code_info__save_ticket(Code, TicketSlot, !CI),
+		MaybeTicketSlot = yes(TicketSlot)
 	;
-		{ Code = empty },
-		{ MaybeTicketSlot = no }
+		Code = empty,
+		MaybeTicketSlot = no
 	).
 
-code_info__maybe_reset_ticket(MaybeTicketSlot, Reason, Code) -->
-	( { MaybeTicketSlot = yes(TicketSlot) } ->
+code_info__maybe_reset_ticket(MaybeTicketSlot, Reason, Code) :-
+	( MaybeTicketSlot = yes(TicketSlot) ->
 		code_info__reset_ticket(TicketSlot, Reason, Code)
 	;
-		{ Code = empty }
+		Code = empty
 	).
 
-code_info__maybe_release_ticket(MaybeTicketSlot) -->
-	( { MaybeTicketSlot = yes(TicketSlot) } ->
-		code_info__release_ticket(TicketSlot)
+code_info__maybe_release_ticket(MaybeTicketSlot, !CI) :-
+	( MaybeTicketSlot = yes(TicketSlot) ->
+		code_info__release_ticket(TicketSlot, !CI)
 	;
-		[]
+		true
 	).
 
-code_info__maybe_reset_and_prune_ticket(MaybeTicketSlot, Reason, Code) -->
-	( { MaybeTicketSlot = yes(TicketSlot) } ->
+code_info__maybe_reset_and_prune_ticket(MaybeTicketSlot, Reason, Code) :-
+	( MaybeTicketSlot = yes(TicketSlot) ->
 		code_info__reset_and_prune_ticket(TicketSlot, Reason, Code)
 	;
-		{ Code = empty }
+		Code = empty
 	).
 
 code_info__maybe_reset_prune_and_release_ticket(MaybeTicketSlot, Reason,
-		Code) -->
-	( { MaybeTicketSlot = yes(TicketSlot) } ->
+		Code, !CI) :-
+	( MaybeTicketSlot = yes(TicketSlot) ->
 		code_info__reset_prune_and_release_ticket(TicketSlot, Reason,
-			Code)
+			Code, !CI)
 	;
-		{ Code = empty }
+		Code = empty
 	).
 
-code_info__maybe_reset_and_discard_ticket(MaybeTicketSlot, Reason, Code) -->
-	( { MaybeTicketSlot = yes(TicketSlot) } ->
+code_info__maybe_reset_and_discard_ticket(MaybeTicketSlot, Reason, Code) :-
+	( MaybeTicketSlot = yes(TicketSlot) ->
 		code_info__reset_and_discard_ticket(TicketSlot, Reason, Code)
 	;
-		{ Code = empty }
+		Code = empty
 	).
 
 code_info__maybe_reset_discard_and_release_ticket(MaybeTicketSlot, Reason,
-		Code) -->
-	( { MaybeTicketSlot = yes(TicketSlot) } ->
+		Code, !CI) :-
+	( MaybeTicketSlot = yes(TicketSlot) ->
 		code_info__reset_discard_and_release_ticket(TicketSlot, Reason,
-			Code)
+			Code, !CI)
 	;
-		{ Code = empty }
+		Code = empty
 	).
 
 %---------------------------------------------------------------------------%
@@ -3051,8 +3002,8 @@
 
 :- interface.
 
-:- pred code_info__variable_locations(map(prog_var, set(lval))::out,
-	code_info::in, code_info::out) is det.
+:- pred code_info__variable_locations(code_info::in,
+	map(prog_var, set(lval))::out) is det.
 
 :- pred code_info__set_var_location(prog_var::in, lval::in,
 	code_info::in, code_info::out) is det.
@@ -3149,16 +3100,15 @@
 :- pred code_info__save_variables_on_stack(list(prog_var)::in, code_tree::out,
 	code_info::in, code_info::out) is det.
 
-:- pred code_info__max_reg_in_use(int::out, code_info::in, code_info::out)
-	is det.
+:- pred code_info__max_reg_in_use(code_info::in, int::out) is det.
 
 %---------------------------------------------------------------------------%
 
 :- implementation.
 
-code_info__variable_locations(Lvals) -->
-	code_info__get_var_locn_info(VarLocnInfo),
-	{ var_locn__get_var_locations(VarLocnInfo, Lvals) }.
+code_info__variable_locations(CI, Lvals) :-
+	code_info__get_var_locn_info(CI, VarLocnInfo),
+	var_locn__get_var_locations(VarLocnInfo, Lvals).
 
 :- func code_info__rval_map_to_lval_map(prog_var, set(rval)) = set(lval).
 
@@ -3169,34 +3119,34 @@
 
 code_info__rval_is_lval(lval(Lval)) = Lval.
 
-code_info__set_var_location(Var, Lval) -->
-	code_info__get_var_locn_info(VarLocnInfo0),
-	{ var_locn__check_and_set_magic_var_location(Var, Lval,
-		VarLocnInfo0, VarLocnInfo) },
-	code_info__set_var_locn_info(VarLocnInfo).
-
-code_info__assign_var_to_var(Var, AssignedVar) -->
-	code_info__get_var_locn_info(VarLocnInfo0),
-	{ var_locn__assign_var_to_var(Var, AssignedVar,
-		VarLocnInfo0, VarLocnInfo) },
-	code_info__set_var_locn_info(VarLocnInfo).
-
-code_info__assign_lval_to_var(Var, Lval, Code) -->
-	code_info__get_var_locn_info(VarLocnInfo0),
-	code_info__get_static_cell_info(StaticCellInfo),
-	{ var_locn__assign_lval_to_var(Var, Lval, StaticCellInfo, Code,
-		VarLocnInfo0, VarLocnInfo) },
-	code_info__set_var_locn_info(VarLocnInfo).
-
-code_info__assign_const_to_var(Var, ConstRval) -->
-	code_info__get_var_locn_info(VarLocnInfo0),
-	{ var_locn__assign_const_to_var(Var, ConstRval,
-		VarLocnInfo0, VarLocnInfo) },
-	code_info__set_var_locn_info(VarLocnInfo).
-
-code_info__assign_expr_to_var(Var, Rval, Code) -->
-	code_info__get_var_locn_info(VarLocnInfo0),
-	{
+code_info__set_var_location(Var, Lval, !CI) :-
+	code_info__get_var_locn_info(!.CI, VarLocnInfo0),
+	var_locn__check_and_set_magic_var_location(Var, Lval,
+		VarLocnInfo0, VarLocnInfo),
+	code_info__set_var_locn_info(VarLocnInfo, !CI).
+
+code_info__assign_var_to_var(Var, AssignedVar, !CI) :-
+	code_info__get_var_locn_info(!.CI, VarLocnInfo0),
+	var_locn__assign_var_to_var(Var, AssignedVar,
+		VarLocnInfo0, VarLocnInfo),
+	code_info__set_var_locn_info(VarLocnInfo, !CI).
+
+code_info__assign_lval_to_var(Var, Lval, Code, !CI) :-
+	code_info__get_var_locn_info(!.CI, VarLocnInfo0),
+	code_info__get_static_cell_info(!.CI, StaticCellInfo),
+	var_locn__assign_lval_to_var(Var, Lval, StaticCellInfo, Code,
+		VarLocnInfo0, VarLocnInfo),
+	code_info__set_var_locn_info(VarLocnInfo, !CI).
+
+code_info__assign_const_to_var(Var, ConstRval, !CI) :-
+	code_info__get_var_locn_info(!.CI, VarLocnInfo0),
+	var_locn__assign_const_to_var(Var, ConstRval,
+		VarLocnInfo0, VarLocnInfo),
+	code_info__set_var_locn_info(VarLocnInfo, !CI).
+
+code_info__assign_expr_to_var(Var, Rval, Code, !CI) :-
+	code_info__get_var_locn_info(!.CI, VarLocnInfo0),
+	(
 		code_util__lvals_in_rval(Rval, Lvals),
 		Lvals = []
 	->
@@ -3204,30 +3154,30 @@
 			VarLocnInfo0, VarLocnInfo)
 	;
 		error("code_info__assign_expr_to_var: non-var lvals")
-	},
-	code_info__set_var_locn_info(VarLocnInfo).
+	),
+	code_info__set_var_locn_info(VarLocnInfo, !CI).
 
-code_info__assign_cell_to_var(Var, Ptag, Vector, Size, TypeMsg, Code) -->
-	code_info__get_var_locn_info(VarLocnInfo0),
-	code_info__get_static_cell_info(StaticCellInfo0),
-	{ var_locn__assign_cell_to_var(Var, Ptag, Vector, Size, TypeMsg, Code,
-		StaticCellInfo0, StaticCellInfo, VarLocnInfo0, VarLocnInfo) },
-	code_info__set_static_cell_info(StaticCellInfo),
-	code_info__set_var_locn_info(VarLocnInfo).
-
-code_info__place_var(Var, Lval, Code) -->
-	code_info__get_var_locn_info(VarLocnInfo0),
-	{ var_locn__place_var(Var, Lval, Code, VarLocnInfo0, VarLocnInfo) },
-	code_info__set_var_locn_info(VarLocnInfo).
+code_info__assign_cell_to_var(Var, Ptag, Vector, Size, TypeMsg, Code, !CI) :-
+	code_info__get_var_locn_info(!.CI, VarLocnInfo0),
+	code_info__get_static_cell_info(!.CI, StaticCellInfo0),
+	var_locn__assign_cell_to_var(Var, Ptag, Vector, Size, TypeMsg, Code,
+		StaticCellInfo0, StaticCellInfo, VarLocnInfo0, VarLocnInfo),
+	code_info__set_static_cell_info(StaticCellInfo, !CI),
+	code_info__set_var_locn_info(VarLocnInfo, !CI).
+
+code_info__place_var(Var, Lval, Code, !CI) :-
+	code_info__get_var_locn_info(!.CI, VarLocnInfo0),
+	var_locn__place_var(Var, Lval, Code, VarLocnInfo0, VarLocnInfo),
+	code_info__set_var_locn_info(VarLocnInfo, !CI).
 
 :- pred code_info__pick_and_place_vars(assoc_list(prog_var, set(lval))::in,
 	set(lval)::out, code_tree::out, code_info::in, code_info::out) is det.
 
-code_info__pick_and_place_vars(VarLocSets, LiveLocs, Code) -->
-	{ code_info__pick_var_places(VarLocSets, VarLocs) },
-	{ assoc_list__values(VarLocs, Locs) },
-	{ set__list_to_set(Locs, LiveLocs) },
-	code_info__place_vars(VarLocs, Code).
+code_info__pick_and_place_vars(VarLocSets, LiveLocs, Code, !CI) :-
+	code_info__pick_var_places(VarLocSets, VarLocs),
+	assoc_list__values(VarLocs, Locs),
+	set__list_to_set(Locs, LiveLocs),
+	code_info__place_vars(VarLocs, Code, !CI).
 
 :- pred code_info__pick_var_places(assoc_list(prog_var, set(lval))::in,
 	assoc_list(prog_var, lval)::out) is det.
@@ -3247,30 +3197,30 @@
 :- pred code_info__place_vars(assoc_list(prog_var, lval)::in,
 	code_tree::out, code_info::in, code_info::out) is det.
 
-code_info__place_vars(VarLocs, Code) -->
-	code_info__get_var_locn_info(VarLocnInfo0),
-	{ var_locn__place_vars(VarLocs, Code, VarLocnInfo0, VarLocnInfo) },
-	code_info__set_var_locn_info(VarLocnInfo).
-
-code_info__produce_variable(Var, Code, Rval) -->
-	code_info__get_var_locn_info(VarLocnInfo0),
-	{ var_locn__produce_var(Var, Rval, Code, VarLocnInfo0, VarLocnInfo) },
-	code_info__set_var_locn_info(VarLocnInfo).
-
-code_info__produce_variable_in_reg(Var, Code, Lval) -->
-	code_info__get_var_locn_info(VarLocnInfo0),
-	{ var_locn__produce_var_in_reg(Var, Lval, Code,
-		VarLocnInfo0, VarLocnInfo) },
-	code_info__set_var_locn_info(VarLocnInfo).
-
-code_info__produce_variable_in_reg_or_stack(Var, Code, Lval) -->
-	code_info__get_var_locn_info(VarLocnInfo0),
-	{ var_locn__produce_var_in_reg_or_stack(Var, Lval, Code,
-		VarLocnInfo0, VarLocnInfo) },
-	code_info__set_var_locn_info(VarLocnInfo).
+code_info__place_vars(VarLocs, Code, !CI) :-
+	code_info__get_var_locn_info(!.CI, VarLocnInfo0),
+	var_locn__place_vars(VarLocs, Code, VarLocnInfo0, VarLocnInfo),
+	code_info__set_var_locn_info(VarLocnInfo, !CI).
+
+code_info__produce_variable(Var, Code, Rval, !CI) :-
+	code_info__get_var_locn_info(!.CI, VarLocnInfo0),
+	var_locn__produce_var(Var, Rval, Code, VarLocnInfo0, VarLocnInfo),
+	code_info__set_var_locn_info(VarLocnInfo, !CI).
+
+code_info__produce_variable_in_reg(Var, Code, Lval, !CI) :-
+	code_info__get_var_locn_info(!.CI, VarLocnInfo0),
+	var_locn__produce_var_in_reg(Var, Lval, Code,
+		VarLocnInfo0, VarLocnInfo),
+	code_info__set_var_locn_info(VarLocnInfo, !CI).
 
-code_info__materialize_vars_in_rval(Rval0, Rval, Code, CI0, CI) :-
-	code_info__get_var_locn_info(VarLocnInfo0, CI0, CI1),
+code_info__produce_variable_in_reg_or_stack(Var, Code, Lval, !CI) :-
+	code_info__get_var_locn_info(!.CI, VarLocnInfo0),
+	var_locn__produce_var_in_reg_or_stack(Var, Lval, Code,
+		VarLocnInfo0, VarLocnInfo),
+	code_info__set_var_locn_info(VarLocnInfo, !CI).
+
+code_info__materialize_vars_in_rval(Rval0, Rval, Code, !CI) :-
+	code_info__get_var_locn_info(!.CI, VarLocnInfo0),
 		( Rval0 = lval(Lval0) ->
 			var_locn__materialize_vars_in_lval(Lval0, Lval, Code,
 				VarLocnInfo0, VarLocnInfo),
@@ -3282,13 +3232,13 @@
 		;
 		error("code_info__materialize_vars_in_rval")
 	),
-	code_info__set_var_locn_info(VarLocnInfo, CI1, CI).
+	code_info__set_var_locn_info(VarLocnInfo, !CI).
 
-code_info__acquire_reg_for_var(Var, Lval) -->
-	code_info__get_follow_var_map(FollowVarsMap),
-	code_info__get_next_non_reserved(NextNonReserved),
-	code_info__get_var_locn_info(VarLocnInfo0),
-	{
+code_info__acquire_reg_for_var(Var, Lval, !CI) :-
+	code_info__get_follow_var_map(!.CI, FollowVarsMap),
+	code_info__get_next_non_reserved(!.CI, NextNonReserved),
+	code_info__get_var_locn_info(!.CI, VarLocnInfo0),
+	(
 		map__search(FollowVarsMap, Var, PrefLval),
 		PrefLval = reg(PrefRegType, PrefRegNum),
 		PrefRegNum >= 1
@@ -3301,54 +3251,54 @@
 		% succeeded; otherwise we should put the var in its stack slot.
 		var_locn__acquire_reg_start_at_given(NextNonReserved, Lval,
 			VarLocnInfo0, VarLocnInfo)
-	},
-	code_info__set_var_locn_info(VarLocnInfo).
+	),
+	code_info__set_var_locn_info(VarLocnInfo, !CI).
 
-code_info__acquire_reg(Type, Lval) -->
-	code_info__get_var_locn_info(VarLocnInfo0),
-	{ require(unify(Type, r),
-		"code_info__acquire_reg: unknown reg type") },
-	{ var_locn__acquire_reg(Lval, VarLocnInfo0, VarLocnInfo) },
-	code_info__set_var_locn_info(VarLocnInfo).
-
-code_info__release_reg(Lval) -->
-	code_info__get_var_locn_info(VarLocnInfo0),
-	{ var_locn__release_reg(Lval, VarLocnInfo0, VarLocnInfo) },
-	code_info__set_var_locn_info(VarLocnInfo).
-
-code_info__reserve_r1(Code) -->
-	code_info__get_var_locn_info(VarLocnInfo0),
-	{ var_locn__clear_r1(Code, VarLocnInfo0, VarLocnInfo1) },
-	{ var_locn__acquire_reg_require_given(reg(r, 1),
-		VarLocnInfo1, VarLocnInfo) },
-	code_info__set_var_locn_info(VarLocnInfo).
-
-code_info__clear_r1(empty) -->
-	code_info__get_var_locn_info(VarLocnInfo0),
-	{ var_locn__release_reg(reg(r, 1), VarLocnInfo0, VarLocnInfo) },
-	code_info__set_var_locn_info(VarLocnInfo).
+code_info__acquire_reg(Type, Lval, !CI) :-
+	code_info__get_var_locn_info(!.CI, VarLocnInfo0),
+	require(unify(Type, r),
+		"code_info__acquire_reg: unknown reg type"),
+	var_locn__acquire_reg(Lval, VarLocnInfo0, VarLocnInfo),
+	code_info__set_var_locn_info(VarLocnInfo, !CI).
+
+code_info__release_reg(Lval, !CI) :-
+	code_info__get_var_locn_info(!.CI, VarLocnInfo0),
+	var_locn__release_reg(Lval, VarLocnInfo0, VarLocnInfo),
+	code_info__set_var_locn_info(VarLocnInfo, !CI).
+
+code_info__reserve_r1(Code, !CI) :-
+	code_info__get_var_locn_info(!.CI, VarLocnInfo0),
+	var_locn__clear_r1(Code, VarLocnInfo0, VarLocnInfo1),
+	var_locn__acquire_reg_require_given(reg(r, 1),
+		VarLocnInfo1, VarLocnInfo),
+	code_info__set_var_locn_info(VarLocnInfo, !CI).
+
+code_info__clear_r1(empty, !CI) :-
+	code_info__get_var_locn_info(!.CI, VarLocnInfo0),
+	var_locn__release_reg(reg(r, 1), VarLocnInfo0, VarLocnInfo),
+	code_info__set_var_locn_info(VarLocnInfo, !CI).
 
 %---------------------------------------------------------------------------%
 
-code_info__setup_return(VarArgInfos, OutLocs, Code) -->
-	code_info__setup_call_args(VarArgInfos, callee, OutLocs, Code).
-
-code_info__setup_call(GoalInfo, ArgInfos, LiveLocs, Code) -->
-	{ partition_args(ArgInfos, InArgInfos, OutArgInfos, _UnusedArgInfos) },
-	{ assoc_list__keys(OutArgInfos, OutVars) },
-	{ set__list_to_set(OutVars, OutVarSet) },
-	{ goal_info_get_determinism(GoalInfo, Detism) },
-	code_info__get_opt_no_return_calls(OptNoReturnCalls),
+code_info__setup_return(VarArgInfos, OutLocs, Code, !CI) :-
+	code_info__setup_call_args(VarArgInfos, callee, OutLocs, Code, !CI).
+
+code_info__setup_call(GoalInfo, ArgInfos, LiveLocs, Code, !CI) :-
+	partition_args(ArgInfos, InArgInfos, OutArgInfos, _UnusedArgInfos),
+	assoc_list__keys(OutArgInfos, OutVars),
+	set__list_to_set(OutVars, OutVarSet),
+	goal_info_get_determinism(GoalInfo, Detism),
+	code_info__get_opt_no_return_calls(!.CI, OptNoReturnCalls),
 	(
-		{ Detism = erroneous },
-		{ OptNoReturnCalls = yes }
+		Detism = erroneous,
+		OptNoReturnCalls = yes
 	->
-		{ StackVarLocs = [] }
+		StackVarLocs = []
 	;
-		code_info__compute_forward_live_var_saves(OutVarSet,
+		code_info__compute_forward_live_var_saves(!.CI, OutVarSet,
 			ForwardVarLocs),
-		{ goal_info_get_code_model(GoalInfo, CodeModel) },
-		( { CodeModel = model_non } ->
+		goal_info_get_code_model(GoalInfo, CodeModel),
+		( CodeModel = model_non ->
 				% Save variables protected by the nearest
 				% resumption point on the stack. XXX This
 				% should be unnecessary; with the current
@@ -3359,47 +3309,41 @@
 				% of the resume vars on the stack is delayed
 				% until the first call after the setup of
 				% the resume point.
-			code_info__compute_resume_var_stack_locs(ResumeVarLocs),
-			{ list__append(ResumeVarLocs, ForwardVarLocs,
-				StackVarLocs) }
+			code_info__compute_resume_var_stack_locs(!.CI,
+				ResumeVarLocs),
+			list__append(ResumeVarLocs, ForwardVarLocs,
+				StackVarLocs)
 		;
-			{ StackVarLocs = ForwardVarLocs }
+			StackVarLocs = ForwardVarLocs
 		)
 	),
 
-	code_info__get_var_locn_info(VarLocnInfo0),
-		{ code_info__var_arg_info_to_lval(InArgInfos, InArgLocs) },
-		{ list__append(StackVarLocs, InArgLocs, AllLocs) },
-		{ var_locn__place_vars(AllLocs, Code,
-			VarLocnInfo0, VarLocnInfo) },
-	code_info__set_var_locn_info(VarLocnInfo),
-		{ assoc_list__values(AllLocs, LiveLocList) },
-	{ set__list_to_set(LiveLocList, LiveLocs) }.
-
-		% { assoc_list__keys(InArgLocs, InArgVars) },
-		% { set__init(DeadVars0) },
-		% code_info__which_variables_are_forward_live(InArgVars,
-		% 	DeadVars0, DeadVars),
-		% code_info__make_vars_forward_dead(DeadVars)
+	code_info__get_var_locn_info(!.CI, VarLocnInfo0),
+	code_info__var_arg_info_to_lval(InArgInfos, InArgLocs),
+	list__append(StackVarLocs, InArgLocs, AllLocs),
+	var_locn__place_vars(AllLocs, Code,
+		VarLocnInfo0, VarLocnInfo),
+	code_info__set_var_locn_info(VarLocnInfo, !CI),
+	assoc_list__values(AllLocs, LiveLocList),
+	set__list_to_set(LiveLocList, LiveLocs).
 
 :- pred code_info__setup_call_args(assoc_list(prog_var, arg_info)::in,
 	call_direction::in, set(lval)::out, code_tree::out,
 	code_info::in, code_info::out) is det.
 
-code_info__setup_call_args(AllArgsInfos, Direction, LiveLocs, Code) -->
-	{ list__filter(code_info__call_arg_in_selected_dir(Direction),
-		AllArgsInfos, ArgsInfos) },
-	{ code_info__var_arg_info_to_lval(ArgsInfos, ArgsLocns) },
-	code_info__get_var_locn_info(VarLocnInfo0),
-	{ var_locn__place_vars(ArgsLocns, Code, VarLocnInfo0, VarLocnInfo1) },
-	code_info__set_var_locn_info(VarLocnInfo1),
-	{ assoc_list__values(ArgsLocns, LiveLocList) },
-	{ set__list_to_set(LiveLocList, LiveLocs) },
-	{ assoc_list__keys(ArgsLocns, ArgVars) },
-	{ set__init(DeadVars0) },
-	code_info__which_variables_are_forward_live(ArgVars,
-		DeadVars0, DeadVars),
-	code_info__make_vars_forward_dead(DeadVars).
+code_info__setup_call_args(AllArgsInfos, Direction, LiveLocs, Code, !CI) :-
+	list__filter(code_info__call_arg_in_selected_dir(Direction),
+		AllArgsInfos, ArgsInfos),
+	code_info__var_arg_info_to_lval(ArgsInfos, ArgsLocns),
+	code_info__get_var_locn_info(!.CI, VarLocnInfo0),
+	var_locn__place_vars(ArgsLocns, Code, VarLocnInfo0, VarLocnInfo1),
+	code_info__set_var_locn_info(VarLocnInfo1, !CI),
+	assoc_list__values(ArgsLocns, LiveLocList),
+	set__list_to_set(LiveLocList, LiveLocs),
+	assoc_list__keys(ArgsLocns, ArgVars),
+	code_info__which_variables_are_forward_live(!.CI, ArgVars,
+		set__init, DeadVars),
+	code_info__make_vars_forward_dead(DeadVars, !CI).
 
 :- pred code_info__var_arg_info_to_lval(assoc_list(prog_var, arg_info)::in,
 	assoc_list(prog_var, lval)::out) is det.
@@ -3411,19 +3355,17 @@
 	code_util__arg_loc_to_register(Loc, Lval),
 	code_info__var_arg_info_to_lval(RestInfos, RestLvals).
 
-:- pred code_info__which_variables_are_forward_live(list(prog_var)::in,
-	set(prog_var)::in, set(prog_var)::out,
-	code_info::in, code_info::out) is det.
+:- pred code_info__which_variables_are_forward_live(code_info::in,
+	list(prog_var)::in, set(prog_var)::in, set(prog_var)::out) is det.
 
-code_info__which_variables_are_forward_live([], DeadVars, DeadVars) --> [].
-code_info__which_variables_are_forward_live([Var | Vars], DeadVars0, DeadVars)
-		-->
-	( code_info__variable_is_forward_live(Var) ->
-		{ DeadVars1 = DeadVars0 }
+code_info__which_variables_are_forward_live(_, [], !DeadVars).
+code_info__which_variables_are_forward_live(CI, [Var | Vars], !DeadVars) :-
+	( code_info__variable_is_forward_live(CI, Var) ->
+		true
 	;
-		{ set__insert(DeadVars0, Var, DeadVars1) }
+		set__insert(!.DeadVars, Var, !:DeadVars)
 	),
-	code_info__which_variables_are_forward_live(Vars, DeadVars1, DeadVars).
+	code_info__which_variables_are_forward_live(CI, Vars, !DeadVars).
 
 :- pred code_info__call_arg_in_selected_dir(call_direction::in,
 	pair(prog_var, arg_info)::in) is semidet.
@@ -3437,62 +3379,62 @@
 		Direction = callee
 	).
 
-code_info__lock_regs(N, Exceptions) -->
-	code_info__get_var_locn_info(VarLocnInfo0),
-	{ var_locn__lock_regs(N, Exceptions, VarLocnInfo0, VarLocnInfo) },
-	code_info__set_var_locn_info(VarLocnInfo).
-
-code_info__unlock_regs -->
-	code_info__get_var_locn_info(VarLocnInfo0),
-	{ var_locn__unlock_regs(VarLocnInfo0, VarLocnInfo) },
-	code_info__set_var_locn_info(VarLocnInfo).
-
-code_info__clear_all_registers(OkToDeleteAny) -->
-	code_info__get_var_locn_info(VarLocnInfo0),
-	{ var_locn__clobber_all_regs(OkToDeleteAny,
-		VarLocnInfo0, VarLocnInfo) },
-	code_info__set_var_locn_info(VarLocnInfo).
-
-code_info__clobber_regs(Regs) -->
-	code_info__get_var_locn_info(VarLocnInfo0),
-	{ var_locn__clobber_regs(Regs, VarLocnInfo0, VarLocnInfo) },
-	code_info__set_var_locn_info(VarLocnInfo).
-
-code_info__save_variables(OutArgs, SavedLocs, Code) -->
-	code_info__compute_forward_live_var_saves(OutArgs, VarLocs),
-	{ assoc_list__values(VarLocs, SavedLocList) },
-	{ set__list_to_set(SavedLocList, SavedLocs) },
-	code_info__place_vars(VarLocs, Code).
-
-code_info__save_variables_on_stack(Vars, Code) -->
-	list__map_foldl(code_info__associate_stack_slot, Vars, VarLocs),
-	code_info__place_vars(VarLocs, Code).
-
-:- pred code_info__compute_forward_live_var_saves(set(prog_var)::in,
-	assoc_list(prog_var, lval)::out, code_info::in, code_info::out) is det.
-
-code_info__compute_forward_live_var_saves(OutArgs, VarLocs) -->
-	code_info__get_known_variables(Variables0),
-	{ set__list_to_set(Variables0, Vars0) },
-	code_info__body_typeinfo_liveness(TypeInfoLiveness),
-	code_info__get_proc_info(ProcInfo),
-	{ proc_info_vartypes(ProcInfo, VarTypes) },
-	{ proc_info_typeinfo_varmap(ProcInfo, TVarMap) },
-	{ proc_info_maybe_complete_with_typeinfo_vars(Vars0, TypeInfoLiveness,
-		VarTypes, TVarMap, Vars1) },
-	{ set__difference(Vars1, OutArgs, Vars) },
-	{ set__to_sorted_list(Vars, Variables) },
-	list__map_foldl(code_info__associate_stack_slot, Variables, VarLocs).
-
-:- pred code_info__associate_stack_slot(prog_var::in,
-	pair(prog_var, lval)::out, code_info::in, code_info::out) is det.
-
-code_info__associate_stack_slot(Var, Var - Slot) -->
-	code_info__get_variable_slot(Var, Slot).
-
-code_info__max_reg_in_use(Max) -->
-	code_info__get_var_locn_info(VarLocnInfo),
-	{ var_locn__max_reg_in_use(VarLocnInfo, Max) }.
+code_info__lock_regs(N, Exceptions, !CI) :-
+	code_info__get_var_locn_info(!.CI, VarLocnInfo0),
+	var_locn__lock_regs(N, Exceptions, VarLocnInfo0, VarLocnInfo),
+	code_info__set_var_locn_info(VarLocnInfo, !CI).
+
+code_info__unlock_regs(!CI) :-
+	code_info__get_var_locn_info(!.CI, VarLocnInfo0),
+	var_locn__unlock_regs(VarLocnInfo0, VarLocnInfo),
+	code_info__set_var_locn_info(VarLocnInfo, !CI).
+
+code_info__clear_all_registers(OkToDeleteAny, !CI) :-
+	code_info__get_var_locn_info(!.CI, VarLocnInfo0),
+	var_locn__clobber_all_regs(OkToDeleteAny,
+		VarLocnInfo0, VarLocnInfo),
+	code_info__set_var_locn_info(VarLocnInfo, !CI).
+
+code_info__clobber_regs(Regs, !CI) :-
+	code_info__get_var_locn_info(!.CI, VarLocnInfo0),
+	var_locn__clobber_regs(Regs, VarLocnInfo0, VarLocnInfo),
+	code_info__set_var_locn_info(VarLocnInfo, !CI).
+
+code_info__save_variables(OutArgs, SavedLocs, Code, !CI) :-
+	code_info__compute_forward_live_var_saves(!.CI, OutArgs, VarLocs),
+	assoc_list__values(VarLocs, SavedLocList),
+	set__list_to_set(SavedLocList, SavedLocs),
+	code_info__place_vars(VarLocs, Code, !CI).
+
+code_info__save_variables_on_stack(Vars, Code, !CI) :-
+	list__map(code_info__associate_stack_slot(!.CI), Vars, VarLocs),
+	code_info__place_vars(VarLocs, Code, !CI).
+
+:- pred code_info__compute_forward_live_var_saves(code_info::in,
+	set(prog_var)::in, assoc_list(prog_var, lval)::out) is det.
+
+code_info__compute_forward_live_var_saves(CI, OutArgs, VarLocs) :-
+	code_info__get_known_variables(CI, Variables0),
+	set__list_to_set(Variables0, Vars0),
+	TypeInfoLiveness = code_info__body_typeinfo_liveness(CI),
+	code_info__get_proc_info(CI, ProcInfo),
+	proc_info_vartypes(ProcInfo, VarTypes),
+	proc_info_typeinfo_varmap(ProcInfo, TVarMap),
+	proc_info_maybe_complete_with_typeinfo_vars(Vars0, TypeInfoLiveness,
+		VarTypes, TVarMap, Vars1),
+	set__difference(Vars1, OutArgs, Vars),
+	set__to_sorted_list(Vars, Variables),
+	list__map(code_info__associate_stack_slot(CI), Variables, VarLocs).
+
+:- pred code_info__associate_stack_slot(code_info::in, prog_var::in,
+	pair(prog_var, lval)::out) is det.
+
+code_info__associate_stack_slot(CI, Var, Var - Slot) :-
+	code_info__get_variable_slot(CI, Var, Slot).
+
+code_info__max_reg_in_use(CI, Max) :-
+	code_info__get_var_locn_info(CI, VarLocnInfo),
+	var_locn__max_reg_in_use(VarLocnInfo, Max).
 
 %---------------------------------------------------------------------------%
 %---------------------------------------------------------------------------%
@@ -3506,94 +3448,93 @@
 
 :- interface.
 
-:- pred code_info__generate_call_vn_livevals(list(arg_loc)::in,
-	set(prog_var)::in, set(lval)::out, code_info::in, code_info::out)
-	is det.
+:- pred code_info__generate_call_vn_livevals(code_info::in, list(arg_loc)::in,
+	set(prog_var)::in, set(lval)::out) is det.
 
-:- pred code_info__generate_return_live_lvalues(
+:- pred code_info__generate_return_live_lvalues(code_info::in,
 	assoc_list(prog_var, arg_loc)::in, instmap::in, bool::in,
-	list(liveinfo)::out, code_info::in, code_info::out) is det.
+	list(liveinfo)::out) is det.
 
 %---------------------------------------------------------------------------%
 
 :- implementation.
 
-code_info__generate_call_vn_livevals(InputArgLocs, OutputArgs, LiveVals) -->
-	code_info__generate_call_stack_vn_livevals(OutputArgs, StackLiveVals),
-	{ code_info__generate_input_var_vn(InputArgLocs, StackLiveVals,
-		LiveVals) }.
-
-:- pred code_info__generate_call_stack_vn_livevals(set(prog_var)::in,
-	set(lval)::out, code_info::in, code_info::out) is det.
-
-code_info__generate_call_stack_vn_livevals(OutputArgs, LiveVals) -->
-	code_info__get_known_variables(KnownVarList),
-	{ set__list_to_set(KnownVarList, KnownVars) },
-	{ set__difference(KnownVars, OutputArgs, LiveVars) },
-	{ set__to_sorted_list(LiveVars, LiveVarList) },
-	{ set__init(LiveVals0) },
-	code_info__generate_stack_var_vn(LiveVarList, LiveVals0, LiveVals1),
-
-	code_info__get_active_temps_data(Temps),
-	{ code_info__generate_call_temp_vn(Temps, LiveVals1, LiveVals) }.
-
-:- pred code_info__generate_stack_var_vn(list(prog_var)::in, set(lval)::in,
-	set(lval)::out, code_info::in, code_info::out) is det.
-
-code_info__generate_stack_var_vn([], Vals, Vals) --> [].
-code_info__generate_stack_var_vn([V | Vs], Vals0, Vals) -->
-	code_info__get_variable_slot(V, Lval),
-	{ set__insert(Vals0, Lval, Vals1) },
-	code_info__generate_stack_var_vn(Vs, Vals1, Vals).
+code_info__generate_call_vn_livevals(CI, InputArgLocs, OutputArgs, LiveVals) :-
+	code_info__generate_call_stack_vn_livevals(CI, OutputArgs,
+		StackLiveVals),
+	code_info__generate_input_var_vn(InputArgLocs, StackLiveVals,
+		LiveVals).
+
+:- pred code_info__generate_call_stack_vn_livevals(code_info::in,
+	set(prog_var)::in, set(lval)::out) is det.
+
+code_info__generate_call_stack_vn_livevals(CI, OutputArgs, LiveVals) :-
+	code_info__get_known_variables(CI, KnownVarList),
+	set__list_to_set(KnownVarList, KnownVars),
+	set__difference(KnownVars, OutputArgs, LiveVars),
+	set__to_sorted_list(LiveVars, LiveVarList),
+	code_info__generate_stack_var_vn(CI, LiveVarList,
+		set__init, LiveVals1),
+	code_info__get_active_temps_data(CI, Temps),
+	code_info__generate_call_temp_vn(Temps, LiveVals1, LiveVals).
+
+:- pred code_info__generate_stack_var_vn(code_info::in, list(prog_var)::in,
+	set(lval)::in, set(lval)::out) is det.
+
+code_info__generate_stack_var_vn(_, [], !Vals).
+code_info__generate_stack_var_vn(CI, [V | Vs], !Vals) :-
+	code_info__get_variable_slot(CI, V, Lval),
+	set__insert(!.Vals, Lval, !:Vals),
+	code_info__generate_stack_var_vn(CI, Vs, !Vals).
 
 :- pred code_info__generate_call_temp_vn(assoc_list(lval, slot_contents)::in,
 	set(lval)::in, set(lval)::out) is det.
 
-code_info__generate_call_temp_vn([], Vals, Vals).
-code_info__generate_call_temp_vn([Lval - _ | Temps], Vals0, Vals) :-
-	set__insert(Vals0, Lval, Vals1),
-	code_info__generate_call_temp_vn(Temps, Vals1, Vals).
+code_info__generate_call_temp_vn([], !Vals).
+code_info__generate_call_temp_vn([Lval - _ | Temps], !Vals) :-
+	set__insert(!.Vals, Lval, !:Vals),
+	code_info__generate_call_temp_vn(Temps, !Vals).
 
 :- pred code_info__generate_input_var_vn(list(arg_loc)::in,
 	set(lval)::in, set(lval)::out) is det.
 
-code_info__generate_input_var_vn([], Vals, Vals).
-code_info__generate_input_var_vn([InputArgLoc | InputArgLocs], Vals0, Vals) :-
+code_info__generate_input_var_vn([], !Vals).
+code_info__generate_input_var_vn([InputArgLoc | InputArgLocs], !Vals) :-
 	code_util__arg_loc_to_register(InputArgLoc, Lval),
-	set__insert(Vals0, Lval, Vals1),
-	code_info__generate_input_var_vn(InputArgLocs, Vals1, Vals).
+	set__insert(!.Vals, Lval, !:Vals),
+	code_info__generate_input_var_vn(InputArgLocs, !Vals).
 
 %---------------------------------------------------------------------------%
 
-code_info__generate_return_live_lvalues(OutputArgLocs, ReturnInstMap,
-		OkToDeleteAny, LiveLvalues) -->
-	code_info__variable_locations(VarLocs),
-	code_info__get_known_variables(Vars),
-	code_info__get_active_temps_data(Temps),
-	code_info__get_proc_info(ProcInfo),
-	code_info__get_globals(Globals),
-	code_info__get_module_info(ModuleInfo),
-	{ continuation_info__generate_return_live_lvalues(OutputArgLocs,
+code_info__generate_return_live_lvalues(CI, OutputArgLocs, ReturnInstMap,
+		OkToDeleteAny, LiveLvalues) :-
+	code_info__variable_locations(CI, VarLocs),
+	code_info__get_known_variables(CI, Vars),
+	code_info__get_active_temps_data(CI, Temps),
+	code_info__get_proc_info(CI, ProcInfo),
+	code_info__get_globals(CI, Globals),
+	code_info__get_module_info(CI, ModuleInfo),
+	continuation_info__generate_return_live_lvalues(OutputArgLocs,
 		ReturnInstMap, Vars, VarLocs, Temps, ProcInfo, ModuleInfo,
-		Globals, OkToDeleteAny, LiveLvalues) }.
+		Globals, OkToDeleteAny, LiveLvalues).
 
 :- pred code_info__generate_resume_layout(label::in, resume_map::in,
 	code_info::in, code_info::out) is det.
 
-code_info__generate_resume_layout(Label, ResumeMap) -->
-	code_info__get_globals(Globals),
-	{ globals__lookup_bool_option(Globals, agc_stack_layout,
-		AgcStackLayout) },
-	( { AgcStackLayout = yes } ->
-		code_info__get_active_temps_data(Temps),
-		code_info__get_instmap(InstMap),
-		code_info__get_proc_info(ProcInfo),
-		code_info__get_module_info(ModuleInfo),
-		{ continuation_info__generate_resume_layout(ResumeMap,
-			Temps, InstMap, ProcInfo, ModuleInfo, Layout) },
-		code_info__add_resume_layout_for_label(Label, Layout)
+code_info__generate_resume_layout(Label, ResumeMap, !CI) :-
+	code_info__get_globals(!.CI, Globals),
+	globals__lookup_bool_option(Globals, agc_stack_layout,
+		AgcStackLayout),
+	( AgcStackLayout = yes ->
+		code_info__get_active_temps_data(!.CI, Temps),
+		code_info__get_instmap(!.CI, InstMap),
+		code_info__get_proc_info(!.CI, ProcInfo),
+		code_info__get_module_info(!.CI, ModuleInfo),
+		continuation_info__generate_resume_layout(ResumeMap,
+			Temps, InstMap, ProcInfo, ModuleInfo, Layout),
+		code_info__add_resume_layout_for_label(Label, Layout, !CI)
 	;
-		[]
+		true
 	).
 
 %---------------------------------------------------------------------------%
@@ -3633,93 +3574,89 @@
 	% Returns the total stackslot count, but not including space for
 	% succip. This total can change in the future if this call is
 	% followed by further allocations of temp slots.
-:- pred code_info__get_total_stackslot_count(int, code_info, code_info).
-:- mode code_info__get_total_stackslot_count(out, in, out) is det.
+:- pred code_info__get_total_stackslot_count(code_info::in, int::out) is det.
 
 	% Acquire a stack slot for storing a temporary. The slot_contents
 	% description is for accurate gc.
-:- pred code_info__acquire_temp_slot(slot_contents, lval,
-	code_info, code_info).
-:- mode code_info__acquire_temp_slot(in, out, in, out) is det.
+:- pred code_info__acquire_temp_slot(slot_contents::in, lval::out,
+	code_info::in, code_info::out) is det.
 
 	% Release a stack slot acquired earlier for a temporary value.
-:- pred code_info__release_temp_slot(lval, code_info, code_info).
-:- mode code_info__release_temp_slot(in, in, out) is det.
+:- pred code_info__release_temp_slot(lval::in,
+	code_info::in, code_info::out) is det.
 
 	% Return the lval of the stack slot in which the given variable
 	% is stored. Aborts if the variable does not have a stack slot
 	% an assigned to it.
-:- pred code_info__get_variable_slot(prog_var, lval, code_info, code_info).
-:- mode code_info__get_variable_slot(in, out, in, out) is det.
+:- pred code_info__get_variable_slot(code_info::in, prog_var::in, lval::out)
+	is det.
 
 %---------------------------------------------------------------------------%
 %---------------------------------------------------------------------------%
 
 :- implementation.
 
-code_info__acquire_temp_slot(Item, StackVar) -->
-	code_info__get_temps_in_use(TempsInUse0),
-	{ IsTempUsable = lambda([TempContent::in, Lval::out] is semidet, (
+code_info__acquire_temp_slot(Item, StackVar, !CI) :-
+	code_info__get_temps_in_use(!.CI, TempsInUse0),
+	IsTempUsable = lambda([TempContent::in, Lval::out] is semidet, (
 		TempContent = Lval - ContentType,
 		ContentType = Item,
 		\+ set__member(Lval, TempsInUse0)
-	)) },
-	code_info__get_temp_content_map(TempContentMap0),
-	{ map__to_assoc_list(TempContentMap0, TempContentList) },
-	{ list__filter_map(IsTempUsable, TempContentList, UsableLvals) },
-	(
-		{ UsableLvals = [UsableLval | _] },
-		{ StackVar = UsableLval }
-	;
-		{ UsableLvals = [] },
-		code_info__get_var_slot_count(VarSlots),
-		code_info__get_max_temp_slot_count(TempSlots0),
-		{ TempSlots = TempSlots0 + 1 },
-		{ Slot = VarSlots + TempSlots },
-		code_info__stack_variable(Slot, StackVar),
-		code_info__set_max_temp_slot_count(TempSlots),
-		{ map__det_insert(TempContentMap0, StackVar, Item,
-			TempContentMap) },
-		code_info__set_temp_content_map(TempContentMap)
-	),
-	{ set__insert(TempsInUse0, StackVar, TempsInUse) },
-	code_info__set_temps_in_use(TempsInUse).
-
-code_info__release_temp_slot(StackVar) -->
-	code_info__get_temps_in_use(TempsInUse0),
-	{ set__delete(TempsInUse0, StackVar, TempsInUse) },
-	code_info__set_temps_in_use(TempsInUse).
+	)),
+	code_info__get_temp_content_map(!.CI, TempContentMap0),
+	map__to_assoc_list(TempContentMap0, TempContentList),
+	list__filter_map(IsTempUsable, TempContentList, UsableLvals),
+	(
+		UsableLvals = [UsableLval | _],
+		StackVar = UsableLval
+	;
+		UsableLvals = [],
+		code_info__get_var_slot_count(!.CI, VarSlots),
+		code_info__get_max_temp_slot_count(!.CI, TempSlots0),
+		TempSlots = TempSlots0 + 1,
+		Slot = VarSlots + TempSlots,
+		code_info__stack_variable(!.CI, Slot, StackVar),
+		code_info__set_max_temp_slot_count(TempSlots, !CI),
+		map__det_insert(TempContentMap0, StackVar, Item,
+			TempContentMap),
+		code_info__set_temp_content_map(TempContentMap, !CI)
+	),
+	set__insert(TempsInUse0, StackVar, TempsInUse),
+	code_info__set_temps_in_use(TempsInUse, !CI).
+
+code_info__release_temp_slot(StackVar, !CI) :-
+	code_info__get_temps_in_use(!.CI, TempsInUse0),
+	set__delete(TempsInUse0, StackVar, TempsInUse),
+	code_info__set_temps_in_use(TempsInUse, !CI).
 
 %---------------------------------------------------------------------------%
 
-code_info__get_variable_slot(Var, Slot) -->
-	code_info__get_stack_slots(StackSlots),
-	( { map__search(StackSlots, Var, SlotPrime) } ->
-		{ Slot = SlotPrime }
-	;
-		code_info__variable_to_string(Var, Name),
-		{ term__var_to_int(Var, Num) },
-		{ string__int_to_string(Num, NumStr) },
-		{ string__append_list([
+code_info__get_variable_slot(CI, Var, Slot) :-
+	code_info__get_stack_slots(CI, StackSlots),
+	( map__search(StackSlots, Var, SlotPrime) ->
+		Slot = SlotPrime
+	;
+		Name = code_info__variable_to_string(CI, Var),
+		term__var_to_int(Var, Num),
+		string__int_to_string(Num, NumStr),
+		string__append_list([
 			"code_info__get_variable_slot: variable `",
-			Name, "' (", NumStr, ") not found"], Str) },
-		{ error(Str) }
+			Name, "' (", NumStr, ") not found"], Str),
+		error(Str)
 	).
 
-code_info__get_total_stackslot_count(NumSlots) -->
-	code_info__get_var_slot_count(SlotsForVars),
-	code_info__get_max_temp_slot_count(SlotsForTemps),
-	{ NumSlots = SlotsForVars + SlotsForTemps }.
+code_info__get_total_stackslot_count(CI, NumSlots) :-
+	code_info__get_var_slot_count(CI, SlotsForVars),
+	code_info__get_max_temp_slot_count(CI, SlotsForTemps),
+	NumSlots = SlotsForVars + SlotsForTemps.
 
-:- pred code_info__max_var_slot(stack_slots, int).
-:- mode code_info__max_var_slot(in, out) is det.
+:- pred code_info__max_var_slot(stack_slots::in, int::out) is det.
 
 code_info__max_var_slot(StackSlots, SlotCount) :-
 	map__values(StackSlots, StackSlotList),
 	code_info__max_var_slot_2(StackSlotList, 0, SlotCount).
 
-:- pred code_info__max_var_slot_2(list(lval), int, int).
-:- mode code_info__max_var_slot_2(in, in, out) is det.
+:- pred code_info__max_var_slot_2(list(lval)::in, int::in, int::out) is det.
 
 code_info__max_var_slot_2([], Max, Max).
 code_info__max_var_slot_2([L | Ls], Max0, Max) :-
@@ -3732,26 +3669,23 @@
 	),
 	code_info__max_var_slot_2(Ls, Max1, Max).
 
-:- pred code_info__stack_variable(int, lval, code_info, code_info).
-:- mode code_info__stack_variable(in, out, in, out) is det.
+:- pred code_info__stack_variable(code_info::in, int::in, lval::out) is det.
 
-code_info__stack_variable(Num, Lval) -->
-	code_info__get_proc_model(CodeModel),
-	( { CodeModel = model_non } ->
-		{ Lval = framevar(Num) }
+code_info__stack_variable(CI, Num, Lval) :-
+	( code_info__get_proc_model(CI) = model_non ->
+		Lval = framevar(Num)
 	;
-		{ Lval = stackvar(Num) }
+		Lval = stackvar(Num)
 	).
 
-:- pred code_info__stack_variable_reference(int, rval, code_info, code_info).
-:- mode code_info__stack_variable_reference(in, out, in, out) is det.
+:- pred code_info__stack_variable_reference(code_info::in, int::in, rval::out)
+	is det.
 
-code_info__stack_variable_reference(Num, mem_addr(Ref)) -->
-	code_info__get_proc_model(CodeModel),
-	( { CodeModel = model_non } ->
-		{ Ref = framevar_ref(Num) }
+code_info__stack_variable_reference(CI, Num, mem_addr(Ref)) :-
+	( code_info__get_proc_model(CI) = model_non ->
+		Ref = framevar_ref(Num)
 	;
-		{ Ref = stackvar_ref(Num) }
+		Ref = stackvar_ref(Num)
 	).
 
 %---------------------------------------------------------------------------%
Index: dense_switch.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/dense_switch.m,v
retrieving revision 1.46
diff -u -b -r1.46 dense_switch.m
--- dense_switch.m	20 Oct 2003 07:29:04 -0000	1.46
+++ dense_switch.m	22 Oct 2003 06:05:18 -0000
@@ -31,27 +31,23 @@
 	% (we may convert locally semidet switches into locally det
 	% switches by adding extra cases whose body is just `fail').
 
-:- pred dense_switch__is_dense_switch(prog_var, cases_list, can_fail, int,
-	int, int, can_fail, code_info, code_info).
-:- mode dense_switch__is_dense_switch(in, in, in, in, out, out, out, in, out)
-	is semidet.
+:- pred dense_switch__is_dense_switch(code_info::in, prog_var::in,
+	cases_list::in, can_fail::in, int::in, int::out, int::out,
+	can_fail::out) is semidet.
 
 	% Generate code for a switch using a dense jump table.
 
-:- pred dense_switch__generate(cases_list, int, int, prog_var, code_model,
-	can_fail, hlds_goal_info, label, branch_end, branch_end, code_tree,
-	code_info, code_info).
-:- mode dense_switch__generate(in, in, in, in, in, in, in, in,
-	in, out, out, in, out) is det.
+:- pred dense_switch__generate(cases_list::in, int::in, int::in, prog_var::in,
+	code_model::in, can_fail::in, hlds_goal_info::in, label::in,
+	branch_end::in, branch_end::out, code_tree::out,
+	code_info::in, code_info::out) is det.
 
 	% also used by lookup_switch
-:- pred dense_switch__calc_density(int, int, int).
-:- mode dense_switch__calc_density(in, in, out) is det.
+:- pred dense_switch__calc_density(int::in, int::in, int::out) is det.
 
 	% also used by lookup_switch
-:- pred dense_switch__type_range(type_category, type, int,
-	code_info, code_info).
-:- mode dense_switch__type_range(in, in, out, in, out) is semidet.
+:- pred dense_switch__type_range(code_info::in, type_category::in, (type)::in,
+	int::out) is semidet.
 
 %-----------------------------------------------------------------------------%
 
@@ -66,9 +62,8 @@
 
 :- import_module char, map, libs__tree, int, std_util, require, list.
 
-dense_switch__is_dense_switch(CaseVar, TaggedCases, CanFail0, ReqDensity,
-		FirstVal, LastVal, CanFail) -->
-	{
+dense_switch__is_dense_switch(CI, CaseVar, TaggedCases, CanFail0, ReqDensity,
+		FirstVal, LastVal, CanFail) :-
 		list__length(TaggedCases, NumCases),
 		NumCases > 2,
 		TaggedCases = [FirstCase | _],
@@ -78,35 +73,35 @@
 		Span = LastCaseVal - FirstCaseVal,
 		Range = Span + 1,
 		dense_switch__calc_density(NumCases, Range, Density),
-		Density > ReqDensity
-	},
-	( { CanFail0 = can_fail } ->
+	Density > ReqDensity,
+	( CanFail0 = can_fail ->
 		% For semidet switches, we normally need to check that
 		% the variable is in range before we index into the jump table.
 		% However, if the range of the type is sufficiently small,
 		% we can make the jump table large enough to hold all
 		% of the values for the type.
-		code_info__variable_type(CaseVar, Type),
-		code_info__get_module_info(ModuleInfo),
-		{ classify_type(ModuleInfo, Type) = TypeCategory },
+		Type = code_info__variable_type(CI, CaseVar),
+		code_info__get_module_info(CI, ModuleInfo),
+		classify_type(ModuleInfo, Type) = TypeCategory,
 		(
-			dense_switch__type_range(TypeCategory, Type, TypeRange),
-			{ dense_switch__calc_density(NumCases, TypeRange,
-				DetDensity) },
-			{ DetDensity > ReqDensity }
+			dense_switch__type_range(CI, TypeCategory, Type,
+				TypeRange),
+			dense_switch__calc_density(NumCases, TypeRange,
+				DetDensity),
+			DetDensity > ReqDensity
 		->
-			{ CanFail = cannot_fail },
-			{ FirstVal = 0 },
-			{ LastVal = TypeRange - 1 }
-		;
-			{ CanFail = CanFail0 },
-			{ FirstVal = FirstCaseVal },
-			{ LastVal = LastCaseVal }
+			CanFail = cannot_fail,
+			FirstVal = 0,
+			LastVal = TypeRange - 1
+		;
+			CanFail = CanFail0,
+			FirstVal = FirstCaseVal,
+			LastVal = LastCaseVal
 		)
 	;
-		{ CanFail = CanFail0 },
-		{ FirstVal = FirstCaseVal },
-		{ LastVal = LastCaseVal }
+		CanFail = CanFail0,
+		FirstVal = FirstCaseVal,
+		LastVal = LastCaseVal
 	).
 
 %---------------------------------------------------------------------------%
@@ -124,42 +119,41 @@
 	% Fail if the type isn't the sort of type that has a range
 	% or if the type's range is to big to switch on (e.g. int).
 
-dense_switch__type_range(TypeCategory, Type, Range) -->
-	code_info__get_module_info(ModuleInfo),
-	{ switch_util__type_range(TypeCategory, Type, ModuleInfo,
-		Min, Max) },
-	{ Range = Max - Min + 1 }.
+dense_switch__type_range(CI, TypeCategory, Type, Range) :-
+	code_info__get_module_info(CI, ModuleInfo),
+	switch_util__type_range(TypeCategory, Type, ModuleInfo, Min, Max),
+	Range = Max - Min + 1.
 
 %---------------------------------------------------------------------------%
 
 dense_switch__generate(Cases, StartVal, EndVal, Var, CodeModel, CanFail,
-		SwitchGoalInfo, EndLabel, MaybeEnd0, MaybeEnd, Code) -->
+		SwitchGoalInfo, EndLabel, MaybeEnd0, MaybeEnd, Code, !CI) :-
 		% Evaluate the variable which we are going to be switching on
-	code_info__produce_variable(Var, VarCode, Rval),
+	code_info__produce_variable(Var, VarCode, Rval, !CI),
 		% If the case values start at some number other than 0,
 		% then subtract that number to give us a zero-based index
-	{ StartVal = 0 ->
+	( StartVal = 0 ->
 		Index = Rval
 	;
 		Index = binop(-, Rval, const(int_const(StartVal)))
-	},
+	),
 		% If the switch is not locally deterministic, we need to
 		% check that the value of the variable lies within the
 		% appropriate range
 	(
-		{ CanFail = can_fail },
-		{ Difference = EndVal - StartVal },
+		CanFail = can_fail,
+		Difference = EndVal - StartVal,
 		code_info__fail_if_rval_is_false(
 			binop(unsigned_le, Index,
-				const(int_const(Difference))), RangeCheck)
+				const(int_const(Difference))), RangeCheck, !CI)
 	;
-		{ CanFail = cannot_fail },
-		{ RangeCheck = empty }
+		CanFail = cannot_fail,
+		RangeCheck = empty
 	),
 		% Now generate the jump table and the cases
 	dense_switch__generate_cases(Cases, StartVal, EndVal, CodeModel,
 		SwitchGoalInfo, EndLabel, MaybeEnd0, MaybeEnd, Labels,
-		CasesCode),
+		CasesCode, !CI),
 
 		% XXX
 		% We keep track of the code_info at the end of one of
@@ -167,94 +161,81 @@
 		% generating a `fail' slot last would yield the
 		% wrong liveness and would not unset the failure cont
 		% for a nondet switch.
-	{ DoJump = node([
+	DoJump = node([
 		computed_goto(Index, Labels)
 			- "switch (using dense jump table)"
-	]) },
+	]),
 		% Assemble the code together
-	{ Code = tree(VarCode, tree(RangeCheck, tree(DoJump, CasesCode))) }.
+	Code = tree(VarCode, tree(RangeCheck, tree(DoJump, CasesCode))).
 
-:- pred dense_switch__generate_cases(cases_list, int, int,
-	code_model, hlds_goal_info, label, branch_end, branch_end,
-	list(label), code_tree, code_info, code_info).
-:- mode dense_switch__generate_cases(in, in, in, in, in, in, in, out,
-	out, out, in, out) is det.
+:- pred dense_switch__generate_cases(cases_list::in, int::in, int::in,
+	code_model::in, hlds_goal_info::in, label::in, branch_end::in,
+	branch_end::out, list(label)::out, code_tree::out,
+	code_info::in, code_info::out) is det.
 
 dense_switch__generate_cases(Cases0, NextVal, EndVal, CodeModel,
-		SwitchGoalInfo, EndLabel, MaybeEnd0, MaybeEnd, Labels, Code)
-		-->
-	(
-		{ NextVal > EndVal }
-	->
-		{ MaybeEnd = MaybeEnd0 },
-		{ Labels = [] },
-		{ Code = node([
+		SwitchGoalInfo, EndLabel, !MaybeEnd, Labels, Code, !CI) :-
+	( NextVal > EndVal ->
+		Labels = [],
+		Code = node([
 			label(EndLabel)
 				- "End of dense switch"
-		]) }
+		])
 	;
-		code_info__get_next_label(ThisLabel),
-		dense_switch__generate_case(Cases0, NextVal, CodeModel,
-			SwitchGoalInfo, Cases1, MaybeEnd0, MaybeEnd1,
-			ThisCode, Comment),
-		{ LabelCode = node([
+		code_info__get_next_label(ThisLabel, !CI),
+		dense_switch__generate_case(Cases0, Cases1, NextVal, CodeModel,
+			SwitchGoalInfo, !MaybeEnd, ThisCode, Comment, !CI),
+		LabelCode = node([
 			label(ThisLabel)
 				- Comment
-		]) },
-		{ JumpCode = node([
+		]),
+		JumpCode = node([
 			goto(label(EndLabel))
 				- "branch to end of dense switch"
-		]) },
+		]),
 			% generate the rest of the cases.
-		{ NextVal1 = NextVal + 1 },
+		NextVal1 = NextVal + 1,
 		dense_switch__generate_cases(Cases1, NextVal1, EndVal,
 			CodeModel, SwitchGoalInfo, EndLabel,
-			MaybeEnd1, MaybeEnd, Labels1, OtherCasesCode),
-		{ Labels = [ThisLabel | Labels1] },
-		{ Code =
+			!MaybeEnd, Labels1, OtherCasesCode, !CI),
+		Labels = [ThisLabel | Labels1],
+		Code =
 			tree(LabelCode,
 			tree(ThisCode,
 			tree(JumpCode,
 			     OtherCasesCode)))
-		}
 	).
 
 %---------------------------------------------------------------------------%
 
-:- pred dense_switch__generate_case(cases_list, int, code_model,
-	hlds_goal_info, cases_list, branch_end, branch_end, code_tree, string,
-	code_info, code_info).
-:- mode dense_switch__generate_case(in, in, in, in, out, in, out, out, out,
-	in, out) is det.
+:- pred dense_switch__generate_case(cases_list::in, cases_list::out, int::in,
+	code_model::in, hlds_goal_info::in, branch_end::in, branch_end::out,
+	code_tree::out, string::out, code_info::in, code_info::out) is det.
 
-dense_switch__generate_case(Cases0, NextVal, CodeModel, SwitchGoalInfo, Cases,
-		MaybeEnd0, MaybeEnd, Code, Comment) -->
+dense_switch__generate_case(!Cases, NextVal, CodeModel, SwitchGoalInfo,
+		!MaybeEnd, Code, Comment, !CI) :-
 	(
-		{ Cases0 = [Case | Cases1] },
-		{ Case = case(_, int_constant(NextVal), _, Goal) }
+		!.Cases = [Case | !:Cases],
+		Case = case(_, int_constant(NextVal), _, Goal)
 	->
-		{ Comment = "case of dense switch" },
+		Comment = "case of dense switch",
 		% We need to save the expression cache, etc.,
 		% and restore them when we've finished.
-		code_info__remember_position(BranchStart),
+		code_info__remember_position(!.CI, BranchStart),
 		trace__maybe_generate_internal_event_code(Goal, SwitchGoalInfo,
-			TraceCode),
-		code_gen__generate_goal(CodeModel, Goal, GoalCode),
-		{ goal_info_get_store_map(SwitchGoalInfo, StoreMap) },
-		code_info__generate_branch_end(StoreMap, MaybeEnd0, MaybeEnd,
-			SaveCode),
-		{ Code =
+			TraceCode, !CI),
+		code_gen__generate_goal(CodeModel, Goal, GoalCode, !CI),
+		goal_info_get_store_map(SwitchGoalInfo, StoreMap),
+		code_info__generate_branch_end(StoreMap, !MaybeEnd, SaveCode,
+			!CI),
+		Code =
 			tree(TraceCode,
 			tree(GoalCode,
-			     SaveCode))
-		},
-		code_info__reset_to_position(BranchStart),
-		{ Cases = Cases1 }
+			     SaveCode)),
+		code_info__reset_to_position(BranchStart, !CI)
 	;
 		% This case didn't occur in the original case list
 		% - just generate a `fail' for it.
-		{ Comment = "compiler-introduced `fail' case of dense switch" },
-		code_info__generate_failure(Code),
-		{ MaybeEnd = MaybeEnd0 },
-		{ Cases = Cases0 }
+		Comment = "compiler-introduced `fail' case of dense switch",
+		code_info__generate_failure(Code, !CI)
 	).
Index: disj_gen.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/disj_gen.m,v
retrieving revision 1.78
diff -u -b -r1.78 disj_gen.m
--- disj_gen.m	15 Mar 2003 07:11:56 -0000	1.78
+++ disj_gen.m	22 Oct 2003 06:12:23 -0000
@@ -44,25 +44,25 @@
 
 :- import_module bool, set, libs__tree, map, std_util, term, require.
 
-disj_gen__generate_disj(CodeModel, Goals, DisjGoalInfo, Code) -->
+disj_gen__generate_disj(CodeModel, Goals, DisjGoalInfo, Code, !CI) :-
 	(
-		{ Goals = [] },
-		( { CodeModel = model_semi } ->
-			code_info__generate_failure(Code)
+		Goals = [],
+		( CodeModel = model_semi ->
+			code_info__generate_failure(Code, !CI)
 		;
-			{ error("empty disjunction") }
+			error("empty disjunction")
 		)
 	;
-		{ Goals = [Goal | _] },
-		{ Goal = _ - GoalInfo },
-		{ goal_info_get_resume_point(GoalInfo, Resume) },
-		{ Resume = resume_point(ResumeVarsPrime, _) ->
+		Goals = [Goal | _],
+		Goal = _ - GoalInfo,
+		goal_info_get_resume_point(GoalInfo, Resume),
+		( Resume = resume_point(ResumeVarsPrime, _) ->
 			ResumeVars = ResumeVarsPrime
 		;
 			set__init(ResumeVars)
-		},
+		),
 		disj_gen__generate_real_disj(CodeModel, ResumeVars,
-			Goals, DisjGoalInfo, Code)
+			Goals, DisjGoalInfo, Code, !CI)
 	).
 
 %---------------------------------------------------------------------------%
@@ -71,37 +71,37 @@
 	list(hlds_goal)::in, hlds_goal_info::in, code_tree::out,
 	code_info::in, code_info::out) is det.
 
-disj_gen__generate_real_disj(CodeModel, ResumeVars, Goals, DisjGoalInfo, Code)
-		-->
+disj_gen__generate_real_disj(CodeModel, ResumeVars, Goals, DisjGoalInfo, Code,
+		!CI)  :-
 
 		% Make sure that the variables whose values will be needed
 		% on backtracking to any disjunct are materialized into
 		% registers or stack slots. Their locations are recorded
 		% in ResumeMap.
-	code_info__produce_vars(ResumeVars, ResumeMap, FlushCode),
+	code_info__produce_vars(ResumeVars, ResumeMap, FlushCode, !CI),
 
 		% If we are using a trail, save the current trail state
 		% before the first disjunct.
 		% XXX We should use a scheme such as the one we use for heap
 		% recovery for semi and det disjunctions, and delay saving
 		% the ticket until necessary.
-	code_info__get_globals(Globals),
-	{ globals__lookup_bool_option(Globals, use_trail, UseTrail) },
+	code_info__get_globals(!.CI, Globals),
+	globals__lookup_bool_option(Globals, use_trail, UseTrail),
 	code_info__maybe_save_ticket(UseTrail, SaveTicketCode,
-		MaybeTicketSlot),
+		MaybeTicketSlot, !CI),
 
 		% If we are using a grade in which we can recover memory
 		% by saving and restoring the heap pointer, set up for
 		% doing so if necessary.
-	( { CodeModel = model_non } ->
+	( CodeModel = model_non ->
 			% With nondet disjunctions, we must recover memory
 			% across all disjuncts, even disjuncts that cannot
 			% themselves allocate memory, since we can backtrack
 			% to disjunct N after control leaves disjunct N-1.
-		{ globals__lookup_bool_option(Globals,
-			reclaim_heap_on_nondet_failure, ReclaimHeap) },
+		globals__lookup_bool_option(Globals,
+			reclaim_heap_on_nondet_failure, ReclaimHeap),
 		code_info__maybe_save_hp(ReclaimHeap, SaveHpCode,
-			MaybeHpSlot)
+			MaybeHpSlot, !CI)
 	;
 			% With other disjunctions, we can backtrack to
 			% disjunct N only from disjunct N-1, so if disjunct
@@ -110,40 +110,39 @@
 			% for no disjunct to allocate memory, we delay saving
 			% the heap pointer and allocating a stack slot for
 			% the saved hp as long as possible.
-		{ globals__lookup_bool_option(Globals,
-			reclaim_heap_on_semidet_failure, ReclaimHeap) },
-		{ SaveHpCode = empty },
-		{ MaybeHpSlot = no }
+		globals__lookup_bool_option(Globals,
+			reclaim_heap_on_semidet_failure, ReclaimHeap),
+		SaveHpCode = empty,
+		MaybeHpSlot = no
 	),
 
 		% Save the values of any stack slots we may hijack,
 		% and if necessary, set the redofr slot of the top frame
 		% to point to this frame.
 	code_info__prepare_for_disj_hijack(CodeModel,
-		HijackInfo, PrepareHijackCode),
+		HijackInfo, PrepareHijackCode, !CI),
 
-	code_info__get_next_label(EndLabel),
+	code_info__get_next_label(EndLabel, !CI),
 
-	code_info__remember_position(BranchStart),
+	code_info__remember_position(!.CI, BranchStart),
 	disj_gen__generate_disjuncts(Goals, CodeModel, ResumeMap, no,
 		HijackInfo, DisjGoalInfo, EndLabel,
 		ReclaimHeap, MaybeHpSlot, MaybeTicketSlot,
-		BranchStart, no, MaybeEnd, GoalsCode),
+		BranchStart, no, MaybeEnd, GoalsCode, !CI),
 
-	{ goal_info_get_store_map(DisjGoalInfo, StoreMap) },
-	code_info__after_all_branches(StoreMap, MaybeEnd),
-	( { CodeModel = model_non } ->
-		code_info__set_resume_point_to_unknown
+	goal_info_get_store_map(DisjGoalInfo, StoreMap),
+	code_info__after_all_branches(StoreMap, MaybeEnd, !CI),
+	( CodeModel = model_non ->
+		code_info__set_resume_point_to_unknown(!CI)
 	;
-		[]
+		true
 	),
-	{ Code =
+	Code =
 		tree(FlushCode,
 		tree(SaveTicketCode,
 		tree(SaveHpCode,
 		tree(PrepareHijackCode,
-		     GoalsCode))))
-	}.
+		     GoalsCode)))).
 
 %---------------------------------------------------------------------------%
 
@@ -154,33 +153,33 @@
 	maybe(branch_end_info)::in, maybe(branch_end_info)::out,
 	code_tree::out, code_info::in, code_info::out) is det.
 
-disj_gen__generate_disjuncts([], _, _, _, _, _, _, _, _, _, _, _, _, _) -->
-	{ error("empty disjunction!") }.
+disj_gen__generate_disjuncts([], _, _, _, _, _, _, _, _, _, _, _, _, _, !CI) :-
+	error("empty disjunction!").
 disj_gen__generate_disjuncts([Goal0 | Goals], CodeModel, FullResumeMap,
 		MaybeEntryResumePoint, HijackInfo, DisjGoalInfo, EndLabel,
 		ReclaimHeap, MaybeHpSlot0, MaybeTicketSlot,
-		BranchStart0, MaybeEnd0, MaybeEnd, Code) -->
+		BranchStart0, MaybeEnd0, MaybeEnd, Code, !CI) :-
 
-	code_info__reset_to_position(BranchStart0),
+	code_info__reset_to_position(BranchStart0, !CI),
 
 		% If this is not the first disjunct, generate the
 		% resume point by which arrive at this disjunct.
-	( { MaybeEntryResumePoint = yes(EntryResumePoint) } ->
+	( MaybeEntryResumePoint = yes(EntryResumePoint) ->
 		code_info__generate_resume_point(EntryResumePoint,
-			EntryResumePointCode)
+			EntryResumePointCode, !CI)
 	;
-		{ EntryResumePointCode = empty }
+		EntryResumePointCode = empty
 	),
 
-	{ Goal0 = GoalExpr0 - GoalInfo0 },
-	{ goal_info_get_resume_point(GoalInfo0, Resume) },
+	Goal0 = GoalExpr0 - GoalInfo0,
+	goal_info_get_resume_point(GoalInfo0, Resume),
 	(
-		{ Resume = resume_point(ResumeVars, ResumeLocs) }
+		Resume = resume_point(ResumeVars, ResumeLocs)
 	->
 		% Emit code for a non-last disjunct, including setting things
 		% up for the execution of the next disjunct.
 
-		( { MaybeEntryResumePoint = yes(_) } ->
+		( MaybeEntryResumePoint = yes(_) ->
 				% Reset the heap pointer to recover memory
 				% allocated by the previous disjunct(s),
 				% if necessary.
@@ -191,26 +190,26 @@
 			code_info__maybe_reset_ticket(MaybeTicketSlot, undo,
 				RestoreTicketCode)
 		;
-			{ RestoreHpCode = empty },
-			{ RestoreTicketCode = empty }
+			RestoreHpCode = empty,
+			RestoreTicketCode = empty
 		),
 
 			% The pre_goal_update sanity check insists on
 			% no_resume_point, to make sure that all resume
 			% points have been handled by surrounding code.
-		{ goal_info_set_resume_point(GoalInfo0, no_resume_point,
-			GoalInfo) },
-		{ Goal = GoalExpr0 - GoalInfo },
+		goal_info_set_resume_point(GoalInfo0, no_resume_point,
+			GoalInfo),
+		Goal = GoalExpr0 - GoalInfo,
 
 			% Save hp if it needs to be saved and hasn't been
 			% saved previously.
 		(
-			{ ReclaimHeap = yes },
-			{ goal_may_allocate_heap(Goal) },
-			{ MaybeHpSlot0 = no }
+			ReclaimHeap = yes,
+			goal_may_allocate_heap(Goal),
+			MaybeHpSlot0 = no
 		->
-			code_info__save_hp(SaveHpCode, HpSlot),
-			{ MaybeHpSlot = yes(HpSlot) },
+			code_info__save_hp(SaveHpCode, HpSlot, !CI),
+			MaybeHpSlot = yes(HpSlot),
 				% This method of updating BranchStart0 is
 				% ugly. The best alternative would be to
 				% arrange things so that a remember_position
@@ -220,49 +219,50 @@
 				% disjunction, which overwrites part of the
 				% location-dependent state originally in
 				% BranchStart0.
-			{ code_info__save_hp_in_branch(BranchSaveHpCode,
-				BranchHpSlot, BranchStart0, BranchStart) },
-			{ tree__flatten(SaveHpCode, HpCodeList) },
-			{ tree__flatten(BranchSaveHpCode, BranchHpCodeList) },
-			{ require(unify(HpCodeList, BranchHpCodeList),
-				"cannot use same code for saving hp") },
-			{ require(unify(HpSlot, BranchHpSlot),
-				"cannot allocate same slot for saved hp") }
+			code_info__save_hp_in_branch(BranchSaveHpCode,
+				BranchHpSlot, BranchStart0, BranchStart),
+			tree__flatten(SaveHpCode, HpCodeList),
+			tree__flatten(BranchSaveHpCode, BranchHpCodeList),
+			require(unify(HpCodeList, BranchHpCodeList),
+				"cannot use same code for saving hp"),
+			require(unify(HpSlot, BranchHpSlot),
+				"cannot allocate same slot for saved hp")
 		;
-			{ SaveHpCode = empty },
-			{ MaybeHpSlot = MaybeHpSlot0 },
-			{ BranchStart = BranchStart0 }
+			SaveHpCode = empty,
+			MaybeHpSlot = MaybeHpSlot0,
+			BranchStart = BranchStart0
 		),
 
 		code_info__make_resume_point(ResumeVars, ResumeLocs,
-			FullResumeMap, NextResumePoint),
+			FullResumeMap, NextResumePoint, !CI),
 		code_info__effect_resume_point(NextResumePoint, CodeModel,
-			ModContCode),
+			ModContCode, !CI),
 
 		trace__maybe_generate_internal_event_code(Goal, DisjGoalInfo,
-			TraceCode),
-		{ goal_info_get_code_model(GoalInfo, GoalCodeModel) },
-		code_gen__generate_goal(GoalCodeModel, Goal, GoalCode),
+			TraceCode, !CI),
+		goal_info_get_code_model(GoalInfo, GoalCodeModel),
+		code_gen__generate_goal(GoalCodeModel, Goal, GoalCode, !CI),
 
-		( { CodeModel = model_non } ->
+		( CodeModel = model_non ->
 			% We can backtrack to the next disjunct from outside,
 			% so we make sure every variable in the resume set
 			% is in its stack slot.
-			code_info__flush_resume_vars_to_stack(ResumeVarsCode),
+			code_info__flush_resume_vars_to_stack(ResumeVarsCode,
+			!CI),
 
 			% We hang onto any temporary slots holding saved
 			% heap pointers and/or tickets, thus ensuring that
 			% they will still be reserved after the disjunction.
-			{ PruneTicketCode = empty }
+			PruneTicketCode = empty
 		;
-			{ ResumeVarsCode = empty },
+			ResumeVarsCode = empty,
 
-			code_info__maybe_release_hp(MaybeHpSlot),
+			code_info__maybe_release_hp(MaybeHpSlot, !CI),
 			% We're committing to this disjunct if it succeeds.
 			code_info__maybe_reset_prune_and_release_ticket(
-				MaybeTicketSlot, commit, PruneTicketCode),
+				MaybeTicketSlot, commit, PruneTicketCode, !CI),
 
-			code_info__reset_resume_known(BranchStart)
+			code_info__reset_resume_known(BranchStart, !CI)
 		),
 
 			% Forget the variables that are needed only at the
@@ -270,29 +270,29 @@
 			% so that we don't generate exceptions when their
 			% storage is clobbered by the movement of the live
 			% variables to the places indicated in the store map.
-		code_info__pop_resume_point,
-		code_info__pickup_zombies(Zombies),
-		code_info__make_vars_forward_dead(Zombies),
+		code_info__pop_resume_point(!CI),
+		code_info__pickup_zombies(Zombies, !CI),
+		code_info__make_vars_forward_dead(Zombies, !CI),
 
 			% Put every variable whose value is needed after
 			% the disjunction to the place indicated by StoreMap,
 			% and accumulate information about the code_info state
 			% at the ends of the branches so far.
-		{ goal_info_get_store_map(DisjGoalInfo, StoreMap) },
+		goal_info_get_store_map(DisjGoalInfo, StoreMap),
 		code_info__generate_branch_end(StoreMap, MaybeEnd0, MaybeEnd1,
-			SaveCode),
+			SaveCode, !CI),
 
-		{ BranchCode = node([
+		BranchCode = node([
 			goto(label(EndLabel)) -
 				"skip to end of nondet disj"
-		]) },
+		]),
 
 		disj_gen__generate_disjuncts(Goals, CodeModel, FullResumeMap,
 			yes(NextResumePoint), HijackInfo, DisjGoalInfo,
 			EndLabel, ReclaimHeap, MaybeHpSlot, MaybeTicketSlot,
-			BranchStart, MaybeEnd1, MaybeEnd, RestCode),
+			BranchStart, MaybeEnd1, MaybeEnd, RestCode, !CI),
 
-		{ Code =
+		Code =
 			tree(EntryResumePointCode, 
 			tree(RestoreHpCode,
 			tree(RestoreTicketCode,
@@ -305,30 +305,29 @@
 			tree(SaveCode,
 			tree(BranchCode,
 			     RestCode)))))))))))
-		}
 	;
 		% Emit code for the last disjunct
 
 			% Restore the heap pointer and solver state
 			% if necessary.
 		code_info__maybe_restore_and_release_hp(MaybeHpSlot0,
-			RestoreHpCode),
+			RestoreHpCode, !CI),
 		code_info__maybe_reset_discard_and_release_ticket(
-			MaybeTicketSlot, undo, RestoreTicketCode),
+			MaybeTicketSlot, undo, RestoreTicketCode, !CI),
 
-		code_info__undo_disj_hijack(HijackInfo, UndoCode),
+		code_info__undo_disj_hijack(HijackInfo, UndoCode, !CI),
 
 		trace__maybe_generate_internal_event_code(Goal0, DisjGoalInfo,
-			TraceCode),
-		code_gen__generate_goal(CodeModel, Goal0, GoalCode),
-		{ goal_info_get_store_map(DisjGoalInfo, StoreMap) },
+			TraceCode, !CI),
+		code_gen__generate_goal(CodeModel, Goal0, GoalCode, !CI),
+		goal_info_get_store_map(DisjGoalInfo, StoreMap),
 		code_info__generate_branch_end(StoreMap, MaybeEnd0, MaybeEnd,
-			SaveCode),
+			SaveCode, !CI),
 
-		{ EndCode = node([
+		EndCode = node([
 			label(EndLabel) - "End of nondet disj"
-		]) },
-		{ Code =
+		]),
+		Code =
 			tree(EntryResumePointCode,
 			tree(TraceCode,
 			tree(RestoreHpCode,
@@ -337,7 +336,6 @@
 			tree(GoalCode,
 			tree(SaveCode,
 			     EndCode)))))))
-		}
 	).
 
 %---------------------------------------------------------------------------%
Index: ite_gen.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/ite_gen.m,v
retrieving revision 1.71
diff -u -b -r1.71 ite_gen.m
--- ite_gen.m	18 Mar 2003 16:37:29 -0000	1.71
+++ ite_gen.m	22 Oct 2003 06:18:30 -0000
@@ -49,20 +49,20 @@
 :- import_module bool, string, set, term, list, map, std_util, require.
 
 ite_gen__generate_ite(CodeModel, CondGoal0, ThenGoal, ElseGoal, IteGoalInfo,
-		Code) -->
-	{ CondGoal0 = CondExpr - CondInfo0 },
-	{ goal_info_get_code_model(CondInfo0, CondCodeModel) },
-	{
+		Code, !CI) :-
+	CondGoal0 = CondExpr - CondInfo0,
+	goal_info_get_code_model(CondInfo0, CondCodeModel),
+	(
 		CodeModel = model_non,
 		CondCodeModel \= model_non
 	->
 		EffCodeModel = model_semi
 	;
 		EffCodeModel = CodeModel
-	},
+	),
 
-	{ goal_info_get_resume_point(CondInfo0, Resume) },
-	{
+	goal_info_get_resume_point(CondInfo0, Resume),
+	(
 		Resume = resume_point(ResumeVarsPrime, ResumeLocsPrime)
 	->
 		ResumeVars = ResumeVarsPrime,
@@ -75,19 +75,19 @@
 		CondGoal = CondExpr - CondInfo
 	;
 		error("condition of an if-then-else has no resume point")
-	},
+	),
 
 		% Make sure that the variables whose values will be needed
 		% on backtracking to the else part are materialized into
 		% registers or stack slots. Their locations are recorded
 		% in ResumeMap.
-	code_info__produce_vars(ResumeVars, ResumeMap, FlushCode),
+	code_info__produce_vars(ResumeVars, ResumeMap, FlushCode, !CI),
 
 		% Maybe save the heap state current before the condition.
 		% This is after code_info__produce_vars since code that
 		% flushes the cache may allocate memory we must not "recover".
-	code_info__get_globals(Globals),
-	{ 
+	code_info__get_globals(!.CI, Globals),
+	(
 		globals__lookup_bool_option(Globals,
 			reclaim_heap_on_semidet_failure, yes),
 		goal_may_allocate_heap(CondGoal)
@@ -95,37 +95,37 @@
 		ReclaimHeap = yes
 	;
 		ReclaimHeap = no
-	},
-	code_info__maybe_save_hp(ReclaimHeap, SaveHpCode, MaybeHpSlot),
+	),
+	code_info__maybe_save_hp(ReclaimHeap, SaveHpCode, MaybeHpSlot, !CI),
 
 		% Maybe save the current trail state before the condition
-	{ globals__lookup_bool_option(Globals, use_trail, UseTrail) },
+	globals__lookup_bool_option(Globals, use_trail, UseTrail),
 	code_info__maybe_save_ticket(UseTrail, SaveTicketCode,
-		MaybeTicketSlot),
+		MaybeTicketSlot, !CI),
 
-	code_info__remember_position(BranchStart),
+	code_info__remember_position(!.CI, BranchStart),
 
 	code_info__prepare_for_ite_hijack(EffCodeModel, HijackInfo,
-		PrepareHijackCode),
+		PrepareHijackCode, !CI),
 
 	code_info__make_resume_point(ResumeVars, ResumeLocs, ResumeMap,
-		ResumePoint),
+		ResumePoint, !CI),
 	code_info__effect_resume_point(ResumePoint, EffCodeModel,
-		EffectResumeCode),
+		EffectResumeCode, !CI),
 
 		% Generate the condition
 	trace__maybe_generate_internal_event_code(CondGoal, IteGoalInfo,
-		CondTraceCode),
-	code_gen__generate_goal(CondCodeModel, CondGoal, CondCode),
+		CondTraceCode, !CI),
+	code_gen__generate_goal(CondCodeModel, CondGoal, CondCode, !CI),
 
-	code_info__ite_enter_then(HijackInfo, ThenNeckCode, ElseNeckCode),
+	code_info__ite_enter_then(HijackInfo, ThenNeckCode, ElseNeckCode, !CI),
 
 		% Kill again any variables that have become zombies
-	code_info__pickup_zombies(Zombies),
-	code_info__make_vars_forward_dead(Zombies),
+	code_info__pickup_zombies(Zombies, !CI),
+	code_info__make_vars_forward_dead(Zombies, !CI),
 
 		% Discard hp and prune trail ticket if the condition succeeded
-	( { CondCodeModel = model_non } ->
+	( CondCodeModel = model_non ->
 		% We cannot release the stack slots used for the heap pointer
 		% and the trail ticket if the condition can be backtracked
 		% into.  Nor can we prune the trail ticket that we allocated,
@@ -134,58 +134,59 @@
 		code_info__maybe_reset_ticket(
 			MaybeTicketSlot, solve, ResetTicketCode)
 	;
-		code_info__maybe_release_hp(MaybeHpSlot),
+		code_info__maybe_release_hp(MaybeHpSlot, !CI),
 		code_info__maybe_reset_prune_and_release_ticket(
-			MaybeTicketSlot, commit, ResetTicketCode)
+			MaybeTicketSlot, commit, ResetTicketCode, !CI)
 	),
 
-	{ goal_info_get_store_map(IteGoalInfo, StoreMap) },
-	code_info__get_instmap(EndCondInstMap),
-	( { instmap__is_unreachable(EndCondInstMap) } ->
+	goal_info_get_store_map(IteGoalInfo, StoreMap),
+	code_info__get_instmap(!.CI, EndCondInstMap),
+	( instmap__is_unreachable(EndCondInstMap) ->
 		% If the instmap indicates we cannot reach the then part,
 		% do not attempt to generate it (may cause aborts).
-		{ ThenTraceCode = empty },
-		{ ThenCode = empty },
-		{ map__init(EmptyStoreMap) },
+		ThenTraceCode = empty,
+		ThenCode = empty,
+		map__init(EmptyStoreMap),
 		code_info__generate_branch_end(EmptyStoreMap, no,
-			MaybeEnd0, ThenSaveCode)
+			MaybeEnd0, ThenSaveCode, !CI)
 	;	
 			% Generate the then branch
 		trace__maybe_generate_internal_event_code(ThenGoal,
-			IteGoalInfo, ThenTraceCode),
-		code_gen__generate_goal(CodeModel, ThenGoal, ThenCode),
+			IteGoalInfo, ThenTraceCode, !CI),
+		code_gen__generate_goal(CodeModel, ThenGoal, ThenCode, !CI),
 		code_info__generate_branch_end(StoreMap, no,
-			MaybeEnd0, ThenSaveCode)
+			MaybeEnd0, ThenSaveCode, !CI)
 	),
 
 		% Generate the entry to the else branch
-	code_info__reset_to_position(BranchStart),
-	code_info__generate_resume_point(ResumePoint, ResumeCode),
+	code_info__reset_to_position(BranchStart, !CI),
+	code_info__generate_resume_point(ResumePoint, ResumeCode, !CI),
 
 		% Restore the heap pointer and solver state if necessary.
-	code_info__maybe_restore_and_release_hp(MaybeHpSlot, RestoreHpCode),
+	code_info__maybe_restore_and_release_hp(MaybeHpSlot, RestoreHpCode,
+		!CI),
 	code_info__maybe_reset_discard_and_release_ticket(
-		MaybeTicketSlot, undo, RestoreTicketCode),
+		MaybeTicketSlot, undo, RestoreTicketCode, !CI),
 
 		% Generate the else branch
 	trace__maybe_generate_internal_event_code(ElseGoal, IteGoalInfo,
-		ElseTraceCode),
-	code_gen__generate_goal(CodeModel, ElseGoal, ElseCode),
+		ElseTraceCode, !CI),
+	code_gen__generate_goal(CodeModel, ElseGoal, ElseCode, !CI),
 	code_info__generate_branch_end(StoreMap, MaybeEnd0, MaybeEnd,
-		ElseSaveCode),
+		ElseSaveCode, !CI),
 
-	code_info__get_next_label(EndLabel),
-	{ JumpToEndCode = node([
+	code_info__get_next_label(EndLabel, !CI),
+	JumpToEndCode = node([
 		goto(label(EndLabel))
 			- "Jump to the end of if-then-else"
-	]) },
-	{ EndLabelCode = node([
+	]),
+	EndLabelCode = node([
 		label(EndLabel)
 			- "end of if-then-else"
-	]) },
-	{ make_pneg_context_wrappers(Globals, PNegCondCode, PNegThenCode,
-		PNegElseCode) },
-	{ Code =
+	]),
+	make_pneg_context_wrappers(Globals, PNegCondCode, PNegThenCode,
+		PNegElseCode),
+	Code =
 		tree(FlushCode,
 		tree(SaveHpCode,
 		tree(SaveTicketCode,
@@ -209,24 +210,21 @@
 		tree(PNegElseCode,
 		tree(ElseCode,
 		tree(ElseSaveCode,
-		     EndLabelCode)))))))))))))))))))))))
-	},
-	code_info__after_all_branches(StoreMap, MaybeEnd).
+		     EndLabelCode))))))))))))))))))))))),
+	code_info__after_all_branches(StoreMap, MaybeEnd, !CI).
 
 %---------------------------------------------------------------------------%
 
-ite_gen__generate_negation(CodeModel, Goal0, NotGoalInfo, Code) -->
-	{ CodeModel = model_non ->
+ite_gen__generate_negation(CodeModel, Goal0, NotGoalInfo, Code, !CI) :-
+	( CodeModel = model_non ->
 		error("nondet negation")
 	;
 		true
-	},
+	),
 
-	{ Goal0 = GoalExpr - GoalInfo0 },
-	{ goal_info_get_resume_point(GoalInfo0, Resume) },
-	{
-		Resume = resume_point(ResumeVarsPrime, ResumeLocsPrime)
-	->
+	Goal0 = GoalExpr - GoalInfo0,
+	goal_info_get_resume_point(GoalInfo0, Resume),
+	( Resume = resume_point(ResumeVarsPrime, ResumeLocsPrime) ->
 		ResumeVars = ResumeVarsPrime,
 		ResumeLocs = ResumeLocsPrime,
 		goal_info_set_resume_point(GoalInfo0, no_resume_point,
@@ -234,43 +232,44 @@
 		Goal = GoalExpr - GoalInfo
 	;
 		error("negated goal has no resume point")
-	},
+	),
 
 		% For a negated simple test, we can generate better code
 		% than the general mechanism, because we don't have to
 		% flush the cache.
 	(
-		{ CodeModel = model_semi },
-		{ GoalExpr = unify(_, _, _, simple_test(L, R), _) },
-		code_info__failure_is_direct_branch(CodeAddr),
-		code_info__get_globals(Globals),
-		{ globals__lookup_bool_option(Globals, simple_neg, yes) }
+		CodeModel = model_semi,
+		GoalExpr = unify(_, _, _, simple_test(L, R), _),
+		code_info__failure_is_direct_branch(!.CI, CodeAddr),
+		code_info__get_globals(!.CI, Globals),
+		globals__lookup_bool_option(Globals, simple_neg, yes)
 	->
 			% Because we are generating the negated goal ourselves,
 			% we need to apply the pre- and post-goal updates
 			% that would normally be applied by
 			% code_gen__generate_goal.
 
-		code_info__enter_simple_neg(ResumeVars, GoalInfo, SimpleNeg),
-		code_info__produce_variable(L, CodeL, ValL),
-		code_info__produce_variable(R, CodeR, ValR),
-		code_info__variable_type(L, Type),
-		{ Type = term__functor(term__atom("string"), [], _) ->
+		code_info__enter_simple_neg(ResumeVars, GoalInfo, SimpleNeg,
+			!CI),
+		code_info__produce_variable(L, CodeL, ValL, !CI),
+		code_info__produce_variable(R, CodeR, ValR, !CI),
+		Type = code_info__variable_type(!.CI, L),
+		( Type = term__functor(term__atom("string"), [], _) ->
 			Op = str_eq
 		; Type = term__functor(term__atom("float"), [], _) ->
 			Op = float_eq
 		;
 			Op = eq
-		},
-		{ TestCode = node([
+		),
+		TestCode = node([
 			if_val(binop(Op, ValL, ValR), CodeAddr) -
 				"test inequality"
-		]) },
-		code_info__leave_simple_neg(GoalInfo, SimpleNeg),
-		{ Code = tree(tree(CodeL, CodeR), TestCode) }
+		]),
+		code_info__leave_simple_neg(GoalInfo, SimpleNeg, !CI),
+		Code = tree(tree(CodeL, CodeR), TestCode)
 	;
 		generate_negation_general(CodeModel, Goal, NotGoalInfo,
-			ResumeVars, ResumeLocs, Code)
+			ResumeVars, ResumeLocs, Code, !CI)
 	).
 
 	% The code of generate_negation_general is a cut-down version
@@ -281,15 +280,15 @@
 	code_info::in, code_info::out) is det.
 
 generate_negation_general(CodeModel, Goal, NotGoalInfo, ResumeVars, ResumeLocs,
-		Code) -->
+		Code, !CI) :-
 
-	code_info__produce_vars(ResumeVars, ResumeMap, FlushCode),
+	code_info__produce_vars(ResumeVars, ResumeMap, FlushCode, !CI),
 
 		% Maybe save the heap state current before the condition;
 		% this ought to be after we make the failure continuation
 		% because that causes the cache to get flushed
-	code_info__get_globals(Globals),
-	{
+	code_info__get_globals(!.CI, Globals),
+	(
 		globals__lookup_bool_option(Globals,
 			reclaim_heap_on_semidet_failure, yes),
 		goal_may_allocate_heap(Goal)
@@ -297,72 +296,73 @@
 		ReclaimHeap = yes
 	;
 		ReclaimHeap = no
-	},
-	code_info__maybe_save_hp(ReclaimHeap, SaveHpCode, MaybeHpSlot),
+	),
+	code_info__maybe_save_hp(ReclaimHeap, SaveHpCode, MaybeHpSlot, !CI),
 
-	{ globals__lookup_bool_option(Globals, use_trail, UseTrail) },
+	globals__lookup_bool_option(Globals, use_trail, UseTrail),
 	code_info__maybe_save_ticket(UseTrail, SaveTicketCode,
-		MaybeTicketSlot),
+		MaybeTicketSlot, !CI),
 
 	code_info__prepare_for_ite_hijack(CodeModel, HijackInfo,
-		PrepareHijackCode),
+		PrepareHijackCode, !CI),
 
 	code_info__make_resume_point(ResumeVars, ResumeLocs, ResumeMap,
-		ResumePoint),
+		ResumePoint, !CI),
 	code_info__effect_resume_point(ResumePoint, CodeModel,
-		EffectResumeCode),
+		EffectResumeCode, !CI),
 
 		% Generate the negated goal as a semi-deterministic goal;
 		% it cannot be nondet, since mode correctness requires it
 		% to have no output vars.
 	trace__maybe_generate_internal_event_code(Goal, NotGoalInfo,
-		EnterTraceCode),
-	code_gen__generate_goal(model_semi, Goal, GoalCode),
+		EnterTraceCode, !CI),
+	code_gen__generate_goal(model_semi, Goal, GoalCode, !CI),
 
-	code_info__ite_enter_then(HijackInfo, ThenNeckCode, ElseNeckCode),
+	code_info__ite_enter_then(HijackInfo, ThenNeckCode, ElseNeckCode, !CI),
 
 		% Kill again any variables that have become zombies
-	code_info__pickup_zombies(Zombies),
-	code_info__make_vars_forward_dead(Zombies),
+	code_info__pickup_zombies(Zombies, !CI),
+	code_info__make_vars_forward_dead(Zombies, !CI),
 
-	code_info__get_forward_live_vars(LiveVars),
+	code_info__get_forward_live_vars(!.CI, LiveVars),
 
-	( { CodeModel = model_det } ->
+	( CodeModel = model_det ->
 			% the then branch will never be reached
-		{ PruneTicketCode = empty },
-		{ FailTraceCode = empty },
-		{ FailCode = empty }
+		PruneTicketCode = empty,
+		FailTraceCode = empty,
+		FailCode = empty
 	;
-		code_info__remember_position(AfterNegatedGoal),
+		code_info__remember_position(!.CI, AfterNegatedGoal),
 		% The call to reset_ticket(..., commit) here is necessary
 		% in order to properly detect floundering.
-		code_info__maybe_release_hp(MaybeHpSlot),
+		code_info__maybe_release_hp(MaybeHpSlot, !CI),
 		code_info__maybe_reset_prune_and_release_ticket(
-			MaybeTicketSlot, commit, PruneTicketCode),
+			MaybeTicketSlot, commit, PruneTicketCode, !CI),
 		trace__maybe_generate_negated_event_code(Goal, NotGoalInfo,
-			neg_failure, FailTraceCode),
-		code_info__generate_failure(FailCode),
+			neg_failure, FailTraceCode, !CI),
+		code_info__generate_failure(FailCode, !CI),
 			% We want liveness after not(G) to be the same as
 			% after G. Information about what variables are where
 			% will be set by code_info__generate_resume_point.
-		code_info__reset_to_position(AfterNegatedGoal)
+		code_info__reset_to_position(AfterNegatedGoal, !CI)
 	),
 
 		% Generate the entry to the else branch
-	code_info__generate_resume_point(ResumePoint, ResumeCode),
+	code_info__generate_resume_point(ResumePoint, ResumeCode, !CI),
 
-	code_info__set_forward_live_vars(LiveVars),
+	code_info__set_forward_live_vars(LiveVars, !CI),
 
 		% Restore the heap pointer and solver state if necessary.
-	code_info__maybe_restore_and_release_hp(MaybeHpSlot, RestoreHpCode),
+	code_info__maybe_restore_and_release_hp(MaybeHpSlot, RestoreHpCode,
+		!CI),
 	code_info__maybe_reset_discard_and_release_ticket(
-		MaybeTicketSlot, undo, RestoreTicketCode),
+		MaybeTicketSlot, undo, RestoreTicketCode, !CI),
 	trace__maybe_generate_negated_event_code(Goal, NotGoalInfo,
-		neg_success, SuccessTraceCode),
+		neg_success, SuccessTraceCode, !CI),
 
-	{ make_pneg_context_wrappers(Globals, PNegCondCode, PNegThenCode,
-		PNegElseCode) },
-	{ Code =
+	make_pneg_context_wrappers(Globals, PNegCondCode, PNegThenCode,
+		PNegElseCode),
+	Code =
 		tree(FlushCode,
 		tree(PrepareHijackCode,
 		tree(EffectResumeCode,
@@ -381,8 +381,7 @@
 		tree(RestoreTicketCode,
 		tree(RestoreHpCode,
 		tree(SuccessTraceCode,
-		     PNegElseCode))))))))))))))))))
-	}.
+		     PNegElseCode)))))))))))))))))).
 
 %---------------------------------------------------------------------------%
 
Index: lookup_switch.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/lookup_switch.m,v
retrieving revision 1.50
diff -u -b -r1.50 lookup_switch.m
--- lookup_switch.m	20 Oct 2003 07:29:07 -0000	1.50
+++ lookup_switch.m	22 Oct 2003 06:26:23 -0000
@@ -94,9 +94,9 @@
 	% get the constants (if they exist). We can't throw it away at the
 	% end because we may have allocated some new static ground term labels.
 lookup_switch__is_lookup_switch(CaseVar, TaggedCases, GoalInfo, SwitchCanFail,
-		ReqDensity, StoreMap, MaybeEnd0, MaybeEnd, CodeModel,
+		ReqDensity, StoreMap, !MaybeEnd, CodeModel,
 		FirstVal, LastVal, NeedRangeCheck, NeedBitVecTest, OutVars,
-		CaseValues, MLiveness) -->
+		CaseValues, MLiveness, !CI) :-
 
 		% Since lookup switches rely on static ground terms to
 		% work efficiently, there is no point in using a lookup
@@ -105,9 +105,9 @@
 		% some circumstances, but it would take a pretty complex
 		% heuristic to get it right, so, lets just use a simple
 		% one - no static ground terms, no lookup switch.
-	code_info__get_globals(Globals),
-	{ globals__lookup_bool_option(Globals, static_ground_terms, yes) },
-	{
+	code_info__get_globals(!.CI, Globals),
+	globals__lookup_bool_option(Globals, static_ground_terms, yes),
+
 		% We want to generate a lookup switch for any switch
 		% that is dense enough - we don't care how many cases
 		% it has. A memory lookup tends to be cheaper than
@@ -120,88 +120,86 @@
 		Span = LastCaseVal - FirstCaseVal,
 		Range = Span + 1,
 		dense_switch__calc_density(NumCases, Range, Density),
-		Density > ReqDensity
-	},
+	Density > ReqDensity,
+
 	% If there are going to be no gaps in the lookup
 	% table then we won't need a bitvector test to see
 	% if this switch has a value for this case.
-	(
-		{ NumCases = Range }
-	->
-		{ NeedBitVecTest0 = cannot_fail }
+	( NumCases = Range ->
+		NeedBitVecTest0 = cannot_fail
 	;
-		{ NeedBitVecTest0 = can_fail }
+		NeedBitVecTest0 = can_fail
 	),
 	(
-		{ SwitchCanFail = can_fail },
+		SwitchCanFail = can_fail,
 		% For semidet switches, we normally need to check that
 		% the variable is in range before we index into the jump table.
 		% However, if the range of the type is sufficiently small,
 		% we can make the jump table large enough to hold all
 		% of the values for the type, but then we will need to do the
 		% bitvector test.
-		code_info__variable_type(CaseVar, Type),
-		code_info__get_module_info(ModuleInfo),
-		{ classify_type(ModuleInfo, Type) = TypeCategory },
+		Type = code_info__variable_type(!.CI, CaseVar),
+		code_info__get_module_info(!.CI, ModuleInfo),
+		classify_type(ModuleInfo, Type) = TypeCategory,
 		(
-			dense_switch__type_range(TypeCategory, Type,
+			dense_switch__type_range(!.CI, TypeCategory, Type,
 				TypeRange),
-			{ dense_switch__calc_density(NumCases, TypeRange,
-				DetDensity) },
-			{ DetDensity > ReqDensity }
+			dense_switch__calc_density(NumCases, TypeRange,
+				DetDensity),
+			DetDensity > ReqDensity
 		->
-			{ NeedRangeCheck = cannot_fail },
-			{ NeedBitVecTest = can_fail },
-			{ FirstVal = 0 },
-			{ LastVal = TypeRange - 1 }
-		;
-			{ NeedRangeCheck = SwitchCanFail },
-			{ NeedBitVecTest = NeedBitVecTest0 },
-			{ FirstVal = FirstCaseVal },
-			{ LastVal = LastCaseVal }
+			NeedRangeCheck = cannot_fail,
+			NeedBitVecTest = can_fail,
+			FirstVal = 0,
+			LastVal = TypeRange - 1
+		;
+			NeedRangeCheck = SwitchCanFail,
+			NeedBitVecTest = NeedBitVecTest0,
+			FirstVal = FirstCaseVal,
+			LastVal = LastCaseVal
 		)
 	;
-		{ SwitchCanFail = cannot_fail },
-		{ NeedRangeCheck = cannot_fail },
-		{ NeedBitVecTest = NeedBitVecTest0 },
-		{ FirstVal = FirstCaseVal },
-		{ LastVal = LastCaseVal }
+		SwitchCanFail = cannot_fail,
+		NeedRangeCheck = cannot_fail,
+		NeedBitVecTest = NeedBitVecTest0,
+		FirstVal = FirstCaseVal,
+		LastVal = LastCaseVal
 	),
-	lookup_switch__figure_out_output_vars(GoalInfo, OutVars),
+	lookup_switch__figure_out_output_vars(!.CI, GoalInfo, OutVars),
 	lookup_switch__generate_constants(TaggedCases, OutVars, StoreMap,
-		MaybeEnd0, MaybeEnd, CodeModel, CaseValues, MLiveness).
+		!MaybeEnd, CodeModel, CaseValues, MLiveness, !CI).
 
 %---------------------------------------------------------------------------%
 
-:- pred lookup_switch__figure_out_output_vars(hlds_goal_info::in,
-	list(prog_var)::out, code_info::in, code_info::out) is det.
+:- pred lookup_switch__figure_out_output_vars(code_info::in,
+	hlds_goal_info::in, list(prog_var)::out) is det.
 
 	% Figure out which variables are bound in the switch.
 	% We do this by using the current instmap and the instmap delta in
 	% the goal info to work out which variables are [further] bound by
 	% the switch.
 
-lookup_switch__figure_out_output_vars(GoalInfo, OutVars) -->
-	{ goal_info_get_instmap_delta(GoalInfo, InstMapDelta) },
+lookup_switch__figure_out_output_vars(CI, GoalInfo, OutVars) :-
+	goal_info_get_instmap_delta(GoalInfo, InstMapDelta),
 	(
-		{ instmap_delta_is_unreachable(InstMapDelta) }
+		instmap_delta_is_unreachable(InstMapDelta)
 	->
-		{ OutVars = [] }
+		OutVars = []
 	;
-		code_info__get_instmap(CurrentInstMap),
-		code_info__get_module_info(ModuleInfo),
-		{ instmap_delta_changed_vars(InstMapDelta, ChangedVars) },
-		{ instmap__apply_instmap_delta(CurrentInstMap, InstMapDelta,
-			InstMapAfter) },
-		{ Lambda = lambda([Var::out] is nondet, (
+		code_info__get_instmap(CI, CurrentInstMap),
+		code_info__get_module_info(CI, ModuleInfo),
+		instmap_delta_changed_vars(InstMapDelta, ChangedVars),
+		instmap__apply_instmap_delta(CurrentInstMap, InstMapDelta,
+			InstMapAfter),
+		Lambda = (pred(Var::out) is nondet :-
 			% If a variable has a final inst, then it changed
 			% instantiatedness during the switch.
 			set__member(Var, ChangedVars),
 			instmap__lookup_var(CurrentInstMap, Var, Initial),
 			instmap__lookup_var(InstMapAfter, Var, Final),
 			mode_is_output(ModuleInfo, (Initial -> Final))
-		)) },
-		{ solutions(Lambda, OutVars) }
+		),
+		solutions(Lambda, OutVars)
 	).
 
 %---------------------------------------------------------------------------%
@@ -214,42 +212,40 @@
 	% To figure out if the outputs are constants, we generate code for
 	% the cases, and check to see if each of the output vars is a constant,
 	% and that no actual code was generated for the goal.
-lookup_switch__generate_constants([], _Vars, _StoreMap, MaybeEnd, MaybeEnd,
-		_CodeModel, [], no) --> [].
+lookup_switch__generate_constants([], _Vars, _StoreMap, !MaybeEnd,
+		_CodeModel, [], no, !CI).
 lookup_switch__generate_constants([Case | Cases], Vars, StoreMap,
-		MaybeEnd0, MaybeEnd, CodeModel,
-		[CaseVal | Rest], yes(Liveness)) -->
-	{ Case = case(_, int_constant(CaseTag), _, Goal) },
-	code_info__remember_position(BranchStart),
-	code_gen__generate_goal(CodeModel, Goal, Code),
-	{ tree__tree_of_lists_is_empty(Code) },
-	code_info__get_forward_live_vars(Liveness),
-	lookup_switch__get_case_rvals(Vars, CaseRvals),
-	{ CaseVal = CaseTag - CaseRvals },
+		!MaybeEnd, CodeModel, [CaseVal | Rest], yes(Liveness), !CI) :-
+	Case = case(_, int_constant(CaseTag), _, Goal),
+	code_info__remember_position(!.CI, BranchStart),
+	code_gen__generate_goal(CodeModel, Goal, Code, !CI),
+	tree__tree_of_lists_is_empty(Code),
+	code_info__get_forward_live_vars(!.CI, Liveness),
+	lookup_switch__get_case_rvals(Vars, CaseRvals, !CI),
+	CaseVal = CaseTag - CaseRvals,
 		% EndCode code may contain instructions that place Vars
 		% in the locations dictated by StoreMap, and thus does not have
 		% to be empty. (The array lookup code will put those variables
 		% in those locations directly.)
-	code_info__generate_branch_end(StoreMap, MaybeEnd0, MaybeEnd1,
-		_EndCode),
-	code_info__reset_to_position(BranchStart),
-	lookup_switch__generate_constants(Cases, Vars, StoreMap,
-		MaybeEnd1, MaybeEnd, CodeModel, Rest, _).
+	code_info__generate_branch_end(StoreMap, !MaybeEnd, _EndCode, !CI),
+	code_info__reset_to_position(BranchStart, !CI),
+	lookup_switch__generate_constants(Cases, Vars, StoreMap, !MaybeEnd,
+		CodeModel, Rest, _, !CI).
 
 %---------------------------------------------------------------------------%
 
 :- pred lookup_switch__get_case_rvals(list(prog_var)::in, list(rval)::out,
 	code_info::in, code_info::out) is semidet.
 
-lookup_switch__get_case_rvals([], []) --> [].
-lookup_switch__get_case_rvals([Var | Vars], [Rval | Rvals]) -->
-	code_info__produce_variable(Var, Code, Rval),
-	{ tree__tree_of_lists_is_empty(Code) },
-	code_info__get_globals(Globals),
-	{ globals__get_options(Globals, Options) },
-	{ exprn_aux__init_exprn_opts(Options, ExprnOpts) },
-	{ lookup_switch__rval_is_constant(Rval, ExprnOpts) },
-	lookup_switch__get_case_rvals(Vars, Rvals).
+lookup_switch__get_case_rvals([], [], !CI).
+lookup_switch__get_case_rvals([Var | Vars], [Rval | Rvals], !CI) :-
+	code_info__produce_variable(Var, Code, Rval, !CI),
+	tree__tree_of_lists_is_empty(Code),
+	code_info__get_globals(!.CI, Globals),
+	globals__get_options(Globals, Options),
+	exprn_aux__init_exprn_opts(Options, ExprnOpts),
+	lookup_switch__rval_is_constant(Rval, ExprnOpts),
+	lookup_switch__get_case_rvals(Vars, Rvals, !CI).
 
 %---------------------------------------------------------------------------%
 
@@ -281,62 +277,62 @@
 
 lookup_switch__generate(Var, OutVars, CaseValues,
 		StartVal, EndVal, NeedRangeCheck, NeedBitVecCheck,
-		MLiveness, StoreMap, MaybeEnd0, Code) -->
+		MLiveness, StoreMap, MaybeEnd0, Code, !CI) :-
 
 		% Evaluate the variable which we are going to be switching on.
-	code_info__produce_variable(Var, VarCode, Rval),
+	code_info__produce_variable(Var, VarCode, Rval, !CI),
 		% If the case values start at some number other than 0,
 		% then subtract that number to give us a zero-based index.
-	{ StartVal = 0 ->
+	( StartVal = 0 ->
 		Index = Rval
 	;
 		Index = binop(-, Rval, const(int_const(StartVal)))
-	},
+	),
 		% If the switch is not locally deterministic, we need to
 		% check that the value of the variable lies within the
 		% appropriate range.
 	(
-		{ NeedRangeCheck = can_fail },
-		{ Difference = EndVal - StartVal },
+		NeedRangeCheck = can_fail,
+		Difference = EndVal - StartVal,
 		code_info__fail_if_rval_is_false(
 			binop(unsigned_le, Index,
-				const(int_const(Difference))), RangeCheck)
+				const(int_const(Difference))), RangeCheck, !CI)
 	;
-		{ NeedRangeCheck = cannot_fail },
-		{ RangeCheck = empty }
+		NeedRangeCheck = cannot_fail,
+		RangeCheck = empty
 	),
 	(
-		{ NeedBitVecCheck = can_fail },
+		NeedBitVecCheck = can_fail,
 		lookup_switch__generate_bitvec_test(Index, CaseValues,
-			StartVal, EndVal, CheckBitVec)
+			StartVal, EndVal, CheckBitVec, !CI)
 	;
-		{ NeedBitVecCheck = cannot_fail },
-		{ CheckBitVec = empty }
+		NeedBitVecCheck = cannot_fail,
+		CheckBitVec = empty
 	),
 		% Now generate the terms into which we do the lookups
-	lookup_switch__generate_terms(Index, OutVars, CaseValues, StartVal),
+	lookup_switch__generate_terms(Index, OutVars, CaseValues, StartVal,
+		!CI),
 		% We keep track of what variables are supposed to be
 		% live at the end of cases. We have to do this explicitly
 		% because generating a `fail' slot last would yield the
 		% wrong liveness.
 	(
-		{ MLiveness = yes(Liveness) },
-		code_info__set_forward_live_vars(Liveness)
+		MLiveness = yes(Liveness),
+		code_info__set_forward_live_vars(Liveness, !CI)
 	;
-		{ MLiveness = no },
-		{ error("lookup_switch__generate: no liveness!") }
+		MLiveness = no,
+		error("lookup_switch__generate: no liveness!")
 	),
 	code_info__generate_branch_end(StoreMap, MaybeEnd0, _MaybeEnd,
-		LookupCode),
+		LookupCode, !CI),
 		% Assemble to code together
-	{ Comment = node([comment("lookup switch") - ""]) },
-	{ Code =
+	Comment = node([comment("lookup switch") - ""]),
+	Code =
 		tree(Comment,
 		tree(VarCode,
 		tree(RangeCheck,
 		tree(CheckBitVec,
-		     LookupCode))))
-	}.
+		     LookupCode)))).
 
 %------------------------------------------------------------------------------%
 
@@ -349,9 +345,10 @@
 	% the (range checked) input to the lookup switch. The bit is `1'
 	% iff we have a case for that tag value.
 lookup_switch__generate_bitvec_test(Index, CaseVals, Start, _End,
-		CheckCode) -->
-	lookup_switch__get_word_bits(WordBits, Log2WordBits),
-	generate_bit_vec(CaseVals, Start, WordBits, BitVecArgs, BitVecRval),
+		CheckCode, !CI) :-
+	lookup_switch__get_word_bits(!.CI, WordBits, Log2WordBits),
+	generate_bit_vec(CaseVals, Start, WordBits, BitVecArgs, BitVecRval,
+		!CI),
 
 		%
 		% Optimize the single-word case:
@@ -361,7 +358,7 @@
 		% of the index specify which word to use and the
 		% low bits specify which bit.
 		%
-	{ BitVecArgs = [SingleWord] ->
+	( BitVecArgs = [SingleWord] ->
 		Word = SingleWord,
 		BitNum = Index
 	;
@@ -376,14 +373,13 @@
 		% BitNum = binop(mod, Index, const(int_const(WordBits)))
 		% except that it can generate more efficient code.
 		BitNum = binop(&, Index, const(int_const(WordBits - 1)))
-	},
-	{ HasBit = binop((&),
+	),
+	HasBit = binop((&),
 			binop((<<), const(int_const(1)), BitNum),
-			Word) },
-	code_info__fail_if_rval_is_false(HasBit, CheckCode).
+			Word),
+	code_info__fail_if_rval_is_false(HasBit, CheckCode, !CI).
 
-:- pred lookup_switch__get_word_bits(int::out, int::out,
-	code_info::in, code_info::out) is det.
+:- pred lookup_switch__get_word_bits(code_info::in, int::out, int::out) is det.
 
 	% Prevent cross-compilation errors by making sure that
 	% the bitvector uses a number of bits that will fit both
@@ -393,16 +389,17 @@
 	% we use is a power of 2, so that we implement division as
 	% right-shift (see above).
 
-lookup_switch__get_word_bits(WordBits, Log2WordBits) -->
-	{ int__bits_per_int(HostWordBits) },
-	code_info__get_globals(Globals),
-	{ globals__lookup_int_option(Globals, bits_per_word, TargetWordBits) },
-	{ int__min(HostWordBits, TargetWordBits, WordBits0) },
+lookup_switch__get_word_bits(CI, WordBits, Log2WordBits) :-
+	int__bits_per_int(HostWordBits),
+	code_info__get_globals(CI, Globals),
+	globals__lookup_int_option(Globals, bits_per_word, TargetWordBits),
+	int__min(HostWordBits, TargetWordBits, WordBits0),
 	% round down to the nearest power of 2
-	{ Log2WordBits = log2_rounded_down(WordBits0) },
-	{ int__pow(2, Log2WordBits, WordBits) }.
+	Log2WordBits = log2_rounded_down(WordBits0),
+	int__pow(2, Log2WordBits, WordBits).
 
 :- func log2_rounded_down(int) = int.
+
 log2_rounded_down(X) = Log :-
 	int__log2(X + 1, Log + 1).  % int__log2 rounds up
 
@@ -413,12 +410,12 @@
 	% marking the bit for each case. (We represent the bitvector
 	% here as a map from the word number in the vector to the bits
 	% for that word.
-generate_bit_vec(CaseVals, Start, WordBits, Args, BitVec, !CodeInfo) :-
+generate_bit_vec(CaseVals, Start, WordBits, Args, BitVec, !CI) :-
 	map__init(Empty),
 	generate_bit_vec_2(CaseVals, Start, WordBits, Empty, BitMap),
 	map__to_assoc_list(BitMap, WordVals),
 	generate_bit_vec_args(WordVals, 0, Args),
-	add_static_cell_natural_types(Args, DataAddr, !CodeInfo),
+	add_static_cell_natural_types(Args, DataAddr, !CI),
 	BitVec = const(data_addr_const(DataAddr, no)).
 
 :- pred generate_bit_vec_2(case_consts::in, int::in, int::in,
@@ -464,26 +461,26 @@
 	% array, and caching an expression for the variable to get the
 	% Index'th field of that term.
 
-lookup_switch__generate_terms(Index, OutVars, CaseVals, Start) -->
-	{ map__init(Empty) },
-	{ rearrange_vals(OutVars, CaseVals, Start, Empty, ValMap) },
-	lookup_switch__generate_terms_2(Index, OutVars, ValMap).
+lookup_switch__generate_terms(Index, OutVars, CaseVals, Start, !CI) :-
+	map__init(Empty),
+	rearrange_vals(OutVars, CaseVals, Start, Empty, ValMap),
+	lookup_switch__generate_terms_2(Index, OutVars, ValMap, !CI).
 
 :- pred lookup_switch__generate_terms_2(rval::in, list(prog_var)::in,
 	rval_map::in, code_info::in, code_info::out) is det.
 
-lookup_switch__generate_terms_2(_Index, [], _Map) --> [].
-lookup_switch__generate_terms_2(Index, [Var | Vars], Map) -->
-	{ map__lookup(Map, Var, Vals0) },
-	{ list__sort(Vals0, Vals) },
-	{ construct_args(Vals, 0, Args) },
-	code_info__add_static_cell_natural_types(Args, DataAddr),
-	{ ArrayTerm = const(data_addr_const(DataAddr, no)) },
-	{ LookupLval = field(yes(0), ArrayTerm, Index) },
-	code_info__assign_lval_to_var(Var, LookupLval, Code),
-	{ require(tree__is_empty(Code),
-		"lookup_switch__generate_terms_2: nonempty code") },
-	lookup_switch__generate_terms_2(Index, Vars, Map).
+lookup_switch__generate_terms_2(_Index, [], _Map, !CI).
+lookup_switch__generate_terms_2(Index, [Var | Vars], Map, !CI) :-
+	map__lookup(Map, Var, Vals0),
+	list__sort(Vals0, Vals),
+	construct_args(Vals, 0, Args),
+	code_info__add_static_cell_natural_types(Args, DataAddr, !CI),
+	ArrayTerm = const(data_addr_const(DataAddr, no)),
+	LookupLval = field(yes(0), ArrayTerm, Index),
+	code_info__assign_lval_to_var(Var, LookupLval, Code, !CI),
+	require(tree__is_empty(Code),
+		"lookup_switch__generate_terms_2: nonempty code"),
+	lookup_switch__generate_terms_2(Index, Vars, Map, !CI).
 
 :- pred construct_args(list(pair(int, rval))::in, int::in, list(rval)::out)
 	is det.
Index: middle_rec.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/middle_rec.m,v
retrieving revision 1.96
diff -u -b -r1.96 middle_rec.m
--- middle_rec.m	20 Oct 2003 07:29:08 -0000	1.96
+++ middle_rec.m	22 Oct 2003 06:44:59 -0000
@@ -47,7 +47,7 @@
 
 %---------------------------------------------------------------------------%
 
-middle_rec__match_and_generate(Goal, Instrs, CodeInfo0, CodeInfo) :-
+middle_rec__match_and_generate(Goal, Instrs, !CI) :-
 	Goal = GoalExpr - GoalInfo,
 	(
 		GoalExpr = switch(Var, cannot_fail, [Case1, Case2]),
@@ -56,17 +56,17 @@
 		(
 			contains_only_builtins(Goal1),
 			code_aux__contains_simple_recursive_call(Goal2,
-				CodeInfo0, _)
+				!.CI, _)
 		->
 			middle_rec__generate_switch(Var, ConsId1, Goal1, Goal2,
-				GoalInfo, Instrs, CodeInfo0, CodeInfo)
+				GoalInfo, Instrs, !CI)
 		;
 			contains_only_builtins(Goal2),
 			code_aux__contains_simple_recursive_call(Goal1,
-				CodeInfo0, _)
+				!.CI, _)
 		->
 			middle_rec__generate_switch(Var, ConsId2, Goal2, Goal1,
-				GoalInfo, Instrs, CodeInfo0, CodeInfo)
+				GoalInfo, Instrs, !CI)
 		;
 			fail
 		)
@@ -75,23 +75,21 @@
 		(
 			contains_only_builtins(Cond),
 			contains_only_builtins(Then),
-			code_aux__contains_simple_recursive_call(Else,
-				CodeInfo0, no)
+			code_aux__contains_simple_recursive_call(Else, !.CI,
+				no)
 		->
 			semidet_fail,
 			middle_rec__generate_ite(Vars, Cond, Then, Else,
-				in_else, GoalInfo, Instrs,
-				CodeInfo0, CodeInfo)
+				in_else, GoalInfo, Instrs, !CI)
 		;
 			contains_only_builtins(Cond),
-			code_aux__contains_simple_recursive_call(Then,
-				CodeInfo0, no),
+			code_aux__contains_simple_recursive_call(Then, !.CI,
+				no),
 			contains_only_builtins(Else)
 		->
 			semidet_fail,
 			middle_rec__generate_ite(Vars, Cond, Then, Else,
-				in_then, GoalInfo, Instrs,
-				CodeInfo0, CodeInfo)
+				in_then, GoalInfo, Instrs, !CI)
 		;
 			fail
 		)
@@ -101,92 +99,89 @@
 
 %---------------------------------------------------------------------------%
 
-:- pred middle_rec__generate_ite(list(prog_var), hlds_goal, hlds_goal,
-	hlds_goal, ite_rec, hlds_goal_info,
-	code_tree, code_info, code_info).
-:- mode middle_rec__generate_ite(in, in, in, in, in, in, out, in, out)
-	is det.
+:- pred middle_rec__generate_ite(list(prog_var)::in, hlds_goal::in,
+	hlds_goal::in, hlds_goal::in, ite_rec::in, hlds_goal_info::in,
+	code_tree::out, code_info::in, code_info::out) is det.
 
 middle_rec__generate_ite(_Vars, _Cond, _Then, _Else, _Rec, _IteGoalInfo,
-		Instrs) -->
-	( { semidet_fail } ->
-		{ Instrs = empty }
+		Instrs, !CI) :-
+	( semidet_fail ->
+		Instrs = empty
 	;
-		{ error("middle_rec__generate_ite reached") }
+		error("middle_rec__generate_ite reached")
 	).
 
 %---------------------------------------------------------------------------%
 
-:- pred middle_rec__generate_switch(prog_var, cons_id, hlds_goal, hlds_goal,
-	hlds_goal_info, code_tree, code_info, code_info).
-:- mode middle_rec__generate_switch(in, in, in, in, in, out, in, out)
-	is semidet.
+:- pred middle_rec__generate_switch(prog_var::in, cons_id::in, hlds_goal::in,
+	hlds_goal::in, hlds_goal_info::in, code_tree::out,
+	code_info::in, code_info::out) is semidet.
 
 middle_rec__generate_switch(Var, BaseConsId, Base, Recursive, SwitchGoalInfo,
-		Instrs) -->
-	code_info__get_stack_slots(StackSlots),
-	code_info__get_varset(VarSet),
-	{ code_aux__explain_stack_slots(StackSlots, VarSet, SlotsComment) },
-	code_info__get_module_info(ModuleInfo),
-	code_info__get_pred_id(PredId),
-	code_info__get_proc_id(ProcId),
-	{ code_util__make_local_entry_label(ModuleInfo, PredId, ProcId, no,
-		EntryLabel) },
+		Instrs, !CI) :-
+	code_info__get_stack_slots(!.CI, StackSlots),
+	code_info__get_varset(!.CI, VarSet),
+	code_aux__explain_stack_slots(StackSlots, VarSet, SlotsComment),
+	code_info__get_module_info(!.CI, ModuleInfo),
+	code_info__get_pred_id(!.CI, PredId),
+	code_info__get_proc_id(!.CI, ProcId),
+	code_util__make_local_entry_label(ModuleInfo, PredId, ProcId, no,
+		EntryLabel),
 
-	code_info__pre_goal_update(SwitchGoalInfo, no),
+	code_info__pre_goal_update(SwitchGoalInfo, no, !CI),
 	unify_gen__generate_tag_test(Var, BaseConsId, branch_on_success,
-		BaseLabel, EntryTestCode),
-	{ tree__flatten(EntryTestCode, EntryTestListList) },
-	{ list__condense(EntryTestListList, EntryTestList) },
-
-	{ goal_info_get_store_map(SwitchGoalInfo, StoreMap) },
-	code_info__remember_position(BranchStart),
-	code_gen__generate_goal(model_det, Base, BaseGoalCode),
+		BaseLabel, EntryTestCode, !CI),
+	tree__flatten(EntryTestCode, EntryTestListList),
+	list__condense(EntryTestListList, EntryTestList),
+
+	goal_info_get_store_map(SwitchGoalInfo, StoreMap),
+	code_info__remember_position(!.CI, BranchStart),
+	code_gen__generate_goal(model_det, Base, BaseGoalCode, !CI),
 	code_info__generate_branch_end(StoreMap, no, MaybeEnd1,
-		BaseSaveCode),
-	code_info__reset_to_position(BranchStart),
-	code_gen__generate_goal(model_det, Recursive, RecGoalCode),
+		BaseSaveCode, !CI),
+	code_info__reset_to_position(BranchStart, !CI),
+	code_gen__generate_goal(model_det, Recursive, RecGoalCode, !CI),
 	code_info__generate_branch_end(StoreMap, MaybeEnd1, MaybeEnd,
-		RecSaveCode),
+		RecSaveCode, !CI),
 
-	code_info__post_goal_update(SwitchGoalInfo),
-	code_info__after_all_branches(StoreMap, MaybeEnd),
+	code_info__post_goal_update(SwitchGoalInfo, !CI),
+	code_info__after_all_branches(StoreMap, MaybeEnd, !CI),
 
-	code_info__get_arginfo(ArgModes),
-	code_info__get_headvars(HeadVars),
-	{ assoc_list__from_corresponding_lists(HeadVars, ArgModes, Args) },
-	code_info__setup_return(Args, LiveArgs, EpilogCode),
-
-	{ BaseCode = tree(BaseGoalCode, tree(BaseSaveCode, EpilogCode)) },
-	{ RecCode = tree(RecGoalCode, tree(RecSaveCode, EpilogCode)) },
-	{ LiveValCode = [livevals(LiveArgs) - ""] },
-
-	{ tree__flatten(BaseCode, BaseListList) },
-	{ list__condense(BaseListList, BaseList) },
-	{ tree__flatten(RecCode, RecListList) },
-	{ list__condense(RecListList, RecList) },
+	ArgModes = code_info__get_arginfo(!.CI),
+	HeadVars = code_info__get_headvars(!.CI),
+	assoc_list__from_corresponding_lists(HeadVars, ArgModes, Args),
+	code_info__setup_return(Args, LiveArgs, EpilogCode, !CI),
+
+	BaseCode = tree(BaseGoalCode, tree(BaseSaveCode, EpilogCode)),
+	RecCode = tree(RecGoalCode, tree(RecSaveCode, EpilogCode)),
+	LiveValCode = [livevals(LiveArgs) - ""],
+
+	tree__flatten(BaseCode, BaseListList),
+	list__condense(BaseListList, BaseList),
+	tree__flatten(RecCode, RecListList),
+	list__condense(RecListList, RecList),
 
 	% In the code we generate, the base instruction sequence is executed
 	% in situations where this procedure has no stack frame. If this
 	% sequence refers to stackvars, it will be to some other procedure's
 	% variables, which is obviously incorrect.
-	{ opt_util__block_refers_stackvars(BaseList, no) },
+	opt_util__block_refers_stackvars(BaseList, no),
 
-	{ list__append(BaseList, RecList, AvoidList) },
-	{ middle_rec__find_unused_register(AvoidList, AuxReg) },
+	list__append(BaseList, RecList, AvoidList),
+	middle_rec__find_unused_register(AvoidList, AuxReg),
 
-	{ middle_rec__split_rec_code(RecList, BeforeList0, AfterList) },
-	{ middle_rec__add_counter_to_livevals(BeforeList0, AuxReg,
-		BeforeList) },
+	middle_rec__split_rec_code(RecList, BeforeList0, AfterList),
+	middle_rec__add_counter_to_livevals(BeforeList0, AuxReg,
+		BeforeList),
 
-	code_info__get_next_label(Loop1Label),
-	code_info__get_next_label(Loop2Label),
-	code_info__get_total_stackslot_count(FrameSize),
+	code_info__get_next_label(Loop1Label, !CI),
+	code_info__get_next_label(Loop2Label, !CI),
+	code_info__get_total_stackslot_count(!.CI, FrameSize),
 
-	{ middle_rec__generate_downloop_test(EntryTestList,
-		Loop1Label, Loop1Test) },
+	middle_rec__generate_downloop_test(EntryTestList,
+		Loop1Label, Loop1Test),
 
-	{ FrameSize = 0 ->
+	( FrameSize = 0 ->
 		MaybeIncrSp = [],
 		MaybeDecrSp = [],
 		InitAuxReg = [assign(AuxReg, const(int_const(0)))
@@ -215,7 +210,7 @@
 				lval(sp), lval(AuxReg)),
 				label(Loop2Label))
 				- "test on upward loop"]
-	},
+	),
 
 	% Even though the recursive call is followed by some goals
 	% in the HLDS, these goals may generate no LLDS code, so
@@ -223,7 +218,8 @@
 	% There is no point in testing BeforeList for empty,
 	% since if it is, the code is an infinite loop anyway.
 
-	{ AfterList = [] ->
+	(
+		AfterList = [],
 		list__condense([
 			[
 				label(EntryLabel) - "Procedure entry point",
@@ -248,6 +244,7 @@
 			]
 		], InstrList)
 	;
+		AfterList = [_ | _],
 		% The instruction list we are constructing has two copies
 		% of BaseList. If this list of instructions defines any
 		% labels, we must either not apply this version of the
@@ -294,8 +291,8 @@
 				- "exit from base case"
 			]
 		], InstrList)
-	},
-	{ Instrs = node(InstrList) }.
+	),
+	Instrs = node(InstrList).
 
 %---------------------------------------------------------------------------%
 %---------------------------------------------------------------------------%
@@ -311,10 +308,12 @@
 		( Instrs0 = [] ->
 			true
 		;
-			error("middle_rec__generate_downloop_test: if_val followed by other instructions")
+			error("middle_rec__generate_downloop_test: " ++
+				"if_val followed by other instructions")
 		),
 		code_util__neg_rval(Test, NewTest),
-		Instrs = [if_val(NewTest, label(Target)) - "test on downward loop"]
+		Instrs = [if_val(NewTest, label(Target))
+			- "test on downward loop"]
 	;
 		middle_rec__generate_downloop_test(Instrs0, Target, Instrs1),
 		Instrs = [Instr0 | Instrs1]
@@ -338,7 +337,8 @@
 			Before = [],
 			After = Instrs3
 		;
-			error("call not followed by label in middle_rec__split_rec_code")
+			error("middle_rec__split_rec_code: " ++
+				"call not followed by label")
 		)
 	;
 		middle_rec__split_rec_code(Instrs1, Before1, After),
@@ -347,9 +347,8 @@
 
 %---------------------------------------------------------------------------%
 
-:- pred middle_rec__add_counter_to_livevals(list(instruction), lval,
-						list(instruction)).
-:- mode middle_rec__add_counter_to_livevals(in, in, out) is det.
+:- pred middle_rec__add_counter_to_livevals(list(instruction)::in, lval::in,
+	list(instruction)::out) is det.
 
 middle_rec__add_counter_to_livevals([], _Lval, []).
 middle_rec__add_counter_to_livevals([I0|Is0], Lval, [I|Is]) :-
@@ -365,8 +364,8 @@
 
 %---------------------------------------------------------------------------%
 
-:- pred middle_rec__find_unused_register(list(instruction), lval).
-:- mode middle_rec__find_unused_register(in, out) is det.
+:- pred middle_rec__find_unused_register(list(instruction)::in, lval::out)
+	is det.
 
 middle_rec__find_unused_register(Instrs, UnusedReg) :-
 	set__init(Used0),
@@ -374,8 +373,8 @@
 	set__to_sorted_list(Used1, UsedList),
 	middle_rec__find_unused_register_2(UsedList, 1, UnusedReg).
 
-:- pred middle_rec__find_unused_register_2(list(int), int, lval).
-:- mode middle_rec__find_unused_register_2(in, in, out) is det.
+:- pred middle_rec__find_unused_register_2(list(int)::in, int::in, lval::out)
+	is det.
 
 middle_rec__find_unused_register_2([], N, reg(r, N)).
 middle_rec__find_unused_register_2([H | T], N, Reg) :-
@@ -386,16 +385,16 @@
 		middle_rec__find_unused_register_2(T, N1, Reg)
 	).
 
-:- pred middle_rec__find_used_registers(list(instruction), set(int), set(int)).
-:- mode middle_rec__find_used_registers(in, di, uo) is det.
+:- pred middle_rec__find_used_registers(list(instruction)::in,
+	set(int)::di, set(int)::uo) is det.
 
-middle_rec__find_used_registers([], Used, Used).
-middle_rec__find_used_registers([Instr - _ | Instrs], Used0, Used) :-
-	middle_rec__find_used_registers_instr(Instr, Used0, Used1),
-	middle_rec__find_used_registers(Instrs, Used1, Used).
+middle_rec__find_used_registers([], !Used).
+middle_rec__find_used_registers([Instr - _ | Instrs], !Used) :-
+	middle_rec__find_used_registers_instr(Instr, !Used),
+	middle_rec__find_used_registers(Instrs, !Used).
 
-:- pred middle_rec__find_used_registers_instr(instr, set(int), set(int)).
-:- mode middle_rec__find_used_registers_instr(in, di, uo) is det.
+:- pred middle_rec__find_used_registers_instr(instr::in,
+	set(int)::di, set(int)::uo) is det.
 
 middle_rec__find_used_registers_instr(comment(_), !Used).
 middle_rec__find_used_registers_instr(livevals(LvalSet), !Used) :-
@@ -447,144 +446,137 @@
 middle_rec__find_used_registers_instr(join_and_continue(Lval,_), !Used) :-
 	middle_rec__find_used_registers_lval(Lval, !Used).
 
-:- pred middle_rec__find_used_registers_components(list(pragma_c_component),
-	set(int), set(int)).
-:- mode middle_rec__find_used_registers_components(in, di, uo) is det.
-
-middle_rec__find_used_registers_components([], Used, Used).
-middle_rec__find_used_registers_components([Comp | Comps], Used0, Used) :-
-	middle_rec__find_used_registers_component(Comp, Used0, Used1),
-	middle_rec__find_used_registers_components(Comps, Used1, Used).
-
-:- pred middle_rec__find_used_registers_component(pragma_c_component,
-	set(int), set(int)).
-:- mode middle_rec__find_used_registers_component(in, di, uo) is det.
-
-middle_rec__find_used_registers_component(pragma_c_inputs(In), Used0, Used) :-
-	insert_pragma_c_input_registers(In, Used0, Used).
-middle_rec__find_used_registers_component(pragma_c_outputs(Out), Used0, Used) :-
-	insert_pragma_c_output_registers(Out, Used0, Used).
-middle_rec__find_used_registers_component(pragma_c_user_code(_, _), Used, Used).
-middle_rec__find_used_registers_component(pragma_c_raw_code(_, _), Used, Used).
-middle_rec__find_used_registers_component(pragma_c_fail_to(_), Used, Used).
-middle_rec__find_used_registers_component(pragma_c_noop, Used, Used).
-
-:- pred middle_rec__find_used_registers_lvals(list(lval), set(int), set(int)).
-:- mode middle_rec__find_used_registers_lvals(in, di, uo) is det.
-
-middle_rec__find_used_registers_lvals([], Used, Used).
-middle_rec__find_used_registers_lvals([Lval | Lvals], Used0, Used) :-
-	middle_rec__find_used_registers_lval(Lval, Used0, Used1),
-	middle_rec__find_used_registers_lvals(Lvals, Used1, Used).
+:- pred middle_rec__find_used_registers_components(
+	list(pragma_c_component)::in,
+	set(int)::di, set(int)::uo) is det.
+
+middle_rec__find_used_registers_components([], !Used).
+middle_rec__find_used_registers_components([Comp | Comps], !Used) :-
+	middle_rec__find_used_registers_component(Comp, !Used),
+	middle_rec__find_used_registers_components(Comps, !Used).
+
+:- pred middle_rec__find_used_registers_component(pragma_c_component::in,
+	set(int)::di, set(int)::uo) is det.
+
+middle_rec__find_used_registers_component(pragma_c_inputs(In), !Used) :-
+	insert_pragma_c_input_registers(In, !Used).
+middle_rec__find_used_registers_component(pragma_c_outputs(Out), !Used) :-
+	insert_pragma_c_output_registers(Out, !Used).
+middle_rec__find_used_registers_component(pragma_c_user_code(_, _), !Used).
+middle_rec__find_used_registers_component(pragma_c_raw_code(_, _), !Used).
+middle_rec__find_used_registers_component(pragma_c_fail_to(_), !Used).
+middle_rec__find_used_registers_component(pragma_c_noop, !Used).
+
+:- pred middle_rec__find_used_registers_lvals(list(lval)::in,
+	set(int)::di, set(int)::uo) is det.
 
-:- pred middle_rec__find_used_registers_lval(lval, set(int), set(int)).
-:- mode middle_rec__find_used_registers_lval(in, di, uo) is det.
+middle_rec__find_used_registers_lvals([], !Used).
+middle_rec__find_used_registers_lvals([Lval | Lvals], !Used) :-
+	middle_rec__find_used_registers_lval(Lval, !Used),
+	middle_rec__find_used_registers_lvals(Lvals, !Used).
+
+:- pred middle_rec__find_used_registers_lval(lval::in,
+	set(int)::di, set(int)::uo) is det.
 
-middle_rec__find_used_registers_lval(Lval, Used0, Used) :-
+middle_rec__find_used_registers_lval(Lval, !Used) :-
 	( Lval = reg(r, N) ->
 		copy(N, N1),
-		set__insert(Used0, N1, Used)
+		set__insert(!.Used, N1, !:Used)
 	; Lval = field(_, Rval, FieldNum) ->
-		middle_rec__find_used_registers_rval(Rval, Used0, Used1),
-		middle_rec__find_used_registers_rval(FieldNum, Used1, Used)
+		middle_rec__find_used_registers_rval(Rval, !Used),
+		middle_rec__find_used_registers_rval(FieldNum, !Used)
 	; Lval = lvar(_) ->
 		error("lvar found in middle_rec__find_used_registers_lval")
 	;
-		Used = Used0
+		true
 	).
 
-:- pred middle_rec__find_used_registers_rval(rval, set(int), set(int)).
-:- mode middle_rec__find_used_registers_rval(in, di, uo) is det.
+:- pred middle_rec__find_used_registers_rval(rval::in,
+	set(int)::di, set(int)::uo) is det.
 
-middle_rec__find_used_registers_rval(Rval, Used0, Used) :-
+middle_rec__find_used_registers_rval(Rval, !Used) :-
 	(
 		Rval = lval(Lval),
-		middle_rec__find_used_registers_lval(Lval, Used0, Used)
+		middle_rec__find_used_registers_lval(Lval, !Used)
 	;
 		Rval = var(_),
 		error("var found in middle_rec__find_used_registers_rval")
 	;
 		Rval = mkword(_, Rval1),
-		middle_rec__find_used_registers_rval(Rval1, Used0, Used)
+		middle_rec__find_used_registers_rval(Rval1, !Used)
 	;
-		Rval = const(_),
-		Used = Used0
+		Rval = const(_)
 	;
 		Rval = unop(_, Rval1),
-		middle_rec__find_used_registers_rval(Rval1, Used0, Used)
+		middle_rec__find_used_registers_rval(Rval1, !Used)
 	;
 		Rval = binop(_, Rval1, Rval2),
-		middle_rec__find_used_registers_rval(Rval1, Used0, Used1),
-		middle_rec__find_used_registers_rval(Rval2, Used1, Used)
+		middle_rec__find_used_registers_rval(Rval1, !Used),
+		middle_rec__find_used_registers_rval(Rval2, !Used)
 	;
 		Rval = mem_addr(MemRef),
-		middle_rec__find_used_registers_mem_ref(MemRef, Used0, Used)
+		middle_rec__find_used_registers_mem_ref(MemRef, !Used)
 	).
 
-:- pred middle_rec__find_used_registers_mem_ref(mem_ref, set(int), set(int)).
-:- mode middle_rec__find_used_registers_mem_ref(in, di, uo) is det.
+:- pred middle_rec__find_used_registers_mem_ref(mem_ref::in,
+	set(int)::di, set(int)::uo) is det.
+
+middle_rec__find_used_registers_mem_ref(stackvar_ref(_), !Used).
+middle_rec__find_used_registers_mem_ref(framevar_ref(_), !Used).
+middle_rec__find_used_registers_mem_ref(heap_ref(Rval, _, _), !Used) :-
+	middle_rec__find_used_registers_rval(Rval, !Used).
 
-middle_rec__find_used_registers_mem_ref(stackvar_ref(_), Used, Used).
-middle_rec__find_used_registers_mem_ref(framevar_ref(_), Used, Used).
-middle_rec__find_used_registers_mem_ref(heap_ref(Rval, _, _), Used0, Used) :-
-	middle_rec__find_used_registers_rval(Rval, Used0, Used).
-
-:- pred middle_rec__find_used_registers_maybe_rvals(list(maybe(rval)),
-	set(int), set(int)).
-:- mode middle_rec__find_used_registers_maybe_rvals(in, di, uo) is det.
-
-middle_rec__find_used_registers_maybe_rvals([], Used, Used).
-middle_rec__find_used_registers_maybe_rvals([MaybeRval | MaybeRvals],
-		Used0, Used) :-
+:- pred middle_rec__find_used_registers_maybe_rvals(list(maybe(rval))::in,
+	set(int)::di, set(int)::uo) is det.
+
+middle_rec__find_used_registers_maybe_rvals([], !Used).
+middle_rec__find_used_registers_maybe_rvals([MaybeRval | MaybeRvals], !Used) :-
 	(
-		MaybeRval = no,
-		Used1 = Used0
+		MaybeRval = no
 	;
 		MaybeRval = yes(Rval),
-		middle_rec__find_used_registers_rval(Rval, Used0, Used1)
+		middle_rec__find_used_registers_rval(Rval, !Used)
 	),
-	middle_rec__find_used_registers_maybe_rvals(MaybeRvals, Used1, Used).
+	middle_rec__find_used_registers_maybe_rvals(MaybeRvals, !Used).
 
-:- pred insert_pragma_c_input_registers(list(pragma_c_input), 
-	set(int), set(int)).
-:- mode insert_pragma_c_input_registers(in, di, uo) is det.
+:- pred insert_pragma_c_input_registers(list(pragma_c_input)::in, 
+	set(int)::di, set(int)::uo) is det.
 
-insert_pragma_c_input_registers([], Used, Used).
-insert_pragma_c_input_registers([Input|Inputs], Used0, Used) :-	
+insert_pragma_c_input_registers([], !Used).
+insert_pragma_c_input_registers([Input|Inputs], !Used) :-	
 	Input = pragma_c_input(_, _, Rval, _),
-	middle_rec__find_used_registers_rval(Rval, Used0, Used1),
-	insert_pragma_c_input_registers(Inputs, Used1, Used).
+	middle_rec__find_used_registers_rval(Rval, !Used),
+	insert_pragma_c_input_registers(Inputs, !Used).
 
-:- pred insert_pragma_c_output_registers(list(pragma_c_output), 
-	set(int), set(int)).
-:- mode insert_pragma_c_output_registers(in, di, uo) is det.
+:- pred insert_pragma_c_output_registers(list(pragma_c_output)::in, 
+	set(int)::di, set(int)::uo) is det.
 
-insert_pragma_c_output_registers([], Used, Used).
-insert_pragma_c_output_registers([Output|Outputs], Used0, Used) :-	
+insert_pragma_c_output_registers([], !Used).
+insert_pragma_c_output_registers([Output|Outputs], !Used) :-	
 	Output = pragma_c_output(Lval, _, _, _),
-	middle_rec__find_used_registers_lval(Lval, Used0, Used1),
-	insert_pragma_c_output_registers(Outputs, Used1, Used).
+	middle_rec__find_used_registers_lval(Lval, !Used),
+	insert_pragma_c_output_registers(Outputs, !Used).
 
 %---------------------------------------------------------------------------%
 
 	% Find all the labels defined in an instruction sequence.
 
-:- pred middle_rec__find_labels(list(instruction), list(label)).
-:- mode middle_rec__find_labels(in, out) is det.
+:- pred middle_rec__find_labels(list(instruction)::in, list(label)::out)
+	is det.
 
 middle_rec__find_labels(Instrs, Label2) :-
 	middle_rec__find_labels_2(Instrs, [], Label2).
 
-:- pred middle_rec__find_labels_2(list(instruction), list(label), list(label)).
-:- mode middle_rec__find_labels_2(in, in, out) is det.
+:- pred middle_rec__find_labels_2(list(instruction)::in,
+	list(label)::in, list(label)::out) is det.
 
-middle_rec__find_labels_2([], Labels, Labels).
-middle_rec__find_labels_2([Instr - _ | Instrs], Labels0, Labels) :-
+middle_rec__find_labels_2([], !Labels).
+middle_rec__find_labels_2([Instr - _ | Instrs], !Labels) :-
 	( Instr = label(Label) ->
-		Labels1 = [Label | Labels0]
+		!:Labels = [Label | !.Labels]
 	; Instr = block(_, _, Block) ->
-		middle_rec__find_labels_2(Block, Labels0, Labels1)
+		middle_rec__find_labels_2(Block, !Labels)
 	;
-		Labels1 = Labels0
+		true
 	),
-	middle_rec__find_labels_2(Instrs, Labels1, Labels).
+	middle_rec__find_labels_2(Instrs, !Labels).
Index: ml_switch_gen.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/ml_switch_gen.m,v
retrieving revision 1.13
diff -u -b -r1.13 ml_switch_gen.m
--- ml_switch_gen.m	20 Oct 2003 07:29:08 -0000	1.13
+++ ml_switch_gen.m	22 Oct 2003 08:18:29 -0000
@@ -325,7 +325,7 @@
 	=(MLGenInfo),
 	{ ml_gen_info_get_module_info(MLGenInfo, ModuleInfo) },
 	{ type_util__classify_type(ModuleInfo, Type) = TypeCategory },
-	{ switch_util__type_cat_to_switch_cat(TypeCategory, SwitchCategory) }.
+	{ SwitchCategory = switch_util__type_cat_to_switch_cat(TypeCategory) }.
 
 %-----------------------------------------------------------------------------%
 
@@ -341,7 +341,7 @@
 	{ Case = case(ConsId, Goal) },
 	ml_variable_type(Var, Type),
 	ml_cons_id_to_tag(ConsId, Type, Tag),
-	{ switch_util__switch_priority(Tag, Priority) },
+	{ Priority = switch_util__switch_priority(Tag) },
 	{ TaggedCase = case(Priority, Tag, ConsId, Goal) },
 	ml_switch_lookup_tags(Cases, Var, TaggedCases).
 
Index: par_conj_gen.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/par_conj_gen.m,v
retrieving revision 1.13
diff -u -b -r1.13 par_conj_gen.m
--- par_conj_gen.m	20 Oct 2003 07:29:10 -0000	1.13
+++ par_conj_gen.m	22 Oct 2003 06:53:29 -0000
@@ -129,8 +129,8 @@
 
 %---------------------------------------------------------------------------%
 
-par_conj_gen__generate_par_conj(Goals, GoalInfo, CodeModel, Code) -->
-	{
+par_conj_gen__generate_par_conj(Goals, GoalInfo, CodeModel, Code, !CI) :-
+	(
 		CodeModel = model_det
 	;
 		CodeModel = model_semi,
@@ -138,24 +138,24 @@
 	;
 		CodeModel = model_non,
 		error("sorry, nondet parallel conjunction not implemented")
-	},
-	code_info__get_globals(Globals),
-	{ globals__lookup_int_option(Globals, sync_term_size, STSize) },
-	code_info__get_known_variables(Vars),
-	code_info__save_variables_on_stack(Vars, SaveCode),
-	{ goal_info_get_code_gen_nonlocals(GoalInfo, Nonlocals) },
-	{ set__to_sorted_list(Nonlocals, Variables) },
-	code_info__get_instmap(Initial),
-	{ goal_info_get_instmap_delta(GoalInfo, Delta) },
-	{ instmap__apply_instmap_delta(Initial, Delta, Final) },
-	code_info__get_module_info(ModuleInfo),
-	{ par_conj_gen__find_outputs(Variables, Initial, Final, ModuleInfo,
-			[], Outputs) },
-	{ list__length(Goals, NumGoals) },
-	code_info__acquire_reg(r, RegLval),
-	code_info__acquire_temp_slot(sync_term, SyncSlot),
-	code_info__acquire_temp_slot(lval(sp), SpSlot),
-	{ MakeTerm = node([
+	),
+	code_info__get_globals(!.CI, Globals),
+	globals__lookup_int_option(Globals, sync_term_size, STSize),
+	code_info__get_known_variables(!.CI, Vars),
+	code_info__save_variables_on_stack(Vars, SaveCode, !CI),
+	goal_info_get_code_gen_nonlocals(GoalInfo, Nonlocals),
+	set__to_sorted_list(Nonlocals, Variables),
+	code_info__get_instmap(!.CI, Initial),
+	goal_info_get_instmap_delta(GoalInfo, Delta),
+	instmap__apply_instmap_delta(Initial, Delta, Final),
+	code_info__get_module_info(!.CI, ModuleInfo),
+	par_conj_gen__find_outputs(Variables, Initial, Final, ModuleInfo,
+		[], Outputs),
+	list__length(Goals, NumGoals),
+	code_info__acquire_reg(r, RegLval, !CI),
+	code_info__acquire_temp_slot(sync_term, SyncSlot, !CI),
+	code_info__acquire_temp_slot(lval(sp), SpSlot, !CI),
+	MakeTerm = node([
 		assign(SpSlot, lval(sp))
 			- "save the parent stack pointer",
 		incr_hp(RegLval, no, no, const(int_const(STSize)),
@@ -165,15 +165,15 @@
 			- "initialize sync term",
 		assign(SyncSlot, lval(RegLval))
 			- "store the sync-term on the stack"
-	]) },
-	code_info__release_reg(RegLval),
-	code_info__clear_all_registers(no),
+	]),
+	code_info__release_reg(RegLval, !CI),
+	code_info__clear_all_registers(no, !CI),
 	par_conj_gen__generate_det_par_conj_2(Goals, 0, SyncSlot, SpSlot,
-		Initial, no, GoalCode),
-	code_info__release_temp_slot(SyncSlot),
-	{ Code = tree(tree(SaveCode, MakeTerm), GoalCode) },
-	code_info__clear_all_registers(no),
-	par_conj_gen__place_all_outputs(Outputs).
+		Initial, no, GoalCode, !CI),
+	code_info__release_temp_slot(SyncSlot, !CI),
+	Code = tree(tree(SaveCode, MakeTerm), GoalCode),
+	code_info__clear_all_registers(no, !CI),
+	par_conj_gen__place_all_outputs(Outputs, !CI).
 
 :- pred par_conj_gen__generate_det_par_conj_2(list(hlds_goal), int, lval, lval,
 		instmap, branch_end, code_tree, code_info, code_info).
@@ -181,118 +181,113 @@
 		in, in, out, in, out) is det.
 
 par_conj_gen__generate_det_par_conj_2([], _N, _SyncTerm, _SpSlot, _Initial,
-		_, empty) --> [].
-par_conj_gen__generate_det_par_conj_2([Goal|Goals], N, SyncTerm, SpSlot,
-		Initial, MaybeEnd0, Code) -->
-	code_info__remember_position(StartPos),
-	code_info__get_next_label(ThisConjunct),
-	code_info__get_next_label(NextConjunct),
-	code_gen__generate_goal(model_det, Goal, ThisGoalCode),
-	code_info__get_stack_slots(AllSlots),
-	code_info__get_known_variables(Variables),
-	{ set__list_to_set(Variables, LiveVars) },
-	{ map__select(AllSlots, LiveVars, StoreMap) },
+		_, empty, !CI).
+par_conj_gen__generate_det_par_conj_2([Goal | Goals], N, SyncTerm, SpSlot,
+		Initial, MaybeEnd0, Code, !CI) :-
+	code_info__remember_position(!.CI, StartPos),
+	code_info__get_next_label(ThisConjunct, !CI),
+	code_info__get_next_label(NextConjunct, !CI),
+	code_gen__generate_goal(model_det, Goal, ThisGoalCode, !CI),
+	code_info__get_stack_slots(!.CI, AllSlots),
+	code_info__get_known_variables(!.CI, Variables),
+	set__list_to_set(Variables, LiveVars),
+	map__select(AllSlots, LiveVars, StoreMap),
 	code_info__generate_branch_end(StoreMap, MaybeEnd0, MaybeEnd,
-		SaveCode),
-	{ Goal = _GoalExpr - GoalInfo },
-	{ goal_info_get_instmap_delta(GoalInfo, Delta) },
-	{ instmap__apply_instmap_delta(Initial, Delta, Final) },
-	code_info__get_module_info(ModuleInfo),
-	{ par_conj_gen__find_outputs(Variables, Initial, Final, ModuleInfo,
-			[], TheseOutputs) },
-	par_conj_gen__copy_outputs(TheseOutputs, SpSlot, CopyCode),
+		SaveCode, !CI),
+	Goal = _GoalExpr - GoalInfo,
+	goal_info_get_instmap_delta(GoalInfo, Delta),
+	instmap__apply_instmap_delta(Initial, Delta, Final),
+	code_info__get_module_info(!.CI, ModuleInfo),
+	par_conj_gen__find_outputs(Variables, Initial, Final, ModuleInfo,
+			[], TheseOutputs),
+	par_conj_gen__copy_outputs(!.CI, TheseOutputs, SpSlot, CopyCode),
 	(
-		{ Goals = [_|_] }
+		Goals = [_ | _]
 	->
-		code_info__reset_to_position(StartPos),
-		code_info__get_total_stackslot_count(NumSlots),
-		{ ForkCode = node([
+		code_info__reset_to_position(StartPos, !CI),
+		code_info__get_total_stackslot_count(!.CI, NumSlots),
+		ForkCode = node([
 			fork(ThisConjunct, NextConjunct, NumSlots)
 				- "fork off a child",
 			label(ThisConjunct)
 				- "child thread"
-		]) },
-		{ JoinCode = node([
+		]),
+		JoinCode = node([
 			join_and_terminate(SyncTerm)
 				- "finish",
 			label(NextConjunct)
 				- "start of the next conjunct"
-		]) }
+		])
 	;
-		code_info__get_next_label(ContLab),
-		{ ForkCode = empty },
-		{ JoinCode = node([
+		code_info__get_next_label(ContLab, !CI),
+		ForkCode = empty,
+		JoinCode = node([
 			join_and_continue(SyncTerm, ContLab)
 				- "sync with children then continue",
 			label(ContLab)
 				- "end of parallel conjunction"
-		]) }
+		])
 	),
-	{ ThisCode = tree(
+	ThisCode = tree(
 		ForkCode,
 		tree(ThisGoalCode, tree(tree(SaveCode, CopyCode), JoinCode))
-	) },
-	{ N1 = N + 1 },
+	),
+	N1 = N + 1,
 	par_conj_gen__generate_det_par_conj_2(Goals, N1, SyncTerm, SpSlot,
-			Initial, MaybeEnd, RestCode),
-	{ Code = tree(ThisCode, RestCode) }.
+		Initial, MaybeEnd, RestCode, !CI),
+	Code = tree(ThisCode, RestCode).
 
-:- pred par_conj_gen__find_outputs(list(prog_var), instmap, instmap,
-		module_info, list(prog_var), list(prog_var)).
-:- mode par_conj_gen__find_outputs(in, in, in, in, in, out) is det.
-
-par_conj_gen__find_outputs([], _Initial, _Final, _ModuleInfo,
-		Outputs, Outputs).
-par_conj_gen__find_outputs([Var|Vars],  Initial, Final, ModuleInfo,
-		Outputs0, Outputs) :-
+:- pred par_conj_gen__find_outputs(list(prog_var)::in,
+	instmap::in, instmap::in, module_info::in,
+	list(prog_var)::in, list(prog_var)::out) is det.
+
+par_conj_gen__find_outputs([], _Initial, _Final, _ModuleInfo, !Outputs).
+par_conj_gen__find_outputs([Var | Vars],  Initial, Final, ModuleInfo,
+		!Outputs) :-
 	instmap__lookup_var(Initial, Var, InitialInst),
 	instmap__lookup_var(Final, Var, FinalInst),
-	(
-		mode_is_output(ModuleInfo, (InitialInst -> FinalInst))
-	->
-		Outputs1 = [Var|Outputs0]
+	( mode_is_output(ModuleInfo, (InitialInst -> FinalInst)) ->
+		!:Outputs = [Var | !.Outputs]
 	;
-		Outputs1 = Outputs0
+		!:Outputs = !.Outputs
 	),
-	par_conj_gen__find_outputs(Vars, Initial, Final, ModuleInfo,
-			Outputs1, Outputs).
+	par_conj_gen__find_outputs(Vars, Initial, Final, ModuleInfo, !Outputs).
 
-:- pred par_conj_gen__copy_outputs(list(prog_var), lval, code_tree,
-		code_info, code_info).
-:- mode par_conj_gen__copy_outputs(in, in, out, in, out) is det.
+:- pred par_conj_gen__copy_outputs(code_info::in, list(prog_var)::in, lval::in,
+	code_tree::out) is det.
 
-par_conj_gen__copy_outputs([], _, empty) --> [].
-par_conj_gen__copy_outputs([Var|Vars], SpSlot, Code) -->
-	code_info__get_variable_slot(Var, SrcSlot),
+par_conj_gen__copy_outputs(_, [], _, empty).
+par_conj_gen__copy_outputs(CI, [Var | Vars], SpSlot, Code) :-
+	code_info__get_variable_slot(CI, Var, SrcSlot),
 	(
-		{ SrcSlot = stackvar(SlotNum) }
+		SrcSlot = stackvar(SlotNum)
 	->
-		{ NegSlotNum = (- SlotNum) },
-		{ DestSlot = field(yes(0), lval(SpSlot),
-			const(int_const(NegSlotNum))) }
+		NegSlotNum = (- SlotNum),
+		DestSlot = field(yes(0), lval(SpSlot),
+			const(int_const(NegSlotNum)))
 	;
-		{ error("par conj in model non procedure!") }
+		error("par conj in model non procedure!")
 	),
-	{ ThisCode = node([
+	ThisCode = node([
 		assign(DestSlot, lval(SrcSlot))
 			- "copy result to parent stackframe"
-	]) },
-	{ Code = tree(ThisCode, RestCode) },
-	par_conj_gen__copy_outputs(Vars, SpSlot, RestCode).
-
-:- pred par_conj_gen__place_all_outputs(list(prog_var), code_info, code_info).
-:- mode par_conj_gen__place_all_outputs(in, in, out) is det.
-
-par_conj_gen__place_all_outputs([]) --> [].
-par_conj_gen__place_all_outputs([Var|Vars]) -->
-	code_info__variable_locations(VarLocations),
-	code_info__get_variable_slot(Var, Slot),
+	]),
+	Code = tree(ThisCode, RestCode),
+	par_conj_gen__copy_outputs(CI, Vars, SpSlot, RestCode).
+
+:- pred par_conj_gen__place_all_outputs(list(prog_var)::in,
+	code_info::in, code_info::out) is det.
+
+par_conj_gen__place_all_outputs([], !CI).
+par_conj_gen__place_all_outputs([Var | Vars], !CI) :-
+	code_info__variable_locations(!.CI, VarLocations),
+	code_info__get_variable_slot(!.CI, Var, Slot),
 	(
-		{ map__search(VarLocations, Var, Locations) },
-		{ set__member(Slot, Locations) }
+		map__search(VarLocations, Var, Locations),
+		set__member(Slot, Locations)
 	->
-		[]
+		true
 	;
-		code_info__set_var_location(Var, Slot)
+		code_info__set_var_location(Var, Slot, !CI)
 	),
-	par_conj_gen__place_all_outputs(Vars).
+	par_conj_gen__place_all_outputs(Vars, !CI).
Index: pragma_c_gen.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/pragma_c_gen.m,v
retrieving revision 1.61
diff -u -b -r1.61 pragma_c_gen.m
--- pragma_c_gen.m	24 Oct 2003 06:17:46 -0000	1.61
+++ pragma_c_gen.m	24 Oct 2003 06:30:42 -0000
@@ -327,28 +327,28 @@
 
 pragma_c_gen__generate_pragma_c_code(CodeModel, Attributes,
 		PredId, ProcId, ArgVars, ArgDatas, OrigArgTypes, GoalInfo,
-		PragmaImpl, Code) -->
+		PragmaImpl, Code, !CI) :-
 	(
-		{ PragmaImpl = ordinary(C_Code, Context) },
+		PragmaImpl = ordinary(C_Code, Context),
 		pragma_c_gen__ordinary_pragma_c_code(CodeModel, Attributes,
 			PredId, ProcId, ArgVars, ArgDatas, OrigArgTypes,
-			C_Code, Context, GoalInfo, Code)
+			C_Code, Context, GoalInfo, Code, !CI)
 	;
-		{ PragmaImpl = nondet(
+		PragmaImpl = nondet(
 			Fields, FieldsContext, First, FirstContext,
-			Later, LaterContext, Treat, Shared, SharedContext) },
+			Later, LaterContext, Treat, Shared, SharedContext),
 		pragma_c_gen__nondet_pragma_c_code(CodeModel, Attributes,
 			PredId, ProcId, ArgVars, ArgDatas, OrigArgTypes,
 			Fields, FieldsContext, First, FirstContext,
 			Later, LaterContext, Treat, Shared, SharedContext,
-			Code)
+			Code, !CI)
 	;
-		{ PragmaImpl = import(Name, HandleReturn, Vars, Context) },
-		{ C_Code = string__append_list([HandleReturn, " ",
-				Name, "(", Vars, ");"]) },
+		PragmaImpl = import(Name, HandleReturn, Vars, Context),
+		C_Code = string__append_list([HandleReturn, " ",
+				Name, "(", Vars, ");"]),
 		pragma_c_gen__ordinary_pragma_c_code(CodeModel, Attributes,
 			PredId, ProcId, ArgVars, ArgDatas, OrigArgTypes,
-			C_Code, Context, GoalInfo, Code)
+			C_Code, Context, GoalInfo, Code, !CI)
 	).
 
 %---------------------------------------------------------------------------%
@@ -362,52 +362,52 @@
 
 pragma_c_gen__ordinary_pragma_c_code(CodeModel, Attributes,
 		PredId, ProcId, ArgVars, ArgDatas, OrigArgTypes,
-		C_Code, Context, GoalInfo, Code) -->
+		C_Code, Context, GoalInfo, Code, !CI) :-
 	
 	%
 	% Extract the attributes
 	%
-	{ may_call_mercury(Attributes, MayCallMercury) },
-	{ thread_safe(Attributes, ThreadSafe) },
+	may_call_mercury(Attributes, MayCallMercury),
+	thread_safe(Attributes, ThreadSafe),
 
 	%
 	% First we need to get a list of input and output arguments
 	%
-	code_info__get_pred_proc_arginfo(PredId, ProcId, ArgInfos),
-	{ make_c_arg_list(ArgVars, ArgDatas, OrigArgTypes, ArgInfos, Args) },
-	{ pragma_select_in_args(Args, InArgs) },
-	{ pragma_select_out_args(Args, OutArgs) },
-
-	{ goal_info_get_post_deaths(GoalInfo, PostDeaths) },
-	{ set__init(DeadVars0) },
-	{ find_dead_input_vars(InArgs, PostDeaths, DeadVars0, DeadVars) },
+	ArgInfos = code_info__get_pred_proc_arginfo(!.CI, PredId, ProcId),
+	make_c_arg_list(ArgVars, ArgDatas, OrigArgTypes, ArgInfos, Args),
+	pragma_select_in_args(Args, InArgs),
+	pragma_select_out_args(Args, OutArgs),
+
+	goal_info_get_post_deaths(GoalInfo, PostDeaths),
+	set__init(DeadVars0),
+	find_dead_input_vars(InArgs, PostDeaths, DeadVars0, DeadVars),
 
 	%
 	% Generate code to <save live variables on stack>
 	%
-	( { MayCallMercury = will_not_call_mercury } ->
-		{ SaveVarsCode = empty }
+	( MayCallMercury = will_not_call_mercury ->
+		SaveVarsCode = empty
 	;
 		% the C code might call back Mercury code
 		% which clobbers the succip
-		code_info__succip_is_used,
+		code_info__succip_is_used(!CI),
 
 		% the C code might call back Mercury code which clobbers the
 		% other registers, so we need to save any live variables
 		% (other than the output args) onto the stack
-		{ get_c_arg_list_vars(OutArgs, OutArgs1) },
-		{ set__list_to_set(OutArgs1, OutArgsSet) },
-		code_info__save_variables(OutArgsSet, _, SaveVarsCode)
+		get_c_arg_list_vars(OutArgs, OutArgs1),
+		set__list_to_set(OutArgs1, OutArgsSet),
+		code_info__save_variables(OutArgsSet, _, SaveVarsCode, !CI)
 	),
 
-	{ goal_info_get_determinism(GoalInfo, Detism) },
-	( { CodeModel = model_semi } ->
+	goal_info_get_determinism(GoalInfo, Detism),
+	( CodeModel = model_semi ->
 		% We want to clear r1 even for Detism = failure,
 		% since code with such detism may still assign to
 		% SUCCESS_INDICATOR (i.e. r1).
-		code_info__reserve_r1(ReserveR1_Code)
+		code_info__reserve_r1(ReserveR1_Code, !CI)
 	;
-		{ ReserveR1_Code = empty }
+		ReserveR1_Code = empty
 	),
 
 	%
@@ -415,7 +415,7 @@
 	% (NB we need to be careful that the rvals generated here
 	% remain valid below.)
 	%
-	get_pragma_input_vars(InArgs, InputDescs, InputVarsCode),
+	get_pragma_input_vars(InArgs, InputDescs, InputVarsCode, !CI),
 
 	%
 	% For semidet pragma c_code, we have to move anything that is
@@ -434,13 +434,13 @@
 	% SUCCESS_INDICATOR. Instead we generate that argument directly
 	% into some other location.
 	%
-	( { CodeModel = model_semi } ->
+	( CodeModel = model_semi ->
 		% We want to clear r1 even for Detism = failure,
 		% since code with such detism may still assign to
 		% SUCCESS_INDICATOR (i.e. r1).
-		code_info__clear_r1(ClearR1_Code)
+		code_info__clear_r1(ClearR1_Code, !CI)
 	;
-		{ ClearR1_Code = empty }
+		ClearR1_Code = empty
 	),
 
 	%
@@ -448,44 +448,46 @@
 	% finished generating the code producing the input variables.
 	% (The forward dead variables will be dead after the pragma_c_code,
 	% but are live during its input phase.)
-	code_info__make_vars_forward_dead(DeadVars),
+	code_info__make_vars_forward_dead(DeadVars, !CI),
 
 	%
 	% Generate <declaration of one local variable for each arg>
 	%
-	code_info__get_module_info(ModuleInfo),
-	{ make_pragma_decls(Args, ModuleInfo, Decls) },
+	code_info__get_module_info(!.CI, ModuleInfo),
+	make_pragma_decls(Args, ModuleInfo, Decls),
 
 	%
 	% Generate #define MR_PROC_LABEL <procedure label> /* see note (5) */
 	% and #undef MR_PROC_LABEL
 	%
-	code_info__get_pred_id(CallerPredId),
-	code_info__get_proc_id(CallerProcId),
-	{ make_proc_label_hash_define(ModuleInfo, CallerPredId, CallerProcId,
-		ProcLabelHashDefine, ProcLabelHashUndef) },
+	code_info__get_pred_id(!.CI, CallerPredId),
+	code_info__get_proc_id(!.CI, CallerProcId),
+	make_proc_label_hash_define(ModuleInfo, CallerPredId, CallerProcId,
+		ProcLabelHashDefine, ProcLabelHashUndef),
 
 	%
 	% <assignment of input values from registers to local vars>
 	%
-	{ InputComp = pragma_c_inputs(InputDescs) },
+	InputComp = pragma_c_inputs(InputDescs),
 
 	%
 	% MR_save_registers(); /* see notes (1) and (2) above */
 	%
-	{ MayCallMercury = will_not_call_mercury ->
+	(
+		MayCallMercury = will_not_call_mercury,
 		SaveRegsComp = pragma_c_raw_code("",
 			live_lvals_info(set__init))
 	;
+		MayCallMercury = may_call_mercury,
 		SaveRegsComp = pragma_c_raw_code(
 			"\tMR_save_registers();\n",
 			live_lvals_info(set__init))
-	},
+	),
 
 	%
 	% Code fragments to obtain and release the global lock
 	%
-	{ ThreadSafe = thread_safe ->
+	( ThreadSafe = thread_safe ->
 		ObtainLock = pragma_c_raw_code("", live_lvals_info(set__init)),
 		ReleaseLock = pragma_c_raw_code("", live_lvals_info(set__init))
 	;
@@ -500,23 +502,23 @@
 			MangledName, """);\n"], ReleaseLockStr),
 		ReleaseLock = pragma_c_raw_code(ReleaseLockStr,
 			live_lvals_info(set__init))
-	},
+	),
 
 	%
 	% <The C code itself>
 	%
-	{ C_Code_Comp = pragma_c_user_code(Context, C_Code) },
+	C_Code_Comp = pragma_c_user_code(Context, C_Code),
 
 	%
 	% <for semidet code, check of r1>
 	%
-	( { CodeModel = model_semi, Detism \= failure } ->
-		code_info__get_next_label(FailLabel),
-		{ CheckR1_Comp = pragma_c_fail_to(FailLabel) },
-		{ MaybeFailLabel = yes(FailLabel) }
+	( ( CodeModel = model_semi, Detism \= failure ) ->
+		code_info__get_next_label(FailLabel, !CI),
+		CheckR1_Comp = pragma_c_fail_to(FailLabel),
+		MaybeFailLabel = yes(FailLabel)
 	;
-		{ CheckR1_Comp = pragma_c_noop },
-		{ MaybeFailLabel = no }
+		CheckR1_Comp = pragma_c_noop,
+		MaybeFailLabel = no
 	),
 
 	%
@@ -524,51 +526,52 @@
 	%   MR_restore_registers(); /* see notes (1) and (3) above */
 	% #endif
 	%
-	{ MayCallMercury = will_not_call_mercury ->
+	( MayCallMercury = will_not_call_mercury ->
 		RestoreRegsComp = pragma_c_noop
 	;
 		RestoreRegsComp = pragma_c_raw_code(
 		"#ifndef MR_CONSERVATIVE_GC\n\tMR_restore_registers();\n#endif\n",
 		live_lvals_info(set__init)
 		)
-	},
+	),
 
 	%
 	% The C code may have called Mercury code which clobbered the regs,
 	% in which case we need to tell the code_info that they have been
 	% clobbered.
 	%
-	( { MayCallMercury = will_not_call_mercury } ->
-		[]
+	(
+		MayCallMercury = will_not_call_mercury
 	;
-		{ goal_info_get_instmap_delta(GoalInfo, InstMapDelta) },
-		{ instmap_delta_is_reachable(InstMapDelta) ->
+		MayCallMercury = may_call_mercury,
+		goal_info_get_instmap_delta(GoalInfo, InstMapDelta),
+		(instmap_delta_is_reachable(InstMapDelta) ->
 			OkToDelete = no
 		;
 			OkToDelete = yes
-		},
-		code_info__clear_all_registers(OkToDelete)
+		),
+		code_info__clear_all_registers(OkToDelete, !CI)
 	),
 
 	%
 	% <assignment of the output values from local variables to registers>
 	%
-	pragma_acquire_regs(OutArgs, Regs),
-	place_pragma_output_args_in_regs(OutArgs, Regs, OutputDescs),
-	{ OutputComp = pragma_c_outputs(OutputDescs) },
+	pragma_acquire_regs(OutArgs, Regs, !CI),
+	place_pragma_output_args_in_regs(OutArgs, Regs, OutputDescs, !CI),
+	OutputComp = pragma_c_outputs(OutputDescs),
 
 	%
 	% join all the components of the pragma_c together
 	%
-	{ Components = [ProcLabelHashDefine, InputComp, SaveRegsComp,
+	Components = [ProcLabelHashDefine, InputComp, SaveRegsComp,
 			ObtainLock, C_Code_Comp, ReleaseLock,
 			CheckR1_Comp, RestoreRegsComp,
-			OutputComp, ProcLabelHashUndef] },
-	{ PragmaCCode = node([
+			OutputComp, ProcLabelHashUndef],
+	PragmaCCode = node([
 		pragma_c(Decls, Components, MayCallMercury, no, no, no,
 			MaybeFailLabel, no)
 			- "Pragma C inclusion"
-	]) },
+	]),
 
 	%
 	% for semidet code, we need to insert the failure handling code here:
@@ -583,41 +586,38 @@
 	%
 	%	<code to fail>
 	%
-	( { MaybeFailLabel = yes(TheFailLabel) } ->
-		code_info__get_next_label(SkipLabel),
-		code_info__generate_failure(FailCode),
-		{ GotoSkipLabelCode = node([
+	( MaybeFailLabel = yes(TheFailLabel) ->
+		code_info__get_next_label(SkipLabel, !CI),
+		code_info__generate_failure(FailCode, !CI),
+		GotoSkipLabelCode = node([
 			goto(label(SkipLabel)) - "Skip past failure code"
-		]) },
-		{ SkipLabelCode = node([ label(SkipLabel) - "" ]) },
-		{ FailLabelCode = node([ label(TheFailLabel) - "" ]) },
-		{ FailureCode =
+		]),
+		SkipLabelCode = node([ label(SkipLabel) - "" ]),
+		FailLabelCode = node([ label(TheFailLabel) - "" ]),
+		FailureCode =
 			tree(GotoSkipLabelCode,
 			tree(FailLabelCode,
 			tree(FailCode,
 			     SkipLabelCode)))
-		}
-	; { Detism = failure } ->
-		code_info__generate_failure(FailureCode)
+	; Detism = failure ->
+		code_info__generate_failure(FailureCode, !CI)
 	;
-		{ FailureCode = empty }
+		FailureCode = empty
 	),
 
 	%
 	% join all code fragments together
 	%
-	{ Code =
+	Code =
 		tree(SaveVarsCode,
 		tree(ReserveR1_Code, 
 		tree(InputVarsCode,
 		tree(ClearR1_Code, 
 		tree(PragmaCCode,
-		     FailureCode)))))
-	}.
+		     FailureCode))))).
 
-:- pred make_proc_label_hash_define(module_info, pred_id, proc_id,
-		pragma_c_component, pragma_c_component).
-:- mode make_proc_label_hash_define(in, in, in, out, out) is det.
+:- pred make_proc_label_hash_define(module_info::in, pred_id::in, proc_id::in,
+	pragma_c_component::out, pragma_c_component::out) is det.
 
 make_proc_label_hash_define(ModuleInfo, PredId, ProcId,
 		ProcLabelHashDef, ProcLabelHashUndef) :-
@@ -666,9 +666,9 @@
 	% Generate #define MR_PROC_LABEL <procedure label> /* see note (5) */
 	% and #undef MR_PROC_LABEL
 	%
-	code_info__get_module_info(ModuleInfo, !CI),
-	code_info__get_pred_id(CallerPredId, !CI),
-	code_info__get_proc_id(CallerProcId, !CI),
+	code_info__get_module_info(!.CI, ModuleInfo),
+	code_info__get_pred_id(!.CI, CallerPredId),
+	code_info__get_proc_id(!.CI, CallerProcId),
 	make_proc_label_hash_define(ModuleInfo, CallerPredId, CallerProcId,
 		ProcLabelDefine, ProcLabelUndef),
 
@@ -681,15 +681,15 @@
 	%
 	% Get a list of input and output arguments
 	%
-	code_info__get_pred_proc_arginfo(PredId, ProcId, ArgInfos, !CI),
+	ArgInfos = code_info__get_pred_proc_arginfo(!.CI, PredId, ProcId),
 	make_c_arg_list(ArgVars, ArgDatas, OrigArgTypes, ArgInfos, Args),
 	pragma_select_in_args(Args, InArgs),
 	pragma_select_out_args(Args, OutArgs),
 	make_pragma_decls(Args, ModuleInfo, Decls),
 	make_pragma_decls(OutArgs, ModuleInfo, OutDecls),
 
-	input_descs_from_arg_info(InArgs, InputDescs, !CI),
-	output_descs_from_arg_info(OutArgs, OutputDescs, !CI),
+	input_descs_from_arg_info(!.CI, InArgs, InputDescs),
+	output_descs_from_arg_info(!.CI, OutArgs, OutputDescs),
 
 	module_info_pred_info(ModuleInfo, PredId, PredInfo),
 	ModuleName = pred_info_module(PredInfo),
@@ -715,51 +715,53 @@
 			"Start of the retry block"
 	]),
 
-	code_info__get_globals(Globals, !CI),
+	code_info__get_globals(!.CI, Globals),
 
 	globals__lookup_bool_option(Globals, reclaim_heap_on_nondet_failure,
 		ReclaimHeap),
 	code_info__maybe_save_hp(ReclaimHeap, SaveHeapCode, MaybeHpSlot, !CI),
-	code_info__maybe_restore_hp(MaybeHpSlot, RestoreHeapCode, !CI),
+	code_info__maybe_restore_hp(MaybeHpSlot, RestoreHeapCode),
 
 	globals__lookup_bool_option(Globals, use_trail, UseTrail),
-	code_info__maybe_save_ticket(UseTrail, SaveTicketCode,
-		MaybeTicketSlot, !CI),
+	code_info__maybe_save_ticket(UseTrail, SaveTicketCode, MaybeTicketSlot,
+		!CI),
 	code_info__maybe_reset_ticket(MaybeTicketSlot, undo,
-		RestoreTicketCode, !CI),
+		RestoreTicketCode),
 
-	( FirstContext = yes(FirstContextPrime) ->
-		ActualFirstContext = FirstContextPrime
+	(
+		FirstContext = yes(ActualFirstContext)
 	;
+		FirstContext = no,
 		term__context_init(ActualFirstContext)
 	),
 	trace__maybe_generate_pragma_event_code(nondet_pragma_first,
 		ActualFirstContext, FirstTraceCode, !CI),
-	( LaterContext = yes(LaterContextPrime) ->
-		ActualLaterContext = LaterContextPrime
+	(
+		LaterContext = yes(ActualLaterContext)
 	;
+		LaterContext = no,
 		term__context_init(ActualLaterContext)
 	),
 	trace__maybe_generate_pragma_event_code(nondet_pragma_later,
 		ActualLaterContext, LaterTraceCode, !CI),
 
-	( FirstDisjunctCode =
+	FirstDisjunctCode =
 		tree(SaveHeapCode,
 		tree(SaveTicketCode,
-		     FirstTraceCode))
-	),
-	( LaterDisjunctCode =
+		     FirstTraceCode)),
+	LaterDisjunctCode =
 		tree(RestoreHeapCode,
 		tree(RestoreTicketCode,
-		     LaterTraceCode))
-	),
+		     LaterTraceCode)),
 
 	%
 	% MR_save_registers(); /* see notes (1) and (2) above */
 	%
-	( MayCallMercury = will_not_call_mercury ->
+	(
+		MayCallMercury = will_not_call_mercury,
 		SaveRegs = ""
 	;
+		MayCallMercury = may_call_mercury,
 		SaveRegs = "\tMR_save_registers();\n"
 	),
 
@@ -1186,31 +1188,31 @@
 :- pred get_pragma_input_vars(list(c_arg)::in, list(pragma_c_input)::out,
 	code_tree::out, code_info::in, code_info::out) is det.
 
-get_pragma_input_vars([], [], empty) --> [].
-get_pragma_input_vars([Arg | Args], Inputs, Code) -->
-	{ Arg = c_arg(Var, MaybeName, Type, _ArgInfo) },
-	( { var_is_not_singleton(MaybeName, Name) } ->
-		code_info__produce_variable(Var, FirstCode, Rval),
-		% code_info__produce_variable_in_reg(Var, FirstCode, Lval),
-		% { Rval = lval(Lval) },
-		get_maybe_foreign_type_name(Type, MaybeForeign),
-		{ Input = pragma_c_input(Name, Type, Rval, MaybeForeign) },
-		get_pragma_input_vars(Args, Inputs1, RestCode),
-		{ Inputs = [Input | Inputs1] },
-		{ Code = tree(FirstCode, RestCode) }
+get_pragma_input_vars([], [], empty, !CI).
+get_pragma_input_vars([Arg | Args], Inputs, Code, !CI) :-
+	Arg = c_arg(Var, MaybeName, Type, _ArgInfo),
+	( var_is_not_singleton(MaybeName, Name) ->
+		code_info__produce_variable(Var, FirstCode, Rval, !CI),
+		% code_info__produce_variable_in_reg(Var, FirstCode, Lval, !CI)
+		% Rval = lval(Lval),
+		MaybeForeign = get_maybe_foreign_type_name(!.CI, Type),
+		Input = pragma_c_input(Name, Type, Rval, MaybeForeign),
+		get_pragma_input_vars(Args, Inputs1, RestCode, !CI),
+		Inputs = [Input | Inputs1],
+		Code = tree(FirstCode, RestCode)
 	;
 		% if the variable doesn't occur in the ArgNames list,
 		% it can't be used, so we just ignore it
-		get_pragma_input_vars(Args, Inputs, Code)
+		get_pragma_input_vars(Args, Inputs, Code, !CI)
 	).
 
-:- pred get_maybe_foreign_type_name((type)::in, maybe(string)::out,
-		code_info::in, code_info::out) is det.
+:- func get_maybe_foreign_type_name(code_info, (type)) = maybe(string).
 
-get_maybe_foreign_type_name(Type, MaybeForeignType) -->
-	code_info__get_module_info(Module),
-	{ module_info_types(Module, Types) },
-	{ 
+get_maybe_foreign_type_name(CI, Type) = MaybeForeignType :-
+	code_info__get_module_info(CI, Module),
+	module_info_types(Module, Types),
+	
+	(
 		type_to_ctor_and_args(Type, TypeId, _SubTypes),
 		map__search(Types, TypeId, Defn),
 		hlds_data__get_type_defn_body(Defn, Body),
@@ -1222,12 +1224,12 @@
 		; MaybeC = no,
 			% This is ensured by check_foreign_type in
 			% make_hlds.
-			unexpected(this_file,
-			"get_maybe_foreign_type_name: no c foreign type")
+			unexpected(this_file, "get_maybe_foreign_type_name: "
+				++ "no c foreign type")
 		)
 	;
 		MaybeForeignType = no
-	}.
+	).
 		
 %---------------------------------------------------------------------------%
 
@@ -1237,11 +1239,11 @@
 :- pred pragma_acquire_regs(list(c_arg)::in, list(lval)::out,
 	code_info::in, code_info::out) is det.
 
-pragma_acquire_regs([], []) --> [].
-pragma_acquire_regs([Arg | Args], [Reg | Regs]) -->
-	{ Arg = c_arg(Var, _, _, _) },
-	code_info__acquire_reg_for_var(Var, Reg),
-	pragma_acquire_regs(Args, Regs).
+pragma_acquire_regs([], [], !CI).
+pragma_acquire_regs([Arg | Args], [Reg | Regs], !CI) :-
+	Arg = c_arg(Var, _, _, _),
+	code_info__acquire_reg_for_var(Var, Reg, !CI),
+	pragma_acquire_regs(Args, Regs, !CI).
 
 %---------------------------------------------------------------------------%
 
@@ -1252,54 +1254,49 @@
 :- pred place_pragma_output_args_in_regs(list(c_arg)::in, list(lval)::in,
 	list(pragma_c_output)::out, code_info::in, code_info::out) is det.
 
-place_pragma_output_args_in_regs([], [], []) --> [].
-place_pragma_output_args_in_regs([Arg | Args], [Reg | Regs], Outputs) -->
-	place_pragma_output_args_in_regs(Args, Regs, Outputs0),
-	{ Arg = c_arg(Var, MaybeName, OrigType, _ArgInfo) },
-	code_info__release_reg(Reg),
-	( code_info__variable_is_forward_live(Var) ->
-		code_info__set_var_location(Var, Reg),
-		get_maybe_foreign_type_name(OrigType, MaybeForeign),
-		{
-			var_is_not_singleton(MaybeName, Name)
-		->
+place_pragma_output_args_in_regs([], [], [], !CI).
+place_pragma_output_args_in_regs([Arg | Args], [Reg | Regs], Outputs, !CI) :-
+	place_pragma_output_args_in_regs(Args, Regs, Outputs0, !CI),
+	Arg = c_arg(Var, MaybeName, OrigType, _ArgInfo),
+	code_info__release_reg(Reg, !CI),
+	( code_info__variable_is_forward_live(!.CI, Var) ->
+		code_info__set_var_location(Var, Reg, !CI),
+		MaybeForeign = get_maybe_foreign_type_name(!.CI, OrigType),
+		( var_is_not_singleton(MaybeName, Name) ->
 			PragmaCOutput = pragma_c_output(Reg, OrigType,
 						Name, MaybeForeign),
 			Outputs = [PragmaCOutput | Outputs0]
 		;
 			Outputs = Outputs0
-		}
+		)
 	;
-		{ Outputs = Outputs0 }
+		Outputs = Outputs0
 	).
-place_pragma_output_args_in_regs([_|_], [], _) -->
-	{ error("place_pragma_output_args_in_regs: length mismatch") }.
-place_pragma_output_args_in_regs([], [_|_], _) -->
-	{ error("place_pragma_output_args_in_regs: length mismatch") }.
+place_pragma_output_args_in_regs([_|_], [], _, !CI) :-
+	error("place_pragma_output_args_in_regs: length mismatch").
+place_pragma_output_args_in_regs([], [_|_], _, !CI) :-
+	error("place_pragma_output_args_in_regs: length mismatch").
 
 %---------------------------------------------------------------------------%
 
 % input_descs_from_arg_info returns a list of pragma_c_inputs, which
 % are pairs of rvals and (C) variables which receive the input value.
 
-:- pred input_descs_from_arg_info(list(c_arg)::in, list(pragma_c_input)::out,
-		code_info::in, code_info::out) is det.
+:- pred input_descs_from_arg_info(code_info::in, list(c_arg)::in,
+	list(pragma_c_input)::out) is det.
 
-input_descs_from_arg_info([], [], CodeInfo, CodeInfo).
-input_descs_from_arg_info([Arg | Args], Inputs, CodeInfo0, CodeInfo) :-
+input_descs_from_arg_info(_, [], []).
+input_descs_from_arg_info(CI, [Arg | Args], Inputs) :-
 	Arg = c_arg(_Var, MaybeName, OrigType, ArgInfo),
-	(
-		var_is_not_singleton(MaybeName, Name)
-	->
+	( var_is_not_singleton(MaybeName, Name) ->
 		ArgInfo = arg_info(N, _),
 		Reg = reg(r, N),
-		get_maybe_foreign_type_name(OrigType, MaybeForeign,
-				CodeInfo0, CodeInfo1),
+		MaybeForeign = get_maybe_foreign_type_name(CI, OrigType),
 		Input = pragma_c_input(Name, OrigType, lval(Reg), MaybeForeign),
-		Inputs = [Input | Inputs1],
-		input_descs_from_arg_info(Args, Inputs1, CodeInfo1, CodeInfo)
+		input_descs_from_arg_info(CI, Args, Inputs1),
+		Inputs = [Input | Inputs1]
 	;
-		input_descs_from_arg_info(Args, Inputs, CodeInfo0, CodeInfo)
+		input_descs_from_arg_info(CI, Args, Inputs)
 	).
 
 %---------------------------------------------------------------------------%
@@ -1308,25 +1305,21 @@
 % are pairs of names of output registers and (C) variables which hold the
 % output value.
 
-:- pred output_descs_from_arg_info(list(c_arg)::in, list(pragma_c_output)::out,
-		code_info::in, code_info::out) is det.
+:- pred output_descs_from_arg_info(code_info::in, list(c_arg)::in,
+	list(pragma_c_output)::out) is det.
 
-output_descs_from_arg_info([], [], CodeInfo, CodeInfo).
-output_descs_from_arg_info([Arg | Args], Outputs, CodeInfo0, CodeInfo) :-
+output_descs_from_arg_info(_, [], []).
+output_descs_from_arg_info(CI, [Arg | Args], Outputs) :-
 	Arg = c_arg(_Var, MaybeName, OrigType, ArgInfo),
-	output_descs_from_arg_info(Args, Outputs0, CodeInfo0, CodeInfo1),
-	(
-		var_is_not_singleton(MaybeName, Name)
-	->
+	output_descs_from_arg_info(CI, Args, Outputs0),
+	( var_is_not_singleton(MaybeName, Name) ->
 		ArgInfo = arg_info(N, _),
 		Reg = reg(r, N),
-		get_maybe_foreign_type_name(OrigType, MaybeForeign,
-				CodeInfo1, CodeInfo),
+		MaybeForeign = get_maybe_foreign_type_name(CI, OrigType),
 		Outputs = [pragma_c_output(Reg, OrigType, Name, MaybeForeign) |
 				Outputs0]
 	;
-		Outputs = Outputs0,
-		CodeInfo = CodeInfo1
+		Outputs = Outputs0
 	).
 
 %---------------------------------------------------------------------------%
Index: string_switch.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/string_switch.m,v
retrieving revision 1.44
diff -u -b -r1.44 string_switch.m
--- string_switch.m	20 Oct 2003 07:29:11 -0000	1.44
+++ string_switch.m	22 Oct 2003 07:17:13 -0000
@@ -25,11 +25,10 @@
 :- import_module ll_backend__llds.
 :- import_module parse_tree__prog_data.
 
-:- pred string_switch__generate(cases_list, prog_var, code_model,
-	can_fail, hlds_goal_info, label, branch_end, branch_end, code_tree,
-	code_info, code_info).
-:- mode string_switch__generate(in, in, in, in, in, in, in, out, out, in, out)
-	is det.
+:- pred string_switch__generate(cases_list::in, prog_var::in, code_model::in,
+	can_fail::in, hlds_goal_info::in, label::in,
+	branch_end::in, branch_end::out, code_tree::out,
+	code_info::in, code_info::out) is det.
 
 %-----------------------------------------------------------------------------%
 
@@ -45,13 +44,13 @@
 :- import_module bool, int, string, list, map, std_util, assoc_list, require.
 
 string_switch__generate(Cases, Var, CodeModel, _CanFail, SwitchGoalInfo,
-		EndLabel, MaybeEnd0, MaybeEnd, Code, !CodeInfo) :-
-	code_info__produce_variable(Var, VarCode, VarRval, !CodeInfo),
-	code_info__acquire_reg(r, SlotReg, !CodeInfo),
-	code_info__acquire_reg(r, StringReg, !CodeInfo),
-	code_info__get_next_label(LoopLabel, !CodeInfo),
-	code_info__get_next_label(FailLabel, !CodeInfo),
-	code_info__get_next_label(JumpLabel, !CodeInfo),
+		EndLabel, !MaybeEnd, Code, !CI) :-
+	code_info__produce_variable(Var, VarCode, VarRval, !CI),
+	code_info__acquire_reg(r, SlotReg, !CI),
+	code_info__acquire_reg(r, StringReg, !CI),
+	code_info__get_next_label(LoopLabel, !CI),
+	code_info__get_next_label(FailLabel, !CI),
+	code_info__get_next_label(JumpLabel, !CI),
 
 	% Determine how big to make the hash table.
 	% Currently we round the number of cases up to the nearest
@@ -78,29 +77,28 @@
 		% registers), and because that code is generated manually
 		% (below) so we don't need the reg info to be valid when
 		% we generate it.
-	code_info__release_reg(SlotReg, !CodeInfo),
-	code_info__release_reg(StringReg, !CodeInfo),
+	code_info__release_reg(SlotReg, !CI),
+	code_info__release_reg(StringReg, !CI),
 
 		% Generate the code for when the hash lookup fails.
 		% This must be done before gen_hash_slots, since
 		% we want to use the exprn_info corresponding to
 		% the start of the switch, not to the end of the last case.
-	code_info__generate_failure(FailCode, !CodeInfo),
+	code_info__generate_failure(FailCode, !CI),
 
 		% Generate the code etc. for the hash table
 		%
 	string_switch__gen_hash_slots(0, TableSize, HashSlotsMap, CodeModel,
-		SwitchGoalInfo, FailLabel, EndLabel, MaybeEnd0, MaybeEnd,
-		Strings, Labels, NextSlots, SlotsCode, !CodeInfo),
+		SwitchGoalInfo, FailLabel, EndLabel, !MaybeEnd,
+		Strings, Labels, NextSlots, SlotsCode, !CI),
 
 		% Generate code which does the hash table lookup
 	(
 		add_static_cell_natural_types(NextSlots, NextSlotsTableAddr,
-			!CodeInfo),
+			!CI),
 		NextSlotsTable = const(
 			data_addr_const(NextSlotsTableAddr, no)),
-		add_static_cell_natural_types(Strings, StringTableAddr,
-			!CodeInfo),
+		add_static_cell_natural_types(Strings, StringTableAddr, !CI),
 		StringTable = const(data_addr_const(StringTableAddr, no)),
 		HashLookupCode = node([
 			comment("hashed string switch") -
@@ -141,102 +139,91 @@
 		tree(JumpCode,
 		     SlotsCode)))).
 
-:- pred string_switch__gen_hash_slots(int, int, map(int, hash_slot),
-	code_model, hlds_goal_info, label, label, branch_end, branch_end,
-	list(rval), list(label), list(rval), code_tree, code_info, code_info).
-:- mode string_switch__gen_hash_slots(in, in, in, in, in, in, in,
-	in, out, out, out, out, out, in, out) is det.
+:- pred string_switch__gen_hash_slots(int::in, int::in,
+	map(int, hash_slot)::in, code_model::in, hlds_goal_info::in, label::in,
+	label::in, branch_end::in, branch_end::out,
+	list(rval)::out, list(label)::out, list(rval)::out, code_tree::out,
+	code_info::in, code_info::out) is det.
 
 string_switch__gen_hash_slots(Slot, TableSize, HashSlotMap, CodeModel,
-		SwitchGoalInfo, FailLabel, EndLabel, MaybeEnd0, MaybeEnd,
-		Strings, Labels, NextSlots, Code) -->
-	( { Slot = TableSize } ->
-		{
-			MaybeEnd = MaybeEnd0,
+		SwitchGoalInfo, FailLabel, EndLabel, !MaybeEnd,
+		Strings, Labels, NextSlots, Code, !CI) :-
+	( Slot = TableSize ->
 			Strings = [],
 			Labels = [],
 			NextSlots = [],
 			Code = node([
 				label(EndLabel) - "end of hashed string switch"
 			])
-		}
 	;
 		string_switch__gen_hash_slot(Slot, TableSize, HashSlotMap,
 			CodeModel, SwitchGoalInfo, FailLabel, EndLabel,
-			MaybeEnd0, MaybeEnd1,
-			String, Label, NextSlot, SlotCode),
-		{ Slot1 = Slot + 1 },
-		{ 
+			!MaybeEnd, String, Label, NextSlot, SlotCode, !CI),
+		Slot1 = Slot + 1,
+		string_switch__gen_hash_slots(Slot1, TableSize, HashSlotMap,
+			CodeModel, SwitchGoalInfo, FailLabel, EndLabel,
+			!MaybeEnd, Strings0, Labels0, NextSlots0, Code0, !CI),
 			Strings = [String | Strings0],
 			Labels = [Label | Labels0],
 			NextSlots = [NextSlot | NextSlots0],
 			Code = tree(SlotCode, Code0)
-		},
-		string_switch__gen_hash_slots(Slot1, TableSize, HashSlotMap,
-			CodeModel, SwitchGoalInfo, FailLabel, EndLabel,
-			MaybeEnd1, MaybeEnd,
-			Strings0, Labels0, NextSlots0, Code0)
 	).
 
-:- pred string_switch__gen_hash_slot(int, int, map(int, hash_slot),
-	code_model, hlds_goal_info, label, label, branch_end, branch_end,
-	rval, label, rval, code_tree,
-	code_info, code_info).
-:- mode string_switch__gen_hash_slot(in, in, in, in, in, in, in,
-	in, out, out, out, out, out, in, out) is det.
+:- pred string_switch__gen_hash_slot(int::in, int::in, map(int, hash_slot)::in,
+	code_model::in, hlds_goal_info::in, label::in, label::in,
+	branch_end::in, branch_end::out, rval::out, label::out, rval::out,
+	code_tree::out, code_info::in, code_info::out) is det.
 
 string_switch__gen_hash_slot(Slot, TblSize, HashSlotMap, CodeModel,
-		SwitchGoalInfo, FailLabel, EndLabel, MaybeEnd0, MaybeEnd,
-		StringRval, Label, NextSlotRval, Code) -->
-	( { map__search(HashSlotMap, Slot, hash_slot(Case, Next)) } ->
-		{ NextSlotRval = const(int_const(Next)) },
-		{ Case = case(_, ConsTag, _, Goal) },
-		{ ConsTag = string_constant(String0) ->
+		SwitchGoalInfo, FailLabel, EndLabel, !MaybeEnd,
+		StringRval, Label, NextSlotRval, Code, !CI) :-
+	( map__search(HashSlotMap, Slot, hash_slot(Case, Next)) ->
+		NextSlotRval = const(int_const(Next)),
+		Case = case(_, ConsTag, _, Goal),
+		( ConsTag = string_constant(String0) ->
 			String = String0
 		;
 			error("string_switch__gen_hash_slots: string expected")
-		},
-		{ StringRval = const(string_const(String)) },
-		code_info__get_next_label(Label),
-		{ string__append_list(["case """, String, """"], Comment) },
-		{ LabelCode = node([
+		),
+		StringRval = const(string_const(String)),
+		code_info__get_next_label(Label, !CI),
+		string__append_list(["case """, String, """"], Comment),
+		LabelCode = node([
 			label(Label) - Comment
-		]) },
-		code_info__remember_position(BranchStart),
+		]),
+		code_info__remember_position(!.CI, BranchStart),
 		trace__maybe_generate_internal_event_code(Goal, SwitchGoalInfo,
-			TraceCode),
-		code_gen__generate_goal(CodeModel, Goal, GoalCode),
-		{ goal_info_get_store_map(SwitchGoalInfo, StoreMap) },
-		code_info__generate_branch_end(StoreMap, MaybeEnd0, MaybeEnd,
-			SaveCode),
+			TraceCode, !CI),
+		code_gen__generate_goal(CodeModel, Goal, GoalCode, !CI),
+		goal_info_get_store_map(SwitchGoalInfo, StoreMap),
+		code_info__generate_branch_end(StoreMap, !MaybeEnd,
+			SaveCode, !CI),
 		(
-			{ string_switch__this_is_last_case(Slot, TblSize,
-				HashSlotMap) }
+			string_switch__this_is_last_case(Slot, TblSize,
+				HashSlotMap)
 		->
-			[]
+			true
 		;
-			code_info__reset_to_position(BranchStart)
+			code_info__reset_to_position(BranchStart, !CI)
 		),
-		{ FinishCode = node([
+		FinishCode = node([
 			goto(label(EndLabel)) - "jump to end of switch"
-		]) },
-		{ Code =
+		]),
+		Code =
 			tree(LabelCode,
 			tree(TraceCode,
 			tree(GoalCode,
 			tree(SaveCode,
 			     FinishCode))))
-		}
 	;
-		{ MaybeEnd = MaybeEnd0 },
-		{ StringRval = const(int_const(0)) },
-		{ Label = FailLabel },
-		{ NextSlotRval = const(int_const(-2)) },
-		{ Code = empty }
+		StringRval = const(int_const(0)),
+		Label = FailLabel,
+		NextSlotRval = const(int_const(-2)),
+		Code = empty
 	).
 
-:- pred string_switch__this_is_last_case(int, int, map(int, hash_slot)).
-:- mode string_switch__this_is_last_case(in, in, in) is semidet.
+:- pred string_switch__this_is_last_case(int::in, int::in,
+	map(int, hash_slot)::in) is semidet.
 
 string_switch__this_is_last_case(Slot, TableSize, Table) :-
 	Slot1 = Slot + 1,
Index: switch_gen.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/switch_gen.m,v
retrieving revision 1.82
diff -u -b -r1.82 switch_gen.m
--- switch_gen.m	20 Oct 2003 07:29:11 -0000	1.82
+++ switch_gen.m	22 Oct 2003 07:33:22 -0000
@@ -54,10 +54,9 @@
 
 :- import_module list.
 
-:- pred switch_gen__generate_switch(code_model, prog_var, can_fail, list(case),
-	hlds_goal_info, code_tree, code_info, code_info).
-:- mode switch_gen__generate_switch(in, in, in, in, in, out, in, out)
-	is det.
+:- pred switch_gen__generate_switch(code_model::in, prog_var::in, can_fail::in,
+	list(case)::in, hlds_goal_info::in, code_tree::out,
+	code_info::in, code_info::out) is det.
 
 %---------------------------------------------------------------------------%
 
@@ -87,84 +86,85 @@
 	% CanFail says whether the switch covers all cases.
 
 switch_gen__generate_switch(CodeModel, CaseVar, CanFail, Cases, GoalInfo,
-		Code) -->
-	{ goal_info_get_store_map(GoalInfo, StoreMap) },
-	switch_gen__determine_category(CaseVar, SwitchCategory),
-	code_info__get_next_label(EndLabel),
-	switch_gen__lookup_tags(Cases, CaseVar, TaggedCases0),
-	{ list__sort_and_remove_dups(TaggedCases0, TaggedCases) },
-	code_info__get_globals(Globals),
-	{ globals__lookup_bool_option(Globals, smart_indexing,
-		Indexing) },
+		Code, !CI) :-
+	goal_info_get_store_map(GoalInfo, StoreMap),
+	SwitchCategory = switch_gen__determine_category(!.CI, CaseVar),
+	code_info__get_next_label(EndLabel, !CI),
+	switch_gen__lookup_tags(!.CI, Cases, CaseVar, TaggedCases0),
+	list__sort_and_remove_dups(TaggedCases0, TaggedCases),
+	code_info__get_globals(!.CI, Globals),
+	globals__lookup_bool_option(Globals, smart_indexing,
+		Indexing),
 	(
 		% Check for a switch on a type whose representation
 		% uses reserved addresses 
-		{ list__member(Case, TaggedCases) },    
-		{ Case = case(_Priority, Tag, _ConsId, _Goal) },
-		{
+		list__member(Case, TaggedCases),    
+		Case = case(_Priority, Tag, _ConsId, _Goal),
+		(
 			Tag = reserved_address(_)
 		;
 			Tag = shared_with_reserved_addresses(_, _)
-		}
+		)
 	->
 		% XXX This may be be inefficient in some cases.
 		switch_gen__generate_all_cases(TaggedCases, CaseVar, CodeModel,
-			CanFail, GoalInfo, EndLabel, no, MaybeEnd, Code)
+			CanFail, GoalInfo, EndLabel, no, MaybeEnd, Code, !CI)
 	;
-		{ Indexing = yes },
-		{ SwitchCategory = atomic_switch },
-		code_info__get_maybe_trace_info(MaybeTraceInfo),
-		{ MaybeTraceInfo = no },
-		{ list__length(TaggedCases, NumCases) },
-		{ globals__lookup_int_option(Globals, lookup_switch_size,
-			LookupSize) },
-		{ NumCases >= LookupSize },
-		{ globals__lookup_int_option(Globals, lookup_switch_req_density,
-			ReqDensity) },
-		lookup_switch__is_lookup_switch(CaseVar, TaggedCases, GoalInfo,
-			CanFail, ReqDensity, StoreMap, no, MaybeEndPrime,
-			CodeModel, FirstVal, LastVal, NeedRangeCheck,
-			NeedBitVecCheck, OutVars, CaseVals, MLiveness)
+		Indexing = yes,
+		SwitchCategory = atomic_switch,
+		code_info__get_maybe_trace_info(!.CI, MaybeTraceInfo),
+		MaybeTraceInfo = no,
+		list__length(TaggedCases, NumCases),
+		globals__lookup_int_option(Globals, lookup_switch_size,
+			LookupSize),
+		NumCases >= LookupSize,
+		globals__lookup_int_option(Globals, lookup_switch_req_density,
+			ReqDensity),
+		lookup_switch__is_lookup_switch(CaseVar, TaggedCases,
+			GoalInfo, CanFail, ReqDensity, StoreMap, no,
+			MaybeEndPrime, CodeModel, FirstVal, LastVal,
+			NeedRangeCheck, NeedBitVecCheck, OutVars, CaseVals,
+			MLiveness, !CI)
 	->
-		{ MaybeEnd = MaybeEndPrime },
+		MaybeEnd = MaybeEndPrime,
 		lookup_switch__generate(CaseVar, OutVars, CaseVals,
 			FirstVal, LastVal, NeedRangeCheck, NeedBitVecCheck,
-			MLiveness, StoreMap, no, Code)
+			MLiveness, StoreMap, no, Code, !CI)
 	;
-		{ Indexing = yes },
-		{ SwitchCategory = atomic_switch },
-		{ list__length(TaggedCases, NumCases) },
-		{ globals__lookup_int_option(Globals, dense_switch_size,
-			DenseSize) },
-		{ NumCases >= DenseSize },
-		{ globals__lookup_int_option(Globals, dense_switch_req_density,
-			ReqDensity) },
-		dense_switch__is_dense_switch(CaseVar, TaggedCases, CanFail,
-			ReqDensity, FirstVal, LastVal, CanFail1)
+		Indexing = yes,
+		SwitchCategory = atomic_switch,
+		list__length(TaggedCases, NumCases),
+		globals__lookup_int_option(Globals, dense_switch_size,
+			DenseSize),
+		NumCases >= DenseSize,
+		globals__lookup_int_option(Globals, dense_switch_req_density,
+			ReqDensity),
+		dense_switch__is_dense_switch(!.CI, CaseVar, TaggedCases,
+			CanFail, ReqDensity, FirstVal, LastVal, CanFail1)
 	->
 		dense_switch__generate(TaggedCases,
 			FirstVal, LastVal, CaseVar, CodeModel, CanFail1,
-			GoalInfo, EndLabel, no, MaybeEnd, Code)
+			GoalInfo, EndLabel, no, MaybeEnd, Code, !CI)
 	;
-		{ Indexing = yes },
-		{ SwitchCategory = string_switch },
-		{ list__length(TaggedCases, NumCases) },
-		{ globals__lookup_int_option(Globals, string_switch_size,
-			StringSize) },
-		{ NumCases >= StringSize }
+		Indexing = yes,
+		SwitchCategory = string_switch,
+		list__length(TaggedCases, NumCases),
+		globals__lookup_int_option(Globals, string_switch_size,
+			StringSize),
+		NumCases >= StringSize
 	->
 		string_switch__generate(TaggedCases, CaseVar, CodeModel,
-			CanFail, GoalInfo, EndLabel, no, MaybeEnd, Code)
+			CanFail, GoalInfo, EndLabel, no, MaybeEnd, Code, !CI)
 	;
-		{ Indexing = yes },
-		{ SwitchCategory = tag_switch },
-		{ list__length(TaggedCases, NumCases) },
-		{ globals__lookup_int_option(Globals, tag_switch_size,
-			TagSize) },
-		{ NumCases >= TagSize }
+		Indexing = yes,
+		SwitchCategory = tag_switch,
+		list__length(TaggedCases, NumCases),
+		globals__lookup_int_option(Globals, tag_switch_size,
+			TagSize),
+		NumCases >= TagSize
 	->
 		tag_switch__generate(TaggedCases, CaseVar, CodeModel, CanFail,
-			GoalInfo, EndLabel, no, MaybeEnd, Code)
+			GoalInfo, EndLabel, no, MaybeEnd, Code, !CI)
 	;
 		% To generate a switch, first we flush the
 		% variable on whose tag we are going to switch, then we
@@ -172,9 +172,9 @@
 
 		switch_gen__generate_all_cases(TaggedCases, CaseVar,
 			CodeModel, CanFail, GoalInfo, EndLabel, no, MaybeEnd,
-			Code)
+			Code, !CI)
 	),
-	code_info__after_all_branches(StoreMap, MaybeEnd).
+	code_info__after_all_branches(StoreMap, MaybeEnd, !CI).
 
 %---------------------------------------------------------------------------%
 
@@ -182,29 +182,26 @@
 	% being switched on is an atomic type, a string, or
 	% something more complicated.
 
-:- pred switch_gen__determine_category(prog_var, switch_category,
-	code_info, code_info).
-:- mode switch_gen__determine_category(in, out, in, out) is det.
-
-switch_gen__determine_category(CaseVar, SwitchCategory) -->
-	code_info__variable_type(CaseVar, Type),
-	code_info__get_module_info(ModuleInfo),
-	{ classify_type(ModuleInfo, Type) = TypeCategory },
-	{ switch_util__type_cat_to_switch_cat(TypeCategory, SwitchCategory) }.
+:- func switch_gen__determine_category(code_info, prog_var) = switch_category.
+
+switch_gen__determine_category(CI, CaseVar) = SwitchCategory :-
+	Type = code_info__variable_type(CI, CaseVar),
+	code_info__get_module_info(CI, ModuleInfo),
+	classify_type(ModuleInfo, Type) = TypeCategory,
+	SwitchCategory = switch_util__type_cat_to_switch_cat(TypeCategory).
 
 %---------------------------------------------------------------------------%
 
-:- pred switch_gen__lookup_tags(list(case), prog_var, cases_list,
-				code_info, code_info).
-:- mode switch_gen__lookup_tags(in, in, out, in, out) is det.
-
-switch_gen__lookup_tags([], _, []) --> [].
-switch_gen__lookup_tags([Case | Cases], Var, [TaggedCase | TaggedCases]) -->
-	{ Case = case(ConsId, Goal) },
-	code_info__cons_id_to_tag(Var, ConsId, Tag),
-	{ switch_util__switch_priority(Tag, Priority) },
-	{ TaggedCase = case(Priority, Tag, ConsId, Goal) },
-	switch_gen__lookup_tags(Cases, Var, TaggedCases).
+:- pred switch_gen__lookup_tags(code_info::in, list(case)::in, prog_var::in,
+	cases_list::out) is det.
+
+switch_gen__lookup_tags(_, [], _, []).
+switch_gen__lookup_tags(CI, [Case | Cases], Var, [TaggedCase | TaggedCases]) :-
+	Case = case(ConsId, Goal),
+	Tag = code_info__cons_id_to_tag(CI, Var, ConsId),
+	Priority = switch_util__switch_priority(Tag),
+	TaggedCase = case(Priority, Tag, ConsId, Goal),
+	switch_gen__lookup_tags(CI, Cases, Var, TaggedCases).
 
 %---------------------------------------------------------------------------%
 %---------------------------------------------------------------------------%
@@ -235,27 +232,26 @@
 	% and put that one first. This minimizes the number of pipeline
 	% breaks caused by taken branches.
 
-:- pred switch_gen__generate_all_cases(list(extended_case), prog_var,
-	code_model, can_fail, hlds_goal_info, label, branch_end, branch_end,
-	code_tree, code_info, code_info).
-:- mode switch_gen__generate_all_cases(in, in, in, in, in, in, in, out, out,
-	in, out) is det.
+:- pred switch_gen__generate_all_cases(list(extended_case)::in, prog_var::in,
+	code_model::in, can_fail::in, hlds_goal_info::in, label::in,
+	branch_end::in, branch_end::out, code_tree::out,
+	code_info::in, code_info::out) is det.
 
 switch_gen__generate_all_cases(Cases0, Var, CodeModel, CanFail, GoalInfo,
-		EndLabel, MaybeEnd0, MaybeEnd, Code) -->
-	code_info__produce_variable(Var, VarCode, _Rval),
+		EndLabel, !MaybeEnd, Code, !CI) :-
+	code_info__produce_variable(Var, VarCode, _Rval, !CI),
 	(
-		{ CodeModel = model_det },
-		{ CanFail = cannot_fail },
-		{ Cases0 = [Case1, Case2] },
-		{ Case1 = case(_, _, _, Goal1) },
-		{ Case2 = case(_, _, _, Goal2) }
+		CodeModel = model_det,
+		CanFail = cannot_fail,
+		Cases0 = [Case1, Case2],
+		Case1 = case(_, _, _, Goal1),
+		Case2 = case(_, _, _, Goal2)
 	->
-		code_info__get_pred_id(PredId),
-		code_info__get_proc_id(ProcId),
-		{ count_recursive_calls(Goal1, PredId, ProcId, Min1, Max1) },
-		{ count_recursive_calls(Goal2, PredId, ProcId, Min2, Max2) },
-		{
+		code_info__get_pred_id(!.CI, PredId),
+		code_info__get_proc_id(!.CI, ProcId),
+		count_recursive_calls(Goal1, PredId, ProcId, Min1, Max1),
+		count_recursive_calls(Goal2, PredId, ProcId, Min2, Max2),
+		(
 			Max1 = 0,	% Goal1 is a base case
 			Min2 = 1	% Goal2 is probably singly recursive
 		->
@@ -267,82 +263,78 @@
 			Cases = [Case2, Case1]
 		;
 			Cases = Cases0
-		}
+		)
 	;
-		{ Cases = Cases0 }
+		Cases = Cases0
 	),
 	switch_gen__generate_cases(Cases, Var, CodeModel, CanFail,
-		GoalInfo, EndLabel, MaybeEnd0, MaybeEnd, CasesCode),
-	{ Code = tree(VarCode, CasesCode) }.
+		GoalInfo, EndLabel, !MaybeEnd, CasesCode, !CI),
+	Code = tree(VarCode, CasesCode).
 
-:- pred switch_gen__generate_cases(list(extended_case), prog_var, code_model,
-	can_fail, hlds_goal_info, label, branch_end, branch_end, code_tree,
-	code_info, code_info).
-:- mode switch_gen__generate_cases(in, in, in, in, in, in, in, out, out,
-	in, out) is det.
+:- pred switch_gen__generate_cases(list(extended_case)::in, prog_var::in,
+	code_model::in, can_fail::in, hlds_goal_info::in, label::in,
+	branch_end::in, branch_end::out, code_tree::out,
+	code_info::in, code_info::out) is det.
 
 	% At the end of a locally semidet switch, we fail because we
 	% came across a tag which was not covered by one of the cases.
 	% It is followed by the end of switch label to which the cases
 	% branch.
 switch_gen__generate_cases([], _Var, _CodeModel, CanFail, _GoalInfo,
-		EndLabel, MaybeEnd, MaybeEnd, Code) -->
-	( { CanFail = can_fail } ->
-		code_info__generate_failure(FailCode)
+		EndLabel, !MaybeEnd, Code, !CI) :-
+	( CanFail = can_fail ->
+		code_info__generate_failure(FailCode, !CI)
 	;
-		{ FailCode = empty }
+		FailCode = empty
 	),
-	{ EndCode = node([
+	EndCode = node([
 		label(EndLabel) -
 			"end of switch"
-	]) },
-	{ Code = tree(FailCode, EndCode) }.
+	]),
+	Code = tree(FailCode, EndCode).
 
 switch_gen__generate_cases([case(_, _, Cons, Goal) | Cases], Var, CodeModel,
-		CanFail, SwitchGoalInfo, EndLabel, MaybeEnd0, MaybeEnd,
-		CasesCode) -->
-	code_info__remember_position(BranchStart),
-	{ goal_info_get_store_map(SwitchGoalInfo, StoreMap) },
+		CanFail, SwitchGoalInfo, EndLabel, !MaybeEnd, CasesCode,
+		!CI) :-
+	code_info__remember_position(!.CI, BranchStart),
+	goal_info_get_store_map(SwitchGoalInfo, StoreMap),
 	(
-		{ Cases = [_|_] ; CanFail = can_fail }
+		( Cases = [_|_] ; CanFail = can_fail )
 	->
 		unify_gen__generate_tag_test(Var, Cons, branch_on_failure,
-			NextLabel, TestCode),
+			NextLabel, TestCode, !CI),
 		trace__maybe_generate_internal_event_code(Goal, SwitchGoalInfo,
-			TraceCode),
-		code_gen__generate_goal(CodeModel, Goal, GoalCode),
-		code_info__generate_branch_end(StoreMap, MaybeEnd0, MaybeEnd1,
-			SaveCode),
-		{ ElseCode = node([
+			TraceCode, !CI),
+		code_gen__generate_goal(CodeModel, Goal, GoalCode, !CI),
+		code_info__generate_branch_end(StoreMap, !MaybeEnd, SaveCode,
+			!CI),
+		ElseCode = node([
 			goto(label(EndLabel)) -
 				"skip to the end of the switch",
 			label(NextLabel) -
 				"next case"
-		]) },
-		{ ThisCaseCode =
+		]),
+		ThisCaseCode =
 			tree(TestCode,
 			tree(TraceCode,
 			tree(GoalCode,
 			tree(SaveCode,
 			     ElseCode))))
-		}
 	;
 		trace__maybe_generate_internal_event_code(Goal, SwitchGoalInfo,
-			TraceCode),
-		code_gen__generate_goal(CodeModel, Goal, GoalCode),
-		code_info__generate_branch_end(StoreMap, MaybeEnd0, MaybeEnd1,
-			SaveCode),
-		{ ThisCaseCode =
+			TraceCode, !CI),
+		code_gen__generate_goal(CodeModel, Goal, GoalCode, !CI),
+		code_info__generate_branch_end(StoreMap, !MaybeEnd, SaveCode,
+			!CI),
+		ThisCaseCode =
 			tree(TraceCode,
 			tree(GoalCode,
 			     SaveCode))
-		}
 	),
-	code_info__reset_to_position(BranchStart),
+	code_info__reset_to_position(BranchStart, !CI),
 		% generate the rest of the cases.
 	switch_gen__generate_cases(Cases, Var, CodeModel, CanFail,
-		SwitchGoalInfo, EndLabel, MaybeEnd1, MaybeEnd,
-		OtherCasesCode),
-	{ CasesCode = tree(ThisCaseCode, OtherCasesCode) }.
+		SwitchGoalInfo, EndLabel, !MaybeEnd, OtherCasesCode, !CI),
+	CasesCode = tree(ThisCaseCode, OtherCasesCode).
 
 %------------------------------------------------------------------------------%
Index: switch_util.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/switch_util.m,v
retrieving revision 1.15
diff -u -b -r1.15 switch_util.m
--- switch_util.m	20 Oct 2003 07:29:11 -0000	1.15
+++ switch_util.m	22 Oct 2003 07:34:20 -0000
@@ -39,16 +39,14 @@
 	;	tag_switch
 	;	other_switch.
 
-:- pred switch_util__type_cat_to_switch_cat(type_category, switch_category).
-:- mode switch_util__type_cat_to_switch_cat(in, out) is det.
+:- func switch_util__type_cat_to_switch_cat(type_category) = switch_category.
 
 	% Return the priority of a constructor test.
 	% A low number here indicates a high priority.
 	% We prioritize the tag tests so that the cheapest
 	% (most efficient) ones come first.
 	%
-:- pred switch_util__switch_priority(cons_tag, int).
-:- mode switch_util__switch_priority(in, out) is det.
+:- func switch_util__switch_priority(cons_tag) = int.
 
 	% switch_util__type_range(TypeCategory, Type, ModuleInfo, Min, Max):
 	% Determine the range [Min..Max] of an atomic type.
@@ -67,9 +65,8 @@
 	% in the list of cases, and store the cases in a map
 	% from hash values to cases.
 
-:- pred switch_util__string_hash_cases(cases_list, int,
-		map(int, cases_list)).
-:- mode switch_util__string_hash_cases(in, in, out) is det.
+:- pred switch_util__string_hash_cases(cases_list::in, int::in,
+	map(int, cases_list)::out) is det.
 
 	% switch_util__calc_hash_slots(AssocList, HashMap, Map) :-
 	%	For each (HashVal - Case) pair in AssocList,
@@ -83,9 +80,8 @@
 
 :- type hash_slot ---> hash_slot(extended_case, int).
 
-:- pred switch_util__calc_hash_slots(assoc_list(int, cases_list),
-	map(int, cases_list), map(int, hash_slot)).
-:- mode switch_util__calc_hash_slots(in, in, out) is det.
+:- pred switch_util__calc_hash_slots(assoc_list(int, cases_list)::in,
+	map(int, cases_list)::in, map(int, hash_slot)::out) is det.
 
 %-----------------------------------------------------------------------------%
 %
@@ -111,9 +107,8 @@
 	% Group together all the cases that depend on the given variable
 	% having the same primary tag value.
 
-:- pred switch_util__group_cases_by_ptag(cases_list,
-		ptag_case_map, ptag_case_map).
-:- mode switch_util__group_cases_by_ptag(in, in, out) is det.
+:- pred switch_util__group_cases_by_ptag(cases_list::in,
+	ptag_case_map::in, ptag_case_map::out) is det.
 
 	% Order the primary tags based on the number of secondary tags
 	% associated with them, putting the ones with the most secondary tags
@@ -123,9 +118,8 @@
 	% where the initial inst of the switch variable is a bound(...) inst
 	% representing a subtype.
 
-:- pred switch_util__order_ptags_by_count(ptag_count_list, ptag_case_map,
-		ptag_case_list).
-:- mode switch_util__order_ptags_by_count(in, in, out) is det.
+:- pred switch_util__order_ptags_by_count(ptag_count_list::in,
+	ptag_case_map::in, ptag_case_list::out) is det.
 
 	% switch_util__order_ptags_by_value(FirstPtag, MaxPtag,
 	%	PtagCaseMap0, PtagCaseList):
@@ -134,16 +128,14 @@
 	% Note that it is not an error for a primary tag to have no case list,
 	% since this can happen in semidet switches.
 
-:- pred switch_util__order_ptags_by_value(int, int, ptag_case_map,
-		ptag_case_list).
-:- mode switch_util__order_ptags_by_value(in, in, in, out) is det.
+:- pred switch_util__order_ptags_by_value(int::in, int::in, ptag_case_map::in,
+	ptag_case_list::out) is det.
 
 	% Find out how many secondary tags share each primary tag
 	% of the given variable.
 
-:- pred switch_util__get_ptag_counts(type, module_info, int,
-		ptag_count_map).
-:- mode switch_util__get_ptag_counts(in, in, out, out) is det.
+:- pred switch_util__get_ptag_counts((type)::in, module_info::in,
+	int::out, ptag_count_map::out) is det.
 
 %-----------------------------------------------------------------------------%
 
@@ -265,24 +257,24 @@
 %
 
 	% Convert a type category to a switch category
-switch_util__type_cat_to_switch_cat(enum_type, atomic_switch).
-switch_util__type_cat_to_switch_cat(int_type,  atomic_switch).
-switch_util__type_cat_to_switch_cat(char_type, atomic_switch).
-switch_util__type_cat_to_switch_cat(float_type, other_switch).
-switch_util__type_cat_to_switch_cat(str_type,  string_switch).
-switch_util__type_cat_to_switch_cat(higher_order_type, other_switch).
-switch_util__type_cat_to_switch_cat(user_ctor_type, tag_switch).
-switch_util__type_cat_to_switch_cat(variable_type, other_switch).
-switch_util__type_cat_to_switch_cat(tuple_type, other_switch).
-switch_util__type_cat_to_switch_cat(void_type, _) :-
+switch_util__type_cat_to_switch_cat(enum_type) = atomic_switch.
+switch_util__type_cat_to_switch_cat(int_type) =  atomic_switch.
+switch_util__type_cat_to_switch_cat(char_type) = atomic_switch.
+switch_util__type_cat_to_switch_cat(float_type) = other_switch.
+switch_util__type_cat_to_switch_cat(str_type) =  string_switch.
+switch_util__type_cat_to_switch_cat(higher_order_type) = other_switch.
+switch_util__type_cat_to_switch_cat(user_ctor_type) = tag_switch.
+switch_util__type_cat_to_switch_cat(variable_type) = other_switch.
+switch_util__type_cat_to_switch_cat(tuple_type) = other_switch.
+switch_util__type_cat_to_switch_cat(void_type) = _ :-
 	error("switch_util__type_cat_to_switch_cat: void").
-switch_util__type_cat_to_switch_cat(type_info_type, _) :-
+switch_util__type_cat_to_switch_cat(type_info_type) = _ :-
 	error("switch_util__type_cat_to_switch_cat: type_info").
-switch_util__type_cat_to_switch_cat(type_ctor_info_type, _) :-
+switch_util__type_cat_to_switch_cat(type_ctor_info_type) = _ :-
 	error("switch_util__type_cat_to_switch_cat: type_ctor_info").
-switch_util__type_cat_to_switch_cat(typeclass_info_type, _) :-
+switch_util__type_cat_to_switch_cat(typeclass_info_type) = _ :-
 	error("switch_util__type_cat_to_switch_cat: typeclass_info").
-switch_util__type_cat_to_switch_cat(base_typeclass_info_type, _) :-
+switch_util__type_cat_to_switch_cat(base_typeclass_info_type) = _ :-
 	error("switch_util__type_cat_to_switch_cat: base_typeclass_info").
 
 	% Return the priority of a constructor test.
@@ -290,25 +282,24 @@
 	% We prioritize the tag tests so that the cheapest
 	% (most efficient) ones come first.
 	%
-switch_util__switch_priority(no_tag, 0).		% should never occur
-switch_util__switch_priority(int_constant(_), 1).
-switch_util__switch_priority(reserved_address(_), 1).
-switch_util__switch_priority(shared_local_tag(_, _), 1).
-switch_util__switch_priority(single_functor, 2).
-switch_util__switch_priority(unshared_tag(_), 2).
-switch_util__switch_priority(float_constant(_), 3).
-switch_util__switch_priority(shared_remote_tag(_, _), 4).
-switch_util__switch_priority(string_constant(_), 5).
-switch_util__switch_priority(shared_with_reserved_addresses(RAs, Tag), N) :-
-	switch_util__switch_priority(Tag, N0),
-	N = N0 + list__length(RAs).
+switch_util__switch_priority(no_tag) = 0.		% should never occur
+switch_util__switch_priority(int_constant(_)) = 1.
+switch_util__switch_priority(reserved_address(_)) = 1.
+switch_util__switch_priority(shared_local_tag(_, _)) = 1.
+switch_util__switch_priority(single_functor) = 2.
+switch_util__switch_priority(unshared_tag(_)) = 2.
+switch_util__switch_priority(float_constant(_)) = 3.
+switch_util__switch_priority(shared_remote_tag(_, _)) = 4.
+switch_util__switch_priority(string_constant(_)) = 5.
+switch_util__switch_priority(shared_with_reserved_addresses(RAs, Tag)) =
+	switch_util__switch_priority(Tag) + list__length(RAs).
 	% The following tags should all never occur in switches.
-switch_util__switch_priority(pred_closure_tag(_, _, _), 6).
-switch_util__switch_priority(type_ctor_info_constant(_, _, _), 6).
-switch_util__switch_priority(base_typeclass_info_constant(_, _, _), 6).
-switch_util__switch_priority(tabling_pointer_constant(_, _), 6).
-switch_util__switch_priority(deep_profiling_proc_static_tag(_), 6).
-switch_util__switch_priority(table_io_decl_tag(_), 6).
+switch_util__switch_priority(pred_closure_tag(_, _, _)) = 6.
+switch_util__switch_priority(type_ctor_info_constant(_, _, _)) = 6.
+switch_util__switch_priority(base_typeclass_info_constant(_, _, _)) = 6.
+switch_util__switch_priority(tabling_pointer_constant(_, _)) = 6.
+switch_util__switch_priority(deep_profiling_proc_static_tag(_)) = 6.
+switch_util__switch_priority(table_io_decl_tag(_)) = 6.
 
 	% Determine the range of an atomic type.
 	% Fail if the type isn't the sort of type that has a range
Index: tag_switch.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/tag_switch.m,v
retrieving revision 1.56
diff -u -b -r1.56 tag_switch.m
--- tag_switch.m	26 May 2003 09:00:10 -0000	1.56
+++ tag_switch.m	22 Oct 2003 07:59:18 -0000
@@ -26,11 +26,10 @@
 
 	% Generate intelligent indexing code for tag based switches.
 
-:- pred tag_switch__generate(list(extended_case), prog_var, code_model,
-	can_fail, hlds_goal_info, label, branch_end, branch_end, code_tree,
-	code_info, code_info).
-:- mode tag_switch__generate(in, in, in, in, in, in, in, out, out, in, out)
-	is det.
+:- pred tag_switch__generate(list(extended_case)::in, prog_var::in,
+	code_model::in, can_fail::in, hlds_goal_info::in, label::in,
+	branch_end::in, branch_end::out, code_tree::out,
+	code_info::in, code_info::out) is det.
 
 :- implementation.
 
@@ -180,36 +179,36 @@
 			;	binary_search.
 
 tag_switch__generate(Cases, Var, CodeModel, CanFail, SwitchGoalInfo, EndLabel,
-		MaybeEnd0, MaybeEnd, Code) -->
+		!MaybeEnd, Code, !CI) :-
 	% group the cases based on primary tag value
 	% and find out how many constructors share each primary tag value
 
-	code_info__get_module_info(ModuleInfo),
-	code_info__get_proc_info(ProcInfo),
-	{ proc_info_vartypes(ProcInfo, VarTypes) },
-	{ map__lookup(VarTypes, Var, Type) },
-	{ switch_util__get_ptag_counts(Type, ModuleInfo,
-		MaxPrimary, PtagCountMap) },
-	{ map__to_assoc_list(PtagCountMap, PtagCountList) },
-	{ map__init(PtagCaseMap0) },
-	{ switch_util__group_cases_by_ptag(Cases, PtagCaseMap0, PtagCaseMap) },
-
-	{ map__count(PtagCaseMap, PtagsUsed) },
-	code_info__get_globals(Globals),
-	{ globals__lookup_int_option(Globals, dense_switch_size,
-		DenseSwitchSize) },
-	{ globals__lookup_int_option(Globals, try_switch_size,
-		TrySwitchSize) },
-	{ globals__lookup_int_option(Globals, binary_switch_size,
-		BinarySwitchSize) },
-	( { PtagsUsed >= DenseSwitchSize } ->
-		{ PrimaryMethod = jump_table }
-	; { PtagsUsed >= BinarySwitchSize } ->
-		{ PrimaryMethod = binary_search }
-	; { PtagsUsed >= TrySwitchSize } ->
-		{ PrimaryMethod = try_chain }
+	code_info__get_module_info(!.CI, ModuleInfo),
+	code_info__get_proc_info(!.CI, ProcInfo),
+	proc_info_vartypes(ProcInfo, VarTypes),
+	map__lookup(VarTypes, Var, Type),
+	switch_util__get_ptag_counts(Type, ModuleInfo,
+		MaxPrimary, PtagCountMap),
+	map__to_assoc_list(PtagCountMap, PtagCountList),
+	map__init(PtagCaseMap0),
+	switch_util__group_cases_by_ptag(Cases, PtagCaseMap0, PtagCaseMap),
+
+	map__count(PtagCaseMap, PtagsUsed),
+	code_info__get_globals(!.CI, Globals),
+	globals__lookup_int_option(Globals, dense_switch_size,
+		DenseSwitchSize),
+	globals__lookup_int_option(Globals, try_switch_size,
+		TrySwitchSize),
+	globals__lookup_int_option(Globals, binary_switch_size,
+		BinarySwitchSize),
+	( PtagsUsed >= DenseSwitchSize ->
+		PrimaryMethod = jump_table
+	; PtagsUsed >= BinarySwitchSize ->
+		PrimaryMethod = binary_search
+	; PtagsUsed >= TrySwitchSize ->
+		PrimaryMethod = try_chain
 	;
-		{ PrimaryMethod = try_me_else_chain }
+		PrimaryMethod = try_me_else_chain
 	),
 
 	% We get a register for holding the tag. The tag is needed only
@@ -221,11 +220,11 @@
 	% or if the "register" we get is likely to be slower than
 	% recomputing the tag from scratch.
 
-	code_info__produce_variable_in_reg(Var, VarCode, VarLval),
-	{ VarRval = lval(VarLval) },
-	code_info__acquire_reg(r, PtagReg),
-	code_info__release_reg(PtagReg),
-	{
+	code_info__produce_variable_in_reg(Var, VarCode, VarLval, !CI),
+	VarRval = lval(VarLval),
+	code_info__acquire_reg(r, PtagReg, !CI),
+	code_info__release_reg(PtagReg, !CI),
+	(
 		PrimaryMethod \= jump_table,
 		PtagsUsed >= 2,
 		globals__lookup_int_option(Globals, num_real_r_regs,
@@ -248,236 +247,222 @@
 	;
 		PtagCode = empty,
 		PtagRval = unop(tag, VarRval)
-	},
+	),
 
 	% We generate FailCode and EndCode here because the last case within
 	% a primary tag may not be the last case overall.
 
-	code_info__get_next_label(FailLabel),
-	{ FailLabelCode = node([
+	code_info__get_next_label(FailLabel, !CI),
+	FailLabelCode = node([
 		label(FailLabel) -
 			"switch has failed"
-	]) },
+	]),
 	(
-		{ CanFail = cannot_fail },
-		{ FailCode = node([
+		CanFail = cannot_fail,
+		FailCode = node([
 			goto(do_not_reached) - "oh-oh, det switch failed"
-		]) }
+		])
 	;
-		{ CanFail = can_fail },
-		code_info__generate_failure(FailCode)
+		CanFail = can_fail,
+		code_info__generate_failure(FailCode, !CI)
 	),
-	{ LabelledFailCode = tree(FailLabelCode, FailCode) },
+	LabelledFailCode = tree(FailLabelCode, FailCode),
 
-	{ EndCode = node([label(EndLabel) - "end of tag switch"]) },
+	EndCode = node([label(EndLabel) - "end of tag switch"]),
 
 	(
-		{ PrimaryMethod = binary_search },
-		{ switch_util__order_ptags_by_value(0, MaxPrimary, PtagCaseMap,
-			PtagCaseList) },
+		PrimaryMethod = binary_search,
+		switch_util__order_ptags_by_value(0, MaxPrimary, PtagCaseMap,
+			PtagCaseList),
 		tag_switch__generate_primary_binary_search(PtagCaseList,
 			0, MaxPrimary, PtagRval, VarRval, CodeModel, CanFail,
 			SwitchGoalInfo, EndLabel, FailLabel, PtagCountMap,
-			no, MaybeEnd, CasesCode)
+			!MaybeEnd, CasesCode, !CI)
 	;
-		{ PrimaryMethod = jump_table },
-		{ switch_util__order_ptags_by_value(0, MaxPrimary, PtagCaseMap,
-			PtagCaseList) },
+		PrimaryMethod = jump_table,
+		switch_util__order_ptags_by_value(0, MaxPrimary, PtagCaseMap,
+			PtagCaseList),
 		tag_switch__generate_primary_jump_table(PtagCaseList,
 			0, MaxPrimary, VarRval, CodeModel, SwitchGoalInfo,
-			EndLabel, FailLabel, PtagCountMap, MaybeEnd0, MaybeEnd,
-			Labels, TableCode),
-		{ SwitchCode = node([
+			EndLabel, FailLabel, PtagCountMap, !MaybeEnd,
+			Labels, TableCode, !CI),
+		SwitchCode = node([
 			computed_goto(PtagRval, Labels) -
 				"switch on primary tag"
-		]) },
-		{ CasesCode = tree(SwitchCode, TableCode) }
+		]),
+		CasesCode = tree(SwitchCode, TableCode)
 	;
-		{ PrimaryMethod = try_chain },
-		{ switch_util__order_ptags_by_count(PtagCountList, PtagCaseMap,
-			PtagCaseList0) },
-		{
+		PrimaryMethod = try_chain,
+		switch_util__order_ptags_by_count(PtagCountList, PtagCaseMap,
+			PtagCaseList0),
+		(
 			CanFail = cannot_fail,
 			PtagCaseList0 = [MostFreqCase | OtherCases]
 		->
 			list__append(OtherCases, [MostFreqCase], PtagCaseList)
 		;
 			PtagCaseList = PtagCaseList0
-		},
+		),
 		tag_switch__generate_primary_try_chain(PtagCaseList,
 			PtagRval, VarRval, CodeModel, CanFail, SwitchGoalInfo,
 			EndLabel, FailLabel, PtagCountMap, empty, empty,
-			MaybeEnd0, MaybeEnd, CasesCode)
+			!MaybeEnd, CasesCode, !CI)
 	;
-		{ PrimaryMethod = try_me_else_chain },
-		{ switch_util__order_ptags_by_count(PtagCountList, PtagCaseMap,
-			PtagCaseList) },
+		PrimaryMethod = try_me_else_chain,
+		switch_util__order_ptags_by_count(PtagCountList, PtagCaseMap,
+			PtagCaseList),
 		tag_switch__generate_primary_try_me_else_chain(PtagCaseList,
 			PtagRval, VarRval, CodeModel, CanFail, SwitchGoalInfo,
-			EndLabel, FailLabel, PtagCountMap, MaybeEnd0, MaybeEnd,
-			CasesCode)
+			EndLabel, FailLabel, PtagCountMap, !MaybeEnd,
+			CasesCode, !CI)
 	),
-
-	{ Code =
+	Code =
 		tree(VarCode,
 		tree(PtagCode,
 		tree(CasesCode,
 		tree(LabelledFailCode,
-		     EndCode))))
-	}.
+		     EndCode)))).
 
 %-----------------------------------------------------------------------------%
 
 	% Generate a switch on a primary tag value using a try-me-else chain.
 
-:- pred tag_switch__generate_primary_try_me_else_chain(ptag_case_list,
-	rval, rval, code_model, can_fail, hlds_goal_info, label, label,
-	ptag_count_map, branch_end, branch_end,
-	code_tree, code_info, code_info).
-:- mode tag_switch__generate_primary_try_me_else_chain(in, in, in, in, in, in,
-	in, in, in, in, out, out, in, out) is det.
+:- pred tag_switch__generate_primary_try_me_else_chain(ptag_case_list::in,
+	rval::in, rval::in, code_model::in, can_fail::in, hlds_goal_info::in,
+	label::in, label::in, ptag_count_map::in,
+	branch_end::in, branch_end::out, code_tree::out,
+	code_info::in, code_info::out) is det.
 
 tag_switch__generate_primary_try_me_else_chain([], _, _, _, _, _, _, _, _, _,
-		_, _) -->
-	{ error("generate_primary_try_me_else_chain: empty switch") }.
+		_, _, !CI) :-
+	error("generate_primary_try_me_else_chain: empty switch").
 tag_switch__generate_primary_try_me_else_chain([PtagGroup | PtagGroups],
 		TagRval, VarRval, CodeModel, CanFail, SwitchGoalInfo,
-		EndLabel, FailLabel, PtagCountMap, MaybeEnd0, MaybeEnd, Code)
-		-->
-	{ PtagGroup = Primary - (StagLoc - StagGoalMap) },
-	{ map__lookup(PtagCountMap, Primary, CountInfo) },
-	{ CountInfo = StagLoc1 - MaxSecondary },
-	{ StagLoc = StagLoc1 ->
+		EndLabel, FailLabel, PtagCountMap, !MaybeEnd, Code, !CI) :-
+	PtagGroup = Primary - (StagLoc - StagGoalMap),
+	map__lookup(PtagCountMap, Primary, CountInfo),
+	CountInfo = StagLoc1 - MaxSecondary,
+	( StagLoc = StagLoc1 ->
 		true
 	;
 		error("secondary tag locations differ in generate_primary_try_me_else_chain")
-	},
-	(
-		{ PtagGroups = [_|_] ; CanFail = can_fail }
-	->
-		code_info__remember_position(BranchStart),
-		code_info__get_next_label(ElseLabel),
-		{ TestRval = binop(ne, TagRval,
-			unop(mktag, const(int_const(Primary)))) },
-		{ TestCode = node([
+	),
+	( ( PtagGroups = [_|_] ; CanFail = can_fail ) ->
+		code_info__remember_position(!.CI, BranchStart),
+		code_info__get_next_label(ElseLabel, !CI),
+		TestRval = binop(ne, TagRval,
+			unop(mktag, const(int_const(Primary)))),
+		TestCode = node([
 			if_val(TestRval, label(ElseLabel)) -
 				"test primary tag only"
-		]) },
+		]),
 		tag_switch__generate_primary_tag_code(StagGoalMap,
 			Primary, MaxSecondary, StagLoc, VarRval, CodeModel,
-			SwitchGoalInfo, EndLabel, FailLabel,
-			MaybeEnd0, MaybeEnd1, TagCode),
-		{ ElseCode = node([
+			SwitchGoalInfo, EndLabel, FailLabel, !MaybeEnd,
+			TagCode, !CI),
+		ElseCode = node([
 			label(ElseLabel) -
 				"handle next primary tag"
-		]) },
-		{ ThisTagCode =
+		]),
+		ThisTagCode =
 			tree(TestCode,
 			tree(TagCode,
-			     ElseCode))
-		},
-		( { PtagGroups = [_|_] } ->
-			code_info__reset_to_position(BranchStart),
+			     ElseCode)),
+		( PtagGroups = [_|_] ->
+			code_info__reset_to_position(BranchStart, !CI),
 			tag_switch__generate_primary_try_me_else_chain(
 				PtagGroups, TagRval, VarRval, CodeModel,
 				CanFail, SwitchGoalInfo, EndLabel, FailLabel,
-				PtagCountMap, MaybeEnd1, MaybeEnd,
-				OtherTagsCode),
-			{ Code = tree(ThisTagCode, OtherTagsCode) }
+				PtagCountMap, !MaybeEnd, OtherTagsCode, !CI),
+			Code = tree(ThisTagCode, OtherTagsCode)
 		;
 			% FailLabel ought to be the next label anyway,
 			% so this goto will be optimized away (unless the
 			% layout of the failcode in the caller changes).
-			{ FailCode = node([
+			FailCode = node([
 				goto(label(FailLabel)) -
 					"primary tag with no code to handle it"
-			]) },
-			{ MaybeEnd = MaybeEnd1 },
-			{ Code = tree(ThisTagCode, FailCode) }
+			]),
+			Code = tree(ThisTagCode, FailCode)
 		)
 	;
 		tag_switch__generate_primary_tag_code(StagGoalMap,
 			Primary, MaxSecondary, StagLoc, VarRval, CodeModel,
-			SwitchGoalInfo, EndLabel, FailLabel,
-			MaybeEnd0, MaybeEnd, Code)
+			SwitchGoalInfo, EndLabel, FailLabel, !MaybeEnd, Code,
+			!CI)
 	).
 
 %-----------------------------------------------------------------------------%
 
 	% Generate a switch on a primary tag value using a try chain.
 
-:- pred tag_switch__generate_primary_try_chain(ptag_case_list,
-	rval, rval, code_model, can_fail, hlds_goal_info, label, label,
-	ptag_count_map, code_tree, code_tree, branch_end, branch_end,
-	code_tree, code_info, code_info).
-:- mode tag_switch__generate_primary_try_chain(in, in, in, in, in, in,
-	in, in, in, in, in, in, out, out, in, out) is det.
+:- pred tag_switch__generate_primary_try_chain(ptag_case_list::in,
+	rval::in, rval::in, code_model::in, can_fail::in, hlds_goal_info::in,
+	label::in, label::in, ptag_count_map::in, code_tree::in, code_tree::in,
+	branch_end::in, branch_end::out, code_tree::out,
+	code_info::in, code_info::out) is det.
 
 tag_switch__generate_primary_try_chain([], _, _, _, _, _, _, _, _, _, _, _,
-		_, _) -->
-	 { error("empty list in generate_primary_try_chain") }.
+		_, _, !CI) :-
+	 error("empty list in generate_primary_try_chain").
 tag_switch__generate_primary_try_chain([PtagGroup | PtagGroups],
 		TagRval, VarRval, CodeModel, CanFail, SwitchGoalInfo, EndLabel,
 		FailLabel, PtagCountMap, PrevTests0, PrevCases0,
-		MaybeEnd0, MaybeEnd, Code) -->
-	{ PtagGroup = Primary - (StagLoc - StagGoalMap) },
-	{ map__lookup(PtagCountMap, Primary, CountInfo) },
-	{ CountInfo = StagLoc1 - MaxSecondary },
-	{ StagLoc = StagLoc1 ->
+		!MaybeEnd, Code, !CI) :-
+	PtagGroup = Primary - (StagLoc - StagGoalMap),
+	map__lookup(PtagCountMap, Primary, CountInfo),
+	CountInfo = StagLoc1 - MaxSecondary,
+	( StagLoc = StagLoc1 ->
 		true
 	;
 		error("secondary tag locations differ in generate_primary_try_chain")
-	},
-	(
-		{ PtagGroups = [_|_] ; CanFail = can_fail }
-	->
-		code_info__remember_position(BranchStart),
-		code_info__get_next_label(ThisPtagLabel),
-		{ TestRval = binop(eq, TagRval,
-			unop(mktag, const(int_const(Primary)))) },
-		{ TestCode = node([
+	),
+	( ( PtagGroups = [_|_] ; CanFail = can_fail ) ->
+		code_info__remember_position(!.CI, BranchStart),
+		code_info__get_next_label(ThisPtagLabel, !CI),
+		TestRval = binop(eq, TagRval,
+			unop(mktag, const(int_const(Primary)))),
+		TestCode = node([
 			if_val(TestRval, label(ThisPtagLabel)) -
 				"test primary tag only"
-		]) },
-		{ LabelCode = node([
+		]),
+		LabelCode = node([
 			label(ThisPtagLabel) -
 				"this primary tag"
-		]) },
+		]),
 		tag_switch__generate_primary_tag_code(StagGoalMap,
 			Primary, MaxSecondary, StagLoc, VarRval, CodeModel,
 			SwitchGoalInfo, EndLabel, FailLabel,
-			MaybeEnd0, MaybeEnd1, TagCode),
-		{ PrevTests = tree(PrevTests0, TestCode) },
-		{ PrevCases = tree(tree(LabelCode, TagCode), PrevCases0) },
-		( { PtagGroups = [_|_] } ->
-			code_info__reset_to_position(BranchStart),
+			!MaybeEnd, TagCode, !CI),
+		PrevTests = tree(PrevTests0, TestCode),
+		PrevCases = tree(tree(LabelCode, TagCode), PrevCases0),
+		( PtagGroups = [_|_] ->
+			code_info__reset_to_position(BranchStart, !CI),
 			tag_switch__generate_primary_try_chain(PtagGroups,
 				TagRval, VarRval, CodeModel, CanFail,
 				SwitchGoalInfo, EndLabel, FailLabel,
 				PtagCountMap, PrevTests, PrevCases,
-				MaybeEnd1, MaybeEnd, Code)
+				!MaybeEnd, Code, !CI)
 		;
-			{ FailCode = node([
+			FailCode = node([
 				goto(label(FailLabel)) -
 					"primary tag with no code to handle it"
-			]) },
-			{ MaybeEnd = MaybeEnd1 },
-			{ Code = tree(PrevTests, tree(FailCode, PrevCases)) }
+			]),
+			Code = tree(PrevTests, tree(FailCode, PrevCases))
 		)
 	;
-		{ Comment = node([
+		Comment = node([
 			comment("fallthrough to last tag value") - ""
-		]) },
+		]),
 		tag_switch__generate_primary_tag_code(StagGoalMap,
 			Primary, MaxSecondary, StagLoc, VarRval,
 			CodeModel, SwitchGoalInfo, EndLabel, FailLabel,
-			MaybeEnd0, MaybeEnd, TagCode),
-		{ Code =
+			!MaybeEnd, TagCode, !CI),
+		Code =
 			tree(PrevTests0,
 			tree(Comment,
 			tree(TagCode,
 			     PrevCases0)))
-		}
 	).
 
 %-----------------------------------------------------------------------------%
@@ -485,73 +470,75 @@
 	% Generate the cases for a primary tag using a dense jump table
 	% that has an entry for all possible primary tag values.
 
-:- pred tag_switch__generate_primary_jump_table(ptag_case_list, int, int,
-	rval, code_model, hlds_goal_info, label, label, ptag_count_map,
-	branch_end, branch_end, list(label), code_tree, code_info, code_info).
-:- mode tag_switch__generate_primary_jump_table(in, in, in, in,
-	in, in, in, in, in, in, out, out, out, in, out) is det.
+:- pred tag_switch__generate_primary_jump_table(ptag_case_list::in, int::in,
+	int::in, rval::in, code_model::in, hlds_goal_info::in,
+	label::in, label::in, ptag_count_map::in,
+	branch_end::in, branch_end::out, list(label)::out, code_tree::out,
+	code_info::in, code_info::out) is det.
 
 tag_switch__generate_primary_jump_table(PtagGroups, CurPrimary, MaxPrimary,
 		VarRval, CodeModel, SwitchGoalInfo, EndLabel, FailLabel,
-		PtagCountMap, MaybeEnd0, MaybeEnd, Labels, Code) -->
-	( { CurPrimary > MaxPrimary } ->
-		{ PtagGroups = [] ->
+		PtagCountMap, !MaybeEnd, Labels, Code, !CI) :-
+	( CurPrimary > MaxPrimary ->
+		( PtagGroups = [] ->
 			true
 		;
-			error("caselist not empty when reaching limiting primary tag")
-		},
-		{ MaybeEnd = MaybeEnd0 },
-		{ Labels = [] },
-		{ Code = empty }
-	;
-		{ NextPrimary = CurPrimary + 1 },
-		( { PtagGroups = [CurPrimary - PrimaryInfo | PtagGroups1] } ->
-			{ PrimaryInfo = StagLoc - StagGoalMap },
-			{ map__lookup(PtagCountMap, CurPrimary, CountInfo) },
-			{ CountInfo = StagLoc1 - MaxSecondary },
-			{ StagLoc = StagLoc1 ->
+			error("tag_switch__generate_primary_jump_table: " ++
+				"caselist not empty " ++
+				"when reaching limiting primary tag")
+		),
+		Labels = [],
+		Code = empty
+	;
+		NextPrimary = CurPrimary + 1,
+		( PtagGroups = [CurPrimary - PrimaryInfo | PtagGroups1] ->
+			PrimaryInfo = StagLoc - StagGoalMap,
+			map__lookup(PtagCountMap, CurPrimary, CountInfo),
+			CountInfo = StagLoc1 - MaxSecondary,
+			( StagLoc = StagLoc1 ->
 				true
 			;
-				error("secondary tag locations differ in generate_primary_jump_table")
-			},
-			code_info__get_next_label(NewLabel),
-			{ LabelCode = node([
+				error("secondary tag locations differ " ++
+					"in generate_primary_jump_table")
+			),
+			code_info__get_next_label(NewLabel, !CI),
+			LabelCode = node([
 				label(NewLabel) -
 					"start of a case in primary tag switch"
-			]) },
-			( { PtagGroups1 = [] } ->
+			]),
+			( PtagGroups1 = [] ->
 				tag_switch__generate_primary_tag_code(
 					StagGoalMap, CurPrimary, MaxSecondary,
 					StagLoc, VarRval, CodeModel,
 					SwitchGoalInfo, EndLabel, FailLabel,
-					MaybeEnd0, MaybeEnd1, ThisTagCode)
+					!MaybeEnd, ThisTagCode, !CI)
 			;
-				code_info__remember_position(BranchStart),
+				code_info__remember_position(!.CI,
+					BranchStart),
 				tag_switch__generate_primary_tag_code(
 					StagGoalMap, CurPrimary, MaxSecondary,
 					StagLoc, VarRval, CodeModel,
 					SwitchGoalInfo, EndLabel, FailLabel,
-					MaybeEnd0, MaybeEnd1, ThisTagCode),
-				code_info__reset_to_position(BranchStart)
+					!MaybeEnd, ThisTagCode, !CI),
+				code_info__reset_to_position(BranchStart, !CI)
 			),
 			tag_switch__generate_primary_jump_table(PtagGroups1,
 				NextPrimary, MaxPrimary, VarRval, CodeModel,
 				SwitchGoalInfo, EndLabel, FailLabel,
-				PtagCountMap, MaybeEnd1, MaybeEnd,
-				OtherLabels, OtherCode),
-			{ Labels = [NewLabel | OtherLabels] },
-			{ Code =
+				PtagCountMap, !MaybeEnd, OtherLabels,
+				OtherCode, !CI),
+			Labels = [NewLabel | OtherLabels],
+			Code =
 				tree(LabelCode,
 				tree(ThisTagCode,
 				     OtherCode))
-			}
 		;
 			tag_switch__generate_primary_jump_table(PtagGroups,
 				NextPrimary, MaxPrimary, VarRval, CodeModel,
 				SwitchGoalInfo, EndLabel, FailLabel,
-				PtagCountMap, MaybeEnd0, MaybeEnd,
-				OtherLabels, Code),
-			{ Labels = [FailLabel | OtherLabels] }
+				PtagCountMap, !MaybeEnd, OtherLabels, Code,
+				!CI),
+			Labels = [FailLabel | OtherLabels]
 		)
 	).
 
@@ -561,96 +548,94 @@
 	% This invocation looks after primary tag values in the range
 	% MinPtag to MaxPtag (including both boundary values).
 
-:- pred tag_switch__generate_primary_binary_search(ptag_case_list, int, int,
-	rval, rval, code_model, can_fail, hlds_goal_info, label, label,
-	ptag_count_map, branch_end, branch_end, code_tree,
-	code_info, code_info).
-:- mode tag_switch__generate_primary_binary_search(in, in, in,
-	in, in, in, in, in, in, in, in, in, out, out, in, out) is det.
+:- pred tag_switch__generate_primary_binary_search(ptag_case_list::in, int::in,
+	int::in, rval::in, rval::in, code_model::in, can_fail::in,
+	hlds_goal_info::in, label::in, label::in, ptag_count_map::in,
+	branch_end::in, branch_end::out, code_tree::out,
+	code_info::in, code_info::out) is det.
 
 tag_switch__generate_primary_binary_search(PtagGroups, MinPtag, MaxPtag,
 		PtagRval, VarRval, CodeModel, CanFail, SwitchGoalInfo,
-		EndLabel, FailLabel, PtagCountMap,
-		MaybeEnd0, MaybeEnd, Code) -->
-	( { MinPtag = MaxPtag } ->
-		{ CurPrimary = MinPtag },
-		( { PtagGroups = [] } ->
+		EndLabel, FailLabel, PtagCountMap, !MaybeEnd, Code, !CI) :-
+	( MinPtag = MaxPtag ->
+		CurPrimary = MinPtag,
+		( PtagGroups = [] ->
 			% there is no code for this tag
 			(
-				{ CanFail = can_fail },
-				{ string__int_to_string(CurPrimary, PtagStr) },
-				{ string__append("no code for ptag ", PtagStr,
-					Comment) },
-				{ Code = node([
+				CanFail = can_fail,
+				string__int_to_string(CurPrimary, PtagStr),
+				string__append("no code for ptag ", PtagStr,
+					Comment),
+				Code = node([
 					goto(label(FailLabel)) -
 						Comment
-				]) }
+				])
 			;
-				{ CanFail = cannot_fail },
-				{ Code = empty }
-			),
-			{ MaybeEnd = MaybeEnd0 }
-		; { PtagGroups = [CurPrimary - PrimaryInfo] } ->
-			{ PrimaryInfo = StagLoc - StagGoalMap },
-			{ map__lookup(PtagCountMap, CurPrimary, CountInfo) },
-			{ CountInfo = StagLoc1 - MaxSecondary },
-			{ StagLoc = StagLoc1 ->
+				CanFail = cannot_fail,
+				Code = empty
+			)
+		; PtagGroups = [CurPrimary - PrimaryInfo] ->
+			PrimaryInfo = StagLoc - StagGoalMap,
+			map__lookup(PtagCountMap, CurPrimary, CountInfo),
+			CountInfo = StagLoc1 - MaxSecondary,
+			( StagLoc = StagLoc1 ->
 				true
 			;
-				error("secondary tag locations differ in generate_primary_jump_table")
-			},
+				error("secondary tag locations differ " ++
+					"in generate_primary_jump_table")
+			),
 			tag_switch__generate_primary_tag_code(
 				StagGoalMap, CurPrimary, MaxSecondary, StagLoc,
 				VarRval, CodeModel, SwitchGoalInfo, EndLabel,
-				FailLabel, MaybeEnd0, MaybeEnd, Code)
+				FailLabel, !MaybeEnd, Code, !CI)
 		;
-			{ error("caselist not singleton or empty when binary search ends") }
+			error("caselist not singleton or empty " ++
+				"when binary search ends")
 		)
 	;
-		{ LowRangeEnd = (MinPtag + MaxPtag) // 2 },
-		{ HighRangeStart = LowRangeEnd + 1 },
-		{ InLowGroup = lambda([PtagGroup::in] is semidet, (
+		LowRangeEnd = (MinPtag + MaxPtag) // 2,
+		HighRangeStart = LowRangeEnd + 1,
+		InLowGroup = (pred(PtagGroup::in) is semidet :-
 			PtagGroup = Ptag - _,
 			Ptag =< LowRangeEnd
-		)) },
-		{ list__filter(InLowGroup, PtagGroups, LowGroups, HighGroups) },
-		code_info__get_next_label(NewLabel),
-		{ string__int_to_string(MinPtag, LowStartStr) },
-		{ string__int_to_string(LowRangeEnd, LowEndStr) },
-		{ string__int_to_string(HighRangeStart, HighStartStr) },
-		{ string__int_to_string(MaxPtag, HighEndStr) },
-		{ string__append_list(["fallthrough for ptags ",
-			LowStartStr, " to ", LowEndStr], IfComment) },
-		{ string__append_list(["code for ptags ", HighStartStr,
-			" to ", HighEndStr], LabelComment) },
-		{ LowRangeEndConst = const(int_const(LowRangeEnd)) },
-		{ TestRval = binop(>, PtagRval, LowRangeEndConst) },
-		{ IfCode = node([
+		),
+		list__filter(InLowGroup, PtagGroups, LowGroups, HighGroups),
+		code_info__get_next_label(NewLabel, !CI),
+		string__int_to_string(MinPtag, LowStartStr),
+		string__int_to_string(LowRangeEnd, LowEndStr),
+		string__int_to_string(HighRangeStart, HighStartStr),
+		string__int_to_string(MaxPtag, HighEndStr),
+		string__append_list(["fallthrough for ptags ",
+			LowStartStr, " to ", LowEndStr], IfComment),
+		string__append_list(["code for ptags ", HighStartStr,
+			" to ", HighEndStr], LabelComment),
+		LowRangeEndConst = const(int_const(LowRangeEnd)),
+		TestRval = binop(>, PtagRval, LowRangeEndConst),
+		IfCode = node([
 			if_val(TestRval, label(NewLabel)) -
 				IfComment
-		]) },
-		{ LabelCode = node([
+		]),
+		LabelCode = node([
 			label(NewLabel) -
 				LabelComment
-		]) },
+		]),
 
-		code_info__remember_position(BranchStart),
+		code_info__remember_position(!.CI, BranchStart),
 		tag_switch__generate_primary_binary_search(LowGroups,
 			MinPtag, LowRangeEnd, PtagRval, VarRval, CodeModel,
 			CanFail, SwitchGoalInfo, EndLabel, FailLabel,
-			PtagCountMap, MaybeEnd0, MaybeEnd1, LowRangeCode),
-		code_info__reset_to_position(BranchStart),
+			PtagCountMap, !MaybeEnd, LowRangeCode, !CI),
+		code_info__reset_to_position(BranchStart, !CI),
 		tag_switch__generate_primary_binary_search(HighGroups,
 			HighRangeStart, MaxPtag, PtagRval, VarRval, CodeModel,
 			CanFail, SwitchGoalInfo, EndLabel, FailLabel,
-			PtagCountMap, MaybeEnd1, MaybeEnd, HighRangeCode),
+			PtagCountMap, !MaybeEnd, HighRangeCode, !CI),
 
-		{ Code =
+		Code =
 			tree(IfCode,
 			tree(LowRangeCode,
 			tree(LabelCode,
 			     HighRangeCode)))
-		}
 	).
 
 %-----------------------------------------------------------------------------%
@@ -659,52 +644,51 @@
 	% If this primary tag has secondary tags, decide whether we should
 	% use a jump table to implement the secondary switch.
 
-:- pred tag_switch__generate_primary_tag_code(stag_goal_map, tag_bits, int,
-	stag_loc, rval, code_model, hlds_goal_info, label, label,
-	branch_end, branch_end, code_tree, code_info, code_info).
-:- mode tag_switch__generate_primary_tag_code(in, in, in, in, in, in, in,
-	in, in, in, out, out, in, out) is det.
+:- pred tag_switch__generate_primary_tag_code(stag_goal_map::in, tag_bits::in,
+	int::in, stag_loc::in, rval::in, code_model::in, hlds_goal_info::in,
+	label::in, label::in, branch_end::in, branch_end::out, code_tree::out,
+	code_info::in, code_info::out) is det.
 
 tag_switch__generate_primary_tag_code(GoalMap, Primary, MaxSecondary, StagLoc,
 		Rval, CodeModel, SwitchGoalInfo, EndLabel, FailLabel,
-		MaybeEnd0, MaybeEnd, Code) -->
-	{ map__to_assoc_list(GoalMap, GoalList) },
+		!MaybeEnd, Code, !CI) :-
+	map__to_assoc_list(GoalMap, GoalList),
 	(
-		{ StagLoc = none }
+		StagLoc = none
 	->
 		% There is no secondary tag, so there is no switch on it
-		( { GoalList = [-1 - Goal] } ->
+		( GoalList = [-1 - Goal] ->
 			trace__maybe_generate_internal_event_code(Goal,
-				SwitchGoalInfo, TraceCode),
-			code_gen__generate_goal(CodeModel, Goal, GoalCode),
-			{ goal_info_get_store_map(SwitchGoalInfo, StoreMap) },
-			code_info__generate_branch_end(StoreMap,
-				MaybeEnd0, MaybeEnd, SaveCode),
-			{ GotoCode = node([
+				SwitchGoalInfo, TraceCode, !CI),
+			code_gen__generate_goal(CodeModel, Goal, GoalCode,
+				!CI),
+			goal_info_get_store_map(SwitchGoalInfo, StoreMap),
+			code_info__generate_branch_end(StoreMap, !MaybeEnd,
+				SaveCode, !CI),
+			GotoCode = node([
 				goto(label(EndLabel)) -
 					"skip to end of primary tag switch"
-			]) },
-			{ Code =
+			]),
+			Code =
 				tree(TraceCode,
 				tree(GoalCode,
 				tree(SaveCode,
 				     GotoCode)))
-			}
-		; { GoalList = [] } ->
-			{ error("no goal for non-shared tag") }
+		; GoalList = [] ->
+			error("no goal for non-shared tag")
 		;
-			{ error("more than one goal for non-shared tag") }
+			error("more than one goal for non-shared tag")
 		)
 	;
 		% There is a secondary tag, so figure out how to switch on it
-		code_info__get_globals(Globals),
-		{ globals__lookup_int_option(Globals, dense_switch_size,
-			DenseSwitchSize) },
-		{ globals__lookup_int_option(Globals, binary_switch_size,
-			BinarySwitchSize) },
-		{ globals__lookup_int_option(Globals, try_switch_size,
-			TrySwitchSize) },
-		{ MaxSecondary >= DenseSwitchSize ->
+		code_info__get_globals(!.CI, Globals),
+		globals__lookup_int_option(Globals, dense_switch_size,
+			DenseSwitchSize),
+		globals__lookup_int_option(Globals, binary_switch_size,
+			BinarySwitchSize),
+		globals__lookup_int_option(Globals, try_switch_size,
+			TrySwitchSize),
+		( MaxSecondary >= DenseSwitchSize ->
 			SecondaryMethod = jump_table
 		; MaxSecondary >= BinarySwitchSize ->
 			SecondaryMethod = binary_search
@@ -712,20 +696,20 @@
 			SecondaryMethod = try_chain
 		;
 			SecondaryMethod = try_me_else_chain
-		},
+		),
 
-		{ StagLoc = remote ->
+		( StagLoc = remote ->
 			OrigStagRval = lval(field(yes(Primary), Rval,
 				const(int_const(0)))),
 			Comment = "compute remote sec tag to switch on"
 		;
 			OrigStagRval = unop(unmkbody, Rval),
 			Comment = "compute local sec tag to switch on"
-		},
+		),
 
-		code_info__acquire_reg(r, StagReg),
-		code_info__release_reg(StagReg),
-		{
+		code_info__acquire_reg(r, StagReg, !CI),
+		code_info__release_reg(StagReg, !CI),
+		(
 			SecondaryMethod \= jump_table,
 			MaxSecondary >= 2,
 			globals__lookup_int_option(Globals, num_real_r_regs,
@@ -748,50 +732,48 @@
 		;
 			StagCode = empty,
 			StagRval = OrigStagRval
-		},
-
-
+		),
 		(
-			{ list__length(GoalList, GoalCount) },
-			{ FullGoalCount = MaxSecondary + 1 },
-			{ FullGoalCount = GoalCount }
+			list__length(GoalList, GoalCount),
+			FullGoalCount = MaxSecondary + 1,
+			FullGoalCount = GoalCount
 		->
-			{ CanFail = cannot_fail }
+			CanFail = cannot_fail
 		;
-			{ CanFail = can_fail }
+			CanFail = can_fail
 		),
 
 		(
-			{ SecondaryMethod = jump_table },
+			SecondaryMethod = jump_table,
 			tag_switch__generate_secondary_jump_table(GoalList,
 				0, MaxSecondary, CodeModel, SwitchGoalInfo,
-				EndLabel, FailLabel, MaybeEnd0, MaybeEnd,
-				Labels, CasesCode),
-			{ SwitchCode = node([
+				EndLabel, FailLabel, !MaybeEnd, Labels,
+				CasesCode, !CI),
+			SwitchCode = node([
 				computed_goto(StagRval, Labels) -
 					"switch on secondary tag"
-			]) },
-			{ Code = tree(SwitchCode, CasesCode) }
+			]),
+			Code = tree(SwitchCode, CasesCode)
 		;
-			{ SecondaryMethod = binary_search },
+			SecondaryMethod = binary_search,
 			tag_switch__generate_secondary_binary_search(GoalList,
 				0, MaxSecondary, StagRval, CodeModel, CanFail,
-				SwitchGoalInfo, EndLabel, FailLabel,
-				MaybeEnd0, MaybeEnd, Code)
+				SwitchGoalInfo, EndLabel, FailLabel, !MaybeEnd,
+				Code, !CI)
 		;
-			{ SecondaryMethod = try_chain },
+			SecondaryMethod = try_chain,
 			tag_switch__generate_secondary_try_chain(GoalList,
 				StagRval, CodeModel, CanFail, SwitchGoalInfo,
 				EndLabel, FailLabel, empty, empty,
-				MaybeEnd0, MaybeEnd, Codes),
-			{ Code = tree(StagCode, Codes) }
+				!MaybeEnd, Codes, !CI),
+			Code = tree(StagCode, Codes)
 		;
-			{ SecondaryMethod = try_me_else_chain },
+			SecondaryMethod = try_me_else_chain,
 			tag_switch__generate_secondary_try_me_else_chain(
 				GoalList, StagRval, CodeModel, CanFail,
 				SwitchGoalInfo, EndLabel, FailLabel,
-				MaybeEnd0, MaybeEnd, Codes),
-			{ Code = tree(StagCode, Codes) }
+				!MaybeEnd, Codes, !CI),
+			Code = tree(StagCode, Codes)
 		)
 	).
 
@@ -799,162 +781,153 @@
 
 	% Generate a switch on a secondary tag value using a try-me-else chain.
 
-:- pred tag_switch__generate_secondary_try_me_else_chain(stag_goal_list, rval,
-	code_model, can_fail, hlds_goal_info, label, label,
-	branch_end, branch_end, code_tree, code_info, code_info).
-:- mode tag_switch__generate_secondary_try_me_else_chain(in, in, in, in, in,
-	in, in, in, out, out, in, out) is det.
-
-tag_switch__generate_secondary_try_me_else_chain([], _, _, _, _, _, _, _, _, _)
-		-->
-	{ error("generate_secondary_try_me_else_chain: empty switch") }.
+:- pred tag_switch__generate_secondary_try_me_else_chain(stag_goal_list::in,
+	rval::in, code_model::in, can_fail::in, hlds_goal_info::in,
+	label::in, label::in, branch_end::in, branch_end::out, code_tree::out,
+	code_info::in, code_info::out) is det.
+
+tag_switch__generate_secondary_try_me_else_chain([], _, _, _, _, _, _, _, _, _,
+		!CI) :-
+	error("generate_secondary_try_me_else_chain: empty switch").
 tag_switch__generate_secondary_try_me_else_chain([Case0 | Cases0], StagRval,
 		CodeModel, CanFail, SwitchGoalInfo, EndLabel, FailLabel,
-		MaybeEnd0, MaybeEnd, Code) -->
-	{ Case0 = Secondary - Goal },
-	{ goal_info_get_store_map(SwitchGoalInfo, StoreMap) },
-	( { Cases0 = [_|_] ; CanFail = can_fail } ->
-		code_info__remember_position(BranchStart),
-		code_info__get_next_label(ElseLabel),
-		{ TestCode = node([
+		!MaybeEnd, Code, !CI) :-
+	Case0 = Secondary - Goal,
+	goal_info_get_store_map(SwitchGoalInfo, StoreMap),
+	( ( Cases0 = [_|_] ; CanFail = can_fail ) ->
+		code_info__remember_position(!.CI, BranchStart),
+		code_info__get_next_label(ElseLabel, !CI),
+		TestCode = node([
 			if_val(binop(ne, StagRval,
 					const(int_const(Secondary))),
 				label(ElseLabel))
 				- "test remote sec tag only"
-		]) },
+		]),
 		trace__maybe_generate_internal_event_code(Goal, SwitchGoalInfo,
-			TraceCode),
-		code_gen__generate_goal(CodeModel, Goal, GoalCode),
-		code_info__generate_branch_end(StoreMap, MaybeEnd0, MaybeEnd1,
-			SaveCode),
-		{ GotoLabelCode = node([
+			TraceCode, !CI),
+		code_gen__generate_goal(CodeModel, Goal, GoalCode, !CI),
+		code_info__generate_branch_end(StoreMap, !MaybeEnd,
+			SaveCode, !CI),
+		GotoLabelCode = node([
 			goto(label(EndLabel)) -
 				"skip to end of secondary tag switch",
 			label(ElseLabel) -
 				"handle next secondary tag"
-		]) },
-		{ ThisCode =
+		]),
+		ThisCode =
 			tree(TestCode,
 			tree(TraceCode,
 			tree(GoalCode,
 			tree(SaveCode,
-			     GotoLabelCode))))
-		},
-		( { Cases0 = [_|_] } ->
-			code_info__reset_to_position(BranchStart),
-			tag_switch__generate_secondary_try_me_else_chain(Cases0,
-				StagRval, CodeModel, CanFail, SwitchGoalInfo,
-				EndLabel, FailLabel, MaybeEnd1, MaybeEnd,
-				OtherCode),
-			{ Code = tree(ThisCode, OtherCode) }
+			     GotoLabelCode)))),
+		( Cases0 = [_|_] ->
+			code_info__reset_to_position(BranchStart, !CI),
+			tag_switch__generate_secondary_try_me_else_chain(
+				Cases0, StagRval, CodeModel, CanFail,
+				SwitchGoalInfo, EndLabel, FailLabel, !MaybeEnd,
+				OtherCode, !CI),
+			Code = tree(ThisCode, OtherCode)
 		;
-			{ FailCode = node([
+			FailCode = node([
 				goto(label(FailLabel)) -
 					"secondary tag does not match"
-			]) },
-			{ MaybeEnd = MaybeEnd1 },
-			{ Code = tree(ThisCode, FailCode) }
+			]),
+			Code = tree(ThisCode, FailCode)
 		)
 	;
 		trace__maybe_generate_internal_event_code(Goal, SwitchGoalInfo,
-			TraceCode),
-		code_gen__generate_goal(CodeModel, Goal, GoalCode),
-		code_info__generate_branch_end(StoreMap, MaybeEnd0, MaybeEnd,
-			SaveCode),
-		{ GotoCode = node([
+			TraceCode, !CI),
+		code_gen__generate_goal(CodeModel, Goal, GoalCode, !CI),
+		code_info__generate_branch_end(StoreMap, !MaybeEnd, SaveCode,
+			!CI),
+		GotoCode = node([
 			goto(label(EndLabel)) -
 				"skip to end of secondary tag switch"
-		]) },
-		{ Code =
+		]),
+		Code =
 			tree(TraceCode,
 			tree(GoalCode,
 			tree(SaveCode,
 			     GotoCode)))
-		}
 	).
 
 %-----------------------------------------------------------------------------%
 
 	% Generate a switch on a secondary tag value using a try chain.
 
-:- pred tag_switch__generate_secondary_try_chain(stag_goal_list, rval,
-	code_model, can_fail, hlds_goal_info, label, label,
-	code_tree, code_tree, branch_end, branch_end, code_tree, code_info,
-	code_info).
-:- mode tag_switch__generate_secondary_try_chain(in, in, in, in, in,
-	in, in, in, in, in, out, out, in, out) is det.
-
-tag_switch__generate_secondary_try_chain([], _, _, _, _, _, _, _, _, _, _, _)
-		-->
-	{ error("generate_secondary_try_chain: empty switch") }.
+:- pred tag_switch__generate_secondary_try_chain(stag_goal_list::in, rval::in,
+	code_model::in, can_fail::in, hlds_goal_info::in, label::in, label::in,
+	code_tree::in, code_tree::in, branch_end::in, branch_end::out,
+	code_tree::out, code_info::in, code_info::out) is det.
+
+tag_switch__generate_secondary_try_chain([], _, _, _, _, _, _, _, _, _, _, _,
+		!CI) :-
+	error("generate_secondary_try_chain: empty switch").
 tag_switch__generate_secondary_try_chain([Case0 | Cases0], StagRval,
 		CodeModel, CanFail, SwitchGoalInfo, EndLabel, FailLabel,
-		PrevTests0, PrevCases0, MaybeEnd0, MaybeEnd, Code) -->
-	{ Case0 = Secondary - Goal },
-	{ goal_info_get_store_map(SwitchGoalInfo, StoreMap) },
-	( { Cases0 = [_|_] ; CanFail = can_fail } ->
-		code_info__remember_position(BranchStart),
-		code_info__get_next_label(ThisStagLabel),
-		{ TestCode = node([
+		PrevTests0, PrevCases0, !MaybeEnd, Code, !CI) :-
+	Case0 = Secondary - Goal,
+	goal_info_get_store_map(SwitchGoalInfo, StoreMap),
+	( ( Cases0 = [_|_] ; CanFail = can_fail ) ->
+		code_info__remember_position(!.CI, BranchStart),
+		code_info__get_next_label(ThisStagLabel, !CI),
+		TestCode = node([
 			if_val(binop(eq, StagRval,
 					const(int_const(Secondary))),
 				label(ThisStagLabel))
 				- "test remote sec tag only"
-		]) },
-		{ LabelCode = node([
+		]),
+		LabelCode = node([
 			label(ThisStagLabel) -
 				"handle next secondary tag"
-		]) },
+		]),
 		trace__maybe_generate_internal_event_code(Goal, SwitchGoalInfo,
-			TraceCode),
-		code_gen__generate_goal(CodeModel, Goal, GoalCode),
-		code_info__generate_branch_end(StoreMap, MaybeEnd0, MaybeEnd1,
-			SaveCode),
-		{ GotoCode = node([
+			TraceCode, !CI),
+		code_gen__generate_goal(CodeModel, Goal, GoalCode, !CI),
+		code_info__generate_branch_end(StoreMap, !MaybeEnd, SaveCode,
+			!CI),
+		GotoCode = node([
 			goto(label(EndLabel)) -
 				"skip to end of secondary tag switch"
-		]) },
-		{ ThisCode =
+		]),
+		ThisCode =
 			tree(LabelCode,
 			tree(TraceCode,
 			tree(GoalCode,
 			tree(SaveCode,
-			     GotoCode))))
-		},
-		{ PrevTests = tree(PrevTests0, TestCode) },
-		{ PrevCases = tree(ThisCode, PrevCases0) },
-		( { Cases0 = [_|_] } ->
-			code_info__reset_to_position(BranchStart),
+			     GotoCode)))),
+		PrevTests = tree(PrevTests0, TestCode),
+		PrevCases = tree(ThisCode, PrevCases0),
+		( Cases0 = [_|_] ->
+			code_info__reset_to_position(BranchStart, !CI),
 			tag_switch__generate_secondary_try_chain(Cases0,
 				StagRval, CodeModel, CanFail, SwitchGoalInfo,
 				EndLabel, FailLabel, PrevTests, PrevCases,
-				MaybeEnd1, MaybeEnd, Code)
+				!MaybeEnd, Code, !CI)
 		;
-			{ FailCode = node([
+			FailCode = node([
 				goto(label(FailLabel)) -
 					"secondary tag with no code to handle it"
-			]) },
-			{ MaybeEnd = MaybeEnd1 },
-			{ Code = tree(PrevTests, tree(FailCode, PrevCases)) }
+			]),
+			Code = tree(PrevTests, tree(FailCode, PrevCases))
 		)
 	;
 		trace__maybe_generate_internal_event_code(Goal, SwitchGoalInfo,
-			TraceCode),
-		code_gen__generate_goal(CodeModel, Goal, GoalCode),
-		code_info__generate_branch_end(StoreMap, MaybeEnd0, MaybeEnd,
-			SaveCode),
-		{ GotoCode = node([
+			TraceCode, !CI),
+		code_gen__generate_goal(CodeModel, Goal, GoalCode, !CI),
+		code_info__generate_branch_end(StoreMap, !MaybeEnd, SaveCode,
+			!CI),
+		GotoCode = node([
 			goto(label(EndLabel)) -
 				"skip to end of secondary tag switch"
-		]) },
-		{ Code =
+		]),
+		Code =
 			tree(PrevTests0,
 			tree(TraceCode,
 			tree(GoalCode,
 			tree(SaveCode,
 			tree(GotoCode,
 			     PrevCases0)))))
-		}
 	).
 
 %-----------------------------------------------------------------------------%
@@ -962,67 +935,65 @@
 	% Generate the cases for a primary tag using a dense jump table
 	% that has an entry for all possible secondary tag values.
 
-:- pred tag_switch__generate_secondary_jump_table(stag_goal_list, int, int,
-	code_model, hlds_goal_info, label, label, branch_end, branch_end,
-	list(label), code_tree, code_info, code_info).
-:- mode tag_switch__generate_secondary_jump_table(in, in, in, in,
-	in, in, in, in, out, out, out, in, out) is det.
+:- pred tag_switch__generate_secondary_jump_table(stag_goal_list::in, int::in,
+	int::in, code_model::in, hlds_goal_info::in, label::in, label::in,
+	branch_end::in, branch_end::out, list(label)::out, code_tree::out,
+	code_info::in, code_info::out) is det.
 
 tag_switch__generate_secondary_jump_table(CaseList, CurSecondary, MaxSecondary,
 		CodeModel, SwitchGoalInfo, EndLabel, FailLabel,
-		MaybeEnd0, MaybeEnd, Labels, Code) -->
-	( { CurSecondary > MaxSecondary } ->
-		{ CaseList = [] ->
+		!MaybeEnd, Labels, Code, !CI) :-
+	( CurSecondary > MaxSecondary ->
+		( CaseList = [] ->
 			true
 		;
-			error("caselist not empty when reaching limiting secondary tag")
-		},
-		{ MaybeEnd = MaybeEnd0 },
-		{ Labels = [] },
-		{ Code = empty }
-	;
-		{ NextSecondary = CurSecondary + 1 },
-		( { CaseList = [CurSecondary - Goal | CaseList1] } ->
-			code_info__get_next_label(NewLabel),
-			{ LabelCode = node([
+			error("caselist not empty when reaching " ++
+				"limiting secondary tag")
+		),
+		Labels = [],
+		Code = empty
+	;
+		NextSecondary = CurSecondary + 1,
+		( CaseList = [CurSecondary - Goal | CaseList1] ->
+			code_info__get_next_label(NewLabel, !CI),
+			LabelCode = node([
 				label(NewLabel) -
 					"start of case in secondary tag switch"
-			]) },
-			code_info__remember_position(BranchStart),
+			]),
+			code_info__remember_position(!.CI, BranchStart),
 			trace__maybe_generate_internal_event_code(Goal,
-				SwitchGoalInfo, TraceCode),
-			code_gen__generate_goal(CodeModel, Goal, GoalCode),
-			{ goal_info_get_store_map(SwitchGoalInfo, StoreMap) },
+				SwitchGoalInfo, TraceCode, !CI),
+			code_gen__generate_goal(CodeModel, Goal, GoalCode, !CI),
+			goal_info_get_store_map(SwitchGoalInfo, StoreMap),
 			code_info__generate_branch_end(StoreMap,
-				MaybeEnd0, MaybeEnd1, SaveCode),
-			( { CaseList1 = [] } ->
-				[]
+				!MaybeEnd, SaveCode, !CI),
+			( CaseList1 = [] ->
+				true
 			;
-				code_info__reset_to_position(BranchStart)
+				code_info__reset_to_position(BranchStart, !CI)
 			),
-			{ GotoCode = node([
+			GotoCode = node([
 				goto(label(EndLabel)) -
 					"branch to end of tag switch"
-			]) },
+			]),
 			tag_switch__generate_secondary_jump_table(CaseList1,
 				NextSecondary, MaxSecondary, CodeModel,
 				SwitchGoalInfo, EndLabel, FailLabel,
-				MaybeEnd1, MaybeEnd, OtherLabels, OtherCode),
-			{ Labels = [NewLabel | OtherLabels] },
-			{ Code =
+				!MaybeEnd, OtherLabels, OtherCode, !CI),
+			Labels = [NewLabel | OtherLabels],
+			Code =
 				tree(LabelCode,
 				tree(TraceCode,
 				tree(GoalCode,
 				tree(SaveCode,
 				tree(GotoCode,
 				     OtherCode)))))
-			}
 		;
 			tag_switch__generate_secondary_jump_table(CaseList,
 				NextSecondary, MaxSecondary, CodeModel,
 				SwitchGoalInfo, EndLabel, FailLabel,
-				MaybeEnd0, MaybeEnd, OtherLabels, Code),
-			{ Labels = [FailLabel | OtherLabels] }
+				!MaybeEnd, OtherLabels, Code, !CI),
+			Labels = [FailLabel | OtherLabels]
 		)
 	).
 
@@ -1032,93 +1003,91 @@
 	% This invocation looks after secondary tag values in the range
 	% MinPtag to MaxPtag (including both boundary values).
 
-:- pred tag_switch__generate_secondary_binary_search(stag_goal_list, int, int,
-	rval, code_model, can_fail, hlds_goal_info, label, label,
-	branch_end, branch_end, code_tree, code_info, code_info).
-:- mode tag_switch__generate_secondary_binary_search(in, in, in,
-	in, in, in, in, in, in, in, out, out, in, out) is det.
+:- pred tag_switch__generate_secondary_binary_search(stag_goal_list::in,
+	int::in, int::in, rval::in, code_model::in, can_fail::in,
+	hlds_goal_info::in, label::in, label::in,
+	branch_end::in, branch_end::out, code_tree::out,
+	code_info::in, code_info::out) is det.
 
 tag_switch__generate_secondary_binary_search(StagGoals, MinStag, MaxStag,
 		StagRval, CodeModel, CanFail, SwitchGoalInfo, EndLabel,
-		FailLabel, MaybeEnd0, MaybeEnd, Code) -->
-	( { MinStag = MaxStag } ->
-		{ CurSec = MinStag },
-		( { StagGoals = [] } ->
+		FailLabel, !MaybeEnd, Code, !CI) :-
+	( MinStag = MaxStag ->
+		CurSec = MinStag,
+		( StagGoals = [] ->
 			% there is no code for this tag
 			(
-				{ CanFail = can_fail },
-				{ string__int_to_string(CurSec, StagStr) },
-				{ string__append("no code for ptag ", StagStr,
-					Comment) },
-				{ Code = node([
+				CanFail = can_fail,
+				string__int_to_string(CurSec, StagStr),
+				string__append("no code for ptag ", StagStr,
+					Comment),
+				Code = node([
 					goto(label(FailLabel)) -
 						Comment
-				]) }
+				])
 			;
-				{ CanFail = cannot_fail },
-				{ Code = empty }
-			),
-			{ MaybeEnd = MaybeEnd0 }
-		; { StagGoals = [CurSec - Goal] } ->
+				CanFail = cannot_fail,
+				Code = empty
+			)
+		; StagGoals = [CurSec - Goal] ->
 			trace__maybe_generate_internal_event_code(Goal,
-				SwitchGoalInfo, TraceCode),
-			code_gen__generate_goal(CodeModel, Goal, GoalCode),
-			{ goal_info_get_store_map(SwitchGoalInfo, StoreMap) },
-			code_info__generate_branch_end(StoreMap,
-				MaybeEnd0, MaybeEnd, SaveCode),
-			{ Code =
+				SwitchGoalInfo, TraceCode, !CI),
+			code_gen__generate_goal(CodeModel, Goal, GoalCode,
+				!CI),
+			goal_info_get_store_map(SwitchGoalInfo, StoreMap),
+			code_info__generate_branch_end(StoreMap, !MaybeEnd,
+				SaveCode, !CI),
+			Code =
 				tree(TraceCode,
 				tree(GoalCode,
 				     SaveCode))
-			}
 		;
-			{ error("goallist not singleton or empty when binary search ends") }
+			error("goallist not singleton or empty when binary search ends")
 		)
 	;
-		{ LowRangeEnd = (MinStag + MaxStag) // 2 },
-		{ HighRangeStart = LowRangeEnd + 1 },
-		{ InLowGroup = lambda([StagGoal::in] is semidet, (
+		LowRangeEnd = (MinStag + MaxStag) // 2,
+		HighRangeStart = LowRangeEnd + 1,
+		InLowGroup = lambda([StagGoal::in] is semidet, (
 			StagGoal = Stag - _,
 			Stag =< LowRangeEnd
-		)) },
-		{ list__filter(InLowGroup, StagGoals, LowGoals, HighGoals) },
-		code_info__get_next_label(NewLabel),
-		{ string__int_to_string(MinStag, LowStartStr) },
-		{ string__int_to_string(LowRangeEnd, LowEndStr) },
-		{ string__int_to_string(HighRangeStart, HighStartStr) },
-		{ string__int_to_string(MaxStag, HighEndStr) },
-		{ string__append_list(["fallthrough for stags ",
-			LowStartStr, " to ", LowEndStr], IfComment) },
-		{ string__append_list(["code for stags ", HighStartStr,
-			" to ", HighEndStr], LabelComment) },
-		{ LowRangeEndConst = const(int_const(LowRangeEnd)) },
-		{ TestRval = binop(>, StagRval, LowRangeEndConst) },
-		{ IfCode = node([
+		)),
+		list__filter(InLowGroup, StagGoals, LowGoals, HighGoals),
+		code_info__get_next_label(NewLabel, !CI),
+		string__int_to_string(MinStag, LowStartStr),
+		string__int_to_string(LowRangeEnd, LowEndStr),
+		string__int_to_string(HighRangeStart, HighStartStr),
+		string__int_to_string(MaxStag, HighEndStr),
+		string__append_list(["fallthrough for stags ",
+			LowStartStr, " to ", LowEndStr], IfComment),
+		string__append_list(["code for stags ", HighStartStr,
+			" to ", HighEndStr], LabelComment),
+		LowRangeEndConst = const(int_const(LowRangeEnd)),
+		TestRval = binop(>, StagRval, LowRangeEndConst),
+		IfCode = node([
 			if_val(TestRval, label(NewLabel)) -
 				IfComment
-		]) },
-		{ LabelCode = node([
+		]),
+		LabelCode = node([
 			label(NewLabel) -
 				LabelComment
-		]) },
+		]),
 
-		code_info__remember_position(BranchStart),
+		code_info__remember_position(!.CI, BranchStart),
 		tag_switch__generate_secondary_binary_search(LowGoals,
 			MinStag, LowRangeEnd, StagRval, CodeModel,
 			CanFail, SwitchGoalInfo, EndLabel, FailLabel,
-			MaybeEnd0, MaybeEnd1, LowRangeCode),
-		code_info__reset_to_position(BranchStart),
+			!MaybeEnd, LowRangeCode, !CI),
+		code_info__reset_to_position(BranchStart, !CI),
 		tag_switch__generate_secondary_binary_search(HighGoals,
 			HighRangeStart, MaxStag, StagRval, CodeModel,
 			CanFail, SwitchGoalInfo, EndLabel, FailLabel,
-			MaybeEnd1, MaybeEnd, HighRangeCode),
+			!MaybeEnd, HighRangeCode, !CI),
 
-		{ Code =
+		Code =
 			tree(IfCode,
 			tree(LowRangeCode,
 			tree(LabelCode,
 			     HighRangeCode)))
-		}
 	).
 
 %-----------------------------------------------------------------------------%
Index: trace.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/trace.m,v
retrieving revision 1.60
diff -u -b -r1.60 trace.m
--- trace.m	24 Oct 2003 06:17:49 -0000	1.60
+++ trace.m	24 Oct 2003 06:18:02 -0000
@@ -155,13 +155,12 @@
 	code_info::in, code_info::out) is det.
 
 	% Generate code to fill in the reserved stack slots.
-:- pred trace__generate_slot_fill_code(trace_info::in, code_tree::out,
-	code_info::in, code_info::out) is det.
+:- pred trace__generate_slot_fill_code(code_info::in, trace_info::in,
+	code_tree::out) is det.
 
 	% If we are doing execution tracing, generate code to prepare for
 	% a call.
-:- pred trace__prepare_for_call(code_tree::out, code_info::in, code_info::out)
-	is det.
+:- pred trace__prepare_for_call(code_info::in, code_tree::out) is det.
 
 	% If we are doing execution tracing, generate code for an internal
 	% trace event. This predicate must be called just before generating
@@ -413,27 +412,27 @@
 	).
 
 trace__setup(_ModuleInfo, PredInfo, ProcInfo, Globals, TraceSlotInfo,
-		TraceInfo) -->
-	code_info__get_proc_model(CodeModel),
-	{ globals__get_trace_level(Globals, TraceLevel) },
-	{ globals__get_trace_suppress(Globals, TraceSuppress) },
-	{ globals__lookup_bool_option(Globals, trace_table_io, TraceTableIo) },
-	{ TraceRedo = eff_trace_needs_port(PredInfo, ProcInfo, TraceLevel,
-		TraceSuppress, redo) },
-	(
-		{ TraceRedo = yes },
-		{ CodeModel = model_non }
-	->
-		code_info__get_next_label(RedoLayoutLabel),
-		{ MaybeRedoLayoutLabel = yes(RedoLayoutLabel) },
-		{ NextSlotAfterRedoLayout = 5 }
-	;
-		{ MaybeRedoLayoutLabel = no },
-		{ NextSlotAfterRedoLayout = 4 }
-	),
-	{ FromFullSlot = eff_trace_level_needs_from_full_slot(PredInfo,
-		ProcInfo, TraceLevel) },
-	{
+		TraceInfo, !CI) :-
+	CodeModel = code_info__get_proc_model(!.CI),
+	globals__get_trace_level(Globals, TraceLevel),
+	globals__get_trace_suppress(Globals, TraceSuppress),
+	globals__lookup_bool_option(Globals, trace_table_io, TraceTableIo),
+	TraceRedo = eff_trace_needs_port(PredInfo, ProcInfo, TraceLevel,
+		TraceSuppress, redo),
+	(
+		TraceRedo = yes,
+		CodeModel = model_non
+	->
+		code_info__get_next_label(RedoLayoutLabel, !CI),
+		MaybeRedoLayoutLabel = yes(RedoLayoutLabel),
+		NextSlotAfterRedoLayout = 5
+	;
+		MaybeRedoLayoutLabel = no,
+		NextSlotAfterRedoLayout = 4
+	),
+	FromFullSlot = eff_trace_level_needs_from_full_slot(PredInfo,
+		ProcInfo, TraceLevel),
+	(
 		FromFullSlot = no,
 		MaybeFromFullSlot = no,
 		MaybeFromFullSlotLval = no,
@@ -445,8 +444,8 @@
 			CodeModel, NextSlotAfterRedoLayout),
 		MaybeFromFullSlotLval = yes(CallFromFullSlot),
 		NextSlotAfterFromFull = NextSlotAfterRedoLayout + 1
-	},
-	{
+	),
+	(
 		TraceTableIo = yes,
 		MaybeIoSeqSlot = yes(NextSlotAfterFromFull),
 		IoSeqLval = llds__stack_slot_num_to_lval(CodeModel,
@@ -458,8 +457,8 @@
 		MaybeIoSeqSlot = no,
 		MaybeIoSeqLval = no,
 		NextSlotAfterIoSeq = NextSlotAfterFromFull
-	},
-	{ globals__lookup_bool_option(Globals, use_trail, yes) ->
+	),
+	( globals__lookup_bool_option(Globals, use_trail, yes) ->
 		MaybeTrailSlot = yes(NextSlotAfterIoSeq),
 		TrailLval = llds__stack_slot_num_to_lval(CodeModel,
 			NextSlotAfterIoSeq),
@@ -471,9 +470,9 @@
 		MaybeTrailSlot = no,
 		MaybeTrailLvals = no,
 		NextSlotAfterTrail = NextSlotAfterIoSeq
-	},
-	{ proc_info_get_need_maxfr_slot(ProcInfo, NeedMaxfr) },
-	{
+	),
+	proc_info_get_need_maxfr_slot(ProcInfo, NeedMaxfr),
+	(
 		NeedMaxfr = yes,
 		MaybeMaxfrSlot = yes(NextSlotAfterTrail),
 		MaxfrLval = llds__stack_slot_num_to_lval(CodeModel,
@@ -485,8 +484,8 @@
 		MaybeMaxfrSlot = no,
 		MaybeMaxfrLval = no,
 		NextSlotAfterMaxfr = NextSlotAfterTrail
-	},
-	{ proc_info_get_call_table_tip(ProcInfo, yes(_)) ->
+	),
+	( proc_info_get_call_table_tip(ProcInfo, yes(_)) ->
 		MaybeCallTableSlot = yes(NextSlotAfterMaxfr),
 		CallTableLval = llds__stack_slot_num_to_lval(CodeModel,
 			NextSlotAfterMaxfr),
@@ -494,16 +493,15 @@
 	;
 		MaybeCallTableSlot = no,
 		MaybeCallTableLval = no
-	},
-	{ TraceSlotInfo = trace_slot_info(MaybeFromFullSlot, MaybeIoSeqSlot,
-		MaybeTrailSlot, MaybeMaxfrSlot, MaybeCallTableSlot) },
-	{ TraceInfo = trace_info(TraceLevel, TraceSuppress,
+	),
+	TraceSlotInfo = trace_slot_info(MaybeFromFullSlot, MaybeIoSeqSlot,
+		MaybeTrailSlot, MaybeMaxfrSlot, MaybeCallTableSlot),
+	TraceInfo = trace_info(TraceLevel, TraceSuppress,
 		MaybeFromFullSlotLval, MaybeIoSeqLval, MaybeTrailLvals,
-		MaybeMaxfrLval, MaybeCallTableLval, MaybeRedoLayoutLabel) }.
+		MaybeMaxfrLval, MaybeCallTableLval, MaybeRedoLayoutLabel).
 
-trace__generate_slot_fill_code(TraceInfo, TraceCode) -->
-	code_info__get_proc_model(CodeModel),
-	{
+trace__generate_slot_fill_code(CI, TraceInfo, TraceCode) :-
+	CodeModel = code_info__get_proc_model(CI),
 	MaybeFromFullSlot  = TraceInfo ^ from_full_lval,
 	MaybeIoSeqSlot     = TraceInfo ^ io_seq_lval,
 	MaybeTrailLvals    = TraceInfo ^ trail_lvals,
@@ -614,13 +612,12 @@
 		MaybeCallTableLval = no,
 		TraceCode3 = empty
 	),
-	TraceCode = tree(TraceCode1, tree(TraceCode2, TraceCode3))
-	}.
+	TraceCode = tree(TraceCode1, tree(TraceCode2, TraceCode3)).
 
-trace__prepare_for_call(TraceCode) -->
-	code_info__get_maybe_trace_info(MaybeTraceInfo),
-	code_info__get_proc_model(CodeModel),
-	{
+trace__prepare_for_call(CI, TraceCode) :-
+	code_info__get_maybe_trace_info(CI, MaybeTraceInfo),
+	CodeModel = code_info__get_proc_model(CI),
+	(
 		MaybeTraceInfo = yes(TraceInfo)
 	->
 		MaybeFromFullSlot = TraceInfo ^ from_full_lval,
@@ -644,16 +641,14 @@
 		])
 	;
 		TraceCode = empty
-	}.
+	).
 
-trace__maybe_generate_internal_event_code(Goal, OutsideGoalInfo, Code) -->
-	code_info__get_maybe_trace_info(MaybeTraceInfo),
+trace__maybe_generate_internal_event_code(Goal, OutsideGoalInfo, Code, !CI) :-
+	code_info__get_maybe_trace_info(!.CI, MaybeTraceInfo),
+	( MaybeTraceInfo = yes(TraceInfo) ->
+		Goal = _ - GoalInfo,
+		goal_info_get_goal_path(GoalInfo, Path),
 	(
-		{ MaybeTraceInfo = yes(TraceInfo) }
-	->
-		{ Goal = _ - GoalInfo },
-		{ goal_info_get_goal_path(GoalInfo, Path) },
-		{
 			Path = [LastStep | _],
 			(
 				LastStep = switch(_, _),
@@ -678,98 +673,99 @@
 			Port = PortPrime
 		;
 			error("trace__generate_internal_event_code: bad path")
-		},
+		),
 		(
-			code_info__get_pred_info(PredInfo),
-			code_info__get_proc_info(ProcInfo),
-			{ eff_trace_needs_port(PredInfo, ProcInfo,
+			code_info__get_pred_info(!.CI, PredInfo),
+			code_info__get_proc_info(!.CI, ProcInfo),
+			eff_trace_needs_port(PredInfo, ProcInfo,
 				TraceInfo ^ trace_level,
-				TraceInfo ^ trace_suppress_items, Port) = yes }
+				TraceInfo ^ trace_suppress_items, Port) = yes
 		->
-			{ goal_info_get_pre_deaths(GoalInfo, PreDeaths) },
-			{ goal_info_get_context(GoalInfo, Context) },
-			{ goal_info_has_feature(OutsideGoalInfo,
+			goal_info_get_pre_deaths(GoalInfo, PreDeaths),
+			goal_info_get_context(GoalInfo, Context),
+			(
+				goal_info_has_feature(OutsideGoalInfo,
 				hide_debug_event)
 			->
 				HideEvent = yes
 			;
 				HideEvent = no
-			},
+			),
 			trace__generate_event_code(Port,
 				internal(Path, PreDeaths), TraceInfo,
-				Context, HideEvent, _, _, Code)
+				Context, HideEvent, _, _, Code, !CI)
 		;
-			{ Code = empty }
+			Code = empty
 		)
 	;
-		{ Code = empty }
+		Code = empty
 	).
 
-trace__maybe_generate_negated_event_code(Goal, OutsideGoalInfo, NegPort, Code)
-		-->
-	code_info__get_maybe_trace_info(MaybeTraceInfo),
+trace__maybe_generate_negated_event_code(Goal, OutsideGoalInfo, NegPort, Code,
+		!CI) :-
+	code_info__get_maybe_trace_info(!.CI, MaybeTraceInfo),
+	(
+		MaybeTraceInfo = yes(TraceInfo),
 	(
-		{ MaybeTraceInfo = yes(TraceInfo) },
-		{
 			NegPort = neg_failure,
 			Port = neg_failure
 		;
 			NegPort = neg_success,
 			Port = neg_success
-		},
-		code_info__get_pred_info(PredInfo),
-		code_info__get_proc_info(ProcInfo),
-		{ eff_trace_needs_port(PredInfo, ProcInfo,
+		),
+		code_info__get_pred_info(!.CI, PredInfo),
+		code_info__get_proc_info(!.CI, ProcInfo),
+		eff_trace_needs_port(PredInfo, ProcInfo,
 			TraceInfo ^ trace_level,
-			TraceInfo ^ trace_suppress_items, Port) = yes }
+			TraceInfo ^ trace_suppress_items, Port) = yes
 	->
-		{ Goal = _ - GoalInfo },
-		{ goal_info_get_goal_path(GoalInfo, Path) },
-		{ goal_info_get_context(GoalInfo, Context) },
-		{ goal_info_has_feature(OutsideGoalInfo, hide_debug_event) ->
+		Goal = _ - GoalInfo,
+		goal_info_get_goal_path(GoalInfo, Path),
+		goal_info_get_context(GoalInfo, Context),
+		( goal_info_has_feature(OutsideGoalInfo, hide_debug_event) ->
 			HideEvent = yes
 		;
 			HideEvent = no
-		},
+		),
 		trace__generate_event_code(Port, negation_end(Path),
-			TraceInfo, Context, HideEvent, _, _, Code)
+			TraceInfo, Context, HideEvent, _, _, Code, !CI)
 	;
-		{ Code = empty }
+		Code = empty
 	).
 
-trace__maybe_generate_pragma_event_code(PragmaPort, Context, Code) -->
-	code_info__get_maybe_trace_info(MaybeTraceInfo),
+trace__maybe_generate_pragma_event_code(PragmaPort, Context, Code, !CI) :-
+	code_info__get_maybe_trace_info(!.CI, MaybeTraceInfo),
 	(
-		{ MaybeTraceInfo = yes(TraceInfo) },
-		{ trace__convert_nondet_pragma_port_type(PragmaPort, Port) },
-		code_info__get_pred_info(PredInfo),
-		code_info__get_proc_info(ProcInfo),
-		{ eff_trace_needs_port(PredInfo, ProcInfo,
+		MaybeTraceInfo = yes(TraceInfo),
+		trace__convert_nondet_pragma_port_type(PragmaPort, Port),
+		code_info__get_pred_info(!.CI, PredInfo),
+		code_info__get_proc_info(!.CI, ProcInfo),
+		eff_trace_needs_port(PredInfo, ProcInfo,
 			TraceInfo ^ trace_level,
-			TraceInfo ^ trace_suppress_items, Port) = yes }
+			TraceInfo ^ trace_suppress_items, Port) = yes
 	->
 		trace__generate_event_code(Port, nondet_pragma, TraceInfo,
-			Context, no, _, _, Code)
+			Context, no, _, _, Code, !CI)
 	;
-		{ Code = empty }
+		Code = empty
 	).
 
 trace__generate_external_event_code(ExternalPort, TraceInfo, Context,
-		MaybeExternalInfo) -->
-	{ trace__convert_external_port_type(ExternalPort, Port) },
+		MaybeExternalInfo, !CI) :-
+	trace__convert_external_port_type(ExternalPort, Port),
 	(
-		code_info__get_pred_info(PredInfo),
-		code_info__get_proc_info(ProcInfo),
-		{ eff_trace_needs_port(PredInfo, ProcInfo,
+		code_info__get_pred_info(!.CI, PredInfo),
+		code_info__get_proc_info(!.CI, ProcInfo),
+		eff_trace_needs_port(PredInfo, ProcInfo,
 			TraceInfo ^ trace_level,
-			TraceInfo ^ trace_suppress_items, Port) = yes }
+			TraceInfo ^ trace_suppress_items, Port) = yes
 	->
 		trace__generate_event_code(Port, external, TraceInfo,
-			Context, no, Label, TvarDataMap, Code),
-		{ MaybeExternalInfo = yes(external_event_info(Label,
-			TvarDataMap, Code)) }
+			Context, no, Label, TvarDataMap, Code, !CI),
+		MaybeExternalInfo = yes(external_event_info(Label,
+			TvarDataMap, Code))
 	;
-		{ MaybeExternalInfo = no }
+		MaybeExternalInfo = no
 	).
 
 :- pred trace__generate_event_code(trace_port::in, trace_port_info::in,
@@ -778,48 +774,46 @@
 	code_info::in, code_info::out) is det.
 
 trace__generate_event_code(Port, PortInfo, TraceInfo, Context, HideEvent,
-		Label, TvarDataMap, Code) -->
-	code_info__get_next_label(Label),
-	code_info__get_known_variables(LiveVars0),
-	(
-		{ PortInfo = external },
-		{ LiveVars = LiveVars0 },
-		{ Path = [] }
-	;
-		{ PortInfo = internal(Path, PreDeaths) },
-		code_info__current_resume_point_vars(ResumeVars),
-		{ set__difference(PreDeaths, ResumeVars, RealPreDeaths) },
-		{ set__to_sorted_list(RealPreDeaths, RealPreDeathList) },
-		{ list__delete_elems(LiveVars0, RealPreDeathList, LiveVars) }
-	;
-		{ PortInfo = negation_end(Path) },
-		{ LiveVars = LiveVars0 }
-	;
-		{ PortInfo = nondet_pragma },
-		{ LiveVars = [] },
-		{ Port = nondet_pragma_first ->
+		Label, TvarDataMap, Code, !CI) :-
+	code_info__get_next_label(Label, !CI),
+	code_info__get_known_variables(!.CI, LiveVars0),
+	(
+		PortInfo = external,
+		LiveVars = LiveVars0,
+		Path = []
+	;
+		PortInfo = internal(Path, PreDeaths),
+		ResumeVars = code_info__current_resume_point_vars(!.CI),
+		set__difference(PreDeaths, ResumeVars, RealPreDeaths),
+		set__to_sorted_list(RealPreDeaths, RealPreDeathList),
+		list__delete_elems(LiveVars0, RealPreDeathList, LiveVars)
+	;
+		PortInfo = negation_end(Path),
+		LiveVars = LiveVars0
+	;
+		PortInfo = nondet_pragma,
+		LiveVars = [],
+		( Port = nondet_pragma_first ->
 			Path = [first]
 		; Port = nondet_pragma_later ->
 			Path = [later]
 		;
 			error("bad nondet pragma port")
-		}
+		)
+	),
+	code_info__get_varset(!.CI, VarSet),
+	code_info__get_instmap(!.CI, InstMap),
+	trace__produce_vars(LiveVars, VarSet, InstMap, set__init, TvarSet,
+		VarInfoList, ProduceCode, !CI),
+	code_info__max_reg_in_use(!.CI, MaxReg),
+	code_info__get_max_reg_in_use_at_trace(!.CI, MaxTraceReg0),
+	( MaxTraceReg0 < MaxReg ->
+		code_info__set_max_reg_in_use_at_trace(MaxReg, !CI)
+	;
+		true
 	),
-	code_info__get_varset(VarSet),
-	code_info__get_instmap(InstMap),
-	{ set__init(TvarSet0) },
-	trace__produce_vars(LiveVars, VarSet, InstMap, TvarSet0, TvarSet,
-		VarInfoList, ProduceCode),
-	code_info__max_reg_in_use(MaxReg),
-	code_info__get_max_reg_in_use_at_trace(MaxTraceReg0),
-	( { MaxTraceReg0 < MaxReg } ->
-		code_info__set_max_reg_in_use_at_trace(MaxReg)
-	;
-		[]
-	),
-	code_info__variable_locations(VarLocs),
-	code_info__get_proc_info(ProcInfo),
-	{
+	code_info__variable_locations(!.CI, VarLocs),
+	code_info__get_proc_info(!.CI, ProcInfo),
 	set__to_sorted_list(TvarSet, TvarList),
 	continuation_info__find_typeinfos_for_tvars(TvarList,
 		VarLocs, ProcInfo, TvarDataMap),
@@ -839,18 +833,17 @@
 	DeclStmt = "\t\tMR_Code *MR_jumpaddr;\n",
 	SaveStmt = "\t\tMR_save_transient_registers();\n",
 	RestoreStmt = "\t\tMR_restore_transient_registers();\n",
-	GotoStmt = "\t\tif (MR_jumpaddr != NULL) MR_GOTO(MR_jumpaddr);\n"
-	},
-	{ string__append_list([
+	GotoStmt = "\t\tif (MR_jumpaddr != NULL) MR_GOTO(MR_jumpaddr);\n",
+	string__append_list([
 		"\t\tMR_jumpaddr = MR_trace(\n",
 		"\t\t\t(const MR_Label_Layout *)\n",
 		"\t\t\t&", LabelStr, ");\n"],
-		CallStmt) },
+		CallStmt),
 	code_info__add_trace_layout_for_label(Label, Context, Port, HideEvent,
-		Path, LayoutLabelInfo),
+		Path, LayoutLabelInfo, !CI),
 	(
-		{ Port = fail },
-		{ TraceInfo ^ redo_label = yes(RedoLabel) }
+		Port = fail,
+		TraceInfo ^ redo_label = yes(RedoLabel)
 	->
 		% The layout information for the redo event is the same as
 		% for the fail event; all the non-clobbered inputs in their
@@ -863,11 +856,10 @@
 		% for the redo event, whose layout information is filled in
 		% when we get to the fail event.
 		code_info__add_trace_layout_for_label(RedoLabel, Context, redo,
-			HideEvent, Path, LayoutLabelInfo)
+			HideEvent, Path, LayoutLabelInfo, !CI)
 	;
-		[]
+		true
 	),
-	{
 	string__append_list([DeclStmt, SaveStmt, CallStmt, RestoreStmt,
 		GotoStmt], TraceStmt),
 	TraceCode =
@@ -886,8 +878,7 @@
 				may_call_mercury, no, no, yes(Label), no, yes)
 				- ""
 		]),
-	Code = tree(ProduceCode, TraceCode)
-	}.
+	Code = tree(ProduceCode, TraceCode).
 
 :- func find_lval_in_var_info(var_info) = lval.
 
@@ -931,23 +922,22 @@
 	set(tvar)::in, set(tvar)::out, list(var_info)::out, code_tree::out,
 	code_info::in, code_info::out) is det.
 
-trace__produce_vars([], _, _, Tvars, Tvars, [], empty) --> [].
+trace__produce_vars([], _, _, Tvars, Tvars, [], empty, !CI).
 trace__produce_vars([Var | Vars], VarSet, InstMap, Tvars0, Tvars,
-		[VarInfo | VarInfos], tree(VarCode, VarsCode)) -->
+		[VarInfo | VarInfos], tree(VarCode, VarsCode), !CI) :-
 	trace__produce_var(Var, VarSet, InstMap, Tvars0, Tvars1,
-		VarInfo, VarCode),
+		VarInfo, VarCode, !CI),
 	trace__produce_vars(Vars, VarSet, InstMap, Tvars1, Tvars,
-		VarInfos, VarsCode).
+		VarInfos, VarsCode, !CI).
 
 :- pred trace__produce_var(prog_var::in, prog_varset::in, instmap::in,
 	set(tvar)::in, set(tvar)::out, var_info::out, code_tree::out,
 	code_info::in, code_info::out) is det.
 
-trace__produce_var(Var, VarSet, InstMap, Tvars0, Tvars, VarInfo, VarCode) -->
-	code_info__produce_variable_in_reg_or_stack(Var, VarCode, Lval),
-	code_info__variable_type(Var, Type),
-	code_info__get_module_info(ModuleInfo),
-	{
+trace__produce_var(Var, VarSet, InstMap, !Tvars, VarInfo, VarCode, !CI) :-
+	code_info__produce_variable_in_reg_or_stack(Var, VarCode, Lval, !CI),
+	Type = code_info__variable_type(!.CI, Var),
+	code_info__get_module_info(!.CI, ModuleInfo),
 	( varset__search_name(VarSet, Var, SearchName) ->
 		Name = SearchName
 	;
@@ -962,8 +952,7 @@
 	LiveType = var(Var, Name, Type, LldsInst),
 	VarInfo = var_info(direct(Lval), LiveType),
 	type_util__real_vars(Type, TypeVars),
-	set__insert_list(Tvars0, TypeVars, Tvars)
-	}.
+	set__insert_list(!.Tvars, TypeVars, !:Tvars).
 
 %-----------------------------------------------------------------------------%
 
Index: unify_gen.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/unify_gen.m,v
retrieving revision 1.133
diff -u -b -r1.133 unify_gen.m
--- unify_gen.m	20 Oct 2003 07:29:12 -0000	1.133
+++ unify_gen.m	22 Oct 2003 08:16:02 -0000
@@ -69,49 +69,49 @@
 
 %---------------------------------------------------------------------------%
 
-unify_gen__generate_unification(CodeModel, Uni, GoalInfo, Code) -->
-	{ CodeModel = model_non ->
+unify_gen__generate_unification(CodeModel, Uni, GoalInfo, Code, !CI) :-
+	( CodeModel = model_non ->
 		error("nondet unification in unify_gen__generate_unification")
 	;
 		true
-	},
+	),
 	(
-		{ Uni = assign(Left, Right) },
-		( code_info__variable_is_forward_live(Left) ->
-			unify_gen__generate_assignment(Left, Right, Code)
+		Uni = assign(Left, Right),
+		( code_info__variable_is_forward_live(!.CI, Left) ->
+			unify_gen__generate_assignment(Left, Right, Code, !CI)
 		;
-			{ Code = empty }
+			Code = empty
 		)
 	;
-		{ Uni = construct(Var, ConsId, Args, Modes, _, _, Size) },
-		( code_info__variable_is_forward_live(Var) ->
+		Uni = construct(Var, ConsId, Args, Modes, _, _, Size),
+		( code_info__variable_is_forward_live(!.CI, Var) ->
 			unify_gen__generate_construction(Var, ConsId,
-				Args, Modes, Size, GoalInfo, Code)
+				Args, Modes, Size, GoalInfo, Code, !CI)
 		;
-			{ Code = empty }
+			Code = empty
 		)
 	;
-		{ Uni = deconstruct(Var, ConsId, Args, Modes,
-				_CanFail, _CanCGC) },
-		( { CodeModel = model_det } ->
+		Uni = deconstruct(Var, ConsId, Args, Modes,
+				_CanFail, _CanCGC),
+		( CodeModel = model_det ->
 			unify_gen__generate_det_deconstruction(Var, ConsId,
-				Args, Modes, Code)
+				Args, Modes, Code, !CI)
 		;
 			unify_gen__generate_semi_deconstruction(Var, ConsId,
-				Args, Modes, Code)
+				Args, Modes, Code, !CI)
 		)
 	;
-		{ Uni = simple_test(Var1, Var2) },
-		( { CodeModel = model_det } ->
-			{ error("det simple_test during code generation") }
+		Uni = simple_test(Var1, Var2),
+		( CodeModel = model_det ->
+			error("det simple_test during code generation")
 		;
-			unify_gen__generate_test(Var1, Var2, Code)
+			unify_gen__generate_test(Var1, Var2, Code, !CI)
 		)
 	;
 			% These should have been transformed into calls
 			% to unification procedures by polymorphism.m.
-		{ Uni = complicated_unify(_UniMode, _CanFail, _TypeInfoVars) },
-		{ error("complicated unify during code generation") }
+		Uni = complicated_unify(_UniMode, _CanFail, _TypeInfoVars),
+		error("complicated unify during code generation")
 	).
 
 %---------------------------------------------------------------------------%
@@ -123,14 +123,14 @@
 :- pred unify_gen__generate_assignment(prog_var::in, prog_var::in,
 	code_tree::out, code_info::in, code_info::out) is det.
 
-unify_gen__generate_assignment(VarA, VarB, empty) -->
-	( code_info__variable_is_forward_live(VarA) ->
-		code_info__assign_var_to_var(VarA, VarB)
+unify_gen__generate_assignment(VarA, VarB, empty, !CI) :-
+	( code_info__variable_is_forward_live(!.CI, VarA) ->
+		code_info__assign_var_to_var(VarA, VarB, !CI)
 	;
 		% For free-free unifications, the mode analysis reports
 		% them as assignment to the dead variable.  For such
 		% unifications we of course don't generate any code
-		[]
+		true
 	).
 
 %---------------------------------------------------------------------------%
@@ -144,25 +144,25 @@
 :- pred unify_gen__generate_test(prog_var::in, prog_var::in, code_tree::out,
 	code_info::in, code_info::out) is det.
 
-unify_gen__generate_test(VarA, VarB, Code) -->
-	code_info__produce_variable(VarA, CodeA, ValA),
-	code_info__produce_variable(VarB, CodeB, ValB),
-	{ CodeAB = tree(CodeA, CodeB) },
-	code_info__variable_type(VarA, Type),
-	{ Type = term__functor(term__atom("string"), [], _) ->
+unify_gen__generate_test(VarA, VarB, Code, !CI) :-
+	code_info__produce_variable(VarA, CodeA, ValA, !CI),
+	code_info__produce_variable(VarB, CodeB, ValB, !CI),
+	CodeAB = tree(CodeA, CodeB),
+	Type = code_info__variable_type(!.CI, VarA),
+	( Type = term__functor(term__atom("string"), [], _) ->
 		Op = str_eq
 	; Type = term__functor(term__atom("float"), [], _) ->
 		Op = float_eq
 	;
 		Op = eq
-	},
-	code_info__fail_if_rval_is_false(binop(Op, ValA, ValB), FailCode),
-	{ Code = tree(CodeAB, FailCode) }.
+	),
+	code_info__fail_if_rval_is_false(binop(Op, ValA, ValB), FailCode, !CI),
+	Code = tree(CodeAB, FailCode).
 
 %---------------------------------------------------------------------------%
 
-unify_gen__generate_tag_test(Var, ConsId, Sense, ElseLab, Code) -->
-	code_info__produce_variable(Var, VarCode, Rval),
+unify_gen__generate_tag_test(Var, ConsId, Sense, ElseLab, Code, !CI) :-
+	code_info__produce_variable(Var, VarCode, Rval, !CI),
 	%
 	% As an optimization, for data types with exactly two alternatives,
 	% one of which is a constant, we make sure that we test against the
@@ -170,15 +170,13 @@
 	% since a test against a constant is cheaper than a tag test.
 	%
 	(
-		{ ConsId = cons(_, Arity) },
-		{ Arity > 0 }
-	->
-		code_info__variable_type(Var, Type),
-		code_info__lookup_type_defn(Type, TypeDefn),
-		{ hlds_data__get_type_defn_body(TypeDefn, TypeBody) },
-		{
-			ConsTable = TypeBody ^ du_type_cons_tag_values
+		ConsId = cons(_, Arity),
+		Arity > 0
 		->
+		Type = code_info__variable_type(!.CI, Var),
+		TypeDefn = code_info__lookup_type_defn(!.CI, Type),
+		hlds_data__get_type_defn_body(TypeDefn, TypeBody),
+		( ConsTable = TypeBody ^ du_type_cons_tag_values ->
 			map__to_assoc_list(ConsTable, ConsList),
 			(
 				ConsList = [ConsId - _, OtherConsId - _],
@@ -195,51 +193,51 @@
 			)
 		;
 			Reverse = no
-		}
+		)
 	;
-		{ Reverse = no }
+		Reverse = no
 	),
-	code_info__variable_to_string(Var, VarName),
-	{ hlds_out__cons_id_to_string(ConsId, ConsIdName) },
+	VarName = code_info__variable_to_string(!.CI, Var),
+	hlds_out__cons_id_to_string(ConsId, ConsIdName),
 	(
-		{ Reverse = no },
-		{ string__append_list(["checking that ", VarName,
-			" has functor ", ConsIdName], Comment) },
-		{ CommentCode = node([comment(Comment) - ""]) },
-		code_info__cons_id_to_tag(Var, ConsId, Tag),
-		{ unify_gen__generate_tag_test_rval_2(Tag, Rval, TestRval) }
+		Reverse = no,
+		string__append_list(["checking that ", VarName,
+			" has functor ", ConsIdName], Comment),
+		CommentCode = node([comment(Comment) - ""]),
+		Tag = code_info__cons_id_to_tag(!.CI, Var, ConsId),
+		unify_gen__generate_tag_test_rval_2(Tag, Rval, TestRval)
 	;
-		{ Reverse = yes(TestConsId) },
-		{ string__append_list(["checking that ", VarName,
+		Reverse = yes(TestConsId),
+		string__append_list(["checking that ", VarName,
 			" has functor ", ConsIdName, " (inverted test)"],
-			Comment) },
-		{ CommentCode = node([comment(Comment) - ""]) },
-		code_info__cons_id_to_tag(Var, TestConsId, Tag),
-		{ unify_gen__generate_tag_test_rval_2(Tag, Rval, NegTestRval) },
-		{ code_util__neg_rval(NegTestRval, TestRval) }
+			Comment),
+		CommentCode = node([comment(Comment) - ""]),
+		Tag = code_info__cons_id_to_tag(!.CI, Var, TestConsId),
+		unify_gen__generate_tag_test_rval_2(Tag, Rval, NegTestRval),
+		code_util__neg_rval(NegTestRval, TestRval)
 	),
-	code_info__get_next_label(ElseLab),
+	code_info__get_next_label(ElseLab, !CI),
 	(
-		{ Sense = branch_on_success },
-		{ TheRval = TestRval }
+		Sense = branch_on_success,
+		TheRval = TestRval
 	;
-		{ Sense = branch_on_failure },
-		{ code_util__neg_rval(TestRval, TheRval) }
+		Sense = branch_on_failure,
+		code_util__neg_rval(TestRval, TheRval)
 	),
-	{ TestCode = node([
+	TestCode = node([
 		if_val(TheRval, label(ElseLab)) - "tag test"
-	]) },
-	{ Code = tree(VarCode, tree(CommentCode, TestCode)) }.
+	]),
+	Code = tree(VarCode, tree(CommentCode, TestCode)).
 
 %---------------------------------------------------------------------------%
 
 :- pred unify_gen__generate_tag_test_rval(prog_var::in, cons_id::in,
 	rval::out, code_tree::out, code_info::in, code_info::out) is det.
 
-unify_gen__generate_tag_test_rval(Var, ConsId, TestRval, Code) -->
-        code_info__produce_variable(Var, Code, Rval),
-	code_info__cons_id_to_tag(Var, ConsId, Tag),
-	{ unify_gen__generate_tag_test_rval_2(Tag, Rval, TestRval) }.
+unify_gen__generate_tag_test_rval(Var, ConsId, TestRval, Code, !CI) :-
+        code_info__produce_variable(Var, Code, Rval, !CI),
+	Tag = code_info__cons_id_to_tag(!.CI, Var, ConsId),
+	unify_gen__generate_tag_test_rval_2(Tag, Rval, TestRval).
 
 :- pred unify_gen__generate_tag_test_rval_2(cons_tag::in, rval::in, rval::out)
 	is det.
@@ -337,10 +335,10 @@
 	is det.
 
 unify_gen__generate_construction(Var, Cons, Args, Modes, Size, GoalInfo,
-	Code) -->
-	code_info__cons_id_to_tag(Var, Cons, Tag),
+		Code, !CI) :-
+	Tag = code_info__cons_id_to_tag(!.CI, Var, Cons),
 	unify_gen__generate_construction_2(Tag, Var, Args,
-		Modes, Size, GoalInfo, Code).
+		Modes, Size, GoalInfo, Code, !CI).
 
 :- pred unify_gen__generate_construction_2(cons_tag::in, prog_var::in, 
 	list(prog_var)::in, list(uni_mode)::in, maybe(term_size_value)::in,
@@ -348,136 +346,139 @@
 	is det.
 
 unify_gen__generate_construction_2(string_constant(String),
-		Var, _Args, _Modes, _, _, empty) -->
-	code_info__assign_const_to_var(Var, const(string_const(String))).
+		Var, _Args, _Modes, _, _, empty, !CI) :-
+	code_info__assign_const_to_var(Var, const(string_const(String)), !CI).
 unify_gen__generate_construction_2(int_constant(Int),
-		Var, _Args, _Modes, _, _, empty) -->
-	code_info__assign_const_to_var(Var, const(int_const(Int))).
+		Var, _Args, _Modes, _, _, empty, !CI) :-
+	code_info__assign_const_to_var(Var, const(int_const(Int)), !CI).
 unify_gen__generate_construction_2(float_constant(Float),
-		Var, _Args, _Modes, _, _, empty) -->
-	code_info__assign_const_to_var(Var, const(float_const(Float))).
-unify_gen__generate_construction_2(no_tag, Var, Args, Modes, _, _, Code) -->
-	( { Args = [Arg], Modes = [Mode] } ->
-		code_info__variable_type(Arg, Type),
+		Var, _Args, _Modes, _, _, empty, !CI) :-
+	code_info__assign_const_to_var(Var, const(float_const(Float)), !CI).
+unify_gen__generate_construction_2(no_tag, Var, Args, Modes, _, _, Code,
+		!CI) :-
+	( Args = [Arg], Modes = [Mode] ->
+		Type = code_info__variable_type(!.CI, Arg),
 		unify_gen__generate_sub_unify(ref(Var), ref(Arg),
-			Mode, Type, Code)
+			Mode, Type, Code, !CI)
 	;
-		{ error(
-		"unify_gen__generate_construction_2: no_tag: arity != 1") }
+		error("unify_gen__generate_construction_2: no_tag: " ++
+			"arity != 1")
 	).
 unify_gen__generate_construction_2(single_functor,
-		Var, Args, Modes, Size, GoalInfo, Code) -->
+		Var, Args, Modes, Size, GoalInfo, Code, !CI) :-
 	% treat single_functor the same as unshared_tag(0)
 	unify_gen__generate_construction_2(unshared_tag(0),
-		Var, Args, Modes, Size, GoalInfo, Code).
+		Var, Args, Modes, Size, GoalInfo, Code, !CI).
 unify_gen__generate_construction_2(unshared_tag(Ptag),
-		Var, Args, Modes, Size, _, Code) -->
-	code_info__get_module_info(ModuleInfo),
-	unify_gen__var_types(Args, ArgTypes),
-	{ unify_gen__generate_cons_args(Args, ArgTypes, Modes, ModuleInfo,
-		Rvals) },
-	code_info__variable_type(Var, VarType),
-	{ unify_gen__var_type_msg(VarType, VarTypeMsg) },
-	code_info__assign_cell_to_var(Var, Ptag, Rvals, Size, VarTypeMsg, Code).
+		Var, Args, Modes, Size, _, Code, !CI) :-
+	code_info__get_module_info(!.CI, ModuleInfo),
+	unify_gen__var_types(!.CI, Args, ArgTypes),
+	unify_gen__generate_cons_args(Args, ArgTypes, Modes, ModuleInfo,
+		Rvals),
+	VarType = code_info__variable_type(!.CI, Var),
+	unify_gen__var_type_msg(VarType, VarTypeMsg),
+	code_info__assign_cell_to_var(Var, Ptag, Rvals, Size, VarTypeMsg, Code,
+		!CI).
 unify_gen__generate_construction_2(shared_remote_tag(Ptag, Sectag),
-		Var, Args, Modes, Size, _, Code) -->
-	code_info__get_module_info(ModuleInfo),
-	unify_gen__var_types(Args, ArgTypes),
-	{ unify_gen__generate_cons_args(Args, ArgTypes, Modes, ModuleInfo,
-		Rvals0) },
+		Var, Args, Modes, Size, _, Code, !CI) :-
+	code_info__get_module_info(!.CI, ModuleInfo),
+	unify_gen__var_types(!.CI, Args, ArgTypes),
+	unify_gen__generate_cons_args(Args, ArgTypes, Modes, ModuleInfo,
+		Rvals0),
 		% the first field holds the secondary tag
-	{ Rvals = [yes(const(int_const(Sectag))) | Rvals0] },
-	code_info__variable_type(Var, VarType),
-	{ unify_gen__var_type_msg(VarType, VarTypeMsg) },
-	code_info__assign_cell_to_var(Var, Ptag, Rvals, Size, VarTypeMsg, Code).
+	Rvals = [yes(const(int_const(Sectag))) | Rvals0],
+	VarType = code_info__variable_type(!.CI, Var),
+	unify_gen__var_type_msg(VarType, VarTypeMsg),
+	code_info__assign_cell_to_var(Var, Ptag, Rvals, Size, VarTypeMsg, Code,
+		!CI).
 unify_gen__generate_construction_2(shared_local_tag(Bits1, Num1),
-		Var, _Args, _Modes, _, _, empty) -->
+		Var, _Args, _Modes, _, _, empty, !CI) :-
 	code_info__assign_const_to_var(Var,
-		mkword(Bits1, unop(mkbody, const(int_const(Num1))))).
+		mkword(Bits1, unop(mkbody, const(int_const(Num1)))), !CI).
 unify_gen__generate_construction_2(type_ctor_info_constant(ModuleName,
-		TypeName, TypeArity), Var, Args, _Modes, _, _, empty) -->
-	( { Args = [] } ->
-		[]
+		TypeName, TypeArity), Var, Args, _Modes, _, _, empty, !CI) :-
+	( Args = [] ->
+		true
 	;
-		{ error("unify_gen: type-info constant has args") }
+		error("unify_gen: type-info constant has args")
 	),
-	{ RttiTypeCtor = rtti_type_ctor(ModuleName, TypeName, TypeArity) },
-	{ DataAddr = rtti_addr(ctor_rtti_id(RttiTypeCtor, type_ctor_info)) },
+	RttiTypeCtor = rtti_type_ctor(ModuleName, TypeName, TypeArity),
+	DataAddr = rtti_addr(ctor_rtti_id(RttiTypeCtor, type_ctor_info)),
 	code_info__assign_const_to_var(Var,
-		const(data_addr_const(DataAddr, no))).
+		const(data_addr_const(DataAddr, no)), !CI).
 unify_gen__generate_construction_2(base_typeclass_info_constant(ModuleName,
-		ClassId, Instance), Var, Args, _Modes, _, _, empty) -->
-	( { Args = [] } ->
-		[]
+		ClassId, Instance), Var, Args, _Modes, _, _, empty, !CI) :-
+	( Args = [] ->
+		true
 	;
-		{ error("unify_gen: typeclass-info constant has args") }
+		error("unify_gen: typeclass-info constant has args")
 	),
 	code_info__assign_const_to_var(Var,
 		const(data_addr_const(rtti_addr(tc_rtti_id(
 			base_typeclass_info(ModuleName, ClassId, Instance))),
-			no))).
+			no)), !CI).
 unify_gen__generate_construction_2(tabling_pointer_constant(PredId, ProcId),
-		Var, Args, _Modes, _, _, empty) -->
-	( { Args = [] } ->
-		[]
-	;
-		{ error("unify_gen: tabling pointer constant has args") }
-	),
-	code_info__get_module_info(ModuleInfo),
-	{ ProcLabel = make_proc_label(ModuleInfo, PredId, ProcId) },
-	{ module_info_name(ModuleInfo, ModuleName) },
-	{ DataAddr = data_addr(ModuleName, tabling_pointer(ProcLabel)) },
+		Var, Args, _Modes, _, _, empty, !CI) :-
+	( Args = [] ->
+		true
+	;
+		error("unify_gen: tabling pointer constant has args")
+	),
+	code_info__get_module_info(!.CI, ModuleInfo),
+	ProcLabel = make_proc_label(ModuleInfo, PredId, ProcId),
+	module_info_name(ModuleInfo, ModuleName),
+	DataAddr = data_addr(ModuleName, tabling_pointer(ProcLabel)),
 	code_info__assign_const_to_var(Var,
-		const(data_addr_const(DataAddr, no))).
+		const(data_addr_const(DataAddr, no)), !CI).
 unify_gen__generate_construction_2(
 		deep_profiling_proc_static_tag(RttiProcLabel),
-		Var, Args, _Modes, _, _, empty) -->
-	( { Args = [] } ->
-		[]
+		Var, Args, _Modes, _, _, empty, !CI) :-
+	( Args = [] ->
+		true
 	;
-		{ error("unify_gen: deep_profiling_proc_static has args") }
+		error("unify_gen: deep_profiling_proc_static has args")
 	),
-	{ DataAddr = layout_addr(proc_static(RttiProcLabel)) },
+	DataAddr = layout_addr(proc_static(RttiProcLabel)),
 	code_info__assign_const_to_var(Var,
-		const(data_addr_const(DataAddr, no))).
+		const(data_addr_const(DataAddr, no)), !CI).
 unify_gen__generate_construction_2(table_io_decl_tag(RttiProcLabel),
-		Var, Args, _Modes, _, _, empty) -->
-	( { Args = [] } ->
-		[]
+		Var, Args, _Modes, _, _, empty, !CI) :-
+	( Args = [] ->
+		true
 	;
-		{ error("unify_gen: table_io_decl has args") }
+		error("unify_gen: table_io_decl has args")
 	),
-	{ DataAddr = layout_addr(table_io_decl(RttiProcLabel)) },
+	DataAddr = layout_addr(table_io_decl(RttiProcLabel)),
 	code_info__assign_const_to_var(Var,
-		const(data_addr_const(DataAddr, no))).
+		const(data_addr_const(DataAddr, no)), !CI).
 unify_gen__generate_construction_2(reserved_address(RA),
-		Var, Args, _Modes, _, _, empty) -->
-	( { Args = [] } ->
-		[]
+		Var, Args, _Modes, _, _, empty, !CI) :-
+	( Args = [] ->
+		true
 	;
-		{ error("unify_gen: reserved_address constant has args") }
+		error("unify_gen: reserved_address constant has args")
 	),
 	code_info__assign_const_to_var(Var,
-		unify_gen__generate_reserved_address(RA)).
+		unify_gen__generate_reserved_address(RA), !CI).
 unify_gen__generate_construction_2(
 		shared_with_reserved_addresses(_RAs, ThisTag),
-		Var, Args, Modes, Size, GoalInfo, Code) -->
+		Var, Args, Modes, Size, GoalInfo, Code, !CI) :-
 	% For shared_with_reserved_address, the sharing is only
 	% important for tag tests, not for constructions,
 	% so here we just recurse on the real representation.
 	unify_gen__generate_construction_2(ThisTag,
-		Var, Args, Modes, Size, GoalInfo, Code).
+		Var, Args, Modes, Size, GoalInfo, Code, !CI).
 unify_gen__generate_construction_2(
 		pred_closure_tag(PredId, ProcId, EvalMethod),
-		Var, Args, _Modes, _, GoalInfo, Code) -->
+		Var, Args, _Modes, _, GoalInfo, Code, !CI) :-
 	% This code constructs or extends a closure.
 	% The structure of closures is defined in runtime/mercury_ho_call.h.
 
-	code_info__get_module_info(ModuleInfo),
-	{ module_info_preds(ModuleInfo, Preds) },
-	{ map__lookup(Preds, PredId, PredInfo) },
-	{ pred_info_procedures(PredInfo, Procs) },
-	{ map__lookup(Procs, ProcId, ProcInfo) },
+	code_info__get_module_info(!.CI, ModuleInfo),
+	module_info_preds(ModuleInfo, Preds),
+	map__lookup(Preds, PredId, PredInfo),
+	pred_info_procedures(PredInfo, Procs),
+	map__lookup(Procs, ProcId, ProcInfo),
 %
 % We handle currying of a higher-order pred variable as a special case.
 % We recognize
@@ -503,53 +504,53 @@
 % to typecheck them (you get a message about call/2 should be used as a goal,
 % not an expression).
 %
-	{ proc_info_goal(ProcInfo, ProcInfoGoal) },
-	{ proc_info_interface_code_model(ProcInfo, CodeModel) },
-	{ proc_info_headvars(ProcInfo, ProcHeadVars) },
-	(
-		{ EvalMethod = normal },
-		{ Args = [CallPred | CallArgs] },
-		{ ProcHeadVars = [ProcPred | ProcArgs] },
-		{ ProcInfoGoal = generic_call(higher_order(ProcPred, _, _, _),
-			ProcArgs, _, CallDeterminism) - _GoalInfo },
-		{ determinism_to_code_model(CallDeterminism, CallCodeModel) },
+	proc_info_goal(ProcInfo, ProcInfoGoal),
+	proc_info_interface_code_model(ProcInfo, CodeModel),
+	proc_info_headvars(ProcInfo, ProcHeadVars),
+	(
+		EvalMethod = normal,
+		Args = [CallPred | CallArgs],
+		ProcHeadVars = [ProcPred | ProcArgs],
+		ProcInfoGoal = generic_call(higher_order(ProcPred, _, _, _),
+			ProcArgs, _, CallDeterminism) - _GoalInfo,
+		determinism_to_code_model(CallDeterminism, CallCodeModel),
 			% Check that the code models are compatible.
 			% Note that det is not compatible with semidet,
 			% and semidet is not compatible with nondet,
 			% since the arguments go in different registers.
 			% But det is compatible with nondet.
-		{ CodeModel = CallCodeModel
+		( CodeModel = CallCodeModel
 		; CodeModel = model_non, CallCodeModel = model_det
-		},
+		),
 			% This optimization distorts deep profiles, so don't
 			% perform it in deep profiling grades.
-		{ module_info_globals(ModuleInfo, Globals) },
-		{ globals__lookup_bool_option(Globals, profile_deep, Deep) },
-		{ Deep = no }
+		module_info_globals(ModuleInfo, Globals),
+		globals__lookup_bool_option(Globals, profile_deep, Deep),
+		Deep = no
 	->
-	    ( { CallArgs = [] } ->
+	    ( CallArgs = [] ->
 		% if there are no new arguments, we can just use the old
 		% closure
-		code_info__assign_var_to_var(Var, CallPred),
-		{ Code = empty }
+		code_info__assign_var_to_var(Var, CallPred, !CI),
+		Code = empty
 	    ;
-		code_info__get_next_label(LoopStart),
-		code_info__get_next_label(LoopTest),
-		code_info__acquire_reg(r, LoopCounter),
-		code_info__acquire_reg(r, NumOldArgs),
-		code_info__acquire_reg(r, NewClosure),
-		{ Zero = const(int_const(0)) },
-		{ One = const(int_const(1)) },
-		{ Two = const(int_const(2)) },
-		{ Three = const(int_const(3)) },
-		{ list__length(CallArgs, NumNewArgs) },
-		{ NumNewArgs_Rval = const(int_const(NumNewArgs)) },
-		{ NumNewArgsPlusThree = NumNewArgs + 3 },
-		{ NumNewArgsPlusThree_Rval =
-			const(int_const(NumNewArgsPlusThree)) },
+		code_info__get_next_label(LoopStart, !CI),
+		code_info__get_next_label(LoopTest, !CI),
+		code_info__acquire_reg(r, LoopCounter, !CI),
+		code_info__acquire_reg(r, NumOldArgs, !CI),
+		code_info__acquire_reg(r, NewClosure, !CI),
+		Zero = const(int_const(0)),
+		One = const(int_const(1)),
+		Two = const(int_const(2)),
+		Three = const(int_const(3)),
+		list__length(CallArgs, NumNewArgs),
+		NumNewArgs_Rval = const(int_const(NumNewArgs)),
+		NumNewArgsPlusThree = NumNewArgs + 3,
+		NumNewArgsPlusThree_Rval =
+			const(int_const(NumNewArgsPlusThree)),
 		code_info__produce_variable(CallPred, OldClosureCode,
-			OldClosure),
-		{ NewClosureCode = node([
+			OldClosure, !CI),
+		NewClosureCode = node([
 			comment("build new closure from old closure") - "",
 			assign(NumOldArgs,
 				lval(field(yes(0), OldClosure, Two)))
@@ -591,102 +592,102 @@
 			if_val(binop(<, lval(LoopCounter), lval(NumOldArgs)),
 				label(LoopStart))
 				- "repeat the loop?"
-		]) },
+		]),
 		unify_gen__generate_extra_closure_args(CallArgs,
-			LoopCounter, NewClosure, ExtraArgsCode),
-		code_info__release_reg(LoopCounter),
-		code_info__release_reg(NumOldArgs),
-		code_info__release_reg(NewClosure),
-		code_info__assign_lval_to_var(Var, NewClosure, AssignCode),
-		{ Code =
+			LoopCounter, NewClosure, ExtraArgsCode, !CI),
+		code_info__release_reg(LoopCounter, !CI),
+		code_info__release_reg(NumOldArgs, !CI),
+		code_info__release_reg(NewClosure, !CI),
+		code_info__assign_lval_to_var(Var, NewClosure, AssignCode,
+			!CI),
+		Code =
 			tree(OldClosureCode,
 			tree(NewClosureCode,
 			tree(ExtraArgsCode,
 			     AssignCode)))
-		}
 	    )
 	;
-		code_info__make_entry_label(ModuleInfo,
-			PredId, ProcId, no, CodeAddr),
-		{ code_util__extract_proc_label_from_code_addr(CodeAddr,
-			ProcLabel) },
-		(
-			{ EvalMethod = normal },
-			{ CallArgsRval = const(code_addr_const(CodeAddr)) }
-		;
-			{ EvalMethod = (aditi_bottom_up) },
-			{ rl__get_c_interface_rl_proc_name(ModuleInfo,
-				proc(PredId, ProcId), RLProcName) },
-			{ rl__proc_name_to_string(RLProcName, RLProcNameStr) },
-			list__map_foldl(code_info__variable_type,
-				Args, InputTypes),
-			{ rl__schema_to_string(ModuleInfo,
-				InputTypes, InputSchemaStr) },
-			{ AditiCallArgs = [
+		CodeAddr = code_info__make_entry_label(!.CI, ModuleInfo,
+			PredId, ProcId, no),
+		code_util__extract_proc_label_from_code_addr(CodeAddr,
+			ProcLabel),
+		(
+			EvalMethod = normal,
+			CallArgsRval = const(code_addr_const(CodeAddr))
+		;
+			EvalMethod = (aditi_bottom_up),
+			rl__get_c_interface_rl_proc_name(ModuleInfo,
+				proc(PredId, ProcId), RLProcName),
+			rl__proc_name_to_string(RLProcName, RLProcNameStr),
+			InputTypes = list__map(code_info__variable_type(!.CI),
+				Args),
+			rl__schema_to_string(ModuleInfo,
+				InputTypes, InputSchemaStr),
+			AditiCallArgs = [
 				const(string_const(RLProcNameStr)),
 				const(string_const(InputSchemaStr))
-			] },
+			],
 			code_info__add_static_cell_natural_types(AditiCallArgs,
-				CallArgsDataAddr),
-			{ CallArgsRval =
-				const(data_addr_const(CallArgsDataAddr, no)) }
-		),
-		{ continuation_info__generate_closure_layout(
-			ModuleInfo, PredId, ProcId, ClosureInfo) },
-		{ module_info_name(ModuleInfo, ModuleName) },
-		{ goal_info_get_context(GoalInfo, Context) },
-		{ term__context_file(Context, FileName) },
-		{ term__context_line(Context, LineNumber) },
-		{ goal_info_get_goal_path(GoalInfo, GoalPath) },
-		{ goal_path_to_string(GoalPath, GoalPathStr) },
-		code_info__get_cur_proc_label(CallerProcLabel),
-		code_info__get_next_closure_seq_no(SeqNo),
-		code_info__get_static_cell_info(StaticCellInfo0),
-		{ stack_layout__construct_closure_layout(CallerProcLabel,
+				CallArgsDataAddr, !CI),
+			CallArgsRval =
+				const(data_addr_const(CallArgsDataAddr, no))
+		),
+		continuation_info__generate_closure_layout(
+			ModuleInfo, PredId, ProcId, ClosureInfo),
+		module_info_name(ModuleInfo, ModuleName),
+		goal_info_get_context(GoalInfo, Context),
+		term__context_file(Context, FileName),
+		term__context_line(Context, LineNumber),
+		goal_info_get_goal_path(GoalInfo, GoalPath),
+		goal_path_to_string(GoalPath, GoalPathStr),
+		code_info__get_cur_proc_label(!.CI, CallerProcLabel),
+		code_info__get_next_closure_seq_no(SeqNo, !CI),
+		code_info__get_static_cell_info(!.CI, StaticCellInfo0),
+		stack_layout__construct_closure_layout(CallerProcLabel,
 			SeqNo, ClosureInfo, ProcLabel, ModuleName,
 			FileName, LineNumber, GoalPathStr,
 			StaticCellInfo0, StaticCellInfo,
-			ClosureLayoutRvalsTypes, Data) },
-		code_info__set_static_cell_info(StaticCellInfo),
-		code_info__add_closure_layout(Data),
+			ClosureLayoutRvalsTypes, Data),
+		code_info__set_static_cell_info(StaticCellInfo, !CI),
+		code_info__add_closure_layout(Data, !CI),
 		% For now, closures always have zero size, and the size slot
 		% is never looked at.
 		code_info__add_static_cell(ClosureLayoutRvalsTypes,
-			ClosureDataAddr),
-		{ ClosureLayoutRval =
-			const(data_addr_const(ClosureDataAddr, no)) },
-		{ list__length(Args, NumArgs) },
-		{ proc_info_arg_info(ProcInfo, ArgInfo) },
-		{ unify_gen__generate_pred_args(Args, ArgInfo, PredArgs) },
-		{ Vector = [
+			ClosureDataAddr, !CI),
+		ClosureLayoutRval =
+			const(data_addr_const(ClosureDataAddr, no)),
+		list__length(Args, NumArgs),
+		proc_info_arg_info(ProcInfo, ArgInfo),
+		unify_gen__generate_pred_args(Args, ArgInfo, PredArgs),
+		Vector = [
 			yes(ClosureLayoutRval),
 			yes(CallArgsRval),
 			yes(const(int_const(NumArgs)))
 			| PredArgs
-		] },
+		],
 		code_info__assign_cell_to_var(Var, 0, Vector, no, "closure",
-			Code)
+			Code, !CI)
 	).
 
 :- pred unify_gen__generate_extra_closure_args(list(prog_var)::in, lval::in,
 	lval::in, code_tree::out, code_info::in, code_info::out) is det.
 
-unify_gen__generate_extra_closure_args([], _, _, empty) --> [].
+unify_gen__generate_extra_closure_args([], _, _, empty, !CI).
 unify_gen__generate_extra_closure_args([Var | Vars], LoopCounter,
-				NewClosure, Code) -->
-	code_info__produce_variable(Var, Code0, Value),
-	{ One = const(int_const(1)) },
-	{ Code1 = node([
+		NewClosure, Code, !CI) :-
+	code_info__produce_variable(Var, Code0, Value, !CI),
+	One = const(int_const(1)),
+	Code1 = node([
 		assign(field(yes(0), lval(NewClosure), lval(LoopCounter)),
 			Value)
 			- "set new argument field",
 		assign(LoopCounter,
 			binop(+, lval(LoopCounter), One))
 			- "increment argument counter"
-	]) },
-	{ Code = tree(tree(Code0, Code1), Code2) },
+	]),
+	Code = tree(tree(Code0, Code1), Code2),
 	unify_gen__generate_extra_closure_args(Vars, LoopCounter,
-		NewClosure, Code2).
+		NewClosure, Code2, !CI).
 
 :- pred unify_gen__generate_pred_args(list(prog_var)::in, list(arg_info)::in,
 	list(maybe(rval))::out) is det.
@@ -741,13 +742,13 @@
 
 %---------------------------------------------------------------------------%
 
-:- pred unify_gen__var_types(list(prog_var)::in, list(type)::out,
-	code_info::in, code_info::out) is det.
+:- pred unify_gen__var_types(code_info::in, list(prog_var)::in,
+	list(type)::out) is det.
 
-unify_gen__var_types(Vars, Types) -->
-	code_info__get_proc_info(ProcInfo),
-	{ proc_info_vartypes(ProcInfo, VarTypes) },
-	{ map__apply_to_list(Vars, VarTypes, Types) }.
+unify_gen__var_types(CI, Vars, Types) :-
+	code_info__get_proc_info(CI, ProcInfo),
+	proc_info_vartypes(ProcInfo, VarTypes),
+	map__apply_to_list(Vars, VarTypes, Types).
 
 %---------------------------------------------------------------------------%
 
@@ -776,91 +777,92 @@
 	% assignment unifications are cached.
 
 :- pred unify_gen__generate_det_deconstruction(prog_var::in, cons_id::in,
-	list(prog_var)::in, list(uni_mode)::in,
-	code_tree::out, code_info::in, code_info::out) is det.
+	list(prog_var)::in, list(uni_mode)::in, code_tree::out,
+	code_info::in, code_info::out) is det.
 
-unify_gen__generate_det_deconstruction(Var, Cons, Args, Modes, Code) -->
-	code_info__cons_id_to_tag(Var, Cons, Tag),
+unify_gen__generate_det_deconstruction(Var, Cons, Args, Modes, Code, !CI) :-
+	Tag = code_info__cons_id_to_tag(!.CI, Var, Cons),
 	unify_gen__generate_det_deconstruction_2(Var, Cons, Args, Modes,
-		Tag, Code).
+		Tag, Code, !CI).
 
 :- pred unify_gen__generate_det_deconstruction_2(prog_var::in, cons_id::in,
 	list(prog_var)::in, list(uni_mode)::in, cons_tag::in,
 	code_tree::out, code_info::in, code_info::out) is det.
 
-unify_gen__generate_det_deconstruction_2(Var, Cons, Args, Modes, Tag, Code) -->
+unify_gen__generate_det_deconstruction_2(Var, Cons, Args, Modes, Tag, Code,
+		!CI) :-
 	% For constants, if the deconstruction is det, then we already know
 	% the value of the constant, so Code = empty.
 	(
-		{ Tag = string_constant(_String) },
-		{ Code = empty }
+		Tag = string_constant(_String),
+		Code = empty
 	;
-		{ Tag = int_constant(_Int) },
-		{ Code = empty }
+		Tag = int_constant(_Int),
+		Code = empty
 	;
-		{ Tag = float_constant(_Float) },
-		{ Code = empty }
+		Tag = float_constant(_Float),
+		Code = empty
 	;
-		{ Tag = pred_closure_tag(_, _, _) },
-		{ Code = empty }
+		Tag = pred_closure_tag(_, _, _),
+		Code = empty
 	;
-		{ Tag = type_ctor_info_constant(_, _, _) },
-		{ Code = empty }
+		Tag = type_ctor_info_constant(_, _, _),
+		Code = empty
 	;
-		{ Tag = base_typeclass_info_constant(_, _, _) },
-		{ Code = empty }
+		Tag = base_typeclass_info_constant(_, _, _),
+		Code = empty
 	;
-		{ Tag = tabling_pointer_constant(_, _) },
-		{ Code = empty }
+		Tag = tabling_pointer_constant(_, _),
+		Code = empty
 	;
-		{ Tag = deep_profiling_proc_static_tag(_) },
-		{ Code = empty }
+		Tag = deep_profiling_proc_static_tag(_),
+		Code = empty
 	;
-		{ Tag = table_io_decl_tag(_) },
-		{ error("unify_gen__generate_det_deconstruction: table_io_decl_tag") }
+		Tag = table_io_decl_tag(_),
+		error("unify_gen__generate_det_deconstruction: table_io_decl_tag")
 	;
-		{ Tag = no_tag },
-		( { Args = [Arg], Modes = [Mode] } ->
-			code_info__variable_type(Arg, Type),
+		Tag = no_tag,
+		( Args = [Arg], Modes = [Mode] ->
+			Type = code_info__variable_type(!.CI, Arg),
 			unify_gen__generate_sub_unify(ref(Var), ref(Arg),
-				Mode, Type, Code)
+				Mode, Type, Code, !CI)
 		;
-			{ error("unify_gen__generate_det_deconstruction: no_tag: arity != 1") }
+			error("unify_gen__generate_det_deconstruction: no_tag: arity != 1")
 		)
 	;
-		{ Tag = single_functor },
+		Tag = single_functor,
 		% treat single_functor the same as unshared_tag(0)
 		unify_gen__generate_det_deconstruction_2(Var, Cons, Args,
-			Modes, unshared_tag(0), Code)
+			Modes, unshared_tag(0), Code, !CI)
 	;
-		{ Tag = unshared_tag(Ptag) },
-		{ Rval = var(Var) },
-		{ unify_gen__make_fields_and_argvars(Args, Rval, 0,
-			Ptag, Fields, ArgVars) },
-		unify_gen__var_types(Args, ArgTypes),
+		Tag = unshared_tag(Ptag),
+		Rval = var(Var),
+		unify_gen__make_fields_and_argvars(Args, Rval, 0,
+			Ptag, Fields, ArgVars),
+		unify_gen__var_types(!.CI, Args, ArgTypes),
 		unify_gen__generate_unify_args(Fields, ArgVars,
-			Modes, ArgTypes, Code)
+			Modes, ArgTypes, Code, !CI)
 	;
-		{ Tag = shared_remote_tag(Ptag, _Sectag1) },
-		{ Rval = var(Var) },
-		{ unify_gen__make_fields_and_argvars(Args, Rval, 1,
-			Ptag, Fields, ArgVars) },
-		unify_gen__var_types(Args, ArgTypes),
+		Tag = shared_remote_tag(Ptag, _Sectag1),
+		Rval = var(Var),
+		unify_gen__make_fields_and_argvars(Args, Rval, 1,
+			Ptag, Fields, ArgVars),
+		unify_gen__var_types(!.CI, Args, ArgTypes),
 		unify_gen__generate_unify_args(Fields, ArgVars,
-			Modes, ArgTypes, Code)
+			Modes, ArgTypes, Code, !CI)
 	;
-		{ Tag = shared_local_tag(_Ptag, _Sectag2) },
-		{ Code = empty } % if this is det, then nothing happens
+		Tag = shared_local_tag(_Ptag, _Sectag2),
+		Code = empty % if this is det, then nothing happens
 	;
-		{ Tag = reserved_address(_RA) },
-		{ Code = empty } % if this is det, then nothing happens
+		Tag = reserved_address(_RA),
+		Code = empty % if this is det, then nothing happens
 	;
 		% For shared_with_reserved_address, the sharing is only
 		% important for tag tests, not for det deconstructions,
 		% so here we just recurse on the real representation.
-		{ Tag = shared_with_reserved_addresses(_RAs, ThisTag) },
+		Tag = shared_with_reserved_addresses(_RAs, ThisTag),
 		unify_gen__generate_det_deconstruction_2(Var, Cons, Args, Modes,
-			ThisTag, Code)
+			ThisTag, Code, !CI)
 	).
 
 %---------------------------------------------------------------------------%
@@ -873,23 +875,22 @@
 	list(prog_var)::in, list(uni_mode)::in,
 	code_tree::out, code_info::in, code_info::out) is det.
 
-unify_gen__generate_semi_deconstruction(Var, Tag, Args, Modes, Code) -->
+unify_gen__generate_semi_deconstruction(Var, Tag, Args, Modes, Code, !CI) :-
 	unify_gen__generate_tag_test(Var, Tag, branch_on_success,
-		SuccLab, TagTestCode),
-	code_info__remember_position(AfterUnify),
-	code_info__generate_failure(FailCode),
-	code_info__reset_to_position(AfterUnify),
+		SuccLab, TagTestCode, !CI),
+	code_info__remember_position(!.CI, AfterUnify),
+	code_info__generate_failure(FailCode, !CI),
+	code_info__reset_to_position(AfterUnify, !CI),
 	unify_gen__generate_det_deconstruction(Var, Tag, Args, Modes,
-		DeconsCode),
-	{ SuccessLabelCode = node([
+		DeconsCode, !CI),
+	SuccessLabelCode = node([
 		label(SuccLab) - ""
-	]) },
-	{ Code =
+	]),
+	Code =
 		tree(TagTestCode,
 		tree(FailCode,
 		tree(SuccessLabelCode,
-		     DeconsCode)))
-	}.
+		     DeconsCode))).
 
 %---------------------------------------------------------------------------%
 
@@ -897,26 +898,26 @@
 	% for the arguments of a construction.
 
 :- pred unify_gen__generate_unify_args(list(uni_val)::in, list(uni_val)::in,
-	list(uni_mode)::in, list(type)::in,
-	code_tree::out, code_info::in, code_info::out) is det.
+	list(uni_mode)::in, list(type)::in, code_tree::out,
+	code_info::in, code_info::out) is det.
 
-unify_gen__generate_unify_args(Ls, Rs, Ms, Ts, Code) -->
-	( unify_gen__generate_unify_args_2(Ls, Rs, Ms, Ts, Code0) ->
-		{ Code = Code0 }
+unify_gen__generate_unify_args(Ls, Rs, Ms, Ts, Code, !CI) :-
+	( unify_gen__generate_unify_args_2(Ls, Rs, Ms, Ts, Code0, !CI) ->
+		Code = Code0
 	;
-		{ error("unify_gen__generate_unify_args: length mismatch") }
+		error("unify_gen__generate_unify_args: length mismatch")
 	).
 
 :- pred unify_gen__generate_unify_args_2(list(uni_val)::in, list(uni_val)::in,
-	list(uni_mode)::in, list(type)::in,
-	code_tree::out, code_info::in, code_info::out) is semidet.
+	list(uni_mode)::in, list(type)::in, code_tree::out,
+	code_info::in, code_info::out) is semidet.
 
-unify_gen__generate_unify_args_2([], [], [], [], empty) --> [].
+unify_gen__generate_unify_args_2([], [], [], [], empty, !CI).
 unify_gen__generate_unify_args_2([L | Ls], [R | Rs], [M | Ms], [T | Ts],
-		Code) -->
-	unify_gen__generate_sub_unify(L, R, M, T, CodeA),
-	unify_gen__generate_unify_args_2(Ls, Rs, Ms, Ts, CodeB),
-	{ Code = tree(CodeA, CodeB) }.
+		Code, !CI) :-
+	unify_gen__generate_sub_unify(L, R, M, T, CodeA, !CI),
+	unify_gen__generate_unify_args_2(Ls, Rs, Ms, Ts, CodeB, !CI),
+	Code = tree(CodeA, CodeB).
 
 %---------------------------------------------------------------------------%
 
@@ -925,41 +926,41 @@
 :- pred unify_gen__generate_sub_unify(uni_val::in, uni_val::in, uni_mode::in,
 	(type)::in, code_tree::out, code_info::in, code_info::out) is det.
 
-unify_gen__generate_sub_unify(L, R, Mode, Type, Code) -->
-	{ Mode = ((LI - RI) -> (LF - RF)) },
-	code_info__get_module_info(ModuleInfo),
-	{ mode_to_arg_mode(ModuleInfo, (LI -> LF), Type, LeftMode) },
-	{ mode_to_arg_mode(ModuleInfo, (RI -> RF), Type, RightMode) },
+unify_gen__generate_sub_unify(L, R, Mode, Type, Code, !CI) :-
+	Mode = ((LI - RI) -> (LF - RF)),
+	code_info__get_module_info(!.CI, ModuleInfo),
+	mode_to_arg_mode(ModuleInfo, (LI -> LF), Type, LeftMode),
+	mode_to_arg_mode(ModuleInfo, (RI -> RF), Type, RightMode),
 	(
 			% Input - input == test unification
-		{ LeftMode = top_in },
-		{ RightMode = top_in }
+		LeftMode = top_in,
+		RightMode = top_in
 	->
 		% This shouldn't happen, since mode analysis should
 		% avoid creating any tests in the arguments
 		% of a construction or deconstruction unification.
-		{ error("test in arg of [de]construction") }
+		error("test in arg of [de]construction")
 	;
 			% Input - Output== assignment ->
-		{ LeftMode = top_in },
-		{ RightMode = top_out }
+		LeftMode = top_in,
+		RightMode = top_out
 	->
-		unify_gen__generate_sub_assign(R, L, Code)
+		unify_gen__generate_sub_assign(R, L, Code, !CI)
 	;
 			% Output - Input== assignment <-
-		{ LeftMode = top_out },
-		{ RightMode = top_in }
+		LeftMode = top_out,
+		RightMode = top_in
 	->
-		unify_gen__generate_sub_assign(L, R, Code)
+		unify_gen__generate_sub_assign(L, R, Code, !CI)
 	;
-		{ LeftMode = top_unused },
-		{ RightMode = top_unused }
+		LeftMode = top_unused,
+		RightMode = top_unused
 	->
-		{ Code = empty } % free-free - ignore
+		Code = empty % free-free - ignore
 			% XXX I think this will have to change
 			% if we start to support aliasing
 	;
-		{ error("unify_gen__generate_sub_unify: some strange unify") }
+		error("unify_gen__generate_sub_unify: some strange unify")
 	).
 
 %---------------------------------------------------------------------------%
@@ -968,40 +969,41 @@
 	code_tree::out, code_info::in, code_info::out) is det.
 
 	% Assignment between two lvalues - cannot happen.
-unify_gen__generate_sub_assign(lval(_Lval0), lval(_Rval), _Code) -->
-	{ error("unify_gen__generate_sub_assign: lval/lval") }.
+unify_gen__generate_sub_assign(lval(_Lval0), lval(_Rval), _Code, !CI) :-
+	error("unify_gen__generate_sub_assign: lval/lval").
 
 	% Assignment from a variable to an lvalue - cannot cache
 	% so generate immediately.
-unify_gen__generate_sub_assign(lval(Lval0), ref(Var), Code) -->
-	code_info__produce_variable(Var, SourceCode, Source),
+unify_gen__generate_sub_assign(lval(Lval0), ref(Var), Code, !CI) :-
+	code_info__produce_variable(Var, SourceCode, Source, !CI),
 	code_info__materialize_vars_in_rval(lval(Lval0), NewLval,
-		MaterializeCode),
+		MaterializeCode, !CI),
 	(
-		{ NewLval = lval(Lval) }
+		NewLval = lval(Lval)
 	->
-		{ Code = tree(
+		Code = tree(
 			tree(SourceCode, MaterializeCode),
 			node([
 				assign(Lval, Source) - "Copy value"
 			])
-		) }
+		)
 	;
-		{ error("unify_gen__generate_sub_assign: lval vanished with ref") }
+		error("unify_gen__generate_sub_assign: " ++
+			"lval vanished with ref")
 	).
 	% Assignment to a variable, so cache it.
-unify_gen__generate_sub_assign(ref(Var), lval(Lval), Code) -->
-	( code_info__variable_is_forward_live(Var) ->
-		code_info__assign_lval_to_var(Var, Lval, Code)
+unify_gen__generate_sub_assign(ref(Var), lval(Lval), Code, !CI) :-
+	( code_info__variable_is_forward_live(!.CI, Var) ->
+		code_info__assign_lval_to_var(Var, Lval, Code, !CI)
 	;
-		{ Code = empty }
+		Code = empty
 	).
 	% Assignment to a variable, so cache it.
-unify_gen__generate_sub_assign(ref(Lvar), ref(Rvar), empty) -->
-	( code_info__variable_is_forward_live(Lvar) ->
-		code_info__assign_var_to_var(Lvar, Rvar)
+unify_gen__generate_sub_assign(ref(Lvar), ref(Rvar), empty, !CI) :-
+	( code_info__variable_is_forward_live(!.CI, Lvar) ->
+		code_info__assign_var_to_var(Lvar, Rvar, !CI)
 	;
-		[]
+		true
 	).
 
 %---------------------------------------------------------------------------%
Index: var_locn.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/var_locn.m,v
retrieving revision 1.11
diff -u -b -r1.11 var_locn.m
--- var_locn.m	20 Oct 2003 07:29:12 -0000	1.11
+++ var_locn.m	22 Oct 2003 04:38:33 -0000
@@ -98,12 +98,11 @@
 :- pred var_locn__check_and_set_magic_var_location(prog_var::in, lval::in,
 	var_locn_info::in, var_locn_info::out) is det.
 
-%	var_locn__lval_in_use(Lval, VarLocnInfo0, VarLocnInfo)
+%	var_locn__lval_in_use(VarLocnInfo, Lval)
 %		Succeeds iff Lval, which should be a register or stack slot,
 %		holds (a path to) a variable or is otherwise reserved.
 
-:- pred var_locn__lval_in_use(lval::in, var_locn_info::in, var_locn_info::out)
-	is semidet.
+:- pred var_locn__lval_in_use(var_locn_info::in, lval::in) is semidet.
 
 %	var_locn__var_becomes_dead(Var, FirstTime, VarLocnInfo0, VarLocnInfo)
 %		Frees any code generator resources used by Var in VarLocnInfo0
@@ -290,26 +289,24 @@
 :- pred var_locn__get_var_locations(var_locn_info::in,
 	map(prog_var, set(lval))::out) is det.
 
-%	var_locn__get_stack_slots(StackSlots)
+%	var_locn__get_stack_slots(VarLocnInfo, StackSlots)
 %		Returns the table mapping each variable to its stack slot
 %		(if any).
 
-:- pred var_locn__get_stack_slots(stack_slots::out,
-	var_locn_info::in, var_locn_info::out) is det.
+:- pred var_locn__get_stack_slots(var_locn_info::in, stack_slots::out) is det.
 
-%	var_locn__get_follow_vars(FollowVars)
+%	var_locn__get_follow_vars(VarLocnInfo, FollowVars)
 %		Returns the table mapping each variable to the lval (if any)
 %		where it is desired next.
 
-:- pred var_locn__get_follow_var_map(follow_vars_map::out,
-	var_locn_info::in, var_locn_info::out) is det.
+:- pred var_locn__get_follow_var_map(var_locn_info::in, follow_vars_map::out)
+	is det.
 
-%	var_locn__get_next_non_reserved(NonRes)
+%	var_locn__get_next_non_reserved(VarLocnInfo, NonRes)
 %		Returns the number of the first register which is free for
-%		general use.
+%		general use. It does not reserve the register.
 
-:- pred var_locn__get_next_non_reserved(int::out,
-	var_locn_info::in, var_locn_info::out) is det.
+:- pred var_locn__get_next_non_reserved(var_locn_info::in, int::out) is det.
 
 %	var_locn__set_follow_vars(FollowVars)
 %		Sets the table mapping each variable to the lval (if any)
@@ -471,9 +468,9 @@
 	maybe(set(prog_var))::in, var_state_map::in, var_state_map::out,
 	loc_var_map::in, loc_var_map::out) is det.
 
-var_locn__init_state_2([], _, VarStateMap, VarStateMap, LocVarMap, LocVarMap).
+var_locn__init_state_2([], _, !VarStateMap, !LocVarMap).
 var_locn__init_state_2([Var - Lval |  Rest], MaybeLiveness,
-		VarStateMap0, VarStateMap, LocVarMap0, LocVarMap) :-
+		!VarStateMap, !LocVarMap) :-
 	require(var_locn__is_root_lval(Lval),
 		"var_locn__init_state_2: unexpected lval"),
 	(
@@ -486,27 +483,26 @@
 			% clobber_regs would throw an exception, since it would
 			% believe that it is throwing away the last location
 			% storing the value of a "live" variable.
-		VarStateMap1 = VarStateMap0,
-		LocVarMap1 = LocVarMap0
+		true
 	;
-		( map__search(VarStateMap0, Var, _) ->
+		( map__search(!.VarStateMap, Var, _) ->
 			error("var_locn__init_state_2: repeated variable")
 		;
 			set__singleton_set(NewLocs, Lval),
 			set__init(Using),
 			State = state(NewLocs, no, no, Using, alive),
-			map__det_insert(VarStateMap0, Var, State, VarStateMap1)
+			map__det_insert(!.VarStateMap, Var, State,
+				!:VarStateMap)
 		),
 		var_locn__make_var_depend_on_lval_roots(Var, Lval,
-			LocVarMap0, LocVarMap1)
+			!LocVarMap)
 	),
-	var_locn__init_state_2(Rest, MaybeLiveness, VarStateMap1, VarStateMap,
-		LocVarMap1, LocVarMap).
+	var_locn__init_state_2(Rest, MaybeLiveness, !VarStateMap, !LocVarMap).
 
 %----------------------------------------------------------------------------%
 
-var_locn__get_var_locations(VarLocnInfo, VarLocations) :-
-	var_locn__get_var_state_map(VarStateMap, VarLocnInfo, _),
+var_locn__get_var_locations(VLI, VarLocations) :-
+	var_locn__get_var_state_map(VLI, VarStateMap),
 	map__to_assoc_list(VarStateMap, VarLocList),
 	list__filter_map(var_locn__convert_live_to_lval_set, VarLocList,
 		LiveVarLocList),
@@ -520,53 +516,50 @@
 
 %----------------------------------------------------------------------------%
 
-var_locn__clobber_all_regs(OkToDeleteAny) -->
-	{ set__init(Acquired) },
-	var_locn__set_acquired(Acquired),
-	var_locn__set_locked(0),
-	var_locn__set_exceptions([]),
-	var_locn__get_loc_var_map(LocVarMap0),
-	var_locn__get_var_state_map(VarStateMap0),
-	{ map__keys(LocVarMap0, Locs) },
-	{ var_locn__clobber_regs_in_maps(Locs, OkToDeleteAny,
-		LocVarMap0, LocVarMap, VarStateMap0, VarStateMap) },
-	var_locn__set_loc_var_map(LocVarMap),
-	var_locn__set_var_state_map(VarStateMap).
-
-var_locn__clobber_regs(Regs) -->
-	var_locn__get_acquired(Acquired0),
-	{ Acquired = set__delete_list(Acquired0, Regs) },
-	var_locn__set_acquired(Acquired),
-	var_locn__get_loc_var_map(LocVarMap0),
-	var_locn__get_var_state_map(VarStateMap0),
-	{ var_locn__clobber_regs_in_maps(Regs, no,
-		LocVarMap0, LocVarMap, VarStateMap0, VarStateMap) },
-	var_locn__set_loc_var_map(LocVarMap),
-	var_locn__set_var_state_map(VarStateMap).
+var_locn__clobber_all_regs(OkToDeleteAny, !VLI) :-
+	var_locn__set_acquired(set__init, !VLI),
+	var_locn__set_locked(0, !VLI),
+	var_locn__set_exceptions([], !VLI),
+	var_locn__get_loc_var_map(!.VLI, LocVarMap0),
+	var_locn__get_var_state_map(!.VLI, VarStateMap0),
+	map__keys(LocVarMap0, Locs),
+	var_locn__clobber_regs_in_maps(Locs, OkToDeleteAny,
+		LocVarMap0, LocVarMap, VarStateMap0, VarStateMap),
+	var_locn__set_loc_var_map(LocVarMap, !VLI),
+	var_locn__set_var_state_map(VarStateMap, !VLI).
+
+var_locn__clobber_regs(Regs, !VLI) :-
+	var_locn__get_acquired(!.VLI, Acquired0),
+	Acquired = set__delete_list(Acquired0, Regs),
+	var_locn__set_acquired(Acquired, !VLI),
+	var_locn__get_loc_var_map(!.VLI, LocVarMap0),
+	var_locn__get_var_state_map(!.VLI, VarStateMap0),
+	var_locn__clobber_regs_in_maps(Regs, no,
+		LocVarMap0, LocVarMap, VarStateMap0, VarStateMap),
+	var_locn__set_loc_var_map(LocVarMap, !VLI),
+	var_locn__set_var_state_map(VarStateMap, !VLI).
 
 :- pred var_locn__clobber_regs_in_maps(list(lval)::in, bool::in,
 	loc_var_map::in, loc_var_map::out,
 	var_state_map::in, var_state_map::out) is det.
 
-var_locn__clobber_regs_in_maps([], _, LocVarMap, LocVarMap,
-		VarStateMap, VarStateMap).
+var_locn__clobber_regs_in_maps([], _, !LocVarMap, !VarStateMap).
 var_locn__clobber_regs_in_maps([Lval | Lvals], OkToDeleteAny,
-		LocVarMap0, LocVarMap, VarStateMap0, VarStateMap) :-
+		!LocVarMap, !VarStateMap) :-
 	(
 		Lval = reg(_, _),
-		map__search(LocVarMap0, Lval, DependentVarsSet)
+		map__search(!.LocVarMap, Lval, DependentVarsSet)
 	->
-		map__delete(LocVarMap0, Lval, LocVarMap1),
+		map__delete(!.LocVarMap, Lval, !:LocVarMap),
 		set__to_sorted_list(DependentVarsSet, DependentVars),
 		list__foldl(var_locn__clobber_lval_in_var_state_map(Lval, [],
 			OkToDeleteAny),
-			DependentVars, VarStateMap0, VarStateMap1)
+			DependentVars, !VarStateMap)
 	;
-		LocVarMap1 = LocVarMap0,
-		VarStateMap1 = VarStateMap0
+		true
 	),
 	var_locn__clobber_regs_in_maps(Lvals, OkToDeleteAny,
-		LocVarMap1, LocVarMap, VarStateMap1, VarStateMap).
+		!LocVarMap, !VarStateMap).
 
 :- pred var_locn__clobber_lval_in_var_state_map(lval::in, list(prog_var)::in,
 	bool::in, prog_var::in, var_state_map::in, var_state_map::out) is det.
@@ -592,8 +585,8 @@
 	var_state_map::in, var_state_map::out) is semidet.
 
 var_locn__try_clobber_lval_in_var_state_map(Lval, OkToDeleteVars,
-		OkToDeleteAny, Var, VarStateMap0, VarStateMap) :-
-	map__lookup(VarStateMap0, Var, State0),
+		OkToDeleteAny, Var, !VarStateMap) :-
+	map__lookup(!.VarStateMap, Var, State0),
 	State0 = state(LvalSet0, MaybeConstRval, MaybeExprRval, Using,
 		DeadOrAlive),
 	LvalSet = set__filter(var_locn__lval_does_not_support_lval(Lval),
@@ -610,9 +603,9 @@
 		DeadOrAlive = dead,
 		set__to_sorted_list(Using, UsingVars),
 		var_locn__recursive_using_vars_dead_and_ok_to_delete(UsingVars,
-			VarStateMap0, OkToDeleteVars)
+			!.VarStateMap, OkToDeleteVars)
 	),
-	map__det_update(VarStateMap0, Var, State, VarStateMap).
+	map__det_update(!.VarStateMap, Var, State, !:VarStateMap).
 
 :- pred var_locn__recursive_using_vars_dead_and_ok_to_delete(
 	list(prog_var)::in, var_state_map::in, list(prog_var)::in) is semidet.
@@ -635,14 +628,13 @@
 
 %----------------------------------------------------------------------------%
 
-var_locn__assign_var_to_var(Var, OldVar) -->
-	var_locn__check_var_is_unknown(Var),
-
-	var_locn__get_var_state_map(VarStateMap0),
-	{ map__lookup(VarStateMap0, OldVar, OldState0) },
-	{ OldState0 = state(Lvals, MaybeConstRval, MaybeExprRval,
-		Using0, DeadOrAlive) },
-	{
+var_locn__assign_var_to_var(Var, OldVar, !VLI) :-
+	var_locn__check_var_is_unknown(!.VLI, Var),
+	var_locn__get_var_state_map(!.VLI, VarStateMap0),
+	map__lookup(VarStateMap0, OldVar, OldState0),
+	OldState0 = state(Lvals, MaybeConstRval, MaybeExprRval,
+		Using0, DeadOrAlive),
+	(
 		MaybeExprRval = yes(_),
 		State = state(Lvals, MaybeConstRval, yes(var(OldVar)),
 			set__init, alive),
@@ -655,80 +647,80 @@
 		set__init(Empty),
 		State = state(Lvals, MaybeConstRval, no, Empty, alive),
 		VarStateMap1 = VarStateMap0
-	},
-	{ map__det_insert(VarStateMap1, Var, State, VarStateMap) },
-	var_locn__set_var_state_map(VarStateMap),
+	),
+	map__det_insert(VarStateMap1, Var, State, VarStateMap),
+	var_locn__set_var_state_map(VarStateMap, !VLI),
 
-	var_locn__get_loc_var_map(LocVarMap0),
-	{ var_locn__make_var_depend_on_lvals_roots(Var, Lvals,
-		LocVarMap0, LocVarMap) },
-	var_locn__set_loc_var_map(LocVarMap).
+	var_locn__get_loc_var_map(!.VLI, LocVarMap0),
+	var_locn__make_var_depend_on_lvals_roots(Var, Lvals,
+		LocVarMap0, LocVarMap),
+	var_locn__set_loc_var_map(LocVarMap, !VLI).
 
 %----------------------------------------------------------------------------%
 
-var_locn__assign_lval_to_var(Var, Lval0, StaticCellInfo, Code) -->
-	var_locn__check_var_is_unknown(Var),
+var_locn__assign_lval_to_var(Var, Lval0, StaticCellInfo, Code, !VLI) :-
+	var_locn__check_var_is_unknown(!.VLI, Var),
 	(
-		{ Lval0 = field(yes(Ptag), var(BaseVar),
-			const(int_const(Offset))) }
+		Lval0 = field(yes(Ptag), var(BaseVar),
+			const(int_const(Offset)))
 	->
-		var_locn__get_var_state_map(VarStateMap0),
-		{ map__lookup(VarStateMap0, BaseVar, BaseState) },
-		{ BaseState = state(BaseVarLvals, MaybeConstBaseVarRval,
-			_MaybeExprRval, _UsingVars, _DeadOrAlive) },
+		var_locn__get_var_state_map(!.VLI, VarStateMap0),
+		map__lookup(VarStateMap0, BaseVar, BaseState),
+		BaseState = state(BaseVarLvals, MaybeConstBaseVarRval,
+			_MaybeExprRval, _UsingVars, _DeadOrAlive),
 		(
-			{ MaybeConstBaseVarRval = yes(BaseVarRval) },
-			{ BaseVarRval = mkword(Ptag, BaseConst) },
-			{ BaseConst = const(data_addr_const(DataAddr,
-				MaybeBaseOffset)) },
+			MaybeConstBaseVarRval = yes(BaseVarRval),
+			BaseVarRval = mkword(Ptag, BaseConst),
+			BaseConst = const(data_addr_const(DataAddr,
+				MaybeBaseOffset)),
 			% XXX We could drop the MaybeBaseOffset = no condition,
 			% but this would require more complex code below.
-			{ MaybeBaseOffset = no },
-			{ search_static_cell(StaticCellInfo, DataAddr,
-				StaticCellArgsTypes) }
-		->
-			{ list__index0_det(StaticCellArgsTypes, Offset,
-				SelectedArgRval - _SelectedArgType) },
-			{ MaybeConstRval = yes(SelectedArgRval) },
-			{ Lvals = set__map(var_locn__add_field_offset(
+			MaybeBaseOffset = no,
+			search_static_cell(StaticCellInfo, DataAddr,
+				StaticCellArgsTypes)
+		->
+			list__index0_det(StaticCellArgsTypes, Offset,
+				SelectedArgRval - _SelectedArgType),
+			MaybeConstRval = yes(SelectedArgRval),
+			Lvals = set__map(var_locn__add_field_offset(
 				yes(Ptag), const(int_const(Offset))),
-				BaseVarLvals) },
-			{ set__init(Using) },
-			{ State = state(Lvals, MaybeConstRval, no,
-				Using, alive) },
-			{ map__det_insert(VarStateMap0, Var, State,
-				VarStateMap) },
-			var_locn__set_var_state_map(VarStateMap),
-
-			var_locn__get_loc_var_map(LocVarMap0),
-			{ var_locn__make_var_depend_on_lvals_roots(Var, Lvals,
-				LocVarMap0, LocVarMap) },
-			var_locn__set_loc_var_map(LocVarMap)
-		;
-			{ set__init(Lvals) },
-			{ Expr = lval(Lval0) },
-			{ set__init(Using) },
-			{ State = state(Lvals, no, yes(Expr), Using, alive) },
-			{ map__det_insert(VarStateMap0, Var, State,
-				VarStateMap1) },
-			{ var_locn__add_use_ref(BaseVar, Var,
-				VarStateMap1, VarStateMap) },
-			var_locn__set_var_state_map(VarStateMap)
-		),
-		{ Code = empty }
-	;
-		var_locn__materialize_vars_in_lval(Lval0, Lval, Code),
-
-		var_locn__get_var_state_map(VarStateMap0),
-		{ set__singleton_set(LvalSet, Lval) },
-		{ State = state(LvalSet, no, no, set__init, alive) },
-		{ map__det_insert(VarStateMap0, Var, State, VarStateMap) },
-		var_locn__set_var_state_map(VarStateMap),
-
-		var_locn__get_loc_var_map(LocVarMap0),
-		{ var_locn__make_var_depend_on_lval_roots(Var, Lval,
-			LocVarMap0, LocVarMap) },
-		var_locn__set_loc_var_map(LocVarMap)
+				BaseVarLvals),
+			set__init(Using),
+			State = state(Lvals, MaybeConstRval, no,
+				Using, alive),
+			map__det_insert(VarStateMap0, Var, State,
+				VarStateMap),
+			var_locn__set_var_state_map(VarStateMap, !VLI),
+
+			var_locn__get_loc_var_map(!.VLI, LocVarMap0),
+			var_locn__make_var_depend_on_lvals_roots(Var, Lvals,
+				LocVarMap0, LocVarMap),
+			var_locn__set_loc_var_map(LocVarMap, !VLI)
+		;
+			set__init(Lvals),
+			Expr = lval(Lval0),
+			set__init(Using),
+			State = state(Lvals, no, yes(Expr), Using, alive),
+			map__det_insert(VarStateMap0, Var, State,
+				VarStateMap1),
+			var_locn__add_use_ref(BaseVar, Var,
+				VarStateMap1, VarStateMap),
+			var_locn__set_var_state_map(VarStateMap, !VLI)
+		),
+		Code = empty
+	;
+		var_locn__materialize_vars_in_lval(Lval0, Lval, Code, !VLI),
+
+		var_locn__get_var_state_map(!.VLI, VarStateMap0),
+		set__singleton_set(LvalSet, Lval),
+		State = state(LvalSet, no, no, set__init, alive),
+		map__det_insert(VarStateMap0, Var, State, VarStateMap),
+		var_locn__set_var_state_map(VarStateMap, !VLI),
+
+		var_locn__get_loc_var_map(!.VLI, LocVarMap0),
+		var_locn__make_var_depend_on_lval_roots(Var, Lval,
+			LocVarMap0, LocVarMap),
+		var_locn__set_loc_var_map(LocVarMap, !VLI)
 	).
 
 :- func var_locn__add_field_offset(maybe(tag), rval, lval) = lval.
@@ -738,37 +730,37 @@
 
 %----------------------------------------------------------------------------%
 
-var_locn__assign_const_to_var(Var, ConstRval0) -->
-	var_locn__check_var_is_unknown(Var),
+var_locn__assign_const_to_var(Var, ConstRval0, !VLI) :-
+	var_locn__check_var_is_unknown(!.VLI, Var),
 
-	var_locn__get_var_state_map(VarStateMap0),
-	var_locn__get_exprn_opts(ExprnOpts),
+	var_locn__get_var_state_map(!.VLI, VarStateMap0),
+	var_locn__get_exprn_opts(!.VLI, ExprnOpts),
 	(
-		{ var_locn__expr_is_constant(VarStateMap0, ExprnOpts,
-			ConstRval0, ConstRval) }
+		var_locn__expr_is_constant(VarStateMap0, ExprnOpts,
+			ConstRval0, ConstRval)
 	->
-		{ State = state(set__init, yes(ConstRval), no,
-			set__init, alive) },
-		{ map__det_insert(VarStateMap0, Var, State, VarStateMap) },
-		var_locn__set_var_state_map(VarStateMap)
+		State = state(set__init, yes(ConstRval), no,
+			set__init, alive),
+		map__det_insert(VarStateMap0, Var, State, VarStateMap),
+		var_locn__set_var_state_map(VarStateMap, !VLI)
 	;
-		{ error("var_locn__set_var_state_map: supposed constant isn't") }
+		error("var_locn__set_var_state_map: supposed constant isn't")
 	).
 
 %----------------------------------------------------------------------------%
 
-var_locn__assign_expr_to_var(Var, Rval, empty) -->
-	var_locn__check_var_is_unknown(Var),
+var_locn__assign_expr_to_var(Var, Rval, empty, !VLI) :-
+	var_locn__check_var_is_unknown(!.VLI, Var),
 
-	var_locn__get_var_state_map(VarStateMap0),
-	{ State = state(set__init, no, yes(Rval), set__init, alive) },
-	{ map__det_insert(VarStateMap0, Var, State, VarStateMap1) },
+	var_locn__get_var_state_map(!.VLI, VarStateMap0),
+	State = state(set__init, no, yes(Rval), set__init, alive),
+	map__det_insert(VarStateMap0, Var, State, VarStateMap1),
 
-	{ exprn_aux__vars_in_rval(Rval, ContainedVars0) },
-	{ list__remove_dups(ContainedVars0, ContainedVars) },
-	{ var_locn__add_use_refs(ContainedVars, Var,
-		VarStateMap1, VarStateMap) },
-	var_locn__set_var_state_map(VarStateMap).
+	exprn_aux__vars_in_rval(Rval, ContainedVars0),
+	list__remove_dups(ContainedVars0, ContainedVars),
+	var_locn__add_use_refs(ContainedVars, Var,
+		VarStateMap1, VarStateMap),
+	var_locn__set_var_state_map(VarStateMap, !VLI).
 
 :- pred var_locn__add_use_refs(list(prog_var)::in, prog_var::in,
 	var_state_map::in, var_state_map::out) is det.
@@ -796,7 +788,7 @@
 %----------------------------------------------------------------------------%
 
 var_locn__assign_cell_to_var(Var, Ptag, MaybeRvals0, SizeInfo, TypeMsg, Code,
-		!StaticCellInfo, !VarLocn) :-
+		!StaticCellInfo, !VLI) :-
 	(
 		SizeInfo = yes(SizeSource),
 		(
@@ -813,8 +805,8 @@
 		MaybeRvals = MaybeRvals0,
 		MaybeOffset = no
 	),
-	var_locn__get_var_state_map(VarStateMap, !VarLocn),
-	var_locn__get_exprn_opts(ExprnOpts, !VarLocn),
+	var_locn__get_var_state_map(!.VLI, VarStateMap),
+	var_locn__get_exprn_opts(!.VLI, ExprnOpts),
 	(
 		var_locn__cell_is_constant(VarStateMap, ExprnOpts,
 			MaybeRvals, RvalsTypes)
@@ -822,11 +814,11 @@
 		add_static_cell(RvalsTypes, DataAddr, !StaticCellInfo),
 		CellPtrRval = mkword(Ptag, const(
 			data_addr_const(DataAddr, MaybeOffset))),
-		var_locn__assign_const_to_var(Var, CellPtrRval, !VarLocn),
+		var_locn__assign_const_to_var(Var, CellPtrRval, !VLI),
 		Code = empty
 	;
 		var_locn__assign_dynamic_cell_to_var(Var, Ptag, MaybeRvals,
-			MaybeOffset, TypeMsg, Code, !VarLocn)
+			MaybeOffset, TypeMsg, Code, !VLI)
 	).
 
 :- pred var_locn__assign_dynamic_cell_to_var(prog_var::in, tag::in,
@@ -834,69 +826,70 @@
 	var_locn_info::in, var_locn_info::out) is det.
 
 var_locn__assign_dynamic_cell_to_var(Var, Ptag, Vector, MaybeOffset,
-		TypeMsg, Code) -->
-	var_locn__check_var_is_unknown(Var),
+		TypeMsg, Code, !VLI) :-
+	var_locn__check_var_is_unknown(!.VLI, Var),
 
-	var_locn__select_preferred_reg_or_stack(Var, Lval),
-	var_locn__get_var_name(Var, VarName),
-	{ list__length(Vector, Size) },
-	{ CellCode = node([
+	var_locn__select_preferred_reg_or_stack_check(!.VLI, Var, Lval),
+	var_locn__get_var_name(!.VLI, Var, VarName),
+	list__length(Vector, Size),
+	CellCode = node([
 		incr_hp(Lval, yes(Ptag), MaybeOffset, const(int_const(Size)),
 			TypeMsg)
 			- string__append("Allocating heap for ", VarName)
-	]) },
-	var_locn__set_magic_var_location(Var, Lval),
-	{
+	]),
+	var_locn__set_magic_var_location(Var, Lval, !VLI),
+	(
 		MaybeOffset = yes(Offset),
 		StartOffset = -Offset
 	;
 		MaybeOffset = no,
 		StartOffset = 0
-	},
+	),
 	var_locn__assign_cell_args(Vector, yes(Ptag), lval(Lval), StartOffset,
-		ArgsCode),
-	{ Code = tree(CellCode, ArgsCode) }.
+		ArgsCode, !VLI),
+	Code = tree(CellCode, ArgsCode).
 
 :- pred var_locn__assign_cell_args(list(maybe(rval))::in,
 	maybe(tag)::in, rval::in, int::in, code_tree::out,
 	var_locn_info::in, var_locn_info::out) is det.
 
-var_locn__assign_cell_args([], _, _, _, empty) --> [].
+var_locn__assign_cell_args([], _, _, _, empty, !VLI).
 var_locn__assign_cell_args([MaybeRval0 | MaybeRvals0], Ptag, Base, Offset,
-		Code) -->
-	( { MaybeRval0 = yes(Rval0) } ->
-		{ Target = field(Ptag, Base, const(int_const(Offset))) },
-		( { Rval0 = var(Var) } ->
-			var_locn__find_var_availability(Var, no, Avail),
+		Code, !VLI) :-
+	( MaybeRval0 = yes(Rval0) ->
+		Target = field(Ptag, Base, const(int_const(Offset))),
+		( Rval0 = var(Var) ->
+			var_locn__find_var_availability(!.VLI, Var, no, Avail),
 			(
-				{ Avail = available(Rval) },
-				{ EvalCode = empty }
+				Avail = available(Rval),
+				EvalCode = empty
 			;
-				{ Avail = needs_materialization },
+				Avail = needs_materialization,
 				var_locn__materialize_var(Var, no, no, [],
-					Rval, EvalCode)
+					Rval, EvalCode, !VLI)
 			),
-			var_locn__add_additional_lval_for_var(Var, Target),
-			var_locn__get_var_name(Var, VarName),
-			{ Comment = string__append("assigning from ",
-				VarName) }
-		; { Rval0 = const(_) } ->
-			{ Rval = Rval0 },
-			{ EvalCode = empty },
-			{ Comment = "assigning field from const" }
+			var_locn__add_additional_lval_for_var(Var, Target,
+				!VLI),
+			var_locn__get_var_name(!.VLI, Var, VarName),
+			Comment = string__append("assigning from ",
+				VarName)
+		; Rval0 = const(_) ->
+			Rval = Rval0,
+			EvalCode = empty,
+			Comment = "assigning field from const"
 		;
-			{ error("var_locn__assign_cell_args: unknown rval") }
+			error("var_locn__assign_cell_args: unknown rval")
 		),
-		{ AssignCode = node([
+		AssignCode = node([
 			assign(Target, Rval) - Comment
-		]) },
-		{ ThisCode = tree(EvalCode, AssignCode) }
+		]),
+		ThisCode = tree(EvalCode, AssignCode)
 	;
-		{ ThisCode = empty }
+		ThisCode = empty
 	),
 	var_locn__assign_cell_args(MaybeRvals0, Ptag, Base, Offset + 1,
-		RestCode),
-	{ Code = tree(ThisCode, RestCode) }.
+		RestCode, !VLI),
+	Code = tree(ThisCode, RestCode).
 
 %----------------------------------------------------------------------------%
 
@@ -906,64 +899,64 @@
 :- pred var_locn__add_additional_lval_for_var(prog_var::in, lval::in,
 	var_locn_info::in, var_locn_info::out) is det.
 
-var_locn__add_additional_lval_for_var(Var, Lval) -->
-	var_locn__get_loc_var_map(LocVarMap0),
-	{ var_locn__make_var_depend_on_lval_roots(Var, Lval,
-		LocVarMap0, LocVarMap) },
-	var_locn__set_loc_var_map(LocVarMap),
-
-	var_locn__get_var_state_map(VarStateMap0),
-	{ map__lookup(VarStateMap0, Var, State0) },
-	{ State0 = state(LvalSet0, MaybeConstRval, MaybeExprRval0,
-		Using, DeadOrAlive) },
-	{ set__insert(LvalSet0, Lval, LvalSet) },
-	{ State = state(LvalSet, MaybeConstRval, no, Using, DeadOrAlive) },
-	{ map__det_update(VarStateMap0, Var, State, VarStateMap) },
-	var_locn__set_var_state_map(VarStateMap),
+var_locn__add_additional_lval_for_var(Var, Lval, !VLI) :-
+	var_locn__get_loc_var_map(!.VLI, LocVarMap0),
+	var_locn__make_var_depend_on_lval_roots(Var, Lval,
+		LocVarMap0, LocVarMap),
+	var_locn__set_loc_var_map(LocVarMap, !VLI),
+
+	var_locn__get_var_state_map(!.VLI, VarStateMap0),
+	map__lookup(VarStateMap0, Var, State0),
+	State0 = state(LvalSet0, MaybeConstRval, MaybeExprRval0,
+		Using, DeadOrAlive),
+	set__insert(LvalSet0, Lval, LvalSet),
+	State = state(LvalSet, MaybeConstRval, no, Using, DeadOrAlive),
+	map__det_update(VarStateMap0, Var, State, VarStateMap),
+	var_locn__set_var_state_map(VarStateMap, !VLI),
 
-	var_locn__remove_use_refs(MaybeExprRval0, Var).
+	var_locn__remove_use_refs(MaybeExprRval0, Var, !VLI).
 
 :- pred var_locn__remove_use_refs(maybe(rval)::in, prog_var::in,
 	var_locn_info::in, var_locn_info::out) is det.
 
-var_locn__remove_use_refs(MaybeExprRval, UsingVar) -->
+var_locn__remove_use_refs(MaybeExprRval, UsingVar, !VLI) :-
 	(
-		{ MaybeExprRval = yes(ExprRval) },
-		{ exprn_aux__vars_in_rval(ExprRval, ContainedVars0) },
-		{ list__remove_dups(ContainedVars0, ContainedVars) },
-		var_locn__remove_use_refs_2(ContainedVars, UsingVar)
+		MaybeExprRval = yes(ExprRval),
+		exprn_aux__vars_in_rval(ExprRval, ContainedVars0),
+		list__remove_dups(ContainedVars0, ContainedVars),
+		var_locn__remove_use_refs_2(ContainedVars, UsingVar, !VLI)
 	;
-		{ MaybeExprRval = no }
+		MaybeExprRval = no
 	).
 
 :- pred var_locn__remove_use_refs_2(list(prog_var)::in, prog_var::in,
 	var_locn_info::in, var_locn_info::out) is det.
 
-var_locn__remove_use_refs_2([], _) --> [].
-var_locn__remove_use_refs_2([ContainedVar | ContainedVars], UsingVar) -->
-	var_locn__get_var_state_map(VarStateMap0),
-	{ map__lookup(VarStateMap0, ContainedVar, State0) },
-	{ State0 = state(Lvals, MaybeConstRval, MaybeExprRval,
-		Using0, DeadOrAlive) },
-	{ set__remove(Using0, UsingVar, Using1) ->
+var_locn__remove_use_refs_2([], _, !VLI).
+var_locn__remove_use_refs_2([ContainedVar | ContainedVars], UsingVar, !VLI) :-
+	var_locn__get_var_state_map(!.VLI, VarStateMap0),
+	map__lookup(VarStateMap0, ContainedVar, State0),
+	State0 = state(Lvals, MaybeConstRval, MaybeExprRval,
+		Using0, DeadOrAlive),
+	( set__remove(Using0, UsingVar, Using1) ->
 		Using = Using1
 	;
 		error("var_locn__remove_use_refs_2: using ref not present")
-	},
-	{ State = state(Lvals, MaybeConstRval, MaybeExprRval,
-		Using, DeadOrAlive) },
-	{ map__det_update(VarStateMap0, ContainedVar, State,
-		VarStateMap) },
-	var_locn__set_var_state_map(VarStateMap),
+	),
+	State = state(Lvals, MaybeConstRval, MaybeExprRval,
+		Using, DeadOrAlive),
+	map__det_update(VarStateMap0, ContainedVar, State,
+		VarStateMap),
+	var_locn__set_var_state_map(VarStateMap, !VLI),
 	(
-		{ set__empty(Using) },
-		{ DeadOrAlive = dead }
+		set__empty(Using),
+		DeadOrAlive = dead
 	->
-		var_locn__var_becomes_dead(ContainedVar, no)
+		var_locn__var_becomes_dead(ContainedVar, no, !VLI)
 	;
-		[]
+		true
 	),
-	var_locn__remove_use_refs_2(ContainedVars, UsingVar).
+	var_locn__remove_use_refs_2(ContainedVars, UsingVar, !VLI).
 
 %----------------------------------------------------------------------------%
 
@@ -971,100 +964,99 @@
 % "magically" appeared there (i.e. our caller has arranged for it to be put
 % there).
 
-var_locn__check_and_set_magic_var_location(Var, Lval) -->
-	( var_locn__lval_in_use(Lval) ->
-		{ error("var_locn__check_and_set_magic_var_location: in use") }
+var_locn__check_and_set_magic_var_location(Var, Lval, !VLI) :-
+	( var_locn__lval_in_use(!.VLI, Lval) ->
+		error("var_locn__check_and_set_magic_var_location: in use")
 	;
-		var_locn__set_magic_var_location(Var, Lval)
+		var_locn__set_magic_var_location(Var, Lval, !VLI)
 	).
 
 % Record that Var has "magically" appeared in Lval (i.e. our caller has
 % arranged for it to be put there). Var must not have been previously known.
 
-var_locn__set_magic_var_location(Var, Lval) -->
-	var_locn__get_loc_var_map(LocVarMap0),
-	{ var_locn__make_var_depend_on_lval_roots(Var, Lval,
-		LocVarMap0, LocVarMap) },
-	var_locn__set_loc_var_map(LocVarMap),
+var_locn__set_magic_var_location(Var, Lval, !VLI) :-
+	var_locn__get_loc_var_map(!.VLI, LocVarMap0),
+	var_locn__make_var_depend_on_lval_roots(Var, Lval,
+		LocVarMap0, LocVarMap),
+	var_locn__set_loc_var_map(LocVarMap, !VLI),
 
-	var_locn__get_var_state_map(VarStateMap0),
-	{ set__singleton_set(LvalSet, Lval) },
-	{ State = state(LvalSet, no, no, set__init, alive) },
-	{ map__det_insert(VarStateMap0, Var, State, VarStateMap) },
-	var_locn__set_var_state_map(VarStateMap).
+	var_locn__get_var_state_map(!.VLI, VarStateMap0),
+	set__singleton_set(LvalSet, Lval),
+	State = state(LvalSet, no, no, set__init, alive),
+	map__det_insert(VarStateMap0, Var, State, VarStateMap),
+	var_locn__set_var_state_map(VarStateMap, !VLI).
 
 %----------------------------------------------------------------------------%
 
-:- pred var_locn__check_var_is_unknown(prog_var::in,
-	var_locn_info::in, var_locn_info::out) is det.
+:- pred var_locn__check_var_is_unknown(var_locn_info::in, prog_var::in) is det.
 
-var_locn__check_var_is_unknown(Var) -->
-	var_locn__get_var_state_map(VarStateMap0),
-	( { map__search(VarStateMap0, Var, _) } ->
-		var_locn__get_var_name(Var, Name),
-		{ string__append("var_locn__assign_to_var: existing definition of variable ",
-			Name, Msg) },
-		{ error(Msg) }
+var_locn__check_var_is_unknown(VLI, Var) :-
+	var_locn__get_var_state_map(VLI, VarStateMap0),
+	( map__search(VarStateMap0, Var, _) ->
+		var_locn__get_var_name(VLI, Var, Name),
+		string__append("var_locn__assign_to_var: " ++
+			"existing definition of variable ", Name, Msg),
+		error(Msg)
 	;
-		[]
+		true
 	).
 
 %----------------------------------------------------------------------------%
 
-var_locn__produce_var(Var, Rval, Code) -->
-	var_locn__get_var_state_map(VarStateMap),
-	{ map__lookup(VarStateMap, Var, State) },
-	{ State = state(Lvals, MaybeConstRval, _, _, _) },
-	{ set__to_sorted_list(Lvals, LvalsList) },
+var_locn__produce_var(Var, Rval, Code, !VLI) :-
+	var_locn__get_var_state_map(!.VLI, VarStateMap),
+	map__lookup(VarStateMap, Var, State),
+	State = state(Lvals, MaybeConstRval, _, _, _),
+	set__to_sorted_list(Lvals, LvalsList),
 	(
-		{ var_locn__maybe_select_lval_or_rval(LvalsList,
-			MaybeConstRval, Rval1) }
+		var_locn__maybe_select_lval_or_rval(LvalsList,
+			MaybeConstRval, Rval1)
 	->
-		{ Rval = Rval1 },
-		{ Code = empty }
+		Rval = Rval1,
+		Code = empty
 	;
-		var_locn__select_preferred_reg(Var, Lval),
-		var_locn__place_var(Var, Lval, Code),
-		{ Rval = lval(Lval) }
+		var_locn__select_preferred_reg(!.VLI, Var, Lval),
+		var_locn__place_var(Var, Lval, Code, !VLI),
+		Rval = lval(Lval)
 	).
 
-var_locn__produce_var_in_reg(Var, Lval, Code) -->
-	var_locn__get_var_state_map(VarStateMap),
-	{ map__lookup(VarStateMap, Var, State) },
-	{ State = state(Lvals, _, _, _, _) },
-	{ set__to_sorted_list(Lvals, LvalList) },
-	( { var_locn__select_reg_lval(LvalList, SelectLval) } ->
-		{ Lval = SelectLval },
-		{ Code = empty }
+var_locn__produce_var_in_reg(Var, Lval, Code, !VLI) :-
+	var_locn__get_var_state_map(!.VLI, VarStateMap),
+	map__lookup(VarStateMap, Var, State),
+	State = state(Lvals, _, _, _, _),
+	set__to_sorted_list(Lvals, LvalList),
+	( var_locn__select_reg_lval(LvalList, SelectLval) ->
+		Lval = SelectLval,
+		Code = empty
 	;
-		var_locn__select_preferred_reg(Var, Lval),
-		var_locn__place_var(Var, Lval, Code)
+		var_locn__select_preferred_reg(!.VLI, Var, Lval),
+		var_locn__place_var(Var, Lval, Code, !VLI)
 	).
 
-var_locn__produce_var_in_reg_or_stack(Var, Lval, Code) -->
-	var_locn__get_var_state_map(VarStateMap),
-	{ map__lookup(VarStateMap, Var, State) },
-	{ State = state(Lvals, _, _, _, _) },
-	{ set__to_sorted_list(Lvals, LvalList) },
-	( { var_locn__select_reg_or_stack_lval(LvalList, SelectLval) } ->
-		{ Lval = SelectLval },
-		{ Code = empty }
+var_locn__produce_var_in_reg_or_stack(Var, Lval, Code, !VLI) :-
+	var_locn__get_var_state_map(!.VLI, VarStateMap),
+	map__lookup(VarStateMap, Var, State),
+	State = state(Lvals, _, _, _, _),
+	set__to_sorted_list(Lvals, LvalList),
+	( var_locn__select_reg_or_stack_lval(LvalList, SelectLval) ->
+		Lval = SelectLval,
+		Code = empty
 	;
-		var_locn__select_preferred_reg_or_stack(Var, Lval),
-		var_locn__place_var(Var, Lval, Code)
+		var_locn__select_preferred_reg_or_stack_check(!.VLI, Var,
+			Lval),
+		var_locn__place_var(Var, Lval, Code, !VLI)
 	).
 
 %----------------------------------------------------------------------------%
 
-var_locn__clear_r1(Code) -->
-	var_locn__free_up_lval(reg(r, 1), [], [], Code),
-
-	var_locn__get_loc_var_map(LocVarMap0),
-	var_locn__get_var_state_map(VarStateMap0),
-	{ var_locn__clobber_regs_in_maps([reg(r, 1)], no,
-		LocVarMap0, LocVarMap, VarStateMap0, VarStateMap) },
-	var_locn__set_loc_var_map(LocVarMap),
-	var_locn__set_var_state_map(VarStateMap).
+var_locn__clear_r1(Code, !VLI) :-
+	var_locn__free_up_lval(reg(r, 1), [], [], Code, !VLI),
+	var_locn__get_loc_var_map(!.VLI, LocVarMap0),
+	var_locn__get_var_state_map(!.VLI, VarStateMap0),
+	var_locn__clobber_regs_in_maps([reg(r, 1)], no,
+		LocVarMap0, LocVarMap, VarStateMap0, VarStateMap),
+	var_locn__set_loc_var_map(LocVarMap, !VLI),
+	var_locn__set_var_state_map(VarStateMap, !VLI).
 
 % If we are asked to place several variables, then we must make sure that in
 % the process of freeing up an lval for one variable, we do not save its
@@ -1077,73 +1069,75 @@
 % VarLocns, then it is OK to move it to the location assigned to it by
 % VarLocns.
 
-var_locn__place_vars(VarLocns, Code) -->
-	{ assoc_list__values(VarLocns, Lvals) },
-	{ code_util__max_mentioned_reg(Lvals, MaxReg) },
-	var_locn__lock_regs(MaxReg, VarLocns),
-	var_locn__actually_place_vars(VarLocns, Code),
-	var_locn__unlock_regs.
+var_locn__place_vars(VarLocns, Code, !VLI) :-
+	assoc_list__values(VarLocns, Lvals),
+	code_util__max_mentioned_reg(Lvals, MaxReg),
+	var_locn__lock_regs(MaxReg, VarLocns, !VLI),
+	var_locn__actually_place_vars(VarLocns, Code, !VLI),
+	var_locn__unlock_regs(!VLI).
 
 :- pred var_locn__actually_place_vars(assoc_list(prog_var, lval)::in,
 	code_tree::out, var_locn_info::in, var_locn_info::out) is det.
 
-var_locn__actually_place_vars([], empty) --> [].
-var_locn__actually_place_vars([Var - Lval | Rest], Code) -->
-	var_locn__place_var(Var, Lval, FirstCode),
-	var_locn__actually_place_vars(Rest, RestCode),
-	{ Code = tree(FirstCode, RestCode) }.
+var_locn__actually_place_vars([], empty, !VLI).
+var_locn__actually_place_vars([Var - Lval | Rest], Code, !VLI) :-
+	var_locn__place_var(Var, Lval, FirstCode, !VLI),
+	var_locn__actually_place_vars(Rest, RestCode, !VLI),
+	Code = tree(FirstCode, RestCode).
 
-var_locn__place_var(Var, Target, Code) -->
-	var_locn__actually_place_var(Var, Target, [], Code).
+var_locn__place_var(Var, Target, Code, !VLI) :-
+	var_locn__actually_place_var(Var, Target, [], Code, !VLI).
 
 :- pred var_locn__actually_place_var(prog_var::in, lval::in, list(lval)::in,
 	code_tree::out, var_locn_info::in, var_locn_info::out) is det.
 
-var_locn__actually_place_var(Var, Target, ForbiddenLvals, Code) -->
-	var_locn__get_acquired(Acquired),
-	{ set__member(Target, Acquired) ->
+var_locn__actually_place_var(Var, Target, ForbiddenLvals, Code, !VLI) :-
+	var_locn__get_acquired(!.VLI, Acquired),
+	( set__member(Target, Acquired) ->
 		error("var_locn__actually_place_var: target is acquired reg")
 	;
 		true
-	},
-	var_locn__get_var_state_map(VarStateMap0),
-	{ map__lookup(VarStateMap0, Var, State0) },
-	{ State0 = state(Lvals0, _, _, _, _) },
-	( { set__member(Target, Lvals0) } ->
-		{ Code = empty }
+	),
+	var_locn__get_var_state_map(!.VLI, VarStateMap0),
+	map__lookup(VarStateMap0, Var, State0),
+	State0 = state(Lvals0, _, _, _, _),
+	( set__member(Target, Lvals0) ->
+		Code = empty
 	;
 		var_locn__free_up_lval(Target, [Var], ForbiddenLvals,
-			FreeCode),
+			FreeCode, !VLI),
 
 			% If Var's value is cached, Lvals0 must be empty.
 			% However, the cached value may simply be var(Other),
 			% and Other may already be in Target. However, it may
 			% also be in another lval, so we say we prefer the
 			% copy in Target.
-		var_locn__find_var_availability(Var, yes(Target), Avail),
+		var_locn__find_var_availability(!.VLI, Var, yes(Target),
+			Avail),
 		(
-			{ Avail = available(Rval) },
-			{ EvalCode = empty },
-			( { Rval = lval(SourceLval) } ->
-				var_locn__record_copy(SourceLval, Target)
+			Avail = available(Rval),
+			EvalCode = empty,
+			( Rval = lval(SourceLval) ->
+				var_locn__record_copy(SourceLval, Target, !VLI)
 			;
-				var_locn__record_clobbering(Target, [Var])
+				var_locn__record_clobbering(Target, [Var],
+					!VLI)
 			)
 		;
-			{ Avail = needs_materialization },
+			Avail = needs_materialization,
 			var_locn__materialize_var(Var, yes(Target), no,
-				[Target], Rval, EvalCode),
-			var_locn__record_clobbering(Target, [Var])
+				[Target], Rval, EvalCode, !VLI),
+			var_locn__record_clobbering(Target, [Var], !VLI)
 		),
 
 			% Record that Var is now in Target.
-		var_locn__add_additional_lval_for_var(Var, Target),
+		var_locn__add_additional_lval_for_var(Var, Target, !VLI),
 
-		( { Rval = lval(Target) } ->
-			{ AssignCode = empty }
+		( Rval = lval(Target) ->
+			AssignCode = empty
 		;
-			var_locn__get_var_name(Var, VarName),
-			{ ForbiddenLvals = [] ->
+			var_locn__get_var_name(!.VLI, Var, VarName),
+			( ForbiddenLvals = [] ->
 				string__append("Placing ", VarName, Msg)
 			;
 				string__int_to_string(
@@ -1151,33 +1145,33 @@
 					LengthStr),
 				string__append_list(["Placing ", VarName,
 					" (depth ", LengthStr, ")"], Msg)
-			},
-			{ AssignCode = node([
+			),
+			AssignCode = node([
 				assign(Target, Rval)
 					- Msg
-			]) }
+			])
 		),
-		{ Code = tree(FreeCode, tree(EvalCode, AssignCode)) }
+		Code = tree(FreeCode, tree(EvalCode, AssignCode))
 	).
 
 :- pred var_locn__record_clobbering(lval::in, list(prog_var)::in,
 	var_locn_info::in, var_locn_info::out) is det.
 
-var_locn__record_clobbering(Target, Assigns) -->
-	var_locn__get_loc_var_map(LocVarMap1),
-	( { map__search(LocVarMap1, Target, DependentVarsSet) } ->
-		{ set__to_sorted_list(DependentVarsSet, DependentVars) },
-		{ map__delete(LocVarMap1, Target, LocVarMap) },
-		var_locn__set_loc_var_map(LocVarMap),
+var_locn__record_clobbering(Target, Assigns, !VLI) :-
+	var_locn__get_loc_var_map(!.VLI, LocVarMap1),
+	( map__search(LocVarMap1, Target, DependentVarsSet) ->
+		set__to_sorted_list(DependentVarsSet, DependentVars),
+		map__delete(LocVarMap1, Target, LocVarMap),
+		var_locn__set_loc_var_map(LocVarMap, !VLI),
 
-		var_locn__get_var_state_map(VarStateMap2),
-		{ list__foldl(
+		var_locn__get_var_state_map(!.VLI, VarStateMap2),
+		list__foldl(
 			var_locn__clobber_lval_in_var_state_map(Target,
 				Assigns, no),
-			DependentVars, VarStateMap2, VarStateMap) },
-		var_locn__set_var_state_map(VarStateMap)
+			DependentVars, VarStateMap2, VarStateMap),
+		var_locn__set_var_state_map(VarStateMap, !VLI)
 	;
-		[]
+		true
 	).
 
 % Make Lval available, i.e. make sure that the values of all variables
@@ -1200,21 +1194,21 @@
 :- pred var_locn__free_up_lval(lval::in, list(prog_var)::in, list(lval)::in,
 	code_tree::out, var_locn_info::in, var_locn_info::out) is det.
 
-var_locn__free_up_lval(Lval, ToBeAssignedVars, ForbiddenLvals, Code) -->
+var_locn__free_up_lval(Lval, ToBeAssignedVars, ForbiddenLvals, Code, !VLI) :-
 	(
-		var_locn__get_loc_var_map(LocVarMap0),
-		{ map__search(LocVarMap0, Lval, AffectedVarSet) },
-		{ set__to_sorted_list(AffectedVarSet, AffectedVars) },
-		var_locn__get_var_state_map(VarStateMap0),
-		\+ { list__foldl(
+		var_locn__get_loc_var_map(!.VLI, LocVarMap0),
+		map__search(LocVarMap0, Lval, AffectedVarSet),
+		set__to_sorted_list(AffectedVarSet, AffectedVars),
+		var_locn__get_var_state_map(!.VLI, VarStateMap0),
+		\+ list__foldl(
 			var_locn__try_clobber_lval_in_var_state_map(
 				Lval, ToBeAssignedVars, no),
-			AffectedVars, VarStateMap0, _) }
+			AffectedVars, VarStateMap0, _)
 	->
 		var_locn__free_up_lval_with_copy(Lval, ToBeAssignedVars,
-			ForbiddenLvals, Code)
+			ForbiddenLvals, Code, !VLI)
 	;
-		{ Code = empty }
+		Code = empty
 	).
 
 % If we must copy the value in Lval somewhere else to prevent it from being
@@ -1238,55 +1232,56 @@
 	list(lval)::in, code_tree::out, var_locn_info::in, var_locn_info::out)
 	is det.
 
-var_locn__free_up_lval_with_copy(Lval, ToBeAssignedVars, ForbiddenLvals, Code)
-		-->
+var_locn__free_up_lval_with_copy(Lval, ToBeAssignedVars, ForbiddenLvals, Code,
+		!VLI) :-
 	(
-		var_locn__get_loc_var_map(LocVarMap0),
-		{ map__search(LocVarMap0, Lval, AffectedVarSet) },
-		{ set__delete_list(AffectedVarSet, ToBeAssignedVars,
-			EffAffectedVarSet) },
-		{ set__to_sorted_list(EffAffectedVarSet, EffAffectedVars) },
+		var_locn__get_loc_var_map(!.VLI, LocVarMap0),
+		map__search(LocVarMap0, Lval, AffectedVarSet),
+		set__delete_list(AffectedVarSet, ToBeAssignedVars,
+			EffAffectedVarSet),
+		set__to_sorted_list(EffAffectedVarSet, EffAffectedVars),
 
-		var_locn__get_var_state_map(VarStateMap0),
+		var_locn__get_var_state_map(!.VLI, VarStateMap0),
 		(
-			{ var_locn__find_one_occupying_var(EffAffectedVars,
+			var_locn__find_one_occupying_var(EffAffectedVars,
 				Lval, VarStateMap0, OccupyingVar,
-				OtherSources) }
+				OtherSources)
 		->
-			{ MovedVar = OccupyingVar },
-			{ list__delete_all(EffAffectedVars, MovedVar,
-				OtherVars) },
+			MovedVar = OccupyingVar,
+			list__delete_all(EffAffectedVars, MovedVar,
+				OtherVars),
 			list__foldl(var_locn__ensure_copies_are_present(
-				Lval, OtherSources), OtherVars)
+				Lval, OtherSources), OtherVars, !VLI)
 		;
-			{ EffAffectedVars = [MovedVar] }
+			EffAffectedVars = [MovedVar]
 		),
 
-		{ CheckInUse = no },
-		var_locn__select_preferred_reg_or_stack(MovedVar, Pref,
+		CheckInUse = no,
+		var_locn__select_preferred_reg_or_stack(!.VLI, MovedVar, Pref,
 			CheckInUse),
-		{ \+ Pref = Lval },
-		{ \+ list__member(Pref, ForbiddenLvals) },
-		( \+ var_locn__lval_in_use(Pref) ->
-			[]
+		\+ Pref = Lval,
+		\+ list__member(Pref, ForbiddenLvals),
+		( \+ var_locn__lval_in_use(!.VLI, Pref) ->
+			true
 		;
 				% The code generator assumes that values in
 				% stack slots don't get clobbered without an
 				% explicit assignment (via a place_var
 				% operation with a stack var as a target).
-			{ Pref = reg(r, RegNum) },
-			var_locn__reg_is_not_locked_for_var(RegNum, MovedVar)
+			Pref = reg(r, RegNum),
+			var_locn__reg_is_not_locked_for_var(!.VLI, RegNum,
+				MovedVar)
 		)
 	->
 		var_locn__actually_place_var(MovedVar, Pref,
-			[Lval | ForbiddenLvals], Code)
+			[Lval | ForbiddenLvals], Code, !VLI)
 	;
-		var_locn__get_spare_reg(Target),
-		var_locn__record_copy(Lval, Target),
-		{ Code = node([
+		var_locn__get_spare_reg(!.VLI, Target),
+		var_locn__record_copy(Lval, Target, !VLI),
+		Code = node([
 			assign(Target, lval(Lval))
 				- "Freeing up the source lval"
-		]) }
+		])
 	).
 
 % Find a variable in the given list that is currently stored directly in Lval
@@ -1311,35 +1306,35 @@
 :- pred var_locn__ensure_copies_are_present(lval::in, list(lval)::in,
 	prog_var::in, var_locn_info::in, var_locn_info::out) is det.
 
-var_locn__ensure_copies_are_present(OneSource, OtherSources, Var) -->
-	var_locn__get_var_state_map(VarStateMap0),
-	{ map__lookup(VarStateMap0, Var, State0) },
-	{ State0 = state(LvalSet0, MaybeConstRval, MaybeExprRval,
-		Using, DeadOrAlive) },
-	{ set__to_sorted_list(LvalSet0, Lvals0) },
-	{ list__foldl(var_locn__ensure_copies_are_present_lval(
-		OtherSources, OneSource), Lvals0, LvalSet0, LvalSet) },
-	{ State = state(LvalSet, MaybeConstRval, MaybeExprRval,
-		Using, DeadOrAlive) },
-	{ map__det_update(VarStateMap0, Var, State, VarStateMap) },
-	var_locn__set_var_state_map(VarStateMap),
-
-	var_locn__get_loc_var_map(LocVarMap0),
-	{ var_locn__record_change_in_root_dependencies(LvalSet0, LvalSet, Var,
-		LocVarMap0, LocVarMap) },
-	var_locn__set_loc_var_map(LocVarMap).
+var_locn__ensure_copies_are_present(OneSource, OtherSources, Var, !VLI) :-
+	var_locn__get_var_state_map(!.VLI, VarStateMap0),
+	map__lookup(VarStateMap0, Var, State0),
+	State0 = state(LvalSet0, MaybeConstRval, MaybeExprRval,
+		Using, DeadOrAlive),
+	set__to_sorted_list(LvalSet0, Lvals0),
+	list__foldl(var_locn__ensure_copies_are_present_lval(
+		OtherSources, OneSource), Lvals0, LvalSet0, LvalSet),
+	State = state(LvalSet, MaybeConstRval, MaybeExprRval,
+		Using, DeadOrAlive),
+	map__det_update(VarStateMap0, Var, State, VarStateMap),
+	var_locn__set_var_state_map(VarStateMap, !VLI),
+
+	var_locn__get_loc_var_map(!.VLI, LocVarMap0),
+	var_locn__record_change_in_root_dependencies(LvalSet0, LvalSet, Var,
+		LocVarMap0, LocVarMap),
+	var_locn__set_loc_var_map(LocVarMap, !VLI).
 
 :- pred var_locn__ensure_copies_are_present_lval(list(lval)::in, lval::in,
 	lval::in, set(lval)::in, set(lval)::out) is det.
 
-var_locn__ensure_copies_are_present_lval([], _, _, LvalSet, LvalSet).
+var_locn__ensure_copies_are_present_lval([], _, _, !LvalSet).
 var_locn__ensure_copies_are_present_lval([OtherSource | OtherSources],
-		OneSource, Lval, LvalSet0, LvalSet) :-
+		OneSource, Lval, !LvalSet) :-
 	SubstLval = var_locn__substitute_lval_in_lval(OneSource, OtherSource,
 		Lval),
-	set__insert(LvalSet0, SubstLval, LvalSet1),
-	var_locn__ensure_copies_are_present_lval(OtherSources,
-		OneSource, Lval, LvalSet1, LvalSet).
+	set__insert(!.LvalSet, SubstLval, !:LvalSet),
+	var_locn__ensure_copies_are_present_lval(OtherSources, OneSource, Lval,
+		!LvalSet).
 
 %----------------------------------------------------------------------------%
 
@@ -1357,28 +1352,28 @@
 :- pred var_locn__record_copy(lval::in, lval::in,
 	var_locn_info::in, var_locn_info::out) is det.
 
-var_locn__record_copy(Old, New) -->
-	{ require(var_locn__is_root_lval(New),
-		"var_locn__record_copy: non-root New lval") },
-	var_locn__get_var_state_map(VarStateMap0),
-	var_locn__get_loc_var_map(LocVarMap0),
-	{ set__list_to_set([Old, New], AssignSet) },
-	{ var_locn__get_var_set_roots(AssignSet, NoDupRootLvals) },
+var_locn__record_copy(Old, New, !VLI) :-
+	require(var_locn__is_root_lval(New),
+		"var_locn__record_copy: non-root New lval"),
+	var_locn__get_var_state_map(!.VLI, VarStateMap0),
+	var_locn__get_loc_var_map(!.VLI, LocVarMap0),
+	set__list_to_set([Old, New], AssignSet),
+	var_locn__get_var_set_roots(AssignSet, NoDupRootLvals),
 		% Convert the list of root lvals to the list of sets of
 		% affected vars; if a root lval is not in LocVarMap0,
 		% then it does not affect any variables.
-	{ list__filter_map(map__search(LocVarMap0), NoDupRootLvals,
-		AffectedVarSets) },
+	list__filter_map(map__search(LocVarMap0), NoDupRootLvals,
+		AffectedVarSets),
 		% Take the union of the list of sets of affected vars.
-	{ list__foldl(set__union, AffectedVarSets,
-		set__init, AffectedVarSet) },
+	list__foldl(set__union, AffectedVarSets,
+		set__init, AffectedVarSet),
 		% Convert the union set to a list of affected vars.
-	{ set__to_sorted_list(AffectedVarSet, AffectedVars) },
-	{ list__foldl2(var_locn__record_copy_for_var(Old, New),
+	set__to_sorted_list(AffectedVarSet, AffectedVars),
+	list__foldl2(var_locn__record_copy_for_var(Old, New),
 		AffectedVars, VarStateMap0, VarStateMap,
-		LocVarMap0, LocVarMap) },
-	var_locn__set_loc_var_map(LocVarMap),
-	var_locn__set_var_state_map(VarStateMap).
+		LocVarMap0, LocVarMap),
+	var_locn__set_loc_var_map(LocVarMap, !VLI),
+	var_locn__set_var_state_map(VarStateMap, !VLI).
 
 % Record the effect of the assignment New := Old on the state of the given
 % variable.
@@ -1401,14 +1396,14 @@
 %	that the assigned value is now in New.
 %
 % For example, with New and Old being as above and LvalSet0 being the set
-% { r5, field(3, field(0, r1, 2), 4) }:
+% r5, field(3, field(0, r1, 2), 4):
 %
-% -	Step 1 will set LvalSet1 to { r5, field(3, Token, 4) }, and LvalSet2
-% 	to { r5, field(3, field(0, r1, 2), 4), field(3, Token, 4) }.
+% -	Step 1 will set LvalSet1 to r5, field(3, Token, 4), and LvalSet2
+% 	to r5, field(3, field(0, r1, 2), 4), field(3, Token, 4).
 %
-% -	Step 2 will set LvalSet3 { r5, field(3, Token, 4) }.
+% -	Step 2 will set LvalSet3 r5, field(3, Token, 4).
 %
-% -	Step 3 will set LvalSet { r5, field(3, r1, 4) }.
+% -	Step 3 will set LvalSet r5, field(3, r1, 4).
 %
 % The reason why we don't need to modify the MaybeExprRval field in the
 % variable state is that the only lvals these fields can refer to are
@@ -1477,40 +1472,40 @@
 % called for Var, if FirstTime = yes, then as a consistency check we would like
 % to insist on Var being alive (but don't (yet) due to bugs in liveness).
 
-var_locn__var_becomes_dead(Var, FirstTime) -->
-	var_locn__get_var_state_map(VarStateMap0),
-	( { map__search(VarStateMap0, Var, State0) } ->
-		{ State0 = state(Lvals, MaybeConstRval, MaybeExprRval,
-			Using, DeadOrAlive0) },
-		( { DeadOrAlive0 = dead } ->
-			{ require(unify(FirstTime, no),
-				"var_locn__var_becomes_dead: already dead") }
-		;
-			[]
-		),
-		( { set__empty(Using) } ->
-			{ map__det_remove(VarStateMap0, Var, _, VarStateMap) },
-			var_locn__set_var_state_map(VarStateMap),
-
-			var_locn__get_loc_var_map(LocVarMap0),
-			{ var_locn__get_var_set_roots(Lvals, NoDupRootLvals) },
-			{ list__foldl(
+var_locn__var_becomes_dead(Var, FirstTime, !VLI) :-
+	var_locn__get_var_state_map(!.VLI, VarStateMap0),
+	( map__search(VarStateMap0, Var, State0) ->
+		State0 = state(Lvals, MaybeConstRval, MaybeExprRval,
+			Using, DeadOrAlive0),
+		( DeadOrAlive0 = dead ->
+			require(unify(FirstTime, no),
+				"var_locn__var_becomes_dead: already dead")
+		;
+			true
+		),
+		( set__empty(Using) ->
+			map__det_remove(VarStateMap0, Var, _, VarStateMap),
+			var_locn__set_var_state_map(VarStateMap, !VLI),
+
+			var_locn__get_loc_var_map(!.VLI, LocVarMap0),
+			var_locn__get_var_set_roots(Lvals, NoDupRootLvals),
+			list__foldl(
 				var_locn__make_var_not_depend_on_root_lval(
 					Var),
-				NoDupRootLvals, LocVarMap0, LocVarMap) },
-			var_locn__set_loc_var_map(LocVarMap),
+				NoDupRootLvals, LocVarMap0, LocVarMap),
+			var_locn__set_loc_var_map(LocVarMap, !VLI),
 
-			var_locn__remove_use_refs(MaybeExprRval, Var)
+			var_locn__remove_use_refs(MaybeExprRval, Var, !VLI)
 		;
-			{ State = state(Lvals, MaybeConstRval, MaybeExprRval,
-				Using, dead) },
-			{ map__det_update(VarStateMap0, Var, State,
-				VarStateMap) },
-			var_locn__set_var_state_map(VarStateMap)
+			State = state(Lvals, MaybeConstRval, MaybeExprRval,
+				Using, dead),
+			map__det_update(VarStateMap0, Var, State,
+				VarStateMap),
+			var_locn__set_var_state_map(VarStateMap, !VLI)
 		)
 	;
-		{ require(unify(FirstTime, no),
-			"var_locn__var_becomes_dead: premature deletion") }
+		require(unify(FirstTime, no),
+			"var_locn__var_becomes_dead: premature deletion")
 	).
 
 % Given a set of lvals, return the set of root lvals among them and inside
@@ -1615,46 +1610,46 @@
 
 %----------------------------------------------------------------------------%
 
-:- pred var_locn__select_preferred_reg_avoid(prog_var::in, list(lval)::in,
-	lval::out, var_locn_info::in, var_locn_info::out) is det.
+:- pred var_locn__select_preferred_reg_avoid(var_locn_info::in, prog_var::in,
+	list(lval)::in, lval::out) is det.
 
-var_locn__select_preferred_reg_avoid(Var, Avoid, Lval) -->
-	var_locn__select_preferred_reg(Var, yes, Avoid, Lval).
+var_locn__select_preferred_reg_avoid(VLI, Var, Avoid, Lval) :-
+	var_locn__select_preferred_reg(VLI, Var, yes, Avoid, Lval).
 
-:- pred var_locn__select_preferred_reg(prog_var::in, lval::out,
-	var_locn_info::in, var_locn_info::out) is det.
+:- pred var_locn__select_preferred_reg(var_locn_info::in, prog_var::in,
+	lval::out) is det.
 
-var_locn__select_preferred_reg(Var, Lval) -->
-	var_locn__select_preferred_reg(Var, yes, [], Lval).
+var_locn__select_preferred_reg(VLI, Var, Lval) :-
+	var_locn__select_preferred_reg(VLI, Var, yes, [], Lval).
 
 % Select the register into which Var should be put. If the follow_vars map
 % maps Var to a register, then select that register, unless it is already in
 % use, and CheckInUse = yes.
 
-:- pred var_locn__select_preferred_reg(prog_var::in, bool::in, list(lval)::in,
-	lval::out, var_locn_info::in, var_locn_info::out) is det.
+:- pred var_locn__select_preferred_reg(var_locn_info::in, prog_var::in,
+	bool::in, list(lval)::in, lval::out) is det.
 
-var_locn__select_preferred_reg(Var, CheckInUse, Avoid, Lval) -->
-	var_locn__get_follow_var_map(FollowVarMap),
+var_locn__select_preferred_reg(VLI, Var, CheckInUse, Avoid, Lval) :-
+	var_locn__get_follow_var_map(VLI, FollowVarMap),
 	(
-		{ map__search(FollowVarMap, Var, PrefLval) },
-		{ PrefLval = reg(_, _) }
+		map__search(FollowVarMap, Var, PrefLval),
+		PrefLval = reg(_, _)
 	->
 		(
-			{ real_lval(PrefLval) },
-			( { CheckInUse = yes } ->
-				\+ var_locn__lval_in_use(PrefLval)
+			real_lval(PrefLval),
+			( CheckInUse = yes ->
+				\+ var_locn__lval_in_use(VLI, PrefLval)
 			;
-				[]
+				true
 			),
-			{ \+ list__member(PrefLval, Avoid) }
+			\+ list__member(PrefLval, Avoid)
 		->
-			{ Lval = PrefLval }
+			Lval = PrefLval
 		;
-			var_locn__get_spare_reg_avoid(Avoid, Lval)
+			var_locn__get_spare_reg_avoid(VLI, Avoid, Lval)
 		)
 	;
-		var_locn__get_spare_reg_avoid(Avoid, Lval)
+		var_locn__get_spare_reg_avoid(VLI, Avoid, Lval)
 	).
 
 % Select the register or stack slot into which Var should be put. If the
@@ -1667,46 +1662,46 @@
 % maps will be empty, which would cause this predicate to try to put far too
 % many things in stack slots.)
 
-:- pred var_locn__select_preferred_reg_or_stack(prog_var::in, lval::out,
-	var_locn_info::in, var_locn_info::out) is det.
+:- pred var_locn__select_preferred_reg_or_stack_check(var_locn_info::in,
+	prog_var::in, lval::out) is det.
 
-var_locn__select_preferred_reg_or_stack(Var, Lval) -->
-	var_locn__select_preferred_reg_or_stack(Var, Lval, yes).
+var_locn__select_preferred_reg_or_stack_check(VLI, Var, Lval) :-
+	var_locn__select_preferred_reg_or_stack(VLI, Var, Lval, yes).
 
-:- pred var_locn__select_preferred_reg_or_stack(prog_var::in, lval::out,
-	bool::in, var_locn_info::in, var_locn_info::out) is det.
+:- pred var_locn__select_preferred_reg_or_stack(var_locn_info::in,
+	prog_var::in, lval::out, bool::in) is det.
 
-var_locn__select_preferred_reg_or_stack(Var, Lval, CheckInUse) -->
-	var_locn__get_follow_var_map(FollowVarMap),
+var_locn__select_preferred_reg_or_stack(VLI, Var, Lval, CheckInUse) :-
+	var_locn__get_follow_var_map(VLI, FollowVarMap),
 	(
-		{ map__search(FollowVarMap, Var, PrefLval) },
-		{ PrefLval = reg(_, _) }
+		map__search(FollowVarMap, Var, PrefLval),
+		PrefLval = reg(_, _)
 	->
 		(
-			{ real_lval(PrefLval) },
-			( { CheckInUse = yes } ->
-				\+ var_locn__lval_in_use(PrefLval)
+			real_lval(PrefLval),
+			( CheckInUse = yes ->
+				\+ var_locn__lval_in_use(VLI, PrefLval)
 			;
-				[]
+				true
 			)
 		->
-			{ Lval = PrefLval }
+			Lval = PrefLval
 		;
-			var_locn__get_spare_reg(Lval)
+			var_locn__get_spare_reg(VLI, Lval)
 		)
 	;
 		(
-			var_locn__get_stack_slots(StackSlots),
-			{ map__search(StackSlots, Var, StackSlot) },
-			( { CheckInUse = yes } ->
-				\+ var_locn__lval_in_use(StackSlot)
+			var_locn__get_stack_slots(VLI, StackSlots),
+			map__search(StackSlots, Var, StackSlot),
+			( CheckInUse = yes ->
+				\+ var_locn__lval_in_use(VLI, StackSlot)
 			;
-				[]
+				true
 			)
 		->
-			{ Lval = StackSlot }
+			Lval = StackSlot
 		;
-			var_locn__get_spare_reg(Lval)
+			var_locn__get_spare_reg(VLI, Lval)
 		)
 	).
 
@@ -1723,40 +1718,39 @@
 % Get a register that is not in use. We start the search at the next register
 % that is needed for the next call.
 
-:- pred var_locn__get_spare_reg_avoid(list(lval)::in, lval::out,
-	var_locn_info::in, var_locn_info::out) is det.
-
-var_locn__get_spare_reg_avoid(Avoid, Lval) -->
-	var_locn__get_next_non_reserved(NextNonReserved),
-	var_locn__get_spare_reg_2(Avoid, NextNonReserved, Lval).
+:- pred var_locn__get_spare_reg_avoid(var_locn_info::in, list(lval)::in,
+	lval::out) is det.
 
-:- pred var_locn__get_spare_reg(lval::out,
-	var_locn_info::in, var_locn_info::out) is det.
-
-var_locn__get_spare_reg(Lval) -->
-	var_locn__get_next_non_reserved(NextNonReserved),
-	var_locn__get_spare_reg_2([], NextNonReserved, Lval).
-
-:- pred var_locn__get_spare_reg_2(list(lval)::in, int::in, lval::out,
-	var_locn_info::in, var_locn_info::out) is det.
-
-var_locn__get_spare_reg_2(Avoid, N0, Lval) -->
-	{ TryLval = reg(r, N0) },
-	( var_locn__lval_in_use(TryLval) ->
-		var_locn__get_spare_reg_2(Avoid, N0 + 1, Lval)
-	; { list__member(TryLval, Avoid) } ->
-		var_locn__get_spare_reg_2(Avoid, N0 + 1, Lval)
+var_locn__get_spare_reg_avoid(VLI, Avoid, Lval) :-
+	var_locn__get_next_non_reserved(VLI, NextNonReserved),
+	var_locn__get_spare_reg_2(VLI, Avoid, NextNonReserved, Lval).
+
+:- pred var_locn__get_spare_reg(var_locn_info::in, lval::out) is det.
+
+var_locn__get_spare_reg(VLI, Lval) :-
+	var_locn__get_next_non_reserved(VLI, NextNonReserved),
+	var_locn__get_spare_reg_2(VLI, [], NextNonReserved, Lval).
+
+:- pred var_locn__get_spare_reg_2(var_locn_info::in, list(lval)::in, int::in,
+	lval::out) is det.
+
+var_locn__get_spare_reg_2(VLI, Avoid, N0, Lval) :-
+	TryLval = reg(r, N0),
+	( var_locn__lval_in_use(VLI, TryLval) ->
+		var_locn__get_spare_reg_2(VLI, Avoid, N0 + 1, Lval)
+	; list__member(TryLval, Avoid) ->
+		var_locn__get_spare_reg_2(VLI, Avoid, N0 + 1, Lval)
 	;
-		{ Lval = TryLval }
+		Lval = TryLval
 	).
 
 % Succeeds if Lval is currently in use or locked.
 
-var_locn__lval_in_use(Lval) -->
-	var_locn__get_loc_var_map(LocVarMap),
-	var_locn__get_acquired(Acquired),
-	var_locn__get_locked(Locked),
-	{
+var_locn__lval_in_use(VLI, Lval) :-
+	var_locn__get_loc_var_map(VLI, LocVarMap),
+	var_locn__get_acquired(VLI, Acquired),
+	var_locn__get_locked(VLI, Locked),
+	(
 		map__search(LocVarMap, Lval, UsingVars),
 		\+ set__empty(UsingVars)
 	;
@@ -1764,91 +1758,89 @@
 	;
 		Lval = reg(r, N),
 		N =< Locked
-	}.
+	).
 
 % Succeeds if Var may be stored in Reg, possibly after copying its contents
 % somewhere else. This requires Reg to be either not locked, or if it is
 % locked, to be locked for Var.
 
-:- pred var_locn__reg_is_not_locked_for_var(int::in, prog_var::in,
-	var_locn_info::in, var_locn_info::out) is semidet.
+:- pred var_locn__reg_is_not_locked_for_var(var_locn_info::in, int::in,
+	prog_var::in) is semidet.
 
-var_locn__reg_is_not_locked_for_var(RegNum, Var) -->
-	var_locn__get_acquired(Acquired),
-	var_locn__get_locked(Locked),
-	var_locn__get_exceptions(Exceptions),
-	{
+var_locn__reg_is_not_locked_for_var(VLI, RegNum, Var) :-
+	var_locn__get_acquired(VLI, Acquired),
+	var_locn__get_locked(VLI, Locked),
+	var_locn__get_exceptions(VLI, Exceptions),
 		Reg = reg(r, RegNum),
 		\+ set__member(Reg, Acquired),
-		RegNum =< Locked => list__member(Var - Reg, Exceptions)
-	}.
+	RegNum =< Locked => list__member(Var - Reg, Exceptions).
 
 %----------------------------------------------------------------------------%
 
-var_locn__acquire_reg(Lval) -->
-	var_locn__get_spare_reg(Lval),
-	var_locn__get_acquired(Acquired0),
-	{ set__insert(Acquired0, Lval, Acquired) },
-	var_locn__set_acquired(Acquired).
+var_locn__acquire_reg(Lval, !VLI) :-
+	var_locn__get_spare_reg(!.VLI, Lval),
+	var_locn__get_acquired(!.VLI, Acquired0),
+	set__insert(Acquired0, Lval, Acquired),
+	var_locn__set_acquired(Acquired, !VLI).
 
-var_locn__acquire_reg_require_given(Lval) -->
-	( var_locn__lval_in_use(Lval) ->
-		{ error("var_locn__acquire_reg_require_given: lval in use") }
+var_locn__acquire_reg_require_given(Lval, !VLI) :-
+	( var_locn__lval_in_use(!.VLI, Lval) ->
+		error("var_locn__acquire_reg_require_given: lval in use")
 	;
-		[]
+		true
 	),
-	var_locn__get_acquired(Acquired0),
-	{ set__insert(Acquired0, Lval, Acquired) },
-	var_locn__set_acquired(Acquired).
-
-var_locn__acquire_reg_prefer_given(Pref, Lval) -->
-	{ PrefLval = reg(r, Pref) },
-	( var_locn__lval_in_use(PrefLval) ->
-		var_locn__get_spare_reg(Lval)
+	var_locn__get_acquired(!.VLI, Acquired0),
+	set__insert(Acquired0, Lval, Acquired),
+	var_locn__set_acquired(Acquired, !VLI).
+
+var_locn__acquire_reg_prefer_given(Pref, Lval, !VLI) :-
+	PrefLval = reg(r, Pref),
+	( var_locn__lval_in_use(!.VLI, PrefLval) ->
+		var_locn__get_spare_reg(!.VLI, Lval)
 	;
-		{ Lval = PrefLval }
+		Lval = PrefLval
 	),
-	var_locn__get_acquired(Acquired0),
-	{ set__insert(Acquired0, Lval, Acquired) },
-	var_locn__set_acquired(Acquired).
+	var_locn__get_acquired(!.VLI, Acquired0),
+	set__insert(Acquired0, Lval, Acquired),
+	var_locn__set_acquired(Acquired, !VLI).
 
-var_locn__acquire_reg_start_at_given(Start, Lval) -->
-	{ StartLval = reg(r, Start) },
-	( var_locn__lval_in_use(StartLval) ->
-		var_locn__acquire_reg_start_at_given(Start + 1, Lval)
+var_locn__acquire_reg_start_at_given(Start, Lval, !VLI) :-
+	StartLval = reg(r, Start),
+	( var_locn__lval_in_use(!.VLI, StartLval) ->
+		var_locn__acquire_reg_start_at_given(Start + 1, Lval, !VLI)
 	;
-		{ Lval = StartLval },
-		var_locn__get_acquired(Acquired0),
-		{ set__insert(Acquired0, Lval, Acquired) },
-		var_locn__set_acquired(Acquired)
+		Lval = StartLval,
+		var_locn__get_acquired(!.VLI, Acquired0),
+		set__insert(Acquired0, Lval, Acquired),
+		var_locn__set_acquired(Acquired, !VLI)
 	).
 
-var_locn__release_reg(Lval) -->
-	var_locn__get_acquired(Acquired0),
-	( { set__member(Lval, Acquired0) } ->
-		{ set__delete(Acquired0, Lval, Acquired) },
-		var_locn__set_acquired(Acquired)
+var_locn__release_reg(Lval, !VLI) :-
+	var_locn__get_acquired(!.VLI, Acquired0),
+	( set__member(Lval, Acquired0) ->
+		set__delete(Acquired0, Lval, Acquired),
+		var_locn__set_acquired(Acquired, !VLI)
 	;
-		{ error("var_locn__release_reg: unacquired reg") }
+		error("var_locn__release_reg: unacquired reg")
 	).
 
 %----------------------------------------------------------------------------%
 
-var_locn__lock_regs(N, Exceptions) -->
-	var_locn__set_locked(N),
-	var_locn__set_exceptions(Exceptions).
+var_locn__lock_regs(N, Exceptions, !VLI) :-
+	var_locn__set_locked(N, !VLI),
+	var_locn__set_exceptions(Exceptions, !VLI).
 
-var_locn__unlock_regs -->
-	var_locn__set_locked(0),
-	var_locn__set_exceptions([]).
+var_locn__unlock_regs(!VLI) :-
+	var_locn__set_locked(0, !VLI),
+	var_locn__set_exceptions([], !VLI).
 
 %----------------------------------------------------------------------------%
 
-var_locn__max_reg_in_use(VarLocnInfo, Max) :-
-	var_locn__get_loc_var_map(LocVarMap, VarLocnInfo, _),
+var_locn__max_reg_in_use(VLI, Max) :-
+	var_locn__get_loc_var_map(VLI, LocVarMap),
 	map__keys(LocVarMap, VarLocs),
 	code_util__max_mentioned_reg(VarLocs, Max1),
-	var_locn__get_acquired(Acquired, VarLocnInfo, _),
+	var_locn__get_acquired(VLI, Acquired),
 	set__to_sorted_list(Acquired, AcquiredList),
 	code_util__max_mentioned_reg(AcquiredList, Max2),
 	int__max(Max1, Max2, Max).
@@ -1901,90 +1893,90 @@
 
 % Lval is Lval0 with all variables in Lval0 replaced by their values.
 
-var_locn__materialize_vars_in_lval(Lval0, Lval, Code) -->
-	var_locn__materialize_vars_in_lval(Lval0, [], Lval, Code).
+var_locn__materialize_vars_in_lval(Lval0, Lval, Code, !VLI) :-
+	var_locn__materialize_vars_in_lval(Lval0, [], Lval, Code, !VLI).
 
 :- pred var_locn__materialize_vars_in_lval(lval::in, list(lval)::in,
 	lval::out, code_tree::out,
 	var_locn_info::in, var_locn_info::out) is det.
 
-var_locn__materialize_vars_in_lval(Lval0, Avoid, Lval, Code) -->
+var_locn__materialize_vars_in_lval(Lval0, Avoid, Lval, Code, !VLI) :-
 	(
-		{ Lval0 = reg(_, _) },
-		{ Lval = Lval0 },
-		{ Code = empty }
+		Lval0 = reg(_, _),
+		Lval = Lval0,
+		Code = empty
 	;
-		{ Lval0 = stackvar(_) },
-		{ Lval = Lval0 },
-		{ Code = empty }
+		Lval0 = stackvar(_),
+		Lval = Lval0,
+		Code = empty
 	;
-		{ Lval0 = framevar(_) },
-		{ Lval = Lval0 },
-		{ Code = empty }
+		Lval0 = framevar(_),
+		Lval = Lval0,
+		Code = empty
 	;
-		{ Lval0 = succip },
-		{ Lval = Lval0 },
-		{ Code = empty }
+		Lval0 = succip,
+		Lval = Lval0,
+		Code = empty
 	;
-		{ Lval0 = maxfr },
-		{ Lval = Lval0 },
-		{ Code = empty }
+		Lval0 = maxfr,
+		Lval = Lval0,
+		Code = empty
 	;
-		{ Lval0 = curfr },
-		{ Lval = Lval0 },
-		{ Code = empty }
+		Lval0 = curfr,
+		Lval = Lval0,
+		Code = empty
 	;
-		{ Lval0 = hp },
-		{ Lval = Lval0 },
-		{ Code = empty }
+		Lval0 = hp,
+		Lval = Lval0,
+		Code = empty
 	;
-		{ Lval0 = sp },
-		{ Lval = Lval0 },
-		{ Code = empty }
+		Lval0 = sp,
+		Lval = Lval0,
+		Code = empty
 	;
-		{ Lval0 = succip(Rval0) },
+		Lval0 = succip(Rval0),
 		var_locn__materialize_vars_in_rval(Rval0, no, Avoid,
-			Rval, Code),
-		{ Lval = succip(Rval) }
+			Rval, Code, !VLI),
+		Lval = succip(Rval)
 	;
-		{ Lval0 = redoip(Rval0) },
+		Lval0 = redoip(Rval0),
 		var_locn__materialize_vars_in_rval(Rval0, no, Avoid,
-			Rval, Code),
-		{ Lval = redoip(Rval) }
+			Rval, Code, !VLI),
+		Lval = redoip(Rval)
 	;
-		{ Lval0 = succfr(Rval0) },
+		Lval0 = succfr(Rval0),
 		var_locn__materialize_vars_in_rval(Rval0, no, Avoid,
-			Rval, Code),
-		{ Lval = succfr(Rval) }
+			Rval, Code, !VLI),
+		Lval = succfr(Rval)
 	;
-		{ Lval0 = redofr(Rval0) },
+		Lval0 = redofr(Rval0),
 		var_locn__materialize_vars_in_rval(Rval0, no, Avoid,
-			Rval, Code),
-		{ Lval = redofr(Rval) }
+			Rval, Code, !VLI),
+		Lval = redofr(Rval)
 	;
-		{ Lval0 = prevfr(Rval0) },
+		Lval0 = prevfr(Rval0),
 		var_locn__materialize_vars_in_rval(Rval0, no, Avoid,
-			Rval, Code),
-		{ Lval = prevfr(Rval) }
+			Rval, Code, !VLI),
+		Lval = prevfr(Rval)
 	;
-		{ Lval0 = mem_ref(Rval0) },
+		Lval0 = mem_ref(Rval0),
 		var_locn__materialize_vars_in_rval(Rval0, no, Avoid,
-			Rval, Code),
-		{ Lval = mem_ref(Rval) }
+			Rval, Code, !VLI),
+		Lval = mem_ref(Rval)
 	;
-		{ Lval0 = field(Tag, RvalA0, RvalB0) },
+		Lval0 = field(Tag, RvalA0, RvalB0),
 		var_locn__materialize_vars_in_rval(RvalA0, no, Avoid,
-			RvalA, CodeA),
+			RvalA, CodeA, !VLI),
 		var_locn__materialize_vars_in_rval(RvalB0, no, Avoid,
-			RvalB, CodeB),
-		{ Lval = field(Tag, RvalA, RvalB) },
-		{ Code = tree(CodeA, CodeB) }
+			RvalB, CodeB, !VLI),
+		Lval = field(Tag, RvalA, RvalB),
+		Code = tree(CodeA, CodeB)
 	;
-		{ Lval0 = temp(_, _) },
-		{ error("var_locn__materialize_vars_in_lval: temp") }
+		Lval0 = temp(_, _),
+		error("var_locn__materialize_vars_in_lval: temp")
 	;
-		{ Lval0 = lvar(_) },
-		{ error("var_locn__materialize_vars_in_lval: lvar") }
+		Lval0 = lvar(_),
+		error("var_locn__materialize_vars_in_lval: lvar")
 	).
 
 % Rval is Rval0 with all variables in Rval0 replaced by their values.
@@ -1993,47 +1985,50 @@
 	list(lval)::in, rval::out, code_tree::out,
 	var_locn_info::in, var_locn_info::out) is det.
 
-var_locn__materialize_vars_in_rval(Rval0, MaybePrefer, Avoid, Rval, Code) -->
+var_locn__materialize_vars_in_rval(Rval0, MaybePrefer, Avoid, Rval, Code,
+		!VLI) :-
 	(
-		{ Rval0 = lval(Lval0) },
-		var_locn__materialize_vars_in_lval(Lval0, Avoid, Lval, Code),
-		{ Rval = lval(Lval) }
+		Rval0 = lval(Lval0),
+		var_locn__materialize_vars_in_lval(Lval0, Avoid, Lval, Code,
+			!VLI),
+		Rval = lval(Lval)
 	;
-		{ Rval0 = mkword(Tag, SubRval0) },
+		Rval0 = mkword(Tag, SubRval0),
 		var_locn__materialize_vars_in_rval(SubRval0, no, Avoid,
-			SubRval, Code),
-		{ Rval = mkword(Tag, SubRval) }
+			SubRval, Code, !VLI),
+		Rval = mkword(Tag, SubRval)
 	;
-		{ Rval0 = unop(Unop, SubRval0) },
+		Rval0 = unop(Unop, SubRval0),
 		var_locn__materialize_vars_in_rval(SubRval0, no, Avoid,
-			SubRval, Code),
-		{ Rval = unop(Unop, SubRval) }
+			SubRval, Code, !VLI),
+		Rval = unop(Unop, SubRval)
 	;
-		{ Rval0 = binop(Binop, SubRvalA0, SubRvalB0) },
+		Rval0 = binop(Binop, SubRvalA0, SubRvalB0),
 		var_locn__materialize_vars_in_rval(SubRvalA0, no, Avoid,
-			SubRvalA, CodeA),
+			SubRvalA, CodeA, !VLI),
 		var_locn__materialize_vars_in_rval(SubRvalB0, no, Avoid,
-			SubRvalB, CodeB),
-		{ Rval = binop(Binop, SubRvalA, SubRvalB) },
-		{ Code = tree(CodeA, CodeB) }
+			SubRvalB, CodeB, !VLI),
+		Rval = binop(Binop, SubRvalA, SubRvalB),
+		Code = tree(CodeA, CodeB)
 	;
-		{ Rval0 = const(_) },
-		{ Rval = Rval0 },
-		{ Code = empty }
+		Rval0 = const(_),
+		Rval = Rval0,
+		Code = empty
 	;
-		{ Rval0 = mem_addr(_) },
-		{ Rval = Rval0 },
-		{ Code = empty }
+		Rval0 = mem_addr(_),
+		Rval = Rval0,
+		Code = empty
 	;
-		{ Rval0 = var(Var) },
-		var_locn__find_var_availability(Var, MaybePrefer, Avail),
+		Rval0 = var(Var),
+		var_locn__find_var_availability(!.VLI, Var, MaybePrefer,
+			Avail),
 		(
-			{ Avail = available(Rval) },
-			{ Code = empty }
+			Avail = available(Rval),
+			Code = empty
 		;
-			{ Avail = needs_materialization },
+			Avail = needs_materialization,
 			var_locn__materialize_var(Var, MaybePrefer, yes,
-				Avoid, Rval, Code)
+				Avoid, Rval, Code, !VLI)
 		)
 	).
 
@@ -2041,58 +2036,59 @@
 	--->	available(rval)
 	;	needs_materialization.
 
-:- pred var_locn__find_var_availability(prog_var::in, maybe(lval)::in,
-	var_avail::out, var_locn_info::in, var_locn_info::out) is det.
+:- pred var_locn__find_var_availability(var_locn_info::in, prog_var::in,
+	maybe(lval)::in, var_avail::out) is det.
 
-var_locn__find_var_availability(Var, MaybePrefer, Avail) -->
-	var_locn__get_var_state_map(VarStateMap),
-	{ map__lookup(VarStateMap, Var, State) },
-	{ State = state(Lvals, MaybeConstRval, _, _, _) },
-	{ set__to_sorted_list(Lvals, LvalsList) },
+var_locn__find_var_availability(VLI, Var, MaybePrefer, Avail) :-
+	var_locn__get_var_state_map(VLI, VarStateMap),
+	map__lookup(VarStateMap, Var, State),
+	State = state(Lvals, MaybeConstRval, _, _, _),
+	set__to_sorted_list(Lvals, LvalsList),
 	(
-		{ MaybePrefer = yes(Prefer) },
-		{ list__member(Prefer, LvalsList) }
+		MaybePrefer = yes(Prefer),
+		list__member(Prefer, LvalsList)
 	->
-		{ Rval = lval(Prefer) },
-		{ Avail = available(Rval) }
+		Rval = lval(Prefer),
+		Avail = available(Rval)
 	;
-		{ var_locn__maybe_select_lval_or_rval(LvalsList,
-			MaybeConstRval, Rval) }
+		var_locn__maybe_select_lval_or_rval(LvalsList,
+			MaybeConstRval, Rval)
 	->
-		{ Avail = available(Rval) }
+		Avail = available(Rval)
 	;
-		{ Avail = needs_materialization }
+		Avail = needs_materialization
 	).
 
 :- pred var_locn__materialize_var(prog_var::in, maybe(lval)::in, bool::in,
 	list(lval)::in, rval::out, code_tree::out,
 	var_locn_info::in, var_locn_info::out) is det.
 
-var_locn__materialize_var(Var, MaybePrefer, StoreIfReq, Avoid, Rval, Code) -->
-	var_locn__get_var_state_map(VarStateMap),
-	{ map__lookup(VarStateMap, Var, State) },
-	{ State = state(_Lvals, _MaybeConstRval, MaybeExprRval,
-		UsingVars, _DeadOrAlive) },
-	{
+var_locn__materialize_var(Var, MaybePrefer, StoreIfReq, Avoid, Rval, Code,
+		!VLI) :-
+	var_locn__get_var_state_map(!.VLI, VarStateMap),
+	map__lookup(VarStateMap, Var, State),
+	State = state(_Lvals, _MaybeConstRval, MaybeExprRval,
+		UsingVars, _DeadOrAlive),
+	(
 		MaybeExprRval = yes(ExprRval)
 	;
 		MaybeExprRval = no,
 		error("var_locn__materialize_var: no expr")
-	},
+	),
 	var_locn__materialize_vars_in_rval(ExprRval, MaybePrefer, Avoid,
-		Rval0, ExprCode),
+		Rval0, ExprCode, !VLI),
 	(
-		{ StoreIfReq = yes },
-		{ set__count(UsingVars, NumUsingVars) },
-		{ NumUsingVars > 1 }
-	->
-		var_locn__select_preferred_reg_avoid(Var, Avoid, Lval),
-		var_locn__place_var(Var, Lval, PlaceCode),
-		{ Rval = lval(Lval) },
-		{ Code = tree(ExprCode, PlaceCode) }
+		StoreIfReq = yes,
+		set__count(UsingVars, NumUsingVars),
+		NumUsingVars > 1
+	->
+		var_locn__select_preferred_reg_avoid(!.VLI, Var, Avoid, Lval),
+		var_locn__place_var(Var, Lval, PlaceCode, !VLI),
+		Rval = lval(Lval),
+		Code = tree(ExprCode, PlaceCode)
 	;
-		{ Rval = Rval0 },
-		{ Code = ExprCode }
+		Rval = Rval0,
+		Code = ExprCode
 	).
 
 %----------------------------------------------------------------------------%
@@ -2103,32 +2099,30 @@
 :- pred var_locn__make_var_depend_on_lvals_roots(prog_var::in,
 	set(lval)::in, loc_var_map::in, loc_var_map::out) is det.
 
-var_locn__make_var_depend_on_lvals_roots(Var, Lvals,
-		LocVarMap0, LocVarMap) :-
+var_locn__make_var_depend_on_lvals_roots(Var, Lvals, !LocVarMap) :-
 	var_locn__get_var_set_roots(Lvals, NoDupRootLvals),
 	list__foldl(var_locn__make_var_depend_on_root_lval(Var),
-		NoDupRootLvals, LocVarMap0, LocVarMap).
+		NoDupRootLvals, !LocVarMap).
 
 :- pred var_locn__make_var_depend_on_lval_roots(prog_var::in,
 	lval::in, loc_var_map::in, loc_var_map::out) is det.
 
-var_locn__make_var_depend_on_lval_roots(Var, Lval, LocVarMap0, LocVarMap) :-
+var_locn__make_var_depend_on_lval_roots(Var, Lval, !LocVarMap) :-
 	set__singleton_set(Lvals, Lval),
-	var_locn__make_var_depend_on_lvals_roots(Var, Lvals,
-		LocVarMap0, LocVarMap).
+	var_locn__make_var_depend_on_lvals_roots(Var, Lvals, !LocVarMap).
 
 :- pred var_locn__make_var_depend_on_root_lval(prog_var::in, lval::in,
 	loc_var_map::in, loc_var_map::out) is det.
 
-var_locn__make_var_depend_on_root_lval(Var, Lval, LocVarMap0, LocVarMap) :-
+var_locn__make_var_depend_on_root_lval(Var, Lval, !LocVarMap) :-
 	require(var_locn__is_root_lval(Lval),
 		"var_locn__make_var_depend_on_root_lval: non-root lval"),
-	( map__search(LocVarMap0, Lval, Vars0) ->
+	( map__search(!.LocVarMap, Lval, Vars0) ->
 		set__insert(Vars0, Var, Vars),
-		map__det_update(LocVarMap0, Lval, Vars, LocVarMap)
+		map__det_update(!.LocVarMap, Lval, Vars, !:LocVarMap)
 	;
 		set__singleton_set(Vars, Var),
-		map__det_insert(LocVarMap0, Lval, Vars, LocVarMap)
+		map__det_insert(!.LocVarMap, Lval, Vars, !:LocVarMap)
 	).
 
 % Update LocVarMap0 to reflect that Var is no longer dependent on the root lval
@@ -2137,15 +2131,15 @@
 :- pred var_locn__make_var_not_depend_on_root_lval(prog_var::in, lval::in,
 	loc_var_map::in, loc_var_map::out) is det.
 
-var_locn__make_var_not_depend_on_root_lval(Var, Lval, LocVarMap0, LocVarMap) :-
+var_locn__make_var_not_depend_on_root_lval(Var, Lval, !LocVarMap) :-
 	require(var_locn__is_root_lval(Lval),
 		"var_locn__make_var_depend_on_root_lval: non-root lval"),
-	( map__search(LocVarMap0, Lval, Vars0) ->
+	( map__search(!.LocVarMap, Lval, Vars0) ->
 		set__delete(Vars0, Var, Vars),
 		( set__empty(Vars) ->
-			map__det_remove(LocVarMap0, Lval, _, LocVarMap)
+			map__det_remove(!.LocVarMap, Lval, _, !:LocVarMap)
 		;
-			map__det_update(LocVarMap0, Lval, Vars, LocVarMap)
+			map__det_update(!.LocVarMap, Lval, Vars, !:LocVarMap)
 		)
 	;
 		error("var_locn__make_var_not_depend_on_root_lval: no record")
@@ -2229,18 +2223,18 @@
 
 %----------------------------------------------------------------------------%
 
-var_locn__set_follow_vars(follow_vars(FollowVarMap, NextNonReserved)) -->
-	var_locn__set_follow_var_map(FollowVarMap),
-	var_locn__set_next_non_reserved(NextNonReserved).
+var_locn__set_follow_vars(follow_vars(FollowVarMap, NextNonReserved), !VLI) :-
+	var_locn__set_follow_var_map(FollowVarMap, !VLI),
+	var_locn__set_next_non_reserved(NextNonReserved, !VLI).
 
 %----------------------------------------------------------------------------%
 
-:- pred var_locn__get_var_name(prog_var::in, string::out,
-	var_locn_info::in, var_locn_info::out) is det.
+:- pred var_locn__get_var_name(var_locn_info::in, prog_var::in, string::out)
+	is det.
 
-var_locn__get_var_name(Var, Name) -->
-	var_locn__get_varset(Varset),
-	{ varset__lookup_name(Varset, Var, Name) }.
+var_locn__get_var_name(VLI, Var, Name) :-
+	var_locn__get_varset(VLI, Varset),
+	varset__lookup_name(Varset, Var, Name).
 
 %----------------------------------------------------------------------------%
 
@@ -2255,61 +2249,50 @@
 
 %----------------------------------------------------------------------------%
 
-:- pred var_locn__get_varset(prog_varset::out,
-	var_locn_info::in, var_locn_info::out) is det.
+:- pred var_locn__get_varset(var_locn_info::in, prog_varset::out) is det.
+:- pred var_locn__get_exprn_opts(var_locn_info::in, exprn_opts::out) is det.
+:- pred var_locn__get_var_state_map(var_locn_info::in, var_state_map::out)
+	is det.
+:- pred var_locn__get_loc_var_map(var_locn_info::in, loc_var_map::out) is det.
+:- pred var_locn__get_acquired(var_locn_info::in, set(lval)::out) is det.
+:- pred var_locn__get_locked(var_locn_info::in, int::out) is det.
+:- pred var_locn__get_exceptions(var_locn_info::in,
+	assoc_list(prog_var, lval)::out) is det.
 
 :- pred var_locn__set_varset(prog_varset::in,
 	var_locn_info::in, var_locn_info::out) is det.
 
-:- pred var_locn__get_exprn_opts(exprn_opts::out,
-	var_locn_info::in, var_locn_info::out) is det.
-
 :- pred var_locn__set_follow_var_map(follow_vars_map::in,
 	var_locn_info::in, var_locn_info::out) is det.
 
 :- pred var_locn__set_next_non_reserved(int::in,
 	var_locn_info::in, var_locn_info::out) is det.
 
-:- pred var_locn__get_var_state_map(var_state_map::out,
-	var_locn_info::in, var_locn_info::out) is det.
-
 :- pred var_locn__set_var_state_map(var_state_map::in,
 	var_locn_info::in, var_locn_info::out) is det.
 
-:- pred var_locn__get_loc_var_map(loc_var_map::out,
-	var_locn_info::in, var_locn_info::out) is det.
-
 :- pred var_locn__set_loc_var_map(loc_var_map::in,
 	var_locn_info::in, var_locn_info::out) is det.
 
-:- pred var_locn__get_acquired(set(lval)::out,
-	var_locn_info::in, var_locn_info::out) is det.
-
 :- pred var_locn__set_acquired(set(lval)::in,
 	var_locn_info::in, var_locn_info::out) is det.
 
-:- pred var_locn__get_locked(int::out,
-	var_locn_info::in, var_locn_info::out) is det.
-
 :- pred var_locn__set_locked(int::in,
 	var_locn_info::in, var_locn_info::out) is det.
 
-:- pred var_locn__get_exceptions(assoc_list(prog_var, lval)::out,
-	var_locn_info::in, var_locn_info::out) is det.
-
 :- pred var_locn__set_exceptions(assoc_list(prog_var, lval)::in,
 	var_locn_info::in, var_locn_info::out) is det.
 
-var_locn__get_varset(VI ^ varset, VI, VI).
-var_locn__get_stack_slots(VI ^ stack_slots, VI, VI).
-var_locn__get_exprn_opts(VI ^ exprn_opts, VI, VI).
-var_locn__get_follow_var_map(VI ^ follow_vars_map, VI, VI).
-var_locn__get_next_non_reserved(VI ^ next_non_res, VI, VI).
-var_locn__get_var_state_map(VI ^ var_state_map, VI, VI).
-var_locn__get_loc_var_map(VI ^ loc_var_map, VI, VI).
-var_locn__get_acquired(VI ^ acquired, VI, VI).
-var_locn__get_locked(VI ^ locked, VI, VI).
-var_locn__get_exceptions(VI ^ exceptions, VI, VI).
+var_locn__get_varset(VI, VI ^ varset).
+var_locn__get_stack_slots(VI, VI ^ stack_slots).
+var_locn__get_exprn_opts(VI, VI ^ exprn_opts).
+var_locn__get_follow_var_map(VI, VI ^ follow_vars_map).
+var_locn__get_next_non_reserved(VI, VI ^ next_non_res).
+var_locn__get_var_state_map(VI, VI ^ var_state_map).
+var_locn__get_loc_var_map(VI, VI ^ loc_var_map).
+var_locn__get_acquired(VI, VI ^ acquired).
+var_locn__get_locked(VI, VI ^ locked).
+var_locn__get_exceptions(VI, VI ^ exceptions).
 
 var_locn__set_varset(VS, VI, VI ^ varset := VS).
 var_locn__set_follow_var_map(FVM, VI, VI ^ follow_vars_map := FVM).
cvs diff: Diffing notes
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list