for review: improve handling of pred_consts (was Re: [m-rev.] diff: fix accumulator test case failure)

Simon Taylor stayl at cs.mu.OZ.AU
Mon Jul 9 03:58:51 AEST 2001


On 07-Jul-2001, Fergus Henderson <fjh at cs.mu.OZ.AU> wrote:
> On 07-Jul-2001, Simon Taylor <stayl at cs.mu.OZ.AU> wrote:
> > compiler/hlds_out.m:
> > 	Don't abort if the cons_id in a unify_rhs is a pred_const.
> > 
> > 	Without this change tests/general/accumulator/highorder.m fails.
> 
> That is not the right fix.  It is documented in hlds_goal.m as
> an invariant of the HLDS that the cons_id in a unify_rhs is never
> a pred_const.  So either the invariant needs to be changed, or (IMHO
> more likely) the code which produces such a unify_rhs needs to be fixed.

>From hlds_goal.m:
	% The cons_id for functor/2 cannot be a pred_const, code_addr_const,
	% or type_ctor_info_const, since none of these can be created when
	% the unify_rhs field is used.
	:- type unify_rhs
		--->    var(prog_var)
		;       functor(cons_id, list(prog_var))
	...

That comment is out of date. polymorphism.m creates unify_rhs terms
where the cons_id is a type_ctor_info_const. code_addr_const is
no longer used.
 
> BTW, when did the highorder test start failing, and what options caused
> it to fail?  It seems to have been working fine previously.

It was my change to higher_order.m.

Simon.


Estimated hours taken: 3

Use pred_const cons_ids in the unify_rhs field for constructions
of higher-order terms. Previously there would be a `cons(sym_name, arity)'
cons_id in the `unify_rhs', and a pred_const in the `unification'.

This avoids multiple calls to get_pred_id_and_proc_id, and is more
consistent with how other cons_ids are handled.

compiler/post_typecheck.m:
	Find the pred_const cons_id for constructions of higher-order terms.

