[m-rev.] diff: tabling via extra args (part 2 of 4)

Zoltan Somogyi zs at cs.mu.OZ.AU
Mon Jun 7 19:04:08 AEST 2004


Index: compiler/hlds_out.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/hlds_out.m,v
retrieving revision 1.332
diff -u -b -r1.332 hlds_out.m
--- compiler/hlds_out.m	20 May 2004 22:53:28 -0000	1.332
+++ compiler/hlds_out.m	7 Jun 2004 08:49:55 -0000
@@ -895,9 +895,9 @@
 	pred_info_get_indexes(PredInfo, Indexes),
 	globals__io_lookup_string_option(dump_hlds_options, Verbose, !IO),
 	( string__contains_char(Verbose, 'v') ->
-		AppendVarnums = yes
+		AppendVarNums = yes
 	;
-		AppendVarnums = no
+		AppendVarNums = no
 	),
 	( string__contains_char(Verbose, 'C') ->
 		% Information about predicates is dumped if 'C'
@@ -907,7 +907,7 @@
 			mercury_output_pred_type(TVarSet, ExistQVars,
 				qualified(Module, PredName),
 				ArgTypes, no, Purity, ClassContext, Context,
-				AppendVarnums, !IO)
+				AppendVarNums, !IO)
 		;
 			PredOrFunc = function,
 			pred_args_to_func_args(ArgTypes, FuncArgTypes,
@@ -915,7 +915,7 @@
 			mercury_output_func_type(TVarSet, ExistQVars,
 				qualified(Module, PredName), FuncArgTypes,
 				FuncRetType, no, Purity, ClassContext,
-				Context, AppendVarnums, !IO)
+				Context, AppendVarNums, !IO)
 		)
 	;
 		true
@@ -944,15 +944,15 @@
 			hlds_out__write_marker_list(MarkerList, !IO),
 			io__write_string("\n", !IO)
 		),
-		hlds_out__write_typeinfo_varmap(Indent, AppendVarnums,
+		hlds_out__write_typeinfo_varmap(Indent, AppendVarNums,
 			TypeInfoMap, VarSet, TVarSet, !IO),
-		hlds_out__write_typeclass_info_varmap(Indent, AppendVarnums,
+		hlds_out__write_typeclass_info_varmap(Indent, AppendVarNums,
 			TypeClassInfoMap, VarSet, TVarSet, !IO),
 		( map__is_empty(Proofs) ->
 			true
 		;
 			hlds_out__write_constraint_proofs(Indent, TVarSet,
-				Proofs, AppendVarnums, !IO),
+				Proofs, AppendVarNums, !IO),
 			io__write_string("\n", !IO)
 		),
 
@@ -974,18 +974,18 @@
 			io__write_string("% head_type_params:\n", !IO),
 			io__write_string("% ", !IO),
 			mercury_output_vars(HeadTypeParams, TVarSet,
-				AppendVarnums, !IO),
+				AppendVarNums, !IO),
 			io__write_string("\n", !IO)
 		;
 			true
 		),
-		hlds_out__write_var_types(Indent, VarSet, AppendVarnums,
+		hlds_out__write_var_types(Indent, VarSet, AppendVarNums,
 			VarTypes, TVarSet, !IO),
 
 		( Clauses \= [] ->
 			set_dump_opts_for_clauses(SavedDumpString, !IO),
 			hlds_out__write_clauses(Indent, ModuleInfo, PredId,
-				VarSet, AppendVarnums, HeadVars, PredOrFunc,
+				VarSet, AppendVarNums, HeadVars, PredOrFunc,
 				Clauses, no, !IO),
 			globals__io_set_option(dump_hlds_options,
 				string(SavedDumpString), !IO)
@@ -1002,13 +1002,13 @@
 			io__write_string("% instance method constraints:\n",
 				!IO),
 			ClassId = class_id(ClassName, _),
-			mercury_output_constraint(TVarSet, AppendVarnums,
+			mercury_output_constraint(TVarSet, AppendVarNums,
 				constraint(ClassName, InstanceTypes), !IO),
 			io__nl(!IO),
 			io__write_string("instance constraints: ", !IO),
 			io__write_list(InstanceConstraints, ", ",
 				mercury_output_constraint(TVarSet,
-					AppendVarnums), !IO),
+					AppendVarNums), !IO),
 			io__nl(!IO),
 
 			ClassMethodConstraints = constraints(
@@ -1017,12 +1017,12 @@
 			io__write_string("method univ constraints: ", !IO),
 			io__write_list(MethodUnivConstraints, ", ",
 				mercury_output_constraint(TVarSet,
-					AppendVarnums), !IO),
+					AppendVarNums), !IO),
 			io__nl(!IO),
 			io__write_string("method exist constraints: ", !IO),
 			io__write_list(MethodExistConstraints, ", ",
 				mercury_output_constraint(TVarSet,
-					AppendVarnums), !IO),
+					AppendVarNums), !IO),
 			io__nl(!IO)
 
 		;
@@ -1031,7 +1031,7 @@
 	;
 		true
 	),
-	hlds_out__write_procs(Indent, AppendVarnums, ModuleInfo, PredId,
+	hlds_out__write_procs(Indent, AppendVarNums, ModuleInfo, PredId,
 		ImportStatus, PredInfo, !IO),
 	io__write_string("\n", !IO).
 
@@ -1096,7 +1096,7 @@
 	io__write_string(Name, !IO).
 
 hlds_out__write_promise(PromiseType, Indent, ModuleInfo, _PredId, VarSet,
-		AppendVarnums, HeadVars, _PredOrFunc, Clause, TypeQual, !IO) :-
+		AppendVarNums, HeadVars, _PredOrFunc, Clause, TypeQual, !IO) :-
 
 		% curry the varset for term_io__write_variable/4
 	PrintVar = (pred(VarName::in, IOState0::di, IOState::uo) is det :-
@@ -1121,20 +1121,20 @@
 	),
 
 	Clause = clause(_Modes, Goal, _Lang, _Context),
-	hlds_out__write_goal_a(Goal, ModuleInfo, VarSet, AppendVarnums,
+	hlds_out__write_goal_a(Goal, ModuleInfo, VarSet, AppendVarNums,
 		Indent+1, ").\n", TypeQual, !IO).
 
-hlds_out__write_clauses(Indent, ModuleInfo, PredId, VarSet, AppendVarnums,
+hlds_out__write_clauses(Indent, ModuleInfo, PredId, VarSet, AppendVarNums,
 		HeadVars, PredOrFunc, Clauses0, TypeQual, !IO) :-
 	hlds_out__write_clauses_2(Indent, ModuleInfo, PredId, VarSet,
-		AppendVarnums, HeadVars, PredOrFunc, Clauses0, TypeQual,
+		AppendVarNums, HeadVars, PredOrFunc, Clauses0, TypeQual,
 		1, !IO).
 
 :- pred hlds_out__write_clauses_2(int::in, module_info::in, pred_id::in,
 	prog_varset::in, bool::in, list(prog_var)::in, pred_or_func::in,
 	list(clause)::in, maybe_vartypes::in, int::in, io::di, io::uo) is det.
 
-hlds_out__write_clauses_2(Indent, ModuleInfo, PredId, VarSet, AppendVarnums,
+hlds_out__write_clauses_2(Indent, ModuleInfo, PredId, VarSet, AppendVarNums,
 		HeadVars, PredOrFunc, Clauses0, TypeQual, ClauseNum, !IO) :-
 	(
 		Clauses0 = [Clause | Clauses]
@@ -1145,17 +1145,17 @@
 		io__write_int(ClauseNum, !IO),
 		io__write_string("\n", !IO),
 		hlds_out__write_clause(Indent, ModuleInfo, PredId, VarSet,
-			AppendVarnums, HeadTerms, PredOrFunc,
+			AppendVarNums, HeadTerms, PredOrFunc,
 			Clause, UseDeclaredModes, TypeQual, !IO),
 		hlds_out__write_clauses_2(Indent, ModuleInfo, PredId, VarSet,
-			AppendVarnums, HeadVars, PredOrFunc, Clauses, TypeQual,
+			AppendVarNums, HeadVars, PredOrFunc, Clauses, TypeQual,
 			ClauseNum + 1, !IO)
 	;
 		true
 	).
 
 hlds_out__write_clause(Indent, ModuleInfo, PredId, VarSet,
-		AppendVarnums, HeadTerms, PredOrFunc, Clause,
+		AppendVarNums, HeadTerms, PredOrFunc, Clause,
 		UseDeclaredModes, TypeQual, !IO) :-
 	Clause = clause(Modes, Goal, Lang, Context),
 	Indent1 = Indent + 1,
@@ -1188,21 +1188,21 @@
 		)
 	->
 		hlds_out__write_clause_head(ModuleInfo, PredId, VarSet,
-			AppendVarnums, HeadTerms, PredOrFunc, !IO)
+			AppendVarNums, HeadTerms, PredOrFunc, !IO)
 	;
 		% If Modes contains more than one mode, the output will have
 		% multiple clause heads. This won't be pretty and it won't be
 		% syntactically valid, but it is more useful for debugging
 		% than a compiler abort during the dumping process.
 		hlds_out__write_annotated_clause_heads(ModuleInfo, Context,
-			PredId, Modes, VarSet, AppendVarnums, HeadTerms,
+			PredId, Modes, VarSet, AppendVarNums, HeadTerms,
 			PredOrFunc, UseDeclaredModes, !IO)
 	),
 	( Goal = conj([]) - _GoalInfo ->
 		io__write_string(".\n", !IO)
 	;
 		io__write_string(" :-\n", !IO),
-		hlds_out__write_goal_a(Goal, ModuleInfo, VarSet, AppendVarnums,
+		hlds_out__write_goal_a(Goal, ModuleInfo, VarSet, AppendVarNums,
 			Indent1, ".\n", TypeQual, !IO)
 	).
 
@@ -1213,13 +1213,13 @@
 
 hlds_out__write_annotated_clause_heads(_, _, _, [], _, _, _, _, _, !IO).
 hlds_out__write_annotated_clause_heads(ModuleInfo, Context, PredId,
-		[ProcId | ProcIds], VarSet, AppendVarnums, HeadTerms,
+		[ProcId | ProcIds], VarSet, AppendVarNums, HeadTerms,
 		PredOrFunc, UseDeclaredModes, !IO) :-
 	hlds_out__write_annotated_clause_head(ModuleInfo, Context, PredId,
-		ProcId, VarSet, AppendVarnums, HeadTerms,
+		ProcId, VarSet, AppendVarNums, HeadTerms,
 		PredOrFunc, UseDeclaredModes, !IO),
 	hlds_out__write_annotated_clause_heads(ModuleInfo, Context, PredId,
-		ProcIds, VarSet, AppendVarnums, HeadTerms,
+		ProcIds, VarSet, AppendVarNums, HeadTerms,
 		PredOrFunc, UseDeclaredModes, !IO).
 
 :- pred hlds_out__write_annotated_clause_head(module_info::in,
@@ -1228,7 +1228,7 @@
 	io__state::di, io__state::uo) is det.
 
 hlds_out__write_annotated_clause_head(ModuleInfo, Context, PredId, ProcId,
-		VarSet, AppendVarnums, HeadTerms,
+		VarSet, AppendVarNums, HeadTerms,
 		PredOrFunc, UseDeclaredModes, !IO) :-
 	module_info_pred_info(ModuleInfo, PredId, PredInfo),
 	pred_info_procedures(PredInfo, Procedures),
@@ -1260,7 +1260,7 @@
 		AnnotatedHeadTerms = list__map(add_mode_qualifier(Context),
 			AnnotatedPairs),
 		hlds_out__write_clause_head(ModuleInfo, PredId, VarSet,
-			AppendVarnums, AnnotatedHeadTerms, PredOrFunc, !IO)
+			AppendVarNums, AnnotatedHeadTerms, PredOrFunc, !IO)
 	;
 		% This procedure, even though it existed in the past, has been
 		% eliminated.
@@ -1271,7 +1271,7 @@
 	prog_varset::in, bool::in, list(prog_term)::in, pred_or_func::in,
 	io::di, io::uo) is det.
 
-hlds_out__write_clause_head(ModuleInfo, PredId, VarSet, AppendVarnums,
+hlds_out__write_clause_head(ModuleInfo, PredId, VarSet, AppendVarNums,
 			HeadTerms, PredOrFunc, !IO) :-
 	predicate_name(ModuleInfo, PredId, PredName),
 	predicate_module(ModuleInfo, PredId, ModuleName),
@@ -1280,21 +1280,21 @@
 		pred_args_to_func_args(HeadTerms, FuncArgs, RetVal),
 		hlds_out__write_qualified_functor_with_term_args(
 			ModuleName, term__atom(PredName), FuncArgs, VarSet,
-			AppendVarnums, !IO),
+			AppendVarNums, !IO),
 		io__write_string(" = ", !IO),
-		mercury_output_term(RetVal, VarSet, AppendVarnums,
+		mercury_output_term(RetVal, VarSet, AppendVarNums,
 			next_to_graphic_token, !IO)
 	;
 		PredOrFunc = predicate,
 		hlds_out__write_qualified_functor_with_term_args(
 			ModuleName, term__atom(PredName), HeadTerms, VarSet,
-			AppendVarnums, !IO)
+			AppendVarNums, !IO)
 	).
 
-hlds_out__write_goal(Goal, ModuleInfo, VarSet, AppendVarnums, Indent, Follow,
+hlds_out__write_goal(Goal, ModuleInfo, VarSet, AppendVarNums, Indent, Follow,
 		!IO) :-
 		% don't type qualify everything
-	hlds_out__write_goal_a(Goal, ModuleInfo, VarSet, AppendVarnums,
+	hlds_out__write_goal_a(Goal, ModuleInfo, VarSet, AppendVarNums,
 		Indent, Follow, no, !IO).
 
 	% TypeQual is yes(TVarset, VarTypes) if all constructors should
@@ -1303,7 +1303,7 @@
 	bool::in, int::in, string::in, maybe_vartypes::in, io::di, io::uo)
 	is det.
 
-hlds_out__write_goal_a(Goal - GoalInfo, ModuleInfo, VarSet, AppendVarnums,
+hlds_out__write_goal_a(Goal - GoalInfo, ModuleInfo, VarSet, AppendVarNums,
 		Indent, Follow, TypeQual, !IO) :-
 	globals__io_lookup_string_option(dump_hlds_options, Verbose, !IO),
 	( string__contains_char(Verbose, 'c') ->
@@ -1344,7 +1344,7 @@
 			hlds_out__write_indent(Indent, !IO),
 			io__write_string("% nonlocals: ", !IO),
 			mercury_output_vars(NonLocalsList, VarSet,
-				AppendVarnums, !IO),
+				AppendVarNums, !IO),
 			io__write_string("\n", !IO)
 		;
 			true
@@ -1361,7 +1361,7 @@
 			hlds_out__write_indent(Indent, !IO),
 			io__write_string("% pre-deaths: ", !IO),
 			mercury_output_vars(PreDeathList, VarSet,
-				AppendVarnums, !IO),
+				AppendVarNums, !IO),
 			io__write_string("\n", !IO)
 		;
 			true
@@ -1374,7 +1374,7 @@
 			hlds_out__write_indent(Indent, !IO),
 			io__write_string("% pre-births: ", !IO),
 			mercury_output_vars(PreBirthList, VarSet,
-				AppendVarnums, !IO),
+				AppendVarNums, !IO),
 			io__write_string("\n", !IO)
 		;
 			true
@@ -1391,7 +1391,7 @@
 	;
 		true
 	),
-	hlds_out__write_goal_2(Goal, ModuleInfo, VarSet, AppendVarnums,
+	hlds_out__write_goal_2(Goal, ModuleInfo, VarSet, AppendVarNums,
 		Indent, Follow, TypeQual, !IO),
 	( string__contains_char(Verbose, 'i') ->
 		goal_info_get_instmap_delta(GoalInfo, InstMapDelta),
@@ -1406,13 +1406,13 @@
 			( string__contains_char(Verbose, 'D') ->
 				io__write_string("% new insts: ", !IO),
 				hlds_out__write_instmap_delta(InstMapDelta,
-					VarSet, AppendVarnums, Indent, !IO),
+					VarSet, AppendVarNums, Indent, !IO),
 				io__write_string("\n", !IO)
 			;
 				io__write_string("% vars with new insts: ",
 					!IO),
 				hlds_out__write_instmap_delta_vars(
-					InstMapDelta, VarSet, AppendVarnums,
+					InstMapDelta, VarSet, AppendVarNums,
 					!IO),
 				io__write_string("\n", !IO)
 			)
@@ -1429,7 +1429,7 @@
 			hlds_out__write_indent(Indent, !IO),
 			io__write_string("% post-deaths: ", !IO),
 			mercury_output_vars(PostDeathList, VarSet,
-				AppendVarnums, !IO),
+				AppendVarNums, !IO),
 			io__write_string("\n", !IO)
 		;
 			true
@@ -1442,7 +1442,7 @@
 			hlds_out__write_indent(Indent, !IO),
 			io__write_string("% post-births: ", !IO),
 			mercury_output_vars(PostBirthList, VarSet,
-				AppendVarnums, !IO),
+				AppendVarNums, !IO),
 			io__write_string("\n", !IO)
 		;
 			true
@@ -1456,7 +1456,7 @@
 	;
 		CodeGenInfo = llds_code_gen_info(_CodeGenDetails),
 		hlds_out__write_llds_code_gen_info(GoalInfo, VarSet,
-			AppendVarnums, Indent, Verbose, !IO)
+			AppendVarNums, Indent, Verbose, !IO)
 	),
 	( string__contains_char(Verbose, 'g') ->
 		goal_info_get_features(GoalInfo, Features),
@@ -1478,19 +1478,19 @@
 	io::di, io::uo) is det.
 
 hlds_out__write_goal_2(switch(Var, CanFail, CasesList), ModuleInfo, VarSet,
-		AppendVarnums, Indent, Follow, TypeQual, !IO) :-
+		AppendVarNums, Indent, Follow, TypeQual, !IO) :-
 	hlds_out__write_indent(Indent, !IO),
 	io__write_string("( % ", !IO),
 	hlds_out__write_can_fail(CanFail, !IO),
 	io__write_string(" switch on `", !IO),
-	mercury_output_var(Var, VarSet, AppendVarnums, !IO),
+	mercury_output_var(Var, VarSet, AppendVarNums, !IO),
 	io__write_string("'\n", !IO),
 	Indent1 = Indent + 1,
 	( CasesList = [Case | Cases] ->
 		hlds_out__write_case(Case, Var, ModuleInfo, VarSet,
-			AppendVarnums, Indent1, TypeQual, !IO),
+			AppendVarNums, Indent1, TypeQual, !IO),
 		hlds_out__write_cases(Cases, Var, ModuleInfo, VarSet,
-			AppendVarnums, Indent, TypeQual, !IO)
+			AppendVarNums, Indent, TypeQual, !IO)
 	;
 		hlds_out__write_indent(Indent1, !IO),
 		io__write_string("fail\n", !IO)
@@ -1500,10 +1500,10 @@
 	io__write_string(Follow, !IO).
 
 hlds_out__write_goal_2(some(Vars, CanRemove, Goal), ModuleInfo, VarSet,
-		AppendVarnums, Indent, Follow, TypeQual, !IO) :-
+		AppendVarNums, Indent, Follow, TypeQual, !IO) :-
 	hlds_out__write_indent(Indent, !IO),
 	io__write_string("some [", !IO),
-	mercury_output_vars(Vars, VarSet, AppendVarnums, !IO),
+	mercury_output_vars(Vars, VarSet, AppendVarNums, !IO),
 	io__write_string("] (", !IO),
 	( CanRemove = cannot_remove ->
 		io__write_string(" % (cannot remove)", !IO)
@@ -1511,24 +1511,24 @@
 		true
 	),
 	io__nl(!IO),
-	hlds_out__write_goal_a(Goal, ModuleInfo, VarSet, AppendVarnums,
+	hlds_out__write_goal_a(Goal, ModuleInfo, VarSet, AppendVarNums,
 		Indent + 1, "\n", TypeQual, !IO),
 	hlds_out__write_indent(Indent, !IO),
 	io__write_string(")", !IO),
 	io__write_string(Follow, !IO).
 
 hlds_out__write_goal_2(if_then_else(Vars, Cond, Then, Else), ModuleInfo,
-		VarSet, AppendVarnums, Indent, Follow, TypeQual, !IO) :-
+		VarSet, AppendVarNums, Indent, Follow, TypeQual, !IO) :-
 	hlds_out__write_indent(Indent, !IO),
 	io__write_string("(if", !IO),
 	hlds_out__write_some(Vars, VarSet, !IO),
 	io__write_string("\n", !IO),
 	Indent1 = Indent + 1,
-	hlds_out__write_goal_a(Cond, ModuleInfo, VarSet, AppendVarnums,
+	hlds_out__write_goal_a(Cond, ModuleInfo, VarSet, AppendVarNums,
 		Indent1, "\n", TypeQual, !IO),
 	hlds_out__write_indent(Indent, !IO),
 	io__write_string("then\n", !IO),
-	hlds_out__write_goal_a(Then, ModuleInfo, VarSet, AppendVarnums,
+	hlds_out__write_goal_a(Then, ModuleInfo, VarSet, AppendVarNums,
 		Indent1, "\n", TypeQual, !IO),
 	hlds_out__write_indent(Indent, !IO),
 	io__write_string("else\n", !IO),
@@ -1537,27 +1537,27 @@
 		Verbose \= "",
 		Else = if_then_else(_, _, _, _) - _
 	->
-		hlds_out__write_goal_a(Else, ModuleInfo, VarSet, AppendVarnums,
+		hlds_out__write_goal_a(Else, ModuleInfo, VarSet, AppendVarNums,
 			Indent, "\n", TypeQual, !IO)
 	;
-		hlds_out__write_goal_a(Else, ModuleInfo, VarSet, AppendVarnums,
+		hlds_out__write_goal_a(Else, ModuleInfo, VarSet, AppendVarNums,
 			Indent1, "\n", TypeQual, !IO)
 	),
 	hlds_out__write_indent(Indent, !IO),
 	io__write_string(")", !IO),
 	io__write_string(Follow, !IO).
 
-hlds_out__write_goal_2(not(Goal), ModuleInfo, VarSet, AppendVarnums,
+hlds_out__write_goal_2(not(Goal), ModuleInfo, VarSet, AppendVarNums,
 		Indent, Follow, TypeQual, !IO) :-
 	hlds_out__write_indent(Indent, !IO),
 	io__write_string("\\+ (\n", !IO),
-	hlds_out__write_goal_a(Goal, ModuleInfo, VarSet, AppendVarnums,
+	hlds_out__write_goal_a(Goal, ModuleInfo, VarSet, AppendVarNums,
 		Indent + 1, "\n", TypeQual, !IO),
 	hlds_out__write_indent(Indent, !IO),
 	io__write_string(")", !IO),
 	io__write_string(Follow, !IO).
 
-hlds_out__write_goal_2(conj(List), ModuleInfo, VarSet, AppendVarnums,
+hlds_out__write_goal_2(conj(List), ModuleInfo, VarSet, AppendVarNums,
 		Indent, Follow, TypeQual, !IO) :-
 	( List = [Goal | Goals] ->
 		globals__io_lookup_string_option(dump_hlds_options, Verbose,
@@ -1566,14 +1566,14 @@
 			hlds_out__write_indent(Indent, !IO),
 			io__write_string("( % conjunction\n", !IO),
 			hlds_out__write_conj(Goal, Goals, ModuleInfo, VarSet,
-				AppendVarnums, Indent + 1, "\n", Verbose,
+				AppendVarNums, Indent + 1, "\n", Verbose,
 				",\n", TypeQual, !IO),
 			hlds_out__write_indent(Indent, !IO),
 			io__write_string(")", !IO),
 			io__write_string(Follow, !IO)
 		;
 			hlds_out__write_conj(Goal, Goals, ModuleInfo, VarSet,
-				AppendVarnums, Indent, Follow, Verbose, ",\n",
+				AppendVarNums, Indent, Follow, Verbose, ",\n",
 				TypeQual, !IO)
 		)
 	;
@@ -1582,16 +1582,16 @@
 		io__write_string(Follow, !IO)
 	).
 
-hlds_out__write_goal_2(par_conj(List), ModuleInfo, VarSet, AppendVarnums,
+hlds_out__write_goal_2(par_conj(List), ModuleInfo, VarSet, AppendVarNums,
 		Indent, Follow, TypeQual, !IO) :-
 	hlds_out__write_indent(Indent, !IO),
 	( List = [Goal | Goals] ->
 		io__write_string("( % parallel conjunction\n", !IO),
-		hlds_out__write_goal_a(Goal, ModuleInfo, VarSet, AppendVarnums,
+		hlds_out__write_goal_a(Goal, ModuleInfo, VarSet, AppendVarNums,
 			Indent + 1, "\n", TypeQual, !IO),
 			% See comments at hlds_out__write_goal_list.
 		hlds_out__write_goal_list(Goals, ModuleInfo, VarSet,
-			AppendVarnums, Indent, "&\n", TypeQual, !IO),
+			AppendVarNums, Indent, "&\n", TypeQual, !IO),
 		hlds_out__write_indent(Indent, !IO),
 		io__write_string(")", !IO),
 		io__write_string(Follow, !IO)
@@ -1600,15 +1600,15 @@
 		io__write_string(Follow, !IO)
 	).
 
-hlds_out__write_goal_2(disj(List), ModuleInfo, VarSet, AppendVarnums,
+hlds_out__write_goal_2(disj(List), ModuleInfo, VarSet, AppendVarNums,
 		Indent, Follow, TypeQual, !IO) :-
 	hlds_out__write_indent(Indent, !IO),
 	( List = [Goal | Goals] ->
 		io__write_string("( % disjunction\n", !IO),
-		hlds_out__write_goal_a(Goal, ModuleInfo, VarSet, AppendVarnums,
+		hlds_out__write_goal_a(Goal, ModuleInfo, VarSet, AppendVarNums,
 			Indent + 1, "\n", TypeQual, !IO),
 		hlds_out__write_goal_list(Goals, ModuleInfo, VarSet,
-			AppendVarnums, Indent, ";\n", TypeQual, !IO),
+			AppendVarNums, Indent, ";\n", TypeQual, !IO),
 		hlds_out__write_indent(Indent, !IO),
 		io__write_string(")", !IO),
 		io__write_string(Follow, !IO)
@@ -1618,7 +1618,7 @@
 	).
 
 hlds_out__write_goal_2(generic_call(GenericCall, ArgVars, Modes, _),
-		ModuleInfo, VarSet, AppendVarnums, Indent, Follow, _, !IO) :-
+		ModuleInfo, VarSet, AppendVarNums, Indent, Follow, _, !IO) :-
 		% XXX we should print more info here
 	(
 		GenericCall = higher_order(PredVar, Purity, PredOrFunc, _),
@@ -1636,7 +1636,7 @@
 			hlds_out__write_indent(Indent, !IO),
 			write_purity_prefix(Purity, !IO),
 			hlds_out__write_functor(term__atom("call"),
-				[PredVar | ArgVars], VarSet, AppendVarnums, !IO)
+				[PredVar | ArgVars], VarSet, AppendVarNums, !IO)
 		;
 			PredOrFunc = function,
 			( string__contains_char(Verbose, 'l') ->
@@ -1650,11 +1650,11 @@
 				FuncArgVars, FuncRetVar),
 			hlds_out__write_indent(Indent, !IO),
 			write_purity_prefix(Purity, !IO),
-			mercury_output_var(FuncRetVar, VarSet, AppendVarnums,
+			mercury_output_var(FuncRetVar, VarSet, AppendVarNums,
 				!IO),
 			io__write_string(" = ", !IO),
 			hlds_out__write_functor(term__atom("apply"),
-				FuncArgVars, VarSet, AppendVarnums, !IO)
+				FuncArgVars, VarSet, AppendVarNums, !IO)
 		),
 		io__write_string(Follow, !IO)
 	;
@@ -1677,7 +1677,7 @@
 		Term = term__functor(Functor,
 			[TCInfoTerm, MethodNumTerm | ArgTerms], Context),
 		hlds_out__write_indent(Indent, !IO),
-		mercury_output_term(Term, VarSet, AppendVarnums, !IO),
+		mercury_output_term(Term, VarSet, AppendVarNums, !IO),
 		io__write_string(Follow, !IO)
 	;
 		GenericCall = unsafe_cast,
@@ -1703,18 +1703,18 @@
 		term__context_init(Context),
 		Term = term__functor(Functor, ArgTerms, Context),
 		hlds_out__write_indent(Indent, !IO),
-		mercury_output_term(Term, VarSet, AppendVarnums, !IO),
+		mercury_output_term(Term, VarSet, AppendVarNums, !IO),
 		io__write_string(Follow, !IO)
 	;
 		GenericCall = aditi_builtin(AditiBuiltin, CallId),
 		hlds_out__write_indent(Indent, !IO),
 		hlds_out__write_aditi_builtin(ModuleInfo, AditiBuiltin, CallId,
-			ArgVars, VarSet, AppendVarnums, Indent, Follow, !IO)
+			ArgVars, VarSet, AppendVarNums, Indent, Follow, !IO)
 	).
 
 hlds_out__write_goal_2(call(PredId, ProcId, ArgVars, Builtin,
 		MaybeUnifyContext, PredName), ModuleInfo, VarSet,
-		AppendVarnums, Indent, Follow, TypeQual, !IO) :-
+		AppendVarNums, Indent, Follow, TypeQual, !IO) :-
 	globals__io_lookup_string_option(dump_hlds_options, Verbose, !IO),
 	( string__contains_char(Verbose, 'b') ->
 		(
@@ -1748,11 +1748,11 @@
 	;
 		PredOrFunc = function,
 		pred_args_to_func_args(ArgVars, NewArgVars, LHSVar),
-		mercury_output_var(LHSVar, VarSet, AppendVarnums, !IO),
+		mercury_output_var(LHSVar, VarSet, AppendVarNums, !IO),
 		io__write_string(" = ", !IO)
 	),
 	hlds_out__write_sym_name_and_args(PredName, NewArgVars, VarSet,
-		AppendVarnums, !IO),
+		AppendVarNums, !IO),
 	io__write_string(Follow, !IO),
 	( string__contains_char(Verbose, 'l') ->
 		pred_id_to_int(PredId, PredNum),
@@ -1774,12 +1774,12 @@
 					RHS, _UnifyContext),
 			hlds_out__write_indent(Indent, !IO),
 			io__write_string("% unify context: ", !IO),
-			mercury_output_var(Var, VarSet, AppendVarnums, !IO),
+			mercury_output_var(Var, VarSet, AppendVarNums, !IO),
 			io__write_string(" = ", !IO),
 				% XXX Fake the inst varset
 			varset__init(InstVarSet),
 			hlds_out__write_unify_rhs_2(RHS, ModuleInfo, VarSet,
-				InstVarSet, AppendVarnums, Indent, Follow,
+				InstVarSet, AppendVarNums, Indent, Follow,
 				VarType, TypeQual, !IO)
 		;
 			true
@@ -1789,9 +1789,9 @@
 	).
 
 hlds_out__write_goal_2(unify(A, B, _, Unification, _), ModuleInfo, VarSet,
-		AppendVarnums, Indent, Follow, TypeQual, !IO) :-
+		AppendVarNums, Indent, Follow, TypeQual, !IO) :-
 	hlds_out__write_indent(Indent, !IO),
-	mercury_output_var(A, VarSet, AppendVarnums, !IO),
+	mercury_output_var(A, VarSet, AppendVarNums, !IO),
 	io__write_string(" = ", !IO),
 	( TypeQual = yes(_, VarTypes) ->
 		map__lookup(VarTypes, A, UniType),
@@ -1802,7 +1802,7 @@
 		% XXX Fake the inst varset
 	varset__init(InstVarSet),
 	hlds_out__write_unify_rhs_2(B, ModuleInfo, VarSet, InstVarSet,
-		AppendVarnums, Indent, Follow, VarType, TypeQual, !IO),
+		AppendVarNums, Indent, Follow, VarType, TypeQual, !IO),
 	globals__io_lookup_string_option(dump_hlds_options, Verbose, !IO),
 	(
 		(
@@ -1823,31 +1823,44 @@
 			true
 		;
 			hlds_out__write_unification(Unification, ModuleInfo,
-				VarSet, InstVarSet, AppendVarnums, Indent, !IO)
+				VarSet, InstVarSet, AppendVarNums, Indent, !IO)
 		)
 	;
 		true
 	).
 
