for review: Aditi round 2 [1]

Simon Taylor stayl at cs.mu.OZ.AU
Thu Jul 30 13:43:07 AEST 1998


Hi Fergus,

You asked for a relative diff for the second round, but a bit too
much has changed since then (nested modules and existential types) for
that to be useful for some files, so I've included the full diff for them.

Simon.

Revised log message:

Estimated hours taken: 1000

Aditi compilation.

compiler/options.m:
	The documentation for these is commented out because the Aditi
	system is not currently useful to the general public. 
	--aditi: enable Aditi compilation.
	--dump-rl: write the intermediate RL to `<module>.rl_dump'.
	--dump-rl-bytecode: write a text version of the bytecodes 
		to `<module>.rla'
	--aditi-only: don't produce a `.c' file.
	--filenames-from-stdin: accept a list of filenames to compile
		from stdin. This is used by the query shell.
	--optimize-rl, --optimize-rl-cse, --optimize-rl-invariants,
	--detect-rl-streams:
		Options to control RL optimization passes which are not
		implemented or are not ready to commit yet.
	--aditi-user:
		Default owner of any Aditi procedures, defaults to $USER.
	--generate-schemas:
		write schemas for base relations to `<module>'.base_schema
		and schemas for derived relations to `<module>'.derived_schema.
		This is used by the query shell.

compiler/handle_options.m:
	Set --aditi-user to $USER or "guest" if it is not already set.

compiler/globals.m:
	Add a field to record whether there are any local Aditi procedures
	in the current module.

compiler/hlds_pred.m:
compiler/prog_data.m:
compiler/prog_io_pragma.m:
compiler/make_hlds.m:
	Add some Aditi pragma declarations - `aditi', `supp_magic', `context',
	`naive', `psn' (predicate semi-naive), `aditi_memo', `aditi_no_memo',
	`base_relation' and `owner'.

compiler/hlds_pred.m:
	Add predicates to identify Aditi procedures.
	Added markers `generate_inline' and `aditi_interface', which
	are used internally for Aditi code generation.
	Add an `owner' field to pred_infos, which is used for database
	security checks.

compiler/make_hlds.m:
	Some pragmas must be exported if the corresponding predicates
	are exported, check this.
	Make sure stratification of Aditi procedures is checked.
	Set the `do_aditi_compilation' field of the module_info if there
	are any local Aditi procedures or base relations.
	Check that `--aditi' is set if Aditi compilation is required.

compiler/post_typecheck.m:
	Check that every Aditi predicate has an `aditi__state' argument,
	which is used to ensure sequencing of updates and that Aditi
	procedures are only called within transactions.

compiler/dnf.m:
	Changed the definition of disjunctive normal form slightly
	so that a call followed by some atomic goals not including 
	any database calls is considered atomic. magic.m can handle
	this kind of goal, and it results in more efficient RL code.

compiler/hlds_module.m:
compiler/dependency_graph.m:
	Added dependency_graph__get_scc_entry_points which finds
	the procedures in an SCC which could be called from outside.
	Added a new field to the dependency_info, the
	aditi_dependency_ordering. This contains all Aditi SCCs of
	the original program, with multiple SCCs merged where
	possible to improve the effectiveness of differential evaluation
	and the low level RL optimizations. 

compiler/hlds_module.m:
	Added versions of module_info_pred_proc_info and 
	module_info_set_pred_proc_info which take a pred_proc_id,
	not a separate pred_id and proc_id.

compiler/polymorphism.m:
compiler/lambda.m:
	Make sure that predicates created for closures in Aditi procedures
	have the correct markers.

compiler/goal_util.m:
	Added goal_util__switch_to_disjunction,
	goal_util__case_to_disjunct (factored out from simplify.m)
	and goal_util__if_then_else_to_disjunction. These are
	require because supplementary magic sets can't handle 
	if-then-elses or switches.

compiler/type_util.m:
	Added type_is_aditi_state/1.

compiler/mode_util.m:
	Added partition_args/5 which partitions a list of arguments
	into inputs and others.

compiler/inlining.m:
	Don't inline memoed procedures.
	Don't inline Aditi procedures into non-Aditi procedures.

compiler/simplify.m:
	Export a slightly different interface for use by magic.m.
	Remove explicit quantifications where possible.
	Merge multiple nested quantifications.
	Don't report infinite recursion warnings for Aditi procedures.

compiler/prog_out.m:
	Generalised the code to output a module list to write any list.

compiler/code_gen.m:
compiler/arg_info.m:
	Don't process Aditi procedures.

compiler/mercury_compile.m:
	Call magic.m and rl_gen.m.
	Don't perform some low-level annotation passes on Aditi procedures.

compiler/passes_aux.m:
	Add predicates to process only non-Aditi procedures.

compiler/llds.m:
compiler/llds_out.m:
	Added new `code_addr' enum members, do_{det,semidet,nondet}_aditi_call,
	which are defined in extras/aditi/aditi.m.

compiler/call_gen.m:
	Handle generation of do_*_aditi_call.

compiler/llds_out.m:
	Write the RL code for the module as a constant char array
	in the `.c' file.

compiler/term_errors.m:
compiler/error_util.m:
	Move code to describe predicates into error_util.m
	Allow the caller to explicitly add line breaks.
	Added error_util:list_to_pieces to format a list of
	strings.
	Reordered some arguments for currying.

compiler/hlds_out.m:
	Don't try to print clauses if there are none.

runtime/mercury_init.h:
util/mkinit.c:
scripts/c2init.in:
	Added a function `mercury__load_aditi_rl_code()' to the generated
	`<module>_init.c' file which throws all the RL code for the program
	at the database. This should be called at connection time by
	`aditi__connect'.
	Added an option `--aditi' which controls the output
	`mercury__load_aditi_rl_code()'.

compiler/notes/compiler_design.html:
	Document the new files.
	
New files:

compiler/magic.m:
compiler/magic_util.m:
	Supplementary magic sets transformation. Report errors 
	for constructs that Aditi can't handle.

compiler/context.m:
	Supplementary context transformation.

compiler/rl_gen.m:
	Aditi code generation.

compiler/rl_exprn.m:
	Generate join conditions.

compiler/rl_info.m:
	Code generator state.

compiler/rl.m:	
	Intermediate RL representation.

compiler/rl_dump.m: 
	Print out the representation in rl.m.

compiler/rl_opt.m:
compiler/rl_block.m:
compiler/rl_analyse.m:
compiler/rl_liveness.m:
	Make sure all relations are initialised before used, clear
	references to relations that are no longer required.

compiler/rl_code.m:
	RL bytecode definitions. Automatically generated from the Aditi 
	header files.

compiler/rl_out.m:
compiler/rl_file.m:
	Output the RL bytecodes in binary to <module>.rlo (for use by Aditi)
	and in text to <module>.rla (for use by the RL interpreter).
	Also output the schema information if --generate-schemas is set.

extras/aditi/aditi.m:
	Definitions of some Aditi library predicates and the 
	interfacing and transaction processing code.



Revised diff:

--- dependency_graph.m	1998/07/07 06:43:06	1.5
+++ dependency_graph.m	1998/07/16 00:27:26
@@ -731,7 +731,7 @@
 		dependency_graph__do_merge_aditi_sccs(SCCid, CalledSCCs, 
 			NoMergeSCCs, SCCs0, SCCs, SCCPreds, SCCRel, 
 			EqvSCCs0, EqvSCCs, 
-			aditi_sub_module([SCC0], EntryPoints), SCC),
+			aditi_scc([SCC0], EntryPoints), SCC),
 		Ordering1 = [SCC | Ordering0]
 	),
 	dependency_graph__merge_aditi_sccs_2(SCCs, EqvSCCs, MergedSCCs0,
@@ -754,7 +754,7 @@
 		set(scc_id)::in, list(scc_id)::in, list(scc_id)::out, 
 		scc_pred_map::in, relation(scc_id)::in, 
 		eqvclass(scc_id)::in, eqvclass(scc_id)::out, 
-		aditi_sub_module::in, aditi_sub_module::out) is det.
+		aditi_scc::in, aditi_scc::out) is det.
 
 dependency_graph__do_merge_aditi_sccs(_, _, _, [], [], 
 		_, _, Eqv, Eqv, SubModule, SubModule).
@@ -788,11 +788,8 @@
 			% would mean that the lower SCC was called from
 			% multiple places and could not be merged.
 			%
-			SubModule0 = 
-				aditi_sub_module(CurrSCCPreds0, EntryPoints),
-			SubModule1 = 
-				aditi_sub_module(
-					[LowerSCCPreds | CurrSCCPreds0], 
+			SubModule0 = aditi_scc(CurrSCCPreds0, EntryPoints),
+			SubModule1 = aditi_scc([LowerSCCPreds | CurrSCCPreds0], 
 					EntryPoints),
 
 			%




Index: hlds_module.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/hlds_module.m,v
retrieving revision 1.35
diff -u -t -u -r1.35 hlds_module.m
--- hlds_module.m	1998/07/20 10:00:49	1.35
+++ hlds_module.m	1998/07/21 06:50:30
@@ -85,6 +85,12 @@
         % map from proc to a list of unused argument numbers.
 :- type unused_arg_info == map(pred_proc_id, list(int)).
 
+        % This field should be set to `do_aditi_compilation' if there
+        % are local Aditi predicates.
+:- type do_aditi_compilation
+        --->    do_aditi_compilation
+        ;       no_do_aditi_compilation.
+
 %-----------------------------------------------------------------------------%
 
         % Create an empty module_info for a given module name (and the
@@ -178,6 +184,9 @@
 :- pred module_info_globals(module_info, globals).
 :- mode module_info_globals(in, out) is det.
 
+:- pred module_info_set_globals(module_info, globals, module_info).
+:- mode module_info_set_globals(in, in, out) is det.
+
 :- pred module_info_get_c_header(module_info, c_header_info).
 :- mode module_info_get_c_header(in, out) is det.
 
@@ -240,6 +249,13 @@
         module_info).
 :- mode module_info_set_stratified_preds(in, in, out) is det.
 
+:- pred module_info_get_do_aditi_compilation(module_info,
+                do_aditi_compilation).
+:- mode module_info_get_do_aditi_compilation(in, out) is det.
+
+:- pred module_info_set_do_aditi_compilation(module_info, module_info).
+:- mode module_info_set_do_aditi_compilation(in, out) is det.
+
 %-----------------------------------------------------------------------------%
 
 :- pred module_info_preds(module_info, pred_table).
@@ -255,6 +271,10 @@
         pred_info, proc_info).
 :- mode module_info_pred_proc_info(in, in, in, out, out) is det.
 
+:- pred module_info_pred_proc_info(module_info, pred_proc_id,
+        pred_info, proc_info).
+:- mode module_info_pred_proc_info(in, in, out, out) is det.
+
         % Return a list of the pred_ids of all the "valid" predicates.
         % (Predicates whose definition contains a type error, etc.
         % get removed from this list, so that later passes can rely
@@ -289,6 +309,10 @@
         pred_id, proc_id, pred_info, proc_info, module_info).
 :- mode module_info_set_pred_proc_info(in, in, in, in, in, out) is det.
 
+:- pred module_info_set_pred_proc_info(module_info,
+        pred_proc_id, pred_info, proc_info, module_info).
+:- mode module_info_set_pred_proc_info(in, in, in, in, out) is det.
+
 :- pred module_info_typeids(module_info, list(type_id)).
 :- mode module_info_typeids(in, out) is det.
 
@@ -304,6 +328,10 @@
 :- pred module_info_dependency_info(module_info, dependency_info).
 :- mode module_info_dependency_info(in, out) is det.
 
+:- pred module_info_aditi_dependency_ordering(module_info, 
+                aditi_dependency_ordering).
+:- mode module_info_aditi_dependency_ordering(in, out) is det.
+
 :- pred module_info_set_dependency_info(module_info, dependency_info,
         module_info).
 :- mode module_info_set_dependency_info(in, in, out) is det.
@@ -366,6 +394,9 @@
 :- pred module_sub_get_globals(module_sub_info, globals).
 :- mode module_sub_get_globals(in, out) is det.
 
+:- pred module_sub_set_globals(module_sub_info, globals, module_sub_info).
+:- mode module_sub_set_globals(in, in, out) is det.
+
 :- pred module_sub_get_c_header_info(module_sub_info, c_header_info).
 :- mode module_sub_get_c_header_info(in, out) is det.
 
@@ -401,6 +432,10 @@
 :- pred module_sub_get_model_non_pragma_count(module_sub_info, int).
 :- mode module_sub_get_model_non_pragma_count(in, out) is det.
 
+:- pred module_sub_get_do_aditi_compilation(module_sub_info,
+                do_aditi_compilation).
+:- mode module_sub_get_do_aditi_compilation(in, out) is det.
+
 :- pred module_sub_set_c_header_info(module_sub_info, c_header_info,
         module_sub_info).
 :- mode module_sub_set_c_header_info(in, in, out) is det.
@@ -443,6 +478,9 @@
         module_sub_info).
 :- mode module_sub_set_model_non_pragma_count(in, in, out) is det.
 
+:- pred module_sub_set_do_aditi_compilation(module_sub_info, module_sub_info).
+:- mode module_sub_set_do_aditi_compilation(in, out) is det.
+
 :- type module_info
         --->    module(
                         module_sub_info,
@@ -486,8 +524,11 @@
                                         % predicates in the current
                                         % module which has been exported
                                         % in .opt files.
-                        int             % number of the structure types defined
+                        int,            % number of the structure types defined
                                         % so far for model_non pragma C codes
+                        do_aditi_compilation
+                                        % are there any local Aditi predicates
+                                        % for which Aditi-RL must be produced.
                 ).
 
         % A predicate which creates an empty module
