[m-dev.] for review: Aditi updates[2]

Simon Taylor stayl at cs.mu.OZ.AU
Sat Jun 5 14:46:53 AEST 1999


Index: compiler/hlds_out.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/hlds_out.m,v
retrieving revision 1.219
diff -u -u -r1.219 hlds_out.m
--- hlds_out.m	1999/06/01 09:43:47	1.219
+++ hlds_out.m	1999/06/04 00:52:25
@@ -34,19 +34,25 @@
 
 :- import_module hlds_module, hlds_pred, hlds_goal, hlds_data.
 :- import_module prog_data, llds, instmap, term.
-:- import_module io, bool, map, list.
+:- import_module io, bool, map, list, term.
 
 %-----------------------------------------------------------------------------%
 
 :- pred hlds_out__write_type_id(type_id, io__state, io__state).
 :- mode hlds_out__write_type_id(in, di, uo) is det.
 
+:- pred hlds_out__write_class_id(class_id, io__state, io__state).
+:- mode hlds_out__write_class_id(in, di, uo) is det.
+
 :- pred hlds_out__write_cons_id(cons_id, io__state, io__state).
 :- mode hlds_out__write_cons_id(in, di, uo) is det.
 
 :- pred hlds_out__cons_id_to_string(cons_id, string).
 :- mode hlds_out__cons_id_to_string(in, out) is det.
 
+:- pred hlds_out__aditi_builtin_name(aditi_builtin, string).
+:- mode hlds_out__aditi_builtin_name(in, out) is det.
+
 	% hlds_out__write_pred_id/4 writes out a message such as
 	% 	predicate `foo:bar/3'
 	% or	function `foo:myfoo/5'
@@ -63,12 +69,24 @@
 	io__state, io__state).
 :- mode hlds_out__write_pred_proc_id(in, in, in, di, uo) is det.
 