-hlds_out__write_goal_2(foreign_proc(Attributes, _PredId, _ProcId, ArgVars,
-		ArgNames, OrigArgTypes, PragmaCode),
-		_, _, AppendVarNums, Indent, Follow, _, !IO) :-
+hlds_out__write_goal_2(foreign_proc(Attributes, PredId, ProcId, Args,
+		ExtraArgs, PragmaCode), ModuleInfo, VarSet, AppendVarNums,
+		Indent, Follow, _, !IO) :-
 	ForeignLang = foreign_language(Attributes),
 	hlds_out__write_indent(Indent, !IO),
-	io__write_string("$pragma_foreign_proc( /* ", !IO),
+	io__write_string("$pragma_foreign_proc(/* ", !IO),
 	io__write_string(foreign_language_string(ForeignLang), !IO),
-	io__write_string(" */ [", !IO),
-	hlds_out__write_varnum_list(ArgVars, !IO),
-	io__write_string("], [", !IO),
-	get_pragma_foreign_var_names(ArgNames, Names),
-	hlds_out__write_string_list(Names, !IO),
-	io__write_string("], [", !IO),
+	io__write_string(" */, ", !IO),
+	hlds_out__write_pred_id(ModuleInfo, PredId, !IO),
+	io__write_string(" proc ", !IO),
+	proc_id_to_int(ProcId, ProcIdInt),
+	io__write_int(ProcIdInt, !IO),
+	io__write_string(",\n", !IO),
+	hlds_out__write_indent(Indent, !IO),
 	% XXX We don't have the TypeVarSet available here,
 	%     but it's only used for printing out the names of the
 	%     type variables, which isn't essential.
 	varset__init(TypeVarSet),
-	hlds_out__write_type_list(OrigArgTypes, TypeVarSet, AppendVarNums, !IO),
-	io__write_string("], ", !IO),
+	io__write_string("[", !IO),
+	hlds_out__write_foreign_args(Args, VarSet, TypeVarSet, AppendVarNums,
+		!IO),
+	io__write_string("],\n", !IO),
+	(
+		ExtraArgs = []
+	;
+		ExtraArgs = [_ | _],
+		hlds_out__write_indent(Indent, !IO),
+		io__write_string("{", !IO),
+		hlds_out__write_foreign_args(ExtraArgs, VarSet, TypeVarSet,
+			AppendVarNums, !IO),
+		io__write_string("},\n", !IO)
+	),
 	(
 		PragmaCode = ordinary(C_Code, _),
 		io__write_string("""", !IO),
@@ -1888,33 +1901,58 @@
 	io__write_string(Follow, !IO).
 
 hlds_out__write_goal_2(shorthand(ShortHandGoal), ModuleInfo, VarSet,
-		AppendVarnums, Indent, Follow, TypeQual, !IO) :-
+		AppendVarNums, Indent, Follow, TypeQual, !IO) :-
 	hlds_out__write_goal_2_shorthand(ShortHandGoal, ModuleInfo,
-		VarSet, AppendVarnums, Indent, Follow, TypeQual, !IO).
+		VarSet, AppendVarNums, Indent, Follow, TypeQual, !IO).
 
 :- pred hlds_out__write_goal_2_shorthand(shorthand_goal_expr::in,
 	module_info::in, prog_varset::in, bool::in, int::in, string::in,
 	maybe_vartypes::in, io::di, io::uo) is det.
 
 hlds_out__write_goal_2_shorthand(bi_implication(LHS, RHS), ModuleInfo,
-		VarSet,	AppendVarnums, Indent, Follow, TypeQual, !IO) :-
+		VarSet,	AppendVarNums, Indent, Follow, TypeQual, !IO) :-
 	hlds_out__write_indent(Indent, !IO),
 	io__write_string("( % bi-implication\n", !IO),
 	Indent1 = Indent + 1,
-	hlds_out__write_goal_a(LHS, ModuleInfo, VarSet, AppendVarnums,
+	hlds_out__write_goal_a(LHS, ModuleInfo, VarSet, AppendVarNums,
 		Indent1, "\n", TypeQual, !IO),
 	hlds_out__write_indent(Indent, !IO),
 	io__write_string("<=>\n", !IO),
-	hlds_out__write_goal_a(RHS, ModuleInfo, VarSet, AppendVarnums,
+	hlds_out__write_goal_a(RHS, ModuleInfo, VarSet, AppendVarNums,
 		Indent1, "\n", TypeQual, !IO),
 	hlds_out__write_indent(Indent, !IO),
 	io__write_string(")", !IO),
 	io__write_string(Follow, !IO).
 
+:- pred hlds_out__write_foreign_args(list(foreign_arg)::in, prog_varset::in,
+	tvarset::in, bool::in, io::di, io::uo) is det.
+
+hlds_out__write_foreign_args([], _, _, _, !IO).
+hlds_out__write_foreign_args([Arg | Args], VarSet, TVarSet, AppendVarNums,
+		!IO) :-
+	Arg = foreign_arg(Var, MaybeNameMode, Type),
+	mercury_output_var(Var, VarSet, AppendVarNums, !IO),
+	(
+		MaybeNameMode = yes(Name - _),
+		io__write_string("/" ++ Name, !IO)
+	;
+		MaybeNameMode = no
+	),
+	io__write_string("@", !IO),
+	mercury_output_term(Type, TVarSet, AppendVarNums, !IO),
+	(
+		Args = []
+	;
+		Args = [_ | _],
+		io__write_string(", ", !IO),
+		hlds_out__write_foreign_args(Args, VarSet, TVarSet,
+			AppendVarNums, !IO)
+	).
+
 :- pred hlds_out__write_llds_code_gen_info(hlds_goal_info::in, prog_varset::in,
 	bool::in, int::in, string::in, io__state::di, io__state::uo) is det.
 
-hlds_out__write_llds_code_gen_info(GoalInfo, VarSet, AppendVarnums,
+hlds_out__write_llds_code_gen_info(GoalInfo, VarSet, AppendVarNums,
 		Indent, Verbose, !IO) :-
 	( string__contains_char(Verbose, 'f') ->
 		goal_info_get_follow_vars(GoalInfo, MaybeFollowVars),
@@ -1927,7 +1965,7 @@
 			io__write_int(NextReg, !IO),
 			io__write_string("\n", !IO),
 			hlds_out__write_var_to_abs_locns(FVlist, VarSet,
-				AppendVarnums, Indent, !IO)
+				AppendVarNums, Indent, !IO)
 		;
 			MaybeFollowVars = no
 		)
@@ -1957,7 +1995,7 @@
 				io__write_string("stack and orig ", !IO)
 			),
 			mercury_output_vars(ResumeVarList, VarSet,
-				AppendVarnums, !IO),
+				AppendVarNums, !IO),
 			io__write_string("\n", !IO)
 		)
 	;
@@ -1972,7 +2010,7 @@
 		hlds_out__write_indent(Indent, !IO),
 		io__write_string("% store map:\n", !IO),
 		hlds_out__write_var_to_abs_locns(StoreMapList, VarSet,
-			AppendVarnums, Indent, !IO)
+			AppendVarNums, Indent, !IO)
 	;
 		true
 	),
@@ -1993,7 +2031,7 @@
 			io__write_string("none\n", !IO)
 		;
 			hlds_out__write_vars(CallForwardList, VarSet,
-				AppendVarnums, !IO),
+				AppendVarNums, !IO),
 			io__write_string("\n", !IO)
 		),
 
@@ -2003,7 +2041,7 @@
 			io__write_string("none\n", !IO)
 		;
 			hlds_out__write_vars(CallResumeList, VarSet,
-				AppendVarnums, !IO),
+				AppendVarNums, !IO),
 			io__write_string("\n", !IO)
 		),
 
@@ -2013,7 +2051,7 @@
 			io__write_string("none\n", !IO)
 		;
 			hlds_out__write_vars(CallNondetList, VarSet,
-				AppendVarnums, !IO),
+				AppendVarNums, !IO),
 			io__write_string("\n", !IO)
 		)
 	;
@@ -2046,7 +2084,7 @@
 			io__write_string("none\n", !IO)
 		;
 			hlds_out__write_vars(ResumeResumeList, VarSet,
-				AppendVarnums, !IO),
+				AppendVarNums, !IO),
 			io__write_string("\n", !IO)
 		),
 
@@ -2056,7 +2094,7 @@
 			io__write_string("none\n", !IO)
 		;
 			hlds_out__write_vars(ResumeNondetList, VarSet,
-				AppendVarnums, !IO),
+				AppendVarNums, !IO),
 			io__write_string("\n", !IO)
 		)
 	;
@@ -2072,7 +2110,7 @@
 		set__to_sorted_list(ParConjSet, ParConjList),
 		hlds_out__write_indent(Indent, !IO),
 		io__write_string("% need in par_conj vars: ", !IO),
-		hlds_out__write_vars(ParConjList, VarSet, AppendVarnums, !IO),
+		hlds_out__write_vars(ParConjList, VarSet, AppendVarNums, !IO),
 		io__write_string("\n", !IO)
 	;
 		true
@@ -2082,12 +2120,12 @@
 	io__state::di, io__state::uo) is det.
 
 hlds_out__write_vars([], _, _, !IO).
-hlds_out__write_vars([Var], VarSet, AppendVarnums, !IO) :-
-	mercury_output_var(Var, VarSet, AppendVarnums, !IO).
-hlds_out__write_vars([Var1, Var2 | Vars], VarSet, AppendVarnums, !IO) :-
-	mercury_output_var(Var1, VarSet, AppendVarnums, !IO),
+hlds_out__write_vars([Var], VarSet, AppendVarNums, !IO) :-
+	mercury_output_var(Var, VarSet, AppendVarNums, !IO).
+hlds_out__write_vars([Var1, Var2 | Vars], VarSet, AppendVarNums, !IO) :-
+	mercury_output_var(Var1, VarSet, AppendVarNums, !IO),
 	io__write_string(", ", !IO),
-	hlds_out__write_vars([Var2 | Vars], VarSet, AppendVarnums, !IO).
+	hlds_out__write_vars([Var2 | Vars], VarSet, AppendVarNums, !IO).
 
 :- pred hlds_out__write_varnum_list(list(prog_var)::in, io::di, io::uo) is det.
 
@@ -2137,7 +2175,7 @@
 
 hlds_out__write_aditi_builtin(_ModuleInfo,
 		aditi_tuple_update(InsertDelete, PredId), CallId,
-		ArgVars, VarSet, AppendVarnums, Indent, Follow, !IO) :-
+		ArgVars, VarSet, AppendVarNums, Indent, Follow, !IO) :-
 	% make_hlds.m checks the arity so this cannot fail.
 	get_state_args_det(ArgVars, Args, State0Var, StateVar),
 	hlds_out__write_indent(Indent, !IO),
@@ -2154,28 +2192,28 @@
 	(
 		PredOrFunc = predicate,
 		hlds_out__write_sym_name_and_args(SymName, Args,
-			VarSet, AppendVarnums, !IO)
+			VarSet, AppendVarNums, !IO)
 	;
 		PredOrFunc = function,
 		pred_args_to_func_args(Args, FuncArgs, RetArg),
 		io__write_string("(", !IO),
 		hlds_out__write_sym_name_and_args(SymName, FuncArgs,
-			VarSet, AppendVarnums, !IO),
+			VarSet, AppendVarNums, !IO),
 		io__write_string(" = ", !IO),
-		mercury_output_var(RetArg, VarSet, AppendVarnums, !IO),
+		mercury_output_var(RetArg, VarSet, AppendVarNums, !IO),
 		io__write_string(")", !IO)
 	),
 	io__write_string(", ", !IO),
-	mercury_output_var(State0Var, VarSet, AppendVarnums, !IO),
+	mercury_output_var(State0Var, VarSet, AppendVarNums, !IO),
 	io__write_string(", ", !IO),
-	mercury_output_var(StateVar, VarSet, AppendVarnums, !IO),
+	mercury_output_var(StateVar, VarSet, AppendVarNums, !IO),
 	io__write_string(")", !IO),
 	io__write_string(Follow, !IO),
 	io__nl(!IO),
 	hlds_out__write_aditi_builtin_pred_id(Indent, PredId, !IO).
 
 hlds_out__write_aditi_builtin(_ModuleInfo, Builtin, CallId,
-		ArgVars, VarSet, AppendVarnums, Indent, Follow, !IO) :-
+		ArgVars, VarSet, AppendVarNums, Indent, Follow, !IO) :-
 	Builtin = aditi_bulk_update(_, PredId, _Syntax),
 	hlds_out__write_indent(Indent, !IO),
 	hlds_out__aditi_builtin_name(Builtin, UpdateName),
@@ -2188,7 +2226,7 @@
 	hlds_out__simple_call_id_to_sym_name_and_arity(CallId, SymArity),
 	prog_out__write_sym_name_and_arity(SymArity, !IO),
 	io__write_string(", ", !IO),
-	mercury_output_vars(ArgVars, VarSet, AppendVarnums, !IO),
+	mercury_output_vars(ArgVars, VarSet, AppendVarNums, !IO),
 	io__write_string(")", !IO),
 	io__write_string(Follow, !IO),
 	io__nl(!IO),
@@ -2220,32 +2258,32 @@
 	is det.
 
 hlds_out__write_unification(assign(X, Y), _, ProgVarSet, _InstVarSet,
-		AppendVarnums, Indent, !IO) :-
+		AppendVarNums, Indent, !IO) :-
 	hlds_out__write_indent(Indent, !IO),
 	io__write_string("% ", !IO),
-	mercury_output_var(X, ProgVarSet, AppendVarnums, !IO),
+	mercury_output_var(X, ProgVarSet, AppendVarNums, !IO),
 	io__write_string(" := ", !IO),
-	mercury_output_var(Y, ProgVarSet, AppendVarnums, !IO),
+	mercury_output_var(Y, ProgVarSet, AppendVarNums, !IO),
 	io__write_string("\n", !IO).
 
-hlds_out__write_unification(simple_test(X, Y), _, ProgVarSet, _, AppendVarnums,
+hlds_out__write_unification(simple_test(X, Y), _, ProgVarSet, _, AppendVarNums,
 		Indent, !IO) :-
 	hlds_out__write_indent(Indent, !IO),
 	io__write_string("% ", !IO),
-	mercury_output_var(X, ProgVarSet, AppendVarnums, !IO),
+	mercury_output_var(X, ProgVarSet, AppendVarNums, !IO),
 	io__write_string(" == ", !IO),
-	mercury_output_var(Y, ProgVarSet, AppendVarnums, !IO),
+	mercury_output_var(Y, ProgVarSet, AppendVarNums, !IO),
 	io__write_string("\n", !IO).
 
 hlds_out__write_unification(construct(Var, ConsId, ArgVars, ArgModes,
 		_ConstructHow, Uniqueness, Size), ModuleInfo, ProgVarSet,
-		InstVarSet, AppendVarnums, Indent, !IO) :-
+		InstVarSet, AppendVarNums, Indent, !IO) :-
 	hlds_out__write_indent(Indent, !IO),
 	io__write_string("% ", !IO),
-	mercury_output_var(Var, ProgVarSet, AppendVarnums, !IO),
+	mercury_output_var(Var, ProgVarSet, AppendVarNums, !IO),
 	io__write_string(" := ", !IO),
 	hlds_out_write_functor_and_submodes(ConsId, ArgVars, ArgModes,
-		ModuleInfo, ProgVarSet, InstVarSet, AppendVarnums, Indent,
+		ModuleInfo, ProgVarSet, InstVarSet, AppendVarNums, Indent,
 		!IO),
 	(
 		Uniqueness = cell_is_unique,
@@ -2266,7 +2304,7 @@
 		;
 			SizeSource = dynamic_size(SizeVar),
 			io__write_string("var ", !IO),
-			mercury_output_var(SizeVar, ProgVarSet, AppendVarnums,
+			mercury_output_var(SizeVar, ProgVarSet, AppendVarNums,
 				!IO),
 			io__write_string("\n", !IO)
 		)
@@ -2276,7 +2314,7 @@
 
 hlds_out__write_unification(deconstruct(Var, ConsId, ArgVars, ArgModes,
 		CanFail, CanCGC), ModuleInfo, ProgVarSet, InstVarSet,
-		AppendVarnums, Indent, !IO) :-
+		AppendVarNums, Indent, !IO) :-
 	globals__io_lookup_string_option(dump_hlds_options, Verbose, !IO),
 	( string__contains_char(Verbose, 'G') ->
 		hlds_out__write_indent(Indent, !IO),
@@ -2288,7 +2326,7 @@
 	),
 	hlds_out__write_indent(Indent, !IO),
 	io__write_string("% ", !IO),
-	mercury_output_var(Var, ProgVarSet, AppendVarnums, !IO),
+	mercury_output_var(Var, ProgVarSet, AppendVarNums, !IO),
 	(
 		CanFail = can_fail,
 		io__write_string(" ?= ", !IO)
@@ -2297,7 +2335,7 @@
 		io__write_string(" => ", !IO)
 	),
 	hlds_out_write_functor_and_submodes(ConsId, ArgVars, ArgModes,
-		ModuleInfo, ProgVarSet, InstVarSet, AppendVarnums, Indent,
+		ModuleInfo, ProgVarSet, InstVarSet, AppendVarNums, Indent,
 		!IO).
 
 hlds_out__write_unification(complicated_unify(Mode, CanFail, TypeInfoVars),
@@ -2325,13 +2363,13 @@
 	bool::in, int::in, io::di, io::uo) is det.
 
 hlds_out_write_functor_and_submodes(ConsId, ArgVars, ArgModes, _ModuleInfo,
-		ProgVarSet, InstVarSet, AppendVarnums, Indent, !IO) :-
+		ProgVarSet, InstVarSet, AppendVarNums, Indent, !IO) :-
 	hlds_out__write_cons_id(ConsId, !IO),
 	( ArgVars = [] ->
 		io__write_string("\n", !IO)
 	;
 		io__write_string(" (", !IO),
-		mercury_output_vars(ArgVars, ProgVarSet, AppendVarnums, !IO),
+		mercury_output_vars(ArgVars, ProgVarSet, AppendVarNums, !IO),
 		io__write_string(")\n", !IO),
 		globals__io_lookup_string_option(dump_hlds_options, Verbose,
 			!IO),
@@ -2345,30 +2383,30 @@
 		)
 	).
 
-hlds_out__write_unify_rhs(Rhs, ModuleInfo, VarSet, InstVarSet, AppendVarnums,
+hlds_out__write_unify_rhs(Rhs, ModuleInfo, VarSet, InstVarSet, AppendVarNums,
 		Indent, !IO) :-
 	hlds_out__write_unify_rhs_3(Rhs, ModuleInfo, VarSet, InstVarSet,
-		AppendVarnums, Indent, no, no, !IO).
+		AppendVarNums, Indent, no, no, !IO).
 
 :- pred hlds_out__write_unify_rhs_2(unify_rhs::in, module_info::in,
 	prog_varset::in, inst_varset::in, bool::in, int::in, string::in,
 	maybe(type)::in, maybe_vartypes::in, io::di, io::uo) is det.
 
-hlds_out__write_unify_rhs_2(Rhs, ModuleInfo, VarSet, InstVarSet, AppendVarnums,
+hlds_out__write_unify_rhs_2(Rhs, ModuleInfo, VarSet, InstVarSet, AppendVarNums,
 		Indent, Follow, MaybeType, TypeQual, !IO) :-
 	hlds_out__write_unify_rhs_3(Rhs, ModuleInfo, VarSet, InstVarSet,
-		AppendVarnums, Indent, MaybeType, TypeQual, !IO),
+		AppendVarNums, Indent, MaybeType, TypeQual, !IO),
 	io__write_string(Follow, !IO).
 
 :- pred hlds_out__write_unify_rhs_3(unify_rhs::in, module_info::in,
 	prog_varset::in, inst_varset::in, bool::in, int::in, maybe(type)::in,
 	maybe_vartypes::in, io::di, io::uo) is det.
 
-hlds_out__write_unify_rhs_3(var(Var), _, VarSet, _, AppendVarnums, _, _, _,
+hlds_out__write_unify_rhs_3(var(Var), _, VarSet, _, AppendVarNums, _, _, _,
 		!IO) :-
-	mercury_output_var(Var, VarSet, AppendVarnums, !IO).
+	mercury_output_var(Var, VarSet, AppendVarNums, !IO).
 hlds_out__write_unify_rhs_3(functor(ConsId0, IsExistConstruct, ArgVars),
-		ModuleInfo, VarSet, _, AppendVarnums, _Indent,
+		ModuleInfo, VarSet, _, AppendVarNums, _Indent,
 		MaybeType, TypeQual, !IO) :-
 	(
 		IsExistConstruct = yes,
@@ -2380,7 +2418,7 @@
 		ConsId = ConsId0
 	),
 	hlds_out__write_functor_cons_id(ConsId, ArgVars, VarSet, ModuleInfo,
-		AppendVarnums, !IO),
+		AppendVarNums, !IO),
 	(
 		MaybeType = yes(Type),
 		TypeQual = yes(TVarSet, _)
@@ -2394,7 +2432,7 @@
 
 hlds_out__write_unify_rhs_3(lambda_goal(Purity, PredOrFunc, EvalMethod, _,
 		NonLocals, Vars, Modes, Det, Goal), ModuleInfo, VarSet,
-		InstVarSet, AppendVarnums, Indent, MaybeType, TypeQual, !IO) :-
+		InstVarSet, AppendVarNums, Indent, MaybeType, TypeQual, !IO) :-
 	Indent1 = Indent + 1,
 	write_purity_prefix(Purity, !IO),
 	(
@@ -2413,13 +2451,13 @@
 		;
 			io__write_string("pred(", !IO),
 			hlds_out__write_var_modes(Vars, Modes, VarSet,
-				InstVarSet, AppendVarnums, !IO),
+				InstVarSet, AppendVarNums, !IO),
 			io__write_string(")", !IO)
 		),
 		io__write_string(" is ", !IO),
 		mercury_output_det(Det, !IO),
 		io__write_string(" :-\n", !IO),
-		hlds_out__write_goal_a(Goal, ModuleInfo, VarSet, AppendVarnums,
+		hlds_out__write_goal_a(Goal, ModuleInfo, VarSet, AppendVarNums,
 			Indent1, "\n", TypeQual, !IO),
 		hlds_out__write_indent(Indent, !IO),
 		io__write_string(")", !IO)
@@ -2434,16 +2472,16 @@
 		;
 			io__write_string("func(", !IO),
 			hlds_out__write_var_modes(ArgVars, ArgModes, VarSet,
-				InstVarSet, AppendVarnums, !IO),
+				InstVarSet, AppendVarNums, !IO),
 			io__write_string(")", !IO)
 		),
 		io__write_string(" = (", !IO),
 		hlds_out__write_var_mode(RetVar, RetMode, VarSet,
-			InstVarSet, AppendVarnums, !IO),
+			InstVarSet, AppendVarNums, !IO),
 		io__write_string(") is ", !IO),
 		mercury_output_det(Det, !IO),
 		io__write_string(" :-\n", !IO),
-		hlds_out__write_goal_a(Goal, ModuleInfo, VarSet, AppendVarnums,
+		hlds_out__write_goal_a(Goal, ModuleInfo, VarSet, AppendVarNums,
 			Indent1, "\n", TypeQual, !IO),
 		hlds_out__write_indent(Indent, !IO),
 		io__write_string(")", !IO)
@@ -2453,7 +2491,7 @@
 		TypeQual = yes(TVarSet, _)
 	->
 		io__write_string(" `with_type` ", !IO),
-		mercury_output_term(Type, TVarSet, AppendVarnums,
+		mercury_output_term(Type, TVarSet, AppendVarNums,
 			next_to_graphic_token, !IO)
 	;
 		true
@@ -2463,7 +2501,7 @@
 		( NonLocals \= [] ->
 			hlds_out__write_indent(Indent1, !IO),
 			io__write_string("% lambda nonlocals: ", !IO),
-			mercury_output_vars(NonLocals, VarSet, AppendVarnums,
+			mercury_output_vars(NonLocals, VarSet, AppendVarNums,
 				!IO)
 		;
 			true
@@ -2475,41 +2513,41 @@
 :- pred hlds_out__write_sym_name_and_args(sym_name::in, list(prog_var)::in,
 	prog_varset::in, bool::in, io::di, io::uo) is det.
 
-hlds_out__write_sym_name_and_args(PredName, ArgVars, VarSet, AppendVarnums,
+hlds_out__write_sym_name_and_args(PredName, ArgVars, VarSet, AppendVarNums,
 		!IO) :-
 	(
 		PredName = qualified(ModuleName, Name),
 		hlds_out__write_qualified_functor(ModuleName,
-			term__atom(Name), ArgVars, VarSet, AppendVarnums, !IO)
+			term__atom(Name), ArgVars, VarSet, AppendVarNums, !IO)
 	;
 		PredName = unqualified(Name),
 		hlds_out__write_functor(term__atom(Name), ArgVars, VarSet,
-			AppendVarnums, next_to_graphic_token, !IO)
+			AppendVarNums, next_to_graphic_token, !IO)
 	).
 
-hlds_out__write_functor(Functor, ArgVars, VarSet, AppendVarnums, !IO) :-
-	hlds_out__write_functor(Functor, ArgVars, VarSet, AppendVarnums,
+hlds_out__write_functor(Functor, ArgVars, VarSet, AppendVarNums, !IO) :-
+	hlds_out__write_functor(Functor, ArgVars, VarSet, AppendVarNums,
 		not_next_to_graphic_token, !IO).
 
 :- pred hlds_out__write_functor(const::in, list(prog_var)::in, prog_varset::in,
 	bool::in, needs_quotes::in, io::di, io::uo) is det.
 
-hlds_out__write_functor(Functor, ArgVars, VarSet, AppendVarnums,
+hlds_out__write_functor(Functor, ArgVars, VarSet, AppendVarNums,
 		NextToGraphicToken, !IO) :-
 	term__context_init(Context),
 	term__var_list_to_term_list(ArgVars, ArgTerms),
 	Term = term__functor(Functor, ArgTerms, Context),
-	mercury_output_term(Term, VarSet, AppendVarnums, NextToGraphicToken,
+	mercury_output_term(Term, VarSet, AppendVarNums, NextToGraphicToken,
 		!IO).
 
 :- pred hlds_out__write_qualified_functor(module_name::in, const::in,
 	list(prog_var)::in, prog_varset::in, bool::in, io::di, io::uo) is det.
 
 hlds_out__write_qualified_functor(ModuleName, Functor, ArgVars, VarSet,
-		AppendVarnums, !IO) :-
+		AppendVarNums, !IO) :-
 	mercury_output_bracketed_sym_name(ModuleName, !IO),
 	io__write_string(".", !IO),
-	hlds_out__write_functor(Functor, ArgVars, VarSet, AppendVarnums,
+	hlds_out__write_functor(Functor, ArgVars, VarSet, AppendVarNums,
 		next_to_graphic_token, !IO).
 
 :- pred hlds_out__write_qualified_functor_with_term_args(module_name::in,
@@ -2525,32 +2563,32 @@
 		AppendVarNums, next_to_graphic_token, !IO).
 
 hlds_out__write_functor_cons_id(ConsId, ArgVars, VarSet, ModuleInfo,
-		AppendVarnums, !IO) :-
+		AppendVarNums, !IO) :-
 	(
 		ConsId = cons(SymName, _),
 		(
 			SymName = qualified(Module, Name),
 			hlds_out__write_qualified_functor(Module,
 				term__atom(Name), ArgVars, VarSet,
-				AppendVarnums, !IO)
+				AppendVarNums, !IO)
 		;
 			SymName = unqualified(Name),
 			hlds_out__write_functor(term__atom(Name),
-				ArgVars, VarSet, AppendVarnums,
+				ArgVars, VarSet, AppendVarNums,
 				next_to_graphic_token, !IO)
 		)
 	;
 		ConsId = int_const(Int),
 		hlds_out__write_functor(term__integer(Int), ArgVars,
-			VarSet, AppendVarnums, !IO)
+			VarSet, AppendVarNums, !IO)
 	;
 		ConsId = float_const(Float),
 		hlds_out__write_functor(term__float(Float), ArgVars,
-			VarSet, AppendVarnums, !IO)
+			VarSet, AppendVarNums, !IO)
 	;
 		ConsId = string_const(Str),
 		hlds_out__write_functor(term__string(Str), ArgVars,
-			VarSet, AppendVarnums, !IO)
+			VarSet, AppendVarNums, !IO)
 	;
 		ConsId = pred_const(PredId, _, _),
 		module_info_pred_info(ModuleInfo, PredId, PredInfo),
@@ -2559,7 +2597,7 @@
 		hlds_out__write_functor_cons_id(
 			cons(qualified(PredModule, PredName),
 				list__length(ArgVars)),
-			ArgVars, VarSet, ModuleInfo, AppendVarnums, !IO)
+			ArgVars, VarSet, ModuleInfo, AppendVarNums, !IO)
 	;
 		ConsId = type_ctor_info_const(Module, Name, Arity),
 		io__write_string("type_ctor_info(""", !IO),
@@ -2586,13 +2624,13 @@
 		ConsId = type_info_cell_constructor(_),
 		hlds_out__write_functor(
 			term__atom("type_info_cell_constructor"),
-			ArgVars, VarSet, AppendVarnums, next_to_graphic_token,
+			ArgVars, VarSet, AppendVarNums, next_to_graphic_token,
 			!IO)
 	;
 		ConsId = typeclass_info_cell_constructor,
 		hlds_out__write_functor(
 			term__atom("typeclass_info_cell_constructor"),
-			ArgVars, VarSet, AppendVarnums, next_to_graphic_token,
+			ArgVars, VarSet, AppendVarNums, next_to_graphic_token,
 			!IO)
 	;
 		ConsId = tabling_pointer_const(PredId, ProcId),
@@ -2624,8 +2662,8 @@
 
 hlds_out__write_var_modes([], [], _, _, _, !IO).
 hlds_out__write_var_modes([Var|Vars], [Mode|Modes], VarSet, InstVarSet,
-		AppendVarnums, !IO) :-
-	hlds_out__write_var_mode(Var, Mode, VarSet, InstVarSet, AppendVarnums,
+		AppendVarNums, !IO) :-
+	hlds_out__write_var_mode(Var, Mode, VarSet, InstVarSet, AppendVarNums,
 		!IO),
 	( Vars \= [] ->
 		io__write_string(", ", !IO)
@@ -2633,7 +2671,7 @@
 		true
 	),
 	hlds_out__write_var_modes(Vars, Modes, VarSet, InstVarSet,
-		AppendVarnums, !IO).
+		AppendVarNums, !IO).
 
 hlds_out__write_var_modes([], [_|_], _, _, _, !IO) :-
 	error("hlds_out__write_var_modes: length mis-match").
