[m-dev.] for review: retry in trailing grades

Zoltan Somogyi zs at cs.mu.OZ.AU
Tue Oct 5 11:14:32 AEST 1999


For review by anyone who knows RTTI.

I would like Warwick to extend HAL's trail system to handle retry as a trail
reset reason, and then check whether the change works with HAL. That going to
be a significant amount of work, but it should make the HAL project more
productive in the long run.

Estimated hours taken: 18

Make the retry command work in trailing grades (e.g. for HAL).

compiler/trace.m:
	In trailing grades, reserve two stack slots to hold (a) the trail
	pointer on entry, and (b) a new ticket obtained on entry. Arrange to
	put the numbers of these stack slots in the proc layout.

compiler/stack_layout.m:
	Put the number of the first of these stack slots in the proc layout.

compiler/code_info.m:
	Arrange the default: there are no such slots if debugging is not
	enabled.

compiler/code_gen.m:
	Insert code to discard the allocated ticket, in the success epilog
	of model_det procedures, the success and failure epilogs of model_semi
	procedures, and the failure epilogs of model_non procedures.
	(Model_det procedures don't have failure epilogs, and discarding
	the ticket in the success epilog of a model_non procedure would be
	premature.)

compiler/llds.m:
	Add two new alternatives to the type describing stack slots:
	a stack slot may contain a trail pointer or a ticket.

	Add a new reason for resetting the trail: a retry in the debugger.

compiler/llds_out.m:
	Minor changes to conform to llds.m, and to make diagnostic output
	less misleading.

library/builtin.m:
	Add the type_ctor_info for the new "types" describing stored trail
	pointers and tickets.

	Bring up to date the type_ctor_infos of other "types" used only
	for describing stack slots.

library/std_util.m:
	Add the missing code to handle the type_ctor_infos of trail pointers,
	tickets and other "types" used only for describing stack slots.

runtime/mercury_type_info.h:
	Add a new type_ctor representation value for stored trail pointers,
	tickets, and for other "types" used only for describing stack slots.

runtime/mercury_deep_copy_body.h:
runtime/mercury_tabling.c:
	Add the missing code to handle the type_ctor_infos of trail pointers,
	tickets and other "types" used only for describing stack slots.

runtime/mercury_stack_layout.h:
	Add a field to proc layouts to hold either the number of the first
	of the two stack slots holding trail info, or -1.

runtime/mercury_trail.h:
	Add the new reason why the trail may be reset.

trace/mercury_trace.c:
	In trailing grades, reset the trail, with the reason being given
	as retry, when the debugger's retry command is executed.

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_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/code_gen.m,v
retrieving revision 1.66
diff -u -b -r1.66 code_gen.m
--- code_gen.m	1999/07/13 08:52:42	1.66
+++ code_gen.m	1999/09/27 09:27:30
@@ -213,7 +213,8 @@
 
 		% Generate code for the procedure.
 	generate_category_code(CodeModel, Goal, OutsideResumePoint,
-		CodeTree, MaybeTraceCallLabel, FrameInfo, CodeInfo0, CodeInfo),
+		TraceSlotInfo, CodeTree, MaybeTraceCallLabel, FrameInfo,
+		CodeInfo0, CodeInfo),
 	code_info__get_cell_count(CellCount, CodeInfo, _),
 
 		% Turn the code tree into a list.
@@ -325,10 +326,11 @@
 	% for the failure continuation at all times.)
 
 :- pred generate_category_code(code_model::in, hlds_goal::in,
-	resume_point_info::in, code_tree::out, maybe(label)::out,
-	frame_info::out, code_info::in, code_info::out) is det.
+	resume_point_info::in, trace_slot_info::in, code_tree::out,
+	maybe(label)::out, frame_info::out, code_info::in, code_info::out)
+	is det.
 
-generate_category_code(model_det, Goal, ResumePoint, Code,
+generate_category_code(model_det, Goal, ResumePoint, TraceSlotInfo, Code,
 		MaybeTraceCallLabel, FrameInfo) -->
 		% generate the code for the body of the clause
 	(
@@ -352,7 +354,8 @@
 		code_gen__generate_goal(model_det, Goal, BodyCode),
 		code_gen__generate_entry(model_det, Goal, ResumePoint,
 			FrameInfo, EntryCode),
-		code_gen__generate_exit(model_det, FrameInfo, _, ExitCode),
+		code_gen__generate_exit(model_det, FrameInfo, TraceSlotInfo,
+			_, ExitCode),
 		{ Code =
 			tree(EntryCode,
 			tree(TraceCallCode,
@@ -361,7 +364,7 @@
 		}
 	).
 
-generate_category_code(model_semi, Goal, ResumePoint, Code,
+generate_category_code(model_semi, Goal, ResumePoint, TraceSlotInfo, Code,
 		MaybeTraceCallLabel, FrameInfo) -->
 	{ set__singleton_set(FailureLiveRegs, reg(r, 1)) },
 	{ FailCode = node([
@@ -377,7 +380,7 @@
 		code_gen__generate_goal(model_semi, Goal, BodyCode),
 		code_gen__generate_entry(model_semi, Goal, ResumePoint,
 			FrameInfo, EntryCode),
-		code_gen__generate_exit(model_semi, FrameInfo,
+		code_gen__generate_exit(model_semi, FrameInfo, TraceSlotInfo,
 			RestoreDeallocCode, ExitCode),
 
 		code_info__generate_resume_point(ResumePoint, ResumeCode),
@@ -401,7 +404,7 @@
 		code_gen__generate_goal(model_semi, Goal, BodyCode),
 		code_gen__generate_entry(model_semi, Goal, ResumePoint,
 			FrameInfo, EntryCode),
-		code_gen__generate_exit(model_semi, FrameInfo,
+		code_gen__generate_exit(model_semi, FrameInfo, TraceSlotInfo,
 			RestoreDeallocCode, ExitCode),
 		code_info__generate_resume_point(ResumePoint, ResumeCode),
 		{ Code =
@@ -414,7 +417,7 @@
 		}
 	).
 
-generate_category_code(model_non, Goal, ResumePoint, Code,
+generate_category_code(model_non, Goal, ResumePoint, TraceSlotInfo, Code,
 		MaybeTraceCallLabel, FrameInfo) -->
 	code_info__get_maybe_trace_info(MaybeTraceInfo),
 	( { MaybeTraceInfo = yes(TraceInfo) } ->
@@ -424,7 +427,8 @@
 		code_gen__generate_goal(model_non, Goal, BodyCode),
 		code_gen__generate_entry(model_non, Goal, ResumePoint,
 			FrameInfo, EntryCode),
-		code_gen__generate_exit(model_non, FrameInfo, _, ExitCode),
+		code_gen__generate_exit(model_non, FrameInfo, TraceSlotInfo,
+			_, ExitCode),
 
 		code_info__generate_resume_point(ResumePoint, ResumeCode),
 		{ code_info__resume_point_vars(ResumePoint, ResumeVarList) },
@@ -432,6 +436,13 @@
 		code_info__set_forward_live_vars(ResumeVars),
 		trace__generate_external_event_code(fail, TraceInfo, _, _,
 			TraceFailCode),
+		{ TraceSlotInfo = trace_slot_info(_, _, yes(_)) ->
+			DiscardTraceTicketCode = node([
+				discard_ticket - "discard retry ticket"
+			])
+		;
+			DiscardTraceTicketCode = empty
+		},
 		{ FailCode = node([
 			goto(do_fail) - "fail after fail trace port"
 		]) },
@@ -442,14 +453,16 @@
 			tree(ExitCode,
 			tree(ResumeCode,
 			tree(TraceFailCode,
-			     FailCode))))))
+			tree(DiscardTraceTicketCode,
+			     FailCode)))))))
 		}
 	;
 		{ MaybeTraceCallLabel = no },
 		code_gen__generate_goal(model_non, Goal, BodyCode),
 		code_gen__generate_entry(model_non, Goal, ResumePoint,
 			FrameInfo, EntryCode),
