[m-rev.] diff: more info about subgoals

Zoltan Somogyi zs at cs.mu.OZ.AU
Thu May 1 20:16:08 AEST 2003


Return meaningful information when deconstructing subgoals, instead of
a placeholder, to make it easier to debug minimal model tabling.

library/table_builtin.m:
	Instead of making all the types involved in tabling aliases
	of each other and mapping them all to MR_TrieNode, specify
	separate types for subgoals, answer blocks and lists of answer
	blocks, each implemented using its own, already existing C type.
	Each of these types is one specific alternative of an MR_TableNode
	union pointed to by the MR_TrieNode it replaces. The goals that
	create subgoals, answer blocks and lists of answer blocks do
	one more step of pointer chasing than before, and the goals that
	use them (of which are the majority) do one less step.

	Update the implementations accordingly.

	Be stricter in the use of terminology in comments: use subgoal
	only for entities represented by MR_Subgoal in the implementation.

compiler/table_gen.m:
	Create each variable with the correct type.

	Switch to state variable syntax for threading the main data
	structures.

runtime/mercury_minimal_model.h:
	Change the types of some fields to make them more natural,
	and avoid some casts.

	Add a back pointer from MR_Subgoals to the MR_TrieNode that
	points to them, for use in implementing subgoal deletion
	inside committed choice contexts and for diagnostic messages.

	Fix a bug: declare functions only if mercury_minimal_model.c
	defines them.

runtime/mercury_tabling_macros.h:
	Update the implementation of the macros dealing with answer blocks
	(used by table_builtin.m) to do one less step of pointer chasing.

runtime/mercury_stacks.[ch]:
	Change the types of the arguments representing subgoals from
	MR_TrieNodes to MR_Subgoals.

	Shorten some field names.

runtime/mercury_ml_expand_body.h:
	Special case subgoals when deconstructing terms. This affects only
	implementors, since user programs cannot get their hands on terms
	of such types, and the debugger displays them only with
	print_optionals.

runtime/mercury_deconstruct.c:
	Add a #include needed by mercury_ml_expand_body.h, which
	mercury_deconstruct.c #includes.

trace/mercury_trace.c:
	Use a shortened field name.

Zoltan.

cvs diff: Diffing .
cvs diff: Diffing analysis
cvs diff: Diffing bindist
cvs diff: Diffing boehm_gc
cvs diff: Diffing boehm_gc/Mac_files
cvs diff: Diffing boehm_gc/cord
cvs diff: Diffing boehm_gc/cord/private
cvs diff: Diffing boehm_gc/doc
cvs diff: Diffing boehm_gc/include
cvs diff: Diffing boehm_gc/include/private
cvs diff: Diffing boehm_gc/tests
cvs diff: Diffing browser
cvs diff: Diffing bytecode
cvs diff: Diffing compiler
Index: compiler/table_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/table_gen.m,v
retrieving revision 1.48
diff -u -r1.48 table_gen.m
--- compiler/table_gen.m	15 Apr 2003 04:12:12 -0000	1.48
+++ compiler/table_gen.m	30 Apr 2003 18:32:11 -0000
@@ -605,13 +605,13 @@
 	hlds_goal::out, maybe(proc_table_info)::out) is det.
 
 table_gen__create_new_io_goal(OrigGoal, TableDecl, Unitize, TableIoStates,
-		HeadVars, HeadVarModes, VarTypes0, VarTypes, VarSet0, VarSet,
-		TableInfo0, TableInfo, Goal, MaybeProcTableInfo) :-
+		HeadVars, HeadVarModes, !VarTypes, !VarSet, !TableInfo,
+		Goal, MaybeProcTableInfo) :-
 	OrigGoal = _ - OrigGoalInfo,
 	goal_info_get_nonlocals(OrigGoalInfo, OrigNonLocals),
 	goal_info_get_context(OrigGoalInfo, Context),
 
-	ModuleInfo = TableInfo0 ^ table_module_info,
+	ModuleInfo = !.TableInfo ^ table_module_info,
 
 	get_input_output_vars(HeadVars, HeadVarModes, ModuleInfo, InputVars,
 		OutputVars),
@@ -623,28 +623,28 @@
 		SavedHeadVars = HeadVars
 	;
 		TableIoStates = no,
-		list__filter(table_gen__var_is_io_state(VarTypes0),
+		list__filter(table_gen__var_is_io_state(!.VarTypes),
 			OutputVars, IoStateAssignToVars, SavedOutputVars),
-		list__filter(table_gen__var_is_io_state(VarTypes0),
+		list__filter(table_gen__var_is_io_state(!.VarTypes),
 			InputVars, IoStateAssignFromVars, _SavedInputVars),
-		list__filter(table_gen__var_is_io_state(VarTypes0),
+		list__filter(table_gen__var_is_io_state(!.VarTypes),
 			HeadVars, _, SavedHeadVars)
 	),
 
-	generate_new_table_var("TableVar0", node_type, VarTypes0, VarTypes1,
-		VarSet0, VarSet1, TableVar0),
-	generate_new_table_var("CounterVar", int_type, VarTypes1, VarTypes2,
-		VarSet1, VarSet2, CounterVar),
-	generate_new_table_var("StartVar", int_type, VarTypes2, VarTypes3,
-		VarSet2, VarSet3, StartVar),
+	generate_new_table_var("TableVar0", trie_node_type, !VarTypes, !VarSet,
+		TableVar0),
+	generate_new_table_var("CounterVar", int_type, !VarTypes, !VarSet,
+		CounterVar),
+	generate_new_table_var("StartVar", int_type, !VarTypes, !VarSet,
+		StartVar),
 	generate_call("table_io_in_range", [TableVar0, CounterVar, StartVar],
 		semidet, yes(impure), [TableVar0 - ground(shared, none),
 		CounterVar - ground(shared, none),
 		StartVar - ground(shared, none)],
 		ModuleInfo, Context, InRangeGoal),
 
-	generate_new_table_var("TableVar", node_type, VarTypes3, VarTypes4,
-		VarSet3, VarSet4, TableVar),
+	generate_new_table_var("TableVar", trie_node_type, !VarTypes, !VarSet,
+		TableVar),
 	generate_call("table_lookup_insert_start_int",
 		[TableVar0, StartVar, CounterVar, TableVar],
 		det, yes(impure), [TableVar - ground(unique, none)],
@@ -655,15 +655,14 @@
 
 	(
 		TableDecl = table_io_decl,
-		PredId = TableInfo0 ^ table_cur_pred_id,
-		ProcId = TableInfo0 ^ table_cur_proc_id,
+		PredId = !.TableInfo ^ table_cur_pred_id,
+		ProcId = !.TableInfo ^ table_cur_proc_id,
 		RttiProcLabel = rtti__make_rtti_proc_label(ModuleInfo,
 			PredId, ProcId),
 		TableIoDeclConsId = table_io_decl(RttiProcLabel),
-		make_const_construction(TableIoDeclConsId, node_type,
+		make_const_construction(TableIoDeclConsId, c_pointer_type,
 			yes("TableIoDeclPtr"), TableIoDeclGoal,
-			TableIoDeclPtrVar, VarTypes4, VarTypes5,
-			VarSet4, VarSet5),
+			TableIoDeclPtrVar, !VarTypes, !VarSet),
 		allocate_slot_numbers(SavedHeadVars, 1, NumberedSavedHeadVars),
 		NumberedSaveVars = [TableIoDeclPtrVar - 0 |
 			NumberedSavedHeadVars],
@@ -671,15 +670,13 @@
 			NumberedSaveVars, NumberedSavedOutputVars),
 		NumberedRestoreVars = NumberedSavedOutputVars,
 
-		ProcInfo0 = TableInfo0 ^ table_cur_proc_info,
+		ProcInfo0 = !.TableInfo ^ table_cur_proc_info,
 		continuation_info__generate_table_arg_type_info(ProcInfo0,
 			NumberedSavedHeadVars, TableArgTypeInfo),
 		ProcTableInfo = table_io_decl_info(TableArgTypeInfo),
 		MaybeProcTableInfo = yes(ProcTableInfo)
 	;
 		TableDecl = table_io_proc,
-		VarTypes5 = VarTypes4,
-		VarSet5 = VarSet4,
 		true_goal(TableIoDeclGoal),
 		allocate_slot_numbers(SavedOutputVars, 0,
 			NumberedSavedOutputVars),
@@ -691,8 +688,7 @@
 	list__length(NumberedSaveVars, BlockSize),
 
 	generate_restore_goal(NumberedRestoreVars, TableVar,
-		ModuleInfo, Context, VarTypes5, VarTypes6, VarSet5, VarSet6,
-		RestoreAnsGoal0),
+		ModuleInfo, Context, !VarTypes, !VarSet, RestoreAnsGoal0),
 
 	(
 		TableIoStates = yes,
@@ -736,19 +732,15 @@
 		RestoreAnsGoal = RestoreAnsGoalEx - RestoreAnsGoalInfo
 	),
 	generate_save_goal(NumberedSaveVars, TableVar, BlockSize,
-		Context, VarTypes6, VarTypes7, VarSet6, VarSet7,
-		TableInfo0, TableInfo, SaveAnsGoal),
+		Context, !VarTypes, !VarSet, !TableInfo, SaveAnsGoal),
 
 	(
 		Unitize = table_io_alone,
-		VarSet = VarSet7,
-		VarTypes = VarTypes7,
 		CallSaveAnsGoalList = [OrigGoal, TableIoDeclGoal, SaveAnsGoal]
 	;
 		Unitize = table_io_unitize,
 		generate_new_table_var("SavedTraceEnabled", int_type,
-			VarTypes7, VarTypes, VarSet7, VarSet,
-			SavedTraceEnabledVar),
+			!VarTypes, !VarSet, SavedTraceEnabledVar),
 		generate_call("table_io_left_bracket_unitized_goal",
 			[SavedTraceEnabledVar], det, yes(impure),
 			[SavedTraceEnabledVar - ground(unique, none)],
@@ -1244,10 +1236,10 @@
 	prog_varset::in, prog_varset::out,
 	prog_var::out, hlds_goal::out) is det.
 
-generate_get_table_goal(PredId, ProcId, VarTypes0, VarTypes, VarSet0, VarSet,
-		PredTableVar, Goal) :-
-	generate_new_table_var("PredTable", node_type, VarTypes0, VarTypes,
-		VarSet0, VarSet, PredTableVar),
+generate_get_table_goal(PredId, ProcId, !VarTypes, !VarSet, PredTableVar,
+		Goal) :-
+	generate_new_table_var("PredTable", trie_node_type, !VarTypes, !VarSet,
+		PredTableVar),
 	ConsId = tabling_pointer_const(PredId, ProcId),
 	make_const_construction(PredTableVar, ConsId, GoalExpr - GoalInfo0),
 	goal_info_add_feature(GoalInfo0, impure, GoalInfo),
@@ -1261,14 +1253,12 @@
 	prog_varset::in, prog_varset::out, table_info::in, table_info::out,
 	prog_var::out, hlds_goal::out, list(table_trie_step)::out) is det.
 
-generate_simple_lookup_goal(Vars, PredId, ProcId, Context, VarTypes0, VarTypes,
-		VarSet0, VarSet, TableInfo0, TableInfo, TableVar, Goal,
-		Steps) :-
-	generate_get_table_goal(PredId, ProcId, VarTypes0, VarTypes1,
-		VarSet0, VarSet1, PredTableVar, GetTableGoal),
+generate_simple_lookup_goal(Vars, PredId, ProcId, Context, !VarTypes, !VarSet,
+		!TableInfo, TableVar, Goal, Steps) :-
+	generate_get_table_goal(PredId, ProcId, !VarTypes, !VarSet,
+		PredTableVar, GetTableGoal),
 	generate_lookup_goals(Vars, Context, PredTableVar, TableVar,
-		VarTypes1, VarTypes, VarSet1, VarSet, TableInfo0, TableInfo,
-		LookupGoals, Steps),
+		!VarTypes, !VarSet, !TableInfo, LookupGoals, Steps),
 	GoalEx = conj([GetTableGoal | LookupGoals]),
 	set__singleton_set(NonLocals0, TableVar),
 	set__insert_list(NonLocals0, Vars, NonLocals),
