Commit Graph

161 Commits

Author SHA1 Message Date
Peter Wang
898534b36d Restore low-level debugging to working state.
Estimated hours taken: 0.5
Branches: main

Restore low-level debugging to working state.

runtime/mercury_conf_param.h:
	Fix typos.

runtime/mercury_overflow.h:
runtime/mercury_wrapper.c:
	Update references to outdated field names.
2006-03-20 23:43:17 +00:00
Julien Fischer
4123f78ae6 Avoid a warning about deprecated lvalue casts in high level C nogc
Estimated hours taken: 0.1
Branches: main

runtime/mercury_wrapper.c:
	Avoid a warning about deprecated lvalue casts in high level C nogc
	grades.
2006-03-02 11:09:42 +00:00
Julien Fischer
9d8ca0ad37 Remove residual parts of the Aditi backend that weren't deleted the other day.
Estimated hours taken: 1.5
Branches: main

Remove residual parts of the Aditi backend that weren't deleted the other day.

configure.in:
Mmake.common.in:
	Remove support for enabling the Aditi backend.

runtime/mercury_aditi.h:
	Remove this file.

runtime/Mmakefile:
runtime/mercury.h:
runtime/mercury_imp.h:
runtime/mercury_ho_call.[ch]:
runtime/mercury_wrapper.[ch]:
	Delete support for Aditi in the runtime.

scripts/Mmake.rules:
scripts/Mmake.vars.in:
scripts/c2init.in:
scripts/parse_ml_options.sh-subr.in:
	Remove mmake support for building .rlo files, etc.

util/mkinit.c:
	Remove Aditi specific code.

compiler/bytecode_data.m:
compiler/closure_analysis.m:
compiler/code_model.m:
compiler/compile_target_code.m:
compiler/det_analysis.m:
compiler/handle_options.m:
compiler/hlds_goal.m:
compiler/hlds_module.m:
compiler/make.dependencies.m:
compiler/make.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make.util.m:
compiler/make_hlds_error.m:
compiler/make_hlds_passes.m:
compiler/mercury_to_mercury.m:
compiler/mlds_to_gcc.m:
compiler/modecheck_call.m:
compiler/modules.m:
compiler/opt_debug.m:
compiler/options.m:
compiler/prog_data.m:
compiler/prog_foreign.m:
compiler/prog_mode.m:
compiler/prog_type.m:
compiler/rtti.m:
compiler/rtti_out.m:
compiler/rtti_to_mlds.m:
compiler/term_errors.m:
compiler/unify_proc.m:
mdbcomp/prim_data.m:
	Remove residual support for Aditi.

library/ops.m:
	Remove the 'aditi_bottom_up' and 'aditi_top_down' operators from the
	ops table.

doc/reference_manual.texi:
doc/user_guide.texi:
	Delete the sections on the Aditi interface.