-:- pred hlds_out__write_call_id(pred_or_func, pred_call_id,
+:- pred hlds_out__write_call_id(call_id, io__state, io__state).
+:- mode hlds_out__write_call_id(in, di, uo) is det.
+
+:- pred hlds_out__write_simple_call_id(simple_call_id, io__state, io__state).
+:- mode hlds_out__write_simple_call_id(in, di, uo) is det.
+
+:- pred hlds_out__write_simple_call_id(pred_or_func, sym_name_and_arity,
 	io__state, io__state).
-:- mode hlds_out__write_call_id(in, in, di, uo) is det.
+:- mode hlds_out__write_simple_call_id(in, in, di, uo) is det.
 
-:- pred hlds_out__write_pred_call_id(pred_call_id, io__state, io__state).
-:- mode hlds_out__write_pred_call_id(in, di, uo) is det.
+:- pred hlds_out__write_simple_call_id(pred_or_func, sym_name, arity,
+	io__state, io__state).
+:- mode hlds_out__write_simple_call_id(in, in, in, di, uo) is det.
+
+	% Write "argument %i of call to pred_or_func `foo/n'".
+:- pred hlds_out__write_call_arg_id(call_id, int,
+		io__state, io__state).
+:- mode hlds_out__write_call_arg_id(in, in, di, uo) is det.
 
 :- pred hlds_out__write_pred_or_func(pred_or_func, io__state, io__state).
 :- mode hlds_out__write_pred_or_func(in, di, uo) is det.
@@ -207,16 +225,17 @@
 
 :- import_module mercury_to_mercury, globals, options, purity, special_pred.
 :- import_module llds_out, prog_out, prog_util, (inst), instmap, trace.
-:- import_module term_io, varset, termination, term_errors, check_typeclass.
+:- import_module rl, termination, term_errors, check_typeclass.
 
-:- import_module int, string, set, std_util, assoc_list, multi_map.
-:- import_module require, getopt.
+:- import_module int, string, set, assoc_list, multi_map.
+:- import_module require, getopt, std_util, term_io, varset.
 
 
 hlds_out__write_type_id(Name - Arity) -->
-	prog_out__write_sym_name(Name),
-	io__write_string("/"),
-	io__write_int(Arity).
+	prog_out__write_sym_name_and_arity(Name / Arity).
+
+hlds_out__write_class_id(class_id(Name, Arity)) -->
+	prog_out__write_sym_name_and_arity(Name / Arity).
 
 hlds_out__cons_id_to_string(cons(SymName, Arity), String) :-
 	prog_out__sym_name_to_string(SymName, SymNameString0),
@@ -241,7 +260,7 @@
 hlds_out__cons_id_to_string(string_const(String), S) :-
 	string__append_list(["""", String, """"], S).
 hlds_out__cons_id_to_string(float_const(_), "<float>").
-hlds_out__cons_id_to_string(pred_const(_, _), "<pred>").
+hlds_out__cons_id_to_string(pred_const(_, _, _), "<pred>").
 hlds_out__cons_id_to_string(code_addr_const(_, _), "<code_addr>").
 hlds_out__cons_id_to_string(type_ctor_info_const(_, _, _), "<type_ctor_info>").
 hlds_out__cons_id_to_string(base_typeclass_info_const(_, _, _, _),
@@ -250,16 +269,14 @@
 	"<tabling_pointer>").
 
 hlds_out__write_cons_id(cons(SymName, Arity)) -->
-	prog_out__write_sym_name(SymName),
-	io__write_string("/"),
-	io__write_int(Arity).
+	prog_out__write_sym_name_and_arity(SymName / Arity).
 hlds_out__write_cons_id(int_const(Int)) -->
 	io__write_int(Int).
 hlds_out__write_cons_id(string_const(String)) -->
 	term_io__quote_string(String).
 hlds_out__write_cons_id(float_const(Float)) -->
 	io__write_float(Float).
-hlds_out__write_cons_id(pred_const(_PredId, _ProcId)) -->
+hlds_out__write_cons_id(pred_const(_PredId, _ProcId, _)) -->
 	io__write_string("<pred>").
 hlds_out__write_cons_id(code_addr_const(_PredId, _ProcId)) -->
 	io__write_string("<code_addr>").
@@ -299,19 +316,8 @@
 	->
 		io__write_string("type class method implementation")
 	;
-		hlds_out__write_pred_or_func(PredOrFunc),
-		io__write_string(" `"),
-		prog_out__write_sym_name(Module),
-		io__write_string(":"),
-		{ PredOrFunc = function ->
-			OrigArity is Arity - 1
-		;
-			OrigArity = Arity
-		},
-		io__write_string(Name),
-		io__write_string("/"),
-		io__write_int(OrigArity),
-		io__write_string("'")
+		hlds_out__write_simple_call_id(PredOrFunc,
+			qualified(Module, Name), Arity)
 	).
 
 hlds_out__write_pred_proc_id(ModuleInfo, PredId, ProcId) -->
@@ -320,21 +326,145 @@
 	{ proc_id_to_int(ProcId, ModeNum) },
 	io__write_int(ModeNum).
 
-hlds_out__write_call_id(PredOrFunc, Name/Arity) -->
+hlds_out__write_simple_call_id(PredOrFunc - Name/Arity) -->
+	hlds_out__write_simple_call_id(PredOrFunc, Name, Arity).
+
+hlds_out__write_simple_call_id(PredOrFunc, Name/Arity) -->
+	hlds_out__write_simple_call_id(PredOrFunc, Name, Arity).
+
+hlds_out__write_simple_call_id(PredOrFunc, Name, Arity) -->
 	hlds_out__write_pred_or_func(PredOrFunc),
 	io__write_string(" `"),
-	{ PredOrFunc = function ->
-		OrigArity is Arity - 1
+	{ hlds_out__simple_call_id_to_sym_name_and_arity(
+		PredOrFunc - Name/Arity, SymArity) },
+	prog_out__write_sym_name_and_arity(SymArity),
+	io__write_string("'").
+
+:- pred hlds_out__simple_call_id_to_sym_name_and_arity(simple_call_id,
+		sym_name_and_arity).
+:- mode hlds_out__simple_call_id_to_sym_name_and_arity(in, out) is det.
+
+hlds_out__simple_call_id_to_sym_name_and_arity(PredOrFunc - SymName/Arity,
+		SymName/OrigArity) :-
+	adjust_func_arity(PredOrFunc, OrigArity, Arity).
+
+hlds_out__write_call_id(call(PredCallId)) -->
+	hlds_out__write_simple_call_id(PredCallId).
+hlds_out__write_call_id(generic_call(GenericCallId)) -->
+	hlds_out__write_generic_call_id(GenericCallId).
+
+:- pred hlds_out__write_generic_call_id(generic_call_id, io__state, io__state).
+:- mode hlds_out__write_generic_call_id(in, di, uo) is det.
+
+hlds_out__write_generic_call_id(higher_order(PredOrFunc, Arity)) -->
+	{
+		PredOrFunc = predicate,
+		Name = "call"
 	;
-		OrigArity = Arity
+		PredOrFunc = function,
+		Name = "apply"
 	},
-	hlds_out__write_pred_call_id(Name/OrigArity),
-	io__write_string("'").
+	hlds_out__write_simple_call_id(PredOrFunc, unqualified(Name), Arity).
+hlds_out__write_generic_call_id(class_method(_ClassId, MethodId)) -->
+	hlds_out__write_simple_call_id(MethodId).
+hlds_out__write_generic_call_id(
+		aditi_builtin(AditiBuiltin, CallId)) -->
+	{ hlds_out__aditi_builtin_name(AditiBuiltin, Name) },
+	io__write_strings(["`", Name, "' of "]),
+	hlds_out__write_simple_call_id(CallId).
+
+hlds_out__write_call_arg_id(CallId, ArgNum) -->
+	( { ArgNum = 0 } ->
+		% We don't know which argument it was.
+		[]
+	;
+		hlds_out__write_arg_number(CallId, ArgNum),
+		io__write_string(" of ")
+	),	
+	io__write_string("call to "),
+	hlds_out__write_call_id(CallId).
+	
+:- pred hlds_out__write_arg_number(call_id, int, io__state, io__state).
+:- mode hlds_out__write_arg_number(in, in, di, uo) is det.
+
+hlds_out__write_arg_number(call(PredOrFunc - _/Arity), ArgNum) -->
+	( { PredOrFunc = function, Arity = ArgNum } ->
+		io__write_string("the return value")
+	;
+		io__write_string("argument "),
+		io__write_int(ArgNum)
+	).
+hlds_out__write_arg_number(generic_call(higher_order(PredOrFunc, Arity)),
+		ArgNum) -->
+	( { PredOrFunc = function, ArgNum = Arity } ->
+		io__write_string("the return value")
+	;
+		io__write_string("argument "),
+		io__write_int(ArgNum),
+		io__write_string(" (i.e. "),
+		( { ArgNum = 1 } ->
+			io__write_string("the "),
+			hlds_out__write_pred_or_func(PredOrFunc),
+			io__write_string(" term")
+		;
+			io__write_string("argument "),
+			{ ArgNum1 is ArgNum - 1 },
+			io__write_int(ArgNum1),
+			io__write_string(" of the called "),
+			hlds_out__write_pred_or_func(PredOrFunc)
+		)
+	),
+	io__write_string(")").
 
-hlds_out__write_pred_call_id(Name / Arity) -->
-	prog_out__write_sym_name(Name),
-	io__write_char('/'),
-	io__write_int(Arity).
+hlds_out__write_arg_number(generic_call(class_method(_, _)), ArgNum) -->
+	io__write_string("argument "),
+	io__write_int(ArgNum).
+hlds_out__write_arg_number(generic_call(aditi_builtin(Builtin, CallId)),
+		ArgNum) -->
+	hlds_out__write_aditi_builtin_arg_number(Builtin, CallId, ArgNum).
+
+:- pred hlds_out__write_aditi_builtin_arg_number(aditi_builtin, simple_call_id,
+		int, io__state, io__state).
+:- mode hlds_out__write_aditi_builtin_arg_number(in, in, in, di, uo) is det.
+
+hlds_out__write_aditi_builtin_arg_number(aditi_call(_, _, _, _), _, ArgNum) -->
+	io__write_string("argument "),
+	io__write_int(ArgNum).
+hlds_out__write_aditi_builtin_arg_number(aditi_insert(_),
+		_ - _/Arity, ArgNum) -->
+	io__write_string("argument "),
+	( { ArgNum =< Arity } ->
+		io__write_int(ArgNum),
+		io__write_string(" of the inserted tuple")
+	;
+		io__write_int(ArgNum - Arity + 1)
+	).
+hlds_out__write_aditi_builtin_arg_number(aditi_delete(_, pred_term),
+		_, ArgNum) -->
+	io__write_string("argument "),
+	io__write_int(ArgNum).
+hlds_out__write_aditi_builtin_arg_number(aditi_delete(_, sym_name_and_closure),
+		_, ArgNum) -->
+	% The original goal had a sym_name/arity
+	% at the front of the argument list.
+	io__write_string("argument "),
+	io__write_int(ArgNum + 1).
+hlds_out__write_aditi_builtin_arg_number(aditi_bulk_operation(_, _),
+		_, ArgNum) -->
+	% The original goal had a sym_name/arity
+	% at the front of the argument list.
+	io__write_string("argument "),
+	io__write_int(ArgNum + 1).
+hlds_out__write_aditi_builtin_arg_number(aditi_modify(_, pred_term),
+		_, ArgNum) -->
+	io__write_string("argument "),
+	io__write_int(ArgNum).	
+hlds_out__write_aditi_builtin_arg_number(aditi_modify(_, sym_name_and_closure),
+		_, ArgNum) -->
+	% The original goal had a sym_name/arity
+	% at the front of the argument list.
+	io__write_string("argument "),
+	io__write_int(ArgNum + 1).	
 
 hlds_out__write_pred_or_func(predicate) -->
 	io__write_string("predicate").
@@ -367,9 +497,9 @@
 	io__write_string(" of clause head:\n").
 hlds_out__write_unify_main_context(First, call(PredId, ArgNum), Context, no) -->
 	hlds_out__write_in_argument(First, ArgNum, Context),
-	io__write_string(" of call to predicate `"),
-	hlds_out__write_pred_call_id(PredId),
-	io__write_string("':\n").
+	io__write_string(" of call to "),
+	hlds_out__write_call_id(PredId),
+	io__write_string(":\n").
 
 :- pred hlds_out__write_unify_sub_contexts(bool, unify_sub_contexts,
 	prog_context, bool, io__state, io__state).
@@ -634,7 +764,7 @@
 hlds_out__marker_name(check_termination, "check_termination").
 hlds_out__marker_name(does_not_terminate, "does_not_terminate").
 hlds_out__marker_name(aditi, "aditi").
-hlds_out__marker_name(aditi_interface, "aditi_interface").
+hlds_out__marker_name((aditi_top_down), "aditi_top_down").
 hlds_out__marker_name(base_relation, "base_relation").
 hlds_out__marker_name(generate_inline, "generate_inline").
 hlds_out__marker_name(aditi_memo, "aditi_memo").
@@ -998,12 +1128,18 @@
 	io__write_string(")"),
 	io__write_string(Follow).
 
-hlds_out__write_goal_2(some(Vars, Goal), ModuleInfo, VarSet, AppendVarnums,
-		Indent, Follow, TypeQual) -->
+hlds_out__write_goal_2(some(Vars, CanRemove, Goal), ModuleInfo,
+		VarSet, AppendVarnums, Indent, Follow, TypeQual) -->
 	hlds_out__write_indent(Indent),
 	io__write_string("some ["),
 	mercury_output_vars(Vars, VarSet, AppendVarnums),
-	io__write_string("] (\n"),
+	io__write_string("] ("),
+	( { CanRemove = cannot_remove } ->
+		io__write_string(" % (cannot remove)")
+	;
+		[]
+	),
+	io__nl,
 	{ Indent1 is Indent + 1 },
 	hlds_out__write_goal_a(Goal, ModuleInfo, VarSet, AppendVarnums,
 		Indent1, "\n", TypeQual),
@@ -1114,9 +1250,11 @@
 		io__write_string(Follow)
 	).
 
-hlds_out__write_goal_2(higher_order_call(PredVar, ArgVars, _, _, _, PredOrFunc),
-		_ModuleInfo, VarSet, AppendVarnums, Indent, Follow, _) -->
+hlds_out__write_goal_2(generic_call(GenericCall, ArgVars, _, _),
+		ModuleInfo, VarSet, AppendVarnums, Indent, Follow, _) -->
 		% XXX we should print more info here
+    ( 
+	{ GenericCall = higher_order(PredVar, PredOrFunc, _) },
 	globals__io_lookup_string_option(dump_hlds_options, Verbose),
 	hlds_out__write_indent(Indent),
 	(
@@ -1145,12 +1283,10 @@
 		hlds_out__write_functor(term__atom("apply"), FuncArgVars,
 				VarSet, AppendVarnums)
 	),
-	io__write_string(Follow).
-
-hlds_out__write_goal_2(	
-		class_method_call(TCInfoVar, MethodNum, ArgVars, _, _, _),
-		_ModuleInfo, VarSet, AppendVarnums, Indent, Follow, _) -->
-		% XXX we should print more info here too
+	io__write_string(Follow)
+    ; 
+	{ GenericCall = class_method(TCInfoVar, MethodNum,
+		_ClassId, _MethodId) },
 	globals__io_lookup_string_option(dump_hlds_options, Verbose),
 	hlds_out__write_indent(Indent),
 	( { string__contains_char(Verbose, 'l') } ->
@@ -1168,7 +1304,13 @@
 	{ Term = term__functor(Functor, [TCInfoTerm, MethodNumTerm | ArgTerms],
 			Context) },
 	mercury_output_term(Term, VarSet, AppendVarnums),
-	io__write_string(Follow).
+	io__write_string(Follow)
+    ;
+	{ GenericCall = aditi_builtin(AditiBuiltin, CallId) },
+	hlds_out__write_aditi_builtin(ModuleInfo, AditiBuiltin, CallId,
+		ArgVars, VarSet, AppendVarnums, Indent, Follow),	
+	io__write_string(Follow)
+    ).
 
 hlds_out__write_goal_2(call(PredId, ProcId, ArgVars, Builtin,
 			MaybeUnifyContext, PredName),
@@ -1190,23 +1332,17 @@
 		[]
 	),
 	hlds_out__write_indent(Indent),
-	( { invalid_pred_id(PredId)} ->
+	( { invalid_pred_id(PredId) } ->
 		[]
 	;
 		{ module_info_pred_info(ModuleInfo, PredId, PredInfo) },
 		{ pred_info_get_purity(PredInfo, Purity) },
 		write_purity_prefix(Purity)
 	),
-	(
-		{ PredName = qualified(ModuleName, Name) },
-		hlds_out__write_qualified_functor(ModuleName,
-			term__atom(Name),
-			ArgVars, VarSet, AppendVarnums)
-	;
-		{ PredName = unqualified(Name) },
-		hlds_out__write_functor(term__atom(Name), ArgVars, VarSet,
-			AppendVarnums)
-	),
+
+	hlds_out__write_sym_name_and_args(PredName,
+		ArgVars, VarSet, AppendVarnums),
+
 	io__write_string(Follow),
 	( { string__contains_char(Verbose, 'l') } ->
 		{ pred_id_to_int(PredId, PredNum) },
@@ -1364,6 +1500,126 @@
 	io__write_string(", "),
 	hlds_out__write_string_list([Name2 | Names]).
 
+:- pred hlds_out__write_aditi_builtin(module_info, aditi_builtin,
+	simple_call_id, list(prog_var), prog_varset, bool, int, string,
+	io__state, io__state).
+:- mode hlds_out__write_aditi_builtin(in, in, in, in, in, in, in, in,
+	di, uo) is det.
+
+hlds_out__write_aditi_builtin(ModuleInfo,
+		aditi_call(PredProcId, _NumInputs, _InputTypes, _NumOutputs),
+		_CallId, ArgVars, VarSet, AppendVarnums,
+		Indent, Follow) -->
+	hlds_out__write_indent(Indent),	
+	io__write_string("aditi_call "),
+	{ rl__get_entry_proc_name(ModuleInfo, PredProcId, ProcName) },
+	io__write(ProcName),
+	io__write_string("("),
+	mercury_output_vars(ArgVars, VarSet, AppendVarnums),
+	io__write_string(")"),
+	io__write_string(Follow),
+	io__nl.
+
+hlds_out__write_aditi_builtin(_ModuleInfo, aditi_insert(PredId), CallId,
+		ArgVars, VarSet, AppendVarnums, Indent, Follow) -->
+	{ get_state_args_det(ArgVars, Args, State0, State) },
+	hlds_out__write_indent(Indent),	
+	io__write_string("aditi_insert("),
+	{ CallId = PredOrFunc - SymName/_ },
+	(
+		{ PredOrFunc = predicate },
+		hlds_out__write_sym_name_and_args(SymName, Args,
+			VarSet, AppendVarnums)
+	;
+		{ PredOrFunc = function },
+		{ pred_args_to_func_args(Args, FuncArgs, RetArg) },
+		io__write_string("("),
+		hlds_out__write_sym_name_and_args(SymName, FuncArgs,
+			VarSet, AppendVarnums),	
+		io__write_string(" = "),
+		mercury_output_var(RetArg, VarSet, AppendVarnums),
+		io__write_string(")")
+	),
+	io__write_string(", "),
+	mercury_output_var(State0, VarSet, AppendVarnums),
+	io__write_string(", "),
+	mercury_output_var(State, VarSet, AppendVarnums),
+	io__write_string(")"),
+	io__write_string(Follow),
+	io__nl,
+	hlds_out__write_aditi_builtin_pred_id(Indent, PredId).
+
+hlds_out__write_aditi_builtin(_ModuleInfo,
+		aditi_delete(PredId, _), CallId,
+		ArgVars, VarSet, AppendVarnums, Indent, Follow) -->
+	hlds_out__write_aditi_builtin_2("aditi_delete", PredId, CallId,
+		ArgVars, VarSet, AppendVarnums, Indent, Follow).
+
+hlds_out__write_aditi_builtin(_ModuleInfo,
+		aditi_bulk_operation(BulkOp, PredId), CallId,
+		ArgVars, VarSet, AppendVarnums, Indent, Follow) -->
+	{
+		BulkOp = insert,
+		Name = "aditi_bulk_insert"
+	;
+		BulkOp = delete,
+		Name = "aditi_bulk_delete"
+	},
+	hlds_out__write_aditi_builtin_2(Name, PredId, CallId,
+		ArgVars, VarSet, AppendVarnums, Indent, Follow).
+
+hlds_out__write_aditi_builtin(_ModuleInfo, aditi_modify(PredId, _), CallId,
+		ArgVars, VarSet, AppendVarnums, Indent, Follow) -->
+	hlds_out__write_aditi_builtin_2("aditi_modify", PredId, CallId,
+		ArgVars, VarSet, AppendVarnums, Indent, Follow).
+
+:- pred hlds_out__write_aditi_builtin_2(string, pred_id, simple_call_id,
+	list(prog_var), prog_varset, bool, int, string, io__state, io__state).
+:- mode hlds_out__write_aditi_builtin_2(in, in, in, in, in, in, in, in,
+	di, uo) is det.
+
+hlds_out__write_aditi_builtin_2(UpdateName, PredId, CallId,
+		ArgVars, VarSet, AppendVarnums, Indent, Follow) -->
+	hlds_out__write_indent(Indent),	
+	io__write_string(UpdateName),
+	io__write_string("("),
+	{ CallId = PredOrFunc - _ },
+	{ hlds_out__pred_or_func_to_str(PredOrFunc, PredOrFuncStr) },
+	io__write_string(PredOrFuncStr),
+	io__write_string(" "),
+	{ hlds_out__simple_call_id_to_sym_name_and_arity(CallId, SymArity) },
+	prog_out__write_sym_name_and_arity(SymArity),
+	io__write_string(", "),
+	mercury_output_vars(ArgVars, VarSet, AppendVarnums),	
+	io__write_string(")"),
+	io__write_string(Follow),
+	io__nl,
+	hlds_out__write_aditi_builtin_pred_id(Indent, PredId).
+
+:- pred hlds_out__write_aditi_builtin_pred_id(int, pred_id,
+		io__state, io__state).
+:- mode hlds_out__write_aditi_builtin_pred_id(in, in, di, uo) is det.
+
+hlds_out__write_aditi_builtin_pred_id(Indent, PredId) -->
+	hlds_out__write_indent(Indent),
+	io__write_string("% Update of pred_id: "),
+	{ pred_id_to_int(PredId, PredInt) },
+	io__write_int(PredInt),
+	io__write_string(".\n").
+
+hlds_out__aditi_builtin_name(aditi_call(_, _, _, _), "aditi_call").
+hlds_out__aditi_builtin_name(aditi_insert(_), "aditi_insert").
+hlds_out__aditi_builtin_name(aditi_delete(_, _), "aditi_delete").
+hlds_out__aditi_builtin_name(aditi_bulk_operation(BulkOp, _), Name) :-
+	(
+		BulkOp = insert,
+		Name = "aditi_bulk_insert"
+	;
+		BulkOp = delete,
+		Name = "aditi_bulk_delete"
+	).
+hlds_out__aditi_builtin_name(aditi_modify(_, _), "aditi_modify").
+
 :- pred hlds_out__write_unification(unification, module_info, prog_varset,
 		inst_varset, bool, int, io__state, io__state).
 :- mode hlds_out__write_unification(in, in, in, in, in, in, di, uo) is det.
@@ -1384,7 +1640,7 @@
 	io__write_string(" == "),
 	mercury_output_var(Y, ProgVarSet, AppendVarnums),
 	io__write_string("\n").
-hlds_out__write_unification(construct(Var, ConsId, ArgVars, ArgModes),
+hlds_out__write_unification(construct(Var, ConsId, ArgVars, ArgModes, _, _, _),
 		ModuleInfo, ProgVarSet, InstVarSet, AppendVarnums, Indent) -->
 	hlds_out__write_indent(Indent),
 	io__write_string("% "),
@@ -1481,14 +1737,27 @@
 		[]
 	).
 hlds_out__write_unify_rhs_3(
-		lambda_goal(PredOrFunc, NonLocals, Vars, Modes, Det, Goal),
+		lambda_goal(PredOrFunc, EvalMethod, _, NonLocals, Vars, Modes,
+		Det, Goal),
 		ModuleInfo, VarSet, InstVarSet, AppendVarnums, Indent,
 		MaybeType, TypeQual)
 		-->
 	{ Indent1 is Indent + 1 },
+	{
+		EvalMethod = normal,
+		EvalStr = ""
+	;
+		EvalMethod = (aditi_bottom_up),
+		EvalStr = "aditi_bottom_up "
+	;
+		EvalMethod = (aditi_top_down),
+		EvalStr = "aditi_top_down "
+	},
 	(
 		{ PredOrFunc = predicate },
-		io__write_string("(pred("),
+		io__write_string("("),
+		io__write_string(EvalStr),
+		io__write_string("pred("),
 		hlds_out__write_var_modes(Vars, Modes, VarSet, InstVarSet,
 			AppendVarnums),
 		io__write_string(") is "),
@@ -1502,7 +1771,9 @@
 		{ PredOrFunc = function },
 		{ pred_args_to_func_args(Modes, ArgModes, RetMode) },
 		{ pred_args_to_func_args(Vars, ArgVars, RetVar) },
-		io__write_string("(func("),
+		io__write_string("("),
+		io__write_string(EvalStr),
+		io__write_string("func("),
 		hlds_out__write_var_modes(ArgVars, ArgModes, VarSet,
 			InstVarSet, AppendVarnums),
 		io__write_string(") = ("),
@@ -1536,6 +1807,22 @@
 		[]
 	).
 
+:- pred hlds_out__write_sym_name_and_args(sym_name, list(prog_var),
+		prog_varset, bool, io__state, io__state).
+:- mode hlds_out__write_sym_name_and_args(in, in, in, in, di, uo) is det.
+
+hlds_out__write_sym_name_and_args(PredName, ArgVars, VarSet, AppendVarnums) -->
+	(
+		{ PredName = qualified(ModuleName, Name) },
+		hlds_out__write_qualified_functor(ModuleName,
+			term__atom(Name),
+			ArgVars, VarSet, AppendVarnums)
+	;
+		{ PredName = unqualified(Name) },
+		hlds_out__write_functor(term__atom(Name),
+			ArgVars, VarSet, AppendVarnums)
+	).
+
 hlds_out__write_functor(Functor, ArgVars, VarSet, AppendVarnums) -->
 	hlds_out__write_functor(Functor, ArgVars, VarSet, AppendVarnums,
 		not_next_to_graphic_token).
@@ -1591,7 +1878,7 @@
 		hlds_out__write_functor(term__string(Str), ArgVars,
 			VarSet, AppendVarnums)
 	;
-		{ ConsId = pred_const(_, _) },
+		{ ConsId = pred_const(_, _, _) },
 		{ error("hlds_out__write_functor_cons_id: pred_const") }
 	;
 		{ ConsId = code_addr_const(_, _) },
@@ -2120,10 +2407,7 @@
 	hlds_out__write_indent(Indent),
 	io__write_string("% "),
 
-	{ ClassId = class_id(SymName, Arity) },
-	prog_out__write_sym_name(SymName),
-	io__write_string("/"),
-	io__write_int(Arity),
+	hlds_out__write_class_id(ClassId),
 	io__write_string(":\n"),
 
 	{ ClassDefn = hlds_class_defn(Constraints, Vars, Interface, VarSet,
@@ -2197,11 +2481,7 @@
 hlds_out__write_superclass(Indent, ClassId - SubClassDetailsList) -->
 	hlds_out__write_indent(Indent),
 	io__write_string("% "),
-
-	{ ClassId = class_id(SymName, Arity) },
-	prog_out__write_sym_name(SymName),
-	io__write_string("/"),
-	io__write_int(Arity),
+	hlds_out__write_class_id(ClassId),
 	io__write_string(":\n"),
 
 	io__write_list(SubClassDetailsList, "\n",
@@ -2253,13 +2533,8 @@
 hlds_out__write_instance_defns(Indent, ClassId - InstanceDefns) -->
 	hlds_out__write_indent(Indent),
 	io__write_string("% "),
-
-	{ ClassId = class_id(SymName, Arity) },
-	prog_out__write_sym_name(SymName),
-	io__write_string("/"),
-	io__write_int(Arity),
+	hlds_out__write_class_id(ClassId),
 	io__write_string(":\n"),
-
 	io__write_list(InstanceDefns, "\n",
 		hlds_out__write_instance_defn(Indent)).
 
Index: compiler/hlds_pred.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/hlds_pred.m,v
retrieving revision 1.58
diff -u -u -r1.58 hlds_pred.m
--- hlds_pred.m	1999/06/01 09:43:51	1.58
+++ hlds_pred.m	1999/06/02 02:25:11
@@ -76,7 +76,18 @@
 
 :- type proc_table	==	map(proc_id, proc_info).
 
-:- type pred_call_id	--->	sym_name / arity.
+:- type call_id
+	--->	call(simple_call_id)
+	;	generic_call(generic_call_id)
+	.
+
+:- type generic_call_id
+	--->	higher_order(pred_or_func, arity)
+	;	class_method(class_id, simple_call_id)
+	;	aditi_builtin(aditi_builtin, simple_call_id)
+	.
+
+:- type simple_call_id == pair(pred_or_func, sym_name_and_arity).
 
 :- type pred_proc_id	--->	proc(pred_id, proc_id).
 :- type pred_proc_list	==	list(pred_proc_id).
@@ -236,6 +247,23 @@
 
 	;	dnf		% Requests that this predicate be transformed
 				% into disjunctive normal form.
+
+	;	aditi		% Generate bottom-up Aditi-RL for this
+				% predicate.
+
+	;	(aditi_top_down)
+				% Generate top-down Aditi-RL, not C, for this
+				% predicate. This is used for the builtin
+				% `delete' predicate - the closure is used
+				% to select which tuples are to be deleted.
+
+	;	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.
+	
 	;	aditi_memo	% Requests that this Aditi predicate be
 				% evaluated using memoing. This has no
 				% relation to eval_method field of the
@@ -244,14 +272,6 @@
 	;	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'
@@ -272,12 +292,6 @@
 				% 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
@@ -555,6 +569,9 @@
 :- pred pred_info_set_markers(pred_info, pred_markers, pred_info).
 :- mode pred_info_set_markers(in, in, out) is det.
 
+:- pred pred_info_get_call_id(pred_info, simple_call_id).
+:- mode pred_info_get_call_id(in, out) is det.
+
 	% create an empty set of markers
 :- pred init_markers(pred_markers).
 :- mode init_markers(out) is det.
@@ -1015,6 +1032,14 @@
 
 %-----------------------------------------------------------------------------%
 
+pred_info_get_call_id(PredInfo, PredOrFunc - qualified(Module, Name)/Arity) :-
+	pred_info_get_is_pred_or_func(PredInfo, PredOrFunc),
+	pred_info_module(PredInfo, Module),
+	pred_info_name(PredInfo, Name),
+	pred_info_arity(PredInfo, Arity).
+
+%-----------------------------------------------------------------------------%
+
 type_info_locn_var(type_info(Var), Var).
 type_info_locn_var(typeclass_info(Var, _), Var).
 
@@ -1296,6 +1321,12 @@
 :- pred proc_info_is_address_taken(proc_info, is_address_taken).
 :- mode proc_info_is_address_taken(in, out) is det.
 
+:- pred proc_info_get_rl_exprn_id(proc_info, maybe(rl_exprn_id)).
+:- mode proc_info_get_rl_exprn_id(in, out) is det.
+
+:- pred proc_info_set_rl_exprn_id(proc_info, rl_exprn_id, proc_info).
+:- mode proc_info_set_rl_exprn_id(in, in, out) is det.
+
 	% For a set of variables V, find all the type variables in the types 
 	% of the variables in V, and return set of typeinfo variables for 
 	% those type variables. (find all typeinfos for variables in V).
@@ -1373,12 +1404,19 @@
 					% analysis.
 			maybe(list(mode)),
 					% declared modes of arguments.
-			is_address_taken
+			is_address_taken,
 					% Is the address of this procedure
 					% taken? If yes, we will need to use
 					% typeinfo liveness for them, so that
 					% deep_copy and accurate gc have the
 					% RTTI they need for copying closures.
+			maybe(rl_exprn_id)
+					% For predicates with an
+					% `aditi_top_down' marker, which are
+					% executed top-down on the Aditi side
+					% of the connection, we generate an RL
+					% expression, for which this is an
+					% identifier. See rl_update.m.
 		).
 
 	% Some parts of the procedure aren't known yet. We initialize
@@ -1403,38 +1441,41 @@
 	CanProcess = yes,
 	map__init(TVarsMap),
 	map__init(TCVarsMap),
+	RLExprn = no,
 	NewProc = procedure(
 		MaybeDet, BodyVarSet, BodyTypes, HeadVars, Modes, MaybeArgLives,
 		ClauseBody, MContext, StackSlots, InferredDet, CanProcess,
 		ArgInfo, InitialLiveness, TVarsMap, TCVarsMap, eval_normal,
-		no, no, DeclaredModes, IsAddressTaken
+		no, no, DeclaredModes, IsAddressTaken, RLExprn
 	).
 
 proc_info_set(DeclaredDetism, BodyVarSet, BodyTypes, HeadVars, HeadModes,
 		HeadLives, Goal, Context, StackSlots, InferredDetism,
 		CanProcess, ArgInfo, Liveness, TVarMap, TCVarsMap, ArgSizes,
 		Termination, IsAddressTaken, ProcInfo) :-
+	RLExprn = no,
 	ProcInfo = procedure(
 		DeclaredDetism, BodyVarSet, BodyTypes, HeadVars, HeadModes,
 		HeadLives, Goal, Context, StackSlots, InferredDetism,
 		CanProcess, ArgInfo, Liveness, TVarMap, TCVarsMap, eval_normal, 
-		ArgSizes, Termination, no, IsAddressTaken).
+		ArgSizes, Termination, no, IsAddressTaken, RLExprn).
 
 proc_info_create(VarSet, VarTypes, HeadVars, HeadModes, Detism, Goal,
 		Context, TVarMap, TCVarsMap, IsAddressTaken, ProcInfo) :-
 	map__init(StackSlots),
 	set__init(Liveness),
 	MaybeHeadLives = no,
+	RLExprn = no,
 	ProcInfo = procedure(yes(Detism), VarSet, VarTypes, HeadVars, HeadModes,
 		MaybeHeadLives, Goal, Context, StackSlots, Detism, yes, [],
 		Liveness, TVarMap, TCVarsMap, eval_normal, no, no, no, 
-		IsAddressTaken).
+		IsAddressTaken, RLExprn).
 
 proc_info_set_body(ProcInfo0, VarSet, VarTypes, HeadVars, Goal, ProcInfo) :-
 	ProcInfo0 = procedure(A, _, _, _, E, F, _,
-		H, I, J, K, L, M, N, O, P, Q, R, S, T),
+		H, I, J, K, L, M, N, O, P, Q, R, S, T, U),
 	ProcInfo = procedure(A, VarSet, VarTypes, HeadVars, E, F, Goal,
-		H, I, J, K, L, M, N, O, P, Q, R, S, T).
+		H, I, J, K, L, M, N, O, P, Q, R, S, T, U).
 
 proc_info_interface_determinism(ProcInfo, Determinism) :-
 	proc_info_declared_determinism(ProcInfo, MaybeDeterminism),
@@ -1492,83 +1533,87 @@
 
 proc_info_declared_determinism(ProcInfo, A) :-
 	ProcInfo = procedure(A, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, 
-    		_, _, _, _).
+    		_, _, _, _, _).
 
 proc_info_varset(ProcInfo, B) :-
 	ProcInfo = procedure(_, B, _, _, _, _, _, _, _, _, _, _, _, _, _, _, 
-		_, _, _, _).
+		_, _, _, _, _).
 
 proc_info_vartypes(ProcInfo, C) :-
 	ProcInfo = procedure(_, _, C, _, _, _, _, _, _, _, _, _, _, _, _, _, 
-		_, _, _, _).
+		_, _, _, _, _).
 
 proc_info_headvars(ProcInfo, D) :-
 	ProcInfo = procedure(_, _, _, D, _, _, _, _, _, _, _, _, _, _, _, _, 
-		_, _, _, _).
+		_, _, _, _, _).
 
 proc_info_argmodes(ProcInfo, E) :-
 	ProcInfo = procedure(_, _, _, _, E, _, _, _, _, _, _, _, _, _, _, _, 
-		_, _, _, _).
+		_, _, _, _, _).
 
 proc_info_maybe_arglives(ProcInfo, F) :-
 	ProcInfo = procedure(_, _, _, _, _, F, _, _, _, _, _, _, _, _, _, _, 
-		_, _, _, _).
+		_, _, _, _, _).
 
 proc_info_goal(ProcInfo, G) :-
 	ProcInfo = procedure(_, _, _, _, _, _, G, _, _, _, _, _, _, _, _, _, 
-		_, _, _, _).
+		_, _, _, _, _).
 
 proc_info_context(ProcInfo, H) :-
 	ProcInfo = procedure(_, _, _, _, _, _, _, H, _, _, _, _, _, _, _, _, 
-		_, _, _, _).
+		_, _, _, _, _).
 
 proc_info_stack_slots(ProcInfo, I) :-
 	ProcInfo = procedure(_, _, _, _, _, _, _, _, I, _, _, _, _, _, _, _, 
-		_, _, _, _).
+		_, _, _, _, _).
 
 proc_info_inferred_determinism(ProcInfo, J) :-
 	ProcInfo = procedure(_, _, _, _, _, _, _, _, _, J, _, _, _, _, _, _, 
-		_, _, _, _).
+		_, _, _, _, _).
 
 proc_info_can_process(ProcInfo, K) :-
 	ProcInfo = procedure(_, _, _, _, _, _, _, _, _, _, K, _, _, _, _, _, 
-		_, _, _, _).
+		_, _, _, _, _).
 
 proc_info_arg_info(ProcInfo, L) :- 
 	ProcInfo = procedure(_, _, _, _, _, _, _, _, _, _, _, L, _, _, _, _, 
-		_, _, _, _).
+		_, _, _, _, _).
 
 proc_info_liveness_info(ProcInfo, M) :-
 	ProcInfo = procedure(_, _, _, _, _, _, _, _, _, _, _, _, M, _, _, _,
-		_, _, _, _).
+		_, _, _, _, _).
 
 proc_info_typeinfo_varmap(ProcInfo, N) :-
 	ProcInfo = procedure(_, _, _, _, _, _, _, _, _, _, _, _, _, N, _, _, 
-		_, _, _, _).
+		_, _, _, _, _).
 
 proc_info_typeclass_info_varmap(ProcInfo, O) :-
 	ProcInfo = procedure(_, _, _, _, _, _, _, _, _, _, _, _, _, _, O, _, 
-		_, _, _, _).
+		_, _, _, _, _).
 
 proc_info_eval_method(ProcInfo, P) :-
 	ProcInfo = procedure(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, P, 
-		_, _, _, _).
+		_, _, _, _, _).
 
 proc_info_get_maybe_arg_size_info(ProcInfo, Q) :-
 	ProcInfo = procedure(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, 
-		Q, _, _, _).
+		Q, _, _, _, _).
 
 proc_info_get_maybe_termination_info(ProcInfo, R) :-
 	ProcInfo = procedure(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, 
-		_, R, _, _).
+		_, R, _, _, _).
 
 proc_info_maybe_declared_argmodes(ProcInfo, S) :-
 	ProcInfo = procedure(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, 
-		_, _, S, _).
+		_, _, S, _, _).
 
 proc_info_is_address_taken(ProcInfo, T) :-
 	ProcInfo = procedure(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, 
-		_, _, _, T).
+		_, _, _, T, _).
+
+proc_info_get_rl_exprn_id(ProcInfo, U) :-
+	ProcInfo = procedure(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, 
+		_, _, _, _, U).
 
 % :- type proc_info
 % 	--->	procedure(
@@ -1628,103 +1673,116 @@
 %					% typeinfo liveness for them, so that
 %					% deep_copy and accurate gc have the
 %					% RTTI they need for copying closures.
+% U			maybe(rl_exprn_id)
+%					% For predicates with an
+%					% `aditi_top_down' marker, which are
+%					% executed top-down on the Aditi side
+%					% of the connection, we generate an RL
+%					% expression, for which this is an
+%					% identifier. See rl_update.m.
 %		).
 
 proc_info_set_varset(ProcInfo0, B, ProcInfo) :-
 	ProcInfo0 = procedure(A, _, C, D, E, F, G, H, I, J, K, L, M, N, O, 
-		P, Q, R, S, T),
+		P, Q, R, S, T, U),
 	ProcInfo  = procedure(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, 
-		P, Q, R, S, T).
+		P, Q, R, S, T, U).
 
 proc_info_set_vartypes(ProcInfo0, C, ProcInfo) :-
 	ProcInfo0 = procedure(A, B, _, D, E, F, G, H, I, J, K, L, M, N, O, 
-		P, Q, R, S, T),
+		P, Q, R, S, T, U),
 	ProcInfo  = procedure(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, 
-		P, Q, R, S, T).
+		P, Q, R, S, T, U).
 
 proc_info_set_headvars(ProcInfo0, D, ProcInfo) :-
 	ProcInfo0 = procedure(A, B, C, _, E, F, G, H, I, J, K, L, M, N, O, 
-		P, Q, R, S, T),
+		P, Q, R, S, T, U),
 	ProcInfo  = procedure(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, 
-		P, Q, R, S, T).
+		P, Q, R, S, T, U).
 
 proc_info_set_argmodes(ProcInfo0, E, ProcInfo) :-
 	ProcInfo0 = procedure(A, B, C, D, _, F, G, H, I, J, K, L, M, N, O, 
-		P, Q, R, S, T),
+		P, Q, R, S, T, U),
 	ProcInfo  = procedure(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, 
-		P, Q, R, S, T).
+		P, Q, R, S, T, U).
 
 proc_info_set_maybe_arglives(ProcInfo0, F, ProcInfo) :-
 	ProcInfo0 = procedure(A, B, C, D, E, _, G, H, I, J, K, L, M, N, O, 
-		P, Q, R, S, T),
+		P, Q, R, S, T, U),
 	ProcInfo  = procedure(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, 
-		P, Q, R, S, T).
+		P, Q, R, S, T, U).
 
 proc_info_set_goal(ProcInfo0, G, ProcInfo) :-
 	ProcInfo0 = procedure(A, B, C, D, E, F, _, H, I, J, K, L, M, N, O, 
-		P, Q, R, S, T),
+		P, Q, R, S, T, U),
 	ProcInfo  = procedure(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, 
-		P, Q, R, S, T).
+		P, Q, R, S, T, U).
 
 proc_info_set_stack_slots(ProcInfo0, I, ProcInfo) :-
 	ProcInfo0 = procedure(A, B, C, D, E, F, G, H, _, J, K, L, M, N, O, 
-		P, Q, R, S, T),
+		P, Q, R, S, T, U),
 	ProcInfo  = procedure(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, 
-		P, Q, R, S, T).
+		P, Q, R, S, T, U).
 
 proc_info_set_inferred_determinism(ProcInfo0, J, ProcInfo) :-
 	ProcInfo0 = procedure(A, B, C, D, E, F, G, H, I, _, K, L, M, N, O, 
-		P, Q, R, S, T),
+		P, Q, R, S, T, U),
 	ProcInfo  = procedure(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, 
-		P, Q, R, S, T).
+		P, Q, R, S, T, U).
 
 proc_info_set_can_process(ProcInfo0, K, ProcInfo) :-
 	ProcInfo0 = procedure(A, B, C, D, E, F, G, H, I, J, _, L, M, N, O, 
-		P, Q, R, S, T),
+		P, Q, R, S, T, U),
 	ProcInfo  = procedure(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, 
-		P, Q, R, S, T).
+		P, Q, R, S, T, U).
 
 proc_info_set_arg_info(ProcInfo0, L, ProcInfo) :-
 	ProcInfo0 = procedure(A, B, C, D, E, F, G, H, I, J, K, _, M, N, O, 
-		P, Q, R, S, T),
+		P, Q, R, S, T, U),
 	ProcInfo  = procedure(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, 
-		P, Q, R, S, T).
+		P, Q, R, S, T, U).
 
 proc_info_set_liveness_info(ProcInfo0, M, ProcInfo) :-
 	ProcInfo0 = procedure(A, B, C, D, E, F, G, H, I, J, K, L, _, N, O, 
-		P, Q, R, S, T),
+		P, Q, R, S, T, U),
 	ProcInfo  = procedure(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, 
-		P, Q, R, S, T).
+		P, Q, R, S, T, U).
 
 proc_info_set_typeinfo_varmap(ProcInfo0, N, ProcInfo) :-
 	ProcInfo0 = procedure(A, B, C, D, E, F, G, H, I, J, K, L, M, _, O, 
-		P, Q, R, S, T),
+		P, Q, R, S, T, U),
 	ProcInfo  = procedure(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, 
-		P, Q, R, S, T).
+		P, Q, R, S, T, U).
 
 proc_info_set_typeclass_info_varmap(ProcInfo0, O, ProcInfo) :-
 	ProcInfo0 = procedure(A, B, C, D, E, F, G, H, I, J, K, L, M, N, _, 
-		P, Q, R, S, T),
+		P, Q, R, S, T, U),
 	ProcInfo  = procedure(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, 
-		P, Q, R, S, T).
+		P, Q, R, S, T, U).
 
 proc_info_set_eval_method(ProcInfo0, P, ProcInfo) :-
 	ProcInfo0 = procedure(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O,
-		_, Q, R, S, T),
+		_, Q, R, S, T, U),
 	ProcInfo  = procedure(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O,
-		P, Q, R, S, T).
+		P, Q, R, S, T, U).
 
 proc_info_set_maybe_arg_size_info(ProcInfo0, Q, ProcInfo) :-
 	ProcInfo0 = procedure(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, 
-		P, _, R, S, T),
+		P, _, R, S, T, U),
 	ProcInfo  = procedure(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, 
-		P, Q, R, S, T).
+		P, Q, R, S, T, U).
 
 proc_info_set_maybe_termination_info(ProcInfo0, R, ProcInfo) :-
 	ProcInfo0 = procedure(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, 
-		P, Q, _, S, T),
+		P, Q, _, S, T, U),
 	ProcInfo  = procedure(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, 
-		P, Q, R, S, T).
+		P, Q, R, S, T, U).
+
+proc_info_set_rl_exprn_id(ProcInfo0, U, ProcInfo) :-
+	ProcInfo0 = procedure(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, 
+		P, Q, R, S, T, _),
+	ProcInfo  = procedure(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, 
+		P, Q, R, S, T, yes(U)).
 
 proc_info_get_typeinfo_vars_setwise(ProcInfo, Vars, TypeInfoVars) :-
 	set__to_sorted_list(Vars, VarList),
@@ -1819,6 +1877,23 @@
 :- pred pred_args_to_func_args(list(T), list(T), T).
 :- mode pred_args_to_func_args(in, out, out) is det.
 
+	% We internally store the arity as the length of the argument
+	% list, which is one more than the arity of a function reported
+	% in error messages.
+:- pred adjust_func_arity(pred_or_func, int, int).
+:- mode adjust_func_arity(in, in, out) is det.
+:- mode adjust_func_arity(in, out, in) is det.
+
+	% Get the last two arguments from the list, failing if there
+	% aren't at least two arguments.
+:- pred get_state_args(list(T), list(T), T, T).
+:- mode get_state_args(in, out, out, out) is semidet.
+
+	% Get the last two arguments from the list, aborting if there
+	% aren't at least two arguments.
+:- pred get_state_args_det(list(T), list(T), T, T).
+:- mode get_state_args_det(in, out, out, out) is det.
+
 :- implementation.
 
 make_n_fresh_vars(BaseName, N, VarSet0, Vars, VarSet) :-
@@ -1850,6 +1925,23 @@
 		FuncReturn = FuncReturn0
 	;
 		error("pred_args_to_func_args: function missing return value?")
+	).
+
+adjust_func_arity(predicate, Arity, Arity).
+adjust_func_arity(function, Arity - 1, Arity).
+
+get_state_args(Args0, Args, State0, State) :-
+	list__reverse(Args0, RevArgs0),
+	RevArgs0 = [State, State0 | RevArgs],
+	list__reverse(RevArgs, Args).
+
+get_state_args_det(Args0, Args, State0, State) :-
+	( get_state_args(Args0, Args1, State0A, StateA) ->
+		Args = Args1,
+		State0 = State0A,
+		State = StateA
+	;
+		error("hlds_pred__get_state_args_det")
 	).
 
 %-----------------------------------------------------------------------------%
Index: compiler/inlining.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/inlining.m,v
retrieving revision 1.81
diff -u -u -r1.81 inlining.m
--- inlining.m	1998/12/06 23:43:23	1.81
+++ inlining.m	1999/05/14 04:49:13
@@ -304,7 +304,7 @@
 	inlining__is_flat_simple_goal_list(Goals).
 inlining__is_flat_simple_goal(not(Goal) - _) :-
 	inlining__is_flat_simple_goal(Goal).
-inlining__is_flat_simple_goal(some(_, Goal) - _) :-
+inlining__is_flat_simple_goal(some(_, _, Goal) - _) :-
 	inlining__is_flat_simple_goal(Goal).
 inlining__is_flat_simple_goal(call(_, _, _, BuiltinState, _, _) - _) :-
 	BuiltinState = inline_builtin.
@@ -458,8 +458,8 @@
 inlining__inlining_in_goal(not(Goal0) - GoalInfo, not(Goal) - GoalInfo) -->
 	inlining__inlining_in_goal(Goal0, Goal).
 
-inlining__inlining_in_goal(some(Vars, Goal0) - GoalInfo,
-		some(Vars, Goal) - GoalInfo) -->
+inlining__inlining_in_goal(some(Vars, CanRemove, Goal0) - GoalInfo,
+		some(Vars, CanRemove, Goal) - GoalInfo) -->
 	inlining__inlining_in_goal(Goal0, Goal).
 
 inlining__inlining_in_goal(call(PredId, ProcId, ArgVars, Builtin, Context,
@@ -516,11 +516,8 @@
 		VarThresh, InlinedProcs, ModuleInfo, HeadTypeParams, Markers,
 		VarSet, VarTypes, TypeVarSet, TypeInfoVarMap, DetChanged).
 
-inlining__inlining_in_goal(higher_order_call(A, B, C, D, E, F) - GoalInfo,
-		higher_order_call(A, B, C, D, E, F) - GoalInfo) --> [].
-
-inlining__inlining_in_goal(class_method_call(A, B, C, D, E, F) - GoalInfo,
-		class_method_call(A, B, C, D, E, F) - GoalInfo) --> [].
+inlining__inlining_in_goal(generic_call(A, B, C, D) - GoalInfo,
+		generic_call(A, B, C, D) - GoalInfo) --> [].
 
 inlining__inlining_in_goal(unify(A, B, C, D, E) - GoalInfo,
 		unify(A, B, C, D, E) - GoalInfo) --> [].
Index: compiler/intermod.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/intermod.m,v
retrieving revision 1.64
diff -u -u -r1.64 intermod.m
--- intermod.m	1999/04/23 01:02:44	1.64
+++ intermod.m	1999/05/27 06:08:39
@@ -429,11 +429,8 @@
 	%
 	intermod_info_add_proc(PredId, DoWrite).
 
-intermod__traverse_goal(higher_order_call(A,B,C,D,E,F) - Info,
-			higher_order_call(A,B,C,D,E,F) - Info, yes) --> [].
-
-intermod__traverse_goal(class_method_call(A,B,C,D,E,F) - Info,
-			class_method_call(A,B,C,D,E,F) - Info, yes) --> [].
+intermod__traverse_goal(generic_call(A,B,C,D) - Info,
+			generic_call(A,B,C,D) - Info, yes) --> [].
 
 intermod__traverse_goal(switch(A, B, Cases0, D) - Info,
 		switch(A, B, Cases, D) - Info, DoWrite) -->
@@ -448,8 +445,8 @@
 intermod__traverse_goal(not(Goal0) - Info, not(Goal) - Info, DoWrite) -->
 	intermod__traverse_goal(Goal0, Goal, DoWrite).
 
-intermod__traverse_goal(some(Vars, Goal0) - Info, some(Vars, Goal) - Info,
-		DoWrite) -->
+intermod__traverse_goal(some(Vars, CanRemove, Goal0) - Info,
+		some(Vars, CanRemove, Goal) - Info, DoWrite) -->
 	intermod__traverse_goal(Goal0, Goal, DoWrite).
 
 intermod__traverse_goal(if_then_else(Vars, Cond0, Then0, Else0, SM) - Info,
@@ -623,17 +620,29 @@
 		intermod_info::out) is det.
 
 intermod__module_qualify_unify_rhs(_, var(Var), var(Var), yes) --> [].
-intermod__module_qualify_unify_rhs(_LVar, lambda_goal(A,B,C,Modes,E,Goal0),
-		lambda_goal(A,B,C,Modes,E,Goal), DoWrite) -->
-	intermod__traverse_goal(Goal0, Goal, DoWrite),
-	intermod_info_get_module_info(ModuleInfo),
-	{ module_info_modes(ModuleInfo, ModeTable) },
-	{ mode_table_get_mode_defns(ModeTable, ModeDefns) },
-	{ module_info_insts(ModuleInfo, Insts) },
-	{ inst_table_get_user_insts(Insts, UserInsts) },
-	{ user_inst_table_get_inst_defns(UserInsts, UserInstDefns) },
-	intermod__gather_proc_modes(ModuleInfo, ModeDefns,
-				UserInstDefns, Modes).
+
+intermod__module_qualify_unify_rhs(_LVar,
+		lambda_goal(A,EvalMethod,C,D,E,Modes,G,Goal0),
+		lambda_goal(A,EvalMethod,C,D,E,Modes,G,Goal), DoWrite) -->
+	( { EvalMethod = (aditi_top_down) } ->
+		% XXX Predicates which build this type of lambda expression
+		% can't be exported because the importing modules have
+		% no way of knowing which Aditi-RL bytecode fragment
+		% to use. The best way to handle these is probably to
+		% add some sort of lookup table to Aditi.
+		{ DoWrite = no },
+		{ Goal = Goal0 }
+	;
+		intermod__traverse_goal(Goal0, Goal, DoWrite),
+		intermod_info_get_module_info(ModuleInfo),
+		{ module_info_modes(ModuleInfo, ModeTable) },
+		{ mode_table_get_mode_defns(ModeTable, ModeDefns) },
+		{ module_info_insts(ModuleInfo, Insts) },
+		{ inst_table_get_user_insts(Insts, UserInsts) },
+		{ user_inst_table_get_inst_defns(UserInsts, UserInstDefns) },
+		intermod__gather_proc_modes(ModuleInfo, ModeDefns,
+					UserInstDefns, Modes)
+	).	
 
 	% Fully module-qualify the right-hand-side of a unification.
 	% For function calls and higher-order terms, call intermod__add_proc
@@ -684,24 +693,38 @@
 		{ Functor0 = cons(PredName, Arity) },
 		intermod_info_get_var_types(VarTypes),
 		{ map__lookup(VarTypes, LVar, LVarType) },
-		{ type_is_higher_order(LVarType, PredOrFunc, PredArgTypes) }
+		{ type_is_higher_order(LVarType, PredOrFunc,
+			EvalMethod, PredArgTypes) }
 	->
-		%
-		% Yes, the unification creates a higher-order term.
-		% Make sure that the predicate/function is exported.
-		%
-		{ map__apply_to_list(Vars, VarTypes, Types) },
-		{ list__append(Types, PredArgTypes, ArgTypes) },
-		{ get_pred_id_and_proc_id(PredName, PredOrFunc,
-			TVarSet, ArgTypes, ModuleInfo, PredId, _ProcId) },
-		intermod_info_add_proc(PredId, DoWrite),
-		%
-		% Fully module-qualify it.
-		%
-		{ unqualify_name(PredName, UnqualPredName) },
-		{ predicate_module(ModuleInfo, PredId, Module) },
-		{ QualifiedPredName = qualified(Module, UnqualPredName) },
-		{ Functor = cons(QualifiedPredName, Arity) }
+		( { EvalMethod = (aditi_top_down) } ->
+			% XXX Predicates which build this type of lambda
+			% expression can't be exported because the importing
+			% modules have no way of knowing which Aditi-RL
+			% bytecode fragment to use. The best way to handle
+			% these is probably to add some sort of lookup table
+			% to Aditi. 
+			{ DoWrite = no },
+			{ Functor = Functor0 }
+		;
+			%
+			% Yes, the unification creates a higher-order term.
+			% Make sure that the predicate/function is exported.
+			%
+			{ map__apply_to_list(Vars, VarTypes, Types) },
+			{ list__append(Types, PredArgTypes, ArgTypes) },
+			{ get_pred_id_and_proc_id(PredName, PredOrFunc,
+				TVarSet, ArgTypes, ModuleInfo,
+				PredId, _ProcId) },
+			intermod_info_add_proc(PredId, DoWrite),
+			%
+			% Fully module-qualify it.
+			%
+			{ unqualify_name(PredName, UnqualPredName) },
+			{ predicate_module(ModuleInfo, PredId, Module) },
+			{ QualifiedPredName =
+				qualified(Module, UnqualPredName) },
+			{ Functor = cons(QualifiedPredName, Arity) }
+		)
 	;
 		%
 		% Is it a functor symbol for which we can add
@@ -1141,6 +1164,11 @@
 intermod__should_output_marker(no_inline, yes).
 intermod__should_output_marker(dnf, yes).
 intermod__should_output_marker(aditi, yes).
+intermod__should_output_marker((aditi_top_down), _) :-
+	% We don't write out code for predicates which depend on
+	% predicates with this marker: see the comments in
+	% intermod__module_qualify_unify_rhs.
+	error("intermod__should_output_marker: aditi_top_down").
 intermod__should_output_marker(base_relation, yes).
 intermod__should_output_marker(aditi_memo, yes).
 intermod__should_output_marker(aditi_no_memo, yes).
@@ -1156,9 +1184,6 @@
 intermod__should_output_marker(generate_inline, _) :-
 	% This marker should only occur after the magic sets transformation.
 	error("intermod__should_output_marker: generate_inline").
-intermod__should_output_marker(aditi_interface, _) :-
-	% This marker should only occur after the magic sets transformation.
-	error("intermod__should_output_marker: aditi_interface").
 
 	% Some pretty kludgy stuff to get c code written correctly.
 :- pred intermod__write_c_code(sym_name::in, pred_or_func::in, 
Index: compiler/lambda.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/lambda.m,v
retrieving revision 1.49
diff -u -u -r1.49 lambda.m
--- lambda.m	1999/06/01 09:43:53	1.49
+++ lambda.m	1999/06/02 01:30:45
@@ -75,13 +75,14 @@
 :- pred lambda__process_pred(pred_id, module_info, module_info).
 :- mode lambda__process_pred(in, in, out) is det.
 
-:- pred lambda__transform_lambda(pred_or_func, string, list(prog_var),
-		list(mode), determinism, list(prog_var), set(prog_var),
-		hlds_goal, unification, prog_varset, map(prog_var, type),
-		class_constraints, tvarset, map(tvar, type_info_locn),
-		map(class_constraint, prog_var), pred_markers, aditi_owner,
-		module_info, unify_rhs, unification, module_info).
-:- mode lambda__transform_lambda(in, in, in, in, in, in, in, in, in,
+:- pred lambda__transform_lambda(pred_or_func, lambda_eval_method, string,
+		list(prog_var), list(mode), determinism, list(prog_var),
+		set(prog_var), hlds_goal, unification, prog_varset,
+		map(prog_var, type), class_constraints, tvarset,
+		map(tvar, type_info_locn), map(class_constraint, prog_var),
+		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, in, out, out, out) is det.
 
 %-----------------------------------------------------------------------------%
@@ -198,12 +199,12 @@
 
 lambda__process_goal_2(unify(XVar, Y, Mode, Unification, Context), GoalInfo,
 			Unify - GoalInfo) -->
-	( { Y = lambda_goal(PredOrFunc, NonLocalVars, Vars, 
+	( { Y = lambda_goal(PredOrFunc, EvalMethod, _, NonLocalVars, Vars, 
 			Modes, Det, LambdaGoal0) } ->
 		% for lambda expressions, we must convert the lambda expression
 		% into a new predicate
-		lambda__process_lambda(PredOrFunc, Vars, Modes, Det, 
-			NonLocalVars, LambdaGoal0, 
+		lambda__process_lambda(PredOrFunc, EvalMethod, Vars,
+			Modes, Det, NonLocalVars, LambdaGoal0, 
 			Unification, Y1, Unification1),
 		{ Unify = unify(XVar, Y1, Mode, Unification1, Context) }
 	;
@@ -226,19 +227,16 @@
 lambda__process_goal_2(switch(Var, CanFail, Cases0, SM), GoalInfo, 
 			switch(Var, CanFail, Cases, SM) - GoalInfo) -->
 	lambda__process_cases(Cases0, Cases).
-lambda__process_goal_2(some(Vars, Goal0), GoalInfo,
-			some(Vars, Goal) - GoalInfo) -->
+lambda__process_goal_2(some(Vars, CanRemove, Goal0), GoalInfo,
+			some(Vars, CanRemove, Goal) - GoalInfo) -->
 	lambda__process_goal(Goal0, Goal).
 lambda__process_goal_2(if_then_else(Vars, A0, B0, C0, SM), GoalInfo,
 			if_then_else(Vars, A, B, C, SM) - GoalInfo) -->
 	lambda__process_goal(A0, A),
 	lambda__process_goal(B0, B),
 	lambda__process_goal(C0, C).
-lambda__process_goal_2(higher_order_call(A,B,C,D,E,F), GoalInfo,
-			higher_order_call(A,B,C,D,E,F) - GoalInfo) -->
-	[].
-lambda__process_goal_2(class_method_call(A,B,C,D,E,F), GoalInfo,
-			class_method_call(A,B,C,D,E,F) - GoalInfo) -->
+lambda__process_goal_2(generic_call(A,B,C,D), GoalInfo,
+			generic_call(A,B,C,D) - GoalInfo) -->
 	[].
 lambda__process_goal_2(call(A,B,C,D,E,F), GoalInfo,
 			call(A,B,C,D,E,F) - GoalInfo) -->
@@ -266,14 +264,16 @@
 	lambda__process_goal(Goal0, Goal),
 	lambda__process_cases(Cases0, Cases).
 
-:- pred lambda__process_lambda(pred_or_func, list(prog_var), list(mode),
-		determinism, list(prog_var), hlds_goal, unification,
-		unify_rhs, unification, lambda_info, lambda_info).
-:- mode lambda__process_lambda(in, in, in, in, in, in, in, out, out,
+:- pred lambda__process_lambda(pred_or_func, lambda_eval_method,
+		list(prog_var), list(mode), determinism, list(prog_var),
+		hlds_goal, unification, unify_rhs, unification,
+		lambda_info, lambda_info).
+:- mode lambda__process_lambda(in, in, in, in, in, in, in, in, out, out,
 		in, out) is det.
 
-lambda__process_lambda(PredOrFunc, Vars, Modes, Det, OrigNonLocals0, LambdaGoal,
-		Unification0, Functor, Unification, LambdaInfo0, LambdaInfo) :-
+lambda__process_lambda(PredOrFunc, EvalMethod, Vars, Modes, Det,
+		OrigNonLocals0, LambdaGoal, Unification0, Functor,
+		Unification, LambdaInfo0, LambdaInfo) :-
 	LambdaInfo0 = lambda_info(VarSet, VarTypes, Constraints, TVarSet,
 		TVarMap, TCVarMap, Markers, POF, PredName, Owner, ModuleInfo0),
 	% XXX existentially typed lambda expressions are not yet supported
@@ -283,20 +283,20 @@
 	goal_info_get_nonlocals(LambdaGoalInfo, LambdaNonLocals),
 	goal_util__extra_nonlocal_typeinfos(TVarMap, TCVarMap, VarTypes,
 		ExistQVars, LambdaNonLocals, ExtraTypeInfos),
-	lambda__transform_lambda(PredOrFunc, PredName, Vars, Modes, Det,
-		OrigNonLocals0, ExtraTypeInfos, LambdaGoal, Unification0,
+	lambda__transform_lambda(PredOrFunc, EvalMethod, PredName, Vars, Modes,
+		Det, OrigNonLocals0, ExtraTypeInfos, LambdaGoal, Unification0,
 		VarSet, VarTypes, Constraints, TVarSet, TVarMap, TCVarMap,
 		Markers, Owner, ModuleInfo0, Functor, Unification, ModuleInfo),
 	LambdaInfo = lambda_info(VarSet, VarTypes, Constraints, TVarSet,
 		TVarMap, TCVarMap, Markers, POF, PredName, Owner, ModuleInfo).
 
-lambda__transform_lambda(PredOrFunc, OrigPredName, Vars, Modes, Detism,
-		OrigVars, ExtraTypeInfos, LambdaGoal, Unification0,
+lambda__transform_lambda(PredOrFunc, EvalMethod, OrigPredName, Vars, Modes,
+		Detism, OrigVars, ExtraTypeInfos, LambdaGoal, Unification0,
 		VarSet, VarTypes, Constraints, TVarSet, TVarMap, TCVarMap,
 		Markers, Owner, ModuleInfo0, Functor,
 		Unification, ModuleInfo) :-
 	(
-		Unification0 = construct(Var0, _, _, UniModes0)
+		Unification0 = construct(Var0, _, _, UniModes0, _, _, _)
 	->
 		Var = Var0,
 		UniModes1 = UniModes0
@@ -334,9 +334,20 @@
 	( 
 		LambdaGoal = call(PredId0, ProcId0, CallVars,
 					_, _, PredName0) - _,
-		module_info_pred_proc_info(ModuleInfo0, PredId0, ProcId0, _,
-			Call_ProcInfo),
+		module_info_pred_proc_info(ModuleInfo0, PredId0, ProcId0,
+			Call_PredInfo, Call_ProcInfo),
 
+		(
+			EvalMethod = (aditi_top_down),
+			pred_info_get_markers(Call_PredInfo, Call_Markers),
+			check_marker(Call_Markers, (aditi_top_down))
+		;
+			EvalMethod = (aditi_bottom_up),
+			pred_info_get_markers(Call_PredInfo, Call_Markers),
+			check_marker(Call_Markers, aditi)
+		;
+			EvalMethod = normal
+		),
 		list__remove_suffix(CallVars, Vars, InitialVars),
 	
 		% check that none of the variables that we're trying to
@@ -432,7 +443,8 @@
 			% within Aditi predicates are treated as aggregate
 			% inputs.
 			determinism_components(Detism, _, at_most_many),
-			check_marker(Markers, aditi)
+			check_marker(Markers, aditi),
+			EvalMethod = (aditi_bottom_up)
 		->
 			markers_to_marker_list(Markers, MarkerList0),
 			list__filter(
@@ -452,6 +464,11 @@
 				MarkerList0, MarkerList),
 			marker_list_to_markers(MarkerList, LambdaMarkers)
 		;
+			EvalMethod = (aditi_top_down)
+		->
+			marker_list_to_markers([(aditi_top_down)],
+				LambdaMarkers)
+		; 
 			init_markers(LambdaMarkers)
 		),
 
@@ -476,8 +493,10 @@
 			ModuleInfo)
 	),
 	Functor = functor(cons(PredName, NumArgVars), ArgVars),
-	ConsId = pred_const(PredId, ProcId),
-	Unification = construct(Var, ConsId, ArgVars, UniModes).
+	ConsId = pred_const(PredId, ProcId, EvalMethod),
+
+	Unification = construct(Var, ConsId, ArgVars, UniModes,
+		no, cell_is_unique, no).
 
 :- pred lambda__uni_modes_to_modes(list(uni_mode), list(mode)).
 :- mode lambda__uni_modes_to_modes(in, out) is det.
Index: compiler/lco.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/lco.m,v
retrieving revision 1.11
diff -u -u -r1.11 lco.m
--- lco.m	1998/06/09 02:13:08	1.11
+++ lco.m	1999/05/21 03:53:07
@@ -79,16 +79,13 @@
 	lco_in_goal(Then0, ModuleInfo, Then),
 	lco_in_goal(Else0, ModuleInfo, Else).
 
-lco_in_goal_2(some(Vars, Goal0), ModuleInfo, some(Vars, Goal)) :-
+lco_in_goal_2(some(Vars, CanRemove, Goal0), ModuleInfo,
+		some(Vars, CanRemove, Goal)) :-
 	lco_in_goal(Goal0, ModuleInfo, Goal).
 
 lco_in_goal_2(not(Goal), _ModuleInfo, not(Goal)).
 
-lco_in_goal_2(higher_order_call(A,B,C,D,E,F), _ModuleInfo,
-		higher_order_call(A,B,C,D,E,F)).
-
-lco_in_goal_2(class_method_call(A,B,C,D,E,F), _ModuleInfo,
-		class_method_call(A,B,C,D,E,F)).
+lco_in_goal_2(generic_call(A,B,C,D), _ModuleInfo, generic_call(A,B,C,D)).
 
 lco_in_goal_2(call(A,B,C,D,E,F), _ModuleInfo, call(A,B,C,D,E,F)).
 
@@ -147,7 +144,7 @@
 	Goal0 = GoalExpr0 - _,
 	(
 		GoalExpr0 = unify(_, _, _, Unif, _),
-		Unif = construct(_, _, _, _)
+		Unif = construct(_, _, _, _, _, _, _)
 	->
 		Unifies1 = [Goal0 | Unifies0],
 		lco_in_conj(Goals0, Unifies1, ModuleInfo, Goals)
Index: compiler/live_vars.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/live_vars.m,v
retrieving revision 1.81
diff -u -u -r1.81 live_vars.m
--- live_vars.m	1999/06/01 09:43:55	1.81
+++ live_vars.m	1999/06/02 01:33:16
@@ -229,9 +229,9 @@
 	build_live_sets_in_goal(Goal0, Liveness0, ResumeVars0, LiveSets0,
 		ModuleInfo, ProcInfo, Liveness, _, LiveSets).
 
-build_live_sets_in_goal_2(some(_Vs, Goal0), Liveness0, ResumeVars0, LiveSets0,
-		GoalInfo, ModuleInfo, ProcInfo, Liveness, ResumeVars, LiveSets)
-		:-
+build_live_sets_in_goal_2(some(_Vs, _, Goal0), Liveness0, ResumeVars0,
+		LiveSets0, GoalInfo, ModuleInfo, ProcInfo,
+		Liveness, ResumeVars, LiveSets) :-
 	build_live_sets_in_goal(Goal0, Liveness0, ResumeVars0, LiveSets0,
 		ModuleInfo, ProcInfo, Liveness, ResumeVars1, LiveSets),
 
@@ -247,43 +247,8 @@
 		ResumeVars = ResumeVars0
 	).
 
-build_live_sets_in_goal_2(higher_order_call(_PredVar, ArgVars,
-				Types, Modes, Det, _IsPredOrFunc),
-		Liveness, ResumeVars0, LiveSets0,
-		GoalInfo, ModuleInfo, ProcInfo,
-		Liveness, ResumeVars, LiveSets) :-
-	% The variables which need to be saved onto the stack
-	% before the call are all the variables that are live
-	% after the call, except for the output arguments produced
-	% by the call, plus all the variables that may be needed
-	% at an enclosing resumption point.
-
-	determinism_to_code_model(Det, CallModel),
-	make_arg_infos(Types, Modes, CallModel, ModuleInfo, ArgInfos),
-	find_output_vars_from_arg_info(ArgVars, ArgInfos, OutVars),
-	set__difference(Liveness, OutVars, InputLiveness),
-	set__union(InputLiveness, ResumeVars0, StackVars0),
-
-	% Might need to add more live variables with alternate liveness
-	% calculation.
-
-	maybe_add_alternate_liveness_typeinfos(ModuleInfo, ProcInfo,
-		OutVars, StackVars0, StackVars),
-
-	set__insert(LiveSets0, StackVars, LiveSets),
-
-	% If this is a nondet call, then all the stack slots we need
-	% must be protected against reuse in following code.
-
-	goal_info_get_code_model(GoalInfo, CodeModel),
-	( CodeModel = model_non ->
-		ResumeVars = StackVars		% includes ResumeVars0
-	;
-		ResumeVars = ResumeVars0
-	).
-
-	% Code duplication. Ulch.
-build_live_sets_in_goal_2(class_method_call(_, _, ArgVars, Types, Modes, Det),
+build_live_sets_in_goal_2(
+		generic_call(_GenericCall, ArgVars, Modes, Det),
 		Liveness, ResumeVars0, LiveSets0,
 		GoalInfo, ModuleInfo, ProcInfo,
 		Liveness, ResumeVars, LiveSets) :-
@@ -294,6 +259,8 @@
 	% at an enclosing resumption point.
 
 	determinism_to_code_model(Det, CallModel),
+	proc_info_vartypes(ProcInfo, VarTypes),
+	map__apply_to_list(ArgVars, VarTypes, Types),
 	make_arg_infos(Types, Modes, CallModel, ModuleInfo, ArgInfos),
 	find_output_vars_from_arg_info(ArgVars, ArgInfos, OutVars),
 	set__difference(Liveness, OutVars, InputLiveness),
Index: compiler/livemap.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/livemap.m,v
retrieving revision 1.41
diff -u -u -r1.41 livemap.m
--- livemap.m	1999/04/30 06:19:29	1.41
+++ livemap.m	1999/04/30 06:36:35
@@ -400,6 +400,11 @@
 livemap__special_code_addr(do_det_aditi_call, no).
 livemap__special_code_addr(do_semidet_aditi_call, no).
 livemap__special_code_addr(do_nondet_aditi_call, no).
+livemap__special_code_addr(do_aditi_insert, no).
+livemap__special_code_addr(do_aditi_delete, no).
+livemap__special_code_addr(do_aditi_bulk_insert, no).
+livemap__special_code_addr(do_aditi_bulk_delete, no).
+livemap__special_code_addr(do_aditi_modify, no).
 livemap__special_code_addr(do_not_reached, no).
 
 %-----------------------------------------------------------------------------%
Index: compiler/liveness.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/liveness.m,v
retrieving revision 1.99
diff -u -u -r1.99 liveness.m
--- liveness.m	1998/11/20 04:08:07	1.99
+++ liveness.m	1999/05/14 04:50:26
@@ -311,16 +311,13 @@
 	add_liveness_after_goal(Then1, ResidueThen, Then),
 	add_liveness_after_goal(Else1, ResidueElse, Else).
 
-detect_liveness_in_goal_2(some(Vars, Goal0), Liveness0, _, LiveInfo,
-		Liveness, some(Vars, Goal)) :-
+detect_liveness_in_goal_2(some(Vars, CanRemove, Goal0), Liveness0, _, LiveInfo,
+		Liveness, some(Vars, CanRemove, Goal)) :-
 	detect_liveness_in_goal(Goal0, Liveness0, LiveInfo, Liveness, Goal).
 
-detect_liveness_in_goal_2(higher_order_call(_,_,_,_,_,_), _, _, _, _, _) :-
+detect_liveness_in_goal_2(generic_call(_,_,_,_), _, _, _, _, _) :-
 	error("higher-order-call in detect_liveness_in_goal_2").
 
-detect_liveness_in_goal_2(class_method_call(_,_,_,_,_,_), _, _, _, _, _) :-
-	error("class method call in detect_liveness_in_goal_2").
-
 detect_liveness_in_goal_2(call(_,_,_,_,_,_), _, _, _, _, _) :-
 	error("call in detect_liveness_in_goal_2").
 
@@ -517,16 +514,13 @@
 	add_deadness_before_goal(Cond1, ResidueCond, Cond),
 	add_deadness_before_goal(Else1, ResidueElse, Else).
 
-detect_deadness_in_goal_2(some(Vars, Goal0), _, Deadness0, LiveInfo,
-		Deadness, some(Vars, Goal)) :-
+detect_deadness_in_goal_2(some(Vars, CanRemove, Goal0), _, Deadness0, LiveInfo,
+		Deadness, some(Vars, CanRemove, Goal)) :-
 	detect_deadness_in_goal(Goal0, Deadness0, LiveInfo, Deadness, Goal).
 
-detect_deadness_in_goal_2(higher_order_call(_,_,_,_,_,_), _, _, _, _, _) :-
+detect_deadness_in_goal_2(generic_call(_,_,_,_), _, _, _, _, _) :-
 	error("higher-order-call in detect_deadness_in_goal_2").
 
-detect_deadness_in_goal_2(class_method_call(_,_,_,_,_,_), _, _, _, _, _) :-
-	error("class-method-call in detect_deadness_in_goal_2").
-
 detect_deadness_in_goal_2(call(_,_,_,_,_,_), _, _, _, _, _) :-
 	error("call in detect_deadness_in_goal_2").
 
@@ -714,8 +708,9 @@
 
 	require_equal(LivenessThen, LivenessElse, "if-then-else", LiveInfo).
 
-detect_resume_points_in_goal_2(some(Vars, Goal0), _, Liveness0, LiveInfo,
-		ResumeVars0, some(Vars, Goal), Liveness) :-
+detect_resume_points_in_goal_2(some(Vars, CanRemove, Goal0), _, Liveness0,
+		LiveInfo, ResumeVars0, some(Vars, CanRemove, Goal),
+		Liveness) :-
 	detect_resume_points_in_goal(Goal0, Liveness0, LiveInfo, ResumeVars0,
 					Goal, Liveness).
 
@@ -743,11 +738,8 @@
 	Resume = resume_point(ResumeVars1, ResumeLocs),
 	goal_set_resume_point(Goal1, Resume, Goal).
 
-detect_resume_points_in_goal_2(higher_order_call(A,B,C,D,E,F), _, Liveness,
-		_, _, higher_order_call(A,B,C,D,E,F), Liveness).
-
-detect_resume_points_in_goal_2(class_method_call(A,B,C,D,E,F), _, Liveness, _,
-		_, class_method_call(A,B,C,D,E,F), Liveness).
+detect_resume_points_in_goal_2(generic_call(A,B,C,D), _, Liveness,
+		_, _, generic_call(A,B,C,D), Liveness).
 
 detect_resume_points_in_goal_2(call(A,B,C,D,E,F), _, Liveness, _, _,
 		call(A,B,C,D,E,F), Liveness).
Index: compiler/llds.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/llds.m,v
retrieving revision 1.241
diff -u -u -r1.241 llds.m
--- llds.m	1999/05/28 05:26:19	1.241
+++ llds.m	1999/05/29 02:10:48
@@ -854,6 +854,11 @@
 	;	do_det_aditi_call
 	;	do_semidet_aditi_call
 	;	do_nondet_aditi_call
+	;	do_aditi_insert
+	;	do_aditi_delete
+	;	do_aditi_bulk_insert
+	;	do_aditi_bulk_delete
+	;	do_aditi_modify
 	;	do_not_reached.		% We should never jump to this address.
 
 	% A proc_label is a label used for the entry point to a procedure.
Index: compiler/llds_out.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/llds_out.m,v
retrieving revision 1.113
diff -u -u -r1.113 llds_out.m
--- llds_out.m	1999/05/28 05:26:22	1.113
+++ llds_out.m	1999/05/29 02:10:49
@@ -2626,6 +2626,11 @@
 need_code_addr_decls(do_det_aditi_call, yes) --> [].
 need_code_addr_decls(do_semidet_aditi_call, yes) --> [].
 need_code_addr_decls(do_nondet_aditi_call, yes) --> [].
+need_code_addr_decls(do_aditi_insert, yes) --> [].
+need_code_addr_decls(do_aditi_delete, yes) --> [].
+need_code_addr_decls(do_aditi_bulk_insert, yes) --> [].
+need_code_addr_decls(do_aditi_bulk_delete, yes) --> [].
+need_code_addr_decls(do_aditi_modify, yes) --> [].
 need_code_addr_decls(do_not_reached, yes) --> [].
 
 :- pred output_code_addr_decls(code_addr, io__state, io__state).
@@ -2671,6 +2676,16 @@
 	io__write_string("Declare_entry(do_semidet_aditi_call);\n").
 output_code_addr_decls(do_nondet_aditi_call) -->
 	io__write_string("Declare_entry(do_nondet_aditi_call);\n").
+output_code_addr_decls(do_aditi_insert) -->
+	io__write_string("Declare_entry(do_aditi_insert);\n").
+output_code_addr_decls(do_aditi_delete) -->
+	io__write_string("Declare_entry(do_aditi_delete);\n").
+output_code_addr_decls(do_aditi_bulk_insert) -->
+	io__write_string("Declare_entry(do_aditi_bulk_insert);\n").
+output_code_addr_decls(do_aditi_bulk_delete) -->
+	io__write_string("Declare_entry(do_aditi_bulk_delete);\n").
+output_code_addr_decls(do_aditi_modify) -->
+	io__write_string("Declare_entry(do_aditi_modify);\n").
 output_code_addr_decls(do_not_reached) -->
 	io__write_string("Declare_entry(do_not_reached);\n").
 
@@ -2887,6 +2902,26 @@
 	io__write_string("tailcall(ENTRY(do_nondet_aditi_call),\n\t\t"),
 	output_label_as_code_addr(CallerLabel),
 	io__write_string(");\n").
+output_goto(do_aditi_insert, CallerLabel) -->
+	io__write_string("tailcall(ENTRY(do_aditi_insert),\n\t\t"),
+	output_label_as_code_addr(CallerLabel),
+	io__write_string(");\n").
+output_goto(do_aditi_delete, CallerLabel) -->
+	io__write_string("tailcall(ENTRY(do_aditi_delete),\n\t\t"),
+	output_label_as_code_addr(CallerLabel),
+	io__write_string(");\n").
+output_goto(do_aditi_bulk_insert, CallerLabel) -->
+	io__write_string("tailcall(ENTRY(do_aditi_bulk_insert),\n\t\t"),
+	output_label_as_code_addr(CallerLabel),
+	io__write_string(");\n").
+output_goto(do_aditi_bulk_delete, CallerLabel) -->
+	io__write_string("tailcall(ENTRY(do_aditi_bulk_delete),\n\t\t"),
+	output_label_as_code_addr(CallerLabel),
+	io__write_string(");\n").
+output_goto(do_aditi_modify, CallerLabel) -->
+	io__write_string("tailcall(ENTRY(do_aditi_modify),\n\t\t"),
+	output_label_as_code_addr(CallerLabel),
+	io__write_string(");\n").
 output_goto(do_not_reached, CallerLabel) -->
 	io__write_string("tailcall(ENTRY(do_not_reached),\n\t\t"),
 	output_label_as_code_addr(CallerLabel),
@@ -2963,6 +2998,16 @@
 	io__write_string("ENTRY(do_semidet_aditi_call)").
 output_code_addr(do_nondet_aditi_call) -->
 	io__write_string("ENTRY(do_nondet_aditi_call)").
+output_code_addr(do_aditi_insert) -->
+	io__write_string("ENTRY(do_aditi_insert)").
+output_code_addr(do_aditi_delete) -->
+	io__write_string("ENTRY(do_aditi_delete)").
+output_code_addr(do_aditi_bulk_insert) -->
+	io__write_string("ENTRY(do_aditi_bulk_insert)").
+output_code_addr(do_aditi_bulk_delete) -->
+	io__write_string("ENTRY(do_aditi_bulk_delete)").
+output_code_addr(do_aditi_modify) -->
+	io__write_string("ENTRY(do_aditi_modify)").
 output_code_addr(do_not_reached) -->
 	io__write_string("ENTRY(do_not_reached)").
 
Index: compiler/magic.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/magic.m,v
retrieving revision 1.4
diff -u -u -r1.4 magic.m
--- magic.m	1999/06/01 09:43:57	1.4
+++ magic.m	1999/06/02 01:34:24
@@ -65,13 +65,14 @@
 %       TypeInfo_13 = type_ctor_info("", "int", 0),	% input type_info
 %       TypeInfo_14 = type_ctor_info("", "int", 0),	% output type_info
 %
-%	% anc__do_aditi_call has the `aditi_interface' marker,
-%	% which causes call_gen.m to generate it as a call
-% 	% to `do_nondet_aditi_call', which is hand-coded C
-% 	% in extras/aditi/aditi.m
-%       anc__do_aditi_call(V_15, V_16, V_17, V_18,
-%		 TypeInfo_13, HeadVar__2,
-% 		 TypeInfo_14, HeadVar__3).
+%	% The aditi__state is not needed (it contains no information),
+%	% so it is not passed.
+% 	% aditi_call(PredName, Number of inputs, Input relation schema,
+%	% 	Number of Outputs)
+%	generic_call(
+%		aditi_call("stayl/a/a__anc__c_interface_2_0/2", 1, "(:I)", 1),
+%		TypeInfo_13, HeadVar__2,
+% 		TypeInfo_14, HeadVar__3).
 %
 % :- pred anc__c_interface(pred(int)::(pred(out) is nondet),
 % 		 int::out) is nondet.
@@ -348,11 +349,11 @@
 	{ 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) },
-	{ magic_util__remove_aditi_state(ArgTypes0, ArgModes0, ArgModes1) },
+	{ type_util__remove_aditi_state(ArgTypes0, ArgTypes0, ArgTypes) },
+	{ type_util__remove_aditi_state(ArgTypes0, ArgModes0, ArgModes1) },
 	{ list__map(magic_util__mode_to_output_mode(ModuleInfo0),
 		ArgModes1, ArgModes) },
-	{ magic_util__remove_aditi_state(ArgTypes0, HeadVars0, HeadVars) },
+	{ type_util__remove_aditi_state(ArgTypes0, HeadVars0, HeadVars) },
 	{ pred_info_get_indexes(PredInfo0, Indexes0) },
 	{ list__map(magic_util__adjust_index(ArgTypes0), Indexes0, Indexes) },
 	{ pred_info_set_indexes(PredInfo0, Indexes, PredInfo1) },
@@ -394,12 +395,12 @@
 		PredInfo, ProcInfo) },
 	{ proc_info_argmodes(ProcInfo, ArgModes0) },
 	{ pred_info_arg_types(PredInfo, ArgTypes0) },
-	{ magic_util__remove_aditi_state(ArgTypes0, ArgTypes0, ArgTypes) },
-	{ magic_util__remove_aditi_state(ArgTypes0, ArgModes0, ArgModes) },
+	{ type_util__remove_aditi_state(ArgTypes0, ArgTypes0, ArgTypes) },
+	{ type_util__remove_aditi_state(ArgTypes0, ArgModes0, ArgModes) },
 	{ partition_args(ModuleInfo, ArgModes, ArgModes, InputModes, _) },
 	{ partition_args(ModuleInfo, ArgModes, ArgTypes, InputTypes, _) },
-	{ term__context_init(Context) },
-	{ Type = term__functor(term__atom("pred"), InputTypes, Context) },
+	{ construct_higher_order_type(predicate, (aditi_bottom_up),
+		InputTypes, Type) },
 	{ GetOutputMode = lambda([ArgMode::in, OutputMode::out] is det, (
 			mode_get_insts(ModuleInfo, ArgMode, _, OutputInst),
 			OutputMode = (free -> OutputInst)
@@ -578,9 +579,9 @@
 	%
 	% Strip out the aditi__state argument.
 	%
-	{ magic_util__remove_aditi_state(ArgTypes0, ArgTypes0, ArgTypes1) },
-	{ magic_util__remove_aditi_state(ArgTypes0, HeadVars0, HeadVars1) },
-	{ magic_util__remove_aditi_state(ArgTypes0, ArgModes0, ArgModes1) },
+	{ type_util__remove_aditi_state(ArgTypes0, ArgTypes0, ArgTypes1) },
+	{ type_util__remove_aditi_state(ArgTypes0, HeadVars0, HeadVars1) },
+	{ type_util__remove_aditi_state(ArgTypes0, ArgModes0, ArgModes1) },
 
 	%
 	% Convert all of the original modes to output. The input
@@ -764,7 +765,10 @@
 		% Create an empty input closure.
 		%
 		{ list__index1_det(MagicTypes, CurrVar, MagicType) },
-		{ type_is_higher_order(MagicType, predicate, ArgTypes1) ->
+		{ 
+			type_is_higher_order(MagicType, predicate,
+				(aditi_bottom_up), ArgTypes1)
+		->
 			ArgTypes = ArgTypes1
 		;
 			error("magic__interface_call_args")
@@ -845,7 +849,7 @@
 		CPredInfo, CProcInfo) },
 	{ proc_info_argmodes(CProcInfo, ArgModes0) },
 	{ pred_info_arg_types(CPredInfo, ArgTypes) },
-	{ magic_util__remove_aditi_state(ArgTypes, ArgModes0, ArgModes) },
+	{ type_util__remove_aditi_state(ArgTypes, ArgModes0, ArgModes) },
 	{ partition_args(ModuleInfo0, ArgModes, ArgModes,
 		InputArgModes, OutputArgModes) },
 	(
@@ -870,7 +874,7 @@
 		% No join with the input is needed for a base relation
 		% with no input arguments.
 		{ proc_info_headvars(CProcInfo, HeadVars0) },
-		{ magic_util__remove_aditi_state(ArgTypes,
+		{ type_util__remove_aditi_state(ArgTypes,
 			HeadVars0, HeadVars) },
 
 		% Build a call to the original C proc.
@@ -906,7 +910,7 @@
 		% only one input closure argument.
 		{ proc_info_vartypes(CProcInfo, VarTypes0) },
 		{ proc_info_headvars(CProcInfo, HeadVars0) },
-		{ magic_util__remove_aditi_state(ArgTypes,
+		{ type_util__remove_aditi_state(ArgTypes,
 			HeadVars0, HeadVars) },
 
 		{ partition_args(ModuleInfo0, ArgModes, HeadVars,
@@ -914,8 +918,7 @@
 
 		{ map__apply_to_list(InputArgs, VarTypes0, InputVarTypes) },
 
-		{ list__length(InputVarTypes, NumInputVars) },
-		{ construct_type(unqualified("pred") - NumInputVars,
+		{ construct_higher_order_type(predicate, (aditi_bottom_up),
 			InputVarTypes, ClosureVarType) },
 		{ list__map(magic_util__mode_to_output_mode(ModuleInfo0),
 			InputArgModes, MagicArgModes) },
@@ -931,9 +934,10 @@
 			ModuleInfo0, HOCallDelta) },
 		{ goal_info_init(HOCallNonLocals, HOCallDelta, nondet,
 			InputGoalInfo) },
-		{ InputGoal = higher_order_call(ClosureVar,
-			InputArgs, InputVarTypes, MagicArgModes,
-			nondet, predicate) - InputGoalInfo },
+		{ list__length(InputArgs, Arity) },
+		{ InputGoal = generic_call(
+			higher_order(ClosureVar, predicate, Arity),
+			InputArgs, MagicArgModes, nondet) - InputGoalInfo },
 
 		% Build a call to the original C proc.
 		{ CPredProcId = proc(CPredId, CProcId) },
@@ -1047,37 +1051,33 @@
 		magic_info::in, magic_info::out) is det.		
 
 magic__create_aditi_call_proc(CPredProcId, AditiPredProcId) -->
-	magic__interface_pred_info(CPredProcId, AditiPredProcId,
-		AditiProcName, InputSchema),
-
 	magic_info_get_module_info(ModuleInfo0),
 	{ module_info_pred_proc_info(ModuleInfo0, CPredProcId,
 		CPredInfo0, CProcInfo0) },
-	{ pred_info_module(CPredInfo0, PredModule) },
-	{ pred_info_arg_types(CPredInfo0, TVarSet, ExistQVars, ArgTypes) },
+	{ pred_info_arg_types(CPredInfo0, ArgTypes) },
 	{ proc_info_argmodes(CProcInfo0, ArgModes) },
 	{ proc_info_headvars(CProcInfo0, HeadVars) },
 
 	% Base relations will have an empty vartypes field, so fill it in here.
 	{ map__from_corresponding_lists(HeadVars, ArgTypes, VarTypes0) },
-	{ proc_info_set_vartypes(CProcInfo0, VarTypes0, CProcInfo0a) },
+	{ proc_info_set_vartypes(CProcInfo0, VarTypes0, CProcInfo1) },
 
 	%
 	% Build type-infos for the arguments so do_*_aditi_call
 	% can do the required data conversions.
 	%
 
-	{ magic_util__remove_aditi_state(ArgTypes, ArgTypes, ArgTypes1) },
-	{ magic_util__remove_aditi_state(ArgTypes, ArgModes, ArgModes1) },
-	{ magic_util__remove_aditi_state(ArgTypes, HeadVars, HeadVars1) },
+	{ type_util__remove_aditi_state(ArgTypes, ArgTypes, ArgTypes1) },
+	{ type_util__remove_aditi_state(ArgTypes, ArgModes, ArgModes1) },
+	{ type_util__remove_aditi_state(ArgTypes, HeadVars, HeadVars1) },
 
 	magic__make_type_info_vars(ArgTypes1, TypeInfoVars, TypeInfoGoals,
-		CPredInfo0, CPredInfo1, CProcInfo0a, CProcInfo1),
+		CPredInfo0, CPredInfo1, CProcInfo1, CProcInfo2),
 
 	magic_info_get_module_info(ModuleInfo1),
 
 	{ partition_args(ModuleInfo1, ArgModes1, ArgTypes1,
-		InputArgTypes, OutputArgTypes) },
+		InputArgTypes, _OutputArgTypes) },
 	{ partition_args(ModuleInfo1, ArgModes1, ArgModes1,
 		InputArgModes, OutputArgModes) },
 	{ partition_args(ModuleInfo1, ArgModes1, TypeInfoVars,
@@ -1085,130 +1085,52 @@
 	{ partition_args(ModuleInfo1, ArgModes1,
 		HeadVars1, InputArgs, OutputArgs) },
 
-	{ construct_type(unqualified("int") - 0, [], IntType) },
-	{ construct_type(unqualified("string") - 0, [], StringType) },
-
 	%
 	% Build up some other information that do_*_aditi_call needs.
 	% 
 
-	% Procedure name.
-	{ magic__make_const(StringType, string_const(AditiProcName),
-		ProcNameVar, ProcNameGoal, CProcInfo1, CProcInfo2) },
-
-	% Number of input arguments.
-	{ list__length(InputArgTypes, NumInputArgs) },
-	{ magic__make_const(IntType, int_const(NumInputArgs), InputArgsVar,
-		InputArgsGoal, CProcInfo2, CProcInfo3) },
-
-	% Input schema.
-	{ magic__make_const(StringType, string_const(InputSchema),
-		InputSchemaVar, InputSchemaGoal, CProcInfo3, CProcInfo4) },
-	{ list__length(OutputArgTypes, NumOutputArgs) },
-
-	% Number of output arguments.
-	{ magic__make_const(IntType, int_const(NumOutputArgs), OutputArgsVar,
-		OutputArgsGoal, CProcInfo4, CProcInfo5) },
-
 	% Argument variables.
-	{ list__condense([[ProcNameVar, InputArgsVar, InputSchemaVar,
-		OutputArgsVar], InputTypeInfoVars, InputArgs,
+	{ list__condense([InputTypeInfoVars, InputArgs,
 		OutputTypeInfoVars, OutputArgs], DoCallAditiArgs) },
 
-	% Argument types.
-	{ proc_info_vartypes(CProcInfo5, VarTypes) },
-	{ map__apply_to_list(InputTypeInfoVars,
-		VarTypes, InputTypeInfoTypes) },
-	{ map__apply_to_list(OutputTypeInfoVars,
-		VarTypes, OutputTypeInfoTypes) },
-	{ list__condense([[StringType, IntType, StringType, IntType],
-		InputTypeInfoTypes, InputArgTypes, OutputTypeInfoTypes,
-		OutputArgTypes], DoCallAditiArgTypes) },
-
 	% Argument modes.
 	{ in_mode(InMode) },
+	{ list__length(InputArgs, NumInputArgs) },
+	{ list__length(OutputArgs, NumOutputArgs) },
 	{ list__duplicate(NumInputArgs, InMode, InputTypeInfoModes) },
 	{ list__duplicate(NumOutputArgs, InMode, OutputTypeInfoModes) },
-	{ list__condense([[InMode, InMode, InMode, InMode],
-		InputTypeInfoModes, InputArgModes, OutputTypeInfoModes,
-		OutputArgModes], DoCallAditiArgModes) },
-
-	%
-	% Create a new procedure which is just an alias for do_*_aditi_call.
-	%
-	{ varset__init(VarSet0) },
-	{ list__length(DoCallAditiArgTypes, Arity) },
-	{ varset__new_vars(VarSet0, Arity, DoCallAditiHeadVars, VarSet) },
-	{ map__from_corresponding_lists(DoCallAditiHeadVars,
-		DoCallAditiArgTypes, DoCallAditiVarTypes) },
-	{ true_goal(DummyGoal) },
-	{ term__context_init(DummyContext) },
-	{ proc_info_inferred_determinism(CProcInfo5, Detism) },
-	{ map__init(TVarMap) },
-	{ map__init(TCVarMap) },
-	{ proc_info_create(VarSet, DoCallAditiVarTypes, DoCallAditiHeadVars,
-		DoCallAditiArgModes, Detism, DummyGoal, DummyContext,
-		TVarMap, TCVarMap, address_is_not_taken,
-		DoCallAditiProcInfo) },
-
-	{ CPredProcId = proc(_, CProcId) },
-	magic_util__make_pred_name(CPredInfo1, CProcId, "Do_Aditi_Call_For",
-		no, CallPredName),
-	{ init_markers(Markers0) },
-	{ add_marker(Markers0, aditi_interface, Markers) },
-	{ ClassContext = constraints([], []) },
-	{ pred_info_get_aditi_owner(CPredInfo1, User) },
-	{ pred_info_create(PredModule, CallPredName,
-		TVarSet, ExistQVars, DoCallAditiArgTypes, true, DummyContext,
-		imported, Markers, predicate, ClassContext, User,
-		DoCallAditiProcInfo, DoCallAditiProcId, DoCallAditiPredInfo) },
-
-	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(ModuleInfo2,
-		PredTable, ModuleInfo3) },
+	{ list__condense([InputTypeInfoModes, InputArgModes,
+		OutputTypeInfoModes, OutputArgModes], DoCallAditiArgModes) },
 
 	%
 	% Make the C procedure call the new alias for do_*_aditi_call.
 	%
 	{ set__list_to_set(DoCallAditiArgs, CallNonLocals) },
 	{ instmap_delta_from_mode_list(DoCallAditiArgs, DoCallAditiArgModes,
-		ModuleInfo2, GoalDelta) },
+		ModuleInfo1, GoalDelta) },
+	{ proc_info_inferred_determinism(CProcInfo2, Detism) },
 	{ goal_info_init(CallNonLocals, GoalDelta, Detism, CallGoalInfo) },
-	{ DoCallAditiGoal = call(DoCallAditiPredId, DoCallAditiProcId,
-		DoCallAditiArgs, not_builtin, no, CallPredName)
-		- CallGoalInfo },
-	{ list__condense([[ProcNameGoal, InputArgsGoal, InputSchemaGoal,
-		OutputArgsGoal], TypeInfoGoals, [DoCallAditiGoal]], Goals) },
+	{ pred_info_get_is_pred_or_func(CPredInfo1, CPredOrFunc) },
+	{ pred_info_module(CPredInfo1, CPredModule) },
+	{ pred_info_name(CPredInfo1, CPredName) },
+	{ pred_info_arity(CPredInfo1, Arity) },
+	{ DoCallAditiGoal =
+		generic_call(aditi_builtin(
+			aditi_call(AditiPredProcId, NumInputArgs,
+				InputArgTypes, NumOutputArgs),
+			CPredOrFunc - qualified(CPredModule, CPredName)/Arity),
+		DoCallAditiArgs, DoCallAditiArgModes, Detism) - CallGoalInfo },
+	{ list__append(TypeInfoGoals, [DoCallAditiGoal], Goals) },
 	{ set__list_to_set(HeadVars, GoalNonLocals) },
 	{ goal_list_determinism(Goals, GoalDetism) },
 	{ goal_info_init(GoalNonLocals, GoalDelta, GoalDetism, GoalInfo) },
 	{ Goal = conj(Goals) - GoalInfo },
-	{ proc_info_set_goal(CProcInfo5, Goal, CProcInfo) },
+	{ proc_info_set_goal(CProcInfo2, Goal, CProcInfo) },
 
-	{ module_info_set_pred_proc_info(ModuleInfo3, CPredProcId,
+	{ module_info_set_pred_proc_info(ModuleInfo1, CPredProcId,
 		CPredInfo1, CProcInfo, ModuleInfo) },
 	magic_info_set_module_info(ModuleInfo).
 
-:- pred magic__interface_pred_info(pred_proc_id::in, pred_proc_id::in,
-	string::out, string::out, magic_info::in, magic_info::out) is det.
-
-magic__interface_pred_info(CPredProcId, PredProcId,
-		ProcNameStr, InputSchema) -->
-	magic_info_get_module_info(ModuleInfo),
-	{ rl_gen__get_entry_proc_name(ModuleInfo, PredProcId, ProcName) },
-	{ rl__proc_name_to_string(ProcName, ProcNameStr) },
-	{ module_info_pred_proc_info(ModuleInfo, CPredProcId,
-		CPredInfo, CProcInfo) },
-	{ 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) },
-	{ partition_args(ModuleInfo, ArgModes, ArgTypes, InputArgTypes, _) },
-	{ rl__schema_to_string(ModuleInfo, InputArgTypes, InputSchema) }.
-
 :- pred magic__make_type_info_vars(list(type)::in, list(prog_var)::out,
 	list(hlds_goal)::out, pred_info::in, pred_info::out,
 	proc_info::in, proc_info::out, magic_info::in, magic_info::out) is det.
@@ -1235,7 +1157,7 @@
 	instmap_delta_init_reachable(Delta0),
 	instmap_delta_insert(Delta0, Var, Inst, Delta),
 	UnifyMode = (free -> Inst) - (Inst -> Inst),
-	Uni = construct(Var, ConsId, [], []),
+	Uni = construct(Var, ConsId, [], [], no, cell_is_unique, no),
 	Context = unify_context(explicit, []),
 	goal_info_init(NonLocals, Delta, det, GoalInfo),
 	Goal = unify(Var, functor(ConsId, []), UnifyMode, Uni, Context) -
@@ -1312,9 +1234,10 @@
 		{ instmap_delta_from_assoc_list(InstAL0, InstMapDelta0) },
 		{ goal_info_init(NonLocals0, InstMapDelta0,
 			nondet, GoalInfo0) },
-		{ Goal0 = higher_order_call(CurrPredVar, InputArgs0,
-			InputTypes, OutputModes0,
-			nondet, predicate) - GoalInfo0 },
+		{ list__length(InputArgs0, Arity) },
+		{ Goal0 = generic_call(
+			higher_order(CurrPredVar, predicate, Arity),
+			InputArgs0, OutputModes0, nondet) - GoalInfo0 },
 		( { IsContext = yes(ArgsAL) } ->
 			% Create assignments to assign to the extra arguments.
 			{ magic__create_assignments(ModuleInfo0, ArgsAL,
@@ -1509,10 +1432,8 @@
 	{ Goal = if_then_else(_, _, _, _, _) - _ }.
 magic__preprocess_goal_2(par_conj(_, _) - _, _, _, _) -->
 	{ error("Sorry, not yet implemented: parallel conjunction in Aditi procedures") }.
-magic__preprocess_goal_2(class_method_call(_, _, _, _, _, _) - _, _, _, _) -->
-	{ error("Sorry, not yet implemented: class method calls in Aditi procedures") }.
-magic__preprocess_goal_2(higher_order_call(_, _, _, _, _, _) - _, _, _, _) -->
-	{ error("Sorry, not yet implemented: higher-order calls in Aditi procedures") }.
+magic__preprocess_goal_2(generic_call(_, _, _, _) - _, _, _, _) -->
+	{ error("Sorry, not yet implemented: higher-order or class-method calls in Aditi procedures") }.
 magic__preprocess_goal_2(pragma_c_code(_, _, _, _, _, _, _) - _, _, _, _) -->
 	{ error("Sorry, not yet implemented: pragma c_code calls in Aditi procedures") }.
 
@@ -1546,8 +1467,8 @@
 	;
 		{ Goals = [Goal0] }
 	).
-magic__preprocess_goal_2(some(Vars, Goal0) - Info, [some(Vars, Goal) - Info],
-		HOMap0, HOMap) -->
+magic__preprocess_goal_2(some(Vars, CanRemove, Goal0) - Info,
+		[some(Vars, CanRemove, Goal) - Info], HOMap0, HOMap) -->
 	{ Goal0 = _ - SomeGoalInfo },
 	magic__preprocess_goal(Goal0, SomeGoals, HOMap0, HOMap),
 	{ conj_list_to_goal(SomeGoals, SomeGoalInfo, Goal) }.
@@ -1559,7 +1480,7 @@
 magic__preprocess_goal_2(Goal0, Goals, HOMap0, HOMap) -->
 	{ Goal0 = unify(_, _, _, Uni, _) - GoalInfo },
 	(
-		{ Uni = construct(Var, pred_const(_, _), Args, _) }
+		{ Uni = construct(Var, pred_const(_, _, _), Args, _, _, _, _) }
 	->
 		% Collect up the closure construction so that it can be
 		% placed next to the aggregate goal that uses it.
@@ -1677,7 +1598,7 @@
 		{
 			Goal = not(_) - _
 		;
-			Goal = some(_, _) - _
+			Goal = some(_, _, _) - _
 		;
 			Goal = conj(_) - _
 		; 	
@@ -1686,13 +1607,17 @@
 				Goal, _, _)
 		;
 			Goal = unify(_, _, _, Uni, _) - _,
-			Uni = construct(_, pred_const(PredId, ProcId), _, _),
+			Uni = construct(_, pred_const(PredId, ProcId, _),
+				_, _, _, _, _),
+			% XXX once the implementation of aggregates has
+			% been updated to use `aditi_bottom_up' closures,
+			% this can be done by just checking the eval_method.
 			(
 				map__contains(PredMap, proc(PredId, ProcId))
 			;
 				hlds_pred__is_aditi_relation(ModuleInfo,
 					PredId)
-			)	
+			)
 		}
 	->
 		[]
