[m-dev.] diff: fix writing of type spec preds to .opt files

Simon Taylor stayl at cs.mu.OZ.AU
Mon Feb 7 11:13:36 AEDT 2000



Estimated hours taken: 0.5

Remove some code duplication that was causing termination
pragmas to be handled differently when written to `.opt'
files rather than `.trans_opt' files.

compiler/termination.m:
	Rename `termination__make_opt_int_preds' as
	`termination__write_pred_termination_info', and export
	it for use by trans_opt.m.
	Incorporate the recent changes made to similar code in
	trans_opt.m to avoid writing user-guided type specialization
	predicates to the optimization interface files.

compiler/trans_opt.m:
	Remove the duplicated code.



Index: termination.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/termination.m,v
retrieving revision 1.19
diff -u -u -r1.19 termination.m
--- termination.m	1999/07/08 05:08:58	1.19
+++ termination.m	2000/02/07 00:06:48
@@ -48,7 +48,7 @@
 :- interface.
 
 :- import_module io, bool, std_util, list.
-:- import_module prog_data, hlds_module, term_util.
+:- import_module prog_data, hlds_module, hlds_pred, term_util.
 
 	% Perform termination analysis on the module.
 
@@ -65,6 +65,13 @@
 :- pred termination__write_maybe_termination_info(maybe(termination_info)::in,
 	bool::in, io__state::di, io__state::uo) is det.
 
+	% Write out a termination_info pragma for the predicate if it
+	% is exported, it is not a builtin and it is not a predicate used
+	% to force type specialization.
+:- pred termination__write_pred_termination_info(module_info, pred_id,
+	io__state, io__state).
+:- mode termination__write_pred_termination_info(in, in, di, uo) is det.
+
 	% This predicate outputs termination_info pragmas;
 	% such annotations can be part of .opt and .trans_opt files.
 
@@ -79,7 +86,7 @@
 
 :- import_module term_pass1, term_pass2, term_errors.
 :- import_module inst_match, passes_aux, options, globals.
-:- import_module hlds_data, hlds_goal, hlds_pred, dependency_graph, varset.
+:- import_module hlds_data, hlds_goal, dependency_graph, varset.
 :- import_module mode_util, hlds_out, code_util, prog_out, prog_util.
 :- import_module mercury_to_mercury, type_util, special_pred.
 :- import_module modules.
@@ -672,7 +679,8 @@
 	io__open_append(OptFileName, OptFileRes),
 	( { OptFileRes = ok(OptFile) },
 		io__set_output_stream(OptFile, OldStream),
-		termination__make_opt_int_preds(PredIds, Module),
+		list__foldl(termination__write_pred_termination_info(Module),
+			PredIds),
 		io__set_output_stream(OldStream, _),
 		io__close_output(OptFile),
 		maybe_write_string(Verbose, " done.\n")
@@ -684,19 +692,22 @@
 			OptFileName, "' for output: ", IOErrorMessage]),
 		io__set_exit_status(1)
 	).
-
-:- pred termination__make_opt_int_preds(list(pred_id), module_info, 
-	io__state, io__state).
-:- mode termination__make_opt_int_preds(in, in, di, uo) is det.
 
-termination__make_opt_int_preds([], _Module) --> [].
-termination__make_opt_int_preds([ PredId | PredIds ], Module) -->
-	{ module_info_preds(Module, PredTable) },
-	{ map__lookup(PredTable, PredId, PredInfo) },
+termination__write_pred_termination_info(Module, PredId) -->
+	{ module_info_pred_info(Module, PredId, PredInfo) },
 	{ pred_info_import_status(PredInfo, ImportStatus) },
+	{ module_info_type_spec_info(Module, TypeSpecInfo) },
+	{ TypeSpecInfo = type_spec_info(_, TypeSpecForcePreds, _, _) },
+
 	( 
 		{ ImportStatus = exported },
-		{ \+ code_util__compiler_generated(PredInfo) }
+		{ \+ code_util__compiler_generated(PredInfo) },
+
+		% XXX These should be allowed, but the predicate
+		% declaration for the specialized predicate is not produced
+		% before the termination pragmas are read in, resulting
+		% in an undefined predicate error.
+		\+ { set__member(PredId, TypeSpecForcePreds) }
 	->
 		{ pred_info_name(PredInfo, PredName) },
 		{ pred_info_procedures(PredInfo, ProcTable) },
@@ -709,8 +720,7 @@
 			PredOrFunc, SymName, Context)
 	;
 		[]
