[m-dev.] for review: polymorphic ground insts [2/3]

David Overton dmo at ender.cs.mu.oz.au
Wed Feb 9 13:39:58 AEDT 2000


Index: compiler/mercury_to_mercury.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mercury_to_mercury.m,v
retrieving revision 1.166
diff -u -r1.166 mercury_to_mercury.m
--- compiler/mercury_to_mercury.m	2000/01/25 04:09:52	1.166
+++ compiler/mercury_to_mercury.m	2000/02/03 03:44:05
@@ -597,12 +597,14 @@
 
 mercury_output_inst_defn(VarSet, abstract_inst(Name, Args), Context) -->
 	io__write_string(":- inst ("),
-	{ construct_qualified_term(Name, Args, Context, InstTerm) },
+	{ list__map(pred(V::in, variable(V)::out) is det, Args, ArgTerms) },
+	{ construct_qualified_term(Name, ArgTerms, Context, InstTerm) },
 	mercury_output_term(InstTerm, VarSet, no),
 	io__write_string(").\n").
 mercury_output_inst_defn(VarSet, eqv_inst(Name, Args, Body), Context) -->
 	io__write_string(":- inst ("),
-	{ construct_qualified_term(Name, Args, Context, InstTerm) },
+	{ list__map(pred(V::in, variable(V)::out) is det, Args, ArgTerms) },
+	{ construct_qualified_term(Name, ArgTerms, Context, InstTerm) },
 	mercury_output_term(InstTerm, VarSet, no),
 	io__write_string(") = "),
 	mercury_output_inst(Body, VarSet),
@@ -640,12 +642,12 @@
 	mercury_output_structured_bound_insts(BoundInsts, Indent, VarSet),
 	mercury_output_tabs(Indent),
 	io__write_string(")\n").
-mercury_output_structured_inst(ground(Uniq, MaybePredInfo), Indent, VarSet)
+mercury_output_structured_inst(ground(Uniq, GroundInstInfo), Indent, VarSet)
 		-->
 	mercury_output_tabs(Indent),
 	(	
-		{ MaybePredInfo = yes(pred_inst_info(PredOrFunc, Modes, Det)) }
-	->
+		{ GroundInstInfo = higher_order(pred_inst_info(PredOrFunc,
+				Modes, Det)) },
 		( { Uniq = shared } ->
 			[]
 		;
@@ -682,6 +684,13 @@
 			io__write_string(")\n")
 		)
 	;
+		{ GroundInstInfo = constrained_inst_var(Var) },
+		mercury_output_tabs(Indent),
+		mercury_output_var(Var, VarSet, no),
+		io__write_string("\n")
+		% AAA
+	;
+		{ GroundInstInfo = none},
 		mercury_output_uniqueness(Uniq, "ground"),
 		io__write_string("\n")
 	).
@@ -709,10 +718,10 @@
 	io__write_string("("),
 	mercury_output_bound_insts(BoundInsts, VarSet),
 	io__write_string(")").
-mercury_output_inst(ground(Uniq, MaybePredInfo), VarSet) -->
+mercury_output_inst(ground(Uniq, GroundInstInfo), VarSet) -->
 	(	
-		{ MaybePredInfo = yes(pred_inst_info(PredOrFunc, Modes, Det)) }
-	->
+		{ GroundInstInfo = higher_order(pred_inst_info(PredOrFunc,
+				Modes, Det)) },
 		( { Uniq = shared } ->
 			[]
 		;
@@ -750,6 +759,11 @@
 			io__write_string(")")
 		)
 	;
+		{ GroundInstInfo = constrained_inst_var(Var) },
+		mercury_output_var(Var, VarSet, no)
+		% AAA
+	;
+		{ GroundInstInfo = none },
 		mercury_output_uniqueness(Uniq, "ground")
 	).
 mercury_output_inst(inst_var(Var), VarSet) -->
@@ -1102,7 +1116,8 @@
 
 mercury_output_mode_defn(VarSet, eqv_mode(Name, Args, Mode), Context) -->
 	io__write_string(":- mode ("),
-	{ construct_qualified_term(Name, Args, Context, ModeTerm) },
+	{ list__map(pred(V::in, variable(V)::out) is det, Args, ArgTerms) },
+	{ construct_qualified_term(Name, ArgTerms, Context, ModeTerm) },
 	mercury_output_term(ModeTerm, VarSet, no),
 	io__write_string(") :: "),
 	mercury_output_mode(Mode, VarSet),
@@ -1139,8 +1154,8 @@
 	    % check for higher-order pred or func modes, and output them
 	    % in a nice format
 	    %
-	    { InstA = ground(_Uniq,
-			yes(pred_inst_info(_PredOrFunc, _Modes, _Det))) },
+	    { InstA = ground(_Uniq, higher_order(pred_inst_info(_PredOrFunc,
+				_Modes, _Det))) },
 	    { InstB = InstA }
 	->
 	    mercury_output_inst(InstA, VarSet)
Index: compiler/mode_info.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mode_info.m,v
retrieving revision 1.51
diff -u -r1.51 mode_info.m
--- compiler/mode_info.m	1999/07/13 08:53:13	1.51
+++ compiler/mode_info.m	2000/02/04 00:04:22
@@ -1,5 +1,5 @@
 %-----------------------------------------------------------------------------%
-% Copyright (C) 1994-1999 The University of Melbourne.
+% Copyright (C) 1994-2000 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.
 %-----------------------------------------------------------------------------%
@@ -339,35 +339,42 @@
 
 :- type mode_info 
 	--->	mode_info(
-			io__state,
-			module_info,
-			pred_id,	% The pred we are checking
-			proc_id,	% The mode which we are checking
-			prog_varset,	% The variables in the current proc
-			map(prog_var, type),
+			io_state :: io__state,
+			module_info :: module_info,
+			predid :: pred_id,	% The pred we are checking
+			procid :: proc_id,	% The mode which we are checking
+			varset :: prog_varset,	
+					% The variables in the current proc
+			var_types :: map(prog_var, type),
 					% The types of the variables
-			prog_context,	% The line number of the subgoal we
+			context :: prog_context,
+					% The line number of the subgoal we
 					% are currently checking
-			mode_context,	% A description of where in the
+			mode_context :: mode_context,
+					% A description of where in the
 					% goal the error occurred
-			instmap,	% The current instantiatedness
+			instmap :: instmap,
+					% The current instantiatedness
 					% of the variables
-			locked_vars,	% The "locked" variables,
+			locked_vars :: locked_vars,
+					% The "locked" variables,
 					% i.e. variables which cannot be
 					% further instantiated inside a
 					% negated context
-			delay_info,	% info about delayed goals
-			list(mode_error_info),
+			delay_info :: delay_info,
+					% info about delayed goals
+			errors :: list(mode_error_info),
 					% The mode errors found
 
-			list(set(prog_var)),	% The live variables,
+			live_vars :: list(set(prog_var)),
+					% The live variables,
 	% i.e. those variables which may be referenced again on forward
 	% execution or after shallow backtracking.  (By shallow
 	% backtracking, I mean semidet backtracking in a negation,
 	% if-then-else, or semidet disjunction within the current
 	% predicate.)
 
-			list(set(prog_var)),
+			nondet_live_vars :: list(set(prog_var)),
 					% The nondet-live variables,
 	% i.e. those variables which may be referenced again after deep
 	% backtracking TO THE CURRENT EXECUTION POINT.  These are the
@@ -378,7 +385,9 @@
 	% execution point, since those variables will *already* have
 	% been marked as mostly_unique rather than unique.)
 
-			assoc_list(prog_var, inst),
+			instvarset :: inst_varset,
+
+			last_checkpoint_insts :: assoc_list(prog_var, inst),
 	% This field is used by the checkpoint code when debug_modes is on.
 	% It has the instmap that was current at the last mode checkpoint,
 	% so that checkpoints do not print out the insts of variables
@@ -386,7 +395,8 @@
 	% This field will always contain an empty list if debug_modes is off,
 	% since its information is not needed then.
 
-			list(pair(set(prog_var), set(prog_var))),
+			parallel_vars ::
+				list(pair(set(prog_var), set(prog_var))),
 	% A stack of pairs of sets of variables used to mode-check
 	% parallel conjunctions. The first set is the nonlocals of
 	% the parallel conjunction. The second set is a subset of the
@@ -394,18 +404,20 @@
 	% bound inside the current parallel conjunct - the stack is for
 	% the correct handling of nested parallel conjunctions.
 