extras/aditi/*:
	Delete this.
2006-02-24 07:11:21 +00:00
Zoltan Somogyi
17eb414a8f Add a new mdb command "ambiguity" that prints out ambiguous predicate, function
Estimated hours taken: 3
Branches: main

Add a new mdb command "ambiguity" that prints out ambiguous predicate, function
and type names.

doc/user_guide.texi:
	Document the new command.

doc/mdb_categories:
	Add the new command, as well as some others that should have been added
	previously but weren't.

trace/mercury_trace_internal.c:
	Add the user interface for the new command.

	Fix some old cut-and-paste bugs.

trace/mercury_trace_tables.[ch]:
	Add the implementation of the new command.

runtime/mercury_type_tables.[ch]:
	Change the signature of the function that return the list of all
	type_ctor_infos to also return their number, for use in the new code
	in mercury_trace_tables.c.

	Convert to four-space indentation.

runtime/mercury_layout_util.c:
runtime/mercury_wrapper.c:
	Convert to four-space indentation.

tests/debugger/completion.exp:
tests/debugger/mdb_command_test.inp:
	Expect the mdb command added by this diff, as well as the ones added
	by Ralph recently.
2005-10-25 04:00:56 +00:00
Julien Fischer
570f2aa3c5 Update the documentation to reflect the fact that mlds_to_c.m
Estimated hours taken: 0.4
Branches: main

util/mkinit.c:
	Update the documentation to reflect the fact that mlds_to_c.m
	also generates ENDINIT comments.

	Fix a typo.

README.MinGW:
library/io.m:
library/store.m:
runtime/mercury.h:
runtime/mercry_wrapper.c:
runtime/mercury_goto.h:
	Fix some typos.
2005-10-11 04:45:52 +00:00
Julien Fischer
f57fe1b7df Add language and compiler support for finalise declarations.
Estimated hours taken: 8
Branches: main

Add language and compiler support for finalise declarations.

NEWS:
	Mention finalise declarations.

compiler/prog_data.m:
	Add a new item type for finalise declarations.

	Add a new kind of item origin - items can now be introduced as part of
	the source-to-source transformation that implements finalise
	declarations.

compiler/prog_io.m:
	Parse finalise declarations.

compiler/modules.m:
	Don't write out finalise declarations in private interfaces.

compiler/hlds_module.m:
	Add a slot to the HLDS that stores the names of the predicates in
	finalise declarations.

	Add access predicates for the above.

compiler/add_pragma.m:
compiler/make_hlds_passes.m:
	Fix in incorrect comment: we add initialise declarations on third, not
	second, pass.

	Restore the code that use the enhanced switch detection capability.

	Implement the source-to-source transformation that implements finalise
	declarations.  This is almost identical to that for intitialise
	declarations.

compiler/llds.m:
compiler/llds_out.m:
compiler/transform_llds.m:
	Add a slot to the LLDS to hold the name of the predicates specified in
	the finalise declarations.

	Emit the necessary code to call these predicates after main has finished.

compiler/mlds.m:
compiler/ml_code_gen.m:
compiler/ml_elim_nested.m:
compiler/ml_optimize.m:
compiler/ml_tailcall.m:
compiler/mlds_to_c.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_il.m:
compiler/mlds_to_ilasm.m:
compiler/mlds_to_java.m:
compiler/mlds_to_managed.m:
	As above, but for the MLDS.

compiler/mercury_compile.m:
	Conform to changes in the MLDS.
	XXX This module probably shouldn't manipulating the MLDS directly.

compiler/module_qual.m:
compiler/mercury_to_mercury.m:
compiler/recompilation.check.m:
compiler/recompilation.version.m:
	Conform to the above changes.

library/ops.m:
	Add `finalise' as an operator.

runtime/mercury_wrapper.c:
	Call any user specified finalise predicates from
	mercury_runtime_terminate.

doc/reference_manual.texi:
	Document finalise declarations.

tests/hard_coded/Mmakefile:
tests/hard_coded/finalise_decl.m:
tests/hard_coded/finalise_decl.exp:
	Tests finalise declarations.

tests/hard_coded/sub-modules/Mmakefile:
tests/hard_coded/sub-modules/finalise_child.m:
tests/hard_coded/sub-modules/finalise_parent.m:
tests/hard_coded/sub-modules/finalise_parent.{exp,exp2}:
	Test finalise declarations and sub-modules.  There are two expected
	outputs because the order of execution between a parent module and its
	children of any finalisers is arbitrary.

tests/invalid/Mmakefile:
tests/invalid/bad_finalise_decl.m:
tests/invalid/bad_finalise_decl.err_exp:
	Test error messages associated with finalise declarations.
2005-09-29 06:33:17 +00:00
Julien Fischer
29c44a3e93 Add the initial stage of finalise declarations.
Estimated hours taken: 2
Branches: main

Add the initial stage of finalise declarations.  These are a counterpart
to the recently added intialise declarations; they allow the user to specify
predicates that are to be run after main/2 exits.

util/mkinit.c:
	Add support for `REQUIRED_FINAL' directives.  These are similar to
	`REQUIRED_INIT' directives except that the specified functions are
	run after main/2.  Any functions specified using this directive are
	gathered into bunches and called from the final_module_required
	function.

runtime/mercury_wrapper.h:
runtime/mercury_wrapper.c:
	Export a new global that points to the final_module_required function
	for the program.
2005-09-28 06:00:58 +00:00
Zoltan Somogyi
99293279e6 This is step 1 of eliminating the arguments of the type_ctor_info, type_info,
Estimated hours taken: 8
Branches: main

This is step 1 of eliminating the arguments of the type_ctor_info, type_info,
base_typeclass_info and typeclass_info type constructors. This step doesn't
delete those arity-1 type constructors yet; that will be done in step 2.
This delay due to bootstrapping issues: installed compilers still generate
references to those type constructors. However, after this change, compilers
will instead generate references to arity-0 versions of those types named
zero_type_ctor_info, zero_type_info, zero_base_typeclass_info and
zero_typeclass_info.

library/private_builtin.m:
	Add the new type constructors.

	For each predicate that operates on the old arity-1 type constructors,
	add a version that operates on the new type arity-0 onstructors,
	and whose implementation is identical.

runtime/mercury_builtin_types.m:
	Add the unify and compare predicates of the new type constructors.

runtime/mercury_wrapper.[ch]:
runtime/mercury_init.h:
util/mkinit.c:
	Change the C type of the variable that holds the types of type_infos
	and pseudo_type_infos, since their representation is now simpler
	(no dummy argument).

trace/mercury_trace_vars.c:
	Modify data structures that recognize the four old types to recognize
	their new variants as well.

compiler/higher_order.m:
compiler/polymorphism.m:
	Generate references to the new versions of predicates that manipulate
	type_infos and typeclass_infos.

compiler/hlds_pred.m:
compiler/ml_code_util.m:
compiler/type_ctor_info.m:
	Modify predicates that recognize the four old types to recognize their
	new variants as well.

compiler/type_util.m:
	Modify the predicates that construct the types of type_infos
	to create references to the new arity-0 type constructors.

	Modify predicates that recognize the four old types to recognize their
	new variants as well.

	Delete the predicate whose job was to replace the dummy arguments
	of the arity-1 type constructors with the void type, since it is not
	needed anymore.

	Delete the unused predicate cell_type_name.

compiler/stack_layout.m:
	Fix comment.

compiler/size_prof.m:
	Conform to the changes in type_util.

compiler/pseudo_type_info.m:
	Conform to the changes in type_util.

	Convert to four-space indentation.
2005-09-19 07:26:38 +00:00
Zoltan Somogyi
1ed891b7b1 Introduce a mechanism for extending the det and nondet stacks when needed.
Estimated hours taken: 24
Branches: main

Introduce a mechanism for extending the det and nondet stacks when needed.
The mechanism takes the form of a new grade component, .exts ("extend stacks").

While the new mechanism may be useful in its own right, it is intended mainly
to support a new implementation of minimal model tabling, which will use a
separate Mercury context for each distinct subgoal. Each context has its own
det and nondet stack. Clearly, we can't have hundreds of contexts each with
megabyte sized det stacks. The intention is that the stacks of the subgoals
will start small, and be expanded when needed.

The runtime expansion of stacks doesn't work yet, but it is unnecessarily
hard to debug without an installed compiler that understands the new grade
component, which is why this diff will be committed before that is fixed.

compiler/handle_options.m:
compiler/options.m:
runtime/mercury_grade.h:
scripts/canonical_grade.sh-subr
scripts/init_grade_options.sh-subr
scripts/parse_grade_options.sh-subr
scripts/mgnuc.in
	Handle the new grade component.

runtime/mercury_memory_zones.h:
	Add MR_ prefixes to the names of the fields of the zone structure.

	Record not just the actual size of each zone, which includes various
	kinds of buffers, but also the desired size of the zone exclusive of
	buffers.

	Format the documentation of the zone structure fields more
	comprehensibly.

runtime/mercury_memory_zones.c:
	Instead of implementing memalign if it is not provided by the operating
	system, implement a function that allows us to reallocate the returned
	area of memory.

	Provide a prototype implementation of memory zone extension. It doesn't
	work yet.

	Factor out the code for setting up redzones, since it is now needed
	in more than place.

	Convert to four space indentation.

	Make the debugging functions a bit more flexible.

runtime/mercury_wrapper.c:
	Conform to the improved interface of the debugging functions.

runtime/mercury_overflow.h:
runtime/mercury_std.h:
	Move a generally useful macro from mercury_overflow.h to mercury_std.h.

runtime/mercury_stacks.c:
	Add functions to extend the stacks.

runtime/mercury_stacks.h:
	Add the tests required to invoke the functions that extend the stacks.

	Add the macros needed by the change to compiler/llds.m.

	Convert to four space indentation.

runtime/mercury_conf.h.in:
	Prepare for the use of the posix_memalign function, which is the
	current replacement of the obsolete memalign library function.
	We don't yet use it.

runtime/mercury_context.h:
	Format the documentation of the context structure fields more
	comprehensibly.

	Put MR_ prefixes on the names of the fields of some structures
	that didn't previously have them.

	Conform to the new names of the fields of the zone structure.

runtime/mercury_context.c:
runtime/mercury_debug.c:
runtime/mercury_deep_copy.c:
runtime/mercury_engine.c:
runtime/mercury_memory_handlers.c:
library/benchmarking.m:
library/exception.m:
	Conform to the new names of the fields of the zone structure.

	In some cases, add missing MR_ prefixes to function names
	and/or convert to four space indentation.

runtime/mercury_engine.h:
	Add a new low level debug flag for debugging stack extensions.

	Format the documentation of the engine structure fields more
	comprehensibly.

	Convert to four space indentation.

runtime/mercury_conf_param.h:
	Document a new low level debug flag for debugging stack extensions.

compiler/compile_target_code.m:
compiler/handle_options.m:
compiler/options.m:
	Handle the new grade component.

compiler/llds.m:
	Add two new kinds of LLDS instructions, save_maxfr and restore_maxfr.
	These are needed because the nondet stack may be relocated between
	saving and the restoring of maxfr, and the saved maxfr may point to
	the old stack. In .exts grades, these instructions will save not a
	pointer but the offset of maxfr from the start of the nondet stack,
	since offsets are not affected by the movement of the nondet stack.

compiler/code_info.m:
	Use the new instructions where relevant. (Some more work may be
	needed on this score; the relevant places are marked with XXX.)

compiler/dupelim.m:
compiler/dupproc.m:
compiler/exprn_aux.m:
compiler/jumpopt.m:
compiler/livemap.m:
compiler/llds_out.m:
compiler/middle_rec.m:
compiler/opt_debug.m:
compiler/opt_util.m:
compiler/reassign.m:
compiler/use_local_vars.m:
	Handle the new LLDS instructions.

tools/bootcheck:
	Provide a mechanism for setting the initial stack sizes for a
	bootcheck.
2005-09-13 08:25:44 +00:00
Mark Brown
28715a17c5 Make the default sizes of memory zones proportional to the word size.
Estimated hours taken: 1
Branches: main

Make the default sizes of memory zones proportional to the word size.  None
of the default sizes change on a 32-bit architecture.

The rationale for this is that the amount of memory used by a Mercury program
for a given input is generally proportional to the word size.  Therefore,
before this change, a program that works on a 32-bit machine may overflow one
of the memory zones on a 64-bit machine unless special precautions are taken.
(In particular, the compiler cannot be bootchecked in asm_fast.gc.tr.debug
on a 64-bit machine without such a change.)

Add variants of size-setting options in the MERCURY_OPTIONS environment
variable that take kilo-words as the units.

runtime/mercury_wrapper.c:
	Modify the defaults and parse the new options.

	Add a comment that says the user guide should be updated if the
	defaults change.

doc/user_guide.texi:
	Update the documentation corresponding to this.  Also, fix some
	out-of-date numbers.
2005-09-01 12:04:35 +00:00
Zoltan Somogyi
5b105a0968 Optimize higher order calls by providing variants of the relevant code that
Estimated hours taken: 6
Branches: main

Optimize higher order calls by providing variants of the relevant code that
are specialized to a given number of explicitly given arguments.

runtime/mercury_ho_call.[ch]:
	Define variants of do_call_closure and do_call_class_method
	specialized to 0, 1, 2 or 3 explicit input arguments. Apart from
	not needing to be passed the number of explicit input arguments
	in a register, these avoid some runtime tests and unroll loops.

	Harmonize the variable names used in the do_call_closure and
	do_call_class_method variants. Since they are near-copies of each
	other, factor out their documentation. (Factoring out the code itself
	would be possible, but would not make maintenance easier and would make
	the code harder to read.)

	Provide a mechanism to gather statistics about the numbers of hidden
	and explicit arguments if the macro MR_DO_CALL_STATS is set.

compiler/options.m:
	Add options that specify how many of these variants exist. These
	provide the necessary synchronization between the runtime and the
	compiler. They are not meant to be set from the command line, even by
	implementors.

runtime/mercury_conf_params.h:
	Document MR_DO_CALL_STATS.

runtime/mercury_wrapper.c:
	If MR_DO_CALL_STATS is set, print the gathered statistics when
	execution ends.

runtime/mecury_mm_own_stack.c:
	Fix a typo that prevented the stage2 library from linking in jump.gc
	grade.

compiler/llds.m:
	Provide a way to represent the labels of the new specialized variants.

compiler/llds__out.m:
	Output the labels of the new specialized variants if required.

	Convert to four-space indentation.

compiler/call_gen.m:
	Call the specialized variants of do_call_closure or
	do_call_class_method if they are applicable.

code_info/follow_vars.m:
code_info/interval.m:
code_info/tupling.m:
	Conform to the change in call_gen.m.

code_info/dupproc.m:
code_info/exprn_aux.m:
code_info/livemap.m:
code_info/opt_util.m:
	Conform to the change in llds.m.

compiler/code_info.m:
	Minor style cleanups.

tools/bootcheck:
	Enable the collection of statistics from the compilation of stage 3
	and the test cases, for use when the stage 2 is built with
	MR_DO_CALL_STATS enabled.

tools/ho_call_stats:
	A new script to analyze the statistics collected.

tools/makebatch:
	Add a new option --save-stage2-on-no-compiler, which is a variant of
	the existing option --save-stage2-on-error.
2005-08-29 15:44:32 +00:00
Ralph Becket
88b75863dc Add support for initialisation predicates to be called before main/2 is
Estimated hours taken: 16
Branches: main

Add support for initialisation predicates to be called before main/2 is
invoked.  The new directive is `:- initialise initpredname.'

NEWS:
	Mention the new functionality.

compiler/export.m:
	`:- pragma export' also adds a C function declaration in the
	generated C wrapper code to avoid C compiler warnings about
	missing declarations.

compiler/hlds_module.m:
	Added a new user_init_preds field to the module_info to
	record the preds named in `initialise' directives.
	Added predicates to access and update the new field.
	The exported names are generated automatically.

compiler/llds.m:
	Added a new field cfile_num_user_inits to c_file structure.

compiler/llds_out.m:
	Add code to include the `REQUIRED_INIT initpredexportname' lines
	in the comment section of the generated C that is recognised
	by mkinit.

compiler/make_hlds_passes.m:
	Handle the new `initialise' directives.

compiler/mercury_compile.m:
	Make sure the list of user defined init pred export names is passed to
	the C code construction preds.

compiler/mercury_to_mercury.m:
	Handle the output of `initialise' directives.

compiler/module_qual.m:
compiler/modules.m:
compiler/recompilation.check.m:
compiler/recompilation.version.m:
	Handle the new `initialise' item.

compiler/prog_data.m:
	Add a new `initialise(sym_name)' item.

compiler/prog_io.m:
	Add code to parse `initialise' directives.

compiler/prog_mode.m:
	Add di_mode pred and func.

compiler/transform_llds.m:
	Handle the extra field in c_file.

doc/reference_manual.texi:
	Update the operator table in the reference manual.
	Document the new `initialise' directive.

library/list.m:
	Added index[01]_of_first_occurrence preds and
	det_index[01]_of_first_occurrence funcs.  I've often
	had a need for these and they are used in looking up
	initprednames in the new module_info field.

library/ops.m:
	Add `initialise' as a prefix operator.

runtime/mercury_wrapper.c:
runtime/mercury_wrapper.h:
	Add a new exported variable, MR_address_of_init_modules_required.
	Call the function pointed to by this variable at the right point
	during module initialisation.

test/hard_coded/Mmakefile:
test/hard_coded/initialise_decl.exp:
test/hard_coded/initialise_decl.m:
test/invalid/Mmakefile:
test/invalid/bad_initialise_decl.err_exp:
test/invalid/bad_initialise_decl.m:
	Added test cases.

util/mkinit.c:
	Now always checks C files for extra inits (previously you had to
	explicitly supply the -x flag).
2005-08-29 03:22:32 +00:00
Zoltan Somogyi
db00e2afa6 Provide a mechanism to shut up progress messages from the declarative debugger
Estimated hours taken: 1
Branches: main

Provide a mechanism to shut up progress messages from the declarative debugger
for use in bootchecks, to remove a potential source of spurious test case
failures.

runtime/mercury_wrapper.[ch]:
	Add a new global, MR_mdb_decl_print_progress, that controls whether
	we print progress messages. Disable it if the new option
	--mdb-disable-progress is given.

tools/bootcheck:
	Set the new option.

trace/mercury_trace_declarative.c:
	Obey MR_mdb_decl_print_progress.

	Fix a bunch of departures from our coding standards.
2005-08-01 02:26:25 +00:00
Zoltan Somogyi
c731d85a1f Add check for misspelt autoconf variable names.
Estimated hours taken: 0.5
Branches: main

runtime/Mmakefile:
	Add check for misspelt autoconf variable names.

runtime/mercury_wrapper.c:
	Add a mechanism for configuring the sizes of the stacks involved in
	minimal model tabling from the MERCURY_OPTIONS environment variable.

	Conform to our coding standards for braces in if-then-elses.

doc/user_guide.texi:
	Document the new options.
2005-05-09 08:05:05 +00:00
Zoltan Somogyi
83f8deb354 Add two new command line tools "mslice" and "mdice", which manipulate slices
Estimated hours taken: 24
Branches: main

Add two new command line tools "mslice" and "mdice", which manipulate slices
and dices respectively. The functionality of "mdice" duplicates the
functionality of mdb's current "dice" command, while the functionality of
"mslice" is new.

runtime/mercury_trace_base.[ch]:
	When generating trace count files, include information about the
	context of each execution count. While mdb has access to this
	information in the running program, mslice and mdice do not.
	In any case, the code in mdb for looking up this information was
	terribly inefficient.

	Provide a mechanism for recording all execution counts, even the zero
	ones, for use in coverage testing. This mechanism is not used yet.

	Put a header on trace counts files, to make them recognizable as such.
	Make this header indicate whether we are including zero trace counts.

runtime/mercury_wrapper.c:
	Provide a flag in MERCURY_OPTIONS for turning on recording of
	zero execution counts.

browser/dice.m:
mdbcomp/slice_and_dice.m:
	Move most of the code of browser/dice.m to mdbcomp/slice_and_dice.m,
	much modified; browser/dice.m is now empty. The modifications are
	as follows.

	Factor out the code for reading dices, since dices are useful
	independent of mdb's dice command.

	Generalize the code for computing dices to allow either or both
	of the slices being subtracted to be specified as the union of
	one or more trace counts files.

	Add two more sort conditions for comparing the execution counts
	in two slices: ascending and descending versions of simple execution
	count differences.

	For each operation we have so far performed on dices, add code
	for performing that operation on slices.

browser/mdb.m:
	Delete the include of dice.m, since it is now empty.

	Delete a duplicate include_module of term_rep, and delete the now
	unnecessary include_modules of set_cc and tree234_cc.

mdbcomp/mdbcomp.m:
	Add slice_and_dice.m as a submodule.

mdbcomp/trace_counts.m:
	Provide a mechanism to allow a slice to be specified as coming not
	from a single trace count file but from the union operation on a set
	of trace count files.

	Convert to four-space indentation to eliminate some excessively
	indented lines.

slice/mdice.m:
slice/mslice.m:
	The main modules of two new commands. Their functionality is almost
	entirely in mdbcomp/slice_and_dice.m and mdbcomp/trace_counts.m.

slice/Mmakefile:
	New Mmakefile for building mslice and mdice. It is modelled on
	profiler/Mmakefile.

slice/Mercury.options:
	Empty file, for use in the future.

slice/.nocopyright:
	Don't require copyright notice in Mercury.options.

Mmakefile:
	Process the slice directory at appropriate points when processing
	other directories.

compiler/tupling.m:
	Conform to the updated interface of mdbcomp/trace_counts.

library/list.m:
	Add versions of list__map for some more arities, for use in the code
	above.

trace/mercury_trace_internal.c:
	Generalize the code for specifying dices to allow either or both
	of the slices being subtracted to be specified as the union of
	one or more trace counts files.

	Fix several places where we weren't checking the return value of
	malloc. Fix two places where we could conceivably free strings that
	were still alive. Fix some places where we could pass NULL strings
	to Mercury code, and some places where we could free NULL pointers
	(which, once upon a time, was not guaranteed to work on all platforms).

	Use existing functions such as MR_copy_string where appropriate.

tests/run_one_test:
	Fix two small bugs in this script: make the filenames more user
	friendly, and make sure that gzip isn't asked to overwrite an
	existing file, since that causes it to ask a question on stdout
	and to wait for an answer.

tools/bootcheck:
	Copy or link the slice directory into stage 2. Rename the
	--copy-profiler option as --copy-profilers, since it now copies three
	directories containing performance engineering tools: profiler,
	deep_profiler and slice.
2005-04-29 01:03:29 +00:00
Julien Fischer
a0a0c63d5e Add some missing curlies.
Estimated hours taken: 0.1
Branches: main, release

runtime/mercury_wrapper.c:
	Add some missing curlies.
2005-03-31 07:10:27 +00:00
Ian MacLarty
3bded6235e Add a --module option to the mdb dice command to limit output to a specific
Estimated hours taken: 6
Branches: main

Add a --module option to the mdb dice command to limit output to a specific
module or package.

Write out the trace counts even if the program aborts because of an uncaught
exception.

browser/dice.m
	Handle the --module option by adding an extra argument to the
	read_dice_to_string predicate which is called from mdb.

doc/user_guide.texi
	Document the --module option.

mdbcomp/prim_data.m
	Add a predicate to check if one module is a sub-module of another.

runtime/mercury_trace_base.c
runtime/mercury_trace_base.h
	Add a function which writes the trace counts out to the file
	indicated by the symbolic constant MERCURY_TRACE_COUNTS_FILE_NAME.

	Move the symbolic constant MERCURY_TRACE_COUNTS_FILE_NAME from
	runtime/mercury_wrapper.c to runtime/mercury_trace_base.h, so it
	is accessible from the above function.

runtime/mercury_wrapper.c
	Register a function to write the trace counts to a file when the
	program aborts because of an uncaught exception.

	Call the same function when the program terminates normally.

tests/debugger/dice.exp
tests/debugger/dice.inp
	Test the new --module option.

trace/mercury_trace_internal.c
	Add and handle the new --module option.
2005-02-18 04:05:35 +00:00
Zoltan Somogyi
86ac840326 Implement a mechanism to generate the information required to determine the
Estimated hours taken: weeks
Branches: main

Implement a mechanism to generate the information required to determine the
algorithmic complexity of selected procedures.

The basis of the mechanism is a program transformation that wraps up the body
of each selected procedure in code that detects top-level (non-recursive)
calls, and for each top-level call, records the sizes of the input arguments
and information about the cost of the call. For now, the cost information
consists only of the number of cells and words allocated during the call,
but there is provision for later adding information from a real-time clock.

compiler/complexity.m:
	A new module containing the new transformation.

compiler/transform_hlds.m:
	Add complexity.m to the list of submodules.

compiler/mercury_compile.m:
	Invoke the new module.

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

compiler/options.m:
	Add an option, --experimental-complexity. Its argument is a filename
	that specifies the list of procedures to transform.

	Add an option, --no-allow-inlining, to disallow all inlining.
	This is simpler to use than specifying several options to turn off
	each potential reason to inline procedures.

doc/user_guide.texi:
	Document the new options. The documentation present now is only a
	shell; it will be expanded later.

compiler/table_gen.m:
compiler/goal_util.m:
	Move the predicate for creating renamings from table_gen.m to
	goal_util.m, since complexity.m also needs it now. In the process,
	make it more general by allowing outputs to have more complex modes
	than simply `out'.

compiler/goal_util.m:
	Fix a bug exposed by the new transformation: when renaming goals
	(e.g. for quantification), rename the variables holding information
	about term sizes.

compiler/handle_options.m:
	Disable inlining if experimental complexity analysis is enabled.

compiler/compile_target_code.m:
	Pass the --experimental-complexity option on to the linker.

library/term_size_prof_builtin.m:
	Add the Mercury predicates that serve as interfaces to the primitives
	needed by the experimental complexity transformation.

runtime/mercury_term_size.[ch]:
	Add the implementations of the primitives needed by the experimental
	complexity transformation.

runtime/mercury_wrapper.[ch]:
	Add global variables holding counters of the numbers of words and cells
	allocated so far.

runtime/mercury_heap.h:
	Update these global variables when allocating memory.

runtime/mercury_complexity.h:
	New file that contains the definition of the data structures holding
	the data collected by the experimental complexity transformation.
	This is separate from mercury_term_size.h, because it needs to be
	#included in mercury_init.h, the header file of the mkinit-generated
	<program>_init.c files.

runtime/mercury_init.h:
runtime/mercury_imp.h:
	#include mercury_complexity.h.

util/mkinit.c:
	Define and initialize the data structures holding complexity
	information when given the -X option (mkinit doesn't have long
	options).

	Fix some deviations from our coding style.

scripts/parse_ml_options.sh-subr.in:
	Accept the --experiment-complexity option.

scripts/c2init.in:
	Pass the --experiment-complexity option on to mkinit.c.

tools/bootcheck:
	Preserve the files containing the results of complexity analysis,
	if they exist.

tools/makebatch:
	Allow the specification of EXTRA_MLFLAGS in the generated
	Mmake.stage.params files.
2005-02-15 05:22:40 +00:00
Zoltan Somogyi
6b0fb566ce Move the mdbcomp library to its own directory.
Estimated hours taken: 12
Branches: main

Move the mdbcomp library to its own directory. To make this change less painful
to test, improve the way we handle installs.

browser/mdbcomp.m:
browser/mer_mdbcomp.m:
browser/prim_data.m:
browser/program_representation.m:
browser/trace_counts.m:
	Move these files to the mdbcomp directory.

browser/Mmakefile:
browser/Mercury.options:
mdbcomp/Mmakefile:
mdbcomp/Mercury.options:
	Split the contents of the old Mmakefile and Mercury.options file
	in the browser directory between these files as appropriate.
	Simplify away the stuff not needed now that there is only one library
	per directory. Make the browser directory see the relevant files
	from the mdbcomp directory.

Mmake.common.in:
	Separate out the prefixes allowed in the browser and the mdbcomp
	directories.

Mmake.workspace:
	Set up a make variable to refer to the mdbcomp directory.

	Adjust references to the mdbcomp library to point to its new location.

Mmakefile:
	Make invocations visit the mdbcomp library as necessary.

	Improve the way we install grades. Making temporary backups of the
	directories modified by the install process is unsatisfactory for two
	reasons. First, if the install fails, the cleanup script, which is
	necessary for user friendliness, destroys any evidence of the cause.
	Second, the restore of the backup wasn't perfect, e.g. it left the
	.d files modified to depend on .mih files, which don't exist in
	LLDS grades, and also left altered timestamps.

	This diff changes the install process to make a single tmp_dir
	subdirectory of the workspace, with all the work of install_grade
	being done inside tmp_dir. The original directories aren't touched
	at all.

*/Mmakefile:
	Adjust references to the browser directory to refer to the mdbcomp
	directory instead or as well.

scripts/Mmake.rules:
*/Mmakefile:
	Make it easier to debug Mmakefiles. Previously, creating a
	Mmake.makefile with mmake -s and invoking "make -d" ignored the
	most fundamental rules of mmake, because Mmake.rules was treating
	an unset MMAKE_USE_MMC_MAKE as if it were set to "yes", simply because
	it was different from "no". This diff changes it to treat an unset
	MMAKE_USE_MMC_MAKE as if it were set to "no", which is a more
	sensible default.

scripts/prepare_tmp_dir_fixed_part.in:
scripts/scripts/prepare_tmp_dir_grade_part:
	Two new scripts that each do half the work of preparing tmp_dir for
	the real work of the install_grade make target. The fixed_part script
	prepares the parts of tmp_dir that are grade-independent, while the
	grade_part scripts prepares the parts that are grade-dependent.

configure.in:
	Test C files in the mdbcomp directory to see whether they need to
	be recompiled after reconfiguration.

	Create prepare_tmp_dir_fixed_part from prepare_tmp_dir_fixed_part.in.

