intermodule optimization bug fix

Simon TAYLOR stayl at students.cs.mu.oz.au
Tue Apr 1 20:44:08 AEST 1997


Hi Fergus,

Could you please review this one.

Simon


Estimated hours taken: 0.5

Fix an abort reported by Peter Schachte, which was caused by 
hlds_module:get_pred_id_and_proc_id attempting to resolve overloading
on a predicate from a `.opt' file, while the code to resolve overloading
in typecheck.m does not attempt to match against predicates declared
in `.opt' files since all calls to such predicates should be module
qualified in the `.opt' file.

compiler/hlds_module.m
	If a predicate call is module qualified, there is no overloading
	to resolve, so don't check the argument types.

tests/valid/Mmake
tests/valid/intermod_lambda.m
tests/valid/intermod_lambda2.m
 	Added a regression test.
 

Index: hlds_module.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/hlds_module.m,v
retrieving revision 1.18
diff -u -r1.18 hlds_module.m
--- hlds_module.m	1997/03/23 07:34:04	1.18
+++ hlds_module.m	1997/03/25 06:27:40
@@ -1427,10 +1427,20 @@
 	module_info_get_predicate_table(ModuleInfo, PredicateTable),
 	list__length(ArgTypes, Arity),
 	(
-		predicate_table_search_pf_sym_arity(PredicateTable,
-			PredOrFunc, SymName, Arity, PredIds),
-		typecheck__find_matching_pred_id(PredIds, ModuleInfo,
-			TVarSet, ArgTypes, PredId0, _PredName)
+		(
+			% In this case there is no overloading to resolve,
+			% so just look up the pred_id. 
+			SymName = qualified(Module, Name),
+			predicate_table_search_pf_m_n_a(PredicateTable,
+				PredOrFunc, Module, Name, Arity, [PredId0])
+		;
+			% Resolve overloading using the arguments types. 
+			SymName = unqualified(Name),
+			predicate_table_search_pf_name_arity(PredicateTable,
+				PredOrFunc, Name, Arity, PredIds),
+			typecheck__find_matching_pred_id(PredIds, ModuleInfo,
+				TVarSet, ArgTypes, PredId0, _PredName)
+		)
 	->
 		PredId = PredId0,
 		get_proc_id(PredicateTable, PredId, ProcId)
@@ -1438,12 +1448,12 @@
 		% Undefined/invalid pred or func.
 		% the type-checker should ensure that this never happens
 		hlds_out__pred_or_func_to_str(PredOrFunc, PredOrFuncStr),
-		unqualify_name(SymName, Name),
+		unqualify_name(SymName, Name2),
 		string__int_to_string(Arity, ArityString),
 		string__append_list(
 			["get_pred_id_and_proc_id: ",
 			"undefined/invalid ", PredOrFuncStr,
-			"\n`", Name, "/", ArityString, "'"],
+			"\n`", Name2, "/", ArityString, "'"],
 			Msg),
 		error(Msg)
 	).


Index: tests/valid/Mmake
===================================================================
RCS file: /home/staff/zs/imp/tests/valid/Mmake,v
retrieving revision 1.27
diff -u -r1.27 Mmake
--- Mmake	1997/02/17 01:31:08	1.27
+++ Mmake	1997/04/01 10:31:34
@@ -25,6 +25,7 @@
 	higher_order3.m \
 	implied_mode.m \
 	indexing.m \
+	intermod_lambda.m \
 	lambda_inference.m\
 	lambda_type.m \
 	lambda_quant.m \
@@ -85,6 +86,14 @@
 
 vn_float.c: vn_float.m
 	$(MCG) --grade $(GRADE) $(MCGFLAGS) -O5 vn_float.m > vn_float.err 2>&1
+
+# intermod_lambda.m needs inter-module optimization
+intermod_lambda.c:
+	$(MC) --grade $(GRADE) $(MCGFLAGS) --make-interface intermod_lambda2.m
+	$(MC) --grade $(GRADE) $(MCGFLAGS) --make-optimization-interface \
+		intermod_lambda2.m
+	$(MCG) --grade $(GRADE) $(MCGFLAGS) --intermodule-optimization \
+		intermod_lambda.m
 
 check:	objs
 



tests/valid/intermod_lambda.m :
 
% Regression test for resolving overloading of higher-order terms
% exported using inter-module optimization.
:- module intermod_lambda.

:- interface.

:- type foo.	% not used

:- import_module intermod_lambda2.

:- interface.



tests/valid/intermod_lambda2.m:

% Regression test for higher-order terms exported using 
% inter-module optimization.
:- module intermod_lambda2.

:- interface.

:- import_module list, set.

%-----------------------------------------------------------------------------%

:- pred sol(pred(T), list(T)).
:- mode sol(pred(out) is det, out) is det.
:- mode sol(pred(out) is det, out) is det.

:- implementation.

sol(Generator, List) :-
	t(Generator, cons, [], List).

:- pred cons(T::in, list(T)::in, list(T)::out) is det.
cons(H, T, [H|T]).

:- pred t(pred(T), pred(T,T2,T2), T2, T2).
:- mode t(pred(out) is det, pred(in,in,out) is det, in, out) is det.

t(_, _, A, A).

%-----------------------------------------------------------------------------%



More information about the developers mailing list