-			bool,		% Changed flag
+			changed_flag :: bool,
+					% Changed flag
 					% If `yes', then we may need
 					% to repeat mode inference.
 
-			how_to_check_goal,
+			how_to_check :: how_to_check_goal,
 
-			may_change_called_proc,
+			may_change_called_proc :: may_change_called_proc,
 					% Is mode analysis allowed
 					% to change which procedure
 					% is called?
 
-			bool		% Are we rechecking a goal after
+			checking_extra_goals :: bool
+					% Are we rechecking a goal after
 					% introducing unifications for
 					% complicated sub-unifications
 					% or an implied mode?
@@ -435,6 +447,7 @@
 	map__lookup(Procs, ProcId, ProcInfo),
 	proc_info_varset(ProcInfo, VarSet),
 	proc_info_vartypes(ProcInfo, VarTypes),
+	proc_info_inst_varset(ProcInfo, InstVarSet),
 
 	LiveVarsList = [LiveVars],
 	NondetLiveVarsList = [LiveVars],
@@ -446,7 +459,7 @@
 	ModeInfo = mode_info(
 		IOState, ModuleInfo, PredId, ProcId, VarSet, VarTypes,
 		Context, ModeContext, InstMapping0, LockedVars, DelayInfo,
-		ErrorList, LiveVarsList, NondetLiveVarsList, [], [],
+		ErrorList, LiveVarsList, NondetLiveVarsList, InstVarSet, [], [],
 		Changed, HowToCheck, MayChangeProc, CheckingExtraGoals
 	).
 
@@ -454,108 +467,83 @@
 
 	% Lots of very boring access predicates.
 
-mode_info_get_io_state(
-		mode_info(IOState0,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_),
-		IOState) :-
+mode_info_get_io_state(ModeInfo, IOState) :-
 	% XXX
-	unsafe_promise_unique(IOState0, IOState).
+	unsafe_promise_unique(ModeInfo^io_state, IOState).
 
 %-----------------------------------------------------------------------------%
 
-mode_info_set_io_state(mode_info(_,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T),
-		IOState0,
-		mode_info(IOState,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T)) :-
+mode_info_set_io_state(ModeInfo, IOState0, ModeInfo^io_state := IOState) :-
 	% XXX
 	unsafe_promise_unique(IOState0, IOState).
 
 %-----------------------------------------------------------------------------%
 
-mode_info_get_module_info(
-		mode_info(_,ModuleInfo,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_),
-		ModuleInfo).
+mode_info_get_module_info(ModeInfo, ModeInfo^module_info).
 
 %-----------------------------------------------------------------------------%
 
-mode_info_set_module_info(mode_info(A,_,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T),
-		ModuleInfo,
-		mode_info(A,ModuleInfo,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T)).
+mode_info_set_module_info(ModeInfo, ModuleInfo,
+		ModeInfo^module_info := ModuleInfo).
 
 %-----------------------------------------------------------------------------%
 
-mode_info_get_preds(
-		mode_info(_,ModuleInfo,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_),
-		Preds) :-
-	module_info_preds(ModuleInfo, Preds).
+mode_info_get_preds(ModeInfo, Preds) :-
+	module_info_preds(ModeInfo^module_info, Preds).
 
 %-----------------------------------------------------------------------------%
 
-mode_info_get_modes(
-		mode_info(_,ModuleInfo,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_),
-		Modes) :-
-	module_info_modes(ModuleInfo, Modes).
+mode_info_get_modes(ModeInfo, Modes) :-
+	module_info_modes(ModeInfo^module_info, Modes).
 
 %-----------------------------------------------------------------------------%
 
-mode_info_get_insts(
-		mode_info(_,ModuleInfo,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_),
-		Insts) :-
-	module_info_insts(ModuleInfo, Insts).
+mode_info_get_insts(ModeInfo, Insts) :-
+	module_info_insts(ModeInfo^module_info, Insts).
 
 %-----------------------------------------------------------------------------%
 
-mode_info_get_predid(mode_info(_,_,PredId,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_),
-		PredId).
+mode_info_get_predid(ModeInfo, ModeInfo^predid).
 
 %-----------------------------------------------------------------------------%
 
-mode_info_get_procid(mode_info(_,_,_,ProcId,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_), 
-		ProcId).
+mode_info_get_procid(ModeInfo, ModeInfo^procid).
 
 %-----------------------------------------------------------------------------%
 
-mode_info_get_varset(mode_info(_,_,_,_,VarSet,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_),
-		VarSet).
+mode_info_get_varset(ModeInfo, ModeInfo^varset).
 
 %-----------------------------------------------------------------------------%
 
-mode_info_set_varset(VarSet,
-		mode_info(A,B,C,D,_,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T),
-		mode_info(A,B,C,D,VarSet,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T)).
+mode_info_set_varset(VarSet) -->
+	^varset := VarSet.
 
 %-----------------------------------------------------------------------------%
 
-mode_info_get_var_types(
-		mode_info(_,_,_,_,_,VarTypes,_,_,_,_,_,_,_,_,_,_,_,_,_,_),
-		VarTypes).
+mode_info_get_var_types(ModeInfo, ModeInfo^var_types).
 
 %-----------------------------------------------------------------------------%
 
-mode_info_set_var_types(VTypes,
-		mode_info(A,B,C,D,E,_,G,H,I,J,K,L,M,N,O,P,Q,R,S,T),
-		mode_info(A,B,C,D,E,VTypes,G,H,I,J,K,L,M,N,O,P,Q,R,S,T)).
+mode_info_set_var_types(VTypes) -->
+	^var_types := VTypes.
 
 %-----------------------------------------------------------------------------%
 
-mode_info_get_context(mode_info(_,_,_,_,_,_,Context,_,_,_,_,_,_,_,_,_,_,_,_,_),
-		Context).
+mode_info_get_context(ModeInfo, ModeInfo^context).
 
 %-----------------------------------------------------------------------------%
 
-mode_info_set_context(Context,
-		mode_info(A,B,C,D,E,F,_,H,I,J,K,L,M,N,O,P,Q,R,S,T),
-		mode_info(A,B,C,D,E,F,Context,H,I,J,K,L,M,N,O,P,Q,R,S,T)).
+mode_info_set_context(Context) -->
+	^context := Context.
 
 %-----------------------------------------------------------------------------%
 
-mode_info_get_mode_context(
-		mode_info(_,_,_,_,_,_,_,ModeContext,_,_,_,_,_,_,_,_,_,_,_,_),
-		ModeContext).
+mode_info_get_mode_context(ModeInfo, ModeInfo^mode_context).
 
 %-----------------------------------------------------------------------------%
 
-mode_info_set_mode_context(ModeContext,
-		mode_info(A,B,C,D,E,F,G,_,I,J,K,L,M,N,O,P,Q,R,S,T),
-		mode_info(A,B,C,D,E,F,G,ModeContext,I,J,K,L,M,N,O,P,Q,R,S,T)).
+mode_info_set_mode_context(ModeContext) -->
+	^mode_context := ModeContext.
 
 %-----------------------------------------------------------------------------%
 
@@ -583,8 +571,7 @@
 
 %-----------------------------------------------------------------------------%
 
-mode_info_get_instmap(mode_info(_,_,_,_,_,_,_,_,InstMap,_,_,_,_,_,_,_,_,_,_,_),
-		InstMap).
+mode_info_get_instmap(ModeInfo, ModeInfo^instmap).
 
 	% mode_info_dcg_get_instmap/3 is the same as mode_info_get_instmap/2
 	% except that it's easier to use inside a DCG.
@@ -594,46 +581,42 @@
 
 %-----------------------------------------------------------------------------%
 
-mode_info_set_instmap( InstMap,
-		mode_info(A,B,C,D,E,F,G,H,InstMap0,J,
-			DelayInfo0,L,M,N,O,P,Q,R,S,T),
-		mode_info(A,B,C,D,E,F,G,H,InstMap,J,
-			DelayInfo,L,M,N,O,P,Q,R,S,T)) :-
-	( instmap__is_unreachable(InstMap), instmap__is_reachable(InstMap0) ->
-		delay_info__bind_all_vars(DelayInfo0, DelayInfo)
+mode_info_set_instmap(InstMap) -->
+	InstMap0 =^ instmap,
+	^instmap := InstMap,
+	(
+		{ instmap__is_unreachable(InstMap) },
+		{ instmap__is_reachable(InstMap0) }
+	->
+		DelayInfo0 =^ delay_info,
+		{ delay_info__bind_all_vars(DelayInfo0, DelayInfo) },
+		^delay_info := DelayInfo
 	;
-		DelayInfo = DelayInfo0
+		[]
 	).
 
 %-----------------------------------------------------------------------------%
 
-mode_info_get_locked_vars(
-		mode_info(_,_,_,_,_,_,_,_,_,LockedVars,_,_,_,_,_,_,_,_,_,_),
-		LockedVars).
+mode_info_get_locked_vars(ModeInfo, ModeInfo^locked_vars).
 
 %-----------------------------------------------------------------------------%
 
-mode_info_set_locked_vars( mode_info(A,B,C,D,E,F,G,H,I,_,K,L,M,N,O,P,Q,R,S,T),
-	LockedVars,
-	mode_info(A,B,C,D,E,F,G,H,I,LockedVars,K,L,M,N,O,P,Q,R,S,T)).
+mode_info_set_locked_vars(ModeInfo, LockedVars,
+		ModeInfo^locked_vars := LockedVars).
 
 %-----------------------------------------------------------------------------%
 
-mode_info_get_errors(mode_info(_,_,_,_,_,_,_,_,_,_,_,Errors,_,_,_,_,_,_,_,_),
-		Errors).
+mode_info_get_errors(ModeInfo, ModeInfo^errors).
 
 %-----------------------------------------------------------------------------%
 
-mode_info_get_num_errors(
-		mode_info(_,_,_,_,_,_,_,_,_,_,_,Errors,_,_,_,_,_,_,_,_),
-		NumErrors) :-
-	list__length(Errors, NumErrors).
+mode_info_get_num_errors(ModeInfo, NumErrors) :-
+	list__length(ModeInfo^errors, NumErrors).
 
 %-----------------------------------------------------------------------------%
 
-mode_info_set_errors(Errors,
-		mode_info(A,B,C,D,E,F,G,H,I,J,K,_,M,N,O,P,Q,R,S,T), 
-		mode_info(A,B,C,D,E,F,G,H,I,J,K,Errors,M,N,O,P,Q,R,S,T)).
+mode_info_set_errors(Errors) -->
+	^errors := Errors.
 
 %-----------------------------------------------------------------------------%
 
@@ -644,25 +627,20 @@
 
 	% Add a set of vars to the bag of live vars and
 	% the bag of nondet-live vars.
-
-mode_info_add_live_vars(NewLiveVars,
-		mode_info(A,B,C,D,E,F,G,H,I,J,K,L,
-			LiveVars0,NondetLiveVars0,O,P,Q,R,S,T),
-		mode_info(A,B,C,D,E,F,G,H,I,J,K,L,
-			LiveVars,NondetLiveVars,O,P,Q,R,S,T)) :-
 
-	LiveVars = [NewLiveVars | LiveVars0],
-	NondetLiveVars = [NewLiveVars | NondetLiveVars0].
+mode_info_add_live_vars(NewLiveVars) -->
+	LiveVars0 =^ live_vars,
+	NondetLiveVars0 =^ nondet_live_vars,
+	^live_vars := [NewLiveVars | LiveVars0],
+	^nondet_live_vars := [NewLiveVars | NondetLiveVars0].
 
 	% Remove a set of vars from the bag of live vars and
 	% the bag of nondet-live vars.
 
-mode_info_remove_live_vars(OldLiveVars, ModeInfo0, ModeInfo) :-
-	ModeInfo0 = mode_info(A,B,C,D,E,F,G,H,I,J,K,L,
-				LiveVars0, NondetLiveVars0,O,P,Q,R,S,T),
-	ModeInfo1 = mode_info(A,B,C,D,E,F,G,H,I,J,K,L,
-				LiveVars, NondetLiveVars,O,P,Q,R,S,T),
-	(
+mode_info_remove_live_vars(OldLiveVars) -->
+	LiveVars0 =^ live_vars,
+	NondetLiveVars0 =^ nondet_live_vars,
+	{
 		list__delete_first(LiveVars0, OldLiveVars, LiveVars1),
 		list__delete_first(NondetLiveVars0, OldLiveVars,
 			NondetLiveVars1)
@@ -671,13 +649,15 @@
 		NondetLiveVars = NondetLiveVars1
 	;
 		error("mode_info_remove_live_vars: failed")
-	),
+	},
+	^live_vars := LiveVars,
+	^nondet_live_vars := NondetLiveVars,
 		% when a variable becomes dead, we may be able to wake
 		% up a goal which is waiting on that variable
-	set__to_sorted_list(OldLiveVars, VarList),
-	mode_info_get_delay_info(ModeInfo1, DelayInfo0),
-	delay_info__bind_var_list(VarList, DelayInfo0, DelayInfo),
-	mode_info_set_delay_info(DelayInfo, ModeInfo1, ModeInfo).
+	{ set__to_sorted_list(OldLiveVars, VarList) },
+	DelayInfo0 =^ delay_info,
+	{ delay_info__bind_var_list(VarList, DelayInfo0, DelayInfo) },
+	^delay_info := DelayInfo.
 
 	% Check whether a list of variables are live or not
 
@@ -688,12 +668,10 @@
 
 	% Check whether a variable is live or not
 
-mode_info_var_is_live(
-		mode_info(_,_,_,_,_,_,_,_,_,_,_,_,LiveVarsList,_,_,_,_,_,_,_),
-		Var, Result) :-
+mode_info_var_is_live(ModeInfo, Var, Result) :-
 	(
 		% some [LiveVars] 
-		list__member(LiveVars, LiveVarsList),
+		list__member(LiveVars, ModeInfo^live_vars),
 		set__member(Var, LiveVars)
 	->
 		Result = live
@@ -703,11 +681,10 @@
 
 	% Check whether a variable is nondet_live or not.
 
-mode_info_var_is_nondet_live(mode_info(_,_,_,_,_,_,_,_,_,_,_,_,_,
-		NondetLiveVarsList,_,_,_,_,_,_), Var, Result) :-
+mode_info_var_is_nondet_live(ModeInfo, Var, Result) :-
 	(
 		% some [LiveVars] 
-		list__member(LiveVars, NondetLiveVarsList),
+		list__member(LiveVars, ModeInfo^nondet_live_vars),
 		set__member(Var, LiveVars)
 	->
 		Result = live
@@ -715,30 +692,23 @@
 		Result = dead
 	).
 
-mode_info_get_liveness(mode_info(_,_,_,_,_,_,_,_,_,_,_,_,LiveVarsList,
-		_,_,_,_,_,_,_), LiveVars) :-
+mode_info_get_liveness(ModeInfo, LiveVars) :-
 	set__init(LiveVars0),
-	mode_info_get_liveness_2(LiveVarsList, LiveVars0, LiveVars).
+	mode_info_get_liveness_2(ModeInfo^live_vars, LiveVars0, LiveVars).
 
 mode_info_get_liveness_2([], LiveVars, LiveVars).
 mode_info_get_liveness_2([LiveVarsSet | LiveVarsList], LiveVars0, LiveVars) :-
 	set__union(LiveVars0, LiveVarsSet, LiveVars1),
 	mode_info_get_liveness_2(LiveVarsList, LiveVars1, LiveVars).
 
-mode_info_get_live_vars(mode_info(_,_,_,_,_,_,_,_,_,_,_,_,LiveVarsList,
-		_,_,_,_,_,_,_), LiveVarsList).
+mode_info_get_live_vars(ModeInfo, ModeInfo^live_vars).
 
-mode_info_set_live_vars(LiveVarsList,
-		mode_info(A,B,C,D,E,F,G,H,I,J,K,L,_,N,O,P,Q,R,S,T),
-		mode_info(A,B,C,D,E,F,G,H,I,J,K,L,LiveVarsList,N,O,P,Q,R,S,T)).
+mode_info_set_live_vars(LiveVarsList) -->
+	^live_vars := LiveVarsList.
 
 %-----------------------------------------------------------------------------%
-
-	% Since we don't yet handle polymorphic modes, the inst varset
-	% is always empty.
 
-mode_info_get_instvarset(_ModeInfo, InstVarSet) :-
-	varset__init(InstVarSet).
+mode_info_get_instvarset(ModeInfo, ModeInfo^instvarset).
 
 mode_info_get_types_of_vars(ModeInfo, Vars, TypesOfVars) :-
 	mode_info_get_var_types(ModeInfo, VarTypes),
@@ -782,72 +752,53 @@
 	;
 		mode_info_var_is_locked_2(Sets, Var, Reason)
 	).
+
+mode_info_get_delay_info(ModeInfo, ModeInfo^delay_info).
+
+mode_info_set_delay_info(DelayInfo) -->
+	^delay_info := DelayInfo.
+
+mode_info_get_nondet_live_vars(ModeInfo, ModeInfo^nondet_live_vars).
+
+mode_info_set_nondet_live_vars(NondetLiveVars) -->
+	^nondet_live_vars := NondetLiveVars.
+
+mode_info_get_last_checkpoint_insts(ModeInfo, ModeInfo^last_checkpoint_insts).
+
+mode_info_set_last_checkpoint_insts(LastCheckpointInsts) -->
+	^last_checkpoint_insts := LastCheckpointInsts.
+
+mode_info_get_parallel_vars(PVars) -->
+	PVars =^ parallel_vars.
+
+mode_info_set_parallel_vars(PVars) -->
+	^parallel_vars := PVars.
+
+mode_info_get_changed_flag(ModeInfo, ModeInfo^changed_flag).
+
+mode_info_set_changed_flag(Changed) -->
+	^changed_flag := Changed.
+
+mode_info_get_how_to_check(ModeInfo, ModeInfo^how_to_check).
+
+mode_info_set_how_to_check(How) -->
+	^how_to_check := How.
+
+mode_info_get_may_change_called_proc(ModeInfo,
+		ModeInfo^may_change_called_proc).
+
+mode_info_set_may_change_called_proc(MayChange) -->
+	^may_change_called_proc := MayChange.
 
-mode_info_get_delay_info(
-		mode_info(_,_,_,_,_,_,_,_,_,_,DelayInfo,_,_,_,_,_,_,_,_,_),
-		DelayInfo).
-
-mode_info_set_delay_info(DelayInfo,
-		mode_info(A,B,C,D,E,F,G,H,I,J,_,L,M,N,O,P,Q,R,S,T),
-		mode_info(A,B,C,D,E,F,G,H,I,J,DelayInfo,L,M,N,O,P,Q,R,S,T)).
-
-mode_info_get_nondet_live_vars(mode_info(_,_,_,_,_,_,_,_,_,_,_,_,_,
-			NondetLiveVars,_,_,_,_,_,_), NondetLiveVars).
-
-mode_info_set_nondet_live_vars(NondetLiveVars,
-	mode_info(A,B,C,D,E,F,G,H,I,J,K,L,M,_,O,P,Q,R,S,T),
-	mode_info(A,B,C,D,E,F,G,H,I,J,K,L,M,NondetLiveVars,O,P,Q,R,S,T)).
-
-mode_info_get_last_checkpoint_insts(mode_info(_,_,_,_,_,_,_,_,_,_,_,_,_,_,
-		LastCheckpointInsts,_,_,_,_,_), LastCheckpointInsts).
-
-mode_info_set_last_checkpoint_insts(LastCheckpointInsts,
-			mode_info(A,B,C,D,E,F,G,H,I,J,K,L,M,N,_,P,Q,R,S,T),
-			mode_info(A,B,C,D,E,F,G,H,I,J,K,L,M,N,
-				LastCheckpointInsts,P,Q,R,S,T)).
-
-mode_info_get_parallel_vars(PVars, ModeInfo, ModeInfo) :-
-	ModeInfo = mode_info(_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,PVars,_,_,_,_).
-
-mode_info_set_parallel_vars(PVars,
-		mode_info(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,_,Q,R,S,T),
-		mode_info(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,PVars,Q,R,S,T)).
-
-mode_info_get_changed_flag(
-		mode_info(_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,Changed,_,_,_),
-		Changed).
-
-mode_info_set_changed_flag(Changed,
-		mode_info(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,_,R,S,T),
-		mode_info(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Changed,R,S,T)).
-
-mode_info_get_how_to_check(
-		mode_info(_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,How,_,_),
-		How).
-
-mode_info_set_how_to_check(How,
-		mode_info(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,_,S,T),
-		mode_info(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,How,S,T)).
-
-mode_info_get_may_change_called_proc(
-		mode_info(_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,MayChange,_),
-		MayChange).
-
-mode_info_set_may_change_called_proc(MayChange,
-		mode_info(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,_,T),
-		mode_info(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,MayChange,T)).
-
-mode_info_set_checking_extra_goals(Checking,
-		mode_info(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,Checking0),
-		mode_info(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,Checking)) :-
-	( Checking0 = yes, Checking = yes ->
+mode_info_set_checking_extra_goals(Checking) -->
+	( yes =^ checking_extra_goals, { Checking = yes } ->
 		% This should never happen - once the extra goals are
 		% introduced, rechecking the goal should not introduce
 		% more extra goals.
-		error(
-		"mode analysis: rechecking extra goals adds more extra goals")
+		{ error(
+		"mode analysis: rechecking extra goals adds more extra goals") }
 	;
-		true
+		^checking_extra_goals := Checking
 	).
 
 %-----------------------------------------------------------------------------%
Index: compiler/mode_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mode_util.m,v
retrieving revision 1.119
diff -u -r1.119 mode_util.m
--- compiler/mode_util.m	2000/02/07 00:31:09	1.119
+++ compiler/mode_util.m	2000/02/09 00:29:49
@@ -112,9 +112,9 @@
 				module_info, module_info).
 :- mode recompute_instmap_delta_proc(in, in, out, in, out) is det.
 
-:- pred recompute_instmap_delta(bool, hlds_goal, hlds_goal, vartypes, instmap,
-				module_info, module_info).
-:- mode recompute_instmap_delta(in, in, out, in, in, in, out) is det.
+:- pred recompute_instmap_delta(bool, hlds_goal, hlds_goal, vartypes,
+		inst_varset, instmap, module_info, module_info).
+:- mode recompute_instmap_delta(in, in, out, in, in, in, in, out) is det.
 
 	% Given corresponding lists of types and modes, produce a new
 	% list of modes which includes the information provided by the
@@ -175,6 +175,20 @@
 
 %-----------------------------------------------------------------------------%
 
+:- pred inst_list_apply_substitution(list(inst), inst_var_sub, list(inst)).
+:- mode inst_list_apply_substitution(in, in, out) is det.
+
+:- pred mode_list_apply_substitution(list(mode), inst_var_sub, list(mode)).
+:- mode mode_list_apply_substitution(in, in, out) is det.
+
+%-----------------------------------------------------------------------------%
+
+:- pred rename_apart_inst_vars(inst_varset, inst_varset, list(mode),
+		list(mode)).
+:- mode rename_apart_inst_vars(in, in, in, out) is det.
+
+%-----------------------------------------------------------------------------%
+
 	% Construct a mode corresponding to the standard `in',
 	% `out', `uo' or `unused' mode.
 :- pred in_mode((mode)::out) is det.