@@ -2643,8 +2681,8 @@
 :- pred hlds_out__write_var_mode(prog_var::in, (mode)::in, prog_varset::in,
 	inst_varset::in, bool::in, io::di, io::uo) is det.
 
-hlds_out__write_var_mode(Var, Mode, VarSet, InstVarSet, AppendVarnums, !IO) :-
-	mercury_output_var(Var, VarSet, AppendVarnums, !IO),
+hlds_out__write_var_mode(Var, Mode, VarSet, InstVarSet, AppendVarNums, !IO) :-
+	mercury_output_var(Var, VarSet, AppendVarNums, !IO),
 	io__write_string("::", !IO),
 	mercury_output_mode(Mode, InstVarSet, !IO).
 
@@ -2652,7 +2690,7 @@
 	module_info::in, prog_varset::in, bool::in, int::in, string::in,
 	string::in, string::in, maybe_vartypes::in, io::di, io::uo) is det.
 
-hlds_out__write_conj(Goal1, Goals1, ModuleInfo, VarSet, AppendVarnums,
+hlds_out__write_conj(Goal1, Goals1, ModuleInfo, VarSet, AppendVarNums,
 		Indent, Follow, Verbose, Separator, TypeQual, !IO) :-
 	(
 		Goals1 = [Goal2 | Goals2],
@@ -2663,33 +2701,33 @@
 			% the lines after one goal
 			% and the lines before the next
 			hlds_out__write_goal_a(Goal1, ModuleInfo, VarSet,
-				AppendVarnums, Indent, "\n", TypeQual, !IO),
+				AppendVarNums, Indent, "\n", TypeQual, !IO),
 			hlds_out__write_indent(Indent, !IO),
 			io__write_string(Separator, !IO)
 		;
 			hlds_out__write_goal_a(Goal1, ModuleInfo, VarSet,
-				AppendVarnums, Indent, Separator, TypeQual,
+				AppendVarNums, Indent, Separator, TypeQual,
 				!IO)
 		),
 		hlds_out__write_conj(Goal2, Goals2, ModuleInfo, VarSet,
-			AppendVarnums, Indent, Follow, Verbose, Separator,
+			AppendVarNums, Indent, Follow, Verbose, Separator,
 			TypeQual, !IO)
 	;
 		Goals1 = [],
 		hlds_out__write_goal_a(Goal1, ModuleInfo, VarSet,
-			AppendVarnums, Indent, Follow, TypeQual, !IO)
+			AppendVarNums, Indent, Follow, TypeQual, !IO)
 	).
 
-hlds_out__write_goal_list(GoalList, ModuleInfo, VarSet, AppendVarnums, Indent,
+hlds_out__write_goal_list(GoalList, ModuleInfo, VarSet, AppendVarNums, Indent,
 		Separator, TypeQual, !IO) :-
 	(
 		GoalList = [Goal | Goals],
 		hlds_out__write_indent(Indent, !IO),
 		io__write_string(Separator, !IO),
 		hlds_out__write_goal_a(Goal, ModuleInfo, VarSet,
-			AppendVarnums, Indent + 1, "\n", TypeQual, !IO),
+			AppendVarNums, Indent + 1, "\n", TypeQual, !IO),
 		hlds_out__write_goal_list(Goals, ModuleInfo, VarSet,
-			AppendVarnums, Indent, Separator, TypeQual, !IO)
+			AppendVarNums, Indent, Separator, TypeQual, !IO)
 	;
 		GoalList = []
 	).
@@ -2699,10 +2737,10 @@
 	io::di, io::uo) is det.
 
 hlds_out__write_case(case(ConsId, Goal), Var, ModuleInfo, VarSet,
-		AppendVarnums, Indent, VarTypes, !IO) :-
+		AppendVarNums, Indent, VarTypes, !IO) :-
 	hlds_out__write_indent(Indent, !IO),
 	io__write_string("% ", !IO),
-	mercury_output_var(Var, VarSet, AppendVarnums, !IO),
+	mercury_output_var(Var, VarSet, AppendVarNums, !IO),
 	io__write_string(" has functor ", !IO),
 	hlds_out__write_cons_id(ConsId, !IO),
 	io__write_string("\n", !IO),
@@ -2711,23 +2749,23 @@
 	% Var to the functor, since simplify.m and unused_args.m remove
 	% the unification. At the moment this is not a problem, since
 	% intermod.m works on the unoptimized clauses.
-	hlds_out__write_goal_a(Goal, ModuleInfo, VarSet, AppendVarnums,
+	hlds_out__write_goal_a(Goal, ModuleInfo, VarSet, AppendVarNums,
 		Indent, "\n", VarTypes, !IO).
 
 :- pred hlds_out__write_cases(list(case)::in, prog_var::in, module_info::in,
 	prog_varset::in, bool::in, int::in, maybe_vartypes::in,
 	io::di, io::uo) is det.
 
-hlds_out__write_cases(CasesList, Var, ModuleInfo, VarSet, AppendVarnums,
+hlds_out__write_cases(CasesList, Var, ModuleInfo, VarSet, AppendVarNums,
 		Indent, VarTypes, !IO) :-
 	(
 		CasesList = [Case | Cases],
 		hlds_out__write_indent(Indent, !IO),
 		io__write_string(";\n", !IO),
 		hlds_out__write_case(Case, Var, ModuleInfo,
-			VarSet, AppendVarnums, Indent + 1, VarTypes, !IO),
+			VarSet, AppendVarNums, Indent + 1, VarTypes, !IO),
 		hlds_out__write_cases(Cases, Var, ModuleInfo,
-			VarSet, AppendVarnums, Indent, VarTypes, !IO)
+			VarSet, AppendVarNums, Indent, VarTypes, !IO)
 	;
 		CasesList = []
 	).
@@ -2739,12 +2777,12 @@
 
 hlds_out__write_some(_Vars, _VarSet, !IO).
 
-hlds_out__write_instmap(InstMap, VarSet, AppendVarnums, Indent, !IO) :-
+hlds_out__write_instmap(InstMap, VarSet, AppendVarNums, Indent, !IO) :-
 	( instmap__is_unreachable(InstMap) ->
 		io__write_string("unreachable", !IO)
 	;
 		instmap__to_assoc_list(InstMap, AssocList),
-		hlds_out__write_instmap_2(AssocList, VarSet, AppendVarnums,
+		hlds_out__write_instmap_2(AssocList, VarSet, AppendVarNums,
 			Indent, !IO)
 	).
 
@@ -2752,9 +2790,9 @@
 	prog_varset::in, bool::in, int::in, io::di, io::uo) is det.
 
 hlds_out__write_instmap_2([], _, _, _, !IO).