compiler/higher_order.m:
compiler/lambda.m:
	Use `pred_const' rather than `cons(sym_name, arity)' in the
	`unify_rhs' of constructions of higher-order terms.

compiler/polymorphism.m:
compiler/modecheck_unify.m:
	Change the interface of polymorphism__convert_pred_to_lambda_goal
	to reflect the fact that the pred_proc_id of the higher-order term
	has already been computed by post_typecheck.m.

compiler/purity.m:
	Don't attempt to resolve overloading if there were type errors.
	If the type inference iteration limit was exceeded the code
	to resolve overloading of higher-order terms in post_typecheck.m
	can abort. This occurred with tests/invalid/type_inf_loop.m.

compiler/hlds_goal.m:
	Remove documentation about the restrictions on cons_ids
	in a unify_rhs, since they no longer apply.

compiler/intermod.m:
	Remove code duplicated from post_typecheck.m.

compiler/hlds_data.m:
	Add a comment that code_addr_const cons_ids are no longer
	used (they are left over from an old method of constructing
	type_ctor_infos).



Index: higher_order.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/higher_order.m,v
retrieving revision 1.88
diff -u -u -r1.88 higher_order.m
--- higher_order.m	2001/07/06 14:13:56	1.88
+++ higher_order.m	2001/07/07 10:36:36
@@ -1111,13 +1111,12 @@
 			{ Result = specialized(ExtraTypeInfoGoals0, Goal1) },
 			{
 				Goal1 = call(NewPredId0, NewProcId0,
-						NewArgs0, _, _, NewName0),
+						NewArgs0, _, _, _),
 				list__remove_suffix(NewArgs0,
 					UncurriedArgs, NewArgs1)
 			->
 				NewPredId = NewPredId0,
 				NewProcId = NewProcId0,
-				NewName = NewName0,
 				NewArgs = NewArgs1
 			;
 				error("maybe_specialize_pred_const")	
@@ -1137,8 +1136,7 @@
 			{ Unify = construct(LVar, NewConsId,
 				NewArgs, UniModes, HowToConstruct,
 				CellIsUnique, MaybeExprn) },
-			{ Functor = cons(NewName, list__length(NewArgs)) },
-			{ Goal2 = unify(LVar, functor(Functor, NewArgs),
+			{ Goal2 = unify(LVar, functor(NewConsId, NewArgs),
 				UniMode, Unify, Context) },
 
 			% Make sure any constants in the
Index: hlds_data.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/hlds_data.m,v
retrieving revision 1.55
diff -u -u -r1.55 hlds_data.m
--- hlds_data.m	2001/05/31 05:59:35	1.55
+++ hlds_data.m	2001/07/08 17:33:33
@@ -35,7 +35,8 @@
 			;	pred_const(pred_id, proc_id,
 					lambda_eval_method)
 			;	code_addr_const(pred_id, proc_id)
-				% Used for constructing type_infos.
+				% No longer used. code_addr_const cons_ids
+				% were once used to construct type_infos.
 				% Note that a pred_const is for a closure
 				% whereas a code_addr_const is just an address.
 			;	type_ctor_info_const(module_name, string, int)
Index: hlds_goal.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/hlds_goal.m,v
retrieving revision 1.88
diff -u -u -r1.88 hlds_goal.m
--- hlds_goal.m	2001/05/31 05:59:35	1.88
+++ hlds_goal.m	2001/07/07 09:22:42
@@ -297,9 +297,6 @@
 	% unify(prog_var, unify_rhs, _, _, _), but mode analysis replaces
 	% these with various special cases (construct/deconstruct/assign/
 	% simple_test/complicated_unify).
-	% The cons_id for functor/2 cannot be a pred_const, code_addr_const,
-	% or type_ctor_info_const, since none of these can be created when
-	% the unify_rhs field is used.
 :- type unify_rhs
 	--->	var(prog_var)
 	;	functor(cons_id, list(prog_var))
Index: intermod.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/intermod.m,v
retrieving revision 1.100
diff -u -u -r1.100 intermod.m
--- intermod.m	2001/06/27 05:04:08	1.100
+++ intermod.m	2001/07/08 17:27:12
@@ -720,54 +720,14 @@
 	% Fully module-qualify the right-hand-side of a unification.
 	% For function calls and higher-order terms, call intermod__add_proc
 	% so that the predicate or function will be exported if necessary.
-intermod__module_qualify_unify_rhs(LVar, functor(Functor0, Vars),
+intermod__module_qualify_unify_rhs(_LVar, functor(Functor, Vars),
 				functor(Functor, Vars), DoWrite) -->
-	intermod_info_get_module_info(ModuleInfo),
-	{ module_info_get_predicate_table(ModuleInfo, PredTable) },
-	intermod_info_get_tvarset(TVarSet),
-	intermod_info_get_var_types(VarTypes),
 	(
-		% Is it a higher-order function call?
-		% (higher-order predicate calls are transformed into
-		% higher_order_call goals by make_hlds.m).
-		{ Functor0 = cons(unqualified(ApplyName), _) },
-		{ ApplyName = "apply"
-		; ApplyName = ""
-		},
-		{ list__length(Vars, ApplyArity) },
-		{ ApplyArity >= 1 }
-	->
-		{ Functor = Functor0 },
-		{ DoWrite = yes }
-	;
-		%
-		% Is it a function call?
-		%
-		{ Functor0 = cons(FuncName, Arity) },
-		{ predicate_table_search_func_sym_arity(PredTable,
-				FuncName, Arity, PredIds) },
-		{ list__append(Vars, [LVar], FuncArgs) },
-		{ map__apply_to_list(FuncArgs, VarTypes, FuncArgTypes) },
-		{ typecheck__find_matching_pred_id(PredIds, ModuleInfo,
-			TVarSet, FuncArgTypes, PredId, QualifiedFuncName) }
-	->
-		%
-		% Yes, it is a function call.
-		% Fully module-qualify it.
-		% Make sure that the called function will be exported.
 		%
-		{ Functor = cons(QualifiedFuncName, Arity) },
-		intermod__add_proc(PredId, DoWrite)
-	;
-		%
 		% Is this a higher-order predicate or higher-order function
 		% term?
 		%
-		{ Functor0 = cons(PredName, Arity) },
-		intermod_info_get_var_types(VarTypes),
-		{ map__lookup(VarTypes, LVar, LVarType) },
-		{ type_is_higher_order(LVarType, PredOrFunc,
-			EvalMethod, PredArgTypes) }
+		{ Functor = pred_const(PredId, _, EvalMethod) }
 	->
 		( { EvalMethod = (aditi_top_down) } ->
 			% XXX Predicates which build this type of lambda
@@ -776,49 +736,25 @@
 			% bytecode fragment to use. The best way to handle
 			% these is probably to add some sort of lookup table
 			% to Aditi. 
-			{ DoWrite = no },
-			{ Functor = Functor0 }
+			{ DoWrite = no }
 		;
 			%
 			% Yes, the unification creates a higher-order term.
 			% Make sure that the predicate/function is exported.
-			%
-			{ map__apply_to_list(Vars, VarTypes, Types) },
-			{ list__append(Types, PredArgTypes, ArgTypes) },
-			{ get_pred_id_and_proc_id(PredName, PredOrFunc,
-				TVarSet, ArgTypes, ModuleInfo,
-				PredId, _ProcId) },
-			intermod__add_proc(PredId, DoWrite),
 			%
-			% Fully module-qualify it.
-			%
-			{ unqualify_name(PredName, UnqualPredName) },
-			{ predicate_module(ModuleInfo, PredId, Module) },
-			{ QualifiedPredName =
-				qualified(Module, UnqualPredName) },
-			{ Functor = cons(QualifiedPredName, Arity) }
+			intermod__add_proc(PredId, DoWrite)
 		)
 	;
 		%
-		% Is it a functor symbol for which we can add
-		% a module qualifier?
+		% It's an ordinary constructor, or a constant of a builtin
+		% type, so just leave it alone.
 		%
-		{ Functor0 = cons(ConsName, ConsArity) },
-		{ map__lookup(VarTypes, LVar, VarType) },
-		{ type_to_type_id(VarType, TypeId, _) },
-		{ TypeId = qualified(TypeModule, _) - _ }
-	->
+		% Constructors are module qualified by post_typecheck.m.
 		%
-		% Fully module-qualify it
+		% Function calls and higher-order function applications
+		% are transformed into ordinary calls and higher-order calls
+		% by post_typecheck.m, so they can't occur here.
 		%
-		{ unqualify_name(ConsName, UnqualConsName) },
-		{ Functor = cons(qualified(TypeModule, UnqualConsName),
-				ConsArity) },
-		{ DoWrite = yes }
-	;
-		% It is a constant of a builtin type.
-		% No module qualification needed.
-		{ Functor = Functor0 },
 		{ DoWrite = yes }
 	).
 
Index: lambda.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/lambda.m,v
retrieving revision 1.73
diff -u -u -r1.73 lambda.m
--- lambda.m	2001/04/07 14:04:43	1.73
+++ lambda.m	2001/07/08 17:50:34
@@ -377,8 +377,7 @@
 		% It's also only valid if all the inputs in the Yi precede the
 		% outputs.  It's also not valid if any of the Xi are in the Yi.
 
-		LambdaGoal = call(PredId0, ProcId0, CallVars,
-					_, _, PredName0) - _,
+		LambdaGoal = call(PredId0, ProcId0, CallVars, _, _, _) - _,
 		module_info_pred_proc_info(ModuleInfo0, PredId0, ProcId0,
 			Call_PredInfo, Call_ProcInfo),
 
@@ -441,8 +440,6 @@
 		ArgVars = InitialVars,
 		PredId = PredId0,
 		ProcId = ProcId0,
-		PredName = PredName0,
-		NumArgVars = NumInitialVars,
 		mode_util__modes_to_uni_modes(CurriedArgModes, CurriedArgModes,
 			ModuleInfo0, UniModes),
 		%
@@ -576,8 +573,8 @@
 		module_info_set_predicate_table(ModuleInfo1, PredicateTable,
 			ModuleInfo)
 	),
-	Functor = functor(cons(PredName, NumArgVars), ArgVars),
 	ConsId = pred_const(PredId, ProcId, EvalMethod),
+	Functor = functor(ConsId, ArgVars),
 
 	RLExprnId = no,
 	Unification = construct(Var, ConsId, ArgVars, UniModes,
Index: modecheck_unify.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/modecheck_unify.m,v
retrieving revision 1.45
diff -u -u -r1.45 modecheck_unify.m
--- modecheck_unify.m	2001/01/17 01:42:05	1.45
+++ modecheck_unify.m	2001/07/07 11:03:49
@@ -125,28 +125,17 @@
 	%
 	(
 		% check if variable has a higher-order type
-		type_is_higher_order(TypeOfX, PredOrFunc, EvalMethod,
-			PredArgTypes),
-		ConsId0 = cons(PName, _),
-		% but in case we are redoing mode analysis, make sure
-		% we don't mess with the address constants for type_info
-		% fields created by polymorphism.m
-		Unification0 \= construct(_, code_addr_const(_, _),
-			_, _, _, _, _),
-		Unification0 \= deconstruct(_,
-				code_addr_const(_, _), _, _, _, _)
+		type_is_higher_order(TypeOfX, _, EvalMethod, PredArgTypes),
+		ConsId0 = pred_const(PredId, ProcId, _)
 	->
 		%
 		% convert the pred term to a lambda expression
 		%
 		mode_info_get_varset(ModeInfo0, VarSet0),
 		mode_info_get_context(ModeInfo0, Context),
-		mode_info_get_predid(ModeInfo0, ThisPredId),
-		module_info_pred_info(ModuleInfo0, ThisPredId, ThisPredInfo),
-		pred_info_typevarset(ThisPredInfo, TVarSet),
-		convert_pred_to_lambda_goal(PredOrFunc, EvalMethod,
-			X0, ConsId0, PName, ArgVars0, PredArgTypes, TVarSet,
-			Unification0, UnifyContext, GoalInfo0, Context,
+		convert_pred_to_lambda_goal(EvalMethod,
+			X0, PredId, ProcId, ArgVars0, PredArgTypes,
+			UnifyContext, GoalInfo0, Context,
 			ModuleInfo0, VarSet0, VarTypes0,
 			Functor0, VarSet, VarTypes),
 		mode_info_set_varset(VarSet, ModeInfo0, ModeInfo1),
Index: polymorphism.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/polymorphism.m,v
retrieving revision 1.211
diff -u -u -r1.211 polymorphism.m
--- polymorphism.m	2001/05/24 02:32:22	1.211
+++ polymorphism.m	2001/07/07 10:49:14
@@ -189,7 +189,7 @@
 :- module polymorphism.
 :- interface.
 
-:- import_module hlds_goal, hlds_module, hlds_pred, hlds_data.
+:- import_module hlds_goal, hlds_module, hlds_pred.
 :- import_module prog_data, special_pred.
 
 :- import_module io, list, term, map.
@@ -307,20 +307,20 @@
 :- mode polymorphism__get_special_proc(in, in, in, out, out, out) is semidet.
 
 	% convert a higher-order pred term to a lambda goal
-:- pred convert_pred_to_lambda_goal(pred_or_func, lambda_eval_method,
-		prog_var, cons_id, sym_name, list(prog_var), list(type),
-		tvarset, unification, unify_context, hlds_goal_info, context,
+:- pred convert_pred_to_lambda_goal(lambda_eval_method,
+		prog_var, pred_id, proc_id, list(prog_var), list(type),
+		unify_context, hlds_goal_info, context,
 		module_info, prog_varset, map(prog_var, type),
 		unify_rhs, prog_varset, map(prog_var, type)).
-:- mode convert_pred_to_lambda_goal(in, in, in, in, in, in, in, in, 
-		in, in, in, in, in, in, in, out, out, out) is det.
+:- mode convert_pred_to_lambda_goal(in, in, in, in, in, in, in, 
+		in, in, in, in, in, out, out, out) is det.
 
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
 
 :- implementation.
 
-:- import_module typecheck, llds, prog_io.
+:- import_module hlds_data, typecheck, llds, prog_io.
 :- import_module type_util, mode_util, quantification, instmap, prog_out.
 :- import_module code_util, unify_proc, prog_util.
 :- import_module (inst), hlds_out, base_typeclass_info, goal_util, passes_aux.
@@ -1323,19 +1323,18 @@
 	%
 
 		% check if variable has a higher-order type
-		type_is_higher_order(TypeOfX, PredOrFunc,
+		type_is_higher_order(TypeOfX, _,
 			EvalMethod, PredArgTypes),
-		ConsId0 = cons(PName, _)
+		ConsId0 = pred_const(PredId, ProcId, _)
 	->
 		%
 		% convert the higher-order pred term to a lambda goal
 		%
 		poly_info_get_varset(PolyInfo0, VarSet0),
-		poly_info_get_typevarset(PolyInfo0, TVarSet),
 		goal_info_get_context(GoalInfo0, Context),
-		convert_pred_to_lambda_goal(PredOrFunc, EvalMethod,
-			X0, ConsId0, PName, ArgVars0, PredArgTypes, TVarSet,
-			Unification0, UnifyContext, GoalInfo0, Context,
+		convert_pred_to_lambda_goal(EvalMethod,
+			X0, PredId, ProcId, ArgVars0, PredArgTypes,
+			UnifyContext, GoalInfo0, Context,
 			ModuleInfo0, VarSet0, VarTypes0,
 			Functor0, VarSet, VarTypes),
 		poly_info_set_varset_and_types(VarSet, VarTypes,
@@ -1402,9 +1401,8 @@
 		PolyInfo = PolyInfo0
 	).
 
-convert_pred_to_lambda_goal(PredOrFunc, EvalMethod, X0, ConsId0, PName,
-		ArgVars0, PredArgTypes, TVarSet,
-		Unification0, UnifyContext, GoalInfo0, Context,
+convert_pred_to_lambda_goal(EvalMethod, X0, PredId, ProcId,
+		ArgVars0, PredArgTypes, UnifyContext, GoalInfo0, Context,
 		ModuleInfo0, VarSet0, VarTypes0,
 		Functor, VarSet, VarTypes) :-
 	%
@@ -1418,32 +1416,17 @@
 	% Build up the hlds_goal_expr for the call that will form
 	% the lambda goal
 	%
-	map__apply_to_list(Args, VarTypes, ArgTypes),
-	(
-		% If we are redoing mode analysis, use the
-		% pred_id and proc_id found before, to avoid aborting
-		% in get_pred_id_and_proc_id if there are multiple
-		% matching procedures.
-		Unification0 = construct(_, 
-			pred_const(PredId0, ProcId0, _),
-			_, _, _, _, _)
-	->
-		PredId = PredId0,
-		ProcId = ProcId0
-	;
-		get_pred_id_and_proc_id(PName, PredOrFunc, TVarSet, 
-			ArgTypes, ModuleInfo0, PredId, ProcId)
-	),
 	module_info_pred_proc_info(ModuleInfo0, PredId, ProcId,
 				PredInfo, ProcInfo),
 
-	% module-qualify the pred name (is this necessary?)
 	pred_info_module(PredInfo, PredModule),
-	unqualify_name(PName, UnqualPName),
-	QualifiedPName = qualified(PredModule, UnqualPName),
+	pred_info_name(PredInfo, PredName),
+	QualifiedPName = qualified(PredModule, PredName),
 
 	CallUnifyContext = call_unify_context(X0,
-			functor(ConsId0, ArgVars0), UnifyContext),
+			functor(cons(QualifiedPName, list__length(ArgVars0)),
+				ArgVars0),
+			UnifyContext),
 	LambdaGoalExpr = call(PredId, ProcId, Args, not_builtin,
 			yes(CallUnifyContext), QualifiedPName),
 
@@ -1484,6 +1467,7 @@
 	%
 	% construct the lambda expression
 	%
+	pred_info_get_is_pred_or_func(PredInfo, PredOrFunc),
 	Functor = lambda_goal(PredOrFunc, EvalMethod, modes_are_ok,
 		ArgVars0, LambdaVars, LambdaModes, LambdaDet, LambdaGoal).
 
Index: post_typecheck.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/post_typecheck.m,v
retrieving revision 1.31
diff -u -u -r1.31 post_typecheck.m
--- post_typecheck.m	2001/06/27 05:04:20	1.31
+++ post_typecheck.m	2001/07/08 16:28:54
@@ -958,14 +958,14 @@
 
 post_typecheck__resolve_unify_functor(X0, ConsId0, ArgVars0, Mode0,
 		Unification0, UnifyContext, GoalInfo0,
-		ModuleInfo0, PredInfo0, PredInfo, VarTypes0, VarTypes,
+		ModuleInfo, PredInfo0, PredInfo, VarTypes0, VarTypes,
 		VarSet0, VarSet, Goal) :-
 
 	map__lookup(VarTypes0, X0, TypeOfX),
 	list__length(ArgVars0, Arity),
 	(
 		%
-		% is the function symbol apply/N or ''/N,
+		% Is the function symbol apply/N or ''/N,
 		% representing a higher-order function call?
 		%
 		ConsId0 = cons(unqualified(ApplyName), _),
@@ -993,7 +993,7 @@
 		Goal = HOCall - GoalInfo0
 	;
 		%
-		% is the function symbol a user-defined function, rather
+		% Is the function symbol a user-defined function, rather
 		% than a functor which represents a data constructor?
 		%
 
@@ -1020,9 +1020,9 @@
 		% compiler for a field access function -- that needs
 		% to be expanded into unifications below.
 		%
-		\+ pred_info_is_field_access_function(ModuleInfo0, PredInfo0),
+		\+ pred_info_is_field_access_function(ModuleInfo, PredInfo0),
 
-		module_info_get_predicate_table(ModuleInfo0, PredTable),
+		module_info_get_predicate_table(ModuleInfo, PredTable),
 		predicate_table_search_func_sym_arity(PredTable,
 			PredName, Arity, PredIds),
 
@@ -1033,7 +1033,7 @@
 		pred_info_typevarset(PredInfo0, TVarSet),
 		map__apply_to_list(ArgVars0, VarTypes0, ArgTypes0),
 		list__append(ArgTypes0, [TypeOfX], ArgTypes),
-		typecheck__find_matching_pred_id(PredIds, ModuleInfo0,
+		typecheck__find_matching_pred_id(PredIds, ModuleInfo,
 			TVarSet, ArgTypes, PredId, QualifiedFuncName)
 	->
 		%
@@ -1059,7 +1059,7 @@
 		% calls into predicate calls above.
 		%
 		ConsId0 = cons(Name, Arity),
-		is_field_access_function_name(ModuleInfo0, Name, Arity,
+		is_field_access_function_name(ModuleInfo, Name, Arity,
 			AccessType, FieldName),
 
 		%
@@ -1076,22 +1076,59 @@
 		%
 		pred_info_typevarset(PredInfo0, TVarSet),
 		map__apply_to_list(ArgVars0, VarTypes0, ArgTypes0),
-		\+ find_matching_constructor(ModuleInfo0, TVarSet,
+		\+ find_matching_constructor(ModuleInfo, TVarSet,
 			ConsId0, TypeOfX, ArgTypes0)
 	->
-		post_typecheck__finish_field_access_function(ModuleInfo0,
+		post_typecheck__finish_field_access_function(ModuleInfo,
 			PredInfo0, PredInfo, VarTypes0, VarTypes,
 			VarSet0, VarSet, AccessType, FieldName,
 			UnifyContext, X0, ArgVars0, GoalInfo0, Goal)
 	;
 		%
-		% ordinary construction/deconstruction unifications
-		% we leave alone
+		% Is the function symbol a higher-order predicate
+		% or function constant?
+		% This test needs to come after the test to recognise
+		% function calls and field access function calls
+		% to avoid being confused by functions that return
+		% higher-order terms.
+		%
+		ConsId0 = cons(Name, _),
+		type_is_higher_order(TypeOfX, PredOrFunc,
+			EvalMethod, HOArgTypes)
+	->
+		%
+		% Find the pred_id and proc_id of the constant.
+		%
+		map__apply_to_list(ArgVars0, VarTypes0, ArgTypes0),
+		AllArgTypes = ArgTypes0 ++ HOArgTypes,
+		pred_info_typevarset(PredInfo0, TVarSet),
+		get_pred_id_and_proc_id(Name, PredOrFunc, TVarSet,
+			AllArgTypes, ModuleInfo, PredId, ProcId),
+		ConsId = pred_const(PredId, ProcId, EvalMethod),
+		Goal = unify(X0, functor(ConsId, ArgVars0), Mode0,
+			Unification0, UnifyContext) - GoalInfo0,
+		PredInfo = PredInfo0,
+		VarTypes = VarTypes0,
+		VarSet = VarSet0
+	;
+		%
+		% Module qualify ordinary construction/deconstruction
+		% unifications.
 		%
 		PredInfo = PredInfo0,
 		VarTypes = VarTypes0,
 		VarSet = VarSet0,
-		Goal = unify(X0, functor(ConsId0, ArgVars0), Mode0,
+		(
+			ConsId0 = cons(Name0, Arity),
+			type_to_type_id(TypeOfX, TypeIdOfX, _),
+			TypeIdOfX = qualified(TypeModule, _) - _
+		->
+			unqualify_name(Name0, Name),
+			ConsId = cons(qualified(TypeModule, Name), Arity)	
+		;
+			ConsId = ConsId0
+		),
+		Goal = unify(X0, functor(ConsId, ArgVars0), Mode0,
 				Unification0, UnifyContext) - GoalInfo0
 	).
 
Index: purity.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/purity.m,v
retrieving revision 1.32
diff -u -u -r1.32 purity.m
--- purity.m	2001/05/16 04:50:50	1.32
+++ purity.m	2001/07/08 17:10:14
@@ -370,7 +370,7 @@
 			PostTypecheckError1 = PostTypecheckError0
 		},
 		puritycheck_pred(PredId, PredInfo1, PredInfo2, ModuleInfo0,
-				PurityErrsInThisPred),
+				FoundTypeError, PurityErrsInThisPred),
 		post_typecheck__finish_pred(ModuleInfo0, PredId, PredInfo2,
 				PredInfo),
 		{ NumErrors1 is NumErrors0 + UnboundTypeErrsInThisPred
@@ -414,11 +414,12 @@
 %  them, and in the translation from goal to hlds_goal, the attached purity is
 %  turned into the appropriate feature in the hlds_goal_info.)
 
-:- pred puritycheck_pred(pred_id, pred_info, pred_info, module_info, int,
+:- pred puritycheck_pred(pred_id, pred_info, pred_info, module_info, bool, int,
 		io__state, io__state).
-:- mode puritycheck_pred(in, in, out, in, out, di, uo) is det.
+:- mode puritycheck_pred(in, in, out, in, in, out, di, uo) is det.
 
-puritycheck_pred(PredId, PredInfo0, PredInfo, ModuleInfo, NumErrors) -->
+puritycheck_pred(PredId, PredInfo0, PredInfo, ModuleInfo,
+		FoundTypeError, NumErrors) -->
 	{ pred_info_get_purity(PredInfo0, DeclPurity) } ,
 	{ pred_info_get_promised_purity(PredInfo0, PromisedPurity) },
 	( { pred_info_get_goal_type(PredInfo0, pragmas) } ->
@@ -435,7 +436,13 @@
 		{ clauses_info_clauses(ClausesInfo0, Clauses0) },
 		{ clauses_info_vartypes(ClausesInfo0, VarTypes0) },
 		{ clauses_info_varset(ClausesInfo0, VarSet0) },
-		{ RunPostTypecheck = yes },
+
+		%
+		% Exceeding the type inference iteration limit can result
+		% in aborts in the code in post_typecheck.m to resolve
+		% overloading.
+		%
+		{ RunPostTypecheck = bool__not(FoundTypeError) },
 		{ PurityInfo0 = purity_info(ModuleInfo, RunPostTypecheck,
 			PredInfo0, VarTypes0, VarSet0, []) },
 		{ compute_purity(Clauses0, Clauses, ProcIds, pure, Purity,
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list