@@ -507,7 +548,7 @@
         map__init(InstanceTable),
         map__init(SuperClassTable),
         ModuleSubInfo = module_sub(Name, Globals, [], [], no, 0, 0, [], 
-                [], [], StratPreds, UnusedArgInfo, 0),
+                [], [], StratPreds, UnusedArgInfo, 0, no_do_aditi_compilation),
         ModuleInfo = module(ModuleSubInfo, PredicateTable, Requests,
                 UnifyPredMap, ContinuationInfo, Types, Insts, Modes, Ctors,
                 ClassTable, SuperClassTable, InstanceTable, 0).
@@ -537,8 +578,11 @@
 %                                       % predicates in the current
 %                                       % module which has been exported
 %                                       % in .opt files.
-% M                     int             % number of the structure types defined
+% M                     int,            % number of the structure types defined
 %                                       % so far for model_non pragma C codes
+% N                     do_aditi_compilation,
+%                                       % are there any local Aditi predicates
+%                                       % for which Aditi-RL must be produced.
 %               ).
 
 %-----------------------------------------------------------------------------%
@@ -546,91 +590,103 @@
         % Various predicates which access the module_sub_info data structure.
 
 module_sub_get_name(MI0, A) :-
-        MI0 = module_sub(A, _, _, _, _, _, _, _, _, _, _, _, _).
+        MI0 = module_sub(A, _, _, _, _, _, _, _, _, _, _, _, _, _).
 
 module_sub_get_globals(MI0, B) :-
-        MI0 = module_sub(_, B, _, _, _, _, _, _, _, _, _, _, _).
+        MI0 = module_sub(_, B, _, _, _, _, _, _, _, _, _, _, _, _).
 
 module_sub_get_c_header_info(MI0, C) :-
-        MI0 = module_sub(_, _, C, _, _, _, _, _, _, _, _, _, _).
+        MI0 = module_sub(_, _, C, _, _, _, _, _, _, _, _, _, _, _).
 
 module_sub_get_c_body_info(MI0, D) :-
-        MI0 = module_sub(_, _, _, D, _, _, _, _, _, _, _, _, _).
+        MI0 = module_sub(_, _, _, D, _, _, _, _, _, _, _, _, _, _).
 
 module_sub_get_maybe_dependency_info(MI0, E) :-
-        MI0 = module_sub(_, _, _, _, E, _, _, _, _, _, _, _, _).
+        MI0 = module_sub(_, _, _, _, E, _, _, _, _, _, _, _, _, _).
 
 module_sub_get_num_errors(MI0, F) :-
-        MI0 = module_sub(_, _, _, _, _, F, _, _, _, _, _, _, _).
+        MI0 = module_sub(_, _, _, _, _, F, _, _, _, _, _, _, _, _).
 
 module_sub_get_lambda_count(MI0, G) :-
-        MI0 = module_sub(_, _, _, _, _, _, G, _, _, _, _, _, _).
+        MI0 = module_sub(_, _, _, _, _, _, G, _, _, _, _, _, _, _).
 
 module_sub_get_pragma_exported_procs(MI0, H) :-
-        MI0 = module_sub(_, _, _, _, _, _, _, H, _, _, _, _, _).
+        MI0 = module_sub(_, _, _, _, _, _, _, H, _, _, _, _, _, _).
 
 module_sub_get_base_gen_infos(MI0, I) :-
-        MI0 = module_sub(_, _, _, _, _, _, _, _, I, _, _, _, _).
+        MI0 = module_sub(_, _, _, _, _, _, _, _, I, _, _, _, _, _).
 
 module_sub_get_base_gen_layouts(MI0, J) :-
-        MI0 = module_sub(_, _, _, _, _, _, _, _, _, J, _, _, _).
+        MI0 = module_sub(_, _, _, _, _, _, _, _, _, J, _, _, _, _).
 
 module_sub_get_stratified_preds(MI0, K) :-
-        MI0 = module_sub(_, _, _, _, _, _, _, _, _, _, K, _, _).
+        MI0 = module_sub(_, _, _, _, _, _, _, _, _, _, K, _, _, _).
 
 module_sub_get_unused_arg_info(MI0, L) :-
-        MI0 = module_sub(_, _, _, _, _, _, _, _, _, _, _, L, _).
+        MI0 = module_sub(_, _, _, _, _, _, _, _, _, _, _, L, _, _).
 
 module_sub_get_model_non_pragma_count(MI0, M) :-
-        MI0 = module_sub(_, _, _, _, _, _, _, _, _, _, _, _, M).
+        MI0 = module_sub(_, _, _, _, _, _, _, _, _, _, _, _, M, _).
+
+module_sub_get_do_aditi_compilation(MI0, N) :-
+        MI0 = module_sub(_, _, _, _, _, _, _, _, _, _, _, _, _, N).
 
 %-----------------------------------------------------------------------------%
 
         % Various predicates which modify the module_sub_info data structure.
 
+module_sub_set_globals(MI0, B, MI) :-
+        MI0 = module_sub(A, _, C, D, E, F, G, H, I, J, K, L, M, N),
+        MI  = module_sub(A, B, C, D, E, F, G, H, I, J, K, L, M, N).
+
 module_sub_set_c_header_info(MI0, C, MI) :-
-        MI0 = module_sub(A, B, _, D, E, F, G, H, I, J, K, L, M),
-        MI  = module_sub(A, B, C, D, E, F, G, H, I, J, K, L, M).
+        MI0 = module_sub(A, B, _, D, E, F, G, H, I, J, K, L, M, N),
+        MI  = module_sub(A, B, C, D, E, F, G, H, I, J, K, L, M, N).
 
 module_sub_set_c_body_info(MI0, D, MI) :-
-        MI0 = module_sub(A, B, C, _, E, F, G, H, I, J, K, L, M),
-        MI  = module_sub(A, B, C, D, E, F, G, H, I, J, K, L, M).
+        MI0 = module_sub(A, B, C, _, E, F, G, H, I, J, K, L, M, N),
+        MI  = module_sub(A, B, C, D, E, F, G, H, I, J, K, L, M, N).
 
 module_sub_set_maybe_dependency_info(MI0, E, MI) :-
-        MI0 = module_sub(A, B, C, D, _, F, G, H, I, J, K, L, M),
-        MI  = module_sub(A, B, C, D, E, F, G, H, I, J, K, L, M).
+        MI0 = module_sub(A, B, C, D, _, F, G, H, I, J, K, L, M, N),
+        MI  = module_sub(A, B, C, D, E, F, G, H, I, J, K, L, M, N).
 
 module_sub_set_num_errors(MI0, F, MI) :-
-        MI0 = module_sub(A, B, C, D, E, _, G, H, I, J, K, L, M),
-        MI  = module_sub(A, B, C, D, E, F, G, H, I, J, K, L, M).
+        MI0 = module_sub(A, B, C, D, E, _, G, H, I, J, K, L, M, N),
+        MI  = module_sub(A, B, C, D, E, F, G, H, I, J, K, L, M, N).
 
 module_sub_set_lambda_count(MI0, G, MI) :-
-        MI0 = module_sub(A, B, C, D, E, F, _, H, I, J, K, L, M),
-        MI  = module_sub(A, B, C, D, E, F, G, H, I, J, K, L, M).
+        MI0 = module_sub(A, B, C, D, E, F, _, H, I, J, K, L, M, N),
+        MI  = module_sub(A, B, C, D, E, F, G, H, I, J, K, L, M, N).
 
 module_sub_set_pragma_exported_procs(MI0, H, MI) :-
-        MI0 = module_sub(A, B, C, D, E, F, G, _, I, J, K, L, M),
-        MI  = module_sub(A, B, C, D, E, F, G, H, I, J, K, L, M).
+        MI0 = module_sub(A, B, C, D, E, F, G, _, I, J, K, L, M, N),
+        MI  = module_sub(A, B, C, D, E, F, G, H, I, J, K, L, M, N).
 
 module_sub_set_base_gen_infos(MI0, I, MI) :-
-        MI0 = module_sub(A, B, C, D, E, F, G, H, _, J, K, L, M),
-        MI  = module_sub(A, B, C, D, E, F, G, H, I, J, K, L, M).
+        MI0 = module_sub(A, B, C, D, E, F, G, H, _, J, K, L, M, N),
+        MI  = module_sub(A, B, C, D, E, F, G, H, I, J, K, L, M, N).
 
 module_sub_set_base_gen_layouts(MI0, J, MI) :-
-        MI0 = module_sub(A, B, C, D, E, F, G, H, I, _, K, L, M),
-        MI  = module_sub(A, B, C, D, E, F, G, H, I, J, K, L, M).
+        MI0 = module_sub(A, B, C, D, E, F, G, H, I, _, K, L, M, N),
+        MI  = module_sub(A, B, C, D, E, F, G, H, I, J, K, L, M, N).
 
 module_sub_set_stratified_preds(MI0, K, MI) :-
-        MI0 = module_sub(A, B, C, D, E, F, G, H, I, J, _, L, M),
-        MI  = module_sub(A, B, C, D, E, F, G, H, I, J, K, L, M).
+        MI0 = module_sub(A, B, C, D, E, F, G, H, I, J, _, L, M, N),
+        MI  = module_sub(A, B, C, D, E, F, G, H, I, J, K, L, M, N).
 
 module_sub_set_unused_arg_info(MI0, L, MI) :-
-        MI0 = module_sub(A, B, C, D, E, F, G, H, I, J, K, _, M),
-        MI  = module_sub(A, B, C, D, E, F, G, H, I, J, K, L, M).
+        MI0 = module_sub(A, B, C, D, E, F, G, H, I, J, K, _, M, N),
+        MI  = module_sub(A, B, C, D, E, F, G, H, I, J, K, L, M, N).
 
 module_sub_set_model_non_pragma_count(MI0, M, MI) :-
-        MI0 = module_sub(A, B, C, D, E, F, G, H, I, J, K, L, _),
-        MI  = module_sub(A, B, C, D, E, F, G, H, I, J, K, L, M).
+        MI0 = module_sub(A, B, C, D, E, F, G, H, I, J, K, L, _, N),
+        MI  = module_sub(A, B, C, D, E, F, G, H, I, J, K, L, M, N).
+
+module_sub_set_do_aditi_compilation(MI0, MI) :-
+        MI0 = module_sub(A, B, C, D, E, F, G, H, I, J, K, L, M, _),
+        MI  = module_sub(A, B, C, D, E, F, G, H, I, J, K, L, M,
+                do_aditi_compilation).
 
 %-----------------------------------------------------------------------------%
 
@@ -810,11 +866,20 @@
         module_info_get_sub_info(MI0, MS0),
         module_sub_get_model_non_pragma_count(MS0, M).
 
+module_info_get_do_aditi_compilation(MI0, N) :-
+        module_info_get_sub_info(MI0, MS0),
+        module_sub_get_do_aditi_compilation(MS0, N).
+
 %-----------------------------------------------------------------------------%
 
         % Various predicates which modify the module_sub_info data structure
         % via the module_info structure.
 
+module_info_set_globals(MI0, B, MI) :-
+        module_info_get_sub_info(MI0, MS0),
+        module_sub_set_globals(MS0, B, MS),
+        module_info_set_sub_info(MI0, MS, MI).
+
 module_info_set_c_header(MI0, C, MI) :-
         module_info_get_sub_info(MI0, MS0),
         module_sub_set_c_header_info(MS0, C, MS),
@@ -870,6 +935,11 @@
         module_sub_set_model_non_pragma_count(MS0, M, MS),
         module_info_set_sub_info(MI0, MS, MI).
 
+module_info_set_do_aditi_compilation(MI0, MI) :-
+        module_info_get_sub_info(MI0, MS0),
+        module_sub_set_do_aditi_compilation(MS0, MS),
+        module_info_set_sub_info(MI0, MS, MI).
+
 %-----------------------------------------------------------------------------%
 
         % Various predicates which do simple things that are nevertheless
@@ -895,6 +965,9 @@
         pred_info_procedures(PredInfo, Procs),
         map__lookup(Procs, ProcId, ProcInfo).
 
+module_info_pred_proc_info(MI, proc(PredId, ProcId), PredInfo, ProcInfo) :-
+        module_info_pred_proc_info(MI, PredId, ProcId, PredInfo, ProcInfo).
+
 module_info_predids(MI, PredIds) :-
         module_info_get_predicate_table(MI, PredTable),
         predicate_table_get_predids(PredTable, PredIds).
@@ -924,6 +997,11 @@
         map__set(Preds0, PredId, PredInfo, Preds),
         module_info_set_preds(MI0, Preds, MI).
 
+module_info_set_pred_proc_info(MI0, proc(PredId, ProcId),
+                PredInfo, ProcInfo, MI) :-
+        module_info_set_pred_proc_info(MI0, PredId, ProcId,
+                PredInfo, ProcInfo, MI).
+
 module_info_set_pred_proc_info(MI0, PredId, ProcId, PredInfo0, ProcInfo, MI) :-
         pred_info_procedures(PredInfo0, Procs0),
         map__set(Procs0, ProcId, ProcInfo, Procs),
@@ -955,6 +1033,16 @@
                 error("Attempted to access invalid dependency_info")
         ).
 