-hlds_out__write_instmap_2([Var - Inst | Rest], VarSet, AppendVarnums, Indent,
+hlds_out__write_instmap_2([Var - Inst | Rest], VarSet, AppendVarNums, Indent,
 		!IO) :-
-	mercury_output_var(Var, VarSet, AppendVarnums, !IO),
+	mercury_output_var(Var, VarSet, AppendVarNums, !IO),
 	io__write_string(" -> ", !IO),
 	varset__init(InstVarSet),
 	mercury_output_inst(Inst, InstVarSet, !IO),
@@ -2763,33 +2801,33 @@
 	;
 		mercury_output_newline(Indent, !IO),
 		io__write_string("%            ", !IO),
-		hlds_out__write_instmap_2(Rest, VarSet, AppendVarnums, Indent,
+		hlds_out__write_instmap_2(Rest, VarSet, AppendVarNums, Indent,
 			!IO)
 	).
 
 :- pred hlds_out__write_instmap_delta(instmap_delta::in, prog_varset::in,
 	bool::in, int::in, io::di, io::uo) is det.
 
-hlds_out__write_instmap_delta(InstMapDelta, VarSet, AppendVarnums, Indent,
+hlds_out__write_instmap_delta(InstMapDelta, VarSet, AppendVarNums, Indent,
 		!IO) :-
 	( instmap_delta_is_unreachable(InstMapDelta) ->
 		io__write_string("unreachable", !IO)
 	;
 		instmap_delta_to_assoc_list(InstMapDelta, AssocList),
-		hlds_out__write_instmap_2(AssocList, VarSet, AppendVarnums,
+		hlds_out__write_instmap_2(AssocList, VarSet, AppendVarNums,
 			Indent, !IO)
 	).
 
 :- pred hlds_out__write_instmap_delta_vars(instmap_delta::in, prog_varset::in,
 	bool::in, io__state::di, io__state::uo) is det.
 
-hlds_out__write_instmap_delta_vars(InstMapDelta, VarSet, AppendVarnums, !IO) :-
+hlds_out__write_instmap_delta_vars(InstMapDelta, VarSet, AppendVarNums, !IO) :-
 	( instmap_delta_is_unreachable(InstMapDelta) ->
 		io__write_string("unreachable", !IO)
 	;
 		instmap_delta_to_assoc_list(InstMapDelta, AssocList),
 		assoc_list__keys(AssocList, Vars),
-		hlds_out__write_vars(Vars, VarSet, AppendVarnums, !IO)
+		hlds_out__write_vars(Vars, VarSet, AppendVarNums, !IO)
 	).
 
 hlds_out__write_import_status(Status, !IO) :-
@@ -2836,12 +2874,12 @@
 :- pred hlds_out__write_var_types(int::in, prog_varset::in, bool::in,
 	vartypes::in, tvarset::in, io::di, io::uo) is det.
 
-hlds_out__write_var_types(Indent, VarSet, AppendVarnums, VarTypes, TVarSet,
+hlds_out__write_var_types(Indent, VarSet, AppendVarNums, VarTypes, TVarSet,
 		!IO) :-
 	hlds_out__write_indent(Indent, !IO),
 	io__write_string("% variable types map:\n", !IO),
 	map__keys(VarTypes, Vars),
-	hlds_out__write_var_types_2(Vars, Indent, VarSet, AppendVarnums,
+	hlds_out__write_var_types_2(Vars, Indent, VarSet, AppendVarNums,
 		VarTypes, TVarSet, !IO).
 
 :- pred hlds_out__write_var_types_2(list(prog_var)::in, int::in,
@@ -2849,32 +2887,32 @@
 	is det.
 
 hlds_out__write_var_types_2([], _, _, _, _, _, !IO).
-hlds_out__write_var_types_2([Var | Vars], Indent, VarSet, AppendVarnums,
+hlds_out__write_var_types_2([Var | Vars], Indent, VarSet, AppendVarNums,
 		VarTypes, TypeVarSet, !IO) :-
 	map__lookup(VarTypes, Var, Type),
 	hlds_out__write_indent(Indent, !IO),
 	io__write_string("% ", !IO),
-	mercury_output_var(Var, VarSet, AppendVarnums, !IO),
+	mercury_output_var(Var, VarSet, AppendVarNums, !IO),
 	io__write_string(" (number ", !IO),
 	term__var_to_int(Var, VarNum),
 	io__write_int(VarNum, !IO),
 	io__write_string(")", !IO),
 	io__write_string(": ", !IO),
-	mercury_output_term(Type, TypeVarSet, AppendVarnums, !IO),
+	mercury_output_term(Type, TypeVarSet, AppendVarNums, !IO),
 	io__write_string("\n", !IO),
-	hlds_out__write_var_types_2(Vars, Indent, VarSet, AppendVarnums,
+	hlds_out__write_var_types_2(Vars, Indent, VarSet, AppendVarNums,
 		VarTypes, TypeVarSet, !IO).
 
 :- pred hlds_out__write_typeinfo_varmap(int::in, bool::in,
 	type_info_varmap::in, prog_varset::in, tvarset::in, io::di, io::uo)
 	is det.
 
-hlds_out__write_typeinfo_varmap(Indent, AppendVarnums, TypeInfoMap, VarSet,
+hlds_out__write_typeinfo_varmap(Indent, AppendVarNums, TypeInfoMap, VarSet,
 		TVarSet, !IO) :-
 	hlds_out__write_indent(Indent, !IO),
 	io__write_string("% type_info varmap:\n", !IO),
 	map__keys(TypeInfoMap, TypeVars),
-	hlds_out__write_typeinfo_varmap_2(TypeVars, Indent, AppendVarnums,
+	hlds_out__write_typeinfo_varmap_2(TypeVars, Indent, AppendVarNums,
 		TypeInfoMap, VarSet, TVarSet, !IO).
 
 :- pred hlds_out__write_typeinfo_varmap_2(list(tvar)::in, int::in, bool::in,
@@ -2882,12 +2920,12 @@
 	io::di, io::uo) is det.
 
 hlds_out__write_typeinfo_varmap_2([], _, _, _, _, _, !IO).
-hlds_out__write_typeinfo_varmap_2([TVar | TVars], Indent, AppendVarnums,
+hlds_out__write_typeinfo_varmap_2([TVar | TVars], Indent, AppendVarNums,
 		TypeInfoMap, VarSet, TVarSet, !IO) :-
 	hlds_out__write_indent(Indent, !IO),
 	io__write_string("% ", !IO),
 
-	mercury_output_var(TVar, TVarSet, AppendVarnums, !IO),
+	mercury_output_var(TVar, TVarSet, AppendVarNums, !IO),
 	io__write_string(" (number ", !IO),
 	term__var_to_int(TVar, TVarNum),
 	io__write_int(TVarNum, !IO),
@@ -2898,12 +2936,12 @@
 	(
 		Locn = type_info(Var),
 		io__write_string("type_info(", !IO),
-		mercury_output_var(Var, VarSet, AppendVarnums, !IO),
+		mercury_output_var(Var, VarSet, AppendVarNums, !IO),
 		io__write_string(") ", !IO)
 	;
 		Locn = typeclass_info(Var, Index),
 		io__write_string("typeclass_info(", !IO),
-		mercury_output_var(Var, VarSet, AppendVarnums, !IO),
+		mercury_output_var(Var, VarSet, AppendVarNums, !IO),
 		io__write_string(", ", !IO),
 		io__write_int(Index, !IO),
 		io__write_string(") ", !IO)
@@ -2914,56 +2952,56 @@
 	io__write_string(")", !IO),
 	io__write_string("\n", !IO),
 
-	hlds_out__write_typeinfo_varmap_2(TVars, Indent, AppendVarnums,
+	hlds_out__write_typeinfo_varmap_2(TVars, Indent, AppendVarNums,
 		TypeInfoMap, VarSet, TVarSet, !IO).
 
 :- pred hlds_out__write_typeclass_info_varmap(int::in, bool::in,
 	typeclass_info_varmap::in, prog_varset::in, tvarset::in,
 	io::di, io::uo) is det.
 
-hlds_out__write_typeclass_info_varmap(Indent, AppendVarnums,
+hlds_out__write_typeclass_info_varmap(Indent, AppendVarNums,
 		TypeClassInfoVarMap, VarSet, TVarSet, !IO) :-
 	hlds_out__write_indent(Indent, !IO),
 	io__write_string("% typeclass_info varmap:\n", !IO),
 	map__foldl(hlds_out__write_typeclass_info_varmap_2(Indent,
-		AppendVarnums, VarSet, TVarSet), TypeClassInfoVarMap, !IO).
+		AppendVarNums, VarSet, TVarSet), TypeClassInfoVarMap, !IO).
 
 :- pred hlds_out__write_typeclass_info_varmap_2(int::in, bool::in,
 	prog_varset::in, tvarset::in, class_constraint::in, prog_var::in,
 	io::di, io::uo) is det.
 
-hlds_out__write_typeclass_info_varmap_2(Indent, AppendVarnums, VarSet, TVarSet,
+hlds_out__write_typeclass_info_varmap_2(Indent, AppendVarNums, VarSet, TVarSet,
 		Constraint, Var, !IO) :-
 	hlds_out__write_indent(Indent, !IO),
 	io__write_string("% ", !IO),
-	mercury_output_constraint(TVarSet, AppendVarnums, Constraint, !IO),
+	mercury_output_constraint(TVarSet, AppendVarNums, Constraint, !IO),
 	io__write_string(" -> ", !IO),
-	mercury_output_var(Var, VarSet, AppendVarnums, !IO),
+	mercury_output_var(Var, VarSet, AppendVarNums, !IO),
 	io__nl(!IO).
 
 :- pred hlds_out__write_stack_slots(int::in, stack_slots::in, prog_varset::in,
 	bool::in, io::di, io::uo) is det.
 
-hlds_out__write_stack_slots(Indent, StackSlots, VarSet, AppendVarnums, !IO) :-
+hlds_out__write_stack_slots(Indent, StackSlots, VarSet, AppendVarNums, !IO) :-
 	map__to_assoc_list(StackSlots, VarSlotList0),
 	VarSlotList = assoc_list__map_values(key_stack_slot_to_abs_locn,
 		VarSlotList0),
-	hlds_out__write_var_to_abs_locns(VarSlotList, VarSet, AppendVarnums,
+	hlds_out__write_var_to_abs_locns(VarSlotList, VarSet, AppendVarNums,
 		Indent, !IO).
 
 :- pred hlds_out__write_var_to_abs_locns(assoc_list(prog_var, abs_locn)::in,
 	prog_varset::in, bool::in, int::in, io::di, io::uo) is det.
 
 hlds_out__write_var_to_abs_locns([], _, _, _, !IO).
-hlds_out__write_var_to_abs_locns([Var - Loc | VarLocs], VarSet, AppendVarnums,
+hlds_out__write_var_to_abs_locns([Var - Loc | VarLocs], VarSet, AppendVarNums,
 		Indent, !IO) :-
 	hlds_out__write_indent(Indent, !IO),
 	io__write_string("%\t", !IO),
-	mercury_output_var(Var, VarSet, AppendVarnums, !IO),
+	mercury_output_var(Var, VarSet, AppendVarNums, !IO),
 	io__write_string("\t-> ", !IO),
 	io__write_string(abs_locn_to_string(Loc), !IO),
 	io__write_string("\n", !IO),
-	hlds_out__write_var_to_abs_locns(VarLocs, VarSet, AppendVarnums, Indent,
+	hlds_out__write_var_to_abs_locns(VarLocs, VarSet, AppendVarNums, Indent,
 		!IO).
 
 %-----------------------------------------------------------------------------%
@@ -3214,20 +3252,20 @@
 
 	globals__io_lookup_string_option(dump_hlds_options, Verbose, !IO),
 	( string__contains_char(Verbose, 'v') ->
-		AppendVarnums = yes
+		AppendVarNums = yes
 	;
-		AppendVarnums = no
+		AppendVarNums = no
 	),
 
 	hlds_out__write_indent(Indent, !IO),
 	io__write_string("% Vars: ", !IO),
-	mercury_output_vars(Vars, VarSet, AppendVarnums, !IO),
+	mercury_output_vars(Vars, VarSet, AppendVarNums, !IO),
 	io__nl(!IO),
 
 	hlds_out__write_indent(Indent, !IO),
 	io__write_string("% Constraints: ", !IO),
 	io__write_list(Constraints, ", ",
-		mercury_output_constraint(VarSet, AppendVarnums), !IO),
+		mercury_output_constraint(VarSet, AppendVarNums), !IO),
 	io__nl(!IO),
 
 	hlds_out__write_indent(Indent, !IO),
@@ -3347,15 +3385,15 @@
 
 	globals__io_lookup_string_option(dump_hlds_options, Verbose, !IO),
 	( string__contains_char(Verbose, 'v') ->
-		AppendVarnums = yes
+		AppendVarNums = yes
 	;
-		AppendVarnums = no
+		AppendVarNums = no
 	),
 
 		% curry the varset for term_io__write_variable/4
 	PrintTerm = (pred(TypeName::in, IO0::di, IO::uo) is det :-
 			mercury_output_term(TypeName, VarSet,
-				AppendVarnums, IO0, IO)
+				AppendVarNums, IO0, IO)
 		),
 	hlds_out__write_indent(Indent, !IO),
 	io__write_string("% Types: ", !IO),
@@ -3365,7 +3403,7 @@
 	hlds_out__write_indent(Indent, !IO),
 	io__write_string("% Constraints: ", !IO),
 	io__write_list(Constraints, ", ",
-		mercury_output_constraint(VarSet, AppendVarnums), !IO),
+		mercury_output_constraint(VarSet, AppendVarNums), !IO),
 	io__nl(!IO),
 
 	hlds_out__write_indent(Indent, !IO),
@@ -3390,7 +3428,7 @@
 	),
 
 	hlds_out__write_constraint_proofs(Indent, VarSet, Proofs,
-		AppendVarnums, !IO),
+		AppendVarNums, !IO),
 	io__nl(!IO).
 
 %-----------------------------------------------------------------------------%
@@ -3426,11 +3464,11 @@
 :- pred hlds_out__write_procs(int::in, bool::in, module_info::in, pred_id::in,
 	import_status::in, pred_info::in, io::di, io::uo) is det.
 
-hlds_out__write_procs(Indent, AppendVarnums, ModuleInfo, PredId,
+hlds_out__write_procs(Indent, AppendVarNums, ModuleInfo, PredId,
 		ImportStatus, PredInfo, !IO) :-
 	pred_info_procedures(PredInfo, ProcTable),
 	ProcIds = pred_info_procids(PredInfo),
-	hlds_out__write_procs_2(ProcIds, AppendVarnums, ModuleInfo, Indent,
+	hlds_out__write_procs_2(ProcIds, AppendVarNums, ModuleInfo, Indent,
 		PredId, ImportStatus, ProcTable, !IO).
 
 :- pred hlds_out__write_procs_2(list(proc_id)::in, bool::in, module_info::in,
@@ -3438,18 +3476,18 @@
 	io::di, io::uo) is det.
 
 hlds_out__write_procs_2([], _, _, _, _, _, _, !IO).
-hlds_out__write_procs_2([ProcId | ProcIds], AppendVarnums, ModuleInfo, Indent,
+hlds_out__write_procs_2([ProcId | ProcIds], AppendVarNums, ModuleInfo, Indent,
 		PredId, ImportStatus, ProcTable, !IO) :-
 	map__lookup(ProcTable, ProcId, ProcInfo),
-	hlds_out__write_proc(Indent, AppendVarnums, ModuleInfo, PredId, ProcId,
+	hlds_out__write_proc(Indent, AppendVarNums, ModuleInfo, PredId, ProcId,
 		ImportStatus, ProcInfo, !IO),
-	hlds_out__write_procs_2(ProcIds, AppendVarnums, ModuleInfo, Indent,
+	hlds_out__write_procs_2(ProcIds, AppendVarNums, ModuleInfo, Indent,
 		PredId, ImportStatus, ProcTable, !IO).
 
 :- pred hlds_out__write_proc(int::in, bool::in, module_info::in, pred_id::in,
 	proc_id::in, import_status::in, proc_info::in, io::di, io::uo) is det.
 
-hlds_out__write_proc(Indent, AppendVarnums, ModuleInfo, PredId, ProcId,
+hlds_out__write_proc(Indent, AppendVarNums, ModuleInfo, PredId, ProcId,
 		ImportStatus, Proc, !IO) :-
 	module_info_pred_info(ModuleInfo, PredId, PredInfo),
 	pred_info_typevarset(PredInfo, TVarSet),
@@ -3503,11 +3541,11 @@
 	),
 
 	hlds_out__write_indent(Indent, !IO),
-	hlds_out__write_var_types(Indent, VarSet, AppendVarnums,
+	hlds_out__write_var_types(Indent, VarSet, AppendVarNums,
 		VarTypes, TVarSet, !IO),
-	hlds_out__write_typeinfo_varmap(Indent, AppendVarnums, TypeInfoMap,
+	hlds_out__write_typeinfo_varmap(Indent, AppendVarNums, TypeInfoMap,
 		VarSet, TVarSet, !IO),
-	hlds_out__write_typeclass_info_varmap(Indent, AppendVarnums,
+	hlds_out__write_typeclass_info_varmap(Indent, AppendVarNums,
 		TypeClassInfoMap, VarSet, TVarSet, !IO),
 
 	(
@@ -3529,7 +3567,7 @@
 	(
 		MaybeCallTableTip = yes(CallTableTip),
 		io__write_string("% call table tip: ", !IO),
-		mercury_output_var(CallTableTip, VarSet, AppendVarnums, !IO),
+		mercury_output_var(CallTableTip, VarSet, AppendVarNums, !IO),
 		io__write_string("\n", !IO)
 	;
 		MaybeCallTableTip = no
@@ -3567,15 +3605,15 @@
 				MaybeOldOutermost),
 			io__write_string("% deep layout info: ", !IO),
 			io__write_string("TopCSD is ", !IO),
-			mercury_output_var(TopCSD, VarSet, AppendVarnums, !IO),
+			mercury_output_var(TopCSD, VarSet, AppendVarNums, !IO),
 			io__write_string(", MiddleCSD is ", !IO),
-			mercury_output_var(MiddleCSD, VarSet, AppendVarnums,
+			mercury_output_var(MiddleCSD, VarSet, AppendVarNums,
 				!IO),
 			(
 				MaybeOldOutermost = yes(OldOutermost),
 				io__write_string(", OldOutermost is ", !IO),
 				mercury_output_var(OldOutermost, VarSet,
-					AppendVarnums, !IO)
+					AppendVarNums, !IO)
 			;
 				MaybeOldOutermost = no
 			),
@@ -3636,13 +3674,13 @@
 		proc_info_stack_slots(Proc, StackSlots),
 		hlds_out__write_indent(Indent, !IO),
 		hlds_out__write_stack_slots(Indent, StackSlots, VarSet,
-			AppendVarnums, !IO),
+			AppendVarNums, !IO),
 		hlds_out__write_indent(Indent, !IO),
 		term__var_list_to_term_list(HeadVars, HeadTerms),
 		hlds_out__write_clause_head(ModuleInfo, PredId, VarSet,
-			AppendVarnums, HeadTerms, PredOrFunc, !IO),
+			AppendVarNums, HeadTerms, PredOrFunc, !IO),
 		io__write_string(" :-\n", !IO),
-		hlds_out__write_goal(Goal, ModuleInfo, VarSet, AppendVarnums,
+		hlds_out__write_goal(Goal, ModuleInfo, VarSet, AppendVarNums,
 			Indent1, ".\n", !IO)
 	).
 
@@ -3755,23 +3793,23 @@
 	map(class_constraint, constraint_proof)::in, bool::in,
 	io::di, io::uo) is det.
 
-hlds_out__write_constraint_proofs(Indent, VarSet, Proofs, AppendVarnums,
+hlds_out__write_constraint_proofs(Indent, VarSet, Proofs, AppendVarNums,
 		!IO) :-
 	hlds_out__write_indent(Indent, !IO),
 	io__write_string("% Proofs: \n", !IO),
 	map__to_assoc_list(Proofs, ProofsList),
 	io__write_list(ProofsList, "\n",
 		hlds_out__write_constraint_proof(Indent,
-			VarSet, AppendVarnums), !IO).
+			VarSet, AppendVarNums), !IO).
 
 :- pred hlds_out__write_constraint_proof(int::in, tvarset::in, bool::in,
 	pair(class_constraint, constraint_proof)::in, io::di, io::uo) is det.
 
-hlds_out__write_constraint_proof(Indent, VarSet, AppendVarnums,
+hlds_out__write_constraint_proof(Indent, VarSet, AppendVarNums,
 		Constraint - Proof, !IO) :-
 	hlds_out__write_indent(Indent, !IO),
 	io__write_string("% ", !IO),
-	mercury_output_constraint(VarSet, AppendVarnums, Constraint, !IO),
+	mercury_output_constraint(VarSet, AppendVarNums, Constraint, !IO),
 	io__write_string(": ", !IO),
 	(
 		Proof = apply_instance(Num),
@@ -3780,7 +3818,7 @@
 	;
 		Proof = superclass(Super),
 		io__write_string("super class of ", !IO),
-		mercury_output_constraint(VarSet, AppendVarnums, Super, !IO)
+		mercury_output_constraint(VarSet, AppendVarNums, Super, !IO)
 	).
 
 %-----------------------------------------------------------------------------%
Index: compiler/hlds_pred.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/hlds_pred.m,v
retrieving revision 1.145
diff -u -b -r1.145 hlds_pred.m
--- compiler/hlds_pred.m	31 May 2004 04:12:53 -0000	1.145
+++ compiler/hlds_pred.m	7 Jun 2004 08:49:55 -0000
@@ -1693,7 +1693,9 @@
 						% type, and thus the size of
 						% the corresponding trie node.
 	;	table_trie_step_user(type)
-	;	table_trie_step_poly.
+	;	table_trie_step_poly
+	;	table_trie_step_typeinfo
+	;	table_trie_step_typeclassinfo.
 
 :- type table_arg_infos
 	--->	table_arg_infos(
@@ -2547,6 +2549,8 @@
 			"unconstrained_type_info_from_typeclass_info", 3).
 no_type_info_builtin_2(table_builtin, "table_restore_any_answer", 3).
 no_type_info_builtin_2(table_builtin, "table_lookup_insert_enum", 4).
+no_type_info_builtin_2(table_builtin, "table_lookup_insert_typeinfo", 3).
+no_type_info_builtin_2(table_builtin, "table_lookup_insert_typeclassinfo", 3).
 no_type_info_builtin_2(term_size_prof_builtin, "increment_size", 2).
 
 proc_info_has_io_state_pair(ModuleInfo, ProcInfo, InArgNum, OutArgNum) :-
Index: compiler/inlining.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/inlining.m,v
retrieving revision 1.117
diff -u -b -r1.117 inlining.m
--- compiler/inlining.m	5 Apr 2004 05:06:49 -0000	1.117
+++ compiler/inlining.m	7 Jun 2004 08:49:55 -0000
@@ -567,7 +567,7 @@
 		Goal = Goal0,
 		GoalInfo = GoalInfo0
 	;
-		Goal0 = foreign_proc(_, _, _, _, _, _, _),
+		Goal0 = foreign_proc(_, _, _, _, _, _),
 		Goal = Goal0,
 		GoalInfo = GoalInfo0
 	;
@@ -911,7 +911,7 @@
 	proc_info_goal(ProcInfo, CalledGoal),
 	\+ (
 		HighLevelCode = no,
-		CalledGoal = foreign_proc(_,_,_,_,_,_,_) - _,
+		CalledGoal = foreign_proc(_, _, _, _, _, _) - _,
 		proc_info_interface_determinism(ProcInfo, Detism),
 		( Detism = nondet ; Detism = multidet )
 	),
@@ -923,7 +923,7 @@
 	(
 		(
 			CalledGoal = foreign_proc(ForeignAttributes,
-				_,_,_,_,_,_) - _,
+				_, _, _, _, _) - _,
 			ForeignLanguage = foreign_language(ForeignAttributes)
 		)
 	=>
Index: compiler/intermod.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/intermod.m,v
retrieving revision 1.159
diff -u -b -r1.159 intermod.m
--- compiler/intermod.m	12 May 2004 14:24:19 -0000	1.159
+++ compiler/intermod.m	7 Jun 2004 08:49:55 -0000
@@ -46,26 +46,22 @@
 
 :- import_module io, bool.
 
-:- pred intermod__write_optfile(module_info, module_info,
-				io__state, io__state).
-:- mode intermod__write_optfile(in, out, di, uo) is det.
+:- pred intermod__write_optfile(module_info::in, module_info::out,
+	io::di, io::uo) is det.
 
 	% Add the items from the .opt files of imported modules to
 	% the items for this module.
-:- pred intermod__grab_optfiles(module_imports, module_imports, bool,
-				io__state, io__state).
-:- mode intermod__grab_optfiles(in, out, out, di, uo) is det.
+:- pred intermod__grab_optfiles(module_imports::in, module_imports::out,
+	bool::out, io::di, io::uo) is det.
 
 	% Make sure that local preds which have been exported in the .opt
 	% file get an exported(_) label.
-:- pred intermod__adjust_pred_import_status(module_info, module_info,
-		io__state, io__state).
-:- mode intermod__adjust_pred_import_status(in, out, di, uo) is det.
+:- pred intermod__adjust_pred_import_status(module_info::in, module_info::out,
+	io::di, io::uo) is det.
 
 :- type opt_file_type
 	--->	opt
-	;	trans_opt
-	.
+	;	trans_opt.
 
 	% intermod__update_error_status(OptFileType, FileName, Error, Messages,
 	% 	Status0, Status)
@@ -80,9 +76,9 @@
 	% Syntax errors in `.opt' files are always fatal.
 	%
 	% This is also used by trans_opt.m for reading `.trans_opt' files.
-:- pred intermod__update_error_status(opt_file_type, string, module_error,
-		message_list, bool, bool, io__state, io__state).
-:- mode intermod__update_error_status(in, in, in, in, in, out, di, uo) is det.
+:- pred intermod__update_error_status(opt_file_type::in, string::in,
+	module_error::in, message_list::in, bool::in, bool::out,
+	io::di, io::uo) is det.
 
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
@@ -118,211 +114,181 @@
 
 %-----------------------------------------------------------------------------%
 
-% Open the file "<module-name>.opt.tmp", and write out the
-% declarations and clauses for intermodule optimization.
-% Note that update_interface and touch_interface_datestamp
-% are called from mercury_compile.m since they must be called
-% after unused_args.m appends its information to the .opt.tmp
-% file.
+	% Open the file "<module-name>.opt.tmp", and write out the
+	% declarations and clauses for intermodule optimization.
+	% Note that update_interface and touch_interface_datestamp
+	% are called from mercury_compile.m since they must be called
+	% after unused_args.m appends its information to the .opt.tmp
+	% file.
 
-intermod__write_optfile(ModuleInfo0, ModuleInfo) -->
+intermod__write_optfile(!ModuleInfo, !IO) :-
 	% We don't want to output line numbers in the .opt files,
 	% since that causes spurious changes to the .opt files
 	% when you make trivial changes (e.g. add comments) to the source files.
-	globals__io_lookup_bool_option(line_numbers, LineNumbers),
-	globals__io_set_option(line_numbers, bool(no)),
+	globals__io_lookup_bool_option(line_numbers, LineNumbers, !IO),
+	globals__io_set_option(line_numbers, bool(no), !IO),
 
-	{ module_info_name(ModuleInfo0, ModuleName) },
-	module_name_to_file_name(ModuleName, ".opt.tmp", yes, TmpName),
-	io__open_output(TmpName, Result2),
-	(
-		{ Result2 = error(Err2) },
-		{ io__error_message(Err2, Msg2) },
-		io__write_string(Msg2),
-		io__set_exit_status(1),
-		{ ModuleInfo = ModuleInfo0 }
-	;
-		{ Result2 = ok(FileStream) },
-		io__set_output_stream(FileStream, OutputStream),
-		{ module_info_predids(ModuleInfo0, RealPredIds) },
-		{ module_info_assertion_table(ModuleInfo0, AssertionTable) },
-		{ assertion_table_pred_ids(AssertionTable, AssertPredIds) },
-		{ list__append(AssertPredIds, RealPredIds, PredIds) },
-		{ init_intermod_info(ModuleInfo0, IntermodInfo0) },
+	module_info_name(!.ModuleInfo, ModuleName),
+	module_name_to_file_name(ModuleName, ".opt.tmp", yes, TmpName, !IO),
+	io__open_output(TmpName, Result2, !IO),
+	(
+		Result2 = error(Err2),
+		io__error_message(Err2, Msg2),
+		io__write_string(Msg2, !IO),
+		io__set_exit_status(1, !IO)
+	;
+		Result2 = ok(FileStream),
+		io__set_output_stream(FileStream, OutputStream, !IO),
+		module_info_predids(!.ModuleInfo, RealPredIds),
+		module_info_assertion_table(!.ModuleInfo, AssertionTable),
+		assertion_table_pred_ids(AssertionTable, AssertPredIds),
+		list__append(AssertPredIds, RealPredIds, PredIds),
+		init_intermod_info(!.ModuleInfo, IntermodInfo0),
 		globals__io_lookup_int_option(
-			intermod_inline_simple_threshold, Threshold),
-		globals__io_lookup_bool_option(deforestation, Deforestation),
+			intermod_inline_simple_threshold, Threshold, !IO),
+		globals__io_lookup_bool_option(deforestation, Deforestation,
+			!IO),
 		globals__io_lookup_int_option(higher_order_size_limit,
-			HigherOrderSizeLimit),
-		{ intermod__gather_preds(PredIds, yes, Threshold,
+			HigherOrderSizeLimit, !IO),
+		intermod__gather_preds(PredIds, yes, Threshold,
 			HigherOrderSizeLimit, Deforestation,
-			IntermodInfo0, IntermodInfo1) },
-		{ intermod__gather_instances(IntermodInfo1,
-			IntermodInfo2) },
-		{ intermod__gather_types(IntermodInfo2,
-			IntermodInfo) },
-		intermod__write_intermod_info(IntermodInfo),
-		{ intermod_info_get_module_info(ModuleInfo1,
-			IntermodInfo, _) },
-		io__set_output_stream(OutputStream, _),
-		io__close_output(FileStream),
+			IntermodInfo0, IntermodInfo1),
+		intermod__gather_instances(IntermodInfo1,
+			IntermodInfo2),
+		intermod__gather_types(IntermodInfo2,
+			IntermodInfo),
+		intermod__write_intermod_info(IntermodInfo, !IO),
+		intermod_info_get_module_info(!:ModuleInfo, IntermodInfo, _),
+		io__set_output_stream(OutputStream, _, !IO),
+		io__close_output(FileStream, !IO),
 		globals__io_lookup_bool_option(intermod_unused_args,
-			UnusedArgs),
-		( { UnusedArgs = yes } ->
-			{ do_adjust_pred_import_status(IntermodInfo,
-				ModuleInfo1, ModuleInfo) }
+			UnusedArgs, !IO),
+		( UnusedArgs = yes ->
+			do_adjust_pred_import_status(IntermodInfo,
+				!ModuleInfo)
 		;
-			{ ModuleInfo = ModuleInfo1 }
+			true
 		)
 	),
 	% restore the option setting that we overrode above
-	globals__io_set_option(line_numbers, bool(LineNumbers)).
-
-	% a collection of stuff to go in the .opt file
-:- type intermod_info
-		 ---> info(
-			set(module_name),	% modules to import
-			set(pred_id), 		% preds to output clauses for
-			set(pred_id),	 	% preds to output decls for
-			assoc_list(class_id, hlds_instance_defn),
-						% instances declarations
-						% to write
-			assoc_list(type_ctor, hlds_type_defn),
-						% type declarations
-						% to write
-			unit,
-			module_info,
-			bool,			% do the c_header_codes for
-				% the module need writing, yes if there
-				% are pragma_foreign_code procs being exported
-			map(prog_var, type),	% Vartypes and tvarset for the
-			tvarset			% current pred
-		).
-
-:- pred init_intermod_info(module_info::in, intermod_info::out) is det.
-
-init_intermod_info(ModuleInfo, IntermodInfo) :-
-	set__init(Modules),
-	set__init(Procs),
-	set__init(ProcDecls),
-	map__init(VarTypes),
-	varset__init(TVarSet),
-	Instances = [],
-	Types = [],
-	IntermodInfo = info(Modules, Procs, ProcDecls, Instances, Types,
-			unit, ModuleInfo, no, VarTypes, TVarSet).
+	globals__io_set_option(line_numbers, bool(LineNumbers), !IO).
 			
 %-----------------------------------------------------------------------------%
+
 	% Predicates to gather stuff to output to .opt file.
 
 :- pred intermod__gather_preds(list(pred_id)::in, bool::in, int::in,
 	int::in, bool::in, intermod_info::in, intermod_info::out) is det.
 
 intermod__gather_preds(AllPredIds, CollectTypes,
-		InlineThreshold, HigherOrderSizeLimit, Deforestation) -->
+		InlineThreshold, HigherOrderSizeLimit, Deforestation, !Info) :-
 	% first gather exported preds
-	{ ProcessLocalPreds = no },
+	ProcessLocalPreds = no,
 	intermod__gather_pred_list(AllPredIds, ProcessLocalPreds,
 		CollectTypes, InlineThreshold, HigherOrderSizeLimit,
-		Deforestation),
+		Deforestation, !Info),
 
 	% then gather preds used by exported preds (recursively)
-	{ set__init(ExtraExportedPreds0) },
+	set__init(ExtraExportedPreds0),
 	intermod__gather_preds_2(ExtraExportedPreds0, CollectTypes,
-		InlineThreshold, HigherOrderSizeLimit, Deforestation).
+		InlineThreshold, HigherOrderSizeLimit, Deforestation, !Info).
 
 :- pred intermod__gather_preds_2(set(pred_id)::in, bool::in, int::in,
 	int::in, bool::in, intermod_info::in, intermod_info::out) is det.
 
 intermod__gather_preds_2(ExtraExportedPreds0, CollectTypes,
-		InlineThreshold, HigherOrderSizeLimit, Deforestation) -->
-	intermod_info_get_pred_decls(ExtraExportedPreds),
-	{ NewlyExportedPreds = set__to_sorted_list(
-		ExtraExportedPreds `set__difference` ExtraExportedPreds0) },
-	( { NewlyExportedPreds = [] } ->
-		[]
+		InlineThreshold, HigherOrderSizeLimit, Deforestation, !Info) :-
+	intermod_info_get_pred_decls(ExtraExportedPreds, !Info),
+	NewlyExportedPreds = set__to_sorted_list(
+		ExtraExportedPreds `set__difference` ExtraExportedPreds0),
+	( NewlyExportedPreds = [] ->
+		true
 	;
-		{ ProcessLocalPreds = yes },
+		ProcessLocalPreds = yes,
 		intermod__gather_pred_list(NewlyExportedPreds,
 			ProcessLocalPreds, CollectTypes,
-			InlineThreshold, HigherOrderSizeLimit, Deforestation),
+			InlineThreshold, HigherOrderSizeLimit, Deforestation,
+			!Info),
 		intermod__gather_preds_2(ExtraExportedPreds, CollectTypes,
-			InlineThreshold, HigherOrderSizeLimit, Deforestation)
+			InlineThreshold, HigherOrderSizeLimit, Deforestation,
+			!Info)
 	).
 
 :- pred intermod__gather_pred_list(list(pred_id)::in, bool::in, bool::in,
 	int::in, int::in, bool::in, intermod_info::in, intermod_info::out)
 	is det.
 
-intermod__gather_pred_list([], _, _, _, _, _) --> [].
+intermod__gather_pred_list([], _, _, _, _, _, !Info).
 intermod__gather_pred_list([PredId | PredIds], ProcessLocalPreds, CollectTypes,
-		InlineThreshold, HigherOrderSizeLimit, Deforestation) -->
-	intermod_info_get_module_info(ModuleInfo0),
-	{ module_info_preds(ModuleInfo0, PredTable0) },
-	{ map__lookup(PredTable0, PredId, PredInfo0) },
-	{ module_info_type_spec_info(ModuleInfo0, TypeSpecInfo) },
-	{ TypeSpecInfo = type_spec_info(_, TypeSpecForcePreds, _, _) },
-	{ pred_info_clauses_info(PredInfo0, ClausesInfo0) },
+		InlineThreshold, HigherOrderSizeLimit, Deforestation, !Info) :-
+	intermod_info_get_module_info(ModuleInfo0, !Info),
+	module_info_preds(ModuleInfo0, PredTable0),
+	map__lookup(PredTable0, PredId, PredInfo0),
+	module_info_type_spec_info(ModuleInfo0, TypeSpecInfo),
+	TypeSpecInfo = type_spec_info(_, TypeSpecForcePreds, _, _),
+	pred_info_clauses_info(PredInfo0, ClausesInfo0),
 	(
 		%
 		% XXX hlds_out__write_clause needs to be changed to
 		% output explicit type qualifications to avoid type
 		% ambiguity errors in clauses written to `.opt' files.
 		%
-		{ clauses_info_explicit_vartypes(ClausesInfo0,
-			ExplicitVarTypes) },
-		{ map__is_empty(ExplicitVarTypes) },
-
-		{ intermod__should_be_processed(ProcessLocalPreds, PredId,
+		clauses_info_explicit_vartypes(ClausesInfo0, ExplicitVarTypes),
+		map__is_empty(ExplicitVarTypes),
+		intermod__should_be_processed(ProcessLocalPreds, PredId,
 			PredInfo0, TypeSpecForcePreds, InlineThreshold,
-			HigherOrderSizeLimit, Deforestation, ModuleInfo0) }
+			HigherOrderSizeLimit, Deforestation, ModuleInfo0)
 	->
-		=(IntermodInfo0),
+		SavedInfo = !.Info,
 		% Write a declaration to the `.opt' file for
 		% `exported_to_submodules' predicates.
-		intermod__add_proc(PredId, DoWrite0),
-		{ clauses_info_clauses(ClausesInfo0, Clauses0) },
-		( { DoWrite0 = yes } ->
-			{ clauses_info_vartypes(ClausesInfo0, VarTypes) },
-			{ pred_info_typevarset(PredInfo0, TVarSet) },
-			intermod_info_set_var_types(VarTypes),
-			intermod_info_set_tvarset(TVarSet),
-			intermod__traverse_clauses(Clauses0, Clauses, DoWrite)
-		;
-			{ Clauses = Clauses0 },
-			{ DoWrite = no }
-		),
-		( { DoWrite = yes } ->
-			{ clauses_info_set_clauses(Clauses,
-				ClausesInfo0, ClausesInfo) },
-			{ pred_info_set_clauses_info(ClausesInfo,
-				PredInfo0, PredInfo) },	
-			{ map__det_update(PredTable0, PredId,
-					PredInfo, PredTable) },
-			{ module_info_set_preds(PredTable,
-				ModuleInfo0, ModuleInfo) },
-			intermod_info_get_preds(Preds0),
-			( { pred_info_pragma_goal_type(PredInfo) } ->
+		intermod__add_proc(PredId, DoWrite0, !Info),
+		clauses_info_clauses(ClausesInfo0, Clauses0),
+		(
+			DoWrite0 = yes,
+			clauses_info_vartypes(ClausesInfo0, VarTypes),
+			pred_info_typevarset(PredInfo0, TVarSet),
+			intermod_info_set_var_types(VarTypes, !Info),
+			intermod_info_set_tvarset(TVarSet, !Info),
+			intermod__traverse_clauses(Clauses0, Clauses, DoWrite,
+				!Info)
+		;
+			DoWrite0 = no,
+			Clauses = Clauses0,
+			DoWrite = no
+		),
+		(
+			DoWrite = yes,
+			clauses_info_set_clauses(Clauses,
+				ClausesInfo0, ClausesInfo),
+			pred_info_set_clauses_info(ClausesInfo,
+				PredInfo0, PredInfo),
+			map__det_update(PredTable0, PredId,
+				PredInfo, PredTable),
+			module_info_set_preds(PredTable,
+				ModuleInfo0, ModuleInfo),
+			intermod_info_get_preds(Preds0, !Info),
+			( pred_info_pragma_goal_type(PredInfo) ->
 				% The header code must be written since
 				% it could be used by the pragma_foreign_code.
-				intermod_info_set_write_header
+				intermod_info_set_write_header(!Info)
 			;
-				[]
+				true
 			),
-			{ set__insert(Preds0, PredId, Preds) },
-			intermod_info_set_preds(Preds),
-			intermod_info_set_module_info(ModuleInfo)
+			set__insert(Preds0, PredId, Preds),
+			intermod_info_set_preds(Preds, !Info),
+			intermod_info_set_module_info(ModuleInfo, !Info)
 		;
+			DoWrite = no,
 			% Remove any items added for the clauses
 			% for this predicate.
-			:=(IntermodInfo0)
+			!:Info = SavedInfo
 		)
 	;
-		[]
+		true
 	),
 	intermod__gather_pred_list(PredIds, ProcessLocalPreds, CollectTypes,
-		InlineThreshold, HigherOrderSizeLimit, Deforestation).
-
+		InlineThreshold, HigherOrderSizeLimit, Deforestation, !Info).
 
 :- pred intermod__should_be_processed(bool::in, pred_id::in, pred_info::in,
 		set(pred_id)::in, int::in, int::in, bool::in,
@@ -424,19 +390,20 @@
 clauses_contain_noninlinable_foreign_code(Target, [_ | Cs]) :-
 	clauses_contain_noninlinable_foreign_code(Target, Cs).
 
-
 :- pred intermod__traverse_clauses(list(clause)::in, list(clause)::out,
 		bool::out, intermod_info::in, intermod_info::out) is det.
 
-intermod__traverse_clauses([], [], yes) --> [].
+intermod__traverse_clauses([], [], yes, !Info).
 intermod__traverse_clauses([clause(P, Goal0, L, C) | Clauses0],
-			[clause(P, Goal, L, C) | Clauses], DoWrite) -->
-	intermod__traverse_goal(Goal0, Goal, DoWrite1),
-	( { DoWrite1 = yes } ->
-		intermod__traverse_clauses(Clauses0, Clauses, DoWrite)
+		[clause(P, Goal, L, C) | Clauses], DoWrite, !Info) :-
+	intermod__traverse_goal(Goal0, Goal, DoWrite1, !Info),
+	(
+		DoWrite1 = yes,
+		intermod__traverse_clauses(Clauses0, Clauses, DoWrite, !Info)
 	;
-		{ Clauses = Clauses0 },
-		{ DoWrite = no }
+		DoWrite1 = no,
+		Clauses = Clauses0,
+		DoWrite = no
 	).
 
 :- pred has_ho_input(module_info::in, proc_info::in) is semidet.
@@ -485,8 +452,8 @@
 goal_contains_one_branched_goal(GoalList) :-
 	goal_contains_one_branched_goal(GoalList, no).
 
-:- pred goal_contains_one_branched_goal(list(hlds_goal)::in,
-		bool::in) is semidet.
+:- pred goal_contains_one_branched_goal(list(hlds_goal)::in, bool::in)
+	is semidet.
 
 goal_contains_one_branched_goal([], yes).
 goal_contains_one_branched_goal([Goal | Goals], FoundBranch0) :-
@@ -506,91 +473,85 @@
 :- pred intermod__traverse_goal(hlds_goal::in, hlds_goal::out, bool::out,
 			intermod_info::in, intermod_info::out) is det.
 
-intermod__traverse_goal(conj(Goals0) - Info, conj(Goals) - Info, DoWrite) -->
-	intermod__traverse_list_of_goals(Goals0, Goals, DoWrite).
-
+intermod__traverse_goal(conj(Goals0) - Info, conj(Goals) - Info, DoWrite,
+		!Info) :-
+	intermod__traverse_list_of_goals(Goals0, Goals, DoWrite, !Info).
 intermod__traverse_goal(par_conj(Goals0) - Info, par_conj(Goals) - Info,
-		DoWrite) -->
-	intermod__traverse_list_of_goals(Goals0, Goals, DoWrite).
-
-intermod__traverse_goal(disj(Goals0) - Info, disj(Goals) - Info, DoWrite) -->
-	intermod__traverse_list_of_goals(Goals0, Goals, DoWrite).
-
-intermod__traverse_goal(Goal, Goal, DoWrite) -->
-	{ Goal = call(PredId, _, _, _, _, _) - _ },
-
+		DoWrite, !Info) :-
+	intermod__traverse_list_of_goals(Goals0, Goals, DoWrite, !Info).
+intermod__traverse_goal(disj(Goals0) - Info, disj(Goals) - Info, DoWrite,
+		!Info) :-
+	intermod__traverse_list_of_goals(Goals0, Goals, DoWrite, !Info).
+intermod__traverse_goal(Goal, Goal, DoWrite, !Info) :-
+	Goal = call(PredId, _, _, _, _, _) - _,
 	%
 	% Ensure that the called predicate will be exported.
 	%
-	intermod__add_proc(PredId, DoWrite).
-
-intermod__traverse_goal(generic_call(CallType, B,C,D) - Info,
-			generic_call(CallType, B,C,D) - Info, DoWrite) -->
-	{ CallType = higher_order(_, _, _, _), DoWrite = yes
+	intermod__add_proc(PredId, DoWrite, !Info).
+intermod__traverse_goal(Goal @ generic_call(CallType, _, _, _) - Info,
+		Goal - Info, DoWrite, !Info) :-
+	( CallType = higher_order(_, _, _, _), DoWrite = yes
 	; CallType = class_method(_, _, _, _), DoWrite = no
 	; CallType = unsafe_cast, DoWrite = no
 	; CallType = aditi_builtin(_, _), DoWrite = yes
-	}.
-
-intermod__traverse_goal(switch(A, B, Cases0) - Info,
-		switch(A, B, Cases) - Info, DoWrite) -->
-	intermod__traverse_cases(Cases0, Cases, DoWrite).
-
+	).
+intermod__traverse_goal(switch(Var, CanFail, Cases0) - Info,
+		switch(Var, CanFail, Cases) - Info, DoWrite, !Info) :-
+	intermod__traverse_cases(Cases0, Cases, DoWrite, !Info).
 	% Export declarations for preds used in higher order pred constants
 	% or function calls.
 intermod__traverse_goal(unify(LVar, RHS0, C, D, E) - Info,
-			unify(LVar, RHS, C, D, E) - Info, DoWrite) -->
-	intermod__module_qualify_unify_rhs(LVar, RHS0, RHS, DoWrite).
-
-intermod__traverse_goal(not(Goal0) - Info, not(Goal) - Info, DoWrite) -->
-	intermod__traverse_goal(Goal0, Goal, DoWrite).
-
+		unify(LVar, RHS, C, D, E) - Info, DoWrite, !Info) :-
+	intermod__module_qualify_unify_rhs(LVar, RHS0, RHS, DoWrite, !Info).
+intermod__traverse_goal(not(Goal0) - Info, not(Goal) - Info, DoWrite, !Info) :-
+	intermod__traverse_goal(Goal0, Goal, DoWrite, !Info).
 intermod__traverse_goal(some(Vars, CanRemove, Goal0) - Info,
-		some(Vars, CanRemove, Goal) - Info, DoWrite) -->
-	intermod__traverse_goal(Goal0, Goal, DoWrite).
-
+		some(Vars, CanRemove, Goal) - Info, DoWrite, !Info) :-
+	intermod__traverse_goal(Goal0, Goal, DoWrite, !Info).
 intermod__traverse_goal(if_then_else(Vars, Cond0, Then0, Else0) - Info,
-		if_then_else(Vars, Cond, Then, Else) - Info, DoWrite) -->
-	intermod__traverse_goal(Cond0, Cond, DoWrite1),
-	intermod__traverse_goal(Then0, Then, DoWrite2),
-	intermod__traverse_goal(Else0, Else, DoWrite3),
-	{ bool__and_list([DoWrite1, DoWrite2, DoWrite3], DoWrite) }.
-
+		if_then_else(Vars, Cond, Then, Else) - Info, DoWrite, !Info) :-
+	intermod__traverse_goal(Cond0, Cond, DoWrite1, !Info),
+	intermod__traverse_goal(Then0, Then, DoWrite2, !Info),
+	intermod__traverse_goal(Else0, Else, DoWrite3, !Info),
+	bool__and_list([DoWrite1, DoWrite2, DoWrite3], DoWrite).
 	% Inlineable exported pragma_foreign_code goals can't use any
 	% non-exported types, so we just write out the clauses. 
-intermod__traverse_goal(foreign_proc(A,B,C,D,E,F,G) - Info,
-		foreign_proc(A,B,C,D,E,F,G) - Info, yes) --> [].
-
-intermod__traverse_goal(shorthand(_) - _, _, _) -->
+intermod__traverse_goal(Goal @ foreign_proc(_, _, _, _, _, _) - Info,
+		Goal - Info, yes, !Info).
+intermod__traverse_goal(shorthand(_) - _, _, _, !Info) :-
 	% these should have been expanded out by now
-	{ error("intermod__traverse_goal: unexpected shorthand") }.
-
+	error("intermod__traverse_goal: unexpected shorthand").
 
 :- pred intermod__traverse_list_of_goals(hlds_goals::in, hlds_goals::out,
 		bool::out, intermod_info::in, intermod_info::out) is det.
 
-intermod__traverse_list_of_goals([], [], yes) --> [].
-intermod__traverse_list_of_goals([Goal0 | Goals0], [Goal | Goals], DoWrite) -->
-	intermod__traverse_goal(Goal0, Goal, DoWrite1),
-	( { DoWrite1 = yes } ->
-		intermod__traverse_list_of_goals(Goals0, Goals, DoWrite)
+intermod__traverse_list_of_goals([], [], yes, !Info).
+intermod__traverse_list_of_goals([Goal0 | Goals0], [Goal | Goals], DoWrite,
+		!Info) :-
+	intermod__traverse_goal(Goal0, Goal, DoWrite1, !Info),
+	(
+		DoWrite1 = yes,
+		intermod__traverse_list_of_goals(Goals0, Goals, DoWrite, !Info)
 	;
-		{ DoWrite = no },
-		{ Goals = Goals0 }
+		DoWrite1 = no,
+		DoWrite = no,
+		Goals = Goals0
 	).
 
 :- pred intermod__traverse_cases(list(case)::in, list(case)::out, bool::out,
 			intermod_info::in, intermod_info::out) is det.
 
-intermod__traverse_cases([], [], yes) --> [].
+intermod__traverse_cases([], [], yes, !Info).
 intermod__traverse_cases([case(F, Goal0) | Cases0],
-		[case(F, Goal) | Cases], DoWrite) -->
-	intermod__traverse_goal(Goal0, Goal, DoWrite1),
-	( { DoWrite1 = yes } ->
-		intermod__traverse_cases(Cases0, Cases, DoWrite)
+		[case(F, Goal) | Cases], DoWrite, !Info) :-
+	intermod__traverse_goal(Goal0, Goal, DoWrite1, !Info),
+	(
+		DoWrite1 = yes,
+		intermod__traverse_cases(Cases0, Cases, DoWrite, !Info)
 	;
-		{ DoWrite = no },
-		{ Cases = Cases0 }
+		DoWrite1 = no,
+		DoWrite = no,
+		Cases = Cases0
 	).
 
 	%
@@ -609,25 +570,25 @@
 :- pred intermod__add_proc(pred_id::in, bool::out,
 		intermod_info::in, intermod_info::out) is det.
 
-intermod__add_proc(PredId, DoWrite) -->
-	( { PredId = invalid_pred_id } ->
+intermod__add_proc(PredId, DoWrite, !Info) :-
+	( PredId = invalid_pred_id ->
 		% This will happen for type class instance methods
 		% defined using the clause syntax.  Currently we
 		% can't handle intermodule-optimization of those.
-		{ DoWrite = no }
+		DoWrite = no
 	;
-		intermod__add_proc_2(PredId, DoWrite)
+		intermod__add_proc_2(PredId, DoWrite, !Info)
 	).
 
 :- pred intermod__add_proc_2(pred_id::in, bool::out,
 		intermod_info::in, intermod_info::out) is det.
 
-intermod__add_proc_2(PredId, DoWrite) -->
-	intermod_info_get_module_info(ModuleInfo),
-	{ module_info_pred_info(ModuleInfo, PredId, PredInfo) },
-	{ pred_info_import_status(PredInfo, Status) },
-	{ ProcIds = pred_info_procids(PredInfo) },
-	{ pred_info_get_markers(PredInfo, Markers) },
+intermod__add_proc_2(PredId, DoWrite, !Info) :-
+	intermod_info_get_module_info(ModuleInfo, !Info),
+	module_info_pred_info(ModuleInfo, PredId, PredInfo),
+	pred_info_import_status(PredInfo, Status),
+	ProcIds = pred_info_procids(PredInfo),
+	pred_info_get_markers(PredInfo, Markers),
 	(
 		%
 		% Calling compiler-generated procedures is fine;
@@ -635,9 +596,9 @@
 		% the `.opt' file, since they will be recreated every
 		% time anyway.
 		%
-		{ is_unify_or_compare_pred(PredInfo) }
+		is_unify_or_compare_pred(PredInfo)
 	->
-		{ DoWrite = yes }
+		DoWrite = yes
 	;
 		%
 		% Don't write the caller to the `.opt' file if it calls
@@ -650,16 +611,16 @@
 		% XXX This prevents intermodule optimizations in such cases,
 		% which is a pity.
 		%
-		{
+		(
 			check_marker(Markers, infer_modes)
 		;
 			pred_info_procedures(PredInfo, Procs),
 			list__member(ProcId, ProcIds),
 			map__lookup(Procs, ProcId, ProcInfo),
 			proc_info_declared_determinism(ProcInfo, no)
-		}
+		)
 	->
-		{ DoWrite = no }
+		DoWrite = no
 	;
 		% Goals which call impure predicates cannot be written
 		% due to limitations in mode analysis. The problem is that
@@ -681,21 +642,21 @@
 		% would be tricky.
 		%
 		% See tests/valid/impure_intermod.m.
-		{ pred_info_get_purity(PredInfo, impure) }
+		pred_info_get_purity(PredInfo, impure)
 	->	
-		{ DoWrite = no }
+		DoWrite = no
 	;
 		%
 		% If a pred whose code we're going to put in the .opt file
 		% calls a predicate which is exported, then we don't
 		% need to do anything special.
 		%
-		{ Status = exported
+		( Status = exported
 		; Status = external(ExternalStatus),
 			status_is_exported(ExternalStatus, yes)
-		}
+		)
 	->
-		{ DoWrite = yes }
+		DoWrite = yes
 	;
 		%
 		% Declarations for class methods will be recreated
@@ -703,10 +664,10 @@
 		% Declarations for local classes are always written
 		% to the `.opt' file.
 		%
-		{ pred_info_get_markers(PredInfo, Markers) },
-		{ check_marker(Markers, class_method) }
+		pred_info_get_markers(PredInfo, Markers),
+		check_marker(Markers, class_method)
 	->
-		{ DoWrite = yes }
+		DoWrite = yes
 	;
 		%
 		% If a pred whose code we're going to put in the `.opt' file
@@ -714,27 +675,27 @@
 		% we need to put the declaration for the called predicate
 		% in the `.opt' file.
 		%
-		{ import_status_to_write(Status) }
+		import_status_to_write(Status)
 	->
-		{ DoWrite = yes },
-		intermod_info_get_pred_decls(PredDecls0),
-		{ set__insert(PredDecls0, PredId, PredDecls) },
-		intermod_info_set_pred_decls(PredDecls)
+		DoWrite = yes,
+		intermod_info_get_pred_decls(PredDecls0, !Info),
+		set__insert(PredDecls0, PredId, PredDecls),
+		intermod_info_set_pred_decls(PredDecls, !Info)
 	;
-		{ Status = imported(_)
+		( Status = imported(_)
 		; Status = opt_imported
-		}
+		)
 	->
 		%
 		% imported pred - add import for module
 		%
-		{ DoWrite = yes },
-		{ PredModule = pred_info_module(PredInfo) },
-		intermod_info_get_modules(Modules0),
-		{ set__insert(Modules0, PredModule, Modules) },
-		intermod_info_set_modules(Modules)
+		DoWrite = yes,
+		PredModule = pred_info_module(PredInfo),
+		intermod_info_get_modules(Modules0, !Info),
+		set__insert(Modules0, PredModule, Modules),
+		intermod_info_set_modules(Modules, !Info)
 	;
-		{ error("intermod__add_proc: unexpected status") }
+		error("intermod__add_proc: unexpected status")
 	).
 
 	% Resolve overloading and module qualify everything in a unify_rhs.
@@ -742,30 +703,24 @@
 		unify_rhs::out, bool::out, intermod_info::in,
 		intermod_info::out) is det.
 
-intermod__module_qualify_unify_rhs(_, var(Var), var(Var), yes) --> [].
-
-intermod__module_qualify_unify_rhs(_LVar,
-		lambda_goal(A,B,EvalMethod,C,D,E,Modes,G,Goal0),
-		lambda_goal(A,B,EvalMethod,C,D,E,Modes,G,Goal), DoWrite) -->
-	intermod__traverse_goal(Goal0, Goal, DoWrite).
-
 	% Fully module-qualify the right-hand-side of a unification.
 	% For function calls and higher-order terms, call intermod__add_proc
 	% so that the predicate or function will be exported if necessary.
-intermod__module_qualify_unify_rhs(_LVar, functor(Functor, E, Vars),
-				functor(Functor, E, Vars), DoWrite) -->
-	(
-		%
+intermod__module_qualify_unify_rhs(_LHS, RHS @ var(_Var), RHS, yes, !Info).
+intermod__module_qualify_unify_rhs(_LHS,
+		lambda_goal(A,B,C,D,E,F,G,H,Goal0),
+		lambda_goal(A,B,C,D,E,F,G,H,Goal), DoWrite, !Info) :-
+	intermod__traverse_goal(Goal0, Goal, DoWrite, !Info).
+intermod__module_qualify_unify_rhs(_LHS, RHS @ functor(Functor, _Exist, _Vars),
+		RHS, DoWrite, !Info) :-
 		% Is this a higher-order predicate or higher-order function
 		% term?
-		%
-		{ Functor = pred_const(PredId, _, _) }
-	->
+	( Functor = pred_const(PredId, _, _) ->
 		%
 		% Yes, the unification creates a higher-order term.
 		% Make sure that the predicate/function is exported.
 		%
-		intermod__add_proc(PredId, DoWrite)
+		intermod__add_proc(PredId, DoWrite, !Info)
 	;
 		%
 		% It's an ordinary constructor, or a constant of a builtin
@@ -777,45 +732,45 @@
 		% are transformed into ordinary calls and higher-order calls
 		% by post_typecheck.m, so they can't occur here.
 		%
-		{ DoWrite = yes }
+		DoWrite = yes
 	).
 
 %-----------------------------------------------------------------------------%
 
-:- pred intermod__gather_instances(intermod_info::in,
-		intermod_info::out) is det.
+:- pred intermod__gather_instances(intermod_info::in, intermod_info::out)
+	is det.
 
-intermod__gather_instances -->
-	intermod_info_get_module_info(ModuleInfo),
-	{ module_info_instances(ModuleInfo, Instances) },
-	map__foldl(intermod__gather_instances_2(ModuleInfo), Instances).
+intermod__gather_instances(!Info) :-
+	intermod_info_get_module_info(ModuleInfo, !Info),
+	module_info_instances(ModuleInfo, Instances),
+	map__foldl(intermod__gather_instances_2(ModuleInfo), Instances, !Info).
 
 :- pred intermod__gather_instances_2(module_info::in, class_id::in,
 		list(hlds_instance_defn)::in,
 		intermod_info::in, intermod_info::out) is det.
 
-intermod__gather_instances_2(ModuleInfo, ClassId, InstanceDefns) -->
+intermod__gather_instances_2(ModuleInfo, ClassId, InstanceDefns, !Info) :-
 	list__foldl(intermod__gather_instances_3(ModuleInfo, ClassId),
-		InstanceDefns).
+		InstanceDefns, !Info).
 
 :- pred intermod__gather_instances_3(module_info::in, class_id::in,
 	hlds_instance_defn::in, intermod_info::in, intermod_info::out) is det.
 		
-intermod__gather_instances_3(ModuleInfo, ClassId, InstanceDefn) -->
-	{ InstanceDefn = hlds_instance_defn(A, Status, C, D, E, Interface0,
-				MaybePredProcIds, H, I) },
+intermod__gather_instances_3(ModuleInfo, ClassId, InstanceDefn, !Info) :-
+	InstanceDefn = hlds_instance_defn(A, Status, C, D, E, Interface0,
+		MaybePredProcIds, H, I),
 	(
 		%
 		% The bodies are always stripped from instance declarations
 		% before writing them to `int' files, so the full instance
 		% declaration should be written even for exported instances.
 		%
-		{ status_defined_in_this_module(Status, yes) }
+		status_defined_in_this_module(Status, yes)
 	->
-		=(IntermodInfo0),
+		SaveInfo = !.Info,
 		(
-			{ Interface0 = concrete(Methods0) },
-			{ MaybePredProcIds = yes(ClassProcs) ->
+			Interface0 = concrete(Methods0),
+			( MaybePredProcIds = yes(ClassProcs) ->
 				GetPredId =
 				    (pred(Proc::in, PredId::out) is det :-
 					Proc = hlds_class_proc(PredId, _)
@@ -828,60 +783,60 @@
 				assoc_list__from_corresponding_lists(
 					ClassPreds, Methods0, MethodAL)
 			;
-				error(
-	"intermod__gather_instances_3: method pred_proc_ids not filled in")
-			},
-			{ list__map_foldl(
+				error("intermod__gather_instances_3: " ++
+					"method pred_proc_ids not filled in")
+			),
+			list__map_foldl(
 				intermod__qualify_instance_method(ModuleInfo),
-				MethodAL, Methods, [], PredIds) },
+				MethodAL, Methods, [], PredIds),
 			list__map_foldl(intermod__add_proc, PredIds, 
-				DoWriteMethodsList),
-			{ bool__and_list(DoWriteMethodsList, DoWriteMethods) },
+				DoWriteMethodsList, !Info),
+			bool__and_list(DoWriteMethodsList, DoWriteMethods),
 			(
-				{ DoWriteMethods = yes },
-				{ Interface = concrete(Methods) }
+				DoWriteMethods = yes,
+				Interface = concrete(Methods)
 			;
-				{ DoWriteMethods = no },
+				DoWriteMethods = no,
 
 				%
 				% Write an abstract instance declaration
 				% if any of the methods cannot be written
 				% to the `.opt' file for any reason.
 				%
-				{ Interface = abstract },
+				Interface = abstract,
 
 				%
 				% Don't write declarations for any of the
 				% methods if one can't be written.
 				%
-				:=(IntermodInfo0)
+				!:Info = SaveInfo
 			)
 		;
-			{ Interface0 = abstract },
-			{ Interface = Interface0 }
+			Interface0 = abstract,
+			Interface = Interface0
 		),
 		(
 			%
 			% Don't write an abstract instance declaration
 			% if the declaration is already in the `.int' file.
 			%
-			{
+			(
 				Interface = abstract
 			=>
 				status_is_exported(Status, no)
-			}
+			)
 		->
-			{ InstanceDefnToWrite = hlds_instance_defn(A, Status,
-					C, D, E, Interface, MaybePredProcIds,
-					H, I) },
-			intermod_info_get_instances(Instances0),
+			InstanceDefnToWrite = hlds_instance_defn(A, Status,
+				C, D, E, Interface, MaybePredProcIds, H, I),
+			intermod_info_get_instances(Instances0, !Info),
 			intermod_info_set_instances(
-				[ClassId - InstanceDefnToWrite | Instances0])
+				[ClassId - InstanceDefnToWrite | Instances0],
+				!Info)
 		;
-			[]
+			true
 		)
 	;
-		[]
+		true
 	).
 
 	% Resolve overloading of instance methods before writing them
@@ -957,8 +912,8 @@
 	% the instance method.
 	%
 :- pred find_func_matching_instance_method(module_info::in, sym_name::in, 
-		arity::in, tvarset::in, list(type)::in,
-		maybe(pred_id)::out, sym_name::out) is semidet.
+	arity::in, tvarset::in, list(type)::in, maybe(pred_id)::out,
+	sym_name::out) is semidet.
 
 find_func_matching_instance_method(ModuleInfo, InstanceMethodName0,
 		MethodArity, MethodCallTVarSet, MethodCallArgTypes,
@@ -1012,8 +967,8 @@
 			InstanceMethodName =
 				qualified(TypeModule, UnqualMethodName)
 		;	
-			error(
-	"unqualified type_ctor in hlds_cons_defn or hlds_ctor_field_defn")
+			error("unqualified type_ctor in " ++
+				"hlds_cons_defn or hlds_ctor_field_defn")
 		)
 	).
 
@@ -1021,10 +976,10 @@
 
 :- pred intermod__gather_types(intermod_info::in, intermod_info::out) is det.
 
-intermod__gather_types -->
-	intermod_info_get_module_info(ModuleInfo),
-	{ module_info_types(ModuleInfo, Types) },
-	map__foldl(intermod__gather_types_2, Types).
+intermod__gather_types(!Info) :-
+	intermod_info_get_module_info(ModuleInfo, !Info),
+	module_info_types(ModuleInfo, Types),
+	map__foldl(intermod__gather_types_2, Types, !Info).
 
 :- pred intermod__gather_types_2(type_ctor::in, hlds_type_defn::in,
 	intermod_info::in, intermod_info::out) is det.
@@ -1105,9 +1060,9 @@
 
 intermod__resolve_foreign_type_body_overloading(ModuleInfo,
 		TypeCtor, foreign_type_body(MaybeIL0, MaybeC0, MaybeJava0),
-		foreign_type_body(MaybeIL, MaybeC, MaybeJava)) -->
-	{ module_info_globals(ModuleInfo, Globals) },
-	{ globals__get_target(Globals, Target) },
+		foreign_type_body(MaybeIL, MaybeC, MaybeJava), !Info) :-
+	module_info_globals(ModuleInfo, Globals),
+	globals__get_target(Globals, Target),
 
 	%
 	% Note that we don't resolve overloading for the foreign
@@ -1119,23 +1074,23 @@
 	% be present (e.g. when testing compiling a module to IL when
 	% the workspace was compiled to C).
 	%
-	( { Target = c ; Target = asm } ->
+	( ( Target = c ; Target = asm ) ->
 		intermod__resolve_foreign_type_body_overloading_2(ModuleInfo,
-			TypeCtor, MaybeC0, MaybeC)
+			TypeCtor, MaybeC0, MaybeC, !Info)
 	;
-		{ MaybeC = MaybeC0 }
+		MaybeC = MaybeC0
 	),
-	( { Target = il } ->
+	( Target = il ->
 		intermod__resolve_foreign_type_body_overloading_2(ModuleInfo,
-			TypeCtor, MaybeIL0, MaybeIL)
+			TypeCtor, MaybeIL0, MaybeIL, !Info)
 	;
-		{ MaybeIL = MaybeIL0 }
+		MaybeIL = MaybeIL0
 	),
-	( { Target = java } ->
+	( Target = java ->
 		intermod__resolve_foreign_type_body_overloading_2(ModuleInfo,
-			TypeCtor, MaybeJava0, MaybeJava)
+			TypeCtor, MaybeJava0, MaybeJava, !Info)
 	;
-		{ MaybeJava = MaybeJava0 }
+		MaybeJava = MaybeJava0
 	).
 
 :- pred intermod__resolve_foreign_type_body_overloading_2(module_info::in,
@@ -1155,27 +1110,27 @@
 	type_ctor::in, maybe(unify_compare)::in, maybe(unify_compare)::out,
 	intermod_info::in, intermod_info::out) is det.
 
-intermod__resolve_unify_compare_overloading(_, _, no, no, Info, Info).
+intermod__resolve_unify_compare_overloading(_, _, no, no, !Info).
 intermod__resolve_unify_compare_overloading(_, _,
-	yes(abstract_noncanonical_type), yes(abstract_noncanonical_type),
-	Info, Info).
+		yes(abstract_noncanonical_type),
+		yes(abstract_noncanonical_type),
+		!Info).
 intermod__resolve_unify_compare_overloading(ModuleInfo, TypeCtor,
 		yes(unify_compare(MaybeUserEq0, MaybeUserCompare0)),
 		yes(unify_compare(MaybeUserEq, MaybeUserCompare)),
-		Info0, Info) :-
+		!Info) :-
 	intermod__resolve_user_special_pred_overloading(ModuleInfo,
-		unify, TypeCtor, MaybeUserEq0, MaybeUserEq, Info0, Info1),
+		unify, TypeCtor, MaybeUserEq0, MaybeUserEq, !Info),
 	intermod__resolve_user_special_pred_overloading(ModuleInfo,
-		compare, TypeCtor, MaybeUserCompare0, MaybeUserCompare,
-		Info1, Info).
+		compare, TypeCtor, MaybeUserCompare0, MaybeUserCompare, !Info).
 
 :- pred intermod__resolve_user_special_pred_overloading(module_info::in,
 	special_pred_id::in, type_ctor::in, maybe(sym_name)::in,
 	maybe(sym_name)::out, intermod_info::in, intermod_info::out) is det.
 
-intermod__resolve_user_special_pred_overloading(_, _, _, no, no, Info, Info).
+intermod__resolve_user_special_pred_overloading(_, _, _, no, no, !Info).
 intermod__resolve_user_special_pred_overloading(ModuleInfo, SpecialId,
-		TypeCtor, yes(Pred0), yes(Pred), Info0, Info) :-
+		TypeCtor, yes(Pred0), yes(Pred), !Info) :-
 	module_info_get_special_pred_map(ModuleInfo, SpecialPreds),
 	map__lookup(SpecialPreds, SpecialId - TypeCtor, UnifyPredId),
 	module_info_pred_info(ModuleInfo, UnifyPredId, UnifyPredInfo),
@@ -1184,7 +1139,7 @@
 	add_marker(calls_are_fully_qualified, Markers0, Markers),
 	typecheck__resolve_pred_overloading(ModuleInfo, Markers, ArgTypes,
 		TVarSet, Pred0, Pred, UserEqPredId),
-	intermod__add_proc(UserEqPredId, _, Info0, Info).
+	intermod__add_proc(UserEqPredId, _, !Info).
 
 :- pred intermod__should_write_type(module_name::in,
 		type_ctor::in, hlds_type_defn::in) is semidet.
@@ -1196,326 +1151,324 @@
 	import_status_to_write(ImportStatus).
 
 %-----------------------------------------------------------------------------%
+
 	% Output module imports, types, modes, insts and predicates
 
 :- pred intermod__write_intermod_info(intermod_info::in,
-	io__state::di, io__state::uo) is det.
+	io::di, io::uo) is det.
 
-intermod__write_intermod_info(IntermodInfo0) -->
-	{ intermod_info_get_module_info(ModuleInfo,
-		IntermodInfo0, IntermodInfo1) },
-	{ module_info_name(ModuleInfo, ModuleName) },
-	io__write_string(":- module "),
-	mercury_output_bracketed_sym_name(ModuleName),
-	io__write_string(".\n"),
-
-	{ intermod_info_get_preds(Preds, IntermodInfo1, IntermodInfo2) },
-	{ intermod_info_get_pred_decls(PredDecls,
-		IntermodInfo2, IntermodInfo3) },
-	{ intermod_info_get_instances(Instances,
-		IntermodInfo3, IntermodInfo) },
+intermod__write_intermod_info(IntermodInfo0, !IO) :-
+	intermod_info_get_module_info(ModuleInfo,
+		IntermodInfo0, IntermodInfo1),
+	module_info_name(ModuleInfo, ModuleName),
+	io__write_string(":- module ", !IO),
+	mercury_output_bracketed_sym_name(ModuleName, !IO),
+	io__write_string(".\n", !IO),
+
+	intermod_info_get_preds(Preds, IntermodInfo1, IntermodInfo2),
+	intermod_info_get_pred_decls(PredDecls,
+		IntermodInfo2, IntermodInfo3),
+	intermod_info_get_instances(Instances,
+		IntermodInfo3, IntermodInfo),
 	(
 		%
 		% If none of these item types need writing, nothing
 		% else needs to be written.
 		%
-		{ set__empty(Preds) },
-		{ set__empty(PredDecls) },
-		{ Instances = [] },
-		{ module_info_types(ModuleInfo, Types) },
-		\+ {
+		set__empty(Preds),
+		set__empty(PredDecls),
+		Instances = [],
+		module_info_types(ModuleInfo, Types),
+		\+ (
 			map__member(Types, _, TypeDefn),
 			hlds_data__get_type_defn_status(TypeDefn, Status),
 			( Status = abstract_exported
 			; Status = exported_to_submodules
 			)
-		}
+		)
 	->
-		[]	
+		true
 	;
-		intermod__write_intermod_info_2(IntermodInfo)	
+		intermod__write_intermod_info_2(IntermodInfo, !IO)
 	).
 
 :- pred intermod__write_intermod_info_2(intermod_info::in,
-	io__state::di, io__state::uo) is det.
-
-intermod__write_intermod_info_2(IntermodInfo) -->
-	{ IntermodInfo = info(_, Preds0, PredDecls0, Instances, Types, _,
-				ModuleInfo, WriteHeader, _, _) },
-	{ set__to_sorted_list(Preds0, Preds) }, 
-	{ set__to_sorted_list(PredDecls0, PredDecls) },
+	io::di, io::uo) is det.
 
