[m-rev.] for review: postpone the processing of reuse/alias-pragma's

Nancy Mazur Nancy.Mazur at cs.kuleuven.ac.be
Thu Aug 22 01:51:06 AEST 2002


Forgot the resulting diff + log, for completeness... 

===================================================================


Estimated hours taken: 16
Branches: reuse

Change the moment where the alias-/reuse-pragma's are processed.  
The alias-/reuse-pragma's used to be processed at the moment they where read
(in make_hlds::parse_tree_to_hlds). The problem with this option is that the
pragma's may concern predicates that do not yet exist in the predicate table at
that moment. Therefore we have chosen to simply keep lists of unprocessed
alias- resp. reuse-pragma's within a module_info, and only process these lists
just before the actual alias- and reuse-analysis.  
This change makes it also possible to correctly produce and process
alias-/reuse-pragma's _with_ typeinfos and possibly other compiler-generated
headvariables. 

compiler/hlds_module.m:
	Add lists of unprocessed alias- and reuse-pragma's to the module_info, 
	and include some get/set-predicates for these new fields. 
	Also add a predicate with which to determine a procedure (proc_id)
	given its pred/func-category, name, arity, and declared modes. 

compiler/hlds_pred.m:
compiler/sr_direct.m:
compiler/sr_indirect.m:
compiler/sr_split.m:
	Small change: do not simplify reuse-information each time it is set
	(in hlds_pred), but only when needed. 

compiler/make_hlds.m:
compiler/pa_run.m:
compiler/pa_prelim_run.m:
compiler/structure_reuse.m:
	Instead of processing the alias-/reuse-pragma's, the information
	is temporarely stored in the module_info. It will only be processed
	at the start of alias_analysis (in pa_runm, pa_prelim_run.m), resp.
	structure reuse analysis (in structure_reuse.m)


Index: compiler/hlds_module.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/hlds_module.m,v
retrieving revision 1.59.2.9
diff -u -r1.59.2.9 hlds_module.m
--- compiler/hlds_module.m	10 Sep 2001 15:48:01 -0000	1.59.2.9
+++ compiler/hlds_module.m	21 Aug 2002 15:46:54 -0000
@@ -1,5 +1,5 @@
 %-----------------------------------------------------------------------------%
-% Copyright (C) 1996-2001 The University of Melbourne.
+% Copyright (C) 1996-2002 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.
 %-----------------------------------------------------------------------------%
@@ -25,12 +25,15 @@
 :- import_module hlds_pred, hlds_data, unify_proc, special_pred.
 :- import_module globals, llds.
 :- import_module relation, map, std_util, list, set, multi_map, counter.
+:- import_module pa_alias_as.
+:- import_module sr_data.
 
 :- implementation.
 
 :- import_module hlds_out, prog_out, prog_util.
 :- import_module typecheck, modules.
 :- import_module bool, require, int, string.
+:- import_module mode_util.
 
 %-----------------------------------------------------------------------------%
 
@@ -114,6 +117,30 @@
 	--->    do_aditi_compilation
 	;       no_aditi_compilation.
 
+	% The unprocessed pragma alias information.  This information is not
+	% processed until just prior to the alias pass in the compiler so that
+	% the entries correspond to the transformed versions of predicates (ie
+	% type-infos and so on).
+	% The types in unproc_alias_pragma match the types in the 
+	% pa_alias_info-pragma (see prog_data.m).
+:- type unproc_alias_pragmas == list(unproc_alias_pragma).
+:- type unproc_alias_pragma 
+	--->	unproc_alias_pragma(pred_or_func, sym_name, 
+			list(mode), list(prog_var), list((type)), 
+			alias_as).
+
+	% The unprocessed pragma reuse information.  This information is not
+	% processed until just prior to the alias pass in the compiler so that
+	% the entries correspond to the transformed versions of predicates (ie
+	% type-infos and so on).
+	% The types in unproc_reuse_pragma match the types in the 
+	% sr_reuse_info-pragma (see prog_data.m).
+:- type unproc_reuse_pragmas == list(unproc_reuse_pragma).
+:- type unproc_reuse_pragma 
+	---> 	unproc_reuse_pragma(pred_or_func, sym_name, 
+			list(mode), list(prog_var), list((type)), 
+			sr_data__memo_reuse, maybe(sym_name)).
+
 %-----------------------------------------------------------------------------%
 
 	% Various predicates for manipulating the module_info data structure
@@ -477,6 +504,28 @@
 :- mode module_info_optimize(in, out) is det.
 
 %-----------------------------------------------------------------------------%