@@ -193,7 +207,7 @@
 %-----------------------------------------------------------------------------%
 
 :- implementation.
-:- import_module require, int, map, set, std_util, assoc_list.
+:- import_module require, int, map, set, std_util, assoc_list, varset.
 :- import_module prog_util, prog_io, type_util.
 :- import_module inst_match, inst_util, term.
 
@@ -227,27 +241,27 @@
 	% This is just to make error messages and inferred modes
 	% more readable.
 	%
-	( Initial = free, Final = ground(shared, no) ->
+	( Initial = free, Final = ground(shared, none) ->
 		make_std_mode("out", [], Mode)
-	; Initial = free, Final = ground(unique, no) ->
+	; Initial = free, Final = ground(unique, none) ->
 		make_std_mode("uo", [], Mode)
-	; Initial = free, Final = ground(mostly_unique, no) ->
+	; Initial = free, Final = ground(mostly_unique, none) ->
 		make_std_mode("muo", [], Mode)
-	; Initial = ground(shared, no), Final = ground(shared, no) ->
+	; Initial = ground(shared, none), Final = ground(shared, none) ->
 		make_std_mode("in", [], Mode)
-	; Initial = ground(unique, no), Final = ground(clobbered, no) ->
+	; Initial = ground(unique, none), Final = ground(clobbered, none) ->
 		make_std_mode("di", [], Mode)
-	; Initial = ground(mostly_unique, no),
-	  Final = ground(mostly_clobbered, no) ->
+	; Initial = ground(mostly_unique, none),
+	  Final = ground(mostly_clobbered, none) ->
 		make_std_mode("mdi", [], Mode)
-	; Initial = ground(unique, no), Final = ground(unique, no) ->
+	; Initial = ground(unique, none), Final = ground(unique, none) ->
 		make_std_mode("ui", [], Mode)
-	; Initial = ground(mostly_unique, no),
-	  Final = ground(mostly_unique, no) ->
+	; Initial = ground(mostly_unique, none),
+	  Final = ground(mostly_unique, none) ->
 		make_std_mode("mdi", [], Mode)
 	; Initial = free ->
 		make_std_mode("out", [Final], Mode)
-	; Final = ground(clobbered, no) ->
+	; Final = ground(clobbered, none) ->
 		make_std_mode("di", [Initial], Mode)
 	; Initial = Final ->
 		make_std_mode("in", [Initial], Mode)
@@ -352,7 +366,7 @@
 	inst_lookup(ModuleInfo, InstName, Inst),
 	get_single_arg_inst(Inst, ModuleInfo, ConsId, ArgInst).
 get_single_arg_inst(not_reached, _, _, not_reached).
-get_single_arg_inst(ground(Uniq, _PredInst), _, _, ground(Uniq, no)).
+get_single_arg_inst(ground(Uniq, _PredInst), _, _, ground(Uniq, none)).
 get_single_arg_inst(bound(_Uniq, List), _, ConsId, ArgInst) :-
 	( get_single_arg_inst_2(List, ConsId, ArgInst0) ->
 		ArgInst = ArgInst0
@@ -408,7 +422,7 @@
 get_arg_insts(not_reached, _ConsId, Arity, ArgInsts) :-
 	list__duplicate(Arity, not_reached, ArgInsts).
 get_arg_insts(ground(Uniq, _PredInst), _ConsId, Arity, ArgInsts) :-
-	list__duplicate(Arity, ground(Uniq, no), ArgInsts).
+	list__duplicate(Arity, ground(Uniq, none), ArgInsts).
 get_arg_insts(bound(_Uniq, List), ConsId, Arity, ArgInsts) :-
 	( get_arg_insts_2(List, ConsId, ArgInsts0) ->
 		ArgInsts = ArgInsts0
@@ -514,7 +528,7 @@
 	; InstName = typed_ground(Uniq, Type),
 		map__init(Subst),
 		propagate_type_into_inst(Type, Subst, ModuleInfo,
-			ground(Uniq, no), Inst)
+			ground(Uniq, none), Inst)
 	; InstName = typed_inst(Type, TypedInstName),
 		inst_lookup_2(TypedInstName, ModuleInfo, Inst0),
 		map__init(Subst),
@@ -636,19 +650,20 @@
 		% XXX do we need to sort the BoundInsts?
 		Inst = bound(Uniq, BoundInsts)
 	).
-propagate_ctor_info(ground(Uniq, no), Type, Constructors, ModuleInfo, Inst) :-
+propagate_ctor_info(ground(Uniq, none), Type, Constructors, ModuleInfo, Inst)
+		:-
 	( type_is_higher_order(Type, function, _, ArgTypes) ->
 		default_higher_order_func_inst(ArgTypes, ModuleInfo,
 			HigherOrderInstInfo),
-		Inst = ground(Uniq, yes(HigherOrderInstInfo))
+		Inst = ground(Uniq, higher_order(HigherOrderInstInfo))
 	;
 		constructors_to_bound_insts(Constructors, Uniq, ModuleInfo,
 			BoundInsts0),
 		list__sort_and_remove_dups(BoundInsts0, BoundInsts),
 		Inst = bound(Uniq, BoundInsts)
 	).
-propagate_ctor_info(ground(Uniq, yes(PredInstInfo0)), Type, _Ctors, ModuleInfo,
-			ground(Uniq, yes(PredInstInfo))) :-
+propagate_ctor_info(ground(Uniq, higher_order(PredInstInfo0)), Type, _Ctors,
+		ModuleInfo, ground(Uniq, higher_order(PredInstInfo))) :-
 	PredInstInfo0 = pred_inst_info(PredOrFunc, Modes0, Det),
 	PredInstInfo = pred_inst_info(PredOrFunc, Modes, Det),
 	(
@@ -665,6 +680,8 @@
 		Modes = Modes0
 	).
 
+propagate_ctor_info(ground(Uniq, constrained_inst_var(Var)), _, _, _,
+		ground(Uniq, constrained_inst_var(Var))). % AAA
 propagate_ctor_info(not_reached, _Type, _Constructors, _ModuleInfo,
 		not_reached).
 propagate_ctor_info(inst_var(V), _, _, _, inst_var(V)).
@@ -696,12 +713,13 @@
 		% XXX do we need to sort the BoundInsts?
 		Inst = bound(Uniq, BoundInsts)
 	).
-propagate_ctor_info_lazily(ground(Uniq, no), Type0, Subst, ModuleInfo, Inst) :-
+propagate_ctor_info_lazily(ground(Uniq, none), Type0, Subst, ModuleInfo, Inst)
+		:-
 	apply_type_subst(Type0, Subst, Type),
 	( type_is_higher_order(Type, function, _, ArgTypes) ->
 		default_higher_order_func_inst(ArgTypes, ModuleInfo,
 			HigherOrderInstInfo),
-		Inst = ground(Uniq, yes(HigherOrderInstInfo))
+		Inst = ground(Uniq, higher_order(HigherOrderInstInfo))
 	;
 		% XXX The information added by this is not yet used,
 		% so it's disabled since it unnecessarily complicates
@@ -709,11 +727,11 @@
 		/*********
 		Inst = defined_inst(typed_ground(Uniq, Type)) 
 		*********/
-		Inst = ground(Uniq, no)
+		Inst = ground(Uniq, none)
 	).
 
-propagate_ctor_info_lazily(ground(Uniq, yes(PredInstInfo0)), Type0, Subst,
-		ModuleInfo, ground(Uniq, yes(PredInstInfo))) :-
+propagate_ctor_info_lazily(ground(Uniq, higher_order(PredInstInfo0)), Type0,
+		Subst, ModuleInfo, ground(Uniq, higher_order(PredInstInfo))) :-
 	PredInstInfo0 = pred_inst_info(PredOrFunc, Modes0, Det),
 	PredInstInfo = pred_inst_info(PredOrFunc, Modes, Det),
 	apply_type_subst(Type0, Subst, Type),
@@ -730,6 +748,8 @@
 		% be reported if anything tries to match with the inst.
 		Modes = Modes0
 	).