+intermod__write_intermod_info_2(IntermodInfo, !IO) :-
+	IntermodInfo = info(_, Preds0, PredDecls0, Instances, Types,
+		ModuleInfo, WriteHeader, _, _),
+	set__to_sorted_list(Preds0, Preds),
+	set__to_sorted_list(PredDecls0, PredDecls),
 
-	{ module_info_get_imported_module_specifiers(ModuleInfo, Modules0) },
-	{ set__to_sorted_list(Modules0, Modules) },
-	( { Modules \= [] } ->
+	module_info_get_imported_module_specifiers(ModuleInfo, Modules0),
+	set__to_sorted_list(Modules0, Modules),
+	(
+		Modules = [_ | _],
 		% XXX this could be reduced to the set that is
 		% actually needed by the items being written.
-		io__write_string(":- use_module "),
-		intermod__write_modules(Modules)
+		io__write_string(":- use_module ", !IO),
+		intermod__write_modules(Modules, !IO)
 	;
-		[]
+		Modules = []
 	),
 
-	intermod__write_types(Types),
-	intermod__write_insts(ModuleInfo),
-	intermod__write_modes(ModuleInfo),
-	intermod__write_classes(ModuleInfo),
-	intermod__write_instances(Instances),
+	intermod__write_types(Types, !IO),
+	intermod__write_insts(ModuleInfo, !IO),
+	intermod__write_modes(ModuleInfo, !IO),
+	intermod__write_classes(ModuleInfo, !IO),
+	intermod__write_instances(Instances, !IO),
 
 	% Disable verbose dumping of clauses.
-	globals__io_lookup_string_option(dump_hlds_options, VerboseDump),
-	globals__io_set_option(dump_hlds_options, string("")),
-	( { WriteHeader = yes } ->
-		{ module_info_get_foreign_import_module(ModuleInfo,
-			RevForeignImports) },
-		{ ForeignImports = list__reverse(RevForeignImports) },
+	globals__io_lookup_string_option(dump_hlds_options, VerboseDump, !IO),
+	globals__io_set_option(dump_hlds_options, string(""), !IO),
+	(
+		WriteHeader = yes,
+		module_info_get_foreign_import_module(ModuleInfo,
+			RevForeignImports),
+		ForeignImports = list__reverse(RevForeignImports),
 
 		list__foldl(
-		    (pred(ForeignImport::in, di, uo) is det -->
-		    	{ ForeignImport = foreign_import_module(Lang,
-						Import, _) },
-		    	mercury_output_pragma_foreign_import_module(Lang,
-				Import)
-		    ), ForeignImports)
-	;
-		[]
-	),
-	intermod__write_pred_decls(ModuleInfo, PredDecls),
-	intermod__write_preds(ModuleInfo, Preds),
-	globals__io_set_option(dump_hlds_options, string(VerboseDump)).
-
-:- pred intermod__write_modules(list(module_name)::in,
-			io__state::di, io__state::uo) is det.
-
-intermod__write_modules([]) --> [].
-intermod__write_modules([Module | Rest]) -->
-	mercury_output_bracketed_sym_name(Module),
-	(
-		{ Rest = [] },
-		io__write_string(".\n")
-	;
-		{ Rest = [_ | _] },
-		io__write_string(", "),
-		intermod__write_modules(Rest)
+			(pred(ForeignImport::in, IO0::di, IO::uo) is det :-
+				ForeignImport = foreign_import_module(Lang,
+					Import, _),
+				mercury_output_pragma_foreign_import_module(
+					Lang, Import, IO0, IO)
+			), ForeignImports, !IO)
+	;
+		WriteHeader = no
+	),
+	intermod__write_pred_decls(ModuleInfo, PredDecls, !IO),
+	intermod__write_preds(ModuleInfo, Preds, !IO),
+	globals__io_set_option(dump_hlds_options, string(VerboseDump), !IO).
+
+:- pred intermod__write_modules(list(module_name)::in, io::di, io::uo) is det.
+
+intermod__write_modules([], !IO).
+intermod__write_modules([Module | Rest], !IO) :-
+	mercury_output_bracketed_sym_name(Module, !IO),
+	(
+		Rest = [],
+		io__write_string(".\n", !IO)
+	;
+		Rest = [_ | _],
+		io__write_string(", ", !IO),
+		intermod__write_modules(Rest, !IO)
 	).
 
 :- pred intermod__write_types(assoc_list(type_ctor, hlds_type_defn)::in,
-		io__state::di, io__state::uo) is det.
+	io::di, io::uo) is det.
 
