[m-dev.] for review: reduce intermodule dependencies

Fergus Henderson fjh at cs.mu.OZ.AU
Wed Jul 7 04:42:17 AEST 1999


Estimated hours taken: 4

Move some declarations around and make some other minor changes
in order to reduce the complexity of the intermodule dependencies. 
In particular, ensure that prog_data.m does not need to import
hlds*.m, purity.m, rl.m, or term_util.m.

Since we expect to have only one input language, but potentially many
different target languages, the general design principle that we have adopted
in order to minimize the number of dependencies, particularly cyclic ones,
is that modules which belong to an earlier stage of compilation should
not depend on modules which belong to a later stage of compilation.
However, that design principle has not been adhered to in many cases.
This change reduces the number of such cases.

compiler/prog_data.m:
compiler/hlds_pred.m:
	Move definition of the types `eval_method' and `pred_or_func'
	from hlds_pred.m to prog_data.m.
	Add new type `mode_num' to prog_data.m, defined by
	`type mode_num == int', and change the proc_id argument of
	the `unused_args' pragma to instead use this type instead of proc_id.
	Delete the import of module hlds_pred from prog_data.m.

compiler/prog_data.m:
compiler/hlds_data.m:
	Move the definition of the type `determinism' from hlds_data.m to
	prog_data.m.  Delete the import of module hlds_data from prog_data.m.

compiler/prog_data.m:
compiler/purity.m:
	Move the definition of the type `purity' from purity.m to prog_data.m.
	Add import of module prog_data to purity.m.
	Delete the import of module purity from prog_data.m.

	This is needed because purity.m imports hlds*.m and so by
	importing purity.m, prog_data.m was indirectly importing hlds*.m.

	(An possible alternative here would be to split purity.m into two
	parts, called say purity.m and check_purity.m; of these, only the
	second would import hlds*.m.  But that would be a significantly
	more complicated change.)

compiler/prog_data.m:
compiler/rl.m:
	Move the definition of the `index_spec' and `index_type' types from
	rl.m to prog_data.m.  Delete the import of module rl from prog_data.m.

compiler/prog_data.m:
	Add new types `pragma_arg_size_info' and `pragma_termination_info'
	to prog_data.m.  These are similar to the existing types 
	`arg_size_info' and `termination_info' defined in term_util.m,
	except that they correspond more directly to what is actually
	used in `pragma termination_info' declarations.

compiler/term_util.m:
	Add new predicates `add_context_to_arg_size_info' and
	`add_context_to_pragma_termination_info' for converting
	the prog_data types to their corresponding term_util types.

compiler/make_hlds.m:
compiler/mercury_to_mercury.m:
compiler/prog_io_pragma.m:
compiler/unused_args.m:
	Minor modifications to handle the change in the type of the
	mode number argument in `unused_args' pragmas, and in the types
	of the arg_size_info and termination_info arguments in
	`termination_info' pragmas.

compiler/mercury_to_mercury.m:
compiler/prog_io_pragma.m:
compiler/inst.m:
compiler/make_hlds.m:
	Delete imports of modules purity, rl, and hlds_pred, or
	move them from the interface section to the implementation section.

compiler/inst.m:
	Add an XXX comment about the import of module hlds_data.

Workspace: /home/mercury0/fjh/mercury-other
Index: compiler/hlds_data.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/hlds_data.m,v
retrieving revision 1.34
diff -u -r1.34 hlds_data.m
--- hlds_data.m	1999/04/22 01:04:08	1.34
+++ hlds_data.m	1999/07/06 15:56:44
@@ -668,14 +668,10 @@
 %-----------------------------------------------------------------------------%
 :- interface.
 
-:- type determinism	--->	det
-			;	semidet
-			;	nondet
-			;	multidet
-			;	cc_nondet
-			;	cc_multidet
-			;	erroneous
-			;	failure.
+%
+% Types and procedures for decomposing and analysing determinism.
+% The `determinism' type itself is defined in prog_data.m.
+%
 
 :- type can_fail	--->	can_fail
 			;	cannot_fail.
