Commit Graph

248 Commits

Author SHA1 Message Date
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
David Jeffery
7406335105 This change implements typeclasses. Included are the necessary changes to
Estimated hours taken: 500 or so

This change implements typeclasses. Included are the necessary changes to
the compiler, runtime and library.

compiler/typecheck.m:
	Typecheck the constraints on a pred by adding constraints for each
	call to a pred/func with constraints, and eliminating constraints
	by applying context reduction.

	While reducing the constraints, keep track of the proofs so that
	polymorphism can produce the tyepclass_infos for eliminated
	constraints.

compiler/polymorphism.m:
	Perform the source-to-source transformation which turns code with
	typeclass constraints into code without constraints, but with extra
	"typeclass_info", or "dictionary" parameters.

	Also, rather than always having a type_info directly for each type
	variable, sometimes the type_info is hidden inside a typeclass_info.

compiler/bytecode*.m:
	Insert some code to abort if bytecode generation is used when
	typeclasses are used.
compiler/call_gen.m:
	Generate code for a class_method_call, which forms the body of a class
	method (by selecting the appropriate proc from the typeclass_info).
compiler/dead_proc_elim.m:
	Don't eliminate class methods if they are potentially used outside
	the module
compiler/hlds_data.m:
	Define data types to store:
		- the typeclass definitions
		- the instances of a class
		- "constraint_proof". ie. the proofs of redundancy of a
		  constraint. This info is used by polymorphism to construct the
		  typeclass_infos for a constraint.
		- the "base_tyepclass_info_constant", which is analagous the
		  the base_type_info_constant
compiler/hlds_data.m:
	Define the class_method_call goal. This goal is inserted into the
	body of class method procs, and is responsible for selecting the
	appropriate part of the typeclass_info to call.
compiler/hlds_data.m:
	Add the class table and instance table to the module_info.
compiler/hlds_out.m:
	Output info about base_typeclass_infos and class_method_calls
compiler/hlds_pred.m:
	Change the representation of the locations of type_infos from "var"
	to type_info_locn, which is either a var, or part of a typeclass_info,
	since now the typeclass_infos contain the type_infos for the type that
	they constrain.

	Add constraints to the pred_info.

	Add constraint_proofs to the pred_info (so that typeclass.m can
	annotate the pred_info with the reasons that constraints were
	eliminated, so that polymorphism.m can in turn generate the
	typeclass_infos for the constraints).

	Add the "class_method" marker.

compiler/lambda.m:
	A feable attempt at adding class ontexts to lambda expressions,
	untested and almost certainly not working.
compiler/llds_out.m:
	Output the code addresses for do_*det_class_method, and output
	appropriately mangled symbol names for base_typeclass_infos.
compiler/make_hlds.m:
	Add constraints to the types on pred and func decls, and add
	class and instance declarations to the class_table and instance_table
	respectively.
compiler/mercury_compile.m:
	Add the check_typeclass pass.
compiler/mercury_to_mercury.m:
	Output constraints of pred and funcs, and output typeclass and instance
	declarations.
compiler/module_qual.m:
	Module qualify typeclass names in pred class contexts, and qualify the
	typeclass and instance decls themselves.
compiler/modules.m:
	Output typeclass declarations in the short interface too.
compiler/prog_data.m:
	Add the "typeclass" and "instance" items. Define the types to store
	information about the declarations, including class contexts on pred
	and func decls.
compiler/prog_io.m:
	Parse constraints on pred and func declarations.
compiler/prod_out.m:
	Output class contexts on pred and func decls.
compiler/type_util.m:
	Add preds to apply a substitution to a class_constraint, and to
	a list of class constraints. Add type_list_matches_exactly/2. Also
	add typeclass_info and base_typeclass_info as types which should not
	be optimised as no_tag types (seeing that we cheat a bit about their
	representation).
compiler/notes/compiler_design.html:
	Add notes on module qualification of class contexts. Needs expansion
	to include more stuff on typeclasses.
