[m-dev.] for review: update alias branch

Simon Taylor stayl at cs.mu.OZ.AU
Wed Dec 22 12:39:36 AEDT 1999


Hi,

David Overton, could you please review this.

The diff below just includes the interesting bits, the full diff is in
/home/mercury1/stayl/amergediff22-12-1999.

Simon.



Estimated hours taken: 20

Merge changes into the alias branch up to trunk_snapshot_19991217154951.

compiler/quantification.m:
	When processing a bi-implication, rename apart the local
	variables in the goals duplicated when the 
	Without this change, the code generator aborts during
	compilation of tests/hard_coded/quantifier2.m.
	This fix will be committed to the main branch as well.

compiler/mode_util.m:
compiler/modecheck_unify.m:
	Add a predicate fix_type_info_cons_id_arity to adjust
	the arity of `type_info' and `typeclass_info' cons_ids
	to match the number of arguments.
	In recompute_instmap_delta_unify, duplicate a fix Fergus
	made to modecheck_unify.m (revision 1.41) where the arity
	of type_infos did not match the number of arguments.
	Test case: tests/hard_coded/typeclasses/
			existential_data_types_regr_test.m	

compiler/modes.m:
	Return an instmap_delta from modecheck_functor_test to
	be put in the instmap_delta field of each case of a switch.

compiler/mode_util.m:
	Add functions to make it easier to construct uni_modes.	

compiler/make_hlds.m:
	Don't add `:- pragma type_spec' declarations to the module_info -
	user-guided type specialization does not yet work on the alias
	branch.

compiler/handle_options.m:
	Make sure that optimizations which do not work on the alias
	branch are not enabled so that test cases for which options
	are passed to enable those optimizations do not fail.

compiler/ml_code_gen.m:
	Thread an instmap through to be passed to mode_is_input, etc.
	
compiler/*.m:
	Assorted trivial changes.


--- ../../../amerge2/mercury/compiler/handle_options.m	Thu Dec 16 17:16:04 1999
+++ handle_options.m	Fri Dec 17 09:09:40 1999
@@ -485,7 +485,14 @@
 
 	% --optimize-frames requires --optimize-labels and --optimize-jumps
 	option_implies(optimize_frames, optimize_labels, bool(yes)),
-	option_implies(optimize_frames, optimize_jumps, bool(yes)).
+	option_implies(optimize_frames, optimize_jumps, bool(yes)),
+	
+	% Various optimizations which don't yet work on the alias branch.
+	globals__io_set_option(optimize_higher_order, bool(no)),
+	globals__io_set_option(user_guided_type_specialization, bool(no)),
+	globals__io_set_option(type_specialization, bool(no)),
+	globals__io_set_option(deforestation, bool(no)),
+	globals__io_set_option(common_struct, bool(no)).
 
 % option_implies(SourceBoolOption, ImpliedOption, ImpliedOptionValue, IO0, IO).
 % If the SourceBoolOption is set to yes, then the ImpliedOption is set
--- ../../../amerge2/mercury/compiler/make_hlds.m	Thu Dec 16 17:16:35 1999
+++ make_hlds.m	Wed Dec 22 11:37:56 1999
@@ -987,7 +987,11 @@
 		TypeSpecInfo = type_spec_info(ProcsToSpec,
 			ForceVersions, SpecMap, PragmaMap),
 		module_info_set_type_spec_info(ModuleInfo3,
-			TypeSpecInfo, ModuleInfo)
+			TypeSpecInfo, _ModuleInfo),
+
+		% YYY type specialization does not yet work on the
+		% alias branch.	
+		ModuleInfo = ModuleInfo0
 	    ;
 	   	ModuleInfo = ModuleInfo2
 	    }
--- ../../../amerge2/mercury/compiler/ml_code_gen.m	Thu Dec 16 17:16:41 1999
+++ ml_code_gen.m	Fri Dec 17 15:44:06 1999
@@ -614,8 +614,8 @@
 :- import_module export, llds_out. % XXX needed for pragma C code
 :- import_module code_util. % XXX needed for `code_util__compiler_generated'.
 			    % and `code_util__cons_id_to_tag'.
-:- import_module goal_util.
-:- import_module hlds_goal, hlds_data, prog_data, special_pred.
+:- import_module goal_util, instmap, inst_table.
+:- import_module hlds_pred, hlds_goal, hlds_data, prog_data, special_pred.
 :- import_module hlds_out, builtin_ops, passes_aux, type_util, mode_util.
 :- import_module prog_util.
 :- import_module globals, options.
@@ -1364,7 +1364,7 @@
 	{ error("ml_gen_goal_expr: unexpected bi_implication") }.
 
 :- pred ml_gen_ordinary_pragma_c_code(code_model, pragma_c_code_attributes,
-		pred_id, proc_id, list(prog_var), list(maybe(pair(string, mode))),
+		pred_id, proc_id, list(prog_var), pragma_c_code_arg_info,
 		list(prog_type), string, prog_context,
 		mlds__defns, mlds__statements, ml_gen_info, ml_gen_info).
 :- mode ml_gen_ordinary_pragma_c_code(in, in, in, in, in, in, 
@@ -1409,8 +1409,10 @@
 	% Java.
 	%
 ml_gen_ordinary_pragma_c_code(CodeModel, Attributes,
-		PredId, _ProcId, ArgVars, ArgDatas, OrigArgTypes,
+		PredId, _ProcId, ArgVars, ArgDatas0, OrigArgTypes,
 		C_Code, Context, MLDS_Decls, MLDS_Statements) -->
+	{ ArgDatas0 = pragma_c_code_arg_info(InstTable, ArgDatas) },
+
 	%
 	% Combine all the information about the each arg
 	%
@@ -1422,15 +1424,21 @@
 	%
 	{ ml_gen_pragma_c_decls(ArgList, ArgDeclsList) },
 
+	% The modes of the C code should not depend on the
+	% aliasing information in the instmap.
+	{ instmap__init_reachable(InstMap) },
+
 	%
 	% Generate code to set the values of the input variables.
 	%
-	list__map_foldl(ml_gen_pragma_c_input_arg, ArgList, AssignInputsList),
+	list__map_foldl(ml_gen_pragma_c_input_arg(InstMap, InstTable),
+		ArgList, AssignInputsList),
 
 	%
 	% Generate code to assign the values of the output variables.
 	%
-	list__map_foldl(ml_gen_pragma_c_output_arg, ArgList, AssignOutputsList),
+	list__map_foldl(ml_gen_pragma_c_output_arg(InstMap, InstTable),
+		ArgList, AssignOutputsList),
 
 	%
 	% Generate code fragments to obtain and release the global lock
@@ -1595,17 +1603,20 @@
 % ml_gen_pragma_c_input_arg generates C code to assign the value of an input
 % arg for a `pragma c_code' declaration.
 %
-:- pred ml_gen_pragma_c_input_arg(ml_c_arg::in, string::out,
+:- pred ml_gen_pragma_c_input_arg(instmap::in, inst_table::in,
+		ml_c_arg::in, string::out,
 		ml_gen_info::in, ml_gen_info::out) is det.
 
-ml_gen_pragma_c_input_arg(ml_c_arg(Var, MaybeNameAndMode, OrigType),
+ml_gen_pragma_c_input_arg(InstMap, InstTable,
+		ml_c_arg(Var, MaybeNameAndMode, OrigType),
 		AssignInputString) -->
 	=(MLDSGenInfo),
 	{ ml_gen_info_get_module_info(MLDSGenInfo, ModuleInfo) },
 	(
 		{ MaybeNameAndMode = yes(ArgName - Mode) },
 		{ \+ var_is_singleton(ArgName) },
-		{ mode_to_arg_mode(ModuleInfo, Mode, OrigType, top_in) }
+		{ mode_to_arg_mode(InstMap, InstTable, ModuleInfo,
+			Mode, OrigType, top_in) }
 	->
 		ml_variable_type(Var, VarType),
 		ml_gen_var(Var, VarLval),
@@ -1633,10 +1644,12 @@
 % ml_gen_pragma_c_output_arg generates C code to assign the value of an output
 % arg for a `pragma c_code' declaration.
 %
-:- pred ml_gen_pragma_c_output_arg(ml_c_arg::in, string::out,
+:- pred ml_gen_pragma_c_output_arg(instmap::in, inst_table::in,
+		ml_c_arg::in, string::out,
 		ml_gen_info::in, ml_gen_info::out) is det.
 
-ml_gen_pragma_c_output_arg(ml_c_arg(Var, MaybeNameAndMode, OrigType),
+ml_gen_pragma_c_output_arg(InstMap, InstTable,
+		ml_c_arg(Var, MaybeNameAndMode, OrigType),
 		AssignOutputString) -->
 	=(MLDSGenInfo),
 	{ ml_gen_info_get_module_info(MLDSGenInfo, ModuleInfo) },
@@ -1644,7 +1657,8 @@
 		{ MaybeNameAndMode = yes(ArgName - Mode) },
 		{ \+ var_is_singleton(ArgName) },
 		{ \+ type_util__is_dummy_argument_type(OrigType) },
-		{ mode_to_arg_mode(ModuleInfo, Mode, OrigType, top_out) }
+		{ mode_to_arg_mode(InstMap, InstTable, ModuleInfo,
+			Mode, OrigType, top_out) }
 	->
 		ml_variable_type(Var, VarType),
 		ml_gen_var(Var, VarLval),
@@ -1687,12 +1701,12 @@
 % Code for procedure calls
 %
 
-:- pred ml_gen_generic_call(generic_call, list(prog_var), list(mode),
+:- pred ml_gen_generic_call(generic_call, list(prog_var), argument_modes,
 		code_model, prog_context, mlds__defns, mlds__statements,
 		ml_gen_info, ml_gen_info).
 :- mode ml_gen_generic_call(in, in, in, in, in, out, out, in, out) is det.
 
-ml_gen_generic_call(GenericCall, ArgVars, ArgModes, CodeModel, Context,
+ml_gen_generic_call(GenericCall, ArgVars, Modes, CodeModel, Context,
 		MLDS_Decls, MLDS_Statements) -->
 	%
 	% allocate some fresh type variables to use as the Mercury types
@@ -1710,9 +1724,12 @@
 	=(MLDSGenInfo),
 	{ ml_gen_info_get_module_info(MLDSGenInfo, ModuleInfo) },
 	{ ml_gen_info_get_varset(MLDSGenInfo, VarSet) },
+	{ ml_gen_info_get_instmap(MLDSGenInfo, InstMap) },
+	{ ml_gen_info_get_inst_table(MLDSGenInfo, InstTable) },
 	{ ArgNames = ml_gen_var_names(VarSet, ArgVars) },
+	{ Modes = argument_modes(_, ArgModes) },
 	{ Params0 = ml_gen_params(ModuleInfo, ArgNames,
-		BoxedArgTypes, ArgModes, CodeModel) },
+		BoxedArgTypes, ArgModes, InstMap, InstTable, CodeModel) },
 
 	%
 	% insert the `closure_arg' parameter
@@ -1750,8 +1767,8 @@
 	ml_gen_var_list(ArgVars, ArgLvals),
 	ml_variable_types(ArgVars, ActualArgTypes),
 	ml_gen_arg_list(ArgNames, ArgLvals, ActualArgTypes, BoxedArgTypes,
-		ArgModes, Context, InputRvals, OutputLvals, ConvArgDecls,
-		ConvOutputStatements),
+		ArgModes, InstMap, InstTable, Context, InputRvals, OutputLvals,
+		ConvArgDecls, ConvOutputStatements),
 	{ ClosureRval = unop(unbox(ClosureArgType), lval(ClosureLval)) },
 
 	%
@@ -1861,16 +1878,20 @@
 	{ module_info_pred_proc_info(ModuleInfo, PredId, ProcId,
 		PredInfo, ProcInfo) },
 	{ pred_info_arg_types(PredInfo, PredArgTypes) },
-	{ proc_info_argmodes(ProcInfo, ArgModes) },
+	{ proc_info_argmodes(ProcInfo, Modes) },
 
 	%
 	% Generate code to box/unbox the arguments
 	% and compute the list of properly converted rvals/lvals
 	% to pass as the function call's arguments and return values
 	%
+	{ Modes = argument_modes(InstTable, ArgModes) },
+	% The modes of the arguments do not depend on the argument
+	% substitutions in the instmap.
+	{ instmap__init_reachable(InstMap) },
 	ml_gen_arg_list(ArgNames, ArgLvals, ActualArgTypes, PredArgTypes,
-		ArgModes, Context, InputRvals, OutputLvals, ConvArgDecls,
-		ConvOutputStatements),
+		ArgModes, InstMap, InstTable, Context,
+		InputRvals, OutputLvals, ConvArgDecls, ConvOutputStatements),
 
 	%
 	% Construct a closure to generate the call
@@ -1983,14 +2004,16 @@
 % Generate rvals and lvals for the arguments of a procedure call
 %
 :- pred ml_gen_arg_list(list(var_name), list(mlds__lval), list(prog_type),
-		list(prog_type), list(mode), prog_context, list(mlds__rval),
-		list(mlds__lval), mlds__defns, mlds__statements,
+		list(prog_type), list(mode), instmap, inst_table,
+		prog_context, list(mlds__rval), list(mlds__lval),
+		mlds__defns, mlds__statements,
 		ml_gen_info, ml_gen_info).
-:- mode ml_gen_arg_list(in, in, in, in, in, in, out, out, out, out,
+:- mode ml_gen_arg_list(in, in, in, in, in, in, in, in, out, out, out, out,
 		in, out) is det.
 
-ml_gen_arg_list(VarNames, VarLvals, CallerTypes, CalleeTypes, Modes, Context,
-		InputRvals, OutputLvals, ConvDecls, ConvOutputStatements) -->
+ml_gen_arg_list(VarNames, VarLvals, CallerTypes, CalleeTypes, Modes,
+		InstMap, InstTable, Context, InputRvals,
+		OutputLvals, ConvDecls, ConvOutputStatements) -->
 	(
 		{ VarNames = [] },
 		{ VarLvals = [] },
@@ -2010,12 +2033,14 @@
 		{ Modes = [Mode | Modes1] }
 	->
 		ml_gen_arg_list(VarNames1, VarLvals1,
-			CallerTypes1, CalleeTypes1, Modes1, Context,
-			InputRvals1, OutputLvals1,
+			CallerTypes1, CalleeTypes1, Modes1, InstMap, InstTable,
+			Context, InputRvals1, OutputLvals1,
 			ConvDecls1, ConvOutputStatements1),
 		=(MLDSGenInfo),
 		{ ml_gen_info_get_module_info(MLDSGenInfo, ModuleInfo) },
-		( { type_util__is_dummy_argument_type(CalleeType) } ->
+		(
+			{ type_util__is_dummy_argument_type(CalleeType) }
+		->
 			%
 			% exclude arguments of type io__state etc.
 			%
@@ -2023,7 +2048,10 @@
 			{ OutputLvals = OutputLvals1 },
 			{ ConvDecls = ConvDecls1 },
 			{ ConvOutputStatements = ConvOutputStatements1 }
-		; { mode_to_arg_mode(ModuleInfo, Mode, CalleeType, top_in) } ->
+		;
+			{ mode_to_arg_mode(InstMap, InstTable, ModuleInfo,
+				Mode, CalleeType, top_in) }
+		->
 			%
 			% it's an input argument
 			%
@@ -2453,7 +2481,14 @@
 :- mode ml_gen_switch(in, in, in, in, in, out, out, in, out) is det.
 
 
-:- type extended_case ---> case(int, cons_tag, cons_id, hlds_goal).
+:- type extended_case
+	---> case(
+		int,
+		cons_tag,
+		cons_id,
+		instmap_delta,
+		hlds_goal
+	).
 :- type cases_list == list(extended_case).
 
 	% TODO: optimize various different special kinds of switches,
@@ -2490,11 +2525,11 @@
 
 ml_switch_lookup_tags([], _, []) --> [].
 ml_switch_lookup_tags([Case | Cases], Var, [TaggedCase | TaggedCases]) -->
-	{ Case = case(ConsId, Goal) },
+	{ Case = case(ConsId, IMDelta, Goal) },
 	ml_variable_type(Var, Type),
 	ml_cons_id_to_tag(ConsId, Type, Tag),
 	{ ml_switch_priority(Tag, Priority) },
-	{ TaggedCase = case(Priority, Tag, ConsId, Goal) },
+	{ TaggedCase = case(Priority, Tag, ConsId, IMDelta, Goal) },
 	ml_switch_lookup_tags(Cases, Var, TaggedCases).
 
 	% Return the priority of a tag test.
@@ -2536,7 +2571,11 @@
 	).
 ml_switch_generate_cases([Case | Cases], Var, CodeModel, CanFail, Context,
 		MLDS_Decls, MLDS_Statements) -->
-	{ Case = case(_, _Tag, ConsId, Goal) },
+	{ Case = case(_, _Tag, ConsId, IMDelta, Goal) },
+	=(MLDSGenInfo0),
+	{ ml_gen_info_get_instmap(MLDSGenInfo0, InstMap0) },
+	{ instmap__apply_instmap_delta(InstMap0, IMDelta, InstMap1) },
+	ml_gen_info_set_instmap(InstMap1),
 	(
 		{ Cases = [], CanFail = cannot_fail }
 	->
@@ -2545,6 +2584,7 @@
 		ml_gen_tag_test(Var, ConsId, TagTestDecls, TagTestStatements,
 			TagTestExpression),
 		ml_gen_goal(CodeModel, Goal, GoalStatement),
+		ml_gen_info_set_instmap(InstMap0),
 		ml_switch_generate_cases(Cases, Var, CodeModel, CanFail,
 			Context, RestDecls, RestStatements),
 		{ Rest = ml_gen_block(RestDecls, RestStatements, Context) },
@@ -2570,6 +2610,8 @@
 		MLDS_Decls, MLDS_Statements) -->
 	{ Cond = _ - CondGoalInfo },
 	{ goal_info_get_code_model(CondGoalInfo, CondCodeModel) },
+	=(MLDSGenInfo0),
+	{ ml_gen_info_get_instmap(MLDSGenInfo0, InstMap0) },
 	(
 		{ CondCodeModel = model_det },
 		% simplify.m should remove these
@@ -2591,7 +2633,9 @@
 		{ CondCodeModel = model_semi },
 		ml_gen_goal(model_semi, Cond, CondDecls, CondStatements),
 		ml_gen_test_success(Succeeded),
+		ml_gen_info_update_instmap(Cond),
 		ml_gen_goal(CodeModel, Then, ThenStatement),
+		ml_gen_info_set_instmap(InstMap0),
 		ml_gen_goal(CodeModel, Else, ElseStatement),
 		{ IfStmt = if_then_else(Succeeded, ThenStatement,
 			yes(ElseStatement)) },
@@ -2633,6 +2677,7 @@
 		{ CondCodeModel = model_non },
 
 		% generate the `then_func'
+		ml_gen_info_update_instmap(Cond),
 		ml_gen_new_func_label(ThenFuncLabel, ThenFuncLabelRval),
 		/* push nesting level */
 		{ Then = _ - ThenGoalInfo },