Index: compiler/hlds_pred.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/hlds_pred.m,v
retrieving revision 1.59
diff -u -r1.59 hlds_pred.m
--- hlds_pred.m	1999/06/30 17:12:25	1.59
+++ hlds_pred.m	1999/07/06 15:17:34
@@ -181,15 +181,6 @@
 			;	clauses		
 			;	none.
 
-	% The evaluation method that should be used for a pred.
-	% Ignored for Aditi procedures.
-:- type eval_method	--->	eval_normal		% normal mercury 
-							% evaluation
-			;	eval_loop_check		% loop check only
-			;	eval_memo		% memoing + loop check 
-			;	eval_minimal.		% minimal model 
-							% evaluation 
-							
 	% Note: `liveness' and `liveness_info' record liveness in the sense
 	% used by code generation.  This is *not* the same thing as the notion
 	% of liveness used by mode analysis!  See compiler/notes/glossary.html.
@@ -262,18 +253,6 @@
 	% status_is_imported.
 :- pred status_defined_in_this_module(import_status::in, bool::out) is det.
 
-	% N-ary functions are converted into N+1-ary predicates.
-	% (Clauses are converted in make_hlds, but calls to functions
-	% cannot be converted until after type-checking, once we have
-	% resolved overloading. So we do that during mode analysis.)
-	% The `is_pred_or_func' field of the pred_info records whether
-	% a pred_info is really for a predicate or whether it is for
-	% what was originally a function.
-
-:- type pred_or_func
-	--->	predicate
-	;	function.
-
 	% Predicates can be marked with various boolean flags, called
 	% "markers".
 
@@ -588,6 +567,14 @@
 
 :- pred pred_info_requested_no_inlining(pred_info).
 :- mode pred_info_requested_no_inlining(in) is semidet.
+
+	% N-ary functions are converted into N+1-ary predicates.
+	% (Clauses are converted in make_hlds, but calls to functions
+	% cannot be converted until after type-checking, once we have
+	% resolved overloading. So we do that during mode analysis.)
+	% The `is_pred_or_func' field of the pred_info records whether
+	% a pred_info is really for a predicate or whether it is for
+	% what was originally a function.
 
 :- pred pred_info_get_is_pred_or_func(pred_info, pred_or_func).
 :- mode pred_info_get_is_pred_or_func(in, out) is det.
Index: compiler/inst.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/inst.m,v
retrieving revision 1.5
diff -u -r1.5 inst.m
--- inst.m	1998/11/20 04:07:54	1.5
+++ inst.m	1999/07/06 17:14:19
@@ -12,7 +12,17 @@
 :- module (inst).
 :- interface.
 
-:- import_module prog_data, hlds_data, hlds_pred.
+% This module should NOT import hlds*.m.  Any types which are needed in
+% both the insts and in the HLDS should be defined here, rather than
+% in hlds*.m, because insts are part of the parse tree and the parse tree
+% should not depend on the HLDS.
+%
+% XXX Currently we have to import hlds_data for the `cons_id' type.
+%     I think the cons_ids in insts only use a subset of the functors
+%     of the `cons_id' type, and so we could define a new type
+%     `abstract_cons_id' and use that here instead of `cons_id'.
+
+:- import_module prog_data, hlds_data.
 :- import_module list, std_util.
 
 %-----------------------------------------------------------------------------%
Index: compiler/make_hlds.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/make_hlds.m,v
retrieving revision 1.296
diff -u -r1.296 make_hlds.m
--- make_hlds.m	1999/06/30 17:12:27	1.296
+++ make_hlds.m	1999/07/06 18:30:13
@@ -22,7 +22,7 @@
 :- module make_hlds.
 :- interface.
 
-:- import_module prog_data, hlds_module, hlds_pred, hlds_goal, hlds_data.
+:- import_module prog_data, hlds_module, hlds_pred, hlds_goal.
 :- import_module equiv_type, module_qual.
 
 :- import_module io, std_util, list, bool.
@@ -56,6 +56,7 @@
 
 :- implementation.
 
