[m-dev.] diff for review: overload resolution for higher-order terms

Fergus Henderson fjh at cs.mu.oz.au
Mon Mar 24 04:35:00 AEDT 1997


Hi Simon,

Could you please review this one?

Estimated hours taken: 1

Fix two bugs in my previous change to intermod.m.

compiler/intermod.m:
	In module-qualification of function calls, don't assume that
	anything which has the same name as a function is a function
	call -- it might be a constructor.
	(Actually this bug was in the original code too, for
	explicitly-qualified function names.)

	In module-qualification of higher-order terms, when
	constructing the list of argument types to pass to
	get_pred_id_and_proc_id, make sure we append the curried
	arguments and the yet-to-be-passed arguments in the right
	order.

compiler/typecheck.m:
	Undo previous change: don't export `typecheck__resolve_overloading',
	since it isn't used anymore after the above fix to intermod.m.

Index: intermod.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/intermod.m,v
retrieving revision 1.20
diff -u -r1.20 intermod.m
--- intermod.m	1997/03/23 07:34:08	1.20
+++ intermod.m	1997/03/23 17:14:36
@@ -511,41 +511,21 @@
 	intermod_info_get_var_types(VarTypes),
 	(
 		%
-		% Is it a module-qualified function call?
+		% Is it a function call?
 		%
-		{ Functor0 = cons(qualified(FuncModule, FuncName), Arity) },
-		{ predicate_table_search_func_m_n_a(PredTable,
-				FuncModule, FuncName, Arity, PredIds) }
-	->
-		%
-		% Yes, it is a module-qualified function call.
-		% Make sure that the called function will be exported.
-		%
-		( { PredIds = [PredId] } ->
-			intermod_info_add_proc(PredId, DoWrite)
-		;
-			% there should be at most one function
-			% with a given module, name, and arity
-			{ error("intermod.m: func_m_n_a not unique") }
-		),
-		{ Functor = Functor0 }
-	;
-		%
-		% Is it an unqualified function call?
-		%
-		{ Functor0 = cons(unqualified(FuncName), Arity) },
-		{ predicate_table_search_func_name_arity(PredTable,
-				FuncName, Arity, PredIds) }
+		{ 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 an unqualified function call.
+		% Yes, it is a function call.
 		% Module-qualify it.
 		% Make sure that the called function will be exported.
 		%
-		{ list__append(Vars, [LVar], FuncArgs) },
-		{ typecheck__resolve_overloading(ModuleInfo,
-			FuncArgs, VarTypes, TVarSet, PredIds,
-			QualifiedFuncName, PredId) },
 		{ Functor = cons(QualifiedFuncName, Arity) },
 		intermod_info_add_proc(PredId, DoWrite)
 	;
@@ -563,7 +543,7 @@
 		% Make sure that the predicate/function is exported.
 		%
 		{ map__apply_to_list(Vars, VarTypes, Types) },
-		{ list__append(PredArgTypes, Types, ArgTypes) },
+		{ list__append(Types, PredArgTypes, ArgTypes) },
 		{ get_pred_id_and_proc_id(PredName, PredOrFunc,
 			TVarSet, ArgTypes, ModuleInfo, PredId, _ProcId) },
 		intermod_info_add_proc(PredId, DoWrite),
Index: typecheck.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/typecheck.m,v
retrieving revision 1.190
diff -u -r1.190 typecheck.m
--- typecheck.m	1997/03/23 07:34:06	1.190
+++ typecheck.m	1997/03/23 17:29:59
@@ -152,15 +152,6 @@
 
 	% Find a predicate or function from the list of pred_ids
 	% which matches the given name and argument types.
-	% Abort if there is no matching pred.
-	% Abort if there are multiple matching preds.
-
-:- pred typecheck__resolve_overloading(module_info, list(var), map(var, type),
-				tvarset, list(pred_id), sym_name, pred_id).
-:- mode typecheck__resolve_overloading(in, in, in, in, in, out, out) is det.
-
-	% Find a predicate or function from the list of pred_ids
-	% which matches the given name and argument types.
 	% Fail if there is no matching pred.
 	% Abort if there are multiple matching preds.
 
@@ -915,11 +906,6 @@
 	;
 		PredIds = []
 	),
-	typecheck__resolve_overloading(ModuleInfo, Args, VarTypes, TVarSet,
-			 PredIds, PredName, PredId).
-
-typecheck__resolve_overloading(ModuleInfo, Args, VarTypes, TVarSet, PredIds,
-		 PredName, PredId) :-
 	%
 	% Check if there any of the candidate pred_ids
 	% have argument/return types which subsume the actual

-- 
Fergus Henderson <fjh at cs.mu.oz.au>   |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>   |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3         |     -- the last words of T. S. Garp.



More information about the developers mailing list