@@ -2650,9 +2695,11 @@
 		ml_get_env_ptr(EnvPtrRval),
 		{ SuccessCont = success_cont(ThenFuncLabelRval, EnvPtrRval) },
 		ml_gen_info_push_success_cont(SuccessCont),
+		ml_gen_info_set_instmap(InstMap0),
 		ml_gen_goal(model_non, Cond, CondDecls, CondStatements),
 		ml_gen_info_pop_success_cont,
 		ml_gen_test_success(Succeeded),
+		ml_gen_info_set_instmap(InstMap0),
 		ml_gen_goal(CodeModel, Else, ElseStatement),
 		{ IfStmt = if_then_else(unop(std_unop(not), Succeeded),
 			ElseStatement, no) },
@@ -2747,10 +2794,24 @@
 ml_gen_conj([First | Rest], CodeModel, Context,
 		MLDS_Decls, MLDS_Statements) -->
 	{ Rest = [_ | _] },
+	=(MLDSGenInfo0),
+	{ ml_gen_info_get_instmap(MLDSGenInfo0, InstMap0) },
 	{ First = _ - FirstGoalInfo },
 	{ goal_info_get_code_model(FirstGoalInfo, FirstCodeModel) },
-	{ DoGenFirst = ml_gen_goal(FirstCodeModel, First) },
-	{ DoGenRest = ml_gen_conj(Rest, CodeModel, Context) },
+	{ goal_info_get_instmap_delta(FirstGoalInfo, FirstInstMapDelta) },
+	{ instmap__apply_instmap_delta(InstMap0, FirstInstMapDelta,
+		InstMapAfterFirst) },
+	{ DoGenFirst =
+	    (pred(FirstDecls::out, FirstStatements::out, in, out) is det -->
+		ml_gen_info_set_instmap(InstMap0),
+		ml_gen_goal(FirstCodeModel, First, FirstDecls, FirstStatements)
+	    ) },
+	{ DoGenRest =
+	    (pred(RestDecls::out, RestStatements::out, in, out) is det -->
+	     	ml_gen_info_set_instmap(InstMapAfterFirst),	
+		ml_gen_conj(Rest, CodeModel, Context,
+			RestDecls, RestStatements)
+	    ) },
 	ml_combine_conj(FirstCodeModel, Context, DoGenFirst, DoGenRest,
 		MLDS_Decls, MLDS_Statements).
 
@@ -2960,6 +3021,10 @@
 ml_gen_disj([First | Rest], CodeModel, Context,
 		MLDS_Decls, MLDS_Statements) -->
 	{ Rest = [_ | _] },