-		code_gen__generate_exit(model_non, FrameInfo, _, ExitCode),
+		code_gen__generate_exit(model_non, FrameInfo, TraceSlotInfo,
+			_, ExitCode),
 		{ Code =
 			tree(EntryCode,
 			tree(BodyCode,
@@ -613,7 +626,8 @@
 	% our caller; this is why we return RestoreDeallocCode.
 	%
 	% At the moment the only special slots are the succip slot, and
-	% the slots holding the call number and call depth for tracing.
+	% the tracing slots (holding the call sequence number, call event
+	% number, call depth, from-full indication, and trail state).
 	%
 	% Not all frames will have all these components. For example, for
 	% nondet procedures we don't deallocate the stack frame before
@@ -625,9 +639,11 @@
 	% we need only #undef a macro defined by the procedure prologue.
 
 :- pred code_gen__generate_exit(code_model::in, frame_info::in,
-	code_tree::out, code_tree::out, code_info::in, code_info::out) is det.
+	trace_slot_info::in, code_tree::out, code_tree::out,
+	code_info::in, code_info::out) is det.
 
-code_gen__generate_exit(CodeModel, FrameInfo, RestoreDeallocCode, ExitCode) -->
+code_gen__generate_exit(CodeModel, FrameInfo, TraceSlotInfo,
+		RestoreDeallocCode, ExitCode) -->
 	{ StartComment = node([
 		comment("Start of procedure epilogue") - ""
 	]) },
@@ -662,26 +678,41 @@
 		;
 			code_info__setup_call(Args, callee, FlushCode)
 		),
-		(
-			{ MaybeSuccipSlot = yes(SuccipSlot) }
+		{
+			MaybeSuccipSlot = yes(SuccipSlot)
 		->
-			{ RestoreSuccipCode = node([
+			RestoreSuccipCode = node([
 				assign(succip, lval(stackvar(SuccipSlot))) -
 					"restore the success ip"
-			]) }
+			])
 		;
-			{ RestoreSuccipCode = empty }
-		),
-		(
-			{ TotalSlots = 0 ; CodeModel = model_non }
+			RestoreSuccipCode = empty
+		},
+		{
+			( TotalSlots = 0 ; CodeModel = model_non )
 		->
-			{ DeallocCode = empty }
+			DeallocCode = empty
 		;
-			{ DeallocCode = node([
+			DeallocCode = node([
 				decr_sp(TotalSlots) - "Deallocate stack frame"
-			]) }
-		),
-		{ RestoreDeallocCode = tree(RestoreSuccipCode, DeallocCode ) },
+			])
+		},
+		{
+			TraceSlotInfo = trace_slot_info(_, _, yes(_)),
+			CodeModel \= model_non
+		->
+			DiscardTraceTicketCode = node([
+				discard_ticket - "discard retry ticket"
+			])
+		;
+			DiscardTraceTicketCode = empty
+		},
+
+		{ RestoreDeallocCode =
+			tree(RestoreSuccipCode,
+			tree(DeallocCode,
+			     DiscardTraceTicketCode))
+		},
 
 		code_info__get_maybe_trace_info(MaybeTraceInfo),
 		( { MaybeTraceInfo = yes(TraceInfo) } ->
Index: compiler/code_info.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/code_info.m,v
retrieving revision 1.241
diff -u -b -r1.241 code_info.m
--- code_info.m	1999/09/30 08:55:03	1.241
+++ code_info.m	1999/09/30 08:57:52
@@ -371,7 +371,7 @@
 		{ MaybeFailVars = yes(FailVars) }
 	;
 		{ MaybeFailVars = no },
-		{ TraceSlotInfo = trace_slot_info(no, no) }
+		{ TraceSlotInfo = trace_slot_info(no, no, no) }
 	).
 
 %---------------------------------------------------------------------------%
Index: compiler/llds.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/llds.m,v
retrieving revision 1.250
diff -u -b -r1.250 llds.m
--- llds.m	1999/09/30 08:55:09	1.250
+++ llds.m	1999/10/05 02:53:21
@@ -318,14 +318,16 @@
 			% The rval must specify a ticket allocated with
 			% `store_ticket' and not yet invalidated or
 			% deallocated.
-			% If undo_reason is `undo' or `exception', restore
-			% any mutable global state to the state it was in when
-			% the ticket was obtained with store_ticket();
-			% invalidates any tickets allocated after this one.
-			% If undo_reason is `commit' or `solve', leave the state
-			% unchanged, just check that it is safe to commit
-			% to this solution (i.e. that there are no outstanding
-			% delayed goals -- this is the "floundering" check).
+			% If reset_trail_reason is `undo', `exception', or
+			% `retry', restore any mutable global state to the
+			% state it was in when the ticket was obtained with
+			% store_ticket(); invalidates any tickets allocated
+			% after this one.
+			% If reset_trail_reason is `commit' or `solve', leave
+			% the state unchanged, just check that it is safe to
+			% commit to this solution (i.e. that there are no
+			% outstanding delayed goals -- this is the
+			% "floundering" check).
 			% Note that we do not discard trail entries after
 			% commits, because that would in general be unsafe.
 			%
@@ -514,6 +516,7 @@
 	;	commit
 	;	solve
 	;	exception
+	;	retry
 	;	gc
 	.
 
@@ -579,6 +582,8 @@
 	;	redoip				% A stored redoip.
 	;	redofr				% A stored redofr.
 	;	hp				% A stored heap pointer.
+	;	trail_ptr			% A stored trail pointer.
+	;	ticket				% A stored ticket.
 	;	var(prog_var, string, type, llds_inst)
 						% A variable (the var number
 						% and name are for execution
Index: compiler/llds_out.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/llds_out.m,v
retrieving revision 1.124
diff -u -b -r1.124 llds_out.m
--- llds_out.m	1999/09/27 05:20:13	1.124
+++ llds_out.m	1999/10/05 02:54:07
@@ -1782,6 +1782,8 @@
 	io__write_string("MR_solve").
 output_reset_trail_reason(exception) -->
 	io__write_string("MR_exception").
+output_reset_trail_reason(retry) -->
+	io__write_string("MR_retry").
 output_reset_trail_reason(gc) -->
 	io__write_string("MR_gc").
 
@@ -1870,12 +1872,14 @@
 :- pred output_live_value_type(live_value_type, io__state, io__state).
 :- mode output_live_value_type(in, di, uo) is det.
 
-output_live_value_type(succip) --> io__write_string("MR_succip").
-output_live_value_type(curfr) --> io__write_string("MR_curfr").
-output_live_value_type(maxfr) --> io__write_string("MR_maxfr").
-output_live_value_type(redofr) --> io__write_string("MR_redofr").
-output_live_value_type(redoip) --> io__write_string("MR_redoip").
-output_live_value_type(hp) --> io__write_string("MR_hp").
+output_live_value_type(succip) --> io__write_string("type succip").
+output_live_value_type(curfr) --> io__write_string("type curfr").
+output_live_value_type(maxfr) --> io__write_string("type maxfr").
+output_live_value_type(redofr) --> io__write_string("type redofr").
+output_live_value_type(redoip) --> io__write_string("type redoip").
+output_live_value_type(hp) --> io__write_string("type hp").
+output_live_value_type(trail_ptr) --> io__write_string("type trail_ptr").
+output_live_value_type(ticket) --> io__write_string("type ticket").
 output_live_value_type(unwanted) --> io__write_string("unwanted").
 output_live_value_type(var(Var, Name, Type, LldsInst)) --> 
 	io__write_string("var("),
Index: compiler/stack_layout.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/stack_layout.m,v
retrieving revision 1.34
diff -u -b -r1.34 stack_layout.m
--- stack_layout.m	1999/08/15 07:50:28	1.34
+++ stack_layout.m	1999/10/05 02:56:11
@@ -480,7 +480,7 @@
 		ModuleRval = yes(const(data_addr_const(
 				data_addr(ModuleName, module_layout)))),
 		TraceSlotInfo = trace_slot_info(MaybeFromFullSlot,
-			MaybeDeclSlots),
+			MaybeDeclSlots, MaybeTrailSlot),
 		( MaybeFromFullSlot = yes(FromFullSlot) ->
 			FromFullRval = yes(const(int_const(FromFullSlot)))
 		;
@@ -491,8 +491,14 @@
 		;
 			DeclRval = yes(const(int_const(-1)))
 		),
-		Rvals = [CallRval, ModuleRval, FromFullRval, DeclRval],
-		ArgTypes = initial([2 - yes(data_ptr), 2 - yes(int_least16)],
+		( MaybeTrailSlot = yes(TrailSlot) ->
+			TrailRval = yes(const(int_const(TrailSlot)))
+		;
+			TrailRval = yes(const(int_const(-1)))
+		),
+		Rvals = [CallRval, ModuleRval,
+			FromFullRval, DeclRval, TrailRval],
+		ArgTypes = initial([2 - yes(data_ptr), 3 - yes(int_least16)],
 			none)
 	;
 		% Indicate the absence of the trace layout fields.
@@ -980,15 +986,15 @@
 
 %---------------------------------------------------------------------------%
 
-	% The constants and representations here should be kept in sync
-	% with runtime/mercury_stack_layout.h, which contains structure
-	% definitions and macros to access the data structures we build here.
-
-	% Construct a representation of a live_value_type without the name.
+	% Construct a representation of the type of a value.
+	%
+	% For values representing variables, this will be a pseudo_type_info
+	% describing the type of the variable.
 	%
-	% Low integers for special values, a pointer for other values.
-	% (Remember to keep the low integers below the max varint value in
-	% runtime/mercury_type_info.h).
+	% For the kinds of values used internally by the compiler,
+	% this will be a pointer to a specific type_ctor_info (acting as a
+	% type_info) defined by hand in builtin.m to stand for values of
+	% each such kind; one for succips, one for hps, etc.
 
 :- pred stack_layout__represent_live_value_type(live_value_type, rval,
 	llds_type, stack_layout_info, stack_layout_info).
@@ -1016,6 +1022,14 @@
 	{ Rval = const(AddrConst) }.
 stack_layout__represent_live_value_type(redoip, Rval, data_ptr) -->
 	{ TypeCtor = type_ctor(info, "redoip", 0) },
+	{ AddrConst = data_addr_const(data_addr(unqualified(""), TypeCtor)) },
+	{ Rval = const(AddrConst) }.
+stack_layout__represent_live_value_type(trail_ptr, Rval, data_ptr) -->
+	{ TypeCtor = type_ctor(info, "trail_ptr", 0) },
+	{ AddrConst = data_addr_const(data_addr(unqualified(""), TypeCtor)) },
+	{ Rval = const(AddrConst) }.
+stack_layout__represent_live_value_type(ticket, Rval, data_ptr) -->
+	{ TypeCtor = type_ctor(info, "ticket", 0) },
 	{ AddrConst = data_addr_const(data_addr(unqualified(""), TypeCtor)) },
 	{ Rval = const(AddrConst) }.
 stack_layout__represent_live_value_type(unwanted, Rval, data_ptr) -->
Index: compiler/trace.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/trace.m,v
retrieving revision 1.23
diff -u -b -r1.23 trace.m
--- trace.m	1999/09/20 08:16:56	1.23
+++ trace.m	1999/09/27 09:25:58
@@ -81,11 +81,20 @@
 					% value of the from-full flag at call.
 					% Otherwise, it will be no.
 
-			maybe(int)	% If --trace-decl is set, this will
+			maybe(int),	% If --trace-decl is set, this will
 					% be yes(M), where stack slots M
 					% and M+1 are reserved for the runtime
 					% system to use in building proof
 					% trees for the declarative debugger.
+					% Otherwise, it will be no.
+
+			maybe(int)	% If --use-trail is set, this will
+					% be yes(M), where stack slots M
+					% and M+1 are the slots that hold the
+					% saved values of the trail pointer
+					% and the ticket counter respectively
+					% at the time of the call. Otherwise,
+					% it will be no.
 		).
 
 	% Return the set of input variables whose values should be preserved
@@ -196,7 +205,7 @@
 	).
 
 	% trace__reserved_slots and trace__setup cooperate in the allocation