+:- import_module hlds_data.
 :- import_module prog_io, prog_io_goal, prog_io_dcg, prog_io_util, prog_out.
 :- import_module modules, module_qual, prog_util, options, hlds_out.
 :- import_module make_tags, quantification, (inst), globals.
@@ -392,7 +393,7 @@
 			% Used for inter-module unused argument elimination.
 			% This can only appear in .opt files.
 		{ Pragma = unused_args(PredOrFunc, SymName,
-				Arity, ProcId, UnusedArgs) },
+				Arity, ModeNum, UnusedArgs) },
 		( { ImportStatus \= opt_imported } ->
 			prog_out__write_context(Context),
 			io__write_string(
@@ -400,7 +401,7 @@
 			{ module_info_incr_errors(Module0, Module) }
 		;
 			add_pragma_unused_args(PredOrFunc, SymName, Arity,
-				ProcId, UnusedArgs, Context, Module0, Module)
+				ModeNum, UnusedArgs, Context, Module0, Module)
 		)
 	;
 		{ Pragma = type_spec(Name, SpecName, Arity, PorF,
@@ -755,19 +756,21 @@
 
 %-----------------------------------------------------------------------------%
 
-:- pred add_pragma_unused_args(pred_or_func, sym_name, arity, proc_id,
+:- pred add_pragma_unused_args(pred_or_func, sym_name, arity, mode_num,
 		list(int), prog_context, module_info, module_info,
 		io__state, io__state).
 :- mode add_pragma_unused_args(in, in, in, in, in, in, in, out, di, uo) is det.
 
-add_pragma_unused_args(PredOrFunc, SymName, Arity, ProcId, UnusedArgs, Context,
-		Module0, Module) -->
+add_pragma_unused_args(PredOrFunc, SymName, Arity, ModeNum, UnusedArgs,
+		Context, Module0, Module) -->
 	{ module_info_get_predicate_table(Module0, Preds) },
 	(
 		{ predicate_table_search_pf_sym_arity(Preds,
 			PredOrFunc, SymName, Arity, [PredId]) }
 	->
 		{ module_info_unused_arg_info(Module0, UnusedArgInfo0) },
+		% convert the mode number to a proc_id
+		{ proc_id_to_int(ProcId, ModeNum) },
 		{ map__set(UnusedArgInfo0, proc(PredId, ProcId), UnusedArgs,
 			UnusedArgInfo) },
 		{ module_info_set_unused_arg_info(Module0, UnusedArgInfo,
@@ -1158,13 +1161,14 @@
 %-----------------------------------------------------------------------------%
 
 :- pred add_pragma_termination_info(pred_or_func, sym_name, list(mode),
-		maybe(arg_size_info), maybe(termination_info),
+		maybe(pragma_arg_size_info), maybe(pragma_termination_info),
 		prog_context, module_info, module_info, io__state, io__state).
 :- mode add_pragma_termination_info(in, in, in, in, in, in, in, out, di, uo)
 		is det.
 
-add_pragma_termination_info(PredOrFunc, SymName, ModeList, MaybeArgSizeInfo,
-		MaybeTerminationInfo, Context, Module0, Module) -->
+add_pragma_termination_info(PredOrFunc, SymName, ModeList,
+		MaybePragmaArgSizeInfo, MaybePragmaTerminationInfo,
+		Context, Module0, Module) -->
 	{ module_info_get_predicate_table(Module0, Preds) },
 	{ list__length(ModeList, Arity) },
 	(
@@ -1181,6 +1185,11 @@
 			{ get_procedure_matching_declmodes(ProcList, 
 				ModeList, Module0, ProcId) }
 		->
+			{ add_context_to_arg_size_info(MaybePragmaArgSizeInfo,
+				Context, MaybeArgSizeInfo) },
+			{ add_context_to_termination_info(
+				MaybePragmaTerminationInfo, Context,
+				MaybeTerminationInfo) },
 			{ map__lookup(ProcTable0, ProcId, ProcInfo0) },
 			{ proc_info_set_maybe_arg_size_info(ProcInfo0, 
 				MaybeArgSizeInfo, ProcInfo1) },
Index: compiler/mercury_to_mercury.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mercury_to_mercury.m,v
retrieving revision 1.157
diff -u -r1.157 mercury_to_mercury.m
--- mercury_to_mercury.m	1999/06/09 16:39:34	1.157
+++ mercury_to_mercury.m	1999/07/06 18:23:28
@@ -23,8 +23,7 @@
 						% is another graphic token
 	;	not_next_to_graphic_token.	% doesn't need quotes
 
-:- import_module hlds_goal, hlds_data, hlds_pred, prog_data, (inst), purity.
-:- import_module rl.
+:- import_module hlds_goal, hlds_data, prog_data, (inst).
 :- import_module bool, std_util, list, io, varset, term.
 
 %	convert_to_mercury(ModuleName, OutputFileName, Items)
@@ -78,7 +77,7 @@
 :- mode mercury_output_pragma_c_code(in, in, in, in, in, in, di, uo) is det.
 
 :- pred mercury_output_pragma_unused_args(pred_or_func, sym_name,
-		int, proc_id, list(int), io__state, io__state) is det.
+		int, mode_num, list(int), io__state, io__state) is det.
 :- mode mercury_output_pragma_unused_args(in, in, in, in, in, di, uo) is det.
 
 	% Write an Aditi index specifier.
@@ -208,6 +207,7 @@
 :- implementation.
 
 :- import_module prog_out, prog_util, hlds_pred, hlds_out, instmap.
+:- import_module purity, term_util.
 :- import_module globals, options, termination.
 
 :- import_module assoc_list, char, int, string, set, lexer, require.
@@ -358,9 +358,9 @@
 		mercury_output_pragma_decl(Pred, Arity, predicate, "no_inline")
 	;
 		{ Pragma = unused_args(PredOrFunc, PredName,
-			Arity, ProcId, UnusedArgs) },
+			Arity, ModeNum, UnusedArgs) },
 		mercury_output_pragma_unused_args(PredOrFunc,
-			PredName, Arity, ProcId, UnusedArgs)
+			PredName, Arity, ModeNum, UnusedArgs)
 	;
 		{ Pragma = fact_table(Pred, Arity, FileName) },
 		mercury_output_pragma_fact_table(Pred, Arity, FileName)
@@ -405,7 +405,12 @@
 					   "promise_pure")
 	;
 		{ Pragma = termination_info(PredOrFunc, PredName, 
-			ModeList, MaybeArgSizeInfo, MaybeTerminationInfo) },
+			ModeList, MaybePragmaArgSizeInfo,
+			MaybePragmaTerminationInfo) },
+		{ add_context_to_arg_size_info(MaybePragmaArgSizeInfo, Context,
+			MaybeArgSizeInfo) },
+		{ add_context_to_termination_info(MaybePragmaTerminationInfo,
+			Context, MaybeTerminationInfo) },
 		termination__write_pragma_termination_info(PredOrFunc,
 			PredName, ModeList, Context,
 			MaybeArgSizeInfo, MaybeTerminationInfo)