+module_info_aditi_dependency_ordering(MI, AditiOrdering) :-
+        module_info_dependency_info(MI, DepInfo),
+        hlds_dependency_info_get_maybe_aditi_dependency_ordering(DepInfo,
+                MaybeOrdering),
+        ( MaybeOrdering = yes(OrderingPrime) ->
+                AditiOrdering = OrderingPrime
+        ;
+                error("Attempted to access invalid aditi_dependency_ordering")
+        ).
+
 module_info_set_dependency_info(MI0, DependencyInfo, MI) :-
         module_info_set_maybe_dependency_info(MI0, yes(DependencyInfo), MI).
 
@@ -1011,8 +1099,20 @@
 
 :- interface.
 
-:- type dependency_ordering     == list(list(pred_proc_id)).
-:- type dependency_graph        == relation(pred_proc_id).
+:- type dependency_ordering             == list(list(pred_proc_id)).
+
+:- type aditi_dependency_ordering       == list(aditi_scc).
+
+        % Each Aditi SCC contains one or more SCCs from the original 
+        % dependency ordering and the entry points of the SCC.
+        % SCCs which are only called from one other SCC and are not
+        % called through negation or aggregation are merged into the
+        % parent SCC. This makes the low-level RL optimizations more
+        % effective while maintaining stratification. 
+:- type aditi_scc
+        --->    aditi_scc(dependency_ordering, list(pred_proc_id)).
+
+:- type dependency_graph                == relation(pred_proc_id).
 :- type dependency_info.
 
 :- pred hlds_dependency_info_init(dependency_info).
@@ -1026,6 +1126,11 @@
         dependency_ordering).
 :- mode hlds_dependency_info_get_dependency_ordering(in, out) is det.
 
+:- pred hlds_dependency_info_get_maybe_aditi_dependency_ordering(
+                dependency_info, maybe(aditi_dependency_ordering)).
+:- mode hlds_dependency_info_get_maybe_aditi_dependency_ordering(in, 
+                out) is det.
+
 :- pred hlds_dependency_info_set_dependency_graph(dependency_info,
         dependency_graph, dependency_info).
 :- mode hlds_dependency_info_set_dependency_graph(in, in, out) is det.
@@ -1034,6 +1139,10 @@
         dependency_ordering, dependency_info).
 :- mode hlds_dependency_info_set_dependency_ordering(in, in, out) is det.
 
+:- pred hlds_dependency_info_set_aditi_dependency_ordering(dependency_info,
+        aditi_dependency_ordering, dependency_info).
+:- mode hlds_dependency_info_set_aditi_dependency_ordering(in, in, out) is det.
+
 %-----------------------------------------------------------------------------%
 
 :- implementation.
@@ -1041,27 +1150,37 @@
 :- type dependency_info --->
                 dependency_info(
                         dependency_graph,       % Dependency graph
-                        dependency_ordering     % Dependency ordering
+                        dependency_ordering,    % Dependency ordering
+                        maybe(aditi_dependency_ordering)
+                                        % Dependency ordering of Aditi SCCs 
                 ).
 
 hlds_dependency_info_init(DepInfo) :-
         relation__init(DepRel),
         DepOrd = [],
-        DepInfo = dependency_info(DepRel, DepOrd).
+        DepInfo = dependency_info(DepRel, DepOrd, no).
 
 hlds_dependency_info_get_dependency_graph(DepInfo, A) :-
-        DepInfo = dependency_info(A, _).
+        DepInfo = dependency_info(A, _, _).
 
 hlds_dependency_info_get_dependency_ordering(DepInfo, B) :-
-        DepInfo = dependency_info(_, B).
+        DepInfo = dependency_info(_, B, _).
+
+hlds_dependency_info_get_maybe_aditi_dependency_ordering(DepInfo, C) :-
+        DepInfo = dependency_info(_, _, C).
 
-hlds_dependency_info_set_dependency_graph(DepInfo0, A, DepInfo) :-
-        DepInfo0 = dependency_info(_, B),
-        DepInfo  = dependency_info(A, B).
-
-hlds_dependency_info_set_dependency_ordering(DepInfo0, B, DepInfo) :-
-        DepInfo0 = dependency_info(A, _),
-        DepInfo  = dependency_info(A, B).
+hlds_dependency_info_set_dependency_graph(DepInfo0, DepRel, DepInfo) :-
+        DepInfo0 = dependency_info(_, B, C),
+        DepInfo = dependency_info(DepRel, B, C).
+
+hlds_dependency_info_set_dependency_ordering(DepInfo0, DepRel, DepInfo) :-
+        DepInfo0 = dependency_info(A, _, C),
+        DepInfo = dependency_info(A, DepRel, C).
+
+hlds_dependency_info_set_aditi_dependency_ordering(DepInfo0, 
+                DepOrd, DepInfo) :-
+        DepInfo0 = dependency_info(A, B, _),
+        DepInfo = dependency_info(A, B, yes(DepOrd)).
 
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%

Index: hlds_pred.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/hlds_pred.m,v
retrieving revision 1.49
diff -u -t -u -r1.49 hlds_pred.m
--- hlds_pred.m	1998/07/08 20:56:22	1.49
+++ hlds_pred.m	1998/07/30 03:21:50
@@ -112,8 +112,8 @@
                         ;       clauses         
                         ;       none.
 
-        % The evaluation method that should be used for a pred
-
+        % 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
@@ -202,12 +202,54 @@
                                 % inlined.
                                 % Used for pragma(no_inline).
                                 % Conflicts with `inline' marker.
+
+                % The default flags for Aditi predicates are
+                % aditi, dnf, supp_magic, psn and memo.
+
         ;       dnf             % Requests that this predicate be transformed
                                 % into disjunctive normal form.
-        ;       magic           % Requests that this predicate be transformed
-                                % using the magic set transformation
-                                % Used for pragma(memo).
-                                % Used for pragma(memo).
+        ;       aditi_memo      % Requests that this Aditi predicate be
+                                % evaluated using memoing. This has no
+                                % relation to eval_method field of the
+                                % pred_info, which is ignore for Aditi
+                                % predicates.
+        ;       aditi_no_memo   % Ensure that this Aditi predicate
+                                % is not memoed.
+        
+        ;       aditi           % Generate Aditi-RL for this predicate.
+        ;       base_relation   % This predicate is an Aditi base relation.
+
+                        % `naive' and `psn' are mutually exclusive.
+        ;       naive           % Use naive evaluation of this Aditi predicate.
+        ;       psn             % Use predicate semi-naive evaluation of this
+                                % Aditi predicate.
+
+                        % `context' and `supp_magic' are mutually
+                        % exclusive. One of them must be performed
+                        % on all Aditi predicates. `supp_magic'
+                        % is the default
+
+        ;       supp_magic      % Perform the supplementary magic sets
+                                % transformation on this predicate. See magic.m
+        ;       context         % Perform the context transformation on
+                                % the predicate. See context.m
+
+        ;       generate_inline % Used for small Aditi predicates which
+                                % project a relation to be used as input to a 
+                                % call to an Aditi predicate in a lower SCC.
+                                % The goal for the predicate should consist
+                                % of fail, true or a single rule.
+                                % These relations are never memoed.
+                                % The reason for this marker is explained 
+                                % where it is introduced in
+                                % magic_util__create_closure.
+
+        ;       aditi_interface % No code is actually generated for this
+                                % predicate type. A call to a predicate with
+                                % this marker is generated as a call to
+                                % do_*_aditi_call, which is defined in hand
+                                % coded C in extras/aditi/aditi.m.
+
         ;       class_method    % Requests that this predicate be transformed
                                 % into the appropriate call to a class method
         ;       (impure)        % Requests that no transformation that would
@@ -246,6 +288,10 @@
                                 % then it must give an error message.
         .
 
+        % Aditi predicates are identified by their owner as well as
+        % module, name and arity.
+:- type aditi_owner == string.
+
 :- type type_info_locn  
         --->    type_info(var)          % it is a normal type info 
                                         % (ie. the type is not constrained)
@@ -260,16 +306,16 @@
 
         % hlds_pred__define_new_pred(Goal, CallGoal, Args, InstMap, PredName,
         %       TVarSet, VarTypes, ClassContext, TVarMap, TCVarMap, 
-        %       VarSet, Markers, ModuleInfo0, ModuleInfo, PredProcId)
+        %       VarSet, Markers, Owner, ModuleInfo0, ModuleInfo, PredProcId)
         %
         % Create a new predicate for the given goal, returning a goal to 
         % call the created predicate.
 :- pred hlds_pred__define_new_pred(hlds_goal, hlds_goal, list(var),
                 instmap, string, tvarset, map(var, type),
                 class_constraints, map(tvar, type_info_locn),
-                map(class_constraint, var), varset, pred_markers, 
+                map(class_constraint, var), varset, pred_markers, string,
                 module_info, module_info, pred_proc_id).
-:- mode hlds_pred__define_new_pred(in, out, in, in, in, in, in,
+:- mode hlds_pred__define_new_pred(in, out, in, in, in, in, in, in,
                 in, in, in, in, in, in, out, out) is det.
 
         % Various predicates for accessing the information stored in the
@@ -278,14 +324,15 @@
 :- pred pred_info_init(module_name, sym_name, arity, tvarset, existq_tvars,
         list(type), condition, term__context, clauses_info, import_status,
         pred_markers, goal_type, pred_or_func, class_constraints, 
-        map(class_constraint, constraint_proof), pred_info).
+        map(class_constraint, constraint_proof), aditi_owner, pred_info).
 :- mode pred_info_init(in, in, in, in, in, in, in, in, in, in, in, in, in,
-        in, in, out) is det.
+        in, in, in, out) is det.
 
 :- pred pred_info_create(module_name, sym_name, tvarset, existq_tvars,
         list(type), condition, term__context, import_status, pred_markers,
-        pred_or_func, class_constraints, proc_info, proc_id, pred_info).
-:- mode pred_info_create(in, in, in, in, in, in, in, in, in, in, in, in,
+        pred_or_func, class_constraints, aditi_owner, proc_info,
+        proc_id, pred_info).
+:- mode pred_info_create(in, in, in, in, in, in, in, in, in, in, in, in, in,
         out, out) is det.
 
 :- pred pred_info_module(pred_info, module_name).
@@ -422,6 +469,12 @@
         map(class_constraint, constraint_proof), pred_info).
 :- mode pred_info_set_constraint_proofs(in, in, out) is det.
 
+:- pred pred_info_get_aditi_owner(pred_info, string).
+:- mode pred_info_get_aditi_owner(in, out) is det.
+
+:- pred pred_info_set_aditi_owner(pred_info, string, pred_info).
+:- mode pred_info_set_aditi_owner(in, in, out) is det.
+
 :- pred pred_info_get_purity(pred_info, purity).
 :- mode pred_info_get_purity(in, out) is det.
 
@@ -451,10 +504,17 @@
 :- pred add_marker(pred_markers, marker, pred_markers).
 :- mode add_marker(in, in, out) is det.
 
+        % remove a marker from the set
+:- pred remove_marker(pred_markers, marker, pred_markers).
+:- mode remove_marker(in, in, out) is det.
+
         % convert the set to a list
 :- pred markers_to_marker_list(pred_markers, list(marker)).
 :- mode markers_to_marker_list(in, out) is det.
 
+:- pred marker_list_to_markers(list(marker), pred_markers).
+:- mode marker_list_to_markers(in, out) is det.
+
 %-----------------------------------------------------------------------------%
 
 :- implementation.
@@ -541,17 +601,23 @@
                                         % (the type_infos are returned from
                                         % the called preds).
                                         % Computed during type checking.
-                        list(class_constraint)
-                                        % unproven class constraints on type variables
-                                        % in the predicate's body, if any
-                                        % (if this remains non-empty after type
-                                        % checking has finished, post_typecheck.m
-                                        % will report a type error).
+                        list(class_constraint),
+                                        % unproven class constraints on type
+                                        % variables in the predicate's body,
+                                        % if any (if this remains non-empty
+                                        % after type checking has finished,
+                                        % post_typecheck.m will report a type
+                                        % error).
+                        aditi_owner
+                                        % The owner of this predicate if
+                                        % it is an Aditi predicate. Set to
+                                        % the value of --aditi-user if no
+                                        % `:- pragma owner' declaration exists.
                 ).
 
 pred_info_init(ModuleName, SymName, Arity, TypeVarSet, ExistQVars, Types,
                 Cond, Context, ClausesInfo, Status, Markers, GoalType,
-                PredOrFunc, ClassContext, ClassProofs, PredInfo) :-
+                PredOrFunc, ClassContext, ClassProofs, User, PredInfo) :-
         map__init(Procs),
         unqualify_name(SymName, PredName),
         sym_name_get_module_name(SymName, ModuleName, PredModuleName),
@@ -561,10 +627,10 @@
         PredInfo = predicate(TypeVarSet, Types, Cond, ClausesInfo, Procs,
                 Context, PredModuleName, PredName, Arity, Status, TypeVarSet, 
                 GoalType, Markers, PredOrFunc, ClassContext, ClassProofs,
-                ExistQVars, HeadTypeParams, UnprovenBodyConstraints).
+                ExistQVars, HeadTypeParams, UnprovenBodyConstraints, User).
 
 pred_info_create(ModuleName, SymName, TypeVarSet, ExistQVars, Types, Cond,
-                Context, Status, Markers, PredOrFunc, ClassContext,
+                Context, Status, Markers, PredOrFunc, ClassContext, User,
                 ProcInfo, ProcId, PredInfo) :-
         map__init(Procs0),
         proc_info_declared_determinism(ProcInfo, MaybeDetism),