-	% of stack slots for tracing purposes. The allocation is done in four
+	% of stack slots for tracing purposes. The allocation is done in five
 	% stages.
 	%
 	% stage 1:	Allocate the fixed slots, slots 1, 2 and 3, to hold
@@ -209,12 +218,25 @@
 	%
 	% stage 3:	If the procedure is shallow traced, allocate the
 	%		next available slot to the saved copy of the
-	%		from-full flag.
+	%		from-full flag. The number of this slot is recorded
+	%		in the maybe_from_full field in the proc layout;
+	%		if there is no such slot, that field will contain -1.
 	%
 	% stage 4:	If --trace-decl is given, allocate the next two
 	%		available slots to hold the pointers to the proof tree
 	%		node of the parent and of this call respectively.
+	%		The number of the first of these two slots is recorded
+	%		in the maybe_decl_debug field in the proc layout;
+	%		if there are no such slots, that field will contain -1.
 	%
+	% stage 5:	If --use-trail is set (given or implied), allocate
+	%		two slots to hold the saved value of the trail pointer
+	%		and the ticket counter at the point of the call, for
+	%		use in implementing retry. The number of the first of
+	%		these two slots is recorded in the maybe_trail field
+	%		in the proc layout; if there are no such slots, that
+	%		field will contain -1.
+	%
 	% The runtime system cannot know whether the stack frame has a slot
 	% that holds the saved from-full flag and whether it has the slots
 	% for the proof tree. This is why trace__setup returns TraceSlotInfo,
@@ -263,8 +285,15 @@
 			DeclDebug = 2
 		;
 			DeclDebug = 0