@@ -2242,7 +2247,7 @@
 %-----------------------------------------------------------------------------%
 
 mercury_output_pragma_unused_args(PredOrFunc, SymName,
-		Arity, ProcId, UnusedArgs) -->
+		Arity, ModeNum, UnusedArgs) -->
 	io__write_string(":- pragma unused_args("),
 	hlds_out__write_pred_or_func(PredOrFunc),
 	io__write_string(", "),
@@ -2250,8 +2255,7 @@
 	io__write_string(", "),
 	io__write_int(Arity),
 	io__write_string(", "),
-	{ proc_id_to_int(ProcId, ProcInt) },
-	io__write_int(ProcInt),
+	io__write_int(ModeNum),
 	io__write_string(", ["),
 	mercury_output_int_list(UnusedArgs),
 	io__write_string("]).\n").
Index: compiler/prog_data.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/prog_data.m,v
retrieving revision 1.45
diff -u -r1.45 prog_data.m
--- prog_data.m	1999/04/23 01:02:58	1.45
+++ prog_data.m	1999/07/06 18:18:37
@@ -18,9 +18,13 @@
 
 :- interface.
 
-:- import_module hlds_data, hlds_pred, (inst), purity, rl, term_util.
-:- import_module assoc_list, list, map, varset, term, std_util.
+% This module should NOT import hlds*.m, either directly or indirectly.
+% Any types which are needed in both the parse tree and in the HLDS
+% should be defined here, rather than in hlds*.m.
 