@@ -584,11 +650,11 @@
         PredInfo = predicate(TypeVarSet, Types, Cond, ClausesInfo, Procs,
                 Context, ModuleName, PredName, Arity, Status, TypeVarSet, 
                 clauses, Markers, PredOrFunc, ClassContext, ClassProofs,
-                ExistQVars, HeadTypeParams, UnprovenBodyConstraints).
+                ExistQVars, HeadTypeParams, UnprovenBodyConstraints, User).
 
 pred_info_procids(PredInfo, ProcIds) :-
         PredInfo = predicate(_, _, _, _, Procs, _, _, _, _, _, _, _, 
-                _, _, _, _, _, _, _),
+                _, _, _, _, _, _, _, _),
         map__keys(Procs, ProcIds).
 
 pred_info_non_imported_procids(PredInfo, ProcIds) :-
@@ -615,57 +681,57 @@
 
 pred_info_clauses_info(PredInfo, Clauses) :-
         PredInfo = predicate(_, _, _, Clauses, _, _, _, _, _, _, _, _, _,
-                _, _, _, _, _, _).
+                _, _, _, _, _, _, _).
 
 pred_info_set_clauses_info(PredInfo0, Clauses, PredInfo) :-
         PredInfo0 = predicate(A, B, C, _, E, F, G, H, I, J, K, L, M, N, O, P,
-                Q, R, S),
+                Q, R, S, T),
         PredInfo = predicate(A, B, C, Clauses, E, F, G, H, I, J, K, 
-                L, M, N, O, P, Q, R, S).
+                L, M, N, O, P, Q, R, S, T).
 
 pred_info_arg_types(PredInfo, ArgTypes) :-
         pred_info_arg_types(PredInfo, _TypeVars, _ExistQVars, ArgTypes).
 
 pred_info_arg_types(PredInfo, TypeVars, ExistQVars, ArgTypes) :-
         PredInfo = predicate(TypeVars, ArgTypes, 
-                _, _, _, _, _, _, _, _, _, _, _, _, _, _, ExistQVars, _, _).
+                _, _, _, _, _, _, _, _, _, _, _, _, _, _, ExistQVars, _, _, _).
 
 pred_info_set_arg_types(PredInfo0, TypeVarSet, ExistQVars, ArgTypes,
                 PredInfo) :-
         PredInfo0 = predicate(_, _, C, D, E, F, G, H, I, J, K, L, M, N, O, P,
-                _, R, S),
+                _, R, S, T),
         PredInfo = predicate(TypeVarSet, ArgTypes, 
-                C, D, E, F, G, H, I, J, K, L, M, N, O, P, ExistQVars, R, S).
+                C, D, E, F, G, H, I, J, K, L, M, N, O, P, ExistQVars, R, S, T).
 
 pred_info_procedures(PredInfo, Procs) :-
         PredInfo = predicate(_, _, _, _, Procs, _, _, _, _, _, _, 
-                _, _, _, _, _, _, _, _).
+                _, _, _, _, _, _, _, _, _).
 
 pred_info_set_procedures(PredInfo0, Procedures, PredInfo) :-
         PredInfo0 = predicate(A, B, C, D, _, F, G, H, I, J, K, L, M, N, O, P,
-                Q, R, S),
+                Q, R, S, T),
         PredInfo = predicate(A, B, C, D, Procedures, F, G, H, I, J, K, L, M, 
-                N, O, P, Q, R, S).
+                N, O, P, Q, R, S, T).
 
 pred_info_context(PredInfo, Context) :-
         PredInfo = predicate(_, _, _, _, _, Context, _, _, _, 
-                _, _, _, _, _, _, _, _, _, _).
+                _, _, _, _, _, _, _, _, _, _, _).
 
 pred_info_module(PredInfo, Module) :-
         PredInfo = predicate(_, _, _, _, _, _, Module, _, _, _, _, 
-                _, _, _, _, _, _, _, _).
+                _, _, _, _, _, _, _, _, _).
 
 pred_info_name(PredInfo, PredName) :-
         PredInfo = predicate(_, _, _, _, _, _, _, PredName, _, _, _, 
-                _, _, _, _, _, _, _, _).
+                _, _, _, _, _, _, _, _, _).
 
 pred_info_arity(PredInfo, Arity) :-
         PredInfo = predicate(_, _, _, _, _, _, _, _, Arity, _, _, 
-                _, _, _, _, _, _, _, _).
+                _, _, _, _, _, _, _, _, _).
 
 pred_info_import_status(PredInfo, ImportStatus) :-
         PredInfo = predicate(_, _, _, _, _, _, _, _, _, ImportStatus, _, _, _,
-                                _, _, _, _, _, _).
+                                _, _, _, _, _, _, _).
 
 pred_info_is_imported(PredInfo) :-
         pred_info_import_status(PredInfo, imported).
@@ -684,35 +750,35 @@
 
 pred_info_mark_as_external(PredInfo0, PredInfo) :-
         PredInfo0 = predicate(A, B, C, D, E, F, G, H, I, _, K, L, M, N, O, P,
-                Q, R, S),
+                Q, R, S, T),
         PredInfo  = predicate(A, B, C, D, E, F, G, H, I, imported, K, L, M, 
-                N, O, P, Q, R, S).
+                N, O, P, Q, R, S, T).
 
 pred_info_set_import_status(PredInfo0, Status, PredInfo) :-
         PredInfo0 = predicate(A, B, C, D, E, F, G, H, I, _, K, L, M, N, O, P,
-                Q, R, S),
+                Q, R, S, T),
         PredInfo  = predicate(A, B, C, D, E, F, G, H, I, Status, K, 
-                L, M, N, O, P, Q, R, S).
+                L, M, N, O, P, Q, R, S, T).
 
 pred_info_typevarset(PredInfo, TypeVarSet) :-
         PredInfo = predicate(_, _, _, _, _, _, _, _, _, _, TypeVarSet, _, _, 
-                _, _, _, _, _, _).
+                _, _, _, _, _, _, _).
 
 pred_info_set_typevarset(PredInfo0, TypeVarSet, PredInfo) :-
         PredInfo0 = predicate(A, B, C, D, E, F, G, H, I, J, _, L, M, N, O, P,
-                Q, R, S),
+                Q, R, S, T),
         PredInfo  = predicate(A, B, C, D, E, F, G, H, I, J, TypeVarSet, L, M,
-                                N, O, P, Q, R, S).
+                                N, O, P, Q, R, S, T).
 
 pred_info_get_goal_type(PredInfo, GoalType) :-
         PredInfo = predicate(_, _, _, _, _, _, _, _, _, _, _, GoalType, _, 
-                _, _, _, _, _, _).
+                _, _, _, _, _, _, _).
 
 pred_info_set_goal_type(PredInfo0, GoalType, PredInfo) :-
         PredInfo0 = predicate(A, B, C, D, E, F, G, H, I, J, K, _, M, N, O, P,
-                Q, R, S),
+                Q, R, S, T),
         PredInfo  = predicate(A, B, C, D, E, F, G, H, I, J, K, GoalType, M, 
-                N, O, P, Q, R, S).
+                N, O, P, Q, R, S, T).
 
 pred_info_requested_inlining(PredInfo0) :-
         pred_info_get_markers(PredInfo0, Markers),
@@ -746,41 +812,41 @@
 
 pred_info_get_markers(PredInfo, Markers) :-
         PredInfo = predicate(_, _, _, _, _, _, _, _, _, _, _, _, Markers, 
-                _, _, _, _, _, _).
+                _, _, _, _, _, _, _).
 
 pred_info_set_markers(PredInfo0, Markers, PredInfo) :-
         PredInfo0 = predicate(A, B, C, D, E, F, G, H, I, J, K, L, _, N, O, P,
-                Q, R, S),
+                Q, R, S, T),
         PredInfo  = predicate(A, B, C, D, E, F, G, H, I, J, K, L, Markers, 
-                N, O, P, Q, R, S).
+                N, O, P, Q, R, S, T).
 
 pred_info_get_is_pred_or_func(PredInfo, IsPredOrFunc) :-
         PredInfo = predicate(_, _, _, _, _, _, _, _, _, _, _, _, _,
-                        IsPredOrFunc, _, _, _, _, _).
+                        IsPredOrFunc, _, _, _, _, _, _).
 
 pred_info_set_class_context(PredInfo0, ClassContext, PredInfo) :-
         PredInfo0 = predicate(A, B, C, D, E, F, G, H, I, J, K, L, M, N, _, P,
-                Q, R, S),
+                Q, R, S, T),
         PredInfo  = predicate(A, B, C, D, E, F, G, H, I, J, K, L, M, N, 
-                ClassContext, P, Q, R, S).
+                ClassContext, P, Q, R, S, T).
 
 pred_info_get_class_context(PredInfo, ClassContext) :-
         PredInfo = predicate(_, _, _, _, _, _, _, _, _, _, _, _, _, _, 
-                ClassContext, _, _, _, _).
+                ClassContext, _, _, _, _, _).
 
 pred_info_set_constraint_proofs(PredInfo0, Proofs, PredInfo) :-
         PredInfo0 = predicate(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, _,
-                Q, R, S),
+                Q, R, S, T),
         PredInfo  = predicate(A, B, C, D, E, F, G, H, I, J, K, L, M, N, 
-                O, Proofs, Q, R, S).
+                O, Proofs, Q, R, S, T).
 
 pred_info_get_constraint_proofs(PredInfo, ConstraintProofs) :-
         PredInfo = predicate(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
-                ConstraintProofs, _, _, _).
+                ConstraintProofs, _, _, _, _).
 
 pred_info_get_exist_quant_tvars(PredInfo, ExistQVars) :-
         PredInfo = predicate(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
-                _, ExistQVars, _, _).
+                _, ExistQVars, _, _, _).
 
 pred_info_get_univ_quant_tvars(PredInfo, UnivQVars) :-
         pred_info_arg_types(PredInfo, ArgTypes),
@@ -791,24 +857,35 @@
 
 pred_info_get_head_type_params(PredInfo, HeadTypeParams) :-
         PredInfo = predicate(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
-                _, _, HeadTypeParams, _).
+                _, _, HeadTypeParams, _, _).
 
 pred_info_set_head_type_params(PredInfo0, HeadTypeParams, PredInfo) :-
         PredInfo0 = predicate(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P,
-                Q, _, S),
+                Q, _, S, T),
         PredInfo  = predicate(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P,
-                Q, HeadTypeParams, S).
+                Q, HeadTypeParams, S, T).
 
 pred_info_get_unproven_body_constraints(PredInfo, UnprovenBodyConstraints) :-
         PredInfo = predicate(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
-                _, _, UnprovenBodyConstraints).
+                _, _, UnprovenBodyConstraints, _).
 
 pred_info_set_unproven_body_constraints(PredInfo0, UnprovenBodyConstraints,
                 PredInfo) :-
         PredInfo0 = predicate(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P,
-                Q, R, _),
+                Q, R, _, T),
         PredInfo  = predicate(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P,
-                Q, R, UnprovenBodyConstraints).
+                Q, R, UnprovenBodyConstraints, T).
+
+
+pred_info_get_aditi_owner(PredInfo, Owner) :-
+        PredInfo = predicate(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
+                _, _, _, _, Owner).
+
+pred_info_set_aditi_owner(PredInfo0, Owner, PredInfo) :-
+        PredInfo0 = predicate(A, B, C, D, E, F, G, H, I, J, K, L, M, N,
+                O, P, Q, R, S, _),
+        PredInfo  = predicate(A, B, C, D, E, F, G, H, I, J, K, L, M, N, 
+                O, P, Q, R, S, Owner).
 
 %-----------------------------------------------------------------------------%
 
@@ -828,13 +905,18 @@
 
 add_marker(Markers, Marker, [Marker | Markers]).
 
+remove_marker(Markers0, Marker, Markers) :-
+        list__delete_all(Markers0, Marker, Markers).
+
 markers_to_marker_list(Markers, Markers).
 
+marker_list_to_markers(Markers, Markers).
+
 %-----------------------------------------------------------------------------%
 
 hlds_pred__define_new_pred(Goal0, Goal, ArgVars0, InstMap0, PredName, TVarSet, 
                 VarTypes0, ClassContext, TVarMap, TCVarMap, VarSet0, 
-                Markers, ModuleInfo0, ModuleInfo, PredProcId) :-
+                Markers, User, ModuleInfo0, ModuleInfo, PredProcId) :-
         Goal0 = _GoalExpr - GoalInfo,
         goal_info_get_instmap_delta(GoalInfo, InstMapDelta),
         instmap__apply_instmap_delta(InstMap0, InstMapDelta, InstMap),