+		),
+		globals__lookup_bool_option(Globals, use_trail, UseTrail),
+		( UseTrail = yes ->
+			Trail = 2
+		;
+			Trail = 0
 		),
-		ReservedSlots is Fixed + RedoLayout + FromFull + DeclDebug
+		ReservedSlots is Fixed + RedoLayout + FromFull + DeclDebug +
+			Trail
 	).
 
 trace__setup(Globals, TraceSlotInfo, TraceInfo) -->
@@ -302,12 +331,29 @@
 		TraceInternal = no
 	},
 	{ globals__lookup_bool_option(Globals, trace_decl, yes) ->
-		MaybeDeclSlots = yes(NextSlotAfterFromFull)
+		MaybeDeclSlots = yes(NextSlotAfterFromFull),
+		NextSlotAfterDecl = NextSlotAfterFromFull + 2
 	;
-		MaybeDeclSlots = no
+		MaybeDeclSlots = no,
+		NextSlotAfterDecl = NextSlotAfterFromFull
 	},
-	{ TraceSlotInfo = trace_slot_info(MaybeFromFullSlot, MaybeDeclSlots) },
-	{ init_trace_info(TraceType, TraceInternal, TraceDecl,
+	{ globals__lookup_bool_option(Globals, use_trail, yes) ->
+		MaybeTrailSlot = yes(NextSlotAfterDecl),
+		( CodeModel = model_non ->
+			TrailLval =  framevar(NextSlotAfterDecl),
+			TicketLval = framevar(NextSlotAfterDecl+1)
+		;
+			TrailLval =  stackvar(NextSlotAfterDecl),
+			TicketLval = stackvar(NextSlotAfterDecl+1)
+		),
+		MaybeTrailLvals = yes(TrailLval - TicketLval)
+	;
+		MaybeTrailSlot = no,
+		MaybeTrailLvals = no
+	},
+	{ TraceSlotInfo = trace_slot_info(MaybeFromFullSlot,
+		MaybeDeclSlots, MaybeTrailSlot) },
+	{ init_trace_info(TraceType, TraceInternal, TraceDecl, MaybeTrailLvals,
 		MaybeRedoLayout, TraceInfo) }.
 
 trace__generate_slot_fill_code(TraceInfo, TraceCode) -->
@@ -315,6 +361,7 @@
 	{
 	trace_info_get_trace_type(TraceInfo, TraceType),
 	trace_info_get_maybe_redo_layout_slot(TraceInfo, MaybeRedoLayoutSlot),
+	trace_info_get_maybe_trail_slots(TraceInfo, MaybeTrailLvals),
 	trace__event_num_slot(CodeModel, EventNumLval),
 	trace__call_num_slot(CodeModel, CallNumLval),
 	trace__call_depth_slot(CodeModel, CallDepthLval),
@@ -340,20 +387,37 @@
 		FillFourSlots = FillThreeSlots
 	),
 	(
+		% This could be done by generating proper LLDS instead of C.
+		% However, in shallow traced code we want to execute this
+		% only when the caller is deep traced, and everything inside
+		% that test must be in C code.
+		MaybeTrailLvals = yes(TrailLval - TicketLval),
+		trace__stackref_to_string(TrailLval, TrailLvalStr),
+		trace__stackref_to_string(TicketLval, TicketLvalStr),
+		string__append_list([
+			FillFourSlots, "\n",
+			"\t\tMR_mark_ticket_stack(", TicketLvalStr, ");\n",
+			"\t\tMR_store_ticket(", TrailLvalStr, ");"
+		], FillAllSlots)
+	;
+		MaybeTrailLvals = no,
+		FillAllSlots = FillFourSlots
+	),
+	(
 		TraceType = shallow_trace(CallFromFullSlot),
 		trace__stackref_to_string(CallFromFullSlot,
 			CallFromFullSlotStr),
 		string__append_list([
 			"\t\t", CallFromFullSlotStr, " = MR_trace_from_full;\n",
 			"\t\tif (MR_trace_from_full) {\n",
-			FillFourSlots, "\n",
+			FillAllSlots, "\n",
 			"\t\t} else {\n",
 			"\t\t\t", CallDepthStr, " = MR_trace_call_depth;\n",
 			"\t\t}"
 		], TraceStmt)
 	;
 		TraceType = deep_trace,
-		TraceStmt = FillFourSlots
+		TraceStmt = FillAllSlots
 	),
 	TraceCode = node([
 		pragma_c([], [pragma_c_raw_code(TraceStmt)],
@@ -463,7 +527,7 @@
 	code_info__get_maybe_trace_info(MaybeTraceInfo),
 	(
 		{ MaybeTraceInfo = yes(TraceInfo) },
-		{ TraceInfo = trace_info(_, yes, _, _) }
+		{ trace_info_get_trace_internal(TraceInfo, yes) }
 	->
 		{ trace__convert_nondet_pragma_port_type(PragmaPort, Port) },
 		trace__generate_event_code(Port, nondet_pragma, TraceInfo,
@@ -486,7 +550,8 @@
 		Code) -->
 	(
 		{ Port = fail },
-		{ TraceInfo = trace_info(_, _, _, yes(RedoLabel)) }
+		{ trace_info_get_maybe_redo_layout_slot(TraceInfo,
+			yes(RedoLabel)) }
 	->
 		% The layout information for the redo event is the same as
 		% for the fail event; all the non-clobbered inputs in their
@@ -592,8 +657,9 @@
 	}.
 
 trace__maybe_setup_redo_event(TraceInfo, Code) :-
-	TraceInfo = trace_info(TraceType, _, _, TraceRedo),
-	( TraceRedo = yes(_) ->
+	trace_info_get_maybe_redo_layout_slot(TraceInfo, TraceRedoLayout),
+	( TraceRedoLayout = yes(_) ->
+		trace_info_get_trace_type(TraceInfo, TraceType),
 		(
 			TraceType = shallow_trace(Lval),
 			% The code in the runtime looks for the from-full
@@ -790,6 +856,11 @@
 					% from-full flag.
 			bool,		% The value of --trace-internal.
 			bool,		% The value of --trace-decl.
+			maybe(pair(lval)),
+					% If trailing is enabled, the lvals
+					% of the slots that hold the value
+					% of the trail pointer and the ticket
+					% counter at the time of the call.
 			maybe(label)	% If we are generating redo events,
 					% this has the label associated with
 					% the fail event, which we then reserve
@@ -800,22 +871,27 @@
 					% two events have identical layouts).
 		).
 
-:- pred init_trace_info(trace_type::in, bool::in, bool::in, maybe(label)::in,
-	trace_info::out) is det.
+:- pred init_trace_info(trace_type::in, bool::in, bool::in,
+	maybe(pair(lval))::in, maybe(label)::in, trace_info::out) is det.
 
 :- pred trace_info_get_trace_type(trace_info::in, trace_type::out) is det.
 :- pred trace_info_get_trace_internal(trace_info::in, bool::out) is det.
 :- pred trace_info_get_trace_decl(trace_info::in, bool::out) is det.
+:- pred trace_info_get_maybe_trail_slots(trace_info::in,
+	maybe(pair(lval))::out) is det.
 :- pred trace_info_get_maybe_redo_layout_slot(trace_info::in,
 	maybe(label)::out) is det.
 
 init_trace_info(TraceType, TraceInternal, TraceDecl,
-	MaybeRedoLayoutSlot,
-	trace_info(TraceType, TraceInternal, TraceDecl, MaybeRedoLayoutSlot)).
+	MaybeTrailSlot, MaybeRedoLayoutSlot,
+	trace_info(TraceType, TraceInternal, TraceDecl,
+		MaybeTrailSlot, MaybeRedoLayoutSlot)).
 
-trace_info_get_trace_type(trace_info(TraceType, _, _, _), TraceType).
-trace_info_get_trace_internal(trace_info(_, TraceInternal, _, _),
+trace_info_get_trace_type(trace_info(TraceType, _, _, _, _), TraceType).
+trace_info_get_trace_internal(trace_info(_, TraceInternal, _, _, _),
 	TraceInternal).
-trace_info_get_trace_decl(trace_info(_, _, TraceDecl, _), TraceDecl).
-trace_info_get_maybe_redo_layout_slot(trace_info(_, _, _, MaybeRedoLayoutSlot),
-	MaybeRedoLayoutSlot).
+trace_info_get_trace_decl(trace_info(_, _, TraceDecl, _, _), TraceDecl).
+trace_info_get_maybe_trail_slots(trace_info(_, _, _, MaybesTrailSlot, _),
+	MaybesTrailSlot).
+trace_info_get_maybe_redo_layout_slot(trace_info(_, _, _, _,
+	MaybeRedoLayoutSlot), MaybeRedoLayoutSlot).
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/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
cvs diff: Diffing library
Index: library/builtin.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/builtin.m,v
retrieving revision 1.20
diff -u -b -r1.20 builtin.m
--- builtin.m	1999/09/27 05:20:31	1.20
+++ builtin.m	1999/10/05 02:51:56
@@ -358,6 +358,26 @@
 
 #endif /* NATIVE_GC */
 
+	/* type_ctor_layout for `trail ptr' (only used by agc and debugger) */
+
+MR_MODULE_STATIC_OR_EXTERN
+const struct mercury_data___type_ctor_layout_trail_ptr_0_struct {
+	TYPE_LAYOUT_FIELDS
+} mercury_data___type_ctor_layout_trail_ptr_0 = {
+	make_typelayout_for_all_tags(TYPE_CTOR_LAYOUT_CONST_TAG, 
+		mkbody(MR_TYPE_CTOR_LAYOUT_TRAIL_PTR_VALUE))
+};
+
+	/* type_ctor_layout for `ticket' (only used by agc and debugger) */
+
+MR_MODULE_STATIC_OR_EXTERN
+const struct mercury_data___type_ctor_layout_ticket_0_struct {
+	TYPE_LAYOUT_FIELDS
+} mercury_data___type_ctor_layout_ticket_0 = {
+	make_typelayout_for_all_tags(TYPE_CTOR_LAYOUT_CONST_TAG, 
+		mkbody(MR_TYPE_CTOR_LAYOUT_TICKET_VALUE))
+};
+
 	/* type_ctor_functors definitions */
 
 	/* type_ctor_functors for `int' */
@@ -463,6 +483,24 @@
 
 #endif /* NATIVE_GC */
 
+	/* type_ctor_functors for `trail ptr' (only used by agc and debugger) */
+
+MR_MODULE_STATIC_OR_EXTERN
+const struct mercury_data___type_ctor_functors_trail_ptr_0_struct {
+	Integer f1;
+} mercury_data___type_ctor_functors_trail_ptr_0 = {
+	MR_TYPE_CTOR_FUNCTORS_SPECIAL
+};
+
+	/* type_ctor_functors for `ticket' (only used by agc and debugger) */
+
+MR_MODULE_STATIC_OR_EXTERN
+const struct mercury_data___type_ctor_functors_ticket_0_struct {
+	Integer f1;
+} mercury_data___type_ctor_functors_ticket_0 = {
+	MR_TYPE_CTOR_FUNCTORS_SPECIAL
+};
+
 	/* type_ctor_infos definitions */
 
 	/* type_ctor_info for `int' */
@@ -564,9 +602,9 @@
 	MR_MAYBE_STATIC_CODE(ENTRY(mercury__unused_0_0)),
 	MR_MAYBE_STATIC_CODE(ENTRY(mercury__unused_0_0)),
 	MR_MAYBE_STATIC_CODE(ENTRY(mercury__unused_0_0)),
-	(const Word *) & mercury_data___type_ctor_layout_succip_0,
-	(const Word *) & mercury_data___type_ctor_functors_succip_0,
-	(const Word *) & mercury_data___type_ctor_layout_succip_0,
+	MR_TYPECTOR_REP_SUCCIP,
+	(MR_TypeCtorFunctors) & mercury_data___type_ctor_functors_succip_0,
+	(MR_TypeCtorLayout) & mercury_data___type_ctor_layout_succip_0,
 	string_const(""builtin"", 7),
 	string_const(""succip"", 6)
 };
@@ -580,9 +618,9 @@
 	MR_MAYBE_STATIC_CODE(ENTRY(mercury__unused_0_0)),
 	MR_MAYBE_STATIC_CODE(ENTRY(mercury__unused_0_0)),
 	MR_MAYBE_STATIC_CODE(ENTRY(mercury__unused_0_0)),
-	(const Word *) & mercury_data___type_ctor_layout_hp_0,
-	(const Word *) & mercury_data___type_ctor_functors_hp_0,
-	(const Word *) & mercury_data___type_ctor_layout_hp_0,
+	MR_TYPECTOR_REP_HP,
+	(MR_TypeCtorFunctors) & mercury_data___type_ctor_functors_hp_0,
+	(MR_TypeCtorLayout) & mercury_data___type_ctor_layout_hp_0,
 	string_const(""builtin"", 7),
 	string_const(""hp"", 2)
 };
@@ -596,9 +634,9 @@
 	MR_MAYBE_STATIC_CODE(ENTRY(mercury__unused_0_0)),
 	MR_MAYBE_STATIC_CODE(ENTRY(mercury__unused_0_0)),
 	MR_MAYBE_STATIC_CODE(ENTRY(mercury__unused_0_0)),
-	(const Word *) & mercury_data___type_ctor_layout_curfr_0,
-	(const Word *) & mercury_data___type_ctor_functors_curfr_0,
-	(const Word *) & mercury_data___type_ctor_layout_curfr_0,
+	MR_TYPECTOR_REP_CURFR,
+	(MR_TypeCtorFunctors) & mercury_data___type_ctor_functors_curfr_0,
+	(MR_TypeCtorLayout) & mercury_data___type_ctor_layout_curfr_0,
 	string_const(""builtin"", 7),
 	string_const(""curfr"", 5)
 };
@@ -612,13 +650,29 @@
 	MR_MAYBE_STATIC_CODE(ENTRY(mercury__unused_0_0)),
 	MR_MAYBE_STATIC_CODE(ENTRY(mercury__unused_0_0)),
 	MR_MAYBE_STATIC_CODE(ENTRY(mercury__unused_0_0)),
-	(const Word *) & mercury_data___type_ctor_layout_maxfr_0,
-	(const Word *) & mercury_data___type_ctor_functors_maxfr_0,
-	(const Word *) & mercury_data___type_ctor_layout_maxfr_0,
+	MR_TYPECTOR_REP_MAXFR,
+	(MR_TypeCtorFunctors) & mercury_data___type_ctor_functors_maxfr_0,
+	(MR_TypeCtorLayout) & mercury_data___type_ctor_layout_maxfr_0,
 	string_const(""builtin"", 7),
 	string_const(""maxfr"", 5)
 };
 
+	/* type_ctor_info for `redofr' (only used by accurate gc) */
+
+Declare_entry(mercury__unused_0_0);
+MR_STATIC_CODE_CONST struct MR_TypeCtorInfo_struct
+mercury_data___type_ctor_info_redofr_0 = {
+	((Integer) 0),
+	MR_MAYBE_STATIC_CODE(ENTRY(mercury__unused_0_0)),
+	MR_MAYBE_STATIC_CODE(ENTRY(mercury__unused_0_0)),
+	MR_MAYBE_STATIC_CODE(ENTRY(mercury__unused_0_0)),
+	MR_TYPECTOR_REP_REDOFR,
+	(MR_TypeCtorFunctors) & mercury_data___type_ctor_functors_redofr_0,
+	(MR_TypeCtorLayout) & mercury_data___type_ctor_layout_redofr_0,
+	string_const(""builtin"", 7),
+	string_const(""redofr"", 6)
+};
+
 	/* type_ctor_info for `redoip' (only used by accurate gc) */
 
 Declare_entry(mercury__unused_0_0);
@@ -628,30 +682,46 @@
 	MR_MAYBE_STATIC_CODE(ENTRY(mercury__unused_0_0)),
 	MR_MAYBE_STATIC_CODE(ENTRY(mercury__unused_0_0)),
 	MR_MAYBE_STATIC_CODE(ENTRY(mercury__unused_0_0)),
-	(const Word *) & mercury_data___type_ctor_layout_redoip_0,
-	(const Word *) & mercury_data___type_ctor_functors_redoip_0,
-	(const Word *) & mercury_data___type_ctor_layout_redoip_0,
+	MR_TYPECTOR_REP_REDOIP,
+	(MR_TypeCtorFunctors) & mercury_data___type_ctor_functors_redoip_0,
+	(MR_TypeCtorLayout) & mercury_data___type_ctor_layout_redoip_0,
 	string_const(""builtin"", 7),
 	string_const(""redoip"", 6)
 };
 
-	/* type_ctor_info for `redofr' (only used by accurate gc) */
+#endif /* NATIVE_GC */
+
+	/* type_ctor_info for `trai ptr' (only used by agc and debugger) */
 
 Declare_entry(mercury__unused_0_0);
 MR_STATIC_CODE_CONST struct MR_TypeCtorInfo_struct
-mercury_data___type_ctor_info_redofr_0 = {
+mercury_data___type_ctor_info_trail_ptr_0 = {
 	((Integer) 0),
 	MR_MAYBE_STATIC_CODE(ENTRY(mercury__unused_0_0)),
 	MR_MAYBE_STATIC_CODE(ENTRY(mercury__unused_0_0)),
 	MR_MAYBE_STATIC_CODE(ENTRY(mercury__unused_0_0)),
-	(const Word *) & mercury_data___type_ctor_layout_redofr_0,
-	(const Word *) & mercury_data___type_ctor_functors_redofr_0,
-	(const Word *) & mercury_data___type_ctor_layout_redofr_0,
+	MR_TYPECTOR_REP_TRAIL_PTR,
+	(MR_TypeCtorFunctors) & mercury_data___type_ctor_functors_trail_ptr_0,
+	(MR_TypeCtorLayout) & mercury_data___type_ctor_layout_trail_ptr_0,
 	string_const(""builtin"", 7),
-	string_const(""redofr"", 6)
+	string_const(""trail_ptr"", 9)
 };
 
-#endif /* NATIVE_GC */
+	/* type_ctor_info for `ticket' (only used by agc and debugger) */
+
+Declare_entry(mercury__unused_0_0);
+MR_STATIC_CODE_CONST struct MR_TypeCtorInfo_struct
+mercury_data___type_ctor_info_ticket_0 = {
+	((Integer) 0),
+	MR_MAYBE_STATIC_CODE(ENTRY(mercury__unused_0_0)),
+	MR_MAYBE_STATIC_CODE(ENTRY(mercury__unused_0_0)),
+	MR_MAYBE_STATIC_CODE(ENTRY(mercury__unused_0_0)),
+	MR_TYPECTOR_REP_TICKET,
+	(MR_TypeCtorFunctors) & mercury_data___type_ctor_functors_ticket_0,
+	(MR_TypeCtorLayout) & mercury_data___type_ctor_layout_ticket_0,
+	string_const(""builtin"", 7),
+	string_const(""ticket"", 6)
+};
 
 BEGIN_MODULE(builtin_types_module)
 
@@ -674,7 +744,7 @@
 	** labels for the special preds of int, float, pred, 
 	** character and string. If they aren't initialized,
 	** we might initialize the type_ctor_info with
-	** garbage
+	** garbage.
 	*/
 	mercury__private_builtin__init();
 
Index: library/std_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/std_util.m,v
retrieving revision 1.160
diff -u -b -r1.160 std_util.m
--- std_util.m	1999/09/30 22:07:48	1.160
+++ std_util.m	1999/10/05 02:52:24
@@ -2480,11 +2480,10 @@
 	    */
 	    fatal_error(""ML_expand: cannot expand void types"");
 
-        case MR_TYPECTOR_REP_ARRAY:
+        case MR_TYPECTOR_REP_C_POINTER:
             if (info->need_functor) {
-                make_aligned_string(info->functor, ""<<array>>"");
+                make_aligned_string(info->functor, ""<<c_pointer>>"");
             }
-	    /* XXX should we return the arguments here? */
             info->argument_vector = NULL;
             info->type_info_vector = NULL;
             info->arity = 0;
@@ -2500,9 +2499,92 @@
             info->arity = 0;
             break;
 
-        case MR_TYPECTOR_REP_C_POINTER:
+        case MR_TYPECTOR_REP_TYPECLASSINFO:
             if (info->need_functor) {
-                make_aligned_string(info->functor, ""<<c_pointer>>"");
+                make_aligned_string(info->functor, ""<<typeclassinfo>>"");
+            }
+	    /* XXX should we return the arguments here? */
+            info->argument_vector = NULL;
+            info->type_info_vector = NULL;
+            info->arity = 0;
+            break;
+
+        case MR_TYPECTOR_REP_ARRAY:
+            if (info->need_functor) {
+                make_aligned_string(info->functor, ""<<array>>"");
+            }
+	    /* XXX should we return the arguments here? */
+            info->argument_vector = NULL;
+            info->type_info_vector = NULL;
+            info->arity = 0;
+            break;
+
+        case MR_TYPECTOR_REP_SUCCIP:
+            if (info->need_functor) {
+                make_aligned_string(info->functor, ""<<succip>>"");
+            }
+            info->argument_vector = NULL;
+            info->type_info_vector = NULL;
+            info->arity = 0;
+            break;
+
+        case MR_TYPECTOR_REP_HP:
+            if (info->need_functor) {
+                make_aligned_string(info->functor, ""<<hp>>"");
+            }
+            info->argument_vector = NULL;
+            info->type_info_vector = NULL;
+            info->arity = 0;
+            break;
+
+        case MR_TYPECTOR_REP_CURFR:
+            if (info->need_functor) {
+                make_aligned_string(info->functor, ""<<curfr>>"");
+            }
+            info->argument_vector = NULL;
+            info->type_info_vector = NULL;
+            info->arity = 0;
+            break;
+
+        case MR_TYPECTOR_REP_MAXFR:
+            if (info->need_functor) {
+                make_aligned_string(info->functor, ""<<maxfr>>"");
+            }
+            info->argument_vector = NULL;
+            info->type_info_vector = NULL;
+            info->arity = 0;
+            break;
+
+        case MR_TYPECTOR_REP_REDOFR:
+            if (info->need_functor) {
+                make_aligned_string(info->functor, ""<<redofr>>"");
+            }
+            info->argument_vector = NULL;
+            info->type_info_vector = NULL;
+            info->arity = 0;
+            break;
+
+        case MR_TYPECTOR_REP_REDOIP:
+            if (info->need_functor) {
+                make_aligned_string(info->functor, ""<<redoip>>"");
+            }
+            info->argument_vector = NULL;
+            info->type_info_vector = NULL;
+            info->arity = 0;
+            break;
+
+        case MR_TYPECTOR_REP_TRAIL_PTR:
+            if (info->need_functor) {
+                make_aligned_string(info->functor, ""<<trail_ptr>>"");
+            }
+            info->argument_vector = NULL;
+            info->type_info_vector = NULL;
+            info->arity = 0;
+            break;
+
+        case MR_TYPECTOR_REP_TICKET:
+            if (info->need_functor) {
+                make_aligned_string(info->functor, ""<<ticket>>"");
             }
             info->argument_vector = NULL;
             info->type_info_vector = NULL;
cvs diff: Diffing profiler
cvs diff: Diffing runtime
Index: runtime/mercury_deep_copy_body.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_deep_copy_body.h,v
retrieving revision 1.11
diff -u -b -r1.11 mercury_deep_copy_body.h
--- mercury_deep_copy_body.h	1999/09/27 05:20:43	1.11
+++ mercury_deep_copy_body.h	1999/10/05 02:48:41
@@ -152,7 +152,7 @@
                     lower_limit, upper_limit);
             break;
 
-        case MR_TYPECTOR_REP_INT:
+        case MR_TYPECTOR_REP_INT:  /* fallthru */
         case MR_TYPECTOR_REP_CHAR:
             new_data = data;
             break;
@@ -315,6 +315,29 @@
             }
             break;
             
+        case MR_TYPECTOR_REP_SUCCIP: /* fallthru */
+        case MR_TYPECTOR_REP_REDOIP:
+	    /* code addresses are never relocated */
+            new_data = data;
+            break;
+
+        case MR_TYPECTOR_REP_HP:
+            fatal_error("Tyson hasn't yet moved the code"
+			    "for copying saved heap pointers here");
+            break;
+
+        case MR_TYPECTOR_REP_CURFR: /* fallthru */
+        case MR_TYPECTOR_REP_MAXFR:
+	    /* we do not modify the layout of the nondet stack */
+            new_data = data;
+            break;
+
+        case MR_TYPECTOR_REP_TRAIL_PTR:
+        case MR_TYPECTOR_REP_TICKET:
+	    /* we do not yet compress the trail when doing gc */
+            new_data = data;
+            break;
+
         case MR_TYPECTOR_REP_UNKNOWN: /* fallthru */
         default:
             fatal_error("Unknown layout type in deep copy");
Index: runtime/mercury_stack_layout.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_stack_layout.h,v
retrieving revision 1.27
diff -u -b -r1.27 mercury_stack_layout.h
--- mercury_stack_layout.h	1999/08/24 09:40:39	1.27
+++ mercury_stack_layout.h	1999/09/27 03:33:51
@@ -366,6 +366,7 @@
 				*MR_sle_module_layout;
 	MR_int_least16_t	MR_sle_maybe_from_full;
 	MR_int_least16_t	MR_sle_maybe_decl_debug;
+	MR_int_least16_t	MR_sle_maybe_trail;
 } MR_Stack_Layout_Entry;
 
 #define	MR_sle_user	MR_sle_proc_id.MR_proc_user
