[m-dev.] diff: minimal model tabling, part 1

Zoltan Somogyi zs at cs.mu.OZ.AU
Mon Apr 19 16:22:06 AEST 1999


Most of this diff has already been reviewed by Fergus. He requested
the introduction of a new grade component, which I have done. He should
review the relevant parts of this diff.

Estimated hours taken: 130

Rewrite significant parts of minimal model tabling so that it works
in a much wider variety of situations, including coups. Also, clean up
the tabling implementation to make it more maintainable, and introduce
a new grade component, .mm, that enables minimal model tabling.
(Minimal model tabling requires distributed fat, and we don't want to
incur such costs unless necessary.)

compiler/options.m:
	Add a new option --use-minimal-model, which for now is documented
	as "not for general use". This option is a grade option, and is
	required if minimal model tabling is to work.

compiler/handle_options.m:
	When --use-minimal-model is given, do not allow nondet frame hijacks,
	since minimal model tabling cannot cope with hijacks.

	Make --use-minimal-model a grade component.

compiler/code_info.m:
	When --use-minimal-model is given, insert calls to MR_commit_{mark,cut}
	around goals being committed across. This is now necessary, so that we
	can detect and handle sitations where a goal being committed across
	starts but does not complete a tabled goal.

compiler/table_gen.m:
	Rename many of the tabling helper predicates, using a naming scheme
	that separates predicates used for model_non procedures from those
	used to implement simpler forms of tabling, while bringing out
	the parallels between these two sets of predicates.

	When calls to two tabling helper predicates always occur
	one after the other, merge the two into one.

	Generate and use more meaningful variable names; having all of the
	several variables inserted by this transformation named TableVar
	was quite confusing.

library/private_builtin.m:
	Reorganize this file, to separate out the different sections.
	The contents of the non-tabling sections were not modified, only
	moved around.

	Rename the predicates referred to by table_gen.m.

	Move most of the type declarations and complex code out of here,
	into runtime/mercury_tabling.c. This makes it easier to debug them,
	since (a) creating a new executable is quicker, since you don't have
	to wait for lots of mercury compiler invocations, and (b) gdb doesn't
	get confused by #line directives. It also makes it easier to write
	them, since you don't have to !&(*U&( remember to double all your
	double quotes and to backslash all your backslashes.

runtime/mercury_grade.h:
	Include a grade component reflecting whether MR_USE_MINIMAL_MODEL
	is defined.

runtime/mercury_stacks.[ch]:
	The changes to tabling require the addition of two new stacks,
	the generator stack and the cut stack. This module defines the
	structures of the frames of these stacks and provides the
	operations on these stacks.

	The header file also contains some additional macros that return
	the addresses of fixed nondet stack slots, not their contents,
	for use by tabling code.

runtime/mercury_context.[ch]:
runtime/mercury_memory.[ch]:
runtime/mercury_wrapper.[ch]:
	Declare and set up the two new stacks, both in saved contexts and in
	the active context, if MR_USE_MINIMAL_MODEL is defined.

runtime/mercury_regorder.h:
	Add four new global virtual machine registers to hold pointers
	to the memory areas of the two new stacks and the current offsets
	within them. These are defined whether MR_USE_MINIMAL_MODEL is defined
	or not, since the cost is minimal and the potential bugs we avoid
	would be hard to track down.

runtime/mercury_engine.h:
runtime/mercury_wrapper.c:
	Add support for a new debugging flag, -dS, which prints the contents
	of the nondet stack at several points during tabling.

runtime/mercury_tabling.[ch]:
	The implementation of the new tabling system. Much of the new code here
	is stuff moved from library/private_builtin.m, but in a significantly
	rewritten form. There is also substantial new code, e.g. to handle
	the extension of saved stack segments, and to manage dependencies
	between subgoals in general.

	Improve the documentation considerably.

	Replace lists stored as Mercury data structures with lists stored
	as linked structures in the usual C fashion. This allows us to use
	debuggers such as ddd on these data structures, whose complexity
	requires this.

	Ensure that global names start with MR_.

runtime/mercury_init.h:
	Explicitly include mercury_regs.h at the start. Without this,
	we get an error, because now mercury_wrappers.h, which mercury_init.h
	includes, also includes mercury_regs.h, but not before functions
	have been declared.

runtime/Mmakefile:
	Refer to the new file mercury_stacks.c (mercury_stacks.h already
	existed, but the module consisted entirely of macros.)

	Fix a sorting error.

scripts/{init,parse,final}_grade_options.sh-subr:
scripts/mgnuc.in:
	Handle the new grade component.

