Files
mercury/tests/tabling/fib_string.exp
Zoltan Somogyi 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.
2000-01-03 08:53:15 +00:00

2 lines
14 B
Plaintext