diff: bug fix for handling of `any' insts

Fergus Henderson fjh at kryten.cs.mu.OZ.AU
Sun Sep 14 19:22:35 AEST 1997


Fix a bug where the compiler reported an internal error `unify_inst failed'
for certain ill-moded calls involving `any' insts.

compiler/inst_util.m:
	Add code in abstractly_unify_inst to handle some more cases
	of `any' that previously we didn't allow; specifically, the case
	of unifying a `bound' or `ground' inst with `any'.
	The new cases are allowed only in the `fake_unify' case, not in
	the `real_unify' case, because code generation doesn't yet
	support these cases.

	Also fix a couple of unrelated bugs in abstractly_unify_inst
	where the `live' case was passing `dead' rather than `live'
	to unify_uniq.

compiler/prog_data.m:
	Add a new compiler-generated inst name `any_inst', similar to
	`ground_inst', but for insts resulting from unification with
	`any' rather than unification with `ground'.

compiler/hlds_data.m:
	Any a new `any_inst' table, similar to the `ground_inst' table.

compiler/mercury_to_mercury.m:
compiler/mode_util.m:
	Minor changes to handle new `any_inst' insts.

compiler/inst_util.m:
	Fix a couple of bugs

tests/invalid/Mmake:
tests/invalid/any_mode.m:
tests/invalid/any_mode.err_exp:
	Regression test for the above change.

Index: hlds_data.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/hlds_data.m,v
retrieving revision 1.17
diff -u -u -r1.17 hlds_data.m
--- 1.17	1997/08/22 13:54:57
+++ hlds_data.m	1997/09/14 07:16:25
@@ -334,6 +334,8 @@
 
 :- type ground_inst_table == 	map(inst_name, maybe_inst_det).
 
+:- type any_inst_table == 	map(inst_name, maybe_inst_det).
+
 :- type shared_inst_table == 	map(inst_name, maybe_inst).
 
 :- type mostly_uniq_inst_table == map(inst_name, maybe_inst).
@@ -391,6 +393,9 @@
 :- pred inst_table_get_ground_insts(inst_table, ground_inst_table).
 :- mode inst_table_get_ground_insts(in, out) is det.
 
+:- pred inst_table_get_any_insts(inst_table, any_inst_table).
+:- mode inst_table_get_any_insts(in, out) is det.
+
 :- pred inst_table_get_shared_insts(inst_table, shared_inst_table).
 :- mode inst_table_get_shared_insts(in, out) is det.
 
@@ -409,6 +414,9 @@
 :- pred inst_table_set_ground_insts(inst_table, ground_inst_table, inst_table).
 :- mode inst_table_set_ground_insts(in, in, out) is det.
 
+:- pred inst_table_set_any_insts(inst_table, any_inst_table, inst_table).
+:- mode inst_table_set_any_insts(in, in, out) is det.
+
 :- pred inst_table_set_shared_insts(inst_table, shared_inst_table, inst_table).
 :- mode inst_table_set_shared_insts(in, in, out) is det.
 
@@ -439,6 +447,7 @@
 			unify_inst_table,
 			merge_inst_table,
 			ground_inst_table,
+			any_inst_table,
 			shared_inst_table,
 			mostly_uniq_inst_table
 		).
@@ -453,47 +462,56 @@
 		).
 
 inst_table_init(inst_table(UserInsts, UnifyInsts, MergeInsts, GroundInsts,
-				SharedInsts, NondetLiveInsts)) :-
+			AnyInsts, SharedInsts, NondetLiveInsts)) :-
 	map__init(UserInstDefns),
 	UserInsts = user_inst_table(UserInstDefns, []),
 	map__init(UnifyInsts),
 	map__init(MergeInsts),
 	map__init(GroundInsts),
 	map__init(SharedInsts),
+	map__init(AnyInsts),
 	map__init(NondetLiveInsts).
 
-inst_table_get_user_insts(inst_table(UserInsts, _, _, _, _, _), UserInsts).
+inst_table_get_user_insts(inst_table(UserInsts, _, _, _, _, _, _), UserInsts).
 
-inst_table_get_unify_insts(inst_table(_, UnifyInsts, _, _, _, _), UnifyInsts).
+inst_table_get_unify_insts(inst_table(_, UnifyInsts, _, _, _, _, _),
+			UnifyInsts).
 
-inst_table_get_merge_insts(inst_table(_, _, MergeInsts, _, _, _), MergeInsts).
+inst_table_get_merge_insts(inst_table(_, _, MergeInsts, _, _, _, _),
+			MergeInsts).
 
-inst_table_get_ground_insts(inst_table(_, _, _, GroundInsts, _, _),
+inst_table_get_ground_insts(inst_table(_, _, _, GroundInsts, _, _, _),
 			GroundInsts).
 
-inst_table_get_shared_insts(inst_table(_, _, _, _, SharedInsts, _),
+inst_table_get_any_insts(inst_table(_, _, _, _, AnyInsts, _, _), AnyInsts).
+
+inst_table_get_shared_insts(inst_table(_, _, _, _, _, SharedInsts, _),
 			SharedInsts).
 
-inst_table_get_mostly_uniq_insts(inst_table(_, _, _, _, _, NondetLiveInsts),
+inst_table_get_mostly_uniq_insts(inst_table(_, _, _, _, _, _, NondetLiveInsts),
 			NondetLiveInsts).
 
-inst_table_set_user_insts(inst_table(_, B, C, D, E, F), UserInsts,
-			inst_table(UserInsts, B, C, D, E, F)).
+inst_table_set_user_insts(inst_table(_, B, C, D, E, F, G), UserInsts,
+			inst_table(UserInsts, B, C, D, E, F, G)).
+
+inst_table_set_unify_insts(inst_table(A, _, C, D, E, F, G), UnifyInsts,
+			inst_table(A, UnifyInsts, C, D, E, F, G)).
 
-inst_table_set_unify_insts(inst_table(A, _, C, D, E, F), UnifyInsts,
-			inst_table(A, UnifyInsts, C, D, E, F)).
+inst_table_set_merge_insts(inst_table(A, B, _, D, E, F, G), MergeInsts,
+			inst_table(A, B, MergeInsts, D, E, F, G)).
 
-inst_table_set_merge_insts(inst_table(A, B, _, D, E, F), MergeInsts,
-			inst_table(A, B, MergeInsts, D, E, F)).
+inst_table_set_ground_insts(inst_table(A, B, C, _, E, F, G), GroundInsts,
+			inst_table(A, B, C, GroundInsts, E, F, G)).
 
-inst_table_set_ground_insts(inst_table(A, B, C, _, E, F), GroundInsts,
-			inst_table(A, B, C, GroundInsts, E, F)).
+inst_table_set_any_insts(inst_table(A, B, C, D, _, F, G), AnyInsts,
+			inst_table(A, B, C, D, AnyInsts, F, G)).
 
-inst_table_set_shared_insts(inst_table(A, B, C, D, _, F), SharedInsts,
-			inst_table(A, B, C, D, SharedInsts, F)).
+inst_table_set_shared_insts(inst_table(A, B, C, D, E, _, G), SharedInsts,
+			inst_table(A, B, C, D, E, SharedInsts, G)).
 
-inst_table_set_mostly_uniq_insts(inst_table(A, B, C, D, E, _), NondetLiveInsts,
-			inst_table(A, B, C, D, E, NondetLiveInsts)).
+inst_table_set_mostly_uniq_insts(inst_table(A, B, C, D, E, F, _),
+			NondetLiveInsts,
+			inst_table(A, B, C, D, E, F, NondetLiveInsts)).
 
 user_inst_table_get_inst_defns(user_inst_table(InstDefns, _), InstDefns).
 
Index: inst_util.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/inst_util.m,v
retrieving revision 1.3
diff -u -u -r1.3 inst_util.m
--- 1.3	1997/08/21 07:29:05
+++ inst_util.m	1997/09/14 08:57:26
@@ -177,14 +177,8 @@
 
 abstractly_unify_inst_3(live, not_reached, _, _,	M, not_reached, det, M).
 
-abstractly_unify_inst_3(live, any(UniqX), any(UniqY), Real, M,
-					any(Uniq), semidet, M) :-
-	Real = fake_unify,
-	unify_uniq(live, Real, semidet, UniqX, UniqY, Uniq).
-
-abstractly_unify_inst_3(live, any(UniqX), free, Real, M,
-					any(Uniq), det, M) :-
-	unify_uniq(live, Real, det, UniqX, unique, Uniq).
+abstractly_unify_inst_3(live, any(Uniq), Inst0, Real, M0, Inst, Det, M) :-
+	make_any_inst(Inst0, live, Uniq, Real, M0, Inst, Det, M).
 
 abstractly_unify_inst_3(live, free, any(UniqY), Real, M,
 					any(Uniq), det, M) :-
@@ -211,6 +205,14 @@
 
 % abstractly_unify_inst_3(live, free,   abstract_inst(_,_), _, _, _, _) :- fail.
 
+abstractly_unify_inst_3(live, bound(UniqX, List0), any(UniqY),  Real, M0,
+					bound(Uniq, List), Det, M) :-
+	Real = fake_unify, % we do not yet support it for real_unifies
+	unify_uniq(live, Real, semidet, UniqX, UniqY, Uniq),
+	make_any_bound_inst_list(List0, live, UniqY, Real, M0,
+			List, Det1, M),
+	det_par_conjunction_detism(Det1, semidet, Det).
+
 abstractly_unify_inst_3(live,	   bound(UniqY, List0), free, Real, M0,
 					bound(Uniq, List), det,  M) :-
 	unify_uniq(live, Real, det, unique, UniqY, Uniq),
@@ -222,11 +224,11 @@
 			M0,     bound(Uniq, List), Det, M) :-
 	abstractly_unify_bound_inst_list(live, ListX, ListY, Real, M0,
 		List, Det, M),
-	unify_uniq(dead, Real, Det, UniqX, UniqY, Uniq).
+	unify_uniq(live, Real, Det, UniqX, UniqY, Uniq).
 
 abstractly_unify_inst_3(live, bound(UniqX, BoundInsts0), ground(UniqY, _),
 		Real, M0, bound(Uniq, BoundInsts), Det, M) :-
-	unify_uniq(dead, Real, semidet, UniqX, UniqY, Uniq),
+	unify_uniq(live, Real, semidet, UniqX, UniqY, Uniq),
 	make_ground_bound_inst_list(BoundInsts0, live, UniqY, Real, M0,
 			BoundInsts, Det1, M),
 	det_par_conjunction_detism(Det1, semidet, Det).
@@ -238,13 +240,19 @@
 	bound_inst_list_is_ground(List, M).
 ***/
 
+abstractly_unify_inst_3(live, ground(UniqX, yes(PredInst)), any(UniqY), Real, M,
+				ground(Uniq, yes(PredInst)), semidet, M) :-
+	Real = fake_unify,
+	unify_uniq(live, Real, det, UniqX, UniqY, Uniq).
+
 abstractly_unify_inst_3(live, ground(Uniq0, yes(PredInst)), free, Real, M,
 				ground(Uniq, yes(PredInst)), det, M) :-
 	unify_uniq(live, Real, det, unique, Uniq0, Uniq).
 
 abstractly_unify_inst_3(live, ground(UniqX, yes(_)), bound(UniqY, BoundInsts0),
 		Real, M0, bound(Uniq, BoundInsts), Det, M) :-
-	unify_uniq(dead, Real, semidet, UniqX, UniqY, Uniq),
+	% check `Real = fake_unify' ?
+	unify_uniq(live, Real, semidet, UniqX, UniqY, Uniq),
 	make_ground_bound_inst_list(BoundInsts0, live, UniqX, Real, M0,
 			BoundInsts, Det1, M),
 	det_par_conjunction_detism(Det1, semidet, Det).
