Commit Graph

100 Commits

Author SHA1 Message Date
Zoltan Somogyi
958ba814bc Show cliques in mdb stack traces less obtrusively.
like this:

mdb> stack
   0         pred mutrec.q1/3-0 (det) (mutrec.m:133)
   1 ┌    2* pred mutrec.p2/3-0 (det) (mutrec.m:106 and others)
   3 │       pred mutrec.p3/3-0 (det) (mutrec.m:122)
   4 │    2* pred mutrec.p2/3-0 (det) (mutrec.m:102 and others)
   6 └       pred mutrec.p3/3-0 (det) (mutrec.m:122)
   7      2* pred mutrec.p1/3-0 (det) (mutrec.m:82 and others)
   9         pred mutrec.test/2-0 (det) (mutrec.m:42)
  10         pred mutrec.main/2-0 (det) (mutrec.m:33)

This implements a suggestion by Peter Wang from *April 2012*.

runtime/mercury_stack_trace.h:
    Add a new field to the data structure that represents each line
    in a stack trace. This field represents the string, if any,
    that implements the boxes around the calls in the clique.
    This will be two characters, a box character and a space,
    e.g. for the call at level 6, it will be "└ ".

runtime/mercury_stack_trace.c:
    Use the new capability to add boxes to calls in cliques,
    and equal-length padding to the calls that are not in cliques
    but which share stack traces with calls that are.

    Initialize some variables closer to their first use.
    Group some related statements together. Add some comments.
    Delete some already-acted-upon TODOs.

tests/debugger/mutrec.exp:
tests/debugger/mutrec_higher_order.exp:
    Expect the updated clique markers.

NEWS.md:
doc/user_guide.texi:
    Document the change.
2024-10-02 10:38:02 +02:00
Peter Wang
72f174b4e2 Don't print value of errno in MR_fatal_error.
The majority of calls to MR_fatal_error do not follow an operation that
sets errno, so printing out an error message unrelated to the reason for
the fatal error will lead to confusion. It can also cause test failures
if errno happens to be set to non-zero some time prior to an expected
call to MR_fatal_error. Fixes bug #464.

runtime/mercury_misc.c:
    Don't print value of errno in MR_fatal_error.

runtime/mercury_context.c:
runtime/mercury_thread.c:
    Pass strerror strings to MR_fatal_error where appropriate.

runtime/mercury_memory_zones.c:
runtime/mercury_memory_zones.h:
    Pass strerror strings to MR_fatal_error following failures of
    MR_protect_pages. Document that this assumes MR_protect_pages sets
    errno on error.

    Skip unnecessary call to sprintf before MR_fatal_error.

runtime/mercury_deep_profiling.c:
    Skip unnecessary call to sprintf before MR_fatal_error.

    Reduce size of some buffers.

runtime/mercury_overflow.c:
runtime/mercury_stack_trace.c:
    Pass a fixed format string to MR_fatal_error just in case
    the message string may contain percentage signs.

runtime/mercury_tabling.c:
    Skip unnecessary call to sprintf before MR_fatal_error.

deep_profiler/timeout.m:
library/thread.m:
mdbcomp/shared_utilities.m:
    Pass strerror strings to MR_fatal_error where appropriate.

trace/mercury_trace.c:
    Skip unnecessary call to sprintf before MR_fatal_error.

trace/mercury_trace_external.c:
    Pass a fixed format string to MR_fatal_error just in case.
2018-08-19 12:19:19 +10:00
Peter Wang
2be2e7468c Do not use _snprintf functions directly in place of snprintf functions.
The Windows _snprintf family of functions do not guarantee null
termination when the output is truncated so cannot be used as direct
replacements for the snprintf functions. Also, the _snprintf functions
have different return values from the C99 snprintf functions when output
is truncated (like some older snprintf implementations).

Furthermore, on Windows snprintf/vsnprintf may be synonyms for
_snprintf/_vsnprintf so cannot be relied upon to terminate their outputs
either, even if the functions exist.

runtime/mercury_string.c:
runtime/mercury_string.h:
    Define MR_snprintf and MR_vsnprintf as macro synonyms for
    snprintf/vsnprintf ONLY if _snprintf/_vsnprintf do not exist.

    Otherwise, implement MR_snprintf and MR_vsnprintf functions
    that behave like the C99 functions, in terms of _vsnprintf.

    Require that either snprintf/vsnprintf or _snprintf/_vsnprintf
    are available. This should be true on all systems still in use.

runtime/mercury_debug.c:
runtime/mercury_ml_expand_body.h:
runtime/mercury_runtime_util.c:
runtime/mercury_stack_layout.c:
runtime/mercury_stack_trace.c:
runtime/mercury_stacks.c:
runtime/mercury_tabling.c:
runtime/mercury_threadscope.c:
runtime/mercury_trace_base.c:
runtime/mercury_wrapper.c:
trace/mercury_trace_completion.c:
trace/mercury_trace_internal.c:
trace/mercury_trace_spy.c:
trace/mercury_trace_vars.c:
bytecode/mb_disasm.c:
    Use MR_snprintf instead of snprintf/_snprintf
    and MR_vsnprintf instead of vsnprintf/_vsnprintf.

    Drop code paths using sprintf as a fallback.
2018-07-23 10:26:29 +10:00
Mark Brown
d465fa53cb Update the COPYING.LIB file and references to it.
Discussion of these changes can be found on the Mercury developers
mailing list archives from June 2018.

COPYING.LIB:
    Add a special linking exception to the LGPL.

*:
    Update references to COPYING.LIB.

    Clean up some minor errors that have accumulated in copyright
    messages.