Index: compiler/magic_util.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/magic_util.m,v
retrieving revision 1.2
diff -u -u -r1.2 magic_util.m
--- magic_util.m	1999/06/01 09:43:57	1.2
+++ magic_util.m	1999/06/02 01:21:06
@@ -98,10 +98,6 @@
 :- pred magic_util__mode_to_output_mode(module_info::in,
 		(mode)::in, (mode)::out) is det.
 
-	% Remove an `aditi:state' from the given list if one is present.
-:- pred magic_util__remove_aditi_state(list(type)::in,
-		list(T)::in, list(T)::out) is det.
-
 	% Adjust an index to account for the removal of the `aditi:state'
 	% from the argument list.
 :- pred magic_util__adjust_index(list(type)::in, index_spec::in,
@@ -190,7 +186,7 @@
 	% and multiple nested quantifications are not considered 
 	% atomic by dnf.m.
 	%
-	( Goal0 = some(_, Goal1) - _ -> 
+	( Goal0 = some(_, _, Goal1) - _ -> 
 		Goal2 = Goal1
 	;
 		Goal2 = Goal0
@@ -259,10 +255,10 @@
 
 magic_util__check_aggregate_closure(Goal, Goal) :-
 	Goal = unify(_, _, _, Uni, _) - _,
-	Uni = construct(_, pred_const(_, _), _, _).	
+	Uni = construct(_, pred_const(_, _, _), _, _, _, _, _).	
 
-:- pred magic_util__construct_db_call(module_info::in, pred_id::in, proc_id::in,
-		list(prog_var)::in, hlds_goal::in, db_call::out) is det.
+:- pred magic_util__construct_db_call(module_info::in, pred_id::in,
+	proc_id::in, list(prog_var)::in, hlds_goal::in, db_call::out) is det.
 
 magic_util__construct_db_call(ModuleInfo, PredId, ProcId,
 		Args0, Goal0, Call) :-
@@ -270,27 +266,14 @@
 		PredInfo, ProcInfo),
 	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),
+	type_util__remove_aditi_state(ArgTypes, ArgModes0, ArgModes),
+	type_util__remove_aditi_state(ArgTypes, Args0, Args),
 	partition_args(ModuleInfo, ArgModes, Args, InputArgs, OutputArgs),
 	Call = db_call(no, Goal0, proc(PredId, ProcId), Args,
 		InputArgs, OutputArgs, no).
 
 %-----------------------------------------------------------------------------%
 
-magic_util__remove_aditi_state([], [], []).
-magic_util__remove_aditi_state([], [_|_], _) :-
-	error("magic_util__remove_aditi_state").
-magic_util__remove_aditi_state([_|_], [], _) :-
-	error("magic_util__remove_aditi_state").
-magic_util__remove_aditi_state([Type | Types], [Arg | Args0], Args) :-
-	( type_is_aditi_state(Type) ->
-		magic_util__remove_aditi_state(Types, Args0, Args)
-	;
-		magic_util__remove_aditi_state(Types, Args0, Args1),
-		Args = [Arg | Args1]
-	).
-
 magic_util__adjust_index(ArgTypes0, index_spec(IndexType, Attrs0),
 		index_spec(IndexType, Attrs)) :-
 	strip_prog_contexts(ArgTypes0, ArgTypes),
@@ -315,7 +298,7 @@
 	{ proc_info_vartypes(ProcInfo, VarTypes) },
 	{ set__to_sorted_list(NonLocals0, NonLocals1) },
 	{ map__apply_to_list(NonLocals1, VarTypes, NonLocalTypes) },
-	{ magic_util__remove_aditi_state(NonLocalTypes,
+	{ type_util__remove_aditi_state(NonLocalTypes,
 		NonLocals1, NonLocals2) },
 	{ set__sorted_list_to_set(NonLocals2, NonLocals) }.
 
@@ -447,15 +430,15 @@
 	magic_info_get_pred_map(PredMap),
 	(
 		{ Closure = unify(_, _, UniMode, Uni0, Context) - Info },
-		{ Uni0 = construct(Var, ConsId0, _, Modes) },
-		{ ConsId0 = pred_const(PredId0, ProcId0) },
+		{ Uni0 = construct(Var, ConsId0, _, Modes, _, _, _) },
+		{ ConsId0 = pred_const(PredId0, ProcId0, Method) },
 		%
 		% Replace the pred_proc_id of the procedure being aggregated
 		% over with its Aditi version.
 		%
 		{ map__search(PredMap, proc(PredId0, ProcId0), PredProcId) ->
 			PredProcId = proc(PredId, ProcId),
-			ConsId = pred_const(PredId, ProcId)
+			ConsId = pred_const(PredId, ProcId, Method)
 		;
 			PredId = PredId0,
 			ProcId = ProcId0,
@@ -487,7 +470,8 @@
 		{ Rhs = functor(cons(qualified(PredModule, PredName), Arity),
 				InputVars) },
 
-		{ Uni = construct(Var, ConsId, InputVars, Modes) },
+		{ Uni = construct(Var, ConsId, InputVars, Modes,
+			no, cell_is_unique, no) },
 		{ Goal1 = unify(Var, Rhs, UniMode, Uni, Context) - Info },
 
 		{ list__append(InputGoals, [Goal1], InputAndClosure) }
@@ -724,15 +708,18 @@
 magic_util__get_input_var(MagicTypes, CurrVar, InputVar, ArgTypes, 
 		ProcInfo0, ProcInfo) :-
 	list__index1_det(MagicTypes, CurrVar, MagicType),
-	( type_is_higher_order(MagicType, predicate, ArgTypes1) ->
-		ArgTypes = ArgTypes1
+	(
+		type_is_higher_order(MagicType, predicate,
+			(aditi_bottom_up), ArgTypes1)
+	->
+		ArgTypes = ArgTypes1,
+		construct_higher_order_type(predicate, (aditi_bottom_up),
+			ArgTypes, ClosureType),
+		proc_info_create_var_from_type(ProcInfo0, 
+			ClosureType, InputVar, ProcInfo)
 	;
 		error("magic_util__get_input_var")
-	),
-	term__context_init(Context),
-	ClosureType = term__functor(term__atom("pred"), ArgTypes, Context),
-	proc_info_create_var_from_type(ProcInfo0, 
-		ClosureType, InputVar, ProcInfo).
+	).
 
 magic_util__create_closure(_CurrVar, InputVar, InputMode, LambdaGoal, 
 		LambdaInputs, LambdaVars, InputGoal) -->
@@ -816,8 +803,8 @@
 				SuppArity), LambdaInputs) },
 
 		{ Unify = construct(InputVar, 
-				pred_const(SuppPredId, SuppProcId), 
-				LambdaInputs, UniModes) },
+			pred_const(SuppPredId, SuppProcId, (aditi_bottom_up)), 
+			LambdaInputs, UniModes, no, cell_is_unique, no) },
 		{ UnifyContext = unify_context(explicit, []) },
 
 		% Construct a goal_info.
@@ -1214,7 +1201,7 @@
 	magic_info_get_module_info(ModuleInfo),
 	( { type_is_atomic(ArgType, ModuleInfo) } ->
 		{ Errors = Errors0 }
-	; { type_is_higher_order(ArgType, _, _) } ->
+	; { type_is_higher_order(ArgType, _, _, _) } ->
 		% Higher-order types are not allowed.
 		{ set__insert(Errors0, higher_order, Errors) }
 	; { type_is_aditi_state(ArgType) } ->
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list