compiler/*.m:
	Various minor changes.

New Files:
compiler/base_typeclass_info.m:
	Produce one base_typeclass_info for each instance declaration.
compiler/prog_io_typeclass.m:
	Parse typeclass and instance declarations.
compiler/check_typeclass.m:
	Check the conformance of an instance declaration to the typeclass
	declaration, including building up a proof of how superclass
	constraints are satisfied so that polymorphism.m is able to construct
	the typeclass_info, including the superclass typeclass_infos.

library/mercury_builtin.m:
	Implement that base_typeclass_info and typeclass_info types, as
	well as the predicates type_info_from_typeclass_info/3 to extract
	a type_info from a typeclass_info, and superclass_from_typeclass_info/3
	for extracting superclasses.
library/ops.m:
	Add "typeclass" and "instance" as operators.
library/string.m:
	Add a (in, uo) mode for string__length/3.

runtime/mercury_ho_call.c:
	Implement do_call_*det_class_method, which are the pieces of code
	responsible for extracting the correct code address from the
	typeclass_info, setting up the arguments correctly, then executing
	the code.
runtime/mercury_type_info.h:
	Macros for accessing the typeclass_info structure.
1997-12-19 03:10:47 +00:00
Zoltan Somogyi
248d00e14b First implementation of the generation of traces for Opium-style trace
Estimated hours taken: 7

First implementation of the generation of traces for Opium-style trace
analysis.

In this initial implementation, there are only three ports: call, exit
and fail. Later versions will add ports that indicate entry to an arm
of a switch or disjunction and to the then or else part of an if-then-else.

compiler/options.m:
	Add a new option, --generate-trace.

compiler/handle_options.m:
	When --generate-trace is on, turn off HLDS->HLDS optimizations
	that would change the behavior of the trace.

compiler/code_info.m:
	Add a new field in code_into for storing information that is
	needed when generating trace code. (At the moment, this info is
	the identity of two stack slots storing the sequence number and
	depth of the current procedure call.) This info must be in the
	code_info structure, because it is used not only by code_gen.m
	but also by call_gen.m, and later by switch_gen.m, disj_gen.m and
	ite_gen.m.

compiler/code_gen.m:
	Add code to initialize the tracing info in code_info and to add
	trace statements to procedure prologs and epilogs if --generate-trace
	is on.

compiler/call_gen.m:
	Clean up the generation of code for calls, merging the three
	predicates for det, semi and non procedures into one, and factoring
	out some common code between the generation of code for normal calls
	and higher order calls. Add code to reset the call depth just before
	each (normal or higher-order) call if --generate-trace is on.

compiler/trace.m:
	New file responsible for the generation of trace statements in the
	C file output by the compiler. Code in code_gen.m and call_gen.m
	calls trace.m; so will code in switch_gen.m, disj_gen.m and ite_gen.m.

compiler/mercury_compile.m:
	When --generate-trace is on, include mercury_trace.h at the top
	of generated C files.

runtime/mercury_trace.[ch]:
	The new runtime tracing module. The proper version will be written
	in Rennes, this is just for initial testing.

runtime/Mmakefile:
	Include the new module in the runtime library.

doc/user_guide.texi:
	Document --generate-trace.
1997-10-03 04:56:33 +00:00
Fergus Henderson
2fcaae6d5c Fix a bug in code generation for commits in trailed grades.
Estimated hours taken: 2

Fix a bug in code generation for commits in trailed grades.
This bug broke the test case tests/general/commit_bug.m.

compiler/code_info.m:
	In undo_commit_saves, make sure we use the values that
	pre_commit_saves pused on the stack _before_ popping the stack.
1997-09-14 03:54:36 +00:00
Fergus Henderson
c8642b9dd1 Fix code generation for commits and nondet if-then-elses so that
Estimated hours taken: 9

Fix code generation for commits and nondet if-then-elses so that
it computes MR_ticket_counter correctly.

compiler/ite_gen.m:
compiler/code_info.m:
	Change the way we do a soft cut when generating code for nondet
	if-then-elses with nondet conditions so that the ticket counter
	is restored correctly on backtracking.

compiler/llds.m:
	Add new instructions `mark_trail_stack(lval)' and
	`discard_tickets_to(rval)' to save/restore the ticket counter.

compiler/code_info.m:
	Save the ticket counter before doing a commit and
	restore it afterwards.

compiler/*.m:
	Various minor changes to handle the new LLDS instructions.

runtime/mercury_trail.h:
	Add new macros to implement the new LLDS instructions.

compiler/livemap.m:
	Change the code in build_livemap_instr for mark_hp and
	store_ticket so that it deletes the target lval from the
	set of live variables, and simplify the code there for reset_ticket.
1997-08-25 17:48:57 +00:00
Fergus Henderson
791142c9b0 Add code to handle trailing when generating code for commits.
Estimated hours taken: 3

compiler/code_info.m:
	Add code to handle trailing when generating code for commits.
1997-08-24 10:00:21 +00:00
Fergus Henderson
02f3e99e41 Change the generated code for trailing to match the new trailing interface.
Estimated hours taken: 3

Change the generated code for trailing to match the new trailing interface.

compiler/code_gen.m:
	When generating code for negations, ensure that we generate a
	discard_ticket instruction to discard the current ticket before
	failing.

compiler/llds.m:
compiler/llds_out.m:
compiler/code_info.m:
	Change the `restore_ticket(Rval)' instruction to
	`reset_ticket(Rval, Reason)', where Reason is one of
	undo, commit, exception, or gc, as per runtime/mercury_trail.h.
	A reset with Reason = undo gives the old "restore" behaviour.

compiler/frameopt.m:
compiler/livemap.m:
compiler/llds_common.m:
compiler/middle_rec.m:
compiler/opt_*.m:
compiler/peephole.m:
compiler/value_number.m:
compiler/vn_*.m:
	Trivial changes to handle reset_ticket/2 instead of restore_ticket/1.

compiler/code_gen.m:
compiler/ite_gen.m:
compiler/disj_gen.m:
	Change the places that called code_gen__maybe_discard_ticket
	to instead call code_gen__maybe_reset_and_discard_ticket(...commit...).
1997-08-24 01:30:09 +00:00
Fergus Henderson
796f7f7436 Fix a bug which caused the code generator to fail on certain
Estimated hours taken: 16

Fix a bug which caused the code generator to fail on certain
examples involving predicates with determinism `erroneous'.

compiler/inst_match.m:
	Change `inst_is_bound' so that it succeeds for `not_reached' insts.
	This change is so that the behaviour of the predicate matches
	the documentation, and so that it is consistent with the behaviour
	of `inst_is_ground'.

compiler/liveness.m:
	When computing the value-giving occurrences, check explicitly
	for unreachable instmaps.  This is necessary to handle the above
	change to `inst_is_bound'.

	Fix a bug in detect_deadness: it was applying the deaths before
	the births, but it should be done in the other order.
	Normally deaths must be applied before births, but in detect_deadness
	we are traversing the goal backwards, so we must apply births first
	and then deaths.

	The old solution of just cancelling out any vars that occur in
	both the post-death and post-birth set was not quite right;
	instead we just need to apply them in the correct order.

compiler/code_info.m:
	Change the code so that it applies the pre/post deaths
	before applying the corresponding births.

compiler/live_vars.m:
compiler/store_alloc.m:
compiler/hlds_goal.m:
	Add some comments about making sure we always apply the deaths
	before applying the births.  (The code here was already correct,
	I just added some documentation.)

compiler/hlds_out.m:
	Print out the pre/post deaths before the pre/post births, so
	that the order that they are printed out in matches the order
	in which they should be applied.

tests/hard_coded/Mmake:
tests/hard_coded/erroneous_liveness.m:
tests/hard_coded/erroneous_liveness.exp:
tests/hard_coded/erroneous_liveness.inp:
	Regression test for the above-mentioned bug fix.
1997-08-23 20:35:08 +00:00
Fergus Henderson
04b720630b Update the copyright messages so that (a) they contain the correct years
and (b) they say "Copyright (C) ... _The_ University of Melbourne".
1997-07-27 15:09:59 +00:00
Simon Taylor
27d156bbb5 Implemented a :- use_module directive. This is the same as
Estimated hours taken: 14

Implemented a :- use_module directive. This is the same as
:- import_module, except all uses of the imported items
must be explicitly module qualified.

:- use_module is implemented by ensuring that unqualified versions
of items only get added to the HLDS symbol tables if they were imported
using import_module.

Indirectly imported items (from `.int2' files) and items declared in `.opt'
files are treated as if they were imported with use_module, since all uses
of them should be module qualified.

compiler/module_qual.m
	Keep two sets of type, mode and inst ids, those which can
	be used without qualifiers and those which can't.

	Renamed some predicates which no longer have unique names since
	'__' became a synonym for ':'.

	Made mq_info_set_module_used check whether the current item is in
	the interface, rather than relying on its caller to do the check.

	Removed init_mq_info_module, since make_hlds.m now uses the
	mq_info built during the module qualification pass.

compiler/prog_data.m
	Added a pseudo-declaration `used', same as `imported' except uses of
	the following items must be module qualified.

	Added a type need_qualifier to describe whether uses of an item
	need to be module qualified.

compiler/make_hlds.m
	Keep with the import_status whether current item was imported
	using a :- use_module directive.

	Use the mq_info structure passed in instead of building a new one.

	Ensure unqualified versions of constructors only get added to the
	cons_table if they can be used without qualification.

compiler/hlds_module.m
	Added an extra argument to predicate_table_insert of type
	need_qualifier.

	Only add predicates to the name and name-arity indices if they
	can be used without qualifiers.

	Changed the structure of the module-name-arity index, so that
	lookups can be made without an arity, such as when type-checking
	module qualified higher-order predicate constants. This does not
	change the interface to the module_name_arity index.

	Factored out some common code in predicate_table_insert which
	applies to both predicates and functions.

compiler/hlds_pred.m
	Removed the opt_decl import_status. It isn't needed any more
	since all uses of items declared in .opt files must now be
	module qualified.

	Added some documentation about when the clauses_info is valid.

compiler/intermod.m
	Ensure that predicate and function calls in the `.opt' file are
	module qualified. Use use_module instead of import_module in
	`.opt' files.

compiler/modules.m
	Handle use_module directives.

	Report a warning if both use_module and import_module declarations
	exist for the same module.

compiler/mercury_compile.m
	Collect inter-module optimization information before module
	qualification, since it can't cause conflicts any more. This means
	that the mq_info structure built in module_qual.m can be reused in
	make_hlds.m, instead of building a new one.

compiler/prog_out.m
	Add a predicate prog_out__write_module_list, which was moved
	here from module_qual.m.

compiler/typecheck.m
	Removed code to check that predicates declared in `.opt' files
	were being used appropriately, since this is now handled by
	use_module.

compiler/*.m
	Added missing imports, mostly for prog_data and term.

NEWS
compiler/notes/todo.html
doc/reference_manual.texi
	Document `:- use_module'.

tests/valid/intermod_lambda_test.m
tests/valid/intermod_lambda_test2.m
tests/invalid/errors.m
tests/invalid/errors2.m
	Test cases.
1997-06-29 23:11:42 +00:00
Fergus Henderson
d86ea8fb5a Fix a couple of bugs with nondet code generation.
Estimated hours taken: 12

Fix a couple of bugs with nondet code generation.

compiler/code_info.m:
	Fix two bugs in code_info__make_known_failure cont.

	The first bug was that the way it checked for whether a temp
	frame had been created was incorrect; it was only checking
	the HaveTempFrame parameter, which was true only if the most
	recent disjunction had required creation of a temp frame,
	whereas it needs to check the whole failure continuation stack.

	The second bug was that it was doing the wrong thing in the
	case where the current failure continuation was unknown,
	but a temp frame had been created.  It was just clobbering
	the current redoip, whereas what it needs to do is to create
	another temp frame.

compiler/code_gen.m:
compiler/disj_gen.m:
compiler/ite_gen.m:
	Don't pass the HaveTempFrame parameters to and from
	code_info__make_known_failure_cont.
1997-06-11 05:13:53 +00:00
Tyson Dowd
62b46f531b Fix the insts of live variables in continuation_info.
Estimated hours taken: 1.5

Fix the insts of live variables in continuation_info. They were calculated
using the insts before the call instead of after the call.

compiler/call_gen.m:
compiler/code_info.m:
	Apply the instmap_delta of the current goal to the instmap when
	looking up the insts of live variables.
	Make the hlds_goal_info of the current goal available when
	generating calls.

compiler/code_gen.m:
	Make the hlds_goal_info of the current goal available when
	generating calls.
1997-06-05 05:47:56 +00:00
Tyson Dowd
ab20991f00 Changes to clean up the collection of live value information.
Estimated hours taken: 30

Changes to clean up the collection of live value information. Instead of
requesting shape numbers and outputting .garb files, we store the needed
information for later processing, so we can generate typeinfos for such
types later, when we create stack_layout tables.

The compiler actually _shrinks_ as a result of this change.

compiler/call_gen.m:
	- Don't request shape numbers for live data, store their types
	  and insts instead.

compiler/code_gen.m:
	- Call continuation_info__add_proc_info for each procedure
	  generated.
	- Pass around continuation_infos rather than shape_tables.

compiler/code_info.m:
	- Don't request shape numbers for live data, store their types
	  and insts instead.
	- Provide predicate for converting lvals into live_value_types.
	- Replace shape_table with continuation_info

compiler/continuation_info.m:
	- New module for storing information about continuations needed
	  for accurate garbage collection. This will later be used to
	  output stack_layout structures.

compile/hlds_module.m:
	- Remove shape_table from module_info, put continuation_info in
	  its place.

compiler/llds.m:
	- Add new live_value_type, which describes a live value (succip,
	  curfr, maxfr, redoip, hp, var(type, inst), unwanted).
	  This will replace the shape_num type.

compiler/llds_out.m:
	- Output live_value_types instead of shape_nums.

compiler/make_hlds.m:
	- Don't add abstract_exports to the shape table - we don't
	  use them anymore.

compiler/mercury_compile.m:
	- Document `join_string_list' and `join_module_list' as their names
	  are a bit cryptic.
	- Don't output .garb files, don't do abstract exports pass.
	- Replace handling of shape_table with continuation_info.

compiler/garbage_out.m:
compiler/shapes.m:
	- Remove these files, as they are no longer used.

runtime/mercury_accurate_gc.h:
	- Add new file with defintions for accurate gc.
1997-05-27 03:10:41 +00:00
Tyson Dowd
cbcb23d17b Enable --warn-interface-imports by default.
Estimated hours taken: 3

Enable --warn-interface-imports by default. This was turned off while
list and term were defined in mercury_builtin.m, since it caused many
warnings.

Fix all the unused interface imports that have been added since then.

compiler/options.m:
	Enable --warn-interface-imports by default.

compiler/module_qual.m:
	Fix formatting inconsistencies with module names in warning
	messages. (".m" was not appended to module names if there was
	only one module).

compiler/*.m:
library/*.m:
tests/invalid/type_loop.m:
tests/warnings/*.m:
	Remove usused interface imports, or move them into
	implementation (mostly bool, list and std_util).
1997-05-21 02:16:53 +00:00
Fergus Henderson
651108aac9 Fix a bug introduced by Zoltan's changes to delay flushing
Estimated hours taken: 16

compiler/dense_switch.m:
	Fix a bug introduced by Zoltan's changes to delay flushing
	of variables needed on backtracking.
	The bug was that it was the final code_info after a nondet
	dense_switch had not unset the top failure continuation.
	This caused the code generator to generate incorrect C code for
	the code following the dense switch: the generated C code
	clobbered the topmost redoip, rather than using a new temp frame.
	The fix was to ensure that we use the code_info from the
	end of one of the switch branches (for which we will have called
	code_info__unset_failure_cont from code_info__branch_end)
	rather than using the initial code_info and just resetting
	the live variables.

compiler/code_gen.m:
compiler/code_info.m:
compiler/disj_info.m:
compiler/ite_gen.m:
	Various minor improvements to the comments.

tests/general/space.m:
	Regression test for the above-mentioned bug.
1997-05-20 04:04:30 +00:00
Zoltan Somogyi
5279c1466f Slight rearrangement of the data structures of the code generator, to allow
Estimated hours taken: 5

Slight rearrangement of the data structures of the code generator, to allow
more flexibility in code generation. The rearrangement moves the stack_slots
information (mapping vars to their stack slots if any) and follow_vars
information (mapping vars to the location preferred for them by future code)
from code_info to code_exprn. This allows the predicates in code_exprn to
make use of this information.

As a result of these changes, the code generator now emits 110 fewer lines
of C code for the compiler (478 lines are replaced by 368). There is no
discernible impact on the memory requirements or running time of the compiler
itself.

code_exprn:
	Add the two fields to the exprn_info data structure.

	Several predicates in code_exprn now evaluate variables directly
	into their preferred location, instead of a random register.

code_info:
	Remove the two fields from the code_info data structure.
1997-05-12 07:02:54 +00:00
Zoltan Somogyi
37a4e4d8fb Fix the code that computes the module name of a predicate for use
Estimated hours taken: 0.1

code_info:
	Fix the code that computes the module name of a predicate for use
	in the marker field of the incr_sp statement of a commit code sequence.
1997-04-25 09:14:27 +00:00