2018-06-09 17:43:12 +10:00
Zoltan Somogyi
53b573692a Convert C code to use // style comments.
runtime/*.[ch]:
trace/*.[chyl]:
    As above. In some places, improve comments, e.g. by expanding contractions
    such as "we've". Add #ifndef guards against double inclusion around
    the trace/*.h files that did not already have them.

tools/*:
    Make the corresponding changes in shell scripts that generate .[ch] files
    in the runtime.

tests/*:
    Conform to a slight change in the text of a message.
2016-07-14 13:57:35 +02:00
Zoltan Somogyi
67326f16e4 Fix style issues in the runtime.
Move all .h and .c files to four-space indentation without tabs,
if they weren't there already.

Use the same vim line for all .h and .c files.

Align all backslashes at the ends of lines in macro definitions.
Align close comment signs.

In some places, fix inconsistent indentation.

Fix a bunch of comments. Add XXXs to a few of them.
2016-07-09 12:14:00 +02:00
Zoltan Somogyi
c6ab550db8 Remove the code for automatic initialization of solver vars.
We haven't supported it in years, and keeping it in the compiler
is just a maintenance burden and a performance problem.

mdbcomp/prim_data.m:
    Delete the spec_pred_init functor, since we don't support special
    "init" predicates anymore.

compiler/prog_data.m:
    Delete the slot in solver type details that record the name of the
    auto-initialization predicate.

compiler/prog_io_type_defn.m:
    Don't allow a type definition to specify an auto-initialization predicate.

compiler/options.m:
compiler/globals.m:
    Delete the option that allowed support for auto-initialization to be
    turned back on.

compiler/inst_match.m:
compiler/inst_util.m:
    Delete comments about auto-initialization.

compiler/mode_info.m:
    Delete the record of whether we have variables that can be
    auto-initialized (we never do anymore) and the flag that controls whether
    auto-initialization is permitted or not.

compiler/modecheck_conj.m:
    Simplify the code that modechecks conjunctions, since it no longer
    has to figure out where to insert auto-initializations of solver vars.

compiler/modecheck_goal.m:
    Delete the code that ensured that if one branch of a branched
    control structure auto-initialized a solver variable, then they
    all did.

compiler/modecheck_unify.m:
    Don't auto-initializate variables before unifications.

compiler/modecheck_util.m:
    Delete the code that auto-initialized solver variables at the ends
    of procedure bodies if this needed to be done and wasn't done before.

compiler/add_special_pred.m:
compiler/equiv_type.m:
compiler/equiv_type_hlds.m:
compiler/get_dependencies.m:
compiler/hlds_module.m:
compiler/hlds_pred.m:
compiler/modecheck_call.m:
compiler/modes.m:
compiler/module_qual.qualify_items.m:
compiler/parse_tree_out.m:
compiler/post_term_analysis.m:
compiler/smm_common.m:
compiler/special_pred.m:
compiler/term_constr_errors.m:
compiler/term_constr_initial.m:
compiler/term_util.m:
compiler/termination.m:
compiler/trace_params.m:
compiler/type_util.m:
compiler/unify_proc.m:
    Delete code that handled stuff related to auto-initialization,
    and now always take the path that would normally be taken in the
    absence of auto-initialization.

deep_profiler/read_profile.m:
runtime/mercury_layout_util.c:
runtime/mercury_stack_trace.c:
util/mdemangle.c:
    Remove code that recognized the compiler-generated name of initialization
    predicates.

tests/debugger/solver_test.m:
tests/hard_coded/solver_construction_init_test.m:
tests/hard_coded/solver_disj_inits.m:
tests/hard_coded/solver_ite_inits.m:
tests/invalid/missing_init_pred.m:
tests/invalid/zinc2mer_lib.m:
tests/valid/fz_conf.m:
tests/valid/solver_type_bug_2.m:
tests/valid/solver_type_mutable_bug.m:
    These tests tested the handling of auto-initialization, which we
    no longer support. Keep them around (and a bit more visible than
    inside the git repo) in case we need them again, but add a comment
    to each saying that the test is disabled.

tests/debugger/Mercury.options:
tests/debugger/Mmakefile:
tests/hard_coded/Mercury.options:
tests/hard_coded/Mmakefile:
tests/invalid/Mercury.options:
tests/invalid/Mmakefile:
tests/valid/Mercury.options:
tests/valid/Mmakefile:
    Disable those tests.

tests/warnings/non_term_user_special.{m,exp}:
    Part of this test tested the handling of auto-initialization;
    delete that part.

tests/warnings/Mercury.options:
    Delete the flag required by the deleted part, since we don't support it
    anymore.
2015-12-03 05:06:28 +11:00
Julien Fischer
94535ec121 Fix spelling and formatting throughout the system.
configure.ac:
browser/*.m:
compiler/*.m:
deep_profiler/*.m:
library/*.m:
ssdb/*.m:
runtime/mercury_conf.h.in:
runtime/*.[ch]:
scripts/Mmake.vars.in:
trace/*.[ch]:
util/*.c:
	Fix spelling and doubled-up words.

	Delete trailing whitespace.

	Convert tabs into spaces (where appropriate).
2015-12-02 18:46:14 +11:00
Julien Fischer
787f8b2c6d Fix spelling and grammer in runtime comments.
runtime/*.[ch]:
    As above.
2015-09-03 15:43:35 +10:00
Julien Fischer
9c6654a9ba Workaround a problem with GCC 4.9 on x86_64 systems.
configure.ac:
	Apply the same workaround for a problem with GCC labels
	on x86_64 systems with GCC 4.9 as we do with GCC 4.8.
	(XXX we should probably disable -ftree-dominator-opts on all
	GCCs that support it, but I'm not sure how widespread the problem
	with it is -- I'll look into that separately.)

runtime/mercury_stack_trace.c:
	Avoid a warning from GCC.
2014-09-02 09:34:04 +10:00
Zoltan Somogyi
f6fafa150d Fix Mantis bug 314 for temp frames created by nondet procedures.
Also fix some bugs in related code, and improve the related debugging
infrastructure.

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

runtime/mercury_stacks.[ch]:
   Fix bug 314 for temp frames created by nondet procedures. The fix will
   probably also work for *det* procedures that create temp frames on the
   nondet stack, but I can't think of a way to test that, because det
   procedures create such frames only in very specific circumstances,
   and I cannot think of a way to nest a recursive call inside those
   circumstances.

   The problem was that when we were creating new temp frames on
   the nondet stack, we did not check whether the current nondet stack segment
   had room for them. We now do.

   The stack trace tracing code needs to know the size of each nondet stack
   frame, since it uses the size to classify frames as temp or ordinary.
   The size is given by the difference in address between the address of the
   frame and the address of the previous frame. This difference would yield
   an incorrect size and hence an incorrect frame classification if a temp
   frame were allowed to have a frame on a different segment as its
   immediate predecessor.

   We prevent this by putting an ordinary (i.e. non-temp) frame at the bottom
   of every new nondet stack segment as a sentinel. We hand-build this frame,
   since it is not an "ordinary" ordinary frame. It is not created by a call,
   so it has no meaningful success continuation, and since it does not make
   any calls, no other frame's success continuation can point to it either.

   If backtracking reaches this sentinel frame, we use this fact to free
   all the segments beyond the one the sentinel frame is in, but keep the
   frame the sentinel frame is in, since we are likely to need it again.

   Document the reason why MR_incr_sp_leaf() does not have to check
   whether a new stack segment is needed. (See the fix to llds_out_instr.m
   below.)

runtime/mercury_stack_trace.[ch]:
   When traversing the nondet stack, treat the sentinel frame specially.
   We have to, since it is an ordinary frame (i.e. it is not a temp frame),
   but it is not an "ordinary" ordinary frame: it does not make calls,
   and hence calls cannot return to it, and it does not return to any
   other frame either. It therefore does not have the layout structures
   (label and proc) that the nondet stack traversal expects to find.

   Fix an old bug: the nondet stack traversal used a simple directional
   pointer comparison to check whether it has reached the bottom of the nondet
   stack. This is NOT guaranteed to work in the presence of stack segments:
   depending on exactly what addresses new stack segments get, a stack frame
   can have an address BELOW the address of the initial stack frame
   even if it is logically ABOVE that stack frame.

   Another old bug was that a difference between two pointers, which could
   be 64 bit, was stored in an int, which could be 32 bit.

   The nondet stack traversal code used a similar directional comparison
   to implement optionally stopping at an arbitrary point on the nondet stack.
   Fixing this facility (the limit_addr parameter of MR_dump_nondet_stack)
   while preserving reasonable efficiency would not be trivial, but it would
   also be pointless, since the facility is not actually used. This diff
   deletes the parameter instead.

   Move some loop invariant code out of its loop.

trace/mercury_trace_cmd_developer.c:
trace/mercury_trace_external.c:
   Don't pass the now-deleted parameter to mercury_stack_trace.c.

runtime/mercury_wrapper.c:
   Record the zone of the initial nondet stack frame, since the fix
   of mercury_stack_trace.c needs that info, and it is much more efficient
   to set it up just once.

tests/hard_coded/bug314.{m,exp}:
   The regression test for this bug.

tests/hard_coded/Mercury.options:
   Compile the new test case with the options it needs.

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

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

runtime/mercury_wrapper.c:
   The compiler knows the number of words in a stack frame it is creating,
   not necessarily the number of bytes (though it could put bounds on that
   from the number of tag bits). Since this size must sync with the runtime,
   change the runtime's variable holding this size to also be in words.

   Note that similar changes would also be beneficial for other sizes.

compiler/llds_out_instr.m:
   Conform to the change in mercury_wrapper.c, fixing an old bug
   (mercury_wrapper.c reserved 128 BYTES for leaf procedures, but
   llds_out_instr.m was using that space for procedures whose frames
   were up to 128 WORDS in size.)

compiler/mercury_memory.c:
   Conform to the change in mercury_wrapper.c.

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

runtime/mercury_memory_zones.h:
   Instead of starting to use EVERY zone at a different offset, do this
   only for the INITIAL zones in each memory area, since only on these
   is it useful. When the program first starts up, it WILL be using
   the initial parts of the det stack, nondet stack and heap, so it is
   useful to make sure that these do not collide in the cache. However,
   when we allocate e.g. the second zone in e.g. the nondet stack, we are
   no more likely to be beating on the initial part of any segment
   of the det stack than on any other part of such segments.

   If a new debug macro, MR_DEBUG_STACK_SEGMENTS_SET_SIZE is set (to an int),
   use only that many words in each segment. This allows the segment switchover
   code to be exercised and debugged with smaller test cases.

runtime/mercury_conf_param.h:
   Document the MR_DEBUG_STACK_SEGMENTS_SET_SIZE macro.

   Convert this file to four-space indentation with tabs expanded.

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

runtime/mercury_overflow.h:
   Make abort messages from overflows and underflows more useful by including
   more information.

runtime/mercury_overflow.c:
   Add a new function to help with the better abort messages.
   Since this file did not exist before, create it.

runtime/Mmakefile:
   Add the new source file to the list of source files.

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

runtime/mercury_debug.[ch]:
   Fix problems with the formatting of the debugging output from existing
   functions.

   Add new functions for dumping info about memory zones.

   Factor out some common code.

   Convert the header file to four-space indentation.

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

runtime/mercury_grade.c:
   Generate an error if stack segments are specified together with stack
   extension

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

trace/.gitignore:
util/.gitignore:
tests/debugger/.gitignore:
   List some more files.

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

runtime/mercury_context.c:
runtime/mercury_engine.[ch]:
runtime/mercury_misc.h:
compiler/notes/failure.html:
   Fix white space.
2014-04-18 02:02:35 +10:00
Julien Fischer
e9d90b2891 Avoid warnings from clang in the runtime and util directories.
runtime/mercury_stack_trace.c:
	In the function MR_dump_stack_from_layout_clique initialise the variable
	lines_dumped_so_far.  (This appears to be an actual bug.)

runtime/mercury_prof.c:
	Only define the static global in_profiling_code if either of call count
	profiling or time profiling is enabled.

runtime/mercury_context.c:
runtime/mercury_deconstruct.c:
runtime/mercury_deep_profiling.c:
	Only define some local variables in grades that require them.

runtime/mercury_float.c:
runtime/mercury_deep_copy_body.h:
runtime/mercury_construct.c:
runtime/mercury_memory_zones.c:
runtime/mercury_stm.c:
runtime/mercury_trace_base.c:
runtime/mercury_type_info.c:
	Delete unused local variables.

util/mdemangle.c:
	Delete an unused static global variable.

	Use fputs in place of fprintf in a couple of places in order
	to avoid warnings about format strings that are not string literals.

	Delete an unused function.

util/mkinit.c:
util/mkinit_erl.c:
	Delete unused local variables.
2014-03-20 17:01:15 +11:00
Peter Wang
20ea47995f Fix crashes when dumping stack traces.
In MR_dump_stack_from_layout_clique two variables could be accessed
without being initialised when jumping to the label 'done'.

Also, pair calls to MR_malloc/MR_realloc with MR_free instead of free.
This is purely cosmetic while MR_free is an alias for free.

runtime/mercury_stack_trace.c:
	As above.
2013-02-12 14:20:12 +11:00
Zoltan Somogyi
1962dd6990 Avoid a core dump that we used to get when traversing stack frames
Estimated hours taken: 0.5
Branches: main

runtime/mercury_stack_trace.c:
	Avoid a core dump that we used to get when traversing stack frames
	without debug info, such as the stack frames of hand-written procedures
	like builtin_catch.
2012-11-14 07:02:23 +00:00
Zoltan Somogyi
c733b0359b Give the Mercury debugger the ability to detect cliques of mutually recursive
Estimated hours taken: 30
Branches: main

Give the Mercury debugger the ability to detect cliques of mutually recursive
predicates on the stack. Exploit this ability to enhance the debugger's
level, retry, finish and stack commands.

runtime/mercury_stack_trace.[ch]:
	Add a function, MR_find_clique_entry, that detects the clique
	that contains the top stack frame. This is used to implement the new
	arguments "clentry" and "clparent" (short for clique entry and parent)
	options of the level, retry and finish commands. "clique" is a synonym
	for "clentry" in these commands.

	Add a function, MR_dump_stack_layout_clique, that implements the
	new capabilities of the stack command. It can detect more than one
	clique, anywhere on the stack.

	To make this possible, modify the existing functions for printing
	the lines of stack traces. These used to keep some information around
	between calls in global variables. Now that information is stored in
	two structures that the caller passes them. One contains the parameters
	that govern what is to be printed, the other contains information about
	what has been buffered up to be printed, but has not been flushed yet.
	(The old code was confused in its handling of parameters. Some parts
	of it looked up the global variables storing them, while other parts
	were given the parameter values by their callers, values that could
	have been -but weren't- inconsistent.)

	Change the buffer flushing code to be idempotent, since in the new
	code, sometimes it is hard to avoid flushing the buffer more than once,
	and we want only the first to print its contents.

	Make some type names conform to our standard style.

runtime/mercury_stack_layout.h:
	Add a new flag in MR_ProcLayouts: a flag that indicates that the
	procedure has one or more higher order arguments. The new code in
	mercury_stack_trace.c handles procedures with this flag specially:
	it does not consider two non-consecutive occurrences of such procedures
	on the stack to be necessarily part of the same clique. This is to
	avoid having two calls to e.g. list.map in different part of the
	program pulling all the procedures between those parts on the stack
	into a single clique. (The deep profiler has a very similar tweak.)

	Add a pointer to the corresponding part of the compiler.

compiler/hlds_pred.m:
	Add a predicate to test whether a predicate has any higher order args.

compiler/stack_layout.m:
	When computing the flag in proc layouts, call the new procedure in
	hlds_pred.m to help figure it out.

trace/mercury_trace_cmd_backward.c:
	Implement the new options of the "retry" command.

trace/mercury_trace_cmd_forward.c:
	Implement the new options of the "finish" command.

trace/mercury_trace_cmd_browsing.c:
	Implement the "new options of the "level" command.

	Implement the new functionality of the "stack" command.

trace/mercury_trace_util.[ch]:
	Add some code common to the implementations of the level, retry and
	finish commands.

trace/mercury_trace_external.c:
	Conform to the changes to the runtime.

doc/user_guide.texi:
	Document the debugger's new capabilities.

NEWS:
	Announce the debugger's new capabilities.

tests/debugger/mutrec.{m,inp,exp}:
	A new test case to test the handling of the stack command
	in the presence of cliques.

tests/debugger/mutrec_higher_order.{m,inp,exp}:
	A new test case to test the handling of the stack command
	in the presence of cliques and higher order predicates.

tests/debugger/Mmakefile:
	Enable both new test cases.
2012-06-05 18:19:33 +00:00
Zoltan Somogyi
d4bbcda309 Move all the frequently occurring layout structures and components of layout
Estimated hours taken: 40
Branches: main

Move all the frequently occurring layout structures and components of layout
structures into arrays where possible. By replacing N global variables holding
individual layout structures or layout structure components with one global
variable holding an array of them, we reduce the sizes of the symbol tables
stored in object files, which should speed up both the C compiler and the
linker.

Measured on the modules of the library, mdbcomp and compiler directories
compiled in grade asm_fast.gc.debug, this diff reduces the size of the
generated C source files by 7.8%, the size of the generated object files
by 10.4%, and the number of symbols in the symbol tables of those object files
by a whopping 42.8%. (These improvements include, and are not on top of,
the improvements in my previous similar diff.)

runtime/mercury_stack_layout.h:
	Each label layout structure has information about the type and
	location of every variable that is live at that label. We store
	this information in three arrays: an array of pseudo-typeinfos giving
	the types of all these variables, and two arrays MR_ShortLvals and
	MR_LongLvals respectively giving their locations. (Most of the time,
	the location's encoded form fits into one byte (the MR_ShortLval)
	but sometimes it needs more bits (this is when we use MR_LongLval)).

	We used to store these three arrays, whose elements are different
	types, in a single occurrence-specific common structure,
	one after the other, with a cumbersome mechanism being required
	to access them. We now store them as segments of three separate arrays,
	of pseudo-typeinfos, MR_ShortLvals and MR_LongLvals respectively.
	This makes access simpler and faster (which will matter more to any
	accurate garbage collector than it does to the debugger). It also
	allows more scope for compression, since reusing an existing segment of
	one of the three arrays is easier than reusing an entire common
	structure, which would require the equivalent of exact matches
	on all three arrays.

	Since most label layout structures that have information about
	variables can encode the variables' locations using only MR_ShortLvals,
	create a version of the label layout structure type that omits the
	field used to record the whereabouts of the long location descriptors.

	Add macros now generated by the compiler to initialize layout
	structures.

	Simplify a one-field struct.

runtime/mercury_grade.h:
	Increment the binary compatibility version number for debuggable
	executables, since .c and .o files from before and after the change
	to label layout structures are NOT compatible.

runtime/mercury_type_info.h:
	Fix some binary-compatibility-related bit rot.

runtime/mercury_misc.h:
	Move here the existing macros used by the compiler when generating
	references to layout arrays, and add new ones.

runtime/mercury_goto.h:
	Delete the macros moved to mercury_misc.h.
	Conform to the changes in mercury_stack_layout.h.

runtime/Mmakefile:
	Prevent the unnecessary rebuilding of mercury_conf.h.

runtime/mercury_accurate_gc.c:
runtime/mercury_agc_debug.c:
runtime/mercury_layout_util.c:
runtime/mercury_stack_trace.c:
runtime/mercury_types.h:
trace/mercury_trace.c:
trace/mercury_trace_vars.c:
	Conform to the changes in mercury_stack_layout.h.

runtime/mercury_wrapper.c:
	Improve the debug support a bit.

runtime/mercury_engine.h:
	Fix style.

compiler/layout.m:
	Make the change described at the top. Almost all layout structures
	are now in arrays. The only exceptions are those that occur rarely,
	and proc layouts, whose names need to be derivable from the name
	of the procedure itself.

	Instead of having a single type "layout_data" that can represent
	different kinds of single global variables (not array slots), have
	different kinds for different purposes. This makes the code clearer
	and allows traversals that do not have to skip over inapplicable kinds
	of layout structures.

compiler/layout_out.m:
	Output the new arrays.

compiler/stack_layout.m:
	Generate the new arrays. Previously, an individual term generated by
	stack_layout.m could represent several components of a layout
	structure, with the components separated by layout_out.m. We now
	do the separation in stack_layout.m itself, adding each component
	to the array to which it belongs.

	Instead of passing around a single stack_layout_info structure,
	pass around several smaller one. This is preferable, since I found out
	the hard way that including everything in one structure would give the
	structure 51 fields. Most parts of the module work with only one
	or two of these structures, which makes their role clearer.

	Cluster related predicates together.

compiler/options.m:
doc/user_guide.texi:
	Add an option that control whether stack_layout.m will attempt to
	compress the layout arrays that can meaningfully be comressed.

compiler/llds.m:
	Remove the old distinction between a data_addr and a data_name,
	replacing both types with a single new one: data_id. Since different
	kinds of data_names were treated differently in many places,
	the distinction in types (which was intended to allow us to process
	data_addrs that wrapped data_names differently from other kinds of
	data_addrs) wasn't buying us anything anymore.

	The new data_id type allows for the possibility that the code generator
	wants to generate a reference to an address it does not know yet,
	because it is a slot in a layout array, and the slot has not been
	allocated yet.

	Add the information from which the new layout array structures
	will be generated to the LLDS.

compiler/llds_out.m:
	Call layout_out.m to output the new layout arrays.

	Adapt the decl_id type to the replacement of data_addrs by data_ids.
	Don't both keeping track of the have-vs-have-not-declared status
	of structures that are always declared at the start.

	When writing out a data_addr, for some kinds of data_addr, llds_out.m
	would write out the name of the relevant variable, while for some other
	kinds, it would write out its address. This diff separates out those
	those things into separate predicates, each of which behaves
	consistently.

compiler/mercury_compile_llds_back_end.m:
	Convey the intended contents of the new layout arrays from
	stack_layout.m to llds_out.m.

compiler/continuation_info.m:
	Add a type required by the way we now generate proc_static structures
	for deep profiling.

compiler/hlds_rtti.m:
	Add distinguishing prefixes to the field names of the rtti_proc_label
	type.

compiler/code_info.m:
compiler/code_util.m:
compiler/erl_rtti.m:
compiler/exprn_aux.m:
compiler/global_data.m:
compiler/ll_pseudo_type_info.m:
compiler/ml_code_util.m:
compiler/opt_debug.m:
compiler/proc_gen.m:
compiler/prog_rep.m:
compiler/rtti_out.m:
compiler/unify_gen.m:
	Conform to the changes above.

tests/debugger/declarative/track_through_catch.exp:
	Expect procedures to be listed in the proper order.

tests/EXPECT_FAIL_TESTS.asm_fast.gc.debug:
tests/EXPECT_FAIL_TESTS.asm_fast.gc.profdeep:
	Add these files to ignore expected failues in these grades.
2009-10-30 03:33:34 +00:00
Julien Fischer
ee74813099 Avoid warnings from gcc 4.3 in the runtime.
runtime/mercury_stack_trace.c:
	Handle values of type MR_Level in format strings correctly.

runtime/mercury_wrapper.c:
	Check the return value of a call to system().
2009-06-01 09:28:01 +00:00
Julien Fischer
72b6d4aa18 Avoid a warning from the C compiler.
runtime/mercury_stack_trace.c:
	Delete an unused local variable which is shadowed by another one.
	(It isn't apparent in the source since the declaration of the latter
	one is only present as the result of a macro expansion.)

library/list.m:
	Unrelated change: fix an out-of-place comma.
2008-11-28 05:55:14 +00:00
Zoltan Somogyi
53286dd4bf Implement a new compiler option, --exec-trace-tail-rec, that preserves direct
Estimated hours taken: 30
Branches: main

Implement a new compiler option, --exec-trace-tail-rec, that preserves direct
tail recursion in det and semidet procedures even when debugging is enabled.
This should allow the debugging of programs that previously ran out of stack.

The problem arose because even a directly tail-recursive call had some code
after it: the code for the EXIT event, like this:

	p:
		incr_sp
		fill in the usual debug slots
		CALL EVENT
		...
		/* tail call */
		move arguments to registers as usual
		call p, return to p_ret
	p_ret:
		/* code to move output arguments to right registers is empty */
		EXIT EVENT
		decr_sp
		return

