Commit Graph

60 Commits

Author SHA1 Message Date
Fergus Henderson
8b0dcbb231 Various fixes to get the GCC back-end interface to bootstrap.
Estimated hours taken: 20

Various fixes to get the GCC back-end interface to bootstrap.

library/exception.m:
	Define function versions of mercury__exception__builtin_catch_3_p_*.
	This is needed (a) in case we take their address, and (b) for the
	GCC back-end interface, where we can't use C macros, since we're
	compiling to assembler.

browser/dl.m:
browser/util.m:
browser/interactive_query.m:
compiler/stack_layout.m:
	Add #includes for header files needed by these modules.

browser/dl.m:
	Delete an unnecessary nested extern declaration, to avoid
	a warning from `gcc -Wshadow'.

compiler/mlds_to_gcc.m:
	When calling mlds_to_c to process foreign_code, make all
	definitions public, so that the can be used from the assembler
	code that we generate in mlds_to_gcc.

	Don't call mlds_to_c to generate `.c' and `.h' files if the
	module contains only `pragma foreign_decls', not `pragma
	foreign_code', `pragma foreign_proc', or `pragma export'.
	This change is needed to avoid calling mlds_to_c when
	intermodule optimization is enabled and `pragma c_header_code'
	declarations have been read in from the `.opt' file and have
	propagated through to the MLDS.  Calling mlds_to_c when the
	module itself doesn't contain C code breaks things, since
	Mmake won't compile and link in the generated `.c' files, but
	those files contain the definition of the `*__init_type_tables()'
	functions that are referenced by `*_init.c'.

	XXX This is not quite right, since if the module itself contains
	`pragma foreign_decls', the `.h' file might be needed.
	But the Mercury standard library needs intermodule optimization
	enabled for `make install' to work.
	A better fix would be to ignore foreign_decls that were defined
	in other modules, but to call mlds_to_c for foreign_decls
	that were defined in the module that we're compiling.

compiler/modules.m:
	Change the code which decides when to link in extra object files
	for foreign code to reflect the above change to when mlds_to_gcc.m
	invokes mlds_to_c.m.

compiler/mlds_to_c.m:
	When target=asm, i.e. we're compiling to asm, but mlds_to_c.m
	has been invoked to generate C code for a `foreign_code',
	`foreign_proc', or `pragma export' declaration, don't generate
	#include directives for the imported modules, since we may not
	have generated any header file for them.

	XXX This is a bit of a hack; it might sometimes lead to
	problems, since the header files might sometimes be needed.
	But including them unconditionally is definitely wrong,
	since they may not exist, and so this change is needed to get
	the compiler to bootstrap.

compiler/Mmakefile:
	Add a dependency of mercury_compile on $(GCC_BACK_END_LIBS),
	so that we know to relink it if the GCC back-end has changed.
	(That variable is set to empty if we're not linking in the GCC
	back-end, so it won't cause problems when not using the GCC
	back-end.)

library/Mmakefile:
browser/Mmakefile:
compiler/Mmakefile:
	Add an `ss' target, for use by tools/bootcheck.

tools/bootcheck:
	Add `--target asm' option.  If that is set, pass `--target asm'
	to mmake, and build and compare the stage 3 `.s' files rather
	than the `.c' files.

	Also add `--make-opts' option, for passing options to `make'.
	Put `-k' in `--make-opts', not `--mmake-opts', since `-k' is
	an option to `make', not to `mmake'.  This makes a difference
	since although `make' options can be passed to `mmake', any
	options after the first `make' option are assumed to be
	options to `make', not to `mmake'.
2001-01-29 06:47:32 +00:00
Zoltan Somogyi
2498d9d3fd Instead of generating the layout structures of labels, procs and modules
Estimated hours taken: 36

Instead of generating the layout structures of labels, procs and modules
as rvals, generate them almost entirely as C structures. This will make
future modifications much easier, since mismatches between what the runtime
expects and what the compiler generates will now be pointed out by the C
compiler. (It also reduces the size of the C source files generated with
debugging enabled by about 5%.) Layout structures contain a few components
that are not well-typed in C; we continue to generate these as rvals.

Closure layout structures used to have a well-typed part and a non-well-typed
part. We now generate the well-typed part as a separate structure, pointed to
from the other. We also extend the well-typed part, so that instead of
just giving the name the called procedure, it also identifies the source
location where the closure was constructed. This could be useful for
the debugger and for deep profiling.

This diff also includes a change to get the compiler to bootstrap with lcc
in grade none.gc.debug.tr: initializing the string tables in module layouts
not as a string but as an array of characters.

runtime/mercury_stack_layout.h:
	Reorganize the definitions of layout structures. Rename
	Stack_Layout_Entry structures as Proc_Layout structures,
	and Stack_Layout_Label structures as Label_Layout structures.
	(The debugger paper refers to the structures by the new names.)
	Fold the Stack_Layout_Vars structure into the structure that contains
	it, the Label_Layout structure. Add a Closure_Id structure that
	contains a Proc_Id structure as well as extra information identifying
	the source location where the closure was created.

	Create "short" versions of the Proc_Layout structures, which contain
	only the first one or two of the three groups of fields. Previously,
	the Mercury compiler would define new C types when it generated such
	short structures. Since we are not defining new C types anymore, there
	must be a C type for every kind of structure the Mercury compiler can
	generate. We now also have separate variants for the layouts of
	user-defined and compiler-generated procedures, since the format
	of their procedure id information is different. While the runtime
	system refers to their procedure id information through a union,
	the C types of the structures generated by the Mercury compiler
	do not use a union, since a union cannot be initialized through
	its second member.

	Make the constant fields of structures const, since we now generate
	values of those structure types, and initialize them with constant
	data.

	Move the documentation of layout structures here from stack_layout.m.

runtime/mercury_ho_call.h:
	Instead of bodily including an MR_Proc_Id structure in closures,
	include a pointer to the more detailed MR_Closure_Id structure.

runtime/mercury_accurate_gc.c:
runtime/mercury_agc_debug.c:
runtime/mercury_init.h:
runtime/mercury_label.[ch]:
runtime/mercury_layout_util.[ch]:
	Minor updates to conform to changes in mercury_stack_layout.h.

runtime/mercury_goto.h:
	Use separate naming schemes for label layout structures and proc layout
	structures.

library/exception.m:
	Minor updates to conform to changes in mercury_stack_layout.h.

compiler/layout.m:
	A new module that defines data structures for label, proc and module
	layout structures and for closure id structures.

compiler/layout_out.m:
	A new module that converts the Mercury data structures of layout.m into
	declarations and definitions of C data structures.

compiler/stack_layout.m:
	Generate the new layout structures instead of rvals.

	Move the documentation of layout structures from here to
	runtime/mercury_stack_layout.h, since this module is no longer
	aware of some of their details.

compiler/llds.m:
	Make layout structures a separate kind of compiler-generated data.

compiler/llds_out.m:
	Remove the code for the output of layout structures; call layout_out.m
	instead.

compiler/llds_out.m:
compiler/rtti_out.m:
	Turn some predicates into functions.

compiler/code_gen.m:
compiler/code_info.m:
compiler/llds.m:
compiler/mercury_compile.m:
compiler/unify_gen.m:
	Instead of handling closure layouts like other static data, handle
	them separately. Add a counter to the code_info structure in order
	to allow closure id structures to be identified uniquely by a pair
	consisting of the id of the procedure that generates them and a closure
	sequence number within that procedure.

compiler/llds_common.m:
	Look for common rvals among the rvals in layout structures.

compiler/opt_debug.m:
	Generate developer-friendly names for layout structure references.

browser/dl.m:
	Update the code for constructing closure layouts.
2001-01-18 01:19:17 +00:00
Zoltan Somogyi
ebe9f9a3ec Add tabling of I/O actions for the debugger.
Estimated hours taken: 80

Add tabling of I/O actions for the debugger.

compiler/options.m:
	Add a new option, --trace-table-io, that enables the tabling of I/O
	actions, and another, --trace-table-io-states, that governs whether the
	tabling includes the I/O state variables themselves. (You want to table
	these variables iff they contain meaningful information that is not
	stored in global variables.) These options are for developers only
	for now.

compiler/modules.m:
	Implicitly import table_builtin if --trace-table-io is specified.

compiler/prog_data.m:
	Add eval_table_io as a new eval method.

compiler/hlds_pred.m:
	Add a mechanism for checking whether a predicate has an input/output
	pair of io__state args.

	Extend the tables indexed by eval_method to handle eval_table_io.

compiler/hlds_out.m:
	Print the eval method in HLDS dumps.

compiler/table_gen.m:
	If a procedure has a pair of I/O state args and is defined using pragma
	C code that has the tabled_for_io marker, and --trace-table-io is
	specified, then perform I/O tabling on it and mark it as tabled.

compiler/notes/compiler_design.m:
	Document that table_gen.m can now change the evaluation methods of
	procedures (to eval_table_io).

compiler/stack_layout.m:
runtime/mercury_stack_layout.h:
	Add an extra field to proc layouts. If debugging is enabled and a
	procedure has I/O state arguments, this field gives the number of the
	stack slot which will be filled with the I/O action counter at the
	time of the call, so that on retry the debugger can reset the I/O
	action counter to this value.

compiler/trace.m:
	Add code to reserve and fill this stack slot.

	Make the order of fields in the trace_slots structure match the order
	in proc layouts.

compiler/code_info.m:
compiler/live_vars.m:
	Pass a module_info to trace__setup and trace__reserved_slots.

library/io.m:
	Mark the I/O primitives (i.e. procedures that are defined by pragma C
	code and do I/O) with the tabled_for_io feature. (See the discussion
	of I/O primitives in compiler/table_gen.m.)

	Standardize the formatting of predicates defined by pragma C codes.

library/table_builtin.m:
	Define the predicates that perform I/O tabling, to which calls are
	inserted in I/O tabled predicates. These depend on knowing what the
	maximum MR_Unsigned value is.

library/table_builtin.m:
runtime/mercury_tabling_macros.h:
	Table nodes implementing a simple kind of trie, which can also be
	viewed as a hash table with the hash function hash(n) = hash - start
	were already supported by mercury_tabling.c. They are used to
	implement I/O tabling, since I/O the tabled action numbers form a
	contiguous sequence. Now allow that functionality to be accessed
	from the library through macros.

runtime/mercury_trace_base.[ch]:
	Add the global variables required by I/O tabling.

trace/mercury_trace.c:
	Implement retry across I/O by resetting the I/O counter to the value
	it had on entry to the retried call. However, since this is not safe
	in general, ask the user for permission first.

trace/mercury_trace.h:
	Add two extra arguments to MR_trace_retry to specify the input and
	output streams on which to ask permission.

trace/mercury_trace_internal.c:
	Add commands to start and stop I/O tabling. For now, they are for use
	by developers only and are undocumented; I expect they will change
	significantly before being let loose on users.

trace/mercury_trace_external.c:
trace/mercury_trace_declarative.c:
	Pass extra arguments to MR_trace_retry to indicate that these modules
	are not interested (at least for now) in retry across I/O, since they
	do not (yet) have mechanisms for asking the user for permission.

tests/debugger/tabled_read.{m,inp,exp,data}:
	A new test case to check retry across tabled and non-tabled I/O.

tests/debugger/Mmakefile:
	Enable the new test case.
2000-12-06 06:06:06 +00:00
Mark Brown
2cefe05a11 Record the trace level that the module was compiled with in the module
Estimated hours taken: 3

Record the trace level that the module was compiled with in the module
layout structure.  Use this to avoid an abort if the 'dd' command is used
on a module that is compiled with trace level 'deep'.

compiler/trace_params.m:
	Encode the trace level as an integer.

runtime/mercury_stack_layout.h:
	Add a field to MR_Module_Layout to store the encoded trace level.

compiler/stack_layout.m:
	Fill in this field.

trace/mercury_trace_declarative.c:
	Ignore events from modules that don't have an appropriate trace
	level.  This effectively assumes that the events are correct, so
	we warn the user that this has happened.  Also, disallow the 'dd'
	command at these events.

tests/debugger/declarative/Mmakefile:
tests/debugger/declarative/deep_sub.m:
tests/debugger/declarative/deep_warning.exp:
tests/debugger/declarative/deep_warning.inp:
tests/debugger/declarative/deep_warning.m:
	A test case for the new feature.
2000-11-10 01:01:04 +00:00
Zoltan Somogyi
1c8cb6faf2 Get the compiler to bootstrap with -DMR_NO_BACKWARDS_COMPAT.
Estimated hours taken: 2

Get the compiler to bootstrap with -DMR_NO_BACKWARDS_COMPAT.

compiler/c_util.m:
compiler/rtti_out.m:
	Add MR_ prefixes to various type names in generated code.