+% Predicates to add and remove the unprocessed alias/reuse pragma's. 
+
+:- pred module_info_add_unproc_alias_pragma(module_info, unproc_alias_pragma,
+		module_info).
+:- mode module_info_add_unproc_alias_pragma(in, in, out) is det.
+
+:- pred module_info_unproc_alias_pragmas(module_info, unproc_alias_pragmas).
+:- mode module_info_unproc_alias_pragmas(in, out) is det.
+
+:- pred module_info_remove_unproc_alias_pragmas(module_info, module_info).
+:- mode module_info_remove_unproc_alias_pragmas(in, out) is det.
+
+:- pred module_info_add_unproc_reuse_pragma(module_info, unproc_reuse_pragma,
+		module_info). 
+:- mode module_info_add_unproc_reuse_pragma(in, in, out) is det.
+
+:- pred module_info_unproc_reuse_pragmas(module_info, unproc_reuse_pragmas).
+:- mode module_info_unproc_reuse_pragmas(in, out) is det.
+
+:- pred module_info_remove_unproc_reuse_pragmas(module_info, module_info).
+:- mode module_info_remove_unproc_reuse_pragmas(in, out) is det.
+%-----------------------------------------------------------------------------%
 
 :- implementation.
 
@@ -518,7 +567,9 @@
 					% numbers for constant terms in the
 					% generated C code
 
-		maybe_recompilation_info ::	maybe(recompilation_info)
+		maybe_recompilation_info ::	maybe(recompilation_info),
+		alias_info ::			unproc_alias_pragmas,
+		reuse_info ::			unproc_reuse_pragmas
 	).
 
 :- type module_sub_info --->
@@ -619,7 +670,7 @@
 	ModuleInfo = module(ModuleSubInfo, PredicateTable, Requests,
 		UnifyPredMap, QualifierInfo, Types, Insts, Modes, Ctors,
 		ClassTable, SuperClassTable, InstanceTable, AssertionTable,
-		FieldNameTable, counter__init(1), RecompInfo).
+		FieldNameTable, counter__init(1), RecompInfo, [], []).
 
 %-----------------------------------------------------------------------------%
 
@@ -1209,6 +1260,16 @@
 				sym_name, arity, list(pred_id)) is semidet.
 :- mode predicate_table_search_pf_sym_arity(in, in, in, in, out) is semidet.
 
+	% Search the table for the (unique) procedure matching this
+	% pred_or_func category, sym_name, arity, and declared modes. 
+	% If there was no mode declaration, then use the inferred argmodes.
+:- pred predicate_table_search_pf_sym_arity_declmodes(module_info, 
+				predicate_table,
+				pred_or_func, sym_name, arity, list(mode),
+				pred_id, proc_id).
+:- mode predicate_table_search_pf_sym_arity_declmodes(in, in, in, in, in, 
+				in, out, out) is semidet.
+
 	% Search the table for predicates or functions matching
 	% this pred_or_func category and sym_name.
 
@@ -1664,6 +1725,24 @@
 	predicate_table_search_pf_name_arity(PredicateTable, PredOrFunc,
 		Name, Arity, PredIdList).
 
+	% (inspired from make_hlds::get_procedure_matching_declmodes/4)
+predicate_table_search_pf_sym_arity_declmodes(ModuleInfo, 
+		PredicateTable, PredOrFunc, 
+		SymName, Arity, Modes, PredId, ProcId):- 
+	predicate_table_search_pf_sym_arity(PredicateTable, PredOrFunc, 
+		SymName, Arity, PredIds), 
+	PredIds = [PredId], 
+	module_info_preds(ModuleInfo, PredMap),
+	map__lookup(PredMap, PredId, PredInfo), 
+	pred_info_procedures(PredInfo, ProcedureTable), 
+	map__to_assoc_list(ProcedureTable, ProcedureList), 
+	list__filter(
+		(pred(ProcPair::in) is semidet :- 
+			ProcPair = _Id - ProcInfo, 
+			proc_info_declared_argmodes(ProcInfo, ArgModes),
+			mode_list_matches(Modes, ArgModes, ModuleInfo)),
+		ProcedureList, [ProcId - _ProcInfo]).
+
 predicate_table_search_pf_sym(PredicateTable, predicate,
 		SymName, PredIdList) :-
 	predicate_table_search_pred_sym(PredicateTable, SymName, PredIdList).
@@ -1892,4 +1971,21 @@
 	map__lookup(Preds, PredId, PredInfo),
 	pred_info_arity(PredInfo, Arity).
 
+%-----------------------------------------------------------------------------%
+
+module_info_add_unproc_alias_pragma(ModuleInfo, UnprocAlias, 
+	ModuleInfo ^ alias_info := [UnprocAlias | ModuleInfo ^ alias_info]).
+
+module_info_unproc_alias_pragmas(ModuleInfo, ModuleInfo ^ alias_info).
+
+module_info_remove_unproc_alias_pragmas(ModuleInfo, 
+	ModuleInfo ^ alias_info := []).
+
+module_info_add_unproc_reuse_pragma(ModuleInfo, UnprocReuse, 
+	ModuleInfo ^ reuse_info := [UnprocReuse | ModuleInfo ^ reuse_info]).
+
+module_info_unproc_reuse_pragmas(ModuleInfo, ModuleInfo ^ reuse_info).
+
+module_info_remove_unproc_reuse_pragmas(ModuleInfo, 
+	ModuleInfo ^ reuse_info := []).
 %-----------------------------------------------------------------------------%