@@ -1290,17 +1280,15 @@
 	prog_varset::in, prog_varset::out, table_info::in, table_info::out,
 	prog_var::out, hlds_goal::out, list(table_trie_step)::out) is det.
 
-generate_non_lookup_goal(Vars, PredId, ProcId, Context, VarTypes0, VarTypes,
-		VarSet0, VarSet, TableInfo0, TableInfo, SubgoalVar, Goal,
-		Steps) :-
-	ModuleInfo = TableInfo0 ^ table_module_info,
-	generate_get_table_goal(PredId, ProcId, VarTypes0, VarTypes1,
-		VarSet0, VarSet1, PredTableVar, GetTableGoal),
+generate_non_lookup_goal(Vars, PredId, ProcId, Context, !VarTypes, !VarSet,
+		!TableInfo, SubgoalVar, Goal, Steps) :-
+	ModuleInfo = !.TableInfo ^ table_module_info,
+	generate_get_table_goal(PredId, ProcId, !VarTypes,
+		!VarSet, PredTableVar, GetTableGoal),
 	generate_lookup_goals(Vars, Context, PredTableVar, TableNodeVar,
-		VarTypes1, VarTypes2, VarSet1, VarSet2, TableInfo0, TableInfo,
-		LookupGoals, Steps),
-	generate_new_table_var("SubgoalVar", node_type, VarTypes2, VarTypes,
-		VarSet2, VarSet, SubgoalVar),
+		!VarTypes, !VarSet, !TableInfo, LookupGoals, Steps),
+	generate_new_table_var("SubgoalVar", subgoal_type, !VarTypes, !VarSet,
+		SubgoalVar),
 	generate_call("table_nondet_setup", [TableNodeVar, SubgoalVar],
 		det, yes(impure), [SubgoalVar - ground(unique, none)],
 		ModuleInfo, Context, SetupGoal),
@@ -1329,20 +1317,17 @@
 	prog_varset::in, prog_varset::out, table_info::in, table_info::out,
 	list(hlds_goal)::out, list(table_trie_step)::out) is det.
 
-generate_lookup_goals([], _, TableVar, TableVar, VarTypes, VarTypes,
-		VarSet, VarSet, TableInfo, TableInfo, [], []).
-generate_lookup_goals([Var | Rest], Context, TableVar0, TableVar,
-		VarTypes0, VarTypes, VarSet0, VarSet, TableInfo0, TableInfo,
-		[Goal | RestGoals], [Step | Steps]) :-
-	ModuleInfo = TableInfo0 ^ table_module_info,
-	map__lookup(VarTypes0, Var, VarType),
+generate_lookup_goals([], _, TableVar, TableVar, !VarTypes, !VarSet,
+		!TableInfo, [], []).
+generate_lookup_goals([Var | Rest], Context, TableVar0, TableVar, !VarTypes,
+		!VarSet, !TableInfo, [Goal | RestGoals], [Step | Steps]) :-
+	ModuleInfo = !.TableInfo ^ table_module_info,
+	map__lookup(!.VarTypes, Var, VarType),
 	classify_type(VarType, ModuleInfo, TypeCat),
 	gen_lookup_call_for_type(TypeCat, VarType, TableVar0, Var, Context,
-		VarTypes0, VarTypes1, VarSet0, VarSet1, TableInfo0, TableInfo1,
-		TableVar1, Goal, Step),
+		!VarTypes, !VarSet, !TableInfo, TableVar1, Goal, Step),
 	generate_lookup_goals(Rest, Context, TableVar1, TableVar,
-		VarTypes1, VarTypes, VarSet1, VarSet, TableInfo1, TableInfo,
-		RestGoals, Steps).
+		!VarTypes, !VarSet, !TableInfo, RestGoals, Steps).
 
 :- pred gen_lookup_call_for_type(builtin_type::in, (type)::in,
 	prog_var::in, prog_var::in, term__context::in,
@@ -1351,9 +1336,8 @@
 	prog_var::out, hlds_goal::out, table_trie_step::out) is det.
 
 gen_lookup_call_for_type(TypeCat, Type, TableVar, ArgVar, Context,
-		VarTypes0, VarTypes, VarSet0, VarSet, TableInfo0, TableInfo,
-		NextTableVar, Goal, Step) :-
-	ModuleInfo = TableInfo0 ^ table_module_info,
+		!VarTypes, !VarSet, !TableInfo, NextTableVar, Goal, Step) :-
+	ModuleInfo = !.TableInfo ^ table_module_info,
 
 	( TypeCat = enum_type ->
 		( type_to_ctor_and_args(Type, TypeCtor, _) ->
@@ -1368,13 +1352,11 @@
 				error(
     "gen_lookup_call_for_type: enum type is not du_type?")
 			),
-			gen_int_construction("RangeVar", EnumRange, VarTypes0,
-				VarTypes1, VarSet0, VarSet1, RangeVar,
-				RangeUnifyGoal),
-
-			generate_new_table_var("TableNodeVar", node_type,
-				VarTypes1, VarTypes, VarSet1, VarSet,
-				NextTableVar),
+			gen_int_construction("RangeVar", EnumRange, !VarTypes,
+				!VarSet, RangeVar, RangeUnifyGoal),
+
+			generate_new_table_var("TableNodeVar", trie_node_type,
+				!VarTypes, !VarSet, NextTableVar),
 			generate_call("table_lookup_insert_enum",
 				[TableVar, RangeVar, ArgVar, NextTableVar],
 				det, yes(impure),
@@ -1387,14 +1369,13 @@
 			goal_info_init(NonLocals, InstMapDelta, det, impure,
 				Context, GoalInfo),
 			Goal = conj([RangeUnifyGoal, LookupGoal]) - GoalInfo,
-			Step = table_trie_step_enum(EnumRange),
-			TableInfo = TableInfo0
+			Step = table_trie_step_enum(EnumRange)
 		;
 			error("gen_lookup_call_for_type: unexpected enum type")
 		)
 	;
-		generate_new_table_var("TableNodeVar", node_type,
-			VarTypes0, VarTypes1, VarSet0, VarSet1, NextTableVar),
+		generate_new_table_var("TableNodeVar", trie_node_type,
+			!VarTypes, !VarSet, NextTableVar),
 		InstMapAL = [NextTableVar - ground(unique, none)],
 		(
 			( TypeCat = pred_type
@@ -1409,9 +1390,8 @@
 				LookupPredName = "table_lookup_insert_poly",
 				Step = table_trie_step_poly
 			),
-			make_type_info_var(Type, Context, VarTypes1, VarTypes,
-				VarSet1, VarSet, TableInfo0, TableInfo,
-				TypeInfoVar, ExtraGoals),
+			make_type_info_var(Type, Context, !VarTypes, !VarSet,
+				!TableInfo, TypeInfoVar, ExtraGoals),
 
 			generate_call(LookupPredName,
 				[TypeInfoVar, TableVar, ArgVar, NextTableVar],
@@ -1428,10 +1408,7 @@
 			generate_call(LookupPredName,
 				[TableVar, ArgVar, NextTableVar],
 				det, yes(impure), InstMapAL, ModuleInfo,
-				Context, Goal),
-			VarTypes = VarTypes1,
-			VarSet = VarSet1,
-			TableInfo = TableInfo0
+				Context, Goal)
 		)
 	).
 
@@ -1444,16 +1421,14 @@
 	hlds_goal::out) is det.
 
 generate_save_goal(NumberedVars, TableVar, BlockSize, Context,
-		VarTypes0, VarTypes, VarSet0, VarSet, TableInfo0, TableInfo,
-		Goal) :-
-	ModuleInfo = TableInfo0 ^ table_module_info,
+		!VarTypes, !VarSet, !TableInfo, Goal) :-
+	ModuleInfo = !.TableInfo ^ table_module_info,
 	( BlockSize > 0 ->
-		gen_int_construction("BlockSize", BlockSize, VarTypes0,
-			VarTypes1, VarSet0, VarSet1, BlockSizeVar,
-			BlockSizeVarUnifyGoal),
+		gen_int_construction("BlockSize", BlockSize, !VarTypes,
+			!VarSet, BlockSizeVar, BlockSizeVarUnifyGoal),
 
-		generate_new_table_var("AnswerTableVar", node_type,
-			VarTypes1, VarTypes2, VarSet1, VarSet2, AnsTableVar),
+		generate_new_table_var("AnswerTableVar", answer_block_type,
+			!VarTypes, !VarSet, AnsTableVar),
 
 		generate_call("table_create_ans_block",
 			[TableVar, BlockSizeVar, AnsTableVar], det,
@@ -1461,8 +1436,7 @@
 			ModuleInfo, Context, CreateAnsBlockGoal),
 
 		generate_save_goals(NumberedVars, AnsTableVar, Context,
-			VarTypes2, VarTypes, VarSet2, VarSet,
-			TableInfo0, TableInfo, SaveGoals),
+			!VarTypes, !VarSet, !TableInfo, SaveGoals),
 
 		GoalEx = conj([BlockSizeVarUnifyGoal, CreateAnsBlockGoal |
 			SaveGoals]),
@@ -1476,11 +1450,8 @@
 			GoalInfo),
 		Goal = GoalEx - GoalInfo
 	;
-		VarTypes = VarTypes0,
-		VarSet = VarSet0,
-		generate_call("table_simple_mark_as_succeeded", [TableVar], det,
-			yes(impure), [], ModuleInfo, Context, Goal),
-		TableInfo = TableInfo0
+		generate_call("table_simple_mark_as_succeeded", [TableVar],
+			det, yes(impure), [], ModuleInfo, Context, Goal)
 	).
 
 :- pred generate_non_save_goal(assoc_list(prog_var, int)::in,
@@ -1490,41 +1461,39 @@
 	hlds_goal::out) is det.
 
 generate_non_save_goal(NumberedOutputVars, TableVar, BlockSize, Context,
-		VarTypes0, VarTypes, VarSet0, VarSet, TableInfo0, TableInfo,
-		Goal) :-
-	ModuleInfo = TableInfo0 ^ table_module_info,
+		!VarTypes, !VarSet, !TableInfo, Goal) :-
+	ModuleInfo = !.TableInfo ^ table_module_info,
 
-	generate_new_table_var("AnswerTableVar", node_type,
-		VarTypes0, VarTypes1, VarSet0, VarSet1, AnsTableVar0),
+	generate_new_table_var("AnswerTableVar", trie_node_type,
+		!VarTypes, !VarSet, AnsTableVar0),
 	generate_call("table_nondet_get_ans_table", [TableVar, AnsTableVar0],
 		det, yes(impure), [AnsTableVar0 - ground(unique, none)],
 		ModuleInfo, Context, GetAnsTableGoal),
 	assoc_list__keys(NumberedOutputVars, OutputVars),
 	generate_lookup_goals(OutputVars, Context,
-		AnsTableVar0, AnsTableVar1, VarTypes1, VarTypes2,
-		VarSet1, VarSet2, TableInfo0, TableInfo1, LookupAnsGoals, _),
+		AnsTableVar0, AnsTableVar1, !VarTypes, !VarSet, !TableInfo,
+		LookupAnsGoals, _),
 	generate_call("table_nondet_answer_is_not_duplicate", [AnsTableVar1],
 		semidet, yes(impure), [], ModuleInfo, Context,
 		DuplicateCheckGoal),
 
-	generate_new_table_var("AnswerSlotVar", node_type,
-		VarTypes2, VarTypes3, VarSet2, VarSet3, AnsSlotVar),
+	generate_new_table_var("AnswerSlotVar", trie_node_type,
+		!VarTypes, !VarSet, AnsSlotVar),
 	generate_call("table_nondet_new_ans_slot", [TableVar, AnsSlotVar], det,
 		yes(impure), [AnsSlotVar - ground(unique, none)],
 		ModuleInfo, Context, NewAnsSlotGoal),
 