+propagate_ctor_info_lazily(ground(Uniq, constrained_inst_var(Var)), _, _, _,
+		ground(Uniq, constrained_inst_var(Var))). % AAA
 propagate_ctor_info_lazily(not_reached, _Type, _, _ModuleInfo, not_reached).
 propagate_ctor_info_lazily(inst_var(Var), _, _, _, inst_var(Var)).
 propagate_ctor_info_lazily(abstract_inst(Name, Args), _, _, _,
@@ -761,8 +781,8 @@
 :- mode default_higher_order_func_inst(in, in, out) is det.
 
 default_higher_order_func_inst(PredArgTypes, ModuleInfo, PredInstInfo) :-
-	In = (ground(shared, no) -> ground(shared, no)),
-	Out = (free -> ground(shared, no)),
+	In = (ground(shared, none) -> ground(shared, none)),
+	Out = (free -> ground(shared, none)),
 	list__length(PredArgTypes, NumPredArgs),
 	NumFuncArgs is NumPredArgs - 1,
 	list__duplicate(NumFuncArgs, In, FuncArgModes),
@@ -794,7 +814,7 @@
 	% The information added by this is not yet used, so it's disabled 
 	% since it unnecessarily complicates the insts.
 	% Inst = defined_inst(typed_ground(Uniq, Type)), 
-	Inst = ground(Uniq, no),
+	Inst = ground(Uniq, none),
 	ctor_arg_list_to_inst_list(Args, Uniq, Insts).
 
 :- pred propagate_ctor_info_2(list(bound_inst), (type), module_info,
@@ -944,9 +964,7 @@
 	% mode_apply_substitution(Mode0, Subst, Mode) is true iff
 	% Mode is the mode that results from apply Subst to Mode0.
 
-:- type inst_subst == map(inst_param, inst).
-
-:- pred mode_apply_substitution(mode, inst_subst, mode).
+:- pred mode_apply_substitution(mode, inst_var_sub, mode).
 :- mode mode_apply_substitution(in, in, out) is det.
 
 mode_apply_substitution((I0 -> F0), Subst, (I -> F)) :-
@@ -959,9 +977,6 @@
 	% inst_list_apply_substitution(Insts0, Subst, Insts) is true
 	% iff Inst is the inst that results from applying Subst to Insts0.
 
-:- pred inst_list_apply_substitution(list(inst), inst_subst, list(inst)).
-:- mode inst_list_apply_substitution(in, in, out) is det.
-
 inst_list_apply_substitution([], _, []).
 inst_list_apply_substitution([A0 | As0], Subst, [A | As]) :-
 	inst_apply_substitution(A0, Subst, A),
@@ -971,22 +986,22 @@
 	% iff Inst is the inst that results from substituting all
 	% occurrences of Param in Inst0 with Arg.
 
-:- pred inst_apply_substitution(inst, inst_subst, inst).
+:- pred inst_apply_substitution(inst, inst_var_sub, inst).
 :- mode inst_apply_substitution(in, in, out) is det.
 
 inst_apply_substitution(any(Uniq), _, any(Uniq)).
 inst_apply_substitution(free, _, free).
 inst_apply_substitution(free(T), _, free(T)).
-inst_apply_substitution(ground(Uniq, PredStuff0), Subst,
-			ground(Uniq, PredStuff)) :-
-	maybe_pred_inst_apply_substitution(PredStuff0, Subst, PredStuff).
+inst_apply_substitution(ground(Uniq, GroundInstInfo0), Subst,
+			ground(Uniq, GroundInstInfo)) :-
+	ground_inst_info_apply_substitution(GroundInstInfo0, Subst, Uniq,
+		GroundInstInfo).
 inst_apply_substitution(bound(Uniq, Alts0), Subst, bound(Uniq, Alts)) :-
 	alt_list_apply_substitution(Alts0, Subst, Alts).
 inst_apply_substitution(not_reached, _, not_reached).
 inst_apply_substitution(inst_var(Var), Subst, Result) :-
 	(
-		% XXX should params be vars?
-		map__search(Subst, term__variable(Var), Replacement)
+		map__search(Subst, Var, Replacement)
 	->
 		Result = Replacement
 	;
@@ -994,43 +1009,27 @@
 	).
 inst_apply_substitution(defined_inst(InstName0), Subst,
 		    defined_inst(InstName)) :-
-	inst_name_apply_substitution(InstName0, Subst, InstName).
+	( inst_name_apply_substitution(InstName0, Subst, InstName1) ->
+		InstName = InstName1
+	;
+		InstName = InstName0
+	).
 inst_apply_substitution(abstract_inst(Name, Args0), Subst,
 		    abstract_inst(Name, Args)) :-
 	inst_list_apply_substitution(Args0, Subst, Args).
 
-:- pred inst_name_apply_substitution(inst_name, inst_subst, inst_name).
-:- mode inst_name_apply_substitution(in, in, out) is det.
+:- pred inst_name_apply_substitution(inst_name, inst_var_sub, inst_name).
+:- mode inst_name_apply_substitution(in, in, out) is semidet.
 
 inst_name_apply_substitution(user_inst(Name, Args0), Subst,
 		user_inst(Name, Args)) :-
 	inst_list_apply_substitution(Args0, Subst, Args).
-inst_name_apply_substitution(unify_inst(Live, InstA0, InstB0, Real), Subst,
-		unify_inst(Live, InstA, InstB, Real)) :-
-	inst_apply_substitution(InstA0, Subst, InstA),
-	inst_apply_substitution(InstB0, Subst, InstB).
-inst_name_apply_substitution(merge_inst(InstA0, InstB0), Subst,
-		merge_inst(InstA, InstB)) :-
-	inst_apply_substitution(InstA0, Subst, InstA),
-	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)) :-
-	inst_name_apply_substitution(InstName0, Subst, InstName).
-inst_name_apply_substitution(mostly_uniq_inst(InstName0), Subst,
-				mostly_uniq_inst(InstName)) :-
-	inst_name_apply_substitution(InstName0, Subst, InstName).
 inst_name_apply_substitution(typed_inst(T, Inst0), Subst,
 		typed_inst(T, Inst)) :-
 	inst_name_apply_substitution(Inst0, Subst, Inst).
 inst_name_apply_substitution(typed_ground(Uniq, T), _, typed_ground(Uniq, T)).
 
-:- pred alt_list_apply_substitution(list(bound_inst), inst_subst,
+:- pred alt_list_apply_substitution(list(bound_inst), inst_var_sub,
 				list(bound_inst)).
 :- mode alt_list_apply_substitution(in, in, out) is det.
 
@@ -1041,21 +1040,33 @@
 	Alt = functor(Name, Args),
 	alt_list_apply_substitution(Alts0, Subst, Alts).
 
-:- pred maybe_pred_inst_apply_substitution(maybe(pred_inst_info), inst_subst,
-					maybe(pred_inst_info)).
-:- mode maybe_pred_inst_apply_substitution(in, in, out) is det.
-
-maybe_pred_inst_apply_substitution(no, _, no).
-maybe_pred_inst_apply_substitution(yes(pred_inst_info(PredOrFunc, Modes0, Det)),
-			Subst, yes(pred_inst_info(PredOrFunc, Modes, Det))) :-
+:- pred ground_inst_info_apply_substitution(ground_inst_info, inst_var_sub,
+				uniqueness, ground_inst_info).
+:- mode ground_inst_info_apply_substitution(in, in, in, out) is det.
+
+ground_inst_info_apply_substitution(none, _, _, none).
+ground_inst_info_apply_substitution(
+		higher_order(pred_inst_info(PredOrFunc, Modes0, Det)), Subst,
+		_, higher_order(pred_inst_info(PredOrFunc, Modes, Det))) :-
 	mode_list_apply_substitution(Modes0, Subst, Modes).
+ground_inst_info_apply_substitution(constrained_inst_var(Var), Subst, Uniq,
+		Result) :-
+	(
+		map__search(Subst, Var, Replacement)
+	->
+		( Replacement = ground(Uniq, GroundInstInfo) ->
+			Result = GroundInstInfo
+		;
+			error("ground_inst_info_apply_substitution")
+			% AAA
+		)
+	;
+		Result = constrained_inst_var(Var)
+	).
 
 	% mode_list_apply_substitution(Modes0, Subst, Modes) is true
 	% iff Mode is the mode that results from applying Subst to Modes0.
 
-:- pred mode_list_apply_substitution(list(mode), inst_subst, list(mode)).
-:- mode mode_list_apply_substitution(in, in, out) is det.
-
 mode_list_apply_substitution([], _, []).
 mode_list_apply_substitution([A0 | As0], Subst, [A | As]) :-
 	mode_apply_substitution(A0, Subst, A),
@@ -1063,6 +1074,78 @@
 
 %-----------------------------------------------------------------------------%
 
+rename_apart_inst_vars(VarSet, NewVarSet, Modes0, Modes) :-
+	varset__merge_subst(VarSet, NewVarSet, _, Sub),
+	list__map(rename_apart_inst_vars_in_mode(Sub), Modes0, Modes).
+
+:- pred rename_apart_inst_vars_in_mode(substitution(inst_var_type), mode, mode).
+:- mode rename_apart_inst_vars_in_mode(in, in, out) is det.
+
+rename_apart_inst_vars_in_mode(Sub, I0 -> F0, I -> F) :-
+	rename_apart_inst_vars_in_inst(Sub, I0, I),
+	rename_apart_inst_vars_in_inst(Sub, F0, F).
+rename_apart_inst_vars_in_mode(Sub, user_defined_mode(Name, Insts0),
+		user_defined_mode(Name, Insts)) :-
+	list__map(rename_apart_inst_vars_in_inst(Sub), Insts0, Insts).
+
+:- pred rename_apart_inst_vars_in_inst(substitution(inst_var_type), inst, inst).
+:- mode rename_apart_inst_vars_in_inst(in, in, out) is det.
+
+rename_apart_inst_vars_in_inst(_, any(U), any(U)).
+rename_apart_inst_vars_in_inst(_, free, free).
+rename_apart_inst_vars_in_inst(_, free(T), free(T)).
+rename_apart_inst_vars_in_inst(Sub, bound(U, BIs0), bound(U, BIs)) :-
+	list__map((pred(functor(C, Is0)::in, functor(C, Is)::out) is det :-
+		list__map(rename_apart_inst_vars_in_inst(Sub), Is0, Is)),
+		BIs0, BIs).
+rename_apart_inst_vars_in_inst(Sub, ground(U, GI0), ground(U, GI)) :-
+	(
+		GI0 = higher_order(pred_inst_info(PoF, Modes0, Det)),
+		list__map(rename_apart_inst_vars_in_mode(Sub), Modes0, Modes),
+		GI = higher_order(pred_inst_info(PoF, Modes, Det))
+	;
+		GI0 = constrained_inst_var(V0),
+		( map__search(Sub, V0, term__variable(V)) ->
+			GI = constrained_inst_var(V)
+		;
+			GI = GI0
+		)
+	;
+		GI0 = none,
+		GI = none
+	).
+rename_apart_inst_vars_in_inst(_, not_reached, not_reached).
+rename_apart_inst_vars_in_inst(Sub, inst_var(V0), inst_var(V)) :-
+	( map__search(Sub, V0, term__variable(V1)) ->
+		V = V1
+	;
+		V = V0
+	).
+rename_apart_inst_vars_in_inst(Sub, defined_inst(Name0), defined_inst(Name)) :-
+	( rename_apart_inst_vars_in_inst_name(Sub, Name0, Name1) ->
+		Name = Name1
+	;
+		Name = Name0
+	).
+rename_apart_inst_vars_in_inst(Sub, abstract_inst(Sym, Insts0),
+		abstract_inst(Sym, Insts)) :-
+	list__map(rename_apart_inst_vars_in_inst(Sub), Insts0, Insts).
+
+:- pred rename_apart_inst_vars_in_inst_name(substitution(inst_var_type),
+		inst_name, inst_name).
+:- mode rename_apart_inst_vars_in_inst_name(in, in, out) is semidet.
+
+rename_apart_inst_vars_in_inst_name(Sub, user_inst(Sym, Insts0),
+		user_inst(Sym, Insts)) :-
+	list__map(rename_apart_inst_vars_in_inst(Sub), Insts0, Insts).
+rename_apart_inst_vars_in_inst_name(Sub, typed_inst(Type, Name0),
+		typed_inst(Type, Name)) :-
+	rename_apart_inst_vars_in_inst_name(Sub, Name0, Name).
+rename_apart_inst_vars_in_inst_name(_, typed_ground(U, T), typed_ground(U, T)).
+
+
+%-----------------------------------------------------------------------------%
+
 	% In case we later decided to change the representation
 	% of mode_ids.
 
@@ -1085,55 +1168,71 @@
 	{ proc_info_get_initial_instmap(ProcInfo0, ModuleInfo0, InstMap0) },
 	{ proc_info_vartypes(ProcInfo0, VarTypes) },
 	{ proc_info_goal(ProcInfo0, Goal0) },
+	{ proc_info_inst_varset(ProcInfo0, InstVarSet) },
 	recompute_instmap_delta(RecomputeAtomic, Goal0, Goal,
-		VarTypes, InstMap0),
+		VarTypes, InstVarSet, InstMap0),
 	{ proc_info_set_goal(ProcInfo0, Goal, ProcInfo) }.
 