+:- import_module (inst).
+:- import_module bool, list, assoc_list, map, varset, term, std_util.
+
 %-----------------------------------------------------------------------------%
 
 	% This is how programs (and parse errors) are represented.
@@ -98,6 +102,35 @@
 	--->	type_only(type)
 	;	type_and_mode(type, mode).
 
+:- type pred_or_func
+	--->	predicate
+	;	function.
+
+	% Purity indicates whether a goal can have side effects or can
+	% depend on global state.  See purity.m and the "Purity" section
+	% of the Mercury language reference manual.
+:- type purity		--->	pure
+			;	(semipure)
+			;	(impure).
+
+	% The `determinism' type specifies how many solutions a given
+	% procedure may have.  Procedures for manipulating this type
+	% are defined in det_analysis.m and hlds_data.m.
+:- type determinism	
+	--->	det
+	;	semidet
+	;	nondet
+	;	multidet
+	;	cc_nondet
+	;	cc_multidet
+	;	erroneous
+	;	failure.
+
+%-----------------------------------------------------------------------------%
+%
+% Pragmas
+%
+
 :- type pragma_type 
 	--->	c_header_code(string)
 
@@ -143,9 +176,9 @@
 	;	source_file(string)
 			% Source file name.
 
-	;	unused_args(pred_or_func, sym_name, int,
-			proc_id, list(int))
-			% PredName, Arity, Mode, Optimized pred name,
+	;	unused_args(pred_or_func, sym_name, arity,
+			mode_num, list(int))
+			% PredName, Arity, Mode number, Optimized pred name,
 			% 	Removed arguments.
 			% Used for inter-module unused argument
 			% removal, should only appear in .opt files.
@@ -200,7 +233,8 @@
 			% Predname, Arity
 
 	;	termination_info(pred_or_func, sym_name, list(mode),
-			maybe(arg_size_info), maybe(termination_info))
+				maybe(pragma_arg_size_info),
+				maybe(pragma_termination_info))
 			% the list(mode) is the declared argmodes of the
 			% procedure, unless there are no declared argmodes,
 			% in which case the inferred argmodes are used.
@@ -222,12 +256,86 @@
 	;	check_termination(sym_name, arity).
 			% Predname, Arity
 
+%
+% Stuff for tabling pragmas
+%
+
+	% The evaluation method that should be used for a pred.
+	% Ignored for Aditi procedures.
+:- type eval_method
+	--->	eval_normal		% normal mercury 
+					% evaluation
+	;	eval_loop_check		% loop check only
+	;	eval_memo		% memoing + loop check 
+	;	eval_minimal.		% minimal model 
+					% evaluation 
+%
+% Stuff for the `aditi_index' pragma
+%
+
+	% For Aditi base relations, an index_spec specifies how the base
+	% relation is indexed.
+:- type index_spec
+	---> index_spec(
+		index_type,
+		list(int)	% which attributes are being indexed on.
+	).
+
+	% Hash indexes?
+:- type index_type
+	--->	unique_B_tree
+	;	non_unique_B_tree.
+
+%
+% Stuff for the `termination_info' pragma.
+% See term_util.m.
+%
+
+:- type pragma_arg_size_info
+	--->	finite(int, list(bool))
+				% The termination constant is a finite integer.
+				% The list of bool has a 1:1 correspondence
+				% with the input arguments of the procedure.
+				% It stores whether the argument contributes
+				% to the size of the output arguments.
+	;	infinite.
+				% There is no finite integer for which the
+				% above equation is true.
+
+:- type pragma_termination_info
+	---> 	cannot_loop	% This procedure definitely terminates for all
+				% possible inputs.
+	;	can_loop.	% This procedure might not terminate.
+
+
+%
+% Stuff for the `unused_args' pragma.
+%
+
+	% This `mode_num' type is only used for mode numbers written out in
+	% automatically-generateed `pragma unused_args' pragmas in `.opt'
+	% files. 
+	% The mode_num gets converted to an HLDS proc_id by make_hlds.m.
+	% We don't want to use the `proc_id' type here since the parse tree
+	% (prog_data.m) should not depend on the HLDS.
+:- type mode_num == int.
+
+%
+% Stuff for the `type_spec' pragma.
+%
+
 	% The type substitution for a `pragma type_spec' declaration.