-	gen_int_construction("BlockSize", BlockSize, VarTypes3, VarTypes4,
-		VarSet3, VarSet4, BlockSizeVar, BlockSizeVarUnifyGoal),
-	generate_new_table_var("AnswerBlock", node_type, VarTypes4, VarTypes5,
-		VarSet4, VarSet5, AnsBlockVar),
+	gen_int_construction("BlockSize", BlockSize, !VarTypes, !VarSet,
+		BlockSizeVar, BlockSizeVarUnifyGoal),
+	generate_new_table_var("AnswerBlock", answer_block_type,
+		!VarTypes, !VarSet, AnsBlockVar),
 	generate_call("table_create_ans_block",
 		[AnsSlotVar, BlockSizeVar, AnsBlockVar], det, yes(impure),
 		[AnsBlockVar - ground(unique, none)],
 		ModuleInfo, Context, CreateAnsBlockGoal),
 
 	generate_save_goals(NumberedOutputVars, AnsBlockVar, Context,
-		VarTypes5, VarTypes, VarSet5, VarSet, TableInfo1, TableInfo,
-		SaveGoals),
+		!VarTypes, !VarSet, !TableInfo, SaveGoals),
 
 	list__append([GetAnsTableGoal | LookupAnsGoals],
 		[DuplicateCheckGoal, NewAnsSlotGoal, BlockSizeVarUnifyGoal,
@@ -1544,27 +1513,24 @@
 	prog_varset::in, prog_varset::out, table_info::in, table_info::out,
 	list(hlds_goal)::out) is det.
 
-generate_save_goals([], _TableVar, _Context,
-		VarTypes, VarTypes, VarSet, VarSet, TableInfo, TableInfo, []).
+generate_save_goals([], _TableVar, _Context, !VarTypes, !VarSet, !TableInfo,
+		[]).
 generate_save_goals([NumberedVar | NumberedRest], TableVar, Context,
-		VarTypes0, VarTypes, VarSet0, VarSet, TableInfo0, TableInfo,
-		Goals) :-
+		!VarTypes, !VarSet, !TableInfo, Goals) :-
 
 	NumberedVar = Var - Offset,
-	gen_int_construction("OffsetVar", Offset, VarTypes0, VarTypes1,
-		VarSet0, VarSet1, OffsetVar, OffsetUnifyGoal),
+	gen_int_construction("OffsetVar", Offset, !VarTypes,
+		!VarSet, OffsetVar, OffsetUnifyGoal),
 
-	ModuleInfo = TableInfo0 ^ table_module_info,
-	map__lookup(VarTypes1, Var, VarType),
+	ModuleInfo = !.TableInfo ^ table_module_info,
+	map__lookup(!.VarTypes, Var, VarType),
 	classify_type(VarType, ModuleInfo, TypeCat),
 
 	gen_save_call_for_type(TypeCat, VarType, TableVar, Var, OffsetVar,
-		Context, VarTypes1, VarTypes2, VarSet1, VarSet2,
-		TableInfo0, TableInfo1, CallGoal),
+		Context, !VarTypes, !VarSet, !TableInfo, CallGoal),
 
 	generate_save_goals(NumberedRest, TableVar, Context,
-		VarTypes2, VarTypes, VarSet2, VarSet, TableInfo1, TableInfo,
-		RestGoals),
+		!VarTypes, !VarSet, !TableInfo, RestGoals),
 
 	Goals =	[OffsetUnifyGoal, CallGoal | RestGoals].
 
@@ -1575,21 +1541,15 @@
 	hlds_goal::out) is det.
 
 gen_save_call_for_type(TypeCat, Type, TableVar, Var, OffsetVar, Context,
-		VarTypes0, VarTypes, VarSet0, VarSet, TableInfo0, TableInfo,
-		Goal) :-
-	ModuleInfo = TableInfo0 ^ table_module_info,
+		!VarTypes, !VarSet, !TableInfo, Goal) :-
+	ModuleInfo = !.TableInfo ^ table_module_info,
 	( type_util__type_is_io_state(Type) ->
 		LookupPredName = "table_save_io_state_ans",
 		generate_call(LookupPredName, [TableVar, OffsetVar, Var],
-			det, yes(impure), [], ModuleInfo, Context, Goal),
-
-		VarTypes = VarTypes0,
-		VarSet = VarSet0,
-		TableInfo = TableInfo0
+			det, yes(impure), [], ModuleInfo, Context, Goal)
 	; not_builtin_type(TypeCat) ->
-		make_type_info_var(Type, Context, VarTypes0, VarTypes,
-			VarSet0, VarSet, TableInfo0, TableInfo,
-			TypeInfoVar, ExtraGoals),
+		make_type_info_var(Type, Context, !VarTypes, !VarSet,
+			!TableInfo, TypeInfoVar, ExtraGoals),
 
 		generate_call("table_save_any_ans",
 			[TypeInfoVar, TableVar, OffsetVar, Var],
@@ -1603,11 +1563,7 @@
 		string__append_list(["table_save_", CatString, "_ans"],
 			LookupPredName),
 		generate_call(LookupPredName, [TableVar, OffsetVar, Var],
-			det, yes(impure), [], ModuleInfo, Context, Goal),
-
-		VarTypes = VarTypes0,
-		VarSet = VarSet0,
-		TableInfo = TableInfo0
+			det, yes(impure), [], ModuleInfo, Context, Goal)
 	).
 
 %-----------------------------------------------------------------------------%
@@ -1618,11 +1574,10 @@
 	prog_varset::in, prog_varset::out, hlds_goal::out) is det.
 
 generate_restore_goal(NumberedOutputVars, TableVar, ModuleInfo, Context,
-		VarTypes0, VarTypes, VarSet0, VarSet, Goal) :-
+		!VarTypes, !VarSet, Goal) :-
 
 	generate_restore_goals(NumberedOutputVars, TableVar,
-		ModuleInfo, Context, VarTypes0, VarTypes, VarSet0, VarSet,
-		RestoreGoals),
+		ModuleInfo, Context, !VarTypes, !VarSet, RestoreGoals),
 
 	GoalEx = conj(RestoreGoals),
 	set__singleton_set(NonLocals0, TableVar),
@@ -1641,11 +1596,10 @@
 	prog_varset::in, prog_varset::out, hlds_goal::out) is det.
 
 generate_restore_all_goal(Detism, NumberedOutputVars, TableVar,
-		ModuleInfo, Context, VarTypes0, VarTypes, VarSet0, VarSet,
-		Goal) :-
+		ModuleInfo, Context, !VarTypes, !VarSet, Goal) :-
 
-	generate_new_table_var("AnswerTable", node_type, VarTypes0, VarTypes1,
-		VarSet0, VarSet1, AnsTableVar),
+	generate_new_table_var("AnswerTable", answer_block_type,
+		!VarTypes, !VarSet, AnsTableVar),
 	( Detism = multidet ->
 		ReturnAllAns = "table_multi_return_all_ans"
 	; Detism = nondet ->
@@ -1658,7 +1612,7 @@
 		ModuleInfo, Context, ReturnAnsBlocksGoal),
 
 	generate_restore_goals(NumberedOutputVars, AnsTableVar, ModuleInfo,
-		Context, VarTypes1, VarTypes, VarSet1, VarSet, RestoreGoals),
+		Context, !VarTypes, !VarSet, RestoreGoals),
 
 	GoalEx = conj([ReturnAnsBlocksGoal | RestoreGoals]),
 	set__singleton_set(NonLocals0, TableVar),
@@ -1677,23 +1631,23 @@
 	prog_varset::in, prog_varset::out, list(hlds_goal)::out) is det.
 
 generate_restore_goals([], _TableVar, _ModuleInfo, _Context,
-		VarTypes, VarTypes, VarSet, VarSet, []).
+		!VarTypes, !VarSet, []).
 generate_restore_goals([NumberedVar | NumberedRest], TableVar,
-		ModuleInfo, Context, VarTypes0, VarTypes, VarSet0, VarSet,
+		ModuleInfo, Context, !VarTypes, !VarSet,
 		[OffsetUnifyGoal, CallGoal | RestGoals]) :-
 
 	NumberedVar = Var - Offset,
-	gen_int_construction("OffsetVar", Offset, VarTypes0, VarTypes1,
-		VarSet0, VarSet1, OffsetVar, OffsetUnifyGoal),
+	gen_int_construction("OffsetVar", Offset, !VarTypes, !VarSet,
+		OffsetVar, OffsetUnifyGoal),
 
-	map__lookup(VarTypes1, Var, VarType),
+	map__lookup(!.VarTypes, Var, VarType),
 	classify_type(VarType, ModuleInfo, TypeCat),
 
 	gen_restore_call_for_type(TypeCat, VarType, TableVar, Var, OffsetVar,
 		ModuleInfo, Context, CallGoal),
 
 	generate_restore_goals(NumberedRest, TableVar, ModuleInfo, Context,
-		VarTypes1, VarTypes, VarSet1, VarSet, RestGoals).
+		!VarTypes, !VarSet, RestGoals).
 
 :- pred gen_restore_call_for_type(builtin_type::in, (type)::in,
 	prog_var::in, prog_var::in, prog_var::in, module_info::in,
@@ -1722,17 +1676,16 @@
 	prog_varset::in, prog_varset::out, hlds_goal::out) is det.
 
 generate_suspend_goal(NumberedOutputVars, TableVar, ModuleInfo, Context,
-		VarTypes0, VarTypes, VarSet0, VarSet, Goal) :-
+		!VarTypes, !VarSet, Goal) :-
 
-	generate_new_table_var("AnswerTable", node_type, VarTypes0, VarTypes1,
-		VarSet0, VarSet1, AnsTableVar),
+	generate_new_table_var("AnswerTable", answer_block_type,
+		!VarTypes, !VarSet, AnsTableVar),
 	generate_call("table_nondet_suspend", [TableVar, AnsTableVar],
 		nondet, yes(semipure), [AnsTableVar - ground(unique, none)],
 		ModuleInfo, Context, ReturnAnsBlocksGoal),
 
 	generate_restore_goals(NumberedOutputVars, AnsTableVar,
-		ModuleInfo, Context, VarTypes1, VarTypes, VarSet1, VarSet,
-		RestoreGoals),
+		ModuleInfo, Context, !VarTypes, !VarSet, RestoreGoals),
 
 	GoalEx = conj([ReturnAnsBlocksGoal | RestoreGoals]),
 	set__singleton_set(NonLocals0, TableVar),
@@ -1788,10 +1741,9 @@
 	map(prog_var, type)::in, map(prog_var, type)::out,
 	prog_varset::in, prog_varset::out, prog_var::out) is det.
 
-generate_new_table_var(Name, Type, VarTypes0, VarTypes, VarSet0, VarSet, Var)
-		:-
-	varset__new_named_var(VarSet0, Name, Var, VarSet),
-	map__set(VarTypes0, Var, Type, VarTypes).
+generate_new_table_var(Name, Type, !VarTypes, !VarSet, Var) :-
+	varset__new_named_var(!.VarSet, Name, Var, !:VarSet),
+	map__set(!.VarTypes, Var, Type, !:VarTypes).
 
 :- pred generate_call(string::in, list(prog_var)::in, determinism::in,
 	maybe(goal_feature)::in, assoc_list(prog_var, inst)::in,
@@ -1821,24 +1773,36 @@
 	prog_varset::in, prog_varset::out,
 	prog_var::out, hlds_goal::out) is det.
 
-gen_int_construction(VarName, VarValue, VarTypes0, VarTypes, VarSet0, VarSet,
-		Var, Goal) :-
+gen_int_construction(VarName, VarValue, !VarTypes, !VarSet, Var, Goal) :-
 	make_int_const_construction(VarValue, yes(VarName), Goal, Var,
-		VarTypes0, VarTypes, VarSet0, VarSet).
+		!VarTypes, !VarSet).
 
 :- pred gen_string_construction(string::in, string::in,
 	map(prog_var, type)::in, map(prog_var, type)::out,
 	prog_varset::in, prog_varset::out,
 	prog_var::out, hlds_goal::out) is det.
 
-gen_string_construction(VarName, VarValue, VarTypes0, VarTypes, VarSet0, VarSet,
-		Var, Goal) :-
+gen_string_construction(VarName, VarValue, !VarTypes, !VarSet, Var, Goal) :-
 	make_string_const_construction(VarValue, yes(VarName), Goal, Var,
-		VarTypes0, VarTypes, VarSet0, VarSet).
+		!VarTypes, !VarSet).
+
+:- func trie_node_type = (type).
 
-:- func node_type = (type).
+trie_node_type = Type :-
+	mercury_table_builtin_module(TB),
+	construct_type(qualified(TB, "ml_trie_node") - 0, [], Type).
+
+:- func subgoal_type = (type).
+
+subgoal_type = Type :-
+	mercury_table_builtin_module(TB),
+	construct_type(qualified(TB, "ml_subgoal") - 0, [], Type).
+
+:- func answer_block_type = (type).
 