-recompute_instmap_delta(RecomputeAtomic, Goal0, Goal, VarTypes, InstMap0) -->
-	recompute_instmap_delta(RecomputeAtomic, Goal0, Goal, VarTypes,
-		InstMap0, _).
-
-:- pred recompute_instmap_delta(bool, hlds_goal, hlds_goal, vartypes, instmap,
-		instmap_delta, module_info, module_info).
-:- mode recompute_instmap_delta(in, in, out, in, in, out, in, out) is det.
+recompute_instmap_delta(RecomputeAtomic, Goal0, Goal, VarTypes, InstVarSet,
+		InstMap0, ModuleInfo0, ModuleInfo) :-
+	RI0 = recompute_info(ModuleInfo0, InstVarSet),
+	recompute_instmap_delta_1(RecomputeAtomic, Goal0, Goal, VarTypes,
+		InstMap0, _, RI0, RI),
+	ModuleInfo = RI^module_info.
+
+:- pred recompute_instmap_delta_1(bool, hlds_goal, hlds_goal, vartypes,
+	instmap, instmap_delta, recompute_info, recompute_info).
+:- mode recompute_instmap_delta_1(in, in, out, in, in, out, in, out) is det.
 
-recompute_instmap_delta(RecomputeAtomic, Goal0 - GoalInfo0, Goal - GoalInfo,
-		VarTypes, InstMap0, InstMapDelta) -->
+recompute_instmap_delta_1(RecomputeAtomic, Goal0 - GoalInfo0, Goal - GoalInfo,
+		VarTypes, InstMap0, InstMapDelta, RI0, RI) :-
 	( 
-		{ RecomputeAtomic = no },
-		( 
-			{ goal_is_atomic(Goal0) }
-		;
+		RecomputeAtomic = no,
+		goal_is_atomic(Goal0),
+		Goal0 \= unify(_,lambda_goal(_,_,_,_,_,_,_,_),_,_,_)
 			% Lambda expressions always need to be processed.
-			{ Goal0 = unify(_, Rhs, _, _, _) },
-			{ Rhs \= lambda_goal(_, _, _, _, _, _, _, _) }
-		)
 	->
-		{ Goal = Goal0 },
-		{ GoalInfo1 = GoalInfo0 }
-	;
-		recompute_instmap_delta_2(RecomputeAtomic, Goal0,
-			 GoalInfo0, Goal, VarTypes, InstMap0, InstMapDelta0),
-		{ goal_info_get_nonlocals(GoalInfo0, NonLocals) },
-		{ instmap_delta_restrict(InstMapDelta0,
-			NonLocals, InstMapDelta1) },
-		{ goal_info_set_instmap_delta(GoalInfo0,
-			InstMapDelta1, GoalInfo1) }
+		Goal = Goal0,
+		GoalInfo1 = GoalInfo0,
+		RI0 = RI
+	;
+		recompute_instmap_delta_2(RecomputeAtomic, Goal0, GoalInfo0,
+			Goal, VarTypes, InstMap0, InstMapDelta0, RI0, RI),
+		goal_info_get_nonlocals(GoalInfo0, NonLocals),
+		instmap_delta_restrict(InstMapDelta0,
+			NonLocals, InstMapDelta1),
+		goal_info_set_instmap_delta(GoalInfo0,
+			InstMapDelta1, GoalInfo1)
 	),
 
 	% If the initial instmap is unreachable so is the final instmap.
-	( { instmap__is_unreachable(InstMap0) } ->
-		{ instmap_delta_init_unreachable(UnreachableInstMapDelta) },
-		{ goal_info_set_instmap_delta(GoalInfo1,
-			UnreachableInstMapDelta, GoalInfo) }
+	( instmap__is_unreachable(InstMap0) ->
+		instmap_delta_init_unreachable(UnreachableInstMapDelta),
+		goal_info_set_instmap_delta(GoalInfo1,
+			UnreachableInstMapDelta, GoalInfo)
 	;
-		{ GoalInfo = GoalInfo1 }
+		GoalInfo = GoalInfo1
 	),
-	{ goal_info_get_instmap_delta(GoalInfo, InstMapDelta) }.
+	goal_info_get_instmap_delta(GoalInfo, InstMapDelta).
+
+:- type recompute_info
+	--->	recompute_info(
+			module_info :: module_info,
+			inst_varset :: inst_varset
+		).
+
+:- pred lift(pred(T, module_info, module_info), T, recompute_info,
+		recompute_info).
+:- mode lift(pred(out, in, out) is det, out, in, out) is det.
+
+lift(P, R) -->
+	ModuleInfo0 =^ module_info,
+	{ P(R, ModuleInfo0, ModuleInfo) },
+	^module_info := ModuleInfo.
 
 :- pred recompute_instmap_delta_2(bool, hlds_goal_expr, hlds_goal_info,
 		hlds_goal_expr, vartypes, instmap, instmap_delta,
-		module_info, module_info).
+		recompute_info, recompute_info).
 :- mode recompute_instmap_delta_2(in, in, in, out, in, in, out, in, out) is det.
 
 recompute_instmap_delta_2(Atomic, switch(Var, Det, Cases0, SM), GoalInfo,
@@ -1163,37 +1262,41 @@
 recompute_instmap_delta_2(Atomic, not(Goal0), _, not(Goal),
 		VarTypes, InstMap, InstMapDelta) -->
 	{ instmap_delta_init_reachable(InstMapDelta) },
-	recompute_instmap_delta(Atomic, Goal0, Goal, VarTypes, InstMap).
+	recompute_instmap_delta_1(Atomic, Goal0, Goal, VarTypes, InstMap, _).
 
 recompute_instmap_delta_2(Atomic, if_then_else(Vars, A0, B0, C0, SM), GoalInfo,
 		if_then_else(Vars, A, B, C, SM), VarTypes, InstMap0, InstMapDelta) -->
-	recompute_instmap_delta(Atomic, A0, A, VarTypes, InstMap0, InstMapDelta1),
+	recompute_instmap_delta_1(Atomic, A0, A, VarTypes, InstMap0,
+		InstMapDelta1),
 	{ instmap__apply_instmap_delta(InstMap0, InstMapDelta1, InstMap1) },
-	recompute_instmap_delta(Atomic, B0, B, VarTypes, InstMap1, InstMapDelta2),
-	recompute_instmap_delta(Atomic, C0, C, VarTypes, InstMap0, InstMapDelta3),
+	recompute_instmap_delta_1(Atomic, B0, B, VarTypes, InstMap1,
+		InstMapDelta2),
+	recompute_instmap_delta_1(Atomic, C0, C, VarTypes, InstMap0,
+		InstMapDelta3),
 	{ instmap_delta_apply_instmap_delta(InstMapDelta1, InstMapDelta2,
 		InstMapDelta4) },
 	{ goal_info_get_nonlocals(GoalInfo, NonLocals) },
-	merge_instmap_delta(InstMap0, NonLocals, InstMapDelta3,
-		InstMapDelta4, InstMapDelta).
+	lift(merge_instmap_delta(InstMap0, NonLocals, InstMapDelta3,
+		InstMapDelta4), InstMapDelta).
 
 recompute_instmap_delta_2(Atomic, some(Vars, CanRemove, Goal0), _,
 		some(Vars, CanRemove, Goal),
 		VarTypes, InstMap, InstMapDelta) -->
-	recompute_instmap_delta(Atomic, Goal0, Goal, VarTypes, InstMap, InstMapDelta).
+	recompute_instmap_delta_1(Atomic, Goal0, Goal, VarTypes, InstMap,
+		InstMapDelta).
 
 recompute_instmap_delta_2(_, generic_call(A, Vars, Modes, D), _,
 		generic_call(A, Vars, Modes, D),
 		_VarTypes, _InstMap, InstMapDelta) -->
-	=(ModuleInfo),
+	ModuleInfo =^ module_info,
 	{ instmap_delta_from_mode_list(Vars, Modes,
 		ModuleInfo, InstMapDelta) }.
 
 recompute_instmap_delta_2(_, call(PredId, ProcId, Args, D, E, F), _,
-		call(PredId, ProcId, Args, D, E, F), _VarTypes,
+		call(PredId, ProcId, Args, D, E, F), VarTypes,
 		InstMap, InstMapDelta) -->
 	recompute_instmap_delta_call(PredId, ProcId,
-		Args, InstMap, InstMapDelta).
+		Args, VarTypes, InstMap, InstMapDelta).
 
 recompute_instmap_delta_2(Atomic, unify(A, Rhs0, UniMode0, Uni, E), GoalInfo, 
 		unify(A, Rhs, UniMode, Uni, E), VarTypes, InstMap0,
@@ -1202,10 +1305,11 @@
 		{ Rhs0 = lambda_goal(PorF, EvalMethod, FixModes, NonLocals,
 			LambdaVars, Modes, Det, Goal0) }
 	->
-		=(ModuleInfo0),
+		ModuleInfo0 =^ module_info,
 		{ instmap__pre_lambda_update(ModuleInfo0, LambdaVars, Modes,
 			InstMap0, InstMap) },
-		recompute_instmap_delta(Atomic, Goal0, Goal, VarTypes, InstMap),
+		recompute_instmap_delta_1(Atomic, Goal0, Goal, VarTypes,
+			InstMap, _),
 		{ Rhs = lambda_goal(PorF, EvalMethod, FixModes, NonLocals,
 			LambdaVars, Modes, Det, Goal) }
 	;
@@ -1221,9 +1325,9 @@
 
 recompute_instmap_delta_2(_, pragma_c_code(A, PredId, ProcId, Args, E, F,
 		G), _, pragma_c_code(A, PredId, ProcId, Args, E, F, G),
-		_VarTypes, InstMap, InstMapDelta) -->
+		VarTypes, InstMap, InstMapDelta) -->
 	recompute_instmap_delta_call(PredId, ProcId,
-		Args, InstMap, InstMapDelta).
+		Args, VarTypes, InstMap, InstMapDelta).
 
 recompute_instmap_delta_2(_, bi_implication(_, _), _, _, _, _, _) -->
 	% these should have been expanded out by now
@@ -1232,14 +1336,14 @@
 %-----------------------------------------------------------------------------%
 
 :- pred recompute_instmap_delta_conj(bool, list(hlds_goal), list(hlds_goal),
-		vartypes, instmap, instmap_delta, module_info, module_info).
+	vartypes, instmap, instmap_delta, recompute_info, recompute_info).
 :- mode recompute_instmap_delta_conj(in, in, out, in, in, out, in, out) is det.
 
 recompute_instmap_delta_conj(_, [], [], _VarTypes, _InstMap, InstMapDelta) -->
 	{ instmap_delta_init_reachable(InstMapDelta) }.
 recompute_instmap_delta_conj(Atomic, [Goal0 | Goals0], [Goal | Goals],
 		VarTypes, InstMap0, InstMapDelta) -->