If the new option is enabled, the compiler will now generate code like this:

	p:
		incr_sp
		fill in the usual debug slots
		fill in new "stack frame reuse count" slot with 0
		CALL EVENT
	p_1:
		...
		/* tail call */
		move arguments to registers as usual
		update the usual debug slots
		increment the "stack frame reuse count" slot
		TAILCALL EVENT
		goto p_1

The new TAIL event takes place in the caller's stack frame, so that the local
variables of the caller are available. This includes the arguments of the
recursive call (though if they are unnamed variables, the debugger will not
show them). The TAIL event serves as a replacement for the CALL event
of the recursive invocation.

compiler/options.m:
	Add the new option.

compiler/handle_options.m:
	Handle an implication of the new option: the declarative debugger
	does not (yet) understand TAIL events.

compiler/mark_tail_calls.m:
	New module to mark directly tail recursive calls and the procedures
	containing them as such.

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

compiler/mercury_compile.m:
	Invoke the new module when the new option asks us to.

compiler/hlds_goal.m:
	Add the feature used to mark tail recursive calls for the debugger.
	Rename an existing feature with a similar but not identical purpose
	to avoid possible confusion.

compiler/hlds_pred.m:
	Add a field to proc_infos that says whether the procedure contains
	tail recursive calls.

	Minor style improvements.

compiler/passes_aux.m:
	Minor change to accommodate the needs of the new module.

compiler/code_info.m:
	Transmit the information from mark_tail_calls to the code generator.

compiler/call_gen.m:
	Implement the new option.

compiler/trace_gen.m:
	Reserve the extra slot needed for the new option.

	Switch to state variable notation in the code that does the slot
	allocation, since this is less error-prone than the previous approach.

compiler/layout.m:
compiler/layout_out.m:
compiler/stack_layout.m:
	Remember what stack slot holds the stack frame reuse counter,
	for transmission to the runtime system.

compiler/proc_gen.m:
	Add the new label needed for tail recursion.

	Put the arguments of some procedures into a more logical order.

compiler/deep_profiling.m:
compiler/deforest.m:
compiler/saved_vars.m:
compiler/table_gen.m:
	Conform to the changes above.

compiler/trace_params.m:
mdbcomp/prim_data.m:
runtime/mercury_trace_base.[ch]:
	Add the new event type.

	Convert mercury_trace_base.h to four-space indentation.

runtime/mercury_stack_layout.h:
	Add a field to the execution trace information we have for each
	procedure that gives the number of the stack slot (if any) that holds
	the stack frame reuse counter. Add a macro to get the value in the
	counter.

	Convert this header file to four-space indentation.

runtime/mercury_stack_trace.[ch]:
	When walking the stack, we now have to be prepared to encounter stack
	frames that have been reused. Modify the algorithms in this module
	accordingly, and modify the interfaces of the exported functions
	to allow the functions' callers to behave accordingly as well.

	Group the information we gather about stack frame for printing into
	one structure, and document it.

	Convert the header to four-space indentation.

library/exception.m:
mdbcomp/trace_counts.m:
	Conform to the changes above.

	In trace_counts.m, fix an apparent cut-and-paste error (that hasn't
	caused any test case failures yet).

trace/mercury_trace.c:
	Modify the implementation of the "next" and "finish" commands
	to accommodate the possibility that the procedure at the selected
	depth may have had its stack frame reused. In such cases

tests/debugger/tailrec1.{m,inp,exp,data}:
	A new test case to check the handling of tail recursive procedures.
2008-11-25 07:46:57 +00:00
Peter Wang
122579d906 Nondet stack segments didn't work properly using the placeholder frame trick
Branches: main