+	% Elsewhere in the compiler we generally use the `tsubst' type
+	% which is a map rather than an assoc_list.
 :- type type_subst == assoc_list(tvar, type).
 
+%
+% Stuff for `c_code' pragma.
+%
+
 	% This type holds information about the implementation details
 	% of procedures defined via `pragma c_code'.
-
+	%
 	% All the strings in this type may be accompanied by the context
 	% of their appearance in the source code. These contexts are
 	% used to tell the C compiler where the included C code comes from,
@@ -283,6 +391,11 @@
 	;	share
 	;	automatic.
 
+%-----------------------------------------------------------------------------%
+%
+% Stuff for type classes
+%
+
 	% A class constraint represents a constraint that a given
 	% list of types is a member of the specified type class.
 	% It is an invariant of this data structure that
@@ -357,6 +470,11 @@
 
 :- type instance_methods ==	list(instance_method).
 
+%-----------------------------------------------------------------------------%
+%
+% Some more stuff for `pragma c_code'.
+%
+
 		% an abstract type for representing a set of
 		% `pragma_c_code_attribute's.
 :- type pragma_c_code_attributes.
@@ -400,6 +518,9 @@
 		% name in code_gen
 
 %-----------------------------------------------------------------------------%
+%
+% Goals
+%
 
 	% Here's how clauses and goals are represented.
 	% a => b --> implies(a, b)
@@ -441,6 +562,7 @@
 	;	call(sym_name, list(prog_term), purity)
 	;	unify(prog_term, prog_term).
 
+:- type goals		==	list(goal).
 
 	% These type equivalences are for the type of program variables
 	% and associated structures.
@@ -456,9 +578,10 @@
 
 :- type prog_context	==	term__context.
 
-:- type goals		==	list(goal).
-
 %-----------------------------------------------------------------------------%
+%
+% Types
+%
 
 	% This is how types are represented.
 
@@ -523,11 +646,16 @@
 	;	where(term).
 
 %-----------------------------------------------------------------------------%
+%
+% insts and modes
+%
 
 	% This is how instantiatednesses and modes are represented.
 	% Note that while we use the normal term data structure to represent 
 	% type terms (see above), we need a separate data structure for inst 
-	% terms.
+	% terms. 
+
+	% The `inst' data type itself is defined in the module `inst.m'.
 
 :- type inst_var_type	--->	inst_var_type.
 :- type inst_var	==	var(inst_var_type).
@@ -611,6 +739,9 @@
 % mode/4 defined above
 
 %-----------------------------------------------------------------------------%
+%
+% Module system
+%
 
 	% This is how module-system declarations (such as imports
 	% and exports) are represented.
@@ -717,6 +848,7 @@
 	;	may_be_unqualified.
 
 %-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
 
 :- implementation.
 
@@ -741,3 +873,5 @@
 set_thread_safe(Attrs0, ThreadSafe, Attrs) :-
 	Attrs0 = attributes(MayCallMercury, _),
 	Attrs  = attributes(MayCallMercury, ThreadSafe).
+
+%-----------------------------------------------------------------------------%
Index: compiler/prog_io_pragma.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/prog_io_pragma.m,v
retrieving revision 1.19
diff -u -r1.19 prog_io_pragma.m
--- prog_io_pragma.m	1999/04/23 01:02:59	1.19
+++ prog_io_pragma.m	1999/07/06 17:59:43
@@ -22,8 +22,8 @@
 
 :- implementation.
 