Index: runtime/mercury_tabling.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_tabling.c,v
retrieving revision 1.11
diff -u -b -r1.11 mercury_tabling.c
--- mercury_tabling.c	1999/09/27 05:20:49	1.11
+++ mercury_tabling.c	1999/10/05 02:48:16
@@ -642,6 +642,18 @@
             fatal_error("Cannot table a void type");
             break;
 
+        case MR_TYPECTOR_REP_C_POINTER:
+            fatal_error("Attempt to table a C_POINTER");
+            break;
+
+        case MR_TYPECTOR_REP_TYPEINFO:
+            MR_DEBUG_TABLE_TYPEINFO(table, (Word *) data_value);
+            break;
+
+        case MR_TYPECTOR_REP_TYPECLASSINFO:
+            fatal_error("Attempt to table a type_class_info");
+            break;
+
         case MR_TYPECTOR_REP_ARRAY: {
             int i;
             MR_ArrayType *array;
@@ -659,12 +671,37 @@
             }
             break;
         }
-        case MR_TYPECTOR_REP_TYPEINFO:
-            MR_DEBUG_TABLE_TYPEINFO(table, (Word *) data_value);
+
+        case MR_TYPECTOR_REP_SUCCIP:
+            fatal_error("Attempt to table a saved succip");
             break;
 