Nondet stack segments didn't work properly using the placeholder frame trick
at the base of nondet stack segments. i.e. when we jump to special procedure
(MR_pop_nondetstack_segment) stored in the succip slot of the base frame, it
should free the top stack segment, set maxfr to the correct value and jump to
the real succip.  However, we were reading values of maxfr and succip from
the *det* stack which is clearly wrong.  After fixing that, it still didn't
work properly.  Nondet execution seems to be too haphazard for the trick to
work.  MR_pop_nondetstack_segment() can be entered not only when the top
stack segment can be deallocated, which complicates things.

Instead, switch to a simpler method to deallocate nondet stack frames.  When
creating a nondet frame, we know that all stack segments above that which
`maxfr' points into can be freed.  In the common case, `maxfr' *will* point
into the top stack segment and that can be checked with just one additional
test.  After deallocating excess stack segments, the new frame can be created
as before.

See also Mantis bug #65.

runtime/mercury_stacks.h:
	Make `MR_nondetstack_extend_and_check' check that `maxfr' still lives
	on the top nondet stack segment.  If not, or if a new segment is
	required, call `MR_nondetstack_segment_extend_slow_path'.

runtime/mercury_stacks.c:
	Rename `MR_new_detstack_segment' to
	`MR_nondetstack_segment_extend_slow_path'.  Make it free excess
	nondet stack segments.

	Fix a bug where `MR_NONDET_FIXED_SIZE' was added twice to the number of
	slots required for a new frame.

	Delete `MR_pop_nondetstack_segment' which is no longer used.

	Don't use red zones for new det and nondet stack segments.

	Add missing parameters to some debugging code.

runtime/mercury_stack_trace.c:
	Delete reference to `MR_pop_nondetstack_segment'.

runtime/mercury_memory_zones.c:
	Add sanity checks for small memory zone sizes, e.g. they may be too
	small to fit all of the usable zone area, red zone and cache offset.

NEWS:
	Announce stack segment support as it should be stable now.
2008-08-07 01:16:19 +00:00
Julien Fischer
70ba4db53d Fix a problem introduced in my previous change to the trace directory
Estimated hours taken: 4
Branches: main

Fix a problem introduced in my previous change to the trace directory
which introduced a dependency between the runtime and the trace directory
which broke compilation of the former in high-level C grades.

Fix up conversion specifiers in the printf control strings in the
trace directory.

runtime/mercury_stack_trace.h:
	Define MR_FrameLimit, MR_SpecLineLimit and MR_AncestorLevel here rather
	than in the trace directory because the code in the runtime for
	stack tracing refers to them.  (Some code that was only enabled
	in high-level C grades and referred to the above types was
	added as part of my last change; this is what broke compilation
	in those grades.)

	Rename MR_AncestorLevel to (the more general) MR_Level in the
	process.

runtime/mercury_stack_trace.c:
	Use MR_FrameLimit and friends in place of ints here.

trace/mercury_trace.h:
	Delete the typedefs for MR_FrameLimit and friends.

trace/mercury_trace_cmd_backward.c:
trace/mercury_trace_external.c:
	Conform to the above change.