-	recompute_instmap_delta(Atomic, Goal0, Goal,
+	recompute_instmap_delta_1(Atomic, Goal0, Goal,
 		VarTypes, InstMap0, InstMapDelta0),
 	{ instmap__apply_instmap_delta(InstMap0, InstMapDelta0, InstMap1) },
 	recompute_instmap_delta_conj(Atomic, Goals0, Goals,
@@ -1251,7 +1355,7 @@
 
 :- pred recompute_instmap_delta_disj(bool, list(hlds_goal), list(hlds_goal),
 		vartypes, instmap, set(prog_var), instmap_delta,
-		module_info, module_info).
+		recompute_info, recompute_info).
 :- mode recompute_instmap_delta_disj(in, in, out, in, in, in, out, in, out)
 		is det.
 
@@ -1259,21 +1363,21 @@
 	{ instmap_delta_init_unreachable(InstMapDelta) }.
 recompute_instmap_delta_disj(Atomic, [Goal0], [Goal],
 		VarTypes, InstMap, _, InstMapDelta) -->
-	recompute_instmap_delta(Atomic, Goal0, Goal, VarTypes, InstMap,
+	recompute_instmap_delta_1(Atomic, Goal0, Goal, VarTypes, InstMap,
 		InstMapDelta).
 recompute_instmap_delta_disj(Atomic, [Goal0 | Goals0], [Goal | Goals],
 		VarTypes, InstMap, NonLocals, InstMapDelta) -->
 	{ Goals0 = [_|_] },
-	recompute_instmap_delta(Atomic, Goal0, Goal,
+	recompute_instmap_delta_1(Atomic, Goal0, Goal,
 		VarTypes, InstMap, InstMapDelta0),
 	recompute_instmap_delta_disj(Atomic, Goals0, Goals,
 		VarTypes, InstMap, NonLocals, InstMapDelta1),
-	merge_instmap_delta(InstMap, NonLocals, InstMapDelta0,
-		InstMapDelta1, InstMapDelta).
+	lift(merge_instmap_delta(InstMap, NonLocals, InstMapDelta0,
+		InstMapDelta1), InstMapDelta).
 
 :- pred recompute_instmap_delta_par_conj(bool, list(hlds_goal),
 		list(hlds_goal), vartypes, instmap, set(prog_var),
-		instmap_delta, module_info, module_info).
+		instmap_delta, recompute_info, recompute_info).
 :- mode recompute_instmap_delta_par_conj(in, in, out, in, in, in, out,
 		in, out) is det.
 
@@ -1281,23 +1385,23 @@
 	{ instmap_delta_init_unreachable(InstMapDelta) }.
 recompute_instmap_delta_par_conj(Atomic, [Goal0], [Goal],
 		VarTypes, InstMap, _, InstMapDelta) -->
-	recompute_instmap_delta(Atomic, Goal0, Goal, VarTypes, InstMap,
+	recompute_instmap_delta_1(Atomic, Goal0, Goal, VarTypes, InstMap,
 		InstMapDelta).
 recompute_instmap_delta_par_conj(Atomic, [Goal0 | Goals0], [Goal | Goals],
 		VarTypes, InstMap, NonLocals, InstMapDelta) -->
 	{ Goals0 = [_|_] },
-	recompute_instmap_delta(Atomic, Goal0, Goal,
+	recompute_instmap_delta_1(Atomic, Goal0, Goal,
 		VarTypes, InstMap, InstMapDelta0),
 	recompute_instmap_delta_par_conj(Atomic, Goals0, Goals,
 		VarTypes, InstMap, NonLocals, InstMapDelta1),
-	unify_instmap_delta(InstMap, NonLocals, InstMapDelta0,
-		InstMapDelta1, InstMapDelta).
+	lift(unify_instmap_delta(InstMap, NonLocals, InstMapDelta0,
+		InstMapDelta1), InstMapDelta).
 
 %-----------------------------------------------------------------------------%
 
 :- pred recompute_instmap_delta_cases(bool, prog_var, list(case), list(case),
 		vartypes, instmap, set(prog_var), instmap_delta,
-		module_info, module_info).
+		recompute_info, recompute_info).
 :- mode recompute_instmap_delta_cases(in, in, in, out,
 		in, in, in, out, in, out) is det.
 
@@ -1307,39 +1411,85 @@
 		VarTypes, InstMap0, NonLocals, InstMapDelta) -->
 	{ Case0 = case(Functor, Goal0) },
 	{ map__lookup(VarTypes, Var, Type) },
-	instmap__bind_var_to_functor(Var, Type, Functor, InstMap0, InstMap),
-	recompute_instmap_delta(Atomic, Goal0, Goal, VarTypes, InstMap,
+	lift(instmap__bind_var_to_functor(Var, Type, Functor, InstMap0),
+		InstMap),
+	recompute_instmap_delta_1(Atomic, Goal0, Goal, VarTypes, InstMap,
 		InstMapDelta0),
-	instmap_delta_bind_var_to_functor(Var, Type, Functor,
-		InstMap0, InstMapDelta0, InstMapDelta1),
+	lift(instmap_delta_bind_var_to_functor(Var, Type, Functor,
+		InstMap0, InstMapDelta0), InstMapDelta1),
 	{ Case = case(Functor, Goal) },
 	recompute_instmap_delta_cases(Atomic, Var, Cases0, Cases,
 		VarTypes, InstMap0, NonLocals, InstMapDelta2),
-	merge_instmap_delta(InstMap0, NonLocals, InstMapDelta1,
-		InstMapDelta2, InstMapDelta).
+	lift(merge_instmap_delta(InstMap0, NonLocals, InstMapDelta1,
+		InstMapDelta2), InstMapDelta).
 
 %-----------------------------------------------------------------------------%
 
 :- pred recompute_instmap_delta_call(pred_id, proc_id,
-		list(prog_var), instmap, instmap_delta,
-		module_info, module_info).
-:- mode recompute_instmap_delta_call(in, in, in, in, out, in, out) is det.
-
-recompute_instmap_delta_call(PredId, ProcId, Args, InstMap,
-		InstMapDelta, ModuleInfo0, ModuleInfo) :-
-	module_info_pred_proc_info(ModuleInfo0, PredId, ProcId, _, ProcInfo),
-	proc_info_interface_determinism(ProcInfo, Detism),
-	( determinism_components(Detism, _, at_most_zero) ->
-		instmap_delta_init_unreachable(InstMapDelta),
-		ModuleInfo = ModuleInfo0
-	;
-		proc_info_argmodes(ProcInfo, ArgModes0),
-		recompute_instmap_delta_call_2(Args, InstMap,
-			ArgModes0, ArgModes, ModuleInfo0, ModuleInfo),
-		instmap_delta_from_mode_list(Args, ArgModes,
-			ModuleInfo, InstMapDelta)
-	).
+		list(prog_var), vartypes, instmap, instmap_delta,
+		recompute_info, recompute_info).
+:- mode recompute_instmap_delta_call(in, in, in, in, in, out, in, out) is det.
 
+recompute_instmap_delta_call(PredId, ProcId, Args, VarTypes, InstMap,
+		InstMapDelta) -->
+	ModuleInfo =^ module_info,
+	{ module_info_pred_proc_info(ModuleInfo, PredId, ProcId, _, ProcInfo) },
+	{ proc_info_interface_determinism(ProcInfo, Detism) },
+	( { determinism_components(Detism, _, at_most_zero) } ->
+		{ instmap_delta_init_unreachable(InstMapDelta) }
+	;
+		{ proc_info_argmodes(ProcInfo, ArgModes0) },
+		{ proc_info_inst_varset(ProcInfo, ProcInstVarSet) },
+		InstVarSet =^ inst_varset,
+		{ rename_apart_inst_vars(InstVarSet, ProcInstVarSet,
+			ArgModes0, ArgModes1) },
+		{ mode_list_get_initial_insts(ArgModes1, ModuleInfo,
+			InitialInsts) },
+		{ map__init(InstVarSub0) },
+		lift(recompute_instmap_delta_call_1(Args, VarTypes, InstMap,
+			InitialInsts, InstVarSub0), InstVarSub),
+
+		{ mode_list_apply_substitution(ArgModes1, InstVarSub,
+			ArgModes2) },
+		lift(recompute_instmap_delta_call_2(Args, InstMap,
+			ArgModes2), ArgModes),
+		{ instmap_delta_from_mode_list(Args, ArgModes,
+			ModuleInfo, InstMapDelta) }
+	).
+
+:- pred recompute_instmap_delta_call_1(list(prog_var), vartypes, instmap,
+	list(inst), inst_var_sub, inst_var_sub, module_info, module_info).
+:- mode recompute_instmap_delta_call_1(in, in, in, in, in, out, in, out) is det.
+
+recompute_instmap_delta_call_1([], _, _, [], Sub, Sub, ModuleInfo, ModuleInfo).
+recompute_instmap_delta_call_1([_|_], _, _, [], _, _, _, _) :-
+	error("recompute_instmap_delta_call_1").
+recompute_instmap_delta_call_1([], _, _, [_|_], _, _, _, _) :-
+	error("recompute_instmap_delta_call_1").
+recompute_instmap_delta_call_1([Arg | Args], VarTypes, InstMap, [Inst | Insts],
+		Sub0, Sub, ModuleInfo0, ModuleInfo) :-
+	% This is similar to modecheck_var_has_inst.
+	( instmap__is_reachable(InstMap) ->
+		instmap__lookup_var(InstMap, Arg, ArgInst),
+		map__lookup(VarTypes, Arg, Type),
+		(
+			inst_matches_initial(ArgInst, Inst, Type, ModuleInfo0,
+				ModuleInfo1, Sub0, Sub1)
+		->
+			ModuleInfo2 = ModuleInfo1,
+			Sub2 = Sub1
+		;
+			% AAA error("recompute_instmap_delta_call_1: inst_matches_initial failed")
+			ModuleInfo2 = ModuleInfo0,
+			Sub2 = Sub0
+		)
+	;
+		ModuleInfo2 = ModuleInfo0,
+		Sub2 = Sub0
+	),
+	recompute_instmap_delta_call_1(Args, VarTypes, InstMap, Insts, Sub2,
+		Sub, ModuleInfo2, ModuleInfo).
+
 :- pred recompute_instmap_delta_call_2(list(prog_var), instmap, list(mode),
 		list(mode), module_info, module_info).
 :- mode recompute_instmap_delta_call_2(in, in, in, out, in, out) is det.
@@ -1373,16 +1523,16 @@
 		Modes0, Modes, ModuleInfo2, ModuleInfo).
 
 :- pred recompute_instmap_delta_unify(unification, unify_mode, unify_mode,
-	hlds_goal_info, instmap, instmap_delta, module_info, module_info).
-:- mode recompute_instmap_delta_unify(in, in, out,
-	in, in, out, in, out) is det.
+	hlds_goal_info, instmap, instmap_delta, recompute_info, recompute_info).
+:- mode recompute_instmap_delta_unify(in, in, out, in, in, out, in, out) is det.
 
 recompute_instmap_delta_unify(Uni, UniMode0, UniMode, GoalInfo,
-		InstMap, InstMapDelta, ModuleInfo, ModuleInfo) :-
+		InstMap, InstMapDelta) -->
 	% Deconstructions are the only types of unifications
 	% that can require updating of the instmap_delta after simplify.m
 	% has been run.
-	(
+	ModuleInfo =^ module_info,
+	{
 		Uni = deconstruct(Var, _ConsId, Vars, UniModes, _)
 	->
 		% Get the final inst of the deconstructed var, which
@@ -1409,7 +1559,7 @@
 	;	
 		goal_info_get_instmap_delta(GoalInfo, InstMapDelta),
 		UniMode = UniMode0
-	).
+	}.
 
 %-----------------------------------------------------------------------------%
 
@@ -1480,8 +1630,8 @@
 strip_builtin_qualifiers_from_inst(free, free).
 strip_builtin_qualifiers_from_inst(free(Type), free(Type)).
 strip_builtin_qualifiers_from_inst(any(Uniq), any(Uniq)).
-strip_builtin_qualifiers_from_inst(ground(Uniq, Pred0), ground(Uniq, Pred)) :-
-	strip_builtin_qualifiers_from_pred_inst(Pred0, Pred).
+strip_builtin_qualifiers_from_inst(ground(Uniq, GII0), ground(Uniq, GII)) :-
+	strip_builtin_qualifiers_from_ground_inst_info(GII0, GII).
 strip_builtin_qualifiers_from_inst(bound(Uniq, BoundInsts0),
 					bound(Uniq, BoundInsts)) :-
 	strip_builtin_qualifiers_from_bound_inst_list(BoundInsts0, BoundInsts).