@@ -889,7 +971,7 @@
 
         pred_info_create(ModuleName, SymName, TVarSet, ExistQVars, ArgTypes,
                 true, Context, local, Markers, predicate, ClassContext, 
-                ProcInfo, ProcId, PredInfo),
+                User, ProcInfo, ProcId, PredInfo),
 
         module_info_get_predicate_table(ModuleInfo0, PredTable0),
         predicate_table_insert(PredTable0, PredInfo, PredId,
@@ -1646,6 +1728,118 @@
 
 %-----------------------------------------------------------------------------%
 
+        % Predicates to check whether a given predicate 
+        % is an Aditi query.
+
+:- interface.
+
+:- pred hlds_pred__is_base_relation(module_info, pred_id).
+:- mode hlds_pred__is_base_relation(in, in) is semidet.
+
+:- pred hlds_pred__is_derived_relation(module_info, pred_id).
+:- mode hlds_pred__is_derived_relation(in, in) is semidet.
+
+        % Is the given predicate a base or derived Aditi relation.
+:- pred hlds_pred__is_aditi_relation(module_info, pred_id).
+:- mode hlds_pred__is_aditi_relation(in, in) is semidet.
+
+        % Is the predicate `aditi:aggregate_compute_initial', declared
+        % in extras/aditi/aditi.m.
+        % Special code is generated for each call to this in rl_gen.m.
+:- pred hlds_pred__is_aditi_aggregate(module_info, pred_id).
+:- mode hlds_pred__is_aditi_aggregate(in, in) is semidet.
+
+:- pred hlds_pred__pred_info_is_aditi_relation(pred_info).
+:- mode hlds_pred__pred_info_is_aditi_relation(in) is semidet.
+
+:- pred hlds_pred__pred_info_is_aditi_aggregate(pred_info).
+:- mode hlds_pred__pred_info_is_aditi_aggregate(in) is semidet.
+
+:- pred hlds_pred__pred_info_is_base_relation(pred_info).
+:- mode hlds_pred__pred_info_is_base_relation(in) is semidet.
+
+        % Aditi can optionally memo the results of predicates
+        % between calls to reduce redundant computation.
+:- pred hlds_pred__is_aditi_memoed(module_info, pred_id).
+:- mode hlds_pred__is_aditi_memoed(in, in) is semidet.
+
+        % Differential evaluation is a method of evaluating recursive
+        % Aditi predicates which uses the just new tuples in each
+        % iteration where possible rather than the full relations,
+        % reducing the sizes of joins.
+:- pred hlds_pred__is_differential(module_info, pred_id).
+:- mode hlds_pred__is_differential(in, in) is semidet.
+
+%-----------------------------------------------------------------------------%
+
+:- implementation.
+
+hlds_pred__is_base_relation(ModuleInfo, PredId) :-
+        module_info_pred_info(ModuleInfo, PredId, PredInfo),
+        hlds_pred__pred_info_is_base_relation(PredInfo).
+
+hlds_pred__pred_info_is_base_relation(PredInfo) :-
+        pred_info_get_markers(PredInfo, Markers),
+        check_marker(Markers, base_relation).
+
+hlds_pred__is_derived_relation(ModuleInfo, PredId) :-
+        module_info_pred_info(ModuleInfo, PredId, PredInfo),
+        pred_info_get_markers(PredInfo, Markers),
+        check_marker(Markers, aditi),
+        \+ hlds_pred__pred_info_is_base_relation(PredInfo),
+        \+ hlds_pred__pred_info_is_aditi_aggregate(PredInfo).
+
+hlds_pred__is_aditi_relation(ModuleInfo, PredId) :-
+        module_info_pred_info(ModuleInfo, PredId, PredInfo),
+        hlds_pred__pred_info_is_aditi_relation(PredInfo).
+
+hlds_pred__pred_info_is_aditi_relation(PredInfo) :-
+        pred_info_get_markers(PredInfo, Markers),
+        check_marker(Markers, aditi).
+
+hlds_pred__is_aditi_aggregate(ModuleInfo, PredId) :-
+        module_info_pred_info(ModuleInfo, PredId, PredInfo),
+        hlds_pred__pred_info_is_aditi_aggregate(PredInfo).
+
+hlds_pred__pred_info_is_aditi_aggregate(PredInfo) :-
+        pred_info_module(PredInfo, Module),
+        pred_info_name(PredInfo, Name),
+        pred_info_arity(PredInfo, Arity),
+        hlds_pred__aditi_aggregate(Module, Name, Arity).
+
+:- pred hlds_pred__aditi_aggregate(sym_name, string, int).
+:- mode hlds_pred__aditi_aggregate(in, in, in) is semidet.
+
+hlds_pred__aditi_aggregate(unqualified("aditi"),
+                "aggregate_compute_initial", 5).
+
+hlds_pred__is_aditi_memoed(ModuleInfo, PredId) :-
+        module_info_pred_info(ModuleInfo, PredId, PredInfo),
+        pred_info_get_markers(PredInfo, Markers),
+        (
+                check_marker(Markers, aditi_memo)
+        ;
+                % Memoing is the default for Aditi procedures.
+                semidet_fail,   % XXX leave it off for now to
+                                % reduce memory usage
+                check_marker(Markers, aditi),
+                \+ check_marker(Markers, aditi_no_memo)
+        ).
+
+hlds_pred__is_differential(ModuleInfo, PredId) :-
+        module_info_pred_info(ModuleInfo, PredId, PredInfo),
+        pred_info_get_markers(PredInfo, Markers),
+        (
+                check_marker(Markers, psn)
+        ;
+                % Predicate semi-naive evaluation is the default. 
+                check_marker(Markers, aditi),
+                \+ check_marker(Markers, naive)
+        ).
+
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+
 :- interface.
 
         % Check if the given evaluation method is allowed with
@@ -1698,3 +1892,5 @@
 eval_method_change_determinism(eval_minimal, Det0, Det) :-
         det_conjunction_detism(semidet, Det0, Det).
 
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%

<<< Changes to compiler/globals.m were undone >>>


Index: intermod.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/intermod.m,v
retrieving revision 1.58
diff -u -t -u -r1.58 intermod.m
--- intermod.m	1998/07/14 06:24:14	1.58
+++ intermod.m	1998/07/30 01:36:05
@@ -1006,24 +1006,52 @@
 
 intermod__write_pragmas(_, _, [], _) --> [].
 intermod__write_pragmas(SymName, Arity, [Marker | Markers], PredOrFunc) -->
-        (
-                % Since the inferred declarations are output, these
-                % don't need to be done in the importing module.
-                % Also purity is output as part of the pred/func decl.
-                % There is no pragma required for generated class methods.
-                ( { Marker = infer_type }
-                ; { Marker = infer_modes }
-                ; { Marker = (impure) }
-                ; { Marker = (semipure) }
-                ; { Marker = class_method }
-                )
-        ->
-                []
-        ;
+        { intermod__should_output_marker(Marker, ShouldOutput) },
+        ( { ShouldOutput = yes } ->
                 { hlds_out__marker_name(Marker, Name) },
                 mercury_output_pragma_decl(SymName, Arity, PredOrFunc, Name)
+        ;
+                []
         ),
         intermod__write_pragmas(SymName, Arity, Markers, PredOrFunc).
+
+        % Is a pragma declaration required in the `.opt' file for
+        % a predicate with the given marker.
+:- pred intermod__should_output_marker(marker::in, bool::out) is det.
+
+        % Since the inferred declarations are output, these
+        % don't need to be done in the importing module.
+intermod__should_output_marker(infer_type, no).
+intermod__should_output_marker(infer_modes, no).
+        % Purity is output as part of the pred/func decl.
+intermod__should_output_marker((impure), no).
+intermod__should_output_marker((semipure), no).
+        % There is no pragma required for generated class methods.
+intermod__should_output_marker(class_method, no).
+        % The warning for calls to local obsolete predicates should appear
+        % once in the defining module, not in importing modules.
+intermod__should_output_marker(obsolete, no).
+intermod__should_output_marker(inline, yes).
+intermod__should_output_marker(no_inline, yes).
+intermod__should_output_marker(dnf, yes).
+intermod__should_output_marker(aditi, yes).
+intermod__should_output_marker(base_relation, yes).
+intermod__should_output_marker(aditi_memo, yes).
+intermod__should_output_marker(aditi_no_memo, yes).
+intermod__should_output_marker(naive, yes).
+intermod__should_output_marker(psn, yes).
+intermod__should_output_marker(supp_magic, yes).
+intermod__should_output_marker(context, yes).
+intermod__should_output_marker(promised_pure, yes).
+intermod__should_output_marker(terminates, yes).
+intermod__should_output_marker(does_not_terminate, yes).
+        % Termination should only be checked in the defining module.
+intermod__should_output_marker(check_termination, no).
+        % These should only occur after the magic sets transformation.
+intermod__should_output_marker(generate_inline, _) :-
+        error("intermod__should_output_marker: generate_inline").
+intermod__should_output_marker(aditi_interface, _) :-
+        error("intermod__should_output_marker: generate_inline").
 
         % Some pretty kludgy stuff to get c code written correctly.
 :- pred intermod__write_c_code(sym_name::in, pred_or_func::in, 

Index: lambda.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/lambda.m,v
retrieving revision 1.44
diff -u -t -u -r1.44 lambda.m
--- lambda.m	1998/07/08 20:56:33	1.44
+++ lambda.m	1998/07/29 04:51:43
@@ -79,9 +79,10 @@
                 determinism, list(var), set(var), hlds_goal, unification,
                 varset, map(var, type), class_constraints, tvarset,
                 map(tvar, type_info_locn), map(class_constraint, var),
-                module_info, unify_rhs, unification, module_info).
-:- mode lambda__transform_lambda(in, in, in, in, in, in, in, in, in, in, in,
-                in, in, in, in, in, out, out, out) is det.
+                pred_markers, aditi_owner, module_info, unify_rhs,
+                unification, module_info).
+:- mode lambda__transform_lambda(in, in, in, in, in, in, in, in, in,
+                in, in, in, in, in, in, in, in, in, out, out, out) is det.
 
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
@@ -105,8 +106,10 @@
                         map(class_constraint, var),
                                                 % from the proc_info
                                                 % (typeclass_infos)
+                        pred_markers,           % from the pred_info
                         pred_or_func,
                         string,                 % pred/func name
+                        aditi_owner,            % Aditi owner
                         module_info
                 ).
 
@@ -156,7 +159,9 @@
         pred_info_name(PredInfo0, PredName),
         pred_info_get_is_pred_or_func(PredInfo0, PredOrFunc),
         pred_info_typevarset(PredInfo0, TypeVarSet0),
+        pred_info_get_markers(PredInfo0, Markers),
         pred_info_get_class_context(PredInfo0, Constraints0),
+        pred_info_get_aditi_owner(PredInfo0, Owner),
         proc_info_varset(ProcInfo0, VarSet0),
         proc_info_vartypes(ProcInfo0, VarTypes0),
         proc_info_goal(ProcInfo0, Goal0),
@@ -165,10 +170,11 @@
 
         % process the goal
         Info0 = lambda_info(VarSet0, VarTypes0, Constraints0, TypeVarSet0,
-                TVarMap0, TCVarMap0, PredOrFunc, PredName, ModuleInfo0),
+                TVarMap0, TCVarMap0, Markers, PredOrFunc, 
+                PredName, Owner, ModuleInfo0),
         lambda__process_goal(Goal0, Goal, Info0, Info),
         Info = lambda_info(VarSet, VarTypes, Constraints, TypeVarSet, 
-                TVarMap, TCVarMap, _, _, ModuleInfo),
+                TVarMap, TCVarMap, _, _, _, _, ModuleInfo),
 
         % set the new values of the fields in proc_info and pred_info
         proc_info_set_goal(ProcInfo0, Goal, ProcInfo1),
@@ -269,7 +275,7 @@
 lambda__process_lambda(PredOrFunc, Vars, Modes, Det, OrigNonLocals0, LambdaGoal,
                 Unification0, Functor, Unification, LambdaInfo0, LambdaInfo) :-
         LambdaInfo0 = lambda_info(VarSet, VarTypes, Constraints, TVarSet,
-                        TVarMap, TCVarMap, POF, PredName, ModuleInfo0),
+                TVarMap, TCVarMap, Markers, POF, PredName, Owner, ModuleInfo0),
         % XXX existentially typed lambda expressions are not yet supported
         % (see the documentation at top of this file)
         ExistQVars = [],
@@ -278,14 +284,15 @@
         lambda__transform_lambda(PredOrFunc, PredName, Vars, Modes, Det,
                 OrigNonLocals0, ExtraTypeInfos, LambdaGoal, Unification0,
                 VarSet, VarTypes, Constraints, TVarSet, TVarMap, TCVarMap,
-                ModuleInfo0, Functor, Unification, ModuleInfo),
+                Markers, Owner, ModuleInfo0, Functor, Unification, ModuleInfo),
         LambdaInfo = lambda_info(VarSet, VarTypes, Constraints, TVarSet,
-                        TVarMap, TCVarMap, POF, PredName, ModuleInfo).
+                TVarMap, TCVarMap, Markers, POF, PredName, Owner, ModuleInfo).
 
 lambda__transform_lambda(PredOrFunc, OrigPredName, Vars, Modes, Detism,
                 OrigVars, ExtraTypeInfos, LambdaGoal, Unification0,
                 VarSet, VarTypes, Constraints, TVarSet, TVarMap, TCVarMap,
-                ModuleInfo0, Functor, Unification, ModuleInfo) :-
+                Markers, Owner, ModuleInfo0, Functor,
+                Unification, ModuleInfo) :-
         (
                 Unification0 = construct(Var0, _, _, UniModes0)
         ->
@@ -420,6 +427,39 @@
                 list__append(ArgModes1, Modes, AllArgModes),
                 map__apply_to_list(AllArgVars, VarTypes, ArgTypes),
 
+                ( 
+                        % Pass through the aditi markers for 
+                        % aggregate query closures.
+                        % XXX we should differentiate between normal
+                        % top-down closures and aggregate query closures,
+                        % possibly by using a different type for aggregate
+                        % queries. Currently all nondet lambda expressions
+                        % within Aditi predicates are treated as aggregate
+                        % inputs.
+                        determinism_components(Detism, _, at_most_many),
+                        check_marker(Markers, aditi)
+                ->
+                        markers_to_marker_list(Markers, MarkerList0),
+                        list__filter(
+                            lambda([Marker::in] is semidet, 
+                                % Pass through only Aditi markers.
+                                % Don't pass through `context' markers, since
+                                % they are useless for non-recursive predicates
+                                % such as the created predicate.
+                                ( Marker = aditi
+                                ; Marker = dnf
+                                ; Marker = psn
+                                ; Marker = naive
+                                ; Marker = supp_magic
+                                ; Marker = aditi_memo
+                                ; Marker = aditi_no_memo
+                                )),
+                                MarkerList0, MarkerList),
+                        marker_list_to_markers(MarkerList, LambdaMarkers)
+                ;
+                        init_markers(LambdaMarkers)
+                ),
+
                 % Choose an args_method which is always directly callable
                 % from do_call_*_closure even if the inputs don't preceed
                 % the outputs in the declaration. mercury_ho_call.c requires
@@ -439,10 +479,10 @@
                         AllArgModes, Detism, LambdaGoal, LambdaContext,
                         TVarMap, TCVarMap, ArgsMethod, ProcInfo),
 