-intermod__write_types(Types) -->
-	list__foldl(intermod__write_type, Types).
+intermod__write_types(Types, !IO) :-
+	list__foldl(intermod__write_type, Types, !IO).
 
 :- pred intermod__write_type(pair(type_ctor, hlds_type_defn)::in,
-		io__state::di, io__state::uo) is det.
+	io::di, io::uo) is det.
 
-intermod__write_type(TypeCtor - TypeDefn) -->
-	{ hlds_data__get_type_defn_tvarset(TypeDefn, VarSet) },
-	{ hlds_data__get_type_defn_tparams(TypeDefn, Args) },
-	{ hlds_data__get_type_defn_body(TypeDefn, Body) },
-	{ hlds_data__get_type_defn_context(TypeDefn, Context) },
-	{ TypeCtor = Name - Arity },
-	(
-		{ Ctors = Body ^ du_type_ctors },
-		{ IsSolverType = Body ^ du_type_is_solver_type },
-		{ MaybeEqualityPred = Body ^ du_type_usereq },
-		{ TypeBody = du_type(Ctors, IsSolverType, MaybeEqualityPred) }
+intermod__write_type(TypeCtor - TypeDefn, !IO) :-
+	hlds_data__get_type_defn_tvarset(TypeDefn, VarSet),
+	hlds_data__get_type_defn_tparams(TypeDefn, Args),
+	hlds_data__get_type_defn_body(TypeDefn, Body),
+	hlds_data__get_type_defn_context(TypeDefn, Context),
+	TypeCtor = Name - Arity,
+	(
+		Ctors = Body ^ du_type_ctors,
+		IsSolverType = Body ^ du_type_is_solver_type,
+		MaybeEqualityPred = Body ^ du_type_usereq,
+		TypeBody = du_type(Ctors, IsSolverType, MaybeEqualityPred)
 	;
-		{ Body = eqv_type(EqvType) },
-		{ TypeBody = eqv_type(EqvType) }
+		Body = eqv_type(EqvType),
+		TypeBody = eqv_type(EqvType)
 	;
-		{ Body = abstract_type(IsSolverType) },
-		{ TypeBody = abstract_type(IsSolverType) }
+		Body = abstract_type(IsSolverType),
+		TypeBody = abstract_type(IsSolverType)
 	;
-		{ Body = foreign_type(_, IsSolverType) },
-		{ TypeBody = abstract_type(IsSolverType) }
+		Body = foreign_type(_, IsSolverType),
+		TypeBody = abstract_type(IsSolverType)
 	),
 	mercury_output_item(
 		type_defn(VarSet, Name, Args, TypeBody, true),
-		Context),
+		Context, !IO),
 
 	(
-		{ Body = foreign_type(ForeignTypeBody, _)
+		( Body = foreign_type(ForeignTypeBody, _)
 		; Body ^ du_type_is_foreign_type = yes(ForeignTypeBody)
-		},
-		{ ForeignTypeBody = foreign_type_body(MaybeIL, MaybeC,
-			MaybeJava) }
+		),
+		ForeignTypeBody = foreign_type_body(MaybeIL, MaybeC,
+			MaybeJava)
 	->
 		(
-			{ MaybeIL = yes(DataIL) },
-			{ DataIL = foreign_type_lang_data(ILForeignType,
-				ILUserEqComp, AssertionsIL) },
+			MaybeIL = yes(DataIL),
+			DataIL = foreign_type_lang_data(ILForeignType,
+				ILUserEqComp, AssertionsIL),
 			mercury_output_item(
 				type_defn(VarSet, Name, Args,
 					foreign_type(il(ILForeignType),
 						ILUserEqComp, AssertionsIL),
 				true),
-				Context)
+				Context, !IO)
 		;
-			{ MaybeIL = no }
+			MaybeIL = no
 		),
 		(
-			{ MaybeC = yes(DataC) },
-			{ DataC = foreign_type_lang_data(CForeignType,
-				CUserEqComp, AssertionsC) },
+			MaybeC = yes(DataC),
+			DataC = foreign_type_lang_data(CForeignType,
+				CUserEqComp, AssertionsC),
 			mercury_output_item(
 				type_defn(VarSet, Name, Args,
 					foreign_type(c(CForeignType),
 						CUserEqComp, AssertionsC),
 					true),
-				Context)
+				Context, !IO)
 		;
-			{ MaybeC = no }
+			MaybeC = no
 		),
 		(
-			{ MaybeJava = yes(DataJava) },
-			{ DataJava = foreign_type_lang_data(JavaForeignType,
-				JavaUserEqComp, AssertionsJava) },
+			MaybeJava = yes(DataJava),
+			DataJava = foreign_type_lang_data(JavaForeignType,
+				JavaUserEqComp, AssertionsJava),
 			mercury_output_item(
 				type_defn(VarSet, Name, Args,
 					foreign_type(java(JavaForeignType),
 						JavaUserEqComp, AssertionsJava),
 					true),
-				Context)
+				Context, !IO)
 		;
-			{ MaybeJava = no }
+			MaybeJava = no
 		)
 	;
-		[]
+		true
 	),
 	(
-		{ ReservedTag = Body ^ du_type_reserved_tag },
-		{ ReservedTag = yes }
+		ReservedTag = Body ^ du_type_reserved_tag,
+		ReservedTag = yes
 	->
 		mercury_output_item(pragma(reserve_tag(Name, Arity)),
-			Context)
+			Context, !IO)
 	;
-		[]
+		true
 	).
 
-:- pred intermod__write_modes(module_info::in,
-		io__state::di, io__state::uo) is det.
+:- pred intermod__write_modes(module_info::in, io::di, io::uo) is det.
 
-intermod__write_modes(ModuleInfo) -->
-	{ module_info_name(ModuleInfo, ModuleName) },
-	{ module_info_modes(ModuleInfo, Modes) },
-	{ mode_table_get_mode_defns(Modes, ModeDefns) },
-	map__foldl(intermod__write_mode(ModuleName), ModeDefns).
+intermod__write_modes(ModuleInfo, !IO) :-
+	module_info_name(ModuleInfo, ModuleName),
+	module_info_modes(ModuleInfo, Modes),
+	mode_table_get_mode_defns(Modes, ModeDefns),
+	map__foldl(intermod__write_mode(ModuleName), ModeDefns, !IO).
 
 :- pred intermod__write_mode(module_name::in, mode_id::in, hlds_mode_defn::in,
-		io__state::di, io__state::uo) is det.
+	io::di, io::uo) is det.
 
-intermod__write_mode(ModuleName, ModeId, ModeDefn) -->
-	{ ModeId = SymName - _Arity },
-	{ ModeDefn = hlds_mode_defn(Varset, Args, eqv_mode(Mode),
-		Context, ImportStatus) },
+intermod__write_mode(ModuleName, ModeId, ModeDefn, !IO) :-
+	ModeId = SymName - _Arity,
+	ModeDefn = hlds_mode_defn(Varset, Args, eqv_mode(Mode), Context,
+		ImportStatus),
 	(
-		{ SymName = qualified(ModuleName, _) },
-		{ import_status_to_write(ImportStatus) }
+		SymName = qualified(ModuleName, _),
+		import_status_to_write(ImportStatus)
 	->
 		mercury_output_item(
 			mode_defn(Varset, SymName, Args, eqv_mode(Mode), true),
-			Context)
+			Context, !IO)
 	;
-		[]
+		true
 	).
 
-:- pred intermod__write_insts(module_info::in,
-		io__state::di, io__state::uo) is det.
+:- pred intermod__write_insts(module_info::in, io::di, io::uo) is det.
 
-intermod__write_insts(ModuleInfo) -->
-	{ module_info_name(ModuleInfo, ModuleName) },
-	{ module_info_insts(ModuleInfo, Insts) },
-	{ inst_table_get_user_insts(Insts, UserInsts) },
-	{ user_inst_table_get_inst_defns(UserInsts, InstDefns) },
-	map__foldl(intermod__write_inst(ModuleName), InstDefns).
+intermod__write_insts(ModuleInfo, !IO) :-
+	module_info_name(ModuleInfo, ModuleName),
+	module_info_insts(ModuleInfo, Insts),
+	inst_table_get_user_insts(Insts, UserInsts),
+	user_inst_table_get_inst_defns(UserInsts, InstDefns),
+	map__foldl(intermod__write_inst(ModuleName), InstDefns, !IO).
 
 :- pred intermod__write_inst(module_name::in, inst_id::in, hlds_inst_defn::in, 
-		io__state::di, io__state::uo) is det.
+	io::di, io::uo) is det.
 
-intermod__write_inst(ModuleName, InstId, InstDefn) -->
-	{ InstId = SymName - _Arity },
-	{ InstDefn = hlds_inst_defn(Varset, Args, Body,
-		Context, ImportStatus) },
+intermod__write_inst(ModuleName, InstId, InstDefn, !IO) :-
+	InstId = SymName - _Arity,
+	InstDefn = hlds_inst_defn(Varset, Args, Body,
+		Context, ImportStatus),
 	(
-		{ SymName = qualified(ModuleName, _) },
-		{ import_status_to_write(ImportStatus) }
+		SymName = qualified(ModuleName, _),
+		import_status_to_write(ImportStatus)
 	->
 		(
-			{ Body = eqv_inst(Inst2) },
-			{ InstBody = eqv_inst(Inst2) }
+			Body = eqv_inst(Inst2),
+			InstBody = eqv_inst(Inst2)
 		;
-			{ Body = abstract_inst },
-			{ InstBody = abstract_inst }
+			Body = abstract_inst,
+			InstBody = abstract_inst
 		),
 		mercury_output_item(
 			inst_defn(Varset, SymName, Args, InstBody, true),
-			Context)
+			Context, !IO)
 	;
-		[]
+		true
 	).
 
-:- pred intermod__write_classes(module_info::in,
-		io__state::di, io__state::uo) is det.
+:- pred intermod__write_classes(module_info::in, io::di, io::uo) is det.
 
-intermod__write_classes(ModuleInfo) -->
-	{ module_info_name(ModuleInfo, ModuleName) },
-	{ module_info_classes(ModuleInfo, Classes) },
-	map__foldl(intermod__write_class(ModuleName), Classes).
+intermod__write_classes(ModuleInfo, !IO) :-
+	module_info_name(ModuleInfo, ModuleName),
+	module_info_classes(ModuleInfo, Classes),
+	map__foldl(intermod__write_class(ModuleName), Classes, !IO).
 
 :- pred intermod__write_class(module_name::in, class_id::in,
-		hlds_class_defn::in, io__state::di, io__state::uo) is det.
+	hlds_class_defn::in, io::di, io::uo) is det.
 
-intermod__write_class(ModuleName, ClassId, ClassDefn) -->
-	{ ClassDefn = hlds_class_defn(ImportStatus, Constraints,
+intermod__write_class(ModuleName, ClassId, ClassDefn, !IO) :-
+	ClassDefn = hlds_class_defn(ImportStatus, Constraints,
 			TVars, Interface, _HLDSClassInterface,
-			TVarSet, Context) },
-	{ ClassId = class_id(QualifiedClassName, _) },
+		TVarSet, Context),
+	ClassId = class_id(QualifiedClassName, _),
 	(
-		{ QualifiedClassName = qualified(ModuleName, _) },
-		{ import_status_to_write(ImportStatus) }
+		QualifiedClassName = qualified(ModuleName, _),
+		import_status_to_write(ImportStatus)
 	->
-		{ Item = typeclass(Constraints, QualifiedClassName, TVars,
-				Interface, TVarSet) },
-		mercury_output_item(Item, Context)
+		Item = typeclass(Constraints, QualifiedClassName, TVars,
+			Interface, TVarSet),
+		mercury_output_item(Item, Context, !IO)
 	;
-		[]
+		true
 	).
 
 :- pred intermod__write_instances(assoc_list(class_id, hlds_instance_defn)::in,
-		io__state::di, io__state::uo) is det.
+	io::di, io::uo) is det.
 
-intermod__write_instances(Instances) -->
-	list__foldl(intermod__write_instance, Instances).
+intermod__write_instances(Instances, !IO) :-
+	list__foldl(intermod__write_instance, Instances, !IO).
 
 :- pred intermod__write_instance(pair(class_id, hlds_instance_defn)::in,
-		io__state::di, io__state::uo) is det.
+	io::di, io::uo) is det.
 
-intermod__write_instance(ClassId - InstanceDefn) -->
-	{ InstanceDefn = hlds_instance_defn(ModuleName, _, Context,
-			Constraints, Types, Body, _, TVarSet, _) },
-	{ ClassId = class_id(ClassName, _) },
-	{ Item = instance(Constraints, ClassName, Types, Body, TVarSet,
-		ModuleName) },
-	mercury_output_item(Item, Context).
+intermod__write_instance(ClassId - InstanceDefn, !IO) :-
+	InstanceDefn = hlds_instance_defn(ModuleName, _, Context,
+		Constraints, Types, Body, _, TVarSet, _),
+	ClassId = class_id(ClassName, _),
+	Item = instance(Constraints, ClassName, Types, Body, TVarSet,
+		ModuleName),
+	mercury_output_item(Item, Context, !IO).
 
 	% We need to write all the declarations for local predicates so
 	% the procedure labels for the C code are calculated correctly.
 :- pred intermod__write_pred_decls(module_info::in, list(pred_id)::in,
-			io__state::di, io__state::uo) is det.
+	io::di, io::uo) is det.
 
-intermod__write_pred_decls(_, []) --> [].
-intermod__write_pred_decls(ModuleInfo, [PredId | PredIds]) -->
-	{ module_info_pred_info(ModuleInfo, PredId, PredInfo) },
-	{ Module = pred_info_module(PredInfo) },
-	{ Name = pred_info_name(PredInfo) },
-	{ PredOrFunc = pred_info_is_pred_or_func(PredInfo) },
-	{ pred_info_arg_types(PredInfo, TVarSet, ExistQVars, ArgTypes) },
-	{ pred_info_context(PredInfo, Context) },
-	{ pred_info_get_purity(PredInfo, Purity) },
-	{ pred_info_get_class_context(PredInfo, ClassContext) },
-	{ pred_info_get_goal_type(PredInfo, GoalType) },
-	{
+intermod__write_pred_decls(_, [], !IO).
+intermod__write_pred_decls(ModuleInfo, [PredId | PredIds], !IO) :-
+	module_info_pred_info(ModuleInfo, PredId, PredInfo),
+	Module = pred_info_module(PredInfo),
+	Name = pred_info_name(PredInfo),
+	PredOrFunc = pred_info_is_pred_or_func(PredInfo),
+	pred_info_arg_types(PredInfo, TVarSet, ExistQVars, ArgTypes),
+	pred_info_context(PredInfo, Context),
+	pred_info_get_purity(PredInfo, Purity),
+	pred_info_get_class_context(PredInfo, ClassContext),
+	pred_info_get_goal_type(PredInfo, GoalType),
+	(
 		GoalType = pragmas,
 		% For foreign code goals we can't append variable numbers
 		% to type variables in the predicate declaration
@@ -1537,170 +1490,170 @@
 	;
 		GoalType = none,
 		AppendVarNums = yes
-	},
+	),
 	(
-		{ PredOrFunc = predicate },
+		PredOrFunc = predicate,
 		mercury_output_pred_type(TVarSet, ExistQVars,
 			qualified(Module, Name), ArgTypes, no, Purity,
-			ClassContext, Context, AppendVarNums)
+			ClassContext, Context, AppendVarNums, !IO)
 	;
-		{ PredOrFunc = function },
-		{ pred_args_to_func_args(ArgTypes, FuncArgTypes, FuncRetType) },
+		PredOrFunc = function,
+		pred_args_to_func_args(ArgTypes, FuncArgTypes, FuncRetType),
 		mercury_output_func_type(TVarSet, ExistQVars,
 			qualified(Module, Name), FuncArgTypes,
 			FuncRetType, no, Purity, ClassContext, Context,
-			AppendVarNums)
+			AppendVarNums, !IO)
 	),
-	{ pred_info_procedures(PredInfo, Procs) },
-	{ ProcIds = pred_info_procids(PredInfo) },
+	pred_info_procedures(PredInfo, Procs),
+	ProcIds = pred_info_procids(PredInfo),
 		% Make sure the mode declarations go out in the same
 		% order they came in, so that the all the modes get the
 		% same proc_id in the importing modules.