trace/*.c:
	Change the signedness of conversion specifiers to conform
	to recent type changes.
2007-10-02 17:04:38 +00:00
Julien Fischer
4bf295460a Fix up some places in the trace directory where there were (potential)
Estimated hours taken: 5
Branches: main

Fix up some places in the trace directory where there were (potential)
mismatches between the sizes of types used to represent natural numbers.
Much of the existing code in the trace directory assumed that
sizeof(int) == sizeof(MR_Unsigned), which is not true on our 64-bit
machines.  Zoltan's recent change to MR_trace_is_natural_number() broke
that assumption in a lot of places.  (I committed a workaround for that
yesterday.)

This diff addresses the above problem by changing the types of many of
things that represent natural numbers from int to MR_Unsigned.
This should make the trace code more robust on 64-bit machines and
help avoid a recurrence of problems like the above.

NOTE: this change does not change slot numbers into unsigned values since
they still use negative values as sentinels.  I will address slot numbers
in as part of a separate change.

trace/mercury_trace.h:
	Add typedefs for MR_Unsigned for several commonly used quantities
	within the trace code.  For I/O action numbers we just re-use
	the type MR_IoActionNum from the runtime, rather than defining
	a new typedef here.

trace/mercury_trace_tables.h:
	Change the type of the `match_proc_max' and `match_proc_next' fields
	of the MR_MatchesInfo structure into MR_Unsigned instead of int.

trace/mercury_trace_cmd_parameter.[ch]:
	Change the type of the global variables, MR_scroll_{limit,next}
	and MR_num_context_lines into MR_Unsigned instead of int.

trace/mercury_trace_util.[ch]:
	Restore Zoltan's change that made the type of the second argument of
	MR_trace_is_natural_number() into MR_Unsigned.  The places that
	caused this to break on 64-bit machines have now been fixed.

	Update the documentation of MR_trace_is_natural_number();

	Delete MR_trace_is_unsigned() since that now duplicates
	MR_trace_is_natural_number().

	Add a new function MR_trace_is_nonneg_int() which is similar
	to the above functions except that it stores its result in
	an int.  (This is needed for handling slot numbers which are
	still represented using ints.)

trace/mercury_trace_cmd_developer.c:
	Refactor some code so that we don't need to use -1 as a sentinel
	value.

trace/mercury_trace_cmd_help.c:
	Use MR_trace_is_nonneg_int() instead of MR_trace_is_natural_number()
	to handle slot numbers.

runtime/mercury_trace_base.[ch]:
	Change the type of the first argument of MR_trace_get_action()
	from int to MR_IoActionNum.

trace/mercury_trace_alias.c:
trace/mercury_trace_cmd_backward.c:
trace/mercury_trace_cmd_breakpoint.c:
trace/mercury_trace_cmd_browsing.c:
trace/mercury_trace_cmd_dd.c:
trace/mercury_trace_cmd_exp.c:
trace/mercury_trace_cmd_forward.c:
trace/mercury_stack_trace.c:
trace/mercury_trace_internal.c:
trace/mercury_trace_spy.[ch]:
trace/mercury_trace_vars.[ch]:
	Use MR_Unsigned instead of int to represent natural numbers.
2007-10-02 03:37:29 +00:00
Zoltan Somogyi
b61ea9de44 Implement a large chunk of the code that was previously missing for .mmos
Estimated hours taken: 20
Branches: main

Implement a large chunk of the code that was previously missing for .mmos
grades. The system now correctly computes several answers for the tc_minimal
test case, before going into an infinite loop (since the code for recognizing
the absence of further solutions is not yet there).

Significantly improve the infrastructure for debugging such changes.

compiler/table_gen.m:
	Complete the mmos transformation.

compiler/proc_gen.m:
	Handle the special return requirements of mmos generators, which must
	return not to a caller (since each generator is the root of its own
	SLD tree), but to a consumer in another SLD tree that is waiting for an
	answer.

compiler/hlds_pred.m:
	Provide a mechanism whereby table_gen.m can communicate to proc_gen.m
	the requirement for this special return.

compiler/trace_gen.m:
	When generating events, include the port and the goal path in a
	comment. This makes the generated C code significantly easier to
	understand.

compiler/layout_out.m:
	Export a function for trace_gen.m to use.

compiler/hlds_goal.m:
	Change goal_path_to_string to a function to make it easier to use.

compiler/*.m:
	Conform to the change to goal_path_to_string.

runtime/mercury_context.[ch]:
	In .mmos grades, include the current debugger call sequence number,
	depth, and event number in contexts, to be saved and loaded with
	the contexts. This allows each context to have its own separate
	sequence of events.

	This capability depends not directly on the grade, but on the macro
	MR_EXEC_TRACE_INFO_IN_CONTEXT. For now, this is defined only in .mmos
	grades, but in future, it may be useful in other grades as well.

runtime/mercury_conf_param.h:
	Define and document MR_EXEC_TRACE_INFO_IN_CONTEXT.

runtime/mercury_mm_own_stacks.[ch]:
runtime/mercury_tabling_preds.h:
	Implement some predicates needed by the own stack transformation.
	Implement the code for generators returning answers to consumers,
	and the code for consumers scheduling generators when they need
	more answers. At the moment, the code for detecting when generators
	depend on each other is not yet written.

	Provide better facilities for debugging own stack minimal model grades.

	Fix a cut-and-paste bug (wrong macro name guarding the handwritten
	C module).

runtime/Mmakefile:
	Rebuild only what needs to be rebuilt when mercury_tabling_preds.h
	changes.

runtime/mercury_label.[ch]:
	Add a utility function for returning the name of an arbitrary label
	(internal or entry).

	Rename some fields to give them MR_ prefixes.

	Always define the functions for recording both entry and internal
	labels, even if they are not called from most modules, since they
	may be called from a few handwritten modules in the runtime.

	Rename a function to avoid a clash with the name of a macro,
	and thus allow the change to mercury_goto.h.

runtime/mercury_goto.h:
	Fix a bug with MR_init_entry_an. This macro was supposed to always
	insert the entry label that is its argument into the entry table,
	but instead of calling the function it was meant to call, it called
	a macro that could be (and usually way) defined to expand to nothing.

	The fix is to call the function a different name than the macro,
	and to call the function, not the macro.

runtime/mercury_wrapper.c:
	In own stack minimal model grades, create a main context separate
	from the current context, since the current context may be needed
	to hold a generator's state. Make MR_eng_this_context point to
	this context.

	Register all labels in the debugging variants of minimal model grades.

runtime/mercury_accurate_gc.c:
runtime/mercury_agc_debug.c:
runtime/mercury_debug.c:
library/exception.m:
	Conform to the change to runtime/mercury_label.h.

runtime/mercury_stack_trace.c:
	Conform to the change to runtime/mercury_label.h.

	Document the link to trace/mercury_trace_internal.c.

trace/mercury_trace.[ch]:
trace/mercury_trace_cmd_forward.c:
	Split the GOTO command into two: STEP and GOTO. STEP always stops
	at the next event (without any test), even if it is in a different
	context (and possibly with a lower event number than the immediately
	previous event, since the event numbers in different contexts are
	not related). As before, GOTO always goes to the specified event
	number, but in .dmmos grades it can now be told that this event number
	should be matched only in a specified context. The specification is
	done by an extra argument specifying the short name of the context's
	generator; the ansence of such an argument means the main context.

trace/mercury_trace_cmd_internal.c:
	In own stack grades, when the current context is that of a generator,
	print the subgoal the generator is working on before the event number,
	call depth, call sequence number and the rest of the event report.

	Document the link to runtime/mercury_stack_trace.c, which has similar
	code.

trace/mercury_trace_cmd_external.c:
trace/mercury_trace_cmd_declararive.c:
	Use the STEP command where GOTO was used for this simpler job,
	since this is (very slightly) faster.

trace/mercury_trace_cmd_developer.c:
	Fix some bugs with handling own stack tables.

doc/user_guide.texi:
	Document the new functionality of the goto mdb command. The
	documentation is commented out, since .mmos grades are for developers
	only at the moment.

tools/lmc.in:
	Turn off C optimizations when C debugging is enabled. For some reason,
	the default value of --cflags-for-debug does not include -O0.
2007-01-03 05:17:21 +00:00
Zoltan Somogyi
45fd0daf5a Implement some of Mark's wish list for making user events more useful.
Estimated hours taken: 20
Branches: main

Implement some of Mark's wish list for making user events more useful.

1. When executing "print *" in mdb, we used to print both the values of all
   attributes and the values of all live variables. Since some attributes'
   values were given directly by live variables, this lead to some things being
   printed twice. This diff eliminates this duplication.

2. At user events, we now print the name of the event. Whether we print the
   other stuff we also print at events (the predicate containing the event,
   and its source location) is now controlled by a new mdb command,
   "user_event_context".

3. We would like different solvers to be compilable independently of one
   another. This means that neither solver's event set should depend on the
   existence of the events needed by the other solvers. This diff therefore
   eliminates the requirement that all modules of the program be compiled with
   the same event set specification. Instead, a program may contain modules
   that were compiled with different event sets. Each event set is named;
   the new requirement is that different named event sets may coexist in the
   program (each being used to compile some modules), but two event sets with
   the same name must be identical in all other respects as well (we need this
   requirement to prevent inconsistencies arising between different versions of
   the same event set).

4. We now generate user events even from modules compiled with --trace shallow.
   The problem here is that user events can occur in procedures that do not
   get caller events and whose ancestors may not get caller events either.
   Yet these procedures must still pass on debugger information such as call
   sequence numbers and the call depth to the predicate with the user event.
   This diff therefore decouples the generation of code for this basic debugger
   infrastructure information from the generation of call events by inventing
   two new trace levels, settable by the compiler only (i.e. not from the
   command line). The trace level "basic_user" is for procedures containing a
   user event whose trace level (in a shallow traced module) would otherwise be
   "none". The trace level "basic" is for procedures not containing a user
   event but which nevertheless may need to transmit information (e.g. depth)
   to a user event. For the foreseeable future, this means that shallow traced
   modules containing user events will have some debugging overhead compiled
   into *all* their procedures.

runtime/mercury_stack_layout.h:
	Add a new field to MR_UserEvent structures, giving the HLDS number of
	the variable representing each attribute.

	Add a new field to module layout structures, giving the name of the
	event set (if any) the module was compiled with.

	Add the new trace levels to the MR_TraceLevel type.

	Update the current layout structure version number.

runtime/mercury_stack_trace.[ch]:
	Allow the printing of the containing predicate's name and/or the
	filename/linenumber context to be turned off when printing contexts.
	Factor out some of the code involved in this printing.

	Give a bunch of variables better names.

	Rename a type to get rid of unnecessary underscores.

compiler/prog_data.m:
compiler/prog_event.m:
	Include the event set name in the information we have about the event
	set.

compiler/simplify.m:
	Mark each procedure and each module that contains user events
	as containing user events.

	Use the same technique to mark each procedure that contains parallel
	conjunctions as containing parallel conjunctions, instead of marking
	the predicate containing the procedure. (Switch detection may eliminate
	arbitrary goals, including parallel conjunctions, from switch arms
	that are unreachable due to initial insts, and in any case we want to
	handle the procedures of a predicate independently from each other
	after mode analysis.)

	Also, change the code handling generic calls to switch on the generic
	call kind, and factor out some common code.

compiler/hlds_module.m:
compiler/hlds_pred.m:
	Provide slots in the proc_info and the module_info for the information
	gathered by simplify.

compiler/trace_params.m:
	Implement the new trace levels described above. This required changing
	the signature of some of the predicates of this module.

compiler/code_info.m:
	Record whether the compiler generated any trace events. We need to know
	this, because if it did, then we must generate a proc layout structure
	for it.

compiler/proc_gen.m:
	Act on the information recorded by code_info.m.

	Factor out the code for generating the call event and its layout
	structure, since the conditions for generating this event have changed.

compiler/continuation_info.m:
compiler/call_gen.m:
	For each user event, record the id of the variables corresponding to
	each argument of a user event.

compiler/layout.m:
compiler/layout_out.m:
compiler/stack_layout.m:
	Generate the new field (giving the HLDS variable number of each
	attribute) in user event structures, and the new field (event set name)
	in module layout structures.

	Allow the call event's layout structure to be missing. This is needed
	for user events in shallow traced modules.

compiler/options.m:
compiler/handle_options.m:
compiler/mercury_compiler.m:
	Rename the option for specifying event sets from --event-spec-file-name
	to --event-set-file-name, since it specifies only one event set, not
	all events.

compiler/jumpopt.m:
	Give some predicates better names.

compiler/dep_par_conj.m:
compiler/deforest.m:
compiler/granularity.m:
compiler/hlds_out.m:
compiler/inlining.m:
compiler/intermod.m:
compiler/lambda.m:
compiler/liveness.m:
compiler/modes.m:
compiler/opt_debug.m:
compiler/optimize.m:
compiler/size_proc.m:
compiler/stack_alloc.m:
compiler/store_alloc.m:
compiler/table_gen.m:
compiler/trace_gen.m:
compiler/typecheck.m:
	Conform to the changes above.

doc/mdb_categories:
	Mention the new mdb command.

doc/user_guide.texi:
	Update the documentation of user events to account for the changes
	above.

trace/mercury_event_parser.y:
trace/mercury_event_scanner.l:
	Modify the grammar for event set specifications to a name for the
	event set.

trace/mercury_event_spec.[ch]:
	Instead of recording information about event sets internally
	in this module, return a representation of each event set read in
	to the callers, for them to do with as they please.

	Include the event set name when we print the Mercury term for
	compiler/prog_event.m.

trace/mercury_trace.c:
	Do not assume that every procedure that contains an event contains a
	call event (and hence a call event layout structure), since that
	is not true anymore.

trace/mercury_trace_cmd_parameter.[ch]:
	Implement the new mdb command "user_event_context".

trace/mercury_trace_cmd_internal.[ch]:
	Include "user_event_context" in the list of mdb commands.

	Print the user event name at user events. Let the current setting
	of the user_event_context mdb command determine what else to print
	at such events.

	Instead of reading in one event set on initialization, read in
	all event sets that occur in the program.

trace/mercury_trace_tables.[ch]:
	Allow the gathering of information for more than one event set
	from the modules of the program.

trace/mercury_trace_vars.[ch]:
	For each attribute value of a user event, record what the HLDS variable
	number of the attribute is. When printing all variables at an event,
	mark the variable numbers of printed attributes as being printed
	already, causing the variable with the same number not to be printed.

	Include the name of the variable (if it has one) in the description
	of an attribute. Without this, users may wonder why the value of the
	variable wasn't printed.

trace/mercury_trace_cmd_browsing.[ch]:
	Pass the current setting of the user_event_context mdb command to
	runtime/mercury_stack_trace.c when printing the context of an event.

tests/debugger/user_event_shallow.{m,inp,exp}:
	New test case to test the new functionality. This test case is the same
	as the user_event test case, but it is compiled with shallow tracing,
	and its mdb input exercises the user_event_context mdb command.

tests/debugger/user_event_spec:
tests/invalid/invalid_event_spec:
	Update these event set spec files by adding an event set name.

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

tests/debugger/user_event.exp:
	Update the expected output of the old user event test case, which now
	prints event names, but doesn't print attribute values twice.

tests/debugger/completion.exp:
	Expect the new "user_event_context" mdb command in the command list.

tests/debugger/mdb_command_test.inp:
	Test the existence of the documentation for the new mdb command.

tests/invalid/Mercury.options:
	Conform to the name change of the --event-spec-file-name option.
2006-12-05 03:51:22 +00:00
Zoltan Somogyi
455e1eea75 The runtime had two different conventions for naming types.
Estimated hours taken: 2
Branches: main

The runtime had two different conventions for naming types. One convention,
used mostly in the debugger-related modules, added underscores between
capitalized words; example: MR_Label_Layout. The other convention, used
in most modules, used capitalized words without underscores (e.g. MR_TypeInfo).

This diff standardizes on the second convention. It has no algorithmic changes,
only renames of types.

runtime/*.[ch]:
trace/*.[ch]:
compiler/*.m:
library/*.m:
mdbcomp/*.m:
	Effect the change described above. The only substantive change is that
	runtime/mercury_stack_layout.h used to define *two* types for trace
	levels: MR_TraceLevel and MR_Trace_Level, and this diff standardizes
	on just one (they had equivalent definitions).

runtime/mercury_bootstrap.h:
	Add a #define from the old name to the new for all the changed type
	names that the installed compiler can put into .c files. We can delete
	these #defines some time after this diff has bootstrapped.

slice/.mgnuc_opts:
	Restore the --no-mercury-stdlib-dir option, without which the slice
	directory won't compile after this change (because it looks for type
	names in the installed runtime header files, which define the old
	versions of type names).
2006-11-29 05:18:42 +00:00
Zoltan Somogyi
ecf1ee3117 Add a mechanism for growing the stacks on demand by adding new segments
Estimated hours taken: 20
Branches: main

Add a mechanism for growing the stacks on demand by adding new segments
to them. You can ask for the new mechanism via a new grade component, stseg
(short for "stack segments").

The mechanism works by adding a test to each increment of a stack pointer (sp
or maxfr). If the test indicates that we are about to run out of stack, we
allocate a new stack segment, allocate a placeholder frame on the new segment,
and then allocate the frame we wanted in the first place on top of the
placeholder. We also override succip to make it point code that will (1)
release the new segment when the newly created stack frame returns, and then
(2) go to the place indicated by the original, overridden succip.

For leaf procedures on the det stack, we optimize away the check of the stack
pointer. We can do this because we reserve some space on each stack for the
use of such stack frames.

My intention is that doc/user_guide.texi and NEWS will be updated once we have
used the feature ourselves for a while and it seems to be stable.

runtime/mercury_grade.h:
	Add the new grade component.

runtime/mercury_conf_param.h:
	Document the new grade component, and the option used to debug stack
	segments.

runtime/mercury_context.[ch]:
	Add new fields to contexts to hold the list of previous segments of the
	det and nondet stacks.

runtime/mercury_memory_zones.[ch]:
	Include a threshold in all zones, for use in stack segments.
	Set it when a zone is allocated.

	Restore the previous #ifdef'd out function MR_unget_zone, for use
	when freeing stack segments execution has fallen out of.

runtime/mercury_debug.[ch]:
	When printing the offsets of pointers into the det and nondet stacks,
	print the number of the segment the pointer points into (unless it is
	the first, in which case we suppress this in the interest of brevity
	and simplicity).

	Make all the functions in this module take a FILE * as an input
	argument; don't print to stdout by default.

runtime/mercury_stacks.[ch]:
	Modify the macros that allocate stack frames to invoke the code for
	adding new stack segments when we are about to run out of stack.

	Standardize on "nondet" over "nond" as the abbreviation referring to
	the nondet stack.

	Conform to the changes in mercury_debug.c.

runtime/mercury_stack_trace.c:
	When traversing the stack, step over the placeholder stack frames
	at the bottoms of stack segments.

	Conform to the changes in mercury_debug.c.

runtime/mercury_wrapper.[ch]:
	Make the default stack size small in grades that support stack
	segments.

	Standardize on "nondet" over "nond" as the abbreviation referring to
	the nondet stack.

	Conform to the changes in mercury_debug.c.

runtime/mercury_memory.c:
	Standardize on "nondet" over "nond" as the abbreviation referring to
	the nondet stack.

runtime/mercury_engine.[ch]:
runtime/mercury_overflow.h:
	Standardize on "nondet" over "nond" as the abbreviation referring to
	the nondet stack.

	Convert these files to four-space indentation.

runtime/mercury_minimal_model.c:
trace/mercury_trace.c:
trace/mercury_trace_util.c:
	Conform to the changes in mercury_debug.c.

compiler/options.m:
	Add the new grade option for stack segments.

compiler/compile_target_code.m:
compiler/handle_options.m:
	Add the new grade component, and handle its exclusions with other grade
	components and optimizations.

compiler/llds.m:
	Extend the incr_sp instruction to record whether the stack frame
	is for a leaf procedure.

compiler/llds_out.m:
	Output the extended incr_sp instruction.

compiler/proc_gen.m:
	Fill in the extra slot in incr_sp instructions.

compiler/goal_util.m:
	Provide a predicate for testing whether a procedure body is a leaf.

compiler/delay_slot.m:
compiler/dupelim.m:
compiler/dupproc.m:
compiler/exprn_aux.m:
compiler/frameopt.m:
compiler/global_data.m:
compiler/jumpopt.m:
compiler/middle_rec.m:
compiler/opt_debug.m:
compiler/opt_util.m:
compiler/peephole.m:
compiler/reassign.m:
compiler/use_local_vars.m:
	Conform to the change in llds.m.

scripts/canonicate_grade.sh-subr:
scripts/init_grade_options.sh-subr:
scripts/parse_grade_options.sh-subr:
scripts/final_grade_options.sh-subr:
scripts/mgnuc.in:
	Handle the new grade component.

	Convert parse_grade_options.sh-subr to four-space indentation.

Mmake.workspace:
	Fix an old bug that prevented bootcheck from working in the new grade:
	when computing the gc grade, use the workspace's version of ml (which
	in this case understands the new grade components), rather than the
	installed ml (which does not).

	(This was a devil to track down, because neither make --debug nor
	strace on make revealed how the installed ml was being invoked,
	and there was no explicit invocation in the Makefile either; the error
	message appeared to come out of thin air just before the completion
	of the stage 2 library. It turned out the invocation happened
	implicitly, as a result of expanding a make variable.)
2006-11-01 02:31:19 +00:00
Zoltan Somogyi
9eed887d33 This diff is the second step in implementing trace events.
Estimated hours taken: 24
Branches: main

This diff is the second step in implementing trace events. It modifies
label layouts to include room for solver-event-specific information, and
modifies the compiler to generate this information. Modifications to the
debugger to use this information, user-level documentation and test cases
will come later.

runtime/mercury_stack_layout.h:
	Modify label layouts to allow them to hold information about solver
	events.

	Modify the macros creating label layouts to include a null pointer
	as the value of the label layout's solver event field. For each such
	macro, add a version that puts a pointer to the label's solver event
	structure in that field.

	Modify the definition of the MR_Long_Lval type to allow the
	representation of constants, since without this capability solver
	events would often need to be preceded by code to put constant
	values (e.g. solver ids) into lvals. To make it easier to locate
	all the places where MR_Long_Lvals are used (which need to be updated),
	change the type MR_Long_Lval from a synonym for an int to a structure
	containing an int.

runtime/mercury_types.h:
	Add the typedefs now required for mercury_stack_layout.h.

runtime/mercury_goto.h:
	Add a macro needed by mercury_stack_layout.h.

runtime/mercury_grade.h:
	Change the binary compatibility version number for debug grades,
	due to the change to label layouts.

runtime/mercury_layout_util.c:
	Update the functions interpreting MR_Long_Lvals to conform to the
	change in mercury_stack_layout.h.

runtime/mercury_deep_profiling_hand.h:
	Fix a bug, possibly the bug preventing us from bootchecking in deep
	profiling grades: stack slot numbers of ProcStatic structures are
	supposed to be plain integers, not MR_Long_Lvals.

runtime/mercury_stack_trace.c:
library/exception.m:
trace/mercury_trace.c:
	Conform the change in MR_Long_Lval.

runtime/mercury_trace_base.[ch]:
	Add a new port: the solver event port.

	Add a macro and a function for solver events: MR_SOLVER_EVENT and
	MR_solver_trace. For now, they do the same thing as MR_EVENT and
	MR_trace, but in future, they can do something else (e.g. generate
	information for a visualization tool).

mdbcomp/prim_data.m:
	Add a new port: the solver event port.

	Rename all ports to eliminate clashes with language keywords such as
	"call".

mdbcmp/trace_counts.m:
browser/declarative_execution.m:
slice/mcov.m:
compiler/tupling.m:
	Conform to the change in port names, and to the addition of the new
	port.

compiler/trace_params.m:
	Conform to the change in port names, and to the addition of the new
	port.

	Rename some function symbols to avoid some ambiguities.

trace/mercury_trace_declarative.c:
	Ignore the solver port when building the annotated trace, since it
	doesn't fit into it.

compiler/prog_event.m:
	Extend the representation of events to include names for the event
	attributes.

compiler/call_gen.m:
	Implement event goals. The implementation consists of a call to
	MR_SOLVER_EVENT with a layout structure whose solver event field
	points to a solver event structure giving the event goal's arguments.

	Rename some function symbols to avoid some ambiguities.

compiler/trace_gen.m:
	Add a predicate for generating solver events.

	Conform to the change in port names.

	Rename some function symbols to avoid some ambiguities.

compiler/code_info.m:
	When recording trace layout information for a label, take an extra
	argument describing the label layout's associated solver event, if any.

compiler/continuation_info.m:
	Extend the first representation of label layouts to include room
	for solver events.

compiler/stack_layout.m:
	Convert the representation of solver events in continuation_info.m's
	data structure to the data structure required by layout_out.m.

	Conform to the changes in MR_Long_Lvals.

compiler/layout.m:
	Extend the compiler's internal representation of the contents of label
	layout structures to accommodate the optional solver event field.

compiler/layout_out.m:
	Generate the extended label layout structures, using the new macros
	in mercury_stack_layout.h if necessary.

	Conform to the change in the MR_Long_Lval type.

	Conform to the change in port names.

	Rename some function symbols to avoid some ambiguities.

compiler/global_data.m:
	Modify rval_type_as_arg to require only the value of the relevant
	option, not a package of such options. This is for the new code
	in stack_layout.m.

compiler/var_locn.m:
	Conform to the change in global_data.m.

compiler/llds_out.m:
	Conform to the change in continuation_info.m.

	Delete this module's unused definition of rval_type_as_arg.

compiler/opt_debug.m:
	Conform to the change in continuation_info.m.
2006-09-29 06:34:57 +00:00
Zoltan Somogyi
c708b19d20 Minor formatting fixes.
Estimated hours taken: 0.1
Branches: main

runtime/mercury_stack_trace.c:
	Minor formatting fixes.
2005-09-19 08:04:18 +00:00
Mark Brown
67791773af Fix some warnings and type errors that show up on the x86_64 architecture.
Estimated hours taken: 3
Branches: main

Fix some warnings and type errors that show up on the x86_64 architecture.

browser/io_action.m:
	Declare is_func in the C code for pickup_io_action to be MR_Bool
	rather than MR_bool, since it is a (word sized) Mercury bool, not
	a C boolean.

library/construct.m:
runtime/mercury_unify_compare_body.h:
	Provide values for variables even when MR_fatal_error is called,
	to avoid warnings about uninitialized variables.  Add default
	switch cases which call MR_fatal_error.

mdbcomp/rtti_access.m:
	Pass an int* to MR_find_context, and cast the result to an MR_Integer
	afterwards.

robdd/bryant.h:
	This code incorrectly assumes that unsigned long will have 32 bits.
	Flag the error with an XXX.

runtime/mercury_deconstruct.c:
trace/mercury_trace_internal.c:
	Cast arity values to int before printing.  We don't support
	arity > 1024 anyway.

runtime/mercury_proc_id.h:
runtime/mercury_types.h:
	Add an extra branch to the MR_Proc_Id union for the case when no
	proc id is present, and add a macro to test for this case.  We can't
	test the enum directly as we did before, because C compilers may
	report a warning that the test will never succeed (since -1 is not
	one of the values in the enum).

	Clarify the comment about the requirement of MR_PredFunc to match
	prim_data.pred_or_func.

	Define a macro for the value that indicates there is no proc id.

	Fix a couple of out-of-date comments.

trace/mercury_trace_browse.h:
	Clarify the comments about the requirement of MR_Browse_Caller_Type,
	MR_Browse_Format and MR_Query_Type to match their corresponding
	Mercury types.

runtime/mercury_tags.h:
	Add a comment to point out that enums don't necessarily have the
	same size as MR_words.

runtime/mercury_stack_layout.h:
	Use the new macro instead of testing directly whether the proc id
	exists.

runtime/mercury_stack_trace.c:
runtime/mercury_trace_base.c:
runtime/mercury_type_info.c:
trace/mercury_trace_internal.c:
	Use MR_INTEGER_LENGTH_MODIFIER, which is set by `configure', to
	get the right format specifier when printing integers with the same
	size as MR_Word.

runtime/mercury_type_info.c:
	Compare pseudo-typeinfos as MR_Integers rather than ints.

trace/mercury_trace.c:
trace/mercury_trace_tables.c:
	Provide a dummy value for variables to avoid uninitialized variable
	warnings.

trace/mercury_trace_completion.c:
	Cast a void* to MR_Integer before casting it to int.  It would be
	nicer to avoid the second cast altogether, but the readline interface
	requires it.

trace/mercury_trace_internal.c:
	Use MR_trace_is_unsigned when working with MR_Unsigned values.

	Cast pseudo-typeinfos which are variables to MR_Integer rather than
	int, to avoid compiler warnings about pointer casts.  We cast them
	to int before printing them, but that is because we know they won't
	be that big.

	Parse the argument to the goto command as type MR_Unsigned instead
	of int, to make it possible to goto an event with a number bigger
	than 2^31, on 64-bit machines at least.  (We already get 200M+
	events when the compiler is in a debug grade.)

trace/mercury_trace_util.c:
trace/mercury_trace_util.h:
	Provide MR_trace_is_unsigned, which is like MR_trace_is_natural_number
	except that it works with MR_Unsigned values.

trace/mercury_trace_vars.c:
	Cast void* to MR_Integer rather than int.
2005-09-01 07:37:26 +00:00
Ian MacLarty
436c5e6a6f Add --resume option to `dd' command. This resumes the previous declarative
Estimated hours taken: 25
Branches: main

Add --resume option to `dd' command.  This resumes the previous declarative
debugging session and allows the user to switch between the procedural and
declarative debuggers freely.

browser/declarative_analyser.m
	Add analysis_type type which is used to tell the analyser whether
	it must start a new session or resume a previous session.

browser/declarative_debugger.m
	Add two versions of the exported diagnosis predicate: one to
	resume a previous session and one to start a new session.

browser/declarative_user.m
	Print usage message to the correct output stream.

doc/user_guide.texi
	Document the new option.

runtime/mercury_stack_trace.c
runtime/mercury_stack_trace.h
	Add a function to find the first call on the stack whose event
	number is less than or equal to a given event number or whose
	call sequence number is less than or equal to a given call sequence
	number.

	Since this new function uses some code very similar to existing
	code in the function that prints the stack, separate this code into
	a new function called MR_call_details_are_valid.

trace/mercury_trace_declarative.c
trace/mercury_trace_declarative.h
	Previously it could be safely assumed that the current event would
	be somewhere inside the materialized portion of the annotated trace,
	so it was sufficient to record the topmost node of the annotated
	trace and retry to there whenever we needed to build a new subtree
	(and to the topmost node plus some extra for a supertree).

	Now, however, the user may go to any event in the program before
	resuming the previous dd session.  We could just retry to the call
	event for main/2, but this would be far from optimal, especially if the
	user is debugging code deep down in the program's call tree.

	Instead we retry to the first call on the stack whose event number
	is less than or equal to the call event number of the node we
	want to build a subtree for and then start forward execution from
	there.  When building a supertree we retry to the first call on the
	stack whose event number is less than or equal to the event number of
	the call at the top of the currently materialized portion of the
	annotated trace.  Then when we get to the call at the top of the
	currently materialized portion of the annotated trace through forward
	execution, we do a retry to the desired depth and start building the
	new supertree.

	Desribe the function of some of the global variables in more detail.

	Remove the global MR_edt_topmost_call_depth since it is no longer
	needed.

	Fix an inconsistency where the depth limit was being set to
	MR_edt_depth_step_size when starting a dd session, but to
	MR_edt_depth_step_size + 1 when building an additional portion of the
	annotated trace.

	Don't update the saved event details from the global event
	number/seqno/depth variables at the start of MR_decl_diagnosis.  The
	globals could have been updated by a previous call to Mercury code and
	could have incorrect values.

tests/debugger/declarative/Mmakefile
tests/debugger/declarative/resume.exp
tests/debugger/declarative/resume.inp
tests/debugger/declarative/resume.m
	Test the --resume option.  Specifically test the creation of a
	supertree and subtree from a resumed session where the user
	has gone to an event before and after the materialized portion
	of the annotated trace.

trace/mercury_trace_internal.c
	Handle the --resume option.
2005-03-02 01:20:23 +00:00
Zoltan Somogyi
4d443a5c9e Make the stack and nondet_stack commands in mdb limit the number of lines
Estimated hours taken: 3
Branches: main

Make the stack and nondet_stack commands in mdb limit the number of lines
printed, instead of the number of stack frames reported on.

runtime/mercury_stack_trace.[ch]:
	Add a mechanism to limit the number of lines printed by stack traces.

trace/mercury_trace_internal.c:
	Change the existing "stack" and "nondet_stack" mdb commands to make the
	integer argument specify the number of lines printed by default, not
	the number of stack frames reported on, since this is usually what is
	wanted. The number of stack frames N to be reported on can still be
	specified, via the new option -fN.

	Add a new mdb command, "stack_default_limit", that specifies the
	default number of lines to print in stack traces.

trace/mercury_trace_external.c:
	Conform to the changed interfaces in mercury_stack_trace.h.

doc/user_guide.texi:
	Document the changes to mdb commands.

tests/debugger/mdb_command_text.inp:
	Test the documentation of the new command.

tests/debugger/completion.exp*:
	Expect to see the new stack_default_limit command listed.

tests/debugger/queens.exp*:
	Expect the new meaning of the stack command.

tests/debugger/nondet_stack.{inp,exp*}
	Use the new -f option of the nondet_stack command to specify the
	printing of the same number of frames as before. Update the expected
	accordingly.
2005-01-17 05:58:10 +00:00
Zoltan Somogyi
f71532a398 Add an mdb command, all_procedures, for listing all the procedures in the
Estimated hours taken: 2
Branches: main

Add an mdb command, all_procedures, for listing all the procedures in the
program. It has two options: -u or --uci for listing unify, compare, index and
init predicates, and -s or --separate for printing the various parts of
procedure names in separate fields, for automatic processing (e.g. by awk
scripts).

trace/mercury_trace_internal.c:
	Implement all_procedures.

	Fix a couple of small bugs: a wrong help category argument in an option
	processing call, and a NULL completer function.

trace/mercury_trace_tables.[ch]:
	Provide a function that is the guts of all_procedures.

	Fix the code for handling the specification of unify, compare and
	index procedures to also handle init procedures.

doc/user_guide.texi:
	Document all_procedures.

runtime/mercury_stack_trace.[ch]:
	Add a new function for printing procedure ids for all_procedures -s.

	Fix the code for printing unify, compare and index predicates to also
	handle init predicates.

tests/debugger/solver_test.{m,inp,exp}:
	A new test case to test the fix of the printing of init predicates.

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

tests/debugger/mdb_command_test.inp:
tests/debugger/completion.exp:
	Update these files to account for the new mdb command.
2004-12-09 01:03:22 +00:00
Ian MacLarty
e6d82c9bd4 Added trusted' and untrust' commands. Also allowed individual predicates to
Estimated hours taken: 10
Branches: main

Added `trusted' and `untrust' commands.  Also allowed individual predicates to
be trusted.

browser/declarative_debugger.m
	Exported predicates to add a trusted predicate or function, remove
	a trusted object and return a list of the trusted objects.

browser/declarative_oracle.m
	Changed trusted set so it can also contains individual predicates and
	functions.  Added predicates to add a trusted predicate or function
	to the set, remove a trusted object from the set and return a list
	of the trusted objects.

doc/mdb_categories
	Added dd category.

doc/user_guide.texi
	Documented `untrust' and `trusted' commands.

runtime/mercury_stack_trace.c
runtime/mercury_stack_trace.h
	Added a print_mode argument to MR_print_proc_id_internal, so that
	printing of mode information can be turned on or off.  When a list
	of matching predicates for the trust command is shown then mode
	information is superfluous, since a predicate/function is trusted, not
	a procedure.
	Added MR_print_pred_id to print predicate id - i.e. proc id without
	the mode info.

tests/debugger/completion.exp
	New commands shown in completion list.

tests/debugger/completion.inp
	Added a space, since a --More-- prompt is now displayed when showing
	all the commands.

tests/debugger/mdb_command_test.inp
	untrust and trusted added.

tests/debugger/declarative/trust.exp
tests/debugger/declarative/trust.inp
	Testing of new commands.

trace/mercury_trace_declarative.c
trace/mercury_trace_declarative.h
	Added functions to add a trusted predicate and remove a trusted
	object.  Also added a function to print a list of the trusted objects.
	These all call the predicates exported from declarative_debugger.m.

trace/mercury_trace_internal.c
	Added handlers for `trusted' and `untrust' commands.

trace/mercury_trace_tables.c
trace/mercury_trace_tables.h
	Added a function to filter out only the user predicates and functions
	from a list of procedures.  This filters out uci procs and also
	filters out all procs with a mode number > 0 (thus leaving one proc
	for each predicate/function).  This is used when displaying the
	predicates matching an ambiguous proc-spec with a trust command.

NEWS
	Updated NEWS file.
2004-09-20 04:50:26 +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
642c902c90 Reduce the sizes of .c and .o files in debug grades by 8%.
Estimated hours taken: 4
Branches: main

Reduce the sizes of .c and .o files in debug grades by 8%.

Add to mdb the capability of putting breakpoints on unify, compare and index
predicates.

compiler/code_gen.m:
	Since compiler-generated unify, index and compare pred can be presumed
	to be correct, compile them with shallow tracing instead of deep
	tracing even if the user asks for deep tracing of the rest of the
	module. This saves disk space, compile time and run time.

	Move the code for setting the trace level to generate_proc_code,
	where it is executed whether we generate code by predicates or by
	phases.

compiler/trace_params.m:
	Provide a function for use by code_gen.m.

	Consider unify and compare predicates to behave as if their address
	were taken, since they may be called from builtin.unify or
	builtin.compare.

compiler/jumpopt.m:
	Do not replace jumps with the block being jumped to if the block
	contains an instruction that represents a call to the debugger.
	In such cases, the jump is a minor cost in runtime compared to the
	call, and the locality benefit from not increasing the code size is
	quite likely to exceed that cost.

compiler/llds.m:
	Add field names to pragma_c instructions to make the change to jumpopt
	easier.

tests/debugger/uci.{inp,exp}:
	Update this test case. An update is required since we now generate
	fewer events from unify and compare preds due to their now being
	shallow traced.

	To make this the update easier, use the new capability of putting
	breakpoints on unify and compare predicates.

trace/mercury_trace_tables.[ch]:
	Expand procedure specifications to allow the specification of unify,
	compare and index predicates, and expand the function that checks for
	matches between a procedure layout and a procedure specification
	accordingly.

	Fix two instances of a bug: if a procedure specification has no name,
	represent it as NULL, not as a non-NULL pointer to a null character,
	since the match function expects only the former.

doc/user_guide.texi:
	Document the new definition of procedure specifications.

NEWS:
	Mention the new definition of procedure specifications, and expand
	on some previous additions to the debugger.

runtime/mercury_stack_trace.c:
	Allow mdb breakpoint specifications on uci predicates to be saved.

	Factor out some common data structure accesses.

runtime/mercury_proc_id.h:
	Change the name of a macro from MR_PROC_ID_COMPILER_GENERATED to
	MR_PROC_ID_IS_UCI, for consistency with other names dealing with
	unify, compare and index predicates.

runtime/*.[ch]:
trace/*.[ch]:
	Conform to the change in mercury_proc_id.h.
2004-05-23 22:16:57 +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
Zoltan Somogyi
8b9d436cbb More improvements for minimal model tabling.
Estimated hours taken: 12
Branches: main

More improvements for minimal model tabling.

runtime/mercury_engine.[ch]:
	Provide a debug flag to control the printing of debug stack slots
	in nondet stack dumps.

runtime/mercury_stack_trace.[ch]:
	Provide a mechanism that allows a dump of the nondet stack to print
	the principal debugging stack slots of the stack frames of procedures
	that were compiled with debugging, to help debug problems where
	these are overwritten during stack segment saves/restores.

	Add a mechanism for limiting the output of a nondet stack trace
	to a segment of the nondet stack.

runtime/mercury_minimal_model.[ch]:
	Limit the output of a diagnostic nondet stack trace to just the
	segment being saved or restored.

	Provide a label layout structure for the entry point of the suspend
	predicate, since this is necessary for correct nondet stack traces
	at suspensions and resumptions.

	Store the layout structure of the top nondet stack frame with each
	saved state, to allow the saved nondet stack segment to be dumped
	at resumptions as well as suspensions.

	Fix an old bug: when extending a saved stack segment, use the same
	algorithm for determining its lower bound as when the stack segment
	was created in the first place.

	Factor out some repeated definitions.

	Note problems to be fixed later.

	Improve debugging output.

runtime/mercury_stacks.[ch]:
	Move the documentation of the generator stack, the cut stack and the
	pneg stack from the source file to the header file, and expand it
	considerably.

	Make the routines for printing entries of these stacks generate more
	consistently formatted output.

	Simplify some code.

runtime/mercury_stack_layout.h:
	Provide a macro for use by mercury_minimal_model.c.

runtime/mercury_trace_base.[ch]:
	Save and restore the global variables holding event numbers,
	call sequence numbers and call depths across debugging Mercury code.
	We already used to do this for Mercury code invoked by the debugger,
	but now that we can invoke Mercury code to print the values of
	variables as diagnostics from within the suspend and resume predicates
	*outside* the debugger, we need to do it more generally.

trace/mercury_trace.c:
	Fix a bug: provide the layout structure of the current procedure
	to the diagnostic routines for minimal model tabling even if the
	debugger doesn't stop at that procedure.

trace/mercury_trace_internal.c:
	Add two new mdb commands to help debug minimal model tabling.

	The "mm_stack" command has the same effect as the existing commands
	"gen_stack", "cut_stack" and "pneg_stack" executed in sequence.

	The "debug_vars" command prints the counters for event numbers,
	call sequence numbers and call depths, both from their global variables
	and their saved copies, for debugging problems where they are
	overwritten, such as the one fixed by the changes to
	mercury_trace_base.[ch] above.

	Reorder some code for consistency.

trace/mercury_trace_util.[ch]:
	Add a function to implement the "debug_vars" command.

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

doc/mdb_categories:
	Add the new mdb commands to the list of developer commands, as well
	some others previously left out.

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

tests/tabling/combine.m:
	Change the code of this test case to what was intended, so that it now
	matches the old expected output.

tests/tabling/completed_consumer_in_solutions.{m,exp}:
	New test case, an easier version of consumer_in_solutions.

tests/tabling/consumer_in_commit.{m,exp}:
	Extend this test case and update the expected output; we can execute
	both the original code and the extension without runtime exceptions.

tests/tabling/seq2.m:
	Fix Kostis's new test case.

tests/tabling/seq4.exp:
	Fix the expected output of Kostis's new test case.

tests/tabling/Mmakefile:
	Enable the new test cases, and some old test cases that we now pass.
2004-03-12 06:02:19 +00:00
Zoltan Somogyi
759f76a314 Make debugging of minimal model tabling more convenient.
Estimated hours taken: 1.5
Branches: main

Make debugging of minimal model tabling more convenient.

compiler/handle_options.m:
	Make -Dmm generate HLDS dumps tailored for understanding the
	code of procedures transformed by minimal model tabling.

runtime/mercury_minimal_model.c:
	When printing the stack segments being saved, print the values of
	variables in the affected stack frames.

runtime/mercury_stack_trace.c:
	When dumping the nondet stack, print the name of the procedure
	that established each ordinary frame, and the goal path at which
	control will reenter the stack frame, if this information is available.

	Since mercury_minimal_model.c now asks for the printing of variable
	values (which is done by Mercury code) while execution is outside
	the debugger and hence while execution tracing may be enabled,
	explicitly turn off debugging while in the Mercury code that prints
	variable values.

runtime/mercury_trace_base.[ch]:
	Provide a simple mechanism for turning off debugging functionality
	in a region of code.

trace/mercury_trace_internal.c:
	Use the new mechanism in mercury_trace_base to handle turning off
	debugging output inside the debugger. This also allows us to simplify
	the code implementing the "flag" mdb command.

	Make the reports generated by the "unhide_events" and "table_io"
	commands follow the same format as other commands.

	Note that mercury_trace_declarative.c doesn't use the new mechanism,
	because it wants the reexecution of the call being debugged to be
	exactly the same as its first execution; in particular, turning off
	I/O tabling for reexecution would generate incorrect results.

tests/debugger/nondet_stack.exp*:
tests/debugger/tabled_read.exp*:
tests/debugger/tabled_read_decl.exp*:
tests/debugger/tabled_read_unitize.exp*:
tests/debugger/io_stream_test.exp*:
tests/debugger/declarative/tabled_read_decl.exp*:
	Update the expected out of these test cases to reflect the new
	functionality above.
2004-03-10 04:31:06 +00:00
Fergus Henderson
1361805c5e A bug fix for accurate GC.
Estimated hours taken: 4
Branches: main

A bug fix for accurate GC.

runtime/mercury_stack_trace.c:
	In MR_init_nondet_branch_infos(), skip past any deterministic
	frames until we find the first nondet frame (if any).
2004-01-05 08:59:50 +00:00
Fergus Henderson
b274728218 More improvements to LLDS accurate GC.
Estimated hours taken: 8
Branches: main

More improvements to LLDS accurate GC.

runtime/mercury_accurate_gc.c:
	Rewrite the LLDS accurate GC stack traversal code using
	MR_stack_walk_step() and MR_traverse_nondet_stack_from_layout().
	The previous code had some serious bugs.

runtime/mercury_stack_trace.h:
runtime/mercury_stack_trace.c:
	Don't pass `level_number' to the traversal function for
	MR_traverse_nondet_stack_from_layout().  It's not needed.

runtime/mercury_stack_trace.c:
	Add a comment, and an assertion.
2003-11-18 07:02:28 +00:00
Fergus Henderson
5f3bc648d7 Some more refactoring.
Estimated hours taken: 1
Branches: main

Some more refactoring.

runtime/mercury_stack_trace.h:
runtime/mercury_stack_trace.c:
	Move the code for dumping the information about the frame category
	from MR_step_over_nondet_frame() to MR_dump_nondet_stack_frame().
2003-11-13 05:36:21 +00:00
Fergus Henderson
b31ef626ce A first step towards fixing a serious problem with the LLDS accurate
Estimated hours taken: 2
Branches: main

A first step towards fixing a serious problem with the LLDS accurate
garbage collector where it does not handle traversing the nondet
stack correctly.  This step does not change any algorithms; it
just refactors some code to make it more reusable.

runtime/mercury_stack_trace.h:
runtime/mercury_stack_trace.c:
	Define a new function MR_traverse_nondet_stack_from_layout,
	which is like MR_dump_nondet_stack_from_layout, except that
	instead of dumping each frame, it instead just calls a
	caller-supplied traversal function on each frame.
	This is for (eventual) use by mercury_accurate_gc.c.

runtime/mercury_accurate_gc.c:
	Add an XXX comment, saying that we should use
	MR_traverse_nondet_stack_from_layout().
2003-11-11 09:12:26 +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
Zoltan Somogyi
2bf6095986 Add a mechanism to limit the output from the "stack" and "nondet_stack"
Estimated hours taken: 4
Branches: main

Add a mechanism to limit the output from the "stack" and "nondet_stack"
mdb commands to a given number of stack frames. (We may later add a
mechanism to limit the output to a given number of lines, but that
is significantly harder, since it requires knowing how wide the
terminal is and which lines exceed that width.)

NEWS:
	Mention the new capability.

doc/user_guide.texi:
	Document the new optional arguments of the two commands.

trace/mercury_trace_internal.c:
	Implement the new optional arguments.

	Fix some places where we weren't checking that a natural number
	we were expecting wasn't negative or followed by trailing garbage.

runtime/mercury_stack_trace.[ch]:
	Add limit parameters to the stack trace functions, and obey them.

trace/mercury_trace_external.c:
	Pass the new parameters.

tests/debugger/queens.{inp,exp*}:
	Add tests of "stack N" to the supplied input, and update the expected
	outputs accordingly. Remove the .exp3 file, which cannot have been
	used recently (it still has raw event numbers, not the standardized
	ones the Mmakefile now calls for).

tests/debugger/nondet_stack.{inp,exp*}:
	Add tests of "nondet_stack N" to the supplied input, and update
	the expected outputs accordingly.
2003-04-16 12:37:39 +00:00
Zoltan Somogyi
ab5a7c7acf Fix two bugs in the printing of goals where the predicate concerned is an
Estimated hours taken: 6
Branches: main

Fix two bugs in the printing of goals where the predicate concerned is an
compiler-generated unify, compare or index predicate. Improve the mechanisms
for debugging bugs like this.

runtime/mercury_layout_util.[ch]:
	Fix bug one: do not return the arity of a type constructor as
	the arity of the unify, compare or index predicate of that
	type constructor; return the actual arity. When the falsely
	returned arity was greater than the actual arity, we could get
	core dumps; when it was smaller, the mdb command "print goal"
	printed wrong output.

	Provide a mechanism for fixing bug two: add a utility function
	for computing *correctly* a procedure's original arity and the number
	of type_info and/or typeclass_info arguments added by the compiler.
	(For convenience, it also returns a predicate/function indication.)

runtime/mercury_stack_layout.h:
	Rename the MR_comp_arity field of MR_Compiler_Proc_Id to
	MR_comp_type_arity, to make clear that it gives the arity of the type
	constructor, not the arity of the predicate, and thus avoid bugs such
	as those above.

runtime/mercury_stack_trace.c:
	Use the new name of the MR_comp_type_arity field.

trace/mercury_trace_declarative.c:
trace/mercury_trace_vars.c:
	Call the new, correct utility function in runtime/mercury_layout_util
	to compute how many typeinfo and/or typeclassinfo arguments are added
	by the compiler to a unify, compare, or index procedure's arguments,
	instead of the different, but logically equivalent and equally wrong
	pieces of code here.

trace/mercury_trace_external.c:
	Use the new name of the MR_comp_type_arity field. Leave an XXX, since
	I am not sure whether Morphine interprets the arity as the arity of the
	type constructor or as the arity of the predicate.

runtime/mercury_engine.[ch]:
runtime/mercury_layout_util.c:
	Make the printing of locations obtained from RTTI data structures
	switchable from mdb, to make problems like this easier to debug.

tests/debugger/uci.{m,inp,exp}:
	A new test case to test the proper handling of unify, compare and index
	predicates.

tests/debugger/Mercury.options:
tests/debugger/Mmakefile:
	Enable the new test case.
2003-04-02 23:01:45 +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
Ralph Becket
a8ffd3680c Change the compiler and tools so that .' and not :' is now used as the
Estimated hours taken: 14
Branches: main

Change the compiler and tools so that `.' and not `:' is now used as the
module separator in all output.

Infix `.' now has associativity yfx and priority 10.

NEWS:
	Report the change.

configure.in:
	Amend the test for an up-to-date Mercury compiler to check whether
	it recognises `.' as a module qualifier.

compiler/code_gen.m:
compiler/error_util.m:
compiler/hlds_out.m:
compiler/prog_out.m:
compiler/prog_util.m:
compiler/rl_exprn.m:
compiler/rl_gen.m:
compiler/source_file_map.m:
compiler/unused_args.m:
library/io.m:
library/rtti_implementation.m:
library/type_desc.m:
runtime/mercury_debug.c:
runtime/mercury_deconstruct.c:
runtime/mercury_stack_trace.c:
	Change `:' to `.' as module separator for output.

compiler/mercury_to_mercury.m:
compiler/prog_io_typeclass.m:
	As above.
	Fixed a bug where `.' was not being recognised as a module separator.

doc/reference_manual.texi:
	Report the change.

library/term_io.m:
	Ensure that infix `.' is written without surrounding spaces.

tests/hard_coded/dot_separator.m:
tests/hard_coded/dot_separator.exp:
tests/hard_coded/Mmakefile:
	Test case added.
2003-01-17 05:57:20 +00:00
Zoltan Somogyi
a2be486e6c Fix English in a comment.
Estimated hours taken: 0.1
Branches: main

runtime/mercury_stack_trace.c:
	Fix English in a comment.
2002-11-06 06:53:34 +00:00