mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-20 03:43:51 +00:00
083d376e6598628362ee91c2da170febd83590f4
98 Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
594b09c547 |
Handle argv[0] == NULL.
On some operating systems, e.g. Linux, it is possible to enter main()
with argv[0] == NULL if the parent process calls execve() with
argv[0] == NULL, or equivalently, passing NULL for the argv parameter.
runtime/mercury_wrapper.c:
runtime/mercury_wrapper.h:
Do not assume argc > 0 and argv[0] != NULL in MR_process_args.
If argv[0] is NULL then set MR_progname to the empty string
so users of MR_progname can assume it points to a valid string.
Add a new global variable MR_progname_is_known to indicate if
argv[0] was NULL or not.
library/io.m:
Make io.progname return the default program name if argv[0] was
NULL.
util/mkinit.c:
Set MR_progname to a valid string if argv[0] is NULL.
This is not actually necessary, since, in that case, the subsequent
call to parse_options() would immediately exit the program
as no file names will be found in argv.
|
||
|
|
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.
|
||
|
|
daae03f07f |
Delete unnecessary foreign_exported procedures.
library/io.m:
Delete unused foreign_exported procedures.
Add warning about using `ML_io_print_to_stream'.
runtime/mercury_init.h:
runtime/mercury_wrapper.c:
runtime/mercury_wrapper.h:
util/mkinit.c:
Delete unused function pointer `MR_io_print_to_cur_stream'.
|
||
|
|
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.
|
||
|
|
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. |
||
|
|
e473001caf |
Don't export MR_make_argv from the runtime.
runtime/mercury_wrapper.[ch]:
The function MR_make_argv was only exported from this module
for the use of the GCC backend; since that no longer exists,
we no longer need to export it.
|
||
|
|
cd72d000a8 |
Remove support for the MPS garbage collector.
As Tomas By's recent emails suggest, this support is doing more harm than good,
by falsely implying to people that MPS is a viable alternative to the Boehm
collector. The MPS collector was only ever experimental, and never performed
as well as Boehm. MPS isn't even in the git repository on git hub. It was
stored in a separate CVS repository on mundula, and (as far as I know)
wasn't carried over to github. The code of MPS was last touched a long time
ago; I would be surprised if it worked on today's systems without changes.
Mmake.common.in:
Mmake.workspace:
RESERVED_MACRO_NAMES:
boehm_gc/Mmakefile:
compiler/add_pragma.m:
compiler/compile_target_code.m:
compiler/globals.m:
compiler/handle_options.m:
compiler/mercury_compile_mlds_back_end.m:
compiler/mlds_to_c.m:
compiler/options.m:
compiler/peephole.m:
doc/user_guide.texi:
library/benchmarking.m:
runtime/Mmakefile.m:
runtime/mercury.h:
runtime/mercury_conf_param.h:
runtime/mercury_grade.h:
runtime/mercury_heap.h:
runtime/mercury_init.h:
runtime/mercury_memory.h:
runtime/mercury_wrapper.[ch]:
scripts/canonical_grade.sh-subr:
scripts/init_grade_options.sh-subr:
scripts/mgnuc.in:
scripts/ml.in:
scripts/parse_grade_options.sh-subr:
util/mkinit.c:
Remove all references to MPS.
|
||
|
|
29f2dcf213 |
Support dynamic creation of Mercury engines in low-level C parallel grades.
This change allows Mercury engines (each in a separate OS thread) to be
created and destroyed dynamically in low-level C grades.
We divide Mercury engines into two types:
"Shared" engines may execute code from any Mercury thread.
Shared engines may steal work from other shared engines, so are also
called work-stealing engines; we do not have shared engines that
refrain from work-stealing.
"Exclusive" engines execute code only for a single Mercury thread.
Only exclusive engines may be created and destroyed dynamically so far.
This assumption could be lifted when and if the need should arise.
Exclusive engines are a means for the user to map a Mercury thread directly
to an OS thread. Calls to blocking procedures on that thread will not block
progress in arbitrary other Mercury threads. Foreign code which depends on
the OS thread-local state is usable when called from that thread.
We do not yet allow shared engines to steal parallel work from exclusive
engines.
runtime/mercury_wrapper.c:
runtime/mercury_wrapper.h:
Rename MR_num_threads to MR_num_ws_engines. It counts only
work-stealing engines. Move comment to the header file.
Add MR_max_engines. The default value is arbitrary.
Add MERCURY_OPTIONS `--max-engines' option.
Define MR_num_ws_engines and MR_max_engines only with
MR_LL_PARALLEL_CONJ.
runtime/mercury_context.c:
runtime/mercury_context.h:
Rename MR_num_idle_engines to MR_num_idle_ws_engines.
It only counts idle work-stealing engines.
Extend MR_spark_deques to MR_max_engines length.
Extend engine_sleep_sync_data to MR_max_engines length.
Add function to index engine_sleep_sync_data with optional bounds
checking.
Replace instances of MR_num_threads by MR_num_ws_engines or
MR_max_engines as appropriate.
Add MR_ctxt_exclusive_engine field.
Rename existing MR_Context fields to remove the implication that the
engine "owns" the context. The new exclusive_engine field does
imply a kind of ownership, hence potential confusion.
Rename MR_SavedOwner, too.
Make MR_find_ready_context respect MR_ctxt_exclusive_engine.
Make MR_schedule_context respect MR_ctxt_exclusive_engine.
Rename MR_try_wake_an_engine to MR_try_wake_ws_engine
and restrict it to work-stealing engines.
Rename MR_shutdown_all_engines to MR_shutdown_ws_engines
and restrict it to work-stealing engines.
Make try_wake_engine and try_notify_engine decrement
MR_num_idle_ws_engines only for shared engines.
In MR_do_idle, make exclusive engines bypass work-stealing
and skip to the sleep state.
In MR_do_sleep, make exclusive engines ignore work-stealing advice
and abort the program if told to shut down.
Assert that a context with an exclusive_engine really is only loaded
by that engine.
In MR_fork_new_child, make exclusive engines not attempt to wake
work-stealing engines. Its sparks cannot be stolen anyway.
Make do_work_steal fail the attempt for exclusive engines.
There is one call where this might happen.
Add notes to MR_attempt_steal_spark. Its behaviour is unchanged.
Replace a call to MR_destroy_thread by MR_finalize_thread_engine.
Delete MR_num_exited_engines. It was unused.
runtime/mercury_thread.c:
runtime/mercury_thread.h:
Delete MR_next_engine_id and MR_next_engine_id_lock. We can no longer
allocate engine ids by incrementing a counter. Engine ids need to be
reused as they act as indices into fixed-sized arrays.
Extend MR_all_engine_bases to MR_max_engines entries.
Add MR_all_engine_bases_lock to protect MR_all_engine_bases.
Add MR_highest_engine_id.
Add MR_EngineType with the two options described.
Split the main part of MR_init_engine into a new function which
accepts an engine type. MR_init_engine is used by generated code so
maintain the interface.
Factor out setup/shutdown for thread support.
Make MR_finalize_thread_engine call the shutdown function.
Specialise MR_create_thread into MR_create_worksteal_thread.
The generic form was unused.
Move thread pinning into MR_create_worksteal_thread as other threads
do not require it.
Delete MR_destroy_thread. Its one caller can use
MR_finalize_thread_engine.
Delete declaration for non-existent variable
MR_init_engine_array_lock.
runtime/mercury_engine.c:
runtime/mercury_engine.h:
Add MR_eng_type field.
Make MR_eng_spark_deque a pointer to separately-allocated memory.
The reason is given in MR_attempt_steal_spark.
Add MR_ENGINE_ID_NONE, a dummy value for MR_ctxt_exclusive_engine.
Delete MR_eng_owner_thread which was obsoleted by engine ids
before.
Delete misplaced declaration of MR_all_engine_bases.
runtime/mercury_memory_zones.c:
Replace MR_num_threads by appropriate counters (I hope).
runtime/mercury_memory_handlers.c:
runtime/mercury_par_builtin.h:
Conform to changes.
runtime/mercury_threadscope.c:
Conform to renaming (but it might be wrong).
library/thread.m:
Add hidden predicate `spawn_native' for testing.
The interface is subject to change.
Share much of the code with the high-level C backend.
library/par_builtin.m:
Delete `num_os_threads' as it is unused.
doc/user_guide.texi:
Document MERCURY_OPTIONS `--max-engines' option.
|
||
|
|
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.
|
||
|
|
b023312f7a |
Various changes to make feedback analysis (for automatic parallelism) easier to
use.
These changes mean that a normal installation with a deep profiling and a
low-level C parallel grade can be used for automatic parallelism.
compiler/options.m:
Rename --profile-for-implicit-parallelism to --profile-for-feedback.
--profile-for-implicit-parallelism is now retained as a synonym.
Enable --coverage-profiling by default, it is only checked if
--deep-profiling is enabled.
Make corrections to the commented-out documentation for the developer-only
coverage profiling options.
compiler/handle_options.m:
Conform to changes in options.m
Remove the set of options implied by --coverage-profiling since they're
already set correctly in options.m.
doc/user_guide.texi:
Added extra concept index declarations to entries for automatic parallelism
and feedback analysis.
Conform to changes in options.m
library/Mmakefile:
Compile the standard library with --profile-optimized
runtime/mercury_deep_profiling.c:
Always write out the Procrep.data file when writing out the Deep.data file.
runtime/mercury_wrapper.[ch]:
Remove the --deep-procrep-file MERCURY_OPTIONS option, it is now always
enabled. (In the future the procrep data may be included inside the
Deep.data file).
tools/bootcheck:
Remove the --deep-procrep-file option from the bootcheck script.
|
||
|
|
58e305e4c0 |
Implement the source-to-source part of the loop control transformation. The
remaining part is the code generation for code that is to be spawned off. It
must be handled in the code generator since it uses the parent stack pointer in
many cases.
I'm committing this now so that Zoltan can begin to review it while I work on
the code generator component.
compiler/par_loop_control.m:
This new file contains the source-to-source part of the parallel loop
control transformation..
compiler/transform_hlds.m.
Include the par_loop_control module within the transform_hlds module.
compiler/mercury_compile_middle_passes.m:
Call the loop control transformation at stage 206 - after the dependant
parallel conjunction transformation.
Move the last call optimisation pass from stage 175 to 206 since it will
most-likely prevent loop control from working. Where both transformations
are applicable, the loop control transformation is preferred.
compiler/options.m:
Add new options for loop control.
compiler/handle_options.m:
Disable loop control if we're not in a grade that supports parallel
conjunctions.
Other tests that should have been testing for parallel conjunction support
but only tested parallel support have been fixed.
compiler/hlds_goal.m:
Add the feature_do_not_tailcall feature.
compiler/call_gen.m:
Mark LLCS call goals that may not have last call optimisation applied to
them if they have the feature_do_not_tailcall feature set in their HLDS
info.
compiler/goal_util.m:
Create a new predicate expand_plain_conj, this returns a list of the sub
goals of a plain conjunction, or returns the goal in a singleton list.
XXX: Could someone review the name of this predicate.
compiler/hlds_pred.m:
Add a symbol for the new transformation in the pred_transformation type.
Corrected a comment to match the arguments in the predicate it refers to.
compiler/prog_util.m:
Add support to make_pred_name for creating names for loop control
predicates.
compiler/dep_par_conj.m:
Fix grammer in a comment.
compiler/saved_vars.m:
Conform to the change in hlds_goal.m
compiler/layout_out.m:
Conform to the change in hlds_pred.m
runtime/mercury_par_builtin.[ch]:
Add support for lc_wait_free_slot/2, the blocking version of
lc_get_free_slot/2. This means that other loop control builtins have
changed, for instance, lc_join_and_terminate/2 must wake up a context
blocked in lc_wait_free_slot/2 after making the slot it was using free.
Use a spin lock in the loop control structure rather than a POSIX mutex.
runtime/mercury_wrapper.[ch]:
Add support for a runtime variable, the number of contexts per loop control.
This can be controlled with a MERCURY_OPTIONS option.
mdbcomp/program_representation.m:
Include lc_wait_free_slot/2 in the list of external predicates.
mdbcomp/mdbcomp.goal_path.m:
Add two new predicates goal_path_remove_first/3 and goal_path_get_first/2.
library/par_builtin.m:
Add new builtins to support the loop control transformation:
lc_wait_free_slot/2 will block the context until a new slot is
available.
lc_default_num_contexts/1 will return the number of contexts to use, by
default, for a loop-controlled loop.
Add myself as an author of this module.
doc/user_guide.texi:
Document the runtime --num-contexts-per-lc-per-thread option. It is
currently commented out since it is not intended for users, at least for
now.
Document the loop control options for the compiler.
---
The change below was written by Zoltan, I reviewed when I applied his diff to
my workspace.
Allow the compiler to mark calls in the LLDS as calls that cannot have last
call optimization applied to them. Paul will soon need this capability
in order to implement parallel conjunctions in which earlier conjuncts
are spawned off, and later conjuncts contain recursive calls, but the
earlier conjuncts need the stack frame.
compiler/llds.m:
Add a flag to det and semi calls. (Model_non calls have had a similar
flag for a long time, for a totally different reason.)
compiler/call_gen.m:
By default, say that det and semi calls may have LCO applied to them.
compiler/jumpopt.m:
Apply LCO to det and semi calls only if this flag allows it.
compiler/opt_debug.m:
Include the flag in debugging dumps.
|
||
|
|
f1779bd1e8 |
Improve work stealing. Spark deques have been associated with contexts so far.
This is a problem for the following reasons:
The work stealing code must take a lock to access the resizeable array of
work stealing dequeues. This adds global contention that can be avoided if
this array has a fixed size.
If a context is blocked on a future then that engine cannot execute the
sparks from that context, instead it tries to find global work, this is
more expensive than necessary.
If there are a few dozen contexts then there may be just as many work
stealing queues to take work from, the density of these queues will be
higher if they are fewer. Therefore work stealing will be more successful
on average.
This change associates spark deques with Mercury Engines rather than Contexts
to avoid these problems.
This has invalidated some invariants that allowed the runtime system to make
some worth-while optimisations. These optimisations have been maintained.
Mercury's idle loop has been reimplemented to allow for this. This
re-implementation has allowed for a number of other improvements:
Polling was used to check for new global sparks. This has been removed and
each engine now sleeps using it's own semaphore.
Checks for work can be done in different orders depending on how an engine
joins the idle loop.
When global work becomes available a particular engine can be woken up
rather than any arbitrary engine. We take advantage of this when making
contexts runnable, we try to schedule them on the engine that last executed
them.
When an engine is woken up it can be instructed with what it should do upon
waking up.
When a engine looks for a context to run, it will try to pick a context
that was last executed on it. This may avoid cache misses when the context
begins to run.
In the future we should consider:
Experiment with telling engines which context to run.
Improve the selection of which engine work should be scheduled on to be
hardware and memory-hierarchy aware.
Things that need doing next (probably next week):
./configure should check for POSIX semaphore support.
Profiling times have been broken by this change, they will need fixing.
The threadscope event long now breaks an invariants that the threadscope
graphical tool requires.
Semaphores are setup but never released, this is not a big problem but the
manual page says that some implementations may leak resources.
runtime/mercury_context.h:
runtime/mercury_context.c:
Remove the spark deque field from the MR_Context structure.
Export the new array of spark deques so that other modules may fill in
elements as engines are setup.
Modify the resume_owner_thread field of the MR_Context structure, this was
used to ensure that a context returning through C code would be resumed on
the engine with the correct C stack and depth. This field is now an engine
id and has been renamed to resume_owner_engine, it is advisory unless
resume_engine_required is also set. This way it is used to advise which
engine most recently executed this context and therefore may have a warm
cache.
Remove code that dynamically resized the array of spark deques. Including
the lock that protected against updating this array while it was being read
from other thread.
Introduce code that initialises the statically sized array of spark deques.
Reimplement the idle loop. This replaces MR_runnext and MR_do_runnext with
MR_idle and MR_do_idle respectively. There are also two new entry points
into the idle loop. Which one to use depends on the state of the engine.
Introduce new mechanisms for waking a particular engine. For example the
engine that last executed a context that is now runnable.
Change the algorithm for selecting which context to run, try to select
contexts that where last used on the current engine to avoid cache misses.
Use an engine's victim counter rather than a global victim counter when
trying to steal work.
Introduce some conditionally-compiled code that can be used to profile how
quickly new contexts can be created.
Rename MR_init_thread_stuff and MR_finalize_thread_stuff. The term thread
has been replaced with context since they're in mercury_context.c. This
allows the creation of a new function MR_init_thread_stuff() in
mercury_thread.c I also found the mismatch between the function names and
file name confusing. Move some of the code from MR_init_context_stuff to
the new MR_init_thread_stuff function where it belongs.
Refactor the thread pinning code so that even when thread pinning is
disabled it can be used to allocate each thread to a CPU but not actually
pin them.
Fix some whitespace errors.
runtime/mercury_thread.h:
runtime/mercury_thread.c:
In MR_init_engine():
Allocate an engine id for each engine.
A number of arrays had one slot per engine and where setup using a
lock. Now engine ids are used to index each array and setup is done
without a lock, each engine simply sets up its own slot.
Setup the new per-engine work stealing deques.
The MR_all_engine_bases array has been moved to this file.
Implement a new MR_init_thread_stuff function which initialises some global
variables and locks. Some of MR_init_thread_stuff has been moved from
mercury_context.c
Pin threads as part of MR_init_thread, excluding the primordial thread
which must be pinned before threadscope is initialised.
Add functions for debugging the use of semaphores.
Add corresponding macros that can be used to redirect semaphore calls to
debugging functions as above.
Improved thread debugging code, ensured that stderr is flushed after every
use, and that logging is done after calls return as well as before they're
called.
Conform to changes in mercury_context.h
runtime/mercury_engine.h:
runtime/mercury_engine.c:
Add spark deque and victim counter fields to the MercuryEngine structure.
Make the MR_eng_id field of the MercuryEngine structure available in all
thread safe grades, formerly it was used in only threadscope grades.
Move the MR_all_engine_bases variable to mercury_thread.[ch]
Put a reference to the engine's spark queue into the global array. This is
done here, so that it is after thread pinning because the original plan was
to have this array sorted by CPU rather then engine - we may yet do this in
the future.
Initialise an engine's spark deque when an engine is initialised.
Setup the engine specific threadscope data in mercury_thread.c
Conform to changes in mercury_context.h
runtime/mercury_wrapper.c:
The engine base array is no longer setup here, that code has been moved to
mercury_thread.c
Conform to changes in mercury_context.h and mercury_thread.h
runtime/mercury_wsdeque.h:
runtime/mercury_wsdeque.c:
The original implementation allocated an array for a spark queue only if
one wasn't already allocated, which could happen when a context was reused.
Now that spark queues are associated with engines arrays are always
allocated.
Replaced two macros with a single macro since there's no-longer a
distinction between global and local work queues, all work queues are
local.
runtime/mercury_wsdeque.c:
runtime/mercury_wsdeque.h:
Remove the --worksteal-max-attempts and --worksteal-sleep-msecs options as
they are no-longer used.
runtime/mercury_threadscope.h:
runtime/mercury_threadscope.c:
The MR_EngineId type has been moved to mercury_types.h
Engine IDs are no-longer allocated here, this is done in mercury_thread.c
The run spark and steal spark messages now write 0xFFFFFFFF for the context
id if there is no current context. Previously this would dereference a
null pointer.
runtime/mercury_memory_zones.c:
When checking for an existing memory zone check the free_zones_list
variable before taking a lock. This can prevent taking the lock in cases
where there are no free zones.
Introduce some conditionally-compiled code that can be used to profile how
quickly new contexts can be created.
runtime/mercury_bootstrap.h:
Remove macros that no-longer resolve to functions due to changes in the
runtime system.
runtime/mercury_types.h:
Move the MR_EngineId type from mercury_threadscope.h to mercury_types.h
runtime/mercury_grade.h:
Introduce a parallel grade version number, this change brakes binary
compatibility with existing parallel code.
runtime/mercury_backjump.c:
runtime/mercury_par_builtin.c:
runtime/mercury_mm_own_stacks.c:
library/stm_builtin.m:
library/thread.m:
library/thread.semaphore.m:
Conform to changes in mercury_context.h.
library/io.m:
Make this module compatible with MR_debug_threads.
doc/user_guide.texi
Remove the documentation for the --worksteal-max-attempts and
--worksteal-sleep-msecs options. The documentation was already commented
out.
|
||
|
|
ca7878f01a |
Make improvements to stack segments code.
The main benefits of these changes are:
Stack segments (and other memory zones) are cached when they are released
and can be re-used.
Some thread safety-fixes have been added.
All stack segments on all stacks are now the same size:
Small contexts (which had small stacks) aren't used with stack
segments.
The first segment on any stack is the same size as any other segment.
The first segment on any stack no-longer has a redzone.
Hard zones on all memory zones have been set to the minimum of one page
rather than one MR_unit which is usually two pages.
The caching of stack segments results in the following benchmark results. The
benefit is negligible under normal circumstances, but becomes important when
small segment sizes are used. Small segment sizes are common in
asm_fast.gc.par.stseg configurations as they reduce the memory required for
suspended contexts.
Non-segmented stack (32MB)
asm_fast.gc average of 5 with ignore=1 18.16 (1.00)
With 512KB (normal) segments:
asm_fast.gc.stseg and NO caching average of 5 with ignore=1 19.20 (1.06)
asm_fast.gc.stseg WITH caching average of 5 with ignore=1 19.16 (1.06)
With 4KB segments:
asm_fast.gc.stseg and NO caching average of 5 with ignore=1 20.66 (1.14)
asm_fast.gc.stseg WITH caching average of 5 with ignore=1 19.66 (1.08)
Other changes include corrections in code comments, clearer function names and
a documentation fix.
runtime/mercury_memory_zones.h:
runtime/mercury_memory_zones.c:
Re-write a lot of the code that managed the zone lists. The old code did
not re-use previously allocated but saved zones. The changes ensure that
MR_create_or_reuse_zone (formerly MR_create_zone) checks for a free zone
of at least the required size before allocating a new one. When zones are
released they are put on the free list.
As above MR_create_zone is now MR_create_or_reuse_zone,
MR_unget_zone is now MR_release_zone.
MR_construct_zone has been removed, it was only ever called by
MR_create_or_reuse_zone. MR_create_or_reuse_zone now contains the code for
MR_construct_zone.
To avoid an unnecessary sychronisation in parallel code some zones are not
added to the used list. The only zones put on the used list are those that
are useful to have on the used list because they have a non-default signal
handler or a redzone.
Updates to used_memory_zones now use a pthread mutex so that only one
thread may be updating the list at once. This lock is shared with the
free_memory_zones structure.
Updates to used_memory_zones now use memory barriers to guarantee that
concurrent reads always read a consistent, but possibly incomplete,
data-structure. This is necessary because it is read from a signal handler
which cannot call pthread_mutex().
Rename MR_get_used_memory_zones() to MR_get_used_memory_zones_readonly()
and document that the zone lists may be incomplete.
Make the MR_zone_next field of the MR_MemoryZone_Struct structure volatile.
Remove MAX_ZONES, it wasn't being used anywhere.
Insert some calls to MR_debug_log_message to help with debugging.
Use the correct printf integer length modifier for MR_Unsigned values.
Rename MR_context_id_counter to zone_id_counter, protect it with a lock in
HLC thread safe grades and use atomic operations in LLC thread-safe
grades..
The offset at which we start using a memory zone is allocated in sequence
from a table. This table was protected by Mercury's global lock, this is
now a CAS operation which prevents deadlocks when using trail segment,
parallel grades.
runtime/mercury_stacks.c:
Conform to changes in mercury_memory_zones.c.
Use MR_debug_log_message for printf-style debugging rather than printf.
runtime/mercury_wrapper.h:
runtime/mercury_wrapper.c:
Remove support for the smaller sized stacks in grades with stack segments.
Disable redzones when using stack segments. The MR_(non)detstack_zone_size
variables affect the first segment on every stack. Regardless of the type
of contaxt that owns that stack.
Conform to changes in runtime/mercury_memory_zones.h.
runtime/mercury_context.h:
runtime/mercury_context.c:
Removed an extra declaration for MR_init_context_maybe_generator
Small contexts are problematic since it's unclear to the programmer which
computations will be executed on smaller contexts and therefore whether
their stacks would overflow.
Conform to changes in runtime/mercury_memory_zones.h.
Conform to changes in runtime/mercury_wrapper.h.
runtime/mercury_memory.c:
Adjust the definition of MR_unit. It is now guaranteed to be a multiple of
the page size which is required by its use in mercury_memory_zones.c
Conform to changes in mercury_wrapper.h.
runtime/mercury_engine.c:
runtime/mercury_memory_handlers.c:
runtime/mercury_trail.c:
Conform to changes in runtime/mercury_memory_zones.h.
runtime/mercury_memory_handlers.c:
Use the correct printf integer length modifier for MR_Unsigned values.
runtime/mercury_misc.c:
Print out the meaning of errno if it is nonzero in MR_fatal_error.
Use the correct printf integer length modifier for MR_Unsigned values.
runtime/mercury_atomic_ops.h:
Define MR_THREADSAFE_VOLATILE to expand to volatile when MR_THREADSAFE is
defined. Otherwise it expands to nothing.
Make memory fences macros and atomic operations available in all thread safe
grades, not just low level C grades.
doc/user_guide.texi:
Corrected the default detstack size.
|
||
|
|
322feaf217 |
Add more threadscope instrumentation.
This change introduces instrumentation that tracks sparks as well as parallel
conjunctions and their conjuncts. This should hopefully give us more
information to diagnose runtime performance issues.
As of this date the ThreadScope program hasn't been updated to read or
understand these new events.
runtime/mercury_threadscope.[ch]:
Added a function and types to register all the threadscope strings from an
array.
Add functions to post the new events (see below).
runtime/mercury_threadscope.c:
Added support for 5 new threadscope events.
Registering a string so that other messages may refer to a constant
string.
Marking the beginning and ends of parallel conjunctions.
Creating a spark for a parallel conjunct.
Finishing a parallel conjunct.
Re-arranged event IDs, I've started allocating IDs from 38 onwards for
general purposes and 100 onwards for mercury specific events after talking
with Duncan Coutts.
Trimmed excess whitespace from the end of lines.
runtime/mercury_context.h:
Post a beginning parallel conjunction message when the sync term for the
parallel conjunction is initialized.
Post an event when creating a spark for a parallel conjunction.
Add a MR_spark_id field to the MR_Spark structure, these identify sparks to
threadscope.
runtime/mercury_context.c:
Post threadscope messages when a spark is about to be executed.
Post a threadscope event when a parallel conjunct is completed.
Add a missing memory barrier.
runtime/mercury_wrapper.[ch]:
Create a global function pointer for the code that registers strings in the
threadscope string table, this is filled in by mkinit.
Call this function pointer immediatly after setting up threadscope.
runtime/mercury_wsdeque.[ch]:
Modify MR_wsdeque_pop_bottom to return the spark pointer (which points onto
the queue) rather then returning a result through a pointer and bool if the
operation was successful. This pointer is safe to dereference until
MR_wsdeque_push_bottom is used.
runtime/mercury_wsdeque.c:
Corrected a code comment.
runtime/mercury_engine.h:
Documented some of the fields of the engine structure that hadn't been
documented.
Add a next spark ID field to the engine structure.
Change the type of the engine ID field to MR_uint_least16_t
compiler/llds.m:
Add a third field to the init_sync_term instruction that stores the index
into the threadscope string table of the static conjunction ID.
Add a field to the c_file structure containing the threadscope string
table.
compiler/layout.m:
Added a new layout array name for the threadscope string table.
compiler/layout_out.m:
Implement code to write out the threadscope string table.
compiler/llds_out_file.m:
Write out the threadscope string table when writing out the c_file.
compiler/par_conj_gen.m:
Create strings that statically identify parallel conjunctions for each
init_sync_term LLDS instruction. These strings are added to a table in the
!CodeInfo and the index of the string is added to the init_sync_term
instruction.
Add an extra instruction after a parallel conjunction to post the message
that the parallel conjunction has completed.
compiler/global_data.m:
Add fields to the global data structure to represent the threadscope string
table and its current size.
Add predicates to update and retrieve the table.
Handle merging of threadscope string tables in global data by allowing the
references to the strings to be remapped.
Refactored remapping code so that a caller such as proc_gen only needs to
call one remapping predicate after merging global data..
compiler/code_info.m:
Add a table of strings for use with threadscope to the code_info_persistent
type.
Modify the code_info_init to initialise the threadscope string table fields.
Add a predicate to get the string table and another to update it.
compiler/proc_gen.m:
Build the containing goal map before code generation for procedures with
parallel conjunctions in a parallel grade. par_conj_gen.m depends on this.
Conform to changes in code_info.m and global_data.m
compiler/llds_out_instr.m:
Write out the extra parameter in the init_sync_term instruction.
compiler/dupelim.m:
compiler/dupproc.m:
compiler/exprn_aux.m:
compiler/global_data.m:
compiler/jumpopt.m:
compiler/livemap.m:
compiler/llds_to_x86_64.m:
compiler/mercury_compile_llds_back_end.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 changes in llds.m
compiler/opt_debug.m:
Conform to changes in layout.m
compiler/mercury_compile_llds_back_end.m:
Fix some trailing whitespace.
util/mkinit.c:
Build an initialisation function that registers all the strings in
threadscope string tables.
Correct the layout of a comment.
|
||
|
|
b9c889f881 |
Update granularity control to ensure that it works with the current runtime system.
Granularity control now uses the length of a contexts run queue as the measure
of how busy the system is and whether it should fork off work. It is now
configured at runtime rather than compile time and therefore the
--parallelism-target option has been removed from the compiler.
Running some simple tests shows that granularity control has little effect on
most programs. The effect is probably negligible on programs that use few,
large grains of parallelism. On programs that represent pathological cases
such as parallel naive Fibonacci granularity control has a significant affect.
Parallel Fibonacci runs roughly four times faster than sequential Fibonacci
on an eight core machine. But ten times slower if granularity control is
disabled.
Granularity control slightly improves the performance of very-dependant and
parallelism. However the sequential versions of these programs are faster as
there is close to zero 'parallel overlap'.
These tests where informal, more formal testing is required, especially for
tuning.
compiler/granularity.m:
Updated granularity control to use a new macro in the runtime to test if a
new task should be spawned.
Use a runtime option to tune runtime granularity rather than a compile time
option.
Mark the runtime test as thread safe to avoid locking - which is
unnecessary.
compiler/options.m:
Removed --parallelism-target compilation option. Granularity control is
now configured at run-time.
runtime/mercury_wrapper.h:
Create a two new global variable MR_granularity_wsdeque_length and
MR_granularity_wsdeque_length_factor. MR_granularity_wsdeque_length is
MR_granularity_wsdeque_length_factor * MR_num_threads.
MR_granularity_wsdeque_length_factor and MR_engines are both configurable via
the MERCURY_OPTIONS environment.
This test calculates the length of the wsdeque each time. A comment is
provided to justify this design.
runtime/mercury_wrapper.c:
Initialise MR_granularity_wsdeque_length during startup of the runtime.
Parse the new runtime option --runtime-granularity-wsdeque-length-factor
The default value for this option is 8, this has been chosen somewhat
arbitrarily. IN the future we should test the affects of different values
of this option.
runtime/mercury_context.h:
Implement a new granularity control test that is linked to the length of a
local thread's run queue. The test compares the length of the queue to
MR_granularity_wsdeque_length.
runtime/mercury_context.c:
re-initialisation MR_granularity_wsdeque_length after auto-detection of the
MR_num_threads.
runtime/mercury_wsdeque.h:
Provide a new inline function to get the length of a wsdeque.
doc/user_guide.texi:
Updated documentation to reflect changes to compiler and runtime options.
The new runtime option's documentation is commented out, it is intended for
developers who understand it's operational semantics.
|
||
|
|
5cfd73644a |
Implement work stealing.
This patch is heavily based on earlier, uncommitted work by Peter Wang. It
has been updated so that it applies against the current version of the source.
A number of other changes have been made. Peter's original ChangeLog
follows:
Implement work stealing for parallel conjunctions. This builds on an
older patch which introduced work-stealing deques to the runtime but
didn't perform work stealing.
Previously when we came across a parallel conjunct, we would place a spark
into either the _global spark queue_ or the _local spark stack_ of the
Mercury context. A spark on the global spark queue may be picked up for
parallel execution by an idle Mercury engine, whereas a spark on a local
spark stack is confined to execution in the context that originated it.
The problem is that we have to decide, ahead of time, where to put a
spark. Ideally, we should have just enough sparks in the global queue to
keep the available Mercury engines busy, and leave the rest of the sparks
to execute in their original contexts since that is more efficient. But
we can't predict the future so have to make do with guesses using simple
heuristics. A bad decision, once made, cannot be reversed. An engine may
sit idle due to an empty global spark queue, even while there are sparks
available in some local spark stacks.
In the work stealing scheme, sparks are always placed into each context's
_local spark deque_. Idle engines actively try to steal sparks from
random spark deques. We don't need to make irreversible and potentially
suboptimal decisions about where to put sparks. Making a spark available
for parallel execution is cheap and happens by default because of the
work-stealing deques; putting a spark on a global queue implies
synchronisation with other threads. The downside is that idle engines
need to expend more time and effort to find the work from multiple places
instead of just one place.
Practically, the new scheme seems to work as well as the old scheme and
vice versa, except that the old scheme often required
`--max-context-per-threads' to be set "correctly" to get good results.
Only tested on x86-64, which has a relatively constrained memory model.
My modifications include:
The difference between 'shared' and 'private' synchronisation terms has
been removed. All sync terms are assumed to be shared and thread-safe
operations are used everywhere. This allows us to remove complicated code
used when a private synchronisation term became shared. This may change
the performance of thread stealing, in particular it may become slower due
to the assumption that all sync terms are shared and therefore atomic
operations must always be used when decrementing their count field.
I've re-factored MR_do_join_and_continue, It is now much simpler as the
conditional code in it enumerates the possible cases clearly.
This change bootchecks and successfully runs the test suite in asm_fast.gc
asm_fast.gc.par hlc.gc and hlc.par, no other grades where tested. I have not
yet tested performance.
runtime/mercury_context.c:
runtime/mercury_context.h:
Keep pointers to all spark deques in a flat array, so we have access
to them for stealing.
Added functions to manage the global array of spark deques.
Modify MR_do_run_next, it now attempts to steal work from other context's
spark queues. Threads sleeping on the condition variable in
MR_do_run_next now use a timed wait so they can wakeup and try to steal
sparks.
Re-factored MR_do_join_and_continue.
MR_num_idle_engines is used by atomic operations, it has been made an
MR_Integer so that it's size matches the expectations of the atomic
operations we have defined.
Modified the MR_SyncTerm and MR_Spark structures. Sparks now point to
their sync terms. The perant stack pointer has been moved into the
SyncTerm structure. The MR_st_is_shared field in the MR_SyncTerm
structure has been removed.
runtime/mercury_atomic_ops.c:
runtime/mercury_atomic_ops.h:
Implement a new atomic operation: decrement integer and is zero. On the
x86/x86_64 one can't atomically decrement an integer and fetch the result
in a single instruction, a loop with a 'compare and exchange' instruction
is necessary. However since we only want to test if the value has become
zero after the decrement we can use the processor's flags. This can be
done in two instructions, but more importantly a loop is not required and
only one instruction is atomic.
runtime/mercury_wrapper.c:
runtime/mercury_wrapper.h:
Added runtime tunable options for work stealing. These control the number
of attempts an idle engine will make when looking for work, and the
duration to sleep after failing to find any work.
runtime/mercury_thread.c:
runtime/mercury_thread.h:
Added MR_COND_TIMED_WAIT, which waits on condition variables like
MR_COND_WAIT except that it may time out.
runtime/mercury_wsdeque.h:
runtime/mercury_wsdeque.c:
MR_wsdeque_pop_bottom now uses it's second argument to return the code
address to jump to rather the whole spark.
runtime/mercury_conf.h.in:
configure.in:
Test for sched_yield()
Change the synchronisation term structure.
doc/user_guide.texi:
Add commented out documentation for two new tunable parameters,
`--worksteal-max-attempts' and `--worksteal-sleep-msecs'.
Implementors may want to experiment with different values but end
users shouldn't need to know about them.
|
||
|
|
4d41cf6c23 |
Rename the runtime granularity control macros, variables and predicates.
Estimated hours taken: 3 Branches: main Rename the runtime granularity control macros, variables and predicates. Names of the runtime granularity control macros, variables and predicates are now more descriptive and more consistent. An alternative runtime granularity control predicate and macro is now available, it considers the number of contexts and all sparks whereas the original predicate and macro considers only the number of contexts and sparks on the global queue. A new predicate has been added to determine the number of worker threads that the mercury runtime is configured to use. library/par_builtin.m: Renamed predicates. Conform to changes in runtime/mercury_thread.h Added the new predicates. Removed some old foreign procedure attributes. Addressed an XXX comment left by Zoltan. runtime/mercury_context.c: runtime/mercury_context.h: Rename existing runtime granularity control variables and macros. Add new runtime granularity control variable and macro. runtime/mercury_wrapper.c: runtime/mercury_wrapper.h: Export MR_num_threads variable. Make this variable an MR_Unsigned. runtime/mercury_atomic_ops.c: runtime/mercury_atomic_ops.h: Introduce new atomic increment and decrement instructions. These are used to count the number of local sparks created which is done outside of a critical section. library/Mmakefile: Rebuild the par_builtin module when either runtime/mercury_context.h or runtime/mercury_thread.h change. compiler/granularity.m: Conform to changes in runtime/mercury_context.h |
||
|
|
4083906e33 |
MERCURY_OPTIONS is a crude way to give options to Mercury programs, since it
Estimated hours taken: 1 Branches: main MERCURY_OPTIONS is a crude way to give options to Mercury programs, since it applies to all Mercury programs, even though we often want to give options to only one specific Mercury program. (For example, we may want to give it only to a test program's executable, and not to the invocation of the compiler that generates it.) This diff makes the runtime system, when executing a program named "progname", look for and process the environment variable whose name is "MERCURY_OPTIONS-progname". This allows options to be given at runtime to only one specific program. runtime/mercury_wrapper.c: Make the change described above. runtime/mercury_wrapper.h: Fix some obsolete documentation, and add some up-to-date documentation. doc/user_guide.texi: Document the change. util/mkinit.c: Fix indentation. |
||
|
|
2dc982cfe4 |
Make a representation of the program available to the deep profiler.
Estimated hours taken: 50 Branches: main Make a representation of the program available to the deep profiler. We do this by letting the user request, via the option "--deep-procrep-file" in MERCURY_OPTIONS, that when the Deep.data file is written, a Deep.procrep file should be written alongside it. The intended use of this information is the discovery of profitable parallelism. When a conjunction contains two expensive calls, e.g. p(...) and q(...) connected by some shared variables, the potential gain from executing them in parallel is limited by how early p produces those variables and how late q consumes them, and knowing this requires access to the code of p and q. Since the debugger and the deep profiler both need access to program representations, put the relevant data structures and the operations on them in mdbcomp. The data structures are significantly expanded, since the deep profiler deals with the whole program, while the debugger was interested only in one procedure at a time. The layout structures have to change as well. In a previous change, I changed proc layout structures to make room for the procedure representation even in non-debugging grades, but this isn't enough, since the procedure representation refers to the module's string table. This diff therefore makes some parts of the module layout structure, including of course the string table, also available in non-debugging grades. configure.in: Check whether the installed compiler can process switches on foreign enums correctly, since this diff depends on that. runtime/mercury_stack_layout.[ch]: runtime/mercury_types.h: Add a new structure, MR_ModuleCommonLayout, that holds the part of the module layout that is common to deep profiling and debugging. runtime/mercury_deep_profiling.[ch]: The old "deep profiling token" enum type was error prone, since at each point in the data file, only a subset was applicable. This diff breaks up the this enum into several enums, each consisting of the choice applicable at a given point. This also allows some of the resulting enums to be used in procrep files. Rename some enums and functions to avoid ambiguities, and in one case to conform to our naming scheme. Make write_out_proc_statics take a second argument. This is a FILE * that (if not NULL) asks write_out_proc_statics to write the representation of the current module to specified stream. These module representations go into the middle part of the program representation file. Add functions to write out the prologue and epilogue of this file. Write out procedure representations if this is requested. Factor out some code that is now used in more than one place. runtime/mercury_deep_profiling_hand.h: Conform to the changes to mercury_deep_profiling.h. runtime/mercury_builtin_types.c: Pass the extra argument in the argument lists of invocations of write_out_proc_statics. runtime/mercury_trace_base.[ch]: Conform to the name change from proc_rep to proc_defn_rep in mdbcomp. runtime/mercury_grade.h: Due to the change to layout structures, increment the binary compatibility version numbers for both debug and deep profiling grades. runtime/mercury_wrapper.[ch]: Provide two new MERCURY_OPTION options. The first --deep-procrep-file, allows the user to ask for the program representation to be generated. The second, --deep-random-write, allows tools/bootcheck to request that only a fraction of all program invocations should generate any deep profiling output. The first option will be documented once it is tested much more fully. The second option is deliberately not documented. Update the type of the variable that holds the address of the (mkinit-generated) write_out_proc_statics function to accept the second argument. util/mkinit.c: Pass the extra argument in the argument list of write_out_proc_statics. mdbcomp/program_representation.m: Extend the existing data structures for representing a procedure body to represent a procedure (complete with name), a module and a program. The name is implemented as string_proc_label, a form of proc_label that can be written out to files. This replaces the old proc_id type the deep profiler. Extend the representation of switches to record the identity of the variable being switched on, and the cons_ids of the arms. Without the former, we cannot be sure when a variable is first used, and the latter is needed for meaningful prettyprinting of procedure bodies. Add code for reading in files of bytecodes, and for making sense of the bytecodes themselves. (It is this code that uses foreign enums.) mdbcomp/prim_data.m: Note the relationship of proc_label with string_proc_label. mdbcomp/rtti_access.m: Add the access operations needed to find module string tables with the new organization of layout structures. Provide operations on bytecodes and string tables generally. trace/mercury_trace_cmd_browsing.c: Conform to the change to mdbcomp/program_representation.m. compiler/layout.m: Add support for a MR_ModuleCommonLayout. Rename some function symbols to avoid ambiguities. compiler/layout_out.m: Handle the new structure. compiler/stack_layout.m: Generate the new structure and the procedure representation bytecode in deep profiling grades. compiler/llds_out.m: Generate the code required to write out the prologue and epilogue of program representation files. Pass the extra argument in the argument lists of invocations of write_out_proc_statics that tells those invocations to write out the module representations between the prologue and the epilogue. compiler/prog_rep.m: When generating bytecodes, include the new information for switches. compiler/continuation_info.m: Replace a bool with a more expressive type. compiler/proc_rep.m: Conform to the change to continuation_info.m. compiler/opt_debug.m: Conform to the change to layout.m. deep_profiler/mdprof_procrep.m: A new test program to test the reading of program representations. deep_profiler/DEEP_FLAGS.in: deep_profiler/Mmakefile: Copy the contents of the mdbcomp module to this directory on demand, instead of linking to it. This is necessary now that the deep profiler depends directly on mdbcomp even if it is compiled in a non-debugging grade. The arrangements for doing this were copied from the slice directory, which has long done the same. Avoid a duplicate include of Mmake.deep.params. Add the new test program to the list of programs in this directory. Mmakefile: Go through deep_profiler/Mmakefile when deciding whether to do "mmake depend" in the deep_profiler directory. The old actions won't work correctly now that we need to copy some files from mdbcomp before we can run "mmake depend". deep_profiler/profile.m: Remove the code that was moved (in cleaned-up form) to mdbcomp. deep_profiler/dump.m: deep_profiler/profile.m: Conform to the changes above. browser/declarative_execution.m: browser/declarative_tree.m: Conform to the changes in mdbcomp. doc/user_guide.texi: Add commented out documentation of the two new options. slice/Mmakefile: Fix formatting, and a bug. library/exception.m: library/par_builtin.m: library/thread.m: library/thread.semaphore.m: Update all the handwritten modules to pass the extra argument now required by write_out_proc_statics. tests/debugger/declarative/dependency.exp: Conform to the change from proc_rep to proc_defn_rep. tools/bootcheck: Write out deep profiling data only from every 25th invocation, since otherwise the time for a bootcheck takes six times as long in deep profiling grades than in asm_fast.gc. However, do test the ability to write out program representations. Use the mkinit from the workspace, not the installed one. Don't disable line wrapping. |
||
|
|
94b0a40b2c |
Improve support for calling procedures in Mercury libraries from
Estimated hours taken: 20
Branches: main
Improve support for calling procedures in Mercury libraries from
applications written in foreign languages, i.e where the program entry point
is not the Mercury predicate main/2. The main trick is to ensure that the
necessary runtime initialisation is done before any Mercury procedures are
called (or at least to provide the mechanism to do such initialisation,
ensuring that it is done is the programmer's responsibility.)
We currently support this sort of thing via the compiler's `--no-main'
option. This diff adds a more user friendly mechanism (at least on the
Mercury side.) In particular, we no longer require that one of the Mercury
libraries define a main/2 predicate. (Note: the existing behaviour of
--no-main is unchanged.)
For the set of Mercury libraries that we wish to use from a foreign
application we create a standalone interface. A standalone interface is a
cut-down version of the _init.c file that would be created for a Mercury
executable that uses the same set of libraries. (Which libraries to include
in the interface can be specified via the usual mechanisms, e.g. the --ml
option.)
The standalone interface has two parts: an object file that contains the
cut-down version of the _init.c file, and a header file that contains the
declarations for the functions that initialise and shut down the Mercury
runtime. This header file is compatible with both C and C++.
compiler/options.m:
Add a new option `--generate-standalone-interface' that causes the
compiler to generate a header/object pair that can be used to
intialise/shut down the Mercury runtime from a foreign application.
The basename of the header/object pair is given as an argument to this
option.
compiler/mercury_compile.m:
Create the standalone interface if invoked with
`--generate-standalone-interface'.
Emit an error message if `--generate-standalone-interface' is
specified with `--target java' or `--target il'. We don't
currently support that.
compiler/compile_target_code.m:
Add code to implement the `--generate-standalone-interface' option.
Fix a typo: s/Serarator/Separator/.
Fix an overlong line.
compiler/handle_options.m:
Emit an error message if `--generate-standalone-interface' and
`--extra-inits' are specified together.
compiler/passes_aux.m:
Fix some broken indentation.
util/mkinit.c:
Add a new mode of operation that generates standalone interfaces.
The principle differences between a standalone interface and a
_init.c file are that the former sets the program entry point to
MR_dummy_main and does not create a main function.
The new `-s' option tells mkinit to create a standalone interface.
(Note that `-s' implies `-l'.)
Add a comment pointing to various places that may need to updated if
mkinit.c is changed.
runtime/mercury_wrapper.{h,c}:
Add a new procedure MR_dummy_main for use with standalone
interfaces. Any attempt to call main/2 through the usual entry
point when operating in standalone mode will cause a runtime abort.
|
||
|
|
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). |
||
|
|
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.) |
||
|
|
70a83b2632 |
A common way to use parallel conjunction can cause a lot of Mercury contexts
Estimated hours taken: 7
Branches: main
A common way to use parallel conjunction can cause a lot of Mercury contexts
to be allocated, e.g.
map([], []).
map([H0|T0], [H|T]) :-
( p(H0, H) % contains no parallel conjunctions
& map(T0, T)
).
When the left parallel conjunct completes, the engine that was executing it
must suspend the context in which it was run, waiting for the right conjunct
to finish. The engine is then idle and will attempt to find further work to
execute in a _new_ context. To avoid excessive memory consumption due to
contexts we currently limit the number of contexts we allocate. However,
that severely limits the parallelism we can exploit in this example (and
similar patterns of work distribution). There are a lot of contexts
allocated but most of them are simply suspended.
Assuming that most parallel conjuncts contain small sub-computations, we can
allow many contexts to be allocated without excessive memory consumption by
just giving them smaller stacks. This patch creates a simple variant of a
MR_Context structure which has smaller stacks than the initial MR_Context
structure and executes parallel conjuncts in the smaller contexts if
larger contexts are unavailable.
runtime/mercury_memory.c:
runtime/mercury_wrapper.c:
runtime/mercury_wrapper.h:
doc/user_guide.texi:
Add globals to hold the desired sizes of small det and nondet stacks.
Add `--small-detstack-size' and `--small-nondetstack-size'
options for the MERCURY_OPTIONS environment variable to set the
desired sizes.
runtime/mercury_context.h:
Add a MR_ctxt_size field to MR_Context to indicate whether it has
regular or small sized stacks.
runtime/mercury_context.c:
Add an argument to MR_create_context() specifying whether we want a
regular or small context.
Ask for small stacks when creating new contexts to begin execution
from a spark (i.e. parallel conjuncts).
Create a new free-list to hold unused small contexts.
extras/concurrency/spawn.m:
runtime/mercury_mm_own_stacks.c:
runtime/mercury_thread.c:
Match the interface change to MR_create_context(). We give the
initial context and contexts created due for explicit Mercury threads
regular-sized stacks.
|
||
|
|
712027f307 |
This patch changes the parallel execution mechanism in the low level backend.
Estimated hours taken: 100 Branches: main This patch changes the parallel execution mechanism in the low level backend. The main idea is that, even in programs with only moderate parallelism, we won't have enough processors to exploit it all. We should try to reduce the cost in the common case, i.e. when a parallel conjunction gets executed sequentially. This patch does two things along those lines: (1) Instead of unconditionally executing all parallel conjuncts (but the last) in separate Mercury contexts, we allow a context to continue execution of the next conjunct of a parallel conjunction if it has just finished executing the previous conjunct. This saves on allocating unnecessary contexts, which can be a big reduction in memory usage. We also try to execute conjuncts left-to-right so as to minimise the need to suspend contexts when there are dependencies between conjuncts. (2) Conjuncts that *are* executed in parallel still need separate contexts. We used to pass variable bindings to those conjuncts by flushing input variable values to stack slots and copying the procedure's stack frame to the new context. When the conjunct finished, we would copy new variable bindings back to stack slots in the original context. What happens now is that we don't do any copying back and forth. We introduce a new abstract machine register `parent_sp' which points to the location of the stack pointer at the time that a parallel conjunction began. In parallel conjuncts we refer to all stack slots via the `parent_sp' pointer, since we could be running on a different context altogether and `sp' would be pointing into a new detstack. Since parallel conjuncts now share the procedure's stack frame, we have to allocate stack slots such that all parallel conjuncts in a procedure that could be executing simultaneously have distinct sets of stack slots. We currently use the simplest possible strategy, i.e. don't allow variables in parallel conjuncts to reuse stack slots. Note: in effect parent_sp is a frame pointer which is only set for and used by the code of parallel conjuncts. We don't call it a frame pointer as it can be confused with "frame variables" which have to do with the nondet stack. compiler/code_info.m: Add functionality to keep track of how deep inside of nested parallel conjunctions the code generator is. Add functionality to acquire and release "persistent" temporary stack slots. Unlike normal temporary stack slots, these don't get implicitly released when the code generator's location-dependent state is reset. Conform to additions of `parent_sp' and parent stack variables. compiler/exprn_aux.m: Generalise the `substitute_lval_in_*' predicates by `transform_lval_in_*' predicates. Instead of performing a fixed substitution, these take a higher order predicate which performs some operation on each lval. Redefine the substitution predicates in terms of the transformation predicates. Conform to changes in `fork', `join_and_terminate' and `join_and_continue' instructions. Conform to additions of `parent_sp' and parent stack variables. Remove `substitute_rval_in_args' and `substitute_rval_in_arg' which were unused. compiler/live_vars.m: Introduce a new type `parallel_stackvars' which is threaded through `build_live_sets_in_goal'. We accumulate the sets of variables which are assigned stack slots in each parallel conjunct. At the end of processing a parallel conjunction, use this information to force variables which are assigned stack slots to have distinct slots. compiler/llds.m: Change the semantics of the `fork' instruction. It now takes a single argument: the label of the next conjunct after the current one. The instruction now "sparks" the next conjunct to be run, either in a different context (possibly in parallel, on another Mercury engine) or is queued to be executed in the current context after the current conjunct is finished. Change the semantics of the `join_and_continue' instruction. This instruction now serves to end all parallel conjuncts, not just the last one in a parallel conjunction. Remove the `join_and_terminate' instruction (no longer used). Add the new abstract machine register `parent_sp'. Introduce "parent stack slots", which are similar to normal stack slots but relative to the `parent_sp' register. compiler/par_conj_gen.m: Change the code generated for parallel conjunctions. That is: - use the new `fork' instruction at the beginning of a parallel conjunct; - use the `join_and_continue' instruction at the end of all parallel conjuncts; - keep track of how deep the code generator currently is in parallel conjunctions; - set and restore the `parent_sp' register when entering a non-nested parallel conjunction; - after generating the code of a parallel conjunct, replace all references to stack slots by parent stack slots; - remove code to copy back output variables when a parallel conjunct finishes. Update some comments. runtime/mercury_context.c: runtime/mercury_context.h: Add the type `MR_Spark'. Sparks are allocated on the heap and contain enough information to begin execution of a single parallel conjunct. Add globals `MR_spark_queue_head' and `MR_spark_queue_tail'. These are pointers to the start and end of a global queue of sparks. Idle engines can pick up work from this queue in the same way that they can pick up work from the global context queue (the "run queue"). Add new fields to the MR_Context structure. `MR_ctxt_parent_sp' is a saved copy of the `parent_sp' register for when the context is suspended. `MR_ctxt_spark_stack' is a stack of sparks that we decided not to put on the global spark queue. Update `MR_load_context' and `MR_save_context' to save and restore `MR_ctxt_parent_sp'. Add the counters `MR_num_idle_engines' and `MR_num_outstanding_contexts_and_sparks'. These are used to decide, when a `fork' instruction is reached, whether a spark should be put on the global spark queue (with potential for parallelism but also more overhead) or on the calling context's spark stack (no parallelism and less overhead). Rename `MR_init_context' to `MR_init_context_maybe_generator'. When initialising contexts, don't reset redzones of already allocated stacks. It seems to be unnecessary (and the reset implementation is buggy anyway, though it's fine on Linux). Rename `MR_schedule' to `MR_schedule_context'. Add new functions `MR_schedule_spark_globally' and `MR_schedule_spark_locally'. In `MR_do_runnext', add code for idle engines to get work from the global spark queue. Resuming contexts are prioritised over sparks. Rename `MR_fork_new_context' to `MR_fork_new_child'. Change the definitions of `MR_fork_new_child' and `MR_join_and_continue' as per the new behaviour of the `fork' and `join_and_continue' instructions. Delete `MR_join_and_terminate'. Add a new field `MR_st_orig_context' to the MR_SyncTerm structure to record which context originated the parallel conjunction instance represented by a MR_SyncTerm instance, and update `MR_init_sync_term'. This is needed by the new behaviour of `MR_join_and_continue'. Update some comments. runtime/mercury_engine.h: runtime/mercury_regs.c: runtime/mercury_regs.h: runtime/mercury_stacks.h: Add the abstract machine register `parent_sp' and code to copy it to and from the fake_reg array. Add a macro `MR_parent_sv' to access stack slots via `parent_sp'. Add `MR_eng_parent_sp' to the MercuryEngine structure. runtime/mercury_wrapper.c: runtime/mercury_wrapper.h: Add Mercury runtime option `--max-contexts-per-thread' which is saved in the global variable `MR_max_contexts_per_thread'. The number `MR_max_outstanding_contexts' is derived from this. It sets a soft limit on the number of sparks we put in the global spark queue, relative to the number of threads we are running. We don't want to put too many sparks on the global queue if there are plenty of ready contexts or sparks already on the global queues, as they are likely to result in new contexts being allocated. When initially creating worker engines, wait until all the worker engines have acknowledged that they are idle before continuing. This is mainly so programs (especially benchmarks and test cases) with only a few fork instructions near the beginning of the program don't execute the forks before any worker engines are ready, resulting in no parallelism. runtime/mercury_engine.c: runtime/mercury_thread.c: Don't allocate a context at the time a Mercury engine is created. An engine only needs a new context when it is about to pick up a spark. configure.in: compiler/options.m: scripts/Mercury.config.in: Update to reflect the extra field in MR_SyncTerm. Add the option `--sync-term-size' and actually make use the result of the sync term size calculated during configuration. compiler/code_util.m: compiler/continuation_info.m: compiler/dupelim.m: compiler/dupproc.m: compiler/global_data.m: compiler/hlds_llds.m: compiler/jumpopt.m: compiler/livemap.m: compiler/llds_out.m: compiler/middle_rec.m: compiler/opt_debug.m: compiler/opt_util.m: compiler/reassign.m: compiler/stack_layout.m: compiler/use_local_vars.m: compiler/var_locn.m: Conform to changes in `fork', `join_and_terminate' and `join_and_continue' instructions. Conform to additions of `parent_sp' and parent stack variables. XXX not sure about the changes in stack_layout.m library/par_builtin.m: Conform to changes in the runtime system. |
||
|
|
8396edc4b2 |
Let benchmark.report_stats/0 report real times on POSIX platforms.
Estimated hours taken: 1 Branches: main Let benchmark.report_stats/0 report real times on POSIX platforms. configure.in: Check for time.h and gettimeofday(). runtime/mercury_conf.h.in: Add MR_HAVE_TIME_H, MR_HAVE_GETTIMEOFDAY. Unrelated change: add MR_HAVE_PTHREAD_H. runtime/mercury_timing.c: runtime/mercury_timing.h: Add `MR_get_real_milliseconds'. runtime/mercury_wrapper.c: runtime/mercury_wrapper.h: Rename MR_time_* globals to MR_user_time_*. Add and initialise MR_real_time_* globals. library/benchmarking.m: Output real times in ML_report_stats(). Correct spelling of milliseconds. java/runtime/Native.c: java/runtime/Native.java.in: trace/mercury_trace_declarative.c: Correct spelling of milliseconds. |
||
|
|
9d8ca0ad37 |
Remove residual parts of the Aditi backend that weren't deleted the other day.
Estimated hours taken: 1.5 Branches: main Remove residual parts of the Aditi backend that weren't deleted the other day. configure.in: Mmake.common.in: Remove support for enabling the Aditi backend. runtime/mercury_aditi.h: Remove this file. runtime/Mmakefile: runtime/mercury.h: runtime/mercury_imp.h: runtime/mercury_ho_call.[ch]: runtime/mercury_wrapper.[ch]: Delete support for Aditi in the runtime. scripts/Mmake.rules: scripts/Mmake.vars.in: scripts/c2init.in: scripts/parse_ml_options.sh-subr.in: Remove mmake support for building .rlo files, etc. util/mkinit.c: Remove Aditi specific code. compiler/bytecode_data.m: compiler/closure_analysis.m: compiler/code_model.m: compiler/compile_target_code.m: compiler/det_analysis.m: compiler/handle_options.m: compiler/hlds_goal.m: compiler/hlds_module.m: compiler/make.dependencies.m: compiler/make.m: compiler/make.module_target.m: compiler/make.program_target.m: compiler/make.util.m: compiler/make_hlds_error.m: compiler/make_hlds_passes.m: compiler/mercury_to_mercury.m: compiler/mlds_to_gcc.m: compiler/modecheck_call.m: compiler/modules.m: compiler/opt_debug.m: compiler/options.m: compiler/prog_data.m: compiler/prog_foreign.m: compiler/prog_mode.m: compiler/prog_type.m: compiler/rtti.m: compiler/rtti_out.m: compiler/rtti_to_mlds.m: compiler/term_errors.m: compiler/unify_proc.m: mdbcomp/prim_data.m: Remove residual support for Aditi. library/ops.m: Remove the 'aditi_bottom_up' and 'aditi_top_down' operators from the ops table. doc/reference_manual.texi: doc/user_guide.texi: Delete the sections on the Aditi interface. extras/aditi/*: Delete this. |
||
|
|
29c44a3e93 |
Add the initial stage of finalise declarations.
Estimated hours taken: 2 Branches: main Add the initial stage of finalise declarations. These are a counterpart to the recently added intialise declarations; they allow the user to specify predicates that are to be run after main/2 exits. util/mkinit.c: Add support for `REQUIRED_FINAL' directives. These are similar to `REQUIRED_INIT' directives except that the specified functions are run after main/2. Any functions specified using this directive are gathered into bunches and called from the final_module_required function. runtime/mercury_wrapper.h: runtime/mercury_wrapper.c: Export a new global that points to the final_module_required function for the program. |
||
|
|
99293279e6 |
This is step 1 of eliminating the arguments of the type_ctor_info, type_info,
Estimated hours taken: 8 Branches: main This is step 1 of eliminating the arguments of the type_ctor_info, type_info, base_typeclass_info and typeclass_info type constructors. This step doesn't delete those arity-1 type constructors yet; that will be done in step 2. This delay due to bootstrapping issues: installed compilers still generate references to those type constructors. However, after this change, compilers will instead generate references to arity-0 versions of those types named zero_type_ctor_info, zero_type_info, zero_base_typeclass_info and zero_typeclass_info. library/private_builtin.m: Add the new type constructors. For each predicate that operates on the old arity-1 type constructors, add a version that operates on the new type arity-0 onstructors, and whose implementation is identical. runtime/mercury_builtin_types.m: Add the unify and compare predicates of the new type constructors. runtime/mercury_wrapper.[ch]: runtime/mercury_init.h: util/mkinit.c: Change the C type of the variable that holds the types of type_infos and pseudo_type_infos, since their representation is now simpler (no dummy argument). trace/mercury_trace_vars.c: Modify data structures that recognize the four old types to recognize their new variants as well. compiler/higher_order.m: compiler/polymorphism.m: Generate references to the new versions of predicates that manipulate type_infos and typeclass_infos. compiler/hlds_pred.m: compiler/ml_code_util.m: compiler/type_ctor_info.m: Modify predicates that recognize the four old types to recognize their new variants as well. compiler/type_util.m: Modify the predicates that construct the types of type_infos to create references to the new arity-0 type constructors. Modify predicates that recognize the four old types to recognize their new variants as well. Delete the predicate whose job was to replace the dummy arguments of the arity-1 type constructors with the void type, since it is not needed anymore. Delete the unused predicate cell_type_name. compiler/stack_layout.m: Fix comment. compiler/size_prof.m: Conform to the changes in type_util. compiler/pseudo_type_info.m: Conform to the changes in type_util. Convert to four-space indentation. |
||
|
|
1ed891b7b1 |
Introduce a mechanism for extending the det and nondet stacks when needed.
Estimated hours taken: 24
Branches: main
Introduce a mechanism for extending the det and nondet stacks when needed.
The mechanism takes the form of a new grade component, .exts ("extend stacks").
While the new mechanism may be useful in its own right, it is intended mainly
to support a new implementation of minimal model tabling, which will use a
separate Mercury context for each distinct subgoal. Each context has its own
det and nondet stack. Clearly, we can't have hundreds of contexts each with
megabyte sized det stacks. The intention is that the stacks of the subgoals
will start small, and be expanded when needed.
The runtime expansion of stacks doesn't work yet, but it is unnecessarily
hard to debug without an installed compiler that understands the new grade
component, which is why this diff will be committed before that is fixed.
compiler/handle_options.m:
compiler/options.m:
runtime/mercury_grade.h:
scripts/canonical_grade.sh-subr
scripts/init_grade_options.sh-subr
scripts/parse_grade_options.sh-subr
scripts/mgnuc.in
Handle the new grade component.
runtime/mercury_memory_zones.h:
Add MR_ prefixes to the names of the fields of the zone structure.
Record not just the actual size of each zone, which includes various
kinds of buffers, but also the desired size of the zone exclusive of
buffers.
Format the documentation of the zone structure fields more
comprehensibly.
runtime/mercury_memory_zones.c:
Instead of implementing memalign if it is not provided by the operating
system, implement a function that allows us to reallocate the returned
area of memory.
Provide a prototype implementation of memory zone extension. It doesn't
work yet.
Factor out the code for setting up redzones, since it is now needed
in more than place.
Convert to four space indentation.
Make the debugging functions a bit more flexible.
runtime/mercury_wrapper.c:
Conform to the improved interface of the debugging functions.
runtime/mercury_overflow.h:
runtime/mercury_std.h:
Move a generally useful macro from mercury_overflow.h to mercury_std.h.
runtime/mercury_stacks.c:
Add functions to extend the stacks.
runtime/mercury_stacks.h:
Add the tests required to invoke the functions that extend the stacks.
Add the macros needed by the change to compiler/llds.m.
Convert to four space indentation.
runtime/mercury_conf.h.in:
Prepare for the use of the posix_memalign function, which is the
current replacement of the obsolete memalign library function.
We don't yet use it.
runtime/mercury_context.h:
Format the documentation of the context structure fields more
comprehensibly.
Put MR_ prefixes on the names of the fields of some structures
that didn't previously have them.
Conform to the new names of the fields of the zone structure.
runtime/mercury_context.c:
runtime/mercury_debug.c:
runtime/mercury_deep_copy.c:
runtime/mercury_engine.c:
runtime/mercury_memory_handlers.c:
library/benchmarking.m:
library/exception.m:
Conform to the new names of the fields of the zone structure.
In some cases, add missing MR_ prefixes to function names
and/or convert to four space indentation.
runtime/mercury_engine.h:
Add a new low level debug flag for debugging stack extensions.
Format the documentation of the engine structure fields more
comprehensibly.
Convert to four space indentation.
runtime/mercury_conf_param.h:
Document a new low level debug flag for debugging stack extensions.
compiler/compile_target_code.m:
compiler/handle_options.m:
compiler/options.m:
Handle the new grade component.
compiler/llds.m:
Add two new kinds of LLDS instructions, save_maxfr and restore_maxfr.
These are needed because the nondet stack may be relocated between
saving and the restoring of maxfr, and the saved maxfr may point to
the old stack. In .exts grades, these instructions will save not a
pointer but the offset of maxfr from the start of the nondet stack,
since offsets are not affected by the movement of the nondet stack.
compiler/code_info.m:
Use the new instructions where relevant. (Some more work may be
needed on this score; the relevant places are marked with XXX.)
compiler/dupelim.m:
compiler/dupproc.m:
compiler/exprn_aux.m:
compiler/jumpopt.m:
compiler/livemap.m:
compiler/llds_out.m:
compiler/middle_rec.m:
compiler/opt_debug.m:
compiler/opt_util.m:
compiler/reassign.m:
compiler/use_local_vars.m:
Handle the new LLDS instructions.
tools/bootcheck:
Provide a mechanism for setting the initial stack sizes for a
bootcheck.
|
||
|
|
88b75863dc |
Add support for initialisation predicates to be called before main/2 is
Estimated hours taken: 16 Branches: main Add support for initialisation predicates to be called before main/2 is invoked. The new directive is `:- initialise initpredname.' NEWS: Mention the new functionality. compiler/export.m: `:- pragma export' also adds a C function declaration in the generated C wrapper code to avoid C compiler warnings about missing declarations. compiler/hlds_module.m: Added a new user_init_preds field to the module_info to record the preds named in `initialise' directives. Added predicates to access and update the new field. The exported names are generated automatically. compiler/llds.m: Added a new field cfile_num_user_inits to c_file structure. compiler/llds_out.m: Add code to include the `REQUIRED_INIT initpredexportname' lines in the comment section of the generated C that is recognised by mkinit. compiler/make_hlds_passes.m: Handle the new `initialise' directives. compiler/mercury_compile.m: Make sure the list of user defined init pred export names is passed to the C code construction preds. compiler/mercury_to_mercury.m: Handle the output of `initialise' directives. compiler/module_qual.m: compiler/modules.m: compiler/recompilation.check.m: compiler/recompilation.version.m: Handle the new `initialise' item. compiler/prog_data.m: Add a new `initialise(sym_name)' item. compiler/prog_io.m: Add code to parse `initialise' directives. compiler/prog_mode.m: Add di_mode pred and func. compiler/transform_llds.m: Handle the extra field in c_file. doc/reference_manual.texi: Update the operator table in the reference manual. Document the new `initialise' directive. library/list.m: Added index[01]_of_first_occurrence preds and det_index[01]_of_first_occurrence funcs. I've often had a need for these and they are used in looking up initprednames in the new module_info field. library/ops.m: Add `initialise' as a prefix operator. runtime/mercury_wrapper.c: runtime/mercury_wrapper.h: Add a new exported variable, MR_address_of_init_modules_required. Call the function pointed to by this variable at the right point during module initialisation. test/hard_coded/Mmakefile: test/hard_coded/initialise_decl.exp: test/hard_coded/initialise_decl.m: test/invalid/Mmakefile: test/invalid/bad_initialise_decl.err_exp: test/invalid/bad_initialise_decl.m: Added test cases. util/mkinit.c: Now always checks C files for extra inits (previously you had to explicitly supply the -x flag). |
||
|
|
db00e2afa6 |
Provide a mechanism to shut up progress messages from the declarative debugger
Estimated hours taken: 1 Branches: main Provide a mechanism to shut up progress messages from the declarative debugger for use in bootchecks, to remove a potential source of spurious test case failures. runtime/mercury_wrapper.[ch]: Add a new global, MR_mdb_decl_print_progress, that controls whether we print progress messages. Disable it if the new option --mdb-disable-progress is given. tools/bootcheck: Set the new option. trace/mercury_trace_declarative.c: Obey MR_mdb_decl_print_progress. Fix a bunch of departures from our coding standards. |
||
|
|
86ac840326 |
Implement a mechanism to generate the information required to determine the
Estimated hours taken: weeks Branches: main Implement a mechanism to generate the information required to determine the algorithmic complexity of selected procedures. The basis of the mechanism is a program transformation that wraps up the body of each selected procedure in code that detects top-level (non-recursive) calls, and for each top-level call, records the sizes of the input arguments and information about the cost of the call. For now, the cost information consists only of the number of cells and words allocated during the call, but there is provision for later adding information from a real-time clock. compiler/complexity.m: A new module containing the new transformation. compiler/transform_hlds.m: Add complexity.m to the list of submodules. compiler/mercury_compile.m: Invoke the new module. compiler/notes/compiler_design.html: Mention the new module. compiler/options.m: Add an option, --experimental-complexity. Its argument is a filename that specifies the list of procedures to transform. Add an option, --no-allow-inlining, to disallow all inlining. This is simpler to use than specifying several options to turn off each potential reason to inline procedures. doc/user_guide.texi: Document the new options. The documentation present now is only a shell; it will be expanded later. compiler/table_gen.m: compiler/goal_util.m: Move the predicate for creating renamings from table_gen.m to goal_util.m, since complexity.m also needs it now. In the process, make it more general by allowing outputs to have more complex modes than simply `out'. compiler/goal_util.m: Fix a bug exposed by the new transformation: when renaming goals (e.g. for quantification), rename the variables holding information about term sizes. compiler/handle_options.m: Disable inlining if experimental complexity analysis is enabled. compiler/compile_target_code.m: Pass the --experimental-complexity option on to the linker. library/term_size_prof_builtin.m: Add the Mercury predicates that serve as interfaces to the primitives needed by the experimental complexity transformation. runtime/mercury_term_size.[ch]: Add the implementations of the primitives needed by the experimental complexity transformation. runtime/mercury_wrapper.[ch]: Add global variables holding counters of the numbers of words and cells allocated so far. runtime/mercury_heap.h: Update these global variables when allocating memory. runtime/mercury_complexity.h: New file that contains the definition of the data structures holding the data collected by the experimental complexity transformation. This is separate from mercury_term_size.h, because it needs to be #included in mercury_init.h, the header file of the mkinit-generated <program>_init.c files. runtime/mercury_init.h: runtime/mercury_imp.h: #include mercury_complexity.h. util/mkinit.c: Define and initialize the data structures holding complexity information when given the -X option (mkinit doesn't have long options). Fix some deviations from our coding style. scripts/parse_ml_options.sh-subr.in: Accept the --experiment-complexity option. scripts/c2init.in: Pass the --experiment-complexity option on to mkinit.c. tools/bootcheck: Preserve the files containing the results of complexity analysis, if they exist. tools/makebatch: Allow the specification of EXTRA_MLFLAGS in the generated Mmake.stage.params files. |
||
|
|
e4da5e1c94 |
Fix performance problems in the compiler when handling automatically generated
Estimated hours taken: 10 Branches: main Fix performance problems in the compiler when handling automatically generated code (specifically, code generated by caribou). These depend on new facilities in the library. Fix a problem with the debugger: get the debugger to stop when given an interrupt signal. (I needed this fix to find the performance problems above.) The problem was that the variable set by the interrupt handler wasn't the right one. library/map.m: The map__overlay predicate takes time linear in the new map. However, sometimes the compiler wants to overlay a large map on a small one. Add a new version, map__overlay_large_map, which does the same job but whose complexity is linear in the size of the old map. library/set.m: library/set__ordlist.m: Add a new version of set__divide specialized to a situation that occurs in some performance-critical code in the compiler. This lowers the complexity from quadratic to linear. library/bag.m: Add predicates for operating on sets alongside for predicates for operating on lists. These should be able to exploit the sortedness of the set, although we don't do so yet. library/svbag.m: Add this new module to make some of the changes to the compiler easier. library/library.m: NEWS: Mention the new module. compiler/instmap.m: Use either map__overlay or map__overlay_large_map, depending on which one is likely to be more efficient. compiler/deforest.m: compiler/goal_util.m: compiler/mode_util.m: compiler/simplify.m: compiler/table_gen.m: Conform to the changes in instmap.m. compiler/liveness.m: Use the specialized version of set__divide. compiler/mode_info.m: The original representation of liveness information in the mode analyzer had a fast insert operation, but a slow delete operation and a lookup operation that is *very* slow when analyzing long conjunctions. Replace that representation with a more direct and more compact representation with slower insert operation but much faster lookup operation and significantly faster delete operation. compiler/modes.m: compiler/unique_modes.m: Conform to the changes in mode_info.m. trace/mercury_trace.c: Make the debugger's interrupt handler set the variable actually used by MR_trace to select which function to call. runtime/mercury_trace_base.[ch]: Make MR_selected_trace_func_ptr volatile, since it is now set from an interrupt handler. runtime/mercury_wrapper.[ch]: Make MR_trace_handler non-volatile, since it is no longer set from an interrupt handler. Change its name to MR_exec_trace_handler to reflect the fact that it is not the only trace handler. util/mkinit.c: Refer to MR_trace_handler by its new name. |
||
|
|
abc7d6b22b |
Add two runtime options useful in benchmarking I/O tabling.
Estimated hours taken: 2 Branches: main Add two runtime options useful in benchmarking I/O tabling. runtime/mercury_wrapper.[ch]: Recognize the two new runtime options, and implement the first: When --mem-usage-report is included in MERCURY_OPTIONS, write a report on the memory usage of the program when the program exits. trace/mercury_trace_internal.c: Implement the other option, --mdb-benchmark-silent. When this option is given, the debugger will generate no output to stdout (and neither will the program). This is to avoid mixing prompts (e.g. "mdb>" with the timing data output by tools/speedtest, allowing the output of tools/speedtest to be processed automatically. doc/user_guide.texi: Document the new options, with the documentation of --mdb-benchmark-silent being for developers only. Fix a documentation bug on an existing option. |
||
|
|
941be20e27 |
Type_desc__get_functor looks up the types of the arguments of a function
Estimated hours taken: 16
Branches: main
Type_desc__get_functor looks up the types of the arguments of a function
symbol. This predicate used to abort when an argument has an existential
type. This diff makes type_desc__get_functor work even in that case.
However, since in such cases the type of an argument is not a ground type,
this diff has to add the concept of a pseudo_type_desc, a descriptor for
a not necessarily ground type. Pseudo_type_descs are implemented as
MR_PseudoTypeInfos.
runtime/mercury_type_info.[ch]:
Add new macros to operate on pseudo_type_infos. Most have a structure
modelled on corresponding macros operating on type_infos.
Provide versions of MR_get_arg_type_info, MR_compare_type_info,
MR_unify_type_info, MR_collapse_equivalences,
MR_type_params_vector_to_list, MR_create_type_info and
MR_create_type_info_maybe_existq that work on pseudo_type_infos,
not type_infos.
Change MR_pseudo_type_info_vector_to_type_info_list, which implements
the core of get_functor, to return pseudo_type_infos instead of
type_infos, and rename it to reflect this fact.
Change to four-space indentation to reduce the number of lines
that have to be wrapped.
runtime/mercury_make_type_info_body.h:
Generalize the code for creating type_infos to also be handle
pseudo_type_infos.
Change to four-space indentation to reduce the number of lines
that have to be wrapped.
runtime/mercury_type_desc.[ch]:
Provide versions of MR_make_type_ctor_desc and MR_type_ctor_and_args
that work on pseudo_type_infos, not type_infos.
Change to four-space indentation to reduce the number of lines
that have to be wrapped.
runtime/mercury_builtin_types.[ch]:
runtime/mercury_builtin_types_proc_layouts.h:
runtime/mercury_hlc_types.h:
runtime/mercury_unify_compare_body.h:
Add the C types, global variables and functions necessary for the
new builtin Mercury type pseudo_type_desc. This type must be builtin,
because its structure (MR_PseudoTypeInfo) is defined in C, and as such
cannot be unified, compared, deconstructed etc without hand-written
C code.
runtime/mercury_deep_copy.c:
runtime/mercury_deep_copy_body.h:
Handle the copying of pseudo_type_infos/pseudo_type_descs. This code
is almost the same as the code to copy type_infos, but must of course
handle type variables, and the arguments are themselves copied as
pseudo_type_infos, not type_infos.
runtime/mercury_types.h:
Since deep copy needs to create pseudo_type_infos, provide a version
of the MR_PseudoTypeInfo type without const.
runtime/mercury_construct.c:
runtime/mercury_deconstruct.c:
Handle pseudo_type_descs just as we handle type_descs: neither can be
constructed, nor do they have function symbols with named arguments.
runtime/mercury_ml_expand_body.c:
Provide code to deconstruct pseudo_type_descs. This code is almost
the same as the code to deconstruct type_descs, but must of course
handle type variables, and the arguments are themselves
pseudo_type_descs, not type_descs.
runtime/mercury_tabling.c:
Catch attempts to table pseudo_type_infos.
runtime/mercury_tags.h:
Add macros for constructing lists of
pseudo_type_infos/pseudo_type_descs.
runtime/mercury_wrapper.[ch]:
Define global variables holding the addresses of the typeinfos for
describing pseudo_type_descs and lists of pseudo_type_descs.
runtime/mercury_init.c:
Add the extern declarations required by new code in mkinit.c.
util/mkinit.c:
Make the addresses of the typeinfos for describing pseudo_type_descs
and lists of pseudo_type_descs, defined in the library, known to the
runtime.
library/type_desc.m:
Add a new builtin type, pseudo_type_desc, for describing possibly
nonground types.
Add utility predicates for operating on pseudo_type_descs.
library/private_builtin.m:
Handle the new builtin type.
Add builtin typeinfos for describing pseudo_type_descs and lists of
pseudo_type_descs, since some functions in the runtime need them
for memory profiling.
library/rtti_implementation.m:
Handle the new builtin type, mostly by ignoring it, since the backends
that use this module do not have any notion of pseudo_type_infos.
Bring the module up to date with our formatting guidelines.
library/construct.m:
Make get_functor return a list of pseudo_type_descs instead of
type_descs.
Change the name of the version of get_functor that returns argument
names, to distinguish it from the base version by more than just the
arity.
Make the order of predicates more logical.
library/std_util.m:
Change the name of the version of get_functor that returns argument
names, to distinguish it from the base version by more than just the
arity.
However, this name change is effectively the only change: both
get_functor and get_functor_with_names still return lists of
type_descs. This means that they will throw exceptions in the presence
of existential types, but code using them need no algorithmic changes.
library/term.m:
library/term_to_xml.m:
Add module qualifiers as necessary; no algorithmic changes.
library/list.m:
Add two general-purpose predicates, all_true and all_false,
for use in the other library modules.
compiler/ml_util.m:
compiler/mlds_to_gcc.m:
compiler/rtti.m:
compiler/type_ctor_info.m:
Make sure we handle the new builtin type as a builtin type, and not
try to have the compiler create a type_ctor_info for it.
deep_profiler/canonical.m:
Delete the local definition of all_true.
tests/hard_coded/construct_test.{m,exp}:
Update this test case to test the ability to retrieve the names of the
fields of function symbols with existential types.
Add module qualifications as necessary.
tests/hard_coded/construct_test_exist.{m,exp}:
Add a tougher test case to print the types of the arguments of
function symbols with existential types.
tests/hard_coded/Mmakefile:
Add the new test case, and sort the names of the tests.
|
||
|
|
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.
|
||
|
|
72a1de2b8a |
Various improvements for accurate GC in LLDS grades:
Estimated hours taken: 12
Branches: main
Various improvements for accurate GC in LLDS grades:
- allow the active heap size to vary
(XXX currently we still allocate a fixed-size heap, and allow
the active heap size to vary within that; it would be better
to avoid that, by reallocating a bigger heap if the heap
fills up)
- some bug fixes.
runtime/mercury_wrapper.c:
Increase the default heap size from 4Mb to 32Mb.
This is OK because we only touch the parts of it that we use.
If accurate GC is enabled, set the other parameters
(MR_heap_redzone_size for LLDS, MR_heap_margin for MLDS)
so that initially we still only use 4Mb of the heap
before doing (the first) garbage collection.
runtime/mercury_wrapper.h:
runtime/mercury_wrapper.c:
Add a new runtime option --heap-expansion-factor,
for use by mercury_accurate_gc.c.
runtime/mercury_accurate_gc.c:
Only allocate forwarding pointer bitmap entries for the part of
the heap which has been used, not the whole heap. This is to
avoid allocating (and touching) an unnecessarily large bitmap
in cases where we have allocated a large amount of address space
to the heap, but are only using a small part of it before doing
each GC.
For the LLDS back-end, recompute the heap red zone size after
each collection (using MR_heap_expansion_factor).
In MR_schedule_agc(), handle the case where entry_label and/or
proc_layout are NULL.
Also, add some comments.
runtime/mercury_memory_zones.c:
Change MR_reset_redzone() so that it can handle changes in the
size of the red zone. In particular, make sure that we unprotect
all of the normal area, as well as protecting the red zone.
runtime/mercury_label.c:
Fix two bugs in MR_prev_entry_by_addr(): it was not correctly
handling the case where the entry table was empty, and it was
not correctly handling the case where the address searched for
was higher than any address in the entry table.
runtime/mercury_goto.h:
For native GC grades, record the addresses of the end of modules
in the entry table, so that we know where each procedure finishes when
mapping from instruction pointer values to stack layout entries.
Without this, we might think that the following C function was
actually part of the preceding Mercury procedure, and then incorrectly
use the stack layout of the Mercury procedure if we happened to
get a heap overflow signal (SIGSEGV) while in that C function.
|
||
|
|
f7dae76f87 |
Remove a long unused global variable.
Estimated hours taken: 0.1 Branches: main runtime/mercury_wrapper.[ch]: Remove a long unused global variable. |
||
|
|
f007b45df8 |
Implement the infrastructure for term size profiling.
Estimated hours taken: 400
Branches: main
Implement the infrastructure for term size profiling. This means adding two
new grade components, tsw and tsc, and implementing them in the LLDS code
generator. In grades including tsw (term size words), each term is augmented
with an extra word giving the number of heap words it contains; in grades
including tsc (term size cells), each term is augmented with an extra word
giving the number of heap cells it contains. The extra word is at the start,
at offset -1, to leave almost all of the machinery for accessing the heap
unchanged.
For now, the only way to access term sizes is with a new mdb command,
"term_size <varspec>". Later, we will use term sizes in conjunction with
deep profiling to do experimental complexity analysis, but that requires
a lot more research. This diff is a necessary first step.
The implementation of term size profiling consists of three main parts:
- a source-to-source transform that computes the size of each heap cell
when it is constructed (and increments it in the rare cases when a free
argument of an existing heap cell is bound),
- a relatively small change to the code generator that reserves the extra
slot in new heap cells, and
- extensions to the facilities for creating cells from C code to record
the extra information we now need.
The diff overhauls polymorphism.m to make the source-to-source transform
possible. This overhaul includes separating type_ctor_infos and type_infos
as strictly as possible from each other, converting type_ctor_infos into
type_infos only as necessary. It also includes separating type_ctor_infos,
type_infos, base_typeclass_infos and typeclass_infos (as well as voids,
for clarity) from plain user-defined type constructors in type categorizations.
This change needs this separation because values of those four types do not
have size slots, but they ought to be treated specially in other situations
as well (e.g. by tabling).
The diff adds a new mdb command, term_size. It also replaces the proc_body
mdb command with new ways of using the existing print and browse commands
("print proc_body" and "browse proc_body") in order to make looking at
procedure bodies more controllable. This was useful in debugging the effect
of term size profiling on some test case outputs. It is not strictly tied
to term size profiling, but turns out to be difficult to disentangle.
compiler/size_prof.m:
A new module implementing the source-to-source transform.
compiler/notes/compiler_design.html:
Mention the new module.
compiler/transform_hlds.m:
Include size_prof as a submodule of transform_hlds.
compiler/mercury_compile.m:
If term size profiling is enabled, invoke its source-to-source
transform.
compiler/hlds_goal.m:
Extend construction unifications with an optional slot for recording
the size of the term if the size is a constant, or the identity of the
variable holding the size, if the size is not constant. This is
needed by the source-to-source transform.
compiler/quantification.m:
Treat the variable reference that may be in this slot as a nonlocal
variable of construction unifications, since the code generator needs
this.
compiler/compile_target_code.m:
Handle the new grade components.
compiler/options.m:
Implement the options that control term size profiling.
doc/user_guide.texi:
Document the options and grade components that control term size
profiling, and the term_size mdb command. The documentation is
commented out for now.
Modify the wording of the 'u' HLDS dump flag to include other details
of unifications (e.g. term size info) rather than just unification
categories.
Document the new alternatives of the print and browse commands. Since
they are for developers only, the documentation is commented out.
compiler/handle_options.m:
Handle the implications of term size profiling grades.
Add a -D flag value to print HLDS components relevant to HLDS
transformations.
compiler/modules.m:
Import the new builtin library module that implements the operations
needed by term size profiling automatically in term size profiling
grades.
Switch the predicate involved to use state var syntax.
compiler/prog_util.m:
Add predicates and functions that return the sym_names of the modules
needed by term size profiling.
compiler/code_info.m:
compiler/unify_gen.m:
compiler/var_locn.m:
Reserve an extra slot in heap cells and fill them in in unifications
marked by size_prof.
compiler/builtin_ops.m:
Add term_size_prof_builtin.term_size_plus as a builtin, with the same
implementation as int.+.
compiler/make_hlds.m:
Disable warnings about clauses for builtins while the change to
builtin_ops is bootstrapped.
compiler/polymorphism.m:
Export predicates that generate goals to create type_infos and
type_ctor_infos to add_to_construct.m. Rewrite their documentation
to make it more detailed.
Make orders of arguments amenable to the use of state variable syntax.
Consolidate knowledge of which type categories have builtin unify and
compare predicates in one place.
Add code to leave the types of type_ctor_infos alone: instead of
changing their types to type_info when used as arguments of other
type_infos, create a new variable of type type_info instead, and
use an unsafe_cast. This would make the HLDS closer to being type
correct, but this new code is currently commented out, for two
reasons. First, common.m is currently not smart enough to figure out
that if X and Y are equal, then similar unsafe_casts of X and Y
are also equal, and this causes the compiler do not detect some
duplicate calls it used to detect. Second, the code generators
are also not smart enough to know that if Z is an unsafe_cast of X,
then X and Z do not need separate stack slots, but can use the same
slot.
compiler/type_util.m:
Add utility predicates for returning the types of type_infos and
type_ctor_infos, for use by new code in polymorphism.m.
Move some utility predicates here from other modules, since they
are now used by more than one module.
Rename the type `builtin_type' as `type_category', to better reflect
what it does. Extend it to put the type_info, type_ctor_info,
typeclass_info, base_typeclass_info and void types into categories
of their own: treating these types as if they were a user-defined
type (which is how they used to be classified) is not always correct.
Rename the functor polymorphic_type to variable_type, since types
such as list(T) are polymorphic, but they fall into the user-defined
category. Rename user_type as user_ctor_type, since list(int) is not
wholly user-defined but falls into this category. Rename pred_type
as higher_order_type, since it also encompasses functions.
Replace code that used to check for a few of the alternatives
of this type with code that does a full switch on the type,
to ensure that they are updated if the type definition ever
changes again.
compiler/pseudo_type_info.m:
Delete a predicate whose updated implementation is now in type_util.m.
compiler/mlds_to_c.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_il.m:
compiler/mlds_to_java.m:
Still treat type_infos, type_ctor_infos, typeclass_infos and
base_typeclass_infos as user-defined types, but prepare for when
they won't be.
compiler/hlds_pred.m:
Require interface typeinfo liveness when term size profiling is
enabled.
Add term_size_profiling_builtin.increase_size as a
no_type_info_builtin.
compiler/hlds_out.m:
Print the size annotations on unifications if HLDS dump flags call
for unification details. (The flag test is in the caller of the
modified predicate.)
compiler/llds.m:
Extend incr_hp instructions and data_addr_consts with optional fields
that allow the code generator to refer to N words past the start of
a static or dynamic cell. Term size profiling uses this with N=1.
compiler/llds_out.m:
When allocating memory on the heap, use the macro variants that
specify an optional offset, and specify the offset when required.
compiler/bytecode_gen.m:
compiler/dense_switch.m:
compiler/dupelim.m:
compiler/exprn_aux.m:
compiler/goal_form.m:
compiler/goal_util.m:
compiler/higher_order.m:
compiler/inst_match.m:
compiler/intermod.m:
compiler/jumpopt.m:
compiler/lambda.m:
compiler/livemap.m:
compiler/ll_pseudo_type_info.m:
compiler/lookup_switch.m:
compiler/magic_util.m:
compiler/middle_rec.m:
compiler/ml_code_util.m:
compiler/ml_switch_gen.m:
compiler/ml_unify_gen.m:
compiler/mlds.m:
compiler/mlds_to_c.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_il.m:
compiler/mlds_to_java.m:
compiler/modecheck_unify.m:
compiler/opt_debug.m:
compiler/opt_util.m:
compiler/par_conj_gen.m:
compiler/post_typecheck.m:
compiler/reassign.m:
compiler/rl.m:
compiler/rl_key.m:
compiler/special_pred.m:
compiler/stack_layout.m:
compiler/static_term.m:
compiler/string_switch.m:
compiler/switch_gen.m:
compiler/switch_util.m:
compiler/table_gen.m:
compiler/term_util.m:
compiler/type_ctor_info.m:
compiler/unused_args.m:
compiler/use_local_vars.m:
Minor updates to conform to the changes above.
library/term_size_prof_builtin.m:
New module containing helper predicates for term size profiling.
size_prof.m generates call to these predicates.
library/library.m:
Include the new module in the library.
doc/Mmakefile:
Do not include the term_size_prof_builtin module in the library
documentation.
library/array.m:
library/benchmarking.m:
library/construct.m:
library/deconstruct.m:
library/io.m:
library/sparse_bitset.m:
library/store.m:
library/string.m:
Replace all uses of MR_incr_hp with MR_offset_incr_hp, to ensure
that we haven't overlooked any places where offsets may need to be
specified.
Fix formatting of foreign_procs.
Use new macros defined by the runtime system when constructing
terms (which all happen to be lists) in C code. These new macros
specify the types of the cell arguments, allowing the implementation
to figure out the size of the new cell based on the sizes of its
fields.
library/private_builtin.m:
Define some constant type_info structures for use by these macros.
They cannot be defined in the runtime, since they refer to types
defined in the library (list.list and std_util.univ).
util/mkinit.c:
Make the addresses of these type_info structures available to the
runtime.
runtime/mercury_init.h:
Declare these type_info structures, for use in mkinit-generated
*_init.c files.
runtime/mercury_wrapper.[ch]:
Declare and define the variables that hold these addresses, for use
in the new macros for constructing typed lists.
Since term size profiling can refer to a memory cell by a pointer
that is offset by one word, register the extra offsets with the Boehm
collector if is being used.
Document the incompatibility of MR_HIGHTAGS and the Boehm collector.
runtime/mercury_tags.h:
Define new macros for constructing typed lists.
Provide macros for preserving the old interface presented by this file
to the extent possible. Uses of the old MR_list_cons macro will
continue to work in grades without term size profiling. In term
size profiling grades, their use will get a C compiler error.
Fix a bug caused by a missing backslash.
runtime/mercury_heap.h:
Change the basic macros for allocating new heap cells to take
an optional offset argument. If this is nonzero, the macros
increment the returned address by the given number of words.
Term size profiling specifies offset=1, reserving the extra
word at the start (which is ignored by all components of the
system except term size profiling) for holding the size of the term.
Provide macros for preserving the old interface presented by this file
to the extent possible. Since the old MR_create[123] and MR_list_cons
macros did not specify type information, they had to be changed
to take additional arguments. This affects only hand-written C code.
Call new diagnostic macros that can help debug heap allocations.
Document why the macros in this files must expand to expressions
instead of statements, evn though the latter would be preferable
(e.g. by allowing them to declare and use local variables without
depending on gcc extensions).
runtime/mercury_debug.[ch]:
Add diagnostic macros to debug heap allocations, and the functions
behind them if MR_DEBUG_HEAP_ALLOC is defined.
Update the debugging routines for hand-allocated cells to print the
values of the term size slot as well as the other slots in the relevant
grades.
runtime/mercury_string.h:
Provide some needed variants of the macro for copying strings.
runtime/mercury_deconstruct_macros.h:
runtime/mercury_type_info.c:
Supply type information when constructing terms.
runtime/mercury_deep_copy_body.h:
Preserve the term size slot when copying terms.
runtime/mercury_deep_copy_body.h:
runtime/mercury_ho_call.c:
runtime/mercury_ml_expand_body.h:
Use MR_offset_incr_hp instead of MR_incr_hp to ensure that all places
that allocate cells also allocate space for the term size slot if
necessary.
Reduce code duplication by using a now standard macro for copying
strings.
runtime/mercury_grade.h:
Handle the two new grade components.
runtime/mercury_conf_param.h:
Document the C macros used to control the two new grade components,
as well as MR_DEBUG_HEAP_ALLOC.
Detect incompatibilities between high level code and profiling.
runtime/mercury_term_size.[ch]:
A new module to house a function to find and return term sizes
stored in heap cells.
runtime/mercury_proc_id.h:
runtime/mercury_univ.h:
New header files. mercury_proc_id.h contains the (unchanged)
definition of MR_Proc_Id, while mercury_univ.h contains the
definitions of the macros for manipulating univs that used to be
in mercury_type_info.h, updated to use the new macros for allocating
memory.
In the absence of these header files, the following circularity
would ensue:
mercury_deep_profiling.h includes mercury_stack_layout.h
- needs definition of MR_Proc_Id
mercury_stack_layout.h needs mercury_type_info.h
- needs definition of MR_PseudoTypeInfo
mercury_type_info.h needs mercury_heap.h
- needs heap allocation macros for MR_new_univ_on_hp
mercury_heap.h includes mercury_deep_profiling.h
- needs MR_current_call_site_dynamic for recording allocations
Breaking the circular dependency in two places, not just one, is to
minimize similar problems in the future.
runtime/mercury_stack_layout.h:
Delete the definition of MR_Proc_Id, which is now in mercury_proc_id.h.
runtime/mercury_type_info.h:
Delete the macros for manipulating univs, which are now in
mercury_univ.h.
runtime/Mmakefile:
Mention the new files.
runtime/mercury_imp.h:
runtime/mercury.h:
runtime/mercury_construct.c:
runtime/mercury_deep_profiling.h:
Include the new files at appropriate points.
runtime/mercury.c:
Change the names of the functions that create heap cells for
hand-written code, since the interface to hand-written code has
changed to include type information.
runtime/mercury_tabling.h:
Delete some unused macros.
runtime/mercury_trace_base.c:
runtime/mercury_type_info.c:
Use the new macros supplying type information when constructing lists.
scripts/canonical_grade_options.sh-subr:
Fix an undefined sh variable bug that could cause error messages
to come out without identifying the program they were from.
scripts/init_grade_options.sh-subr:
scripts/parse_grade_options.sh-subr:
scripts/canonical_grade_options.sh-subr:
scripts/mgnuc.in:
Handle the new grade components and the options controlling them.
trace/mercury_trace_internal.c:
Implement the mdb command "term_size <varspec>", which is like
"print <varspec>", but prints the size of a term instead of its value.
In non-term-size-profiling grades, it prints an error message.
Replace the "proc_body" command with optional arguments to the "print"
and "browse" commands.
doc/user_guide.tex:
Add documentation of the term_size mdb command. Since the command is
for implementors only, and works only in grades that are not yet ready
for public consumption, the documentation is commented out.
Add documentation of the new arguments of the print and browse mdb
commands. Since they are for implementors only, the documentation
is commented out.
trace/mercury_trace_vars.[ch]:
Add the functions needed to implement the term_size command, and
factor out the code common to the "size" and "print"/"browse" commands.
Decide whether to print the name of a variable before invoking the
supplied print or browse predicate on it based on a flag design for
this purpose, instead of overloading the meaning of the output FILE *
variable. This arrangement is much clearer.
trace/mercury_trace_browse.c:
trace/mercury_trace_external.c:
trace/mercury_trace_help.c:
Supply type information when constructing terms.
browser/program_representation.m:
Since the new library module term_size_prof_builtin never generates
any events, mark it as such, so that the declarative debugger doesn't
expect it to generate any.
Do the same for the deep profiling builtin module.
tests/debugger/term_size_words.{m,inp,exp}:
tests/debugger/term_size_cells.{m,inp,exp}:
Two new test cases, each testing one of the new grades.
tests/debugger/Mmakefile:
Enable the two new test cases in their grades.
Disable the tests sensitive to stack frame sizes in term size profiling
grades.
tests/debugger/completion.exp:
Add the new "term_size" mdb command to the list of command completions,
and delete "proc_body".
tests/debugger/declarative/dependency.{inp,exp}:
Use "print proc_body" instead of "proc_body".
tests/hard_coded/nondet_c.m:
tests/hard_coded/pragma_inline.m:
Use MR_offset_incr_hp instead of MR_incr_hp to ensure that all places
that allocate cells also allocate space for the term size slot if
necessary.
tests/valid/Mmakefile:
Disable the IL tests in term size profiling grades, since the term size
profiling primitives haven't been (and probably won't be) implemented
for the MLDS backends, and handle_options causes a compiler abort
for grades that combine term size profiling and any one of IL, Java
and high level C.
|
||
|
|
3e766fcd11 |
Print streams sensibly in the debugger.
Estimated hours taken: 6
Branches: main
Print streams sensibly in the debugger.
runtime/mercury_library_types.h:
Define MercuryFilePtr as a shorthand for MercuryFile *.
library/io.m:
Define a user-friendly representation for streams that includes not
just the stream's name but all the info about the stream that user
using mdb may wish to know about the stream, as well as a unique stream
id.
Make the changes required to maintain this improved stream database.
If the program is being executed under mdb, then do not ever delete
items from the stream database, since e.g. the declarative debugger
may need to print the stream's representation even after the stream
is closed. (If executing outside mdb, then we delete a stream's entry
from the stream database when the stream is closed, as before.)
To allow the debugger to detect which variables are I/O streams,
change the stream types from being equivalent to c_pointer (and thus
indistinguishable from other c_pointers) to their own type. Implement
this type as MercuryFilePtr in the C backend. In the IL backend, we
represent it as Object[], the minimum representation change possible.
Use the C type definition to get rid of many casts.
When writing streams, write the user-friendly representation, not
a meaningless <<c_pointer>>.
runtime/mercury_init.h:
runtime/mercury_wrapper.[ch]:
runtime/mercury_layout_util.c:
The change in stream's representation changes the types of some of the
arguments of functions exported to C from io.m; conform to those
changes.
browser/browse.m:
browser/sized_pretty.m:
In each of the mechanisms that the debugger can use to display terms,
pass along the stream name database.
browser/browser_info.m:
When deconstructing terms that are streams, return the stream's
user-friendly id, not a c_pointer.
browser/browse_test.m:
Update this test program to test the new way of printing streams.
runtime/mercury_trace_base.[ch]:
Define the MR_trace_ever_enabled variable to let io.m know whether
it is allowed to ever discard stream info.
runtime/mercury_init.h:
runtime/mercury_wrapper.[ch]:
Update the types of the functions dealing with streams to use
MercuryFilePtr to refer to streams instead of MR_Word. These functions
are implemented by Mercury predicates exported to C.
runtime/mercury_wrapper.c:
Set MR_trace_ever_enabled to true when execution tracing is enabled.
This is the only assigment to MR_trace_ever_enabled after
initialization to the default (false).
tests/debugger/declarative/io_stream_test.{m,inp,exp,exp}:
A new test case to test the debugger's printing of I/O streams.
tests/debugger/declarative/Mmakefile:
Enable the new test case.
|
||
|
|
ea33d1945c |
The Aditi API has been re-implemented. This change updates
Estimated hours taken: 40
Branches: main
The Aditi API has been re-implemented. This change updates
the Mercury->Aditi interface to work with the new API.
compiler/aditi_builtin_ops.m:
Pass aditi__states to the builtin predicates implementing
calls to Aditi procedures.
compiler/mode_util.m:
Add a function aditi_ui_mode.
compiler/type_util.m:
Add a function aditi_state_type.
runtime/mercury_wrapper.{c,h}:
util/mkinit.c:
Pass the connection and a transaction in which to
store the Aditi-RL modules.
extras/aditi/aditi.m:
extras/aditi/aditi_private_builtin.m:
util/mkinit.c:
Use the new API.
|
||
|
|
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. |
||
|
|
1315102d7c |
Fix several occurrences of a bug that prevented the compiler from passing
Estimated hours taken: 20 Branches: main Fix several occurrences of a bug that prevented the compiler from passing all the tests in deep profiling grades. We now pass all the tests in deep profiling grades. Some additional changes were useful in tracking this bug down. Using C types to represent deep profiling data structures allowed us to delete a bunch of casts and thus eliminate them as potential bug locations. Another was to fix some bugs in low level debugging support. In light of the fragility of the deep profiling invariants, always check them when writing out deep profiling data files. Since mdprof depends on these invariants, they have to be checked somewhere, and we already have code for the checks in the runtime. Reenable tail recursion support in deep profiling grades, since it now works. (The bug this change fixes used to occur most in tail recursive procedures, which is why previously I turned it off.) compiler/options.m: Reenable tail recursion support in deep profiling grades. runtime/mercury_unify_compare_body.h: Fix the bug that prevented us from passing all the tests with invariants checked and tail recursion support enabled. The bug was that in several cases, the code in mercury_unify_compare_body.h did not invoke the appropriate deep profiling routines and thus did not fill in the deep profiling data structure they were supposed to fill in, breaking an invariant. There were several instances of this bug: unify, compare and compare_representation on tuples, and compare_representation on functions, predicates and user-defined types. These oversights were possible because the actions of returning an answer and filling in the deep profiling data structures (in deep profiling grades) were separate. If one omitted the latter, tests could still work in all grades except deep profiling grades. The fix therefore uses one macro (return_compare_answer or return unify_answer, depending on the the operation) to fill in the deep profiling data structure (in deep profiling grades) and return the answer, making it impossible to forget to do the former. The new approach treats compare_representation the same as compare, and gathers the same information for it. runtime/mercury_ho_call.c: Factor out some commonalities in the definitions of the MR_ProcStatic data structures used by the code in mercury_unify_compare_body.h. Change a macro name to support the changes in mercury_unify_compare_body.h. Change the module name of compare_representation/3 from std_util to builtin, to match unify/2 and compare/3. compiler/deep_profiling.m: Treat compare_representation/3 the same way as we treat compare/3. library/builtin.m library/std_util.m Move the declaration of compare_representation/3 from std_util to builtin, to make it easier to handle it the same way as compare/3. Since it is just a variant of compare/3 and is at least as built into the implementation, it belongs there anyway. library/profiling_builtin.m: Use C types to represent deep profiling data structures. Delete the casts that are redundant after this change. Fix formatting of foreign_procs. runtime/mercury_deep_profiling.c: As mentioned above, always check the invariants of the deep profiling data structures when writing them out. runtime/mercury_deep_profiling.h: Avoid a warning about nested declarations of variable "i". runtime/mercury_deep_rec_depth_body.h: Delete a bunch of casts we don't need anymore. runtime/mercury_wrapper.[ch]: Initialize a couple of predicate names in the low level debug support to "" instead of NULL. The code that accesses these variables passes them to strcmp directly, which lead to core dumps. We could change the accessing code to test for NULL, but since that code is executed on every call when low level debugging is enabled, that would lead to even greater slowdowns, which we can do without. To avoid a warning about casting away const, make the variables involved "const char *" instead of plain "char *"; we don't want to update the pointed-to strings anyway. tools/bootcheck: In profiling grades, write out profiling data files by default, and require the use of an option to turn them off. This is needed to make sure that the deep profiling invariants are checked by default. tests/hard_coded/compare_rep_usereq.m: tests/hard_coded/compare_representation.m: Avoid hard-coding the name of the module defining compare_representation/3. |
||
|
|
f00567129e |
Do not generate assignments to the variables that used to hold the
Estimated hours taken: 0.5 Branches: main util/mkinit.c: Do not generate assignments to the variables that used to hold the address of the type_ctor_infos of the variable arity type_ctor_infos, since those variables aren't needed anymore. runtime/mercury_wrapper.[ch]: Delete those variables. |
||
|
|
17d5aa732e |
Add support for interfacing Mercury with the MPS garbage collector.
Estimated hours taken: 20
Branches: main
Add support for interfacing Mercury with the MPS garbage collector.
This change is broken into three parts:
1. Import version 1.100.1 of the MPS kit into the Mercury
CVS repository, in the directory `mps_gc'.
2. Make some changes to the MPS kit for Mercury,
to support fully-conservative collection and tagged pointers,
and to wrap it in an interface that is similar to that of
the Boehm collector.
3. Modify the rest of the Mercury implementation
to support linking with the MPS kit instead
of the Boehm collector. This involved defining
`mps' as a new GC method and a new grade component.
This is part 3 of 3.
Mmake.workspace:
Include the MPS directories in the header file and library search
paths.
tools/bootcheck:
Link the mps_gc directory into the stage2 and stage3 directories.
Mmake.workspace:
runtime/Mmakefile:
scripts/ml.in:
For *.mps grades, link in mps.a.
(XXX ml.in is linking in libmps.a, which is wrong.)
runtime/Mmakefile:
trace/Mmakefile:
In the rule for `check_headers', which checks macro namespace
cleanliness, allow names to start with `MPS_' or `mps_'.
runtime/RESERVED_MACRO_NAMES:
Add `mercury_mps_h', which is used by mps_gc/code/mercury_mps.h
for its header guard. (Normally it would be better to use
uppercase for header guard macro names, but that would be
inconsistent with the coding style used in mps_gc/code.)
scripts/canonical_grade.sh-subr:
scripts/init_grade_options.sh-subr:
scripts/parse_grade_options.sh-subr:
scripts/canonical_grade.sh-subr:
Handle the new `mps' GC method and grade component.
compiler/globals.m:
compiler/options.m:
doc/user_guide.texi:
Replace gc_method `conservative' with two alternatives
`boehm' and `mps'. ("--gc conservative" is still allowed,
and treated as equivalent to "--gc boehm".)
Add new function `gc_is_conservative' to globals.m.
compiler/mercury_compile.m:
compiler/handle_options.m:
Use `gc_is_conservative' rather than `= conservative'.
compiler/handle_options.m:
Handle the "mps" grade component.
(XXX need to document this in options.m and user_guide.texi)
compiler/compile_target_code.m:
Pass the appropriate C defines for the new GC methods.
compiler/mercury_compile.m:
Wrap the work-around for a Boehm GC bug inside `#ifndef MR_MPS_GC'.
library/array.m:
Use GC_FREE() rather than GC_free().
This is needed for two reasons:
- so that it works with MPS, which only defines GC_FREE
- so that it works with then Boehm collector when
GC debugging is enabled
library/benchmarking.m:
Output GC statistics for the MPS collector.
runtime/mercury.h:
runtime/mercury_heap.h:
runtime/mercury_init.h:
runtime/mercury_memory.h:
If MR_MPS_GC is defined, use mercury_mps.h rather than gc.h.
runtime/mercury_conf_param.h:
Add configuration macros MR_BOEHM_GC and MR_MPS_GC.
Set MR_CONSERVATIVE_GC if either of these is set.
Default to MR_BOEHM_GC if only MR_CONSERVATIVE_GC is set.
runtime/mercury_context.h:
runtime/mercury_deep_copy.h:
runtime/mercury_engine.h:
runtime/mercury_float.h:
runtime/mercury_heap.h:
Explictly #include "mercury_conf.h", so that
MR_CONSERVATIVE_GC will be set properly before it is tested.
runtime/mercury_grade.h:
Handle the .mps grade component.
runtime/mercury_memory.c:
runtime/mercury_wrapper.c:
runtime/mercury_memory_handlers.c:
Move the call to MR_setup_signals() earlier in the
initialization sequence, so that the MPS signal handlers
get installed after our signal handlers. This is needed
because our signal handlers assume that any signals that
they can't handle are fatal errors, which interfere's
with MPS's use of signal handlers for memory barriers.
runtime/mercury_wrapper.c:
Add code to initialize the MPS collector.
Put code which is specific to the Boehm collector inside
#ifdef MR_BOEHM_GC rather than #ifdef MR_CONSERVATIVE_GC.
runtime/mercury_wrapper.h:
Update a comment.
|
||
|
|
010a9ecf74 |
Fix several bugs in deep profiling. These allow the compiler to bootstrap
Estimated hours taken: 30
Branches: main
Fix several bugs in deep profiling. These allow the compiler to bootstrap
again, *including* writing out the profiling data, with sanity checks enabled.
Some test cases still fail, but significantly fewer than before.
These fixes required several improvements in the infrastructure for low
level debugging in the LLDS grades.
compiler/deep_profiling.m:
Mark calls that have a prepare_for_{normal,ho,...}_call inserted before
them as impure, to prevent simplify from optimizing them away, e.g. as
duplicate calls. This is needed because a prepare_for_{...}_call that
is not followed immediately by the call port code of the callee leaves
the profiling tree in a state that violates its invariants.
Mark the redo port code of model_non predicates as needing to be
preserved, even if determinism analysis would normally cause it to be
cut by marking the disjunction it is part of (whose two disjuncts are
the det exit port code and the failure redo port code) as det.
Fix the generation of goal paths to match what the rest of the compiler
does. Start number conjuncts, disjuncts and switch arms from 1, not 0,
and do not reverse goal paths before attaching them to goals; they will
be reversed when they are converted to strings.
compiler/det_analysis.m:
If a disjunct has determinism failure but is impure, treat it as being
able to succeed when computing the max number of solutions of the
disjunction as a whole, *provided* that some earlier disjuct could
succeed. The idea is that ( impure failure ; det ) should be treated
as det, since all backtracking is local within it, while disjunctions
of the form ( det ; impure failure ) should be treated as multi, since
we want to be able to backtrack to the second disjunct from *outside*
the disjunction.
At the moment, we do this not for all impure goals, but only for the
impure goals that deep_profiling marks with the preserve_backtrack_into
feature.
compiler/hlds_goal.m:
Add the preserve_backtrack_into feature.
Add utility predicates for handling the features of a goal directly,
without explicitly dealing with its goal_info.
runtime/mercury_debug.[ch]:
Add mechanisms for turning the printing of low level debugging messages
on and off. Without this, enabling low level debugging can generate
literally gigabytes of debugging output.
The mechanisms all depend on numbering calls.
One mechanism allows messages to be printed starting from calls in
given ranges, by including e.g. -di100-200,300-400 in MERCURY_OPTIONS.
Another mechanism allows N messages to be printed starting from calls
to a given procedure or from calls at which next_call_site_dynamic
has a given value. The value of N (the size of the block of calls)
can be specified by include -dB<num> in MERCURY_OPTIONS. The name of
the given procedure (actually the name of its entry label) can be
specified by including -dj<entrylabel> in MERCURY_OPTIONS. The address
of the call_site_dynamic structure to watch for is specified with the
-dW<addr> option in MERCURY_OPTIONS, as before.
runtime/mercury_wrapper.[ch]:
Add the global variables required to implement the new low level
debugging functionality, as well as the option processing code required
to set those global variables.
Separate the flags controlling the printing of the values of stack
control registers (sp, curfr etc) and ordinary registers (r1, r2 etc).
Print ordinary registers only if explicitly requested.
runtime/mercury_engine.h:
Add the required global flags.
runtime/mercury_deep_profiling.[ch]:
Add two extra arguments to MR_deep_assert, and print them if an
assertion fails. This makes it easier to decide what parameters to give
to the new low level debugging mechanisms.
runtime/mercury_deep_*_port_body.h:
runtime/mercury_deep_rec_depth_*.h:
library/profiling_builtin.m:
Pass the extra arguments to MR_deep_assert, and print low level
debugging messages only if the relevant flag is set.
tools/lmc:
Add mechanisms to add to the list of C compiler flags the program is
compiled with by lmc.
|
||
|
|
32051f5467 |
Add support for command line completion to mdb.
Estimated hours taken: 40
Branches: main
Add support for command line completion to mdb.
NEWS:
Document the change.
trace/mercury_trace_completion.{c,h}:
Define the framework for completion.
Examine command lines to determine which completers to use.
trace/mercury_trace_alias.{c,h}:
trace/mercury_trace_help.{c,h}:
trace/mercury_trace_internal.{c,h}:
trace/mercury_trace_tables.{c,h}:
trace/mercury_trace_vars.{c,h}:
Define context-specific completers.
trace/mercury_trace_help.c:
Record all help topics in an array for use by the completer.
trace/mercury_trace_internal.c:
Add completion information to the list of commands.
Add a function MR_trace_command_completion_info to access
that information.
runtime/mercury_wrapper.{c,h}
Add a runtime option `--force-readline', which tells mdb to
use readline even if MR_mdb_in is not a tty. This is needed
for tests/debugger/completion. `--force-readline' is not
documented because I'm not sure that it will work properly
in all situations (it's fine for the test).
Fix capitalisation in references to the Mercury User's Guide
in error messages.
trace/mercury_trace_readline.c:
Tell Readline to use our completer.
Handle `--force-readline'. Disable some Readline terminal
initialisation code which reports spurious warnings if the
input stream is not a tty.
trace/Mmakefile:
Add mercury_trace_completion.{c,h}.
runtime/mercury_array_macros.h:
Define a macro MR_find_first_match, which is like MR_bsearch
except that it finds the first match, not an arbitrary match.
runtime/mercury_memory.c:
Handle NULL pointers in MR_copy_string();
runtime/mercury_memory.h:
Add a macro MR_free_func which returns the address of free().
Used where it is necessary to pass the address of MR_free().
tests/debugger/Mmakefile:
tests/debugger/completion.m:
tests/debugger/completion.exp:
tests/debugger/completion.inp:
tests/debugger/completion.inputrc:
tests/debugger/completion.sub1.m:
tests/debugger/completion.sub2.m:
tests/debugger/completion.sub2.sub3.m:
Test case.
|
||
|
|
b51c742885 |
Allow the debugger to print higher order values and typeinfos, mainly by
Estimated hours taken: 50
Branches: main
Allow the debugger to print higher order values and typeinfos, mainly by
making the committed choice modes of the predicates in deconstruct.m to
deconstruct higher order values and typeinfos. (The non committed choice
versions will continue to return only placeholders.)
Having the debugger print typeinfos is occasionally useful but more often
it is just distracting. This change therefore adds a new debugger command,
"print_optionals", that toggles the printing of optional values. For now,
the only optional values are typeinfos.
NEWS:
Mention the new capability and the new predicates in the library.
Mention the predicates added previously that allow the caller to
specify how non-canonical terms should be handled, since the change
in their semantics that we anticipated when they were added has now
happened, and their semantics should now be more stable.
browser/browser_info.m:
Use the predicates in the deconstruct.m instead of std_util,
to make the choice of noncanonical term method handling explicit.
browser/browse.m:
When writing small terms using io__write_univ, explicitly use
the same noncanonical term handling method as browser_info.m
library/io.m:
Add predicates to retrieve the current input and output streams.
Add versions of io__write_univ that specify the stream and maybe
the method of handling noncanonical terms.
Add a mode to io__write_list that allows the closure that prints the
list elements to be cc_multi.
All of these are for the new functionality in the browser.
runtime/mercury_ml_expand_body.h:
In committed choice contexts, deconstruct closures as if they were
ordinary terms, with the function symbol being the name of the
predicate/function and the arguments being the terms stored in
the closure.
In committed choice contexts, deconstruct typeinfos as if they were
ordinary terms, with the function symbol being the name of the type
constructor and the arguments being the type constructor's arguments.
runtime/mercury_type_info.[ch]:
Add a new function, MR_collapse_ctor_equivalences, for use by
mercury_ml_expand_body.h.
Delete a redundant function comment.
library/deconstruct.m:
Document the changes in the behavior of the predicates defined in this
module as a result of the change to mercury_ml_expand_body.h.
runtime/mercury_ho_call.h:
runtime/mercury_stack_layout.h:
Add prefixes on structure field names that did not have them.
browser/dl.m:
Add prefixes where needed by the changes to mercury_ho_call.h.
runtime/mercury_layout_util.[ch]:
Remove the first argument of MR_materialize_closure_typeinfos, since
its correct value is always the same part of the second argument.
runtime/mercury_deep_copy_body.h:
Do not pass the first argument of MR_materialize_closure_typeinfos.
Add field name prefixes where necessary.
compiler/modules.m:
The mercury_builtin module is no longer part of the library.
compiler/pd_debug.m:
compiler/rl_analyze.m:
Minor updates to avoid trying to take the address of io__write_list,
since it now has more than one mode.
runtime/mercury_init.h:
runtime/mercury_wrapper.[ch]:
trace/mercury_trace_vars.[ch]:
Add a parameter to MR_trace_browse_all_on_level that specifies
whether we should print values of type type_info.
trace/mercury_trace_vars.c:
Do not ignore predicates and functions anymore.
runtime/mercury_stack_trace.c:
trace/mercury_trace.c:
trace/mercury_trace_declarative.c:
trace/mercury_trace_external.c:
Pass the new parameter of MR_trace_browse_all_on_level.
trace/mercury_trace_internal.c:
Implement the "print_optionals" command.
doc/user_guide.texi:
Document the "print_optionals" command.
tests/debugger/mdb_command_test.inp:
Test the documentation of "print_optionals".
tests/debugger/higher_order.{m,inp,exp,exp2}:
A new test case to exercise the ability to print higher order values.
Note that the format of the predicate names in the output should be
improved, but that is a separate change since doing it the right way
requires bootstrapping.
tests/debugger/Mmakefile:
Enable the new test case.
tests/debugger/nondet_stack.exp*:
Update the expected output to reflect the fact that nondet stack dumps,
being intended for debugging, include type_infos.
tests/debugger/tabled_read_decl.exp*:
Update the expected output to reflect the fact that for maximum
usefulness, the printing of I/O action atoms prints meaningful
type_infos.
tests/hard_coded/deconstruct_arg.*:
tests/hard_coded/write_reg1.*:
Expand these tests to check that we handle higher order values
correctly not just when canonicalizing but also in committed choice
modes.
|
||
|
|
b7c4a317e9 |
Add MR_ prefixes to the remaining non-prefixed symbols.
Estimated hours taken: 4 Branches: main Add MR_ prefixes to the remaining non-prefixed symbols. This change will require all workspaces to be updated The compiler will start generating references to MR_TRUE, MR_bool, etc., which are not defined in the old runtime header files. runtime/mercury_std.h: Add MR_ prefixes to bool, TRUE, FALSE, max, min, streq, strdiff, strtest, strntest, strneq, strndiff, strntest, NO_RETURN. Delete a commented out definition of `reg'. runtime/mercury_tags.h: Add an MR_ prefix to TAGBITS. configure.in: runtime/mercury_goto.h: runtime/machdeps/i386_regs.h/mercury_goto.h: Add an MR_ prefix to PIC. runtime/mercury_conf_param.h: Allow non-prefixed PIC and HIGHTAGS to be defined on the command line. runtime/mercury_bootstrap.h: Add backwards compatibility definitions. RESERVED_MACRO_NAMES: Remove the renamed macros. compiler/export.m: compiler/ml_code_gen.m: Use MR_bool rather than MR_Bool (MR_Bool is meant to be for references to the Mercury type bool__bool). runtime/mercury_types.h: Add a comment the MR_Bool is for references to bool__bool. */*.c: */*.h: */*.m: Add MR_ prefixes. |
||
|
|
c66cea0665 |
Add MR_ prefixes to uses of configuration macros.
Estimated hours taken: 2.5 Branches: main Add MR_ prefixes to uses of configuration macros. Bootcheck now succeeds with MR_NO_CONF_BACKWARDS_COMPAT. Mmake.common.in: Define MR_NO_CONF_BACKWARDS_COMPAT when checking for namespace cleanliness. RESERVED_MACRO_NAMES: Remove the configuration macros. runtime/mercury_conf_bootstrap.h: Remove a duplicate definition of BOXED_FLOAT. configure.in: */*.c: */*.h: */*.m: Add MR_ prefixes. |