compiler/*.m:
runtime/mercury_wrapper.c:
	Update the references to the moved files.

compiler/notes/overall_design.html:
	Mention the new directory.
2005-01-28 07:12:05 +00:00
Zoltan Somogyi
fc1dd28b3b Prevent the generation of filenames with spaces in them.
Estimated hours taken: 0.1
Branches: main

runtime/mercury_wrapper.c:
	Prevent the generation of filenames with spaces in them.
2005-01-10 05:27:56 +00:00
Zoltan Somogyi
e4da5e1c94 Fix performance problems in the compiler when handling automatically generated
Estimated hours taken: 10
Branches: main

Fix performance problems in the compiler when handling automatically generated
code (specifically, code generated by caribou). These depend on new facilities
in the library.

Fix a problem with the debugger: get the debugger to stop when given an
interrupt signal. (I needed this fix to find the performance problems above.)
The problem was that the variable set by the interrupt handler wasn't the
right one.

library/map.m:
	The map__overlay predicate takes time linear in the new map.
	However, sometimes the compiler wants to overlay a large map on a small
	one. Add a new version, map__overlay_large_map, which does the same job
	but whose complexity is linear in the size of the old map.

library/set.m:
library/set__ordlist.m:
	Add a new version of set__divide specialized to a situation that
	occurs in some performance-critical code in the compiler. This lowers
	the complexity from quadratic to linear.

library/bag.m:
	Add predicates for operating on sets alongside for predicates for
	operating on lists. These should be able to exploit the sortedness
	of the set, although we don't do so yet.

library/svbag.m:
	Add this new module to make some of the changes to the compiler easier.

library/library.m:
NEWS:
	Mention the new module.

compiler/instmap.m:
	Use either map__overlay or map__overlay_large_map, depending on which
	one is likely to be more efficient.

compiler/deforest.m:
compiler/goal_util.m:
compiler/mode_util.m:
compiler/simplify.m:
compiler/table_gen.m:
	Conform to the changes in instmap.m.

compiler/liveness.m:
	Use the specialized version of set__divide.

compiler/mode_info.m:
	The original representation of liveness information in the mode
	analyzer had a fast insert operation, but a slow delete operation
	and a lookup operation that is *very* slow when analyzing long
	conjunctions. Replace that representation with a more direct
	and more compact representation with slower insert operation
	but much faster lookup operation and significantly faster delete
	operation.

compiler/modes.m:
compiler/unique_modes.m:
	Conform to the changes in mode_info.m.

trace/mercury_trace.c:
	Make the debugger's interrupt handler set the variable actually used
	by MR_trace to select which function to call.

runtime/mercury_trace_base.[ch]:
	Make MR_selected_trace_func_ptr volatile, since it is now set from
	an interrupt handler.

runtime/mercury_wrapper.[ch]:
	Make MR_trace_handler non-volatile, since it is no longer set from
	an interrupt handler. Change its name to MR_exec_trace_handler to
	reflect the fact that it is not the only trace handler.

util/mkinit.c:
	Refer to MR_trace_handler by its new name.
2005-01-10 05:23:56 +00:00
Fergus Henderson
1513962f4a Comment out some code that doesn't compile on Win32.
Estimated hours taken: 0.25
Branches: main

runtime/mercury_wrapper.c:
	Comment out some code that doesn't compile on Win32.
2004-12-20 05:53:44 +00:00
Zoltan Somogyi
abc7d6b22b Add two runtime options useful in benchmarking I/O tabling.
Estimated hours taken: 2
Branches: main

Add two runtime options useful in benchmarking I/O tabling.

runtime/mercury_wrapper.[ch]:
	Recognize the two new runtime options, and implement the first:
	When --mem-usage-report is included in MERCURY_OPTIONS, write a report
	on the memory usage of the program when the program exits.

trace/mercury_trace_internal.c:
	Implement the other option, --mdb-benchmark-silent. When this option
	is given, the debugger will generate no output to stdout (and neither
	will the program). This is to avoid mixing prompts (e.g. "mdb>" with
	the timing data output by tools/speedtest, allowing the output of
	tools/speedtest to be processed automatically.

doc/user_guide.texi:
	Document the new options, with the documentation of
	--mdb-benchmark-silent being for developers only.

	Fix a documentation bug on an existing option.
2004-12-14 07:04:47 +00:00
Zoltan Somogyi
941be20e27 Type_desc__get_functor looks up the types of the arguments of a function
Estimated hours taken: 16
Branches: main

Type_desc__get_functor looks up the types of the arguments of a function
symbol. This predicate used to abort when an argument has an existential
type. This diff makes type_desc__get_functor work even in that case.
However, since in such cases the type of an argument is not a ground type,
this diff has to add the concept of a pseudo_type_desc, a descriptor for
a not necessarily ground type. Pseudo_type_descs are implemented as
MR_PseudoTypeInfos.

runtime/mercury_type_info.[ch]:
	Add new macros to operate on pseudo_type_infos. Most have a structure
	modelled on corresponding macros operating on type_infos.

	Provide versions of MR_get_arg_type_info, MR_compare_type_info,
	MR_unify_type_info, MR_collapse_equivalences,
	MR_type_params_vector_to_list, MR_create_type_info and
	MR_create_type_info_maybe_existq that work on pseudo_type_infos,
	not type_infos.

	Change MR_pseudo_type_info_vector_to_type_info_list, which implements
	the core of get_functor, to return pseudo_type_infos instead of
	type_infos, and rename it to reflect this fact.

	Change to four-space indentation to reduce the number of lines
	that have to be wrapped.

runtime/mercury_make_type_info_body.h:
	Generalize the code for creating type_infos to also be handle
	pseudo_type_infos.

	Change to four-space indentation to reduce the number of lines
	that have to be wrapped.

runtime/mercury_type_desc.[ch]:
	Provide versions of MR_make_type_ctor_desc and MR_type_ctor_and_args
	that work on pseudo_type_infos, not type_infos.

	Change to four-space indentation to reduce the number of lines
	that have to be wrapped.

runtime/mercury_builtin_types.[ch]:
runtime/mercury_builtin_types_proc_layouts.h:
runtime/mercury_hlc_types.h:
runtime/mercury_unify_compare_body.h:
	Add the C types, global variables and functions necessary for the
	new builtin Mercury type pseudo_type_desc. This type must be builtin,
	because its structure (MR_PseudoTypeInfo) is defined in C, and as such
	cannot be unified, compared, deconstructed etc without hand-written
	C code.

runtime/mercury_deep_copy.c:
runtime/mercury_deep_copy_body.h:
	Handle the copying of pseudo_type_infos/pseudo_type_descs. This code
	is almost the same as the code to copy type_infos, but must of course
	handle type variables, and the arguments are themselves copied as
	pseudo_type_infos, not type_infos.

runtime/mercury_types.h:
	Since deep copy needs to create pseudo_type_infos, provide a version
	of the MR_PseudoTypeInfo type without const.

runtime/mercury_construct.c:
runtime/mercury_deconstruct.c:
	Handle pseudo_type_descs just as we handle type_descs: neither can be
	constructed, nor do they have function symbols with named arguments.

runtime/mercury_ml_expand_body.c:
	Provide code to deconstruct pseudo_type_descs. This code is almost
	the same as the code to deconstruct type_descs, but must of course
	handle type variables, and the arguments are themselves
	pseudo_type_descs, not type_descs.

runtime/mercury_tabling.c:
	Catch attempts to table pseudo_type_infos.

runtime/mercury_tags.h:
	Add macros for constructing lists of
	pseudo_type_infos/pseudo_type_descs.

runtime/mercury_wrapper.[ch]:
	Define global variables holding the addresses of the typeinfos for
	describing pseudo_type_descs and lists of pseudo_type_descs.

runtime/mercury_init.c:
	Add the extern declarations required by new code in mkinit.c.

util/mkinit.c:
	Make the addresses of the typeinfos for describing pseudo_type_descs
	and lists of pseudo_type_descs, defined in the library, known to the
	runtime.

library/type_desc.m:
	Add a new builtin type, pseudo_type_desc, for describing possibly
	nonground types.

	Add utility predicates for operating on pseudo_type_descs.

library/private_builtin.m:
	Handle the new builtin type.

	Add builtin typeinfos for describing pseudo_type_descs and lists of
	pseudo_type_descs, since some functions in the runtime need them
	for memory profiling.

library/rtti_implementation.m:
	Handle the new builtin type, mostly by ignoring it, since the backends
	that use this module do not have any notion of pseudo_type_infos.

	Bring the module up to date with our formatting guidelines.

library/construct.m:
	Make get_functor return a list of pseudo_type_descs instead of
	type_descs.

	Change the name of the version of get_functor that returns argument
	names, to distinguish it from the base version by more than just the
	arity.

	Make the order of predicates more logical.

library/std_util.m:
	Change the name of the version of get_functor that returns argument
	names, to distinguish it from the base version by more than just the
	arity.

	However, this name change is effectively the only change: both
	get_functor and get_functor_with_names still return lists of
	type_descs. This means that they will throw exceptions in the presence
	of existential types, but code using them need no algorithmic changes.

library/term.m:
library/term_to_xml.m:
	Add module qualifiers as necessary; no algorithmic changes.

library/list.m:
	Add two general-purpose predicates, all_true and all_false,
	for use in the other library modules.

compiler/ml_util.m:
compiler/mlds_to_gcc.m:
compiler/rtti.m:
compiler/type_ctor_info.m:
	Make sure we handle the new builtin type as a builtin type, and not
	try to have the compiler create a type_ctor_info for it.

deep_profiler/canonical.m:
	Delete the local definition of all_true.

tests/hard_coded/construct_test.{m,exp}:
	Update this test case to test the ability to retrieve the names of the
	fields of function symbols with existential types.

	Add module qualifications as necessary.

tests/hard_coded/construct_test_exist.{m,exp}:
	Add a tougher test case to print the types of the arguments of
	function symbols with existential types.

tests/hard_coded/Mmakefile:
	Add the new test case, and sort the names of the tests.
2004-12-14 01:07:32 +00:00
Ralph Becket
09f3ce8d2f Remove an earlier simplification that has since caused hlc.par.gc
Estimated hours taken: 32
Branches: main

NEWS:

runtime/mercury_wrapper.c:
	Remove an earlier simplification that has since caused hlc.par.gc
	grades to fail.  Fergus had done some work on making non-hlc.gc
	grades independent of the Mercury engine code.  Since then,
	however, other such dependencies have been introduced and Fergus'
	change meant that the Mercury engine was not initialised in
	these cases, which caused hlc.par.gc programs, for instance, to
	immediately segfault.
2004-11-05 05:03:16 +00:00
Zoltan Somogyi
ba38a2d1d2 Add a mechanism for collecting information about how many times each event
Estimated hours taken: 8
Branches: main

Add a mechanism for collecting information about how many times each event
is executed. Later changes will exploit this information, for coverage testing
and for better search strategies in the declarative debugger.

runtime/mercury_stack_layout.h:
	Extend the module layout structure to contain a pointer to an array
	of counters, with one counter for each label layout structure
	corresponding an event.

	Extend label layout structures to contain the label's index into
	this array. The new field fits into a hole in the existing structure
	required by alignment considerations, so the size of label layout
	structures is unaffected.

	The memory cost of the new facility is thus only one word per event.

	Extend the macros for defining label layout structures to take an extra
	argument for the new field.

runtime/mercury_grade.m:
	Update the binary compatibility version number for debug grades,
	since runtimes before this change and the compiler-generated C files
	in debug grades from after this change are not compatible, and neither
	are runtimes after this change and the compiler-generated C files
	in debug grades from before this change.

runtime/mercury_trace_base.[ch]:
	Add a third alternative function to call from MR_trace; besides
	MR_trace_real (in the trace directory) and MR_trace_fake (in this
	module), add MR_trace_count, which returns after incrementing the
	counter of the event's label layout structure.

	Instead of a single variable, MR_trace_enabled, controlling whether
	MR_trace is enabled or not and debugging is enabled or not, use two
	separate variables: MR_trace_func_enabled controlling whether MR_trace
	is enabled or not, and MR_debug_enabled controlling whether debugging
	is enabled or not. MR_trace_func_enabled is always set to the
	disjunction of MR_debug_enabled and a new variable
	MR_trace_count_enabled, the variable controlling whether the facility
	for counting label executions is enabled.

	Add a function for writing out the gathered execution counts.

runtime/mercury_trace_base.[ch]:
trace/mercury_trace_tables.[ch]:
	Move the table of module_infos from mercury_trace_tables to
	mercury_trace_base, since the code to write out execution counts
	needs it.

runtime/mercury_wrapper.c:
	When MERCURY_OPTIONS contains --trace-count and debugging is not,
	enable the mechanism for counting the execution of events, and
	write out the results.

library/exception.m:
library/io.m:
library/table_builtin.m:
runtime/mercury_tabling_preds.h:
trace/mercury_trace_declarative.c:
trace/mercury_trace_external.c:
trace/mercury_trace_vars.c:
	Conform to the changes involving the replacement of MR_trace_enabled.

tools/bootcheck:
	Add an new option, --trace-count, for enabling the new mechanism.

compiler/layout.m:
	Change the compiler's data structures for label layouts and module
	layouts to conform to the changes in mercury_stack_layout.h.

compiler/layout_out.m:
	Update the code for writing out label layouts and module
	layouts.

compiler/stack_layout.m:
	Allocate slots in the execution count array to the label layout
	structures of all events.

	Delete the unnecessary last arguments of `get' field access predicates.

compiler/llds_out.m:
compiler/opt_debug.m:
	Conform to the changes in layout.m.
2004-08-16 03:51:16 +00:00
Zoltan Somogyi
e854a5f9d9 Major improvements to tabling, of two types.
Estimated hours taken: 32
Branches: main

Major improvements to tabling, of two types. The first is the implementation
of the loopcheck and memo forms of tabling for model_non procedures, and the
second is a start on the implementation of a new method of implementing
minimal model tabling, one that has the potential for a proper fix of the
problem that we currently merely detect with the pneg stack (the detection
is followed by a runtime abort). Since this new method relies on giving each
own generator its own stack, the grade component denoting it is "mmos"
(minimal model own stack). The true name of the existing method is changed
from "mm" to "mmsc" (minimal model stack copy). The grade component "mm"
is now a shorthand for "mmsc"; when the new method works, "mm" will be changed
to be a shorthand for "mmos".

configure.in:
scripts/canonical_grade.sh-subr:
scripts/init_grade_options.sh-subr:
scripts/parse_grade_options.sh-subr:
scripts/final_grade_options.sh-subr:
compiler/options.m:
	Handle the new way of handling minimal model grades.

scripts/mgnuc.in:
compiler/compile_target_code.m:
	Conform to the changes in minimal model grade options.

compiler/table_gen.m:
	Implement the transformations required by the loopcheck and memo
	tabling of model_non procedures, and the minimal model own stack
	transformation.

	The new implementation transformations use foreign_procs with extra
	args, since there is no point in implementing them both that way and
	with separate calls to library predicates. This required making the
	choice of which method to use at the top level of each transformation.

	Fix an oversight that hasn't caused problems yet but may in the future:
	mark goals wrapping the original goals as not impure for determinism
	computations.

compiler/handle_options.m:
	Handle the new arrangement of the options for minimal model tabling.
	Detect simultaneous calls for both forms of minimal model tabling,
	and generate an error message. Allow for more than one error message
	generated at once; report them all once rather than separately.

compiler/globals.m:
	Add a mechanism to allow a fix a problem detected by the changes
	to handle_options: the fact that we currently may generate a usage
	message more than once for invocations with more than one error.

compiler/mercury_compile.m:
compiler/make.program_target.m:
compiler/make.util.m:
	Use the new mechanism in handle_options to avoid generating duplicate
	usage messages.

compiler/error_util.m:
	Add a utility predicate for use by handle_options.

compiler/hlds_pred.m:
	Allow memo tabling for model_non predicates, and handle own stack
	tabling.

compiler/hlds_out.m:
	Print information about the modes of the arguments of foreign_procs,
	since this is useful in debugging transformations such as tabling
	that generate them.

compiler/prog_data.m:
compiler/layout_out.m:
compiler/prog_out.m:
runtime/mercury_stack_layout.h:
	Mention the new evaluation method.

compiler/goal_util.m:
	Change the predicates for creating calls and foreign_procs to allow
	more than one goal feature to be attached to the new goal. table_gen.m
	now uses this capability.

compiler/add_heap_ops.m:
compiler/add_trail_ops.m:
compiler/polymorphism.m:
compiler/simplify.m:
compiler/size_prof.m:
compiler/typecheck.m:
compiler/unify_proc.m:
	Conform to the changes in goal_util.

compiler/code_info.m:
compiler/make_hlds.m:
compiler/modules.m:
compiler/prog_io_pragma.m:
	Conform to the new the options controlling minimal model
	tabling.

compiler/prog_util.m:
	Add a utility predicate for use by table_gen.m.

library/std_util.m:
	Conform to the changes in the macros for minimal model tabling grades.

library/table_builtin.m:
	Add the types and predicates required by the new transformations.

	Delete an obsolete comment.

runtime/mercury_grade.h:
	Handle the new minimal model grade component.

runtime/mercury_conf_param.h:
	List macros controlling minimal model grades.

runtime/mercury_tabling.[ch]:
	Define the types needed by the new transformations,

	Implement the performance-critical predicates that need to be
	hand-written for memo tabling of model_non predicates.

	Add utility predicates for debugging.

runtime/mercury_tabling_preds.h:
	Add the implementations of the predicates required by the new
	transformations.

runtime/mercury_mm_own_stacks.[ch]:
	This new module contains the first draft of the implementation
	of the own stack implementation of minimal model tabling.

runtime/mercury_imp.h:
	Include the new file if the grade needs it.

runtime/Mmakefile:
	Mention the new files, and sort the lists of filenames.

runtime/mercury_tabling_macros.h:
	Add a macro for allocating answer blocks without requiring them to be
	pointed to directly by trie nodes.

runtime/mercury_minimal_model.[ch]:
	The structure type holding answer lists is now in mercury_tabling.h,
	since it is now also needed by memo tabling of model_non predicates.
	It no longer has a field for an answer num, because while it is ok
	to require a separate grade for debugging minimal model tabling,
	it is not ok to require a separate grade for debugging memo tabling
	of model_non predicates. Instead of printing the answer numbers,
	print the answers themselves when we need to identify solutions
	for debugging.

	Change function names, macro names, error messages etc where this is
	useful to distinguish the two kinds of minimal model tabling.

	Fix some oversights wrt transient registers.

runtime/mercury_context.[ch]:
runtime/mercury_engine.[ch]:
runtime/mercury_memory.[ch]:
runtime/mercury_wrapper.[ch]:
	With own stack tabling, each subgoal has its own context, so record
	the identity of the subgoal owning a context in the context itself.
	The main computation's context is the exception: it has no owner.

	Record not just the main context, but also the contexts of subgoals
	in the engine.

	Add variables for holding the sizes of the det and nondet stacks
	of the contexts of subgoals (which should in general be smaller
	than the sizes of the corresponding stacks of the main context),
	and initialize them as needed.

	Initialize the variables holding the sizes of the gen, cut and pneg
	stacks, even in grades where the stacks are not used, for safety.

	Fix some out-of-date documentation, and conform to our coding
	guidelines.

runtime/mercury_memory_zones.[ch]:
	Add a function to test whether a pointer is in a zone, to help
	debugging.

runtime/mercury_debug.[ch]:
	Add some functions to help debugging in the presence of multiple
	contexts, and factor out some common code to help with this.

	Delete the obsolete, unused function MR_printdetslot_as_label.

runtime/mercury_context.h:
runtime/mercury_bootstrap.h:
	Move a bootstrapping #define from mercury_context.h to
	mercury_bootstrap.h.

runtime/mercury_context.h:
runtime/mercury_bootstrap.h:
	Move a bootstrapping #define from mercury_context.h to
	mercury_bootstrap.h.

runtime/mercury_types.h:
	Add some more forward declarations of type names.

runtime/mercury_dlist.[ch]:
	Rename a field to avoid assignments that dereference NULL.

runtime/mercury_debug.c:
runtime/mercury_memory.c:
runtime/mercury_ml_expand_body.h:
runtime/mercury_stack_trace.c:
runtime/mercury_stacks.[ch]:
trace/mercury_trace_util.c
	Update uses of the macros that control minimal model tabling.

runtime/mercury_stack_trace.c:
	Provide a mechanism to allow stack traces to be suppressed entirely.
	The intention is that by using this mechanism, by the testing system
	won't have to provide separate .exp files for hlc grades, nondebug
	LLDS grades and debug LLDS grades, as we do currently. The mechanism
	is the environment variable MERCURY_SUPPRESS_STACK_TRACE.

tools/bootcheck:
tools/test_mercury:
	Specify MERCURY_SUPPRESS_STACK_TRACE.

trace/mercury_trace.c:
	When performing retries across tabled calls, handle memo tabled
	model_non predicates, for which the call table tip variable holds
	a record with a back pointer to a trie node, instead of the trie node
	itself.

trace/mercury_trace_internal.c:
	When printing tables, handle memo tabled model_non predicates. Delete
	the code now moved to runtime/mercury_tabling.c.

	Add functions for printing the data structures for own stack minimal
	model tabling.

tests/debugger/print_table.{m,inp,exp}:
	Update this test case to also test the printing of tables for
	memo tabled model_non predicates.

tests/debugger/retry.{m,inp,exp}:
	Update this test case to also test retries across memo tabled
	model_non predicates.

tests/tabling/loopcheck_nondet.{m,exp}:
tests/tabling/loopcheck_nondet_non_loop.{m,exp}:
	New test cases to test loopcheck tabled model_non predicates.
	One test case has a loop to detect, one doesn't.

tests/tabling/memo_non.{m,exp}:
tests/tabling/tc_memo.{m,exp}:
tests/tabling/tc_memo2.{m,exp}:
	New test cases to test memo tabled model_non predicates.
	One test case has a loop to detect, one has a need for minimal model
	tabling to detect, and the third doesn't have either.

tests/tabling/Mmakefile:
	Add the new test cases, and reenable the existing tc_loop test case.

	Rename some make variables and targets to make them better reflect
	their meaning.

tests/tabling/test_mercury:
	Conform to the change in the name of the make target.
2004-07-20 04:41:55 +00:00
Zoltan Somogyi
8190c16181 Get Mercury to work with gcc 3.4. This required fixing several problems.
Estimated hours taken: 16
Branches: main

Get Mercury to work with gcc 3.4. This required fixing several problems.

One problem that caused errors is that gcc 3.4 is smart enough to figure out
that in LLDS grades with gcc gotos, the C functions containing our code are
not referred to, and so it optimizes them away. The fix is to ensure that
mercury_<module>_init is defined always to call those functions, even if
the macro that usually controls this, MR_MAY_NEED_INITIALIZATION, is not
defined. The mercury_<module>_init won't be called from the init_modules
function in the program's _init.c file, so there is no impact on initialization
time, but gcc doesn't know this when compiling a module's .c file, so
it doesn't optimize away the code we need. The cost of this change is thus
only a small amount of code space. It is worth paying this cost even with
compilers other than gcc 3.4 for simplicity. Actually, this size increase seems
to be slightly smaller than the size reduction due to the better optimization
capabilities of gcc 3.4 compared to gcc 3.2.2.

A second problem is that gcc 3.4 warns about casts in lvalues being a
deprecated feature. This gave lots of warnings, since we used to define
several Mercury abstract machine registers, including MR_succip, MR_hp, MR_sp,
MR_maxfr and MR_curfr using lvalue casts. The fix is to have two macros
for each of these abstract machine registers, one of type MR_Word that you can
assign to (e.g. MR_sp_word), and one of the original type that is of the right
type but not an lvalue (e.g. MR_sp). The lvalue itself can't be made the right
type, because MR_sp isn't a variable in its own right, but possibly defined
to be a machine register. The machine register could made the right type,
but only at the cost of a lot of complexity.

This problem doesn't apply to the special-purpose Mercury abstract machine
registers that can't be allocated to machine registers. Instead of #defining
these to slots in MR_fake_reg, we make them global variables of the natural
type. This should also make it easier to debug code using these registers.
We treat these global variables as if they were machine registers in that
MR_save_registers copies values from these global variables to slots reserved
for them in the MR_fake_reg array, to allow code to loop over all Mercury
abstract machine registers. These saved slots must of course be of type
MR_Word, so we again need two macros to refer to them, a lvalue of type
MR_Word and an rvalue with the right type.

A third problem is that gcc 3.4 warns about conditionals in lvalues being a
deprecated feature. This gave a few warnings, since we used to define
MR_virtual_reg and MR_saved_reg using lvalues using conditionals. The fix
is to have one macro (MR_virtual_reg_value) for use in rvalues and a
separate macro which uses an if-then-else instead of a conditional
expression (MR_virtual_reg_assign), for assignments.

A fourth problem is that gcc 3.4 warns about comma operators in lvalues
being a deprecated feature. This gave warnings in the few places where
we refer to MR_r(N) for values of N that can map to fake registers directly,
since in those cases we preceded the reference to the fake_reg array with
a range check of the array index. The fix to this is to move the test to
compile time for compiler-generated code. Hand-written code never refers
to MR_r(N) for these values, and is very unlikely to do so in the future;
instead, it refers to the underlying fake_reg array directly, since that way
it doesn't have to worry about which fake registers have their own MR_rN macro
and which don't. Therefore no check mechanism for hand-written code is
necessary. This change mean that changing the number of MR_rN registers
now requires change to the compiler as well as to the runtime system.

A fifth problem is that gcc 3.4 by default assumes -fstrict-aliasing at -O2.
Since we cast between integers and pointers of different types all the time,
and changing that is not practical, at least in the short term, we need to
disable -fstrict-aliasing when we enable -O2.

NEWS:
	Note that Mercury now works with gcc 3.4.

configure.in:
scripts/mgnuc.in:
	Detect whether the compiler supports -fstrict-aliasing, and if so,
	whether it assumes it by default with -O2. If the answer is yes to
	both, make mgnuc specify -fno-strict-aliasing when it specifies -O2.
	By including it in CFLAGS_FOR_OPT, which gets put into Mercury.config,
	we also get -f-no-strict-aliasing when mmc invokes the C compiler
	directly.

compiler/llds_out.m:
	Don't generate #ifdef MR_MAY_NEED_INITIALIZATION around the definitions
	and calls to the bunch functions, which call the functions we don't
	want the C compiler to optimize away.

	Generate the newly required lvalues on the left sides of assignments.

	We still have code to generate LVALUE_CASTs in some cases, but I don't
	think those cases ever arise.

	Add a compile-time check of register numbers. Ideally, the code
	generator should use stack slots instead of registers beyond the max
	number, but I don't recall us ever bumping into this limit by accident.

compiler/fact_table.m:
	Use the newly required lvalues on the left sides of assignments
	in some hand-written C code included in generated .c files.

runtime/mercury_regs.h:
	Make the changes described above to fix the second, third and fourth
	problems. We still use comma operators in lvalues when counting
	references to registers, but it is OK to require anyone who wants
	to enable this feature to use a compiler version that supports comma
	operators in lvalues or to ignore the warnings.

	Use the same mapping from Mercury abstract machine registers to
	the register count array as to the MR_fake_reg array.

	Have this mapping depend as little as possible on whether we need a
	real machine register to store MR_engine base, even if it costs a
	wasted slot in MR_fake_reg.

	Fix an old inconsistency: treat the Mercury abstract machine registers
	used for trailing the same way as the other Mercury abstract machine
	registers, by making MR_save_registers/MR_restore_registers copy them
	to and from their global variable homes.

	Document the requirement for the match between the runtime's and the
	compiler's notions of the maximum MR_rN register number. This
	requirement makes it harder for users to increase the number of
	virtual registers, but as far as I know noone has wanted to do this.

	Change the names of some of the macros to make them clearer.

	Reorder some parts of this file, and add some documentation, also
	in the interest of clarity.

runtime/mercury_regorder.h:
	Delete this file after moving its contents, in much modified form,
	to mercury_regs.h. mercury_regorder.h was always logically part of
	mercury_regs.h, but was separated out to make it easier to change
	the mapping from Mercury abstract machine registers to machine
	registers. However, the cost of incompatibility caused by any such
	changes would be much greater that any likely performance benefit.

runtime/Mmakefile:
	Remove the reference to mercury_regorder.h.

runtime/mercury_regs.[ch]:
runtime/mercury_memory_zones.[ch]:
	Move some functionality dealing with registers from
	mercury_memory_zones to mercury_regs, since it belongs there.

runtime/mercury_regs.[ch]:
	Add a function to make it easiler to debug changes to map from
	Mercury abstract machine to MR_fake_reg slots.

runtime/mercury_regs.[ch]:
runtime/mercury_wrapper.c:
	Move the code to print counts of register uses from mercury_wrapper.c
	to mercury_regs.c.

	Make mercury_wrapper.c call the debugging function in mercury_regs.c
	if -X is specified in MERCURY_OPTIONS.

runtime/mercury_bootstrap.h:
	Move the old MR_saved_reg and MR_virtual_reg macros from mercury_regs.h
	to mercury_bootstrap.h to prevent their accidental use. Since
	they shouldn't be used by user code, move them to the section
	that is not enabled by default.

runtime/mercury_stacks.[ch]:
	Add _word versions of the macros for stack slots, for the same reason
	why we need them for Mercury abstract machine registers, and use them.

	Add global variables for the Mercury abstract machine registers
	for the gen, cut and pneg stacks.

runtime/mercury_heap.h:
	Change the macros for allocating memory to assign to MR_hp_word instead
	of MR_hp.

runtime/mercury_string.h:
	Change the macros for allocating strings to accomodate the updates to
	mercury_heap.h. Also change the expected type of the target to make it
	MR_String instead of MR_ConstString, since the latter requires casts in
	the caller.

runtime/mercury_trail.h:
runtime/mercury_types.h:
	Move the definition of the type MR_TrailEntry from mercury_trail.h
	to mercury_types.h, since it is now used in mercury_regs.h.

runtime/mercury_accurate_gc.c:
runtime/mercury_agc_debug.c:
runtime/mercury_calls.h:
runtime/mercury_context.[ch]:
runtime/mercury_deconstruct_macros.h:
runtime/mercury_deep_copy_body.h:
runtime/mercury_engine.[ch]:
runtime/mercury_hand_compare_body.h:
runtime/mercury_hand_unify_body.h:
runtime/mercury_ho_call.c:
runtime/mercury_layout_util.c:
runtime/mercury_make_type_info_body.h:
runtime/mercury_minimal_model.c:
runtime/mercury_ml_deconstruct_body.h:
runtime/mercury_ml_functor_body.h:
runtime/mercury_stack_layout.h:
runtime/mercury_type_desc.c:
runtime/mercury_type_info.c:
runtime/mercury_unify_compare_body.h:
runtime/mercury_wrapper.c:
	Conform to the changes in the rest of the runtime.

	In some cases, fix inconsistencies in indentation.

runtime/mercury_stack_trace.c:
	Add some conditionally compiled debugging code controlled by the macro
	MR_ADDR_DEBUG, to help debug some problems with stored stack pointers.

runtime/mercury_grade.h:
	Increment the binary compatibility version number. This is needed to
	avoid potential problems when a Mercury module and the debugger are
	compiled with different versions of the macros in mercury_regs.h.

library/exception.m:
	Update the code that assigns to abstract machine registers.

library/array.m:
library/construct.m:
library/dir.m:
library/io.m:
library/string.m:
	Conform to the new definitions of allocation macros.

library/time.m:
	Delete an unnecessary #include.

trace/mercury_trace.c:
trace/mercury_trace_declarative.c:
trace/mercury_trace_util.c:
	Conform to the changes in the rest of the runtime.

tests/hard_coded/qual_test_is_imported.m:
tests/hard_coded/aditi_private_builtin.m:
	Remove an unnecessary import to avoid a warning.

tools/makebatch:
	Add an option --save-stage2-on-error, that saves the stage2 directory
	if a bootcheck fails.

scripts/ml.in:
	Make ml more robust in the face of garbage files.
2004-07-07 07:11:22 +00:00
Zoltan Somogyi
cdf0383b52 Fix a bunch of problems with tabling that I identified in Uppsala.
Estimated hours taken: 32
Branches: main

Fix a bunch of problems with tabling that I identified in Uppsala. These fall
into two categories.

First, the tabling transformations we were using were dividing work up
too finely. This had three bad effects. First, it caused too much time to be
spent on transmitting data to and from library predicates. Second, it made the
transformations hard to document and hard to explain in a paper. Third, it
caused us to misidentify just what the various forms of tabling have in common,
and what forms of tabling work for what determinisms. To fix this problem,
this diff reorients table_builtin.m and table_gen.m from being divided
primarily by determinism to being divided by evaluation method.

Second, we weren't being careful in separating out the parts of the tabling
data structures that are needed only for debugging the tabling system itself.
The fix for this is to introduce a new grade flag, MR_MINIMAL_MODEL_DEBUG,
intended for use by implementors only, to govern whether the tabling data
structures include debug-only components. (If this flag weren't a grade flag,
the sizes of data structures created in files with different values of this
flag could be inconsistent, which is something you don't want when debugging
the complex code of the tabling infrastructure.)

compiler/table_gen.m:
	Reorganize the simple (loopcheck and memo) tabling transformations
	completely. Instead of separate transformations for model_det and
	model_semi predicates, have separate transformations for loopcheck
	and memo predicates, since this makes it easier to see (and to ensure)
	that the transformation follows the required scheme. Instead of
	generating nested if-then-elses, generate switches when possible.

	For model_semi loopcheck and memo predicates, generate Mercury code
	that obeys our scope rules by not binding output variables in the
	condition of the one remaining if-then-else.

	Finetune the minimal model tabling transformation by combining some
	operations where this improves clarity and performance.

	Order the transformation predicates logically, and move the
	documentation of each form of tabling next to the code implementing
	that form of tabling.

	Attach call_table_gen markers to the setup goals that now all
	loopcheck, memo and minimal model tabled predicates have,
	to avoid having to special case the last lookup goal, and to avoid
	having to have separate code for lookups in call tables versus answer
	tables.

	Generate unique and more meaningful variable names. Change some
	predicate names to be more meaningful, both here and in the
	transformed code.

	Factor out some common code, e.g. for generating lookup goals,
	for generating instmap_deltas and for attaching hide_debug_event
	markers to goals.

	Report errors in cases where the arguments of a tabled predicate
	aren't completely input or output.

compiler/hlds_pred.m:
	Be more strict about the determinisms of tabled predicates; permit
	only the determinisms we really support in all cases, and do not
	permit the ones that may happen to work in some cases.

	Conform to the change of the name of a builtin.

compiler/det_report.m:
	Improve the error message for cases when the determinism is
	incompatible with the selected tabling mechanism.

compiler/compile_target_code.m:
compiler/handle_options.m:
compiler/options.m:
	Handle the new grade component.

library/private_builtin.m:
	Provide a semipure analog of the imp predicate, a call to which makes
	predicates semipure rather than impure, for use in table_builtin.m.

library/table_builtin.m:
runtime/mercury_tabling_preds.h:
	Change the tabling primitives in the ways required by the changes to
	the tabling transformations.

	Group the primitives by the tabling methods they support, and change
	their names to reflect this.

	Change the implementation of each of the affected predicates to be
	nothing more than the invocation of a macro defined in the new header
	file runtime/mercury_tabling_preds.h. The objective of this change
	is to make it possible for table_gen.m to replace sequences of calls
	to predicates in table_builtin.m with a single extended foreign_proc
	goal whose body just invokes the corresponding macros in sequence.
	That change should improve performance by allowing the variables
	that flow from one tabling primitive to another to stay in x86
	registers, instead of being copied to and from Mercury abstract
	machines registers, which on the x86 aren't real machine registers.
	Benchmarking in Uppsala verified that this is a major cost.

	Mark the foreign types used for tabling as can_pass_as_mercury_type;
	this was the intended use of that assertion. Make them private to the
	module, since the rest of the compiler can now handle this.

	Delete the implementations of the predicates for duplicate checking
	and for returning answers for completed subgoals. Profiling with gprof
	has shown their performance to be critical to the performance of
	minimal model tabling overall, and even with our recent changes,
	the compiler still can't create optimal C code for them. They are
	now implemented with handwritten code in mercury_minimal_model.c.

library/term.m:
	Add two utility predicates for use by table_gen.m.

library/Mmakefile:
	Since much of the implementation of table_builtin.m is now in
	runtime/mercury_tabling_preds.h, make its object files depend
	on that header file.

runtime/mercury_conf_params.h:
runtime/mercury_grade.h:
	Include MR_MINIMAL_MODEL_DEBUG when computing the grade.

runtime/mercury_minimal_model.[ch]:
	Add handwritten code to implement the predicates declared as external
	in table_builtin.m.

	Conform to the new names of the suspension and completion predicates.

	Conform to the presence of debugging fields in tabling data structures
	only if MR_MINIMAL_MODEL_DEBUG is defined.

	Collect a lot more statistics than before.

	Reorder some functions.

	Instead of saving the whole generator stack each time, which the new
	statistics showed to have O(n^2) behavior on some benchmarks, save only
	the segment we need to save.

runtime/mercury_tabling.h:
	Conform to the fact that loopcheck and memo predicates now have
	separate sets of status values, and import mercury_tabling_preds.h.

runtime/mercury_tabling.c:
runtime/mercury_hash_lookup_or_add_body.h:
	Move a huge macro out of mercury_tabling.c to the new file
	mercury_hash_lookup_or_add_body.h for ease of editing, and modify it to
	gather more statistics.

	Make the statistics report easier to read.

runtime/Mmakefile:
	Mention mercury_tabling_preds.h and mercury_hash_lookup_or_add_body.h.

runtime/mercury_wrapper.h:
	Provide a mechanism (--tabling-statistics in MERCURY_OPTIONS)
	that causes the runtime to print tabling statistics at the ends of
	executions, for use in benchmarking.

doc/user_guide.texi:
	Document --tabling-statistics. (Minimal model tabling is not yet
	stable enough to be documented, which is why .dmm isn't documented
	either.)

scripts/canonical_grade.sh-subr:
scripts/init_grade_options.sh-subr:
scripts/parse_grade_options.sh-subr:
scripts/mgnuc.in:
	Implement the new grade component.

trace/mercury_trace.c:
trace/mercury_trace_internal.c:
	Conform to changes in the runtime.

tests/debugger/*.m:
	Avoid now invalid combinations of determinism and evaluation method.

tests/debugger/*.exp:
	Conform to new goal paths in procedures transformed by tabling.

tests/tabling/*.m:
	For tests which had predicate whose determinisms isn't compatible
	with the evaluation method, change the determinism if possible,
	and the evaluation method otherwise, if either is possible.

	Bring these tests up to date with our coding guidelines, since they
	may now appear in papers.

tests/tabling/Mmakefile:
	Disable the tests whose combination of determinism and evaluation
	method is no longer supported, and in which neither one can be changed.

tests/tabling/loopcheck_no_loop.{m,exp}:
	Make this test case tougher.

tests/tabling/test_tabling:
	Make this script more robust in the face of different kinds of
	test case failures.

tests/invalid/loopcheck.{m,err_exp}:
tests/invalid/Mmakefile:
	Test that we get the expected error message for an invalid combination
	of determinism and evaluation method. The new test invalid/loopcheck.m
	is the old test tabling/loopcheck.m.

tests/valid/Mmakefile:
	Use a more general pattern to test for minimal model grades,
	now that we also use .dmm as a grade component.
2004-05-31 04:13:39 +00:00
Zoltan Somogyi
c80d143cc8 The following change is only 98% complete, not 100%.
Estimated hours taken: 120
Branches: main

The following change is only 98% complete, not 100%. I am committing it in
this state because (1) we pass many more test cases in deep profiling grade
with it than without it, and (2) the double maintanance involved in fixing
CVS conflicts is preventing me from doing the last 2%.

Get the deep profiler to work for code that sets up to catch exceptions,
which for the last year or more has included the compiler, and to get it
almost working for code that actually catching exceptions.

The basic problem is that code that throws exceptions will in general cause
several calls to "return" without executing the exit or fail port codes that
the deep profiling transformation inserted into their bodies, and this leaves
the data structure being built by the deep profiling inconsistent. The solution
uses the same approach as we have adopted for the debugger: have the code that
handles the throwing of exceptions simulate a return from each call between
the throw and the catch, updating the deep profiling data structures as needed.

This requires us to be able to walk the stack at runtime not just in debugging
grades but also in deep profiling grades. Since the debugger already has the
mechanisms required for this, we reuse them. The procedure layouts used by the
debugger were designed to have three segments: the procedure stack walk
information, the procedure id, and the execution tracing information. We now
modify this design to make the third segment contain two pointers: to the
execution tracing information (for use by the debugger), and to the procedure's
proc_static structure (for use by deep profiling). Each pointer will be null
unless the pointed-to structure is required by compile-time options.

This common use by the debugger and by deep profiling of the stack-walk
structure and the procedure id structure (which deep profiling used to
generate independently and possibly redundantly) required some rearrangement
of the compiler's version of these data structures.

To make this rearrangement simpler, this diff removes a capability that
we theoretically supported but never used: turning on stack traces without
turning on execution tracing and vice versa. After this diff, stack tracing
is enabled if and only if either execution tracing or deep profiling is
enabled.

The diff also includes improvements in the debugging infrastructure for
debugging deep profiling, which were necessary for the implementation of the
rest of the changes.

compiler/deep_profiling.m:
	The code in exception.m needs to know the locations of the variables
	that we would pass to the exit or fail port code, so it can simulate
	leaving the procedure invocation through the exception port. Without
	this information, throwing an exception leaves the deep profiling
	data structures of the procedure invocations between throw and catch
	in an inconsistent state.

	Deep_profiling.m creates these variables, but it doesn't know where
	they will be at runtime, so it records their identities; the code
	generator will allocate them stack slots and record the numbers of
	these stack slots for placement in the now expanded proc layout
	structures. Deep profiling used to generate static data structures
	separately from the HLDS, but since the code generator now needs
	access to them, we store their information in proc_infos in the HLDS.

	Instead of passing the addresses of proc_static structures to the deep
	profiling port procedures, pass the address of proc_layout structures,
	since the information about the identities of procedures are now stored
	not in the proc_static structure, but in the proc_layout structure
	that points to the proc_static structure.

compiler/hlds_pred.m:
compiler/layout.m:
	Move the definitions of the static data structures generated by deep
	profiling from layout.m to hlds_pred.m, to allow deep_profiling.m
	to store them in proc_infos.

compiler/hlds_pred.m:
compiler/rtti.m:
	Move the definition of rtti_proc_label from rtti.m to hlds_pred.m,
	since some of the new data structures in hlds_pred.m need it. Despite
	its name, the rtti_proc_label type doesn't contain any info that
	doesn't belong in the HLDS.

	Add some information to the rtti_proc_label type that is now needed
	by deep profiling, e.g. record determinisms instead of just code
	models. Record explicitly the outcome of some tests that used to be
	duplicated in more than one place in the compiler, e.g. for whether
	the procedure (as opposed to the predicate) is imported. Change some
	of the field names to be more precise about the field's meaning.

compiler/code_gen.m:
	Transmit the contents of the deep profiling data structures stored in
	the proc_info by deep_profiling.m to continuation_info.m, together
	with the layout structures created for execution tracing and the
	identities of the variables needed for handling exceptions,
	when code generation for a procedure is complete.

	After the goal that generates these variables, save them to stack
	for use by the exception handler.

compiler/hlds_goal.m:
	Add a feature to mark the goal that generates the deep profiling
	variables needed by the exception handler.

compiler/hlds_llds.m:
	Add a utility predicate for new code in code_gen.m

compiler/continuation_info.m:
	Hold the deep profiling information computed by code_gen.m for use by
	stack_layout.m.

compiler/layout.m:
compiler/layout_out.m:
	Update the definitions of the data structures describing procedure
	layouts, and the code writing them out, to reflect the use of some
	parts of procedure layouts by deep profiling as well as debugging.

	Change the layout structures generated by deep profiling to use
	rtti_proc_labels, which are backend independent, instead of
	proc_labels, which are specific to the LLDS backend.

	Conform to the changes in runtime/mercury_stack_layout.h.

compiler/stack_layout.m:
	Generate the updated version of proc_layout structures.

compiler/mercury_compile.m:
compiler/global_data.m:
	Conform to the fact that deep profiling no longer generates layout
	structures separate from proc_infos.

compiler/llds_out.m:
	Register proc_layout structures instead of proc_static structures
	for use by runtime/mercury_deep_profiling.c.

compiler/options.m:
compiler/handle_options.m:
	Rename the require_tracing option as exec_trace, since this more
	directly reflects its meaning.

	Instead of having --debug set both require_tracing and stack_trace,
	make it set (be the user-visible name of) just exec_trace;
	the value of stack_trace is implied.

	Turn off the specialization of deep profiling for self-tail-recursive
	procedures for now. Due to the changes made by this diff in the data
	structures involved in debugging, it cannot be debugged until this
	change has been installed. Handling the full language is more important
	than a specialization that reduces only stack space overheads, not
	runtime overheads.

compiler/compile_target_code.m:
	Conform to the changes in options.m and runtime/mercury_grade.h.

compiler/hlds_data.m:
	Replace the deep_profiling_proc_static cons_id, and its associated tag,
	to deep_profiling_proc_layout, since we now generate addresses of proc
	layout structures, not of proc_static structures.

compiler/code_util.m:
	Simplify some code based on the new info in rtti_proc_labels.

compiler/bytecode_gen.m:
compiler/dependency_graph.m:
compiler/higher_order.m:
compiler/hlds_out.m:
compiler/mercury_to_mercury.m:
compiler/ml_code_util.m:
compiler/ml_unify_gen.m:
compiler/opt_debug.m:
compiler/proc_label.m:
compiler/prog_rep.m:
compiler/rl_exprn.m:
compiler/rtti_out.m:
compiler/rtti_to_mlds.m:
compiler/saved_vars.m:
compiler/switch_util.m:
compiler/unify_gen.m:
	Minor changes to conform to the change from deep_profiling_proc_static
	to deep_profiling_proc_layout, to the change in the structure of
	rtti_proc_labels, to the changes in types of layout.m, and/or to the
	new goal feature.

deep_profiler/measurements.m:
	Reserve space for exception counts.

deep_profiler/html_format.m:
	Add a column for exception counts.

deep_profiler/profile.m:
deep_profiler/read_profile.m:
	Rename the data structures referring to compiler generated unify,
	compare and index predicates to avoid misleading names: they are
	not the only compiler generated predicates.

deep_profiler/read_profile.m:
runtime/mercury_deep_profiling.c:
	Update the string that identifies deep profiling data files.
	This is necessary because the format has changed: it now includes
	information about exception port counts.

library/exception.m:
	In deep profiling grades, execute the exception port code for every
	procedure invocation between a throw and a catch, using the procedure
	layout structures now generated by the compiler for every procedure.
	Rename the function involved to reflect its new, more general purpose.

	Update the definitions of the hand-written proc_static and proc_layout
	structures for the procedures implemented via hand-written C code.

	Indent C preprocessor directives and foreign_procs according to our
	coding standards.

library/profiling_builtin.m:
	Change the parameters of the call port code procedures from proc_static
	to proc_layout. Reach the proc_static structure from the proc_layout
	structure when needed. Include the proc_layout structure in any
	messages from assertion failures.

	Add some conditionally compiled debugging code.

	Give some variables better names.

runtime/mercury_type_info.h:
runtime/mercury_builtin_types.c:
	Move the macros required to create the proc_static structures
	of unify and compare predicates from mercury_type_info.h
	to mercury_builtin_types.c, since the latter is the only file
	that needs them.

	Use the same macros for creating the proc_static structures
	of hand-written unify, compare and compare_reprentation predicates
	as for user defined predicates. This required changing their naming
	scheme.

runtime/mercury_unify_compare_body.h:
	Conform to the new naming scheme.

runtime/mercury_ho_call.c:
	Provide the mechanism for mercury_unify_compare_body.h to conform
	to the new naming scheme.

	Remove the definitions of the proc_static structures for
	hand-written unify, compare and compare_reprentation predicates,
	since these now have to be defined together with the corresponding
	proc_layout structures in mercury_builtin_types.c.

runtime/mercury_builtin_types.[ch]:
	Update the definitions of the hand-written proc_static and proc_layout
	structures for the procedures implemented via hand-written C code,
	and add the required declarations first.

	Handle deep profiling of compare_representation as well as unify
	and compare predicates on builtin types.

	Handle deep profiling of compare_representation on user-defined types,
	since this is done entirely in the runtime, not by compiler generated
	predicates.

runtime/mercury_builtin_types_proc_layouts.h:
	New header file containing the declarations of the proc layout
	structures of the unify, compare and index predicates of builtin types.
	Logically, these declarations belong in mercury_builtin_types.h,
	but putting them there causes problems for the linker; the details
	are explained in the file itself.

runtime/Mmakefile:
	Add the new header file.

runtime/mercury_minimal_model.[ch]:
	Update the definitions of the hand-written proc_static and proc_layout
	structures for the procedures implemented via hand-written C code,
	and add the required declarations first.

runtime/mercury_grade.h:
	Replace the MR_REQUIRE_TRACING grade option with MR_EXEC_TRACING.
	Besides being better named, the MR_EXEC_TRACING option implies
	MR_STACK_TRACE.

	Besides the overall binary compatibility version number, add subsidiary
	version numbers for binary compatibility in deep profiling and
	debugging grades. These will make it easier to bootstrap changes
	(such as this) that affect binary compatibility only in such grades.

runtime/mercury_trace_base.c:
trace/mercury_trace.c:
	Conform to the new names of the configuration parameters.

runtime/mercury_hand_compare_body.h:
runtime/mercury_hand_unify_body.h:
runtime/mercury_hand_unify_compare_body.h:
runtime/mercury_ho_call.c:
tools/make_port_code:
	Pass proc_layout structures instead of proc_static structures
	to deep profiling port routines.

runtime/mercury_conf_param.h:
	Make MR_DEEP_PROFILING as well as MR_EXEC_TRACING imply MR_STACK_TRACE,
	since deep profiling now needs stack tracing. (MR_STACK_TRACE needs
	to be set in this file, because tests in this file depend on knowing
	its value, and this file is among the first files included (in this
	case indirectly) in mercury_imp.h.)

	Document the macros controlling the debugging of deep profiling.

	Enable printing of label names when the relevant deep profiling
	debugging macro is set.

runtime/mercury_debug.c:
runtime/mercury_deep_rec_depth_actions.h:
runtime/mercury_deep_rec_depth_body.h:
runtime/mercury_exception_catch_body.h:
	Get to proc_statics via proc_layouts.

runtime/mercury_deep_call_port_body.c:
runtime/mercury_deep_leave_port_body.c:
	Get to proc_statics via proc_layouts.

	Allow the debugger to disable deep profiling in Mercury code that is
	part of the debugger, not of the user program being executed.

	Add some more assertions.

runtime/mercury_engine.[ch]:
	Add a new debugging flag that controls at runtime whether we generate
	a human readable Deep.debug equivalent to the binary Deep.data files.
	(We already had a mechanism for controlling this at compile time,
	but this isn't flexible enough.)

runtime/mercury_wrapper.c:
	Allow this new debugging flag to be set from MERCURY_OPTIONS.

runtime/mercury_deep_profiling.[ch]:
	Respect this new debugging flag.

	Update the hand-written proc_static structures representing the runtime
	system.

	Print out addresses of proc_layout as well as proc_static structures
	when assertions fail.

	Add a field to the measurement structure for exception port counts,
	and write out this field with the other port counts.

	Remove procedure id information from proc_static structures,
	deep profiling now uses the procedure id in the proc_layout structure.

	Add to proc_static structures fields that specify where, if anywhere,
	the variables needed by exception.m to executed the exception port code
	are in the procedure's stack frame.

	Define a global flag that allows the debugger to disable deep
	profiling in Mercury code that is part of the debugger, not of the
	user program being executed.

	Increase type safety by providing two versions of the function
	for registering proc_layouts, one for the proc_layout structures
	of user-defined predicates and one for unify, compare and index
	predicates.

	Fix a bug that occurs only if MR_DEEP_PROFILING_EXPLICIT_CALL_COUNTS is
	defined (which it usually isn't): the initial call count was wrong.

runtime/mercury_deep_profiling_hand.h:
	Fix a bug: the handwritten code saving deep profiling variables was
	saving them in slots that didn't belong to the relevant stack frame.

	Update to conform to the modified definitions of proc_static structures
	and the fact that we now reach them via proc_layout structures.

runtime/mercury_exception_catch_body.h:
runtime/mercury_stacks.h:
	Fix the other side of the bug in mercury_deep_profiling_hand.h
	by reserving the right number of stack slots in the stack frames
	of the various modes of exception__catch. Make it harder to make
	the same bug in the future by getting the needed info from the
	place in mercury_stacks.h that defines the structure of the relevant
	stack frame.

runtime/mercury_proc_id.h:
	Rename the procedure id structure fields referring to compiler
	generated unify, compare and index predicates: they are not the only
	compiler-generated predicates.

runtime/mercury_stack_layout.h:
	Change procedure layout structures to allow them to be used for deep
	profiling as well as for debugging, as described in the prologue above.

	We don't need the capability to support label layout structures with
	links to misnamed proc layout structures, and supporting it is
	inconvenient, so delete the capability.

runtime/mercury_debug.c:
runtime/mercury_deep_profiling_hand.h:
runtime/mercury_layout_util.c:
runtime/mercury_ml_expand_body.h:
runtime/mercury_stack_trace.c:
runtime/mercury_types.h:
trace/mercury_trace_external.c:
	Conform to the new names of the procedure id structure fields.

runtime/mercury_std.h:
	Add some more arities for MR_PASTE for use in some of the modified
	modules in the runtime.

trace/mercury_trace_internal.c:
	Disable deep profiling actions in Mercury code that is part of the
	debugger, not of the program being debugged.

scripts/init_grade_options.sh-subr:
scripts/parse_grade_options.sh-subr:
	Make changes parallel to the ones in runtime/mercury_grade.h: delete
	--stack-trace as an independent option, and make --debug set its
	own option, not --require-tracing.

scripts/canonical_grade.sh-subr:
scripts/final_grade_options.sh-subr:
scripts/c2init.in:
scripts/mgnuc.in:
scripts/ml.in:
	Conform to the changes in grade options for debugging and for deep
	profiling.

tools/bootcheck:
	If Mmake.stage.{browser,deep,library,runtime,trace}.params exist,
	copy them to become the file Mmake.$dir.params in stage2/$dir
	(where dir is derived from the name of the original file in the obvious
	way). This allows more flexibility in the creation of the stage2;
	for example, it allows some directories (e.g. runtime or library)
	to be compiled with more debugging than other directories (e.g.
	compiler). This may be required because compiling all directories
	with lots of debugging may cause the linker to thrash.

	Add an option, --disable-debug-libs, that clobbers the libraries
	that should be linked in only in debugging grades.

	To conserve disk space, remove Deep.data files created by the bootcheck
	by default. Add an option, --keep-deep-data, to preserve these files.

	Use a consistent mechanism (test -f) for testing the existence of
	all files whose existence is tested.

	When recording modification times, record the modification times
	of some more files.

tests/hard_coded/Mmakefile:
	In deep profiling grades, disable the test cases that we don't now
	pass in such grades, and document the reasons for their failure.

	Fix the misclassification of the write_binary test case.
2004-05-19 04:00:01 +00:00
Fergus Henderson
63f0a3a857 Fix some bugs which caused test case failures in *.rt (--reserve-tag)
Estimated hours taken: 0.5
Branches: main

Fix some bugs which caused test case failures in *.rt (--reserve-tag)
grades.

runtime/mercury_tags.h:
	Define a new macro MR_GET_ENUM_VALUE, for getting the
	value of a Mercury enumeration constant.

runtime/mercury_wrapper.c:
trace/mercury_trace_internal.c:
	When indexing arrays by Mercury enumeration constants,
	call MR_GET_ENUM_VALUE first, in order to strip away the
	reserved tag (if any).
2004-02-12 06:54:59 +00:00
Fergus Henderson
ca36453476 Fix a bug in the implementation of the "-dm" (debug memory) runtime option:
Estimated hours taken: 0.75
Branches: main

Fix a bug in the implementation of the "-dm" (debug memory) runtime option:
it was not printing out the information about the memory zones.

runtime/mercury_memory.c:
runtime/mercury_wrapper.c:
	Don't call debug_memory() at the end of init_memory(),
	because the memory zones haven't been created then.
	Instead, call it in mercury_runtime_init(), after all
	the different memory zones have been initialized.

	(Also, fix an out-of-date comment in mercury_wrapper.c.)
2003-12-30 13:17:14 +00:00
Fergus Henderson
2230ec78d3 Fix an incorrect comment in one of my previous changes
Estimated hours taken: 0.1
Branches: main

runtime/mercury_wrapper.c:
	Fix an incorrect comment in one of my previous changes
	(s/16 Mb/32 Mb/).
2003-10-23 06:51:24 +00:00
Zoltan Somogyi
666c4b785e Move toward the proposed structures for representing type class information at
Estimated hours taken: 32
Branches: main

Move toward the proposed structures for representing type class information at
runtime by adding code for generating the structures corresponding to
base_typeclass_infos. The structures corresponding to typeclass_infos will
be added in a later change.

Register the new data structures in a table at runtime.

Add four new mdb developer commands for checking the contents of the new
type class table, as well as the contents of the existing type constructor
table: class_decl, type_ctor, all_class_decls and all_type_ctors.

compiler/rtti.m:
	Add the data types required to represent the new runtime data
	structures that will eventually replace base_typeclass_infos
	inside the compiler.

	Add the required function symbols to the data types representing both
	the new RTTI data structures themselves and those representing
	references to them.

	Make the required changes to the predicates operating on the modified
	data types, and add some required new predicates.

compiler/rtti_out.m:
	Add code to write out the new data structures for the LLDS backend.

	Make some changes in existing predicates to allow them to be used
	in the new code.

compiler/layout_out.m:
	Factor out some code that is now common with rtti_out.m.

compiler/type_class_info.m:
	A new module to generate the new RTTI data structures.

compiler/backend_libs.m:
	Include the new module.

compiler/options.m:
	Add a new option, --new-type-class-rtti, to control whether we
	invoke the top level predicate of type_class_info.m to generate
	the new type class RTTI structures. We still generate and use
	base_typeclass_infos regardless of the value of this option.

compiler/mercury_compile.m:
	Invoke the code of the new module if --new-type-class-rtti is given.

compiler/opt_debug.m:
	Add code to dump descriptions of the new rtti_ids.

compiler/mlds_to_gcc.m:
compiler/rtti_to_mlds.m:
	Handle the new alternatives in the rtti data types, mostly by throwing
	exceptions. The actual code should be written later by Fergus.

compiler/pseudo_type_info.m:
	Module qualify the names of builtin types when generating
	pseudo-typeinfos for them. This makes the naming scheme more regular.

compiler/base_typeclass_info.m:
compiler/notes/type_class_transformation.html:
	Document the impending obsolescence of these files.

compiler/notes/work_in_progress.html:
	List type class RTTI as work in progress.

library/list.m:
	Add a utility predicate for use by compiler/rtti_out.m.

runtime/mercury_typeclass_info.h:
	Make some changes in the C data types representing type class
	information that I discovered to be necessary or advantageous
	in the process of generating values of those types automatically.

	Rename some types to make their names be better documentation.

	Change some arrays of pointers to structures into arrays of structures,
	where the structures at different array indexes are the same size.

	Removing consts that rtti_out.m supplies automatically avoids
	duplicate const errors from the C compiler.

	Add #includes to make the file namespace clean.

	Protect against multiple inclusion.

runtime/mercury_typeclass_info_example.c:
	Remove this file. After the changes to mercury_typeclass_info.h, its
	contents are no longer correct examples of the structures in
	mercury_typeclass_info.h, and since the compiler can now generate
	those structures automatically, hand-written examples no longer serve
	any useful pupose.

runtime/mercury_types.h:
	Add a new type, MR_CodePtr, for use in mercury_typeclass_info.h.
	The compiler predicate tc_rtti_name_type wants single-word names
	for types.

runtime/mercury_imp.h:
	#include mercury_typeclass_info.h.

runtime/mercury_type_tables.[ch]:
	Add functions to register and to look up type class declarations and
	type class instances.

	Add the functions and data structures required to look up all type
	constructors and all type classes. The debugger uses these to support
	the commands that let the programmer check the contents of these
	tables.

	Eventually, we should be able to use the type class tables to test
	whether a vector of types is a member of a given type class.

runtime/mercury_wrapper.c:
runtime/mercury_type_info.[ch]:
	Move the array of type_ctor_rep names from the mercury_wrapper module
	to the mercury_type_info module, and make it always-defined and public;
	the debugger also needs access to it now.

runtime/Mmakefile:
	Add mercury_typeclass_info.h to the list of header files that other
	files depend on.

trace/mercury_trace_internal.c:
	Add four new mdb commands: class_decl, type_ctor, all_class_decls
	and all_type_ctors.

	Make some existing code follow our coding conventions.

doc/user_guide.texi:
doc/mdb_categories:
	Document the four new mdb commands.

doc/reference_manual.texi:
	Document (in a comment) the compiler's reliance on each type in an
	instance declaration containing exactly one type constructor.

tests/debugger/class_decl.{m,inp,exp}:
	A new test case to test the new mdb commands.

tests/debugger/Mmakefile:
tests/debugger/Mercury.options:
	Add the new test case.

tests/debugger/completion.exp:
	Expect the new commands to appear in the command name completion.

tests/debugger/mdb_command_test.inp:
	Test the documentation of the new mdb commands.
	Expect the new commands to appear in the command name completion.
2003-10-23 02:02:45 +00:00
Fergus Henderson
c743626923 Various bug fixes for accurate GC in LLDS grades:
Estimated hours taken: 4
Branches: main

Various bug fixes for accurate GC in LLDS grades:

runtime/mercury_wrapper.c:
	Fix two bugs in my last change:
	- use MR_NATIVE_GC rather than the non-existent MR_ACCURATE_GC
	- use %lf rather than %f when calling scanf() for a double

runtime/mercury_accurate_gc.c:
	- Fix some bugs with traversing the nondet stack.
	- Make sure that we round the active heap size up to a multiple
	  of the page size, otherwise mprotect() won't work.
	- Avoid some casts by using type `MR_Code **' rather than
	  `MR_Word *' for the saved_success_location variable.
	- Comment out some unused code.

runtime/mercury_stacks.h:
	Add MR_curfr_slot_addr(), which is like MR_curfr_slot() except that
	it returns the slot's address, for use by mercury_accurate_gc.c.
	(Using "&MR_curfr_slot(...)" results in an "invalid lvalue" error
	from GCC, despite the use of MR_LVALUE_CAST in its definition.)

runtime/mercury_stack_trace.h:
	Add some comments.

runtime/mercury_stack_trace.c:
	Fix some incorrect indentation.

compiler/stack_layout.m:
	Fix a cut-and-paste error.
2003-10-22 08:50:15 +00:00
Fergus Henderson
72a1de2b8a Various improvements for accurate GC in LLDS grades:
Estimated hours taken: 12
Branches: main

Various improvements for accurate GC in LLDS grades:

    - allow the active heap size to vary
      (XXX currently we still allocate a fixed-size heap, and allow
      the active heap size to vary within that; it would be better
      to avoid that, by reallocating a bigger heap if the heap
      fills up)

    - some bug fixes.

runtime/mercury_wrapper.c:
	Increase the default heap size from 4Mb to 32Mb.
	This is OK because we only touch the parts of it that we use.

	If accurate GC is enabled, set the other parameters
	(MR_heap_redzone_size for LLDS, MR_heap_margin for MLDS)
	so that initially we still only use 4Mb of the heap
	before doing (the first) garbage collection.

runtime/mercury_wrapper.h:
runtime/mercury_wrapper.c:
	Add a new runtime option --heap-expansion-factor,
	for use by mercury_accurate_gc.c.

runtime/mercury_accurate_gc.c:
	Only allocate forwarding pointer bitmap entries for the part of
	the heap which has been used, not the whole heap.  This is to
	avoid allocating (and touching) an unnecessarily large bitmap
	in cases where we have allocated a large amount of address space
	to the heap, but are only using a small part of it before doing
	each GC.

	For the LLDS back-end, recompute the heap red zone size after
	each collection (using MR_heap_expansion_factor).

	In MR_schedule_agc(), handle the case where entry_label and/or
	proc_layout are NULL.

	Also, add some comments.

runtime/mercury_memory_zones.c:
	Change MR_reset_redzone() so that it can handle changes in the
	size of the red zone.  In particular, make sure that we unprotect
	all of the normal area, as well as protecting the red zone.

runtime/mercury_label.c:
	Fix two bugs in MR_prev_entry_by_addr(): it was not correctly
	handling the case where the entry table was empty, and it was
	not correctly handling the case where the address searched for
	was higher than any address in the entry table.

runtime/mercury_goto.h:
	For native GC grades, record the addresses of the end of modules
	in the entry table, so that we know where each procedure finishes when
	mapping from instruction pointer values to stack layout entries.
	Without this, we might think that the following C function was
	actually part of the preceding Mercury procedure, and then incorrectly
	use the stack layout of the Mercury procedure if we happened to
	get a heap overflow signal (SIGSEGV) while in that C function.
2003-10-22 05:56:08 +00:00
Zoltan Somogyi
f7dae76f87 Remove a long unused global variable.
Estimated hours taken: 0.1
Branches: main

runtime/mercury_wrapper.[ch]:
	Remove a long unused global variable.
2003-10-20 07:45:09 +00:00
Zoltan Somogyi
f007b45df8 Implement the infrastructure for term size profiling.
Estimated hours taken: 400
Branches: main

Implement the infrastructure for term size profiling. This means adding two
new grade components, tsw and tsc, and implementing them in the LLDS code
generator. In grades including tsw (term size words), each term is augmented
with an extra word giving the number of heap words it contains; in grades
including tsc (term size cells), each term is augmented with an extra word
giving the number of heap cells it contains. The extra word is at the start,
at offset -1, to leave almost all of the machinery for accessing the heap
unchanged.

For now, the only way to access term sizes is with a new mdb command,
"term_size <varspec>". Later, we will use term sizes in conjunction with
deep profiling to do experimental complexity analysis, but that requires
a lot more research. This diff is a necessary first step.

The implementation of term size profiling consists of three main parts:

- a source-to-source transform that computes the size of each heap cell
  when it is constructed (and increments it in the rare cases when a free
  argument of an existing heap cell is bound),

- a relatively small change to the code generator that reserves the extra
  slot in new heap cells, and

- extensions to the facilities for creating cells from C code to record
  the extra information we now need.

The diff overhauls polymorphism.m to make the source-to-source transform
possible. This overhaul includes separating type_ctor_infos and type_infos
as strictly as possible from each other, converting type_ctor_infos into
type_infos only as necessary. It also includes separating type_ctor_infos,
type_infos, base_typeclass_infos and typeclass_infos (as well as voids,
for clarity) from plain user-defined type constructors in type categorizations.
This change needs this separation because values of those four types do not
have size slots, but they ought to be treated specially in other situations
as well (e.g. by tabling).

The diff adds a new mdb command, term_size. It also replaces the proc_body
mdb command with new ways of using the existing print and browse commands
("print proc_body" and "browse proc_body") in order to make looking at
procedure bodies more controllable. This was useful in debugging the effect
of term size profiling on some test case outputs. It is not strictly tied
to term size profiling, but turns out to be difficult to disentangle.

compiler/size_prof.m:
	A new module implementing the source-to-source transform.

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

compiler/transform_hlds.m:
	Include size_prof as a submodule of transform_hlds.

compiler/mercury_compile.m:
	If term size profiling is enabled, invoke its source-to-source
	transform.

compiler/hlds_goal.m:
	Extend construction unifications with an optional slot for recording
	the size of the term if the size is a constant, or the identity of the
	variable holding the size, if the size is not constant. This is
	needed by the source-to-source transform.

compiler/quantification.m:
	Treat the variable reference that may be in this slot as a nonlocal
	variable of construction unifications, since the code generator needs
	this.

compiler/compile_target_code.m:
	Handle the new grade components.

compiler/options.m:
	Implement the options that control term size profiling.

doc/user_guide.texi:
	Document the options and grade components that control term size
	profiling, and the term_size mdb command. The documentation is
	commented out for now.

	Modify the wording of the 'u' HLDS dump flag to include other details
	of unifications (e.g. term size info) rather than just unification
	categories.

	Document the new alternatives of the print and browse commands. Since
	they are for developers only, the documentation is commented out.

compiler/handle_options.m:
	Handle the implications of term size profiling grades.

	Add a -D flag value to print HLDS components relevant to HLDS
	transformations.

compiler/modules.m:
	Import the new builtin library module that implements the operations
	needed by term size profiling automatically in term size profiling
	grades.

	Switch the predicate involved to use state var syntax.

compiler/prog_util.m:
	Add predicates and functions that return the sym_names of the modules
	needed by term size profiling.

compiler/code_info.m:
compiler/unify_gen.m:
compiler/var_locn.m:
 	Reserve an extra slot in heap cells and fill them in in unifications
	marked by size_prof.

compiler/builtin_ops.m:
	Add term_size_prof_builtin.term_size_plus as a builtin, with the same
	implementation as int.+.

compiler/make_hlds.m:
	Disable warnings about clauses for builtins while the change to
	builtin_ops is bootstrapped.

compiler/polymorphism.m:
	Export predicates that generate goals to create type_infos and
	type_ctor_infos to add_to_construct.m. Rewrite their documentation
	to make it more detailed.

	Make orders of arguments amenable to the use of state variable syntax.

	Consolidate knowledge of which type categories have builtin unify and
	compare predicates in one place.

	Add code to leave the types of type_ctor_infos alone: instead of
	changing their types to type_info when used as arguments of other
	type_infos, create a new variable of type type_info instead, and
	use an unsafe_cast. This would make the HLDS closer to being type
	correct, but this new code is currently commented out, for two
	reasons. First, common.m is currently not smart enough to figure out
	that if X and Y are equal, then similar unsafe_casts of X and Y
	are also equal, and this causes the compiler do not detect some
	duplicate calls it used to detect. Second, the code generators
	are also not smart enough to know that if Z is an unsafe_cast of X,
	then X and Z do not need separate stack slots, but can use the same
	slot.

compiler/type_util.m:
	Add utility predicates for returning the types of type_infos and
	type_ctor_infos, for use by new code in polymorphism.m.

	Move some utility predicates here from other modules, since they
	are now used by more than one module.

	Rename the type `builtin_type' as `type_category', to better reflect
	what it does. Extend it to put the type_info, type_ctor_info,
	typeclass_info, base_typeclass_info and void types into categories
	of their own: treating these types as if they were a user-defined
	type (which is how they used to be classified) is not always correct.
	Rename the functor polymorphic_type to variable_type, since types
	such as list(T) are polymorphic, but they fall into the user-defined
	category. Rename user_type as user_ctor_type, since list(int) is not
	wholly user-defined but falls into this category. Rename pred_type
	as higher_order_type, since it also encompasses functions.

	Replace code that used to check for a few of the alternatives
	of this type with code that does a full switch on the type,
	to ensure that they are updated if the type definition ever
	changes again.

compiler/pseudo_type_info.m:
	Delete a predicate whose updated implementation is now in type_util.m.

compiler/mlds_to_c.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_il.m:
compiler/mlds_to_java.m:
	Still treat type_infos, type_ctor_infos, typeclass_infos and
	base_typeclass_infos as user-defined types, but prepare for when
	they won't be.

compiler/hlds_pred.m:
	Require interface typeinfo liveness when term size profiling is
	enabled.

	Add term_size_profiling_builtin.increase_size as a
	no_type_info_builtin.

compiler/hlds_out.m:
	Print the size annotations on unifications if HLDS dump flags call
	for unification details. (The flag test is in the caller of the
	modified predicate.)

compiler/llds.m:
	Extend incr_hp instructions and data_addr_consts with optional fields
	that allow the code generator to refer to N words past the start of
	a static or dynamic cell. Term size profiling uses this with N=1.

compiler/llds_out.m:
	When allocating memory on the heap, use the macro variants that
	specify an optional offset, and specify the offset when required.

compiler/bytecode_gen.m:
compiler/dense_switch.m:
compiler/dupelim.m:
compiler/exprn_aux.m:
compiler/goal_form.m:
compiler/goal_util.m:
compiler/higher_order.m:
compiler/inst_match.m:
compiler/intermod.m:
compiler/jumpopt.m:
compiler/lambda.m:
compiler/livemap.m:
compiler/ll_pseudo_type_info.m:
compiler/lookup_switch.m:
compiler/magic_util.m:
compiler/middle_rec.m:
compiler/ml_code_util.m:
compiler/ml_switch_gen.m:
compiler/ml_unify_gen.m:
compiler/mlds.m:
compiler/mlds_to_c.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_il.m:
compiler/mlds_to_java.m:
compiler/modecheck_unify.m:
compiler/opt_debug.m:
compiler/opt_util.m:
compiler/par_conj_gen.m:
compiler/post_typecheck.m:
compiler/reassign.m:
compiler/rl.m:
compiler/rl_key.m:
compiler/special_pred.m:
compiler/stack_layout.m:
compiler/static_term.m:
compiler/string_switch.m:
compiler/switch_gen.m:
compiler/switch_util.m:
compiler/table_gen.m:
compiler/term_util.m:
compiler/type_ctor_info.m:
compiler/unused_args.m:
compiler/use_local_vars.m:
	Minor updates to conform to the changes above.

library/term_size_prof_builtin.m:
	New module containing helper predicates for term size profiling.
	size_prof.m generates call to these predicates.

library/library.m:
	Include the new module in the library.

doc/Mmakefile:
	Do not include the term_size_prof_builtin module in the library
	documentation.

library/array.m:
library/benchmarking.m:
library/construct.m:
library/deconstruct.m:
library/io.m:
library/sparse_bitset.m:
library/store.m:
library/string.m:
	Replace all uses of MR_incr_hp with MR_offset_incr_hp, to ensure
	that we haven't overlooked any places where offsets may need to be
	specified.

	Fix formatting of foreign_procs.

	Use new macros defined by the runtime system when constructing
	terms (which all happen to be lists) in C code. These new macros
	specify the types of the cell arguments, allowing the implementation
	to figure out the size of the new cell based on the sizes of its
	fields.

library/private_builtin.m:
	Define some constant type_info structures for use by these macros.
	They cannot be defined in the runtime, since they refer to types
	defined in the library (list.list and std_util.univ).

util/mkinit.c:
	Make the addresses of these type_info structures available to the
	runtime.

runtime/mercury_init.h:
	Declare these type_info structures, for use in mkinit-generated
	*_init.c files.

runtime/mercury_wrapper.[ch]:
	Declare and define the variables that hold these addresses, for use
	in the new macros for constructing typed lists.

	Since term size profiling can refer to a memory cell by a pointer
	that is offset by one word, register the extra offsets with the Boehm
	collector if is being used.

	Document the incompatibility of MR_HIGHTAGS and the Boehm collector.

runtime/mercury_tags.h:
	Define new macros for constructing typed lists.

	Provide macros for preserving the old interface presented by this file
	to the extent possible. Uses of the old MR_list_cons macro will
	continue to work in grades without term size profiling. In term
	size profiling grades, their use will get a C compiler error.

	Fix a bug caused by a missing backslash.

runtime/mercury_heap.h:
	Change the basic macros for allocating new heap cells to take
	an optional offset argument. If this is nonzero, the macros
	increment the returned address by the given number of words.
	Term size profiling specifies offset=1, reserving the extra
	word at the start (which is ignored by all components of the
	system except term size profiling) for holding the size of the term.

	Provide macros for preserving the old interface presented by this file
	to the extent possible. Since the old MR_create[123] and MR_list_cons
	macros did not specify type information, they had to be changed
	to take additional arguments. This affects only hand-written C code.

	Call new diagnostic macros that can help debug heap allocations.

	Document why the macros in this files must expand to expressions
	instead of statements, evn though the latter would be preferable
	(e.g. by allowing them to declare and use local variables without
	depending on gcc extensions).

runtime/mercury_debug.[ch]:
	Add diagnostic macros to debug heap allocations, and the functions
	behind them if MR_DEBUG_HEAP_ALLOC is defined.

	Update the debugging routines for hand-allocated cells to print the
	values of the term size slot as well as the other slots in the relevant
	grades.

runtime/mercury_string.h:
	Provide some needed variants of the macro for copying strings.

runtime/mercury_deconstruct_macros.h:
runtime/mercury_type_info.c:
	Supply type information when constructing terms.

runtime/mercury_deep_copy_body.h:
	Preserve the term size slot when copying terms.

runtime/mercury_deep_copy_body.h:
runtime/mercury_ho_call.c:
runtime/mercury_ml_expand_body.h:
	Use MR_offset_incr_hp instead of MR_incr_hp to ensure that all places
	that allocate cells also allocate space for the term size slot if
	necessary.

	Reduce code duplication by using a now standard macro for copying
	strings.

runtime/mercury_grade.h:
	Handle the two new grade components.

runtime/mercury_conf_param.h:
	Document the C macros used to control the two new grade components,
	as well as MR_DEBUG_HEAP_ALLOC.

	Detect incompatibilities between high level code and profiling.

runtime/mercury_term_size.[ch]:
	A new module to house a function to find and return term sizes
	stored in heap cells.

runtime/mercury_proc_id.h:
runtime/mercury_univ.h:
	New header files. mercury_proc_id.h contains the (unchanged)
	definition of MR_Proc_Id, while mercury_univ.h contains the
	definitions of the macros for manipulating univs that used to be
	in mercury_type_info.h, updated to use the new macros for allocating
	memory.

	In the absence of these header files, the following circularity
	would ensue:

	mercury_deep_profiling.h includes mercury_stack_layout.h
		- needs definition of MR_Proc_Id
	mercury_stack_layout.h needs mercury_type_info.h
		- needs definition of MR_PseudoTypeInfo
	mercury_type_info.h needs mercury_heap.h
		- needs heap allocation macros for MR_new_univ_on_hp
	mercury_heap.h includes mercury_deep_profiling.h
		- needs MR_current_call_site_dynamic for recording allocations

	Breaking the circular dependency in two places, not just one, is to
	minimize similar problems in the future.

runtime/mercury_stack_layout.h:
	Delete the definition of MR_Proc_Id, which is now in mercury_proc_id.h.

runtime/mercury_type_info.h:
	Delete the macros for manipulating univs, which are now in
	mercury_univ.h.

runtime/Mmakefile:
	Mention the new files.

runtime/mercury_imp.h:
runtime/mercury.h:
runtime/mercury_construct.c:
runtime/mercury_deep_profiling.h:
	Include the new files at appropriate points.

runtime/mercury.c:
	Change the names of the functions that create heap cells for
	hand-written code, since the interface to hand-written code has
	changed to include type information.

runtime/mercury_tabling.h:
	Delete some unused macros.

runtime/mercury_trace_base.c:
runtime/mercury_type_info.c:
	Use the new macros supplying type information when constructing lists.

scripts/canonical_grade_options.sh-subr:
	Fix an undefined sh variable bug that could cause error messages
	to come out without identifying the program they were from.

scripts/init_grade_options.sh-subr:
scripts/parse_grade_options.sh-subr:
scripts/canonical_grade_options.sh-subr:
scripts/mgnuc.in:
	Handle the new grade components and the options controlling them.

trace/mercury_trace_internal.c:
	Implement the mdb command "term_size <varspec>", which is like
	"print <varspec>", but prints the size of a term instead of its value.
	In non-term-size-profiling grades, it prints an error message.

	Replace the "proc_body" command with optional arguments to the "print"
	and "browse" commands.

doc/user_guide.tex:
	Add documentation of the term_size mdb command. Since the command is
	for implementors only, and works only in grades that are not yet ready
	for public consumption, the documentation is commented out.

	Add documentation of the new arguments of the print and browse mdb
	commands. Since they are for implementors only, the documentation
	is commented out.

trace/mercury_trace_vars.[ch]:
	Add the functions needed to implement the term_size command, and
	factor out the code common to the "size" and "print"/"browse" commands.

	Decide whether to print the name of a variable before invoking the
	supplied print or browse predicate on it based on a flag design for
	this purpose, instead of overloading the meaning of the output FILE *
	variable. This arrangement is much clearer.

trace/mercury_trace_browse.c:
trace/mercury_trace_external.c:
trace/mercury_trace_help.c:
	Supply type information when constructing terms.

browser/program_representation.m:
	Since the new library module term_size_prof_builtin never generates
	any events, mark it as such, so that the declarative debugger doesn't
	expect it to generate any.

	Do the same for the deep profiling builtin module.

tests/debugger/term_size_words.{m,inp,exp}:
tests/debugger/term_size_cells.{m,inp,exp}:
	Two new test cases, each testing one of the new grades.

tests/debugger/Mmakefile:
	Enable the two new test cases in their grades.

	Disable the tests sensitive to stack frame sizes in term size profiling
	grades.

tests/debugger/completion.exp:
	Add the new "term_size" mdb command to the list of command completions,
	and delete "proc_body".

tests/debugger/declarative/dependency.{inp,exp}:
	Use "print proc_body" instead of "proc_body".

tests/hard_coded/nondet_c.m:
tests/hard_coded/pragma_inline.m:
	Use MR_offset_incr_hp instead of MR_incr_hp to ensure that all places
	that allocate cells also allocate space for the term size slot if
	necessary.

tests/valid/Mmakefile:
	Disable the IL tests in term size profiling grades, since the term size
	profiling primitives haven't been (and probably won't be) implemented
	for the MLDS backends, and handle_options causes a compiler abort
	for grades that combine term size profiling and any one of IL, Java
	and high level C.
2003-10-20 07:29:59 +00:00
Zoltan Somogyi
83c028e080 Double the default size of the nondet stack.
Estimated hours taken: 0.1
Branches: main

runtime/mercury_wrapper.c:
	Double the default size of the nondet stack. This is needed to allow
	a compiler compiled in a debugging grade to compile options.m. Since
	the nondet stack is still much smaller than the det stack, the space
	impact is negligible.
2003-10-16 05:26:38 +00:00
Zoltan Somogyi
3e766fcd11 Print streams sensibly in the debugger.
Estimated hours taken: 6
Branches: main

Print streams sensibly in the debugger.

runtime/mercury_library_types.h:
	Define MercuryFilePtr as a shorthand for MercuryFile *.

library/io.m:
	Define a user-friendly representation for streams that includes not
	just the stream's name but all the info about the stream that user
	using mdb may wish to know about the stream, as well as a unique stream
	id.

	Make the changes required to maintain this improved stream database.
	If the program is being executed under mdb, then do not ever delete
	items from the stream database, since e.g. the declarative debugger
	may need to print the stream's representation even after the stream
	is closed. (If executing outside mdb, then we delete a stream's entry
	from the stream database when the stream is closed, as before.)

	To allow the debugger to detect which variables are I/O streams,
	change the stream types from being equivalent to c_pointer (and thus
	indistinguishable from other c_pointers) to their own type. Implement
	this type as MercuryFilePtr in the C backend. In the IL backend, we
	represent it as Object[], the minimum representation change possible.

	Use the C type definition to get rid of many casts.

	When writing streams, write the user-friendly representation, not
	a meaningless <<c_pointer>>.

runtime/mercury_init.h:
runtime/mercury_wrapper.[ch]:
runtime/mercury_layout_util.c:
	The change in stream's representation changes the types of some of the
	arguments of functions exported to C from io.m; conform to those
	changes.

browser/browse.m:
browser/sized_pretty.m:
	In each of the mechanisms that the debugger can use to display terms,
	pass along the stream name database.

browser/browser_info.m:
	When deconstructing terms that are streams, return the stream's
	user-friendly id, not a c_pointer.

browser/browse_test.m:
	Update this test program to test the new way of printing streams.

runtime/mercury_trace_base.[ch]:
	Define the MR_trace_ever_enabled variable to let io.m know whether
	it is allowed to ever discard stream info.

runtime/mercury_init.h:
runtime/mercury_wrapper.[ch]:
	Update the types of the functions dealing with streams to use
	MercuryFilePtr to refer to streams instead of MR_Word. These functions
	are implemented by Mercury predicates exported to C.

runtime/mercury_wrapper.c:
	Set MR_trace_ever_enabled to true when execution tracing is enabled.
	This is the only assigment to MR_trace_ever_enabled after
	initialization to the default (false).

tests/debugger/declarative/io_stream_test.{m,inp,exp,exp}:
	A new test case to test the debugger's printing of I/O streams.

tests/debugger/declarative/Mmakefile:
	Enable the new test case.
2003-09-14 22:24:41 +00:00
Simon Taylor
ea33d1945c The Aditi API has been re-implemented. This change updates
Estimated hours taken: 40
Branches: main

The Aditi API has been re-implemented. This change updates
the Mercury->Aditi interface to work with the new API.

compiler/aditi_builtin_ops.m:
	Pass aditi__states to the builtin predicates implementing
	calls to Aditi procedures.

compiler/mode_util.m:
	Add a function aditi_ui_mode.

compiler/type_util.m:
	Add a function aditi_state_type.

runtime/mercury_wrapper.{c,h}:
util/mkinit.c:
	Pass the connection and a transaction in which to
	store the Aditi-RL modules.

extras/aditi/aditi.m:
extras/aditi/aditi_private_builtin.m:
util/mkinit.c:
	Use the new API.
2003-08-23 13:31:05 +00:00
Zoltan Somogyi
579f7ff40e Define a new debugging flag whose purpose is to allow an mdb command,
Estimated hours taken: 0.2
Branches: main

runtime/mercury_engine.[ch]:
	Define a new debugging flag whose purpose is to allow an mdb command,
	"flag enabled on", to turn on low level debugging if the
	executable was compiled with the appropriate options.

runtime/mercury_debug.c:
	When recomputing MR_lld_print_enabled, respect the new debugging flag.

runtime/mercury_wrapper.c:
	Document the new condition for enabling low level debugging
	implemented by the change to mercury_debug.c.
2003-06-01 06:52:36 +00:00
Zoltan Somogyi
50b174b910 Add an MR_ prefix.
Estimated hours taken: 0.1
Branches: main

runtime/mercury_conf_param.h:
runtime/mercury_regs.h:
runtime/mercury_wrapper.c:
	Add an MR_ prefix.
2003-04-10 05:51:05 +00:00
Zoltan Somogyi
168500343c This change adds new facilities for debugging minimal model tabling, and
Estimated hours taken: 160
Branches: main

This change adds new facilities for debugging minimal model tabling, and
has several bug fixes found with the aid of those facilities. Most of the
diff affects the behavior of the system only in minimal model grades and/or
when debugging flags are defined.

compiler/ite_gen.m:
	In minimal model grades, surround the conditions of if-then-elses
	with calls to three functions. These functions detect when a
	condition fails due to one or more suspensions, and abort the
	program. (After resumptions, the condition may actually have
	solutions, but by then the computation has committed to the wrong
	path.)

compiler/table_gen.m:
	Change the program transformation for model_non predicates
	to use a switch instead of nested if-then-elses, to avoid the
	overhead of wrapping the condition. The version with switches
	is also a bit easier to debug.

	The transformation for model_det and model_semi predicates
	stays as before, because for such predicates finding the status
	(which we want to switch on) requires computation, not just a lookup.

	Switch to state variable syntax in the affected predicates.

	Make the error message for an internal error in loopcheck predicates
	more precise.

	Mark the code fragments that modify tabling data structures as impure
	and code fragments that examine tabling data structures as semipure.

runtime/mercury_stacks.[ch]:
	Implement the new stack of possibly negated contexts that we use
	to detect false failures due to suspensions in negated contexts.

	Fix a bug: don't refer to MR_cut_stack[-1].

	Shorten the name of the generator stack.

runtime/mercury_context.[ch]:
runtime/mercury_memory.c:
runtime/mercury_wrapper.[ch]:
	Allocate memory for the new stack of possibly negated contexts.

	Use the shortened name of the generator stack.

runtime/mercury_regorder.h:
	Allocate a pointer for the new stack of possibly negated contexts.

runtime/mercury_minimal_model.[ch]:
	A new module holding the part of mercury_tabling.[ch]
	that is specific to minimal model tabling. This version contains
	tools to help debugging of minimal model tabling, as well as some
	bug fixes found with the aid of those tools.

runtime/mercury_tabling.[ch]:
	Remove the code moved to mercury_minimal_model.[ch], and add the
	code moved here from trace/mercury_trace_internal.c.

	Add prefixes to a bunch of structure fields to make it easier
	to read code accessing those fields.

	Add mechanisms to allocate and copy tabling structures with type
	safety.

runtime/mercury_imp.h:
	#include the new header file, if it is needed.

runtime/Mmakefile:
	Mention the new module, and fix sortedness errors.

runtime/mercury_stack_trace.c:
	Fix a bug that sometimes caused stack traces to abort in minimal model
	grades: they were trying to get layout information from labels
	that do not have them, such as do_fail.

	If MR_TABLE_DEBUG is defined, print the locations of stack frames
	when doing stack dumps.

runtime/mercury_trace_base.h:
	Export to mercury_stack_trace.c the labels that we use to let the
	debugger get control at redos and fails, since they don't have
	layout information.

runtime/mercury_types.h:
	Move typedefs here from mercury_tabling.h, and add typedefs for some
	newly added types.

runtime/mercury_engine.[ch]:
	Add a table mapping debugging flags to their offsets in the
	MR_debugflag array, for use in the debugger.

runtime/mercury_misc.c:
	Make the formatting of det stack pointers the same as nondet stack
	pointers in debugging output.

runtime/mercury_debug.[ch]:
	Add conditionally compiled debugging output when creating temp frames
	on the nondet stack.

library/table_builtin.m:
	Conform to the new names of some fields.

	Add a predicate to return the status of a subgoal.

	Add conditionally compiled debugging code.

library/Mmakefile:
	Make table_builtin.m depend on runtime/mercury_minimal_model.h.

trace/mercury_trace.c:
	Conform to the new names of some fields.

trace/mercury_trace_internal.c:
	Add two new mdb commands, to print the cut stack and the new possibly
	negated context stack.

	Add two new mdb commands to print a subgoal and a consumer.

	Move some of the code to print tabling-related
	data structures to runtime/mercury_tabling.[ch].

	Add a new mdb command to report the values of debugging flags and
	to set and clear them. Previously, one had to turn on these debugging
	flags with environment variables, which were problematic because they
	turned on diagnostic printouts even in Mercury programs that *weren't*
	being debugged, such as the Mercury compiler when being used to
	generate the program to be debugged. Now the flags can be turned on
	from a .mdbrc file, which eliminates much setting and unsetting of
	environment variables.

doc/user_guide.tex:
	Document the new mdb commands.

tests/debugger/mdb_command_test.inp:
	Test the documentation of the new mdb commands.

tests/debugger/completion.exp:
	Expect the new commands in the command completion test.

tests/debugger//nondet_stack.exp*:
	Expect the new format of det stack pointers.

tests/debugger/all_solutions.exp3:
tests/debugger/exception_value.exp3:
tests/debugger/declarative/catch.exp3:
tests/debugger/declarative/ho5.exp3:
tests/debugger/declarative/throw.exp3:
	New expected test cases for use in minimal model grades. They
	differ from existing expected output files only in the precise
	phrasing of error messages.

tests/debugger/declarative/Mmakefile:
	Disable the untraced_subgoal test case in .mm grades, since we don't
	pass it yet.

tests/tabling/Mmakefile:
	Enable the mday test case, now that we pass it.
2003-03-18 16:39:01 +00:00
Fergus Henderson
4d625d71fe Fix bugs in Pete's last change.
Estimated hours taken: 0.1
Branches: main

Fix bugs in Pete's last change.

runtime/mercury_wrapper.c:
	#include "mercury_thread.h", since this file references
	MR_debug_threads which is declared there.

runtime/mercury_thread.h:
	Move the declarations of MR_mutex_* and MR_cond_*
	inside `#if MR_THREAD_SAFE', since they refer to
	the MercuryLock and MercuryCond types which are only
	defined in the MR_THREAD_SAFE case.
2003-03-03 16:30:44 +00:00
Peter Ross
9e07789cc1 Allow one to turn thread debugging on at runtime.
Estimated hours taken: 1
Branches: main, release

Allow one to turn thread debugging on at runtime.
However only modules which are compiled with MR_DEBUG_THREADS will
have debugging messages output.

runtime/mercury_thread.c:
	Add MR_debug_threads global variable which is used to control
	whether debugging messages are output.
	Always include the debug version of lock, unlock, signal and
	wait in the runtime library.

runtime/mercury_thread.h:
	When MR_DEBUG_THREADS is defined, conditionally choose using
	the MR_debug_threads global variable between the debug and the
	pthread library versions of lock, unlock, signal and wait.

runtime/mercury_wrapper.c:
	Parse the --debug-threads option in the MERCURY_OPTIONS
	environment variable.

doc/user_guide.texi:
	Document --debug-threads.
2003-03-03 14:58:34 +00:00
Fergus Henderson
d104660072 Fix an out-of-date comment.
Estimated hours taken: 0.1
Branches: main

runtime/mercury_wrapper.c:
	Fix an out-of-date comment.
2003-03-03 07:46:04 +00:00
Zoltan Somogyi
1315102d7c Fix several occurrences of a bug that prevented the compiler from passing
Estimated hours taken: 20
Branches: main

Fix several occurrences of a bug that prevented the compiler from passing
all the tests in deep profiling grades. We now pass all the tests in deep
profiling grades.

Some additional changes were useful in tracking this bug down. Using C types
to represent deep profiling data structures allowed us to delete a bunch of
casts and thus eliminate them as potential bug locations. Another was to fix
some bugs in low level debugging support.

In light of the fragility of the deep profiling invariants, always check them
when writing out deep profiling data files. Since mdprof depends on these
invariants, they have to be checked somewhere, and we already have code for the
checks in the runtime.

Reenable tail recursion support in deep profiling grades, since it now works.
(The bug this change fixes used to occur most in tail recursive procedures,
which is why previously I turned it off.)

compiler/options.m:
	Reenable tail recursion support in deep profiling grades.

runtime/mercury_unify_compare_body.h:
	Fix the bug that prevented us from passing all the tests with
	invariants checked and tail recursion support enabled. The bug was
	that in several cases, the code in mercury_unify_compare_body.h
	did not invoke the appropriate deep profiling routines and thus
	did not fill in the deep profiling data structure they were supposed to
	fill in, breaking an invariant.

	There were several instances of this bug: unify, compare and
	compare_representation on tuples, and compare_representation on
	functions, predicates and user-defined types.

	These oversights were possible because the actions of returning an
	answer and filling in the deep profiling data structures (in deep
	profiling grades) were separate. If one omitted the latter, tests could
	still work in all grades except deep profiling grades.

	The fix therefore uses one macro (return_compare_answer or return
	unify_answer, depending on the the operation) to fill in the deep
	profiling data structure (in deep profiling grades) and return the
	answer, making it impossible to forget to do the former.

	The new approach treats compare_representation the same as compare,
	and gathers the same information for it.

runtime/mercury_ho_call.c:
	Factor out some commonalities in the definitions of the MR_ProcStatic
	data structures used by the code in mercury_unify_compare_body.h.

	Change a macro name to support the changes in
	mercury_unify_compare_body.h.

	Change the module name of compare_representation/3 from std_util to
	builtin, to match unify/2 and compare/3.

compiler/deep_profiling.m:
	Treat compare_representation/3 the same way as we treat compare/3.

library/builtin.m
library/std_util.m
	Move the declaration of compare_representation/3 from std_util to
	builtin, to make it easier to handle it the same way as compare/3.
	Since it is just a variant of compare/3 and is at least as built
	into the implementation, it belongs there anyway.

library/profiling_builtin.m:
	Use C types to represent deep profiling data structures.
	Delete the casts that are redundant after this change.

	Fix formatting of foreign_procs.

runtime/mercury_deep_profiling.c:
	As mentioned above, always check the invariants of the deep profiling
	data structures when writing them out.

runtime/mercury_deep_profiling.h:
	Avoid a warning about nested declarations of variable "i".

runtime/mercury_deep_rec_depth_body.h:
	Delete a bunch of casts we don't need anymore.

runtime/mercury_wrapper.[ch]:
	Initialize a couple of predicate names in the low level debug support
	to "" instead of NULL. The code that accesses these variables passes
	them to strcmp directly, which lead to core dumps. We could change the
	accessing code to test for NULL, but since that code is executed on
	every call when low level debugging is enabled, that would lead to
	even greater slowdowns, which we can do without.

	To avoid a warning about casting away const, make the variables
	involved "const char *" instead of plain "char *"; we don't want
	to update the pointed-to strings anyway.

tools/bootcheck:
	In profiling grades, write out profiling data files by default, and
	require the use of an option to turn them off. This is needed to make
	sure that the deep profiling invariants are checked by default.

tests/hard_coded/compare_rep_usereq.m:
tests/hard_coded/compare_representation.m:
	Avoid hard-coding the name of the module defining
	compare_representation/3.
2002-11-08 00:45:55 +00:00
Peter Ross
4030907a58 Add a comment that MR_init_thread_stuff must be called before
Estimated hours taken: 0.1
Branches: main

runtime/mercury_wrapper.c:
	Add a comment that MR_init_thread_stuff must be called before
	MR_init_memory.
2002-10-30 16:18:12 +00:00
Peter Ross
e7983ff098 Fix a bug which caused a seg-fault with the Win32 version of the
Estimated hours taken: 8
Branches: main

Fix a bug which caused a seg-fault with the Win32 version of the
pthread library.

runtime/mercury_wrapper.c:
	Move MR_init_thread_stuff() so that it is called before
	MR_init_memory() as MR_init_memory() refers to
	MR_engine_base_key which is initialised by
	MR_init_thread_stuff().
2002-10-30 15:43:07 +00:00