Commit Graph

55 Commits

Author SHA1 Message Date
Thomas Conway
2b605fa6e8 Fix several bugs in the runtime engine to do with thread-safe execution.
Estimated hours taken: 15

Fix several bugs in the runtime engine to do with thread-safe execution.

Add a new flag to pragma c_code/import to allow programmers to specify
whether or not the C code is thread-safe or not, and modify code generation
to put a lock around C code that isn't thread_safe.

runtime/mercury_thread.{c,h}:
	Add a global lock.
	Change the handling of thread creation. create_thread now takes
	a "closure" (a C struct with a fn pointer and an argument to pass
	the function) which it calls in the new thread. (The same mechanism
	is used in the Boehm collector), or NULL which causes the thread
	to wait for work to appear in the Mercury runqueue.

runtime/mercury_context.c:
	initialize the global lock.

runtime/mercury_engine.{c,h}:
	Add a new field to the MercuryEngine structre which is used to
	store a list of saved thread ids. These were being saved in a
	local variable in call_engine_inner which was a bug because
	call_engine_inner's (C) stack frame gets scribbled on by Mercury
	execution. For more detail see the comments in mercury_engine.h

runtime/mercury_wrapper.c:
	Use the new interface to create_thread.

compiler/prog_io_pragma.m:
	Parse either a single attribute or a list of attributes instead
	of just 'may_call_mercury' in pragma c code and pragma import.
	These are stored in an abstract type 'pragma_c_code_attributes'
	that uses a bit array (aka int) to store the attributes.

compiler/pragma_c_gen.m:
	Get the code generator to emit c code to obtain and release the
	global lock for pragma c code that isn't thread_safe.

compiler/<various>.m:
	Change may_call_mercury to pragma_c_code_attributes.

doc/reference_manual.m:
	Document the change to pragma c code.

scripts/mgnuc.in:
	Pass some extra C flags for thread-safe compilation for Linux.
1998-08-07 00:50:40 +00:00
Zoltan Somogyi
d1855187e5 Implement new methods of handling failures and the end points of branched
Estimated hours taken: 260

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

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

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

	Clarify the wording in several places.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	Fix this by correctly generating labels rather than assuming
	they are local(...), and using "label" where "proc_label" was
	used before.
1998-07-15 12:21:10 +00:00
Zoltan Somogyi
4ab3f397b1 Allow the debugger to print the values of variables in ancestors
Estimated hours taken: 20

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

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

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

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

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

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

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

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

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

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

	Rename an internal pred for clarity.

	Rename some bool parameter to correctly reflect their new meaning.

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

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

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

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

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

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

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

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

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

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