tests/tabling/*
	Add several new test cases that we now pass, most of which we couldn't
	pass before. Also add some new test cases that we don't pass yet,
	due to interactions between tabling and negated contexts.

trace/mercury_trace_internal.c:
	If MR_USE_MINIMAL_MODEL is defined, add a new command to print
	the generator stack. (The new command is deliberately not documented
	in doc/mdb_doc yet, since (a) it is intended for developers only,
	and (b) there is no way to test MR_USE_MINIMAL_MODEL in mdb_doc.)

Zoltan.

cvs diff: Diffing .
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/include
cvs diff: Diffing boehm_gc/include/private
cvs diff: Diffing browser
cvs diff: Diffing bytecode
cvs diff: Diffing compiler
Index: compiler/code_info.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/code_info.m,v
retrieving revision 1.237
diff -u -b -u -r1.237 code_info.m
--- code_info.m	1999/04/16 06:04:20	1.237
+++ code_info.m	1999/04/17 10:55:19
@@ -36,7 +36,7 @@
 
 :- implementation.
 
-:- import_module code_util, code_exprn, prog_out.
+:- import_module code_util, code_exprn, llds_out, prog_out.
 :- import_module arg_info, type_util, mode_util, options.
 
 :- import_module term, varset.
@@ -1652,8 +1652,10 @@
 
 :- type commit_hijack_info
 	--->	commit_temp_frame(
-			lval		% The stack slot in which we saved
+			lval,		% The stack slot in which we saved
 					% the old value of maxfr.
+			bool		% Do we bracket the goal with
+					% MR_commit_mark and MR_commit_cut?
 		)
 	;	commit_quarter_hijack
 	;	commit_half_hijack(
@@ -1686,14 +1688,45 @@
 		{ Allow = not_allowed ; CondEnv = inside_non_condition }
 	->
 		code_info__acquire_temp_slot(lval(maxfr), MaxfrSlot),
-		{ HijackInfo = commit_temp_frame(MaxfrSlot) },
 		{ MaxfrCode = node([
 			assign(MaxfrSlot, lval(maxfr))
 				- "prepare for temp frame commit"
 		]) },
 		code_info__create_temp_frame(StackLabel,
 			"prepare for temp frame commit", TempFrameCode),
-		{ HijackCode = tree(MaxfrCode, TempFrameCode) }
+		code_info__get_globals(Globals),
+		{ globals__lookup_bool_option(Globals, use_minimal_model,
+			UseMinimalModel) },
+		{ HijackInfo = commit_temp_frame(MaxfrSlot, UseMinimalModel) },
+		{
+			UseMinimalModel = yes,
+			% If the code we are committing across starts but
+			% does not complete the evaluation of a tabled subgoal,
+			% the cut will remove the generator's choice point,
+			% so that the evaluation of the subgoal will never
+			% be completed. We handle such "dangling" generators
+			% by removing them from the subgoal trie of the
+			% tabled procedure. This requires knowing what
+			% tabled subgoals are started inside commits,
+			% which is why we wrap the goal being committed across
+			% inside MR_commit_{mark,cut}.
+			Components = [
+				pragma_c_raw_code(
+					"\tsave_transient_registers();\n"),
+				pragma_c_raw_code(
+					"\tMR_commit_mark();\n"),
+				pragma_c_raw_code(
+					"\trestore_transient_registers();\n")
+			],
+			MarkCode = node([
+				pragma_c([], Components, will_not_call_mercury,
+					no, no) - ""
+			])
+		;
+			UseMinimalModel = no,
+			MarkCode = empty
+		},
+		{ HijackCode = tree(MaxfrCode, tree(TempFrameCode, MarkCode)) }
 	;
 		{ ResumeKnown = resume_point_known },
 		{ CurfrMaxfr = must_be_equal }
@@ -1707,6 +1740,7 @@
 		{ CurfrMaxfr = must_be_equal }
 	->
 		% Here ResumeKnown must be resume_point_unknown.
+
 		code_info__acquire_temp_slot(lval(redoip(lval(curfr))),
 			RedoipSlot),
 		{ HijackInfo = commit_half_hijack(RedoipSlot) },
@@ -1750,12 +1784,28 @@
 	code_info__set_fail_info(FailInfo),
 	% XXX should release the temp slots in each arm of the switch
 	(
-		{ HijackInfo = commit_temp_frame(MaxfrSlot) },
-		{ SuccessUndoCode = node([
+		{ HijackInfo = commit_temp_frame(MaxfrSlot, UseMinimalModel) },
+		{ MaxfrCode = node([
 			assign(maxfr, lval(MaxfrSlot))
-				- "restore maxfr for full commit hijack"
+				- "restore maxfr for temp frame hijack"
 		]) },
-		{ FailureUndoCode = SuccessUndoCode }
+		{
+			UseMinimalModel = yes,
+			% See the comment in prepare_for_semi_commit above.
+			Components = [
+				pragma_c_raw_code("\tMR_commit_cut();\n")
+			],
+			CutCode = node([
+				pragma_c([], Components,
+					will_not_call_mercury, no, no)
+					- "commit for temp frame hijack"
+			])
+		;
+			UseMinimalModel = no,
+			CutCode = empty
+		},
+		{ SuccessUndoCode = tree(MaxfrCode, CutCode) },
+		{ FailureUndoCode = tree(MaxfrCode, CutCode) }
 	;
 		{ HijackInfo = commit_quarter_hijack },
 		{ FailInfo = fail_info(ResumePoints, _, _, _, _) },
Index: compiler/handle_options.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/handle_options.m,v
retrieving revision 1.71
diff -u -b -u -r1.71 handle_options.m
--- handle_options.m	1999/03/29 11:17:59	1.71
+++ handle_options.m	1999/04/11 08:56:26
@@ -164,8 +164,8 @@
                                 ->
                                     postprocess_options_2(OptionTable,
                                         GC_Method, TagsMethod, ArgsMethod,
-                                        PrologDialect, TermNorm, TraceLevel),
-                                    { Error = no }
+                                        PrologDialect, TermNorm, TraceLevel,
+					Error)
                                 ;
                                     { DumpAliasOption = string(DumpAlias) },
                                     { convert_dump_alias(DumpAlias,
@@ -175,8 +175,8 @@
                                         string(DumpOptions), NewOptionTable) },
                                     postprocess_options_2(NewOptionTable,
                                         GC_Method, TagsMethod, ArgsMethod,
-                                        PrologDialect, TermNorm, TraceLevel),
-                                    { Error = no }
+                                        PrologDialect, TermNorm, TraceLevel,
+					Error)
                                 ;
                                     { Error = yes("Invalid argument to option `--hlds-dump-alias'.") }
                                 )
@@ -204,11 +204,11 @@
 
 :- pred postprocess_options_2(option_table, gc_method, tags_method,
 	args_method, prolog_dialect, termination_norm, trace_level,
-	io__state, io__state).
-:- mode postprocess_options_2(in, in, in, in, in, in, in, di, uo) is det.
+	maybe(string), io__state, io__state).
+:- mode postprocess_options_2(in, in, in, in, in, in, in, out, di, uo) is det.
 
 postprocess_options_2(OptionTable, GC_Method, TagsMethod, ArgsMethod,
-		PrologDialect, TermNorm, TraceLevel) -->
+		PrologDialect, TermNorm, TraceLevel, Error) -->
 	% work around for NU-Prolog problems
 	( { map__search(OptionTable, heap_space, int(HeapSpace)) } ->
 		io__preallocate_heap_space(HeapSpace)
@@ -285,8 +285,20 @@
 	% --split-c-files implies --procs-per-c-function 1
 	option_implies(split_c_files, procs_per_c_function, int(1)),
 
+	% Minimal model tabling is not compatible with trailing;
+	% see the comment in runtime/mercury_tabling.c.
+
+	globals__io_lookup_bool_option(use_trail, UseTrail),
+	globals__io_lookup_bool_option(use_minimal_model, UseMinimalModel),
+	{ UseTrail = yes, UseMinimalModel = yes ->
+		Error = yes("trailing and minimal model tabling are not compatible")
+	;
+		Error = no
+	},
+
 	% The `.debug' grade (i.e. --stack-trace plus --require-tracing)
-	% implies --use-trail.
+	% implies --use-trail, except with --use-minimal-model, which is
+	% not compatible with --use-trail.
 	%
 	% The reason for this is to avoid unnecessary proliferation in
 	% the number of different grades.  If you're using --debug,
@@ -296,7 +308,7 @@
 
 	globals__io_lookup_bool_option(stack_trace, StackTrace),
 	globals__io_lookup_bool_option(require_tracing, RequireTracing),
-	( { StackTrace = yes, RequireTracing = yes } ->
+	( { StackTrace = yes, RequireTracing = yes, UseMinimalModel = no } ->
 		globals__io_set_option(use_trail, bool(yes))
 	;
 		[]
@@ -398,6 +410,14 @@
 	% --use-trail.
 	option_implies(use_trail, optimize_value_number, bool(no)),
 
+	% Minimal model tabling needs to be able to rewrite all the redoips
+	% in a given nondet stack segments. If we allow hijacks, some of these
+	% redoips may have been saved in ordinary framevars, which means that
+	% tabling can't find them without label layout info. Since we want
+	% to allow tabling in grades that do not have label layout info,
+	% we disable hijacks instead.
+	option_implies(use_minimal_model, allow_hijacks, bool(no)),
+
 	% --dump-hlds and --statistics require compilation by phases
 	globals__io_lookup_accumulating_option(dump_hlds, DumpStages),
 	globals__io_lookup_bool_option(statistics, Statistics),
@@ -554,6 +574,7 @@
 	;	gc		% the kind of GC to use
 	;	prof		% what profiling options to use
 	;	trail		% whether or not to use trailing
+	;	minimal_model	% whether we set up for minimal model tabling
 	;	args		% argument passing convention
 	;	trace		% tracing/debugging options
 	;	par		% parallelism / multithreading
@@ -687,6 +708,10 @@
 	% Trailing components
 grade_component_table("tr", trail, [use_trail - bool(yes)]).
 
+	% Mimimal model tabling components
+grade_component_table("mm", minimal_model,
+	[use_minimal_model - bool(yes)]).
+
 :- pred reset_grade_options(option_table, option_table).
 :- mode reset_grade_options(in, out) is det.
 
@@ -713,6 +738,7 @@
 grade_start_values(stack_trace - bool(no)).
 grade_start_values(require_tracing - bool(no)).
 grade_start_values(use_trail - bool(no)).
+grade_start_values(use_minimal_model - bool(no)).
 
 :- pred split_grade_string(string, list(string)).
 :- mode split_grade_string(in, out) is semidet.
Index: compiler/options.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/options.m,v
retrieving revision 1.257
diff -u -b -u -r1.257 options.m
--- options.m	1999/04/16 04:34:20	1.257
+++ options.m	1999/04/17 10:55:33
@@ -140,6 +140,7 @@
 		;	stack_trace
 		;	require_tracing
 		;	use_trail
+		;	use_minimal_model
 		;	pic_reg
 		;	tags
 		;	num_tag_bits
@@ -454,6 +455,7 @@
 	require_tracing		-	bool(no),
 	stack_trace		-	bool(no),
 	use_trail		-	bool(no),
+	use_minimal_model	-	bool(no),
 	pic_reg			-	bool(no),
 	tags			-	string("low"),
 	num_tag_bits		-	int(-1),
@@ -809,6 +811,7 @@
 % long_option("stack-trace",		stack_trace).
 % long_option("require-tracing",	require_tracing).
 long_option("use-trail",		use_trail).
+long_option("use-minimal-model",	use_minimal_model).
 long_option("pic-reg",			pic_reg).
 long_option("tags",			tags).
 long_option("num-tag-bits",		num_tag_bits).
@@ -1777,6 +1780,14 @@
 %		"\tKeeps typeinfo variables around for as long as any data",
 %		"\tthat has a type that contains that type variable is live",
 %
+		"--use-minimal-model",
+		"(This option is not for general use.)",
+		"\tEnable the use of minimal model tabling.",
+		"\tYou must compile the entire program with this option",
+		"\tif any part of the program uses `:- pragma minimal_model'.",
+		"\tAll the C code also needs to be compiled with the flag",
+		"\t`-DMR_USE_MINIMAL_MODEL'.",
+
 		"--unboxed-float",
 		"(This option is not for general use.)",
 		"\tDon't box floating point numbers.",
Index: compiler/table_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/table_gen.m,v
retrieving revision 1.6
diff -u -b -u -r1.6 table_gen.m
--- table_gen.m	1998/11/24 03:57:20	1.6
+++ table_gen.m	1999/03/17 07:57:42
@@ -1,10 +1,11 @@
 %-----------------------------------------------------------------------------%
-% Copyright (C) 1997-1998 The University of Melbourne.
+% Copyright (C) 1997-1999 The University of Melbourne.
 % This file may only be copied under the terms of the GNU General
 % Public License - see the file COPYING in the Mercury distribution.
 %-----------------------------------------------------------------------------%
 %
 % Main author: ohutch
+% Significant modifications by zs.
 %
 % This module transforms HLDS code to a form that allows tabled evaluation,
 % minimal model evaluation and loop detection.  The tabling transformation
@@ -26,8 +27,13 @@
 % the semantics behind the transformation. Currently only SLGd is
 % implemented.
 %
-% XXX the current implementation of minimal_model tabling is buggy;
-% e.g. it fails for tests/tabling/coup.m.
+% The current implementation does not attempt to do anything special
+% to handle cases where tabling interacts with if-then-else, solutions,
+% and negated contexts in general. Such situations are not even detected,
+% since the cost of such detection is quite substantial, and this cost
+% would be "distributed fat". Therefore in such cases the system may
+% silently produce incorrect answers. For time being, this is not a bug,
+% but a missing feature :-)
 %
 % Example of transformation for semidet minimal_model :
 %
@@ -49,18 +55,18 @@
 %		impure table_lookup_insert_int(T0, A, T1),
 %		impure table_lookup_insert_int(T1, B, T2),
 %		(if
-%			semipure table_have_ans(T2)
+%			semipure table_simple_is_complete(T2)
 %		then
 %				% True if the subgoal has already succeeded
-%			semipure table_has_succeeded(T2)
+%			semipure table_simple_has_succeeded(T2)
 %		else
 %		   	(if
 %					% Fail if we are already working on
 %					% an ans for this subgoal
-%				semipure table_not_working_on_ans(T2),
+%				semipure table_simple_is_inactive(T2),
 %
 %					% Mark this subgoal as being evaluated
-%				impure table_mark_as_working(T2),
+%				impure table_simple_mark_as_active(T2),
 %
 %				(
 %					%
@@ -68,9 +74,9 @@
 %					%
 %				)
 %			then
-%				impure table_mark_as_succeeded(T2)
+%				impure table_simple_mark_as_succeeded(T2)
 %			else
-%				impure table_mark_as_failed(T2)
+%				impure table_simple_mark_as_failed(T2)
 %			)
 %		).
 %
@@ -87,30 +93,30 @@
 %	The transformed code would be :
 %
 %	p(A, B) :-
-%			% Code to get a handle on the table
+%			% Code to get a handle on the table.
 %		T0 = <table pointer for p/2>,
 %
-%			% Code to lookup input arguments and setup table
+%			% Code to lookup input arguments and setup table.
 %		impure table_lookup_insert_int(T0, A, T1),
-%		impure table_setup(T1, T2),
+%		impure table_nondet_setup(T1, T2),
 %		(if
-%			semipure table_have_all_ans(T2)
+%			semipure table_nondet_is_complete(T2)
 %		then
 %				% Code to return all ans if we have found
-%				% them
-%			impure table_return_all_ans(T2, Ans),
+%				% them.
+%			impure table_nondet_return_all_ans(T2, Ans),
 %			impure table_restore_int_ans(Ans, 0, B)
 %		else if
-%			semipure table_have_some_ans(T2)
+%			semipure table_nondet_is_active(T2)
 %		then
 %				% Code to suspend the current computational
-%				% branch
-%			impure table_suspend(T2, Ans),
+%				% branch.
+%			impure table_nondet_suspend(T2, Ans),
 %			impure table_restore_int_ans(Ans, 0, B)
 %		else
 %		   	(		% Mark that this subgoal is being
-%					% evaluated
-%				impure table_mark_have_some_ans(T2),
+%					% evaluated.
+%				impure table_nondet_mark_as_active(T2),
 %
 %				(
 %					%
@@ -119,29 +125,25 @@
 %				),
 %
 %					% Code to check for duplicate
-%					% answers
-%				impure table_get_ans_table(T2, AT0),
+%					% answers.
+%				impure table_nondet_get_ans_table(T2, AT0),
 %				impure table_lookup_insert_int(AT0, B, AT1),
 %
-%					% The following pred is semidet
+%					% The following pred is semidet;
 %					% it will fail if the answer is
 %					% already in the table.
-%				semipure table_has_not_returned(AT1),
+%				semipure table_nondet_answer_is_not_dupl(AT1),
 %
 %					% Code to save a new ans in the
 %					% table.
-%				impure table_mark_as_returned(AT1),
-%				impure table_new_ans_slot(T2, AS),
+%				impure table_nondet_new_ans_slot(T2, AS),
 %				impure table_create_ans_block(AS, 1, AB),
 %				impure table_save_int_ans(AB, 0, B)
-%			;
-%					% Code to resume suspended nodes.
-%				impure table_resume(T2),
-%				fail
 %			;
-%					% Code to mark the current subgoal
+%					% Code to resume all suspended nodes,
+%					% and then mark the current subgoal
 %					% as totally evaluated.
-%				impure table_mark_have_all_ans(T2),
+%				impure table_nondet_resume(T2),
 %				fail
 %			)
 %		).
@@ -153,6 +155,7 @@
 % dropped and the loop handling code is modified to call an error predicate.
 %
 %-----------------------------------------------------------------------------%
+
 :- module table_gen.
 
 :- interface.
@@ -178,7 +181,7 @@
 
 %-----------------------------------------------------------------------------%
 
-	% NOTE : following preds seem to duplicate the code in passes_aux.m.
+	% NOTE: following preds seem to duplicate the code in passes_aux.m.
 	% This is not strictly true as the following code saved the value of
 	% the pred_info and passes this value on to the code for handling
 	% each of the procedures.
@@ -303,14 +306,14 @@
 
 	generate_det_lookup_goal(InputVars, Module, PredId, ProcId,
 		VarTypes0, VarTypes1, VarSet0, VarSet1, TableVar, LookUpGoal),
-	generate_call("table_have_ans", [TableVar], semidet, semipure,
-		[], Module, HaveAnsCheckGoal),
+	generate_call("table_simple_is_complete", [TableVar], semidet, semipure,
+		[], Module, CompleteCheckGoal),
 	generate_save_goal(OutputVars, TableVar, VarTypes1, VarTypes2,
 		VarSet1, VarSet2, Module, SaveAnsGoal0),
 	generate_restore_goal(OutputVars, TableVar,  Module, VarTypes2,
 		VarTypes3, VarSet2, VarSet3, RestoreAnsGoal),
-	generate_call("table_mark_done_working", [TableVar], det, impure,
-		[], Module, DoneWorkingGoal),
+	generate_call("table_simple_mark_as_inactive", [TableVar], det, impure,
+		[], Module, MarkAsInactiveGoal),
 	generate_loop_error_goal(PredInfo, Module, VarTypes3, VarTypes,
 		VarSet3, VarSet, LoopErrorGoal),
 
@@ -321,23 +324,22 @@
 	set__insert(OrigNonLocals, TableVar, GenAnsNonLocals),
 
 	( EvalMethod = eval_loop_check ->
-		SaveAnsGoal = DoneWorkingGoal
+		SaveAnsGoal = MarkAsInactiveGoal
 	;	EvalMethod = eval_memo ->
 		SaveAnsGoal = SaveAnsGoal0
 	;
 		error(
     "table_gen__create_new_det_goal: unsupported evaluation model")
 	),
+
+	generate_call("table_simple_is_active", [TableVar], semidet,
+		semipure, [], Module, ActiveCheckGoal),
+	generate_call("table_simple_mark_as_active", [TableVar], det,
+		impure, [], Module, MarkAsActiveGoal),
 
-	generate_call("table_working_on_ans", [TableVar], semidet,
-		semipure, [], Module, WorkingCheckGoal),
-	generate_call("table_mark_as_working", [TableVar], det,
-		impure, [], Module, MarkAsWorkingGoal),
-
-	NoLoopGenAnsGoalEx = conj([MarkAsWorkingGoal, OrigGoal,
-		SaveAnsGoal]),
-	create_instmap_delta([MarkAsWorkingGoal, OrigGoal,
-		SaveAnsGoal], NoLoopGenInstMapDelta0),
+	NoLoopGenAnsGoalEx = conj([MarkAsActiveGoal, OrigGoal, SaveAnsGoal]),
+	create_instmap_delta([MarkAsActiveGoal, OrigGoal, SaveAnsGoal],
+		NoLoopGenInstMapDelta0),
 	instmap_delta_restrict(NoLoopGenInstMapDelta0, GenAnsNonLocals,
 		NoLoopGenInstMapDelta),
 	goal_info_init(GenAnsNonLocals, NoLoopGenInstMapDelta, det,
@@ -345,9 +347,9 @@
 	NoLoopGenAnsGoal = NoLoopGenAnsGoalEx - NoLoopGenGoalInfo,
 
 	map__init(StoreMap),
-	GenAnsGoalEx = if_then_else([], WorkingCheckGoal,
+	GenAnsGoalEx = if_then_else([], ActiveCheckGoal,
 		LoopErrorGoal, NoLoopGenAnsGoal, StoreMap),
-	create_instmap_delta([WorkingCheckGoal, LoopErrorGoal,
+	create_instmap_delta([ActiveCheckGoal, LoopErrorGoal,
 		NoLoopGenAnsGoal], GenAnsInstMapDelta0),
 	instmap_delta_restrict(GenAnsInstMapDelta0, GenAnsNonLocals,
 		GenAnsInstMapDelta),
@@ -356,9 +358,9 @@
 
 	GenAnsGoal = GenAnsGoalEx - GenAnsGoalInfo,
 
-	ITEGoalEx = if_then_else([], HaveAnsCheckGoal, RestoreAnsGoal,
+	ITEGoalEx = if_then_else([], CompleteCheckGoal, RestoreAnsGoal,
 		GenAnsGoal, StoreMap),
-	create_instmap_delta([HaveAnsCheckGoal, RestoreAnsGoal, GenAnsGoal],
+	create_instmap_delta([CompleteCheckGoal, RestoreAnsGoal, GenAnsGoal],
 		ITEInstMapDelta0),
 	instmap_delta_restrict(ITEInstMapDelta0, GenAnsNonLocals,
 		ITEInstMapDelta),
@@ -391,20 +393,20 @@
 
 	generate_det_lookup_goal(InputVars, Module, PredId, ProcId,
 		VarTypes0, VarTypes1, VarSet0, VarSet1, TableVar, LookUpGoal),
-	generate_call("table_have_ans", [TableVar], semidet, semipure,
-		[], Module, HaveAnsCheckGoal),
+	generate_call("table_simple_is_complete", [TableVar],
+		semidet, semipure, [], Module, CompleteCheckGoal),
 	generate_save_goal(OutputVars, TableVar, VarTypes1, VarTypes2,
 		VarSet1, VarSet2, Module, SaveAnsGoal0),
 	generate_restore_goal(OutputVars, TableVar,  Module, VarTypes2,
 		VarTypes3, VarSet2, VarSet3, RestoreTrueAnsGoal),
 	generate_loop_error_goal(PredInfo, Module, VarTypes3, VarTypes,
 		VarSet3, VarSet, LoopErrorGoal),
-	generate_call("table_mark_as_failed", [TableVar], failure, impure,
-		[], Module, MarkAsFailedGoal),
-	generate_call("table_has_succeeded", [TableVar], semidet, semipure,
-		[], Module, HasSucceededCheckGoal),
-	generate_call("table_mark_done_working", [TableVar], det, impure,
-		[], Module, DoneWorkingGoal),
+	generate_call("table_simple_mark_as_failed", [TableVar],
+		failure, impure, [], Module, MarkAsFailedGoal),
+	generate_call("table_simple_has_succeeded", [TableVar],
+		semidet, semipure, [], Module, HasSucceededCheckGoal),
+	generate_call("table_simple_mark_as_inactive", [TableVar],
+		det, impure, [], Module, MarkAsInactiveGoal),
 
 	OrigGoal = _ - OrigGoalInfo,
 	goal_info_get_nonlocals(OrigGoalInfo, OrigNonLocals),
@@ -423,17 +425,17 @@
 		(
 			EvalMethod = eval_loop_check
 		->
-			SaveAnsGoal = DoneWorkingGoal
+			SaveAnsGoal = MarkAsInactiveGoal
 		;
 			SaveAnsGoal = SaveAnsGoal0
 		),
-		generate_call("table_working_on_ans", [TableVar], semidet,
-			semipure, [], Module, WorkingCheckGoal),
-		generate_call("table_mark_as_working", [TableVar], det,
-			impure, [], Module, MarkAsWorkingGoal),
+		generate_call("table_simple_is_active", [TableVar], semidet,
+			semipure, [], Module, ActiveCheckGoal),
+		generate_call("table_simple_mark_as_active", [TableVar], det,
+			impure, [], Module, MarkAsActiveGoal),
 
-		NoLoopGenAnsGoalEx = conj([MarkAsWorkingGoal, OrigGoal]),
-		create_instmap_delta([MarkAsWorkingGoal, OrigGoal],
+		NoLoopGenAnsGoalEx = conj([MarkAsActiveGoal, OrigGoal]),
+		create_instmap_delta([MarkAsActiveGoal, OrigGoal],
 			NoLoopGenInstMapDelta0),
 		instmap_delta_restrict(NoLoopGenInstMapDelta0, GenAnsNonLocals,
 			NoLoopGenInstMapDelta),
@@ -441,9 +443,9 @@
 			NoLoopGenGoalInfo),
 		NoLoopGenAnsGoal = NoLoopGenAnsGoalEx - NoLoopGenGoalInfo,
 
-		GenTrueAnsGoalEx = if_then_else([], WorkingCheckGoal,
+		GenTrueAnsGoalEx = if_then_else([], ActiveCheckGoal,
 			LoopErrorGoal, NoLoopGenAnsGoal, StoreMap),
-		create_instmap_delta([WorkingCheckGoal, LoopErrorGoal,
+		create_instmap_delta([ActiveCheckGoal, LoopErrorGoal,
 			NoLoopGenAnsGoal], GenTrueAnsInstMapDelta0),
 		instmap_delta_restrict(GenTrueAnsInstMapDelta0,
 			GenAnsNonLocals, GenTrueAnsInstMapDelta),
@@ -456,16 +458,16 @@
 	->
 		SaveAnsGoal = SaveAnsGoal0,
 
-		generate_call("table_not_working_on_ans", [TableVar], semidet,
-			semipure, [], Module, NotWorkingCheckGoal),
+		generate_call("table_simple_is_inactive", [TableVar], semidet,
+			semipure, [], Module, InactiveCheckGoal),
 
-		generate_call("table_mark_as_working", [TableVar], det,
-			impure, [], Module, MarkAsWorkingGoal),
+		generate_call("table_simple_mark_as_active", [TableVar], det,
+			impure, [], Module, MarkAsActiveGoal),
 
-		GenTrueAnsGoalEx = conj([NotWorkingCheckGoal,
-			MarkAsWorkingGoal, OrigGoal]),
+		GenTrueAnsGoalEx = conj([InactiveCheckGoal,
+			MarkAsActiveGoal, OrigGoal]),
 
-		create_instmap_delta([NotWorkingCheckGoal, MarkAsWorkingGoal,
+		create_instmap_delta([InactiveCheckGoal, MarkAsActiveGoal,
 			OrigGoal, SaveAnsGoal], GenTrueAnsInstMapDelta0),
 		instmap_delta_restrict(GenTrueAnsInstMapDelta0,
 			GenAnsNonLocals, GenTrueAnsInstMapDelta),
@@ -499,9 +501,9 @@
 		GenAnsGoalInfo),
 	GenAnsGoal = GenAnsGoalEx - GenAnsGoalInfo,
 
-	ITEGoalEx = if_then_else([], HaveAnsCheckGoal, RestoreAnsGoal,
+	ITEGoalEx = if_then_else([], CompleteCheckGoal, RestoreAnsGoal,
 		GenAnsGoal, StoreMap),
-	create_instmap_delta([HaveAnsCheckGoal, RestoreAnsGoal, GenAnsGoal],
+	create_instmap_delta([CompleteCheckGoal, RestoreAnsGoal, GenAnsGoal],
 		ITEInstMapDelta0),
 	instmap_delta_restrict(ITEInstMapDelta0, GenAnsNonLocals,
 		ITEInstMapDelta),
@@ -534,24 +536,22 @@
 
 	generate_non_lookup_goal(InputVars, Module, PredId, ProcId,
 		VarTypes0, VarTypes1, VarSet0, VarSet1, TableVar, LookUpGoal),
-	generate_call("table_have_all_ans", [TableVar], semidet, semipure,
-		[], Module, HaveAllAnsCheckGoal),
+	generate_call("table_nondet_is_complete", [TableVar], semidet, semipure,
+		[], Module, CompleteCheckGoal),
 	generate_non_save_goal(OutputVars, TableVar, VarTypes1, VarTypes2,
 		VarSet1, VarSet2, Module, SaveAnsGoal0),
 	generate_restore_all_goal(OutputVars, TableVar,  Module, VarTypes2,
 		VarTypes3, VarSet2, VarSet3, RestoreAllAnsGoal),
-	generate_call("table_have_some_ans", [TableVar], semidet, semipure,
-		[], Module, HaveSomeAnsCheckGoal),
+	generate_call("table_nondet_is_active", [TableVar], semidet, semipure,
+		[], Module, IsActiveCheckGoal),
 	generate_suspend_goal(OutputVars, TableVar, Module, VarTypes3,
 		VarTypes4, VarSet3, VarSet4, SuspendGoal),
 	generate_loop_error_goal(PredInfo, Module, VarTypes4, VarTypes,
 		VarSet4, VarSet, LoopErrorGoal),
-	generate_call("table_mark_have_some_ans", [TableVar], det, impure,
-		[], Module, MarkHaveSomeAnsGoal),
-	generate_call("table_resume", [TableVar], failure, impure,
+	generate_call("table_nondet_mark_as_active", [TableVar], det, impure,
+		[], Module, MarkAsActiveGoal),
+	generate_call("table_nondet_resume", [TableVar], failure, impure,
 		[], Module, ResumeGoal0),
-	generate_call("table_mark_have_all_ans", [TableVar], failure, impure,
-		[], Module, MarkHaveAllAnsGoal),
 
 	true_goal(TrueGoal),
 	fail_goal(FailGoal),
@@ -565,25 +565,25 @@
 		EvalMethod = eval_memo
 	->
 		SaveAnsGoal = SaveAnsGoal0,
-		WorkingOnAnsGoal = LoopErrorGoal
+		ActiveGoal = LoopErrorGoal
 	;
 		EvalMethod = eval_loop_check
 	->
 		SaveAnsGoal = TrueGoal,
-		WorkingOnAnsGoal = LoopErrorGoal
+		ActiveGoal = LoopErrorGoal
 	;
 		EvalMethod = eval_minimal
 	->
 		SaveAnsGoal = SaveAnsGoal0,
-		WorkingOnAnsGoal = SuspendGoal
+		ActiveGoal = SuspendGoal
 	;
 		error(
     "table_gen__create_new_non_goal: unsupported evaluation model")
 	),
 
-	GenAnsGoalPart1Ex = conj([MarkHaveSomeAnsGoal, OrigGoal, SaveAnsGoal]),
+	GenAnsGoalPart1Ex = conj([MarkAsActiveGoal, OrigGoal, SaveAnsGoal]),
 	set__insert(OrigNonLocals, TableVar, GenAnsGoalPart1NonLocals),
-	create_instmap_delta([MarkHaveSomeAnsGoal, OrigGoal, SaveAnsGoal],
+	create_instmap_delta([MarkAsActiveGoal, OrigGoal, SaveAnsGoal],
 		GenAnsGoalPart1IMD0),
 	instmap_delta_restrict(GenAnsGoalPart1IMD0, GenAnsGoalPart1NonLocals,
 		GenAnsGoalPart1IMD),
@@ -598,11 +598,10 @@
 	;
 		ResumeGoal = FailGoal
 	),
-	GenAnsGoalEx = disj([GenAnsGoalPart1, ResumeGoal, MarkHaveAllAnsGoal],
-		StoreMap),
+	GenAnsGoalEx = disj([GenAnsGoalPart1, ResumeGoal], StoreMap),
 	GenAnsGoal = GenAnsGoalEx - GenAnsGoalPart1GoalInfo,
 
-	ITE1GoalEx = if_then_else([], HaveSomeAnsCheckGoal, WorkingOnAnsGoal,
+	ITE1GoalEx = if_then_else([], IsActiveCheckGoal, ActiveGoal,
 		GenAnsGoal, StoreMap),
 	ITE1Goal = ITE1GoalEx - GenAnsGoalPart1GoalInfo,
 
@@ -611,7 +610,7 @@
 	->
 		ITE2Goal = ITE1Goal
 	;
-		ITE2GoalEx = if_then_else([], HaveAllAnsCheckGoal,
+		ITE2GoalEx = if_then_else([], CompleteCheckGoal,
 			RestoreAllAnsGoal, ITE1Goal, StoreMap),
 		ITE2Goal = ITE2GoalEx - GenAnsGoalPart1GoalInfo
 	),
@@ -628,18 +627,19 @@
 :- mode generate_get_table_goal(in, out, in, out, in, in, out, out) is det.
 
 generate_get_table_goal(VarTypes0, VarTypes, VarSet0, VarSet,
-		PredId, ProcId, TableVar, Goal) :-
-	generate_new_table_var(VarTypes0, VarTypes, VarSet0, VarSet, TableVar),
+		PredId, ProcId, PredTableVar, Goal) :-
+	generate_new_table_var("PredTable", VarTypes0, VarTypes,
+		VarSet0, VarSet, PredTableVar),
 
 	ConsId = tabling_pointer_const(PredId, ProcId),
-	TableVarInst = ground(unique, no),
-	UnifyMode = (free -> TableVarInst) - (TableVarInst -> TableVarInst),
+	VarInst = ground(unique, no),
+	UnifyMode = (free -> VarInst) - (VarInst -> VarInst),
 	UnifyContext = unify_context(explicit, []),
-	GoalExpr = unify(TableVar, functor(ConsId, []), UnifyMode,
-			construct(TableVar, ConsId, [], []), UnifyContext),
+	GoalExpr = unify(PredTableVar, functor(ConsId, []), UnifyMode,
+			construct(PredTableVar, ConsId, [], []), UnifyContext),
 
-	set__singleton_set(NonLocals, TableVar),
-	instmap_delta_from_assoc_list([TableVar - TableVarInst],
+	set__singleton_set(NonLocals, PredTableVar),
+	instmap_delta_from_assoc_list([PredTableVar - VarInst],
 		InstMapDelta),
 	goal_info_init(NonLocals, InstMapDelta, det,
 		GoalInfo0),
@@ -658,8 +658,8 @@
 		VarSet0, VarSet, TableVar, Goal) :-
 
 	generate_get_table_goal(VarTypes0, VarTypes1, VarSet0, VarSet1,
-		PredId, ProcId, TableVar0, GetTableGoal),
-	generate_lookup_goals(Vars, TableVar0, TableVar, Module,
+		PredId, ProcId, PredTableVar, GetTableGoal),
+	generate_lookup_goals(Vars, PredTableVar, TableVar, Module,
 		VarTypes1, VarTypes, VarSet1, VarSet, LookupGoals),
 
 	GoalEx = conj([GetTableGoal | LookupGoals]),
@@ -676,20 +676,21 @@
 	is det.
 
 generate_non_lookup_goal(Vars, Module, PredId, ProcId, VarTypes0, VarTypes,
-		VarSet0, VarSet, TableVar, Goal) :-
+		VarSet0, VarSet, SubgoalVar, Goal) :-
 
 	generate_get_table_goal(VarTypes0, VarTypes1, VarSet0, VarSet1,
-		PredId, ProcId, TableVar0, GetTableGoal),
-	generate_lookup_goals(Vars, TableVar0, TableVar1, Module,
+		PredId, ProcId, PredTableVar, GetTableGoal),
+	generate_lookup_goals(Vars, PredTableVar, TableNodeVar, Module,
 		VarTypes1, VarTypes2, VarSet1, VarSet2, LookupGoals),
-	generate_new_table_var(VarTypes2, VarTypes, VarSet2, VarSet,
-		TableVar),
-	generate_call("table_setup", [TableVar1, TableVar], det, impure,
-		[TableVar - ground(unique, no)], Module, SetupGoal),
+	generate_new_table_var("SubgoalVar", VarTypes2, VarTypes,
+		VarSet2, VarSet, SubgoalVar),
+	generate_call("table_nondet_setup", [TableNodeVar, SubgoalVar],
+		det, impure, [SubgoalVar - ground(unique, no)],
+		Module, SetupGoal),
 
 	list__append([GetTableGoal | LookupGoals], [SetupGoal], Goals),
 	GoalEx = conj(Goals),
-	set__singleton_set(NonLocals0, TableVar),
+	set__singleton_set(NonLocals0, SubgoalVar),
 	set__insert_list(NonLocals0, Vars, NonLocals),
 	create_instmap_delta(Goals, InstMapDelta0),
 	instmap_delta_restrict(InstMapDelta0, NonLocals, InstMapDelta),
@@ -743,12 +744,14 @@
 				VarTypes1, VarSet0, VarSet1, RangeVar,
 				RangeUnifyGoal),
 
-			generate_new_table_var(VarTypes1, VarTypes, VarSet1,
-				VarSet, NextTableVar),
-			generate_call("table_lookup_insert_enum", [TableVar,
-				RangeVar, ArgVar, NextTableVar], det, impure,
-				[NextTableVar - ground(unique, no)], Module,
-				LookupGoal),
+			generate_new_table_var("TableNodeVar",
+				VarTypes1, VarTypes, VarSet1, VarSet,
+				NextTableVar),
+			generate_call("table_lookup_insert_enum",
+				[TableVar, RangeVar, ArgVar, NextTableVar],
+				det, impure,
+				[NextTableVar - ground(unique, no)],
+				Module, LookupGoal),
 			set__init(NonLocals0),
 			set__insert_list(NonLocals0, [TableVar, ArgVar],
 				NonLocals),
@@ -780,8 +783,8 @@
 			string__append("table_lookup_insert_", CatString,
 				LookupPredName)
 		),
-		generate_new_table_var(VarTypes0, VarTypes, VarSet0, VarSet,
-			NextTableVar),
+		generate_new_table_var("TableNodeVar", VarTypes0, VarTypes,
+			VarSet0, VarSet, NextTableVar),
 		generate_call(LookupPredName, [TableVar, ArgVar, NextTableVar],
 			det, impure, [NextTableVar - ground(unique, no)],
 			Module, Goal)
@@ -805,22 +808,22 @@
 			VarTypes1, VarSet0, VarSet1, NumAnsVarsVar,
 			NumAnsVarsUnifyGoal),
 
-		generate_new_table_var(VarTypes1, VarTypes2, VarSet1, VarSet2,
-			AnsTableVar),
+		generate_new_table_var("AnswerTableVar", VarTypes1, VarTypes2,
+			VarSet1, VarSet2, AnsTableVar),
 
-		generate_call("table_create_ans_block", [TableVar,
-			NumAnsVarsVar, AnsTableVar], det, impure,
+		generate_call("table_create_ans_block",
+			[TableVar, NumAnsVarsVar, AnsTableVar], det, impure,
 			[AnsTableVar - ground(unique, no)], Module,
-			GenAnsBlockGoal),
+			CreateAnsBlockGoal),
 
 		generate_save_goals(AnsList, AnsTableVar, 0, Module,
 			VarTypes2, VarTypes, VarSet2, VarSet, SaveGoals),
 
-		GoalEx = conj([NumAnsVarsUnifyGoal, GenAnsBlockGoal |
+		GoalEx = conj([NumAnsVarsUnifyGoal, CreateAnsBlockGoal |
 			SaveGoals]),
 		set__singleton_set(NonLocals0, TableVar),
 		set__insert_list(NonLocals0, AnsList, NonLocals),
-		create_instmap_delta([NumAnsVarsUnifyGoal, GenAnsBlockGoal |
+		create_instmap_delta([NumAnsVarsUnifyGoal, CreateAnsBlockGoal |
 			SaveGoals], InstMapDelta0),
 		instmap_delta_restrict(InstMapDelta0, NonLocals, InstMapDelta),
 		goal_info_init(NonLocals, InstMapDelta, det,  GoalInfo),
@@ -837,42 +840,41 @@
 		module_info, hlds_goal).
 :- mode generate_non_save_goal(in, in, in, out, in, out, in, out) is det.
 
-generate_non_save_goal(AnsList, TableVar, VarTypes0, VarTypes, VarSet0,
-		VarSet, Module, Goal) :-
+generate_non_save_goal(AnsList, TableVar, VarTypes0, VarTypes,
+		VarSet0, VarSet, Module, Goal) :-
 
-	generate_new_table_var(VarTypes0, VarTypes1, VarSet0, VarSet1,
-		AnsTableVar0),
-	generate_call("table_get_ans_table", [TableVar, AnsTableVar0], det,
-		impure, [AnsTableVar0 - ground(unique, no)], Module,
-		GetAnsTableGoal),
+	generate_new_table_var("AnswerTableVar", VarTypes0, VarTypes1,
+		VarSet0, VarSet1, AnsTableVar0),
+	generate_call("table_nondet_get_ans_table", [TableVar, AnsTableVar0],
+		det, impure, [AnsTableVar0 - ground(unique, no)],
+		Module, GetAnsTableGoal),
 	generate_lookup_goals(AnsList, AnsTableVar0, AnsTableVar1, Module,
 		VarTypes1, VarTypes2, VarSet1, VarSet2, LookupAnsGoals),
-	generate_call("table_has_not_returned", [AnsTableVar1], semidet,
-		semipure, [], Module, NewAnsCheckGoal),
-	generate_call("table_mark_as_returned", [AnsTableVar1], det, impure,
-		[],  Module, MarkAsReturnedGoal),
-
-	generate_new_table_var(VarTypes2, VarTypes3, VarSet2, VarSet3,
-		AnsBlockVar0),
-	generate_call("table_new_ans_slot", [TableVar, AnsBlockVar0], det,
-		impure, [AnsBlockVar0 - ground(unique, no)], Module,
-		GenAnsSlotGoal),
+	generate_call("table_nondet_answer_is_not_duplicate", [AnsTableVar1],
+		semidet, impure, [], Module, DuplicateCheckGoal),
+
+	generate_new_table_var("AnswerSlotVar", VarTypes2, VarTypes3,
+		VarSet2, VarSet3, AnsSlotVar),
+	generate_call("table_nondet_new_ans_slot", [TableVar, AnsSlotVar], det,
+		impure, [AnsSlotVar - ground(unique, no)],
+		Module, NewAnsSlotGoal),
 
 	list__length(AnsList, NumAnsVars),
 	gen_int_construction("NumAnsVars", NumAnsVars, VarTypes3, VarTypes4,
 		VarSet3, VarSet4, NumAnsVarsVar, NumAnsVarsUnifyGoal),
-	generate_new_table_var(VarTypes4, VarTypes5, VarSet4, VarSet5,
-		AnsBlockVar),
-	generate_call("table_create_ans_block", [AnsBlockVar0, NumAnsVarsVar,
-		AnsBlockVar], det, impure, [AnsBlockVar - ground(unique, no)],
-		Module, GenAnsBlockGoal),
+	generate_new_table_var("AnswerBlock", VarTypes4, VarTypes5,
+		VarSet4, VarSet5, AnsBlockVar),
+	generate_call("table_create_ans_block",
+		[AnsSlotVar, NumAnsVarsVar, AnsBlockVar], det, impure,
+		[AnsBlockVar - ground(unique, no)],
+		Module, CreateAnsBlockGoal),
 
 	generate_save_goals(AnsList, AnsBlockVar, 0, Module, VarTypes5,
 		VarTypes, VarSet5, VarSet, SaveGoals),
 
 	list__append([GetAnsTableGoal | LookupAnsGoals],
-		[NewAnsCheckGoal, MarkAsReturnedGoal, GenAnsSlotGoal,
-		NumAnsVarsUnifyGoal, GenAnsBlockGoal | SaveGoals], Goals),
+		[DuplicateCheckGoal, NewAnsSlotGoal, NumAnsVarsUnifyGoal,
+		CreateAnsBlockGoal | SaveGoals], Goals),
 
 	GoalEx = conj(Goals),
 	set__singleton_set(NonLocals0, TableVar),
@@ -954,9 +956,9 @@
 generate_restore_all_goal(OutputVars, TableVar, Module, VarTypes0, VarTypes,
 		VarSet0, VarSet, Goal) :-
 
-	generate_new_table_var(VarTypes0, VarTypes1, VarSet0, VarSet1,
-		AnsTableVar),
-	generate_call("table_return_all_ans", [TableVar, AnsTableVar],
+	generate_new_table_var("AnswerTable", VarTypes0, VarTypes1,
+		VarSet0, VarSet1, AnsTableVar),
+	generate_call("table_nondet_return_all_ans", [TableVar, AnsTableVar],
 		nondet, semipure, [AnsTableVar - ground(unique, no)],
 		Module, ReturnAnsBlocksGoal),
 
@@ -1025,9 +1027,9 @@
 generate_suspend_goal(OutputVars, TableVar, Module, VarTypes0, VarTypes,
 		VarSet0, VarSet, Goal) :-
 
-	generate_new_table_var(VarTypes0, VarTypes1, VarSet0, VarSet1,
-		AnsTableVar),
-	generate_call("table_suspend", [TableVar, AnsTableVar],
+	generate_new_table_var("AnswerTable", VarTypes0, VarTypes1,
+		VarSet0, VarSet1, AnsTableVar),
+	generate_call("table_nondet_suspend", [TableVar, AnsTableVar],
 		nondet, semipure, [AnsTableVar - ground(unique, no)],
 		Module, ReturnAnsBlocksGoal),
 
@@ -1078,12 +1080,13 @@
 
 %------------------------------------------------------------------------------%
 
-:- pred generate_new_table_var(map(prog_var, type), map(prog_var, type),
+:- pred generate_new_table_var(string,
+		map(prog_var, type), map(prog_var, type),
 		prog_varset, prog_varset, prog_var).
-:- mode generate_new_table_var(in, out, in, out, out) is det.
+:- mode generate_new_table_var(in, in, out, in, out, out) is det.
 
-generate_new_table_var(VarTypes0, VarTypes, VarSet0, VarSet, Var) :-
-	varset__new_named_var(VarSet0, "TableVar", Var, VarSet),
+generate_new_table_var(Name, VarTypes0, VarTypes, VarSet0, VarSet, Var) :-
+	varset__new_named_var(VarSet0, Name, Var, VarSet),
 	get_table_var_type(Type),
 	map__set(VarTypes0, Var, Type, VarTypes).
 
cvs diff: Diffing compiler/notes
cvs diff: Diffing debian
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/dynamic_linking
cvs diff: Diffing extras/exceptions
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/odbc
cvs diff: Diffing extras/references
cvs diff: Diffing extras/references/samples
cvs diff: Diffing extras/references/tests
cvs diff: Diffing extras/trailed_update
cvs diff: Diffing extras/trailed_update/samples
cvs diff: Diffing extras/trailed_update/tests
--------------------------------------------------------------------------
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