@@ -1519,20 +1669,23 @@
 		strip_builtin_qualifiers_from_inst_name(InstName1, Inst0, Inst)
 	; InstName0 = typed_ground(Uniq, _Type) ->
 		% Don't output the $typed_ground in error messages.
-		Inst = ground(Uniq, no)
+		Inst = ground(Uniq, none)
 	;
 		% for the compiler-generated insts, don't bother.
 		Inst = Inst0
 	).
 
-:- pred strip_builtin_qualifiers_from_pred_inst(maybe(pred_inst_info)::in,
-					maybe(pred_inst_info)::out) is det.
+:- pred strip_builtin_qualifiers_from_ground_inst_info( ground_inst_info::in,
+		ground_inst_info::out) is det.
 
-strip_builtin_qualifiers_from_pred_inst(no, no).
-strip_builtin_qualifiers_from_pred_inst(yes(Pred0), yes(Pred)) :-
+strip_builtin_qualifiers_from_ground_inst_info(none, none).
+strip_builtin_qualifiers_from_ground_inst_info(higher_order(Pred0),
+		higher_order(Pred)) :-
 	Pred0 = pred_inst_info(Uniq, Modes0, Det),
 	Pred = pred_inst_info(Uniq, Modes, Det),
 	strip_builtin_qualifiers_from_mode_list(Modes0, Modes).
+strip_builtin_qualifiers_from_ground_inst_info(constrained_inst_var(Var),
+		constrained_inst_var(Var)).
 
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
@@ -1562,7 +1715,7 @@
 			% in the number of inferred modes without any benefit
 			\+ is_introduced_type_info_type(Type)
 		->
-			NormalisedInst = ground(unique, no)
+			NormalisedInst = ground(unique, none)
 		;
 			inst_is_ground(ModuleInfo, Inst),
 			inst_is_mostly_unique(ModuleInfo, Inst),
@@ -1571,12 +1724,12 @@
 			% in the number of inferred modes without any benefit
 			\+ is_introduced_type_info_type(Type)
 		->
-			NormalisedInst = ground(mostly_unique, no)
+			NormalisedInst = ground(mostly_unique, none)
 		;
 			inst_is_ground(ModuleInfo, Inst),
 			\+ inst_is_clobbered(ModuleInfo, Inst)
 		->
-			NormalisedInst = ground(shared, no)
+			NormalisedInst = ground(shared, none)
 		;
 			% XXX need to limit the potential size of insts
 			% here in order to avoid infinite loops in
Index: compiler/modecheck_call.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/modecheck_call.m,v
retrieving revision 1.35
diff -u -r1.35 modecheck_call.m
--- compiler/modecheck_call.m	2000/01/13 06:16:32	1.35
+++ compiler/modecheck_call.m	2000/02/04 00:04:23
@@ -73,7 +73,7 @@
 :- import_module mode_info, mode_debug, modes, mode_util, mode_errors.
 :- import_module clause_to_proc, inst_match.
 :- import_module det_report, unify_proc.
-:- import_module int, map, bool, set, require.
+:- import_module int, map, bool, set, require, term, varset.
 
 modecheck_higher_order_call(PredOrFunc, PredVar, Args0, Modes, Det,
 		Args, ExtraGoals, ModeInfo0, ModeInfo) :-
@@ -87,7 +87,7 @@
 	inst_expand(ModuleInfo0, PredVarInst0, PredVarInst),
 	list__length(Args0, Arity),
 	(
-		PredVarInst = ground(_Uniq, yes(PredInstInfo)),
+		PredVarInst = ground(_Uniq, higher_order(PredInstInfo)),
 		PredInstInfo = pred_inst_info(PredOrFunc, Modes0, Det0),
 		list__length(Modes0, Arity)
 	->
@@ -169,8 +169,9 @@
 	%
 	mode_list_get_initial_insts(Modes, ModuleInfo0, InitialInsts),
 	modecheck_var_has_inst_list(Args0, InitialInsts, ArgOffset,
-				ModeInfo1, ModeInfo2),
-	mode_list_get_final_insts(Modes, ModuleInfo0, FinalInsts),
+		InstVarSub, ModeInfo1, ModeInfo2),
+	mode_list_get_final_insts(Modes, ModuleInfo0, FinalInsts0),
+	inst_list_apply_substitution(FinalInsts0, InstVarSub, FinalInsts),
 	modecheck_set_var_inst_list(Args0, InitialInsts, FinalInsts,
 		ArgOffset, Args, ExtraGoals, ModeInfo2, ModeInfo).
 
@@ -234,14 +235,19 @@
 		% initial insts, and set their new final insts (introducing
 		% extra unifications for implied modes, if necessary).
 		%
-		proc_info_argmodes(ProcInfo, ProcArgModes),
+		proc_info_argmodes(ProcInfo, ProcArgModes0),
+		proc_info_inst_varset(ProcInfo, ProcInstVarSet),
+		mode_info_get_instvarset(ModeInfo1, InstVarSet),
+		rename_apart_inst_vars(InstVarSet, ProcInstVarSet,
+			ProcArgModes0, ProcArgModes),
 		mode_list_get_initial_insts(ProcArgModes, ModuleInfo,
 					InitialInsts),
 		modecheck_var_has_inst_list(ArgVars0, InitialInsts, ArgOffset,
-					ModeInfo1, ModeInfo2),
+					InstVarSub, ModeInfo1, ModeInfo2),
 
-		modecheck_end_of_call(ProcInfo, ArgVars0, ArgOffset, ArgVars,
-					ExtraGoals, ModeInfo2, ModeInfo)
+		modecheck_end_of_call(ProcInfo, ProcArgModes, ArgVars0,
+			ArgOffset, InstVarSub, ArgVars, ExtraGoals, ModeInfo2,
+			ModeInfo)
 	;
 			% set the current error list to empty (and
 			% save the old one in `OldErrors').  This is so the
@@ -265,10 +271,12 @@
 			RevMatchingProcIds = [_|_],
 			list__reverse(RevMatchingProcIds, MatchingProcIds),
 			choose_best_match(MatchingProcIds, PredId, Procs,
-				ArgVars0, TheProcId, ModeInfo2),
+				ArgVars0, TheProcId, InstVarSub, ProcArgModes,
+				ModeInfo2),
 			map__lookup(Procs, TheProcId, ProcInfo),
-			modecheck_end_of_call(ProcInfo, ArgVars0, ArgOffset,
-				ArgVars, ExtraGoals, ModeInfo2, ModeInfo3)
+			modecheck_end_of_call(ProcInfo, ProcArgModes, ArgVars0,
+				ArgOffset, InstVarSub, ArgVars, ExtraGoals,
+				ModeInfo2, ModeInfo3)
 		),
 
 			% restore the error list, appending any new error(s)
@@ -277,6 +285,8 @@
 		mode_info_set_errors(Errors, ModeInfo3, ModeInfo)
 	).
 
+%--------------------------------------------------------------------------%
+
 :- pred no_matching_modes(pred_id, list(prog_var), maybe(determinism),
 		set(prog_var), proc_id, mode_info, mode_info).
 :- mode no_matching_modes(in, in, in, in, out, mode_info_di, mode_info_uo)
@@ -311,11 +321,12 @@
 			mode_error_no_matching_mode(ArgVars, ArgInsts),
 			ModeInfo1, ModeInfo)
 	).
+
+:- type proc_mode ---> proc_mode(proc_id, inst_var_sub, list(mode)).
 
-:- pred modecheck_find_matching_modes(
-		list(proc_id), pred_id, proc_table, list(prog_var),
-		list(proc_id), list(proc_id), set(prog_var), set(prog_var),
-		mode_info, mode_info).
+:- pred modecheck_find_matching_modes(list(proc_id), pred_id, proc_table,
+		list(prog_var), list(proc_mode), list(proc_mode), set(prog_var),
+		set(prog_var), mode_info, mode_info).
 :- mode modecheck_find_matching_modes(in, in, in, in,
 			in, out, in, out, mode_info_di, mode_info_uo) is det.
 
@@ -330,7 +341,11 @@
 		% find the initial insts and the final livenesses
 		% of the arguments for this mode of the called pred
 	map__lookup(Procs, ProcId, ProcInfo),
-	proc_info_argmodes(ProcInfo, ProcArgModes),
+	proc_info_argmodes(ProcInfo, ProcArgModes0),
+	proc_info_inst_varset(ProcInfo, ProcInstVarSet),
+	mode_info_get_instvarset(ModeInfo0, InstVarSet),
+	rename_apart_inst_vars(InstVarSet, ProcInstVarSet, ProcArgModes0,
+		ProcArgModes),
 	mode_info_get_module_info(ModeInfo0, ModuleInfo),
 	proc_info_arglives(ProcInfo, ModuleInfo, ProcArgLives0),
 
@@ -343,7 +358,7 @@
 		% initial insts
 	mode_list_get_initial_insts(ProcArgModes, ModuleInfo, InitialInsts),
 	modecheck_var_has_inst_list(ArgVars0, InitialInsts, 0,
-				ModeInfo1, ModeInfo2),
+				InstVarSub, ModeInfo1, ModeInfo2),
 
 		% If we got an error, reset the error list
 		% and save the list of vars to wait on.
@@ -358,7 +373,8 @@
 		FirstError = mode_error_info(ErrorWaitingVars, _, _, _),
 		set__union(WaitingVars0, ErrorWaitingVars, WaitingVars1)
 	;
-		MatchingProcIds1 = [ProcId | MatchingProcIds0],
+		MatchingProcIds1 = [proc_mode(ProcId, InstVarSub, ProcArgModes)
+					| MatchingProcIds0],
 		ModeInfo3 = ModeInfo2,
 		WaitingVars1 = WaitingVars0
 	),
@@ -368,17 +384,18 @@
 			MatchingProcIds1, MatchingProcIds,
 			WaitingVars1, WaitingVars, ModeInfo3, ModeInfo).
 
-:- pred modecheck_end_of_call(proc_info, list(prog_var), int,
-		list(prog_var), extra_goals, mode_info, mode_info).
-:- mode modecheck_end_of_call(in, in, in, out, out,
+:- pred modecheck_end_of_call(proc_info, list(mode), list(prog_var), int,
+	inst_var_sub, list(prog_var), extra_goals, mode_info, mode_info).
+:- mode modecheck_end_of_call(in, in, in, in, in, out, out,
 				mode_info_di, mode_info_uo) is det.
 
-modecheck_end_of_call(ProcInfo, ArgVars0, ArgOffset,
+modecheck_end_of_call(ProcInfo, ProcArgModes, ArgVars0, ArgOffset, InstVarSub,
 			ArgVars, ExtraGoals, ModeInfo0, ModeInfo) :-
-	proc_info_argmodes(ProcInfo, ProcArgModes),
 	mode_info_get_module_info(ModeInfo0, ModuleInfo),
-	mode_list_get_initial_insts(ProcArgModes, ModuleInfo, InitialInsts),
-	mode_list_get_final_insts(ProcArgModes, ModuleInfo, FinalInsts),
+	mode_list_get_initial_insts(ProcArgModes, ModuleInfo, InitialInsts0),
+	inst_list_apply_substitution(InitialInsts0, InstVarSub, InitialInsts),
+	mode_list_get_final_insts(ProcArgModes, ModuleInfo, FinalInsts0),
+	inst_list_apply_substitution(FinalInsts0, InstVarSub, FinalInsts),
 	modecheck_set_var_inst_list(ArgVars0, InitialInsts, FinalInsts,
 			ArgOffset, ArgVars, ExtraGoals, ModeInfo0, ModeInfo1),
 	proc_info_never_succeeds(ProcInfo, NeverSucceeds),
@@ -410,14 +427,15 @@
 	list__length(ArgVars, Arity),
 	list__duplicate(Arity, not_reached, FinalInsts),
 	inst_lists_to_mode_list(InitialInsts, FinalInsts, Modes),
+	mode_info_get_instvarset(ModeInfo0, InstVarSet),
 
 	%
 	% call unify_proc__request_proc, which will
 	% create the new procedure, set its "can-process" flag to `no',
 	% and insert it into the queue of requested procedures.
 	%
-	unify_proc__request_proc(PredId, Modes, yes(ArgLives), MaybeDet,
-		Context, ModuleInfo0, ProcId, ModuleInfo),
+	unify_proc__request_proc(PredId, Modes, InstVarSet, yes(ArgLives),
+		MaybeDet, Context, ModuleInfo0, ProcId, ModuleInfo),
 
 	mode_info_set_module_info(ModeInfo0, ModuleInfo, ModeInfo1),
 
@@ -488,8 +506,9 @@
 	mode_list_get_initial_insts(ProcArgModes, ModuleInfo, InitialInsts),
 	mode_list_get_initial_insts(OtherProcArgModes, ModuleInfo,
 							OtherInitialInsts),
+	pred_info_arg_types(PredInfo, ArgTypes),
 	compare_inst_list(InitialInsts, OtherInitialInsts, no,
-		CompareInsts, ModuleInfo),
+		ArgTypes, CompareInsts, ModuleInfo),
 	CompareInsts = same,
 
 	%