tests/debugger/*
	Update half the test cases (those which assume a non-debug-grade
	library) to conform to the changes in the debugger interface.
	The others will need to be updated later.
1998-06-18 06:08:37 +00:00
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
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
Tyson Dowd
3fc8750607 Put type parameter locations into stack layouts.
Estimated hours taken: 15

Put type parameter locations into stack layouts.

compiler/code_gen.m:
	Generate typeinfos for entry and exit points.

compiler/stack_layout.m:
	Output the type parameters vector.
1998-02-10 02:04:54 +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
Tyson Dowd
51e8fd3d51 Reorganize options for accurate GC, stack tracing and execution tracing.
Estimated hours taken: 20

Reorganize options for accurate GC, stack tracing and execution tracing.
The new options are:
	--stack-trace		Turn on stack traces (incomplete, just
			 	turns on required stack layouts at the
				moment).
	--basic-stack-layout	Turns on stack layouts for each
				procedure, and (currently) each
				internal label.
	--agc-stack-layout	Turns on stack layouts for accurate gc.
				implies --basic-stack-layout.
	--trace-stack-layout	Turns on stack layouts for execution
				tracing.  Implies --basic-stack-layout.
	--alternate-liveness    Use what was previously called the
				"accurate gc" liveness calculation
				method. Execution tracing needs this too.

Add live value information (at entry and exit) for execution tracing.

compiler/call_gen.m:
compiler/handle_options.m:
compiler/live_vars.m:
compiler/liveness.m:
compiler/mercury_compile.m:
compiler/options.m:
compiler/unused_args.m:
	Use new options.
	Handle new option dependencies.

compiler/code_gen.m:
	Use new options.
	Generate live value information for entry and exit points
	if we are doing execution tracing.
	Add typeinfos to livevals(...) instruction so that value
	numbering doesn't move them.

compiler/continuation_info.m:
	Add support for collecting information on live values at entry
	and exit.
	Change the data structures to accomodate the new data collection
	needed.

compiler/stack_layout.m:
	Output tracing liveness information if needed.
	Use new options.
1998-01-25 05:06:29 +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
Zoltan Somogyi
b4813457c9 A rewrite of termination analysis to make it significantly easier to modify,
Estimated hours taken: 60

A rewrite of termination analysis to make it significantly easier to modify,
and to extend its capabilities.

compiler/error_util.m:
	A new file containing code that makes it easier to generate
	nicely formatted error messages.

compiler/termination.m:
	Updates to reflect the changes to the representation of termination
	information.

	Instead of doing pass 1 on all SCCs and then pass 2 on all SCCs,
	we now do both pass 1 and 2 on an SCC before moving on to the next.

	Do not insist that either all procedures in an SCC are
	compiler-generated or all are user-written, since this need not be
	true in the presence of user-defined equality predicates.

	Clarify the structure of the code that handles builtins and compiler
	generated predicates.

	Concentrate all the code for updating module_infos in this module.
	Previously it was scattered in several places in several files.

	Put all the code for writing out termination information at the
	end of the module in a logical order.

compiler/term_traversal.m:
	A new file containing code used by both pass 1 and pass 2 to
	traverse procedure bodies.

compiler/term_pass1.m:
	Use the new traversal module.

	Clarify the fixpoint computation on the set of output supplier
	arguments.

	Remove duplicates from the list of equations given to the solver.
	This avoids a det stack overflow in lp.m when doing termination
	analysis on options.m.

	If an output argument of a predicate makes sense only in the absence
	of errors, then return it only in the absence of errors.

compiler/term_pass2.m:
	Use the new traversal module. Unlike the previous code, this allows us
	to ignore recursive calls with input arguments bigger than the head
	if those calls occur after goals that cannot succeed (since those
	calls will never be reached).

	Implement a better way of doing single argument analysis, which
	(unlike the previous version) works in the presence of mutual recursion
	and other calls between the recursive call and the start of the clause.

	Implement a more precise way of checking for recursions that don't
	cause termination problems. We now allow calls from p to q in which
	the recursive input supplier arguments can grow, provided that on
	any path on which q can call p, directly or indirectly, the recursive
	input supplier arguments shrink by a greater amount.

	If an output argument of a predicate makes sense only in the absence
	of errors, then return it only in the absence of errors.

compiler/term_util.m:
	Updates to reflect the changes to the representation of termination
	information.

	Reorder to put related code together.

	Change the interface of several predicates to better reflect the
	way they are used.

	Add some more utility predicates.

compiler/term_errors.m:
	Small changes to the set of possible errors, and major changes in
	the way the messages are printed out (we now use error_util).

compiler/options.m:
	Change --term-single-arg from being a bool to an int option,
	whose value indicates the maximum size of an SCC in which we try
	single argument analysis. (Large SCCs can cause single-arg analysis
	to require a lot of iterations.)

	Add an (int) option that controls the max number of paths
	that we are willing to analyze (analyzing too many paths can cause
	det stack overflow).

	Add an (int) option that controls the max number of causes of
	nontermination that we print out.

compiler/hlds_pred.m:
	Use two separate slots in the proc_info to hold argument size data
	and termination info, instead of the single slot used until now.
	The two kinds of information are produced and used separately.

	Make the layout of the get and set procedures for proc_infos more
	regular, to facilitate later updates.

	The procedures proc_info_{,set_}variables did the same work as
	proc_info_{,set_}varset. To eliminate potential confusion, I
	removed the first set.

compiler/*.m:
	Change proc_info_{,set_}variables to proc_info_{,set_}varset.

compiler/hlds_out.m:
compiler/make_hlds.m:
compiler/mercury_to_mercury.m:
	Change the code to handle the arg size data and the termination
	info separately.

compiler/prog_data.m:
	Change the internal representation of termination_info pragmas to
	hold the arg size data and the termination info separately.

compiler/prog_io_pragma.m:
	Change the external representation of termination_info pragmas to
	group the arg size data together with the output supplier data,
	to which it is logically connected.

compiler/module_qual.m:
compiler/modules.m:
	Change the code to accommodate the change to the internal
	representation of termination_info pragmas.

compiler/notes/compiler_design.html:
	Fix some documentation rot, and clarify some points.

	Document termination analysis.

doc/user_guide.texi:
	Document --term-single-arg and the new options.

	Remove spaces from the ends of lines.

library/bag.m:
	Add a new predicate, bag__least_upper_bound.

	Fix code that would do the wrong thing if executed by Prolog.

	Remove spaces from the ends of lines.

library/list.m:
	Add a new predicate, list__take_upto.

library/set{,_ordlist}.m:
	Add a new predicate, set{,_ordlist}__count.

tests/term/*:
	A bunch of new test cases to test the behaviour of termination
	analysis. They are the small benchmark suite from our paper.

tests/Mmakefile:
	Enable the new test case directory.
1997-12-22 10:01:33 +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
Tyson Dowd
24954933b5 Fix some problems Fergus pointed out after reviewing my
Estimated hours taken: 1

Fix some problems Fergus pointed out after reviewing my
stack layouts change.

compiler/continuation_info.m:
	Separate library imports from compiler imports.

compiler/handle_options.m:
compiler/options.m:
	Add some comments to explain the stack_layouts option.
	Comment out the documentation of the stack-layouts option,
	as it is a developer only option.

compiler/code_gen.m:
compiler/llds.m:
compiler/llds_common.m:
compiler/llds_out.m:
compiler/mercury_compile.m:
compiler/optimize.m:
	Remove llds_proc_id from c_procedure, as pred_proc_id is
	available instead.
1997-12-10 07:15:49 +00:00
Tyson Dowd
2a97f96d1a Generate stack layouts for accurate garbage collection.
Estimated hours taken: 50

Generate stack layouts for accurate garbage collection.

compiler/base_type_layout.m:
	Change the order of some arguments so that threaded data
	structures are more often in the final two arguments (allows
	easy use of higher order predicates).
	Simplify some code using higher order preds.
	Export base_type_layout__construct_pseudo_type_info, as
	stack_layout.m needs to be able to generate pseudo_type_infos
	too.
	Fix problems with cell numbers being re-used -- get the next
	cell number from module_info, and update module_info
	after processing base_type_layouts.

compiler/code_gen.m:
	Add information about each procedure to the continuation info.
	Handle new field in c_procedure.

compiler/continuation_info.m:
	Redesign most of this module to deal with labels
	that are continuation points for multiple calls.
	Change the order of some arguments so that threaded data
	structures are in the final two arguments.
	Cleaned up and documented code.

compiler/dupelim.m:
compiler/exprn_aux.m:
	Handle new label_entry data type.

compiler/export.m:
compiler/opt_debug.m:
	Handle new label_entry and general data types.

compiler/llds_out.m:
	Add an argument to get_proc_label to control whether a
	"mercury_" prefix is wanted.
	Handle new label_entry and general data types.

compiler/llds.m:
	Add a new alternative for data_const - a label_entry.
	Add a new alternative for data_name - general, which
	allows any sort of data, with names generated elsewhere.
	Add the pred_proc_id as a field of c_procedure.

compiler/optimize.m:
compiler/llds_common.m:
compiler/optimize.m:
	Handle new field in c_procedure.

compiler/mercury_compile.m:
	Generate layout information after code has been generated,
	and output stack layouts.

compiler/notes/compiler_design.html:
	Document new stack_layout module.

compiler/stack_layout.m:
	New file - generates the LLDS code that defines
	global constants to hold the stack_layout structures.

compiler/options.m:
compiler/handle_options.m:
	Add --stack-layout option which outputs stack layouts.
	Make accurate gc imply stack_layout.
1997-11-08 13:12:08 +00:00
Fergus Henderson
6ba2ecb1cf Fix a wrong XXX comment about checking for floundering in negations
Estimated hours taken: 0.25

compiler/code_gen.m:
	Fix a wrong XXX comment about checking for floundering in negations
	(we already do that).
1997-10-11 15:42:40 +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
Zoltan Somogyi
91ca25776f This checkin is only cosmetic; it does not modify what the compiler does.
Estimated hours taken: 0.5

This checkin is only cosmetic; it does not modify what the compiler does.

code_gen:
	generate_proc_code was passed an I/O state, but used it only to
	access the globals. This change passes the globals directly,
	and dispenses with the unnecessary use of DCG notation.

mercury_compile:
	Pass the globals to generate_proc_code, not the io__state.
	Look up options in the globals directly, rather than getting them
	from the io__state.
1997-09-25 03:34:51 +00:00
Zoltan Somogyi
f4051b8155 Simplify the handling of procedure prologs and epilogs.
Estimated hours taken: 1.5

code_gen.m:
	Simplify the handling of procedure prologs and epilogs. Whereas
	we used to have separate predicates for procedures of the three code
	models, we now use one predicate for prologs for procedures of all
	code models, and another for epilogs.
1997-09-24 22:12:20 +00:00
Fergus Henderson
6963f6f611 Add an XXX comment saying that we should check for delayed
Estimated hours taken: 0.25

compiler/code_gen.m:
compiler/ite_gen.m:
library/std_util.m:
	Add an XXX comment saying that we should check for delayed
	non-linear goals in negations, if-then-else, and solutions/2.
1997-09-14 09:20:36 +00:00
Fergus Henderson
5976f769f7 Fix a bug for the case of a higher-order function call in code
Estimated hours taken: 1

Fix a bug for the case of a higher-order function call in code
with common sub-expression; mercury 0.7 failed this test, reporting
"Software Error: modecheck fails when repeated", due to confusion
between h.o. _function_ call and h.o. _predicate_ call.

compiler/hlds_goal.m:
	Add `pred_or_func' field to HLDS higher_order_calls.

compiler/modes.m:
compiler/modecheck_call.m:
compiler/hlds_out.m:
compiler/*.m:
	Add code to handle new field for higher_order_call goals.

tests/valid/Mmake:
tests/valid/ho_func_call.m:
	Regression test for the above-mentioned bug.
1997-09-01 14:05:44 +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
63ce305441 This change is part one of a group of changes to generalize the
current support for trailing.  This part just involves changing
the names from application-specific (--constraints) to more
general ones (--use-trail).

scripts/mgnuc.in:
compiler/handle_options.m:
	Rename the `*.cnstr' grades as `*.tr', and use
	`-DMR_USE_TRAIL' rather than `-DCONSTRAINTS'.

compiler/options.m:
	Rename the `--constraints' option as `--use-trail'.

compiler/code_gen.m:
compiler/disj_gen.m:
compiler/ite_gen.m:
compiler/mercury_compile.m:
	Trivial changes to handle the renaming of the `constraints'
	option as `use_trail'.
1997-08-23 13:10:47 +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
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
Fergus Henderson
e3471f333f Fix a bug in inlining of polymorphic pragma c_code procedures.
Estimated hours taken: 3

Fix a bug in inlining of polymorphic pragma c_code procedures.

The bug was that if the actual argument type has a specific type
of say `float', then the C variable for the corresponding formal
parameter will be declared to have type `Float', whereas without
inlining the argument type would have been polymorphic and so
the C variable would have been declared to have type `Word'.
Hence we need to keep track of the original argument types,
before any inlining or specialization has occurred, and use
these original argument types to determine how to declare
the C variables, rather than using the actual argument types
for this particular specialization.

compiler/hlds_goal.m:
	Add a new field to pragma_c_code goals, holding the
	original argument types (before any inlining or specialization)
	of the pragma_c_code procedure.

compiler/make_hlds.m:
	Initialize this field with the declared argument types for
	the pragma c_code procedure.

compiler/polymorphism.m:
	Update this field to account for the inserted type_info variables.

compiler/code_gen.m:
	Pass this field to pragma_c_gen.m.

compiler/pragma_c_gen.m:
	Use the original argument types field for the pragma variable
	declarations, rather than looking up the actual types of the
	arguments.

compiler/*.m:
	Trivial changes to handle new field.

compiler/live_vars.m:
	Comment out some code to avoid a warning about `fail'
	in the condition of an if-then-else.
1997-05-05 11:17:40 +00:00
Andrew Bromage
f4d3661ea6 Module qualify predicate names attached to incr_sp instructions to
Estimated hours taken: 0.5

Module qualify predicate names attached to incr_sp instructions to
improve error reporting in debug grades.

compiler/code_gen.m:
compiler/code_info.m:
compiler/middle_rec.m:
	Various minor changes to do above.
1997-04-04 04:41:13 +00:00
Andrew Bromage
d7319104f9 Making the types pred_id and proc_id (almost) abstract.
Estimated hours taken: 7

Making the types pred_id and proc_id (almost) abstract.

compiler/code_util.m:
        Changed the type of several predicates:
                code_util__make_uni_label/4 (arg 3 was int, now proc_id)
                code_util__inline_builtin/4 (arg 3 was proc_id, now int)
        Added predicate code_util__translate_builtin_2/6.

compiler/hlds_module.m:
        Moved invalid_pred_id/1 to hlds_pred.m

compiler/hlds_pred.m:
        Types pred_id/0 and proc_id are now abstract.
        Added predicates:
                hlds_pred__initial_pred_id/1, hlds_pred__initial_proc_id/1,
                hlds_pred__next_pred_id/2, hlds_pred__next_proc_id/2,
                pred_id_to_int/2, proc_id_to_int/2,
                hlds_pred__in_in_unification_proc_id/1
        Moved predicate invalid_pred_id/1 (from hlds_module.m).

compiler/*.m:
        Miscellaneous minor changes to cast pred/proc_ids to ints
        where appropriate.
1997-03-06 05:09:54 +00:00
Fergus Henderson
3ec8a17ffc Enable the code to treat `__' as an alternative syntax for module
Estimated hours taken: 8

Enable the code to treat `__' as an alternative syntax for module
qualification, after fixing various places in the compiler where
we use `__' in ways that are incompatible with this.

compiler/prog_io.m:
compiler/prog_io_goal.m:
	Uncomment the code to handle `__' as module qualification.

compiler/intermod.m:
compiler/hlds_module.m:
compiler/modecheck_unify.m:
	Fix bugs in the handling of module qualified higher-order terms.

compiler/*.m:
	s/hlds__/hlds_/g

compiler/passes_aux.m:
	s/process__/process_/g

compiler/pragma_c_gen.m:
compiler/code_gen.m:
	s/code_gen__/pragma_c_gen__/ for the predicates defined in
	pragma_c_gen.m (this ought to have been done when the code
	was first moved from code_gen.m to pragma_c_gen.m).

compiler/llds.m:
	s/llds__proc_id/llds_proc_id/g
	The reason for this was to avoid ambiguity between proc_id
	in hlds_pred.m and llds__proc_id in llds.m.

compiler/quantification.m:
compiler/make_hlds.m:
compiler/mercury_to_c.m:
	s/goal_vars/quantification__goal_vars/g
	The reason for this was to avoid ambiguity between goal_vars
	in quantification.m and goal_util__goal_vars in goal_util.m.

compiler/dupelim.m:
compiler/optimize.m:
	s/dupelim__main/dupelim_main/g
	The reason for this change is that a program can only
	have one main/2 predicate.

compiler/prog_io_dcg.m:
	Remove the old "temporary hack" to strip off and ignore
	io__gc_call/1, since the new handling of `__' broke it.
	It was only useful for optimizing NU-Prolog performance,
	which we don't care about anymore.

compiler/mercury_compile.m:
compiler/modules.m:
compiler/intermod.m:
compiler/prog_io.m:
	Remove occurrences of io__gc_call.

compiler/llds_out.m:
compiler/base_type_info.m:
	Ensure that we properly handle the special hacks in mercury_builtin
	where predicates from other modules (e.g. term__context_init)
	are defined in mercury_builtin because they are needed for
	type_to_term and term_to_type.  llds_out.m: don't put
	`mercury_builtin' in the mangled names for those symbols.
	base_type_info.m: handle types whose status is "imported"
	in their own module.
1997-02-23 06:08:34 +00:00
Zoltan Somogyi
91c4330db7 The first half of a change to introduce nondet pragma C goals.
Estimated hours taken: 12

The first half of a change to introduce nondet pragma C goals.
This half makes the necessary modifications to the HLDS; the next
half will modify the LLDS and emit it.

prog_data:
	Add a new pragma type for nondet pragma c_codes; these specify
	the names of a a bunch of variables to save across backtracking,
	and a list of label names to which backtracking may take place.

	Rename is_recursive to may_call_mercury, since this is a more
	direct expression of the meaning.

prog_io:
	Move much of the functionality to new files.

prog_io_dcg, prog_io_goal, prog_io_pragma, prog_io_util:
	New files, made up of pieces of prog_io.

hlds_goal:
	Add an extra argument to the pragma_c_goals to store the extra
	information present in the new type of pragma c_codes.

det_analysis:
	Take into account that the new type of pragma_c goal may have
	more than one solution.

goal_util:
	Rename variables in the new field of pragma_cs.

live_vars:
	Allocate stack slots to the saved variables in the new type of pragma_c
	goals.

make_hlds:
	Handle the new type of pragma_c goals.

mercury_output, hlds_out:
	Output the new type of pragma_c goals.

garbage_out:
	Rename type "det" to "frame_type".

others:
	Ignore one more arg of pragma_c goals or import prog_io_util.
1997-01-27 07:45:40 +00:00
Fergus Henderson
5a75f60622 Fix the numerous gcc warnings about "type mismatch with previous
Estimated hours taken: 10

Fix the numerous gcc warnings about "type mismatch with previous
external decl" caused by nested "extern const struct ..." declarations
with incomplete struct types.  (If we're lucky, this change might also
work around the recent problems with gcc getting segmentation faults
(fatal signal 11)).

llds_out.m:
	Output all declarations at global scope rather than in
	locally nested scopes.

module_info.m:
	Add a new cell_count field.
	This is in module_info as well as in code_info since cell
	numbers need to be unique within each module, not just unique
	within each predicate.

code_info.m:
	Add cell_count as a new parameter to code_info_init.
	Make sure that cell_count is not clobbered by slap_code_info.

code_gen.m, mercury_compile.m:
	Thread the cell_count from the module_info through code_info
	and back, to ensure that cell numbers are unique within
	a module.
1997-01-16 16:35:52 +00:00
Zoltan Somogyi
06555906d4 Rewrite the submodule for handling stack slots: instead of a stack
Estimated hours taken: 3

code_info:
	Rewrite the submodule for handling stack slots: instead of a stack
	of temporary values, we now use a set. This removes the requirement
	for doing allocations and deallocations in LIFO order.

	Change the handling of the detstack slots used for performing commits
	in model_non procedures. The old way was computing the wrong liveinfo
	set for use by the accurate garbage collector for all calls inside
	two or more commits in such procedures.

code_gen:
	Pass some data between generate_pre_commit and generate_commit calls,
	since we can no longer rely on the stack top to carry this info.
1997-01-08 07:52:43 +00:00
Zoltan Somogyi
54bb1c4a67 Move the code that generates code for pragma_c_codes to a new module.
Estimated hours taken: 3

code_gen, pragma_c_code:
	Move the code that generates code for pragma_c_codes to a new module.

llds:
	Change the representation of reg and temp lvals, in order to create
	the concept of a "register type" and to reduce memory requirements.

	Also add a comment indicating a possible future extension dealing with
	model_non pragma_c_codes.

code_exprn, code_info:
	Add the ability to request registers of a given type, or a specific
	register, when acquiring registers.

bytecode, bytecode_gen, call_gen, dupelim, exprn_aux, follow_vars, frameopt,
garbage_out, jumpopt, llds_out, middle_rec, opt_debug, opt_util, store_alloc,
string_switch, tag_switch, unify_gen, vn_block, vn_cost, vn_filter, vn_flush,
vn_order, vn_temploc, vn_type, vn_util, vn_verify:
	Small changes to accommodate the new register representation.

hlds_goal:
	Add a comment indicating a possible future extension dealing with
	model_non pragma_c_codes.

inlining:
	Add a comment indicating a how to deal with a possible future extension
	dealing with model_non pragma_c_codes.
1996-12-31 09:58:59 +00:00
Zoltan Somogyi
f23324f5fa This change fixes two bugs, in quantification and liveness.
Estimated hours taken: 10

This change fixes two bugs, in quantification and liveness. I made the changes
to the other files while trying to find them; they ought to be useful in
trying to find similar bugs in the future.

The compiler now bootstraps with agressive inlining enabled.

quantification:
	Fix a bug that switched two different accumulators of the same type
	when processing pragma_c_codes.

liveness:
	Fix a bug that could cause a variable to end up in both the post-death
	and post-birth set of the same goal.

options:
	Reenable inlining.

hlds_out, mercury_to_mercury:
	If -D v is given, include the number of each variable at the end of
	its name (e.g. Varname_20).

	The predicates involved (a few from mercury_to_mercury and many from
	hlds_out) now have an extra argument that says whether this should be
	done or not. (It is not done when printing clauses e.g. for .opt
	files.)

	The bug in quantification was causing the improper substitution of
	one variable for another, but both had the same name; such bugs would
	be very difficult to find without this change.

constraint, det_report, intermod, make_hlds, mercury_to_c, mode_debug,
mode_errors, module_qual, typecheck:
	Call predicates in hlds_out or mercury_to_mercury with the extra
	argument.

saved_vars:
	Thread the io__state through this module to allow debugging.

mercury_compile:
	Call saved_vars via its new interface.

	Fix an inadvertent use of an out-of-date ModuleInfo.

goal_util, hlds_goal:
	Minor formatting cleanup.

code_gen:
	Clean up the import sequence.
1996-12-30 11:31:17 +00:00
Zoltan Somogyi
bc97676d98 Change the definition of is_builtin to use less space.
Estimated hours taken: 2

hlds_goal:
	Change the definition of is_builtin to use less space.

bytecode_gen, code_aux, code_gen, code_util, dependency_graph, follow_code,
higher_order, inlining, live_vars, make_hlds, modecheck_unify, modes,
polymorphism, stratify, unused_args:
	Fixes to accommodate the change to is_builtin.
1996-12-24 02:42:21 +00:00
Zoltan Somogyi
5544174d7c An overhaul of the code saving and restoring heap pointers and tickets,
Estimated hours taken: 3

An overhaul of the code saving and restoring heap pointers and tickets,
and some other changes that affect the interface of code_info.

code_info:
	The predicates that handle save heap pointers and tickets now return
	the slot these things are stored in; the predicates that restore
	and/or discard these values must give them back. This should avoid
	the problem we used to have with the same slot being used to store
	both a heap pointer and a ticket.

	Rename some predicates to better reflect their purpose.

	Accept pre_ and post_goal_update preds and the type lookup preds from
	code_aux, since this is where they belong.

code_aux:
	Move pre_ and post_goal_update preds and the type lookup preds to
	code_info, since that is where they belong.

call_gen:
	Fix the bug that broke nondet tailcalls for the case when the tailcall
	is a higher order call.

code_gen:
	Use the new way of saving and restoring heap pointers. We now save
	tickets across negations; the absence of code to do this was a bug.

disj_gen:
	Use the new way of saving and restoring heap pointers and tickets.
	Avoid restoring anything in the first disjunct. In pruned disjunctions,
	avoid saving the heap pointer more than once. (This does mean that
	we may restore it in some cases were we didn't used to, but such cases
	can be expected to be quite rare.)

ite_gen:
	Use the new way of saving and restoring heap pointers and tickets.

dense_switch, lookup_switch, middle_rec, unify_gen:
	Rename some called predicates as required by the changes to the
	other modules.
1996-12-22 06:37:44 +00:00
Zoltan Somogyi
21a6cafa40 Restructure into several submodules to give the module logical
Estimated hours taken: 3

code_info:
	Restructure into several submodules to give the module logical
	structure. Make very slight alterations in the interface.

call_gen, code_gen:
	Use the new interface of code_info.

code_aux:
	Add comments.

code_util:
	Fix a bug caught by Fergus' review.

disj_gen, ite_gen, liveness:
	Fix some comments.
1996-12-20 08:11:00 +00:00
Zoltan Somogyi
3243dbe238 The only significant change in this checkin is that liveness.m now
Estimated hours taken: 0.5

The only significant change in this checkin is that liveness.m now
tries to compute the best resume_locs for negations (it already did
for if-then-elses and disjunctions; leaving out negations was an
oversight in my earlier checkin).

The other changes are only syntactic:

I have removed the cont-lives and nondet-lives field from goal_info,
since they are not used anymore.

I have replaced the nondet-lives field in code_info, which is not used
anymore, with a follow-vars field, which is not used yet (but will be).

Some of the "read" access predicates in hlds_goal did not have "get" in
their name; I added them.
1996-12-18 11:09:52 +00:00
Zoltan Somogyi
08a5f48e2c Take the code generator a big step closer to notes/ALLOCATION.
Estimated hours taken: _____

Take the code generator a big step closer to notes/ALLOCATION.
The new code generator emits code that is smaller and faster than
the code we used to emit.

Nondet liveness is no longer used; nondet live sets are always empty.
In code that was being modified anyway, remove its handling. Other
uses will be removed later (this keeps this change from being far too big;
as it is it is merely too big). Similarly for cont-lives.

In several places, clarify the code that gathers several code pieces together.

call_gen:
	Unset the failure continuation and flush the resume vars to
	their stack slots before nondet calls.

	Move the code that decides whether a nondet call can be a tailcall
	to code_info.

code_aux:
	Remove the code to handle resume points, since these are now
	handled in the specific constructs that need them. Replace it
	with a sanity check.

code_exprn:
	Add a predicate to place multiple vars.

code_gen:
	Remove the predicate code_gen__generate_forced_goal, since it
	packaged together some operations that should be executed at different
	times.

	Don't unset the failure continuation after every nondet goal;
	this is now done in the constructs that need it.

	Modify the handling of negation to use resume point info
	according to notes/ALLOCATION.

	Remove the predicate code_gen__ensure_vars_are_saved which was
	use to save all lives variables to the stack before nondet
	disjunctions and if-then-elses; we don't do that anymore.

code_info:
	Significantly simplify and document the handling of failure
	continuations, and make the types involved abstract types.

	Factor out common code in the handling of det and semi commits.

	Keep track of "zombies", variables that are dead wrt forward
	execution but whose values we need because they may be needed
	at a resume point we can reach.

	Remove several now unneeded predicates, and introduce new
	predicates to help other modules.

code_util:
	Add a couple of predicates to check whether ia goal cannot fail before
	flushing all variables to the stack, and whether a goal cannot flush
	any variables to the stack. These are used in liveness to decide
	which entry labels will be needed at resume points.

disj_gen:
	Unify the handling of det and semi disjunctions. Model the code
	handling of nondet disjunctions on the code handling pruned
	disjunctions. It is possible that the handling of nondet and pruned
	disjunctions can also be unified; the new code should make this
	significantly easier.

	Make the code conform to notes/ALLOCATION. This means saving
	only the variables mentioned in the resume_point field, not
	flushing all live variables to the stack at the start of a
	nondet disjunction, handling zombies, and using the new method
	of flushing variables at the ends of branched structures.

ite_gen:
	Unify the handling of det and semi if-then-elses. Model the code
	handling of nondet if-then-elses on the code handling det/semi
	if-then-elses. It is possible that the handling of nondet and pruned
	if-then-elses can also be unified; the new code should make this
	significantly easier.

	Make the code conform to notes/ALLOCATION. This means saving
	only the variables mentioned in the resume_point field, not
	flushing all live variables to the stack at the start of a
	nondet if-then-else, handling zombies, and using the new method
	of flushing variables at the ends of branched structures.

	Apply the new rules about liveness in if-then-elses, which say that
	the else part is parallel not to the then part but to the conjunction
	of the condition and the then part.

dense_switch, lookup_switch, string_switch, switch_gen, tag_switch, middle_rec:
	Use the new method of flushing variables at the ends of branched
	structures. Don't call remake_with_store map; switch_gen will do so.

	Fix an old bug in lookup_switch.

	The code in switch_gen which looked for the special case of a two-way
	switch used to use a heuristic to decide which one was recursive and
	which one was a base case. We now check the codes of the cases.

hlds_goal:
	Adjust the structure of the resume_point field to make it easier
	to use. Add a more convenient access predicate.

hlds_out:
	Don't print the nondet liveness and cont live fields, since they are
	not used anymore. Comment out the printing of the context field,
	which is rarely useful. Modify the printing of the resume_point field
	to conform to its new definition.

live_vars:
	Use the resume_point field, not the nondetlives field, to decide
	which variables may be needed on backward execution. Remove some
	code copied from liveness.m.

liveness:
	Put the several pieces of information we thread through the traversal
	predicates into a single tuple.

	Don't put variables which are local to one branch of a branched
	structure into the post-birth sets of other branches.

	Apply the new rules about liveness in if-then-elses, which say that
	the else part is parallel not to the then part but to the conjunction
	of the condition and the then part. Variables that are needed in the
	else part but not in the condition or the then part now die in at the
	start of the condition (they will be protected by the resume point on
	the condition).

	We now treat pruned and non-pruned disjunctions the same way
	wrt deadness; the old way was too conservative (it had to be).

	We still mishandle branches which produce some variables but
	can't succeed.

mercury_compile:
	Liveness now prints its own progress message with -V; support this.

store_alloc:
	When figuring out what variables need to be saved across calls,
	make sure that we put in interference arcs between those variables
	and those that are required by enclosing resume points.

	Don't compute cont-lives, since they are not used anymore.

livemap:
	Fix the starting comment.
1996-12-18 08:56:10 +00:00
Zoltan Somogyi
b72a942944 Start using resume_point information to save variables to their
Estimated hours taken: 3

code_aux, code_info:
	Start using resume_point information to save variables to their
	stack slots when they become forward dead.

code_gen, middle_rec:
	Handle the code fragments that can now result from pre and post
	goal updates.

live_vars:
	Make sure that variables that can be put into stack slots at
	resumption points get stack slots allocated to them.

liveness:
	Fix a bug in the computation of resume_point sets.

llds_common:
	Fix some comments.
1996-11-25 10:07:59 +00:00
Zoltan Somogyi
584e402c33 Another step towards implementing notes/ALLOCATION.
Estimated hours taken: 6

Another step towards implementing notes/ALLOCATION.

hlds_goal:
	Define a new type that gives the information associated with
	resumption points. Add a field of this type to goal_info, and the
	associated operations.

	Change the layout of the access predicates to make the code_info
	structure easier to modify in the future.

liveness:
	Fill in the resume_point fields of goals that establish
	resumption points.

hlds_out:
	Print the new resume_point field of goal_info.

	Allow the printing of base_type_infos on the right hand sides
	of unifications.

code_info:
	Reuse the stack of store maps field, which we don't use anymore,
	to store the stack of resumption-point variable sets. Add operations
	on this new stack.

	Remove the slot that holds the code model of the current procedure,
	since it is used rarely and can be easily looked up in the proc_info,
	which we also store. Reuse the slot to store the maximum number of
	stack pushes, eliminating the pair used to store it previously.

	Change the layout of the access predicates to make the code_info
	structure easier to modify in the future.

code_gen:
	Don't pass the code model to code_info__init.

code_exprn:
	Make an abort message more specific.

hlds_pred:
	Fix typos.
1996-11-25 00:27:43 +00:00
Zoltan Somogyi
ee24e66a71 Switch from using a stack of store_maps in the code_info to govern what
Estimated hours taken: 2.5

Switch from using a stack of store_maps in the code_info to govern what
goes where at the end of each branched structure to using the store map
fields of the goal expressions of those structures.

Fix variable names where they resembled the wrong kind of map(var, lval).

code_info:
	Remove the operations on stacks of store maps.
	Modify the generate_forced_saves and remake_with_store_map operations
	to take a store_map parameter.

	When making variables magically live, pick random unused variables
	to hold them, since we can no longer use the guidance of the top
	store map stack entry. This may lead to the generation of some
	excess move instructions at non-reachable points in the code;
	this will be fixed later.

code_gen:
	Remove the store map push and pop invocations.
	Modify the generate_forced_goal operation to take a store_map parameter.

code_exprn:
	Export a predicate for use by code_info.

middle_rec, disj_gen, ite_gen, switch_gen,
dense_switch, lookup_switch, string_switch, tag_switch:
	Pass the store map around to get it to invocations of the primitives
	in code_gen and code_info that now need it.

goal_util:
	Name apart the new follow_vars field in hlds__goal_infos.
	(This should have been in the change that introduced that field.)

common, constraint, cse_detection, det_analysis, dnf, excess, follow_code,
intermod, lambda, lco, liveness, make_hlds, mode_util, modes, polymorphism,
quantification, simplify, switch_detection, typecheck, unique_modes,
unused_args:
	Fix variable names.

follow_vars, store_alloc:
	Add comments.
1996-11-23 10:39:02 +00:00
Zoltan Somogyi
f8da25795a Documented the distinction between the three kinds of uses we have
Estimated hours taken: 3

hlds_goal:
	Documented the distinction between the three kinds of uses we have
	for map(var, lval): stack_slots, store_map and follow_vars.
	Added a new field, follow_vars, to hlds__goal_info.

follow_vars:
	Attach the follow_vars information to the kinds of goals listed
	in notes/ALLOCATION.

hlds_out:
	Print out the follow_vars field. Make some other outputs easier to
	read.

hlds_pred:
	Remove the follow_vars field of the proc_info, since the follow_vars
	of the goal_info of the goal of the procedure has taken its place.

code_gen:
	Use the follow_vars field from the main goal's goal_info, rather
	than the follow_vars field of the proc_info.

store_alloc:
	Attach the last follow_vars not to the proc_info but to the main goal.
1996-11-23 06:01:49 +00:00
Zoltan Somogyi
92bd26cdc8 The first step towards the implementation of the new ALLOCATION strategy:
Estimated hours taken: 0.75

The first step towards the implementation of the new ALLOCATION strategy:
renamed call_info to stack_slots.

There are no algorithmic changes in this checkin.
1996-11-21 09:25:34 +00:00