-	),
-	termination__make_opt_int_preds(PredIds, Module).
+	).
 
 :- pred termination__make_opt_int_procs(pred_id, list(proc_id), proc_table,
 	pred_or_func, sym_name, prog_context, io__state, io__state).
Index: trans_opt.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/trans_opt.m,v
retrieving revision 1.14
diff -u -u -r1.14 trans_opt.m
--- trans_opt.m	1999/11/14 02:27:26	1.14
+++ trans_opt.m	2000/01/18 03:27:29
@@ -112,7 +112,8 @@
 		% file should go here.
 
 		{ module_info_predids(Module, PredIds) },
-		trans_opt__write_preds(PredIds, Module),
+		list__foldl(termination__write_pred_termination_info(Module),
+			PredIds),
 
 		io__set_output_stream(OldStream, _),
 		io__close_output(Stream),
@@ -122,61 +123,6 @@
 		update_interface(OptName),
 		touch_interface_datestamp(ModuleName, ".trans_opt_date")
 	).
-	
-:- pred trans_opt__write_preds(list(pred_id), module_info, 
-	io__state, io__state).
-:- mode trans_opt__write_preds(in, in, di, uo) is det.
-trans_opt__write_preds([], _) --> [].
-trans_opt__write_preds([PredId | PredIds], Module) -->
-	{ module_info_preds(Module, PredTable) },
-	{ module_info_type_spec_info(Module, TypeSpecInfo) },
-	{ TypeSpecInfo = type_spec_info(_, TypeSpecForcePreds, _, _) },
-	{ map__lookup(PredTable, PredId, PredInfo) },
-
-	( 	
-		{ pred_info_is_exported(PredInfo) },
-		\+ { code_util__predinfo_is_builtin(PredInfo) },
-		\+ { code_util__compiler_generated(PredInfo) },
-		% XXX These should be allowed, but the predicate
-		% declaration for the specialized predicate is not produced 
-		% before the termination pragmas are read in, resulting
-		% in an undefined predicate error.
-		\+ { set__member(PredId, TypeSpecForcePreds) }
-	->
-		% All predicates to write predicate info into the .trans_opt 
-		% file should go here.
-
-		{ pred_info_procedures(PredInfo, ProcTable) },
-		{ map__keys(ProcTable, ProcIds) },
-		trans_opt__write_procs(ProcIds, PredId, PredInfo)
-	;
-		[]
-	),
-	trans_opt__write_preds(PredIds, Module).
-	
-:- pred trans_opt__write_procs(list(proc_id), pred_id, pred_info, 
-	io__state, io__state).
-:- mode trans_opt__write_procs(in, in, in, di, uo) is det.
-
-trans_opt__write_procs([], _, _) --> [].
-trans_opt__write_procs([ProcId | ProcIds], PredId, PredInfo) -->
-	{ pred_info_procedures(PredInfo, ProcTable) },
-	{ map__lookup(ProcTable, ProcId, ProcInfo) },
-	{ pred_info_name(PredInfo, PredName) },
-	{ pred_info_module(PredInfo, ModuleName) },
-	{ pred_info_get_is_pred_or_func(PredInfo, PredOrFunc) },
-	{ pred_info_context(PredInfo, Context) },
-	{ SymName = qualified(ModuleName, PredName) },
-	{ proc_info_get_maybe_arg_size_info(ProcInfo, ArgSize) },
-	{ proc_info_get_maybe_termination_info(ProcInfo, Termination) },
-	{ proc_info_declared_argmodes(ProcInfo, ModeList) },
-
-	% All predicates to write procedure items into the .trans_opt file
-	% should go here.
-	termination__write_pragma_termination_info(PredOrFunc, SymName,
-		ModeList, Context, ArgSize, Termination),
-	
-	trans_opt__write_procs(ProcIds, PredId, PredInfo).
 
 %-----------------------------------------------------------------------------%
 	% Read in and process the transitive optimization interfaces.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list