[m-dev.] for review: alias branch improvements [2/2]

David Overton dmo at cs.mu.OZ.AU
Fri Jul 23 18:23:51 AEST 1999


Index: intermod.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/intermod.m,v
retrieving revision 1.32.2.22
diff -u -u -r1.32.2.22 intermod.m
--- intermod.m	1999/07/19 01:44:41	1.32.2.22
+++ intermod.m	1999/07/21 06:33:15
@@ -65,7 +65,7 @@
 
 :- import_module code_util, globals, goal_util, instmap, term, varset.
 :- import_module hlds_data, hlds_goal, hlds_pred, hlds_out, inlining, llds.
-:- import_module mercury_to_mercury, mode_util, modules.
+:- import_module mercury_to_mercury, mode_util, modules, inst_table.
 :- import_module options, passes_aux, prog_data, prog_io, prog_out, prog_util.
 :- import_module special_pred, typecheck, type_util, instmap, (inst).
 
Index: lambda.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/lambda.m,v
retrieving revision 1.32.2.18
diff -u -u -r1.32.2.18 lambda.m
--- lambda.m	1999/07/19 01:44:42	1.32.2.18
+++ lambda.m	1999/07/21 06:33:29
@@ -69,7 +69,8 @@
 
 :- interface. 
 
-:- import_module hlds_module, hlds_pred, hlds_goal, hlds_data, prog_data.
+:- import_module hlds_module, hlds_pred, hlds_goal, prog_data.
+:- import_module inst_table.
 :- import_module list, map, set.
 
 :- pred lambda__process_module(module_info, module_info).
Index: lco.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/lco.m,v
retrieving revision 1.7.2.14
diff -u -u -r1.7.2.14 lco.m
--- lco.m	1999/07/19 01:44:43	1.7.2.14
+++ lco.m	1999/07/21 06:33:55
@@ -29,7 +29,7 @@
 
 :- import_module hlds_goal, passes_aux, hlds_out, (inst), instmap, inst_match.
 :- import_module mode_util, hlds_data, prog_data, type_util, globals, options.
-:- import_module arg_info.
+:- import_module arg_info, inst_table.
 :- import_module list, std_util, map, assoc_list, require.
 :- import_module bool, set, int, varset.
 
Index: liveness.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/liveness.m,v
retrieving revision 1.81.2.17
diff -u -u -r1.81.2.17 liveness.m
--- liveness.m	1999/07/19 01:44:45	1.81.2.17
+++ liveness.m	1999/07/21 06:34:13
@@ -152,7 +152,7 @@
 :- import_module hlds_goal, hlds_data, llds, quantification, (inst), instmap.
 :- import_module hlds_out, mode_util, code_util, quantification, options.
 :- import_module prog_data, trace, globals, polymorphism, passes_aux.
-:- import_module inst_match, term, varset.
+:- import_module inst_match, inst_table, term, varset.
 
 :- import_module bool, map, std_util, list, assoc_list, require.
 :- import_module string.
Index: llds.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/llds.m,v
retrieving revision 1.210.2.17
diff -u -u -r1.210.2.17 llds.m
--- llds.m	1999/07/19 01:44:47	1.210.2.17
+++ llds.m	1999/07/21 05:22:27
@@ -17,7 +17,7 @@
 :- interface.
 
 :- import_module hlds_pred, hlds_data, tree, prog_data, (inst).
-:- import_module builtin_ops.
+:- import_module builtin_ops, inst_table.
 
 :- import_module bool, assoc_list, list, map, set, std_util.
 
Index: magic_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/magic_util.m,v
retrieving revision 1.1.2.4
diff -u -u -r1.1.2.4 magic_util.m
--- magic_util.m	1999/07/19 01:44:51	1.1.2.4
+++ magic_util.m	1999/07/21 06:00:18
@@ -15,7 +15,7 @@
 :- interface.
 
 :- import_module hlds_data, hlds_goal, hlds_module, hlds_pred, prog_data.
-:- import_module (inst), instmap.
+:- import_module (inst), instmap, inst_table.
 :- import_module bool, io, list, map, set, std_util.
 
 	% Check that the argument types and modes are legal for
Index: make_hlds.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/make_hlds.m,v
retrieving revision 1.239.2.24
diff -u -u -r1.239.2.24 make_hlds.m
--- make_hlds.m	1999/07/19 01:44:52	1.239.2.24
+++ make_hlds.m	1999/07/21 06:34:32
@@ -63,7 +63,7 @@
 :- import_module code_util, unify_proc, special_pred, type_util, mode_util.
 :- import_module mercury_to_mercury, passes_aux, clause_to_proc, inst_match.
 :- import_module fact_table, purity, goal_util, term_util, export, llds.
-:- import_module error_util.
+:- import_module error_util, inst_table.
 
 :- import_module string, char, int, set, bintree, map, multi_map, require.
 :- import_module term, varset, getopt, assoc_list, term_io.
Index: mercury_to_c.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mercury_to_c.m,v
retrieving revision 1.27.2.14
diff -u -u -r1.27.2.14 mercury_to_c.m
--- mercury_to_c.m	1999/07/19 01:44:58	1.27.2.14
+++ mercury_to_c.m	1999/07/21 06:34:55
@@ -56,7 +56,7 @@
 :- import_module hlds_pred, hlds_goal, hlds_data, prog_data, instmap, (inst).
 :- import_module llds, llds_out, prog_out, prog_io, mercury_to_mercury.
 :- import_module prog_util, mode_util, hlds_out, stack, quantification.
-:- import_module globals, options, varset, term.
+:- import_module globals, options, inst_table, varset, term.
 :- import_module string, map, list, require, std_util, term_io, getopt.
 :- import_module bool, set, int.
 
Index: mercury_to_goedel.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mercury_to_goedel.m,v
retrieving revision 1.60.2.7
diff -u -u -r1.60.2.7 mercury_to_goedel.m
--- mercury_to_goedel.m	1999/07/13 04:43:47	1.60.2.7
+++ mercury_to_goedel.m	1999/07/21 06:35:11
@@ -42,7 +42,7 @@
 :- implementation.
 :- import_module bool, int, char, std_util, require, string.
 :- import_module prog_io, prog_out, prog_util, equiv_type, purity.
-:- import_module globals, options, hlds_data, term, varset.
+:- import_module globals, options, hlds_data, inst_table, term, varset.
 %-----------------------------------------------------------------------------%
 
 	% The following is a hard-coded hack.
Index: mercury_to_mercury.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mercury_to_mercury.m,v
retrieving revision 1.115.2.27
diff -u -u -r1.115.2.27 mercury_to_mercury.m
--- mercury_to_mercury.m	1999/07/19 01:44:59	1.115.2.27
+++ mercury_to_mercury.m	1999/07/21 06:35:31
@@ -28,7 +28,7 @@
 	;	expand_silently		% Expansion
 	;	expand_noisily.		% alias(IK, Expansion)
 
-:- import_module hlds_goal, hlds_data, prog_data, (inst), instmap.
+:- import_module hlds_goal, hlds_data, prog_data, (inst), instmap, inst_table.
 :- import_module bool, std_util, list, io, varset, term.
 
 %	convert_to_mercury(ModuleName, OutputFileName, Items)
@@ -991,10 +991,10 @@
 		InstMap, InstTable),
 	mercury_output_tabs(Indent),
 	io__write_string(")\n").
