Commit Graph

264 Commits

Author SHA1 Message Date
Zoltan Somogyi
9c58f97e3b Add a new optimization, --use-local-vars, to the LLDS backend.
Estimated hours taken: 20
Branches: main

Add a new optimization, --use-local-vars, to the LLDS backend. This
optimization is intended to replace references to fake registers and stack
slots with references to temporary variables in C code, since accessing these
should be cheaper.

With this optimization and one for delaying construction unifications,
the eager code generator should generate code at least good as that produced by
the old value numbering pass. This should make it possible to get rid of value
numbering, which is much harder to maintain.

compiler/use_local_vars.m:
	New module containing the optimization.

compiler/notes/compiler_design.html:
	Mention the new module.

compiler/exprn_aux.m:
	Add new utility predicates for use by use_local_vars.

	If --debug-opt is specified, do not dump instruction sequences to
	standard output. Instead, put them in separate files, where they can be
	compared more easily.

compiler/options.m:
	Add the --use-local-vars option to control whether the use_local_vars
	pass gets run.

compiler/llds.m:
	Add liveness information to the c_code and pragma_foreign_code LLDS
	instructions, in order to allow use_local_vars to work in the presence
	of automatically-generated C code (e.g. by debugging).

compiler/livemap.m:
	Use the new liveness information to generate useful livemap information
	even in the presence of automatically generated C code.

compiler/code_gen.m:
compiler/code_info.m:
compiler/dupelim.m:
compiler/frameopt.m:
compiler/llds_common.m:
compiler/llds_out.m:
compiler/middle_rec.m:
compiler/opt_debug.m:
compiler/opt_util.m:
compiler/pragma_c_gen.m:
compiler/trace.m:
compiler/vn_block.m:
compiler/vn_cost.m:
compiler/vn_filter.m:
compiler/vn_verify.m:
	Provide and/or ignore this additional liveness information.

compiler/wrap_block.m:
	The post_value_number pass wraps LLDS instruction sequences
	using temporaries in a block instruction which actually declares
	those temporaries. It used to be used only by value numbering;
	it is now also used by use_local_vars. It has therefore been renamed
	and put in its own file.

compiler/optimize.m:
	Invoke use_local_vars if required, and call wrap_blocks instead of
	post_value_number.

compiler/value_number.m:
	Since the value numbering pass still cannot handle automatically
	generated C code, check for it explicitly now that livemap carries out
	only a weaker check.

compiler/basic_block.m:
	Add a module qualification.

library/set.m:
library/set_bbbtree.m:
library/set_ordlist.m:
library/set_unordlist.m:
	Add a new predicate, union_list, to each implementation of sets,
	for use by some of the new code above.

tests/general/array_test.m:
	Print out the result of each operation as soon as it is done, so that
	if you get a seg fault, you know which operations have completed and
	which haven't.
2001-04-24 03:59:13 +00:00
Zoltan Somogyi
69ab8651f3 Fix the interaction of the eager code generator with accurate gc to the extent
Estimated hours taken: 16
Branches: main

Fix the interaction of the eager code generator with accurate gc to the extent
of getting to the end of stage 2 of a bootcheck in the asm_fast.agc grade.

compiler/call_gen.m:
compiler/pragma_c_gen.m:
	Kill the variables in the post-death set that are not needed after the
	call is made before we make the call, in particular before we clear
	the registers (to reflect the fact that the callee may modify any
	register). This prevents var_locn from throwing exceptions in accurate
	gc grades.

compiler/code_info.m:
	Delete the code for killing the variables in post-death set in
	code_info__setup_call, since this is now done in the setup_call's
	callers in call_gen.m.

compiler/var_locn.m:
	Turn back on the sanity check we had to turn off because we were
	deleting the states of variables before we killed them.
2001-03-06 05:51:25 +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
d5c0f873c3 Divide the code_info data structure into three components, the static
Estimated hours taken: 0.5

compiler/code_info.m:
	Divide the code_info data structure into three components, the static
	part (which is read-only after initialization), the location-dependent
	part and the persistent part. There are no changes in algorithms or
	in the semantics of the data, just its form.

	This gives a speedup of around 2%.
2001-01-02 06:23:11 +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
Fergus Henderson
4be69fa961 Eliminated a lot of the dependencies on the the `code_model' type,
Estimated hours taken: 6

Eliminated a lot of the dependencies on the the `code_model' type,
and move that type from llds.m into a new module `code_model'.
The aim of this change is to improve the modularity of the compiler by
reducing the number of places in the compiler front-end that depend
on back-end concepts and the number of places in the MLDS back-end
which depend on the LLDS.

compiler/code_model.m:
	New module.  Contains the code_model type and associated
	procedures.

compiler/llds.m:
	Move the code_model type into code_model.m.

compiler/hlds_goal.m:
	Move the goal_info_get_code_model procedure into code_model.m,
	to avoid having the HLDS modules import code_model.

compiler/hlds_out.m:
	Delete `hlds_out__write_code_model', since it wasn't being used.

compiler/hlds_pred.m:
	Move the proc_info_interface_code_model procedure into code_model.m,
	to avoid having the HLDS modules import code_model.

compiler/goal_path.m:
	When computing the `maybe_cut' field for `some' goals,
	compute it by comparing the determinism rather than by
	comparing the goal_infos.

compiler/unique_modes.m:
	Use determinism and test for soln_count = at_most_many
	rather than using code_model and testing for model_non.

compiler/inlining.m:
	Test for determinism nondet/multi rather than testing
	for code_model model_non.

compiler/hlds_pred.m:
compiler/det_report.m:
	Change valid_code_model_for_eval_method, which succeeded unless
	the eval_method was minimal_model and the code_model was model_det,
	to valid_determinism_for_eval_method, which succeeds unless the
	eval_method is minimal_model and the determinism cannot fail.
	As well as avoiding a dependency on code_model in the HLDS
	modules, this also fixes a bug where det_report could give
	misleading error messages, saying that `multi' was a valid
	determinism for `minimal_model' predicates, when in fact the
	compiler will always report a determinism error if you declare
	a `minimal_model' predicate with determinism `multi'.
	(Actually the code in which this bug occurs is in fact
	unreachable, but this is no doubt also a bug... I'll address
	that one in a separate change.)

compiler/lookup_switch.m:
	Simplify the code a bit by using globals__lookup_*_option
	rather than globals__get_option and then getopt__lookup_option.