-        case MR_TYPECTOR_REP_C_POINTER:
-            fatal_error("Attempt to use a C_POINTER tag in table");
+        case MR_TYPECTOR_REP_HP:
+            fatal_error("Attempt to table a saved hp");
+            break;
+
+        case MR_TYPECTOR_REP_CURFR:
+            fatal_error("Attempt to table a saved curfr");
+            break;
+
+        case MR_TYPECTOR_REP_MAXFR:
+            fatal_error("Attempt to table a saved maxfr");
+            break;
+
+        case MR_TYPECTOR_REP_REDOFR:
+            fatal_error("Attempt to table a saved redofr");
+            break;
+
+        case MR_TYPECTOR_REP_REDOIP:
+            fatal_error("Attempt to table a saved redoip");
+            break;
+
+        case MR_TYPECTOR_REP_TRAIL_PTR:
+            fatal_error("Attempt to table a saved trail pointer");
+            break;
+
+        case MR_TYPECTOR_REP_TICKET:
+            fatal_error("Attempt to table a saved ticket");
             break;
 
         case MR_TYPECTOR_REP_UNKNOWN: /* fallthru */
Index: runtime/mercury_trail.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_trail.c,v
retrieving revision 1.7
diff -u -b -r1.7 mercury_trail.c
--- mercury_trail.c	1999/03/10 22:05:25	1.7
+++ mercury_trail.c	1999/09/14 07:38:51
@@ -54,6 +54,7 @@
 	    break;
 	case MR_undo:
 	case MR_exception:
