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

Peter Ross pro at missioncriticalit.com
Wed Aug 21 23:51:11 AEST 2002


On Tue, Aug 20, 2002 at 02:42:13PM +0200, Nancy Mazur wrote:
> 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	20 Aug 2002 12:37:40 -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.
>  %-----------------------------------------------------------------------------%
> @@ -114,6 +114,36 @@
>  	--->    do_aditi_compilation
>  	;       no_aditi_compilation.
>  
> +:- import_module pa_alias_as.

This import_module should be grouped with all the other import_modules.

> +	% This type is used to list all unprocessed alias-pragma's. These
> +	% pragma's are read during the make_hlds-stage, but they may not 
> +	% be processed until the actual alias-pass is started. The reason
> +	% for this is that alias-information is provided for predicates that
> +	% may not yet be within the predicate table at the moment where 
> +	% make_hlds wishes to process this information. 
> +	% The types in unproc_alias_pragma match the types in the 
> +	% pa_alias_info-pragma (see prog_data.m).

I would suggest rewording this simply as follows:

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

> +:- 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).
> +
> +:- import_module sr_data.

Again place this import_module with all the others.

> +	% This type is used to list all unprocessed reuse-pragma's. These
> +	% pragma's are read during the make_hlds-stage, but they may not 
> +	% be processed until the actual reuse-pass is started. The reason
> +	% for this is that reuse-information is provided for predicates that
> +	% may not yet be within the predicate table at the moment where 
> +	% make_hlds wishes to process this information. 
> +	% The types in unproc_reuse_pragma match the types in the 
> +	% sr_reuse_info-pragma (see prog_data.m).

Reword similar to above.

> +:- 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 +507,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 +570,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 +673,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 +1263,17 @@
>  				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.
> +	% (inspired from make_hlds::get_procedure_matching_declmodes/4)

The inspired comment would be better placed as a comment on the code below,
not on the interface declaration.

> +:- 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 +1729,35 @@
>  	predicate_table_search_pf_name_arity(PredicateTable, PredOrFunc,
>  		Name, Arity, PredIdList).
>  
> +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]).
> +
> +:- import_module mode_util.

Again put the import with all the other imports.

> +:- 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).
> +

It would be better to move this mode_list_matches predicate into
mode_util.m and delete it from make_hlds.m.

>  predicate_table_search_pf_sym(PredicateTable, predicate,
>  		SymName, PredIdList) :-
>  	predicate_table_search_pred_sym(PredicateTable, SymName, PredIdList).
> @@ -1892,4 +1986,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/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	20 Aug 2002 12:38:16 -0000
> @@ -24,21 +24,109 @@
> +:- 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"),

You definitely need to report an error here.

Use

io__set_exit_status(1),
{ module_info_incr_errors(Module0, Module) },

This should ensure that the compiler finishes with an abort.

> +		{ 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)).
>  

> 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	20 Aug 2002 12:38:43 -0000
> @@ -74,6 +82,77 @@
> +:- 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 }

Similarly here, report the error and set the error_status.

> +	).
> +
> +:- 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 ) },
--------------------------------------------------------------------------
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