-                init_markers(Markers),
                 pred_info_create(ModuleName, PredName, TVarSet, ExistQVars,
-                        ArgTypes, true, LambdaContext, local, Markers,
-                        PredOrFunc, Constraints, ProcInfo, ProcId, PredInfo),
+                        ArgTypes, true, LambdaContext, local, LambdaMarkers,
+                        PredOrFunc, Constraints, Owner, ProcInfo,
+                        ProcId, PredInfo),
 
                 % save the new predicate in the predicate table
 


--- magic.m	1998/07/07 06:43:06	1.47
+++ magic.m	1998/07/20 03:31:09
@@ -132,11 +132,15 @@
 % Any closures occurring in Aditi procedures must not have curried arguments.
 % Closures may only be used for aggregates.
 %
-% This should attempt to reorder within rules so that no supplementary
+% XXX This should attempt to reorder within rules so that no supplementary
 % predicates are created with partially instantiated arguments, since Aditi
 % can only handle ground terms in relations. The problem occurs if there are
 % partially instantiated terms live across a database predicate call. At the
 % moment an error is reported.
+%
+% Note that the transformation introduces new mangled predicate names,
+% but these should not show up in the generated C code so util/mdemangle does
+% not need to handle them.
 % 
 %-----------------------------------------------------------------------------%
 :- module magic.
@@ -172,12 +176,12 @@
 		% Add magic procedures, do some transformation on the goals.
 	maybe_write_string(Verbose, "% preprocessing module\n"),
 	maybe_flush_output(Verbose),
-	{ list__foldl(magic__preprocess_sub_module, Ordering, Info1, Info2) },
+	{ list__foldl(magic__preprocess_scc, Ordering, Info1, Info2) },
 
 		% Do the transformation.
 	maybe_write_string(Verbose, "% processing module\n"),
 	maybe_flush_output(Verbose),
-	list__foldl2(magic__process_sub_module, Ordering, Info2, Info3),
+	list__foldl2(magic__process_scc, Ordering, Info2, Info3),
 
 	{ magic_info_get_module_info(ModuleInfo2, Info3, Info) },
 	{ magic_info_get_errors(Errors, Info, _) },
@@ -229,7 +233,7 @@
 magic__process_imported_procs_2(_, []) --> [].
 magic__process_imported_procs_2(PredId, [ProcId | ProcIds]) -->
 	{ PredProcId = proc(PredId, ProcId) },
-	magic__get_sub_module_inputs([PredProcId], InputTypes, InputModes),
+	magic__get_scc_inputs([PredProcId], InputTypes, InputModes),
 	magic__adjust_pred_info([PredProcId], InputTypes, 
 		InputModes, PredProcId),
 	magic__process_imported_procs_2(PredId, ProcIds).
@@ -260,7 +264,7 @@
 		PredInfo0, ProcInfo0) },
 
 	% Remove aditi:states, convert arguments to output.
-	{ pred_info_arg_types(PredInfo0, TVarSet, ArgTypes0) },
+	{ pred_info_arg_types(PredInfo0, TVarSet, ExistQVars, ArgTypes0) },
 	{ proc_info_argmodes(ProcInfo0, ArgModes0) },
 	{ proc_info_headvars(ProcInfo0, HeadVars0) },
 	{ magic_util__remove_aditi_state(ArgTypes0, ArgTypes0, ArgTypes) },
@@ -268,7 +272,8 @@
 	{ list__map(magic_util__mode_to_output_mode(ModuleInfo0),
 		ArgModes1, ArgModes) },
 	{ magic_util__remove_aditi_state(ArgTypes0, HeadVars0, HeadVars) },