+	case MR_retry:
 	    /* Handle both function and value trail entries */
 	    while (tr_ptr != old_trail_ptr) {
 		tr_ptr--;
Index: runtime/mercury_trail.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_trail.h,v
retrieving revision 1.16
diff -u -b -r1.16 mercury_trail.h
--- mercury_trail.h	1999/09/29 04:48:05	1.16
+++ mercury_trail.h	1999/09/29 05:20:32
@@ -32,16 +32,18 @@
 ** MR_store_ticket()
 **	called when creating a choice point, or before a commit
 ** MR_reset_ticket()
-**	called when resuming forward execution after failing (MR_undo),
-**	or after a commit (MR_commit), or after a "soft commit"
-**	[one that doesn't prune away all the alternative solutions,
-**	but which does require us to commit to this goal being solvable]
-**	in an if-then-else with a nondet condition, or in solutions/2
-**	(MR_solve).
+**	called under the following circumstances, with different parameters:
+**	- when resuming forward execution after failing (MR_undo);
+**	- after a commit (MR_commit);
+**	- after a "soft commit" [one that doesn't prune away all the
+**	  alternative solutions, but which does require us to commit to
+**	  this goal being solvable] in an if-then-else with a nondet condition,
+**	  or in solutions/2 (MR_solve);
+**	- when executing a `retry' command in the debugger (MR_retry).
 ** MR_discard_ticket()
 **	called when cutting away or failing over the topmost choice point
 ** MR_mark_ticket_stack()
-**	called before a commit
+**	called before a commit, and when entering an execution traced procedure
 ** MR_discard_tickets_to()
 **	called after a commit
 */
@@ -145,6 +147,14 @@
 	** choose to behave differently for exceptions than for failure.
 	*/
 	MR_exception,  
+
+	/*
+	** MR_retry:
+	** A `retry' command was executed in the debugger.
+	** Behaves as MR_undo, except that function trail entries may
+	** choose to behave differently for retries than for failure.
+	*/
+	MR_retry,  
 
 	/*
 	** MR_gc:
Index: runtime/mercury_type_info.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_type_info.h,v
retrieving revision 1.26
diff -u -b -r1.26 mercury_type_info.h
--- mercury_type_info.h	1999/09/30 08:09:03	1.26
+++ mercury_type_info.h	1999/10/05 02:47:19
@@ -201,6 +201,8 @@
 ** Changes in this type may need to be reflected in
 ** compiler/base_type_layout.m.
 **
+** XXX Much of the information in this type is now stored in TypeCtorRep;
+** it is here only temporarily.
 */
 
 enum MR_TypeLayoutValue {
@@ -220,7 +222,7 @@
 		/*
 		** The following enum values represent the "types" of
 		** of values stored in lvals that the garbage collector
-		** needs to know about.
+		** and/or the debugger need to know about.
 		*/
 	MR_TYPE_CTOR_LAYOUT_SUCCIP_VALUE,
 	MR_TYPE_CTOR_LAYOUT_HP_VALUE,
@@ -228,6 +230,8 @@
 	MR_TYPE_CTOR_LAYOUT_MAXFR_VALUE,
 	MR_TYPE_CTOR_LAYOUT_REDOFR_VALUE,
 	MR_TYPE_CTOR_LAYOUT_REDOIP_VALUE,
+	MR_TYPE_CTOR_LAYOUT_TRAIL_PTR_VALUE,
+	MR_TYPE_CTOR_LAYOUT_TICKET_VALUE,
 	MR_TYPE_CTOR_LAYOUT_UNWANTED_VALUE
 };
 
@@ -758,6 +762,14 @@
 	MR_TYPECTOR_REP_TYPEINFO,
 	MR_TYPECTOR_REP_TYPECLASSINFO,
 	MR_TYPECTOR_REP_ARRAY,
+	MR_TYPECTOR_REP_SUCCIP,
+	MR_TYPECTOR_REP_HP,
+	MR_TYPECTOR_REP_CURFR,
+	MR_TYPECTOR_REP_MAXFR,
+	MR_TYPECTOR_REP_REDOFR,
+	MR_TYPECTOR_REP_REDOIP,
+	MR_TYPECTOR_REP_TRAIL_PTR,
+	MR_TYPECTOR_REP_TICKET,
 	MR_TYPECTOR_REP_UNKNOWN
 } MR_TypeCtorRepresentation;
 