Index: compiler/hlds_pred.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/hlds_pred.m,v
retrieving revision 1.81.2.19
diff -u -r1.81.2.19 hlds_pred.m
--- compiler/hlds_pred.m	10 Sep 2001 15:48:11 -0000	1.81.2.19
+++ compiler/hlds_pred.m	21 Aug 2002 15:46:56 -0000
@@ -1,5 +1,5 @@
 %-----------------------------------------------------------------------------%
-% Copyright (C) 1996-2001 The University of Melbourne.
+% Copyright (C) 1996-2002 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.
 %-----------------------------------------------------------------------------%
@@ -2232,10 +2232,10 @@
 			AliasReuseInfo^maybe_global_use := yes(GlobalUse),
 			ProcInfo). 
 proc_info_set_reuse_information(ProcInfo0, Reuse0, ProcInfo):- 
-	memo_reuse_simplify(Reuse0, Reuse),
+	% memo_reuse_simplify(Reuse0, Reuse),
 	proc_info_alias_reuse_info(ProcInfo0, AliasReuseInfo), 
 	proc_info_set_alias_reuse_info(ProcInfo0,
-			AliasReuseInfo^structure_reuse := Reuse,
+			AliasReuseInfo^structure_reuse := Reuse0,
 			ProcInfo). 
 proc_info_set_static_terms(ProcInfo0, StaticTerms, ProcInfo):- 
 	proc_info_alias_reuse_info(ProcInfo0, AliasReuseInfo), 
Index: compiler/make_hlds.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/make_hlds.m,v
retrieving revision 1.347.2.20
diff -u -r1.347.2.20 make_hlds.m
--- compiler/make_hlds.m	16 Oct 2001 11:14:25 -0000	1.347.2.20
+++ compiler/make_hlds.m	21 Aug 2002 15:47:03 -0000
@@ -1,5 +1,5 @@
 %-----------------------------------------------------------------------------%
-% Copyright (C) 1993-2001 The University of Melbourne.
+% Copyright (C) 1993-2002 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.
 %-----------------------------------------------------------------------------%
@@ -1453,80 +1453,16 @@
 			module_info::in, module_info::out, 
 			io__state::di, io__state::uo) is det.
 
+:- import_module pa_sr_util.
+
 add_pragma_possible_aliases_info(_, _, _, _, _, no, Module, Module) --> [].
 add_pragma_possible_aliases_info(PredOrFunc,SymName, Modes, 
 				HeadVars, Types, yes(AliasAS),
 				Module0, Module) --> 
-	{ module_info_get_predicate_table(Module0, Preds) },
-	{ list__length(Modes, Arity) },
-	(
-		{ predicate_table_search_pf_sym_arity( Preds,
-			PredOrFunc, SymName, Arity, PredIds) },
-		{ PredIds \= [] }
-	->
-	   (
-		{ PredIds = [PredId] }
-	   ->
-		{ module_info_preds(Module0, PredTable0) },
-		{ map__lookup(PredTable0, PredId, PredInfo0) },
-		{ pred_info_procedures(PredInfo0, ProcTable0) },
-		{ map__to_assoc_list(ProcTable0, ProcList) },
-		(
-			{ get_procedure_matching_declmodes( ProcList,
-				Modes, Module0, ProcId) }
-		->
-			{ map__lookup(ProcTable0, ProcId, ProcInfo0) },
-			{ proc_info_headvars(ProcInfo0, ProcHeadVars) },
-			{ list__map( term__coerce_var, HeadVars, CHeadVars )},
-			{ map__from_corresponding_lists(CHeadVars,
-				ProcHeadVars, MapHeadVars) },
-			{ pa_alias_as__rename( MapHeadVars, AliasAS, 
-						RenAliasAS0) },
-
-			% rename type variables
-			{ pred_info_arg_types( PredInfo0, ArgTypes ) }, 
-			{ pa_alias_as__rename_types( Types,
-				ArgTypes, RenAliasAS0, RenAliasAS ) }, 
-
-			{ proc_info_set_possible_aliases( ProcInfo0, 
-				RenAliasAS, ProcInfo ) },
-			{ map__det_update(ProcTable0, ProcId, ProcInfo,
-					ProcTable) },
-			{ pred_info_set_procedures(PredInfo0, ProcTable,
-					PredInfo) },
-			{ map__det_update(PredTable0, PredId, PredInfo,
-					PredTable) },
-			{ module_info_set_preds( Module0, PredTable, Module) }
-		;
-
-			% 	{ module_info_incr_errors(Module0, Module) },
-			io__write_string(
-				"Error: `:- pragma pa_alias_info' "),
-			io__write_string(
-				"declaration for undeclared mode of "),
-			hlds_out__write_simple_call_id(PredOrFunc,
-				SymName/Arity),
-			io__write_string(".\n"),
-			{ Module = Module0 },
-			io__set_exit_status(1)
-		)
-	   ;
-		io__write_string("Error: ambiguous predicate name "),
-		hlds_out__write_simple_call_id(PredOrFunc, SymName/Arity),
-		io__write_string(" in `pragma pa_alias_info'.\n"),
-		{ Module = Module0 },
-		io__set_exit_status(1)
-		% { module_info_incr_errors(Module0, Module) }
-	   )
-	;
-	   io__write_string("Warning: no corresponding entry found for "),
-	   hlds_out__write_simple_call_id(PredOrFunc, SymName/Arity),
-	   io__write_string(" with `pragma pa_alias_info'.\n"),
-	   { Module = Module0 }
-	   % io__set_exit_status(1)
-	   % { module_info_incr_errors(Module0, Module) }
-	).
-
+	{ list__map(term__coerce_var, HeadVars, CHeadVars) },
+	{ module_info_add_unproc_alias_pragma(Module0, 
+		unproc_alias_pragma(PredOrFunc, SymName, Modes, CHeadVars,
+			Types, AliasAS), Module) }.
 
 
 %-----------------------------------------------------------------------------%
