mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-23 05:13:48 +00:00
083d376e6598628362ee91c2da170febd83590f4
5 Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
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.
|
||
|
|
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. |
||
|
|
ff4ece869e |
Updating wording of expected exception message.
Estimated hours taken: 0.1 Branches: main tests/tabling/tc_loop.exp: Updating wording of expected exception message. |
||
|
|
1eb831eb34 |
A major cleanup of the internals of tabling.
Estimated hours taken: 40
A major cleanup of the internals of tabling.
Tabling builds up two kinds of tables, both conceptually tries. For call
tables, there is one layer in the trie for each input argument; for answer
tables, there is one layer in the trie for each output argument. However,
the way each trie node is implemented depends on the type of the relevant
argument. In addition, what is stored at the tips of the call and answer tables
also depends on what kind of tabling (e.g. loopcheck, memo, minimal model)
is being performed on the current predicate, and (in some cases) on what
stage the execution of the current predicate has reached.
Previously, all trie nodes were declared with the C type Word **, and were
cast to their actual types at the point of use, with the casts mostly being
hidden inside macros. This arrangement lacked readability and was highly
error prone. I have replaced it with a system in which trie nodes are declared
with a C type which is a pointer to a union of all the possible actual types.
There are very few casts left in the internals of the tabling system; this
change replaces them with casts at the interface (in the predicates of
private_builtin.m) and the use of the various fields of the union.
library/private_builtin.m:
Changes to conform to the changed types in mercury_tabling.h.
In some cases, improve the debugging support.
Do not table the typeinfos of polymorphic types in the
table_lookup_insert_poly predicate; since those typeinfos
are also arguments, and since they appear before the polymorphic
arguments, they have already been tabled by the time
table_lookup_insert_poly is called.
library/private_builtin.m:
library/io.m:
Add an interface to a new function in the runtime to report
statistics about the operation of the tabling system.
runtime/mercury_tabling.h:
Define and document the new types.
Add macros for allocating memory for holding one or more structures.
Make the existing macros call the versions that check for malloc
returning NULL.
runtime/mercury_tabling_macros.h:
This new file contains macros that used to be part of the file
mercury_tabling.h. The macros call the functions defined in
mercury_tabling.c, but they also optionally print debugging messages.
runtime/Mmakefile:
Add mercury_tabling_macros.h to the list of header files.
runtime/mercury_tabling.c:
Conform to the new system of C types.
Recode the hash table routines to achieve code commonality, better
debugging and statistics gathering support, much greater readability,
and the following three performance benefits:
1. The old code used open addressing to resolve collisions. In many
uses of tabling, successive searches specify keys that have
neighboring hash values, which frequently leads to very long
searches (I have observed searches that searched more than half
the slots of the hash table.) The new code uses separate chaining
to resolve collisions.
2. The old code called GC_malloc whenever it inserted a new element
into the table. The new code amortizes this overhead over a
substantial (and configurable) number of insertions.
3. In order to check whether the hash table should be expanded, the
old code was executing a float multiplication and a float comparison
on every hash table access. The new code executes the float
multiplication only when the table size is changed; in the usual
case it only executes an integer comparison, which is much cheaper.
Recode the routines for tabling typeinfos for higher speed. Instead
of storing them in a binary search tree, which requires lots of
comparisons, store the address of the type_ctor_info in a hash table
and chain its argument typeinfos from that.
Add support for expandable tables, which are implemented as arrays
indexed by key - start. This is not used yet, but will be used for
I/O tabling soon.
runtime/mercury_stacks.c:
Conform to the new system of C types for tabling.
Improve the debugging support.
runtime/mercury_wrapper.c:
When debugging tabling, set stdout to be line buffered.
runtime/mercury_engine.h:
runtime/mercury_wrapper.c:
Add a new debugging flag, -dH, for debugging the operation of hash
tables.
In mercury_wrapper.c, sort the code fragments for for processing
the arguments of -d.
runtime/mercury_trace_base.c:
Disable the generation of nuisance debugging messages from Mercury
initialization code called before main, which may have been compiled
with MR_TABLE_DEBUG enabled.
runtime/mercury_conf_param.h:
Document MR_TABLE_STATISTICS as well as MR_TABLE_DEBUG.
trace/mercury_trace_internal.c:
Disable the generation of nuisance debugging messages from Mercury
code called by the debugger that may have been compiled with
MR_TABLE_DEBUG enabled, by turning off MR_tabledebug when MR_trace
is entered. We then turn MR_tabledebug back on (even if it wasn't
turned on in the first place) when executing debugger commands
that require it to be turned on in order to work.
tests/tabling/fib.m:
Improve the (commented out) debugging support. Start the search
for the right problem size closer to its probable end point.
tests/tabling/fib_{float,string,list}.{m,exp}:
New test cases to test the low-level routines for tabling floats,
strings, and user-defined types; they are all modified versions of fib.
tests/tabling/expand.{m,exp}:
tests/tabling/expand_float.{m,exp}:
tests/tabling/expand_poly.{m,exp}:
New test cases to test the code for resizing (i.e. expanding)
hash tables, and the code for handling polymorphic arguments.
tests/tabling/Mmakefile:
Enable the new test cases.
|
||
|
|
c0b36b2333 |
Add the new tabling directory to the list of directories.
Estimated hours taken: 1
tests/Mmakefile:
Add the new tabling directory to the list of directories.
tests/tabling/Mmakefile:
tests/tabling/runtests:
The intrastructure of the new tests directory.
tests/tabling/fib.{m,exp}:
A test of the memoing of a det procedure.
tests/tabling/tc_loop.{m,exp}:
A test of loop checking for a nondet procedure.
tests/tabling/tc_minimal.{m,exp}:
A test of minimal model tabling for a nondet procedure.
(Doesn't work yet).
tests/tabling/boyer.{m,exp}:
A benchmark program, translated to Mercury by Bart Demoen
from an original in Prolog.
(Doesn't work yet).
|