@@ -781,6 +793,7 @@
 
 /*---------------------------------------------------------------------------*/
 
+/* XXX these typedefs should include const [zs, 14 Sep 1999] */
 typedef	Word *	MR_TypeCtorFunctors;
 typedef	Word *	MR_TypeCtorLayout;
 
@@ -797,7 +810,7 @@
 	Code				*index_pred;
 	Code				*compare_pred;
 		/* 
-		** The representation that is used for this
+		** The representation that is used for this type
 		** constructor -- e.g. an enumeration, or a builtin
 		** type, or a no-tag type, etc.
 		*/
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 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/hard_coded
cvs diff: Diffing tests/hard_coded/exceptions
cvs diff: Diffing tests/hard_coded/sub-modules
cvs diff: Diffing tests/hard_coded/typeclasses
cvs diff: Diffing tests/invalid
cvs diff: Diffing tests/misc_tests
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.12
diff -u -b -r1.12 mercury_trace.c
--- mercury_trace.c	1999/09/15 17:53:41	1.12
+++ mercury_trace.c	1999/09/30 06:40:05
@@ -384,6 +384,22 @@
 				MR_LONG_LVAL_NUMBER(location));
 		MR_saved_sp(saved_regs) -= entry->MR_sle_stack_slots;
 		MR_trace_event_number = MR_event_num_stackvar(this_frame);
+
+#ifdef	MR_USE_TRAIL
+		if (entry->MR_sle_maybe_trail >= 0) {
+			Word	ticket_counter;
+			Word	trail_ptr;
+
+			trail_ptr = MR_based_stackvar(this_frame,
+					entry->MR_sle_maybe_trail);
+			ticket_counter = MR_based_stackvar(this_frame,
+					entry->MR_sle_maybe_trail+1);
+			MR_reset_ticket(trail_ptr, MR_retry);
+			MR_discard_tickets_to(ticket_counter);
+		} else {
+			fatal_error("retry cannot restore the trail");
+		}
+#endif
 	} else {
 		Word	*this_frame;
 
@@ -400,6 +416,22 @@
 		MR_saved_curfr(saved_regs) = MR_succfr_slot(this_frame);
 		MR_saved_maxfr(saved_regs) = MR_prevfr_slot(this_frame);
 		MR_trace_event_number = MR_event_num_framevar(this_frame);
+
+#ifdef	MR_USE_TRAIL
+		if (entry->MR_sle_maybe_trail >= 0) {
+			Word	ticket_counter;
+			Word	trail_ptr;
+
+			trail_ptr = MR_based_framevar(this_frame,
+					entry->MR_sle_maybe_trail);
+			ticket_counter = MR_based_framevar(this_frame,
+					entry->MR_sle_maybe_trail+1);
+			MR_reset_ticket(trail_ptr, MR_retry);
+			MR_discard_tickets_to(ticket_counter);
+		} else {
+			fatal_error("retry cannot restore the trail");
+		}
+#endif
 	}
 
 	for (i = 1; i < arg_max; i++) {
cvs diff: Diffing trial
cvs diff: Diffing util
--------------------------------------------------------------------------
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