-:- import_module prog_io, prog_io_goal, prog_util, hlds_pred.
-:- import_module term_util, term_errors, rl.
+:- import_module prog_io, prog_io_goal, prog_util.
+:- import_module term_util, term_errors.
 :- import_module int, map, string, std_util, bool, require.
 
 parse_pragma(ModuleName, VarSet, PragmaTerms, Result) :-
@@ -336,10 +336,9 @@
 			PredOrFuncTerm,
 			PredNameTerm,
 			term__functor(term__integer(Arity), [], _),
-			term__functor(term__integer(ProcInt), [], _),
+			term__functor(term__integer(ModeNum), [], _),
 			UnusedArgsTerm
 		],
-		proc_id_to_int(ProcId, ProcInt),
 		(
 			PredOrFuncTerm = term__functor(
 					term__atom("predicate"), [], _),
@@ -357,7 +356,7 @@
 		UnusedArgsResult = ok(UnusedArgs)
 	->	
 		Result = ok(pragma(unused_args(PredOrFunc, PredName,
-				Arity, ProcId, UnusedArgs)))
+				Arity, ModeNum, UnusedArgs)))
 	;
 		Result = error("error in `:- pragma unused_args'", ErrorTerm)
 	).
@@ -585,10 +584,8 @@
 		ArgSizeTerm = term__functor(term__atom("not_set"), [], _),
 		MaybeArgSizeInfo = no
 	;
-		ArgSizeTerm = term__functor(term__atom("infinite"), [],
-			ArgSizeContext),
-		MaybeArgSizeInfo = yes(infinite(
-			[ArgSizeContext - imported_pred]))
+		ArgSizeTerm = term__functor(term__atom("infinite"), [], _),
+		MaybeArgSizeInfo = yes(infinite)
 	;
 		ArgSizeTerm = term__functor(term__atom("finite"),
 			[IntTerm, UsedArgsTerm], _),
@@ -600,17 +597,15 @@
 		TerminationTerm = term__functor(term__atom("not_set"), [], _),
 		MaybeTerminationInfo = no
 	;
-		TerminationTerm = term__functor(term__atom("can_loop"),
-			[], TermContext),
-		MaybeTerminationInfo = yes(can_loop(
-			[TermContext - imported_pred]))
+		TerminationTerm = term__functor(term__atom("can_loop"), [], _),
+		MaybeTerminationInfo = yes(can_loop)
 	;
 		TerminationTerm = term__functor(term__atom("cannot_loop"),
 			[], _),
 		MaybeTerminationInfo = yes(cannot_loop)
 	),
 	Result0 = ok(pragma(termination_info(PredOrFunc, PredName, 
-	ModeList, MaybeArgSizeInfo, MaybeTerminationInfo)))
+			ModeList, MaybeArgSizeInfo, MaybeTerminationInfo)))
     ->
 	Result = Result0
     ;
Index: compiler/purity.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/purity.m,v
retrieving revision 1.14
diff -u -r1.14 purity.m
--- purity.m	1999/06/30 17:12:38	1.14
+++ purity.m	1999/07/06 16:04:01
@@ -79,13 +79,13 @@
 :- module purity.
 :- interface.
 
-:- import_module hlds_module, hlds_goal.
+:- import_module prog_data, hlds_module, hlds_goal.
 :- import_module io, bool.
 
-:- type purity		--->	pure
-			;	(semipure)
-			;	(impure).
-
+% The purity type itself is defined in prog_data.m as follows:
+% :- type purity	--->	pure
+% 			;	(semipure)
+% 			;	(impure).
 
 %  Purity check a whole module.
 %  The first argument specifies whether there were any type
Index: compiler/rl.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/rl.m,v
retrieving revision 1.4
diff -u -r1.4 rl.m
--- rl.m	1999/06/24 02:07:19	1.4
+++ rl.m	1999/07/06 16:34:49
@@ -74,17 +74,6 @@
 
 %-----------------------------------------------------------------------------%
 