+
+	=(MLDSGenInfo0),
+	{ ml_gen_info_get_instmap(MLDSGenInfo0, InstMap0) },
+
 	( { CodeModel = model_non } ->
 		%
 		% model_non disj:
@@ -2970,6 +3035,7 @@
 		%		<Goals && SUCCEED()>
 		%
 		ml_gen_goal(model_non, First, FirstDecls, FirstStatements),
+		ml_gen_info_set_instmap(InstMap0),
 		ml_gen_disj(Rest, model_non, Context,
 			RestDecls, RestStatements),
 		{ ml_join_decls(FirstDecls, FirstStatements,
@@ -3008,6 +3074,7 @@
 			ml_gen_goal(model_semi, First,
 				FirstDecls, FirstStatements),
 			ml_gen_test_success(Succeeded),
+			ml_gen_info_set_instmap(InstMap0),
 			ml_gen_disj(Rest, CodeModel, Context,
 				RestDecls, RestStatements),
 			{ RestStatement = ml_gen_block(RestDecls,
@@ -3369,8 +3436,10 @@
 	{ MLDS_ArgTypes0 = list__map(mercury_type_to_mlds_type, ArgTypes) },
 	=(Info),
 	{ ml_gen_info_get_module_info(Info, ModuleInfo) },
-	{ ml_gen_cons_args(ArgLvals, ArgTypes, ArgModes, ModuleInfo,
-		ArgRvals0) },
+	{ ml_gen_info_get_instmap(Info, InstMap) },
+	{ ml_gen_info_get_inst_table(Info, InstTable) },
+	{ ml_gen_cons_args(ArgLvals, ArgTypes, ArgModes, InstMap, InstTable,
+		ModuleInfo, ArgRvals0) },
 
 	%
 	% Compute the rval which holds the number of arguments
@@ -3497,7 +3566,8 @@
 	{ module_info_pred_proc_info(ModuleInfo, PredId, ProcId,
 		_PredInfo, ProcInfo) },
 	{ proc_info_headvars(ProcInfo, ProcHeadVars) },
-	{ proc_info_argmodes(ProcInfo, ProcArgModes) },
+	{ proc_info_argmodes(ProcInfo, ProcModes) },
+	{ ProcModes = argument_modes(InstTable, ProcArgModes) },
 	{ proc_info_interface_code_model(ProcInfo, CodeModel) },
 	{ proc_info_varset(ProcInfo, ProcVarSet) },
 	{ ProcArity = list__length(ProcHeadVars) },
@@ -3534,8 +3604,12 @@
 	},
 	{ WrapperHeadVarNames = ml_gen_wrapper_head_var_names(1,
 		list__length(WrapperHeadVars)) },
-	{ WrapperParams0 = ml_gen_params(ModuleInfo, WrapperHeadVarNames,
-		WrapperBoxedArgTypes, WrapperArgModes, CodeModel) },
+	% The argument modes do not depend on the alias substitutions
+	% in the instmap.
+	{ instmap__init_reachable(InstMap) },
+	{ WrapperParams0 = ml_gen_params(ModuleInfo,
+		WrapperHeadVarNames, WrapperBoxedArgTypes, WrapperArgModes,
+		InstMap, InstTable, CodeModel) },
 
 	% then insert the `closure_arg' parameter
 	{ ClosureArg = data(var("closure_arg")) - mlds__generic_env_ptr_type },
@@ -3677,7 +3751,12 @@
 		ml_qualify_var(Name, VarLval),
 		=(Info),
 		{ ml_gen_info_get_module_info(Info, ModuleInfo) },
-		{ mode_to_arg_mode(ModuleInfo, Mode, Type, top_in) ->
+		{ ml_gen_info_get_instmap(Info, InstMap) },
+		{ ml_gen_info_get_inst_table(Info, InstTable) },
+		{
+			mode_to_arg_mode(InstMap, InstTable,
+				ModuleInfo, Mode, Type, top_in)
+		->
 			Lval = VarLval
 		;
 			% output arguments are passed by reference,
@@ -3754,8 +3833,10 @@
 	{ MLDS_ArgTypes0 = list__map(mercury_type_to_mlds_type, ArgTypes) },
 	=(Info),
 	{ ml_gen_info_get_module_info(Info, ModuleInfo) },
-	{ ml_gen_cons_args(ArgLvals, ArgTypes, ArgModes, ModuleInfo,
-		ArgRvals0) },
+	{ ml_gen_info_get_instmap(Info, InstMap) },
+	{ ml_gen_info_get_inst_table(Info, InstTable) },
+	{ ml_gen_cons_args(ArgLvals, ArgTypes, ArgModes, InstMap, InstTable,
+		ModuleInfo, ArgRvals0) },
 
 	% 
 	% If there is a secondary tag, it goes in the first field
@@ -3809,11 +3890,15 @@
 	SizeofWordRval = lval(var(qual(MLDS_Module, "SIZEOF_WORD"))).
 
 :- pred ml_gen_cons_args(list(mlds__lval), list(prog_type),
-		list(uni_mode), module_info, list(mlds__rval)).
-:- mode ml_gen_cons_args(in, in, in, in, out) is det.
+		list(uni_mode), instmap, inst_table,
+		module_info, list(mlds__rval)).
+:- mode ml_gen_cons_args(in, in, in, in, in, in, out) is det.
 
-ml_gen_cons_args(Lvals, Types, Modes, ModuleInfo, Rvals) :-
-	( ml_gen_cons_args_2(Lvals, Types, Modes, ModuleInfo, Rvals0) ->
+ml_gen_cons_args(Lvals, Types, Modes, InstMap, InstTable, ModuleInfo, Rvals) :-
+	(
+		ml_gen_cons_args_2(Lvals, Types, Modes, InstMap, InstTable,
+			ModuleInfo, Rvals0)
+	->
 		Rvals = Rvals0
 	;
 		error("ml_gen_cons_args: length mismatch")
@@ -3827,20 +3912,24 @@
 	% null value.  (XXX perhaps we should have a special `null' rval.)
 
 :- pred ml_gen_cons_args_2(list(mlds__lval), list(prog_type),
-		list(uni_mode), module_info, list(mlds__rval)).
-:- mode ml_gen_cons_args_2(in, in, in, in, out) is semidet.
+		list(uni_mode), instmap, inst_table,
+		module_info, list(mlds__rval)).
+:- mode ml_gen_cons_args_2(in, in, in, in, in, in, out) is semidet.
 
-ml_gen_cons_args_2([], [], [], _, []).
+ml_gen_cons_args_2([], [], [], _, _, _, []).
 ml_gen_cons_args_2([Lval|Lvals], [Type|Types], [UniMode|UniModes],
-			ModuleInfo, [Rval|Rvals]) :-
+			InstMap, InstTable, ModuleInfo, [Rval|Rvals]) :-
 	UniMode = ((_LI - RI) -> (_LF - RF)),
-	( mode_to_arg_mode(ModuleInfo, (RI -> RF), Type, top_in) ->
+	(
+		mode_to_arg_mode(InstMap, InstTable, ModuleInfo,
+			(RI -> RF), Type, top_in) ->
 		Rval = lval(Lval)
 	;
 		% XXX perhaps we should have a special `null' rval.
 		Rval = const(int_const(0))
 	),
-	ml_gen_cons_args_2(Lvals, Types, UniModes, ModuleInfo, Rvals).
+	ml_gen_cons_args_2(Lvals, Types, UniModes, InstMap, InstTable,
+		ModuleInfo, Rvals).
 
 %-----------------------------------------------------------------------------%
 
@@ -3998,8 +4087,12 @@
 	{ Mode = ((LI - RI) -> (LF - RF)) },
 	=(Info),
 	{ ml_gen_info_get_module_info(Info, ModuleInfo) },
-	{ mode_to_arg_mode(ModuleInfo, (LI -> LF), ArgType, LeftMode) },
-	{ mode_to_arg_mode(ModuleInfo, (RI -> RF), ArgType, RightMode) },
+	{ ml_gen_info_get_instmap(Info, InstMap) },
+	{ ml_gen_info_get_inst_table(Info, InstTable) },
+	{ mode_to_arg_mode(InstMap, InstTable, ModuleInfo,
+		(LI -> LF), ArgType, LeftMode) },
+	{ mode_to_arg_mode(InstMap, InstTable, ModuleInfo,
+		(RI -> RF), ArgType, RightMode) },
 	(
 		% skip dummy argument types, since they will not have
 		% been declared
@@ -4442,24 +4535,28 @@
 	proc_info_varset(ProcInfo, VarSet),
 	proc_info_headvars(ProcInfo, HeadVars),
 	pred_info_arg_types(PredInfo, HeadTypes),
-	proc_info_argmodes(ProcInfo, HeadModes),
+	proc_info_argmodes(ProcInfo, Modes),
 	proc_info_interface_code_model(ProcInfo, CodeModel),
 	HeadVarNames = ml_gen_var_names(VarSet, HeadVars),
+	Modes = argument_modes(InstTable, HeadModes),
+	% The argument modes do not depend on the alias substitutions in
+	% the instmap.
+	instmap__init_reachable(InstMap),
 	FuncParams = ml_gen_params(ModuleInfo, HeadVarNames, HeadTypes,
-		HeadModes, CodeModel).
+		HeadModes, InstMap, InstTable, CodeModel).
 
 :- func ml_gen_params(module_info, list(string), list(prog_data__type),
-		list(mode), code_model) = mlds__func_params.
+	list(mode), instmap, inst_table, code_model) = mlds__func_params.
 
-ml_gen_params(ModuleInfo, HeadVarNames, HeadTypes, HeadModes, CodeModel) =
-		FuncParams :-
+ml_gen_params(ModuleInfo, HeadVarNames, HeadTypes, HeadModes, InstMap,
+		InstTable, CodeModel) = FuncParams :-
 	( CodeModel = model_semi ->
 		RetTypes = [mlds__bool_type]
 	;
 		RetTypes = []
 	),
-	ml_gen_arg_decls(ModuleInfo, HeadVarNames, HeadTypes, HeadModes,
-		FuncArgs0),
+	ml_gen_arg_decls(InstMap, InstTable, ModuleInfo, HeadVarNames,
+		HeadTypes, HeadModes, FuncArgs0),
 	( CodeModel = model_non ->
 		ContType = mlds__cont_type,
 		ContName = data(var("cont")),
@@ -4485,11 +4582,13 @@
 	% Given the argument variable names, and corresponding lists of their
 	% types and modes, generate the MLDS argument list declaration.
 	%
-:- pred ml_gen_arg_decls(module_info, list(mlds__var_name), list(prog_type),
+:- pred ml_gen_arg_decls(instmap, inst_table, module_info,
+		list(mlds__var_name), list(prog_type),
 		list(mode), mlds__arguments).
-:- mode ml_gen_arg_decls(in, in, in, in, out) is det.
+:- mode ml_gen_arg_decls(in, in, in, in, in, in, out) is det.
 
-ml_gen_arg_decls(ModuleInfo, HeadVars, HeadTypes, HeadModes, FuncArgs) :-
+ml_gen_arg_decls(InstMap, InstTable, ModuleInfo, HeadVars, HeadTypes,
+		HeadModes, FuncArgs) :-
 	(
 		HeadVars = [], HeadTypes = [], HeadModes = []
 	->
@@ -4499,12 +4598,14 @@
 		HeadTypes = [Type | Types],
 		HeadModes = [Mode | Modes]
 	->
-		ml_gen_arg_decls(ModuleInfo, Vars, Types, Modes, FuncArgs0),
+		ml_gen_arg_decls(InstMap, InstTable, ModuleInfo,
+			Vars, Types, Modes, FuncArgs0),
 		% exclude types such as io__state, etc.
 		( type_util__is_dummy_argument_type(Type) ->
 			FuncArgs = FuncArgs0
 		;
-			ml_gen_arg_decl(ModuleInfo, Var, Type, Mode, FuncArg),
+			ml_gen_arg_decl(InstMap, InstTable,
+				ModuleInfo, Var, Type, Mode, FuncArg),
 			FuncArgs = [FuncArg | FuncArgs0]
 		)
 	;
@@ -4514,13 +4615,16 @@
 	% Given an argument variable, and its type and mode,
 	% generate an MLDS argument declaration for it.
 	%
-:- pred ml_gen_arg_decl(module_info, var_name, prog_type, mode,
-			pair(mlds__entity_name, mlds__type)).
-:- mode ml_gen_arg_decl(in, in, in, in, out) is det.
+:- pred ml_gen_arg_decl(instmap, inst_table, module_info, var_name, prog_type,
+			mode, pair(mlds__entity_name, mlds__type)).
+:- mode ml_gen_arg_decl(in, in, in, in, in, in, out) is det.
 
-ml_gen_arg_decl(ModuleInfo, Var, Type, Mode, FuncArg) :-
+ml_gen_arg_decl(InstMap, InstTable, ModuleInfo, Var, Type, Mode, FuncArg) :-
 	MLDS_Type = mercury_type_to_mlds_type(Type),
-	( \+ mode_to_arg_mode(ModuleInfo, Mode, Type, top_in) ->
+	(
+		\+ mode_to_arg_mode(InstMap, InstTable,
+			ModuleInfo, Mode, Type, top_in)
+	->
 		MLDS_ArgType = mlds__ptr_type(MLDS_Type)
 	;
 		MLDS_ArgType = MLDS_Type
@@ -4532,21 +4636,25 @@
 	% return a list containing only those variables which have
 	% an output mode.
 	%
-:- func select_output_vars(module_info, list(prog_var), list(mode),
-		map(prog_var, prog_type)) = list(prog_var).
+:- func select_output_vars(instmap, inst_table, module_info, list(prog_var),
+		list(mode), map(prog_var, prog_type)) = list(prog_var).
 
-select_output_vars(ModuleInfo, HeadVars, HeadModes, VarTypes) = OutputVars :-
+select_output_vars(InstMap, InstTable, ModuleInfo, HeadVars,
+		HeadModes, VarTypes) = OutputVars :-
 	( HeadVars = [], HeadModes = [] ->
 		OutputVars = []
 	; HeadVars = [Var|Vars], HeadModes = [Mode|Modes] ->
 		map__lookup(VarTypes, Var, Type),
-		( \+ mode_to_arg_mode(ModuleInfo, Mode, Type, top_in) ->
-			OutputVars1 = select_output_vars(ModuleInfo,
-					Vars, Modes, VarTypes),
+		(
+			\+ mode_to_arg_mode(InstMap, InstTable,
+				ModuleInfo, Mode, Type, top_in)
+		->
+			OutputVars1 = select_output_vars(InstMap, InstTable,
+					ModuleInfo, Vars, Modes, VarTypes),
 			OutputVars = [Var | OutputVars1]
 		;
-			OutputVars = select_output_vars(ModuleInfo,
-					Vars, Modes, VarTypes)
+			OutputVars = select_output_vars(InstMap, InstTable,
+					ModuleInfo, Vars, Modes, VarTypes)
 		)
 	;
 		error("select_output_vars: length mismatch")
@@ -4686,7 +4794,9 @@
 				% constants which should be inserted
 				% before the definition of the function
 				% for the current procedure
-			mlds__defns
+			mlds__defns,
+			instmap,
+			inst_table
 		).
 
 :- type commit_sequence_num == int.
@@ -4699,9 +4809,12 @@
 	proc_info_headvars(ProcInfo, HeadVars),
 	proc_info_varset(ProcInfo, VarSet),
 	proc_info_vartypes(ProcInfo, VarTypes),
-	proc_info_argmodes(ProcInfo, HeadModes),
-	OutputVars = select_output_vars(ModuleInfo, HeadVars, HeadModes,
-		VarTypes),
+	proc_info_argmodes(ProcInfo, Modes),
+	Modes = argument_modes(_, HeadModes),
+	proc_info_get_initial_instmap(ProcInfo, ModuleInfo, InstMap),
+	proc_info_inst_table(ProcInfo, InstTable),
+	OutputVars = select_output_vars(InstMap, InstTable,
+			ModuleInfo, HeadVars, HeadModes, VarTypes),
 	FuncLabelCounter = 0,
 	CommitLabelCounter = 0,
 	stack__init(SuccContStack),
@@ -4716,13 +4829,16 @@
 			FuncLabelCounter,
 			CommitLabelCounter,
 			SuccContStack,
-			ExtraDefns
+			ExtraDefns,
+			InstMap,
+			InstTable
 		).
 
 :- pred ml_gen_info_get_module_info(ml_gen_info, module_info).
 :- mode ml_gen_info_get_module_info(in, out) is det.
 
-ml_gen_info_get_module_info(ml_gen_info(ModuleInfo, _, _, _, _, _, _, _, _, _),
+ml_gen_info_get_module_info(
+	ml_gen_info(ModuleInfo, _, _, _, _, _, _, _, _, _, _, _),
 	ModuleInfo).
 
 :- pred ml_gen_info_get_module_name(ml_gen_info, mercury_module_name).
@@ -4735,36 +4851,41 @@
 :- pred ml_gen_info_get_pred_id(ml_gen_info, pred_id).
 :- mode ml_gen_info_get_pred_id(in, out) is det.
 
-ml_gen_info_get_pred_id(ml_gen_info(_, PredId, _, _, _, _, _, _, _, _), PredId).
+ml_gen_info_get_pred_id(ml_gen_info(_, PredId, _, _, _, _, _, _, _, _, _, _),
+		PredId).
 
 :- pred ml_gen_info_get_proc_id(ml_gen_info, proc_id).
 :- mode ml_gen_info_get_proc_id(in, out) is det.
 
-ml_gen_info_get_proc_id(ml_gen_info(_, _, ProcId, _, _, _, _, _, _, _), ProcId).
+ml_gen_info_get_proc_id(ml_gen_info(_, _, ProcId, _, _, _, _, _, _, _, _, _),
+		ProcId).
 
 :- pred ml_gen_info_get_varset(ml_gen_info, prog_varset).
 :- mode ml_gen_info_get_varset(in, out) is det.
 
-ml_gen_info_get_varset(ml_gen_info(_, _, _, VarSet, _, _, _, _, _, _), VarSet).
+ml_gen_info_get_varset(ml_gen_info(_, _, _, VarSet, _, _, _, _, _, _, _, _),
+		VarSet).
 
 :- pred ml_gen_info_get_var_types(ml_gen_info, map(prog_var, prog_type)).
 :- mode ml_gen_info_get_var_types(in, out) is det.
 
-ml_gen_info_get_var_types(ml_gen_info(_, _, _, _, VarTypes, _, _, _, _, _),
+ml_gen_info_get_var_types(
+	ml_gen_info(_, _, _, _, VarTypes, _, _, _, _, _, _, _),
 	VarTypes).
 
 :- pred ml_gen_info_get_output_vars(ml_gen_info, list(prog_var)).
 :- mode ml_gen_info_get_output_vars(in, out) is det.
 
-ml_gen_info_get_output_vars(ml_gen_info(_, _, _, _, _, OutputVars, _, _, _, _),
+ml_gen_info_get_output_vars(
+	ml_gen_info(_, _, _, _, _, OutputVars, _, _, _, _, _, _),
 	OutputVars).
 
 :- pred ml_gen_info_new_func_label(ml_label_func, ml_gen_info, ml_gen_info).
 :- mode ml_gen_info_new_func_label(out, in, out) is det.
 
 ml_gen_info_new_func_label(Label,
-		ml_gen_info(A, B, C, D, E, F, Label0, H, I, J),
-		ml_gen_info(A, B, C, D, E, F, Label, H, I, J)) :-
+		ml_gen_info(A, B, C, D, E, F, Label0, H, I, J, K, L),
+		ml_gen_info(A, B, C, D, E, F, Label, H, I, J, K, L)) :-
 	Label is Label0 + 1.
 
 :- pred ml_gen_info_new_commit_label(commit_sequence_num,
@@ -4772,8 +4893,8 @@
 :- mode ml_gen_info_new_commit_label(out, in, out) is det.
 
 ml_gen_info_new_commit_label(CommitLabel,
-		ml_gen_info(A, B, C, D, E, F, G, CommitLabel0, I, J),
-		ml_gen_info(A, B, C, D, E, F, G, CommitLabel, I, J)) :-
+		ml_gen_info(A, B, C, D, E, F, G, CommitLabel0, I, J, K, L),
+		ml_gen_info(A, B, C, D, E, F, G, CommitLabel, I, J, K, L)) :-
 	CommitLabel is CommitLabel0 + 1.
 
 :- type success_cont 
@@ -4791,15 +4912,16 @@
 :- mode ml_gen_info_get_success_cont_stack(in, out) is det.
 
 ml_gen_info_get_success_cont_stack(
-	ml_gen_info(_, _, _, _, _, _, _, _, SuccContStack, _), SuccContStack).
+	ml_gen_info(_, _, _, _, _, _, _, _, SuccContStack, _, _, _),
+	SuccContStack).
 
 :- pred ml_gen_info_set_success_cont_stack(stack(success_cont),
 			ml_gen_info, ml_gen_info).
 :- mode ml_gen_info_set_success_cont_stack(in, in, out) is det.
 
 ml_gen_info_set_success_cont_stack(SuccContStack,
-		ml_gen_info(A, B, C, D, E, F, G, H, _, J),
-		ml_gen_info(A, B, C, D, E, F, G, H, SuccContStack, J)).
+		ml_gen_info(A, B, C, D, E, F, G, H, _, J, K, L),
+		ml_gen_info(A, B, C, D, E, F, G, H, SuccContStack, J, K, L)).
 ********/
 
 :- pred ml_gen_info_push_success_cont(success_cont,
@@ -4807,16 +4929,16 @@
 :- mode ml_gen_info_push_success_cont(in, in, out) is det.
 
 ml_gen_info_push_success_cont(SuccCont,
-		ml_gen_info(A, B, C, D, E, F, G, H, Stack0, J),
-		ml_gen_info(A, B, C, D, E, F, G, H, Stack, J)) :-
+		ml_gen_info(A, B, C, D, E, F, G, H, Stack0, J, K, L),
+		ml_gen_info(A, B, C, D, E, F, G, H, Stack, J, K, L)) :-
 	stack__push(Stack0, SuccCont, Stack).
 
 :- pred ml_gen_info_pop_success_cont(ml_gen_info, ml_gen_info).
 :- mode ml_gen_info_pop_success_cont(in, out) is det.
 
 ml_gen_info_pop_success_cont(
-		ml_gen_info(A, B, C, D, E, F, G, H, Stack0, J),
-		ml_gen_info(A, B, C, D, E, F, G, H, Stack, J)) :-
+		ml_gen_info(A, B, C, D, E, F, G, H, Stack0, J, K, L),
+		ml_gen_info(A, B, C, D, E, F, G, H, Stack, J, K, L)) :-
 	stack__pop_det(Stack0, _SuccCont, Stack).
 
 :- pred ml_gen_info_current_success_cont(success_cont,
@@ -4824,8 +4946,8 @@
 :- mode ml_gen_info_current_success_cont(out, in, out) is det.
 
 ml_gen_info_current_success_cont(SuccCont,
-		ml_gen_info(A, B, C, D, E, F, G, H, Stack, J),
-		ml_gen_info(A, B, C, D, E, F, G, H, Stack, J)) :-
+		ml_gen_info(A, B, C, D, E, F, G, H, Stack, J, K, L),
+		ml_gen_info(A, B, C, D, E, F, G, H, Stack, J, K, L)) :-
 	stack__top_det(Stack, SuccCont).
 
 :- pred ml_gen_info_add_extra_defn(mlds__defn,
@@ -4833,15 +4955,47 @@
 :- mode ml_gen_info_add_extra_defn(in, in, out) is det.
 
 ml_gen_info_add_extra_defn(ExtraDefn,
-		ml_gen_info(A, B, C, D, E, F, G, H, I, ExtraDefns0),
-		ml_gen_info(A, B, C, D, E, F, G, H, I, ExtraDefns)) :-
+		ml_gen_info(A, B, C, D, E, F, G, H, I, ExtraDefns0, K, L),
+		ml_gen_info(A, B, C, D, E, F, G, H, I, ExtraDefns, K, L)) :-
 	ExtraDefns = [ExtraDefn | ExtraDefns0].
 
 :- pred ml_gen_info_get_extra_defns(ml_gen_info, mlds__defns).
 :- mode ml_gen_info_get_extra_defns(in, out) is det.
 
-ml_gen_info_get_extra_defns(ml_gen_info(_, _, _, _, _, _, _, _, _, ExtraDefns),
+ml_gen_info_get_extra_defns(
+	ml_gen_info(_, _, _, _, _, _, _, _, _, ExtraDefns, _, _),
 	ExtraDefns).
+
+:- pred ml_gen_info_get_instmap(ml_gen_info, instmap).
+:- mode ml_gen_info_get_instmap(in, out) is det.
+
+ml_gen_info_get_instmap(
+	ml_gen_info(_, _, _, _, _, _, _, _, _, _, InstMap, _),
+	InstMap).
+
+:- pred ml_gen_info_set_instmap(instmap, ml_gen_info, ml_gen_info).
+:- mode ml_gen_info_set_instmap(in, in, out) is det.
+
+ml_gen_info_set_instmap(InstMap,
+		ml_gen_info(A, B, C, D, E, F, G, H, I, J, _, L),
+		ml_gen_info(A, B, C, D, E, F, G, H, I, J, InstMap, L)).
+
+:- pred ml_gen_info_update_instmap(hlds_goal,
+		ml_gen_info, ml_gen_info).
+:- mode ml_gen_info_update_instmap(in, in, out) is det.
+
+ml_gen_info_update_instmap(_ - GoalInfo, Info0, Info) :-
+	goal_info_get_instmap_delta(GoalInfo, InstMapDelta),
+	ml_gen_info_get_instmap(Info0, InstMap0),
+	instmap__apply_instmap_delta(InstMap0, InstMapDelta, InstMap),
+	ml_gen_info_set_instmap(InstMap, Info0, Info).
+
+:- pred ml_gen_info_get_inst_table(ml_gen_info, inst_table).
+:- mode ml_gen_info_get_inst_table(in, out) is det.
+
+ml_gen_info_get_inst_table(
+	ml_gen_info(_, _, _, _, _, _, _, _, _, _, _, InstTable),
+	InstTable).
 
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
--- ../../../amerge2/mercury/compiler/mode_util.m	Thu Dec 16 17:16:46 1999
+++ mode_util.m	Tue Dec 21 09:16:18 1999
@@ -16,7 +16,7 @@
 
 :- import_module hlds_module, hlds_pred, hlds_goal, hlds_data, prog_data.
 :- import_module instmap, (inst), inst_table.
-:- import_module bool, list, map, assoc_list.
+:- import_module bool, list, assoc_list, std_util.
 
 	% mode_get_insts returns the initial instantiatedness and
 	% the final instantiatedness for a given mode, aborting
@@ -134,21 +134,15 @@
 	% may need to insert new merge_insts into the merge_inst table.
 	% If the first argument is yes, the instmap_deltas for calls
 	% and deconstruction unifications are also recomputed.
-<<<<<<< mode_util.m
 :- pred recompute_instmap_delta_proc(proc_info, proc_info,
 		module_info, module_info).
 :- mode recompute_instmap_delta_proc(in, out, in, out) is det.
 
 :- pred recompute_instmap_delta(list(prog_var), list(is_live),
-		map(prog_var, type), hlds_goal, hlds_goal, instmap, inst_table,
+		vartypes, hlds_goal, hlds_goal, instmap, inst_table,
 		inst_table, bool, module_info, module_info).
 :- mode recompute_instmap_delta(in, in, in, in, out, in, in, out, out, in, out)
 		is det.
-=======
-:- pred recompute_instmap_delta(bool, hlds_goal, hlds_goal, vartypes, instmap,
-				module_info, module_info).
-:- mode recompute_instmap_delta(in, in, out, in, in, in, out) is det.
->>>>>>> 1.118
 
 	% Given corresponding lists of types and modes, produce a new
 	% list of modes which includes the information provided by the
@@ -231,6 +225,19 @@
 
 %-----------------------------------------------------------------------------%
 
+	%
+	% Fix up the cons_id arity for type(class)_info constructions.
+	% The cons_id for type(class)_info constructions always has
+	% arity 1, to match the arity in the declaration in
+	% library/private_builtin.m,
+	% but for the inst we need the arity of the cons_id
+	% to match the number of arguments.
+	%
+:- pred fix_type_info_cons_id_arity(cons_id, list(T), cons_id).
+:- mode fix_type_info_cons_id_arity(in, in, out) is det.
+
+%-----------------------------------------------------------------------------%
+
 	% Construct a mode corresponding to the standard `in',
 	% `out', `uo' or `unused' mode.
 :- pred in_mode((mode)::out) is det.
@@ -238,6 +245,16 @@
 :- pred uo_mode((mode)::out) is det.
 :- pred unused_mode((mode)::out) is det.
 
+:- func in_mode = (mode).
+:- func out_mode = (mode).
+:- func uo_mode = (mode).
+:- func unused_mode = (mode).
+
+:- func in_inst_pair = pair(inst).
+:- func out_inst_pair = pair(inst).
+:- func uo_inst_pair = pair(inst).
+:- func unused_inst_pair = pair(inst).
+
 	% Construct the modes used for `aditi__state' arguments.
 	% XXX These should be unique, but are not yet because that
 	% would require alias tracking.
@@ -1302,27 +1319,21 @@
 	% and deconstructions may become non-local (XXX does this require
 	% rerunning mode analysis rather than just recompute_instmap_delta?).
 
-<<<<<<< mode_util.m
 :- type recompute_info --->
 		recompute_info(
-			map(prog_var, type),
+			vartypes,
 			module_info,
 			inst_table,
 			bag(prog_var),
 			bool
 		).
-=======
-recompute_instmap_delta(RecomputeAtomic, Goal0, Goal, VarTypes, InstMap0) -->
-	recompute_instmap_delta(RecomputeAtomic, Goal0, Goal, VarTypes, InstMap0, _).
->>>>>>> 1.118
 
-<<<<<<< mode_util.m
 :- pred slap_recompute_info(recompute_info, recompute_info, recompute_info).
 :- mode slap_recompute_info(in, in, out) is det.
 
 slap_recompute_info(RI, _, RI).
 
-:- pred recompute_info_get_vartypes(recompute_info, map(prog_var, type)).
+:- pred recompute_info_get_vartypes(recompute_info, vartypes).
 :- mode recompute_info_get_vartypes(in, out) is det.
 
 recompute_info_get_vartypes(recompute_info(VarTypes, _, _, _, _), VarTypes).
@@ -1462,16 +1473,6 @@
 	recompute_instmap_delta_3(Goal0, GoalInfo0, Goal, GoalInfo1, InstMap0,
 			InstMapDelta, RI0, RI1),
 	(
-=======
-:- pred recompute_instmap_delta(bool, hlds_goal, hlds_goal, vartypes, instmap,
-		instmap_delta, module_info, module_info).
-:- mode recompute_instmap_delta(in, in, out, in, in, out, in, out) is det.
-
-recompute_instmap_delta(RecomputeAtomic, Goal0 - GoalInfo0, Goal - GoalInfo,
-		VarTypes, InstMap0, InstMapDelta) -->
-	( 
-		{ RecomputeAtomic = no },
->>>>>>> 1.118
 		( 
 			% If the initial instmap is unreachable so is
 			% the final instmap.
@@ -1483,48 +1484,20 @@
 			determinism_components(Det, _, at_most_zero)
 		)
 	->
-<<<<<<< mode_util.m
 		instmap_delta_init_unreachable(Unreachable),
 		goal_info_set_instmap_delta(GoalInfo1, Unreachable, GoalInfo),
 		instmap__init_unreachable(InstMap)
-=======
-		{ Goal = Goal0 },
-		{ GoalInfo1 = GoalInfo0 }
-	;
-		recompute_instmap_delta_2(RecomputeAtomic, Goal0,
-			 GoalInfo0, Goal, VarTypes, InstMap0, InstMapDelta0),
-		{ goal_info_get_nonlocals(GoalInfo0, NonLocals) },
-		{ instmap_delta_restrict(InstMapDelta0,
-			NonLocals, InstMapDelta1) },
-		{ goal_info_set_instmap_delta(GoalInfo0,
-			InstMapDelta1, GoalInfo1) }
-	),
-
-	% If the initial instmap is unreachable so is the final instmap.
-	( { instmap__is_unreachable(InstMap0) } ->
-		{ instmap_delta_init_unreachable(UnreachableInstMapDelta) },
-		{ goal_info_set_instmap_delta(GoalInfo1,
-			UnreachableInstMapDelta, GoalInfo) }
->>>>>>> 1.118
 	;
 		goal_info_set_instmap_delta(GoalInfo1, InstMapDelta, GoalInfo),
 		instmap__apply_instmap_delta(InstMap0, InstMapDelta, InstMap)
 	),
 	RI = RI1.
 
-<<<<<<< mode_util.m
 :- pred recompute_instmap_delta_3(hlds_goal_expr, hlds_goal_info,
 		hlds_goal_expr, hlds_goal_info, instmap, instmap_delta,
 		recompute_info, recompute_info).
 :- mode recompute_instmap_delta_3(in, in, out, out, in, out, in, out) is det.
-=======
-:- pred recompute_instmap_delta_2(bool, hlds_goal_expr, hlds_goal_info,
-		hlds_goal_expr, vartypes, instmap, instmap_delta,
-		module_info, module_info).
-:- mode recompute_instmap_delta_2(in, in, in, out, in, in, out, in, out) is det.
->>>>>>> 1.118
 
-<<<<<<< mode_util.m
 recompute_instmap_delta_3(switch(Var, Det, Cases0, SM), GoalInfo,
 		switch(Var, Det, Cases, SM), GoalInfo, InstMap0,
 		InstMapDelta) -->
@@ -1574,47 +1547,12 @@
 	recompute_instmap_delta_disj(Goals0, Goals,
 		InstMap0, NonLocals, InstMap),
 	{ compute_instmap_delta(InstMap0, InstMap, InstMapDelta) }.
-=======
-recompute_instmap_delta_2(Atomic, switch(Var, Det, Cases0, SM), GoalInfo,
-		switch(Var, Det, Cases, SM), VarTypes, InstMap,
-		InstMapDelta) -->
-	{ goal_info_get_nonlocals(GoalInfo, NonLocals) },
-	recompute_instmap_delta_cases(Atomic, Var, Cases0, Cases,
-		VarTypes, InstMap, NonLocals, InstMapDelta).
-
-recompute_instmap_delta_2(Atomic, conj(Goals0), _, conj(Goals),
-		VarTypes, InstMap, InstMapDelta) -->
-	recompute_instmap_delta_conj(Atomic, Goals0, Goals,
-		VarTypes, InstMap, InstMapDelta).
-
-recompute_instmap_delta_2(Atomic, par_conj(Goals0, SM), GoalInfo,
-		par_conj(Goals, SM), VarTypes, InstMap, InstMapDelta) -->
-	{ goal_info_get_nonlocals(GoalInfo, NonLocals) },
-	recompute_instmap_delta_par_conj(Atomic, Goals0, Goals,
-		VarTypes, InstMap, NonLocals, InstMapDelta).
-
-recompute_instmap_delta_2(Atomic, disj(Goals0, SM), GoalInfo, disj(Goals, SM),
-		VarTypes, InstMap, InstMapDelta) -->
-	{ goal_info_get_nonlocals(GoalInfo, NonLocals) },
-	recompute_instmap_delta_disj(Atomic, Goals0, Goals,
-		VarTypes, InstMap, NonLocals, InstMapDelta).
->>>>>>> 1.118
 
-<<<<<<< mode_util.m
 recompute_instmap_delta_3(not(Goal0), GoalInfo, not(Goal), GoalInfo,
 		InstMap, InstMapDelta) -->
-=======
-recompute_instmap_delta_2(Atomic, not(Goal0), _, not(Goal),
-		VarTypes, InstMap, InstMapDelta) -->
->>>>>>> 1.118
 	{ instmap_delta_init_reachable(InstMapDelta) },
-<<<<<<< mode_util.m
 	recompute_instmap_delta_2(Goal0, Goal, InstMap).
-=======
-	recompute_instmap_delta(Atomic, Goal0, Goal, VarTypes, InstMap).
->>>>>>> 1.118
 
-<<<<<<< mode_util.m
 recompute_instmap_delta_3(if_then_else(Vars, A0, B0, C0, SM), GoalInfo0,
 		Goal, GoalInfo, InstMap0, InstMapDelta) -->
 	=(RI0),
@@ -1692,33 +1630,7 @@
 		recompute_info_set_module_info(M),
 		recompute_info_set_inst_table(InstTable)
 	).
-=======
-recompute_instmap_delta_2(Atomic, if_then_else(Vars, A0, B0, C0, SM), GoalInfo,
-		if_then_else(Vars, A, B, C, SM), VarTypes, InstMap0, InstMapDelta) -->
-	recompute_instmap_delta(Atomic, A0, A, VarTypes, InstMap0, InstMapDelta1),
-	{ instmap__apply_instmap_delta(InstMap0, InstMapDelta1, InstMap1) },
-	recompute_instmap_delta(Atomic, B0, B, VarTypes, InstMap1, InstMapDelta2),
-	recompute_instmap_delta(Atomic, C0, C, VarTypes, InstMap0, InstMapDelta3),
-	{ instmap_delta_apply_instmap_delta(InstMapDelta1, InstMapDelta2,
-		InstMapDelta4) },
-	{ goal_info_get_nonlocals(GoalInfo, NonLocals) },
-	merge_instmap_delta(InstMap0, NonLocals, InstMapDelta3,
-		InstMapDelta4, InstMapDelta).
-
-recompute_instmap_delta_2(Atomic, some(Vars, CanRemove, Goal0), _,
-		some(Vars, CanRemove, Goal),
-		VarTypes, InstMap, InstMapDelta) -->
-	recompute_instmap_delta(Atomic, Goal0, Goal, VarTypes, InstMap, InstMapDelta).
-
-recompute_instmap_delta_2(_, generic_call(A, Vars, Modes, D), _,
-		generic_call(A, Vars, Modes, D),
-		_VarTypes, _InstMap, InstMapDelta) -->
-	=(ModuleInfo),
-	{ instmap_delta_from_mode_list(Vars, Modes,
-		ModuleInfo, InstMapDelta) }.
->>>>>>> 1.118
 
-<<<<<<< mode_util.m
 recompute_instmap_delta_3(some(Vars, CanRemove, Goal0), GoalInfo,
 		some(Vars, CanRemove, Goal), GoalInfo,
 		InstMap, InstMapDelta) -->
@@ -1739,42 +1651,9 @@
 recompute_instmap_delta_3(call(PredId, ProcId, Args, D, E, F), GoalInfo,
 		call(PredId, ProcId, Args, D, E, F), GoalInfo, InstMap,
 		InstMapDelta) -->
-=======
-recompute_instmap_delta_2(_, call(PredId, ProcId, Args, D, E, F), _,
-		call(PredId, ProcId, Args, D, E, F), _VarTypes,
-		InstMap, InstMapDelta) -->
->>>>>>> 1.118
 	recompute_instmap_delta_call(PredId, ProcId,
 		Args, InstMap, InstMapDelta).
-<<<<<<< mode_util.m
-=======
-
-recompute_instmap_delta_2(Atomic, unify(A, Rhs0, UniMode0, Uni, E), GoalInfo, 
-		unify(A, Rhs, UniMode, Uni, E), VarTypes, InstMap0,
-		InstMapDelta) -->
-	(
-		{ Rhs0 = lambda_goal(PorF, EvalMethod, FixModes, NonLocals,
-			LambdaVars, Modes, Det, Goal0) }
-	->
-		=(ModuleInfo0),
-		{ instmap__pre_lambda_update(ModuleInfo0, LambdaVars, Modes,
-			InstMap0, InstMap) },
-		recompute_instmap_delta(Atomic, Goal0, Goal, VarTypes, InstMap),
-		{ Rhs = lambda_goal(PorF, EvalMethod, FixModes, NonLocals,
-			LambdaVars, Modes, Det, Goal) }
-	;
-		{ Rhs = Rhs0 }
-	),
-	( { Atomic = yes } ->
-		recompute_instmap_delta_unify(Uni, UniMode0, UniMode,
-			GoalInfo, InstMap0, InstMapDelta)
-	;
-		{ UniMode = UniMode0 },
-		{ goal_info_get_instmap_delta(GoalInfo, InstMapDelta) }
-	).
->>>>>>> 1.118
 
-<<<<<<< mode_util.m
 recompute_instmap_delta_3(unify(Var, UnifyRhs0, UniMode0, Uni0, UniContext),
 		GoalInfo0, Goal, GoalInfo, InstMap, InstMapDelta) -->
 	recompute_instmap_delta_unify(Var, UnifyRhs0, UniMode0, Uni0,
@@ -1784,37 +1663,21 @@
 recompute_instmap_delta_3(pragma_c_code(A, PredId, ProcId, Args, E, F, G),
 		GoalInfo, pragma_c_code(A, PredId, ProcId, Args, E, F, G),
 		GoalInfo, InstMap, InstMapDelta) -->
-=======
-recompute_instmap_delta_2(_, pragma_c_code(A, PredId, ProcId, Args, E, F,
-		G), _, pragma_c_code(A, PredId, ProcId, Args, E, F, G),
-		_VarTypes, InstMap, InstMapDelta) -->
->>>>>>> 1.118
 	recompute_instmap_delta_call(PredId, ProcId,
 		Args, InstMap, InstMapDelta).
 
-recompute_instmap_delta_2(_, bi_implication(_, _), _, _, _, _, _) -->
+recompute_instmap_delta_3(bi_implication(_, _), _, _, _, _, _) -->
 	% these should have been expanded out by now
-	{ error("recompute_instmap_delta_2: unexpected bi_implication") }.
+	{ error("recompute_instmap_delta_3: unexpected bi_implication") }.
 	
 %-----------------------------------------------------------------------------%
 
-<<<<<<< mode_util.m
 :- pred recompute_instmap_delta_conj(list(hlds_goal), list(hlds_goal),
 		instmap, instmap_delta, recompute_info, recompute_info).
 :- mode recompute_instmap_delta_conj(in, out, in, out, in, out) is det.
-=======
-:- pred recompute_instmap_delta_conj(bool, list(hlds_goal), list(hlds_goal),
-		vartypes, instmap, instmap_delta, module_info, module_info).
-:- mode recompute_instmap_delta_conj(in, in, out, in, in, out, in, out) is det.
->>>>>>> 1.118
 
-<<<<<<< mode_util.m
 recompute_instmap_delta_conj([], [], _InstMap, InstMapDelta) -->
-=======
-recompute_instmap_delta_conj(_, [], [], _VarTypes, _InstMap, InstMapDelta) -->
->>>>>>> 1.118
 	{ instmap_delta_init_reachable(InstMapDelta) }.
-<<<<<<< mode_util.m
 recompute_instmap_delta_conj([Goal0 | Goals0], [Goal | Goals],
 		InstMap0, InstMapDelta) -->
 	{ Goal0 = _ - GoalInfo0 },
@@ -1840,21 +1703,9 @@
 		{ instmap_delta_apply_instmap_delta(InstMapDelta0,
 				InstMapDelta1, InstMapDelta) }
 	).
-=======
-recompute_instmap_delta_conj(Atomic, [Goal0 | Goals0], [Goal | Goals],
-		VarTypes, InstMap0, InstMapDelta) -->
-	recompute_instmap_delta(Atomic, Goal0, Goal,
-		VarTypes, InstMap0, InstMapDelta0),
-	{ instmap__apply_instmap_delta(InstMap0, InstMapDelta0, InstMap1) },
-	recompute_instmap_delta_conj(Atomic, Goals0, Goals,
-		VarTypes, InstMap1, InstMapDelta1),
-	{ instmap_delta_apply_instmap_delta(InstMapDelta0, InstMapDelta1,
-		InstMapDelta) }.
->>>>>>> 1.118
 
 %-----------------------------------------------------------------------------%
 
-<<<<<<< mode_util.m
 :- pred recompute_instmap_delta_par_conj(list(hlds_goal), list(hlds_goal),
 		instmap, list(pair(instmap, set(prog_var))),
 		list(pair(instmap, set(prog_var))), recompute_info,
@@ -1883,15 +1734,7 @@
 			IMNonLocals1, IMNonLocals).
 
 %-----------------------------------------------------------------------------%
-=======
-:- pred recompute_instmap_delta_disj(bool, list(hlds_goal), list(hlds_goal),
-		vartypes, instmap, set(prog_var), instmap_delta,
-		module_info, module_info).
-:- mode recompute_instmap_delta_disj(in, in, out, in, in, in, out, in, out)
-		is det.
->>>>>>> 1.118
 
-<<<<<<< mode_util.m
 :- pred recompute_instmap_delta_disj(list(hlds_goal), list(hlds_goal), instmap,
 		set(prog_var), instmap, recompute_info, recompute_info).
 :- mode recompute_instmap_delta_disj(in, out, in, in, out, in, out) is det.
@@ -1903,18 +1746,7 @@
 	recompute_instmap_delta_2(Goal0, Goal, InstMap0, InstMap, _).
 recompute_instmap_delta_disj([Goal0 | Goals0], [Goal | Goals],
 		InstMap0, NonLocals, InstMap) -->
-=======
-recompute_instmap_delta_disj(_, [], [], _, _, _, InstMapDelta) -->
-	{ instmap_delta_init_unreachable(InstMapDelta) }.
-recompute_instmap_delta_disj(Atomic, [Goal0], [Goal],
-		VarTypes, InstMap, _, InstMapDelta) -->
-	recompute_instmap_delta(Atomic, Goal0, Goal, VarTypes, InstMap,
-		InstMapDelta).
-recompute_instmap_delta_disj(Atomic, [Goal0 | Goals0], [Goal | Goals],
-		VarTypes, InstMap, NonLocals, InstMapDelta) -->
->>>>>>> 1.118
 	{ Goals0 = [_|_] },
-<<<<<<< mode_util.m
 	recompute_instmap_delta_2(Goal0, Goal, InstMap0, InstMapThisBranch, _),
 	recompute_instmap_delta_disj(Goals0, Goals,
 			InstMap0, NonLocals, InstMapBranches),
@@ -1932,49 +1764,9 @@
 	},
 	recompute_info_set_module_info(M),
 	recompute_info_set_inst_table(InstTable).
-=======
-	recompute_instmap_delta(Atomic, Goal0, Goal,
-		VarTypes, InstMap, InstMapDelta0),
-	recompute_instmap_delta_disj(Atomic, Goals0, Goals,
-		VarTypes, InstMap, NonLocals, InstMapDelta1),
-	merge_instmap_delta(InstMap, NonLocals, InstMapDelta0,
-		InstMapDelta1, InstMapDelta).
-
-:- pred recompute_instmap_delta_par_conj(bool, list(hlds_goal),
-		list(hlds_goal), vartypes, instmap, set(prog_var),
-		instmap_delta, module_info, module_info).
-:- mode recompute_instmap_delta_par_conj(in, in, out, in, in, in, out,
-		in, out) is det.
-
-recompute_instmap_delta_par_conj(_, [], [], _, _, _, InstMapDelta) -->
-	{ instmap_delta_init_unreachable(InstMapDelta) }.
-recompute_instmap_delta_par_conj(Atomic, [Goal0], [Goal],
-		VarTypes, InstMap, _, InstMapDelta) -->
-	recompute_instmap_delta(Atomic, Goal0, Goal, VarTypes, InstMap,
-		InstMapDelta).
-recompute_instmap_delta_par_conj(Atomic, [Goal0 | Goals0], [Goal | Goals],
-		VarTypes, InstMap, NonLocals, InstMapDelta) -->
-	{ Goals0 = [_|_] },
-	recompute_instmap_delta(Atomic, Goal0, Goal,
-		VarTypes, InstMap, InstMapDelta0),
-	recompute_instmap_delta_par_conj(Atomic, Goals0, Goals,
-		VarTypes, InstMap, NonLocals, InstMapDelta1),
-	unify_instmap_delta(InstMap, NonLocals, InstMapDelta0,
-		InstMapDelta1, InstMapDelta).
->>>>>>> 1.118
 
 %-----------------------------------------------------------------------------%
-<<<<<<< mode_util.m
-=======
-
-:- pred recompute_instmap_delta_cases(bool, prog_var, list(case), list(case),
-		vartypes, instmap, set(prog_var), instmap_delta,
-		module_info, module_info).
-:- mode recompute_instmap_delta_cases(in, in, in, out,
-		in, in, in, out, in, out) is det.
->>>>>>> 1.118
 
-<<<<<<< mode_util.m
 :- pred recompute_instmap_delta_cases(prog_var, list(case), list(case), instmap,
 		set(prog_var), instmap, recompute_info, recompute_info).
 :- mode recompute_instmap_delta_cases(in, in, out, in, in, out, in, out) is det.
@@ -1987,7 +1779,9 @@
 	=(RI0),
 	{ recompute_info_get_module_info(RI0, M0) },
 	{ recompute_info_get_inst_table(RI0, InstTable0) },
-	{ instmap__bind_var_to_functor(Var, Functor, InstMap0, InstMap1,
+	{ recompute_info_get_vartypes(RI0, VarTypes0) },
+	{ map__lookup(VarTypes0, Var, Type) },
+	{ instmap__bind_var_to_functor(Var, Type, Functor, InstMap0, InstMap1,
 		InstTable0, InstTable1, M0, M1) },
 	{ compute_instmap_delta(InstMap0, InstMap1, IMDelta) },
 	recompute_info_set_module_info(M1),
@@ -2010,24 +1804,6 @@
 	},
 	recompute_info_set_module_info(M),
 	recompute_info_set_inst_table(InstTable).
-=======
-recompute_instmap_delta_cases(_, _, [], [], _, _, _, InstMapDelta) -->
-	{ instmap_delta_init_unreachable(InstMapDelta) }.
-recompute_instmap_delta_cases(Atomic, Var, [Case0 | Cases0], [Case | Cases],
-		VarTypes, InstMap0, NonLocals, InstMapDelta) -->
-	{ Case0 = case(Functor, Goal0) },
-	{ map__lookup(VarTypes, Var, Type) },
-	instmap__bind_var_to_functor(Var, Type, Functor, InstMap0, InstMap),
-	recompute_instmap_delta(Atomic, Goal0, Goal, VarTypes, InstMap,
-		InstMapDelta0),
-	instmap_delta_bind_var_to_functor(Var, Type, Functor,
-		InstMap0, InstMapDelta0, InstMapDelta1),
-	{ Case = case(Functor, Goal) },
-	recompute_instmap_delta_cases(Atomic, Var, Cases0, Cases,
-		VarTypes, InstMap0, NonLocals, InstMapDelta2),
-	merge_instmap_delta(InstMap0, NonLocals, InstMapDelta1,
-		InstMapDelta2, InstMapDelta).
->>>>>>> 1.118
 
 %-----------------------------------------------------------------------------%
 
@@ -2131,9 +1907,10 @@
 	list__length(Vars, Arity),
 	recompute_info_var_is_live(RI0, Var, VarLive),
 	list__map(instmap__lookup_var(InstMap1), Vars, ArgInsts),
+	fix_type_info_cons_id_arity(ConsId, Vars, InstConsId),
 	(
 		abstractly_unify_inst_functor(VarLive, InitialInst,
-			ConsId, ArgInsts, ArgLives, real_unify,
+			InstConsId, ArgInsts, ArgLives, real_unify,
 			InstTable1, ModuleInfo0, InstMap1,
 			UnifyInst0, Det0, InstTable2, ModuleInfo2, InstMap2)
 	->
@@ -2147,13 +1924,13 @@
 	),
 	instmap__set(InstMap3, Var, UnifyInst, InstMap),
 	ModeOfX = (InitialInst - UnifyInst),
-	ModeOfY = (bound(unique, [functor(ConsId, ArgInsts)]) - UnifyInst),
+	ModeOfY = (bound(unique, [functor(InstConsId, ArgInsts)]) - UnifyInst),
 	UniMode = ModeOfX - ModeOfY,
 	UnifyRhs = functor(ConsId, Vars),
 	(
 		inst_expand(InstMap1, InstTable, ModuleInfo, InitialInst,
 			InstOfX2),
-		get_arg_insts(InstOfX2, ConsId, Arity, InstOfXArgs),
+		get_arg_insts(InstOfX2, InstConsId, Arity, InstOfXArgs),
 		get_mode_of_args(UnifyInst, InstOfXArgs, ModeOfXArgs0)
 	->
 		ModeOfXArgs = ModeOfXArgs0
@@ -2651,24 +2428,42 @@
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
 
-in_mode(Mode) :- make_std_mode("in", [], Mode).
+in_mode(in_mode).
+out_mode(out_mode).
+uo_mode(uo_mode).
+unused_mode(unused_mode).
+
+in_mode = make_std_mode("in", []).
+out_mode = make_std_mode("out", []).
+uo_mode = make_std_mode("uo", []).
+unused_mode = make_std_mode("unused", []).
+
+in_inst_pair = ground_inst - ground_inst.
+out_inst_pair = free_inst - ground_inst.
+uo_inst_pair = free_inst - unique_inst.
+unused_inst_pair = free_inst - free_inst.
+
+:- func ground_inst = (inst).
+ground_inst = ground(shared, no).
+
+:- func unique_inst = (inst).
+unique_inst = ground(unique, no).
+
+:- func free_inst = (inst).
+free_inst = free(unique).
+
+aditi_ui_mode = in_mode.
+aditi_di_mode = in_mode.
+aditi_uo_mode = out_mode.
 
-out_mode(Mode) :- make_std_mode("out", [], Mode).
-
-uo_mode(Mode) :- make_std_mode("uo", [], Mode).
-
-unused_mode(Mode) :- make_std_mode("unused", [], Mode).
-
-aditi_ui_mode = Mode :- in_mode(Mode). 
+:- pred make_std_mode(string, list(inst), (mode)).
+:- mode make_std_mode(in, in, out) is det.
 
-aditi_di_mode = Mode :- in_mode(Mode).
+make_std_mode(Name, Args, make_std_mode(Name, Args)).
 
-aditi_uo_mode = Mode :- out_mode(Mode).
+:- func make_std_mode(string, list(inst)) = (mode).
 
-:- pred make_std_mode(string, list(inst), mode).
-:- mode make_std_mode(in, in, out) is det.
-
-make_std_mode(Name, Args, Mode) :-
+make_std_mode(Name, Args) = Mode :-
 	mercury_public_builtin_module(MercuryBuiltin),
 	QualifiedName = qualified(MercuryBuiltin, Name),
 	Mode = user_defined_mode(QualifiedName, Args).
@@ -2806,6 +2601,23 @@
 	;
 		InputArgs = InputArgs1,
 		OutputArgs = [Arg | OutputArgs1]
+	).
+
+%-----------------------------------------------------------------------------%
+
+fix_type_info_cons_id_arity(ConsId, Args, InstConsId) :-
+	(
+		ConsId = cons(SymName, _),
+		SymName = qualified(Module, UnqualName),
+		mercury_private_builtin_module(Module),
+		( UnqualName = "typeclass_info"
+		; UnqualName = "type_info"
+		)
+	->
+		list__length(Args, InstArity),
+		InstConsId = cons(SymName, InstArity)
+	;
+		InstConsId = ConsId
 	).
 
 %-----------------------------------------------------------------------------%
--- ../../../amerge2/mercury/compiler/modecheck_unify.m	Thu Dec 16 17:16:48 1999
+++ modecheck_unify.m	Tue Dec 21 08:59:35 1999
@@ -497,45 +497,20 @@
 		unqualify_name(Name0, UnqualName),
 		Name = qualified(TypeModule, UnqualName),
 		ConsId = cons(Name, OrigArity),
-		%
-		% Fix up the cons_id arity for type(class)_info constructions.
-		% The cons_id for type(class)_info constructions always has
-		% arity 1, to match the arity in the declaration in
-		% library/private_builtin.m,
-		% but for the inst we need the arity of the cons_id
-		% to match the number of arguments.
-		%
-		(
-			mercury_private_builtin_module(TypeModule),
-			( UnqualName = "typeclass_info"
-			; UnqualName = "type_info"
-			)
-		->
-			list__length(ArgVars0, InstArity),
-			InstConsId = cons(Name, InstArity)
-		;
-			InstConsId = ConsId
-		)
+		fix_type_info_cons_id_arity(ConsId, ArgVars0, InstConsId)
 	;
 		ConsId = ConsId0,
 		InstConsId = ConsId
 	),
 	mode_info_get_instmap(ModeInfo0, InstMap0),
 	instmap__lookup_var(InstMap0, X, InstOfX),
-<<<<<<< modecheck_unify.m
 	mode_info_make_aliased_insts(ArgVars0, InstArgs, ModeInfo0, ModeInfo1),
 	mode_info_get_module_info(ModeInfo1, ModuleInfo1),
 	mode_info_get_inst_table(ModeInfo1, InstTable1),
 	mode_info_get_instmap(ModeInfo1, InstMap1),
 	mode_info_var_is_live(ModeInfo1, X, LiveX),
 	mode_info_var_list_is_live(ArgVars0, ModeInfo1, LiveArgs),
-	InstOfY = bound(unique, [functor(ConsId, InstArgs)]),
-=======
-	instmap__lookup_vars(ArgVars0, InstMap0, InstArgs),
-	mode_info_var_is_live(ModeInfo0, X, LiveX),
-	mode_info_var_list_is_live(ArgVars0, ModeInfo0, LiveArgs),
 	InstOfY = bound(unique, [functor(InstConsId, InstArgs)]),
->>>>>>> 1.41
 	(
 		% The occur check: X = f(X) is considered a mode error
 		% unless X is ground.  (Actually it wouldn't be that
@@ -573,8 +548,7 @@
 		ArgVars = ArgVars0,
 		ExtraGoals = no_extra_goals
 	;
-<<<<<<< modecheck_unify.m
-		abstractly_unify_inst_functor(LiveX, InstOfX, ConsId,
+		abstractly_unify_inst_functor(LiveX, InstOfX, InstConsId,
 			InstArgs, LiveArgs, real_unify, InstTable1,
 			ModuleInfo1, InstMap1,
 			UnifyInst, Det1, InstTable2, ModuleInfo2, InstMap2),
@@ -591,11 +565,6 @@
 			% as early as possible and then, in the code generator,
 			% cache references to free(alias) variables until they
 			% are actually needed.
-=======
-		abstractly_unify_inst_functor(LiveX, InstOfX, InstConsId,
-			InstArgs, LiveArgs, real_unify, ModuleInfo0,
-			UnifyInst, Det1, ModuleInfo1)
->>>>>>> 1.41
 	->
 		Inst = UnifyInst,
 		mode_info_set_module_info(ModeInfo1, ModuleInfo2, ModeInfo2),
@@ -614,15 +583,11 @@
 			inst_expand(InstMap1, InstTable4, ModuleInfo4,
 				InstOfX, InstOfX2),
 			list__length(ArgVars0, Arity),
-<<<<<<< modecheck_unify.m
-			get_arg_insts(InstOfX2, ConsId, Arity, InitialInstsX),
+			get_arg_insts(InstOfX2, InstConsId,
+				Arity, InitialInstsX),
 			inst_expand(InstMap2, InstTable4, ModuleInfo4,
 				Inst, Inst2),
-			get_arg_insts(Inst2, ConsId, Arity, FinalInstsX)
-=======
-			get_arg_insts(InstOfX1, InstConsId, Arity, InstOfXArgs),
-			get_mode_of_args(Inst, InstOfXArgs, ModeOfXArgs0)
->>>>>>> 1.41
+			get_arg_insts(Inst2, InstConsId, Arity, FinalInstsX)
 		->
 			assoc_list__from_corresponding_lists(InitialInstsX,
 				FinalInstsX, ModeOfXArgs)
--- ../../../amerge2/mercury/compiler/modes.m	Thu Dec 16 17:16:49 1999
+++ modes.m	Fri Dec 17 09:10:26 1999
@@ -248,13 +248,14 @@
 					mode_info).
 :- mode mode_info_remove_goals_live_vars(in, mode_info_di, mode_info_uo) is det.
 
-	% modecheck_functor_test(ConsId, Var):
+	% modecheck_functor_test(ConsId, Var, IMDelta):
 	%	update the instmap to reflect the fact that
 	%	Var was bound to ConsId. 
 	% This is used for the functor tests in `switch' statements.
 	%
-:- pred modecheck_functor_test(prog_var, cons_id, mode_info, mode_info).
-:- mode modecheck_functor_test(in, in, mode_info_di, mode_info_uo) is det.
+:- pred modecheck_functor_test(prog_var, cons_id, instmap_delta,
+		mode_info, mode_info).
+:- mode modecheck_functor_test(in, in, out, mode_info_di, mode_info_uo) is det.
 
 %-----------------------------------------------------------------------------%
 
@@ -1068,17 +1069,13 @@
 	{ goal_info_get_nonlocals(GoalInfo0, InnerNonLocals) },
 	{ goal_get_nonlocals(B0, B_Vars) },
 	mode_info_dcg_get_instmap(InstMap0),
-<<<<<<< modes.m
-	{ instmap__vars(InstMap0, OuterNonLocals) },
-	{ set__union(InnerNonLocals, OuterNonLocals, NonLocals) },
-	mode_info_lock_vars(if_then_else, InnerNonLocals),
-=======
 	%
 	% We need to lock the non-local variables, to ensure
 	% that the condition of the if-then-else does not bind them.
 	%
-	mode_info_lock_vars(if_then_else, NonLocals),
->>>>>>> 1.237
+	{ instmap__vars(InstMap0, OuterNonLocals) },
+	{ set__union(InnerNonLocals, OuterNonLocals, NonLocals) },
+	mode_info_lock_vars(if_then_else, InnerNonLocals),
 	mode_info_add_live_vars(B_Vars),
 	modecheck_goal(A0, A),
 	mode_info_dcg_get_instmap(InstMapA),
@@ -1241,17 +1238,12 @@
 			InstMap0, Goal),
 
 	mode_info_unset_call_context,
-<<<<<<< modes.m
 	mode_checkpoint(exit, "pragma_c_code", GoalInfo).
 
-=======
-	mode_checkpoint(exit, "pragma_c_code").
-
 modecheck_goal_expr(bi_implication(_, _), _, _) -->
 	% these should have been expanded out by now
 	{ error("modecheck_goal_expr: unexpected bi_implication") }.
 
->>>>>>> 1.237
  	% given the right-hand-side of a unification, return a list of
 	% the potentially non-local variables of that unification.
 
@@ -1686,27 +1678,12 @@
 	{ Case = case(ConsId, IMDelta, Goal) },
 	mode_info_dcg_get_instmap(InstMap0),
 
-<<<<<<< modes.m
-		% record the fact that Var was bound to ConsId in the
-		% instmap before processing this case
-	mode_info_bind_var_to_functor(Var, ConsId),
-	mode_info_dcg_get_instmap(InstMap1),
-	{ compute_instmap_delta(InstMap0, InstMap1, IMDelta) },
-=======
 	% record the fact that Var was bound to ConsId in the
 	% instmap before processing this case
-	modecheck_functor_test(Var, ConsId),
->>>>>>> 1.237
-
-<<<<<<< modes.m
-		% modecheck this case (if it is reachable)
-	mode_info_dcg_get_instmap(InstMap2),
-	( { instmap__is_reachable(InstMap2) } ->
-=======
+	modecheck_functor_test(Var, ConsId, IMDelta),
 	% modecheck this case (if it is reachable)
 	mode_info_dcg_get_instmap(InstMap1),
 	( { instmap__is_reachable(InstMap1) } ->
->>>>>>> 1.237
 		modecheck_goal(Goal0, Goal1),
 		mode_info_dcg_get_instmap(InstMap)
 	;
@@ -1714,7 +1691,7 @@
 		% Instead we optimize the goal away, so that later passes
 		% won't complain about it not having mode information.
 		{ true_goal(Goal1) },
-		{ InstMap = InstMap2 }
+		{ InstMap = InstMap1 }
 	),
 
 	% Don't lose the information added by the functor test above.
@@ -1729,20 +1706,11 @@
 	%	Var was bound to ConsId. 
 	% This is used for the functor tests in `switch' statements.
 	%
-modecheck_functor_test(Var, ConsId) -->
-		% figure out the arity of this constructor,
-		% _including_ any type-infos or typeclass-infos
-		% inserted for existential data types.
-	=(ModeInfo0),
-	{ mode_info_get_module_info(ModeInfo0, ModuleInfo) },
-	{ mode_info_get_var_types(ModeInfo0, VarTypes) },
-	{ map__lookup(VarTypes, Var, Type) },
-	{ AdjustedArity = cons_id_adjusted_arity(ModuleInfo, Type, ConsId) },
-
-		% record the fact that Var was bound to ConsId in the instmap
-	{ list__duplicate(AdjustedArity, free, ArgInsts) },
-	modecheck_set_var_inst(Var,
-		bound(unique, [functor(ConsId, ArgInsts)])).
+modecheck_functor_test(Var, ConsId, IMDelta) -->
+	mode_info_dcg_get_instmap(InstMap0),
+	mode_info_bind_var_to_functor(Var, ConsId),
+	mode_info_dcg_get_instmap(InstMap1),
+	{ compute_instmap_delta(InstMap0, InstMap1, IMDelta) }.
 
 %-----------------------------------------------------------------------------%
 
--- ../../../amerge2/mercury/compiler/quantification.m	Thu Dec 16 17:17:08 1999
+++ quantification.m	Mon Dec 20 17:11:15 1999
@@ -361,6 +361,7 @@
 	implicitly_quantify_atomic_goal(Vars).
 
 implicitly_quantify_goal_2(bi_implication(LHS0, RHS0), Context, Goal) -->
+
 		% get the initial values of various settings
 	quantification__get_quant_vars(QuantVars0),
 	quantification__get_outside(OutsideVars0),
@@ -433,7 +434,17 @@
 	{ NotLHS = not(LHS) - LHS_GI },
 	{ NotRHS = not(RHS) - RHS_GI },
 	{ ForwardsImplication = not(conj([LHS, NotRHS]) - GI) - GI },
-	{ ReverseImplication = not(conj([RHS, NotLHS]) - GI) - GI },
+
+		%
+		% Rename apart the local variables of the goals
+		% we've just duplicated.
+		%
+	{ ReverseImplication0 = not(conj([RHS, NotLHS]) - GI) - GI },
+	{ quantification__goal_vars(ReverseImplication0, GoalVars0) },
+	{ set__difference(GoalVars0, NonLocalVars, RenameVars) },
+	quantification__rename_apart(RenameVars, _,
+		ReverseImplication0, ReverseImplication),
+
 	{ Goal = conj([ForwardsImplication, ReverseImplication]) }.
 
 :- pred implicitly_quantify_atomic_goal(list(prog_var), quant_info, quant_info).

--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list