@@ -290,16 +298,19 @@
 
 abstractly_unify_inst_3(dead, not_reached, _, _, M, not_reached, det, M).
 
-abstractly_unify_inst_3(dead, any(UniqX), any(UniqY), Real, M,
-					any(Uniq), semidet, M) :-
-	Real = fake_unify,
-	unify_uniq(dead, Real, semidet, UniqX, UniqY, Uniq).
-
-abstractly_unify_inst_3(dead, any(UniqX), free, _Real, M,
-					any(UniqX), det, M).
+abstractly_unify_inst_3(dead, any(Uniq), Inst0, Real, M0, Inst, Det, M) :-
+	make_any_inst(Inst0, dead, Uniq, Real, M0, Inst, Det, M).
 
 abstractly_unify_inst_3(dead, free, Inst, _, M, Inst, det, M).
 
+abstractly_unify_inst_3(dead, bound(UniqX, List0), any(UniqY), Real, M0,
+					bound(Uniq, List), Det, M) :-
+	Real = fake_unify, % we do not yet support it for real_unifies
+	unify_uniq(dead, Real, semidet, UniqX, UniqY, Uniq),
+	make_any_bound_inst_list(List0, live, UniqY, Real, M0,
+					List, Det1, M),
+	det_par_conjunction_detism(Det1, semidet, Det).
+
 abstractly_unify_inst_3(dead, bound(UniqX, List), free, Real, ModuleInfo,
 				bound(Uniq, List), det, ModuleInfo) :-
 	unify_uniq(dead, Real, det, UniqX, unique, Uniq).