-:- type index_spec
-	---> index_spec(
-		index_type,
-		list(int)	% which attributes are being indexed on.
-	).
-
-	% Hash indexes?
-:- type index_type
-	--->	unique_B_tree
-	;	non_unique_B_tree.
-
 	% A key range gives an upper and lower bound for the part of the
 	% indexed relation to search. For example, a simple B-tree join
 	% algorithm takes a tuple from first relation and uses it to build
Index: compiler/term_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/term_util.m,v
retrieving revision 1.11
diff -u -r1.11 term_util.m
--- term_util.m	1998/11/20 04:09:27	1.11
+++ term_util.m	1999/07/06 18:34:05
@@ -25,6 +25,16 @@
 :- import_module std_util, bool, int, list, map, bag.
 
 %-----------------------------------------------------------------------------%
+%
+% The types `arg_size_info' and `termination_info' hold information
+% about procedures which is used for termination analysis.
+% These types are stored as fields in the HLDS proc_info.
+% For cross-module analysis, the information is written out as
+% `pragma termination_info(...)' declarations in the
+% `.opt' and `.trans_opt' files.  The module prog_data.m defines
+% types similar to these two (but without the `list(term_errors__error)')
+% which are used when parsing `termination_info' pragmas.
+%
 
 % The arg size info defines an upper bound on the difference
 % between the sizes of the output arguments of a procedure and the sizes
@@ -56,6 +66,9 @@
 				% The analysis could not prove that the
 				% procedure terminates.
 
+% The type `used_args' holds a mapping which specifies for each procedure
+% which of its arguments are used.
+
 :- type used_args	==	map(pred_proc_id, list(bool)).
 
 %-----------------------------------------------------------------------------%
@@ -174,6 +187,22 @@
 	prog_context::out) is det.
 
 %-----------------------------------------------------------------------------%
+
+% Convert a prog_data:pragma_termination_info into a
+% term_util:termination_info, by adding the appropriate context.
+
+:- pred add_context_to_termination_info(maybe(pragma_termination_info),
+		prog_context, maybe(termination_info)).
+:- mode add_context_to_termination_info(in, in, out) is det.
+
+% Convert a prog_data:pragma_arg_size_info into a
+% term_util:arg_size_info, by adding the appropriate context.
+
+:- pred add_context_to_arg_size_info(maybe(pragma_arg_size_info),
+		prog_context, maybe(arg_size_info)).
+:- mode add_context_to_arg_size_info(in, in, out) is det.
+
+%-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
 
 :- implementation.
@@ -553,5 +582,17 @@
 	;
 		error("Empty SCC in pass 2 of termination analysis")
 	).
+
+%-----------------------------------------------------------------------------%
+
+add_context_to_termination_info(no, _, no).
+add_context_to_termination_info(yes(cannot_loop), _, yes(cannot_loop)).
+add_context_to_termination_info(yes(can_loop), Context,
+		yes(can_loop([Context - imported_pred]))).
+
+add_context_to_arg_size_info(no, _, no).
+add_context_to_arg_size_info(yes(finite(A, B)), _, yes(finite(A, B))).
+add_context_to_arg_size_info(yes(infinite), Context,
+				yes(infinite([Context - imported_pred]))).
 
 %-----------------------------------------------------------------------------%
Index: compiler/unused_args.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/unused_args.m,v
retrieving revision 1.57
diff -u -r1.57 unused_args.m
--- unused_args.m	1999/06/30 17:12:46	1.57
+++ unused_args.m	1999/07/06 15:35:44
@@ -1519,8 +1519,9 @@
 		{ pred_info_arity(PredInfo, Arity) },
 		{ pred_info_get_is_pred_or_func(PredInfo, PredOrFunc) },
 		io__set_output_stream(OptStream, OldOutput),	
+		{ proc_id_to_int(ProcId, ModeNum) },
 		mercury_output_pragma_unused_args(PredOrFunc,
-			qualified(Module, Name), Arity, ProcId, UnusedArgs),
+			qualified(Module, Name), Arity, ModeNum, UnusedArgs),
 		io__set_output_stream(OldOutput, _)
 	;
 		[]

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