@@ -1542,69 +1478,13 @@
 			module_info::in, module_info::out, 
 			io__state::di, io__state::uo) is det.
 
-add_pragma_reuse_info(PredOrFunc,SymName, Modes, HeadVars, Types, TREUSE,
-		_MaybeReuseName, Module0, Module) --> 
-	{ module_info_get_predicate_table(Module0, Preds) },
-	{ list__length(Modes, Arity) },
-	(
-		{ predicate_table_search_pf_sym_arity( Preds,
-			PredOrFunc, SymName, Arity, PredIds) },
-		{ PredIds \= [] }
-	->
-	   (
-		{ PredIds = [PredId] }
-	   ->
-		{ module_info_preds(Module0, PredTable0) },
-		{ map__lookup(PredTable0, PredId, PredInfo0) },
-		{ pred_info_procedures(PredInfo0, ProcTable0) },
-		{ map__to_assoc_list(ProcTable0, ProcList) },
-		(
-			{ get_procedure_matching_declmodes( ProcList,
-				Modes, Module0, ProcId) }
-		->
-			{ map__lookup(ProcTable0, ProcId, ProcInfo0) },
-			{ proc_info_headvars(ProcInfo0, ProcHeadVars) },
-			{ list__map( term__coerce_var, HeadVars, CHeadVars )},
-			{ map__from_corresponding_lists(CHeadVars,
-				ProcHeadVars, MapHeadVars) },
-			{ sr_data__memo_reuse_rename( MapHeadVars, TREUSE, 
-						RenTREUSE0) },
-			{ pred_info_arg_types( PredInfo0, ArgTypes ) }, 
-			{ sr_data__memo_reuse_rename_types( Types,
-				ArgTypes, RenTREUSE0, RenTREUSE ) }, 
-
-			{ sr_split__create_reuse_pred(proc(PredId, ProcId),
-					RenTREUSE,
-					no, Module0, Module) }
-		;
+add_pragma_reuse_info(PredOrFunc,SymName, Modes, HeadVars, Types, Reuse,
+		MaybeReuseName, Module0, Module) --> 
+	{ list__map(term__coerce_var, HeadVars, CHeadVars) },
+	{ module_info_add_unproc_reuse_pragma(Module0, 
+		unproc_reuse_pragma(PredOrFunc, SymName, Modes, CHeadVars,
+			Types, Reuse, MaybeReuseName), Module) }.
 
-			% 	{ module_info_incr_errors(Module0, Module) },
-			io__write_string(
-				"Error: `:- pragma sr_reuse_info' "),
-			io__write_string(
-				"declaration for undeclared mode of "),
-			hlds_out__write_simple_call_id(PredOrFunc,
-				SymName/Arity),
-			io__write_string(".\n"),
-			{ Module = Module0 },
-			io__set_exit_status(1)
-		)
-	   ;
-		io__write_string("Error: ambiguous predicate name "),
-		hlds_out__write_simple_call_id(PredOrFunc, SymName/Arity),
-		io__write_string(" in `pragma sr_reuse_info'.\n"),
-		{ Module = Module0 },
-		io__set_exit_status(1)
-		% { module_info_incr_errors(Module0, Module) }
-	   )
-	;
-	   io__write_string("Warning: no corresponding entry found for "),
-	   hlds_out__write_simple_call_id(PredOrFunc, SymName/Arity),
-	   io__write_string(" with `pragma sr_reuse_info'.\n"),
-	   { Module = Module0 }
-	   % io__set_exit_status(1)
-	   % { module_info_incr_errors(Module0, Module) }
-	).
 
 %-----------------------------------------------------------------------------%
 
@@ -4782,17 +4662,6 @@
 		get_procedure_matching_declmodes(Procs, Modes, ModuleInfo, 
 			OurProcId)
 	).
-
-:- pred mode_list_matches(list(mode), list(mode), module_info).
-:- mode mode_list_matches(in, in, in) is semidet.
-
-mode_list_matches([], [], _).
-mode_list_matches([Mode1 | Modes1], [Mode2 | Modes2], ModuleInfo) :-
-	% Use mode_get_insts_semidet instead of mode_get_insts to avoid
-	% aborting if there are undefined modes.
-	mode_get_insts_semidet(ModuleInfo, Mode1, Inst1, Inst2),
-	mode_get_insts_semidet(ModuleInfo, Mode2, Inst1, Inst2),
-	mode_list_matches(Modes1, Modes2, ModuleInfo).
 
 %-----------------------------------------------------------------------------%
 