compiler/*.m:
browser/*.m:
library/*.m:
	Add MR_prefixes to various type and function names in pragma C code.

runtime/*.[ch]:
trace/*.[ch]:
	Add MR_prefixes to various type and function names in
	hand-written code.
2000-10-16 01:34:14 +00:00
David Overton
82378c381b Allow polymorphic ground insts. This change assumes that all inst
Estimated hours taken: 80

Allow polymorphic ground insts.  This change assumes that all inst
parameters in the mode declaration for a predicate or function are
constrained to be ground-shared.  This is a temporary measure until we
work out a nice syntax to allow the programmer to tell the compiler that
certain inst parameters may be treated as ground insts.  Since we don't
currently support unconstrained inst parameters anyway, this shouldn't
cause a problem.

	TODO:
		- Add syntax, something like `:- mode p(in(I)) <= ground(I).',
		  to specify that an inst parameter represents a ground inst.
		- Allow abstract ground insts that are treated in a similar
		  way to what we've done here with ground inst parameters.
		- Make mode checking more efficient (i.e. rewrite the mode
		  system).

compiler/inst.m:
	Add a new alternative for ground insts:
		`constrained_inst_var(inst_var)'.
	Define the type `inst_var_sub'.

compiler/inst_match.m:
	Change inst_matches_initial so that it:
		- handles constrained_inst_vars correctly;
		- returns the inst_var substitutions necessary for the call;
		- handles inst_matches_initial(ground(...), bound(...), ...)
		  properly (this requires knowing the type of the variable).

	  The last change has also been made for inst_matches_final
	  and inst_matches_binding.  However, the check is disabled for
	  now because, without alias tracking, the mode checker
	  becomes too conservative.

compiler/hlds_pred.m:
compiler/mode_info.m:
compiler/simplify.m:
compiler/det_util.m:
	Include the inst_varset in the proc_info, mode_info and simplify_info.
	Add a vartypes field to the det_info.
	Remove the vartypes field from the simplify_info since it is
	now in the det_info.
	Use record syntax for these data structures and their access predicates
	to make future changes easier.

compiler/prog_io.m:
	When processing pred and func mode declarations, convert all inst_var(V)
	insts to ground(shared, constrained_inst_var(V)).

compiler/prog_data.m:
compiler/hlds_data.m:
compiler/make_hlds.m:
compiler/mode_util.m:
	Use inst_vars instead of inst_params.

compiler/modes.m:
compiler/modecheck_call.m:
compiler/unique_modes.m:
compiler/mode_util.m:
	When checking or recomputing initial insts of a call, build up
	an inst_var substitution (using the modified
	inst_matches_initial) and apply this to the final insts of the
	called procedure before checking/recomputing them.

compiler/mode_util.m:
	Make sure that recompute_instmap_delta recomputes the
	instmap_deltas for lambda_goals even when RecomputeAtomic = no.

compiler/type_util.m:
	Add a new predicate, type_util__cons_id_arg_types which
	nondeterministically returns the cons_ids and argument types for a
	given type.
	Add a new predicate type_util__get_consid_non_existential_arg_types
	which is the same as type_util__get_existential_arg_types except
	that it fails rather than aborting for existenially typed arguments.

compiler/accumulator.m:
compiler/check_typeclass.m:
compiler/clause_to_proc.m:
compiler/common.m:
compiler/continuation_info.m:
compiler/deforest.m:
compiler/det_analysis.m:
compiler/det_report.m:
compiler/det_util.m:
compiler/dnf.m:
compiler/follow_code.m:
compiler/goal_store.m:
compiler/goal_util.m:
compiler/higher_order.m:
compiler/inst_util.m:
compiler/instmap.m:
compiler/lambda.m:
compiler/magic.m:
compiler/magic_util.m:
compiler/mercury_to_mercury.m:
compiler/modecheck_unify.m:
compiler/module_qual.m:
compiler/pd_info.m:
compiler/pd_util.m:
compiler/polymorphism.m:
compiler/post_typecheck.m:
compiler/prog_io_util.m:
compiler/prog_rep.m:
compiler/saved_vars.m:
compiler/stack_layout.m:
compiler/table_gen.m:
compiler/unify_proc.m:
compiler/unneeded_code.m:
compiler/unused_args.m:
	Pass inst_varsets and types where needed.
	Changes to reflect change in definition of the inst data type.

compiler/inlining.m:
	Recompute the instmap deltas for a procedure after inlining.
	This bug showed up compiling tests/hard_coded/lp.m with
	inlining and deforestation turned on: deforestation was
	getting incorrect instmap deltas from inlining, causing
	the transformation to break mode-correctness.  It has only
	just shown up because of the added call to
	`inst_matches_initial' from within `recompute_instmap_delta'.

tests/invalid/Mmakefile:
tests/invalid/unbound_inst_var.m:
tests/invalid/unbound_inst_var.err_exp:
tests/valid/Mmakefile:
tests/valid/unbound_inst_var.m:
	Move the `unbound_inst_var' test case from `invalid' to `valid'
	and extend its coverage a bit.
2000-10-13 13:56:17 +00:00
Zoltan Somogyi
fdccd65e30 The debugger's retry command at the moment works only from a final port for
Estimated hours taken: 60

The debugger's retry command at the moment works only from a final port for
the call to be retried, the reason being that the RTTI does not have the
information required to make sure that the state of the stacks is reset
correctly. If you invoke retry from a non-final port, the current
implementation skips forward to a final port and then does the retry;
this does not work if you get a core dump or a infinite loop during the forward
skip. This change adds the required info to the RTTI and thus enables
direct retries from the middle of calls.

The information added has two components. First, if a procedure that lives on
the nondet stack allocates any temporary nondet stack frames, then it must
record the old value of maxfr in a stack slot so that retry can restore it.
Second, if a procedure is tabled, then it must record the call table tip node
corresponding to the actual input arguments, so we can reset this node to
uninitialized (if we don't, then the retried call will find the active call
marker and report an infinite loop error).

The support for retries across minimal model calls is not finished yet.
Finding out what the right thing to do in such cases is a research project,
one that cannot even be started until minimal model tabling works reliably
in the *absence* of retries. However, such retries do grossly wrong things
at the moment; this change is a definite improvement. It attempts to perform
the retry from the fail port, since that is the only time when the minimal
model tabling data structures are quiescent. The "fail" command I added to
the debugger command set to let this be done is not complete yet and is
therefore undocumented; the problem is that a call to a model_non predicate
in a committed choice context will not get to the fail port. I added goal paths
to return layouts so that we will eventually be able to tell when execution
leaves a committed choice context surrounding an ancestor of a model_non
predicate call, but this functionality is not yet implemented.

compiler/stack_layout.m:
	Generate the three new fields: the evaluation method, (maybe) the id
	of the stack slot containing the saved value of maxfr, and (maybe)
	the id of the stack slot containing the call table tip.

compiler/continuation_info.m:
	Record the information about the new fields for later use by
	stack_layout.m.

	Add a new field to record the goal path of calls for their return
	layouts.

	Fix a screwed comment for the continuation_info data structure.

compiler/llds.m:
	Add a new field to call() instructions to hold the goal path of the
	call.

	Add a utility function for use by trace.m.

compiler/call_gen.m:
	Fill in this new field.

compiler/trace.m:
compiler/live_vars.m:
	Reserve the fixed stack slot for the saved maxfr if necessary,
	and if the call table tip node is needed, make sure that the variable
	holding its address is allocated a low-numbered stack slot (otherwise,
	its number may not fit into the MR_int_least8_t field in the
	proc_layout).

compiler/trace.m:
	If necessary, fill in the saved maxfr slot.

	If necessary, initialize the call table tip slot.

compiler/hlds_goal.m:
	Add a goal feature which marks its goal as defining the variable
	representing the call table tip node.

	Add a field to the goal path step representing quantification;
	the field says whether the quantification changes the determinism of
	the goal (i.e. whether it cuts away solutions).

compiler/hlds_pred.m:
compiler/hlds_out.m:
	Add two fields to proc_infos which (a) record which variable, if any,
	holds the call table tip node, and (b) record whether the procedure's
	layout structure needs to reserve a slot for the saved value of maxfr.

compiler/table_gen.m:
	Put this feature on the appropriate goal.

	Also, rename a predicate to make it reflect its purpose better.

compiler/code_gen.m:
	Generate code to put the call table tip variable in its stack slot
	immediately after it has been generated.

	Add a sanity check to ensure that if a procedure that lives on the det
	stack can create a temporary nondet frame, and debugging is enabled,
	then it did have a stack slot reserved for the saved maxfr.

compiler/code_util.m:
	Add a predicate to make a conservative prediction of whether a
	procedure may allocate a temporary nondet stack frame. We cannot
	just generate the code and see, because the code generator needs to
	know which variables live in which stack slots, and we cannot decide
	that until we know whether we need a stack slot for the saved value of
	maxfr.

	Make an unrelated predicate semidet procedure use a det helper, in
	order to make it more robust in the face of changes to the HLDS
	(e.g. it was missing code for handling bi_implications).

compiler/code_info.m:
	Record whether a procedure has in fact created a temporary nondet stack
	frame.

compiler/handle_options.m:
	Disable hijacks if debugging is enabled. The code we now use to
	restore the stacks for direct retries works only if the retry does not
	"backtrack" over a hijacked nondet stack frame whose hijack has not
	been undone. Note that code compiled without debugging may still hijack
	nondet stack frames. Execution may reemerge from the nondebugged region
	in one of two ways. If the nondebugged code returns, then it will have
	undone hijack, and the retry code will work. If the nondebugged code
	calls debugged code, there will be a region on the stacks containing
	no debugging information, and the retry command will refuse to perform
	retries that go into or beyond this region. Both cases preserve
	correctness.

compiler/*.m:
	Trivial changes to conform to changes in data structures.

runtime/mercury_stack_layout.h:
	Add three new fields to proc layouts: the numbers of the stack slots
	(if any) storing the saved maxfr and the call table tip, and a
	representation of the procedure's evaluation method.

runtime/mercury_stack_trace.[ch]:
	Now that return layouts contain goal paths, print them in stack dumps
	only if the include_trace_data flag is set (in mdb, this requires the
	-d flag of the "stack" command).

	Pass this flag around directly, instead of encoding its value in
	the NULL vs non-NULL values of sp and curfr.

runtime/mercury_regorder.h:
	Provide a mechanism to access the values of the first few rN registers
	from a save area, for use in debugging low-level C code in the runtime
	and the trace directories.

trace/mercury_trace.[ch]:
	Reimplement MR_trace_retry to allow retries from the middle.
	If the stack segment being retried over contains minimal model
	procedures, we must still arrange to skip to the end of the retried
	call. If this call is a minimal model generator, skipping to just any
	final port is not sufficient to guarantee correctness on retry; to
	ensure that subgoal is complete, we must skip to a fail port.

trace/mercury_trace.[ch]:
trace/mercury_trace_internal.c:
	Implement a debugger command, "fail", which skips to the fail port or
	the exception port of the specified ancestor. Since procedures that are
	not model_non are not guaranteed to get to such a port, this
	command reports an error if the specified call is not model_non.
	Actually, even calls to model_non procedures may not get to the fail
	port, as explained above; this is why the command is not yet
	documented.

trace/mercury_trace.c:
trace/mercury_trace_util.[ch]:
	Move some functions to print parts of the Mercury abstract machine
	state from mercury_trace to mercury_trace_util, so that they are
	available for use in debugging e.g. mercury_trace_declarative.

trace/mercury_trace_internal.c:
trace/mercury_trace_external.c:
trace/mercury_trace_declarative.c:
	Use the new implementation of retries. At the moment, only the
	internal debugger implements the full functionality. The declarative
	debugger issues retry commands only from situations where the missing
	functionality is not (yet) needed. The external debugger should
	continue to work correctly, but Erwan may wish to update it to
	exploit the availability of the fail command.

trace/mercury_trace*.[ch]:
	Fix MR_prefixes, and a signed/unsigned mismatch.

doc/user_guide.texi:
	Document the new "fail" command, but comment it out for now.

tests/debugger/retry.{m,inp,exp,exp2}:
	A new test case for exercising retry.

tests/debugger/Mmakefile:
	Enable the new test case.

tests/debugger/*.exp:
	Update the expected output, given the extra info now output e.g. for
	exception events and detailed stack traces.
2000-10-13 04:06:52 +00:00
Zoltan Somogyi
07d6517521 Implement a general mechanism for suppressing selected aspects of execution
Estimated hours taken: 8

Implement a general mechanism for suppressing selected aspects of execution
tracing.

compiler/trace_params.m:
	This new file contains two abstract data types that define the
	parameters of the execution tracing system, and the operations
	on them.

	The two ADTs are the trace level (moved from globals.m) and a new one,
	trace_suppress_items, which replaces --no-trace-internal,
	--no-trace-redo and --no-trace-return, and provides additional
	capabilities requested by Erwan.

	Basically any given port can now be suppressed, with the exception of
	call (because the call event's layout structure is needed for
	implementing redo from any other event) and excp (because they are
	created on the fly by exception.m, and are not put into object
	code in the first place).

compiler/globals.m:
	Delete the stuff now migrated to trace_params.m. Make
	trace_suppress_items part of the globals structure.

compiler/code_gen.m:
compiler/trace.m:
	Allow the suppression of individual ports.

compiler/stack_layout.m:
	Allow the suppression of parts of layout structures.

compiler/*.m:
	Minor changes, mainly importing trace_params, to conform to the main
	modifications.

compiler/options.m:
	Delete --no-trace-internal, --no-trace-redo and --no-trace-return.
	Add --suppress-trace, but do not document it, since it is really
	intended only for implementors.

doc/user_guide.texi:
	Delete the documentation of --no-trace-internal, --no-trace-redo and
	--no-trace-return. Do not document it --suppress-trace, since it is
	really intended only for implementors. (The only reason why other three
	were documented is that most consumers of the users' guide then *were*
	implementors.)
2000-10-03 00:34:52 +00:00
Zoltan Somogyi
36fc174bed Make declarative debugging a trace level, not a separate option.
Estimated hours taken: 2

Make declarative debugging a trace level, not a separate option.

compiler/globals.m:
	Make trace_level an abstract data type. Define and export several
	functions that check whether the current trace level requires
	particular kinds of treatment.

compiler/options.m:
	Remove --trace-decl as an option.

compiler/*.m:
	Instead of checking for particular values of the trace level, use
	the functions now exported by globals.m.

tests/debugger/declarative/Mmakefile:
	Use the trace level to ask for declarative debugging.
2000-09-27 05:23:36 +00:00
Zoltan Somogyi
3ce3b14c84 Make procedure bodies available to the declarative debugger.
Estimated hours taken: 20

Make procedure bodies available to the declarative debugger.

browser/program_representation.m:
	Add _rep suffixes to the function symbols, to make iit easier to
	distinguish HLDS goals and goal representations.

compiler/static_layout.m:
	If --trace-decl is specified, include a representation of the procedure
	body in the procedure's layout structure.

compiler/prog_rep.m:
	A new module, containing the code that converts goals from HLDS
	to a term in the format we want to put in the layout structure.

compiler/static_term.m:
	A new module, containing the code that converts Mercury terms
	to the LLDS rval we need to give to llds_out.m.

compiler/code_gen.m:
compiler/continuation_info.m:
	Preserve the information needed by prog_rep

compiler/Mmakefile:
	Extend the search path to the browser directory, since the new file
	prog_rep.m imports one of the submodules of mdb.m stored there.

compiler/notes/compiler_desigm.html:
	Document the new modules.

library/std_util.m:
	Add a mechanism for static_term.m to use in converting terms into
	rvals. This mechanism uses RTTI information to deconstruct terms,
	and return not only their arguments, but also information about how
	the term can be constructed from its arguments.

runtime/mercury_type_info.h:
	Add a couple of macros to make construction and deconstruction of univs
	easier, for use in std_util.m.

trace/mercury_trace_internal.c:
	Add a new command, "proc_body", that prints out the representation
	of the body of the current procedure. This is meant only for developers
	to use to check that the procedure body representation is OK; it is
	deliberately not documented.

	Also fix a bug: make sure that we do not pass a NULL pointer to fputs
	when echoing a line of input that isn't there (because we got EOF).
2000-09-25 04:37:26 +00:00
Zoltan Somogyi
c014e2a20b Store the offsets leading to the names of variables in a central location.
Estimated hours taken: 8

Store the offsets leading to the names of variables in a central location.
Previously, each label layout included offsets for the variables live at that
label; now we store the offsets of variables in the proc layout. The new
data structure will soon be required by the declarative debugger for
displaying contours through representations of HLDS goals.

compiler/code_gen.m:
	Preserve the varset of every procedure for use by stack_layout.m.

compiler/continuation_info.m:
	Add a field to the cell from which proc layouts are derived to hold
	the varset.

compiler/stack_layout.m:
	Delete the offsets from label layouts and add them to proc layouts.
	The var name offsets array will always contain meaningful offsets
	for every variable that is live at a label with a label layout; with
	--trace-decl, it will also contain meaningful offsets for all the
	other variables in the procedure body.

runtime/mercury_stack_layout.h:
	Reflect the change in the types of the label and proc layout
	structures.

trace/mercury_trace.c:
trace/mercury_trace_vars.c:
	Look up variable names using the new location of the offsets leading to
	them.
2000-09-22 06:00:04 +00:00
Zoltan Somogyi
a1f326f4e9 Add an alternative to code_exprn that does eager code generation (code_exprn
Estimated hours taken: 140

Add an alternative to code_exprn that does eager code generation (code_exprn
always does lazy code generation). Its main advantages are that the new code
is significantly simpler, and that it does not generate unnecessary shuffling
code. Its main disadvantage, which is that it does not eliminate the creation
of unneeded cells, can be eliminated by switching on --unneeded-code.

For now, you can select the use of the new code generator with the
--no-lazy-code option (which was previously present but unused).
This will be made the default later, after I do more performance tests.

Var_locn contains stricter self-checks than code_exprn does. This required
modifications to some other parts of the code generator to ensure that the
self-checks do not fail unnecessarily. (This mostly took the form of explicitly
killing off dead variables before calling code_info__clear_all_registers, which
would complain about losing the last record of the value of a variable that was
alive as far as it knew.) To make my changes simpler, also took the opportunity
to simplify parts of the code generator which were handing around rvals that
in fact had to be wrappers around lvals, by handing around the lvals directly.

Testing this change also required fixing an old bug which prevented compiling
the library with -O1 --trace deep, together with the usual intermodule
optimization. The bug is that a library module reads predicates from
builtin.opt or private_builtin.opt, does not eliminate them because of the -O1,
and then tries to generate traced code for them. However, this fails because
the builtin modules contain some predicates that cannot be made to conform to
typeinfo-liveness, which is required by tracing.

compiler/var_locn.m:
	The new module that implements eager code generation.

compiler/follow_vars.m:
	Improve the follow_vars pass, since eager code generation requires
	better follow_vars information. We now generate correct information
	for generic calls, and record not only where some vars (e.g. those
	which appear as input arguments of following calls) should be put,
	but also which registers are not reserved for those variables and
	are thus available for other variables.

compiler/hlds_goal.m:
	Modify the follow_vars field of the goal_info to record the number
	of the first non-reserved register.

compiler/code_info.m:
 	Replace the general-purpose predicate code_info__cache_exprn, which
	associated a variable with an rval without generating code, with a set
	of special-purpose predicates such as code_info__assign_const_to_var
	and code_info__assign_cell_to_var, some of which can generate code.

	These new predicates and some older ones (e.g. code_info__setup_call)
	now choose at runtime whether to call code_exprn or var_locn. The
	basis for the decision is checking whether the code_info structure
	contains an exprn_info or a var_locn_info. This is decided in
	code_info__init based on the value of the lazy_code option, and
	maintained unchanged from then on.

	Rename some predicates to better reflect their current possible
	behaviors.

compiler/unify_gen.m:
	Call the new special-purpose predicates in code_info instead of
	code_info__cache_exprn.

	Replace an incorrect clause with a call to error, since that clause
	could never be invoked.

compiler/call_gen.m:
	Hand over the task of generating the args of generic calls to
	code_info, since it already has code to do the right thing, which
	includes reserving the registers to be used for the input args.

	Notify the rest of the code generator after the last use of
	non-forward-live variables, in order to avoid spurious calls to error
	(it is an error to clobber the last location of a live variable).

	Notify the rest of the code generator when generic calls overwrite
	registers, to allow the proper consistency checks to be made.

	If an output variable is singleton, then do not make it known to the
	code generator. It never will never become dead, and may thus cause a
	spurious compiler abort if its storage is ever clobbered.

	Export a predicate for use by follow_vars.

	Factor out some common code.

	Call the new preds in code_info where necessary.

compiler/pragma_c_gen.m:
	Notify the rest of the code generator after the last use of
	non-forward-live variables, in order to avoid spurious calls to error
	(it is an error to clobber the last location of a live variable).

	If an output variable is singleton, then do not make it known to the
	code generator. It never will never become dead, and may thus cause a
	spurious compiler abort if its storage is ever clobbered.

	When using var_locn, ensure that none of the input arguments of a
	model_semi pragma_c_code is assigned to r1. If we did, and the last
	reference to the value of that argument was after an assignment to
	SUCCESS_INDICATOR, the C compiler would be forced to generate code
	to shuffle the value of the argument out of the way.

compiler/code_exprn.m:
	Minor changes to return lvals directly instead of lvals wrapped inside
	rvals and to conform the new format of follow_vars.

	Do not include the registers reserved by follow_vars in the
	search for a spare register.

compiler/lookup_switch.m:
compiler/switch_gen.m:
	Fix an old bug that did not matter with code_exprn but does matter with
	var_locn: the branch end structure was being computed in the wrong
	place.

compiler/disj_gen.m:
	At the ends of non-last disjuncts, kill off the variables that we
	needed to know inside the disjunct but won't need to know after the
	disjunct, in order to avoid error messages about throwing away their
	state. The variables affected are those which are needed only by the
	resumption point of the next disjunct, not by enclosing resumption
	points or forward execution.

compiler/arg_info.m:
	Associate an lval, not an rval, with each argument.

compiler/*.m:
	Minor changes to conform to (a) the new format of follow_vars, (b)
	the replacement of rvals containing lvals by lvals.

compiler/code_util.m:
	Add some utility predicates for var_locn.m.

compiler/exprn_aux.m:
	Add some utility functions for var_locn.m.

	Export a predicate for var_locn.m.

compiler/handle_options.m:
	If --no-lazy-code is set, switch on the "optimizations" on whose
	presence it depends.

compiler/mercury_compile.m:
compiler/code_gen.m:
	Turn off tracing for predicates that don't obey typeinfo liveness
	for backend_by_preds and backend_by_phases respectively.

	Look up options in the globals structure in the module_info, not in the
	globals structure in the I/O state, since this is where we turn off
	tracing. (We should later make sure that other parts of the compiler
	are also consistent on this issue.)

compiler/stack_layout.m:
	Throw away any continuation_info structures that belong to predicates
	that don't obey typeinfo liveness.
2000-09-16 00:08:27 +00:00
Zoltan Somogyi
12af7b3793 Consistently use counters to allocate label numbers and cell numbers
Estimated hours taken: 12

Consistently use counters to allocate label numbers and cell numbers
throughout the LLDS backend.

compiler/hlds_module.m:
	Change the module_info structure to store a counter instead of an
	integer for cell numbers.

compiler/llds.m:
	Change the c_procedure structure to include a proc_label and a counter,
	to allow LLDS to LLDS optimizations to use this counter to allocate
	new label numbers. (The labels also include the proc_label.)

compiler/code_info.m:
	Change the code_info structure to store counters instead of integers
	for both label numbers and cell numbers.

compiler/code_gen.m:
	When creating the c_procedure, copy the final value of the counter
	from code_info to the c_procedure.

compiler/opt_util.m:
	Delete the existing, inefficient procedure for allocating label
	numbers, and modify the interface of the get_prologue predicate
	to no longer return the proc_label (since it can now be looked up
	more directly).

compiler/*.m:
	Minor changes to conform to the new data structures and to use
	counters instead of direct addition.
2000-08-11 08:19:24 +00:00
Zoltan Somogyi
8fa19d7065 Fix bug that only occurs if the list of tvars at a location has a hole,
Estimated hours taken: 1

compiler/stack_layout.m:
	Fix bug that only occurs if the list of tvars at a location has a hole,
	i.e. tvar N is live but tvar N-1 isn't.
2000-07-20 05:44:02 +00:00
Fergus Henderson
6ba459bdaa Add some `MR_' prefixes.
Estimated hours taken: 0.75

Add some `MR_' prefixes.

runtime/mercury_string.h:
runtime/mercury_misc.h:
runtime/mercury_misc.c:
runtime/mercury_make_type_info_body.h:
runtime/mercury_type_info.c:
runtime/mercury.c:
extras/*/*.m:
extras/*/*/*.m:
library/*.m:
trace/*.c:
compiler/fact_table.m:
compiler/ml_code_gen.m:
compiler/stack_layout.m:
	Add `MR_' prefixes to fatal_error(), hash_string(),
	do_hash_string, and HASH_STRING_FUNC_BODY.

runtime/mercury_bootstrap.h:
	Add backwards compatibility macros for
	fatal_error() and hash_string().
2000-05-08 13:48:50 +00:00
Fergus Henderson
cbbd48080f Restructure the handling of RTTI and pseudo_type_infos
Estimated hours taken: 30

Restructure the handling of RTTI and pseudo_type_infos
to reduce dependencies on the LLDS.

compiler/rtti.m:
	- Change the various occurrences of llds__rval to rtti_data.
	- Add `field_types' and `pseudo_type_info' as
	  new alternatives in the rtti_data and rtti_name types,
	  to provide ways of representing things that were
	  previously represented as create() llds__rvals.

compiler/rtti_out.m:
	- Add some documentation to the interface.
	- Modify to handle the changes to rtti.m.

compiler/type_ctor_info.m:
	- Modify to handle the changes to rtti.m.
	- Don't thread the cell_count or module_info through
	  most of the code here, since it is no longer necessary.
	- Modify the interface to eliminate dependency on LLDS:
	  change generate_llds to return a list(rtti_data)
	  rather than a list(llds__comp_gen_c_data), and rename
	  it as generate_rtti.

compiler/mercury_compile.m:
	Update to reflect the changed interface to type_ctor_info.m.

compiler/pseudo_type_info.m:
	Rewrite much of this module to eliminate all dependencies on LLDS.
	Rather than generating an llds__rval, this module now generates a new
	type pseudo_type_info (which is used in the pseudo_type_info
	alternative of the rtti_data type).

compiler/ll_pseudo_type_info.m:
	New file, contains the parts of pseudo_type_info.m that depended on
	LLDS.  This is needed for stack_layout.m, which still needs
	pseudo_type_infos represented as llds__rvals.

compiler/stack_layout.m:
	Call the routines in ll_pseudo_type_info rather than those in
	pseudo_type_info.

compiler/llds_common.m:
	Don't traverse rtti_data rvals, since they can't contain create()
	rvals anymore.

compiler/opt_debug.m:
	Handle the new `field_types' and `pseudo_type_info' alternatives in
	the rtti_data and rtti_name types.

compiler/rtti.m:
compiler/rtti_out.m:
compiler/llds_out.m:
	The predicate `rtti_address_would_include_code_addrs' was
	duplicated in both rtti.m and rtti_out.m. I deleted
	the version in rtti.m, exported the version in rtti_out.m,
	and changed llds_out.m to call the version in rtti_out.m.

runtime/mercury_type_info.h:
	- Define macros for defining MR_TypeInfo and MR_PseudoTypeInfo
	  struct types of different arities, for use by the code
	  generated by compiler/rtti_out.m.
	- Define MR_TypeCtorInfo as a pointer to a _const_ struct type,
	  to avoid the need to generate casts to cast-away-const in
	  various places in compiler/rtti_out.m.
	  Likewise for MR_PseudoTypeInfo.
	  (It would be nice to do the same thing for MR_TypeInfo,
	  since we never modify MR_TypeInfo values after
	  constructing them, but currently they are modified by the
	  MR_fill_in_*() macros which are used to construct them.)
	- Fix a couple of places where macro arguments were not
	  properly parenthesized.
2000-04-02 08:09:50 +00:00
Zoltan Somogyi
4ccc3b32ac Cleanup of the type_ctor_infos and their components, to achieve two goals.
Estimated hours taken: 65

Cleanup of the type_ctor_infos and their components, to achieve two goals.
First, the new data structure is defined in strongly typed C, with only
two unions, whereas the old data structure was defined by a bunch of macros
that used casts all over the place. The new design should therefore make it
significantly easier to debug code that uses RTTI, and to get it right in
the first place. Second, the new data structures are logically organized,
whereas the old ones had several bad features (such as fixed fields coming
after variable-length arrays in "structures") required by backward
compatibility.

For the time being, the runtime system will be able to handle type_ctor_infos
using both the old and the new data structures, which are distinguished by
the type_ctor_info's version number.

To minimize the disruption caused by such bootstrapping, this change also
incorporates an improvement in the RTTI: for most pseudo_type_infos included
in the RTTI, it records information that allows the runtime system to tell
whether the pseudo_type_info is ground or not; if it is, then the runtime
need not scan the pseudo_type_info looking for type parameters to expand.
Based on statistics I have gathered, this will eliminate between half and two
thirds of all such scans when we do unification and comparison by RTTI.

This change does not impact the structures of typeinfos, base_typeclass_infos
or typeclass_infos.

runtime/mercury_type_info.h:
	Define the C types for the new type_ctor_info components.

	Update the C type for type_ctor_infos themselves, and the macros
	that act on it.

	Centralize the list of files that depend on type info representation
	here.

	Make the names of the two macros that give the number of (all kinds of)
	type info vars and the number of existential type info vars consistent.

runtime/mercury_std.h:
	Change a comment to refer to one of these renamed macros by its new
	name.

compiler/rtti.m:
compiler/rtti_out.m:
	New files: rtti.m defines new types that allow us to construct
	Mercury representations of the C structures we want to emit,
	and rtti_out.m converts those representations to C definitions.
	These files are intended to be independent of whether the backend
	is LLDS or MLDS. At the moment, there are several vestiges that
	tie them to LLDS, mostly due to (a) the lack of a shared common
	infrastructure between llds_out.m and mlds_to_c.m, and (b)
	the continued use of the old representation of (pseudo-) typeinfos
	as rvals. These concerns will be addressed in a future change.

compiler/llds.m:
	Update the definition of the comp_gen_c_data and data_addr types
	to account for the new RTTI structures.

compiler/llds_out.m:
	Update the code to output comp_gen_c_data and data_addr values
	to account for the new RTTI structures.

	Make some parts of the code more modular, so that rtti_out.m
	can use what used to be selected parts of predicates.

	Export several predicates for use by rtti_out.m. Some of these
	should later be moved to a file for infrastructure shared by
	llds_out.m and mlds_to_*.m. Others should be made internal again
	when the representation of typeinfos is made independent of the LLDS.

	Rename some predicates to better reflect their purpose.

compiler/base_type_layout.m:
compiler/base_type_info.m:
	These files are obsoleted by this change. They remain in CVS, but
	are no longer used. All of base_type_info.m has been moved into
	type_ctor_info.m, and so have the parts of base_type_layout.m
	that create the functors and layout structures inside type_ctor_infos;
	the remaining part of base_type_layout.m is now in pseudo_type_info.m.

compiler/pseudo_type_info.m:
	New file containing the code to create pseudo_type_infos from
	base_type_layout.m, slightly updated for the new compiler structure.

compiler/type_ctor_info.m:
        New module: almost total rewrite of the base_type_info.m and the
	relevant part of base_type_layout.m for the new data structure.

	Do not invoke base_typeclass_info.m, since the structures it creates
	are not parts of the type_ctor_infos.

compiler/ml_base_type_info.m:
	Comment out obsolete unfinished code. It should be replaced by
	calls to type_ctor_info, once type_ctor_info's dependence on LLDS
	has been eliminated.

compiler/hlds_module.m:
	Rename the data structure from which type_ctor_infos are generated.
	Delete the data structure from which type_ctor_layouts were generated,
	since it is redundant.

	Switch to using field names.

compiler/make_tags.m:
compiler/hlds_data.m:
	make_tags.m had code that duplicated much of the the functionality
	of an existing predicate in hlds_data.m. This change moves that
	predicate to hlds_data where it belongs, and gives it an appropriate
	name.

compiler/mercury_compile.m:
	Do not invoke the predicates that used to be in base_type_layouts
	directly; let type_ctor_info do it for the types for which it is
	appropriate.

	Do invoke base_typeclass_info directly.

compiler/dead_proc_elim.m:
compiler/llds_common.m:
compiler/opt_debug.m:
compiler/stack_layout.m:
compiler/unify_gen.m:
	Trivial changes to conform to the changes in the representation of
	compiler-generated C data.

compiler/notes/compiler_design.html:
	Updates to reflect the new files.

runtime/mercury_deep_copy_body.h:
runtime/mercury_tabling.c:
runtime/mercury_type_info.c:
	Provide alternate implementations of functionality that used the
	old functors and layout structures, to use the new ones instead
	if the relevant type_ctor_info's version number calls for it.
	In many cases, doing this cleanly required reducing the scopes of
	variables.

runtime/mercury_tabling.[ch]:
	Note where additional work on tabling of typeclass infos is needed,
	but do not do the work yet, since it would conflict with DJ's coming
	change.

library/std_util.m:
	Provide alternate implementations of functionality that used the
	old functors and layout structures, to use the new ones instead
	if the relevant type_ctor_info's version number calls for it.
	In many cases, doing this cleanly required reducing the scopes of
	variables.

	The predicates get_functor and construct take an integer argument
	that identifies a functor of a du type. The integer used to be
	the functor's ordinal number in the type definition, but this
	was not documented. It is now the functor's position in the list
	of the type's functors sorted first on name and then on arity.
	This functionality is potentially more useful, since io__read
	could do binary instead of linear search when looking for a given
	functor. This is an incompatibility, but a very minor one.

	Add a new predicate, get_functor_ordinal, to provide a way
	to convert lexicographic position into ordinal position.
	This is not used yet.

	Rename the two different kinds of variables named "info" so that
	one can tell them apart.

tests/hard_coded/construct.exp:
	Update the expected output of this test based on the new definition
	of the meaning of functor numbers in the get_functor and construct
	predicates in std_util.

tests/hard_coded/deep_copy.{m,exp}:
	Add some code to test the "type contains var" bit vector in du
	functor descriptions.

tests/hard_coded/existential_rtti.{m,exp}:
	Make the test case print out results as it goes along, to make it
	easier which subtask a core dump is coming from. Update the expected
	output accordingly.
2000-03-10 13:38:21 +00:00
Simon Taylor
3a26ad82d5 Add information required for structure reuse and compile time garbage
Estimated hours taken: 2

Add information required for structure reuse and compile time garbage
collection to the LLDS. The code generator does not yet generate
this information.

This will be committed to the main branch to avoid CVS conflicts.

compiler/llds.m:
	Add an LLDS instruction `free_heap(rval)', which applies the
	MR_free_heap macro to its argument.

	Add a `maybe(rval)' field to `create' rvals to hold the address
	of a cell to reuse. This field should always be `no' after
	code generation, because all non-constant creates are converted
	into lower-level operations during code generation.

compiler/value_number.m:
	Don't reorder instructions around a `free_heap' instruction
	to avoid generating code which looks at deallocated memory.

compiler/*.m:
	Handle the new instruction and field.
2000-01-14 01:11:11 +00:00
Fergus Henderson
3995b5050f Fix the problem with contexts at exception ports in a way that (unlike Fergus's
Estimated hours taken: 4

(Committed by fjh on behalf of zs.)

Fix the problem with contexts at exception ports in a way that (unlike Fergus's
fix) does not slow down the speed-critical code path inside the debugger.

compiler/stack_layout.m:
	When generating label layouts for return labels, give the two fields
	of the layout structure that correspond to arguments of the old
	four-argument MR_trace() values that are appropriate for use in
	exception events, i.e. port is exception and goal path is empty.

compiler/llds.m:
compiler/llds_out.m:
	Add exception to the trace port type, since the compiler now refers
	to it.

runtime/mercury_stack_layout.h:
trace/mercury_trace.c:
	Undo Fergus's change.

library/exception.m:
	Undo Fergus's change, and my change previous to that. Pass the
	return layout to MR_trace unchanged, after checking that it indeed
	specifies an exception port.
1999-12-16 19:09:40 +00:00
Zoltan Somogyi
0642a10ff8 Reduce the number of arguments of MR_trace() to one.
Estimated hours taken: 24

WARNING: this change affects binary compatibility for debuggable code;
the debuggable modules of the program and the runtime linked into the
executable must either all come from before this change, or they must all
come from after this change. However, this change does *not* affect binary
compatibility for non-debuggable executables.

Reduce the number of arguments of MR_trace() to one. Two of the arguments,
the port and the goal path, move into the label layout structure, as 16-bit
numbers; the port as a simple enumeration type, and the goal path as an
index into the module-wide string table. (The latter will eventually allow the
debugger to support the placement of breakpoints on labels with specific goal
paths.) The third argument, the number of the highest-numbered rN register in
use at the label, has been moved into the proc layout structure. In theory,
this will require more register saves and restores, since the number in the
proc layout is conservative (it is the max of the numbers that would be
required at the individual labels). However, this is not important, for two
reasons. First, we always save and restore all the rM registers that
appear in the mrM array before the last special-purpose register, and in
most cases this dictates how many registers we save/restore. Second, we
save/restore registers only when the debugger starts interaction, so
save/restore is a time critical activity only for the external debugger.

This change reduces the execution time of debuggable executables by about
4-5% when executing outside mdb and 3-4% when executing under mdb. It also
reduces executable sizes, but only by about 0.7% on x86.

This change eliminates the --trace-just-in-case compiler option, since
we now have the best of both --trace-just-in-case and --no-trace-just-in-case.

The drawback of this scheme is slightly increased executable size with the
accurage garbage collector, but that seems a small enough price to pay.

compiler/code_gen.m:
compiler/code_info.m:
	Record the number of the highest numbered rN register live at a trace
	label.

compiler/continuation_info.m:
	Record the number of the highest numbered rN register live at a trace
	label, and the port and goal path associated with the labels of trace
	events.

compiler/stack_layout.m:
	Put the number of the highest numbered rN register live at a trace
	label into proc layouts, and the port and goal path into label layouts.

	Since we are breaking binary compatibility with old debuggable modules
	anyway, compress the procedure id parts of proc layouts by using
	only 16 bits to store the procedure's arity and mode number, instead
	of 32 or 64.

compiler/trace.m:
	Update the handling of ports, goal paths and max live register numbers,
	so that instead of being passed as MR_trace arguments, they are
	recorded in data structures.

	Generate separate labels and layouts for the fail and redo events.
	Although they still have the same layout information, they now record
	different ports.

compiler/llds.m:
	Since trace.m now generates a label layout structure for the redo
	event, we must include redo events in the llds goal path type.

compiler/hlds_goal.m:
	Since the code for handling the port type for nondet pragma events
	has moved from the nondet-pragma-specific to the generic part of
	trace.m, we must now include their event types in the hlds goal path
	type.

compiler/llds_out.m:
	Add a predicate for converting ports into numbers, now that we
	must store ports in static data. Using their symbolic names would
	be better, but that would require complications in the llds type
	system, which would be inadvisable just before the release.

compiler/options.m:
compiler/handle_options.m:
doc/user_guide.texi:
	Eliminate --trace-just-in-case.

compiler/llds.m:
compiler/llds_common.m:
compiler/llds_out.m:
	Eliminate the data structure needed by --trace-just-in-case.

compiler/optimize.m:
	Trivial update to conform to data structure changes.

library/exception.m:
	Update the call to MR_trace.

runtime/mercury_stack_layout.h:
	Update the C structure declarations for the layout structures
	as discussed above.

runtime/mercury_init.h:
	Update the declarations of MR_trace_real and MR_trace_fake
	to use only one argument.

runtime/mercury_wrapper.[ch]:
	Update the declaration of MR_trace_func to use only one argument.

runtime/mercury_trace_base.[ch]:
	Update the declarations of MR_trace, MR_trace_real and MR_trace_fake
	to use only one argument.

	Delete MR_trace_struct(); since we deleted --trace-just-in-case, there
	will not be calls to it anymore.

	Since we are breaking binary compatibility anyway, move the exception
	port to be with the other interface ports. This should speed up a
	frequently executed test in the debugger.

	Update the handling of redo events.

trace/mercury_trace.h:
	Simplify and speed up the macro that tests a port for being an
	interface port, now that exceptions are grouped with other interface
	events.

trace/mercury_trace.c:
	Update the definition of MR_trace_real to use only one argument.
	The port is pulled out of the label layout structure only when
	needed to perform the termination tests for the current debugger
	command, and the goal path and the max live register number are
	looked up only when the termination test succeeds.
1999-12-14 04:54:38 +00:00
David Jeffery
93b1c221fe Implement RTTI for functors with existentially typed arguments.
Estimated hours taken: 160

Implement RTTI for functors with existentially typed arguments. This allows
these functors to be deconstructed (and therefore io__write works for them)
and deep_copied.

compiler/base_type_layout.m:
	Generate extra information in the stack layout: the RTTI needs to
	include the number of extra arguments added for type infos and
	typeclass infos for each functor, as well as the locations of the
	type infos for each type.

compiler/stack_layout.m:
	Pass some extra arguments indicating that the pseudo type infos being
	handled are not existentially quantified.

compiler/std_util.m:
	Change ML_expand so that it includes information about existentially
	quantified arguments in the expand info.

compiler/base_typeclass_info.m:
	Extend the typeclass info structure to include enough information to
	copy it at runtime.

runtime/mercury_type_info.c:
	Use the new information in the RTTI to look up the type info packed
	inside a constructor if the pseudo type-info in question is
	existentially quantified. This may involve looking inside a typeclass
	info or just taking the type info directly.

runtime/mercury_deep_copy_body.h:
	Use the new RTTI to lookup up type so existentially quantified
	variables when doing a deep copy.

	Implement a function to deep copy typeclass infos.

runtime/mercury_deep_copy.c:
	#define the appropriate things to make copy_typeclass_info work for
	the different ways of allocating memory.

runtime/mercury_type_info.h:
	Change some prototypes and add macros to access the new information in
	the functor descriptor.

	Change the macros which access typeclass infos to reflect the new
	structure.

tests/hard_coded/existential_rtti.{m,exp}:
	A bunch of test cases for this change.

tests/hard_coded/Mmakefile:
	Turn this test case on.
1999-12-09 04:42:39 +00:00
Peter Ross
f87f9d2120 Ensure that the none.gc and none grades compile using a compiler
Estimated hours taken: 24

Ensure that the none.gc and none grades compile using a compiler
other than gcc.  This is not completely tested as lcc on linux can't
generate code for boehm_gc, and 'cc -std1' on the alpha runs out of
memory while trying to link the compiler.  However the compiler does
bootstrap using just gcc and also with lcc with boehm_gc compiled by
gcc.

configure.in:
    -Wl,opt1,opt2 syntax is not supported by lcc instead use -Wlopt1
    -Wopt2.

compiler/export.m:
    Only output a label declaration if that label is exported, as the
    static label declarations are not legal C.

library/io.m:
compiler/stack_layout.m:
    Replace escape sequence \x with \\x in pragma c code.

library/array.m:
library/std_util.m:
    Define what the struct is before using it, so the correct size for the
    struct can be calculated.

library/private_builtin.m:
    Replace escape sequence \x with \\x in pragma c code.
    Ensure that there is at least one local variable so that the
    structure definition for holding the local vars contains something.

runtime/mercury_faultaddr.h:
    Remove an unnecessary cast.

runtime/mercury_reg_workarounds.h:
    #include sys/time.h for FD_ZERO().

runtime/mercury_stack_trace.h:
    Remove an extraneous ',' which was causing warnings.
1999-11-25 09:09:46 +00:00
Zoltan Somogyi
229aeed2b7 Reduce the size of traced executables slightly.
Estimated hours taken: 0.2

Reduce the size of traced executables slightly.

runtime/mercury_stack_layout.h:
	Change the type of three fields of proc layouts from MR_int_least16_t
	MR_int_least8_t, since all three are the numbers of initially allocated
	stack slots. They are thus guaranteed to be less than 10, and thus
	fit into 8 bits with plenty to spare.

compiler/stack_layout.m:
	Make the corresponding change when generating proc layouts.
1999-11-15 10:17:05 +00:00
Zoltan Somogyi
f0964815a3 Support line numbers in the debugger. You now get contexts (filename:lineno
Estimated hours taken: 40

Support line numbers in the debugger. You now get contexts (filename:lineno
pairs) printed in several circumstances, and you can put breakpoints on
contexts, when they correspond to trace events or to calls. The latter are
implemented as breakpoints on the label layouts of the return sites.

This required extending the debugging RTTI, so that associated with each
module there is now a new data structure listing the source file names that
contribute labels with layout structures to the code of the module. For each
such source file, this table gives a list of all such labels arising from
that file. The table entry for a label gives the line number within the file,
and the pointer to the label layout structure.

compiler/llds.m:
	Add a context field to the call instruction.

compiler/continuation_info.m:
	Instead of the old division of continuation info about labels into
	trace ports and everything else, divide them into trace ports, resume
	points and return sites. Record contexts with trace ports, and record
	contexts and called procedure information with return sites.

compiler/code_info.m:
	Conform to the changes in continuation_info.m.

compiler/options.m:
	Add a new option that allows us to disable the generation of line
	number information for size benchmarking (it has no other use).

compiler/stack_layout.m:
	Generate the new components of the RTTI, unless the option says not to.

compiler/code_gen.m:
compiler/pragma_c_gen.m:
compiler/trace.m:
	Include contexts in the information we gather for the layouts
	associated with the events we generate.

compiler/call_gen.m:
	Include contexts in the call LLDS instructions, for association
	with the return site's label layout structure (which is done after
	code generation is finished).

compiler/handle_options.m:
	Delete the code that tests or sets the deleted options.

compiler/mercury_compile.m:
	Delete the code that tests the deleted options.

compiler/basic_block.m:
compiler/dupelim.m:
compiler/frameopt.m:
compiler/livemap.m:
compiler/llds_common.m:
compiler/llds_out.m:
compiler/middle_rec.m:
compiler/opt_debug.m:
compiler/opt_util.m:
compiler/value_number.m:
compiler/vn_*.m:
	Trivial changes to conform to the changes to llds.m.

compiler/jumpopt.m:
	Do not optimize away jumps to labels with layout structures.
	The jumps we are particularly concerned about now are the jumps
	that return from procedure calls. Previously, it was okay to redirect
	returns from several calls so that all go to the same label, since
	the live variable information associated with the labels could be
	merged. However, we now also associate line numbers with calls, and
	these cannot be usefully merged.

compiler/optimize.m:
	Pass the information required by jumpopt to it.

doc/user_guide.texi:
	Document that you can now break at line numbers.

	Document the new "context" command, and the -d or --detailed option
	of the stack command and the commands that set ancestor levels.

runtime/mercury_stack_layout.h:
	Extend the module layout structure definition with the new tables.

	Remove the conditional facility for including label numbers in label
	layout structures. It hasn't been used in a long time, and neither
	Tyson or me expect to use it to debug either gc or the debugger itself,
	so it has no uses left; the line numbers have superseded it.

runtime/mercury_stack_trace.[ch]:
	Extend the code to print stack traces to also optionally print
	contexts.

	Add some utility predicates currently used by the debugger that could
	also be use for debugging gc or for more detailed stack traces.

trace/mercury_trace_internal.c:
	Implement the "break <context>" command, the "context" command, and
	the -d or --detailed option of the stack command and the commands
	that set ancestor levels.

	Conditionally define a conditionally used variable.

trace/mercury_trace_external.c:
	Minor changes to keep up with the changes to stack traces.

	Delete an unused variable.

trace/mercury_trace_spy.[ch]:
	Check for breakpoints on contexts.

trace/mercury_trace_tables.[ch]:
	Add functions to search the RTTI data structures for labels
	corresponding to a given context.

trace/mercury_trace_vars.[ch]:
	Remember the context of the current environment.

tests/debugger/queen.{inp,exp}:
	Test the new capabilities of the debugger.

tests/debugger/*.{inp,exp}:
	Update the expected output of the debugger to account for contexts.
	In some cases, modify the input script to put contexts where they don't
	overflow lines.
1999-11-15 00:43:59 +00:00
Fergus Henderson
d5d75ac65a Implement deep_copy() of closures.
Estimated hours taken: 3

Implement deep_copy() of closures.

compiler/stack_layout.m:
	Change the way we generate closure layouts
	so that it matches the MR_Closure_Layout structure
	defined in runtime/mercury_ho_call.h.

runtime/mercury_deep_copy_body.h:
	Handle copying of closures, using the layout information
	in the MR_Closure_Layout structure.

runtime/mercury_deep_copy.c:
	#include "mercury_ho_call.h", since it is needed for the
	MR_Closure_Layout type.

tests/hard_coded/Mmakefile:
tests/hard_coded/copy_pred.m:
tests/hard_coded/copy_pred.exp:
	A test case for this change.
1999-10-19 04:11:44 +00:00
Zoltan Somogyi
466c844964 Make the retry command work in trailing grades (e.g. for HAL).
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.

extras/references/scoped_update.m:
extras/trailed_update/var.m:
clpr/cfloat.m:
extras/trailed_update/tests/func_trail_test.m:
extras/trailed_update/tests/func_trail_test_2.m:
	Handle MR_retry as a reason for unwinding the trail.
1999-10-08 02:56:24 +00:00
Zoltan Somogyi
73de42711a Fix a reference to a C type name.
Estimated hours taken: 0.1

compiler/stack_layout.m:
	Fix a reference to a C type name.
1999-08-15 07:50:28 +00:00
Zoltan Somogyi
3c2a19adfd Make closures always include layout information, not just in grades in which
Estimated hours taken: 51

Make closures always include layout information, not just in grades in which
typeinfo liveness is turned on. This requires separating two notions,
which were previously combined:

-	Body typeinfo liveness means that when a variable X is live, any
	typeinfo variables describing type variables that occur in the type
	of X must also be live.

-	Interface typeinfo liveness means that when the input arguments
	of a procedure include a polymorphically typed variable (e.g. X),
	typeinfo variables describing type variables that occur in the type
	of X must also be among the arguments.

This change turns on interface typeinfo liveness for procedures that either
have their address taken in the current module, or are exported and thus may
have their address taken in some other module.

compiler/hlds_pred.m:
	Centralize decisions wrt whether procedure interfaces and bodies
	use typeinfo liveness here.

compiler/options.m:
	Rename the typeinfo_liveness option as body_typeinfo_liveness,
	since this reflects its new function.

compiler/call_gen.m:
compiler/higher_order.m:
compiler/live_vars.m:
compiler/liveness.m:
compiler/unused_args.m:
	Use hlds_pred.m to make decisions about liveness.

compiler/lambda.m:
	Always include the relevant typeinfos in the interfaces of procedures
	created for lambdas.

compiler/continuation_info.m:
compiler/stack_layout.m:
compiler/unify_gen.m:
	Modify the predicates that record and use layout information about
	closures to always do so, since the necessary information is now
	always available about the interfaces of procedures which can be
	put into closures. Previously, they only did so if typeinfo_liveness
	was set.

	Also, generate information about the types of the variables in a
	closure from the pred_info's arg types field, not from the proc_info's
	var types field, because unlike the latter, it is valid even for
	imported predicates.

compiler/hlds_out.m:
	Print the non-clause-related information in the clauses_info part
	of a pred_info (e.g. the type parameters) even if the predicate
	has no actual clauses. Simplify the code a bit by getting rid of
	a duplicate test.

compiler/middle_rec.m:
	Require that the code generated for the base case not refer to any
	stack slots if this way of generating code is to be used. This is
	necessary because the base case is executed when the current procedure
	has no stack frame, and thus any references to stack slots would
	refer to and possibly overwrite the data in another procedure's frame.
	In the absence of requiring body typeinfo liveness for exported
	procedures, such references were not generated; in its presence,
	they were. However, we now require only interface liveness for
	exported procedures, so we can still use middle recursion for them.

compiler/handle_options.m:
	Do not turn off middle_rec if (body) typeinfo liveness is turned on,
	now that the bug has been fixed. For polymorphic predicates, the base
	case will still contain references to stack slots, and thus the
	middle-rec optimization will not applied for them, but the optimization
	may apply to monomorphic predicates.

compiler/passes_aux.m:
	Add the ability to call compiler passes with the procedure id
	as well as the predicate id of the procedure they are passed.

tests/hard_coded/typeclasses/Mmakefile:
	Refer to --body-typeinfo-liveness instead of --typeinfo-liveness.
1999-08-13 01:43:50 +00:00
Fergus Henderson
d66c8481ae Some more changes to minimize the complexity of the intermodule dependencies.
Estimated hours taken: 4

Some more changes to minimize the complexity of the intermodule dependencies.
In particular, ensure that hlds_module.m does not need to import llds.m.

compiler/hlds_module.m:
compiler/llds.m:
	Move the definition of the c_interface_info type (and the types
	used for all its fields) from llds.m into hlds_module.m, since
	this type contains high-level information about the user-level
	C interface stuff that is not directly related to the LLDS and
	is needed by other back-ends.

compiler/hlds_module.m:
compiler/llds.m:
compiler/mercury_compile.m:
compiler/code_gen.m:
compiler/stack_layout.m:
compiler/table_gen.m:
	Move the `global_data' type from hlds_module.m into llds.m,
	since this type contains low-level stuff that is dependent on
	the LLDS.  Delete the `global_data' field of the module_info,
	instead passing it around as a separate argument where needed.
	Move the code for inserting llds__tabling_pointer_vars into the
	global_data from table_gen.m to code_gen.m, since this is
	dependent on the LLDS and table_gen.m should be a pure
	HLDS->HLDS transformation, so that it can work with other
	back-ends.

compiler/continuation_info.m:
	Update some comments which this change makes obsolete.

compiler/optimize.m:
	Delete the import of module hlds_data, since it is no longer needed.
1999-07-12 06:21:25 +00:00
Zoltan Somogyi
e3232306cb Add a module layout structure containing a string table and a table of
Estimated hours taken: 14

Add a module layout structure containing a string table and a table of
pointers to the proc layouts of the module's procedures. This speeds up
debugger initialization, and reduces the executable size of the compiler
by almost 1.2 Mb (about 3.7%) when compiled with debugging.

Instead of representing variables names as strings (32 or 64 bit pointers)
in the debugger's static data structures, with the string's prefix representing
the variable's number (e.g. "5:X"), represent them as a 16-bit variable number
and a 16 bit offset into the module-wide string table. This gains simplicity
of processing (no more search for the ":") and reduces the amount of storage
required, a bit on 32-bit platforms (we don't have to store "5:ModuleInfo"
and "10:ModuleInfo" strings separately, and there are no string prefixes to
store) and more on 64-bit platforms.

The 16-bit limits are generous. A procedure with more than 64K variables will
take forever to compile (that is why we impose a 4K limit on the number
of variables in inlining), and even the string tables of typecheck.m and
make_hlds require less than four kilobytes each. Exceeding the limits
would require code no human would write. Automatically generated code may
be a problem, but the help the debugger can give on such code is limited
already. In any case, we detect overflows and handle them sensibly.

This change does not enhance the debugger to take advantage of the easier
availability of variable numbers, except to improve the implementation
of retry; that will come later.

The inclusion of the procedure table in the module layout structure
reduces the cost of registering all procedures in all modules,
a task usually performed at the time of the setting of the first breakpoint.
This used to require processing all the internal labels in the label table,
and thus used to take a few seconds for large executables. The sweep of
all internal labels is no longer required, so registering is now much faster.

runtime/mercury_stack_layout.h:
	Add the definition of MR_Module_Layout.

	Modify label layouts to represent names as offsets in the string table,
	not as raw character pointers. This required modifing proc layouts
	to include a pointer to the module's layout, so you can find the
	string table.

	Update the macros that look up variable names.

runtime/mercury_layout_util.h:
	Use the updated macros for looking up variable names.

runtime/mercury_wrapper.[ch]:
	Add a new indirect pointer, MR_register_module_layout, which points
	to a function that registers a module layout, or is NULL if debugging
	is not enabled.

runtime/mercury_init.h:
	Declare the function whose address may be assigned to
	MR_register_module_layout in a <main>_init.c file.

util/mkinit.c:
	Initialize MR_register_module_layout with either the address of
	MR_register_module_layout_real or NULL, depending on whether
	debugging is enabled or not.

compiler/continuation_info.m:
	Don't give names (V_n) to nameless variables, because we don't want
	them to be included in the variables debugging knows about.

compiler/llds.m:
	Add a new function symbol to the type data_addr, which stands for
	the module layout structure of the named (now always the current)
	module.

	Add a new function symbol to the type rval_const. The new function
	symbols, multi_string_const, contains an array of characters of an
	explicitly given length, which consists of several strings, each
	terminated by a null character.

compiler/llds_out.m:
	Accommodate the changes to llds.m, and expand the module initialization
	code to register the module layout structure, if the pointer to the
	registration function is not NULL.

compiler/stack_layout.m:
	Generate the new data structures for representing variable names,
	as well as the module layout.

compiler/mercury_compile.m:
	Rename some variables to reflect the fact that stack_layout.m can
	now include a module layout structure in the list of static layout
	structures it returns.

compiler/dupelim.m:
compiler/exprn_aux.m:
compiler/jumpopt.m:
compiler/opt_debug.m:
	Minor changes to accommodate multi_string_consts.

trace/mercury_trace_tables.[ch]:
	Replace the old data structures for recording information about
	each debuggable module with the module layout structure, and
	register module layout structures directly, instead of trying
	to discover them through the internal label table.

trace/mercury_trace.[ch]:
	Now that it is more easily accessible, use variable numbers
	instead of variable names to find the current locations of
	the input arguments when implementing retry. Unlike our previous
	method, this works even if the user names some variables HeadVar__1,
	etc.

	Remove an unnecessary export of an internal function.

trace/mercury_trace_external.c:
trace/mercury_trace_internal.c:
runtime/mercury_layout_util.c:
	Use the updated macros for looking up variable names.
1999-05-28 05:29:51 +00:00
Tyson Dowd
3e7367b29c Add options to turn off various RTTI features.
Estimated hours taken: 5

Add options to turn off various RTTI features.  Also switch off the
generation of variable names for accurate GC (this should be the default
unless we are tracing).

These new options are for space measurement only.  There is little
chance the code will link or work if the options are used.

compiler/base_type_layout.m:
	Let --type-ctor-layout and --type-ctor-functors control the
	generation of layout and functors.

compiler/mercury_compile.m:
	Let --type-ctor-info control the generation of type_ctor_info
	structures.

compiler/stack_layout.m:
	Turn off the generation of variable names structures unless
	tracing.

compiler/unify_proc.m:
	Use --special-preds to control the generation of unify and
	compare predicates.

compiler/options.m:
	Add the new options (as internal use only options).
1999-05-27 05:14:44 +00:00
Zoltan Somogyi
f97297c65d Compress the representation of value shape information.
Estimated hours taken: 3

Compress the representation of value shape information. Instead of a
pointer to a two-word cell containing a pseudotypeinfo and a dummy inst,
just have the pseudotypeinfo itself.

However, we were previously using small integer "pointers" to represent
special kinds of values such as saved succips, hps, etc. Since pseudotypeinfos
use small integer values for their own purposes (to represent type variables),
we can't continue doing this. Therefore this change also creates type_ctor_info
structures for each of these special kinds of values. These values are only
used by the garbage collector, so nothing else is affected.

compiler/stack_layout.m:
	Effect the above change.

library/builtin.m:
	Add type_ctor_info structures and their components for the new kinds
	of values.

runtime/mercury_stack_layout.h:
	Delete the section on shape information, since we don't generate
	such structures anymore.

runtime/mercury_layout_util.c:
	Access pseudotypeinfos directly, not through the shape structure.

runtime/mercury_type_info.h:
	Add new values to the type_ctor_layout enum for the special kinds
	of values.
1999-05-07 08:09:05 +00:00
Zoltan Somogyi
c2da42e6d0 Allow the compiler to handle create rvals whose arguments have a size
Estimated hours taken: 16

Allow the compiler to handle create rvals whose arguments have a size
which is different from the size of a word. Use this capability to reduce
the size of RTTI information, in two ways.

The first way is by rearranging the way in which we represent information
about the live values at a label. Instead of an array with an entry for
each live value, the entry being a pair of Words containing a shape
representation and a location description respectively, use an array
of shape representations (still Words), followed by an array of 32-bit ints
(which may be smaller than Word) describing locations whose descriptions
don't fit into 8 bits, followed by an array of 8-bit ints describing
locations whose descriptions do fit into 8 bits.

The second way is by reducing the sizes of some fields in the C structs
used for RTTI. Several of these had to be bigger than necessary in the
past because their fields were represented by the args of a create rval.

On cyclone, this reduces the size of the object file for queens.m by 2.8%.

IMPORTANT
Until this change is reflected in the installed compiler, you will not be
able to use any modules compiled with debugging in your workspaces if the
workspace has been updated to include this change. This is because the RTTI
data structures generated by the old installed compiler will not be compatible
with the new structure definitions.

The workaround is simple: if your workspace contains modules compiled with
debugging, don't do a cvs update until this change has been installed.

configure.in:
	Check whether <stdint.h> is present. If not, autoconfigure
	types that are at least 16 and 32 bits in size.

runtime/mercury_conf.h.in:
	Mention the macros used by the configure script, MR_INT_LEAST32_TYPE
	and MR_INT_LEAST16_TYPE.

runtime/mercury_conf_param.h:
	Document the macros used by the configure script, MR_INT_LEAST32_TYPE
	and MR_INT_LEAST16_TYPE.

runtime/mercury_types.h:
	If <stdint.h> is available, get the basic integer types (intptr_t,
	int_least8_t, etc) from there. Otherwise, get them from the
	autoconfigure script. Define types such as Word in terms of these
	(eventually) standard types.

runtime/mercury_stack_layout.h:
	Add macros for manipulating short location descriptions, update the
	types and macros for manipulating long location descriptions.
	Modify the way the variable count is represented (since it now must
	count locations with long and short descriptions separately),
	and move it to the structure containing the arrays it describes.

	Reduce the size of the some fields in structs. This required some
	reordering of fields to avoid the insertion of padding by the compiler,
	and changes to the definitions of some types (e.g. MR_determinism).

runtime/mercury_layout_util.[ch]:
runtime/mercury_stack_trace.c:
runtime/mercury_accurate_gc.c:
trace/mercury_trace.c:
trace/mercury_trace_external.c:
trace/mercury_trace_internal.c:
	Update the code to conform to the changes to stack_layout.h.

compiler/llds.m:
	Modify the create rval in two ways. First, add an extra argument to
	represent the types of the arguments, which used to always be implicit
	always a word in size, but may now be explicit and possibly smaller
	(e.g. uint_least8). Second, since the code generator would do the wrong
	thing with creates with smaller than wordsize arguments, replace
	the old must-be-unique vs may-be-nonunique bool with a three-valued
	marker, must_be_dynamic vs must_be_static vs can_be_either.

	Add uint_least8, uint_least16, uint_least32 (and their signed variants)
	and string as llds_types.

	Add a couple of utility predicates for checking whether an llds_type
	denotes a type whose size is the same as word.

compiler/llds_out.m:
	Use explicitly given argument types when declaring and initializing
	the arguments of a cell, if they are given.

compiler/llds_common.m:
	Don't conflate creates with identical argument values but different
	C-level argument types. The probability of a match is minuscule anyway.

compiler/stack_layout.m:
	Use the new representation of creates to generate the new versions of
	RTTI data structures.

compiler/code_exprn.m:
	If a create is marked must_be_static, don't inspect the arguments
	to decide whether it can be static or not. If it can't, we'll get
	an abort later on in llds_out or during C compilation anyway.

compiler/base_type_layout.m:
	When creating pseudo typeinfos, return the llds_type of the resulting
	rval.

	Minor changes required by the change in create.

compiler/base_type_info.m:
compiler/base_typeclass_info.m.m:
compiler/code_util.m:
compiler/dupelim.m:
compiler/exprn_aux.m:
compiler/jumpopt.m:
compiler/livemap.m:
compiler/lookup_switch.m:
compiler/middle_rec.m:
compiler/opt_debug.m:
compiler/opt_util.m:
compiler/string_switch.m:
compiler/unify_gen.m:
compiler/vn_cost.m:
compiler/vn_filter.m:
compiler/vn_flush.m:
compiler/vn_order.m:
compiler/vn_type.m:
compiler/vn_util.m:
compiler/vn_verify.m:
	Minor changes required by the change in create.

library/benchmarking.m:
library/std_util.m:
	Use the new macros in hand-constructing proc layout structures.

library/Mmakefile:
	Add explicit dependencies for benchmarking.o and std_util.o
	on ../runtime/mercury_stack_layout.h. Although this is only a subset
	of the truth (in reality, all library objects depend on most of the
	runtime headers), it is a good tradeoff between safety and efficiency.
	The other runtime header files tend not to change in incompatible ways.

trace/Mmakefile:
	Add explicit dependencies for all the object files on
	../runtime/mercury_stack_layout.h, for similar reasons.
1999-04-30 06:21:49 +00:00
Zoltan Somogyi
3bf462e0b7 Switch to a closure representation that includes runtime type and procedure id
Estimated hours taken: 36

Switch to a closure representation that includes runtime type and procedure id
information, so that closures can be copied, garbage collected, printed, etc.

This RTTI information is not yet used. Adding code to use it would be futile
until Tyson finishes his changes to the other RTTI data structures.

Note also that this change provides the information required for solving the
problem of trying to deep copy closures only for grades that include
--typeinfo-liveness. Providing this info for other grades is future work.

configure.in:
	Find out what the right way to refer to a variable-sized array
	at the end of a struct is.

runtime/mercury_ho_call.h:
	New file to define the structure of closures and macros for accessing
	closures.

runtime/Mmakefile:
	Add the new header file.

runtime/mercury_ho_call.c:
	Add an entry point to handle calls to new-style closures. The code
	to handle old-style closures, which was unnecessarily duplicated for
	each code model, stays until all the installed compilers use the new
	closure representation.

	Until that time, the new entry point will contain code to detect
	the use of old-style closures and invoke the old code instead.
	This allows stage1s compiled with old compilers to use the old style
	and stage2 to use the new style without any special tricks anywhere
	else.

	Add a new entry point to handle method calls of all code models.
	The old entry points, which had the same code, will also be deleted
	after this change has been bootstrapped.

runtime/mercury_calls.h:
	Remove the macros that call closures. Their interface sucked, they
	were not used, and their implementation is now out of date.

runtime/mercury_stack_layout.h:
	Add a new type, MR_Type_Param_Locns, for use by the C type
	representing closures. Since MR_Stack_Layout_Vars has a field,
	MR_slvs_tvars, which references a data structure identical
	in every way to MR_Type_Param_Locns, change the type of that field
	to this new type, instead of the previous cheat.

runtime/mercury_layout_util.h:
	Minor update to conform to the new type of the MR_slvs_tvars field.
	(This is the only use of that field in the system.)

runtime/mercury_type_info.h:
	Add new types MR_TypeInfo and MR_PseudoTypeInfo. For now, they
	are just Word, but later we can make them more accurate.
	In the meantime, we can refer to them instead of to Word,
	making code clearer. One such reference is now in mercury_ho_call.h.

compiler/notes/release_checklist.html:
	Add a reminder to remove the redundant code from mercury_ho_call.c
	after bootstrapping.

compiler/llds.m:
	Replace three code addresses for calling closures and another three
	for calling methods with one each.

compiler/call_gen.m:
compiler/dupelim.m:
compiler/opt_debug.m:
compiler/opt_util.m:
compiler/llds_out.m:
	Trivial updates in accordance with the change to llds.m

compiler/code_info.m:
	Move the code to handle layouts to continuation_info.m,
	since that's where it belongs. Leave only the code for picking
	up parameters from code_infos and for putting results back in there.

	Remove the redundant arguments of code_info__init, and extract
	them from ProcInfo, to make clear that they are related.

compiler/code_gen.m:
	Since we pass ProcInfo to code_info__init, don't pass its components.

compiler/continuation_info.m:
	Add the code moved from code_info.m, in a form which takes explicit
	arguments for things that used be hidden in the code_info.

	Add new code, closely related to the moved code, that creates
	layout info from a procedure's argument info, rather than from a
	(part of) the current code generator state. This way, it can be
	invoked from places that don't have a code_info for the procedure
	for which they want to generate layouts. This is the case when
	we generate layouts for closures.

compiler/par_conj_gen.m:
compiler/trace.m:
	Minor changes required by the move of stuff from code_info to
	continuation_info.

compiler/stack_layout.m:
	Export some predicates for use by unify_gen.

compiler/unify_gen.m:
	Switch to creating new style closures, complete with layout info.

	Optimize the code for extending closures a bit. By copying the
	fixed words of the closure outside the loop, we avoid incurring
	the loop overhead twice.

compiler/code_util.m:
	Add a couple of utility predicates for continuation_info.m and
	unify_gen.m

library/benchmarking.m:
library/std_util.m:
	Refer to the new entry point for handling closures.

browser/dl.m:
	Use the new closure representation.

	Note that extras/dynamic_linking/dl.m, which is supposed to be
	the same as browser/dl.m but is not, should also be updated, but
	this will be handled later by Fergus.

tests/hard_coded/closure_extension.{m,exp}:
	A new test case to exercise the code for extending closures.

tests/hard_coded/Mmakefile:
	Enable the new test case.
1999-04-16 06:05:49 +00:00
Zoltan Somogyi
27f024b2e9 Reorganize the handling of global data structures, and expose the table
Estimated hours taken: 16

Reorganize the handling of global data structures, and expose the table
pointers for tabled predicates to allow the tables to be reset to empty
by hand-written C code for benchmarking purposes.

compiler/hlds_module.m:
	Introduce a new submodule for dealing with global data.
	At the moment it deals with (a) layout structures and (b)
	tabling pointers.

compiler/continuation_info.m:
	Remove the data structures and predicates whose equivalents are now
	in hlds_module.

compiler/llds.m:
	Introduce a new kind of item, that of compiler-generated variables
	whose value is not defined by rvals. At the moment, the only such
	item is a tabling pointer variable.

compiler/mercury_compile.m:
	Include the new kind of item in the generated LLDS.

compiler/table_gen.m:
	Use the new kind of item instead of a static variable declaration
	in pragma C code to hold the tabling pointer.

	Remove lots of spaces at ends of lines, since many of these screw up
	paragraph commands in vi.

compiler/base_type_layout.m:
compiler/bytecode_gen.m:
compiler/code_gen.m:
compiler/code_util.m:
compiler/dependency_graph.m:
compiler/hlds_out.m:
compiler/llds_out.m:
compiler/mercury_to_mercury.m:
compiler/switch_gen.m:
compiler/transform_llds.m:
compiler/unify_gen.m:
	Handle the changes in the data structures.

library/private_builtin.m:
	Remove the predicate get_table, which is no longer used after the
	changes to table_gen.m.
1998-11-24 03:57:47 +00:00
Zoltan Somogyi
e12c82de10 Change the LLDS representation of a module from containing a list of c_modules
Estimated hours taken: 6

Change the LLDS representation of a module from containing a list of c_modules
to containing four lists, of (a) compiler generated C code, (b) compiler
generated data, (c) user-written C code and (d) exported C functions.
This simplifies the several passes (e.g. transform_llds, llds_common)
that only care about one kind of "c_module".

compiler/llds.m:
	Change the definition of c_file along the lines above.

compiler/llds_out.m:
	Write out the new data structure.

	Change some predicate names to make it clear what predicates
	handle the splitting of C files.

	Remove the obsolete #define of MR_USE_REDOFR

compiler/base_type_info.m:
compiler/base_type_layout.m:
compiler/base_typeclass_info.m:
	Adapt to the new data structure.

compiler/llds_common.m:
	Use the new data structure to simplify the code.
	Change the order of some arguments to conform to our usual
	conventions.

compiler/transform_llds.m:
	Use the new data structure to simplify the code.

compiler/mercury_compile.m:
	Adapt the gathering of the c_file components to the new data structure.
	Fix a predicate name.

	Fix a bug: stack layouts were always treated as static data, although
	proc layouts are only static if we have static code addresses.

compiler/stack_layout.m:
	Return the proc layouts and the label layouts in separate lists,
	since only label layouts are always static data.
1998-11-19 06:13:36 +00:00
Zoltan Somogyi
650fb78cd5 Add compiler support for Mark's declarative debugger.
Estimated hours taken: 5

Add compiler support for Mark's declarative debugger. The runtime support
will come later. from Mark.

compiler/options.m:
	Add a new option, --trace-decl, that causes the compiler to reserve
	two extra stack slots in every stack frame. The declarative debugger
	will use these slots to store pointers to the proof tree node of the
	current call, and the location in the parent's proof tree node where
	the proof tree node of this call ought to be inserted.

	Since there is no runtime support yet, the option is not yet included
	in the help message.

compiler/trace.m:
	Generalize the code for reserving stack slots for tracing, and
	expand it to conditionall allocate two slots for the declarative
	debugger.

	Add a new type trace_slot_info, and use that instead of maybe(int)
	to describe the stack slots used by the trace system, for passing
	through code_info and code_gen to continuation_info.

compiler/code_info.m:
compiler/code_gen.m:
compiler/continuation_info.m:
	Minor changes (mostly to variable names and comments) to refer
	to trace_slot_info.

compiler/stack_layout.m:
	Include the numbers of the two stack slots used for declarative
	debugging in the procedure's stack layout structure. Actually,
	since these two stack slots are always adjacent, we only store
	the number of the first.

runtime/mercury_stack_layout.h:
	Extend the MR_Stack_Layout_Entry struct to cover the new entry.

doc/user_guide.texi:
	Add documentation of the new option, commented out for now.
1998-11-18 08:12:13 +00:00
Zoltan Somogyi
620ce80408 Make stack layout structures work in grades that do not have static code
Estimated hours taken: 16

Make stack layout structures work in grades that do not have static code
addresses. (Although it seems that those grades do not work in the absence
of layout structures.)

compiler/llds_out.m:
	If an entry label has a layout structure, then during its
	initialization, output a macro that will, if necessary,
	initialize the code address inside its layout structure.

	Do not output a const before a layout structure if the macro
	will actually initialize a code address inside it.

compiler/llds.m:
	Separate out proc_layouts from internal_layouts in the type
	data_name, since only proc_layouts have code addresses in them.

	Clarify the existing documentation of the label type's alternatives.
	This should help prevent the recurrence of bugs like the one in
	mercury_goto.h.

compiler/stack_layout.m:
	Replace code addresses inside proc layout structures with a dummy
	value if code addresses are not static.

runtime/mercury_goto.h:
	Fix a long-standing bug: init_local should treat its argument
	as a procedure entry label, not as a label internal to a procedure.

runtime/mercury_stack_layout.h:
	In the macros for creating proc layouts by hand-written C code,
	allow for the absence of static code addresses, and add a new
	macro that fills in the code address slot in proc layouts
	at initialization time if necessary.

library/benchmarking.m:
library/private_builtin.m:
library/std_util.m:
	Add calls to the new initialization macro to accompany hand-written
	proc layout structures.
1998-11-12 03:16:29 +00:00
Zoltan Somogyi
8caba4e15d Make it possible to compile a module (e.g. std_util) without debugging,
Estimated hours taken: 18

Make it possible to compile a module (e.g. std_util) without debugging,
while still allowing debuggable code called from that module via higher-order
predicates (e.g. solutions) to have a proper stack trace.

compiler/options.m:
	Add the new option --stack-trace-higher-order.

compiler/mercury_compile.m:
	Always invoke continuation_info and stack_layout, since it is no
	longer the case that either all procedures or none get layout
	structures generated for them, and the other modules are in a better
	position to make that decision.

compiler/continuation_info.m:
	Handle the extra tests required by the change to mercury_compile.m.

	When we gather info about a procedure, remember whether that
	procedure must have a procedure layout that includes the procedure id
	section.

compiler/stack_layout.m:
	Use the flag remembered by continuation_info to help decide
	whether we need procedure layout structures.

	Fix an old space wastage: after generating marker saying that
	the second and later groups of fields of a procedure layout are
	not present, do not generate another marker saying that the
	third group of fields is not present. Since it was in the wrong
	position, it did not have the right meaning; it only worked because,
	due to the presence of the first marker, it was never looked at anyway.

compiler/code_gen.m:
	Use the new capability of continuation_info.m to require
	procedure layouts including procedure id sections for any predicate
	that has higher-order arguments, if --stack-trace-higher-order is set.

compiler/globals.m:
	Rename want_return_layouts as want_return_var_layouts, since this
	is a more accurate representation of what the predicate does.

compiler/call_gen.m:
compiler/code_info.m:
	Conform to the change in globals.m.

compiler/llds_out.m:
	Separate the c_modules containing compiler-generated code into two
	groups, those that define labels that have stack layouts and those
	that don't. In most cases one or the other category will be empty,
	but with --stack-trace-higher-order, the c_modules containing
	higher-order procedures will have stack layouts, while others will
	not.

	Reorganize the way the way the initialization functions are generated,
	by putting c_modules falling into different categories into different
	bunches. c_module falling into the first category always have their
	initialization code included, while those in the second category
	have it included only if the old flag MR_MAY_NEED_INITIALIZATION
	is set.

	Delete the obsolete #define of MR_STACK_TRACE_THIS_MODULE.

	Improve some predicate names, in an effort to prevent confusion
	about what a "file" is (since the code uses more than one meaning,
	given the presence of --split-c-files).

compiler/pragma_c_gen.m:
	Fix an old bug: s/NONDET_FIXED_SIZE/MR_NONDET_FIXED_SIZE/.
	Required for the change to library/string.m.

doc/user_guide.texi:
	Document the new option.

runtime/mercury_goto.c:
	Simplify the conditions under which labels get added to the label
	table with:

	- The macros init_{entry,label,local}_ai always add
	the label to the label table without a layout structure.

	- The macros init_{entry,label,local}_sl always add it with a layout
	structure.

	- Whether the macros init_{entry,label,local} with no suffix
	add the label to the label table depends on the values of other
	configuration parameters, but they will never include a layout
	structure.

	The intended use is that any label that has a layout structure should
	be initialized with a _sl macro. Any other label that should always
	be in the label table if the label table is needed at all (labels
	such as do_fail) should be initialized with _ai. Everything else
	should be initialized with a suffixless macro.

runtime/mercury_conf_params.c:
	Remove MR_USE_STACK_LAYOUTS and MR_STACK_TRACE_THIS_MODULE, since
	due to the simplification of mercury_goto.h, they are not used anymore.

runtime/mercury_stack_layout.h:
	Remove the old macros for creating layout structures with bogus
	contents, and replace them with new macros for creating layout
	structures with meaningful contents.

runtime/mercury_engine.c:
runtime/mercury_wrapper.c:
	Remove bogus layout structures. Ensure the labels defined here
	always get into the label table.

runtime/mercury_ho_call.c:
	Remove bogus layout structures. Add proper ones where necessary.

runtime/mercury_bootstrap.c:
runtime/mercury_type_info.c:
	Remove bogus layout structures.

runtime/mercury_boostrap.h:
	Add this new file for bootstrapping purposes.

	Temporarily #define NONDET_FIXED_SIZE as MR_NONDET_FIXED_SIZE, since
	pragma_c_gen.m refers to the former until the update to it gets
	installed.

runtime/Mmakefile:
	Add a reference to mercury_boostrap.h.

library/builtin.m:
	Remove bogus layout structures.

library/array.m:
library/benchmarking.m:
library/private_builtin.m:
	Remove bogus layout structures. Add proper ones.

library/std_util.m:
	Remove bogus layout structures. Add proper ones.

	Replace references to framevar(n) with references to MR_framevar(n+1).

	Fix an old bug in code under #ifndef COMPACT_ARGS: in the
	implementation of mercury____Compare___std_util__univ_0_0_i1, the
	succip register was not being saved across the call to
	mercury__compare_3_0.

library/string.m:
	Remove the need for bogus layout structures, by converting the
	implementation of string__append(out, out, in) from hand-written
	C module into nondet pragma C code.
1998-11-05 03:53:48 +00:00
Zoltan Somogyi
e196f28971 Improve the debugger's handling of compiler-generated and inter-module-inlined
Estimated hours taken: 3

Improve the debugger's handling of compiler-generated and inter-module-inlined
procedures.

compiler/stack_layout.m:
	Update a comment.

runtime/mercury_stack_layout.h:
	Introduce provisions for dealing with the procedure id section
	of the layout structures of compiler-generated procedures.

runtime/mercury_stack_trace.c:
	Use the new provisions to generalize the function that prints out
	procedure ids for both stack traces and the debugger, so that it now
	works for both user-written and compiler-generated procedure, and
	prints out the extra info needed for a full identification in cases
	where the defining and declaring modules are not the same. (This can
	happen due to intermodule inlining, or the generation of local
	unification procedures for imported types.)

trace/mercury_trace_tables.c:
	Update the code to conform to the changes in mercury_stack_layout.h.
	We still collect layout info only from user-written procedures,
	which means you can put breakpoints on only user-written procedures.

	Putting break-points on compiler-generated procedures would be
	unnecessary, even in the case of user-defined equality.

trace/mercury_trace_external.c:
	Update the code to conform to the changes in mercury_stack_layout.h,
	and add comments asking Erwan to eventually either generalize his code
	or explicitly restrict it to user-defined procedures.
1998-10-28 05:24:20 +00:00
Zoltan Somogyi
beaa554171 Extend the layout scheme to handle typeinfos inside typeclass infos,
Estimated hours taken: 16

Extend the layout scheme to handle typeinfos inside typeclass infos,
and thus enable the debugger (and later native gc) to work with programs
that use type classes and existential types.

compiler/llds.m:
	Change the data structure that holds information about the locations
	of the typeinfo variables of the tvars active at call return sites
	from set(pair(tvar, lval)) to map(tvar, set(layout_locn)).

	The change from set to map avoids the possibility of inadvertently
	duplicating the info for a give type variable.

	The change to explicitly keep a set of locations in which the typeinfo
	var may be found allows us to use set intersection on those sets if
	(a) the program point may be reached via more than one path, and
	(b) not all paths have the same sets. Both of these can happen in
	programs that use type classes.

	The change from lval to layout_locn (which encodes either an lval,
	or an lval representing a typeclass info and an (indirect) offset
	inside that typeclass info) is necessary support programs with
	type classes.

compiler/continuation_info.m:
	Change the data structure that holds information about the locations
	of the typeinfo variables of the tvars active at a particular program
	point the same way and for the same reasons as in llds.m.

	Take set intersections of typeinfo var locations whenever we find
	multiple live variable info records for the same label.

compiler/call_gen.m:
	Delay the construction of the return live variable information
	until the code generator state has been updated to reflect where
	things will be on return, instead of trying to cobble up this
	info into the code generator state that reflects the point just
	before the call. Apart from being cleaner, this is necessary
	to avoid compiler aborts for programs that use existential types.
	The old compiler could not find the typeinfos of any existentially
	quantified type vars, since they do not exist before the call.

compiler/code_info.m:
	Rewrite and generalize the code for generating live value information.

compiler/trace.m:
	Remove the specialized code for generating live value information;
	call code_info instead.

compiler/stack_layout.m:
	Pick one of several possible locations for a typeinfo var.

	Generate the new indirect layout location descriptions.

	Reduce the number of tag bits used to describe different kinds of
	lvals, to leave more room for the indirect information.

compiler/*.m:
	Conform to the above data structure changes.

compiler/hlds_pred.m:
	Clarify the documentation of type_info_locn.

runtime/mercury_stack_layout.h:
	Update the section that deals with MR_Live_Lval to take
	indirect typeinfo locations into account.

runtime/mercury_layout_util.c:
	Handle indirect typeinfo locations when interpreting layout structures.

runtime/mercury_layout_util.c:
trace/mercury_trace_internal.c:
	Ignore variables whose names start with TypeClassInfo.

runtime/mercury_accurate_gc.c:
runtime/mercury_agc_debug.c:
	Add markers to remind Tyson to handle indirect typeinfo locations.

tests/debugger/implied_instance.{m,inp,exp}:
tests/debugger/multi_paramster.{m,inp,exp}:
tests/debugger/existential_type_classes.{m,inp,exp}:
	Copies of the tests in tests/hard_coded/typeclasses, modified to
	avoid or delay I/O, so that the calls to I/O preds that may or may
	not be traced to do not affect the output.

tests/debugger/Mmakefile:
	Add the new test cases.

	Remove references to the *_lib variants of the old test cases.
	They are not necessary if I/O is delayed until after the last
	reported trace event.

tests/hard_coded/typeclasses/Mmakefile:
	Remove --trace deep from existential_type_classes, since that
	aspect of the test case is now covered in the debugger directory.
1998-10-23 00:42:02 +00:00
Zoltan Somogyi
16f3d4ccaa This checkin has several major purposes, set out in the sections below,
Estimated hours taken: 240

This checkin has several major purposes, set out in the sections below,
all connected with the implementation of the new debugger command set.

DOCUMENT NEW DEBUG COMMAND SET

doc/user_guide.texi:
	Add a new section on the debugger. The description of the commands
	is complete, but some of the background sections, and the section
	about how to build debuggable executables, are not yet done.

	Update the documentation of the tracing options.

doc/generate_mdb_doc:
	A new shell script that automatically converts some of the new
	sections of the user guide into the online documentation of the
	debugger.

doc/mdb_categories:
	The fixed initial part of the online documentation.

doc/Mmakefile:
	Add rules for creating mdb_doc, the file that is the online
	documentation of the debugger, and for installing it together
	with mdbrc.

Mmake.common.in:
	Define INSTALL_DOC_DIR for doc/Mmakefile.

scripts/mdbrc.in:
	A debugger command script that reads in the online documentation
	and then defines some standard aliases.

configure.in:
	Define the variable that scripts/mdb.in and scripts/mdbrc.in use
	to find the right files, and get configure to perform the
	substitutions.

configure.in:
scripts/mdb:
scripts/mdb.in:
	Replace mdb with mdb.in. Mdb is now created during configuration
	from mdb.in, filling in the name of the file that contains the default
	debugger initialization commands.

util/info_to_mdb.c:
	A program that does most of the work involved in automatically
	converting user guide sections into online documentation.
	(This couldn't easily be written in sh, because sh's read
	command has no notion of pushback.)

util/Mmakefile:
	Add info_to_mdb to the list of targets.

tools/bootcheck:
	Make sure that the tests in tests/debugger are executed with an
	initialization setup that is equivalent to what users will see
	by default.

REORGANIZE TRACING OPTIONS

compiler/globals.m:
compiler/handle_options.m:
compiler/options.m:
compiler/trace.m:
	Reorganize the handling of trace levels around the new options
	--trace-internal, --trace-redo, and --trace-return.

compiler/*.m:
	Use the new ways of getting at trace levels.

tests/hard_coded/typeclasses/Mmakefile:
	s/--trace all/--trace deep/

SUPPORT RETRY

compiler/trace.m:
	After every call to MR_trace(), emit code that checks whether it
	should jump away, and if yes, performs the jump. This is used to
	implement retry. (The debugger cannot execute the jump itself
	because it is in the wrong C stack frame.)

compiler/llds.m:
compiler/continuation_info.m:
compiler/stack_layout.m:
	Modify the data structures that record information about live
	value at program points, to record the identity of each variable.
	This is necessary for the implementation of the restart command,
	since we do not want to confuse two distinct variables just because
	they have the same name. For example, a variable whose name is X
	and number is 5 is now recorded in the name array as "5:X".

	Clean up the data structure a bit, so that we don't have to store
	dummy names for values that are not variables.

compiler/*.m:
	Minor changes to conform to the data structure changes.

runtime/mercury_stack_layout.h:
	Redefine an existing macro to strip away the initial number: prefix
	from the "name" of a variable (keeping its original function on
	changed data), and add a new one to access the raw unstripped data.

runtime/mercury_init.h:
runtime/mercury_wrapper.h:
	Update the prototype of MR_trace_{fake,real}, and the type of the
	global that points to them.

runtime/mercury_layout_util.h:
	Add an extra function, MR_get_register_number, for use by retry.

USE FIXED STACK SLOTS FOR TRACE INFO

compiler/code_gen.m:
compiler/code_info.m:
compiler/live_vars.m:
compiler/trace.m:
	If execution tracing is enabled, reserve the first few stack slots
	to hold the event number of the call event, the call number, the
	call depth, the redo layout structure address (if generating redo
	events) and the from_full flag at the time of call (if we are doing
	shallow tracing). By allocating the first four of these to fixed stack
	slots, the debugger knows where to look for them without having
	to be told. It finds out the location of the fifth, if needed,
	from a new slot in the proc layout structure. (It is not possible
	to allocate all five to fixed stack slots without wasting stack space
	in some cases.)

compiler/trace.m:
	Remove from the call to MR_trace the parameters that are now in fixed
	stack slots, since MR_trace can now look them up itself.

compiler/continuation_info.m:
compiler/stack_layout.m:
	Add an extra field to the proc_layout_info. If the module is shallow
	traced, this field says which stack slot holds the saved value of
	MR_from_full. If it is not shallow traced, this field says that
	there is no such stack slot.

runtime/mercury_stack_layout.h:
	Add macros for accessing the fixed stack slots holding the event
	number of the call event, the call number, the call depth, and,
	at a redo event, the redo layout structure address.

	Support the new field in proc layouts that gives the location of the
	from-full flag (if any).

runtime/mercury_trace_base.[ch]:
trace/mercury_trace.[ch]:
	Remove the call number and call depth arguments from MR_trace
	and its avatars, since this info is now in fixed stack slots
	in every procedure that can call MR_trace. This should reduce
	the size of the executable significantly, since there are lots
	of calls to MR_trace.

runtime/mercury_init.h:
runtime/mercury_wrapper.h:
	Update the prototype of MR_trace_{fake,real}, and the type of the
	global that points to them.

START NUMBERING FRAMEVARS FROM ONE

compiler/code_info.m:
compiler/live_vars.m:
compiler/llds_out.m:
compiler/trace.m:
	Start numbering framevars from 1 internally to the compiler;
	the runtime already starts from 1. This simplifies several tasks.

ADD REDO EVENTS

compiler/trace.m:
compiler/code_gen.m:
	Before the code that executes "succeed()", emit code to push a
	a temp nondet frame whose redoip points to a label in the runtime
	that calls MR_trace for a REDO event and then fails, provided
	--trace-redo is set.

compiler/llds.m:
	Add a new code address constant, do_trace_redo_fail, which stands
	for the address in the trace system to which calls MR_trace for
	the redo event and then fails.

compiler/trace.m:
compiler/llds_out.m:
	Provided we are doing redo tracing, fill in the slot that holds
	the layout information for the REDO event.

compiler/*.m:
	Minor changes to conform to handle the new code address constant.

browser/debugger_interface.m:
	Add redo to trace_port_type.

runtime/mercury_trace_base.[ch]:
	Add a C module containing the code that calls MR_trace for REDO
	events.

ENSURE THAT INPUT ARGUMENTS ARE ALWAYS VISIBLE

compiler/trace.m:
	When generating the set of live variables at internal ports,
	the variables that are in the pre-death set of the goal into which
	we are entering may not be available. However, the variables in the
	pre-death set that are also in the resume vars set will be available,
	so now include info about them in the layout structure for the event.
	Since with tracing the non-clobbered input args are in all resume vars
	sets, this ensures that these input args will be available from all
	internal events.

compiler/code_info.m:
	Export a previously internal predicate (current_resume_point_vars)
	to make this possible.

BUG FIX: WANT RETURN LAYOUTS

compiler/globals.m:
compiler/call_gen.m:
compiler/code_info.m:
compiler/mercury_compile.m:
	Add a new pred globals__want_return_layouts, which says whether the
	compiler should generate layout structures for call returns. This pred
	centralizes the several previous copies of the test. One of those
	copies (the one in call_gen) was faulty, leading to a bug: in the
	presence of execution tracing but the absence of accurate gc,
	information about the variables that are live at the call return
	wasn't being gathered properly.

BUG FIX: #include mercury_trace_base.h

compiler/llds_out.m:
	#include mercury_trace_base.h, not mercury_trace.h, since now
	mercury_trace_base.h defines everything directly accessible from
	modules compiled with tracing.

RECAST MERCURY_TRACE_UTIL AS MERCURY_LAYOUT_UTIL

runtime/mercury_trace_util.[ch]:
runtime/mercury_layout_util.[ch]:
	Rename this module from trace_util to layout_util, since it is also
	used by the native garbage collector. Remove "trace" from the names
	of functions.

	Get rid of the global variable MR_saved_regs, and instead thread
	a pointer to this data structure through the relevant functions
	as an extra argument.

	Add a lot more documentation in the header file.

runtime/Mmakefile:
	Reflect the module rename.

runtime/*.c:
	Refer to the new module.

DELETE EASY-TO-MISUSE MACROS

runtime/mercury_stacks.h:
	Delete the based_framevar and based_detstackvar macros, since their
	continued use can lead to off-by-one errors, and the saved_framevar
	and saved_detstackvar macros, since they are no longer used.

runtime/*.c
	Update any references to any macros removed from mercury_stacks.h.

MISC RUNTIME CHANGES

runtime/mercury_trace_base.[ch]:
trace/mercury_trace*.[ch]:
	Make typedef'd names conform to the naming convention.

	Make MR_trace_call_{seqno,depth} consistently Unsigned, rather than
	sometimes Word and sometimes Unsigned.

FIX BUG: MAKE THE DEBUGGER PRINT TO STDOUT, NOT THE CURRENT STREAM

library/io.m:
	Export to C code the predicates that return the identities and types
	of stdin, stdout and stderr, as well as io__print/[34].

library/std_util.m:
	Export to C code a predicate that returns the type_info for the
	type stdutil:type_info. This type_info is required if C code
	wants to invoke make_permanent on any type_info structure,
	as the debugger does.

runtime/mercury_init.h:
	Add extern declarations for the C functions now exported from io.m.

runtime/mercury_wrapper.[ch]:
	Add new global variables to hold the addresses of these C functions.

runtime/mercury_layout_util.c:
	Use indirect calls through these global variables to print Mercury
	values, instead of lower-level code.

util/mkinit.c:
	Assign the addresses of the functions exported from io.m to the
	global variables defined in mercury_wrapper.h.

BUG FIX: STACK TRACE FUNCTIONS DEPEND ON THE LABEL TABLE

runtime/mercury_stack_trace.c:
	On entry to any of the functions exported from this module,
	ensure that the label table is loaded by calling do_init_modules.
	Without a filled-in label table, the stack trace will not be able to
	find any stack layout info.

BUG FIX: REMOVE BROWSER/*.C

configure.in:
	When removing .c files generated by the C compiler, remove those
	in the browser directory as well as the compiler, library and
	profiler directories.

IMPLEMENT NEW DEBUGGER COMMAND SET

runtime/mercury_stack_trace.[ch]:
	Factor out the code that prints the id of a procedure into a function
	of its own, so that it can also be used from the debugger, ensuring
	appearance commonality.

	Add more documentation in the header file.

trace/mercury_trace_internal.c:
	Implement the proposed command set. Command names are now words,
	and several commands now have options allowing the user to override
	the default print level or strictness of the command, or the
	invocation conditions or action of a break point. Allows control
	over command echoing and the scrolling of sequences of event reports.
	Supports aliases, command file sourcing etc. Implements the retry
	command, using the info in the fixed stack slots.

trace/mercury_trace.[ch]:
	Extend the trace controls to support the new functionalities
	required by the new debugger language, which are print levels,
	variable-strictness commands, a more flexible finish command,
	and the retry command.

	Pass the command structure to MR_trace_event_report, since
	the user can now forcibly terminate the scrolling of reports.

trace/mercury_trace_alias.[ch]:
	New module to manage aliases for the debugger.

trace/mercury_trace_help.[ch]:
	New module to interface to browser/help.m.

trace/mercury_trace_spy.[ch]:
	New module to manage break points. The test of whether an event
	matches a break point is now much more efficient than before.
	The new module also allows several breakpoints with different
	actions and different invocation conditions (e.g. all ports,
	entry port, interface ports or specific (possibly internal) port)
	to be defined on the same procedure.

trace/mercury_trace_tables.[ch]:
	New module to manage a table of the debuggable modules, in which
	each such module is linked to the list of the layouts of all the
	procedures defined in that module. This information allows the
	debugger to turn the name of a predicate/function (possibly together
	with its arity and mode number) into the procedure layout structure
	required by the spy point module. Eventually it may also be useful
	in supplying lists of identifiers for command line completion.

	Modules for which no stack layout information is available will
	not be included in the table, since do_init_modules will not
	register any labels for them in the label table.

trace/Mmakefile:
	Mention the new files.

runtime/mercury_array_macros.h:
	A new file holding macros that can be useful in more than one module.

runtime/Mmakefile:
	Mention the new file.

runtime/mercury_conf.h.in:
	Mention a new configuration macro, MR_CANNOT_USE_STRUCTURE_ASSIGNMENT,
	used by runtime/mercury_array_macros.h.

configure.in:
	Find out whether we need to define MR_CANNOT_USE_STRUCTURE_ASSIGNMENT.

ADD TRACE DEPTH HISTOGRAMS

runtime/mercury_conf_param.h:
	Document MR_TRACE_HISTOGRAM.

runtime/mercury_trace_base.[ch]:
	Define the data structures for the histogram, and print the histogram
	when a traced program exits if MR_TRACE_HISTOGRAM is set.

trace/mercury_trace.[ch]:
	If MR_TRACE_HISTOGRAM is defined, record a count of the number of
	events at each depth. This information can help us evaluate space-time
	tradeoffs.

FACTOR OUT SHELL CODE HANDLING GRADE IMPLICATIONS

scripts/final_grade_options.sh-subr:
	A new file to contain any code that implements implications between
	grade flags; currently implements the implication debug -> use trail.

scripts/mgnuc.in:
scripts/ml.in:
	Replace the code that is now in final_grade_options.sh-subr with
	an inclusion of final_grade_options.sh-subr.

configure.in:
	Handle final_grade_options.sh-subr as {init,parse}_grade_options.sh-subr
	are handled.

SIMPLIFY THE MAINTAINANCE OF CONSISTENCY BETWEEN DEBUGGER CODE AND DOCUMENTATION

doc/Mmakefile:
	Add rules for creating mdb_command_list, a C code fragment
	that can included manually in trace/mercury_trace_internal.c
	to supply the list of valid commands, and mdb_command_test.inp,
	which is a list of invalid invocations of debugger commands,
	which tests whether the help message for such invocations
	can be located as expected.

doc/generate_mdb_command_list:
doc/generate_mdb_command_test:
	Awk scripts to create mdb_command_list and mdb_command_test.inp
	respectively from mdb_doc.

tools/bootcheck:
	Copy mdb_command_test.inp from doc to tests/debugger.

tests/debugger/Mmakefile:
	Add a new test that checks whether we get an internal error, unable
	to locate the right help node, for each invalid command invocation in
	mdb_command_test.inp.

UPDATE TEST CASES

tests/debugger/Mmakefile:
	Reenable queens. Conform to the new set of options.

tests/debugger/*.inp:
tests/debugger/*.exp:
	Update the inputs and expected outputs of the debugger test cases
	to use the new command set and output formats.
1998-10-16 06:20:21 +00:00
Fergus Henderson
eb580a2609 Ensure that the declarations and definitions for data constants
Estimated hours taken: 3

Ensure that the declarations and definitions for data constants
specify the same linkage (extern or static), because the C standard
says that if the linkage is different, then the behaviour is undefined.
This bug resulted in undefined symbol link errors for the RS/6000 AIX port.

compiler/llds_out.m:
	When printing out declarations for data constants,
	compute the linkage from the data_name, rather than
	always assuming `extern'.  When printing out definitions,
	add a sanity check to ensure that the linkage that would be
	computed from the data_name is the same as the linkage used
	for the definition.

compiler/base_type_info.m:
	Make base_type_infos always exported from the module, never local.
	This is necessary to ensure that the linkage can be
	computed from the data_name.

compiler/base_type_layout.m:
	Make base_type_functors and base_type_info structures
	always local to the module, rather than exported.
	This is necessary to ensure that the linkage can be
	computed from the data_name.

library/array.m:
library/builtin.m:
library/std_util.m:
	Add `static' to the hand-coded definitions of the base_type_functors
	and base_type_layouts for builtin types.

compiler/base_typeclass_info.m:
compiler/llds.m:
compiler/stack_layout.m:
	Add comments pointing to the new predicate linkage/2 in
	llds_out.m, to ensure that future maintenance doesn't break
	the assumptions it makes.
1998-09-03 11:13:53 +00:00
Zoltan Somogyi
d1855187e5 Implement new methods of handling failures and the end points of branched
Estimated hours taken: 260

Implement new methods of handling failures and the end points of branched
control structures.

compiler/notes/failure.html:
	Fix an omission about the handling of resume_is_known in if-then-elses.
	(This omission lead to a bug in the implementation.)

	Optimize cuts across multi goals when curfr is known to be equal
	to maxfr.

	Clarify the wording in several places.

compiler/code_info.m:
	Completely rewrite the methods for handling failure.

	Separate the fields of code_info into three classes: those which
	do not change after initialization, those which record state that
	depends on where in the HLDS goal we are, and those which contain
	persistent data such as label and cell counters.

	Rename grab_code_info and slap_code_info as remember_position
	and reset_to_position, and add a wrapper around the remembered
	code_info to make it harder to make mistakes in its use.
	(Only the location-dependent fields of the remembered code_info
	are used, but putting only them into a separate data structure would
	result in more, not less, memory being allocated.)

	Gather the predicates that deal with handling branched control
	structures into a submodule.

	Reorder the declarations and definitions of access predicates
	to conform to the new order of fields.

	Reorder the declarations and definitions of the failure handling
	submodule to better reflect the separation of higher-level and
	lower-level predicates.

compiler/code_gen.m:
	Replace code_gen__generate_{det,semi,non}_goal_2 with a single
	predicate, since for most HLDS constructs the code here is the same
	anyway (the called preds check the code model when needed).

	Move classification of the various kinds of unifications to unify_gen,
	since that is where it belongs.

	Move responsibility for initializing the code generator's trace
	info to code_info.

	Move the generation of code for negations to ite_gen, since the
	handling of negations is a cut-down version of the handling of
	negations. This should make the required double maintenance easier,
	and more likely to happen.

compiler/disj_gen.m:
compiler/ite_gen.m:
	These are the two modules that handle most failures; they have
	undergone a significant rewrite. As part of this rewrite, factor
	out the remaining common code between model_non and model_{det,semi}
	goals.

compiler/unify_gen.m:
	Move classification of the various kinds of unifications here from
	code_gen. This allows us to keep several previously exported
	predicates private.

compiler/call_gen.m:
	Factor out some code that was common to ordinary calls, higher order
	calls and method calls. Move the common code that checks whether
	we are doing tracing to trace.m.

	Replace call_gen__generate_{det,semi,nondet}_builtin with a single
	predicate.

	Delete the commented out call_gen__generate_complicated_unify,
	since it will never be needed and in any case suffered from
	significant code rot.

compiler/llds.m:
	Change the mkframe instruction so that depending on one of its
	arguments, it can create either ordinary frames, or the cut-down
	frames used by the new failure handling algorithm (they have only
	three fixed fields: prevfr, redoip and redofr).

compiler/llds_out.m:
	Emit a #define MR_USE_REDOFR before including mercury_imp.h, to
	tell the runtime we are using the new failure handling scheme.
	This effectively changes the grade of the compiled module.

	Emit MR_stackvar and MR_framevar instead of detstackvar and framevar.
	This is a step towards cleaning up the name-space, and a step towards
	making both start numbering at 0. For the time being, the compiler
	internally still starts counting framevars at 0; the code in llds_out.m
	adds a +1 offset.

compiler/trace.m:
	Change the way trace info is initialized to fit in with the new
	requirements of code_info.m.

	Move the "are we tracing" check from the callers to the implementation
	of trace__prepare_for_call.

compiler/*.m:
	Minor changes in accordance with the major ones above.

compiler/options.m:
	Introduce a new option, allow_hijacks, which is set to "yes" by
	default. It is not used yet, but the idea is that when it is set to no,
	the code generator will not generate code that hijacks the nondet
	stack frame of another procedure invocation; instead, it will create
	a new temporary nondet stack frame. If the current procedure is
	model_non, it will have three fields: prevfr, redoip and redofr.
	If the current procedure is model_det or model_semi, it will have
	a fourth field that is set to the value of MR_sp. The idea is that
	the runtime system, which will be able to distinguish between
	ordinary frames (whose size is at least 5 words), 3-word and 4-word
	temporary frames, will now be able to use the redofr slots of
	all three kinds of frames and the fourth slot values of 4-word
	temporary frames as the addresses relative to which framevars
	and detstackvars respectively ought to be offset in stack layouts.

compiler/handle_options.m:
	Turn off allow_hijacks if the gc method is accurate.

runtime/mercury_stacks.h:
	Change the definitions for the nondet stack handling macros
	to accommodate the new nondet stack handling discipline.
	Define a new macro for creating temp nondet frames.

	Define MR_based_stackvar and MR_based_framevar (both of which start
	numbering slots at 1), and express other references, including
	MR_stackvar and MR_framevar and backward compatible definitions of
	detstackvar and framevar for hand-written C code, in terms of those
	two.

runtime/mercury_stack_trace.[ch]:
	Add a new function to print a dump of the fixed elements nondet stack,
	for debugging my changes. (The dump does not include variable values.)

runtime/mercury_trace_internal.c:
	Add a new undocumented command "D" for dumping the nondet stack
	(users should not know about this command, since the output is
	intelligible only to implementors).

	Add a new command "toggle_echo" that can cause the debugger to echo
	all commands. When the input to the debugger is redirected, this
	echo causes the output of the session to be much more readable.

runtime/mercury_wrapper.c:
	Save the address of the artificial bottom nondet stack frame,
	so that the new function in mercury_stack_trace.c can find out
	where to stop.

runtime/mercury_engine.c:
runtime/mercury_wrapper.c:
	Put MR_STACK_TRACE_THIS_MODULE at the tops of these modules, so that
	the labels they define (e.g. do_fail and global_success) are registered
	in the label table when their module initialization functions are
	called. This is necessary for a meaningful nondet stack dump.

runtime/mercury_grade.h:
	Add a new component to the grade string that specifies whether
	the code was compiled with the old or the new method of handling
	the nondet stack. This is important, because modules compiled
	with different nondet stack handling disciplines are not compatible.
	This component depends on whether MR_USE_REDOFR is defined or not.

runtime/mercury_imp.h:
	If MR_DISABLE_REDOFR is defined, undefine off MR_USE_REDOFR before
	including mercury_grade.h. This is to allow people to continue
	working on un-updated workspaces after this change is installed;
	they should put "EXTRA_CFLAGS = -DMR_DISABLE_REDOFR" into
	Mmake.stage.params. (This way their stage1 will use the new method
	of handling failure, while their stage2 2&3 will use the old one.)

	This change should be undone once all our workspaces have switched
	over to the new failure handling method.

tests/hard_coded/cut_test.{m,exp}:
	A new test case to tickle the various ways of handling cuts in the
	new code generator.

tests/hard_coded/Mmakefile:
	Enable the new test case.
1998-07-20 10:04:02 +00:00
Tyson Dowd
16e50a0244 Fix a bug in the generation of init_entry_sl(...) code.
Estimated hours taken: 2

Fix a bug in the generation of init_entry_sl(...) code.

compiler/code_gen.m:
compiler/continuation_info.m:
compiler/stack_layout.m:
	Previously the code used a proc_label to describe an entry label,
	and stored (incorrectly) as local(proc_label) in a list of labels
	(the list of labels that had stack_layouts).

	Later when deciding whether an "init_entry" or "init_entry_sl"
	should be generated, it looked for the label in the list of
	labels for which stack layouts had been generated, but would
	compare with the actual label for the entry.  In particular,
	the label might be exported(....) instead of local(....), which
	means init_entry was used instead of init_entry_sl.

	Fix this by correctly generating labels rather than assuming
	they are local(...), and using "label" where "proc_label" was
	used before.
1998-07-15 12:21:10 +00:00
Zoltan Somogyi
356e316ce1 Reorder the components of this file into a sequence of submodules,
Estimated hours taken: 4

runtime/mercury_stack_layout.h:
	Reorder the components of this file into a sequence of submodules,
	with each submodule containing the definition of a type and all
	the macros that operate on that type. This should remind people
	that updating a type without updating the macros is not a good idea.

	Remove obsolete, unused and incorrect macros.

	Modify the conventions for the use of incomplete fragments of
	proc layout structures, so that by looking at a proc layout
	fragment, one can tell how much of it is actually present and
	meaningful. This is necessary to avoid references to fields
	that are not present or not meaningful.

runtime/mercury_conf_param.h:
	Document a debugging macro now used in mercury_stack_layout.h.

compiler/stack_layout.m:
	Emit data structures that conform to the new convention.
1998-07-09 04:38:47 +00:00
Zoltan Somogyi
4ab3f397b1 Allow the debugger to print the values of variables in ancestors
Estimated hours taken: 20

Allow the debugger to print the values of variables in ancestors
of the current call. This requires knowledge about which named variables
are live at call return sites. Providing this information properly required
fixing the interaction of execution tracing and accurate garbage collection.

compiler/globals.m:
	Introduce a new trace level, so that there are now four:
	none, interface, interface_ports (corresponding to the existing
	three levels) and the new level interface_ports_returns,
	each of which requires all the information required by lower
	levels.

	Make the trace level abstract, since in the future we may want to
	introduce trace levels for new combinations, e.g. interfaces and
	returns but not internal ports. Introduce the necessary new
	predicates.

compiler/continuation_info.m:
	Redefine internal_label_info to allow us to record separate info about
	the sets of vars needed at (a) internal ports of execution tracing
	and at (b) call return points for accurate gc or (now) uplevel
	printing during execution tracing. Neither is a subset of the other,
	and they need to be treated differently.

compiler/mercury_compile.m:
	Gather information about vars at return labels if the trace level
	requires uplevel printing capability, even if agc is off.

compiler/stack_layout.m:
	Fix the handling of labels which are needed both by agc and by
	execution tracing. If information at a return label is needed only
	by uplevel printing in execution tracing and not by agc, then
	discard all info about lvals which do not hold named variables
	or their typeinfos (in fact we keep all typeinfos at the moment).
	If a label is both the label of a port and a return label, we
	include in the layout structure the union of the information
	recorded for the two roles.

	Sort the var_info vector before using it to generate layout
	structures in an attempt to make llds_common more effective
	and to make lists of variables printed by the debugger look better.

	Record a distinguished value when there is no info about the vars
	live at a label, rather than (incorrectly) recording that there
	are no live variables. Before up-level printing, the lie was harmless;
	now it isn't.

	Remove the label number from return label layouts, since the tracer
	isn't expecting it. It used to be included for debugging purposes
	if the label was for agc, but it is possible for a label to be needed
	both for agc and for execution tracing. If Tyson finds he needs the
	label number, it can be easily turned back on for all label layouts.

compiler/code_info.m:
	Conform to the new definition of internal_label_info.

	Rename an internal pred for clarity.

	Rename some bool parameter to correctly reflect their new meaning.

compiler/*.m:
	Trivial changes, mostly due to making trace_level an abstract type.

runtime/mercury_stack_layout.h:
	Remove the label number from return label layouts, since the tracer
	isn't expecting it.

runtime/mercury_stack_trace.[ch]:
	Add a new function that returns the label layout structure at the
	Nth ancestor return continuation, together with the values of
	sp and curfr at that point. This required changing MR_stack_walk_step
	to step from an entry layout only to the return label layout.

runtime/mercury_stacks.h:
	Add macros that let us access detstackvars and framevars based on
	these synthesized values of sp and curfr.

runtime/mercury_trace_util.[ch]:
	Generalize several functions to allow them to use synthesized
	(as opposed to saved) values of sp and curfr in looking up values.

	Retain functions with the original names and signatures that call
	the new, general versions with the necessary additional parameters.

runtime/mercury_trace_internal.c:
	Add a new command that sets the "ancestor level". For example,
	"l 2" sets it to 2, which means that the command "v" and "p" will
	refer to the grandparent of the current call. The ancestor level
	persists while the debugger is at the current event; after that
	it is reset to 0.

	The implementation involves calling the new function in
	mercury_stack_trace.c and the generalized functions in
	mercury_trace_util.c.

	Also add a deliberately undocumented extra command, X, which
	prints the stack pointers.

NEWS:
	Add a reminder about removing the X command before release.

tests/debugger/*
	Update half the test cases (those which assume a non-debug-grade
	library) to conform to the changes in the debugger interface.
	The others will need to be updated later.
1998-06-18 06:08:37 +00:00
Zoltan Somogyi
2f2a450ed0 Move the number of type parameters from the label layout structures
Estimated hours taken: 2

compiler/stack_layout.m:
	Move the number of type parameters from the label layout structures
	to the start of the vector of type parameter locations. Since
	different labels' layouts often have the same set of typeinfo variable
	locations, this saves one word on a large fraction of all label
	layout tables.

	Fix some documentation rot.

runtime/mercury_stack_layout.h:
	Make the corresponding change in the C description of the layout
	structure.

runtime/mercury_trace_internal.c:
	Make the corresponding change in the C code that accesses the layout
	structure.

	Fix an earlier oversight: don't try to materialize type parameters
	that aren't live.
1998-05-19 05:15:10 +00:00
Zoltan Somogyi
d10af74168 This change introduces interface tracing, and makes it possible to successfully
Estimated hours taken: 50

This change introduces interface tracing, and makes it possible to successfully
bootstrap the compiler with tracing (either interface or full).

compiler/options.m:
	Change the bool options --generate-trace into a string option --trace
	with three valid values: minimal, interface and full. The last two mean
	what they say; the intention is that eventually minimal will mean
	no tracing in non-tracing grades and interface tracing in tracing
	grades.

compiler/globals.m:
	Add a new global for the trace level.

compiler/handle_options.m:
	Convert the argument of --trace to a trace level.

	Use only consistent 4-space indentation in the deeply nested
	if-then-else.

compiler/trace.m:
	Implement interface tracing.

	Rename trace__generate_depth_reset_code as trace__prepare_for_call,
	since it does more than reset the depth if this module is compiled
	with interface tracing.

	Do not check whether tracing is enabled before calling MR_trace;
	let MR_trace make the check. This trades increased non-tracing
	execution time for a substantial code size reduction (which may
	in turn benefit execution time).

compiler/call_gen.m:
	Call trace__generate_depth_reset_code by its new name.

compiler/code_info.m:
	Fix a bug in the handling of non/semi commits. When entering a commit,
	we used to push a clone of whatever the top failure continuation was.
	However, the resume setup for this continuation could have started
	with a label that assumed that the resume vars were in their original
	locations (which are often registers), whereas the method of
	backtracking to that point only guarantees the survival of stack slots,
	not registers.

	(This bug caused two lines of incorrect code to be generated among
	the approx 30 million lines of code in the stage 2 compiler when
	compiled with tracing.)

	Fix another bug (previously untriggered as far as I know) in the
	handling of multi/det commits. This one was breaking the invariant
	that the resume vars set of each entry on the failure continuation
	stack included the resume vars set of every other entry below it,
	which meant that the values of these resume vars were not guaranteed
	to be preserved.

compiler/stack_layout.m:
	Make layout structures local to their module. They are not (yet)
	referred to by name from other modules, and by declaring them
	to be global we caused their names to be included even in stripped
	executables, adding several megabytes to the size of the binary.
	(The names are not stripped because a dynamically linked library
	may want to refer to them.)

	Change the mercury_data__stack_layout__ prefix on the names of
	generated globals vars to just mercury_data__layout__. It is now
	merely too long instead of far too long.

	Include the label number in the label layout structure and the number
	of typeinfo variables in a var_info structure only with native gc.
	Their only use is in debugging native gc.

	Fix some documentation rot.

compiler/llds.m:
	Add a new field to the pragma_c instruction that says whether the
	compiler-generated C code fragments access any stack variables.

compiler/frameopt.m:
	Use the new field in pragma_c's to avoid a bug. Because frameopt was
	assuming that the pragma_c instruction that filled in the stack slots
	containing the call sequence number and depth did not access the stack,
	it moved the pragma_c before the incr_sp that allocates the frame
	(it was trying to get it out of the loop).

compiler/*.m:
	Minor changes to set or ignore the extra field in pragma_c, to refer
	to layout structures via the new prefix, or to handle the --trace
	option.

doc/user_guide.texi:
	Update the documentation for --trace.

runtime/mercury_types.h:
	Add the type Unsigned.

runtime/mercury_goto.h:
	Use the shorter layout prefix.

runtime/mercury_stack_layout.h:
	Use the shorter layout prefix, and include the label number only with
	native gc.

runtime/mercury_trace.[ch]:
runtime/mercury_trace_internal.[ch]:
runtime/mercury_trace_external.[ch]:
runtime/mercury_trace_util.[ch]:
	Divide the old mercury_trace.[ch] into several components, with one
	module for the internal debugger, one for the interface to the
	external debugger, one for utilities needed by both. Mercury_trace.c
	now has only the top-level stuff that steers between the two
	debuggers.

runtime/mercury_trace.[ch]:
	Add the new global variable MR_trace_from_full. Before each call,
	the calling procedure assigns TRUE to this variable if the caller
	is fully traced, and FALSE otherwise. Interface traced procedures
	generate trace events only if this variable is TRUE when they are
	called (fully traced callee procedures ignore the initial value of
	the variable).

	Make MR_trace return immediately without doing anything unless
	tracing is enabled and a new extra argument to MR_trace is TRUE.
	This extra argument is always TRUE for trace events in fully traced
	procedures, while for trace events from interface traced procedures,
	its value is set from the value of MR_trace_from_full at the time
	that the procedure was called (i.e. the event is ignored unless the
	interface traced procedure was called from a fully traced procedure).

runtime/mercury_trace.[ch]:
runtime/mercury_trace_internal.[ch]:
	For global variables that are stored in stack slots, make their type
	Word rather than int.

	Use a new function MR_trace_event_report instead of calling
	MR_trace_event with a NULL command structure pointer to indicate
	that the event is to be reported but there is to be no user
	interaction.

	Use %ld formats in printfs and casts to long for better portability.

runtime/mercury_trace_internal.c:
	Save trace-related globals across calls to Mercury library code
	in the debugger, since otherwise any trace events in this code
	could screw up e.g. the event number or the call number sequence.

	Create separate functions for printing port names and determinisms.

runtime/mercury_wrapper.h:
	Disable the tracing of the initialization and finalization code
	written in Mercury.

runtime/Mmakefile:
	Update for the new source and header files.

tests/debugger/{debugger_regs,interpreter,queens}_lib.{m,inp,exp}:
	One new copy of each existing test case. These ones are intended
	to be used when the stage 2 library is compiled with tracing, which
	affects the tests by adding events for the library procedures called
	from the test programs.

	The .m files are the same as before; one of the .inp files is a bit
	different; the .exp files reflect the correct output when the library
	is compiled with full tracing.

tests/debugger/Mmakefile:
	Provide separate targets for the new set of test cases.

	Use --trace full instead of --generate-trace.

tests/debugger/runtests:
	Try both the new set of test cases if the old set fails, and report
	failure only if both sets fail. This is simpler than trying to figure
	out which set should be really tested, and the probability of a false
	positive is negligible.
1998-05-16 07:31:33 +00:00
Tyson Dowd
484d842a34 Fix stack traces, which were broken with recent tracing code changes.
Estimated hours taken: 4

Fix stack traces, which were broken with recent tracing code changes.

compiler/continuation_info.m:
compiler/mercury_compile.m:
	Collect continuation label information for stack traces, but
	without the liveness information that is needed for agc.

compiler/stack_layout.m:
	Add a comment stating that changes in this file may need to be
	reflected in runtime/mercury_stack_layout.h
1998-04-17 06:55:40 +00:00