@@ -331,6 +342,11 @@
 	).
 *****/
 
+abstractly_unify_inst_3(dead, ground(UniqX, yes(PredInst)), any(UniqY), Real, M,
+				ground(Uniq, yes(PredInst)), semidet, M) :-
+	Real = fake_unify, % we do not yet support it for real_unifies
+	unify_uniq(live, Real, semidet, UniqX, UniqY, Uniq).
+
 abstractly_unify_inst_3(dead, ground(Uniq, yes(PredInst)), free, _Real, M,
 				ground(Uniq, yes(PredInst)), det, M).
 
@@ -719,13 +735,13 @@
 	unify_uniq(IsLive, Real, det, unique, Uniq0, Uniq).
 make_ground_inst(bound(Uniq0, BoundInsts0), IsLive, Uniq1, Real, M0,
 		bound(Uniq, BoundInsts), Det, M) :-
-	unify_uniq(dead, Real, semidet, Uniq0, Uniq1, Uniq),
+	unify_uniq(IsLive, Real, semidet, Uniq0, Uniq1, Uniq),
 	make_ground_bound_inst_list(BoundInsts0, IsLive, Uniq1, Real, M0,
 					BoundInsts, Det1, M),
 	det_par_conjunction_detism(Det1, semidet, Det).
-make_ground_inst(ground(Uniq0, _PredInst), _IsLive, Uniq1, Real, M,
+make_ground_inst(ground(Uniq0, _PredInst), IsLive, Uniq1, Real, M,
 		ground(Uniq, no), semidet, M) :-
-	unify_uniq(dead, Real, semidet, Uniq0, Uniq1, Uniq).
+	unify_uniq(IsLive, Real, semidet, Uniq0, Uniq1, Uniq).
 make_ground_inst(inst_var(_), _, _, _, _, _, _, _) :-
 	error("free inst var").
 make_ground_inst(abstract_inst(_,_), _, _, _, M, ground(shared, no),
@@ -800,6 +816,129 @@
 	Bound = functor(ConsId, ArgInsts),
 	make_ground_bound_inst_list(Bounds0, IsLive, Uniq, Real, ModuleInfo1,
 				Bounds, Det2, ModuleInfo),
+	det_par_conjunction_detism(Det1, Det2, Det).
+
+%-----------------------------------------------------------------------------%
+
+% abstractly unify an inst with `any' and calculate the new inst
+% and the determinism of the unification.
+
+:- pred make_any_inst(inst, is_live, uniqueness, unify_is_real, module_info,
+				inst, determinism, module_info).
+:- mode make_any_inst(in, in, in, in, in, out, out, out) is semidet.
+
+make_any_inst(not_reached, _, _, _, M, not_reached, erroneous, M).
+make_any_inst(any(Uniq0), IsLive, Uniq1, Real, M, any(Uniq),
+		semidet, M) :-
+	Real = fake_unify, % not yet supported for real_unifies
+	unify_uniq(IsLive, Real, semidet, Uniq0, Uniq1, Uniq).
+make_any_inst(free, IsLive, Uniq0, Real, M, any(Uniq), det, M) :-
+	unify_uniq(IsLive, Real, det, unique, Uniq0, Uniq).
+make_any_inst(free(T), IsLive, Uniq, Real, M,
+		defined_inst(Any), det, M) :-
+	% The following is a round-about way of doing this
+	%	unify_uniq(IsLive, Real, det, unique, Uniq0, Uniq),
+	%	Any = typed_any(Uniq, T).
+	% without the need for a `typed_any' inst.
+	Any = typed_inst(T, unify_inst(IsLive, free, any(Uniq), Real)).
+make_any_inst(bound(Uniq0, BoundInsts0), IsLive, Uniq1, Real, M0,
+		bound(Uniq, BoundInsts), Det, M) :-
+	Real = fake_unify, % not yet supported for real_unifies
+	unify_uniq(IsLive, Real, semidet, Uniq0, Uniq1, Uniq),
+	make_any_bound_inst_list(BoundInsts0, IsLive, Uniq1, Real, M0,
+					BoundInsts, Det1, M),
+	det_par_conjunction_detism(Det1, semidet, Det).
+make_any_inst(ground(Uniq0, PredInst), IsLive, Uniq1, Real, M,
+		ground(Uniq, PredInst), semidet, M) :-
+	Real = fake_unify, % not yet supported for real_unifies
+	unify_uniq(IsLive, Real, semidet, Uniq0, Uniq1, Uniq).
+make_any_inst(inst_var(_), _, _, _, _, _, _, _) :-
+	error("free inst var").
+make_any_inst(abstract_inst(_,_), _, _, _, M, any(shared),
+		semidet, M).
+make_any_inst(defined_inst(InstName), IsLive, Uniq, Real, ModuleInfo0,
+			Inst, Det, ModuleInfo) :-
+		% check whether the inst name is already in the
+		% any_inst table
+	module_info_insts(ModuleInfo0, InstTable0),
+	inst_table_get_any_insts(InstTable0, AnyInsts0),
+	AnyInstKey = any_inst(InstName, IsLive, Uniq, Real),
+	(
+		map__search(AnyInsts0, AnyInstKey, Result)
+	->
+		( Result = known(AnyInst0, Det0) ->
+			AnyInst = AnyInst0,
+			Det = Det0
+		;
+			AnyInst = defined_inst(AnyInstKey),
+			Det = det
+				% We can safely assume this is det, since
+				% if it were semidet, we would have noticed
+				% this in the process of unfolding the
+				% definition.
+		),
+		ModuleInfo = ModuleInfo0
+	;
+		% insert the inst name in the any_inst table, with
+		% value `unknown' for the moment
+		map__det_insert(AnyInsts0, AnyInstKey, unknown,
+			AnyInsts1),
+		inst_table_set_any_insts(InstTable0, AnyInsts1,
+			InstTable1),
+		module_info_set_insts(ModuleInfo0, InstTable1, ModuleInfo1),
+
+		% expand the inst name, and invoke ourself recursively on
+		% it's expansion
+		inst_lookup(ModuleInfo1, InstName, Inst0),
+		inst_expand(ModuleInfo1, Inst0, Inst1),
+		make_any_inst(Inst1, IsLive, Uniq, Real, ModuleInfo1,
+				AnyInst, Det, ModuleInfo2),
+
+		% now that we have determined the resulting Inst, store
+		% the appropriate value `known(AnyInst, Det)' in the
+		% any_inst table
+		module_info_insts(ModuleInfo2, InstTable2),
+		inst_table_get_any_insts(InstTable2, AnyInsts2),
+		map__det_update(AnyInsts2, AnyInstKey,
+			known(AnyInst, Det), AnyInsts),
+		inst_table_set_any_insts(InstTable2, AnyInsts,
+			InstTable),
+		module_info_set_insts(ModuleInfo2, InstTable, ModuleInfo)
+	),
+		% avoid expanding recursive insts
+	( inst_contains_instname(AnyInst, ModuleInfo, AnyInstKey) ->
+		Inst = defined_inst(AnyInstKey)
+	;
+		Inst = AnyInst
+	).
+
+:- pred make_any_bound_inst_list(list(bound_inst), is_live, uniqueness,
+	unify_is_real, module_info, list(bound_inst), determinism, module_info).
+:- mode make_any_bound_inst_list(in, in, in, in, in,
+	out, out, out) is semidet.
+
+make_any_bound_inst_list([], _, _, _, ModuleInfo, [], det, ModuleInfo).
+make_any_bound_inst_list([Bound0 | Bounds0], IsLive, Uniq, Real, ModuleInfo0,
+			[Bound | Bounds], Det, ModuleInfo) :-
+	Bound0 = functor(ConsId, ArgInsts0),
+	make_any_inst_list(ArgInsts0, IsLive, Uniq, Real, ModuleInfo0,
+				ArgInsts, Det1, ModuleInfo1),
+	Bound = functor(ConsId, ArgInsts),
+	make_any_bound_inst_list(Bounds0, IsLive, Uniq, Real, ModuleInfo1,
+				Bounds, Det2, ModuleInfo),
+	det_par_conjunction_detism(Det1, Det2, Det).
+
+:- pred make_any_inst_list(list(inst), is_live, uniqueness, unify_is_real,
+			module_info, list(inst), determinism, module_info).
+:- mode make_any_inst_list(in, in, in, in, in, out, out, out) is semidet.
+
+make_any_inst_list([], _, _, _, ModuleInfo, [], det, ModuleInfo).
+make_any_inst_list([Inst0 | Insts0], Live, Uniq, Real, ModuleInfo0,
+		[Inst | Insts], Det, ModuleInfo) :-
+	make_any_inst(Inst0, Live, Uniq, Real, ModuleInfo0,
+		Inst, Det1, ModuleInfo1),
+	make_any_inst_list(Insts0, Live, Uniq, Real, ModuleInfo1,
+		Insts, Det2, ModuleInfo),
 	det_par_conjunction_detism(Det1, Det2, Det).
 
 %-----------------------------------------------------------------------------%
Index: mercury_to_mercury.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/mercury_to_mercury.m,v
retrieving revision 1.116
diff -u -u -r1.116 mercury_to_mercury.m
--- 1.116	1997/09/06 05:57:49
+++ mercury_to_mercury.m	1997/09/14 06:39:47
@@ -621,6 +621,26 @@
 	mercury_output_structured_inst_name(InstName, Indent1, VarSet),
 	mercury_output_tabs(Indent),
 	io__write_string(")\n").
+mercury_output_structured_inst_name(any_inst(InstName, IsLive, Uniq, Real),
+		Indent, VarSet) -->
+	mercury_output_tabs(Indent),
+	io__write_string("$any("),
+	( { IsLive = live } ->
+		io__write_string("live, ")
+	;
+		io__write_string("dead, ")
+	),
+	( { Real = real_unify } ->
+		io__write_string("real, ")
+	;
+		io__write_string("fake, ")
+	),
+	mercury_output_uniqueness(Uniq, "shared"),
+	io__write_string(",\n"),
+	{ Indent1 is Indent + 1 },
+	mercury_output_structured_inst_name(InstName, Indent1, VarSet),
+	mercury_output_tabs(Indent),
+	io__write_string(")\n").
 mercury_output_structured_inst_name(typed_ground(Uniqueness, Type),
 		Indent, _VarSet) -->
 	mercury_output_tabs(Indent),
@@ -682,6 +702,22 @@
 	io__write_string(")").
 mercury_output_inst_name(ground_inst(InstName, IsLive, Uniq, Real), VarSet) -->
 	io__write_string("$ground("),
+	mercury_output_inst_name(InstName, VarSet),
+	io__write_string(", "),
+	( { IsLive = live } ->
+		io__write_string("live, ")
+	;
+		io__write_string("dead, ")
+	),
+	mercury_output_uniqueness(Uniq, "shared"),
+	( { Real = real_unify } ->
+		io__write_string(", real")
+	;
+		io__write_string(", fake")
+	),
+	io__write_string(")").
+mercury_output_inst_name(any_inst(InstName, IsLive, Uniq, Real), VarSet) -->
+	io__write_string("$any("),
 	mercury_output_inst_name(InstName, VarSet),
 	io__write_string(", "),
 	( { IsLive = live } ->
Index: mode_util.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/mode_util.m,v
retrieving revision 1.99
diff -u -u -r1.99 mode_util.m
--- 1.99	1997/09/01 14:03:46
+++ mode_util.m	1997/09/14 06:41:16
@@ -441,6 +441,15 @@
 		;
 			Inst = defined_inst(InstName)
 		)
+	; InstName = any_inst(_, _, _, _),
+		module_info_insts(ModuleInfo, InstTable),
+		inst_table_get_any_insts(InstTable, AnyInstTable),
+		map__lookup(AnyInstTable, InstName, MaybeInst),
+		( MaybeInst = known(Inst0, _) ->
+			Inst = Inst0
+		;
+			Inst = defined_inst(InstName)
+		)
 	; InstName = shared_inst(SharedInstName),
 		module_info_insts(ModuleInfo, InstTable),
 		inst_table_get_shared_insts(InstTable, SharedInstTable),
@@ -978,6 +987,9 @@
 	inst_apply_substitution(InstB0, Subst, InstB).
 inst_name_apply_substitution(ground_inst(Inst0, IsLive, Uniq, Real), Subst,
 				ground_inst(Inst, IsLive, Uniq, Real)) :-
+	inst_name_apply_substitution(Inst0, Subst, Inst).
+inst_name_apply_substitution(any_inst(Inst0, IsLive, Uniq, Real), Subst,
+				any_inst(Inst, IsLive, Uniq, Real)) :-
 	inst_name_apply_substitution(Inst0, Subst, Inst).
 inst_name_apply_substitution(shared_inst(InstName0), Subst,
 				shared_inst(InstName)) :-
Index: module_qual.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/module_qual.m,v
retrieving revision 1.22
diff -u -u -r1.22 module_qual.m
--- 1.22	1997/08/22 13:55:43
+++ module_qual.m	1997/09/14 06:42:09
@@ -488,6 +488,8 @@
 	{ error("compiler generated inst unexpected") }.
 qualify_inst_name(ground_inst(_, _, _, _), _, _, _) -->
 	{ error("compiler generated inst unexpected") }.
+qualify_inst_name(any_inst(_, _, _, _), _, _, _) -->
+	{ error("compiler generated inst unexpected") }.
 qualify_inst_name(shared_inst(_), _, _, _) -->
 	{ error("compiler generated inst unexpected") }.
 qualify_inst_name(mostly_uniq_inst(_), _, _, _) -->
Index: prog_data.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/prog_data.m,v
retrieving revision 1.24
diff -u -u -r1.24 prog_data.m
--- 1.24	1997/08/22 13:55:49
+++ prog_data.m	1997/09/14 07:52:46
@@ -241,16 +241,28 @@
 	% An `inst_name' is used as a key for the inst_table.
 	% It is either a user-defined inst `user_inst(Name, Args)',
 	% or some sort of compiler-generated inst, whose name
-	% is a representation of it's meaning.  For example
-	% `merge_inst(InstA, InstB)' is the name used for the inst
-	% that results from merging InstA and InstB using `merge_inst'.
+	% is a representation of it's meaning.
+	%
+	% For example, `merge_inst(InstA, InstB)' is the name used for the
+	% inst that results from merging InstA and InstB using `merge_inst'.
 	% Similarly `unify_inst(IsLive, InstA, InstB, IsReal)' is
 	% the name for the inst that results from a call to
-	% `abstractly_unify_inst(IsLive, InstA, InstB, IsReal)', etc.
+	% `abstractly_unify_inst(IsLive, InstA, InstB, IsReal)'.
+	% And `ground_inst' and `any_inst' are insts that result
+	% from unifying an inst with `ground' or `any', respectively.
+	% `typed_inst' is an inst with added type information.
+	% `typed_ground(Uniq, Type)' a equivalent to
+	% `typed_inst(ground(Uniq, no), Type)'.
+	% Note that `typed_ground' is a special case of `typed_inst',
+	% and `ground_inst' and `any_inst' are special cases of `unify_inst'.
+	% The reason for having the special cases is efficiency.
+	
 :- type inst_name	--->	user_inst(sym_name, list(inst))
 			;	merge_inst(inst, inst)
 			;	unify_inst(is_live, inst, inst, unify_is_real)
 			;	ground_inst(inst_name, is_live, uniqueness,
+						unify_is_real)
+			;	any_inst(inst_name, is_live, uniqueness,
 						unify_is_real)
 			;	shared_inst(inst_name)
 			;	mostly_uniq_inst(inst_name)
cvs diff: Diffing notes
-- 
Fergus Henderson <fjh at cs.mu.oz.au>   |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>   |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3         |     -- the last words of T. S. Garp.



More information about the developers mailing list