-	{ CompareProcId =
+	CompareProcId =
 		(pred(ProcId1::in, ProcId2::in, Result::out) is det :-
 			proc_id_to_int(ProcId1, ProcInt1),
 			proc_id_to_int(ProcId2, ProcInt2),
 			compare(Result, ProcInt1, ProcInt2)
-		) },
-	{ list__sort(CompareProcId, ProcIds, SortedProcIds) },
+		),
+	list__sort(CompareProcId, ProcIds, SortedProcIds),
 	intermod__write_pred_modes(Procs, qualified(Module, Name),
-					PredOrFunc, SortedProcIds),
-	intermod__write_pragmas(PredInfo),
-	intermod__write_type_spec_pragmas(ModuleInfo, PredId),
-	intermod__write_pred_decls(ModuleInfo, PredIds).
+		PredOrFunc, SortedProcIds, !IO),
+	intermod__write_pragmas(PredInfo, !IO),
+	intermod__write_type_spec_pragmas(ModuleInfo, PredId, !IO),
+	intermod__write_pred_decls(ModuleInfo, PredIds, !IO).
 
 :- pred intermod__write_pred_modes(map(proc_id, proc_info)::in, 
 		sym_name::in, pred_or_func::in, list(proc_id)::in,
-		io__state::di, io__state::uo) is det.
+	io::di, io::uo) is det.
 
-intermod__write_pred_modes(_, _, _, []) --> [].
-intermod__write_pred_modes(Procs, SymName, PredOrFunc, [ProcId | ProcIds]) -->
-	{ map__lookup(Procs, ProcId, ProcInfo) },
-	{ proc_info_maybe_declared_argmodes(ProcInfo, MaybeArgModes) },
-	{ proc_info_declared_determinism(ProcInfo, MaybeDetism) },
-	{ MaybeArgModes = yes(ArgModes0), MaybeDetism = yes(Detism0) ->
+intermod__write_pred_modes(_, _, _, [], !IO).
+intermod__write_pred_modes(Procs, SymName, PredOrFunc, [ProcId | ProcIds],
+		!IO) :-
+	map__lookup(Procs, ProcId, ProcInfo),
+	proc_info_maybe_declared_argmodes(ProcInfo, MaybeArgModes),
+	proc_info_declared_determinism(ProcInfo, MaybeDetism),
+	(
+		MaybeArgModes = yes(ArgModes0),
+		MaybeDetism = yes(Detism0)
+	->
 		ArgModes = ArgModes0,
 		Detism = Detism0
 	;
-		error("intermod__write_pred_modes: attempt to write undeclared mode")
-	},
-	{ proc_info_context(ProcInfo, Context) },
-	{ varset__init(Varset) },
+		error("intermod__write_pred_modes: " ++
+			"attempt to write undeclared mode")
+	),
+	proc_info_context(ProcInfo, Context),
+	varset__init(Varset),
 	(
-		{ PredOrFunc = function },
-		{ pred_args_to_func_args(ArgModes, FuncArgModes, FuncRetMode) },
+		PredOrFunc = function,
+		pred_args_to_func_args(ArgModes, FuncArgModes, FuncRetMode),
 		mercury_output_func_mode_decl(Varset, SymName,
 			FuncArgModes, FuncRetMode,
-			yes(Detism), Context)
+			yes(Detism), Context, !IO)
 	;
-		{ PredOrFunc = predicate },
-		mercury_output_pred_mode_decl(Varset, SymName,
-				ArgModes, yes(Detism), Context)
+		PredOrFunc = predicate,
+		mercury_output_pred_mode_decl(Varset, SymName, ArgModes,
+			yes(Detism), Context, !IO)
 	),
-	intermod__write_pred_modes(Procs, SymName, PredOrFunc, ProcIds).	
+	intermod__write_pred_modes(Procs, SymName, PredOrFunc, ProcIds, !IO).
 
 :- pred intermod__write_preds(module_info::in, list(pred_id)::in,
-				io__state::di, io__state::uo) is det.
+	io::di, io::uo) is det.
 
-intermod__write_preds(_, []) --> [].
-intermod__write_preds(ModuleInfo, [PredId | PredIds]) -->
-	{ module_info_pred_info(ModuleInfo, PredId, PredInfo) },
-	{ Module = pred_info_module(PredInfo) },
-	{ Name = pred_info_name(PredInfo) },
-	{ SymName = qualified(Module, Name) },
-	{ PredOrFunc = pred_info_is_pred_or_func(PredInfo) },
-	intermod__write_pragmas(PredInfo),
+intermod__write_preds(_, [], !IO).
+intermod__write_preds(ModuleInfo, [PredId | PredIds], !IO) :-
+	module_info_pred_info(ModuleInfo, PredId, PredInfo),
+	Module = pred_info_module(PredInfo),
+	Name = pred_info_name(PredInfo),
+	SymName = qualified(Module, Name),
+	PredOrFunc = pred_info_is_pred_or_func(PredInfo),
+	intermod__write_pragmas(PredInfo, !IO),
 	% The type specialization pragmas for exported preds should
 	% already be in the interface file.
 
-	{ pred_info_clauses_info(PredInfo, ClausesInfo) },
-	{ clauses_info_varset(ClausesInfo, VarSet) },
-	{ clauses_info_headvars(ClausesInfo, HeadVars) },
-	{ clauses_info_clauses(ClausesInfo, Clauses) },
+	pred_info_clauses_info(PredInfo, ClausesInfo),
+	clauses_info_varset(ClausesInfo, VarSet),
+	clauses_info_headvars(ClausesInfo, HeadVars),
+	clauses_info_clauses(ClausesInfo, Clauses),
 
-	(
-		{ pred_info_get_goal_type(PredInfo, promise(PromiseType)) }
-	->
-		(
-			{ Clauses = [Clause] }
-		->
+	( pred_info_get_goal_type(PredInfo, promise(PromiseType)) ->
+		( Clauses = [Clause] ->
 			hlds_out__write_promise(PromiseType, 0, ModuleInfo, 
 					PredId, VarSet, no, HeadVars, 
-					PredOrFunc, Clause, no)
+				PredOrFunc, Clause, no, !IO)
 		;
-			{ error("intermod__write_preds: assertion not a single clause.") }
+			error("intermod__write_preds: " ++
+				"assertion not a single clause.")
 		)
 	;	
 		list__foldl(intermod__write_clause(ModuleInfo, PredId, VarSet,
-			HeadVars, PredOrFunc, SymName), Clauses)
+			HeadVars, PredOrFunc, SymName), Clauses, !IO)
 	),
-	intermod__write_preds(ModuleInfo, PredIds).
+	intermod__write_preds(ModuleInfo, PredIds, !IO).
 
 :- pred intermod__write_clause(module_info::in, pred_id::in, prog_varset::in,
 		list(prog_var)::in, pred_or_func::in, sym_name::in, clause::in,
-		io__state::di, io__state::uo) is det.
+	io::di, io::uo) is det.
 
 intermod__write_clause(ModuleInfo, PredId, VarSet, HeadVars,
-		PredOrFunc, _SymName, Clause0) -->
-	{ Clause0 = clause(_, _, mercury, _) },
-	{ strip_headvar_unifications(HeadVars, Clause0,
-		ClauseHeadVars, Clause) },
+		PredOrFunc, _SymName, Clause0, !IO) :-
+	Clause0 = clause(_, _, mercury, _),
+	strip_headvar_unifications(HeadVars, Clause0,
+		ClauseHeadVars, Clause),
 	% Variable numbers need to be appended for the case
 	% where the added arguments for a DCG pred expression
 	% are named the same as variables in the enclosing clause.
-	{ AppendVarNums = yes },
-	{ UseDeclaredModes = yes },
-	{ MaybeVarTypes = no },
+	AppendVarNums = yes,
+	UseDeclaredModes = yes,
+	MaybeVarTypes = no,
 	hlds_out__write_clause(1, ModuleInfo, PredId, VarSet, AppendVarNums,
 		ClauseHeadVars, PredOrFunc, Clause, UseDeclaredModes,
-		MaybeVarTypes).
+		MaybeVarTypes, !IO).
 
 intermod__write_clause(ModuleInfo, PredId, VarSet, _HeadVars,
-		PredOrFunc, SymName, Clause) -->
-	{ Clause = clause(ProcIds, Goal, foreign_language(_), _) },
-	{ module_info_pred_info(ModuleInfo, PredId, PredInfo) },
-	{ pred_info_procedures(PredInfo, Procs) },
+		PredOrFunc, SymName, Clause, !IO) :-
+	Clause = clause(ProcIds, Goal, foreign_language(_), _),
+	module_info_pred_info(ModuleInfo, PredId, PredInfo),
+	pred_info_procedures(PredInfo, Procs),
 	(
 		(
 			% Pull the foreign code out of the goal.
-			{ Goal = conj(Goals) - _ },
-			{ list__filter((pred(X::in) is semidet :-
-				    X = foreign_proc(_,_,_,_,_,_,_) - _
-				), Goals, [ForeignCodeGoal]) },
-			{ ForeignCodeGoal = foreign_proc(Attributes,
-				_, _, Vars, Names, _, PragmaCode) - _ }
+			Goal = conj(Goals) - _,
+			list__filter((pred(X::in) is semidet :-
+				    X = foreign_proc(_, _, _, _, _, _) - _
+				), Goals, [ForeignCodeGoal]),
+			ForeignCodeGoal = foreign_proc(Attributes,
+				_, _, Args, _, PragmaCode) - _
 		;
-			{ Goal = foreign_proc(Attributes,
-				_, _, Vars, Names, _, PragmaCode) - _ }
+			Goal = foreign_proc(Attributes,
+				_, _, Args, _, PragmaCode) - _
 		)
 	->	
-		list__foldl(intermod__write_foreign_clause(Procs,
-			PredOrFunc, PragmaCode, Attributes, Vars, 
-			VarSet, Names, SymName), ProcIds)
+		list__foldl(intermod__write_foreign_clause(Procs, PredOrFunc,
+			PragmaCode, Attributes, Args, VarSet, SymName),
+			ProcIds, !IO)
 	;
-		{ error("foreign_proc expected within this goal") }
+		error("foreign_proc expected within this goal")
 	).
 
+:- pred intermod__write_foreign_clause(proc_table::in, pred_or_func::in,
+	pragma_foreign_code_impl::in, pragma_foreign_proc_attributes::in,
+	list(foreign_arg)::in, prog_varset::in, sym_name::in, proc_id::in,
+	io::di, io::uo) is det.
 
-:- pred intermod__write_foreign_clause(proc_table::in, 
-		pred_or_func::in, pragma_foreign_code_impl::in,
-		pragma_foreign_proc_attributes::in, list(prog_var)::in,
-		prog_varset::in, list(maybe(pair(string, mode)))::in,
-		sym_name::in, proc_id::in, io__state::di, io__state::uo) is det.
 intermod__write_foreign_clause(Procs, PredOrFunc, PragmaImpl,
-		Attributes, Vars, VarSet0, Names, SymName, ProcId) -->
-	{ map__lookup(Procs, ProcId, ProcInfo) },
-	{ proc_info_maybe_declared_argmodes(ProcInfo, MaybeArgModes) },
-	( { MaybeArgModes = yes(ArgModes) } ->
-		{ get_pragma_foreign_code_vars(Vars, Names, VarSet0,
-			ArgModes, VarSet, PragmaVars) },
+		Attributes, Args, VarSet0, SymName, ProcId, !IO) :-
+	map__lookup(Procs, ProcId, ProcInfo),
+	proc_info_maybe_declared_argmodes(ProcInfo, MaybeArgModes),
+	( MaybeArgModes = yes(ArgModes) ->
+		get_pragma_foreign_code_vars(Args, ArgModes, VarSet0, VarSet,
+			PragmaVars),
 		mercury_output_pragma_foreign_code(Attributes, SymName,
-			PredOrFunc, PragmaVars, VarSet, PragmaImpl)
+			PredOrFunc, PragmaVars, VarSet, PragmaImpl, !IO)
 	;
-		{ error("intermod__write_clause: no mode declaration") }
+		error("intermod__write_clause: no mode declaration")
 	).
 
-
 	% Strip the `Headvar__n = Term' unifications from each clause,
 	% except if the `Term' is a lambda expression.
 	%
@@ -1729,7 +1682,10 @@
 	->
 		list__map(
 		    (pred(HeadVar0::in, HeadTerm::out) is det :-
-			( map__search(HeadVarMap, HeadVar0, HeadTerm0) ->
+				(
+					map__search(HeadVarMap, HeadVar0,
+						HeadTerm0)
+				->
 				HeadTerm = HeadTerm0
 			;
 				HeadTerm = term__variable(HeadVar0)
@@ -1747,10 +1703,10 @@
 		map(prog_var, prog_term)::out) is semidet.
 
 strip_headvar_unifications_from_goal_list([], _, RevGoals, Goals,
-		HeadVarMap, HeadVarMap) :-
+		!HeadVarMap) :-
 	list__reverse(RevGoals, Goals).
 strip_headvar_unifications_from_goal_list([Goal | Goals0], HeadVars,
-		RevGoals0, Goals, HeadVarMap0, HeadVarMap) :-
+		RevGoals0, Goals, !HeadVarMap) :-
 	(
 		Goal = unify(LHSVar, RHS, _, _, _) - _,
 		list__member(LHSVar, HeadVars),
@@ -1782,61 +1738,60 @@
 	->
 		% Don't strip the headvar unifications if one of the
 		% headvars appears twice. This should probably never happen.
-		map__insert(HeadVarMap0, LHSVar, RHSTerm, HeadVarMap1),
+		map__insert(!.HeadVarMap, LHSVar, RHSTerm, !:HeadVarMap),
 		RevGoals1 = RevGoals0
 	;
-		HeadVarMap1 = HeadVarMap0,
 		RevGoals1 = [Goal | RevGoals0]
 	),
 	strip_headvar_unifications_from_goal_list(Goals0, HeadVars,
-		RevGoals1, Goals, HeadVarMap1, HeadVarMap).
+		RevGoals1, Goals, !HeadVarMap).
 
-:- pred intermod__write_pragmas(pred_info::in,
-		io__state::di, io__state::uo) is det.
+:- pred intermod__write_pragmas(pred_info::in, io::di, io::uo) is det.
 
-intermod__write_pragmas(PredInfo) -->
-	{ Module = pred_info_module(PredInfo) },
-	{ Name = pred_info_name(PredInfo) },
-	{ Arity = pred_info_arity(PredInfo) },
-	{ PredOrFunc = pred_info_is_pred_or_func(PredInfo) },
-	{ SymName = qualified(Module, Name) },
-	{ pred_info_get_markers(PredInfo, Markers) },
-	{ markers_to_marker_list(Markers, MarkerList) },
-	intermod__write_pragmas(SymName, Arity, MarkerList, PredOrFunc).
+intermod__write_pragmas(PredInfo, !IO) :-
+	Module = pred_info_module(PredInfo),
+	Name = pred_info_name(PredInfo),
+	Arity = pred_info_arity(PredInfo),
+	PredOrFunc = pred_info_is_pred_or_func(PredInfo),
+	SymName = qualified(Module, Name),
+	pred_info_get_markers(PredInfo, Markers),
+	markers_to_marker_list(Markers, MarkerList),
+	intermod__write_pragmas(SymName, Arity, MarkerList, PredOrFunc, !IO).
 
 :- pred intermod__write_pragmas(sym_name::in, int::in, list(marker)::in,
-		pred_or_func::in, io__state::di, io__state::uo) is det.
+	pred_or_func::in, io::di, io::uo) is det.
 
-intermod__write_pragmas(_, _, [], _) --> [].
-intermod__write_pragmas(SymName, Arity, [Marker | Markers], PredOrFunc) -->
-	{ intermod__should_output_marker(Marker, ShouldOutput) },
-	( { ShouldOutput = yes } ->
-		{ hlds_out__marker_name(Marker, Name) },
-		mercury_output_pragma_decl(SymName, Arity, PredOrFunc, Name)
+intermod__write_pragmas(_, _, [], _, !IO).
+intermod__write_pragmas(SymName, Arity, [Marker | Markers], PredOrFunc, !IO) :-
+	intermod__should_output_marker(Marker, ShouldOutput),
+	( ShouldOutput = yes ->
+		hlds_out__marker_name(Marker, Name),
+		mercury_output_pragma_decl(SymName, Arity, PredOrFunc, Name,
+			!IO)
 	;
-		[]
+		true
 	),
-	intermod__write_pragmas(SymName, Arity, Markers, PredOrFunc).
+	intermod__write_pragmas(SymName, Arity, Markers, PredOrFunc, !IO).
 
 :- pred intermod__write_type_spec_pragmas(module_info::in, pred_id::in,
-		io__state::di, io__state::uo) is det.
+	io::di, io::uo) is det.
 
-intermod__write_type_spec_pragmas(ModuleInfo, PredId) -->
-	{ module_info_type_spec_info(ModuleInfo,
-		type_spec_info(_, _, _, PragmaMap)) },
-	( { multi_map__search(PragmaMap, PredId, TypeSpecPragmas) } ->
+intermod__write_type_spec_pragmas(ModuleInfo, PredId, !IO) :-
+	module_info_type_spec_info(ModuleInfo,
+		type_spec_info(_, _, _, PragmaMap)),
+	( multi_map__search(PragmaMap, PredId, TypeSpecPragmas) ->
 		list__foldl(
-		    ( pred(Pragma::in, di, uo) is det -->
-			( { Pragma = type_spec(_, _, _, _, _, _, _, _) } ->
-				{ AppendVarnums = yes },
+			( pred(Pragma::in, IO0::di, IO::uo) is det :-
+				( Pragma = type_spec(_, _, _, _, _, _, _, _) ->
+					AppendVarnums = yes,
 				mercury_output_pragma_type_spec(Pragma,
-					AppendVarnums)
+						AppendVarnums, IO0, IO)
 			;
-				{ error("intermod__write_type_spec_pragmas") }
+					error("write_type_spec_pragmas")
 			)
-		    ), TypeSpecPragmas)
+			), TypeSpecPragmas, !IO)
 	;
-		[]
+		true
 	).
 
 	% Is a pragma declaration required in the `.opt' file for
@@ -1880,44 +1835,79 @@
 	error("intermod__should_output_marker: generate_inline").
 intermod__should_output_marker(calls_are_fully_qualified, no).
 
-:- pred get_pragma_foreign_code_vars(list(prog_var)::in,
-		list(maybe(pair(string, mode)))::in, prog_varset::in,
-		list(mode)::in, prog_varset::out, list(pragma_var)::out) is det.
+:- pred get_pragma_foreign_code_vars(list(foreign_arg)::in, list(mode)::in,
+	prog_varset::in, prog_varset::out, list(pragma_var)::out) is det.
 
-get_pragma_foreign_code_vars(HeadVars, VarNames, VarSet0, ArgModes,
-		VarSet, PragmaVars) :- 
+get_pragma_foreign_code_vars(Args, Modes, !VarSet, PragmaVars) :-
 	(
-		HeadVars = [Var | Vars],
-		VarNames = [Maybe_NameAndMode | Names],
-		ArgModes = [Mode | Modes]
+		Args = [Arg | ArgsTail],
+		Modes = [Mode | ModesTail]
 	->
+		Arg = foreign_arg(Var, MaybeNameAndMode, _),
 		(
-			Maybe_NameAndMode = no,
+			MaybeNameAndMode = no,
 			Name = "_"
 		;
-			Maybe_NameAndMode = yes(Name - _Mode2)
+			MaybeNameAndMode = yes(Name - _Mode2)
 		),
 		PragmaVar = pragma_var(Var, Name, Mode),
-		varset__name_var(VarSet0, Var, Name, VarSet1),
-		get_pragma_foreign_code_vars(Vars, Names, VarSet1, Modes,
-			VarSet, PragmaVars1),
-		PragmaVars = [PragmaVar | PragmaVars1] 
-	;
-		HeadVars = [],
-		VarNames = [],
-		ArgModes = []
+		varset__name_var(!.VarSet, Var, Name, !:VarSet),
+		get_pragma_foreign_code_vars(ArgsTail, ModesTail, !VarSet,
+			PragmaVarsTail),
+		PragmaVars = [PragmaVar | PragmaVarsTail]
+	;
+		Args = [],
+		Modes = []
 	->
-		PragmaVars = [],
-		VarSet = VarSet0
+		PragmaVars = []
 	;
 		error("intermod:get_pragma_foreign_code_vars")
 	).
 
 %-----------------------------------------------------------------------------%
-	% Access predicates.
 
-:- pred intermod_info_get_modules(set(module_name)::out, intermod_info::in,
-			intermod_info::out) is det.
+	% a collection of stuff to go in the .opt file
+:- type intermod_info
+	--->	info(
+			im_modules	:: set(module_name),
+					% modules to import
+			im_preds	:: set(pred_id),
+					% preds to output clauses for
+			im_pred_decls	:: set(pred_id),
+					% preds to output decls for
+			im_instances	:: assoc_list(class_id,
+						hlds_instance_defn),
+					% instances declarations to write
+			im_types	:: assoc_list(type_ctor,
+						hlds_type_defn),
+					% type declarations to write
+			im_module_info	:: module_info,
+			im_write_foreign_header	:: bool,
+					% do the c_header_codes for the module
+					% need writing, yes if there are
+					% pragma_foreign_code procs being
+					% exported.
+			im_var_types	:: vartypes,
+			im_tvarset	:: tvarset
+					% Vartypes and tvarset for the
+					% current pred.
+		).
+
+:- pred init_intermod_info(module_info::in, intermod_info::out) is det.
+
+init_intermod_info(ModuleInfo, IntermodInfo) :-
+	set__init(Modules),
+	set__init(Procs),
+	set__init(ProcDecls),
+	map__init(VarTypes),
+	varset__init(TVarSet),
+	Instances = [],
+	Types = [],
+	IntermodInfo = info(Modules, Procs, ProcDecls, Instances, Types,
+		ModuleInfo, no, VarTypes, TVarSet).
+
+:- pred intermod_info_get_modules(set(module_name)::out,
+	intermod_info::in, intermod_info::out) is det.
 :- pred intermod_info_get_preds(set(pred_id)::out, 
 			intermod_info::in, intermod_info::out) is det.
 :- pred intermod_info_get_pred_decls(set(pred_id)::out, 
@@ -1933,25 +1923,10 @@
 			intermod_info::in, intermod_info::out) is det.
 :- pred intermod_info_get_write_foreign_header(bool::out,
 			intermod_info::in, intermod_info::out) is det.
-:- pred intermod_info_get_var_types(map(prog_var, type)::out,
+:- pred intermod_info_get_var_types(vartypes::out,
+	intermod_info::in, intermod_info::out) is det.
+:- pred intermod_info_get_tvarset(tvarset::out,
 			intermod_info::in, intermod_info::out) is det.
-:- pred intermod_info_get_tvarset(tvarset::out, intermod_info::in,
-			intermod_info::out) is det.
-
-intermod_info_get_modules(Modules)	--> =(info(Modules,_,_,_,_,_,_,_,_,_)). 
-intermod_info_get_preds(Procs)		--> =(info(_,Procs,_,_,_,_,_,_,_,_)).
-intermod_info_get_pred_decls(ProcDecls) -->
-					=(info(_,_,ProcDecls,_,_,_,_,_,_,_)).
-intermod_info_get_instances(Instances) -->
-		=(info(_,_,_,Instances,_,_,_,_,_,_)).
-intermod_info_get_types(Types)		--> =(info(_,_,_,_,Types,_,_,_,_,_)).
-%intermod_info_get_modes(Modes)		--> =(info(_,_,_,_,Modes,_,_,_,_,_)).
-%intermod_info_get_insts(Insts)		--> =(info(_,_,_,_,_,Insts,_,_,_,_)).
-intermod_info_get_module_info(Module)	--> =(info(_,_,_,_,_,_,Module,_,_,_)).
-intermod_info_get_write_foreign_header(Write)	--> 
-					    =(info(_,_,_,_,_,_,_,Write,_,_)).
-intermod_info_get_var_types(VarTypes)	--> =(info(_,_,_,_,_,_,_,_,VarTypes,_)).
-intermod_info_get_tvarset(TVarSet)	--> =(info(_,_,_,_,_,_,_,_,_,TVarSet)).
 
 :- pred intermod_info_set_modules(set(module_name)::in,
 			intermod_info::in, intermod_info::out) is det.
@@ -1972,38 +1947,31 @@
 			intermod_info::out) is det.
 :- pred intermod_info_set_var_types(map(prog_var, type)::in, intermod_info::in, 
 			intermod_info::out) is det.
-:- pred intermod_info_set_tvarset(tvarset::in, intermod_info::in,
-			intermod_info::out) is det.
-
-intermod_info_set_modules(Modules, info(_,B,C,D,E,F,G,H,I,J),
-				info(Modules, B,C,D,E,F,G,H,I,J)).
-
-intermod_info_set_preds(Procs, info(A,_,C,D,E,F,G,H,I,J),
-				info(A, Procs, C,D,E,F,G,H,I,J)).
-
-intermod_info_set_pred_decls(ProcDecls, info(A,B,_,D,E,F,G,H,I,J),
-				info(A,B, ProcDecls, D,E,F,G,H,I,J)).
-
-intermod_info_set_instances(Instances, info(A,B,C,_,E,F,G,H,I,J),
-				info(A,B,C, Instances, E,F,G,H,I,J)).
-
-intermod_info_set_types(Types, info(A,B,C,D, _, F,G,H,I,J),
-				info(A,B,C,D, Types, F,G,H,I,J)).
-
-%intermod_info_set_insts(Insts, info(A,B,C,D,E,_,G,H,I,J),
-%				info(A,B,C,D,E, Insts, G,H,I,J)).
-
-intermod_info_set_module_info(ModuleInfo, info(A,B,C,D,E,F,_,H,I,J),
-				info(A,B,C,D,E,F, ModuleInfo, H,I,J)).
-
-intermod_info_set_write_header(info(A,B,C,D,E,F,G,_,I,J),
-				 info(A,B,C,D,E,F,G, yes,I,J)).
+:- pred intermod_info_set_tvarset(tvarset::in,
+	intermod_info::in, intermod_info::out) is det.
 
-intermod_info_set_var_types(VarTypes, info(A,B,C,D,E,F,G,H,_,J),
-				info(A,B,C,D,E,F,G,H,VarTypes,J)).
+intermod_info_get_modules(Info ^ im_modules, Info, Info).
+intermod_info_get_preds(Info ^ im_preds, Info, Info).
+intermod_info_get_pred_decls(Info ^ im_pred_decls, Info, Info).
+intermod_info_get_instances(Info ^ im_instances, Info, Info).
+intermod_info_get_types(Info ^ im_types, Info, Info).
+intermod_info_get_module_info(Info ^ im_module_info, Info, Info).
+intermod_info_get_write_foreign_header(Info ^ im_write_foreign_header,
+		Info, Info).
+intermod_info_get_var_types(Info ^ im_var_types, Info, Info).
+intermod_info_get_tvarset(Info ^ im_tvarset, Info, Info).
 
-intermod_info_set_tvarset(TVarSet, info(A,B,C,D,E,F,G,H,I,_),
-				info(A,B,C,D,E,F,G,H,I, TVarSet)).
+intermod_info_set_modules(Modules, Info, Info ^ im_modules := Modules).
+intermod_info_set_preds(Procs, Info, Info ^ im_preds := Procs).
+intermod_info_set_pred_decls(ProcDecls, Info,
+		Info ^ im_pred_decls := ProcDecls).
+intermod_info_set_instances(Instances, Info, Info ^ im_instances := Instances).
+intermod_info_set_types(Types, Info, Info ^ im_types := Types).
+intermod_info_set_module_info(ModuleInfo, Info,
+		Info ^ im_module_info := ModuleInfo).
+intermod_info_set_write_header(Info, Info ^ im_write_foreign_header := yes).
+intermod_info_set_var_types(VarTypes, Info, Info ^ im_var_types := VarTypes).
+intermod_info_set_tvarset(TVarSet, Info, Info ^ im_tvarset := TVarSet).
 
 %-----------------------------------------------------------------------------%
 
@@ -2228,34 +2196,35 @@
 	).
 
 %-----------------------------------------------------------------------------%
+
 	% Read in and process the optimization interfaces.
 
-intermod__grab_optfiles(Module0, Module, FoundError) -->
+intermod__grab_optfiles(!Module, FoundError, !IO) :-
 
 		%
 		% Read in the .opt files for imported and ancestor modules.
 		%
-	{ ModuleName = Module0 ^ module_name },
-	{ Ancestors0 = Module0 ^ parent_deps },
-	{ InterfaceDeps0 = Module0 ^ int_deps },
-	{ ImplementationDeps0 = Module0 ^ impl_deps },
-	{ OptFiles = list__sort_and_remove_dups(list__condense(
-		[Ancestors0, InterfaceDeps0, ImplementationDeps0])) },
+	ModuleName = !.Module ^ module_name,
+	Ancestors0 = !.Module ^ parent_deps,
+	InterfaceDeps0 = !.Module ^ int_deps,
+	ImplementationDeps0 = !.Module ^ impl_deps,
+	OptFiles = list__sort_and_remove_dups(list__condense(
+		[Ancestors0, InterfaceDeps0, ImplementationDeps0])),
 	globals__io_lookup_bool_option(read_opt_files_transitively,
-		Transitive),
-	{ ModulesProcessed = set__insert(set__sorted_list_to_set(OptFiles),
-				ModuleName) },
+		Transitive, !IO),
+	ModulesProcessed = set__insert(set__sorted_list_to_set(OptFiles),
+		ModuleName),
 	read_optimization_interfaces(Transitive, ModuleName, OptFiles,
-		ModulesProcessed, [], OptItems, no, OptError),
+		ModulesProcessed, [], OptItems, no, OptError, !IO),
 
 		%
 		% Append the items to the current item list, using
 		% a `opt_imported' psuedo-declaration to let
 		% make_hlds know the opt_imported stuff is coming.
 		%