-	{ pred_info_set_arg_types(PredInfo0, TVarSet, ArgTypes, PredInfo) },
+	{ pred_info_set_arg_types(PredInfo0, TVarSet, ExistQVars,
+		ArgTypes, PredInfo) },
 	{ proc_info_set_argmodes(ProcInfo0, ArgModes, ProcInfo1) },
 	{ proc_info_set_headvars(ProcInfo1, HeadVars, ProcInfo) },
 	{ module_info_set_pred_proc_info(ModuleInfo0,
@@ -281,15 +286,15 @@
 	% Go over each sub-module adding in the input arguments for each 
 	% procedure, allocating the magic predicates, filling in the 
 	% magic_map, pred_map and magic_proc_info fields of the magic_info.
-:- pred magic__preprocess_sub_module(aditi_sub_module::in,
+:- pred magic__preprocess_scc(aditi_scc::in,
 		magic_info::in, magic_info::out) is det.
 
-magic__preprocess_sub_module(aditi_sub_module(SubModule0, EntryPoints)) --> 
-	list__foldl(magic__check_scc, SubModule0),
-	{ list__condense(SubModule0, SubModule) },
-	magic__get_sub_module_inputs(EntryPoints, InputTypes, InputModes),
+magic__preprocess_scc(aditi_scc(SCC0, EntryPoints)) --> 
+	list__foldl(magic__check_scc, SCC0),
+	{ list__condense(SCC0, SCC) },
+	magic__get_scc_inputs(EntryPoints, InputTypes, InputModes),
 	list__foldl(magic__adjust_pred_info(EntryPoints,
-		InputTypes, InputModes), SubModule).
+		InputTypes, InputModes), SCC).
 
 :- pred magic__check_scc(list(pred_proc_id)::in,
 		magic_info::in, magic_info::out) is det.
@@ -342,17 +347,17 @@
 
 	% Work out the types and modes of the input relations that need
 	% to be passed around the sub-module.
-:- pred magic__get_sub_module_inputs(list(pred_proc_id)::in, list(type)::out,
+:- pred magic__get_scc_inputs(list(pred_proc_id)::in, list(type)::out,
 		list(mode)::out, magic_info::in, magic_info::out) is det.
 
-magic__get_sub_module_inputs([], [], []) --> [].
-magic__get_sub_module_inputs([PredProcId | PredProcIds],
+magic__get_scc_inputs([], [], []) --> [].
+magic__get_scc_inputs([PredProcId | PredProcIds],
 		[Type | Types], [Mode | Modes]) -->
 	magic_info_get_module_info(ModuleInfo),
 	{ module_info_pred_proc_info(ModuleInfo, PredProcId,
 		PredInfo, ProcInfo) },
 	{ proc_info_argmodes(ProcInfo, ArgModes0) },
-	{ pred_info_arg_types(PredInfo, _, ArgTypes0) },
+	{ pred_info_arg_types(PredInfo, ArgTypes0) },
 	{ magic_util__remove_aditi_state(ArgTypes0, ArgTypes0, ArgTypes) },
 	{ magic_util__remove_aditi_state(ArgTypes0, ArgModes0, ArgModes) },
 	{ partition_args(ModuleInfo, ArgModes, ArgModes, InputModes, _) },
@@ -367,7 +372,7 @@
  	{ Inst = ground(unique, yes(pred_inst_info(predicate, 
 				InputRelModes, nondet))) },
 	{ Mode = (Inst -> Inst) },
-	magic__get_sub_module_inputs(PredProcIds, Types, Modes).
+	magic__get_scc_inputs(PredProcIds, Types, Modes).
 
 %-----------------------------------------------------------------------------%
 
@@ -413,28 +418,28 @@
 	{ pred_info_module(PredInfo0, Module) },
 	{ pred_info_name(PredInfo0, Name) },
 	{ pred_info_get_markers(PredInfo0, Markers) },
-	{ proc_id_to_int(ProcId, ProcInt) },
 
 	( { check_marker(Markers, base_relation) } ->
-		{ NewName = Name }
+		{ NewName = qualified(Module, Name) }
 	;
-		{ string__format("%s__aditi%i",
-			[s(Name), i(ProcInt)], NewName) }
+		magic_util__make_pred_name(PredInfo0, ProcId,
+			"Aditi_Proc_For", NewName)
 	),
 
-	{ pred_info_arg_types(PredInfo0, TVarSet, ArgTypes) },
+	{ pred_info_arg_types(PredInfo0, TVarSet, ExistQVars, ArgTypes) },
 	{ pred_info_context(PredInfo0, Context) },
 	{ pred_info_import_status(PredInfo0, Status) },
 	{ pred_info_get_is_pred_or_func(PredInfo0, PredOrFunc) },
 	{ pred_info_get_aditi_owner(PredInfo0, Owner) },
 		% type classes aren't supported in Aditi.
-	{ ClassConstraints = [] },
-	{ pred_info_create(Module, qualified(Module, NewName), 
-		TVarSet, ArgTypes, true, Context, Status, Markers, 
+	{ ClassConstraints = constraints([], []) },
+	{ pred_info_create(Module, NewName, TVarSet,
+		ExistQVars, ArgTypes, true, Context, Status, Markers, 
 		PredOrFunc, ClassConstraints, Owner, ProcInfo0, 
 		NewProcId, NewPredInfo) },
 
-	{ module_info_get_predicate_table(ModuleInfo0, PredTable0) },
+	magic_info_get_module_info(ModuleInfo1),
+	{ module_info_get_predicate_table(ModuleInfo1, PredTable0) },
 	{ predicate_table_insert(PredTable0, NewPredInfo, NewPredId, 
 		PredTable) },
 	{ module_info_set_predicate_table(ModuleInfo0, PredTable,
@@ -524,7 +529,7 @@
 	% Check that the argument types and modes 
 	% are legal for Aditi procedures.
 	%
-	{ pred_info_arg_types(PredInfo0, TVarSet, ArgTypes0) },
+	{ pred_info_arg_types(PredInfo0, TVarSet, ExistQVars, ArgTypes0) },
 	{ proc_info_headvars(ProcInfo0, HeadVars0) },
 	{ pred_info_context(PredInfo0, Context) },
 	{ proc_info_argmodes(ProcInfo0, ArgModes0) },
@@ -584,7 +589,8 @@
 		ThisProcInfo, MagicProcInfo) },
 	magic_info_set_magic_proc_info(MagicProcInfo),
 
-	{ pred_info_set_arg_types(PredInfo0, TVarSet, ArgTypes, PredInfo) },
+	{ pred_info_set_arg_types(PredInfo0, TVarSet, ExistQVars,
+		ArgTypes, PredInfo) },
 	
 	{ proc_info_set_headvars(ProcInfo3, HeadVars, ProcInfo4) },
 	{ proc_info_set_argmodes(ProcInfo4, ArgModes, ProcInfo) },
@@ -635,7 +641,7 @@
 	{ pred_info_get_markers(ExportedPredInfo0, Markers) },
 	{ pred_info_get_aditi_owner(ExportedPredInfo0, Owner) },
 
-	{ ClassContext = [] },
+	{ ClassContext = constraints([], []) },
 	{ map__init(TVarMap) },
 	{ map__init(TCVarMap) },
 	{ varset__init(TVarSet) },
@@ -665,8 +671,8 @@
 		ExportedHeadVars, ExportedProcInfo1) },
 	{ proc_info_set_argmodes(ExportedProcInfo1,
 		ExportedArgModes, ExportedProcInfo2) },
-	{ pred_info_set_arg_types(ExportedPredInfo0, TVarSet, ExportedArgTypes, 
-		ExportedPredInfo1) },
+	{ pred_info_set_arg_types(ExportedPredInfo0, TVarSet, [],
+		ExportedArgTypes, ExportedPredInfo1) },
 
 	%
 	% Construct the input for the call to the local version.
@@ -792,7 +798,7 @@
 	{ module_info_pred_proc_info(ModuleInfo0, CPredProcId,
 		CPredInfo, CProcInfo) },
 	{ proc_info_argmodes(CProcInfo, ArgModes0) },
-	{ pred_info_arg_types(CPredInfo, _, ArgTypes) },
+	{ pred_info_arg_types(CPredInfo, ArgTypes) },
 	{ magic_util__remove_aditi_state(ArgTypes, ArgModes0, ArgModes) },
 	{ partition_args(ModuleInfo0, ArgModes, ArgModes,
 		InputArgModes, OutputArgModes) },
@@ -838,8 +844,8 @@
 		{ proc_info_set_vartypes(JoinProcInfo2,
 			VarTypes, JoinProcInfo3) },
 		{ proc_info_set_goal(JoinProcInfo3, CallGoal, JoinProcInfo) },
-		magic__build_join_pred_info(CPredInfo, JoinProcInfo,
-			HeadVars, JoinPredProcId, _JoinPredInfo1)
+		magic__build_join_pred_info(CPredProcId, CPredInfo,
+			JoinProcInfo, HeadVars, JoinPredProcId, _JoinPredInfo1)
 	;
 		% The interface procedure on the Aditi side must have
 		% only one input closure argument.
@@ -899,14 +905,14 @@
 		{ proc_info_set_headvars(JoinProcInfo2,
 			[ClosureVar | OutputArgs], JoinProcInfo3) },
 
-		magic__build_join_pred_info(CPredInfo, JoinProcInfo3,
-			[ClosureVar | OutputArgs], JoinPredProcId,
-			JoinPredInfo1),
+		magic__build_join_pred_info(CPredProcId, CPredInfo,
+			JoinProcInfo3, [ClosureVar | OutputArgs],
+			JoinPredProcId, JoinPredInfo1),
 
 		% Transform the new goal.
 		% We don't want the call to be treated as recursive.
 		magic_info_set_magic_vars([ClosureVar]),
-		magic_info_set_sub_module([]),	
+		magic_info_set_scc([]),	
 		magic_info_set_pred_info(JoinPredInfo1),
 		magic_info_set_proc_info(JoinProcInfo3),
 
@@ -932,29 +938,30 @@
 		magic_info_set_module_info(ModuleInfo)
 	).
 
-:- pred magic__build_join_pred_info(pred_info::in, proc_info::in,
-		list(var)::in, pred_proc_id::out, pred_info::out,
-		magic_info::in, magic_info::out) is det.
+:- pred magic__build_join_pred_info(pred_proc_id::in, pred_info::in,
+		proc_info::in, list(var)::in, pred_proc_id::out,
+		pred_info::out, magic_info::in, magic_info::out) is det.
 
-magic__build_join_pred_info(CPredInfo, JoinProcInfo,
+magic__build_join_pred_info(CPredProcId, CPredInfo, JoinProcInfo,
 		Args, JoinPredProcId, JoinPredInfo1) -->
 	{ proc_info_vartypes(JoinProcInfo, JoinVarTypes) },
 	{ map__apply_to_list(Args, JoinVarTypes,
 		NewArgTypes) },
 	{ pred_info_module(CPredInfo, PredModule) },
-	{ pred_info_name(CPredInfo, PredName) },
-	{ string__append(PredName, "__c_interface", NewPredName) },
+	{ CPredProcId = proc(_, CProcId) },
+	magic_util__make_pred_name(CPredInfo, CProcId,
+		"Aditi_C_Interface_Proc_For", NewPredName),
 	{ init_markers(Markers0) },
 	{ add_marker(Markers0, aditi, Markers1) },
-	{ add_marker(Markers1, no_memo, Markers2) },
+	{ add_marker(Markers1, aditi_no_memo, Markers2) },
 	{ add_marker(Markers2, naive, Markers) },
-	{ ClassContext = [] },
+	{ ClassContext = constraints([], []) },
 	{ pred_info_get_aditi_owner(CPredInfo, User) },
 	{ varset__init(TVarSet) },	% must be empty.
 	{ term__context_init(DummyContext) },
-	{ pred_info_create(PredModule,
-		qualified(PredModule, NewPredName),
-		TVarSet, NewArgTypes, true, DummyContext,
+	{ ExistQVars = [] },
+	{ pred_info_create(PredModule, NewPredName,
+		TVarSet, ExistQVars, NewArgTypes, true, DummyContext,
 		exported, Markers, predicate, ClassContext, User,
 		JoinProcInfo, JoinProcId, JoinPredInfo1) },
 	{ JoinPredProcId = proc(JoinPredId, JoinProcId) },
@@ -968,8 +975,9 @@
 	magic_info_set_module_info(ModuleInfo).
 
 	% The new procedure consists of a single call to
-	% <predName>__aditi_interface, which call_gen generates
-	% as a call to do_*_aditi_aditi in extras/aditi/aditi.m.
+	% Aditi_Interface_For_Mode_x_Of__<predName>..., which
+	% call_gen generates as a call to do_*_aditi_aditi in
+	% extras/aditi/aditi.m.
 	% This procedure must use the `compact' argument convention.
 	% The arguments are:
 	% 	1 -> RL procedure name
@@ -991,8 +999,7 @@
 	{ module_info_pred_proc_info(ModuleInfo0, CPredProcId,
 		CPredInfo0, CProcInfo0) },
 	{ pred_info_module(CPredInfo0, PredModule) },
-	{ pred_info_name(CPredInfo0, PredName) },
-	{ pred_info_arg_types(CPredInfo0, TVarSet, ArgTypes) },
+	{ pred_info_arg_types(CPredInfo0, TVarSet, ExistQVars, ArgTypes) },
 	{ proc_info_argmodes(CProcInfo0, ArgModes) },
 	{ proc_info_headvars(CProcInfo0, HeadVars) },
 
@@ -1088,21 +1095,24 @@
 		DoCallAditiArgModes, Detism, DummyGoal, DummyContext,
 		TVarMap, TCVarMap, compact, DoCallAditiProcInfo) },
 
-	{ string__append(PredName, "__do_aditi_call", CallPredName) },
+	{ CPredProcId = proc(_, CProcId) },
+	magic_util__make_pred_name(CPredInfo1, CProcId, "Do_Aditi_Call_For",
+		CallPredName),
 	{ init_markers(Markers0) },
 	{ add_marker(Markers0, aditi_interface, Markers) },
-	{ ClassContext = [] },
+	{ ClassContext = constraints([], []) },
 	{ pred_info_get_aditi_owner(CPredInfo1, User) },
-	{ pred_info_create(PredModule, qualified(PredModule, CallPredName),
-		TVarSet, DoCallAditiArgTypes, true, DummyContext,
+	{ pred_info_create(PredModule, CallPredName,
+		TVarSet, ExistQVars, DoCallAditiArgTypes, true, DummyContext,
 		imported, Markers, predicate, ClassContext, User,
 		DoCallAditiProcInfo, DoCallAditiProcId, DoCallAditiPredInfo) },
 
-	{ module_info_get_predicate_table(ModuleInfo1, PredTable0) },
+	magic_info_get_module_info(ModuleInfo2),
+	{ module_info_get_predicate_table(ModuleInfo2, PredTable0) },
 	{ predicate_table_insert(PredTable0, DoCallAditiPredInfo,
 		DoCallAditiPredId, PredTable) },
-	{ module_info_set_predicate_table(ModuleInfo1,
-		PredTable, ModuleInfo2) },
+	{ module_info_set_predicate_table(ModuleInfo2,
+		PredTable, ModuleInfo3) },
 
 	%
 	% Make the C procedure call the new alias for do_*_aditi_call.
@@ -1112,8 +1122,8 @@
 		ModuleInfo2, GoalDelta) },
 	{ goal_info_init(CallNonLocals, GoalDelta, Detism, CallGoalInfo) },
 	{ DoCallAditiGoal = call(DoCallAditiPredId, DoCallAditiProcId,
-		DoCallAditiArgs, not_builtin, no,
-		qualified(PredModule, CallPredName)) - CallGoalInfo },
+		DoCallAditiArgs, not_builtin, no, CallPredName)
+		- CallGoalInfo },
 	{ list__condense([[ProcNameGoal, InputArgsGoal, InputSchemaGoal,
 		OutputArgsGoal], TypeInfoGoals, [DoCallAditiGoal]], Goals) },
 	{ set__list_to_set(HeadVars, GoalNonLocals) },
@@ -1128,8 +1138,7 @@
 	{ remove_marker(CMarkers2, base_relation, CMarkers) },
 	{ pred_info_set_markers(CPredInfo1, CMarkers, CPredInfo) },
 
-	{ CPredProcId = proc(CPredId, CProcId) },
-	{ module_info_set_pred_proc_info(ModuleInfo2, CPredId, CProcId,
+	{ module_info_set_pred_proc_info(ModuleInfo3, CPredProcId,
 		CPredInfo, CProcInfo, ModuleInfo) },
 	magic_info_set_module_info(ModuleInfo).
 
@@ -1143,7 +1152,7 @@
 	{ rl__proc_name_to_string(ProcName, ProcNameStr) },
 	{ module_info_pred_proc_info(ModuleInfo, CPredProcId,
 		CPredInfo, CProcInfo) },
-	{ pred_info_arg_types(CPredInfo, _, ArgTypes0) },
+	{ pred_info_arg_types(CPredInfo, ArgTypes0) },
 	{ proc_info_argmodes(CProcInfo, ArgModes0) },
 	{ magic_util__remove_aditi_state(ArgTypes0, ArgTypes0, ArgTypes) },
 	{ magic_util__remove_aditi_state(ArgTypes0, ArgModes0, ArgModes) },
@@ -1157,8 +1166,10 @@
 magic__make_type_info_vars(Types, TypeInfoVars, TypeInfoGoals,
 		PredInfo0, PredInfo, ProcInfo0, ProcInfo) -->
 	magic_info_get_module_info(ModuleInfo0),
-	{ poly_info_init(ModuleInfo0, PredInfo0, ProcInfo0, PolyInfo0) },
-	{ polymorphism__make_type_info_vars(Types,
+	{ init_poly_info(ModuleInfo0, PredInfo0, ProcInfo0, PolyInfo0) },
+	{ ExistQVars = [] },
+	{ term__context_init(Context) },
+	{ polymorphism__make_type_info_vars(Types, ExistQVars, Context,
 		TypeInfoVars, TypeInfoGoals, PolyInfo0, PolyInfo) },
 	{ poly_info_extract(PolyInfo, PredInfo0, PredInfo,
 		ProcInfo0, ProcInfo, ModuleInfo) },
@@ -1298,16 +1309,18 @@
 	{ module_info_name(ModuleInfo0, ModuleName) },
 	{ predicate_module(ModuleInfo0, CPredId, PredModule) },
 	{ predicate_name(ModuleInfo0, CPredId, PredName) },
-	{ string__append(PredName, "__magic", NewPredName) },
+	{ string__append(PredName, "Magic_Proc_For", NewPredName) },
 	{ SymName = qualified(PredModule, NewPredName) },
 
 	{ list__append(MagicTypes, InputTypes, AllArgTypes) },
 	{ varset__init(TVarSet) },
 	{ pred_info_get_aditi_owner(PredInfo, Owner) },
-	{ ClassConstraints = [] }, % types must all be ground
-	{ pred_info_create(ModuleName, SymName, TVarSet, AllArgTypes, 
-		true, Context, local, Markers, predicate, ClassConstraints,
-		Owner, ProcInfo, MagicProcId, MagicPredInfo) },
+	{ ClassConstraints = constraints([], []) },
+	{ ExistQVars = [] },
+	{ pred_info_create(ModuleName, SymName, TVarSet, ExistQVars,
+		AllArgTypes, true, Context, local, Markers, predicate,
+		ClassConstraints, Owner, ProcInfo, MagicProcId,
+		MagicPredInfo) },
 
 	{ module_info_get_predicate_table(ModuleInfo0, PredTable0) },
 	{ predicate_table_insert(PredTable0, 
@@ -1638,13 +1651,13 @@
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
 
-:- pred magic__process_sub_module(aditi_sub_module::in, magic_info::in,
+:- pred magic__process_scc(aditi_scc::in, magic_info::in,
 		magic_info::out, io__state::di, io__state::uo) is det.
 
-magic__process_sub_module(aditi_sub_module(SubModule0, _), Info0, Info) -->
-	{ list__condense(SubModule0, SubModule) },
-	{ magic_info_set_sub_module(SubModule, Info0, Info1) },
-	{ list__foldl(magic__process_proc, SubModule, Info1, Info) }.
+magic__process_scc(aditi_scc(SCC0, _), Info0, Info) -->
+	{ list__condense(SCC0, SCC) },
+	{ magic_info_set_scc(SCC, Info0, Info1) },
+	{ list__foldl(magic__process_proc, SCC, Info1, Info) }.
 
 %-----------------------------------------------------------------------------%
 
--- magic_util.m	1998/07/07 06:43:06	1.6
+++ magic_util.m	1998/07/20 03:09:13
@@ -8,6 +8,7 @@
 %
 % Predicates used by magic.m and context.m to transform Aditi procedures.
 %
+% Note: this module contains multiple interface sections.
 %-----------------------------------------------------------------------------%
 :- module magic_util.
 
@@ -101,12 +102,17 @@
 :- pred magic_util__restrict_nonlocals(set(var)::in, set(var)::out,
 		magic_info::in, magic_info::out) is det.
 
+	% Given a prefix, create a unique new name for the predicate
+	% using prog_util__make_pred_name_with_context.
+:- pred magic_util__make_pred_name(pred_info::in, proc_id::in, string::in,
+		sym_name::out, magic_info::in, magic_info::out) is det.
+
 %-----------------------------------------------------------------------------%
 
 :- implementation.
 
 :- import_module hlds_data, code_util, type_util, mode_util, inst_match.
-:- import_module instmap, goal_util, prog_out, hlds_out, error_util.
+:- import_module instmap, goal_util, prog_out, hlds_out, error_util, prog_util.
 
 :- import_module assoc_list,  int, require, string.
 
@@ -250,7 +256,7 @@
 		Args0, Goal0, Call) :-
 	module_info_pred_proc_info(ModuleInfo, PredId, ProcId,
 		PredInfo, ProcInfo),
-	pred_info_arg_types(PredInfo, _, ArgTypes),
+	pred_info_arg_types(PredInfo, ArgTypes),
 	proc_info_argmodes(ProcInfo, ArgModes0),
 	magic_util__remove_aditi_state(ArgTypes, ArgModes0, ArgModes),
 	magic_util__remove_aditi_state(ArgTypes, Args0, Args),
@@ -282,6 +288,21 @@
 		NonLocals1, NonLocals2) },
 	{ set__sorted_list_to_set(NonLocals2, NonLocals) }.
 
+magic_util__make_pred_name(PredInfo, ProcId, Prefix0, Name) -->
+	magic_info_get_module_info(ModuleInfo0),
+	{ module_info_next_lambda_count(ModuleInfo0, Count, ModuleInfo) },
+	magic_info_set_module_info(ModuleInfo),
+	{ pred_info_get_is_pred_or_func(PredInfo, PredOrFunc) },
+	{ pred_info_module(PredInfo, Module) },
+	{ pred_info_name(PredInfo, Name0) },
+	{ proc_id_to_int(ProcId, ProcInt) },
+	{ string__int_to_string(ProcInt, ProcStr) },
+	{ string__append_list([Prefix0, "_Mode_", ProcStr, "_Of"], Prefix) },
+	{ pred_info_context(PredInfo, Context) },
+	{ term__context_line(Context, Line) },
+	{ make_pred_name_with_context(Module, Prefix, PredOrFunc, Name0,
+		Line, Count, Name) }.
+
 %-----------------------------------------------------------------------------%
 
 magic_util__setup_call(PrevGoals, DBCall1, NonLocals, Goals) -->
@@ -379,6 +400,8 @@
 	).
 
 	% Construct the input for the query for an aggregate.
+	% XXX we should check that the input query of an aggregate
+	% is an Aditi relation, not a top-down Mercury predicate.
 :- pred magic_util__setup_aggregate_input(hlds_goal::in, list(hlds_goal)::out,
 		magic_info::in, magic_info::out) is det.
 
@@ -472,8 +495,8 @@
 	{ goal_info_set_determinism(GoalInfo1, 
 		nondet, GoalInfo) },
 
-	magic_info_get_sub_module(SubModule),
-	( { list__member(PredProcId0, SubModule) } ->
+	magic_info_get_scc(SCC),
+	( { list__member(PredProcId0, SCC) } ->
 		magic_info_get_magic_vars(MagicVars),
 		{ list__append(MagicVars, InputArgs, AllMagicVars) },
 		magic_util__add_to_magic_predicate(PredProcId,
@@ -685,13 +708,51 @@
 		{ LambdaGoal = call(_, _, CallArgs, _, _, _) - _ },
 		{ list__append(LambdaInputs, LambdaVars, CallArgs) }
 	->
+		% No projection is needed.
 		{ SuppCall = LambdaGoal }
 	;
 		{ term__context_init(Context) },
 		{ goal_to_conj_list(LambdaGoal, LambdaGoalList) },
+
+		%
+		% The projecting goal must be generated inline.
+		% Otherwise there could be problems with transformed
+		% code such as:
+		% 
+		% q(InP, X, Y, Z) :-
+		% 	magic_p(InP, X, Y),
+		% 	InR = q_supp1(InP),
+		%	r(InR, A, Z),
+		% 	Y == A.
+		% q_supp1(InP, Y) :-
+		% 	magic_p(InP, _X, Y).	
+		%
+		% 'r/3' is defined in a lower SCC.
+		%
+		% rl_gen could produce the recursive part of this SCC as:
+		% 
+		% toplabel:
+		% if (diffs empty) goto bottomlabel:
+		% 	evaluate magic_p;
+		%	evaluate q;
+		%	evaluate q_supp1;
+		% goto toplabel;
+		% bottomlabel:
+		%
+		% In this case, if `q_supp1/2' was not generated inline,
+		% the input relation for the call to `r/3' in `q/4'
+		% would use the value of `magic_p/3' from the previous
+		% iteration, but the join of `magic_p/3' and the result
+		% of `r/3' uses the value of `magic_p/3' from the
+		% current iteration.
+		%
+		% The generate_inline marker forces rl_gen.m evaluate 
+		% `q_supp1/2' in the correct location so that it uses
+		% the correct version of `magic_p/3' as input to `r/3'.
+		% 
 		magic_util__create_supp_call(LambdaGoalList, LambdaInputs,
-			LambdaVars, Context, [no_memo, naive, generate_inline],
-			SuppCall)
+			LambdaVars, Context,
+			[aditi_no_memo, naive, generate_inline], SuppCall)
 	),
 
 	magic_info_get_module_info(ModuleInfo),
@@ -955,13 +1016,12 @@
 	%
 	% Fill in the fields of the new predicate.
 	%
-	magic_info_get_module_info(ModuleInfo0),
 	magic_info_get_pred_info(PredInfo),
-	{ pred_info_name(PredInfo, Name) },
-	magic_info_get_next_supp_id(SuppId),
-	{ string__format("%s__supp%i", [s(Name), i(SuppId)], NewName) },
+	magic_info_get_curr_pred_proc_id(proc(_, ProcId)),
+	magic_util__make_pred_name(PredInfo, ProcId, "Supp_Proc_For", NewName),
+
+	magic_info_get_module_info(ModuleInfo0),
 	{ proc_info_get_initial_instmap(ProcInfo, ModuleInfo0, InstMap) },
-	{ pred_info_arg_types(PredInfo, TVarSet, _) },
 	{ pred_info_get_aditi_owner(PredInfo, Owner) },
 	{ pred_info_get_markers(PredInfo, Markers0) },
 	{ AddMarkers = lambda([Marker::in, Ms0::in, Ms::out] is det,
@@ -971,13 +1031,16 @@
 
 	% Add the predicate to the predicate table.
 	{ conj_list_to_goal(Goals, GoalInfo, SuppGoal) },
-	{ ClassConstraints = [] },
+	{ varset__init(TVarSet) },
+	{ ClassConstraints = constraints([], []) },
 	{ map__init(TVarMap) },
 	{ map__init(TCVarMap) },
 	{ proc_info_varset(ProcInfo, VarSet) },
+	{ unqualify_name(NewName, NewPredName) },
 	{ hlds_pred__define_new_pred(SuppGoal, SuppCall, SuppArgs, InstMap,
-		NewName, TVarSet, VarTypes, ClassConstraints, TVarMap,
-		TCVarMap, VarSet, Markers, Owner, ModuleInfo0, ModuleInfo, _) },
+		NewPredName, TVarSet, VarTypes, ClassConstraints, TVarMap,
+		TCVarMap, VarSet, Markers, Owner,
+		ModuleInfo0, ModuleInfo, _) },
 	magic_info_set_module_info(ModuleInfo).
 
 %-----------------------------------------------------------------------------%
@@ -1180,7 +1243,7 @@
 		set(argument_error)::in, set(argument_error)::out, 
 		magic_info::in, magic_info::out) is det.
 		
-magic_util__check_ctor(Parents, _ - CtorArgs, Errors0, Errors) -->
+magic_util__check_ctor(Parents, ctor(_, _, _, CtorArgs), Errors0, Errors) -->
 	{ assoc_list__values(CtorArgs, CtorArgTypes) },
 	list__foldl2(magic_util__traverse_type(no, Parents), 
 		CtorArgTypes, Errors0, Errors).
@@ -1230,7 +1293,7 @@
 		magic_info::out) is det.
 :- pred magic_info_get_proc_info(proc_info::out, magic_info::in,
 		magic_info::out) is det.
-:- pred magic_info_get_sub_module(list(pred_proc_id)::out, magic_info::in,
+:- pred magic_info_get_scc(list(pred_proc_id)::out, magic_info::in,
 		magic_info::out) is det.
 :- pred magic_info_get_magic_map(magic_map::out, magic_info::in,
 		magic_info::out) is det.
@@ -1263,7 +1326,7 @@
 		magic_info::out) is det.
 :- pred magic_info_set_proc_info(proc_info::in, magic_info::in,
 		magic_info::out) is det.
-:- pred magic_info_set_sub_module(list(pred_proc_id)::in, magic_info::in,
+:- pred magic_info_set_scc(list(pred_proc_id)::in, magic_info::in,
 		magic_info::out) is det.
 :- pred magic_info_set_magic_map(magic_map::in, magic_info::in,
 		magic_info::out) is det.
@@ -1368,8 +1431,8 @@
 		error("magic_info_get_proc_info")
 	).
 
-magic_info_get_sub_module(SubModule, Info, Info) :-
-	Info = magic_info(_,_,_,_,SubModule,_,_,_,_,_,_,_,_,_,_,_,_,_).
+magic_info_get_scc(SCC, Info, Info) :-
+	Info = magic_info(_,_,_,_,SCC,_,_,_,_,_,_,_,_,_,_,_,_,_).
 
 magic_info_get_magic_map(Map, Info, Info) :-
 	Info = magic_info(_,_,_,_,_,Map,_,_,_,_,_,_,_,_,_,_,_,_).
@@ -1424,9 +1487,9 @@
 	Info0 = magic_info(A,B,C,_,E,F,G,H,I,J,K,L,M,N,O,P,Q,R),
 	Info = magic_info(A,B,C,yes(ProcInfo),E,F,G,H,I,J,K,L,M,N,O,P,Q,R).
 
-magic_info_set_sub_module(SubModule, Info0, Info) :-
+magic_info_set_scc(SCC, Info0, Info) :-
 	Info0 = magic_info(A,B,C,D,_,F,G,H,I,J,K,L,M,N,O,P,Q,R),
-	Info = magic_info(A,B,C,D,SubModule,F,G,H,I,J,K,L,M,N,O,P,Q,R).
+	Info = magic_info(A,B,C,D,SCC,F,G,H,I,J,K,L,M,N,O,P,Q,R).
 
 magic_info_set_magic_map(MagicMap, Info0, Info) :-
 	Info0 = magic_info(A,B,C,D,E,_,G,H,I,J,K,L,M,N,O,P,Q,R),


<<< Changed section only for make_hlds.m >>>
Index: make_hlds.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/make_hlds.m,v
retrieving revision 1.269
diff -u -t -u -r1.269 make_hlds.m
--- make_hlds.m	1998/07/08 20:56:38	1.269
+++ make_hlds.m	1998/07/28 23:47:18
@@ -461,6 +511,37 @@
 
 %-----------------------------------------------------------------------------%
 
+        % If there are local, exported or opt_imported Aditi procedures
+        % enable Aditi compilation. opt_imported procedures which are not
+        % specialised will be made imported by dead_proc_elim.m, and
+        % having Aditi compilation enabled for them will be harmless.
+:- pred maybe_enable_aditi_compilation(item_status, term__context,
+                module_info, module_info, io__state, io__state) is det.
+:- mode maybe_enable_aditi_compilation(in, in, in, out, di, uo) is det.
+
+maybe_enable_aditi_compilation(Status, Context, Module0, Module) -->
+        { Status = item_status(ItemStatus, _) },
+        ( { ItemStatus \= imported } ->
+                globals__io_lookup_bool_option(aditi, Aditi),
+                ( { Aditi = no } ->
+                        prog_out__write_context(Context),
+                        io__write_string("Error: compilation of Aditi procedures\n"),
+                        prog_out__write_context(Context),
+                        io__write_string("  requires the `--aditi' option.\n"),
+                        io__set_exit_status(1),
+                        { module_info_incr_errors(Module0, Module) }
+                ;
+                        % There are local Aditi procedures - enable Aditi
+                        % code generation.
+                        { module_info_set_do_aditi_compilation(Module0,
+                                Module) }
+                )
+        ;
+                { Module = Module0 }
+        ).
+
+%-----------------------------------------------------------------------------%
+


<<< Line wrappings in mercury_compile.m undone >>>

<<< Changed section only >>>
Index: modules.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/modules.m,v
retrieving revision 1.83
diff -u -t -u -r1.83 modules.m
--- modules.m	1998/07/26 16:35:35	1.83
+++ modules.m	1998/07/29 04:06:36
 % pragma `obsolete', `terminates', `does_not_terminate' 


-% `termination_info' and `check_termination' declarations
-% are supposed to go in the interface,
+% `termination_info', `check_termination', `aditi', `base_relation'
+% and `owner' pragma declarations are supposed to go in the interface,
 % but all other pragma declarations are implementation
 % details only, and should go in the implementation.
 
@@ -847,6 +849,17 @@
 pragma_allowed_in_interface(terminates(_, _), yes).
 pragma_allowed_in_interface(does_not_terminate(_, _), yes).
 pragma_allowed_in_interface(check_termination(_, _), yes).
+        % `aditi', `base_relation' and `owner' pragmas must be in the
+        % interface for exported preds. This is checked in make_hlds.m.
+pragma_allowed_in_interface(aditi(_, _), yes).
+pragma_allowed_in_interface(base_relation(_, _), yes).
+pragma_allowed_in_interface(supp_magic(_, _), no).
+pragma_allowed_in_interface(context(_, _), no).
+pragma_allowed_in_interface(aditi_memo(_, _), no).
+pragma_allowed_in_interface(aditi_no_memo(_, _), no).
+pragma_allowed_in_interface(naive(_, _), no).
+pragma_allowed_in_interface(psn(_, _), no).
+pragma_allowed_in_interface(owner(_, _, _), yes).
 





More information about the developers mailing list