@@ -536,8 +555,9 @@
 	mode_list_get_initial_insts(ProcArgModes, ModuleInfo, InitialInsts),
 	mode_list_get_initial_insts(OtherProcArgModes, ModuleInfo,
 							OtherInitialInsts),
+	pred_info_arg_types(PredInfo, ArgTypes),
 	compare_inst_list(InitialInsts, OtherInitialInsts, no,
-		CompareInitialInsts, ModuleInfo),
+		ArgTypes, CompareInitialInsts, ModuleInfo),
 	CompareInitialInsts = same,
 
 	%
@@ -547,7 +567,7 @@
 	mode_list_get_final_insts(OtherProcArgModes, ModuleInfo,
 							OtherFinalInsts),
 	compare_inst_list(FinalInsts, OtherFinalInsts, no,
-		CompareFinalInsts, ModuleInfo),
+		ArgTypes, CompareFinalInsts, ModuleInfo),
 	CompareFinalInsts = same,
 
 	%
@@ -611,29 +631,32 @@
 	;	same
 	;	incomparable.
 
-:- pred choose_best_match(list(proc_id), pred_id, proc_table, list(prog_var),
-				proc_id, mode_info).
-:- mode choose_best_match(in, in, in, in, out,
-				mode_info_ui) is det.
+:- pred choose_best_match(list(proc_mode), pred_id,
+		proc_table, list(prog_var), proc_id, inst_var_sub, list(mode),
+		mode_info).
+:- mode choose_best_match(in, in, in, in, out, out, out, mode_info_ui) is det.
 
-choose_best_match([], _, _, _, _, _) :-
+choose_best_match([], _, _, _, _, _, _, _) :-
 	error("choose_best_match: no best match").
-choose_best_match([ProcId | ProcIds], PredId, Procs, ArgVars, TheProcId,
-			ModeInfo) :-
+choose_best_match([proc_mode(ProcId, InstVarSub, ArgModes) | ProcIds], PredId,
+		Procs, ArgVars, TheProcId, TheInstVarSub, TheArgModes,
+		ModeInfo) :-
 	%
 	% This ProcId is best iff there is no other proc_id which is better.
 	%
 	(
 		\+ (
-			list__member(OtherProcId, ProcIds),
+			list__member(proc_mode(OtherProcId, _, _), ProcIds),
 			compare_proc(OtherProcId, ProcId, ArgVars, better,
 					Procs, ModeInfo)
 		)
 	->
-		TheProcId = ProcId
+		TheProcId = ProcId,
+		TheInstVarSub = InstVarSub,
+		TheArgModes = ArgModes
 	;
 		choose_best_match(ProcIds, PredId, Procs, ArgVars, TheProcId,
-				ModeInfo)
+			TheInstVarSub, TheArgModes, ModeInfo)
 	).
 
 	%
@@ -658,12 +681,14 @@
 	proc_info_argmodes(ProcInfo, ProcArgModes),
 	proc_info_argmodes(OtherProcInfo, OtherProcArgModes),
 	mode_info_get_module_info(ModeInfo, ModuleInfo),
+	mode_info_get_var_types(ModeInfo, VarTypes),
+	list__map(map__lookup(VarTypes), ArgVars, ArgTypes),
 	mode_list_get_initial_insts(ProcArgModes, ModuleInfo, InitialInsts),
 	mode_list_get_initial_insts(OtherProcArgModes, ModuleInfo,
 							OtherInitialInsts),
 	get_var_insts_and_lives(ArgVars, ModeInfo, ArgInitialInsts, _ArgLives),
 	compare_inst_list(InitialInsts, OtherInitialInsts, yes(ArgInitialInsts),
-		CompareInsts, ModuleInfo),
+		ArgTypes, CompareInsts, ModuleInfo),
 	%
 	% Compare the expected livenesses of the arguments
 	%
@@ -687,31 +712,35 @@
 	combine_results(CompareInsts, CompareLives, Compare0),
 	prioritized_combine_results(Compare0, CompareDet, Compare).
 
-:- pred compare_inst_list(list(inst), list(inst), maybe(list(inst)), match,
-				module_info).
-:- mode compare_inst_list(in, in, in, out, in) is det.
+:- pred compare_inst_list(list(inst), list(inst), maybe(list(inst)),
+		list(type), match, module_info).
+:- mode compare_inst_list(in, in, in, in, out, in) is det.
 
-compare_inst_list(InstsA, InstsB, ArgInsts, Result, ModuleInfo) :-
-	( compare_inst_list_2(InstsA, InstsB, ArgInsts, Result0, ModuleInfo) ->
+compare_inst_list(InstsA, InstsB, ArgInsts, Types, Result, ModuleInfo) :-
+	(
+		compare_inst_list_2(InstsA, InstsB, ArgInsts, Types, Result0,
+			ModuleInfo)
+	->
 		Result = Result0
 	;
 		error("compare_inst_list: length mis-match")
 	).
 
-:- pred compare_inst_list_2(list(inst), list(inst), maybe(list(inst)), match,
-				module_info).
-:- mode compare_inst_list_2(in, in, in, out, in) is semidet.
+:- pred compare_inst_list_2(list(inst), list(inst), maybe(list(inst)),
+		list(type), match, module_info).
+:- mode compare_inst_list_2(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, Result, ModuleInfo) :-
-	compare_inst(InstA, InstB, no, Result0, ModuleInfo),
-	compare_inst_list_2(InstsA, InstsB, no, Result1, ModuleInfo),
+		std_util:no, [Type | Types], Result, ModuleInfo) :-
+	compare_inst(InstA, InstB, no, Type, Result0, ModuleInfo),
+	compare_inst_list_2(InstsA, InstsB, no, Types, Result1, ModuleInfo),
 	combine_results(Result0, Result1, Result).
 compare_inst_list_2([InstA | InstsA], [InstB | InstsB],
-		yes([ArgInst|ArgInsts]), Result, ModuleInfo) :-
-	compare_inst(InstA, InstB, yes(ArgInst), Result0, ModuleInfo),
-	compare_inst_list_2(InstsA, InstsB, yes(ArgInsts), Result1, ModuleInfo),
+		yes([ArgInst|ArgInsts]), [Type | Types], Result, ModuleInfo) :-
+	compare_inst(InstA, InstB, yes(ArgInst), Type, Result0, ModuleInfo),
+	compare_inst_list_2(InstsA, InstsB, yes(ArgInsts), Types, Result1,
+		ModuleInfo),
 	combine_results(Result0, Result1, Result).
 
 :- pred compare_liveness_list(list(is_live), list(is_live), match).
@@ -786,21 +815,21 @@
 	% 	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), match, module_info).
-:- mode compare_inst(in, in, in, out, in) is det.
+:- pred compare_inst(inst, inst, maybe(inst), type, match, module_info).
+:- mode compare_inst(in, in, in, in, out, in) is det.
 
-compare_inst(InstA, InstB, MaybeArgInst, Result, ModuleInfo) :-
+compare_inst(InstA, InstB, MaybeArgInst, Type, 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.
-	( inst_matches_initial(InstA, InstB, ModuleInfo) ->
+	( inst_matches_initial(InstA, InstB, Type, ModuleInfo) ->
 		A_mi_B = yes
 	;
 		A_mi_B = no
 	),
-	( inst_matches_initial(InstB, InstA, ModuleInfo) ->
+	( inst_matches_initial(InstB, InstA, Type, ModuleInfo) ->
 		B_mi_A = yes
 	;
 		B_mi_A = no
Index: compiler/modecheck_unify.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/modecheck_unify.m,v
retrieving revision 1.41
diff -u -r1.41 modecheck_unify.m
--- compiler/modecheck_unify.m	1999/09/13 10:14:43	1.41
+++ compiler/modecheck_unify.m	2000/02/03 05:26:08
@@ -1,5 +1,5 @@
 %-----------------------------------------------------------------------------%
-% Copyright (C) 1996-1999 The University of Melbourne.
+% Copyright (C) 1996-2000 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.
 %-----------------------------------------------------------------------------%
@@ -355,7 +355,7 @@
 	mode_info_get_module_info(ModeInfo0, ModuleInfo0),
 	mode_info_get_instmap(ModeInfo0, InstMap0),
 	instmap__lookup_var(InstMap0, X, InstOfX),
-	InstOfY = ground(unique, yes(LambdaPredInfo)),
+	InstOfY = ground(unique, higher_order(LambdaPredInfo)),
 	LambdaPredInfo = pred_inst_info(PredOrFunc, LambdaModes, LambdaDet),
 	(
 		abstractly_unify_inst(dead, InstOfX, InstOfY, real_unify,
@@ -877,13 +877,15 @@
 		ModeInfo2 = ModeInfo0
 	;
 		list__length(UnifyTypeInfoVars, NumTypeInfoVars),
-		list__duplicate(NumTypeInfoVars, ground(shared, no),
+		list__duplicate(NumTypeInfoVars, ground(shared, none),
 			ExpectedInsts),
 		mode_info_set_call_context(unify(UnifyContext),
 			ModeInfo0, ModeInfo1),
 		InitialArgNum = 0,
 		modecheck_var_has_inst_list(UnifyTypeInfoVars, ExpectedInsts,
-			InitialArgNum, ModeInfo1, ModeInfo2)
+			InitialArgNum, _InstVarSub, ModeInfo1, ModeInfo2)
+			% We can ignore _InstVarSub since type_info variables
+			% should not have variable insts.
 	),
 
 	mode_info_get_module_info(ModeInfo2, ModuleInfo2),
@@ -957,7 +959,8 @@
 		type_to_type_id(Type, TypeId, _)
 	->
 		mode_info_get_context(ModeInfo2, Context),
-		unify_proc__request_unify(TypeId - UniMode,
+		mode_info_get_instvarset(ModeInfo2, InstVarSet),
+		unify_proc__request_unify(TypeId - UniMode, InstVarSet,
 			Det, Context, ModuleInfo2, ModuleInfo),
 		mode_info_set_module_info(ModeInfo2, ModuleInfo,
 			ModeInfo)
@@ -1168,8 +1171,8 @@
 	->
 		mode_info_set_call_context(unify(UnifyContext)),
 		{ InitialArgNum = 0 },
-		modecheck_var_has_inst_list([ArgVar], [ground(shared, no)],
-			InitialArgNum),
+		modecheck_var_has_inst_list([ArgVar], [ground(shared, none)],
+			InitialArgNum, _InstVarSub),
 		check_type_info_args_are_ground(ArgVars, VarTypes,
 			UnifyContext)
 	;
@@ -1184,7 +1187,7 @@
 bind_args(not_reached, _) -->
 	{ instmap__init_unreachable(InstMap) },
 	mode_info_set_instmap(InstMap).
-bind_args(ground(Uniq, no), Args) -->
+bind_args(ground(Uniq, none), Args) -->
 	ground_args(Uniq, Args).
 bind_args(bound(_Uniq, List), Args) -->
 	( { List = [] } ->
@@ -1209,7 +1212,7 @@
 
 ground_args(_Uniq, []) --> [].
 ground_args(Uniq, [Arg | Args]) -->
-	modecheck_set_var_inst(Arg, ground(Uniq, no)),
+	modecheck_set_var_inst(Arg, ground(Uniq, none)),
 	ground_args(Uniq, Args).
 
 %-----------------------------------------------------------------------------%
@@ -1227,8 +1230,8 @@
 	mode_set_args(ArgInsts, not_reached, ArgModes).
 get_mode_of_args(any(Uniq), ArgInsts, ArgModes) :-
 	mode_set_args(ArgInsts, any(Uniq), ArgModes).
-get_mode_of_args(ground(Uniq, no), ArgInsts, ArgModes) :-
-	mode_set_args(ArgInsts, ground(Uniq, no), ArgModes).
+get_mode_of_args(ground(Uniq, none), ArgInsts, ArgModes) :-
+	mode_set_args(ArgInsts, ground(Uniq, none), ArgModes).
 get_mode_of_args(bound(_Uniq, List), ArgInstsA, ArgModes) :-
 	( List = [] ->
 		% the code is unreachable
--------------------------------------------------------------------------
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