compiler/*.m:
	Add `import_module' declarations for `code_model', and in some
	cases remove `import_module' declarations for `llds'.
2000-11-23 04:32:51 +00:00
Zoltan Somogyi
090552c993 Make everything in the runtime use MR_ prefixes, and make the compiler
Estimated hours taken: 10

Make everything in the runtime use MR_ prefixes, and make the compiler
bootstrap with -DMR_NO_BACKWARDS_COMPAT.

runtime/mercury_*.[ch]
	Add MR_ prefixes to all functions, global variables and almost all
	macros that could pollute the namespace. The (intentional) exceptions
	are

	1. some function, variable, type and label names that already start
	   with MR_, mercury_, Mercury or _entry;
	2. some standard C macros in mercury_std.h;
	3. the macros used in autoconfiguration (since they are used in scripts
	   as well as the runtime, the MR_ prefix may not be appropriate for
	   those).

	In some cases, I deleted things instead of adding prefixes
	if the "things" were obsolete and not user visible.

runtime/mercury_bootstrap.h:
	Provide MR_-less forms of the macros for bootstrapping and for
	backward compatibility for user code.

runtime/mercury_debug.[ch]:
	Add a FILE * parameter to a function that needs it.

compiler/code_info.m:
compiler/export.m:
compiler/fact_table.m:
compiler/llds.m:
compiler/llds_out.m:
compiler/pragma_c_gen.m:
compiler/trace.m:
	Add MR_ prefixes to the C code generated by the compiler.

library/*.m:
	Add MR_ prefixes to handwritten code.

trace/mercury_trace_*.c:
util/mkinit.c:
	Add MR_ prefixes as necessary.

extras/concurrency/semaphore.m:
	Add MR_ prefixes as necessary.
2000-11-23 02:01:11 +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
dd7f3e80d1 Unify the code that performs the three kinds of data movements
Estimated hours taken: 20

Unify the code that performs the three kinds of data movements
required for calls:

(1) putting forward live variables to be saved across the call
    into their stack slots
(2) putting variables protected by enclosing resumption points
    into their stack slots
(3) putting input arguments into their registers

By using the same code (code_info__setup_call) for all three, we gain
two benefits:

(1) This code can also compute the live lval set we must put into
    a livevals LLDS instruction before the call to describe the
    locations that must be preserved by value numbering. Previously,
    this set was computed by other algorithms, raising the possibility
    of a discrepancy. Such discrepancies would cause value numbering
    to generate incorrect code.

(2) The eager back end is more efficient when given a single list
    of data placements to perform instead of three lists, because
    it can reorder operations more freely when required.

compiler/call_gen.m:
	Make the change described above.

	Factor out more code that is common between ordinary and generic calls.

compiler/code_info.m:
	Provide the infrastructure for the change above.

compiler/arg_info.m:
	Concentrate predicates dealing with arg_infos and parameter passing
	conventions in general in this module. Previously, call_gen.m and
	code_util.m also contained such code.

compiler/bytecode_gen.m:
compiler/pragma_c_gen.m:
compiler/disj_gen.m:
compiler/follow_vars.m:
compiler/middle_rec.m:
	Small changes to conform to changes in interfaces of the modules above.

compiler/code_util.m:
	Remove a now redundant predicate.
2000-09-20 00:21:52 +00:00
Zoltan Somogyi
79372969dd Get the most important part of value numbering done at code generation time
Estimated hours taken: 16

Get the most important part of value numbering done at code generation time
when using --no-lazy-code.

compiler/var_locn.m:
	When a field of a cell is assigned to a variable, do not associate
	the variable with the lvals in which it is found; instead, simply
	record the assignment e.g. of field N of X to Y. Later, when we need
	to place Y somewhere, we generate materialize X first. The point of
	this change is that if X is needed not just by Y but also by other
	variables, then we now save X in an lval after materializing it;
	other users of X can thus get it from faster storage.

compiler/code_info.m:
compiler/lookup_switch.m:
compiler/unify_gen.m:
	Minor updates to conform to changes in the interfaces of the predicates
	exported from var_locn.m.
2000-09-19 03:05:16 +00:00
Zoltan Somogyi
0a25db0fa8 Fix formatting.
Estimated hours taken: 0.1

compiler/code_info.m:
	Fix formatting.
2000-09-16 00:08:34 +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
78e4768104 Fix a bug that was causing the compiler to output bogus declarations
Estimated hours taken: 4

Fix a bug that was causing the compiler to output bogus declarations
of nonexistent layout structures, using undefined C structure tags.
For some reason, gcc accepted these declarations on all our platforms
except taifun.

compiler/llds.m:
	We used to have one field in pragma_c instructions that could name
	a label that cannot be renamed by optimizations. In some instructions,
	this label had a layout structure, in others it didn't. We now have
	two fields, one for labels that have layout structures and one for
	labels that don't.

compiler/llds_out.m:
	Declare the C global variable holding the layout structure of a fixed
	(non-renamable) label referred to by a pragma_c instruction only if
	that label does have a layout structure.

compiler/*.m:
	Minor changes to conform to the changes to pragma_c instructions.
2000-04-26 05:40:45 +00:00
Fergus Henderson
84c8146d0d Fix several bugs in the trail handling.
Estimated hours taken: 20

Fix several bugs in the trail handling.
Also improve the documentation of trailing, and add a new macro
MR_choicepoint_newer() to the public trailing interface.

The bugs which this change fixes are:
  - choice point ids were being reused after commits,
    rather than only after backtracking;
  - for if-then-elses with nondet conditions, the generated code was
    using MR_commit rather than MR_solve as the MR_untrail_reason;
  - for semidet disjunctions, when committing to a particular disjunct
    the generated code was not calling MR_reset_ticket(..., MR_commit)
    to invoke function trail entries, and was also leaking a trail ticket
  - the all-solutions predicates in std_util.m were leaking trail
    tickets (i.e. allocating them but not pruning or discarding them).

runtime/mercury_trail.h:
runtime/mercury_regorder.h:
runtime/mercury_regs.h:
runtime/mercury_wrapper.c:
runtime/mercury_context.h:
runtime/mercury_engine.h:
	A bunch of changes to add a new virtual register
	`MR_ticket_high_water':
	- in mercury_trail.h, add MR_ticket_high_water_var variable;
	- in mercury_regorder.h, add MR_ticket_high_water macro;
	- in mercury_regs.h, add MR_TICKET_HIGH_WATER_RN macro;
	- in mercury_wrapper.c, change
	  print_register_usage_counts() to handle
	  MR_TICKET_HIGH_WATER_RN.
	- in mercury_context.h and mercury_engine.h,
	  add code to save/restore this new register when
	  appropriate.

runtime/mercury_trail.h:
	- Change MR_store_ticket() so that it does
	  `MR_ticket_counter = ++MR_ticket_high_water'
	  rather than just `MR_ticket_counter++'.
	- Add new macros MR_prune_ticket() and MR_prune_tickets_to(),
	  which only reset MR_ticket_counter, not MR_ticket_high_water.
	- Change the old macros MR_discard_ticket() and MR_discard_tickets_to()
	  so that they reset both MR_ticket_high_water and MR_ticket_counter.
	- Add new macro MR_choicepoint_newer().
	- Enclose macro arguments in parentheses.
	- Some minor changes to the documentation.

doc/reference_manual.texi:
	Document MR_choicepoint_newer().
	Update the documentation to reflect the fact that exceptions
	are now a standard part of Mercury.
	Clarify the documentation in the "Avoiding Redundant Trailing"
	section, and add a longish example.

compiler/notes/trailing.html:
	Add some documentation on the trail and how we manage it.

compiler/llds.m:
compiler/mlds.m:
	Add new `prune_ticket' and `prune_tickets_to' instructions,
	corresponding to the new macros defined in runtime/mercury_trail.h.
	Comment out the `discard_tickets_to' instruction, since it
	is no longer used in the compiler (the MR_discard_tickets_to()
	macro is only used by library/exception.m and the debugger's
	retry command).
	Replace the duplicated documentation in mlds.m with a pointer
	to llds.m.

compiler/ite_gen.m:
compiler/code_gen.m:
compiler/code_info.m:
	Change the trail handling code generated after commits
	so that the ticket is pruned rather than discarded.

compiler/ite_gen.m:
	When generating the reset_ticket instruction for
	if-then-elses with nondet conditions, use `solve'
	rather than `commit' as the reset_trail_reason.

compiler/disj_gen.m:
	Add code to generate a reset_ticket(..., commit)
	instruction at the end of every non-last disjunct
	in semidet disjunctions.

compiler/dupelim.m:
compiler/livemap.m:
compiler/llds_common.m:
compiler/llds_out.m:
compiler/ml_elim_nested.m:
compiler/middle_rec.m:
compiler/opt_debug.m:
compiler/opt_util.m:
compiler/value_number.m:
compiler/vn_*.m:
	Trivial modifications to handle the changes to the
	trailing instructions.

library/exception.m:
	Change the trail handling code so that when the goal in an
	exception handler succeeds (rather than failing or throwing an
	exception), the trail ticket we created on entry to the
	handler is pruned rather than discarded.

library/std_util.m:
	Add a new impure predicate `discard_trail_ticket', which calls
	MR_discard_ticket(), and call it in `builtin_aggregate' and
	`do_while' to discard the ticket that gets allocated by the
	call to MR_store_ticket() in `get_registers'.
2000-03-20 05:27:30 +00:00
Thomas Conway
6eb2d57b05 Use field names in code_info.m for 2 reasons:
Estimated hours taken: 1

compiler/code_info.m:
	Use field names in code_info.m for 2 reasons:
		- make it easier to read,
		- make it easier to mantain (ie less chance of
		  CVS conflicts).
2000-02-10 01:59:49 +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
Zoltan Somogyi
9ede635651 Fix a bug reported by Warwick, which exposed a design error in failure
Estimated hours taken: 10

Fix a bug reported by Warwick, which exposed a design error in failure
handling. We use to assume in several places that either the address
to jump to on failure was unknown (meaning we must generate a redo()),
or that the address was known *and* stored in the redoip slot of the top
nondet stack frame contained this address. This change takes care of the
third possibility: the address is known but the top redoip slot does not
(necessarily) contain that address.

compiler/code_info.m:
	Make the above distinction in the failure handling state of the
	code generator, and make use of it appropriately.

compiler/disj_gen.m:
	When reaching the end of a disjunct in a model_det or model_semi
	disjunction, reset this part of the state to what it was on entering
	the disjuct. The failure continuation was known, pointing to the
	next disjunct, during the generation of code for the disjunct,
	but the code after the disjunction as a whole should fail the
	same way as the disjunction itself should fail.

	In the absence of this reset, the merging of the failure states
	of the ends of the different branches may produce incorrect info.

compiler/notes/failure.html:
	State that the changed design is not yet documented :-(

tests/hard_coded/redoip_clobber.{m,exp}:
	A test case for the bug.

tests/hard_coded/Mmakefile:
	Enable the test case.
1999-11-17 01:35:30 +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
Zoltan Somogyi
89065f0a1e Fix a bug in frameopt reported by Serge Varennes on April 15, 1999.
Estimated hours taken: 8

Fix a bug in frameopt reported by Serge Varennes on April 15, 1999.

The bug was that frameopt recognized that a procedure did not need a
stack frame, and deleted the frame setup code, but did not redirect the
failure branches inside inlined model_semi pragma_c instructions,
so that they still led to code that deallocated the (now nonexistent)
stack frame. This meant that calls to this procedure violated the
invariant which says that calls leave MR_sp unchanged.

compiler/llds.m:
	Add a new pragma C component (pragma_c_fail_to) that represents the
	branch to a label on failure of a model_semi piece of C code, instead
	of handling this by generating a string containing the C code that
	branches to this label. Record the failure label as a new field
	in pragma_c instructions.

	The point of this change is that it makes it possible to substitute
	the failure label in frameopt.

	Add also a pragma_c_noop component to make the generated code somewhat
	better optimizable.

compiler/pragma_c_gen.m:
	Generate the new LLDS components.

compiler/llds_out.m:
	Output the new LLDS components.

	Move a predicate declaration away from the middle of another predicate.

compiler/frameopt.m:
	Perform substitutions on pragma C code labels that occur only
	in pragma_c_fail_to components.

	If a pragma_c instruction has any other references to labels, we now
	assume that the block containing the instruction needs a stack frame,
	since those labels can't be substituted with their non-teardown
	parallels if this block is moved to a context without a stack frame.

compiler/basic_block.m:
compiler/dupelim.m:
compiler/frameopt.m:
compiler/opt_util.m:
	Both basic_block.m and dupelim.m had code that substantially
	duplicated code in frameopt.m. This change factors out the differences
	among the versions and moves the unified predicates to opt_util.m.

compiler/code_gen.m:
compiler/code_info.m:
compiler/dupelim.m:
compiler/livemap.m:
compiler/llds_common.m:
compiler/middle_rec.m:
compiler/opt_debug.m:
compiler/trace.m:
compiler/value_number.m:
compiler/vn_*.m:
	Trivial updates to conform to the changes in llds.m.

tests/hard_coded/frameopt_pragma_redirect.{m,exp}:
	A new test case that exhibits the problem. (It is not the original
	test cases submitted by Serge Varennes, because that code depended
	on non-standard functions in ieeefp.h.)

tests/hard_coded/Mmakefile:
	Enable the new test case.
1999-11-12 03:47:08 +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
0b35ee3f56 Add a new option, --checked-nondet-tailcalls, that enables the use of
Estimated hours taken: 8

Add a new option, --checked-nondet-tailcalls, that enables the use of
Prolog style nondet tail calls (which check whether the current frame is
on top of the nondet stack and only do a tail call if it is).

This option is not likely to help Mercury code, since most of the time
the test will fail, which means we incurred its cost and did not gain
the benefit of the tailcall. However, HAL often has predicates that are
declared nondet but are det or semidet most of the time, and these can
benefit.

compiler/options.m:
doc/user_guide.texi:
	Add the new option, which is not on by default and is not turned on
	at any optimization level; you have to give it explicitly.

compiler/llds.m:
	Modify the call_model type to distinguish the new style nondet tail
	call from the old (which does not do a runtime test).

compiler/code_info.m:
	Check the fail state whether it is suitable for new style nondet
	tail calls.

compiler/call_gen.m:
	Put the result from code_info.m into the generated LLDS.

compiler/jumpopt.m:
	Use the new status field in the LLDS to perform the optimization,
	if the option is given.

	Document the main predicate and its new argument.

compiler/optimize.m:
	Pass the value of the new option to jumpopt.

tests/hard_coded/checked_nondet_tailcall.{m,exp}:
	A new test case to check that the code we generate with the new
	option works correctly. (Checking whether it actually reduces
	nondet stack usage would be harder.)
1999-09-30 08:55:51 +00:00
Zoltan Somogyi
d49744914b Fix an old problem reported by Erwan about six months ago: in some cases,
Estimated hours taken: 5

Fix an old problem reported by Erwan about six months ago: in some cases,
the debugger listed a variable twice at one stop. The reason was that
we can record information about a variable either at a debugging port
or at a call's return site, and some points in the program are both.
The techniques we use to record the variable's details are necessarily
different (the return sites inspection is done after llds optimization),
and associate different insts with the variable. These differences
are irrelevant for RTTI, but they were confusing the code that was
designed to remove any such duplication.

Also fix another old problem: the appearance of "variable names"
such as V_11 in the lists of variables in the debugger. Such
variables should not appear in the debugger's output.

Both of these changes reduce the size of executables built with debugging.

compiler/llds.m:
	Do not use the type inst in the type live_value_type to record
	the instantiation state of a variabe, since the inst contains
	details such as exact functor bindings and uniqueness that RTTI
	is not interested in. RTTI wants to ignore differences in such
	areas, but this is not really possible while using type inst.
	We therefore introduce a new type llds_inst.

compiler/trace.m:
compiler/continuation_info.m:
	Compute llds_insts from insts before creating live_value_type
	structures. This requires access to a module_info to help interpret
	insts.

	In trace.m, do not invent names for live variables if they don't
	already have one.

compiler/code_info.m:
	Supply the module_info argument now needed by the modified predicates
	in continuation_info.

compiler/llds_out.m:
	Update the code for writing out live_value_types.

tests/debugger/queens.exp:
	Update the expected output of this debugger test case, since it
	no longer contains variables such as V_11.
1999-08-16 05:48:12 +00:00
Zoltan Somogyi
ca0b3b7c6b Add an option that causes the compiler to pass information to the
Estimated hours taken: 8

Add an option that causes the compiler to pass information to the
execution tracing system in one struct, rather than four separate arguments.

Two of these arguments are pointers, which each require two instructions
to set up on SPARC, MIPS and other RISCs that do not use a global pool.
The other two arguments are small constants. Therefore on 32-bit RISCs,
replacing MR_trace/4 with MR_trace_struct/1 will probably replace
six instructions with two, which saves four instructions' worth
of time and 16 bytes of code, at the cost of 12 bytes of data,
and possibly the cost of some instructions later loading the info
from the struct into registers. However, this loading cost does not have
to be paid if tracing is not enabled, and other optimizations may
reduce the cost even if tracing is enabled. For example, I strongly suspect
that on out-of-order machines, which means most CPUs you can buy today,
the load instructions are effectively free, because they happen while
the indirect jump to MR_trace_real takes place.

I intend to benchmark this option on our various platforms,
and have autoconfigure set it on the machines in which it is beneficial.

doc/user_guide.texi:
	Document the new --call-trace-struct option, and say it is not
	for general use.

compiler/options.m:
	Add the new option.

compiler/trace.m:
	If the option is set, call MR_trace_struct instead of MR_trace,
	and create a new kind of static (in both senses) global data structure
	to hold the arguments.

	Move the definition of trace_port to llds.m, and the procedure to
	convert it to string to llds_out.m

compiler/code_info.m:
	Add an extra code_info slot to hold this new kind of global data,
	and its access predicates.

compiler/code_gen.m:
	Transfer this new kind of global data from code_info to the global_data
	part of module_info.

compiler/hlds_module.m:
	Add a new field to the global_data data structure to hold this data.

compiler/mercury_compile.m:
	Include the new global data in the list of things we give to llds_out.

compiler/llds.m:
	Add a new kind of comp_gen_c_data to hold MR_trace_struct arguments.

	Also move the definition of trace_port from trace.m to here,
	since the new kind of comp_gen_c_data refers to this type.

compiler/llds_out.m:
	Add code to print the new kind of comp_gen_c_data.

	Move the code to print trace_ports from trace.m to here.

compiler/llds_common.m:
	Ignore the new kind of comp_gen_c_data, since by construction
	its contents are never common with anything else.

runtime/mercury_trace_base.[ch]:
	Add a new variant of MR_trace, MR_trace_struct, that consolidates
	the arguments into a single MR_Trace_Call_Info struct.

	Fix a bad variable name: the int argument to MR_trace is a max r
	register number, not a max mr register number.
1999-04-30 08:24:24 +00:00
Zoltan Somogyi
dc03496d06 Rewrite significant parts of minimal model tabling so that it works
Estimated hours taken: 130

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

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

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

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

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

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

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

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

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

	Rename the predicates referred to by table_gen.m.

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

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

runtime/mercury_conf_param.h:
	Document MR_USE_MINIMAL_MODEL.

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

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

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

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

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

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

	Improve the documentation considerably.

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

	Ensure that global names start with MR_.

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

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

	Fix a sorting error.

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

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

trace/mercury_trace_internal.c:
	If MR_USE_MINIMAL_MODEL is defined, add a new command to print
	the generator stack. (The new command is deliberately not documented
	in doc/mdb_doc yet, since (a) it is intended for developers only,
	and (b) there is no way to test MR_USE_MINIMAL_MODEL in mdb_doc.)
1999-04-20 11:48:56 +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
e33efd211a Allow the native collector to work for nondet code, by generating layout
Estimated hours taken: 10

Allow the native collector to work for nondet code, by generating layout
structures for the resumption points whose addresses can be put into
redoip slots in nondet stack frames.

If the program is compiled with both native gc and debugging, entries
to disjunctions will have two labels and two layout structures, one
for gc and one for the debugger. At the moment we make no attempt
to try to combine the two structures, since doing so would add significant
extra complexity. Optimizing this option combination will not be important
for a while yet anyway.

compiler/code_info.m:
	Update the code that generates resume points to also optionally
	generate layout structures for the stack labels.

compiler/disj_gen.m:
	When we save the heap pointer, update not only the current code_info
	but the saved code_info that represents the branch start position
	as well, since the slot containing the saved heap pointer will be
	live in each of the following disjuncts.

compiler/labelopt.m:
compiler/mercury_compile.m:
compiler/optimize.m:
compiler/value_number.m:
	Arrange to pass the global_data structure to the label elimination
	and value numbering passes. This is to (a) prevent the label
	elimination pass from removing labels (e.g. stack resume labels)
	that have layout structures, and (b) to prevent value numbering
	for moving computations across such labels, since that would
	invalidate the layout structure.

	(The presence of pragma_c_code fragments in the generated code avoids
	both these potential problems for layout structures that correspond
	to trace events, but that solution would be suboptimal for resume
	labels.)

compiler/hlds_module.m:
	Add a utility predicate needed by optimize.m.
1999-03-12 05:53:29 +00:00
Thomas Conway
5c955626f2 These changes make var' and term' polymorphic.
Estimated hours taken: 20

These changes make `var' and `term' polymorphic. This allows us to make
variables and terms representing types of a different type to those
representing program terms and those representing insts.

These changes do not *fix* any existing problems (for instance
there was a messy conflation of program variables and inst variables,
and where necessary I've just called varset__init(InstVarSet) with
an XXX comment).

NEWS:
	Mention the changes to the standard library.

library/term.m:
	Make term, var and var_supply polymorphic.
	Add new predicates:
		term__generic_term/1
		term__coerce/2
		term__coerce_var/2
		term__coerce_var_supply/2

library/varset.m:
	Make varset polymorphic.
	Add the new predicate:
		varset__coerce/2

compiler/prog_data.m:
	Introduce type equivalences for the different kinds of
	vars, terms, and varsets that we use (tvar and tvarset
	were already there but have been changed to use the
	polymorphic var and term).

	Also change the various kinds of items to use the appropriate
	kinds of var/varset.

compiler/*.m:
	Thousands of boring changes to make the compiler type correct
	with the different types for type, program and inst vars and
	varsets.
1998-11-20 04:10:36 +00:00
Zoltan Somogyi
a2f2f3a4a8 General cleanup of the code dealing with (a) the livevals annotation
compiler/call_gen.m:
compiler/code_info.m:
	General cleanup of the code dealing with (a) the livevals annotation
	before calls, which says what lvals are live before a call; and (b)
	what lvals are live containing what values after a call. This involves
	a rewrite of the appropriate submodule in code_info, including much
	more meaningful predicate names, and related changes in call_gen.
	It also involves adding a new, non-exported predicate in another
	submodule of code_info, and removing some code duplication; some
	of the work of the code_info submodule was duplicated in call_gen.

	There is no change in functionality.
1998-11-18 08:32:42 +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
085c8b8113 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:34 +00:00
Zoltan Somogyi
68a6586ca4 Fix bugs in the handling of temporaries.
Estimated hours taken: 10

Fix bugs in the handling of temporaries.

compiler/code_info.m:
	Reorganize the way temporary slots are handled. Create a stack slot
	to slot_contents map that is part of the permanent state, so each
	slot can be used for only one purpose within a procedure; this is
	to make garbage collection of these slots possible. Make the set
	of temporary slots in use be part of the location dependent state.

	At the ends of branched control structures, consider a temp slot
	in use if it was in use at the end of any branch. (Previously,
	we considered it live after the control structure if it was live
	at the end of the last branch. We got that right for branched
	structures that manipulate temp slots, i.e. disjunctions and
	if-then-elses, but we got it wrong for switches.

	Rename some predicates to get rid of the double meaning of the word
	"discard" as applied to a temporary, which used to mean either
	"release the slot" or "execute the discard_ticket operation".
	It now means only the latter; the word "release" refers to the former.

compiler/disj_gen.m:
compiler/ite_gen.m:
	Conform to the new method of handling temporary slots.

tests/valid/complex_failure.m:
tests/valid/semi_fail_in_non_ite.m:
	Copies of the test cases from tests/general.

tests/valid/Mmakefile:
	Enable the new test cases, running them with --use-trail.

	Unfortunately, we cannot just specify --use-trail for them
	in tests/general, since that would cause a link error in the usual
	case that the runtime being linked with is not in a trailing grade.
1998-11-03 01:36:00 +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
Zoltan Somogyi
3f1198e36f Fix wrong word in comment.
Estimated hours taken: 0.01

compiler/code_info.m:
	Fix wrong word in comment.
1998-08-25 05:09:41 +00:00
Zoltan Somogyi
72c3829fb9 Fix a subtle bug in the new way of handling failure.
Estimated hours taken: 8

Fix a subtle bug in the new way of handling failure. When we enter the
last disjunct of a model_non disjunction inside the model_non condition
of an if-then-else, set resume_point_known to unknown. This forces code
in the last disjunct and after the last disjunction to fail by invoking
redo(), not by a direct branch. The reason this is necessary that a direct
branch to the start of the else case is incorrect if the condition has
already returned some answers.

The bug was causing tests/general/complex_failure to fail at optimization
levels that caused the inlining of a predicate, which resulted in a disjunction
inside the last disjunct of a disjunction inside a model_non condition.

compiler/notes/failure.html:
	Modify the description of failure handling to encompass the solution
	of the problem.

compiler/code_info.m:
	Implement the solution.

tests/general/semi_fail_in_non_ite.{m,exp}:
	Add a new test case, a variant of complex_failure, that tests for the
	bug at all optimization levels.

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

tests/general/complex_failure.m:
	Remove an obsolete comment.
1998-08-07 05:13:17 +00:00
Zoltan Somogyi
ed063bcc00 Extend the new failure handling method to optionally preserve an invariant
Estimated hours taken: 30

Extend the new failure handling method to optionally preserve an invariant
required by accurate gc: always being able to tell with respect to what MR_sp
or MR_curfr to interpret the stackvars and framevars referred to by the label
whose address is the redoip slot of a nondet stack frame. This basically
requires limitations on the hijacking of redoip/redofr slot pairs.

compiler/notes/failure.html:
	Describe the new extension.

	Change the terminology to conform to what is used in the code.

compiler/llds.m:
	For each temporary frame on the nondet stack, specify the native
	stack of the procedure that created it. This is so that we know
	whether the temporary frame ought to have the fourth slot that
	specifies the right value of MR_sp. (The fourth slot is included
	only in temporary nondet stack frames created procedures that live
	on the det stack; procedures that live on the nondet stack never
	have any of their variables on the det stack.)

	Remove the modframe llds instruction, since it does not specify
	what frame's redoip slot it is assigning to. This is error-prone
	(see peephole.m below). We were not using modframe much anyway.

compiler/llds_out.m:
compiler/opt_debug.m:
	Emit either mktempframe or mkdettempframe depending on the new
	field in temp_frame.

compiler/code_info.m:
	Add a fourth item to the failure state, which states whether
	the top frame of the nondet stack may be hijacked. Initialize
	it from the option --allow-hijacks. If about to do a hijack
	but the failure state says no, create a temporary frame instead.

	Separate out the code for creating temporary frames, since it
	is now called from more than one place. Generalize the code
	to handle the new type of temp frame.

compiler/code_info.m:
compiler/ite_gen.m:
	Simplify the way we transmit information about the location
	of the address of the nondet stack frame in which the soft cut
	is performed from the start of the condition to its end.

	Remove the predicate code_info__maybe_push_temp_frame;
	its functionality is now achieved in code_info.m by disabling
	and restoring --allow-hijacks around the generation of code
	for the condition. This also allows us to get rid of the code
	that finds out whether the condition can do any hijacking.

compiler/opt_util.m:
	Rename next_modframe as next_assign_to_redoip, and add an additional
	argument that says which frame's redoip we are after.

compiler/peephole.m:
	Use the new argument of opt_util__next_assign_to_redoip to fix a bug
	where a mkframe of a temporary frame (which leaves curfr unchanged)
	that was followed a modframe (which assigns to the redoip of curfr)
	was incorrectly optimized (the assignment to the redoip slot was
	applied to the temporary frame, not the ordinary one).

compiler/*.m:
	Minor changes to accommodate the disappearance of modframe.

runtime/mercury_stacks.h:
	Add macros to support four-word temp frames on the nondet stack.

	Make the macros that access nondet stack frame slots start with MR_,
	while keeping (redefined) macros needed for backward compatibility.

	Remove the modframe macro.

	Fix a dangling reference to PREDNM instead of MR_PREDNM.

runtime/mercury_stack_trace.c:
	Modify the stack tracing code to allow for the new four-word temp
	frames.

	Use the new MR_ prefixed variants of the macros.

runtime/mercury_debug.h:
runtime/mercury_misc.[ch]:
	Remove references to modframe.

tests/general/complex_failure.{m,exp}:
	A new test case to tickle the various ways of handling nested
	disjunctions and if-then-elses in the new code generator.

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

tests/{general,hard_coded}/space.{m,exp}:
	Move this test case from general to hard_coded. Although NU-Prolog
	can execute it, it does not give the same answers as Mercury due to
	a different default ordering and a difference in integer size (26-bit
	integers in NU-Prolog) that changes the behavior of the pseudo
	random-number generator.

tests/hard_coded/cycles2.exp:
	Add the missing .exp file for this existing test case.

tests/hard_coded/Mmakefile:
	Enable the old test cases cycles, cycles2 and space, since
	we now pass them.
1998-07-29 08:57:09 +00:00
Fergus Henderson
5f3bf8ea52 Delete `:- import_module unsafe, io.', which zs apparently
Estimated hours taken: 0.25

compiler/code_info.m:
	Delete `:- import_module unsafe, io.', which zs apparently
	accidentally included in his previous commit.
1998-07-21 14:02:19 +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
Zoltan Somogyi
f203aea15c 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:12 +00:00
Thomas Conway
a70b59e83c Add a test to find the number of words needed to represent a
configure.in:
        Add a test to find the number of words needed to represent a
        synchronization term.

boehm_gc/gc.h:
        fix a declaration by replacing the args () with (void).
boehm_gc/solaris_pthreads.c:
        add a missing include
        check the return values of pthread calls.

compiler/*.m:
        Add handling for the new HLDS goal type par_conj.
        Add handling for the four new LLDS instructions:
                init_sync_term
                fork
                join_and_terminate
                join_and_continue

compiler/code_info.m:
        add a new alternative for slot_contents - sync_term.

compiler/handle_options.m:
        add .par as part of the grade

compiler/hlds_goal.m:
        add the new goal type par_conj.

compiler/instmap.m:
        add instmap__unify which takes a list of instmaps
                and abstractly unifies them.
        add unify_instmap_delta which tajes two instmap deltas
                and abstractly unifies them.

compiler/llds.m:
        add the new llds instructions.

compiler/mode_info.m:
        add par_conj as a lock reason.

library/Makefile:
        work around a bug in the solaris version pthread.h

library/benchmarking.m:
        reference the stack zones from the engine structure
        rather than from global variables.

library/{nc,sp}_builtin.nl:
        add an op declaration for &.

library/std_util.m:
        change references to global variables to references inside
        the engine structure.

runtime/Mmakefile:
        add mercury_thread.{c,h}
        add THREADLIBS to the libraries

runtime/*.{c,h}
        Remove some old junk from the previous processes/shrd-mem
        changes that found their way into the repository.
        Add MR_ prefixes to lots of names.

runtime/mercury_context.c:
        Add init_thread_stuff for creating and initializing a
        context structure for the current thread.

runtime/mercury_context.h:
        add a field to the mercury context which stores the thread id
        of the thread where this context originated.
        add various macros for implementing the new llds instructions.

runtime/mercury_engine.c:
        initialize the engine structure, rather than a bunch of globals.

runtime/mercury_engine.h:
        declare the mercury_engine structure.

runtime/mercury_regorder.h:
        if MR_THREAD_SAFE, and there is at least one global register
        then use mr0 as a pointer to the mercury engine structure.

scripts/init_grade_options.sh-subr
        add thread_safe

scripts/mgnuc.in
        add THREAD_OPTS

scripts/ml.in:
        add THREAD_LIBS
1998-06-09 02:16:31 +00:00
Fergus Henderson
7370e9117d Fix some bugs in code generation for nondet disjunctions and
Estimated hours taken: 4.5

Fix some bugs in code generation for nondet disjunctions and
if-then-elses.  The compiler was incorrectly releasing the temp stack
slots used to save the heap pointer and trail pointer at the start
of the else or the last clauses, thus allowing them to be reused not
only in the else case or the last clause, but also by goals following the
disjunction or if-then-else, even though the values in these slots might
be needed again on backtracking into the condition or the earlier
disjunctions.

Thanks to Warwick Harvey for reporting this bug.

compiler/code_info.m:
	Add new predicate `code_info__maybe_reset_and_pop_ticket',
	which is like `code_info__maybe_reset_and_discard_ticket',
	except that it does not release the temp stack slot.

compiler/disj_gen.m:
compiler/ite_gen.m:
	When generating code for nondet goals that save
	and restore the hp and trail, if the saved
	values might be needed again on backtracking
	into the current goal from one that follows
	(i.e. in nondet disjunctions and in if-then-elses
	with nondet conditions), make sure we use
	`code_info__maybe_reset_and_pop_ticket' and
	`code_info__reset_hp' instead of
	`code_info__maybe_reset_and_discard_ticket' and
	`code_info__reset_and_discard_hp'.

compiler/code_info.m:
	Include the temp_avail_slots in the set of things
	that slap_code_info does not update.  Temp slots
	that were acquired (and not released) in one branch
	of a branched goal need to be still reserved at the
	end of the branched goal.

extras/trailed_update/Mmakefile:
extras/trailed_update/samples/Mmakefile:
extras/trailed_update/samples/tests.m:
extras/trailed_update/samples/tests.exp:
extras/trailed_update/tests/Mmakefile:
extras/trailed_update/tests/var_test.m:
extras/trailed_update/tests/var_test.exp:
	Add a new subdirectory `tests' in extras/trailed_update,
	and move the test case `tests.{m,exp}' from the samples
	subdirectory into the tests subdirectory, at the same
	time renaming it as `var_test.{m,exp}'.

extras/trailed_update/tests/Mmakefile:
extras/trailed_update/tests/func_trail_test.m:
extras/trailed_update/tests/func_trail_test.exp:
extras/trailed_update/tests/func_trail_test_2.m:
extras/trailed_update/tests/func_trail_test_2.exp:
	Add a couple of regression tests for the bug mentioned above.
	These tests need to go here rather than somewhere in the
	main `tests' directory (e.g. `tests/hard_coded'), because
	they only work in trailing grades, and the normal tests are
	compiled in lots of grades, many of which don't have
	corresponding trailing grades installed.
	(I suppose we could put them in the main `tests' directory,
	and only enable them for trailing grades, but it just seemed
	easier to put them here.)
1998-06-02 05:32:26 +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
Zoltan Somogyi
67d8308260 Same as previous message. 1998-04-08 11:36:13 +00:00
Fergus Henderson
11d8161692 Add support for nested modules.
Estimated hours taken: 50

Add support for nested modules.

- module names may themselves be module-qualified
- modules may contain `:- include_module' declarations
  which name sub-modules
- a sub-module has access to all the declarations in the
  parent module (including its implementation section).

This support is not yet complete; see the BUGS and LIMITATIONS below.

LIMITATIONS
- source file names must match module names
	(just as they did previously)
- mmc doesn't allow path names on the command line any more
	(e.g. `mmc --make-int ../library/foo.m').
- import_module declarations must use the fully-qualified module name
- module qualifiers must use the fully-qualified module name
- no support for root-qualified module names
	(e.g. `:parent:child' instead of `parent:child').
- modules may not be physically nested (only logical nesting, via
  `include_module').

BUGS
- doesn't check that the parent module is imported/used before allowing
	import/use of its sub-modules.
- doesn't check that there is an include_module declaration in the
	parent for each module claiming to be a child of that parent
- privacy of private modules is not enforced

-------------------

NEWS:
	Mention that we support nested modules.

library/ops.m:
library/nc_builtin.nl:
library/sp_builtin.nl:
compiler/mercury_to_mercury.m:
	Add `include_module' as a new prefix operator.
	Change the associativity of `:' from xfy to yfx
	(since this made parsing module qualifiers slightly easier).

compiler/prog_data.m:
	Add new `include_module' declaration.
	Change the `module_name' and `module_specifier' types
	from strings to sym_names, so that module names can
	themselves be module qualified.

compiler/modules.m:
	Add predicates module_name_to_file_name/2 and
	file_name_to_module_name/2.
	Lots of changes to handle parent module dependencies,
	to create parent interface (`.int0') files, to read them in,
	to output correct dependencies information for them to the
	`.d' and `.dep' files, etc.
	Rewrite a lot of the code to improve the readability
	(add comments, use subroutines, better variable names).
	Also fix a couple of bugs:
	- generate_dependencies was using the transitive implementation
	  dependencies rather than the transitive interface dependencies
	  to compute the `.int3' dependencies when writing `.d' files
	  (this bug was introduced during crs's changes to support
	  `.trans_opt' files)
	- when creating the `.int' file, it was reading in the
	  interfaces for modules imported in the implementation section,
	  not just those in the interface section.
	  This meant that the compiler missed a lot of errors.

library/graph.m:
library/lexer.m:
library/term.m:
library/term_io.m:
library/varset.m:
compiler/*.m:
	Add `:- import_module' declarations to the interface needed
	by declarations in the interface.  (The previous version
	of the compiler did not detect these missing interface imports,
	due to the above-mentioned bug in modules.m.)

compiler/mercury_compile.m:
compiler/intermod.m:
	Change mercury_compile__maybe_grab_optfiles and
	intermod__grab_optfiles so that they grab the opt files for
	parent modules as well as the ones for imported modules.

compiler/mercury_compile.m:
	Minor changes to handle parent module dependencies.
	(Also improve the wording of the warning about trans-opt
	dependencies.)

compiler/make_hlds.m:
compiler/module_qual.m:
	Ignore `:- include_module' declarations.

compiler/module_qual.m:
	A couple of small changes to handle nested module names.

compiler/prog_out.m:
compiler/prog_util.m:
	Add new predicates string_to_sym_name/3 (prog_util.m) and
	sym_name_to_string/{2,3} (prog_out.m).

compiler/*.m:
	Replace many occurrences of `string' with `module_name'.
	Change code that prints out module names or converts
	them to strings or filenames to handle the fact that
	module names are now sym_names intead of strings.
	Also change a few places (e.g. in intermod.m, hlds_module.m)
	where the code assumed that any qualified symbol was
	fully-qualified.

compiler/prog_io.m:
compiler/prog_io_goal.m:
	Move sym_name_and_args/3, parse_qualified_term/4 and
	parse_qualified_term/5 preds from prog_io_goal.m to prog_io.m,
	since they are very similar to the parse_symbol_name/2 predicate
	already in prog_io.m.  Rewrite these predicates, both
	to improve maintainability, and to handle the newly
	allowed syntax (module-qualified module names).
	Rename parse_qualified_term/5 as `parse_implicit_qualified_term'.

compiler/prog_io.m:
	Rewrite the handling of `:- module' and `:- end_module'
	declarations, so that it can handle nested modules.
	Add code to parse `include_module' declarations.

compiler/prog_util.m:
compiler/*.m:
	Add new predicates mercury_public_builtin_module/1 and
	mercury_private_builtin_module/1 in prog_util.m.
	Change most of the hard-coded occurrences of "mercury_builtin"
	to call mercury_private_builtin_module/1 or
	mercury_public_builtin_module/1 or both.

compiler/llds_out.m:
	Add llds_out__sym_name_mangle/2, for mangling module names.

compiler/special_pred.m:
compiler/mode_util.m:
compiler/clause_to_proc.m:
compiler/prog_io_goal.m:
compiler/lambda.m:
compiler/polymorphism.m:
	Move the predicates in_mode/1, out_mode/1, and uo_mode/1
	from special_pred.m to mode_util.m, and change various
	hard-coded definitions to instead call these predicates.

compiler/polymorphism.m:
	Ensure that the type names `type_info' and `typeclass_info' are
	module-qualified in the generated code.  This avoids a problem
	where the code generated by polymorphism.m was not considered
	type-correct, due to the type `type_info' not matching
	`mercury_builtin:type_info'.

compiler/check_typeclass.m:
	Simplify the code for check_instance_pred and
	get_matching_instance_pred_ids.

compiler/mercury_compile.m:
compiler/modules.m:
	Disallow directory names in command-line arguments.

compiler/options.m:
compiler/handle_options.m:
compiler/mercury_compile.m:
compiler/modules.m:
	Add a `--make-private-interface' option.
	The private interface file `<module>.int0' contains
	all the declarations in the module; it is used for
	compiling sub-modules.

scripts/Mmake.rules:
scripts/Mmake.vars.in:
	Add support for creating `.int0' and `.date0' files
	by invoking mmc with `--make-private-interface'.

doc/user_guide.texi:
	Document `--make-private-interface' and the `.int0'
	and `.date0' file extensions.

doc/reference_manual.texi:
	Document nested modules.

util/mdemangle.c:
profiler/demangle.m:
	Demangle names with multiple module qualifiers.

tests/general/Mmakefile:
tests/general/string_format_test.m:
tests/general/string_format_test.exp:
tests/general/string__format_test.m:
tests/general/string__format_test.exp:
tests/general/.cvsignore:
	Change the `:- module string__format_test' declaration in
	`string__format_test.m' to `:- module string_format_test',
	because with the original declaration the `__' was taken
	as a module qualifier, which lead to an error message.
	Hence rename the file accordingly, to avoid the warning
	about file name not matching module name.

tests/invalid/Mmakefile:
tests/invalid/missing_interface_import.m:
tests/invalid/missing_interface_import.err_exp:
	Regression test to check that the compiler reports
	errors for missing `import_module' in the interface section.

tests/invalid/*.err_exp:
tests/warnings/unused_args_test.exp:
tests/warnings/unused_import.exp:
	Update the expected diagnostics output for the test cases to
	reflect a few minor changes to the warning messages.

tests/hard_coded/Mmakefile:
tests/hard_coded/parent.m:
tests/hard_coded/parent.child.m:
tests/hard_coded/parent.exp:
tests/hard_coded/parent2.m:
tests/hard_coded/parent2.child.m:
tests/hard_coded/parent2.exp:
	Two simple tests case for the use of nested modules with
	separate compilation.
1998-03-03 17:48:14 +00:00
Zoltan Somogyi
5ef3bb6fdc Use stack layout tables to transmit information to the tracer, to allow
Estimated hours taken: 20

Use stack layout tables to transmit information to the tracer, to allow
the tracer to print the names and values of variables at CALL and EXIT ports.
Extend stack layout tables to permit this.

For the time being the tables do not contain information about how to fill
in pseudo-typeinfos, so printing only works for monomorphic procedures.

compiler/llds.m:
	Allow space for variable names in the information we gather about live
	variables at given labels.

compiler/llds_out.m:
	Print out variable names in the information we gather about live
	variables at given labels in comments.

compiler/continuation_info.m:
	Include variable names in the information we gather about live
	variables at given labels.

	Record the determinism of each procedure, not its code model.

compiler/{call_gen,code_gen,code_info}.m:
	Include the names of variables in the data given to
	continuation_info.m.

compiler/options.m:
	Add a new developer-only option, --procid-stack-layout, whose effect
	is to extend stack_layout structures with static info identifying the
	procedure. This is used by execution tracing, and could (should) be
	used by stack tracing and profiling.

	Rename --alternate-liveness as --typeinfo-liveness. This is more
	expressive. Later we should add a new option --trace-liveness, which
	preserves every variable until the end of the clause for use by
	the trace debugger.

compiler/handle_options.m:
	Handle the option implications of --procid-stack-layout.

compiler/stack_layout.m:
	Include the encoded determinism instead of the code model in stack
	layout tables.

	Include variable names in the live data section of stack layout tables
	if they are available.

	Include procedure identification information in the stack layout tables
	if --procid-stack-layout is set.

compiler/trace.m:
	Use the new interface to MR_trace.

compiler/*.m:
	Trivial changes following from the renaming of --alternate-liveness.

runtime/mercury_accurate_gc.h:
	Add macros to decode encoded determinisms.

	Define structs for accessing the stack layout tables.

runtime/mercury_regs.h:
	Define a macro similar to virtual_reg, except in that it can refer
	to an arbitrary memory area, not just fake_reg.

runtime/{mercury_string,mercury_types}.h:
	Move the typedefs of Char, UnsignedChar, String and ConstString
	from mercury_string.h to mercury_types.h to avoid problems with
	circular #includes.

runtime/mercury_trace.[ch]:
	Revise the interface to MR_trace so that it takes the layout table
	of the procedure as an argument. From the layout table, we can get
	to the module name, predicate name, arity, mode number, and
	determinism of the procedure, so we don't need to pass these any more,
	reducing parameter passing overhead. We can also get to information
	about where the input and output arguments are. We now use this
	information to allow the user to print out the value of the arguments
	at the CALL and EXIT ports.

	Change the prompt to a less intrusive "mtrace> ".

runtime/mercury_wrapper.[ch]:
	Add a new global variable, MR_library_trace_browser. We reserve space
	for this variable in mercury_wrapper.c. It will be initialized by the
	automatically generated xxx_init.c file to point to the procedure
	that the tracer will invoke to let the user browse the values of
	variables. This mechanism allows the runtime to maintain its current
	ignorance about the contents of the standard library.

util/mkinit.c:
	Generate additional code in the xxx_init.c files to fill in the value
	of MR_library_trace_browser.

tests/misc_tests/debugger_test.{inp,exp}:
	Add a few printing commands into the input for this test case, and
	update the expected output.
1998-02-03 08:20:12 +00:00
Zoltan Somogyi
5013dd9c76 Implement nondet pragma C codes.
Estimated hours taken: 40

Implement nondet pragma C codes.

runtime/mercury_stacks.h:
	Define a new macro, mkpragmaframe, for use in the implementation
	of nondet pragma C codes. This new macro includes space for a
	struct with a given sruct tag in the nondet stack frame being created.

compiler/{prog_data.m,hlds_goal.m}:
	Revise the representation of pragma C codes, both as the item and
	in the HLDS.

compiler/prog_io_pragma.m:
	Parse nondet pragma C declarations.

	Fix the indentation in some places.

compiler/llds.m:
	Include an extra argument in mkframe instructions. This extra argument
	gives the details of the C structure (if any) to be included in the
	nondet stack frame to be created.

	Generalize the LLDS representation of pragma C codes. Instead of a
	fixed sequence of <assign from inputs, user c code, assign to outputs>,
	let the sequence contain these elements, as well as arbitrary
	compiler-generated C code, in any order and possibly with repetitions.
	This flexibility is needed for nondet pragma C codes.

	Add a field to pragma C codes to say whether they can call Mercury.
	Some optimizations can do a better job if they know that a pragma C
	code cannot call Mercury.

	Add another field to pragma C codes to give the name of the label
	they refer to (if any). This is needed to prevent labelopt from
	incorrectly optimizing away the label definition.

	Add a new alternative to the type pragma_c_decl, to describe the
	declaration of the local variable that points to the save struct.

compiler/llds_out.m:
	Output mkframe instructions that specify a struct as invoking the new
	mkpragmaframe macro, and make sure that the struct is declared just
	before the procedure that uses it.

	Other minor changes to keep up with the changes to the representation
	of pragma C code in the LLDS, and to make the output look a bit nicer.

compiler/pragma_c_gen.m:
	Add code to generate code for nondet pragma C codes. Revise the utility
	predicates and their data structures a bit to make this possible.

compiler/code_gen.m:
	Add code for the necessary special handling of prologs and epilogs
	of procedures defined by nondet pragma C codes. The prologs need
	to be modified to include a programmer-defined C structure in the
	nondet stack frame and to communicate the location of this structure
	to the pragma C code, whereas the functionality of the epilog is
	taken care of by the pragma C code itself.

compiler/make_hlds.m:
	When creating a proc_info for a procedure defined by a pragma C code,
	we used to insert unifications between the headvars and the vars of
	the pragma C code into the body goal. We now perform substitutions
	instead. This removes a factor that would complicate the generation
	of code for nondet pragma C codes.

	Pass a moduleinfo down the procedures that warn about singletons
	(and other basic scope errors). When checking whether to warn about
	an argument of a pragma C code not being mentioned in the C code
	fragment, we need to know whether the argument is input or output,
	since input variables should appear in some code fragments in a
	nondet pragma C code and must not appear in others. The
	mode_is_{in,out}put checks need the moduleinfo.

	(We do not need to check for any variables being mentioned where
	they shouldn't be. The C compiler will fail in the presence of any
	errors of that type, and since those variables could be referred
	to via macros whose definitions we do not see, we couldn't implement
	a reliable test anyway.)

compiler/opt_util.m:
	Recognize that some sorts of pragma_c codes cannot affect the data
	structures that control backtracking. This allows peepholing to
	do a better job on code sequences produced for nondet pragma C codes.

	Recognize that the C code strings inside some pragma_c codes refer to
	other labels in the procedure. This prevents labelopt from incorrectly
	optimizing away these labels.

compiler/dupelim.m:
	If a label is referred to from within a C code string, then do not
	attempt to optimize it away.

compiler/det_analysis.m:
	Remove a now incorrect part of an error message.

compiler/*.m:
	Minor changes to conform to changes to the HLDS and LLDS data
	structures.
1998-01-13 10:14:23 +00:00
Zoltan Somogyi
bb4442ddc1 Update copyright dates for 1998.
Estimated hours taken: 0.5

compiler/*.m:
	Update copyright dates for 1998.
1998-01-13 10:06:08 +00:00