-node_type = c_pointer_type.
+answer_block_type = Type :-
+	mercury_table_builtin_module(TB),
+	construct_type(qualified(TB, "ml_answer_block") - 0, [], Type).
 
 :- func status_type = (type).
 
@@ -1932,12 +1896,10 @@
 	prog_varset::in, prog_varset::out, table_info::in, table_info::out,
 	prog_var::out, list(hlds_goal)::out) is det.
 
-table_gen__make_type_info_var(Type, Context,
-		VarTypes0, VarTypes, VarSet0, VarSet, TableInfo0, TableInfo,
+table_gen__make_type_info_var(Type, Context, !VarTypes, !VarSet, !TableInfo,
 		TypeInfoVar, TypeInfoGoals) :-
-	table_gen__make_type_info_vars([Type], Context,
-		VarTypes0, VarTypes, VarSet0, VarSet, TableInfo0, TableInfo,
-		TypeInfoVars, TypeInfoGoals),
+	table_gen__make_type_info_vars([Type], Context, !VarTypes, !VarSet,
+		!TableInfo, TypeInfoVars, TypeInfoGoals),
 	( TypeInfoVars = [TypeInfoVar0] ->
 		TypeInfoVar = TypeInfoVar0
 	;
@@ -1949,21 +1911,20 @@
 	prog_varset::in, prog_varset::out, table_info::in, table_info::out,
 	list(prog_var)::out, list(hlds_goal)::out) is det.
 
-table_gen__make_type_info_vars(Types, Context,
-		VarTypes0, VarTypes, VarSet0, VarSet, TableInfo0, TableInfo,
+table_gen__make_type_info_vars(Types, Context, !VarTypes, !VarSet, !TableInfo,
 		TypeInfoVars, TypeInfoGoals) :-
 	%
 	% Extract the information from table_info
 	%
-	table_info_extract(TableInfo0, ModuleInfo0, PredId, ProcId,
+	table_info_extract(!.TableInfo, ModuleInfo0, PredId, ProcId,
 		PredInfo0, ProcInfo0),
 
 	%
 	% Put the varset and vartypes from the simplify_info
 	% back in the proc_info
 	%
-	proc_info_set_vartypes(ProcInfo0, VarTypes0, ProcInfo1),
-	proc_info_set_varset(ProcInfo1, VarSet0, ProcInfo2),
+	proc_info_set_vartypes(ProcInfo0, !.VarTypes, ProcInfo1),
+	proc_info_set_varset(ProcInfo1, !.VarSet, ProcInfo2),
 
 	%
 	% Call polymorphism.m to create the type_infos
@@ -1977,15 +1938,15 @@
 	%
 	% Get the new varset and vartypes from the proc_info
 	%
-	proc_info_vartypes(ProcInfo, VarTypes),
-	proc_info_varset(ProcInfo, VarSet),
+	proc_info_vartypes(ProcInfo, !:VarTypes),
+	proc_info_varset(ProcInfo, !:VarSet),
 
 	%
 	% Put the new module_info, pred_info, and proc_info back in the
 	% table_info.
 	%
 	table_info_init(ModuleInfo, PredId, ProcId, PredInfo, ProcInfo,
-		TableInfo).
+		!:TableInfo).
 
 %-----------------------------------------------------------------------------%
 
cvs diff: Diffing compiler/notes
cvs diff: Diffing debian
cvs diff: Diffing deep_profiler
cvs diff: Diffing deep_profiler/notes
cvs diff: Diffing doc
cvs diff: Diffing extras
cvs diff: Diffing extras/aditi
cvs diff: Diffing extras/cgi
cvs diff: Diffing extras/complex_numbers
cvs diff: Diffing extras/complex_numbers/samples
cvs diff: Diffing extras/complex_numbers/tests
cvs diff: Diffing extras/concurrency
cvs diff: Diffing extras/curs
cvs diff: Diffing extras/curs/samples
cvs diff: Diffing extras/curses
cvs diff: Diffing extras/curses/sample
cvs diff: Diffing extras/dynamic_linking
cvs diff: Diffing extras/error
cvs diff: Diffing extras/graphics
cvs diff: Diffing extras/graphics/mercury_opengl
cvs diff: Diffing extras/graphics/mercury_tcltk
cvs diff: Diffing extras/graphics/samples
cvs diff: Diffing extras/graphics/samples/calc
cvs diff: Diffing extras/graphics/samples/maze
cvs diff: Diffing extras/graphics/samples/pent
cvs diff: Diffing extras/lazy_evaluation
cvs diff: Diffing extras/lex
cvs diff: Diffing extras/lex/samples
cvs diff: Diffing extras/lex/tests
cvs diff: Diffing extras/logged_output
cvs diff: Diffing extras/moose
cvs diff: Diffing extras/moose/samples
cvs diff: Diffing extras/morphine
cvs diff: Diffing extras/morphine/non-regression-tests
cvs diff: Diffing extras/morphine/scripts
cvs diff: Diffing extras/morphine/source
cvs diff: Diffing extras/odbc
cvs diff: Diffing extras/posix
cvs diff: Diffing extras/quickcheck
cvs diff: Diffing extras/quickcheck/tutes
cvs diff: Diffing extras/references
cvs diff: Diffing extras/references/samples
cvs diff: Diffing extras/references/tests
cvs diff: Diffing extras/stream
cvs diff: Diffing extras/trailed_update
cvs diff: Diffing extras/trailed_update/samples
cvs diff: Diffing extras/trailed_update/tests
cvs diff: Diffing extras/xml
cvs diff: Diffing extras/xml/samples
cvs diff: Diffing java
cvs diff: Diffing java/library
cvs diff: Diffing java/runtime
cvs diff: Diffing library
Index: library/table_builtin.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/table_builtin.m,v
retrieving revision 1.28
diff -u -r1.28 table_builtin.m
--- library/table_builtin.m	18 Mar 2003 16:37:58 -0000	1.28
+++ library/table_builtin.m	30 Apr 2003 16:30:34 -0000
@@ -35,25 +35,23 @@
 %
 % The predicates fall into three categories:
 %
-% (1)	Predicates that manage the tabling of simple subgoals.
-%	A subgoal is simple if its predicate is model_det or model_semi,
-%	which means that its evaluation method must be something
-%	other than minimal model.
+% (1)	Predicates that manage the tabling of model_det and model_semi
+%	predicates, whose evaluation method must be something other than
+%	minimal model.
 %
-% (2)	Predicates that manage the tabling of model_non subgoals,
-%	which usually means that its evaluation method is minimal model.
+% (2)	Predicates that manage the tabling of model_non predicates,
+%	whose evaluation method is usually minimal model.
 %
-% (3)	Utility predicates that are needed in the tabling of both
-%	simple and nondet subgoals.
+% (3)	Utility predicates that are needed in the tabling of all predicates.
 %
 % The utility predicates that handle tries are combined lookup/insert
 % operations; if the item being searched for is not already in the trie,
-% they insert it. These predicates are used to implement both subgoal tables,
+% they insert it. These predicates are used to implement both call tables,
 % in which case the items inserted are input arguments of a tabled predicate,
 % and answer tables, in which case the items inserted are output arguments
 % of a tabled predicate.
 %
-% The subgoal table trie is used for detecting duplicate calls,
+% The call table trie is used for detecting duplicate calls,
 % while the answer table trie is used for detecting duplicate answers.
 % However, storing answers only in the answer table trie is not sufficient,
 % for two reasons. First, while the trie encodes the values of the output
@@ -67,13 +65,13 @@
 % concerned. To handle the second problem, for model_non procedures
 % we chain these answer blocks together in a chronological list.
 %
-% For simple goals, the word at the end of the subgoal table trie is used
+% For simple goals, the word at the end of the call table trie is used
 % first as a status indication (of type MR_SimpletableStatus), and later on
 % as a pointer to an answer block (if the goal succeeded). This is OK, because
 % we can distinguish the two, and because an answer block pointer can be
 % associated with only one status value.
 %
-% For nondet goals, the word at the end of the subgoal table trie always
+% For nondet goals, the word at the end of the call table trie always
 % points to a subgoal structure, with several fields. The status of the
 % subgoal and the list of answers are two of these fields. Other fields,
 % described in runtime/mercury_tabling.h, are used in the implementation
@@ -84,41 +82,18 @@
 % this causes the predicates to become impure. The predicates with the semipure
 % directive only examine the tabling structures, but do not modify them.
 
-	% This type is used as a generic table: it can in fact represent two
-	% types, either a subgoal_table or an answer_table. The subgoal_table
-	% and answer_table types are differentiated by what they have at the
-	% table nodes but not by the actual underlying trie structure.
-:- type ml_table.
-
-	% This type is used in contexts where a node of a subgoal table is
-	% expected.
-:- type ml_subgoal_table_node.
-
-	% This type is used in contexts where a node of an answer table is
-	% expected.
-:- type ml_answer_table_node.
+	% This type represents the interior pointers of both call
+	% tables and ansswer tables.
+:- type ml_trie_node.
+
+	% This type represents the data structure at the tips of the call table
+	% in model_non predicates.
+:- type ml_subgoal.
 
-	% This type is used in contexts where an answer slot is expected.
-:- type ml_answer_slot.
-
-	% This type is used in contexts where an answer block is expected.
+	% This type represents a block of memory that contains one word
+	% for each output argument of a procedure.
 :- type ml_answer_block.
 
-	% These equivalences should be local to private_builtin. However,
-	% at the moment table_gen.m assumes that it can use a single variable
-	% sometimes as an ml_table and other times as an ml_subgoal_table_node
-	% (e.g. by giving the output of table_lookup_insert_int as input to
-	% table_have_all_ans). The proper fix would be for table_gen.m to
-	% use additional variables and insert unsafe casts. However, this
-	% would require significant work for no real gain, so for now
-	% we fix the problem by exposing the equivalences to code generated
-	% by table_gen.m.
-:- type ml_subgoal_table_node == ml_table.
-:- type ml_answer_table_node == ml_table.
-:- type ml_answer_slot == ml_table.
-:- type ml_answer_block == ml_table.
-:- type ml_table.
-
 :- implementation.
 
 % At the moment, tabling is supported only by the LLDS and MLDS C backends,
@@ -127,9 +102,20 @@
 % to make this module compile cleanly on the Java and .NET backends
 % respectively.
 
-:- type ml_table --->	ml_table(c_pointer).
-:- pragma foreign_type("C", ml_table, "MR_TrieNode").
-:- pragma foreign_type(il,  ml_table, "class [mscorlib]System.Object").
+	% This type represents a list of answers of a model_non predicate.
+:- type ml_answer_list.
+
+:- type ml_trie_node --->	ml_trie_node(c_pointer).
+:- pragma foreign_type("C", ml_trie_node, "MR_TrieNode").
+:- pragma foreign_type(il,  ml_trie_node, "class [mscorlib]System.Object").
+
+:- type ml_subgoal --->		ml_subgoal(c_pointer).
+:- pragma foreign_type("C", ml_subgoal, "MR_SubgoalPtr").
+:- pragma foreign_type(il,  ml_subgoal, "class [mscorlib]System.Object").
+
+:- type ml_answer_block --->	ml_answer_block(c_pointer).
+:- pragma foreign_type("C", ml_answer_block, "MR_AnswerBlock").
+:- pragma foreign_type(il,  ml_answer_block, "class [mscorlib]System.Object").
 
 :- type ml_answer_list --->	ml_answer_list(c_pointer).
 :- pragma foreign_type("C", ml_answer_list, "MR_AnswerList").
@@ -140,46 +126,46 @@
 :- interface.
 
 %
-% Predicates that manage the tabling of simple subgoals.
+% Predicates that manage the tabling of model_det and model_semi predicates.
 %
 
-	% Return true if the subgoal represented by the given table has an
+	% Return true if the call represented by the given table has an
 	% answer.
-:- semipure pred table_simple_is_complete(ml_subgoal_table_node::in)
+:- semipure pred table_simple_is_complete(ml_trie_node::in)
 	is semidet.
 
-	% Return true if the subgoal represented by the given table has a
+	% Return true if the call represented by the given table has a
 	% true answer.
-:- semipure pred table_simple_has_succeeded(ml_subgoal_table_node::in)
+:- semipure pred table_simple_has_succeeded(ml_trie_node::in)
 	is semidet.
 
-	% Return true if the subgoal represented by the given table has
+	% Return true if the call represented by the given table has
 	% failed.
-:- semipure pred table_simple_has_failed(ml_subgoal_table_node::in) is semidet.
+:- semipure pred table_simple_has_failed(ml_trie_node::in) is semidet.
 
-	% Return true if the subgoal represented by the given table is
+	% Return true if the call represented by the given table is
 	% currently being evaluated (working on an answer).
-:- semipure pred table_simple_is_active(ml_subgoal_table_node::in) is semidet.
+:- semipure pred table_simple_is_active(ml_trie_node::in) is semidet.
 
-	% Return false if the subgoal represented by the given table is
+	% Return false if the call represented by the given table is
 	% currently being evaluated (working on an answer).
-:- semipure pred table_simple_is_inactive(ml_subgoal_table_node::in)
+:- semipure pred table_simple_is_inactive(ml_trie_node::in)
 	is semidet.
 
-	% Save the fact the the subgoal has succeeded in the given table.
-:- impure pred table_simple_mark_as_succeeded(ml_subgoal_table_node::in)
+	% Save the fact the the call has succeeded in the given table.
+:- impure pred table_simple_mark_as_succeeded(ml_trie_node::in)
 	is det.
 
-	% Save the fact the the subgoal has failed in the given table.
-:- impure pred table_simple_mark_as_failed(ml_subgoal_table_node::in) is det.
+	% Save the fact the the call has failed in the given table.
+:- impure pred table_simple_mark_as_failed(ml_trie_node::in) is det.
 
-	% Mark the subgoal represented by the given table as currently
+	% Mark the call represented by the given table as currently
 	% being evaluated (working on an answer).
-:- impure pred table_simple_mark_as_active(ml_subgoal_table_node::in) is det.
+:- impure pred table_simple_mark_as_active(ml_trie_node::in) is det.
 
-	% Mark the subgoal represented by the given table as currently
+	% Mark the call represented by the given table as currently
 	% not being evaluated (working on an answer).
-:- impure pred table_simple_mark_as_inactive(ml_subgoal_table_node::in) is det.
+:- impure pred table_simple_mark_as_inactive(ml_trie_node::in) is det.
 
 	% N.B. interface continued below
 
@@ -406,6 +392,7 @@
 	% matching foreign_proc version.
 	impure private_builtin__imp,
 	private_builtin__sorry("table_simple_mark_as_inactive").
+
 %-----------------------------------------------------------------------------%
 
 :- interface.
@@ -430,7 +417,8 @@
 	% where Start is the I/O action number of the first tabled action.
 	% The three output parameters together specify this location.
 
-:- impure pred table_io_in_range(ml_table::out, int::out, int::out) is semidet.
+:- impure pred table_io_in_range(ml_trie_node::out, int::out, int::out)
+	is semidet.
 
 	% This procedure should be called exactly once for each I/O action
 	% for which table_io_in_range returns true. Given the trie node
@@ -438,7 +426,7 @@
 	% been carried out before (i.e. the action is now being reexecuted
 	% after a retry command in the debugger).
 
-:- impure pred table_io_has_occurred(ml_table::in) is semidet.
+:- impure pred table_io_has_occurred(ml_trie_node::in) is semidet.
 
 	% This predicate simply copies the input I/O state to become the output
 	% I/O state. It is used only because it is easier to get the insts
@@ -635,54 +623,52 @@
 	% Save the information that will be needed later about this
 	% nondet subgoal in a data structure. If we have already seen
 	% this subgoal before, do nothing.
-:- impure pred table_nondet_setup(ml_subgoal_table_node::in,
-	ml_subgoal_table_node::out) is det.
+:- impure pred table_nondet_setup(ml_trie_node::in, ml_subgoal::out) is det.
 
 	% Save the state of the current subgoal and fail. Sometime later,
 	% when the subgoal has some solutions, table_nondet_resume will
 	% restore the saved state. At the time, table_nondet_suspend will
 	% succeed, and return an answer block as its second argument.
-:- impure pred table_nondet_suspend(ml_subgoal_table_node::in,
+:- impure pred table_nondet_suspend(ml_subgoal::in,
 	ml_answer_block::out) is nondet.
 
 	% Resume all suspended subgoal calls. This predicate will resume each
 	% of the suspended subgoals that depend on it in turn until it reaches
 	% a fixed point, at which all depended suspended subgoals have had
 	% all available answers returned to them.
-:- impure pred table_nondet_resume(ml_subgoal_table_node::in) is det.
+:- impure pred table_nondet_resume(ml_subgoal::in) is det.
 
 	% Succeed if we have finished generating all answers for
 	% the given nondet subgoal.
-:- semipure pred table_nondet_is_complete(ml_subgoal_table_node::in)
-	is semidet.
+:- semipure pred table_nondet_is_complete(ml_subgoal::in) is semidet.
 
 	% Succeed if the given nondet subgoal is active,
 	% i.e. the process of computing all its answers is not yet complete.
-:- semipure pred table_nondet_is_active(ml_subgoal_table_node::in) is semidet.
+:- semipure pred table_nondet_is_active(ml_subgoal::in) is semidet.
 
 	% Mark a table as being active.
-:- impure pred table_nondet_mark_as_active(ml_subgoal_table_node::in) is det.
+:- impure pred table_nondet_mark_as_active(ml_subgoal::in) is det.
 
 	% Return the table of answers already returned to the given nondet
 	% table.
-:- impure pred table_nondet_get_ans_table(ml_subgoal_table_node::in,
-	ml_table::out) is det.
+:- impure pred table_nondet_get_ans_table(ml_subgoal::in, ml_trie_node::out)
+	is det.
 
 	% If the answer represented by the given answer table
 	% has not been generated before by this subgoal,
 	% succeed and remember the answer as having been generated.
 	% If the answer has been generated before, fail.
-:- impure pred table_nondet_answer_is_not_duplicate(ml_answer_table_node::in)
+:- impure pred table_nondet_answer_is_not_duplicate(ml_trie_node::in)
 	is semidet.
 
 	% Create a new slot in the answer list.
-:- impure pred table_nondet_new_ans_slot(ml_subgoal_table_node::in,
-	ml_answer_slot::out) is det.
+:- impure pred table_nondet_new_ans_slot(ml_subgoal::in, ml_trie_node::out)
+	is det.
 
 	% Return all of the answer blocks stored in the given table.
-:- semipure pred table_nondet_return_all_ans(ml_subgoal_table_node::in,
+:- semipure pred table_nondet_return_all_ans(ml_subgoal::in,
 	ml_answer_block::out) is nondet.
-:- semipure pred table_multi_return_all_ans(ml_subgoal_table_node::in,
+:- semipure pred table_multi_return_all_ans(ml_subgoal::in,
 	ml_answer_block::out) is multi.
 
 	% This type should correspond exactly to the type MR_SubgoalStatus
@@ -693,8 +679,8 @@
 	;	active
 	;	complete.
 
-:- semipure pred table_subgoal_status(ml_subgoal_table_node::in,
-	subgoal_status::out) is det.
+:- semipure pred table_subgoal_status(ml_subgoal::in, subgoal_status::out)
+	is det.
 
 	% N.B. interface continued below
 
@@ -703,7 +689,7 @@
 :- implementation.
 
 :- pragma foreign_proc("C",
-	table_nondet_setup(T0::in, T::out),
+	table_nondet_setup(T::in, Subgoal::out),
 	[will_not_call_mercury],
 "
 #ifndef	MR_USE_MINIMAL_MODEL
@@ -715,10 +701,6 @@
 #ifdef	MR_HIGHLEVEL_CODE
 #error ""Sorry, not yet implemented: minimal model tabling with high level code""
 #endif
-	MR_TrieNode	table;
-
-	table = T0;
-
 	/*
 	** Initialize the subgoal if this is the first time we see it.
 	** If the subgoal structure already exists but is marked inactive,
@@ -727,11 +709,12 @@
 	** In that case, we want to forget all about the old generator.
 	*/
 
-	if (table->MR_subgoal == NULL) {
+	if (T->MR_subgoal == NULL) {
 		MR_Subgoal	*subgoal;
 
 		subgoal = MR_TABLE_NEW(MR_Subgoal);
 
+		subgoal->MR_sg_back_ptr = T;
 		subgoal->MR_sg_status = MR_SUBGOAL_INACTIVE;
 		subgoal->MR_sg_leader = NULL;
 		subgoal->MR_sg_followers = MR_TABLE_NEW(MR_SubgoalListNode);
@@ -739,7 +722,7 @@
 		subgoal->MR_sg_followers->MR_sl_next = NULL;
 		subgoal->MR_sg_followers_tail =
 			&(subgoal->MR_sg_followers->MR_sl_next);
-		subgoal->MR_sg_answer_table = (MR_Word) NULL;
+		subgoal->MR_sg_answer_table.MR_integer = 0;
 		subgoal->MR_sg_num_ans = 0;
 		subgoal->MR_sg_answer_list = NULL;
 		subgoal->MR_sg_answer_list_tail =
@@ -768,7 +751,7 @@
 
 		if (MR_tabledebug) {
 			printf(""setting up subgoal %p -> %s, "",
-				table, MR_subgoal_addr_name(subgoal));
+				T, MR_subgoal_addr_name(subgoal));
 			printf(""answer slot %p\\n"",
 				subgoal->MR_sg_answer_list_tail);
 			if (subgoal->MR_sg_proc_layout != NULL) {
@@ -785,9 +768,9 @@
 		}
 #endif
 		subgoal->MR_sg_generator_fr = MR_curfr;
-		table->MR_subgoal = subgoal;
+		T->MR_subgoal = subgoal;
 	}
-	T = T0;
+	Subgoal = T->MR_subgoal;
 #endif /* MR_USE_MINIMAL_MODEL */
 ").
 
@@ -825,62 +808,46 @@
 */
 
 :- pragma foreign_proc("C",
-	table_nondet_is_complete(T::in), [will_not_call_mercury], "
+	table_nondet_is_complete(Subgoal::in),
+	[will_not_call_mercury],
+"
 #ifdef	MR_USE_MINIMAL_MODEL
-	MR_TrieNode	table;
-
-	table = T;
-
-	SUCCESS_INDICATOR =
-		(table->MR_subgoal->MR_sg_status == MR_SUBGOAL_COMPLETE);
+	SUCCESS_INDICATOR = (Subgoal->MR_sg_status == MR_SUBGOAL_COMPLETE);
 #else
 	MR_fatal_error(""minimal model code entered when not enabled"");
 #endif
 ").
 
 :- pragma foreign_proc("C",
-	table_nondet_is_active(T::in),
+	table_nondet_is_active(Subgoal::in),
 	[will_not_call_mercury],
 "
 #ifdef	MR_USE_MINIMAL_MODEL
-	MR_TrieNode	table;
-
-	table = T;
-
-	SUCCESS_INDICATOR =
-		(table->MR_subgoal->MR_sg_status == MR_SUBGOAL_ACTIVE);
+	SUCCESS_INDICATOR = (Subgoal->MR_sg_status == MR_SUBGOAL_ACTIVE);
 #else
 	MR_fatal_error(""minimal model code entered when not enabled"");
 #endif
 ").
 
 :- pragma foreign_proc("C",
-	table_nondet_mark_as_active(T::in),
+	table_nondet_mark_as_active(Subgoal::in),
 	[will_not_call_mercury],
 "
 #ifdef	MR_USE_MINIMAL_MODEL
-	MR_TrieNode	table;
-
-	table = T;
-
-	MR_push_generator(MR_curfr, table);
-	MR_register_generator_ptr(table);
-	table->MR_subgoal->MR_sg_status = MR_SUBGOAL_ACTIVE;
+	MR_push_generator(MR_curfr, Subgoal);
+	MR_register_generator_ptr(Subgoal);
+	Subgoal->MR_sg_status = MR_SUBGOAL_ACTIVE;
 #else
 	MR_fatal_error(""minimal model code entered when not enabled"");
 #endif
 ").
 
 :- pragma foreign_proc("C",
-	table_nondet_get_ans_table(T::in, AT::out),
+	table_nondet_get_ans_table(Subgoal::in, AT::out),
 	[will_not_call_mercury],
 "
 #ifdef	MR_USE_MINIMAL_MODEL
-	MR_TrieNode	table;
-
-	table = T;
-
-	AT = (MR_TrieNode) &(table->MR_subgoal->MR_sg_answer_table);
+	AT = &(Subgoal->MR_sg_answer_table);
 #else
 	MR_fatal_error(""minimal model code entered when not enabled"");
 #endif
@@ -893,38 +860,31 @@
 #ifndef	MR_USE_MINIMAL_MODEL
 	MR_fatal_error(""minimal model code entered when not enabled"");
 #else
-	MR_TrieNode	table;
 	MR_bool		is_new_answer;
 
-	table = T;
-
 #ifdef	MR_TABLE_DEBUG
 	if (MR_tabledebug) {
 		printf(""checking if %p is a duplicate answer: %ld\\n"",
-			table, (long) table->MR_integer);
+			T, (long) T->MR_integer);
 	}
 #endif
 
-	is_new_answer = (table->MR_integer == 0);
-	table->MR_integer = 1;	/* any nonzero value will do */
+	is_new_answer = (T->MR_integer == 0);
+	T->MR_integer = 1;	/* any nonzero value will do */
 	SUCCESS_INDICATOR = is_new_answer;
 #endif
 ").
 
 :- pragma foreign_proc("C",
-	table_nondet_new_ans_slot(T::in, Slot::out),
+	table_nondet_new_ans_slot(Subgoal::in, Slot::out),
 	[will_not_call_mercury],
 "
 #ifndef	MR_USE_MINIMAL_MODEL
 	MR_fatal_error(""minimal model code entered when not enabled"");
 #else
-	MR_TrieNode		table;
-	MR_Subgoal		*subgoal;
 	MR_AnswerListNode	*answer_node;
 
-	table = T;
-	subgoal = table->MR_subgoal;
-	subgoal->MR_sg_num_ans++;
+	Subgoal->MR_sg_num_ans++;
 
 	/*
 	**
@@ -934,25 +894,25 @@
 	*/
 
 	answer_node = MR_TABLE_NEW(MR_AnswerListNode);
-	answer_node->MR_aln_answer_num = subgoal->MR_sg_num_ans;
+	answer_node->MR_aln_answer_num = Subgoal->MR_sg_num_ans;
 	answer_node->MR_aln_answer_data.MR_integer = 0;
 	answer_node->MR_aln_next_answer = NULL;
 
 #ifdef	MR_TABLE_DEBUG
 	if (MR_tabledebug) {
-		printf(""%s: new answer slot %d at %p(%p)\n"",
-			MR_subgoal_addr_name(subgoal),
-			subgoal->MR_sg_num_ans, answer_node,
+		printf(""%s: new answer slot %d at %p(%p)\\n"",
+			MR_subgoal_addr_name(Subgoal),
+			Subgoal->MR_sg_num_ans, answer_node,
 			&answer_node->MR_aln_answer_data);
 		printf(""\tstoring into %p\\n"",
-			subgoal->MR_sg_answer_list_tail);
+			Subgoal->MR_sg_answer_list_tail);
 	}
 #endif
 
-	*(subgoal->MR_sg_answer_list_tail) = answer_node;
-	subgoal->MR_sg_answer_list_tail = &(answer_node->MR_aln_next_answer);
+	*(Subgoal->MR_sg_answer_list_tail) = answer_node;
+	Subgoal->MR_sg_answer_list_tail = &(answer_node->MR_aln_next_answer);
 
-	Slot = (MR_TrieNode) &(answer_node->MR_aln_answer_data);
+	Slot = &(answer_node->MR_aln_answer_data);
 #endif
 ").
 
@@ -984,23 +944,21 @@
 		semipure table_nondet_return_all_ans_2(CurNode1, Answer)
 	).
 
-:- semipure pred pickup_answer_list(ml_subgoal_table_node::in,
-	ml_answer_list::out) is det.
+:- semipure pred pickup_answer_list(ml_subgoal::in, ml_answer_list::out)
+	is det.
 
 :- pragma foreign_proc("C",
-	pickup_answer_list(T::in, CurNode::out),
+	pickup_answer_list(Subgoal::in, CurNode::out),
 	[will_not_call_mercury],
 "
 #ifdef MR_USE_MINIMAL_MODEL
-	MR_TrieNode	table;
-
-	table = T;
-	CurNode = table->MR_subgoal->MR_sg_answer_list;
+	CurNode = Subgoal->MR_sg_answer_list;
 
   #ifdef MR_TABLE_DEBUG
 	if (MR_tabledebug) {
-		printf(""restoring all answers in %p -> %s\\n"",
-			table, MR_subgoal_addr_name(table->MR_subgoal));
+		printf(""picking up all answers in %p -> %s\\n"",
+			Subgoal->MR_sg_back_ptr,
+			MR_subgoal_addr_name(Subgoal));
 	}
   #endif
 #else
@@ -1019,7 +977,7 @@
 	if (CurNode0 == NULL) {
 		SUCCESS_INDICATOR = MR_FALSE;
 	} else {
-		AnswerBlock = &CurNode0->MR_aln_answer_data;
+		AnswerBlock = CurNode0->MR_aln_answer_data.MR_answerblock;
 		CurNode = CurNode0->MR_aln_next_answer;
 		SUCCESS_INDICATOR = MR_TRUE;
 	}
@@ -1029,11 +987,11 @@
 ").
 
 :- pragma foreign_proc("C",
-	table_subgoal_status(T::in, Status::out),
+	table_subgoal_status(Subgoal::in, Status::out),
 	[will_not_call_mercury],
 "
 #ifdef MR_USE_MINIMAL_MODEL
-	Status = MR_CONVERT_C_ENUM_CONSTANT(T->MR_subgoal->MR_sg_status);
+	Status = MR_CONVERT_C_ENUM_CONSTANT(Subgoal->MR_sg_status);
 #else
 	MR_fatal_error(""minimal model code entered when not enabled"");
 #endif
@@ -1115,36 +1073,36 @@
 %
 
 	% Lookup or insert an integer in the given table.
-:- impure pred table_lookup_insert_int(ml_table::in, int::in, ml_table::out)
-	is det.
+:- impure pred table_lookup_insert_int(ml_trie_node::in, int::in,
+	ml_trie_node::out) is det.
 
 	% Lookup or insert an integer in the given table.
-:- impure pred table_lookup_insert_start_int(ml_table::in, int::in, int::in,
-	ml_table::out) is det.
+:- impure pred table_lookup_insert_start_int(ml_trie_node::in, int::in,
+	int::in, ml_trie_node::out) is det.
 
 	% Lookup or insert a character in the given trie.
-:- impure pred table_lookup_insert_char(ml_table::in, character::in,
-	ml_table::out) is det.
+:- impure pred table_lookup_insert_char(ml_trie_node::in, character::in,
+	ml_trie_node::out) is det.
 
 	% Lookup or insert a string in the given trie.
-:- impure pred table_lookup_insert_string(ml_table::in, string::in,
-	ml_table::out) is det.
+:- impure pred table_lookup_insert_string(ml_trie_node::in, string::in,
+	ml_trie_node::out) is det.
 
 	% Lookup or insert a float in the current trie.
-:- impure pred table_lookup_insert_float(ml_table::in, float::in,
-	ml_table::out) is det.
+:- impure pred table_lookup_insert_float(ml_trie_node::in, float::in,
+	ml_trie_node::out) is det.
 
 	% Lookup or inert an enumeration type in the given trie.
-:- impure pred table_lookup_insert_enum(ml_table::in, int::in, T::in,
-	ml_table::out) is det.
+:- impure pred table_lookup_insert_enum(ml_trie_node::in, int::in, T::in,
+	ml_trie_node::out) is det.
 
 	% Lookup or insert a monomorphic user defined type in the given trie.
-:- impure pred table_lookup_insert_user(ml_table::in, T::in, ml_table::out)
-	is det.
+:- impure pred table_lookup_insert_user(ml_trie_node::in, T::in,
+	ml_trie_node::out) is det.
 
 	% Lookup or insert a polymorphic user defined type in the given trie.
-:- impure pred table_lookup_insert_poly(ml_table::in, T::in, ml_table::out)
-	is det.
+:- impure pred table_lookup_insert_poly(ml_trie_node::in, T::in,
+	ml_trie_node::out) is det.
 
 	% Save an integer answer in the given answer block at the given
 	% offset.
@@ -1208,7 +1166,7 @@
 
 	% Create an answer block with the given number of slots and add it
 	% to the given table.
-:- impure pred table_create_ans_block(ml_subgoal_table_node::in, int::in,
+:- impure pred table_create_ans_block(ml_trie_node::in, int::in,
 	ml_answer_block::out) is det.
 
 	% Report statistics on the operation of the tabling system to stderr.
@@ -1240,8 +1198,7 @@
 	table_lookup_insert_start_int(T0::in, S::in, I::in, T::out),
 	[will_not_call_mercury],
 "
-	MR_DEBUG_NEW_TABLE_START_INT(T, T0,
-		(MR_Integer) S, (MR_Integer) I);
+	MR_DEBUG_NEW_TABLE_START_INT(T, T0, (MR_Integer) S, (MR_Integer) I);
 ").
 
 :- pragma foreign_proc("C",
@@ -1287,109 +1244,109 @@
 ").
 
 :- pragma foreign_proc("C",
-	table_save_int_ans(T::in, Offset::in, I::in),
+	table_save_int_ans(AB::in, Offset::in, I::in),
 	[will_not_call_mercury],
 "
-	MR_TABLE_SAVE_ANSWER(T, Offset, I,
+	MR_TABLE_SAVE_ANSWER(AB, Offset, I,
 		&MR_TYPE_CTOR_INFO_NAME(builtin, int, 0));
 ").
 
 :- pragma foreign_proc("C",
-	table_save_char_ans(T::in, Offset::in, C::in),
+	table_save_char_ans(AB::in, Offset::in, C::in),
 	[will_not_call_mercury],
 "
-	MR_TABLE_SAVE_ANSWER(T, Offset, C,
+	MR_TABLE_SAVE_ANSWER(AB, Offset, C,
 		&MR_TYPE_CTOR_INFO_NAME(builtin, character, 0));
 ").
 
 :- pragma foreign_proc("C",
-	table_save_string_ans(T::in, Offset::in, S::in),
+	table_save_string_ans(AB::in, Offset::in, S::in),
 	[will_not_call_mercury],
 "
-	MR_TABLE_SAVE_ANSWER(T, Offset, (MR_Word) S,
+	MR_TABLE_SAVE_ANSWER(AB, Offset, (MR_Word) S,
 		&MR_TYPE_CTOR_INFO_NAME(builtin, string, 0));
 ").
 
 :- pragma foreign_proc("C",
-	table_save_float_ans(T::in, Offset::in, F::in),
+	table_save_float_ans(AB::in, Offset::in, F::in),
 	[will_not_call_mercury],
 "
 #ifdef MR_HIGHLEVEL_CODE
-	MR_TABLE_SAVE_ANSWER(T, Offset, (MR_Word) MR_box_float(F),
+	MR_TABLE_SAVE_ANSWER(AB, Offset, (MR_Word) MR_box_float(F),
 		&MR_TYPE_CTOR_INFO_NAME(builtin, float, 0));
 #else
-	MR_TABLE_SAVE_ANSWER(T, Offset, MR_float_to_word(F),
+	MR_TABLE_SAVE_ANSWER(AB, Offset, MR_float_to_word(F),
 		&MR_TYPE_CTOR_INFO_NAME(builtin, float, 0));
 #endif
 ").
 
 :- pragma foreign_proc("C",
-	table_save_io_state_ans(T::in, Offset::in, S::ui),
+	table_save_io_state_ans(AB::in, Offset::in, S::ui),
 	[will_not_call_mercury],
 "
-	MR_TABLE_SAVE_ANSWER(T, Offset, (MR_Word) S,
+	MR_TABLE_SAVE_ANSWER(AB, Offset, (MR_Word) S,
 		&MR_TYPE_CTOR_INFO_NAME(io, state, 0));
 ").
 
 :- pragma foreign_proc("C", 
-	table_save_any_ans(T::in, Offset::in, V::in),
+	table_save_any_ans(AB::in, Offset::in, V::in),
 	[will_not_call_mercury],
 "
-	MR_TABLE_SAVE_ANSWER(T, Offset, V, TypeInfo_for_T);
+	MR_TABLE_SAVE_ANSWER(AB, Offset, V, TypeInfo_for_T);
 ").
 
 :- pragma foreign_proc("C",
-	table_restore_int_ans(T::in, Offset::in, I::out),
+	table_restore_int_ans(AB::in, Offset::in, I::out),
 	[will_not_call_mercury, promise_semipure],
 "
-	I = (MR_Integer) MR_TABLE_GET_ANSWER(T, Offset);
+	I = (MR_Integer) MR_TABLE_GET_ANSWER(AB, Offset);
 ").
 
 :- pragma foreign_proc("C",
-	table_restore_char_ans(T::in, Offset::in, C::out),
+	table_restore_char_ans(AB::in, Offset::in, C::out),
 	[will_not_call_mercury, promise_semipure],
 "
-	C = (MR_Char) MR_TABLE_GET_ANSWER(T, Offset);
+	C = (MR_Char) MR_TABLE_GET_ANSWER(AB, Offset);
 ").
 
 :- pragma foreign_proc("C",
-	table_restore_string_ans(T::in, Offset::in, S::out),
+	table_restore_string_ans(AB::in, Offset::in, S::out),
 	[will_not_call_mercury, promise_semipure],
 "
-	S = (MR_String) MR_TABLE_GET_ANSWER(T, Offset);
+	S = (MR_String) MR_TABLE_GET_ANSWER(AB, Offset);
 ").
 
 :- pragma foreign_proc("C",
-	table_restore_float_ans(T::in, Offset::in, F::out),
+	table_restore_float_ans(AB::in, Offset::in, F::out),
 	[will_not_call_mercury, promise_semipure],
 "
 #ifdef MR_HIGHLEVEL_CODE
-	F = MR_unbox_float(MR_TABLE_GET_ANSWER(T, Offset));
+	F = MR_unbox_float(MR_TABLE_GET_ANSWER(AB, Offset));
 #else
-	F = MR_word_to_float(MR_TABLE_GET_ANSWER(T, Offset));
+	F = MR_word_to_float(MR_TABLE_GET_ANSWER(AB, Offset));
 #endif
 ").
 
 :- pragma foreign_proc("C",
-	table_restore_io_state_ans(T::in, Offset::in, V::uo),
+	table_restore_io_state_ans(AB::in, Offset::in, V::uo),
 	[will_not_call_mercury, promise_semipure],
 "
-	V = (MR_Word) MR_TABLE_GET_ANSWER(T, Offset);
+	V = (MR_Word) MR_TABLE_GET_ANSWER(AB, Offset);
 ").
 
 :- pragma foreign_proc("C",
-	table_restore_any_ans(T::in, Offset::in, V::out),
+	table_restore_any_ans(AB::in, Offset::in, V::out),
 	[will_not_call_mercury, promise_semipure],
 "
-	V = (MR_Word) MR_TABLE_GET_ANSWER(T, Offset);
+	V = (MR_Word) MR_TABLE_GET_ANSWER(AB, Offset);
 ").
 
 :- pragma foreign_proc("C",
-	table_create_ans_block(T0::in, Size::in, T::out),
+	table_create_ans_block(T::in, Size::in, AB::out),
 	[will_not_call_mercury],
 "
-	MR_TABLE_CREATE_ANSWER_BLOCK(T0, Size);
-	T = T0;
+	MR_TABLE_CREATE_ANSWER_BLOCK(T, Size);
+	AB = T->MR_answerblock;
 ").
 
 table_loopcheck_error(Message) :-
cvs diff: Diffing profiler
cvs diff: Diffing robdd
cvs diff: Diffing runtime
Index: runtime/mercury_deconstruct.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_deconstruct.c,v
retrieving revision 1.12
diff -u -r1.12 mercury_deconstruct.c
--- runtime/mercury_deconstruct.c	17 Jan 2003 05:56:50 -0000	1.12
+++ runtime/mercury_deconstruct.c	30 Apr 2003 18:17:08 -0000
@@ -18,6 +18,7 @@
 #include "mercury_deconstruct.h"
 #include "mercury_deconstruct_macros.h"
 #include "mercury_type_desc.h"
+#include "mercury_minimal_model.h"
 
 static  MR_ConstString  MR_expand_type_name(MR_TypeCtorInfo tci, MR_bool);
 
Index: runtime/mercury_minimal_model.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_minimal_model.c,v
retrieving revision 1.1
diff -u -r1.1 mercury_minimal_model.c
--- runtime/mercury_minimal_model.c	18 Mar 2003 16:38:10 -0000	1.1
+++ runtime/mercury_minimal_model.c	30 Apr 2003 12:27:59 -0000
@@ -528,7 +528,7 @@
     }
 
     if (MR_tablestackdebug) {
-        MR_dump_nondet_stack(stdout, MR_maxfr);
+        MR_dump_nondet_stack(stdout, 0, MR_maxfr);
     }
   #endif /* MR_TABLE_DEBUG */
 
@@ -579,7 +579,7 @@
     }
 
     if (MR_tablestackdebug) {
-        MR_dump_nondet_stack_from_layout(stdout, MR_maxfr, NULL,
+        MR_dump_nondet_stack_from_layout(stdout, 0, MR_maxfr, NULL,
             MR_sp, MR_curfr);
     }
   #endif /* MR_TABLE_DEBUG */
@@ -1090,10 +1090,8 @@
         }
 #endif
 
-        if (fr == MR_gen_stack[cur_gen].MR_generator_frame) {
-            if (MR_gen_stack[cur_gen].MR_generator_table->MR_subgoal
-                == subgoal)
-            {
+        if (fr == MR_gen_stack[cur_gen].MR_gen_frame) {
+            if (MR_gen_stack[cur_gen].MR_gen_subgoal == subgoal) {
                 /*
                 ** This is the nondet stack frame of the
                 ** generator corresponding to this consumer.
@@ -1134,7 +1132,7 @@
 
                 MR_save_transient_registers();
                 make_subgoal_follow_leader(MR_gen_stack[cur_gen].
-                    MR_generator_table->MR_subgoal, subgoal);
+                    MR_gen_subgoal, subgoal);
                 MR_restore_transient_registers();
             }
 
Index: runtime/mercury_minimal_model.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_minimal_model.h,v
retrieving revision 1.2
diff -u -r1.2 mercury_minimal_model.h
--- runtime/mercury_minimal_model.h	1 Apr 2003 08:54:13 -0000	1.2
+++ runtime/mercury_minimal_model.h	30 Apr 2003 18:22:19 -0000
@@ -160,12 +160,13 @@
 */
 
 struct MR_Subgoal_Struct {
+	MR_TrieNode		MR_sg_back_ptr;
 	MR_SubgoalStatus	MR_sg_status;
 	MR_Subgoal		*MR_sg_leader;
 	MR_SubgoalList		MR_sg_followers;
 	MR_SubgoalList		*MR_sg_followers_tail;
 	MR_ResumeInfo		*MR_sg_resume_info;
-	MR_Word			MR_sg_answer_table;
+	MR_TableNode		MR_sg_answer_table;
 	MR_Integer		MR_sg_num_ans;
 	MR_Integer		MR_sg_num_committed_ans;
 	MR_AnswerList		MR_sg_answer_list;
@@ -180,6 +181,8 @@
 
 /*---------------------------------------------------------------------------*/
 
+#ifdef	MR_USE_MINIMAL_MODEL
+
 extern	const MR_Proc_Layout	*MR_subgoal_debug_cur_proc;
 
 extern	void		MR_enter_consumer_debug(MR_Consumer *consumer);
@@ -208,6 +211,7 @@
 extern	void		MR_print_consumer(FILE *fp, const MR_Proc_Layout *proc,
 				MR_Consumer *consumer);
 
+#endif	/* MR_USE_MINIMAL_MODEL */
 
 #ifndef	MR_HIGHLEVEL_CODE
 
Index: runtime/mercury_ml_expand_body.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_ml_expand_body.h,v
retrieving revision 1.25
diff -u -r1.25 mercury_ml_expand_body.h
--- runtime/mercury_ml_expand_body.h	21 Mar 2003 08:00:30 -0000	1.25
+++ runtime/mercury_ml_expand_body.h	30 Apr 2003 19:05:59 -0000
@@ -1148,7 +1148,19 @@
             break;
 
         case MR_TYPECTOR_REP_FOREIGN:
+#ifdef  MR_USE_MINIMAL_MODEL
+            if (MR_streq(type_ctor_info->MR_type_ctor_name, "subgoal") &&
+                MR_streq(type_ctor_info->MR_type_ctor_module_name,
+                    "table_builtin") &&
+                (noncanon == MR_NONCANON_CC))
+            {
+                handle_functor_name(MR_subgoal_addr_name(*data_word_ptr));
+            } else {
+                handle_functor_name("<<foreign>>");
+            }
+#else
             handle_functor_name("<<foreign>>");
+#endif
             handle_zero_arity_args();
             break;
 
Index: runtime/mercury_stacks.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_stacks.c,v
retrieving revision 1.9
diff -u -r1.9 mercury_stacks.c
--- runtime/mercury_stacks.c	18 Mar 2003 16:38:11 -0000	1.9
+++ runtime/mercury_stacks.c	30 Apr 2003 12:26:18 -0000
@@ -121,7 +121,7 @@
 static	void	MR_print_gen_stack_entry(FILE *fp, MR_Integer i,
 			MR_GenStackFrame *p);
 
-static	void	MR_cleanup_generator_ptr(MR_TrieNode generator_ptr);
+static	void	MR_cleanup_generator_ptr(MR_SubgoalPtr generator_ptr);
 static	void	MR_print_cut_stack_entry(FILE *fp, MR_Integer i,
 			MR_CutStackFrame *p);
 
@@ -132,10 +132,10 @@
 /***************************************************************************/
 
 void
-MR_push_generator(MR_Word *frame_addr, MR_TrieNode table_addr)
+MR_push_generator(MR_Word *frame_addr, MR_SubgoalPtr subgoal)
 {
-	MR_gen_stack[MR_gen_next].MR_generator_frame = frame_addr;
-	MR_gen_stack[MR_gen_next].MR_generator_table = table_addr;
+	MR_gen_stack[MR_gen_next].MR_gen_frame = frame_addr;
+	MR_gen_stack[MR_gen_next].MR_gen_subgoal = subgoal;
 	MR_gen_next++;
 
 #ifdef	MR_TABLE_DEBUG
@@ -158,7 +158,7 @@
 	}
 #endif
 
-	return MR_gen_stack[MR_gen_next - 1].MR_generator_table->MR_subgoal;
+	return MR_gen_stack[MR_gen_next - 1].MR_gen_subgoal;
 }
 
 void
@@ -199,9 +199,8 @@
 	MR_SubgoalDebug	*subgoal_debug;
 
 	fprintf(fp, "gen %ld = <", (long) i);
-	MR_print_nondstackptr(fp, p->MR_generator_frame);
-	subgoal_debug = MR_lookup_subgoal_debug_addr(
-		p->MR_generator_table->MR_subgoal);
+	MR_print_nondstackptr(fp, p->MR_gen_frame);
+	subgoal_debug = MR_lookup_subgoal_debug_addr(p->MR_gen_subgoal);
 	fprintf(fp, ", %s>\n", MR_subgoal_debug_name(subgoal_debug));
 }
 
@@ -272,7 +271,7 @@
 }
 
 void
-MR_register_generator_ptr(MR_TrieNode generator_ptr)
+MR_register_generator_ptr(MR_SubgoalPtr subgoal)
 {
 	struct MR_CutGeneratorListNode	*node;
 
@@ -281,7 +280,7 @@
 	}
 
 	node = MR_GC_NEW(struct MR_CutGeneratorListNode);
-	node->MR_cut_generator_ptr = generator_ptr;
+	node->MR_cut_generator_ptr = subgoal;
 	node->MR_cut_next_generator =
 		MR_cut_stack[MR_cut_next - 1].MR_cut_generators;
 	MR_cut_stack[MR_cut_next - 1].MR_cut_generators = node;
@@ -290,23 +289,22 @@
 	if (MR_tabledebug) {
 		printf("registering generator %p -> %s "
 			"at commit stack level %d\n",
-			generator_ptr,
-			MR_subgoal_addr_name(generator_ptr->MR_subgoal),
+			subgoal, MR_subgoal_addr_name(subgoal),
 			MR_cut_next - 1);
 	}
 #endif
 }
 
 static void
-MR_cleanup_generator_ptr(MR_TrieNode generator_ptr)
+MR_cleanup_generator_ptr(MR_SubgoalPtr subgoal)
 {
-	if (generator_ptr->MR_subgoal->MR_sg_status == MR_SUBGOAL_COMPLETE) {
+	if (subgoal->MR_sg_status == MR_SUBGOAL_COMPLETE) {
 		/* there is nothing to do, everything is OK */
 #ifdef	MR_TABLE_DEBUG
 		if (MR_tabledebug) {
 			printf("no cleanup: generator %p -> %s is complete\n",
-				generator_ptr, MR_subgoal_addr_name(
-					generator_ptr->MR_subgoal));
+				subgoal->MR_sg_back_ptr,
+				MR_subgoal_addr_name(subgoal));
 		}
 #endif
 	} else {
@@ -314,12 +312,12 @@
 #ifdef	MR_TABLE_DEBUG
 		if (MR_tabledebug) {
 			printf("cleanup: generator %p -> %s deleted\n",
-				generator_ptr, MR_subgoal_addr_name(
-					generator_ptr->MR_subgoal));
+				subgoal->MR_sg_back_ptr,
+				MR_subgoal_addr_name(subgoal));
 		}
 #endif
 
-		generator_ptr->MR_subgoal = NULL;
+		subgoal->MR_sg_back_ptr->MR_subgoal = NULL;
 	}
 }
 
@@ -357,7 +355,7 @@
 			fprintf(fp, " <NULL>");
 		} else {
 			subgoal_debug = MR_lookup_subgoal_debug_addr(
-				gen_list->MR_cut_generator_ptr->MR_subgoal);
+				gen_list->MR_cut_generator_ptr);
 			fprintf(fp, " <%s>",
 				MR_subgoal_debug_name(subgoal_debug));
 		}
@@ -371,7 +369,7 @@
 /***************************************************************************/
 
 void
-MR_register_suspension(MR_Subgoal *subgoal)
+MR_register_suspension(MR_SubgoalPtr subgoal)
 {
 	MR_PNegConsumerList	node_ptr;
 
Index: runtime/mercury_stacks.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_stacks.h,v
retrieving revision 1.38
diff -u -r1.38 mercury_stacks.h
--- runtime/mercury_stacks.h	18 Mar 2003 16:38:12 -0000	1.38
+++ runtime/mercury_stacks.h	30 Apr 2003 12:25:35 -0000
@@ -463,12 +463,12 @@
 /* DEFINITIONS FOR GENERATOR STACK FRAMES */
 
 struct MR_GenStackFrameStruct {
-	MR_Word			*MR_generator_frame;
-	MR_TrieNode		MR_generator_table;
+	MR_Word			*MR_gen_frame;
+	MR_SubgoalPtr		MR_gen_subgoal;
 };
 
 extern	void			MR_push_generator(MR_Word *frame_addr,
-					MR_TrieNode table_addr);
+					MR_SubgoalPtr subgoal);
 extern	MR_Subgoal		*MR_top_generator_table(void);
 extern	void			MR_pop_generator(void);
 extern	void			MR_print_gen_stack(FILE *fp);
@@ -480,7 +480,7 @@
 
 typedef struct MR_CutGeneratorListNode *MR_CutGeneratorList;
 struct MR_CutGeneratorListNode {
-	MR_TrieNode		MR_cut_generator_ptr;
+	MR_SubgoalPtr		MR_cut_generator_ptr;
 	MR_CutGeneratorList	MR_cut_next_generator;
 };
 
@@ -494,7 +494,7 @@
 extern	void			MR_commit_mark(void);
 extern	void			MR_commit_cut(void);
 
-extern	void			MR_register_generator_ptr(MR_TrieNode);
+extern	void			MR_register_generator_ptr(MR_SubgoalPtr);
 extern	void			MR_print_cut_stack(FILE *fp);
 extern	void			MR_print_any_cut_stack(FILE *fp,
 					MR_Integer cut_next,
Index: runtime/mercury_tabling.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_tabling.h,v
retrieving revision 1.30
diff -u -r1.30 mercury_tabling.h
--- runtime/mercury_tabling.h	18 Mar 2003 16:38:12 -0000	1.30
+++ runtime/mercury_tabling.h	15 Apr 2003 04:00:42 -0000
@@ -113,6 +113,9 @@
 ** MR_type_table field.
 */
 
+typedef	MR_Word		*MR_AnswerBlock;
+typedef	MR_Subgoal	*MR_SubgoalPtr;
+
 union MR_TableNode_Union {
 	MR_Integer	MR_integer;
 	MR_HashTable	*MR_hash_table;
@@ -120,7 +123,7 @@
 	MR_TableNode	*MR_start_table;
 	MR_Unsigned	MR_simpletable_status;
 	MR_Subgoal	*MR_subgoal;
-	MR_Word		*MR_answerblock;
+	MR_AnswerBlock	MR_answerblock;
 	MR_Dlist	*MR_type_table;
 };
 
Index: runtime/mercury_tabling_macros.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_tabling_macros.h,v
retrieving revision 1.8
diff -u -r1.8 mercury_tabling_macros.h
--- runtime/mercury_tabling_macros.h	20 Feb 2002 03:14:43 -0000	1.8
+++ runtime/mercury_tabling_macros.h	30 Apr 2003 12:08:15 -0000
@@ -371,25 +371,22 @@
 				(int) (num_slots));			\
 	} while(0)
 
-#define MR_TABLE_GET_ANSWER(table, offset)				\
+#define MR_TABLE_GET_ANSWER(ab, offset)					\
 	(( MR_tabledebug ?						\
-		printf("using answer block: %p -> %p, slot %d\n",	\
-			(table), (table)->MR_answerblock,		\
-			(int) (offset))					\
+		printf("using answer block: -> %p, slot %d\n",		\
+			(ab), (int) (offset))				\
 	:								\
 		(void) 0 /* do nothing */				\
 	),								\
-	((table)->MR_answerblock)[(offset)])
+	(ab)[(offset)])
 
-#define MR_TABLE_SAVE_ANSWER(table, offset, value, type_info)		\
+#define MR_TABLE_SAVE_ANSWER(ab, offset, value, type_info)		\
 	do {								\
 		if (MR_tabledebug)					\
-			printf("saving to answer block: %p -> %p, "	\
+			printf("saving to answer block: %p, "		\
 				"slot %d = %lx\n",			\
-				(table), (table)->MR_answerblock,	\
-				(int) (offset), (long) (value));	\
-		(table)->MR_answerblock[offset] =			\
-			MR_make_permanent((value),			\
+				(ab), (int) (offset), (long) (value));	\
+		(ab)[offset] =	MR_make_permanent((value),		\
 					(MR_TypeInfo) (type_info));	\
 	} while(0)
 
@@ -398,17 +395,16 @@
 #define MR_TABLE_CREATE_ANSWER_BLOCK(table, num_slots)	 		\
 	do {								\
 		(table)->MR_answerblock = MR_TABLE_NEW_ARRAY(MR_Word,	\
-						(num_slots));		\
+			(num_slots));					\
 	} while(0)
 
-#define MR_TABLE_GET_ANSWER(table, offset)				\
-	((table)->MR_answerblock)[(offset)]
+#define MR_TABLE_GET_ANSWER(ab, offset)					\
+	(ab)[(offset)]
 
-#define MR_TABLE_SAVE_ANSWER(table, offset, value, type_info)		\
+#define MR_TABLE_SAVE_ANSWER(ab, offset, value, type_info)		\
 	do {								\
-		(table)->MR_answerblock[offset] =			\
-			MR_make_permanent((value),			\
-					(MR_TypeInfo) (type_info));	\
+		(ab)[offset] = MR_make_permanent((value),		\
+			(MR_TypeInfo) (type_info));			\
 	} while(0)
 
 #endif
cvs diff: Diffing runtime/GETOPT
cvs diff: Diffing runtime/machdeps
cvs diff: Diffing samples
cvs diff: Diffing samples/c_interface
cvs diff: Diffing samples/c_interface/c_calls_mercury
cvs diff: Diffing samples/c_interface/cplusplus_calls_mercury
cvs diff: Diffing samples/c_interface/mercury_calls_c
cvs diff: Diffing samples/c_interface/mercury_calls_cplusplus
cvs diff: Diffing samples/c_interface/mercury_calls_fortran
cvs diff: Diffing samples/c_interface/simpler_c_calls_mercury
cvs diff: Diffing samples/c_interface/simpler_cplusplus_calls_mercury
cvs diff: Diffing samples/diff
cvs diff: Diffing samples/muz
cvs diff: Diffing samples/rot13
cvs diff: Diffing samples/solutions
cvs diff: Diffing samples/tests
cvs diff: Diffing samples/tests/c_interface
cvs diff: Diffing samples/tests/c_interface/c_calls_mercury
cvs diff: Diffing samples/tests/c_interface/cplusplus_calls_mercury
cvs diff: Diffing samples/tests/c_interface/mercury_calls_c
cvs diff: Diffing samples/tests/c_interface/mercury_calls_cplusplus
cvs diff: Diffing samples/tests/c_interface/mercury_calls_fortran
cvs diff: Diffing samples/tests/c_interface/simpler_c_calls_mercury
cvs diff: Diffing samples/tests/c_interface/simpler_cplusplus_calls_mercury
cvs diff: Diffing samples/tests/diff
cvs diff: Diffing samples/tests/muz
cvs diff: Diffing samples/tests/rot13
cvs diff: Diffing samples/tests/solutions
cvs diff: Diffing samples/tests/toplevel
cvs diff: Diffing scripts
cvs diff: Diffing tests
cvs diff: Diffing tests/benchmarks
cvs diff: Diffing tests/debugger
cvs diff: Diffing tests/debugger/declarative
cvs diff: Diffing tests/dppd
cvs diff: Diffing tests/general
cvs diff: Diffing tests/general/accumulator
cvs diff: Diffing tests/general/string_format
cvs diff: Diffing tests/general/structure_reuse
cvs diff: Diffing tests/grade_subdirs
cvs diff: Diffing tests/hard_coded
cvs diff: Diffing tests/hard_coded/exceptions
cvs diff: Diffing tests/hard_coded/purity
cvs diff: Diffing tests/hard_coded/sub-modules
cvs diff: Diffing tests/hard_coded/typeclasses
cvs diff: Diffing tests/invalid
cvs diff: Diffing tests/invalid/purity
cvs diff: Diffing tests/misc_tests
cvs diff: Diffing tests/mmc_make
cvs diff: Diffing tests/mmc_make/lib
cvs diff: Diffing tests/recompilation
cvs diff: Diffing tests/tabling
cvs diff: Diffing tests/term
cvs diff: Diffing tests/valid
cvs diff: Diffing tests/warnings
cvs diff: Diffing tools
cvs diff: Diffing trace
Index: trace/mercury_trace.c
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace.c,v
retrieving revision 1.60
diff -u -r1.60 mercury_trace.c
--- trace/mercury_trace.c	18 Mar 2003 16:39:01 -0000	1.60
+++ trace/mercury_trace.c	30 Apr 2003 17:04:40 -0000
@@ -1267,7 +1267,7 @@
         record_ptrs[record_ptr_next].found_leader_generator = MR_FALSE;
         record_ptr_next++;
 
-        if (cur_maxfr == MR_gen_stack[cur_gen].MR_generator_frame) {
+        if (cur_maxfr == MR_gen_stack[cur_gen].MR_gen_frame) {
             for (i = 0; i < record_ptr_next; i++) {
                 if (record_ptrs[i].record_leader == subgoal) {
                     record_ptrs[i].found_leader_generator = MR_TRUE;
cvs diff: Diffing util
cvs diff: Diffing vim
cvs diff: Diffing vim/after
cvs diff: Diffing vim/ftplugin
cvs diff: Diffing vim/syntax
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list