-	{ module_imports_get_items(Module0, Items0) },
-	{ Items1 = Items0 ++ [make_pseudo_decl(opt_imported) | OptItems] },
-	{ module_imports_set_items(Module0, Items1, Module1) },
+	module_imports_get_items(!.Module, Items0),
+	Items1 = Items0 ++ [make_pseudo_decl(opt_imported) | OptItems],
+	module_imports_set_items(Items1, !Module),
 
 		%
 		% Get the :- pragma unused_args(...) declarations created
@@ -2264,70 +2233,67 @@
 		% with intermod_unused_args, but the interface for other
 		% modules must remain the same.
 		%
-	globals__io_lookup_bool_option(intermod_unused_args, UnusedArgs),
-	( { UnusedArgs = yes } ->
+	globals__io_lookup_bool_option(intermod_unused_args, UnusedArgs, !IO),
+	(
+		UnusedArgs = yes,
 		read_optimization_interfaces(no, ModuleName, [ModuleName],
-				set__init, [], LocalItems, no, UAError),
-		{ IsPragmaUnusedArgs = (pred(Item::in) is semidet :-
+			set__init, [], LocalItems, no, UAError, !IO),
+		IsPragmaUnusedArgs = (pred(Item::in) is semidet :-
 					Item = pragma(PragmaType) - _,
 					PragmaType = unused_args(_,_,_,_,_)
-			) },
-		{ list__filter(IsPragmaUnusedArgs, LocalItems, PragmaItems) },
+		),
+		list__filter(IsPragmaUnusedArgs, LocalItems, PragmaItems),
 
-		{ module_imports_get_items(Module1, Items2) },
-		{ list__append(Items2, PragmaItems, Items) },
-		{ module_imports_set_items(Module1, Items, Module2) }
+		module_imports_get_items(!.Module, Items2),
+		list__append(Items2, PragmaItems, Items),
+		module_imports_set_items(Items, !Module)
 	;
-		{ Module2 = Module1 },
-		{ UAError = no }
+		UnusedArgs = no,
+		UAError = no
 	),
 
 		%
 		% Read .int0 files required by the `.opt' files.
 		%
-	{ Int0Files = list__delete_all(
+	Int0Files = list__delete_all(
 			list__condense(list__map(get_ancestors, OptFiles)),
-			ModuleName) },
+		ModuleName),
 	process_module_private_interfaces(ReadModules, Int0Files,
 			make_pseudo_decl(opt_imported),
 			make_pseudo_decl(opt_imported),
 			[], AncestorImports1,
-			[], AncestorImports2, Module2, Module3),
+		[], AncestorImports2, !Module, !IO),
 
 		%
 		% Figure out which .int files are needed by the .opt files
 		%
-	{ get_dependencies(OptItems, NewImportDeps0, NewUseDeps0) },
-	globals__io_get_globals(Globals),
-	{ get_implicit_dependencies(OptItems, Globals,
-		NewImplicitImportDeps0, NewImplicitUseDeps0) },
-	{ NewDeps = list__sort_and_remove_dups(list__condense(
+	get_dependencies(OptItems, NewImportDeps0, NewUseDeps0),
+	globals__io_get_globals(Globals, !IO),
+	get_implicit_dependencies(OptItems, Globals,
+		NewImplicitImportDeps0, NewImplicitUseDeps0),
+	NewDeps = list__sort_and_remove_dups(list__condense(
 		[NewImportDeps0, NewUseDeps0,
 		NewImplicitImportDeps0, NewImplicitUseDeps0,
-		AncestorImports1, AncestorImports2])) },
+		AncestorImports1, AncestorImports2])),
 
 		%
 		% Read in the .int, and .int2 files needed by the .opt files.
 		%
-	{ map__init(ReadModules) },
+	map__init(ReadModules),
 	process_module_long_interfaces(ReadModules, must_be_qualified, NewDeps,
 			".int",
-			make_pseudo_decl(opt_imported),
-			make_pseudo_decl(opt_imported),
-			[], NewIndirectDeps, [], NewImplIndirectDeps,
-			Module3, Module4),
+		make_pseudo_decl(opt_imported), make_pseudo_decl(opt_imported),
+		[], NewIndirectDeps, [], NewImplIndirectDeps, !Module, !IO),
 	process_module_short_interfaces_and_impls_transitively(
-			ReadModules, NewIndirectDeps ++ NewImplIndirectDeps,
-			".int2",
-			make_pseudo_decl(opt_imported),
-			make_pseudo_decl(opt_imported),
-			Module4, Module),
+		ReadModules, NewIndirectDeps ++ NewImplIndirectDeps, ".int2",
+		make_pseudo_decl(opt_imported), make_pseudo_decl(opt_imported),
+		!Module, !IO),
 
 		%
 		% Figure out whether anything went wrong
 		%
-	{ module_imports_get_error(Module, FoundError0) },
-	{
+	module_imports_get_error(!.Module, FoundError0),
+	(
 		( FoundError0 \= no_module_errors
 		; OptError = yes
 		; UAError = yes
@@ -2336,36 +2302,35 @@
 		FoundError = yes
 	;
 		FoundError = no
-	}.
+	).
 
 :- pred read_optimization_interfaces(bool::in, module_name::in,
 	list(module_name)::in, set(module_name)::in,
 	item_list::in, item_list::out, bool::in, bool::out,
-	io__state::di, io__state::uo) is det.
+	io::di, io::uo) is det.
 
-read_optimization_interfaces(_, _, [], _, Items, Items, Error, Error) --> [].
+read_optimization_interfaces(_, _, [], _, !Items, !Error, !IO).
 read_optimization_interfaces(Transitive, ModuleName,
 		[ModuleToRead | ModulesToRead], ModulesProcessed0,
-		Items0, Items, Error0, Error) -->
-	globals__io_lookup_bool_option(very_verbose, VeryVerbose),
+		!Items, !Error, !IO) :-
+	globals__io_lookup_bool_option(very_verbose, VeryVerbose, !IO),
 	maybe_write_string(VeryVerbose,
-			"% Reading optimization interface for module"),
-	maybe_write_string(VeryVerbose, " `"),
-	{ prog_out__sym_name_to_string(ModuleToRead, ModuleToReadString) },
-	maybe_write_string(VeryVerbose, ModuleToReadString),
-	maybe_write_string(VeryVerbose, "'...\n"),
-	maybe_flush_output(VeryVerbose),
+		"% Reading optimization interface for module", !IO),
+	maybe_write_string(VeryVerbose, " `", !IO),
+	prog_out__sym_name_to_string(ModuleToRead, ModuleToReadString),
+	maybe_write_string(VeryVerbose, ModuleToReadString, !IO),
+	maybe_write_string(VeryVerbose, "'...\n", !IO),
+	maybe_flush_output(VeryVerbose, !IO),
 
-	module_name_to_search_file_name(ModuleToRead, ".opt", FileName),
+	module_name_to_search_file_name(ModuleToRead, ".opt", FileName, !IO),
 	prog_io__read_opt_file(FileName, ModuleToRead,
-			ModuleError, Messages, OptItems),
-	update_error_status(opt, FileName, ModuleError, Messages,
-			Error0, Error1),
-	{ Items1 = Items0 ++ OptItems },
-	maybe_write_string(VeryVerbose, "% done.\n"),
+		ModuleError, Messages, OptItems, !IO),
+	update_error_status(opt, FileName, ModuleError, Messages, !Error, !IO),
+	!:Items = !.Items ++ OptItems,
+	maybe_write_string(VeryVerbose, "% done.\n", !IO),
 
-	globals__io_get_globals(Globals),
-	{ Transitive = yes ->
+	globals__io_get_globals(Globals, !IO),
+	( Transitive = yes ->
 		get_dependencies(OptItems, NewImportDeps0, NewUseDeps0),
 		get_implicit_dependencies(OptItems, Globals,
 			NewImplicitImportDeps0, NewImplicitUseDeps0),
@@ -2379,43 +2344,44 @@
 	;
 		ModulesProcessed = ModulesProcessed0,
 		NewDeps = []
-	},
+	),
 	read_optimization_interfaces(Transitive, ModuleName,
 		NewDeps ++ ModulesToRead, ModulesProcessed,
-		Items1, Items, Error1, Error).
+		!Items, !Error, !IO).
 
 update_error_status(FileType, FileName, ModuleError, Messages,
-		Error0, Error1) -->
+		!Error, !IO) :-
 	(
-		{ ModuleError = no_module_errors },
-		{ Error1 = Error0 }
+		ModuleError = no_module_errors
 	;
-		{ ModuleError = some_module_errors },
-		prog_out__write_messages(Messages),
-		{ Error1 = yes }
+		ModuleError = some_module_errors,
+		prog_out__write_messages(Messages, !IO),
+		!:Error = yes
 	;
-		{ ModuleError = fatal_module_errors },
-		{
+		ModuleError = fatal_module_errors,
+		(
 			FileType = opt,
 			WarningOption = warn_missing_opt_files
 		;
 			FileType = trans_opt,
 			WarningOption = warn_missing_trans_opt_files
-		},
-		globals__io_lookup_bool_option(WarningOption, DoWarn),
-		( { DoWarn = yes } ->
-			io__write_string("Warning: cannot open `"),
-			io__write_string(FileName),
-			io__write_string("'.\n"),
+		),
+		globals__io_lookup_bool_option(WarningOption, DoWarn, !IO),
+		(
+			DoWarn = yes,
+			io__write_string("Warning: cannot open `", !IO),
+			io__write_string(FileName, !IO),
+			io__write_string("'.\n", !IO),
 			globals__io_lookup_bool_option(halt_at_warn,
-					HaltAtWarn),
-			{ HaltAtWarn = yes ->
-				Error1 = yes
+				HaltAtWarn, !IO),
+			(
+				HaltAtWarn = yes,
+				!:Error = yes
 			;
-				Error1 = Error0
-			}
+				HaltAtWarn = no
+			)
 		;
-			{ Error1 = Error0 }	
+			DoWarn = no
 		)
 	).
 
Index: compiler/ite_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ite_gen.m,v
retrieving revision 1.73
diff -u -b -r1.73 ite_gen.m
--- compiler/ite_gen.m	23 Mar 2004 10:52:04 -0000	1.73
+++ compiler/ite_gen.m	7 Jun 2004 08:49:55 -0000
@@ -425,15 +425,15 @@
 		],
 		PNegCondCode = node([
 			pragma_c([], PNegCondComponents, will_not_call_mercury,
-				no, no, no, no, yes) - ""
+				no, no, no, no, yes, yes) - ""
 		]),
 		PNegThenCode = node([
 			pragma_c([], PNegThenComponents, will_not_call_mercury,
-				no, no, no, no, yes) - ""
+				no, no, no, no, yes, yes) - ""
 		]),
 		PNegElseCode = node([
 			pragma_c([], PNegElseComponents, will_not_call_mercury,
-				no, no, no, no, yes) - ""
+				no, no, no, no, yes, yes) - ""
 		])
 	;
 		UseMinimalModel = no,
Index: compiler/jumpopt.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/jumpopt.m,v
retrieving revision 1.71
diff -u -b -r1.71 jumpopt.m
--- compiler/jumpopt.m	23 May 2004 23:14:27 -0000	1.71
+++ compiler/jumpopt.m	7 Jun 2004 08:49:55 -0000
@@ -697,6 +697,8 @@
 		% When debugging is enabled, size is in any case more important
 		% than the last bit of speed.
 		InstrMayBeDuplicated = no
+	; Instr ^ pragma_c_maybe_dupl = no ->
+		InstrMayBeDuplicated = no
 	;
 		InstrMayBeDuplicated = yes
 	).
Index: compiler/lambda.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/lambda.m,v
retrieving revision 1.88
diff -u -b -r1.88 lambda.m
--- compiler/lambda.m	20 May 2004 22:18:35 -0000	1.88
+++ compiler/lambda.m	7 Jun 2004 08:49:55 -0000
@@ -72,11 +72,10 @@
 :- import_module hlds__hlds_module.
 :- import_module hlds__hlds_pred.
 
-:- pred lambda__process_module(module_info, module_info).
-:- mode lambda__process_module(in, out) is det.
+:- pred lambda__process_module(module_info::in, module_info::out) is det.
 
-:- pred lambda__process_pred(pred_id, module_info, module_info).
-:- mode lambda__process_pred(in, in, out) is det.
+:- pred lambda__process_pred(pred_id::in, module_info::in, module_info::out)
+	is det.
 
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
@@ -136,8 +135,8 @@
 	% Need update the dependency graph to include the lambda predicates. 
 	module_info_clobber_dependency_info(ModuleInfo1, ModuleInfo).
 
-:- pred lambda__process_preds(list(pred_id), module_info, module_info).
-:- mode lambda__process_preds(in, in, out) is det.
+:- pred lambda__process_preds(list(pred_id)::in,
+	module_info::in, module_info::out) is det.
 
 lambda__process_preds([], ModuleInfo, ModuleInfo).
 lambda__process_preds([PredId | PredIds], ModuleInfo0, ModuleInfo) :-
@@ -149,16 +148,16 @@
 	ProcIds = pred_info_procids(PredInfo),
 	lambda__process_procs(PredId, ProcIds, ModuleInfo0, ModuleInfo).
 
-:- pred lambda__process_procs(pred_id, list(proc_id), module_info, module_info).
-:- mode lambda__process_procs(in, in, in, out) is det.
+:- pred lambda__process_procs(pred_id::in, list(proc_id)::in,
+	module_info::in, module_info::out) is det.
 
 lambda__process_procs(_PredId, [], ModuleInfo, ModuleInfo).
 lambda__process_procs(PredId, [ProcId | ProcIds], ModuleInfo0, ModuleInfo) :-
 	lambda__process_proc(PredId, ProcId, ModuleInfo0, ModuleInfo1),
 	lambda__process_procs(PredId, ProcIds, ModuleInfo1, ModuleInfo).
 
-:- pred lambda__process_proc(pred_id, proc_id, module_info, module_info).
-:- mode lambda__process_proc(in, in, in, out) is det.
+:- pred lambda__process_proc(pred_id::in, proc_id::in,
+	module_info::in, module_info::out) is det.
 
 lambda__process_proc(PredId, ProcId, !ModuleInfo) :-
 	module_info_preds(!.ModuleInfo, PredTable0),
@@ -225,96 +224,91 @@
 	pred_info_set_typevarset(TypeVarSet, !PredInfo),
 	pred_info_set_class_context(Constraints, !PredInfo).
 
-:- pred lambda__process_goal(hlds_goal, hlds_goal,
-					lambda_info, lambda_info).
-:- mode lambda__process_goal(in, out, in, out) is det.
-
-lambda__process_goal(Goal0 - GoalInfo0, Goal) -->
-	lambda__process_goal_2(Goal0, GoalInfo0, Goal).
-
-:- pred lambda__process_goal_2(hlds_goal_expr, hlds_goal_info,
-					hlds_goal, lambda_info, lambda_info).
-:- mode lambda__process_goal_2(in, in, out, in, out) is det.
+:- pred lambda__process_goal(hlds_goal::in, hlds_goal::out,
+	lambda_info::in, lambda_info::out) is det.
+
+lambda__process_goal(Goal0 - GoalInfo0, Goal, !Info) :-
+	lambda__process_goal_2(Goal0, GoalInfo0, Goal, !Info).
+
+:- pred lambda__process_goal_2(hlds_goal_expr::in, hlds_goal_info::in,
+	hlds_goal::out, lambda_info::in, lambda_info::out) is det.
 
 lambda__process_goal_2(unify(XVar, Y, Mode, Unification, Context), GoalInfo,
-			Unify - GoalInfo) -->
-	( { Y = lambda_goal(Purity, PredOrFunc, EvalMethod, _, NonLocalVars,
-			Vars, Modes, Det, LambdaGoal0) } ->
+			Unify - GoalInfo, !Info) :-
+	(
+		Y = lambda_goal(Purity, PredOrFunc, EvalMethod, _,
+			NonLocalVars, Vars, Modes, Det, LambdaGoal0)
+	->
 		% first, process the lambda goal recursively, in case it
 		% contains some nested lambda expressions.
-		lambda__process_goal(LambdaGoal0, LambdaGoal1),
+		lambda__process_goal(LambdaGoal0, LambdaGoal1, !Info),
 
 		% then, convert the lambda expression into a new predicate
 		lambda__process_lambda(Purity, PredOrFunc, EvalMethod, Vars,
 			Modes, Det, NonLocalVars, LambdaGoal1, 
-			Unification, Y1, Unification1),
-		{ Unify = unify(XVar, Y1, Mode, Unification1, Context) }
+			Unification, Y1, Unification1, !Info),
+		Unify = unify(XVar, Y1, Mode, Unification1, Context)
 	;
 		% ordinary unifications are left unchanged
-		{ Unify = unify(XVar, Y, Mode, Unification, Context) }
+		Unify = unify(XVar, Y, Mode, Unification, Context)
 	).
 
 	% the rest of the clauses just process goals recursively
 
-lambda__process_goal_2(conj(Goals0), GoalInfo, conj(Goals) - GoalInfo) -->
-	lambda__process_goal_list(Goals0, Goals).
+lambda__process_goal_2(conj(Goals0), GoalInfo, conj(Goals) - GoalInfo,
+		!Info) :-
+	lambda__process_goal_list(Goals0, Goals, !Info).
 lambda__process_goal_2(par_conj(Goals0), GoalInfo,
-		par_conj(Goals) - GoalInfo) -->
-	lambda__process_goal_list(Goals0, Goals).
-lambda__process_goal_2(disj(Goals0), GoalInfo, disj(Goals) - GoalInfo)
-		-->
-	lambda__process_goal_list(Goals0, Goals).
-lambda__process_goal_2(not(Goal0), GoalInfo, not(Goal) - GoalInfo) -->
-	lambda__process_goal(Goal0, Goal).
+		par_conj(Goals) - GoalInfo, !Info) :-
+	lambda__process_goal_list(Goals0, Goals, !Info).
+lambda__process_goal_2(disj(Goals0), GoalInfo, disj(Goals) - GoalInfo,
+		!Info) :-
+	lambda__process_goal_list(Goals0, Goals, !Info).
+lambda__process_goal_2(not(Goal0), GoalInfo, not(Goal) - GoalInfo, !Info) :-
+	lambda__process_goal(Goal0, Goal, !Info).
 lambda__process_goal_2(switch(Var, CanFail, Cases0), GoalInfo, 
-			switch(Var, CanFail, Cases) - GoalInfo) -->
-	lambda__process_cases(Cases0, Cases).
+		switch(Var, CanFail, Cases) - GoalInfo, !Info) :-
+	lambda__process_cases(Cases0, Cases, !Info).
 lambda__process_goal_2(some(Vars, CanRemove, Goal0), GoalInfo,
-			some(Vars, CanRemove, Goal) - GoalInfo) -->
-	lambda__process_goal(Goal0, Goal).
-lambda__process_goal_2(if_then_else(Vars, A0, B0, C0), GoalInfo,
-			if_then_else(Vars, A, B, C) - GoalInfo) -->
-	lambda__process_goal(A0, A),
-	lambda__process_goal(B0, B),
-	lambda__process_goal(C0, C).
-lambda__process_goal_2(generic_call(A,B,C,D), GoalInfo,
-			generic_call(A,B,C,D) - GoalInfo) -->
-	[].
-lambda__process_goal_2(call(A,B,C,D,E,F), GoalInfo,
-			call(A,B,C,D,E,F) - GoalInfo) -->
-	[].
-lambda__process_goal_2(foreign_proc(A,B,C,D,E,F,G), GoalInfo,
-			foreign_proc(A,B,C,D,E,F,G) - GoalInfo) -->
-	[].
-lambda__process_goal_2(shorthand(_), _, _) -->
+		some(Vars, CanRemove, Goal) - GoalInfo, !Info) :-
+	lambda__process_goal(Goal0, Goal, !Info).
+lambda__process_goal_2(if_then_else(Vars, Cond0, Then0, Else0), GoalInfo,
+		if_then_else(Vars, Cond, Then, Else) - GoalInfo, !Info) :-
+	lambda__process_goal(Cond0, Cond, !Info),
+	lambda__process_goal(Then0, Then, !Info),
+	lambda__process_goal(Else0, Else, !Info).
+lambda__process_goal_2(Goal @ generic_call(_, _, _, _), GoalInfo,
+		Goal - GoalInfo, !Info).
+lambda__process_goal_2(Goal @ call(_, _, _, _, _, _), GoalInfo,
+		Goal - GoalInfo, !Info).
+lambda__process_goal_2(Goal @ foreign_proc(_, _, _, _, _, _), GoalInfo,
+		Goal - GoalInfo, !Info).
+lambda__process_goal_2(shorthand(_), _, _, !Info) :-
 	% these should have been expanded out by now
-	{ error("lambda__process_goal_2: unexpected shorthand") }.
+	error("lambda__process_goal_2: unexpected shorthand").
 
-:- pred lambda__process_goal_list(list(hlds_goal), list(hlds_goal),
-					lambda_info, lambda_info).
-:- mode lambda__process_goal_list(in, out, in, out) is det.
-
-lambda__process_goal_list([], []) --> [].
-lambda__process_goal_list([Goal0 | Goals0], [Goal | Goals]) -->
-	lambda__process_goal(Goal0, Goal),
-	lambda__process_goal_list(Goals0, Goals).
-
-:- pred lambda__process_cases(list(case), list(case),
-					lambda_info, lambda_info).
-:- mode lambda__process_cases(in, out, in, out) is det.
+:- pred lambda__process_goal_list(list(hlds_goal)::in, list(hlds_goal)::out,
+	lambda_info::in, lambda_info::out) is det.
 
-lambda__process_cases([], []) --> [].
+lambda__process_goal_list([], [], !Info).
+lambda__process_goal_list([Goal0 | Goals0], [Goal | Goals], !Info) :-
+	lambda__process_goal(Goal0, Goal, !Info),
+	lambda__process_goal_list(Goals0, Goals, !Info).
+
+:- pred lambda__process_cases(list(case)::in, list(case)::out,
+	lambda_info::in, lambda_info::out) is det.
+
+lambda__process_cases([], [], !Info).
 lambda__process_cases([case(ConsId, Goal0) | Cases0],
-		[case(ConsId, Goal) | Cases]) -->
-	lambda__process_goal(Goal0, Goal),
-	lambda__process_cases(Cases0, Cases).
-
-:- pred lambda__process_lambda(purity, pred_or_func, lambda_eval_method,
-		list(prog_var), list(mode), determinism, list(prog_var),
-		hlds_goal, unification, unify_rhs, unification,
-		lambda_info, lambda_info).
-:- mode lambda__process_lambda(in, in, in, in, in, in, in, in, in, out, out,
-		in, out) is det.
+		[case(ConsId, Goal) | Cases], !Info) :-
+	lambda__process_goal(Goal0, Goal, !Info),
+	lambda__process_cases(Cases0, Cases, !Info).
+
+:- pred lambda__process_lambda(purity::in, pred_or_func::in,
+	lambda_eval_method::in, list(prog_var)::in, list(mode)::in,
+	determinism::in, list(prog_var)::in, hlds_goal::in, unification::in,
+	unify_rhs::out, unification::out, lambda_info::in, lambda_info::out)
+	is det.
 
 lambda__process_lambda(Purity, PredOrFunc, EvalMethod, Vars, Modes, Detism,
 		OrigNonLocals0, LambdaGoal, Unification0, Functor,
@@ -583,8 +577,8 @@
 		InstVarSet, TVarMap, TCVarMap, Markers, POF, OrigPredName,
 		Owner, ModuleInfo, MustRecomputeNonLocals).
 
-:- pred lambda__constraint_contains_vars(list(tvar), class_constraint).
-:- mode lambda__constraint_contains_vars(in, in) is semidet.
+:- pred lambda__constraint_contains_vars(list(tvar)::in, class_constraint::in)
+	is semidet.
 
 lambda__constraint_contains_vars(LambdaVars, ClassConstraint) :-
 	ClassConstraint = constraint(_, ConstraintTypes),
@@ -596,8 +590,8 @@
 	set__list_to_set(ConstraintVars, ConstraintVarsSet),
 	set__subset(ConstraintVarsSet, LambdaVarsSet).
 
-:- pred lambda__uni_modes_to_modes(list(uni_mode), list(mode)).
-:- mode lambda__uni_modes_to_modes(in, out) is det.
+:- pred lambda__uni_modes_to_modes(list(uni_mode)::in, list(mode)::out)
+	is det.
 
 	% This predicate works out the modes of the original non-local
 	% variables of a lambda expression based on the list of uni_mode
Index: compiler/layout_out.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/layout_out.m,v
retrieving revision 1.34
diff -u -b -r1.34 layout_out.m
--- compiler/layout_out.m	23 May 2004 23:14:28 -0000	1.34
+++ compiler/layout_out.m	7 Jun 2004 08:49:55 -0000
@@ -1616,6 +1616,14 @@
 		Step = table_trie_step_poly,
 		StepType = "MR_TABLE_STEP_POLY",
 		MaybeEnumParam = no
+	;
+		Step = table_trie_step_typeinfo,
+		StepType = "MR_TABLE_STEP_TYPEINFO",
+		MaybeEnumParam = no
+	;
+		Step = table_trie_step_typeclassinfo,
+		StepType = "MR_TABLE_STEP_TYPECLASSINFO",
+		MaybeEnumParam = no
 	),
 	io__write_string(StepType, !IO),
 	io__write_string(",\n", !IO),
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list