Index: compiler/mode_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mode_util.m,v
retrieving revision 1.128.2.7
diff -u -r1.128.2.7 mode_util.m
--- compiler/mode_util.m	16 Oct 2001 11:15:07 -0000	1.128.2.7
+++ compiler/mode_util.m	21 Aug 2002 15:47:11 -0000
@@ -201,6 +201,21 @@
 
 %-----------------------------------------------------------------------------%
 
+	% Returns true if the two mode-lists match, given the additional 
+	% module_info. 
+:- pred mode_list_matches(list(mode), list(mode), module_info).
+:- mode mode_list_matches(in, in, in) is semidet.
+
+mode_list_matches([], [], _).
+mode_list_matches([Mode1 | Modes1], [Mode2 | Modes2], ModuleInfo) :-
+	% Use mode_get_insts_semidet instead of mode_get_insts to avoid
+	% aborting if there are undefined modes.
+	mode_get_insts_semidet(ModuleInfo, Mode1, Inst1, Inst2),
+	mode_get_insts_semidet(ModuleInfo, Mode2, Inst1, Inst2),
+	mode_list_matches(Modes1, Modes2, ModuleInfo).
+
+%-----------------------------------------------------------------------------%
+
 	% Construct a mode corresponding to the standard `in',
 	% `out', `uo' or `unused' mode.
 :- pred in_mode((mode)::out) is det.
Index: compiler/pa_prelim_run.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/Attic/pa_prelim_run.m,v
retrieving revision 1.1.2.6
diff -u -r1.1.2.6 pa_prelim_run.m
--- compiler/pa_prelim_run.m	23 Mar 2001 10:41:29 -0000	1.1.2.6
+++ compiler/pa_prelim_run.m	21 Aug 2002 15:47:15 -0000
@@ -1,5 +1,5 @@
 %-----------------------------------------------------------------------------%
-% Copyright (C) 2000-2001 The University of Melbourne.
+% Copyright (C) 2000-2002 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.
 %-----------------------------------------------------------------------------%
@@ -24,21 +24,109 @@
 
 :- import_module hlds_module, io.
 
+:- pred process_imported_predicates(module_info::in, module_info::out, 
+		io__state::di, io__state::uo) is det.
+
 :- pred annotate_all_liveness_in_module(module_info::in, module_info::out,
 		io__state::di, io__state::uo) is det.
 
 :- pred annotate_all_outscope_vars_in_module(module_info::in,
 		module_info::out) is det.
 
-%-------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
 
 :- implementation.
 
 :- import_module list, map, set, std_util.
 :- import_module hlds_pred, liveness. 
 :- import_module hlds_goal, prog_data.
+:- import_module passes_aux.
+%-----------------------------------------------------------------------------%
 
+% :- import_module pa_sr_util.
+:- import_module term, varset.
+:- import_module pa_alias_as.
+:- import_module globals, options.
+:- import_module hlds_module.
+:- import_module hlds_out.
+:- import_module mercury_to_mercury.
+
+process_imported_predicates(HLDS0, HLDS) -->
+	{ module_info_unproc_alias_pragmas(HLDS0, UnprocAliasPragmas) },
+	list__foldl2(
+		process_unproc_alias_pragma, 
+		UnprocAliasPragmas, HLDS0, HLDS1), 
+	{ module_info_remove_unproc_alias_pragmas(HLDS1, HLDS) }.
+	
+
+:- pred process_unproc_alias_pragma(unproc_alias_pragma, module_info, 
+		module_info, io__state, io__state).
+:- mode process_unproc_alias_pragma(in, in, out, di, uo) is det.
+
+process_unproc_alias_pragma(UnprocAliasPragma, Module0, Module) --> 
+	{ UnprocAliasPragma = unproc_alias_pragma(PredOrFunc, SymName, 
+		Modes, HeadVars, Types, Alias0) },
+
+	globals__io_lookup_bool_option(very_verbose, VeryVerbose),
+
+	{ module_info_get_predicate_table(Module0, Preds) }, 
+	{ list__length(Modes, Arity) },
+	(
+		{ predicate_table_search_pf_sym_arity_declmodes(Module0, 
+			Preds, PredOrFunc, SymName, Arity, Modes, 
+			PredId, ProcId) }
+	->
+		{ module_info_preds(Module0, PredTable0) },
+		{ map__lookup(PredTable0, PredId, PredInfo0) },
+		{ pred_info_procedures(PredInfo0, ProcTable0) },
+		{ map__lookup(ProcTable0, ProcId, ProcInfo0) },
+		write_proc_progress_message("(Alias) Looking into ", 
+			PredId, ProcId, Module0),
+
+			% rename the headvars: 
+		maybe_write_string(VeryVerbose, "Renaming HeadVars..."),
+		{ proc_info_headvars(ProcInfo0, ProcHeadVars) }, 
+		{ list__map(term__coerce_var, HeadVars, CHVars) },
+		{ map__from_corresponding_lists(CHVars, ProcHeadVars,
+			MapHeadVars) }, 
+		{ pa_alias_as__rename(MapHeadVars, Alias0, Alias1) },
+		maybe_write_string(VeryVerbose, "done.\n"),
+	
+		% rename the types: 
+		maybe_write_string(VeryVerbose, "Renaming Types..."),
+		{ pred_info_arg_types(PredInfo0, ArgTypes) },
+		{ pa_alias_as__rename_types(Types, ArgTypes, 
+			Alias1, Alias) },
+		maybe_write_string(VeryVerbose, "done.\n"),
+
+		% set the proc_info right
+		{ proc_info_set_possible_aliases(ProcInfo0, 
+			Alias, ProcInfo) },
+		{ map__det_update(ProcTable0, ProcId, ProcInfo,
+				ProcTable) },
+		{ pred_info_set_procedures(PredInfo0, ProcTable,
+				PredInfo) },
+		{ map__det_update(PredTable0, PredId, PredInfo,
+				PredTable) },
+		{ module_info_set_preds(Module0, PredTable, Module) }
+	;
+		% io__write_string("Warning: no entry found for "),
+		% hlds_out__write_simple_call_id(PredOrFunc, SymName/Arity),
+		% io__write_string(" with modes: "), 
+		% { varset__init(EmptyVarset) },
+		% io__write_list(Modes, ", ", write_mode(EmptyVarset)),
+		% io__write_string(" (alias_info).\n"),
+		{ Module = Module0 }
+	).
+
+:- pred write_mode(varset, (mode), io__state, io__state).
+:- mode write_mode(in, in, di, uo) is det.
+
+write_mode(Varset, Mode) --> 
+	{ varset__coerce(Varset, CVarset) },
+	io__write_string(mercury_mode_to_string(Mode, CVarset)).
 
+%-----------------------------------------------------------------------------%
 annotate_all_liveness_in_module(HLDSin, HLDSout) -->
 	{ module_info_predids(HLDSin, PredIds0) }, 
 
Index: compiler/pa_run.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/Attic/pa_run.m,v
retrieving revision 1.1.2.24
diff -u -r1.1.2.24 pa_run.m
--- compiler/pa_run.m	30 Apr 2001 11:36:29 -0000	1.1.2.24
+++ compiler/pa_run.m	21 Aug 2002 15:47:15 -0000
@@ -1,5 +1,5 @@
 %-----------------------------------------------------------------------------%
-% Copyright (C) 2000-2001 The University of Melbourne.
+% Copyright (C) 2000-2002 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.
 %-----------------------------------------------------------------------------%
@@ -81,10 +81,14 @@
 %-----------------------------------------------------------------------------%
 
 pa_run__aliases_pass(HLDSin, HLDSout) -->
-
 	% preliminary steps:
+
+	% 0. process all the alias-information for all the imported 
+	% predicates.
+	pa_prelim_run__process_imported_predicates(HLDSin, HLDS0),
+
 	% 1. annotate all the liveness
-	pa_prelim_run__annotate_all_liveness_in_module(HLDSin, HLDS1),
+	pa_prelim_run__annotate_all_liveness_in_module(HLDS0, HLDS1),
 
 	% 2. annotate all the outscope vars
 	{ pa_prelim_run__annotate_all_outscope_vars_in_module(HLDS1,HLDS2) },
@@ -734,7 +738,7 @@
 
 		% write headvars vars(HeadVar__1, ... HeadVar__n)
 	{ proc_info_varset(ProcInfo, ProgVarset) },
-	{ proc_info_real_headvars(ProcInfo, RealHeadVars) }, 
+	{ proc_info_headvars(ProcInfo, HeadVars) }, 
 	{ proc_info_vartypes(ProcInfo, VarTypes) }, 
 	{ pred_info_typevarset(PredInfo, TypeVarSet) },
 
@@ -742,14 +746,13 @@
 			ProgVarset, 
 			VarTypes, 
 			TypeVarSet, 
-			RealHeadVars),
+			HeadVars),
 
 	io__write_string(", "),
 
 		% write alias information
 
 	{ proc_info_possible_aliases(ProcInfo, MaybeAliases) },
-
 	pa_alias_as__print_maybe_interface_aliases(MaybeAliases, 
 					ProcInfo, PredInfo),
 
Index: compiler/sr_direct.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/Attic/sr_direct.m,v
retrieving revision 1.1.2.15
diff -u -r1.1.2.15 sr_direct.m
--- compiler/sr_direct.m	5 Jul 2001 15:33:32 -0000	1.1.2.15
+++ compiler/sr_direct.m	21 Aug 2002 15:47:31 -0000
@@ -1,5 +1,5 @@
 %-----------------------------------------------------------------------------%
-% Copyright (C) 2000-2001 The University of Melbourne.
+% Copyright (C) 2000-2002 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.
 %-----------------------------------------------------------------------------%
@@ -109,8 +109,9 @@
 	; 
 		[]
 	), 
-		
-	{ proc_info_set_reuse_information(ProcInfo2, MaybeReuseConditions, 
+	
+	{ memo_reuse_simplify(MaybeReuseConditions, MaybeReuseConditions1) },
+	{ proc_info_set_reuse_information(ProcInfo2, MaybeReuseConditions1, 
 			ProcInfo3) },
 	{ proc_info_set_goal(ProcInfo3, Goal, ProcInfo) }.
 
Index: compiler/sr_indirect.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/Attic/sr_indirect.m,v
retrieving revision 1.1.2.26
diff -u -r1.1.2.26 sr_indirect.m
--- compiler/sr_indirect.m	16 Aug 2001 17:17:21 -0000	1.1.2.26
+++ compiler/sr_indirect.m	21 Aug 2002 15:47:31 -0000
@@ -1,5 +1,5 @@
 %-----------------------------------------------------------------------------%
-% Copyright (C) 2000-2001 The University of Melbourne.
+% Copyright (C) 2000-2002 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.
 %-----------------------------------------------------------------------------%
@@ -103,7 +103,8 @@
 	sr_fixpoint_table_get_final_reuse(PredProcId, Memo, Goal, FP), 
 	module_info_pred_proc_info(HLDS0, PredProcId, PredInfo0, ProcInfo0),
 	proc_info_set_goal(ProcInfo0, Goal, ProcInfo1), 
-	proc_info_set_reuse_information(ProcInfo1, Memo, ProcInfo),
+	memo_reuse_simplify(Memo, MemoS),
+	proc_info_set_reuse_information(ProcInfo1, MemoS, ProcInfo),
 	pred_info_procedures(PredInfo0, Procedures0), 
 	map__det_update(Procedures0, ProcId, ProcInfo, Procedures), 
 	pred_info_set_procedures(PredInfo0, Procedures, PredInfo), 
Index: compiler/sr_split.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/Attic/sr_split.m,v
retrieving revision 1.1.2.16
diff -u -r1.1.2.16 sr_split.m
--- compiler/sr_split.m	28 Jun 2001 08:04:22 -0000	1.1.2.16
+++ compiler/sr_split.m	21 Aug 2002 15:47:32 -0000
@@ -1,5 +1,5 @@
 %-----------------------------------------------------------------------------%
-% Copyright (C) 2000-2001 The University of Melbourne.
+% Copyright (C) 2000-2002 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.
 %-----------------------------------------------------------------------------%
@@ -227,8 +227,8 @@
 		module_info_set_predicate_table(HLDSin1, PredTable, HLDSout)
 	% ; contains_unconditional_reuse(TREUSE) ->
 	;
-		proc_info_set_reuse_information(ProcInfo0, 
-						TREUSE, ProcInfo1),
+		memo_reuse_simplify(TREUSE, TREUSE1),
+		proc_info_set_reuse_information(ProcInfo0, TREUSE1, ProcInfo1),
 		(
 			MaybeHLDS_GOAL = yes(HLDS_GOAL),
 			proc_info_set_goal(ProcInfo1, HLDS_GOAL, ProcInfo)
@@ -247,8 +247,9 @@
 
 create_reuse_pred(TabledReuse, PredProcId, MaybeReuseGoal, PredInfo, ProcInfo,
 		ReusePredInfo, ReuseProcInfo, ReuseProcId, SymName) :-
-	proc_info_set_reuse_information(ProcInfo, 
-				TabledReuse, ReuseProcInfo0),
+	memo_reuse_simplify(TabledReuse, TabledReuse1),
+	proc_info_set_reuse_information(ProcInfo, TabledReuse1, 
+		ReuseProcInfo0),
 	(
 		MaybeReuseGoal = yes(PotReuseGoal),
 		convert_potential_reuse_to_reuse(PotReuseGoal, ReuseGoal),
Index: compiler/structure_reuse.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/Attic/structure_reuse.m,v
retrieving revision 1.1.2.9
diff -u -r1.1.2.9 structure_reuse.m
--- compiler/structure_reuse.m	22 Jun 2001 14:47:00 -0000	1.1.2.9
+++ compiler/structure_reuse.m	21 Aug 2002 15:47:32 -0000
@@ -1,5 +1,5 @@
 %-----------------------------------------------------------------------------%
-% Copyright (C) 2000-2001 The University of Melbourne.
+% Copyright (C) 2000-2002 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.
 %-----------------------------------------------------------------------------%
@@ -56,7 +56,15 @@
 :- import_module list, map, varset, std_util, int, bool.
 :- import_module sr_profile_run.
 
-structure_reuse(HLDS0, HLDS) -->
+structure_reuse(HLDS00, HLDS) -->
+	% Before starting the actual reuse-analysis, process all the reuse
+	% information of the imported predicates.
+	{ module_info_unproc_reuse_pragmas(HLDS00, UnprocReusePragmas) },
+	list__foldl2(
+		process_unproc_reuse_pragma, UnprocReusePragmas, 
+		HLDS00, HLDS01), 
+	{ module_info_remove_unproc_reuse_pragmas(HLDS01, HLDS0) }, 
+	
 	{ module_info_get_special_pred_map(HLDS0, SpecialPredMap) },
 	{ map__values(SpecialPredMap, SpecialPredIds) },
 
@@ -74,6 +82,77 @@
 	sr_split__create_multiple_versions(HLDS2, HLDS), 
 	sr_profile_run__structure_reuse_profiling(HLDS). 
 
+%-----------------------------------------------------------------------------%
+:- import_module term, varset.
+:- import_module sr_data, sr_split.
+:- import_module globals, options.
+:- import_module hlds_module.
+:- import_module hlds_out.
+
+:- pred process_unproc_reuse_pragma(unproc_reuse_pragma, module_info, 
+		module_info, io__state, io__state).
+:- mode process_unproc_reuse_pragma(in, in, out, di, uo) is det.
+
+process_unproc_reuse_pragma(UnprocReusePragma, Module0, Module) --> 
+	{ UnprocReusePragma = unproc_reuse_pragma(PredOrFunc, SymName, 
+		Modes, HeadVars, Types, Reuse, _MaybeReuseName) },
+
+	globals__io_lookup_bool_option(very_verbose, VeryVerbose),
+
+	{ module_info_get_predicate_table(Module0, Preds) }, 
+	{ list__length(Modes, Arity) },
+	(
+		{ predicate_table_search_pf_sym_arity_declmodes(Module0, 
+			Preds, PredOrFunc, SymName, Arity, Modes, 
+			PredId, ProcId) }
+	->
+		{ module_info_preds(Module0, PredTable0) },
+		{ map__lookup(PredTable0, PredId, PredInfo0) },
+		{ pred_info_procedures(PredInfo0, ProcTable0) },
+		{ map__lookup(ProcTable0, ProcId, ProcInfo0) },
+		write_proc_progress_message("(Reuse) Looking into ", 
+			PredId, ProcId, Module0),
+
+			% rename the headvars: 
+		maybe_write_string(VeryVerbose, "Renaming HeadVars..."),
+		{ proc_info_headvars(ProcInfo0, ProcHeadVars) }, 
+		{ list__map(term__coerce_var, HeadVars, CHVars) },
+		{ map__from_corresponding_lists(CHVars, ProcHeadVars,
+			MapHeadVars) }, 
+		{ sr_data__memo_reuse_rename(MapHeadVars, Reuse, Reuse1) },
+		maybe_write_string(VeryVerbose, "done.\n"),
+	
+		% rename the types: 
+		maybe_write_string(VeryVerbose, "Renaming Types..."),
+		{ pred_info_arg_types(PredInfo0, ArgTypes) },
+		{ sr_data__memo_reuse_rename_types(Types, ArgTypes, 
+			Reuse1, Reuse2) },
+		maybe_write_string(VeryVerbose, "done.\n"),
+
+		% create the reuse-version of the procedure
+		{ sr_split__create_reuse_pred(proc(PredId, ProcId),
+			Reuse2, no, Module0, Module) }
+		
+	;
+		% io__write_string("Warning: no entry found for "),
+		% hlds_out__write_simple_call_id(PredOrFunc, SymName/Arity),
+		% io__write_string(" with modes: "), 
+		% { varset__init(EmptyVarset) },
+		% io__write_list(Modes, ", ", write_mode(EmptyVarset)),
+		% io__write_string(" (reuse_info).\n"),
+		{ Module = Module0 }
+	).
+
+:- import_module mercury_to_mercury.
+:- pred write_mode(varset, (mode), io__state, io__state).
+:- mode write_mode(in, in, di, uo) is det.
+
+write_mode(Varset, Mode) --> 
+	{ varset__coerce(Varset, CVarset) },
+	io__write_string(mercury_mode_to_string(Mode, CVarset)).
+
+%-----------------------------------------------------------------------------%
+
 
 write_pragma_reuse_info( HLDS, SpecPredIds, PredId ) --> 
 	{ module_info_pred_info( HLDS, PredId, PredInfo ) },
@@ -136,15 +215,15 @@
 		% write headvars vars(HeadVar__1, ... HeadVar__n)
 
 	{ proc_info_varset(ProcInfo, ProgVarset) },
-	{ proc_info_real_headvars(ProcInfo, HeadVars) },
-	{ proc_info_vartypes( ProcInfo, VarTypes) }, 
-	{ pred_info_typevarset( PredInfo, TypeVarSet ) },
+	{ proc_info_headvars(ProcInfo, HeadVars) },
+	{ proc_info_vartypes(ProcInfo, VarTypes) }, 
+	{ pred_info_typevarset(PredInfo, TypeVarSet) },
 
 	pa_sr_util__trans_opt_output_vars_and_types(
 			ProgVarset, 
 			VarTypes, 
 			TypeVarSet, 
-			HeadVars ),
+			HeadVars),
 
 	io__write_string(", "),
 
@@ -163,7 +242,7 @@
 	{ module_info_pred_proc_info(HLDS, ReusePredId, ReuseProcId,
 			_ReusePredInfo, ReuseProcInfo) },
 	{ proc_info_reuse_information(ReuseProcInfo, TREUSE) },
-	sr_data__memo_reuse_print( TREUSE, ReuseName, ReuseProcInfo, PredInfo) ,
+	sr_data__memo_reuse_print(TREUSE, ReuseName, ReuseProcInfo, PredInfo) ,
 
 	io__write_string(").\n").
 %-----------------------------------------------------------------------------%

--------------------------------------------------------------------------
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