-mercury_output_structured_inst_name(Expand, substitution_inst(InstName, _, _),
+mercury_output_structured_inst_name(Expand, other_inst(_Id, InstName),
 		Indent, VarSet, InstMap, InstTable) -->
 	mercury_output_tabs(Indent),
-	io__write_string("$substitution_inst(\n"),
+	io__write_string("$other_inst(\n"),
 	{ Indent1 is Indent + 1 },
 	mercury_output_structured_inst_name(Expand, InstName, Indent1, VarSet,
 		InstMap, InstTable),
@@ -1098,9 +1098,8 @@
 	io__write_string(", "),
 	mercury_output_inst_name(InstName, VarSet, InstTable),
 	io__write_string(")").
-mercury_output_inst_name(substitution_inst(InstName, _, _), VarSet,
-		InstTable) -->
-	io__write_string("$substitution_inst("),
+mercury_output_inst_name(other_inst(_Id, InstName), VarSet, InstTable) -->
+	io__write_string("$other_inst("),
 	mercury_output_inst_name(InstName, VarSet, InstTable),
 	io__write_string(")").
 
Index: mode_debug.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mode_debug.m,v
retrieving revision 1.9.4.7
diff -u -u -r1.9.4.7 mode_debug.m
--- mode_debug.m	1998/11/24 06:29:53	1.9.4.7
+++ mode_debug.m	1999/07/23 07:23:46
@@ -1,5 +1,5 @@
 %-----------------------------------------------------------------------------%
-% Copyright (C) 1996-1998 The University of Melbourne.
+% Copyright (C) 1996-1999 The University of Melbourne.
 % This file may only be copied under the terms of the GNU General
 % Public License - see the file COPYING in the Mercury distribution.
 %-----------------------------------------------------------------------------%
@@ -41,7 +41,7 @@
 :- import_module term, varset, string, require.
 :- import_module modes, options, mercury_to_mercury, passes_aux.
 :- import_module globals, hlds_goal, instmap, prog_data, (inst).
-:- import_module hlds_module, hlds_data.
+:- import_module hlds_module, hlds_data, inst_table.
 
 %-----------------------------------------------------------------------------%
 
Index: mode_errors.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mode_errors.m,v
retrieving revision 1.47.4.16
diff -u -u -r1.47.4.16 mode_errors.m
--- mode_errors.m	1999/07/19 01:45:02	1.47.4.16
+++ mode_errors.m	1999/07/21 05:23:05
@@ -18,7 +18,7 @@
 :- interface.
 
 :- import_module hlds_data, hlds_pred, hlds_module, hlds_goal.
-:- import_module prog_data, mode_info, (inst).
+:- import_module prog_data, mode_info, (inst), inst_table.
 :- import_module bool, set, assoc_list, list.
 
 %-----------------------------------------------------------------------------%
Index: mode_info.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mode_info.m,v
retrieving revision 1.39.4.17
diff -u -u -r1.39.4.17 mode_info.m
--- mode_info.m	1999/07/19 01:45:03	1.39.4.17
+++ mode_info.m	1999/07/21 05:23:33
@@ -18,6 +18,7 @@
 
 :- import_module hlds_module, hlds_pred, hlds_goal, hlds_data, instmap.
 :- import_module prog_data, mode_errors, delay_info, mode_debug, (inst).
+:- import_module inst_table.
 :- import_module map, list, set, bool, assoc_list, std_util.
 
 :- interface.
Index: mode_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mode_util.m,v
retrieving revision 1.99.2.30
diff -u -u -r1.99.2.30 mode_util.m
--- mode_util.m	1999/07/19 01:45:04	1.99.2.30
+++ mode_util.m	1999/07/23 01:54:32
@@ -15,7 +15,7 @@
 :- interface.
 
 :- import_module hlds_module, hlds_pred, hlds_goal, hlds_data, prog_data.
-:- import_module instmap, (inst).
+:- import_module instmap, (inst), inst_table.
 :- import_module bool, list, map, assoc_list.
 
 	% mode_get_insts returns the initial instantiatedness and
@@ -205,8 +205,8 @@
 
 %-----------------------------------------------------------------------------%
 
-:- pred apply_inst_key_sub_mode(inst_key_sub, mode, mode).
-:- mode apply_inst_key_sub_mode(in, in, out) is det.
+:- pred apply_inst_table_sub_mode(inst_table_sub, mode, mode).
+:- mode apply_inst_table_sub_mode(in, in, out) is det.
 
 %-----------------------------------------------------------------------------%
 
@@ -592,10 +592,10 @@
 		map__init(Subst),
 		propagate_type_into_inst(Type, Subst, InstTable, ModuleInfo,
 			Inst0, Inst)
-	; InstName = substitution_inst(SubInstName, SubKeys, Sub),
-		inst_table_get_substitution_insts(InstTable, SubInsts),
-		map__lookup(SubInsts, substitution_inst(SubInstName, SubKeys,
-			Sub), MaybeInst),
+	; InstName = other_inst(OtherInstId, OtherInstName),
+		inst_table_get_other_insts(InstTable, OtherInsts),
+		other_inst_table_lookup(OtherInsts, OtherInstId, OtherInstName,
+			MaybeInst),
 		( MaybeInst = known(Inst0) ->
 			Inst = Inst0
 		;
@@ -1238,8 +1238,8 @@
 		typed_inst(T, Inst)) :-
 	inst_name_apply_substitution(Inst0, Subst, Inst).
 inst_name_apply_substitution(typed_ground(Uniq, T), _, typed_ground(Uniq, T)).
-inst_name_apply_substitution(substitution_inst(InstName0, K, S), Subst,
-		substitution_inst(InstName, K, S)) :-
+inst_name_apply_substitution(other_inst(Id, InstName0), Subst,
+		other_inst(Id, InstName)) :-
 	inst_name_apply_substitution(InstName0, Subst, InstName).
 
 :- pred alt_list_apply_substitution(list(bound_inst), inst_subst,
@@ -1620,7 +1620,7 @@
 	{ recompute_info_get_inst_table(RI0, InstTable0) },
 	{ Modes = argument_modes(ArgInstTable, ArgModes0) },
 	{ inst_table_create_sub(InstTable0, ArgInstTable, Sub, InstTable) },
-	{ list__map(apply_inst_key_sub_mode(Sub), ArgModes0, ArgModes) },
+	{ list__map(apply_inst_table_sub_mode(Sub), ArgModes0, ArgModes) },
 	recompute_info_set_inst_table(InstTable),
 	recompute_instmap_delta_call_2(Vars, InstMap0, ArgModes, InstMap),
 	{ compute_instmap_delta(InstMap0, InstMap, InstMapDelta) }.
@@ -1795,7 +1795,7 @@
 		proc_info_argmodes(ProcInfo,
 			argument_modes(ArgInstTable, ArgModes0)),
 		inst_table_create_sub(InstTable0, ArgInstTable, Sub, InstTable),
-		list__map(apply_inst_key_sub_mode(Sub), ArgModes0, ArgModes),
+		list__map(apply_inst_table_sub_mode(Sub), ArgModes0, ArgModes),
 		recompute_info_set_inst_table(InstTable, RI0, RI1),
 		recompute_instmap_delta_call_2(Args, InstMap0,
 			ArgModes, InstMap, RI1, RI),
@@ -2139,8 +2139,9 @@
 		recompute_info_get_vartypes(RI0, VarTypes),
 		map__lookup(VarTypes, Var, Type),
 		( type_to_type_id(Type, TypeId, _) ->
-			unify_proc__request_unify(TypeId - ComplUniMode,
-				Det, Context, InstTable, ModuleInfo2,
+			unify_proc__request_unify(unify_proc_id(TypeId,
+					InitialInstX, InitialInstY, InstTable),
+				Det, Context, InstMap0, ModuleInfo2,
 				ModuleInfo)
 		;
 			ModuleInfo = ModuleInfo2
@@ -2506,12 +2507,12 @@
 
 %-----------------------------------------------------------------------------%
 
-apply_inst_key_sub_mode(Sub, (I0 -> F0), (I -> F)) :-
-	inst_apply_sub(Sub, I0, I),
-	inst_apply_sub(Sub, F0, F).
-apply_inst_key_sub_mode(Sub, user_defined_mode(SymName, Insts0),
+apply_inst_table_sub_mode(Sub, (I0 -> F0), (I -> F)) :-
+	inst_apply_inst_table_sub(Sub, I0, I),
+	inst_apply_inst_table_sub(Sub, F0, F).
+apply_inst_table_sub_mode(Sub, user_defined_mode(SymName, Insts0),
 		user_defined_mode(SymName, Insts)) :-
-	list__map(inst_apply_sub(Sub), Insts0, Insts).
+	list__map(inst_apply_inst_table_sub(Sub), Insts0, Insts).
 
 %-----------------------------------------------------------------------------%
 
Index: modecheck_call.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/modecheck_call.m,v
retrieving revision 1.15.2.17
diff -u -u -r1.15.2.17 modecheck_call.m
--- modecheck_call.m	1999/07/19 01:45:06	1.15.2.17
+++ modecheck_call.m	1999/07/21 07:02:11
@@ -69,7 +69,7 @@
 %-----------------------------------------------------------------------------%
 
 :- implementation.
-:- import_module hlds_data, instmap, prog_data, (inst).
+:- import_module hlds_data, instmap, prog_data, (inst), inst_table.
 :- import_module mode_info, mode_debug, modes, mode_util, mode_errors.
 :- import_module clause_to_proc, inst_match, inst_util, make_hlds.
 :- import_module det_report, unify_proc.
@@ -177,7 +177,7 @@
 	%
 	mode_info_get_inst_table(ModeInfo1, InstTable0),
 	inst_table_create_sub(InstTable0, ArgInstTable, Sub, InstTable1),
-	list__map(apply_inst_key_sub_mode(Sub), ArgModes0, ArgModes),
+	list__map(apply_inst_table_sub_mode(Sub), ArgModes0, ArgModes),
 	mode_info_set_inst_table(InstTable1, ModeInfo1, ModeInfo2),
 
 	%
@@ -263,7 +263,7 @@
 		mode_info_get_inst_table(ModeInfo1, InstTable0),
 		inst_table_create_sub(InstTable0, ArgInstTable, Sub,
 					InstTable1),
-		list__map(apply_inst_key_sub_mode(Sub), ArgModes0, ArgModes),
+		list__map(apply_inst_table_sub_mode(Sub), ArgModes0, ArgModes),
 		mode_info_set_inst_table(InstTable1, ModeInfo1, ModeInfo2),
 
 		mode_list_get_initial_insts(ArgModes, ModuleInfo,
@@ -380,7 +380,7 @@
 	proc_info_argmodes(ProcInfo, argument_modes(ArgInstTable, ArgModes0)),
 	mode_info_get_inst_table(ModeInfo0, InstTable0),
 	inst_table_create_sub(InstTable0, ArgInstTable, Sub, InstTable1),
-	list__map(apply_inst_key_sub_mode(Sub), ArgModes0, ArgModes),
+	list__map(apply_inst_table_sub_mode(Sub), ArgModes0, ArgModes),
 	mode_info_set_inst_table(InstTable1, ModeInfo0, ModeInfo1),
 
 		% check whether the livenesses of the args matches their
@@ -546,7 +546,7 @@
 		OtherProcInstMap),
 	inst_table_create_sub(ProcArgInstTable, OtherProcArgInstTable,
 			Sub, InstTable),
-	list__map(apply_inst_key_sub_mode(Sub), OtherProcArgModes0,
+	list__map(apply_inst_table_sub_mode(Sub), OtherProcArgModes0,
 		OtherProcArgModes),
 	mode_list_get_initial_insts(ProcArgModes, ModuleInfo, InitialInsts),
 	mode_list_get_initial_insts(OtherProcArgModes, ModuleInfo,
@@ -606,7 +606,7 @@
 		OtherProcInstMap),
 	inst_table_create_sub(ProcArgInstTable, OtherProcArgInstTable,
 		Sub, InstTable),
-	list__map(apply_inst_key_sub_mode(Sub), OtherProcArgModes0,
+	list__map(apply_inst_table_sub_mode(Sub), OtherProcArgModes0,
 		OtherProcArgModes),
 	mode_list_get_initial_insts(ProcArgModes, ModuleInfo, InitialInsts),
 	mode_list_get_initial_insts(OtherProcArgModes, ModuleInfo,
@@ -734,23 +734,28 @@
 	%
 	mode_info_get_module_info(ModeInfo, ModuleInfo),
 	proc_info_argmodes(ProcInfo,
-		argument_modes(ProcArgInstTable, ProcArgModes)),
+		argument_modes(ProcArgInstTable, ProcArgModes0)),
 	proc_info_get_initial_instmap(ProcInfo, ModuleInfo,
 		ProcInstMap),
 	proc_info_argmodes(OtherProcInfo,
 		argument_modes(OtherProcArgInstTable, OtherProcArgModes0)),
 	proc_info_get_initial_instmap(OtherProcInfo, ModuleInfo,
 		OtherProcInstMap),
-	inst_table_create_sub(ProcArgInstTable, OtherProcArgInstTable,
-			Sub, InstTable),
-	list__map(apply_inst_key_sub_mode(Sub), OtherProcArgModes0,
+	mode_info_get_inst_table(ModeInfo, InstTable0),
+	inst_table_create_sub(InstTable0, ProcArgInstTable, Sub0, InstTable1),
+	inst_table_create_sub(InstTable1, OtherProcArgInstTable, Sub1,
+		InstTable),
+	list__map(apply_inst_table_sub_mode(Sub0), ProcArgModes0, ProcArgModes),
+	list__map(apply_inst_table_sub_mode(Sub1), OtherProcArgModes0,
 		OtherProcArgModes),
 	mode_list_get_initial_insts(ProcArgModes, ModuleInfo, InitialInsts),
 	mode_list_get_initial_insts(OtherProcArgModes, ModuleInfo,
 							OtherInitialInsts),
+	mode_info_get_instmap(ModeInfo, InstMap),
 	get_var_insts_and_lives(ArgVars, ModeInfo, ArgInitialInsts, _ArgLives),
-	compare_inst_list(InitialInsts, OtherInitialInsts, yes(ArgInitialInsts),
-		InstTable, CompareInsts, ModuleInfo),
+	compare_inst_list(InitialInsts, OtherInitialInsts,
+		yes(ArgInitialInsts - InstMap), InstTable, CompareInsts,
+		ModuleInfo),
 	%
 	% Compare the expected livenesses of the arguments
 	%
@@ -776,36 +781,41 @@
 	combine_results(CompareInsts, CompareLives, Compare0),
 	prioritized_combine_results(Compare0, CompareDet, Compare).
 
-:- pred compare_inst_list(list(inst), list(inst), maybe(list(inst)),
-				inst_table, match, module_info).
+:- pred compare_inst_list(list(inst), list(inst),
+	maybe(pair(list(inst), instmap)), inst_table, match, module_info).
 :- mode compare_inst_list(in, in, in, in, out, in) is det.
 
 compare_inst_list(InstsA, InstsB, ArgInsts, InstTable, Result, ModuleInfo) :-
+	map__init(AliasMap0),
 	(
 		compare_inst_list_2(InstsA, InstsB, ArgInsts, InstTable,
-				Result0, ModuleInfo)
+			AliasMap0, Result0, ModuleInfo)
 	->
 		Result = Result0
 	;
 		error("compare_inst_list: length mis-match")
 	).
 
-:- pred compare_inst_list_2(list(inst), list(inst), maybe(list(inst)),
-				inst_table, match, module_info).
-:- mode compare_inst_list_2(in, in, in, in, out, in) is semidet.
+:- pred compare_inst_list_2(list(inst), list(inst),
+	maybe(pair(list(inst), instmap)), inst_table, alias_map, match,
+	module_info).
+:- mode compare_inst_list_2(in, in, in, in, in, out, in) is semidet.
 
-compare_inst_list_2([], [], _, _, same, _).
+compare_inst_list_2([], [], _, _, _, same, _).
 compare_inst_list_2([InstA | InstsA], [InstB | InstsB],
-		no, InstTable, Result, ModuleInfo) :-
-	compare_inst(InstA, InstB, no, InstTable, Result0, ModuleInfo),
-	compare_inst_list_2(InstsA, InstsB, no, InstTable, Result1, ModuleInfo),
+		no, InstTable, AliasMap0, Result, ModuleInfo) :-
+	compare_inst(InstA, InstB, no, InstTable, AliasMap0, AliasMap1,
+		Result0, ModuleInfo),
+	compare_inst_list_2(InstsA, InstsB, no, InstTable, AliasMap1,
+		Result1, ModuleInfo),
 	combine_results(Result0, Result1, Result).
 compare_inst_list_2([InstA | InstsA], [InstB | InstsB],
-		yes([ArgInst|ArgInsts]), InstTable, Result, ModuleInfo) :-
-	compare_inst(InstA, InstB, yes(ArgInst), InstTable, Result0,
-		ModuleInfo),
-	compare_inst_list_2(InstsA, InstsB, yes(ArgInsts), InstTable, Result1,
-		ModuleInfo),
+		yes([ArgInst|ArgInsts] - InstMap), InstTable, AliasMap0,
+		Result, ModuleInfo) :-
+	compare_inst(InstA, InstB, yes(ArgInst - InstMap), InstTable, AliasMap0,
+		AliasMap1, Result0, ModuleInfo),
+	compare_inst_list_2(InstsA, InstsB, yes(ArgInsts - InstMap), InstTable,
+		AliasMap1, Result1, ModuleInfo),
 	combine_results(Result0, Result1, Result).
 
 :- pred compare_liveness_list(list(is_live), list(is_live), match).
@@ -880,33 +890,46 @@
 	% 	prefer ground to any	(e.g. prefer in to in(any))
 	% 	prefer any to free	(e.g. prefer any->ground to out)
 
-:- pred compare_inst(inst, inst, maybe(inst), inst_table, match, module_info).
-:- mode compare_inst(in, in, in, in, out, in) is det.
+:- pred compare_inst(inst, inst, maybe(pair(inst, instmap)), inst_table,
+	alias_map, alias_map, match, module_info).
+:- mode compare_inst(in, in, in, in, in, out, out, in) is det.
 
-compare_inst(InstA, InstB, MaybeArgInst, InstTable, Result, ModuleInfo) :-
+compare_inst(InstA, InstB, MaybeArgInst, InstTable, AliasMap0, AliasMap,
+		Result, ModuleInfo) :-
 	% inst_matches_initial(A,B) succeeds iff
 	%	A specifies at least as much information
 	%	and at least as much binding as B --
 	%	with the exception that `any' matches_initial `free'
 	% 	and perhaps vice versa.
-	instmap__init_reachable(InstMapA),	% YYY
-	instmap__init_reachable(InstMapB),	% YYY
-	instmap__init_reachable(MaybeInstMap),	% YYY
+	instmap__init_reachable(InstMapA),
+	instmap__init_reachable(InstMapB),
+		% Empty instmaps are ok here because InstA and InstB are
+		% initial insts of procedures which will have no alias
+		% substitutions on them.
 	(
 		inst_matches_initial(InstA, InstMapA, InstB, InstMapB,
-				InstTable, ModuleInfo)
+			InstTable, ModuleInfo, AliasMap0, AliasMap1)
 	->
-		A_mi_B = yes
+		A_mi_B = yes,
+		AliasMap2 = AliasMap1
 	;
-		A_mi_B = no
+		A_mi_B = no,
+		AliasMap2 = AliasMap0
 	),
 	(
+		% (It is ok to thread the same AliasMap through both of the
+		% calls to inst_matches_initial in this predicate because
+		% the inst_keys in InstA and InstB will not overlap.  This
+		% is because the inst_keys in InstB were created by
+		% inst_table_create_sub.)
 		inst_matches_initial(InstB, InstMapB, InstA, InstMapA,
-				InstTable, ModuleInfo)
+			InstTable, ModuleInfo, AliasMap2, AliasMap3)
 	->
-		B_mi_A = yes
+		B_mi_A = yes,
+		AliasMap = AliasMap3
 	;
-		B_mi_A = no
+		B_mi_A = no,
+		AliasMap = AliasMap2
 	),
 	( A_mi_B = yes, B_mi_A = no,  Result = better
 	; A_mi_B = no,  B_mi_A = yes, Result = worse
@@ -920,24 +943,27 @@
 		% if the argument is `free', we should prefer `free',
 		% but otherwise, we should prefer `any'.
 		%
+		% We can use the version of inst_matches_final that ignores
+		% aliases here because the aliases have already been checked
+		% by inst_matches_initial, above.
 		(
 			MaybeArgInst = no,
 			Result0 = same
 		;
-			MaybeArgInst = yes(ArgInst),
+			MaybeArgInst = yes(ArgInst - MaybeInstMap),
 			(
-				inst_matches_final(ArgInst, MaybeInstMap,
-					InstA, InstMapA, InstTable,
-					ModuleInfo)
+				inst_matches_final_ignore_aliasing(ArgInst,
+					MaybeInstMap, InstA, InstMapA,
+					InstTable, ModuleInfo)
 			->
 				Arg_mf_A = yes
 			;
 				Arg_mf_A = no
 			),
 			(
-				inst_matches_final(ArgInst, MaybeInstMap,
-					InstB, InstMapB, InstTable,
-					ModuleInfo)
+				inst_matches_final_ignore_aliasing(ArgInst,
+					MaybeInstMap, InstB, InstMapB,
+					InstTable, ModuleInfo)
 			->
 				Arg_mf_B = yes
 			;
@@ -956,8 +982,8 @@
 			% then compare the two proc insts
 			%
 			(
-				inst_matches_final(InstA, InstMapA,
-					InstB, InstMapB, InstTable,
+				inst_matches_final_ignore_aliasing(InstA,
+					InstMapA, InstB, InstMapB, InstTable,
 					ModuleInfo)
 			->
 				A_mf_B = yes
@@ -965,8 +991,8 @@
 				A_mf_B = no
 			),
 			(
-				inst_matches_final(InstB, InstMapB,
-					InstA, InstMapA, InstTable,
+				inst_matches_final_ignore_aliasing(InstB,
+					InstMapB, InstA, InstMapA, InstTable,
 					ModuleInfo)
 			->
 				B_mf_A = yes
Index: modecheck_unify.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/modecheck_unify.m,v
retrieving revision 1.22.2.19
diff -u -u -r1.22.2.19 modecheck_unify.m
--- modecheck_unify.m	1999/07/19 01:45:07	1.22.2.19
+++ modecheck_unify.m	1999/07/23 05:48:19
@@ -45,7 +45,7 @@
 :- import_module mode_debug, mode_util, mode_info, modes, mode_errors.
 :- import_module inst_match, inst_util, unify_proc, code_util, unique_modes.
 :- import_module typecheck, modecheck_call, (inst), quantification, make_hlds.
-:- import_module polymorphism, instmap.
+:- import_module polymorphism, instmap, inst_table.
 
 :- import_module bool, list, map, std_util, int, set, require.
 :- import_module string, assoc_list.
@@ -274,7 +274,7 @@
 
 	Modes = argument_modes(ArgInstTable, ArgModesX),
 	inst_table_create_sub(InstTable0, ArgInstTable, Sub, InstTable1),
-	list__map(apply_inst_key_sub_mode(Sub), ArgModesX, ArgModes),
+	list__map(apply_inst_table_sub_mode(Sub), ArgModesX, ArgModes),
 	mode_list_get_initial_insts(ArgModes, ModuleInfo0, InitialInsts),
 	assoc_list__from_corresponding_lists(Vars, InitialInsts,
 		VarInitialInsts),
@@ -893,8 +893,8 @@
 			ModeInfo = ModeInfo0
 		;
 			modecheck_complicated_unify(X, Y,
-				Type, (IX -> FX), (IY -> FY), Det, UnifyContext,
-				Unification0, ModeInfo0,
+				Type, (IX -> FX), (IY -> FY), InstMapBefore,
+				Det, UnifyContext, Unification0, ModeInfo0,
 				Unification, ModeInfo)
 		)
 	),
@@ -950,27 +950,27 @@
 %
 
 :- pred modecheck_complicated_unify(prog_var, prog_var,
-		type, mode, mode, determinism, unify_context,
+		type, mode, mode, instmap, determinism, unify_context,
 		unification, mode_info, unification, mode_info).
-:- mode modecheck_complicated_unify(in, in, in, in, in, in, in,
+:- mode modecheck_complicated_unify(in, in, in, in, in, in, in, in,
 		in, mode_info_di, out, mode_info_uo) is det.
 
-modecheck_complicated_unify(X, Y, Type, ModeOfX, ModeOfY, Det, UnifyContext,
-		Unification0, ModeInfo0, Unification, ModeInfo) :-
+modecheck_complicated_unify(X, Y, Type, ModeOfX, ModeOfY, InstMapBefore, Det,
+		UnifyContext, Unification0, ModeInfo0, Unification, ModeInfo) :-
 	%
 	% Build up the unification
 	%
 	mode_info_get_module_info(ModeInfo0, ModuleInfo0),
 	mode_get_insts(ModuleInfo0, ModeOfX, InitialInstX, FinalInstX),
 	mode_get_insts(ModuleInfo0, ModeOfY, InitialInstY, FinalInstY),
-	UniMode0 = ((InitialInstX - InitialInstY) -> (FinalInstX - FinalInstY)),
+	UniMode = ((InitialInstX - InitialInstY) -> (FinalInstX - FinalInstY)),
 	determinism_components(Det, CanFail, _),
 	( Unification0 = complicated_unify(_, _, UnifyTypeInfoVars0) ->
 		UnifyTypeInfoVars = UnifyTypeInfoVars0
 	;
 		error("modecheck_complicated_unify")
 	),
-	Unification = complicated_unify(UniMode0, CanFail, UnifyTypeInfoVars),
+	Unification = complicated_unify(UniMode, CanFail, UnifyTypeInfoVars),
 
 	%
 	% check that all the type_info or type_class_info variables used
@@ -1008,7 +1008,7 @@
 		% also be able to handle (in(any), in(any)) unifications.]
 		%
 		Type = term__variable(_),
-		\+ inst_is_ground_or_any(InitialInstX, InstMap, InstTable,
+		\+ inst_is_ground_or_any(InitialInstX, InstMapBefore, InstTable,
 			ModuleInfo2)
 	->
 		set__singleton_set(WaitingVars, X),
@@ -1017,7 +1017,7 @@
 			ModeInfo2, ModeInfo)
 	;
 		Type = term__variable(_),
-		\+ inst_is_ground_or_any(InitialInstY, InstMap, InstTable,
+		\+ inst_is_ground_or_any(InitialInstY, InstMapBefore, InstTable,
 			ModuleInfo2)
 	->
 		set__singleton_set(WaitingVars, Y),
@@ -1067,12 +1067,10 @@
 		%
 		type_to_type_id(Type, TypeId, _)
 	->
-		% YYY Optimise UniMode0 in the case that there
-		%     are no shared inst_keys
-		UniMode0 = UniMode,
 		mode_info_get_context(ModeInfo2, Context),
-		unify_proc__request_unify(TypeId - UniMode,
-			Det, Context, InstTable, ModuleInfo2, ModuleInfo),
+		unify_proc__request_unify(unify_proc_id(TypeId, InitialInstX,
+				InitialInstY, InstTable),
+			Det, Context, InstMapBefore, ModuleInfo2, ModuleInfo),
 		mode_info_set_module_info(ModeInfo2, ModuleInfo,
 			ModeInfo)
 	;
Index: modes.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/modes.m,v
retrieving revision 1.204.2.21
diff -u -u -r1.204.2.21 modes.m
--- modes.m	1999/07/19 01:45:08	1.204.2.21
+++ modes.m	1999/07/23 01:54:32
@@ -310,7 +310,7 @@
 :- import_module globals, options, mercury_to_mercury, hlds_out, int, set.
 :- import_module passes_aux, typecheck, module_qual, clause_to_proc.
 :- import_module modecheck_unify, modecheck_call, inst_util, purity.
-:- import_module prog_out, term, varset.
+:- import_module prog_out, inst_table, term, varset.
 
 :- import_module list, map, string, require, std_util.
 :- import_module assoc_list.
@@ -864,15 +864,17 @@
 		map__lookup(Procs, ProcId, ProcInfo),
 		proc_info_arglives(ProcInfo, ModuleInfo, ArgLives),
 		maybe_clobber_insts(VarFinalInsts2, ArgLives, FinalInsts),
+		map__init(AliasMap0),
 		check_final_insts(HeadVars, FinalInsts0, FinalInsts,
-			InferModes, 1, no, Changed1,
+			InferModes, 1, AliasMap0, no, Changed1,
 			ModeInfo0, ModeInfo1),
 		mode_info_get_changed_flag(ModeInfo1, Changed0),
 		bool__or(Changed0, Changed1, Changed),
 		mode_info_set_changed_flag(Changed, ModeInfo1, ModeInfo)
 	;
+		map__init(AliasMap0),
 		check_final_insts(HeadVars, FinalInsts0, VarFinalInsts1,
-			InferModes, 1, no, _Changed1,
+			InferModes, 1, AliasMap0, no, _Changed1,
 			ModeInfo0, ModeInfo),
 		FinalInsts = FinalInsts0
 	).
@@ -894,12 +896,12 @@
 	maybe_clobber_insts(Insts0, IsLives, Insts).
 
 :- pred check_final_insts(list(prog_var), list(inst), list(inst), bool, int,
-				bool, bool, mode_info, mode_info).
-:- mode check_final_insts(in, in, in, in, in, in, out, mode_info_di,
+				alias_map, bool, bool, mode_info, mode_info).
+:- mode check_final_insts(in, in, in, in, in, in, in, out, mode_info_di,
 				mode_info_uo) is det.
 
 check_final_insts(Vars, Insts, VarInsts, InferModes, ArgNum,
-		Changed0, Changed) -->
+		AliasMap0, Changed0, Changed) -->
 	( { Vars = [], Insts = [], VarInsts = [] } ->
 		{ Changed = Changed0 }
 	; { Vars = [Var|Vars1], Insts = [Inst|Insts1],
@@ -910,11 +912,13 @@
 	    	{ mode_info_get_instmap(ModeInfo0, InstMap) },
 		(
 			{ inst_matches_final(VarInst, InstMap, Inst, InstMap,
-					InstTable, ModuleInfo) }
+				InstTable, ModuleInfo, AliasMap0, AliasMap1) }
 		->
-			{ Changed1 = Changed0 }
+			{ Changed1 = Changed0 },
+			{ AliasMap2 = AliasMap1 }
 		;
 			{ Changed1 = yes },
+			{ AliasMap2 = AliasMap0 },
 			( { InferModes = yes } ->
 				% if we're inferring the mode, then don't report
 				% an error, just set changed to yes to make sure
@@ -923,13 +927,17 @@
 			;
 				% XXX this might need to be reconsidered now
 				% we have unique modes
-				( { inst_matches_initial(VarInst, InstMap,
-						Inst, InstMap,
-				    		InstTable, ModuleInfo) } ->
+				(
+					{ inst_matches_initial_ignore_aliasing(
+						VarInst, InstMap, Inst, InstMap,
+				    		InstTable, ModuleInfo) }
+				->
 					{ Reason = too_instantiated }
-				; { inst_matches_initial(Inst, InstMap,
-						VarInst, InstMap,
-				    		InstTable, ModuleInfo) } ->
+				;
+					{ inst_matches_initial_ignore_aliasing(
+						Inst, InstMap, VarInst, InstMap,
+				    		InstTable, ModuleInfo) }
+				->
 					{ Reason = not_instantiated_enough }
 				;
 					% I don't think this can happen. 
@@ -944,7 +952,7 @@
 		),
 		{ ArgNum1 is ArgNum + 1 },
 		check_final_insts(Vars1, Insts1, VarInsts1, InferModes, ArgNum1,
-			Changed1, Changed)
+			AliasMap2, Changed1, Changed)
 	;
 		{ error("check_final_insts: length mismatch") }
 	).
@@ -1772,22 +1780,32 @@
 	% Given a list of variables and a list of initial insts, ensure
 	% that the inst of each variable matches the corresponding initial
 	% inst.
+modecheck_var_has_inst_list(Vars, Insts, ArgNum0) -->
+	{ map__init(AliasMap0) },
+	modecheck_var_has_inst_list_2(Vars, Insts, ArgNum0, AliasMap0).
+
+:- pred modecheck_var_has_inst_list_2(list(prog_var), list(inst), int,
+		alias_map, mode_info, mode_info).
+:- mode modecheck_var_has_inst_list_2(in, in, in, in,
+		mode_info_di, mode_info_uo) is det.
 
-modecheck_var_has_inst_list([_|_], [], _) -->
+modecheck_var_has_inst_list_2([_|_], [], _, _) -->
 	{ error("modecheck_var_has_inst_list: length mismatch") }.
-modecheck_var_has_inst_list([], [_|_], _) -->
+modecheck_var_has_inst_list_2([], [_|_], _, _) -->
 	{ error("modecheck_var_has_inst_list: length mismatch") }.
-modecheck_var_has_inst_list([], [], _ArgNum) --> [].
-modecheck_var_has_inst_list([Var|Vars], [Inst|Insts], ArgNum0) -->
+modecheck_var_has_inst_list_2([], [], _ArgNum, _) --> [].
+modecheck_var_has_inst_list_2([Var|Vars], [Inst|Insts], ArgNum0, AliasMap0) -->
 	{ ArgNum is ArgNum0 + 1 },
 	mode_info_set_call_arg_context(ArgNum),
-	modecheck_var_has_inst(Var, Inst),
-	modecheck_var_has_inst_list(Vars, Insts, ArgNum).
+	modecheck_var_has_inst(Var, Inst, AliasMap0, AliasMap),
+	modecheck_var_has_inst_list_2(Vars, Insts, ArgNum, AliasMap).
 
-:- pred modecheck_var_has_inst(prog_var, inst, mode_info, mode_info).
-:- mode modecheck_var_has_inst(in, in, mode_info_di, mode_info_uo) is det.
+:- pred modecheck_var_has_inst(prog_var, inst, alias_map, alias_map,
+		mode_info, mode_info).
+:- mode modecheck_var_has_inst(in, in, in, out,
+		mode_info_di, mode_info_uo) is det.
 
-modecheck_var_has_inst(VarId, Inst, ModeInfo0, ModeInfo) :-
+modecheck_var_has_inst(VarId, Inst, AliasMap0, AliasMap, ModeInfo0, ModeInfo) :-
 	mode_info_get_instmap(ModeInfo0, InstMap),
 	instmap__lookup_var(InstMap, VarId, VarInst),
 
@@ -1795,14 +1813,16 @@
 	mode_info_get_inst_table(ModeInfo0, InstTable),
 	(
 		inst_matches_initial(VarInst, InstMap, Inst, InstMap,
-			InstTable, ModuleInfo)
+			InstTable, ModuleInfo, AliasMap0, AliasMap1)
 	->
-		ModeInfo = ModeInfo0
+		ModeInfo = ModeInfo0,
+		AliasMap = AliasMap1
 	;
 		set__singleton_set(WaitingVars, VarId),
 		mode_info_error(WaitingVars,
 			mode_error_var_has_inst(VarId, VarInst, Inst),
-			ModeInfo0, ModeInfo)
+			ModeInfo0, ModeInfo),
+		AliasMap = AliasMap0
 	).
 
 %-----------------------------------------------------------------------------%
@@ -1911,8 +1931,8 @@
 			% If we haven't added any information and
 			% we haven't bound any part of the var, then
 			% the only thing we can have done is lose uniqueness.
-			inst_matches_initial(Inst0, InstMap0, Inst, InstMap2,
-					InstTable2, ModuleInfo2)
+			inst_matches_initial_ignore_aliasing(Inst0, InstMap0,
+				Inst, InstMap2, InstTable2, ModuleInfo2)
 		->
 			instmap__set(InstMap2, Var0, Inst, InstMap),
 			mode_info_set_instmap(InstMap, ModeInfo2, ModeInfo99)
@@ -1989,8 +2009,8 @@
 			% If we haven't added any information and
 			% we haven't bound any part of the var, then
 			% the only thing we can have done is lose uniqueness.
-			inst_matches_initial(Inst0, InstMap0, Inst, InstMap0,
-					InstTable0, ModuleInfo0)
+			inst_matches_initial_ignore_aliasing(Inst0, InstMap0,
+				Inst, InstMap0, InstTable0, ModuleInfo0)
 		->
 			instmap__set(InstMap0, Var0, Inst, InstMap),
 			mode_info_set_instmap(InstMap, ModeInfo0, ModeInfo)
@@ -2053,7 +2073,9 @@
 		% the initial inst specified in the pred's mode declaration,
 		% then it's not a call to an implied mode, it's an exact
 		% match with a genuine mode.
-		inst_matches_final(VarInst0, InstMapBefore,
+		% We can ignore aliasing here because we know that the
+		% variable already matches_initial with the initial inst.
+		inst_matches_final_ignore_aliasing(VarInst0, InstMapBefore,
 			InitialInst, InstMap0, InstTable0, ModuleInfo0)
 	->
 		Var = Var0,
Index: module_qual.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/module_qual.m,v
retrieving revision 1.22.2.18
diff -u -u -r1.22.2.18 module_qual.m
--- module_qual.m	1999/07/19 01:45:11	1.22.2.18
+++ module_qual.m	1999/07/21 06:37:18
@@ -661,7 +661,7 @@
 	{ error("compiler generated inst unexpected") }.
 qualify_inst_name(typed_inst(_, _), _, _, _) -->
 	{ error("compiler generated inst unexpected") }.
-qualify_inst_name(substitution_inst(_, _, _), _, _, _) -->
+qualify_inst_name(other_inst(_, _), _, _, _) -->
 	{ error("compiler generated inst unexpected") }.
 
 	% Qualify an inst of the form bound(functor(...)).
Index: par_conj_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/par_conj_gen.m,v
retrieving revision 1.1.2.6
diff -u -u -r1.1.2.6 par_conj_gen.m
--- par_conj_gen.m	1999/05/05 01:24:22	1.1.2.6
+++ par_conj_gen.m	1999/07/21 06:37:30
@@ -103,7 +103,7 @@
 
 :- import_module hlds_data, code_gen, code_util, options, globals, prog_data.
 :- import_module hlds_module, (inst), instmap, mode_util, code_info.
-:- import_module continuation_info, inst_match.
+:- import_module continuation_info, inst_match, inst_table.
 :- import_module set, tree, list, map, std_util, require, int.
 
 %---------------------------------------------------------------------------%
Index: passes_aux.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/passes_aux.m,v
retrieving revision 1.22.4.12
diff -u -u -r1.22.4.12 passes_aux.m
--- passes_aux.m	1999/07/19 01:45:16	1.22.4.12
+++ passes_aux.m	1999/07/21 06:37:41
@@ -13,7 +13,7 @@
 
 :- interface.
 
-:- import_module hlds_module, hlds_pred, hlds_data, prog_data.
+:- import_module hlds_module, hlds_pred, prog_data, inst_table.
 :- import_module io, std_util, list, bool.
 
 %-----------------------------------------------------------------------------%
Index: pd_info.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/pd_info.m,v
retrieving revision 1.1.6.8
diff -u -u -r1.1.6.8 pd_info.m
--- pd_info.m	1999/06/03 01:39:06	1.1.6.8
+++ pd_info.m	1999/07/21 06:38:09
@@ -161,8 +161,8 @@
 :- implementation.
 
 :- import_module hlds_pred, prog_data, pd_debug, pd_util, det_util, globals.
-:- import_module inst_match, hlds_goal, prog_util, hlds_data, term.
-:- import_module assoc_list, bool, int, require, string.
+:- import_module inst_match, hlds_goal, prog_util, hlds_data, inst_table.
+:- import_module assoc_list, bool, int, require, string, term.
 
 pd_info_init(ModuleInfo, ProcArgInfos, IO, PdInfo) :-
 	map__init(GoalVersionIndex),
@@ -688,14 +688,27 @@
 		instmap::in, version_is_exact::in, version_is_exact::out)
 		is semidet.
 
-pd_info__check_insts(_, _, [], _, _, _, Exact, Exact).
+pd_info__check_insts(InstTable, ModuleInfo, Vars, VarRenaming, OldInstMap,
+		NewInstMap, ExactSoFar0, ExactSoFar) :-
+	map__init(AliasMap0),
+	pd_info__check_insts(InstTable, ModuleInfo, Vars, VarRenaming,
+		OldInstMap, NewInstMap, AliasMap0, AliasMap0,
+		ExactSoFar0, ExactSoFar).
+
+:- pred pd_info__check_insts(inst_table::in, module_info::in,
+		list(prog_var)::in, map(prog_var, prog_var)::in, instmap::in,
+		instmap::in, alias_map::in, alias_map::in,
+		version_is_exact::in, version_is_exact::out) is semidet.
+
+pd_info__check_insts(_, _, [], _, _, _, _, _, Exact, Exact).
 pd_info__check_insts(InstTable, ModuleInfo, [OldVar | Vars], VarRenaming,
-		OldInstMap, NewInstMap, ExactSoFar0, ExactSoFar) :-
+		OldInstMap, NewInstMap, AliasMapOld0, AliasMapNew0,
+		ExactSoFar0, ExactSoFar) :-
 	instmap__lookup_var(OldInstMap, OldVar, OldVarInst),
 	map__lookup(VarRenaming, OldVar, NewVar),
 	instmap__lookup_var(NewInstMap, NewVar, NewVarInst),
 	inst_matches_initial(NewVarInst, NewInstMap, OldVarInst, OldInstMap,
-			InstTable, ModuleInfo),
+			InstTable, ModuleInfo, AliasMapOld0, AliasMapOld1),
 	( ExactSoFar0 = exact ->
 		% Does inst_matches_initial(Inst1, Inst2, M) and
 		% inst_matches_initial(Inst2, Inst1, M) imply that Inst1
@@ -703,17 +716,21 @@
 		( 
 			inst_matches_initial(OldVarInst, OldInstMap,
 				NewVarInst, NewInstMap, InstTable,
-				ModuleInfo)
+				ModuleInfo, AliasMapNew0, AliasMapNew1)
 		->
-			ExactSoFar1 = exact
+			ExactSoFar1 = exact,
+			AliasMapNew2 = AliasMapNew1
 		;
-			ExactSoFar1 = more_general
+			ExactSoFar1 = more_general,
+			AliasMapNew2 = AliasMapNew0
 		)
 	;
-		ExactSoFar1 = more_general
+		ExactSoFar1 = more_general,
+		AliasMapNew2 = AliasMapNew0
 	),
 	pd_info__check_insts(InstTable, ModuleInfo, Vars, VarRenaming,
-		OldInstMap, NewInstMap, ExactSoFar1, ExactSoFar).
+		OldInstMap, NewInstMap, AliasMapOld1, AliasMapNew2,
+		ExactSoFar1, ExactSoFar).
 
 %-----------------------------------------------------------------------------%
 
Index: pd_term.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/pd_term.m,v
retrieving revision 1.1.6.2
diff -u -u -r1.1.6.2 pd_term.m
--- pd_term.m	1998/11/24 06:30:51	1.1.6.2
+++ pd_term.m	1999/07/23 07:23:56
@@ -1,5 +1,5 @@
 %-----------------------------------------------------------------------------%
-% Copyright (C) 1998 University of Melbourne.
+% Copyright (C) 1999 University of Melbourne.
 % This file may only be copied under the terms of the GNU General
 % Public License - see the file COPYING in the Mercury distribution.
 %-----------------------------------------------------------------------------%
@@ -36,7 +36,7 @@
 :- interface.
 
 :- import_module hlds_goal, hlds_module, hlds_pred, instmap, pd_info.
-:- import_module hlds_data.
+:- import_module inst_table.
 :- import_module list, std_util.
 
 	% pd_term__global_check(Module, CallGoal1, BetweenGoals, CallGoal2,
Index: pd_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/pd_util.m,v
retrieving revision 1.1.6.9
diff -u -u -r1.1.6.9 pd_util.m
--- pd_util.m	1999/07/19 01:45:18	1.1.6.9
+++ pd_util.m	1999/07/21 06:38:36
@@ -14,7 +14,7 @@
 :- interface.
 
 :- import_module pd_info, hlds_goal, hlds_module, hlds_pred, mode_errors.
-:- import_module prog_data, simplify, (inst), hlds_data, instmap.
+:- import_module prog_data, simplify, (inst), instmap, inst_table.
 :- import_module bool, list, map, set, std_util.
 
 	% Pick out the pred_proc_ids of the calls in a list of atomic goals.
Index: polymorphism.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/polymorphism.m,v
retrieving revision 1.117.2.29
diff -u -u -r1.117.2.29 polymorphism.m
--- polymorphism.m	1999/07/19 01:45:18	1.117.2.29
+++ polymorphism.m	1999/07/21 06:38:56
@@ -433,7 +433,7 @@
 :- import_module type_util, mode_util, quantification, instmap, prog_out.
 :- import_module code_util, unify_proc, prog_util, make_hlds, inst_util.
 :- import_module (inst), hlds_out, base_typeclass_info, goal_util, passes_aux.
-:- import_module clause_to_proc.
+:- import_module clause_to_proc, inst_table.
 
 :- import_module bool, int, string, set, map.
 :- import_module term, varset, std_util, require, assoc_list.
Index: post_typecheck.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/post_typecheck.m,v
retrieving revision 1.1.4.9
diff -u -u -r1.1.4.9 post_typecheck.m
--- post_typecheck.m	1999/07/19 01:45:21	1.1.4.9
+++ post_typecheck.m	1999/07/21 06:39:11
@@ -108,7 +108,7 @@
 :- implementation.
 
 :- import_module (assertion), typecheck, clause_to_proc.
-:- import_module mode_util, inst_match, (inst).
+:- import_module mode_util, inst_match, (inst), inst_table.
 :- import_module mercury_to_mercury, prog_out, hlds_data, hlds_out, type_util.
 :- import_module globals, options.
 
Index: prog_data.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/prog_data.m,v
retrieving revision 1.24.2.19
diff -u -u -r1.24.2.19 prog_data.m
--- prog_data.m	1999/07/19 01:45:22	1.24.2.19
+++ prog_data.m	1999/07/21 05:01:17
@@ -23,9 +23,7 @@
 % should be defined here, rather than in hlds*.m.
 
 :- import_module (inst).
-:- import_module hlds_data.
-	% YYY hlds_data needed for inst_table definition.  We should move the
-	% definition of inst_table somewhere else.
+:- import_module inst_table.
 :- import_module bool, list, assoc_list, map, varset, term, std_util.
 
 %-----------------------------------------------------------------------------%
@@ -729,8 +727,21 @@
 	;	mostly_uniq_inst(inst_name)
 	;	typed_ground(uniqueness, type)
 	;	typed_inst(type, inst_name)
-	;	substitution_inst(inst_name, inst_key_set, inst_key_sub).
+	;	other_inst(other_inst_id, inst_name).
 
+:- type other_inst_id.
+
+:- type other_inst_id_sub.
+
+:- func init_other_inst_id = other_inst_id.
+
+:- func inc_other_inst_id(other_inst_id) = other_inst_id.
+
+:- func other_inst_id_apply_sub(other_inst_id_sub, other_inst_id)
+		= other_inst_id.
+
+:- func other_inst_id_create_sub(other_inst_id) = other_inst_id_sub.
+
 	% Note: `is_live' records liveness in the sense used by
 	% mode analysis.  This is not the same thing as the notion of liveness
 	% used by code generation.  See compiler/notes/glossary.html.
@@ -907,5 +918,20 @@
 set_thread_safe(Attrs0, ThreadSafe, Attrs) :-
 	Attrs0 = attributes(MayCallMercury, _),
 	Attrs  = attributes(MayCallMercury, ThreadSafe).
+
+%-----------------------------------------------------------------------------%
+
+:- import_module int.
+
+:- type other_inst_id == int.
+:- type other_inst_id_sub == int.
+
+init_other_inst_id = 0.
+
+inc_other_inst_id(Id) = Id + 1.
+
+other_inst_id_apply_sub(Sub, Id0) = Id0 + Sub.
+
+other_inst_id_create_sub(Id) = Id.
 
 %-----------------------------------------------------------------------------%
Index: prog_io.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/prog_io.m,v
retrieving revision 1.162.2.13
diff -u -u -r1.162.2.13 prog_io.m
--- prog_io.m	1999/07/19 01:45:22	1.162.2.13
+++ prog_io.m	1999/07/21 06:39:23
@@ -185,7 +185,7 @@
 :- import_module prog_io_goal, prog_io_dcg, prog_io_pragma, prog_io_util.
 :- import_module prog_io_typeclass.
 :- import_module hlds_data, hlds_pred, prog_util, prog_out.
-:- import_module globals, options, (inst).
+:- import_module globals, options, (inst), inst_table.
 
 :- import_module int, string, std_util, parser, term_io, dir, require.
 :- import_module assoc_list.
Index: prog_io_pragma.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/prog_io_pragma.m,v
retrieving revision 1.6.4.10
diff -u -u -r1.6.4.10 prog_io_pragma.m
--- prog_io_pragma.m	1999/07/19 01:45:25	1.6.4.10
+++ prog_io_pragma.m	1999/07/21 06:39:37
@@ -22,7 +22,7 @@
 
 :- implementation.
 
-:- import_module prog_io, prog_io_goal, prog_util, hlds_data.
+:- import_module prog_io, prog_io_goal, prog_util, hlds_data, inst_table.
 :- import_module term_util, term_errors.
 :- import_module int, map, string, std_util, bool, require.
 
Index: prog_io_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/prog_io_util.m,v
retrieving revision 1.5.4.13
diff -u -u -r1.5.4.13 prog_io_util.m
--- prog_io_util.m	1999/07/19 01:45:26	1.5.4.13
+++ prog_io_util.m	1999/07/21 06:40:00
@@ -132,7 +132,7 @@
 
 :- implementation.
 
-:- import_module prog_io, prog_io_goal, options, globals.
+:- import_module prog_io, prog_io_goal, options, globals, inst_table.
 
 % XXX we should not need to import hlds*.m here.
 % But currently we need to import hlds_data.m for the `cons_id' type
Index: rl.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/rl.m,v
retrieving revision 1.2.2.3
diff -u -u -r1.2.2.3 rl.m
--- rl.m	1999/07/19 01:45:29	1.2.2.3
+++ rl.m	1999/07/21 06:01:57
@@ -18,7 +18,7 @@
 :- interface.
 
 :- import_module hlds_data, hlds_goal, hlds_module, hlds_pred.
-:- import_module instmap, prog_data.
+:- import_module instmap, prog_data, inst_table.
 :- import_module assoc_list, list, std_util, map, set.
 
 %-----------------------------------------------------------------------------%
Index: rl_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/rl_gen.m,v
retrieving revision 1.3.2.3
diff -u -u -r1.3.2.3 rl_gen.m
--- rl_gen.m	1999/07/19 01:45:31	1.3.2.3
+++ rl_gen.m	1999/07/21 06:40:31
@@ -28,7 +28,7 @@
 :- import_module code_aux, code_util, det_analysis, hlds_data, hlds_goal.
 :- import_module hlds_pred, instmap, mode_util, prog_data, prog_out.
 :- import_module rl_relops, rl_info.
-:- import_module tree, type_util, dependency_graph.
+:- import_module tree, type_util, dependency_graph, inst_table.
 :- import_module inst_match, (inst), goal_util, inlining, globals, options.
 
 :- import_module assoc_list, bool, char, int, list, map, queue.
Index: rl_info.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/rl_info.m,v
retrieving revision 1.1.2.1
diff -u -u -r1.1.2.1 rl_info.m
--- rl_info.m	1999/05/05 01:25:01	1.1.2.1
+++ rl_info.m	1999/07/23 07:24:02
@@ -1,5 +1,5 @@
 %-----------------------------------------------------------------------------%
-% Copyright (C) 1998 University of Melbourne.
+% Copyright (C) 1999 University of Melbourne.
 % This file may only be copied under the terms of the GNU General
 % Public License - see the file COPYING in the Mercury distribution.
 %-----------------------------------------------------------------------------%
@@ -12,7 +12,9 @@
 
 :- interface.
 
-:- import_module hlds_data, hlds_module, hlds_pred, prog_data, rl, tree.
+:- import_module hlds_module, hlds_pred, prog_data, rl, tree.
+:- import_module inst_table.
+
 :- import_module bool, io, list, map, set, std_util, string.
 
 :- type rl_info.
Index: saved_vars.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/saved_vars.m,v
retrieving revision 1.11.2.11
diff -u -u -r1.11.2.11 saved_vars.m
--- saved_vars.m	1999/07/19 01:45:34	1.11.2.11
+++ saved_vars.m	1999/07/21 06:40:59
@@ -38,6 +38,7 @@
 
 :- import_module hlds_goal, hlds_out, goal_util, quantification, passes_aux.
 :- import_module mode_util, prog_data, hlds_data, instmap, inst_match.
+:- import_module inst_table.
 :- import_module bool, list, set, map, std_util, term, varset.
 
 %-----------------------------------------------------------------------------%
Index: simplify.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/simplify.m,v
retrieving revision 1.46.2.25
diff -u -u -r1.46.2.25 simplify.m
--- simplify.m	1999/07/19 01:45:35	1.46.2.25
+++ simplify.m	1999/07/23 01:54:32
@@ -29,7 +29,7 @@
 :- interface.
 
 :- import_module hlds_goal, hlds_module, hlds_pred, det_report, det_util.
-:- import_module common, instmap, globals.
+:- import_module common, instmap, inst_table, globals.
 :- import_module io, bool, list, map.
 
 :- pred simplify__pred(list(simplification), pred_id, module_info, module_info,
@@ -1195,8 +1195,12 @@
 			SpecialPredMap) },
 		{ map__lookup(SpecialPredMap, unify - TypeId, PredId) },
 		{ determinism_components(Det, CanFail, at_most_one) },
-		{ unify_proc__lookup_mode_num(InstTable, ModuleInfo, TypeId,
-		 	UniMode, Det, ProcId) },
+		=(Info),
+		{ simplify_info_get_instmap(Info, InstMap) },
+		{ UniMode = (LI - RI -> _) },
+		{ unify_proc__lookup_mode_num(InstMap, ModuleInfo,
+			unify_proc_id(TypeId, LI, RI, InstTable),
+			Det, ProcId) },
 		{ SymName = unqualified("__Unify__") },
 		{ CallContext = call_unify_context(XVar, var(YVar), Context) },
 		{ Call0 = call(PredId, ProcId, ArgVars, not_builtin,
@@ -1870,7 +1874,7 @@
 	% exported for common.m
 :- interface.
 :- import_module set.
-:- import_module prog_data, det_util, instmap, hlds_data.
+:- import_module prog_data, det_util, instmap.
 
 :- pred simplify_info_init(det_info, list(simplification), instmap,
 		prog_varset, map(prog_var, type), simplify_info).
Index: special_pred.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/special_pred.m,v
retrieving revision 1.15.4.5
diff -u -u -r1.15.4.5 special_pred.m
--- special_pred.m	1998/09/25 01:08:50	1.15.4.5
+++ special_pred.m	1999/07/23 07:24:06
@@ -1,5 +1,5 @@
 %-----------------------------------------------------------------------------%
-% Copyright (C) 1995-1998 The University of Melbourne.
+% Copyright (C) 1995-1999 The University of Melbourne.
 % This file may only be copied under the terms of the GNU General
 % Public License - see the file COPYING in the Mercury distribution.
 %-----------------------------------------------------------------------------%
@@ -56,7 +56,7 @@
 
 :- implementation.
 
-:- import_module type_util, mode_util, prog_util.
+:- import_module type_util, mode_util, prog_util, inst_table.
 
 special_pred_list([unify, index, compare]).
 
Index: stratify.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/stratify.m,v
retrieving revision 1.10.2.13
diff -u -u -r1.10.2.13 stratify.m
--- stratify.m	1999/07/19 01:45:38	1.10.2.13
+++ stratify.m	1999/07/21 06:41:55
@@ -48,7 +48,7 @@
 
 :- import_module dependency_graph, hlds_pred, hlds_goal, hlds_data.
 :- import_module hlds_module, type_util, mode_util, prog_data, passes_aux.
-:- import_module prog_out, globals, options, (inst), instmap.
+:- import_module prog_out, globals, options, (inst), instmap, inst_table.
 
 :- import_module assoc_list, map, list, set, bool, std_util, relation, require.
 :- import_module string.
Index: switch_detection.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/switch_detection.m,v
retrieving revision 1.76.2.12
diff -u -u -r1.76.2.12 switch_detection.m
--- switch_detection.m	1999/07/19 01:45:39	1.76.2.12
+++ switch_detection.m	1999/07/21 06:42:10
@@ -50,7 +50,7 @@
 :- implementation.
 
 :- import_module hlds_goal, hlds_data, prog_data, instmap, inst_match, (inst).
-:- import_module modes, mode_util, type_util, det_util.
+:- import_module modes, mode_util, type_util, det_util, inst_table.
 :- import_module passes_aux, term.
 :- import_module bool, char, int, assoc_list, map, set, std_util, require.
 
Index: table_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/table_gen.m,v
retrieving revision 1.1.6.11
diff -u -u -r1.1.6.11 table_gen.m
--- table_gen.m	1999/07/19 01:45:41	1.1.6.11
+++ table_gen.m	1999/07/21 06:42:31
@@ -170,7 +170,7 @@
 :- implementation.
 
 :- import_module hlds_out, prog_out.
-:- import_module hlds_pred, instmap, polymorphism.
+:- import_module hlds_pred, instmap, inst_table, polymorphism.
 :- import_module code_aux, det_analysis, follow_code, goal_util, const_prop.
 :- import_module hlds_module, hlds_goal, hlds_data, (inst), inst_match.
 :- import_module globals, options, passes_aux, prog_data, mode_util, type_util.
Index: term_pass2.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/term_pass2.m,v
retrieving revision 1.2.2.6
diff -u -u -r1.2.2.6 term_pass2.m
--- term_pass2.m	1998/11/24 06:32:15	1.2.2.6
+++ term_pass2.m	1999/07/23 07:24:12
@@ -1,5 +1,5 @@
 %-----------------------------------------------------------------------------
-% Copyright (C) 1997-1998 The University of Melbourne.
+% Copyright (C) 1997-1999 The University of Melbourne.
 % This file may only be copied under the terms of the GNU General
 % Public License - see the file COPYING in the Mercury distribution.
 %-----------------------------------------------------------------------------
@@ -25,7 +25,7 @@
 
 :- implementation.
 
-:- import_module term_traversal, term_errors, instmap.
+:- import_module term_traversal, term_errors, instmap, inst_table.
 :- import_module hlds_data, hlds_goal, prog_data, type_util, mode_util.
 
 :- import_module std_util, bool, int, assoc_list.
Index: term_traversal.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/term_traversal.m,v
retrieving revision 1.3.2.8
diff -u -u -r1.3.2.8 term_traversal.m
--- term_traversal.m	1999/07/19 01:45:42	1.3.2.8
+++ term_traversal.m	1999/07/21 06:42:51
@@ -20,8 +20,8 @@
 
 :- interface.
 
-:- import_module term_util, term_errors, instmap.
-:- import_module hlds_module, hlds_pred, hlds_goal, hlds_data, prog_data.
+:- import_module term_util, term_errors, instmap, inst_table.
+:- import_module hlds_module, hlds_pred, hlds_goal, prog_data.
 :- import_module list, bag, map, std_util, set.
 
 :- type traversal_info
Index: term_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/term_util.m,v
retrieving revision 1.3.2.9
diff -u -u -r1.3.2.9 term_util.m
--- term_util.m	1999/07/19 01:45:42	1.3.2.9
+++ term_util.m	1999/07/21 05:23:49
@@ -19,7 +19,7 @@
 
 :- interface.
 
-:- import_module term_errors, prog_data, instmap.
+:- import_module term_errors, prog_data, instmap, inst_table.
 :- import_module hlds_module, hlds_pred, hlds_data, hlds_goal.
 
 :- import_module std_util, bool, int, list, map, bag.
Index: termination.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/termination.m,v
retrieving revision 1.5.2.11
diff -u -u -r1.5.2.11 termination.m
--- termination.m	1999/07/13 04:45:13	1.5.2.11
+++ termination.m	1999/07/21 06:43:04
@@ -82,7 +82,7 @@
 :- import_module hlds_data, hlds_goal, hlds_pred, dependency_graph.
 :- import_module mode_util, hlds_out, code_util, prog_out, prog_util.
 :- import_module mercury_to_mercury, type_util, special_pred.
-:- import_module modules.
+:- import_module modules, inst_table.
 
 :- import_module map, int, char, string, relation, list.
 :- import_module require, bag, set, term, varset.
Index: trace.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/trace.m,v
retrieving revision 1.1.2.11
diff -u -u -r1.1.2.11 trace.m
--- trace.m	1999/05/05 01:25:30	1.1.2.11
+++ trace.m	1999/07/21 06:43:22
@@ -145,7 +145,7 @@
 
 :- import_module continuation_info, type_util, llds_out, tree, hlds_data.
 :- import_module varset.
-:- import_module (inst), instmap, inst_match, mode_util, options.
+:- import_module (inst), instmap, inst_table, inst_match, mode_util, options.
 :- import_module list, bool, int, string, map, std_util, require.
 
 	% Information specific to a trace port.
Index: unify_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/unify_gen.m,v
retrieving revision 1.83.2.17
diff -u -u -r1.83.2.17 unify_gen.m
--- unify_gen.m	1999/07/19 01:45:48	1.83.2.17
+++ unify_gen.m	1999/07/21 06:43:37
@@ -37,7 +37,7 @@
 
 :- implementation.
 
-:- import_module builtin_ops.
+:- import_module builtin_ops, inst_table.
 :- import_module hlds_module, hlds_pred, prog_data, prog_out, code_util.
 :- import_module mode_util, type_util, code_aux, hlds_out, tree, arg_info.
 :- import_module globals, options, continuation_info, stack_layout, inst_match.
Index: unify_proc.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/unify_proc.m,v
retrieving revision 1.61.2.17
diff -u -u -r1.61.2.17 unify_proc.m
--- unify_proc.m	1999/07/13 04:45:23	1.61.2.17
+++ unify_proc.m	1999/07/23 01:54:32
@@ -46,13 +46,19 @@
 :- module unify_proc.
 
 :- interface.
-:- import_module hlds_module, hlds_pred, hlds_goal, hlds_data.
-:- import_module mode_info, prog_data, special_pred.
+:- import_module hlds_module, hlds_pred, hlds_data, inst_table.
+:- import_module mode_info, prog_data, special_pred, instmap, (inst).
 :- import_module bool, std_util, io, list.
 
 :- type proc_requests.
 
-:- type unify_proc_id == pair(type_id, uni_mode).
+:- type unify_proc_id
+	--->	unify_proc_id(
+			type_id,
+			(inst),		% LHS initial inst.
+			(inst),		% RHS initial inst.
+			inst_table
+		).
 
 	% Initialize the proc_requests table.
 
@@ -63,7 +69,7 @@
 	% proc_requests table.
 
 :- pred unify_proc__request_unify(unify_proc_id, determinism, prog_context,
-				inst_table, module_info, module_info).
+			instmap, module_info, module_info).
 :- mode unify_proc__request_unify(in, in, in, in, in, out) is det.
 
 	% Add a new request for a procedure (not necessarily a unification)
@@ -91,9 +97,9 @@
 	% Given the type and mode of a unification, look up the
 	% mode number for the unification proc.
 
-:- pred unify_proc__lookup_mode_num(inst_table, module_info, type_id,
-					uni_mode, determinism, proc_id).
-:- mode unify_proc__lookup_mode_num(in, in, in, in, in, out) is det.
+:- pred unify_proc__lookup_mode_num(instmap, module_info, unify_proc_id,
+		determinism, proc_id).
+:- mode unify_proc__lookup_mode_num(in, in, in, in, out) is det.
 
 	% Generate the clauses for one of the compiler-generated
 	% special predicates (compare/3, index/3, unify, etc.)
@@ -110,11 +116,12 @@
 
 :- implementation.
 :- import_module tree, map, queue, int, string, require, assoc_list.
+:- import_module term, varset.
 
 :- import_module code_util, code_info, type_util.
-:- import_module mercury_to_mercury, hlds_out.
-:- import_module make_hlds, prog_util, prog_out, inst_match.
-:- import_module quantification, clause_to_proc, term, varset.
+:- import_module mercury_to_mercury, hlds_out, hlds_goal.
+:- import_module make_hlds, prog_util, prog_out, inst_match, inst_table.
+:- import_module quantification, clause_to_proc, inst_util, inst_table.
 :- import_module globals, options, modes, mode_util, (inst), instmap.
 :- import_module switch_detection, cse_detection, det_analysis, unique_modes.
 
@@ -124,7 +131,7 @@
 	% (mode number) of the unification procedure which corresponds to
 	% that mode.
 
-:- type unify_req_map == map(unify_proc_id, proc_id).
+:- type unify_req_map == assoc_list(unify_proc_id, proc_id).
 
 :- type req_queue == queue(pred_proc_id).
 
@@ -139,7 +146,7 @@
 %-----------------------------------------------------------------------------%
 
 unify_proc__init_requests(Requests) :-
-	map__init(UnifyReqMap),
+	UnifyReqMap = [],
 	queue__init(ReqQueue),
 	Requests = proc_requests(UnifyReqMap, ReqQueue).
 
@@ -172,19 +179,21 @@
 
 %-----------------------------------------------------------------------------%
 
-unify_proc__lookup_mode_num(InstTable, ModuleInfo, TypeId, UniMode, Det, Num) :-
+unify_proc__lookup_mode_num(InstMap, ModuleInfo, UnifyId0, Det, Num) :-
 	(
-		unify_proc__search_mode_num(InstTable, ModuleInfo, TypeId, UniMode,
-				Det, Num1)
+		normalise_unify_id(InstMap, ModuleInfo, UnifyId0, UnifyId),
+		instmap__init_reachable(NewInstMap),
+		unify_proc__search_mode_num(NewInstMap, ModuleInfo, UnifyId,
+			Det, Num1)
 	->
 		Num = Num1
 	;
 		error("unify_proc.m: unify_proc__search_num failed")
 	).
 
-:- pred unify_proc__search_mode_num(inst_table, module_info, type_id,
-				uni_mode, determinism, proc_id).
-:- mode unify_proc__search_mode_num(in, in, in, in, in, out) is semidet.
+:- pred unify_proc__search_mode_num(instmap, module_info, unify_proc_id,
+		determinism, proc_id).
+:- mode unify_proc__search_mode_num(in, in, in, in, out) is semidet.
 
 	% Given the type, mode, and determinism of a unification, look up the
 	% mode number for the unification proc.
@@ -194,10 +203,9 @@
 	% we assume that `ground' and `any' have the same representation.)
 	% For unreachable unifications, we also use mode zero.
 
-unify_proc__search_mode_num(InstTable, ModuleInfo, TypeId, UniMode, Determinism,
+unify_proc__search_mode_num(InstMapBefore, ModuleInfo, UnifyId, Determinism,
 		ProcId) :-
-	UniMode = (XInitial - YInitial -> _Final),
-	instmap__init_reachable(InstMapBefore),	% YYY Certainly bogus
+	UnifyId = unify_proc_id(_, XInitial, YInitial, InstTable),
 	(
 		Determinism = semidet,
 		inst_is_ground_or_any(XInitial, InstMapBefore,
@@ -217,22 +225,59 @@
 	;
 		module_info_get_proc_requests(ModuleInfo, Requests),
 		unify_proc__get_unify_req_map(Requests, UnifyReqMap),
-		map__search(UnifyReqMap, TypeId - UniMode, ProcId)
+		unify_proc__search_mode_num_2(UnifyReqMap, UnifyId, 
+			InstMapBefore, ModuleInfo, ProcId)
 	).
 
+:- pred unify_proc__search_mode_num_2(unify_req_map, unify_proc_id,
+		instmap, module_info, proc_id).
+:- mode unify_proc__search_mode_num_2(in, in, in, in, out) is semidet.
+
+unify_proc__search_mode_num_2([UnifyIdA - ProcId0 | Rest], UnifyIdB,
+		InstMapB, ModuleInfo, ProcId) :-
+	UnifyIdA = unify_proc_id(_, LIA0, RIA0, InstTableA),
+	UnifyIdB = unify_proc_id(_, LIB, RIB, InstTableB),
+
+	inst_table_create_sub(InstTableB, InstTableA, Sub, InstTable),
+	inst_apply_inst_table_sub(Sub, LIA0, LIA),
+	inst_apply_inst_table_sub(Sub, RIA0, RIA),
+
+	instmap__init_reachable(InstMapA),
+
+	(
+		map__init(AliasMapA0),
+		inst_matches_final(LIA, InstMapA, LIB, InstMapB, InstTable,
+			ModuleInfo, AliasMapA0, AliasMapA1),
+		inst_matches_final(RIA, InstMapA, RIB, InstMapB, InstTable,
+			ModuleInfo, AliasMapA1, _),
+
+		map__init(AliasMapB0),
+		inst_matches_final(LIB, InstMapB, LIA, InstMapA, InstTable,
+			ModuleInfo, AliasMapB0, AliasMapB1),
+		inst_matches_final(RIB, InstMapB, RIA, InstMapA, InstTable,
+			ModuleInfo, AliasMapB1, _)
+	->
+		ProcId = ProcId0
+	;
+		unify_proc__search_mode_num_2(Rest, UnifyIdB, InstMapB,
+			ModuleInfo, ProcId)
+	).
+
 %-----------------------------------------------------------------------------%
 
-unify_proc__request_unify(UnifyId, Determinism, Context, InstTable, ModuleInfo0,
-		ModuleInfo) :-
+unify_proc__request_unify(UnifyId0, Determinism, Context, InstMap,
+			ModuleInfo0, ModuleInfo) :-
 	%
 	% check if this unification has already been requested, or
 	% if the proc is hand defined.
 	%
-	UnifyId = TypeId - UnifyMode,
+	normalise_unify_id(InstMap, ModuleInfo0, UnifyId0, UnifyId),
+	UnifyId = unify_proc_id(TypeId, X_Initial, Y_Initial, InstTable0),
+	instmap__init_reachable(NewInstMap),
 	(
 		(
-			unify_proc__search_mode_num(InstTable, ModuleInfo0,
-				TypeId, UnifyMode, Determinism, _)
+			unify_proc__search_mode_num(NewInstMap, ModuleInfo0,
+				UnifyId, Determinism, _)
 		; 
 			type_id_is_hand_defined(TypeId)
 		)
@@ -246,9 +291,17 @@
 		module_info_get_special_pred_map(ModuleInfo0, SpecialPredMap),
 		map__lookup(SpecialPredMap, unify - TypeId, PredId),
 
-		% convert from `uni_mode' to `list(mode)'
-		UnifyMode = ((X_Initial - Y_Initial) -> (X_Final - Y_Final)),
-		ArgModes0 = [(X_Initial -> X_Final), (Y_Initial -> Y_Final)],
+		( abstractly_unify_inst(live, X_Initial, Y_Initial, real_unify,
+			InstTable0, ModuleInfo0, NewInstMap, Final0, _,
+			InstTable1, ModuleInfo1, _)
+		->
+			Final = Final0,
+			InstTable = InstTable1,
+			ModuleInfo2 = ModuleInfo1
+		;
+			error("unify_proc__request_unify: error unifying insts")
+		),
+		ArgModes0 = [(X_Initial -> Final), (Y_Initial -> Final)],
 
 		% for polymorphic types, add extra modes for the type_infos
 		TypeId = _TypeName - TypeArity,
@@ -260,17 +313,17 @@
 
 		Modes = argument_modes(InstTable, ArgModes),
 		unify_proc__request_proc(PredId, Modes, ArgLives,
-			yes(Determinism), Context, ModuleInfo0,
-			ProcId, ModuleInfo1),
+			yes(Determinism), Context, ModuleInfo2,
+			ProcId, ModuleInfo3),
 
 		%
 		% save the proc_id for this unify_proc_id
 		%
-		module_info_get_proc_requests(ModuleInfo1, Requests0),
+		module_info_get_proc_requests(ModuleInfo3, Requests0),
 		unify_proc__get_unify_req_map(Requests0, UnifyReqMap0),
-		map__set(UnifyReqMap0, UnifyId, ProcId, UnifyReqMap),
+		UnifyReqMap = [UnifyId - ProcId | UnifyReqMap0],
 		unify_proc__set_unify_req_map(Requests0, UnifyReqMap, Requests),
-		module_info_set_proc_requests(ModuleInfo1, Requests,
+		module_info_set_proc_requests(ModuleInfo3, Requests,
 			ModuleInfo)
 	).
 
@@ -316,6 +369,291 @@
 	queue__put(ReqQueue0, proc(PredId, ProcId), ReqQueue),
 	unify_proc__set_req_queue(Requests0, ReqQueue, Requests),
 	module_info_set_proc_requests(ModuleInfo2, Requests, ModuleInfo).
+
+%-----------------------------------------------------------------------------%
+
+:- pred normalise_unify_id(instmap, module_info, unify_proc_id, unify_proc_id).
+:- mode normalise_unify_id(in, in, in, out) is det.
+
+normalise_unify_id(InstMap, ModuleInfo, UnifyId0, UnifyId) :-
+	UnifyId0 = unify_proc_id(TypeId, InstLI0, InstRI0, OrigInstTable),
+
+	inst_table_init(InstTable0),
+	normalise_unify_insts(InstMap, ModuleInfo, OrigInstTable,
+		InstLI0, InstLI, InstRI0, InstRI, InstTable0, InstTable),
+
+	UnifyId = unify_proc_id(TypeId, InstLI, InstRI, InstTable).
+
+:- pred normalise_unify_insts(instmap, module_info, inst_table,
+	inst, inst, inst, inst, inst_table, inst_table).
+:- mode normalise_unify_insts(in, in, in, in, out, in, out, in, out)
+	is det.
+
+normalise_unify_insts(InstMap, ModuleInfo, OrigInstTable, InstL0, InstL,
+		InstR0, InstR, InstTable0, InstTable) :-
+	( ( InstL0 = defined_inst(_) ; InstR0 = defined_inst(_) ) ->
+		inst_remove_aliases(InstMap, ModuleInfo, OrigInstTable,
+			InstL0, InstL, InstTable0, InstTable1),
+		inst_remove_aliases(InstMap, ModuleInfo, OrigInstTable,
+			InstR0, InstR, InstTable1, InstTable)
+	;
+		normalise_unify_insts_2(InstMap, ModuleInfo, OrigInstTable,
+			InstL0, InstL, InstR0, InstR, InstTable0, InstTable)
+	).
+
+:- pred normalise_unify_insts_2(instmap, module_info, inst_table,
+	inst, inst, inst, inst, inst_table, inst_table).
+:- mode normalise_unify_insts_2(in, in, in, in, out, in, out, in, out)
+	is det.
+
+normalise_unify_insts_2(InstMap, ModuleInfo, OrigInstTable,
+		InstL0, InstL, InstR0, InstR, InstTable0, InstTable) :-
+	(
+		InstL0 = alias(IKL)
+	->
+		( InstR0 = alias(IKR) ->
+			(
+				instmap__inst_keys_are_equivalent(IKL, InstMap,
+					IKR, InstMap)
+			->
+				inst_remove_aliases(InstMap, ModuleInfo,
+					OrigInstTable, alias(IKL), Inst,
+					InstTable0, InstTable1),
+				inst_table_get_inst_key_table(InstTable1, IKT0),
+				inst_key_table_add(IKT0, Inst, IK, IKT),
+				inst_table_set_inst_key_table(InstTable1, IKT,
+					InstTable),
+				InstL = alias(IK),
+				InstR = alias(IK)
+			;
+				inst_table_get_inst_key_table(OrigInstTable,
+					IKT),
+				instmap__inst_key_table_lookup(InstMap, IKT,
+					IKL, InstL1),
+				instmap__inst_key_table_lookup(InstMap, IKT,
+					IKR, InstR1),
+				normalise_unify_insts(InstMap, ModuleInfo,
+					OrigInstTable, InstL1, InstL,
+					InstR1, InstR, InstTable0, InstTable)
+			)
+		;
+			inst_table_get_inst_key_table(OrigInstTable, IKT),
+			instmap__inst_key_table_lookup(InstMap, IKT, IKL,
+				InstL1),
+			normalise_unify_insts(InstMap, ModuleInfo,
+				OrigInstTable, InstL1, InstL, InstR0, InstR,
+				InstTable0, InstTable)
+		)
+	;
+		InstR0 = alias(IK)
+	->
+		inst_table_get_inst_key_table(OrigInstTable, IKT),
+		instmap__inst_key_table_lookup(InstMap, IKT, IK, InstR1),
+		normalise_unify_insts(InstMap, ModuleInfo, OrigInstTable,
+			InstL0, InstL, InstR1, InstR, InstTable0, InstTable)
+	;
+		InstL0 = bound(UniqL, BoundInstsL0)
+	->
+		( InstR0 = bound(UniqR, BoundInstsR0) ->
+			normalise_unify_bound_insts(InstMap, ModuleInfo,
+				OrigInstTable, BoundInstsL0, BoundInstsL,
+				BoundInstsR0, BoundInstsR,
+				InstTable0, InstTable),
+			InstL = bound(UniqL, BoundInstsL),
+			InstR = bound(UniqR, BoundInstsR)
+		;
+			bound_insts_remove_aliases(InstMap, ModuleInfo,
+				OrigInstTable, BoundInstsL0, BoundInstsL,
+				InstTable0, InstTable1),
+			InstL = bound(UniqL, BoundInstsL),
+			inst_remove_aliases(InstMap, ModuleInfo,
+				OrigInstTable, InstR0, InstR, InstTable1,
+				InstTable)
+		)
+	;
+		InstR0 = bound(UniqR, BoundInstsR0)
+	->
+		bound_insts_remove_aliases(InstMap, ModuleInfo, OrigInstTable,
+			BoundInstsR0, BoundInstsR, InstTable0, InstTable1),
+		InstR = bound(UniqR, BoundInstsR),
+		inst_remove_aliases(InstMap, ModuleInfo, OrigInstTable,
+			InstL0, InstL, InstTable1, InstTable)
+	;
+		InstL0 = abstract_inst(Name, InstsL0),
+		InstR0 = abstract_inst(Name, InstsR0),
+		normalise_unify_insts_list(InstMap, ModuleInfo, OrigInstTable,
+			InstsL0, InstsL, InstsR0, InstsR,
+			InstTable0, InstTable1)
+	->
+		InstL = abstract_inst(Name, InstsL),
+		InstR = abstract_inst(Name, InstsR),
+		InstTable = InstTable1
+	;
+		inst_remove_aliases(InstMap, ModuleInfo, OrigInstTable,
+			InstL0, InstL, InstTable0, InstTable1),
+		inst_remove_aliases(InstMap, ModuleInfo, OrigInstTable,
+			InstR0, InstR, InstTable1, InstTable)
+	).
+
+	% normalise_unify_insts fails iff the lists are different lengths.
+:- pred normalise_unify_insts_list(instmap, module_info, inst_table,
+	list(inst), list(inst), list(inst), list(inst), inst_table, inst_table).
+:- mode normalise_unify_insts_list(in, in, in, in, out, in, out, in, out)
+	is semidet.
+
+normalise_unify_insts_list(_, _, _, [], [], [], []) --> [].
+normalise_unify_insts_list(InstMap, ModuleInfo, OrigInstTable,
+		[L0 | Ls0], [L | Ls], [R0 | Rs0], [R | Rs]) -->
+	normalise_unify_insts(InstMap, ModuleInfo, OrigInstTable, L0, L, R0, R),
+	normalise_unify_insts_list(InstMap, ModuleInfo, OrigInstTable,
+		Ls0, Ls, Rs0, Rs).
+
+:- pred normalise_unify_bound_insts(instmap, module_info, inst_table,
+	list(bound_inst), list(bound_inst), list(bound_inst), list(bound_inst),
+	inst_table, inst_table).
+:- mode normalise_unify_bound_insts(in, in, in, in, out, in, out, in, out)
+	is det.
+
+normalise_unify_bound_insts(_, _, _, [], [], [], []) --> [].
+normalise_unify_bound_insts(InstMap, ModuleInfo, OrigInstTable, [], [],
+		BI0, BI) -->
+	{ BI0 = [_|_] },
+	bound_insts_remove_aliases(InstMap, ModuleInfo, OrigInstTable, BI0, BI).
+normalise_unify_bound_insts(InstMap, ModuleInfo, OrigInstTable, BI0, BI,
+		[], []) -->
+	{ BI0 = [_|_] },
+	bound_insts_remove_aliases(InstMap, ModuleInfo, OrigInstTable, BI0, BI).
+normalise_unify_bound_insts(InstMap, ModuleInfo, OrigInstTable,
+		[BL0 | BLs0], BLs, [BR0 | BRs0], BRs) -->
+	{ BL0 = functor(ConsIdL, ILs0) },
+	{ BR0 = functor(ConsIdR, IRs0) },
+	{ compare(Comp, ConsIdL, ConsIdR) },
+	(
+		{ Comp = (=) },
+		( 
+			normalise_unify_insts_list(InstMap, ModuleInfo,
+				OrigInstTable, ILs0, ILs1, IRs0, IRs1)
+		->
+			{ ILs = ILs1 },
+			{ IRs = IRs1 }
+		;
+			insts_remove_aliases(InstMap, ModuleInfo, OrigInstTable,
+				ILs0, ILs),
+			insts_remove_aliases(InstMap, ModuleInfo, OrigInstTable,
+				IRs0, IRs)
+		),
+		{ BLs = [functor(ConsIdL, ILs) | BLs1] },
+		{ BRs = [functor(ConsIdR, IRs) | BRs1] },
+		normalise_unify_bound_insts(InstMap, ModuleInfo, OrigInstTable,
+			BLs0, BLs1, BRs0, BRs1)
+	;
+		{ Comp = (<) },
+		insts_remove_aliases(InstMap, ModuleInfo, OrigInstTable,
+			ILs0, ILs),
+		{ BLs = [functor(ConsIdL, ILs) | BLs1] },
+		normalise_unify_bound_insts(InstMap, ModuleInfo, OrigInstTable,
+			BLs0, BLs1, [BR0 | BRs0], BRs)
+	;
+		{ Comp = (>) },
+		insts_remove_aliases(InstMap, ModuleInfo, OrigInstTable,
+			IRs0, IRs),
+		{ BRs = [functor(ConsIdR, IRs) | BRs1] },
+		normalise_unify_bound_insts(InstMap, ModuleInfo, OrigInstTable,
+			[BL0 | BLs0], BLs, BRs0, BRs1)
+	).
+
+
+%-----------------------------------------------------------------------------%
+
+:- pred inst_remove_aliases(instmap, module_info, inst_table, inst, inst,
+		inst_table, inst_table).
+:- mode inst_remove_aliases(in, in, in, in, out, in, out) is det.
+
+
+inst_remove_aliases(_, _, _, any(U), any(U), IT, IT).
+inst_remove_aliases(_, _, _, free(A), free(A), IT, IT).
+inst_remove_aliases(_, _, _, free(A, T), free(A, T), IT, IT).
+inst_remove_aliases(_, _, _, ground(U, P), ground(U, P), IT, IT).
+inst_remove_aliases(_, _, _, not_reached, not_reached, IT, IT).
+inst_remove_aliases(_, _, _, inst_var(V), inst_var(V), IT, IT).
+inst_remove_aliases(InstMap, ModuleInfo, OrigInstTable, alias(IK), Inst,
+		InstTable0, InstTable) :-
+	inst_table_get_inst_key_table(OrigInstTable, IKT),
+	instmap__inst_key_table_lookup(InstMap, IKT, IK, Inst0),
+	inst_remove_aliases(InstMap, ModuleInfo, OrigInstTable, Inst0, Inst,
+		InstTable0, InstTable).
+inst_remove_aliases(InstMap, ModuleInfo, OrigInstTable,
+		abstract_inst(Name, Insts0), abstract_inst(Name, Insts),
+		InstTable0, InstTable) :-
+	insts_remove_aliases(InstMap, ModuleInfo, OrigInstTable, Insts0, Insts,
+		InstTable0, InstTable).
+inst_remove_aliases(InstMap, ModuleInfo, OrigInstTable, bound(U, BoundInsts0),
+		bound(U, BoundInsts), InstTable0, InstTable) :-
+	bound_insts_remove_aliases(InstMap, ModuleInfo, OrigInstTable,
+		BoundInsts0, BoundInsts, InstTable0, InstTable).
+inst_remove_aliases(InstMap, ModuleInfo, OrigInstTable,
+		defined_inst(InstName0), Inst, InstTable0, InstTable) :-
+	inst_table_get_other_insts(InstTable0, OtherInsts0),
+	other_inst_table_mark_inst_name(OtherInsts0, InstName0, InstName),
+	( other_inst_table_search(OtherInsts0, InstName0, MaybeInst) ->
+		( MaybeInst = known(Inst0) ->
+			Inst2 = Inst0
+		;
+			Inst2 = defined_inst(InstName)
+		),
+		InstTable = InstTable0
+	;
+		other_inst_table_set(OtherInsts0, InstName0, unknown,
+			OtherInsts1),
+		inst_table_set_other_insts(InstTable0, OtherInsts1, InstTable1),
+
+		inst_lookup(OrigInstTable, ModuleInfo, InstName0, Inst0),
+		inst_expand_defined_inst(OrigInstTable, ModuleInfo, Inst0,
+			Inst1),
+		inst_remove_aliases(InstMap, ModuleInfo, OrigInstTable,
+			Inst1, Inst2, InstTable1, InstTable2),
+
+		inst_table_get_other_insts(InstTable2, OtherInsts2),
+		other_inst_table_set(OtherInsts2, InstName0, known(Inst2),
+			OtherInsts),
+		inst_table_set_other_insts(InstTable2, OtherInsts, InstTable)
+	),
+
+		% Avoid expanding recursive insts.  We can use any instmap
+		% here because the new inst doesn't contain any aliases.
+	(
+		inst_contains_instname(Inst2, InstMap, InstTable, ModuleInfo,
+			InstName0)
+	->
+		Inst = defined_inst(InstName0)
+	;
+		inst_contains_instname(Inst2, InstMap, InstTable, ModuleInfo,
+			InstName)
+	->
+		Inst = defined_inst(InstName)
+	;
+		Inst = Inst2
+	).
+
+:- pred insts_remove_aliases(instmap, module_info, inst_table,
+		list(inst), list(inst), inst_table, inst_table).
+:- mode insts_remove_aliases(in, in, in, in, out, in, out) is det.
+
+insts_remove_aliases(_, _, _, [], []) --> [].
+insts_remove_aliases(InstMap, ModuleInfo, OrigInstTable, [I0 | Is0], [I | Is])
+		-->
+	inst_remove_aliases(InstMap, ModuleInfo, OrigInstTable, I0, I),
+	insts_remove_aliases(InstMap, ModuleInfo, OrigInstTable, Is0, Is).
+
+:- pred bound_insts_remove_aliases(instmap, module_info, inst_table,
+		list(bound_inst), list(bound_inst), inst_table, inst_table).
+:- mode bound_insts_remove_aliases(in, in, in, in, out, in, out) is det.
+
+bound_insts_remove_aliases(_, _, _, [], []) --> [].
+bound_insts_remove_aliases(InstMap, ModuleInfo, OrigInstTable,
+		[functor(C, Is0) | Bs0], [functor(C, Is) | Bs]) -->
+	insts_remove_aliases(InstMap, ModuleInfo, OrigInstTable, Is0, Is),
+	bound_insts_remove_aliases(InstMap, ModuleInfo, OrigInstTable, Bs0, Bs).
 
 %-----------------------------------------------------------------------------%
 
Index: unique_modes.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/unique_modes.m,v
retrieving revision 1.39.2.17
diff -u -u -r1.39.2.17 unique_modes.m
--- unique_modes.m	1999/07/19 01:45:49	1.39.2.17
+++ unique_modes.m	1999/07/21 07:03:11
@@ -60,7 +60,7 @@
 :- import_module hlds_data, mode_debug, modecheck_unify, modecheck_call.
 :- import_module mode_util, prog_out, hlds_out, mercury_to_mercury, passes_aux.
 :- import_module modes, prog_data, mode_errors, llds, unify_proc.
-:- import_module (inst), instmap, inst_match, inst_util.
+:- import_module (inst), instmap, inst_match, inst_util, inst_table.
 :- import_module term, varset.
 :- import_module int, list, map, set, std_util, require, assoc_list, string.
 
@@ -197,8 +197,8 @@
 	instmap__lookup_var(InstMapBefore, Var, Inst0),
 	instmap__lookup_var(InstMapAfter, Var, Inst),
 	(
-		\+ inst_matches_final(Inst, InstMapAfter, Inst0, InstMapBefore,
-			InstTable, ModuleInfo)
+		\+ inst_matches_final_ignore_aliasing(Inst, InstMapAfter,
+			Inst0, InstMapBefore, InstTable, ModuleInfo)
 	->
 		ChangedVars = [Var | ChangedVars1],
 		select_changed_inst_vars(Vars, InstMapBefore, InstMapAfter,
@@ -413,7 +413,7 @@
 	mode_info_dcg_get_inst_table(InstTable0),
 	{ inst_table_create_sub(InstTable0, ArgInstTable, Sub, InstTable) },
 	mode_info_set_inst_table(InstTable),
-	{ list__map(apply_inst_key_sub_mode(Sub), ArgModes0, ArgModes) },
+	{ list__map(apply_inst_table_sub_mode(Sub), ArgModes0, ArgModes) },
 
 	{
 		GenericCall = higher_order(_, _, _),
@@ -526,7 +526,7 @@
 	mode_info_get_inst_table(ModeInfo1, InstTable1),
 	inst_table_create_sub(InstTable1, ArgInstTable, Sub, InstTable),
 	mode_info_set_inst_table(InstTable, ModeInfo1, ModeInfo2),
-	list__map(apply_inst_key_sub_mode(Sub), ArgModes0, ArgModes),
+	list__map(apply_inst_table_sub_mode(Sub), ArgModes0, ArgModes),
 
 	proc_info_interface_code_model(ProcInfo, CodeModel),
 	proc_info_never_succeeds(ProcInfo, NeverSucceeds),
Index: unused_args.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/unused_args.m,v
retrieving revision 1.35.2.19
diff -u -u -r1.35.2.19 unused_args.m
--- unused_args.m	1999/07/19 01:45:49	1.35.2.19
+++ unused_args.m	1999/07/21 06:44:47
@@ -56,6 +56,7 @@
 :- import_module code_util, globals, make_hlds, mercury_to_mercury, mode_util.
 :- import_module options, prog_data, prog_out, quantification, special_pred.
 :- import_module passes_aux, inst_match, modules, polymorphism, goal_util.
+:- import_module inst_table.
 
 :- import_module assoc_list, bool, char, int, list, map, require.
 :- import_module set, std_util, string.
-- 
David Overton       Department of Computer Science & Software Engineering
MEngSc Student      The University of Melbourne, Australia
+61 3 9344 9159     http://www.cs.mu.oz.au/~dmo
--------------------------------------------------------------------------
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