Estimated hours taken: 1.5
Split llds into two parts. llds.m defines the data types, while llds_out.m
has the predicates for printing the code.
Removed the call_closure instruction. Instead, we use calls to the
system-defined addresses do_call_{det,semidet,nondet}_closure. This is
how call_closure was implemented already. The advantage of the new
implementation is that it allows jump optimization of what used to be
call_closures, without new code in jumpopt.
Estimated hours taken: 8
options.m:
Rename branch_delay_slot to have_delay_slot.
Set optimize_delay_slot in -O2 only if have_delay_slot was set earlier.
This is possible now because the default optimization level is now
set in mc.
mercury_compile:
Change verbose output a bit to be more consistent.
dead_proc_elim:
Export the predicates that will eventually be needed by inlining.m.
inlining.m:
Use the information about the number of times each procedure is called
to inline local nonrecursive procedures that are called exactly once.
EXCEPT that this is turned off at the moment, since the inlining of
parse_dcg_goal_2 in prog_io, which this change enables, causes the
compiler to emit incorrect code.
prog_io:
Moved the data type definitions to prog_data. (Even though prog_io.m
is ten times the size of prog_data.m, the sizes of the .c files are
not too dissimilar.)
Estimated hours taken: 3
A bunch of cleanups: improve error messages, tidy up the code.
Also, do some work towards supporting higher-order functions.
type_util.m:
Add new predicate type_is_higher_order/3 for checking
whether a type is a higher-order type. This recognizes
both higher-order predicate types and also higher-order
function types.
code_info.m, modes.m, polymorphism.m, shapes.m:
Use type_is_higher_order/3.
make_hlds.m:
Fix another error message to do the right thing when
reporting errors for functions.
mercury_to_mercury:
List `func' in the table of operators, so that it gets
parenthesized correctly.
modes.m, mode_errors.m:
Improve the error message for attempted higher-order unifications:
spit out some context, and if verbose_errors is enabled, spit
out a long description.
Estimated hours taken: 10
hlds, hlds_module, hlds_pred, hlds_goal, hlds_data:
Divided the old hlds.m into four files:
hlds_module.m defines the data structures that deal with issues
that are wider than a single predicate. These data structures are
the module_info structure, dependency_info, the predicate table
and the shape table.
hlds_pred.m defined pred_info and proc_info, pred_id and proc_id.
hlds_goal.m defines hlds__goal, hlds__goal_{expr,info}, and the
other parts of goal structures.
hlsd_data.m defines the HLDS types that deal with issues related
to data and its representation: function symbols, types, insts, modes.
It also defines the types related to determinism.
hlds.m is now an empty module. I have not removed it from CVS
because we may need the name hlds.m again, and CVS does not like
the reuse of a name once removed.
other modules:
Import the necessary part of hlds.
det_analysis:
Define a type that was up to now improperly defined in hlds.m.
prog_io:
Move the definition of type determinism to hlds_data. This decision
may need to be revisited when prog_io is broken up.
dnf, lambda:
Simplify the task of defining predicates.
llds:
Fix some comments.
mercury_compile:
If the option -d all is given, dump all HLDS stages.
shape, unused_args:
Fix formatting.
A Constraint Solver Interface For Mercury
<thunderous applause>
Estimated hours taken: 1 summer studentship
This is the implementation of a fairly general constraint solver interface. If
using a library grade *.cnstr, we emit C instructions to keep track of the
solver's implicit state. This is done by storing and restoring 'tickets' -
abstract handles on the solver's state.
We emit a store_ticket() macro:
-when entering the first disjunct of a disjunction
-when entering the condition of an if-then-else
We emit a restore_ticket() macro:
-when entering a disjunct other than the first of a disjunction
-when entering the else part of an if-then-else
We emit a discard_ticket() macro:
-after the restore_ticket() in the final disjunct of a disjunction
-at the start of the 'then' part of an if-then-else
The rules for emitting the macros is slightly more complicated than that shown
above for if-then-elses (determinism of the parts must be taken into account).
compiler/code_info.m:
Get an llds store_ticket/restore_ticket etc. instruction
compiler/disj_gen.m:
Emit ticket macros in the appropriate places in a disjunction.
compiler/dupelim.m:
Handle the new llds instruction.
compiler/frameopt.m:
Handle the new llds instruction.
compiler/handle_options.m:
If the grade is *.cnstr, set the constraints option on.
compiler/ite_gen.m:
Emit ticket macros in the appopriate places in an if-then-else.
compiler/livemap.m:
Handle the new llds instruction.
compiler/llds.m:
Output the ticket macros.
compiler/make_hlds.m:
An irrelevant tidy-up.
compiler/mercury_compile.pp:
If the grade is *.cnstr, pass -DCONSTRAINTS to mgnuc
compiler/middle_rec.m:
Handle the new llds instruction.
compiler/opt_*.m:
Handle the new llds instruction.
compiler/options.m:
Introduce a new boolean option 'constraints'.
compiler/shapes.m:
Output a new shape - 'ticket'.
compiler/unify_proc.m:
Handle the new llds instruction.
compiler/v*.m:
Handle the new llds instruction.
Estimated hours taken: 1.5
code_exprn:
Distribute the initial comments among the declarations of the exported
predicates. This makes it much less likely that the declarations will
be modified without changes in the comments. Since this has happened
in the past, some predicates are now without comments.
Changed code_exprn__place_var to prefer to get even a constant term
from a location if it has been produced before, and factor out some
code that is shared between the handling of cached and evaled
expressions.
code_exprm, code_info:
Removed an unnecessary argument from code_exprn__get_varlocs.
dead_proc_elim:
Changed the predicate name prefix from dead__ to dead_proc_elim__
to conform to notes/CODING_STANDARDS.
handle_options:
Remove an inappropriate comment.
jumpopt:
Filter out redundant livevals whether --optimize-fulljumps is given
or not. (I thought they aren't created if the option isn't given,
but they are.)
options:
Change the meaning of -O from --c-optimize to --opt-level.
Disabled unused args until the bug is fixed.
Estimated hours taken: 2
code_exprn:
When we are processing the flushing of create expressions, make sure
the Lval we are creating into isn't a field reference. This avoids
deep field of field of field of ... nesting. It does introduce
references to high register numbers, but this is a lesser evil,
and Tom and I plan to fix this anyway.
arg_info, globals, options:
Change --args old to --args simple.
options:
Make some help messages more specific.
code_aux, code_exprn, code_info, det_report, make_hlds, mercury_to_goedel,
prog_io, typecheck:
Changes to accommodate the move from varset__lookup_name
to varset__search_name.
Estimated hours taken: 2
exprn_aux:
Both code_exprn and lookup_switch had code to check whether an
expression is constant or not. Some of the code is different
due to different handling of variables in rvals, but exprn_aux
now contains the common subset.
This common subset used to treat some address constants incorrectly,
simply by not considering them; they are now considered and treated
properly.
code_exprn, lookup_switch, exprn_aux:
Remove redundant option lookups in the process of checking for
constant expressions.
code_exprn:
Other minor cleanups, including removal of a block of code Tom
says was "deep magic" (but which turns out to be unnecessary).
code_info:
Removed some dead code.
options:
Added real support for --opt-level, in the form of a table of
default values of options for each optimization level between
0 and 5 (both inclusive). This needs a new form of documentation.
How do you do tables in texinfo?
Estimated hours taken: 1
Fix a bug in code generation for semidet pragma c_codes.
code_gen.pp:
For semidet pragma c_codes, make sure that we lock register r1
before allocating registers to the output variables, so that
we don't clobber r1 before the test to see if it succeeded.
code_info.m:
Add predicates code_info__lock_reg and code_info__unlock_reg which
forward to code_exprn__lock_reg and code_exprn__unlock_reg, for
use in the above change to code_gen.pp.
Estimated hours taken: 1.5
Undo dylan's changes in the names of some library entities,
by applying the following sed script
s/term_atom/term__atom/g
s/term_string/term__string/g
s/term_integer/term__integer/g
s/term_float/term__float/g
s/term_context/term__context/g
s/term_functor/term__functor/g
s/term_variable/term__variable/g
s/_term__/_term_/g
s/std_util__bool_/bool__/g
to all the `.m' and `.pp' files in the compiler and library directories.
The reason for undoing these changes was to minimize incompatibilities
with 0.4 (and besides, the changes were not a really good idea in the first
place).
I also moved `bool' to a separate module.
The main reason for that change is to ensure that the `__' prefix is
only used when it genuinely represents a module qualifier.
(That's what dylan's changes were trying to acheive, but `term__'
does genuinely represent a module qualifier.)
compiler/*.m:
Apply sed script above;
where appropriate, add `bool' to the list of imported modules.
Estimated hours taken: 3
Fix an omission in determinism analysis: make sure that a goal
with no output variables is considered to be in a single-solution context.
Also, implement pruning of multidet goals in det contexts.
(This fixes the long-standing problem with a
"Sorry, unimplemented: nondet goal in det context" error in code generation.)
compiler/det_analysis.m:
Make sure that a goal with no output variables is considered to
be in a single-solution context.
compiler/code_gen.pp:
Handle model_nondet goals in det contexts by wrapping them
inside a `generate_det_(pre_)commit' pair.
compiler/code_info.m:
Rename `generate_(pre_)commit' as `generate_semi_(pre_)commit',
and add a new pair of predicates `generate_det_(pre_)commit'.
Also fix restore_failure_cont so that it doesn't abort if
a multidet goal is called from within a det goal.
Estimated hours taken: 5
There was a problem where variables that die during forward
execution, and then become live again on backtracking were
not being handled correctly. There was some half-working code
to deal with the problem. It has now been fixed, and there
are some new test cases for the regression tests.
compiler/.cvsignore:
added *.ql since they become very irritating after a while...
compiler/inlining.m:
added a couple of comments
make a bit of the code more concise.
compiler/*.m:
changes to handle nondet-liveness correctly.
Estimated hours taken: _2___
Change names with badly placed double underscores (ie where the part of
a name before a double underscore is not the same as the module name.)
Reflect changes in the library interface.
compiler/*:
Use the newer, more correct form of the term and bool names.
Predicates "bool__" are now "std_util__bool" and labels of
the term ADT are now "term_" instead of "term__".
compiler/vn*.m:
change all names "vn__*" to a correct module prefix. All the
names remain qualified.
compiler/hlds.m:
s/\<is_builtin__/hlds__is_builtin_/g
s/\<dependency_info__/hlds__dependency_info_/g
compiler/unify_proc.m:
s/\<unify_proc_info__/unify_proc__info_/g
compiler/transform.m:
s/\<reschedule__conj/transform__reschedule_conj/g
excess:
A new pass to remove unnecessary assignment unifications.
mercury_compile:
Call the new excess assignment module.
options:
Add a new option, excess_assign, to control the new optimization.
Add another, num-real-regs, to specify how many of r1, r2 etc are
actually real registers. The default is now set to 5 for kryten;
later it should be supplied by the mc script, with a value determined
at configuration time.
tag_switch:
Use num-real-regs to figure out whether it is likely to be worthwhile
to eliminate the common subexpression of taking the primary tag of
a variable. Also fix an old performance bug: the test for when a
jump table is worthwhile was reversed.
value_number, vn_block:
Do value numbering on extended basic blocks, not basic blocks.
vn_debug:
Modify an information message.
labelopt:
Clean up an export an internal predicate for value numbering. Replace
bintree_set with set.
middle_rec:
Prepare for the generalization of middle recursion optimization
to include predicates with an if-then-else structure.
cse_detection:
Fix a bug: when hoisting a common desconstruction X = f(Yi), create
new variables for the Yi. This avoids problems with any of the Yis
appearing in other branches of the code.
goal_util:
Add a new predicate for use by cse_detection.
common:
Fix a bug: recompute instmap deltas, since they may be affected by the
optimization of common structures.
code_info:
Make an error message more explicit.
det_analysis:
Restrict import list to the needed modules.
*.m:
Import assoc_list.
compiler/*
Allow predicate and mode definitions, and predicate calls to have
module qualifiers. This allows a restricted form of predicate
name overloading.
compiler/llds.m, prog_io.m
In addition to above, these modules now write some labels in `*.c'
output files with module-name qualifiers. Predicate `main/2',
predicates of `mercury_builtin' and special predicates with names
like `__*__' are not qualified.
compiler/mercury_to_goedel.m
This module is probably a little more broken than before, as
module:qualifiers are ignored.
code_info:
Expose the predicate for producing a variable not into an arbitrary
location, but into a register.
tag_switch:
Produce the switched-on variable into a register, since we will
need it several times (to extract the primary tag, probably to
extract a secondary tag, and then -usually- to get some of its
fields).
jumpopt:
Added last call optimization for nondet predicates.
llds:
Added a new lval type to represent the succip slot of nondet
stack frames.
other files:
Changes required by the change to llds (there is a minor unrelated
change in vn_cost as well).
Tyson: please check my changes to code_info__get_shape_num and
garbage_out__write_liveval.
instructions, and the last argument from local labels. All these were
placeholders for info put in there by prof.m and used when emitting C
code.
The set of labels that serve as return points are now calculated in llds.m
just before each procedure has its C code generated. This set is passed to
output_instruction along with the label at the start of the procedure.
code_info.m:
Changed an XXX to a (more) meaningful comment, noting that
shapes__request_shape_number doesn't handle partial insts yet.
shapes.m:
Added more of the builtin types.
This set of changes includes most of the work necessary for
mode and determinism checking of higher-order predicates.
prog_io.m:
Change the syntax for lambda expressions: they need
to have a determinism declaration. Lambda
expressions must now look like this:
lambda([X::in, Y::out] is det, ...goal...).
^^^^^^
Note that both the modes and the determinism are mandatory,
not optional.
hlds.m:
Insert a determinism field in the lambda_goal structure.
hlds_out.m, inlining.m, make_hlds.m, modes.m, polymorphism.m, quantification.m,
switch_detection.m, typecheck.m:
Modified to use lambda_goal/4 rather than lambda_goal/3.
prog_io.m:
Add a new field to the `ground' inst, of type `maybe(pred_inst_info)'.
We use this to store the modes and determinism of higher-order
predicate terms.
code_info.m, inst_match.m, mercury_to_mercury.m, mode_util.m, modes.m,
polymorphism.m, shapes.m, undef_modes.m:
Modified to handle higher-order pred modes:
use ground/2 rather than ground/1.
(Note that modes.m still requires a bit more work on this.)
llds.m:
Add a new field to the call_closure/3 instruction to hold the
caller address for use with profiling, since the C macros
require a caller address.
dup_elim.m, frame_opt.m, garbage_out.m, live_map.m, middle_rec.m, opt_debug.m,
opt_util.m, value_number.m, vn_*.m:
Modified to use call_closure/4 rather than call_closure/3.
mercury_to_mercury.m:
Export mercury_output_det for use by hlds_out.m.
code_info.m:
When doing a commit, make the curfr, redoip and maxfr live
so that garbage collection can figure out what is going
on (live values saved on both det & nondet stacks => commit).
code_gen.pp:
Fix a comment about an unimplemented thing.
code_info.m, code_gen.pp:
For the special case of a negated simple test
(ie X \= Y) generate better code. This only works
for the global success or failure of a predicate.
The next version of this fix will work for ->;
as well.
-------------------------------------------------------
Implement unique modes. We do not handle local aliasing yet, so this
is still not very useful, except for io__state. Destructive update is
not yet implemented. Also note that this really only implements
"mostly unique" variables that may be non-unique on backtracking - we
don't check that you don't backtrack over I/O, for example.
prog_io.m, mode_util.m, modes.m, inst_match.m:
Major changes to Handle unique modes.
mercury_to_mercury.m, polymorphism.m, prog_out.m, undef_modes.m:
Use `ground(Uniqueness)' rather than just `ground'.
compiler/*.m:
Fix compile errors now that unique modes are enforced: add a
few calls to copy/2, and comment out lots of unique mode
declarations that caused problems.
typecheck.m, mode_info.m:
Hack around the use of unique modes, which doesn't work
because we don't allow local aliasing yet: make the insts
`uniq_type_info' and `uniq_mode_info' not unique at all,
and add a call to copy/2 when extracting the io_state from
type_info or mode_info.
-------------------------------------------------------
Plus a couple of unrelated changes:
hlds.m:
Change the modes for the special predicates from `ground -> ground'
to `in', so that any error messages that show those modes
come out looking nicer.
Add a new shared_inst_table for shared versions of user-defined
insts.
mercury_to_goedel.m:
Use string__is_alnum_or_underscore.
mercury_compile.pp llds.m:
fix occurences of A.B (use [A|B]) which were
causing problems trying to build a sicstus
compiler.
[the rest].m:
Fix the compiler so that calculator.m works.
This involved introducing an extra field into
the goal_info to keep track of variables that
become nondet-live.
unifications. See the comments at the top of unify_proc.m for
details of how it's done.
hlds.m:
Add new export statuses `pseudo_imported' and `pseudo_exported'
to handle unification predicates, which can now have complicated
modes.
code_gen.pp, code_info.m, common.m, constraint.m, cse_detection.m,
follow_code.m, follow_vars.m, hlds_out.m, inlining.m, live_vars,
make_hlds.m, mercury_compile.pp, modes.m, store_alloc.m,
switch_detection.m:
Handle pseudo_imported predicates.
modes.m, constraint.m:
Change modecheck to return an updated module_info, since
modechecking may insert new entries into the unify_requests
queue in the module_info. Make sure that modechecking
never inserts requests into the unify_requests queue
for code that has mode errors (or needs rescheduling).
call_gen.m, polymorphism.m:
Move duplicated code into unify_proc.m.
clause_to_proc.m:
Add new predicate clauses_to_proc for use by unify_proc.m.
unify_proc.m:
Implement complicated unifications with complicated modes.
options.m:
Added the profiling option, which generates a file <module>.prof, which
contains the static call graph.
dependency_graph.m:
Predicate to output the static call graph in a form useful for the
profiler.
prof.m:
Scan's through the LLDS marking all labels that are continuation
labels. eg All label's cont_type field should be unknown now.
llds.m, code_info.m:
Minor changes so that the above stuff works.
code_info.m:
Change some comments in the generated code slightly.
ite_gen.m:
grab the instmap before generating the condition not
after in all three kinds of ite.
unify_gen.m:
grab and slap the code_info structure across the call
to generate_failure. This pair of calls should probably
be migrated into generate_failure. I'll check this out
soon (tomorrow).
call_gen.m code_gen.pp code_info.m garbage_out.m hlds.m llds.m
mercury_compile.pp shapes.m:
Output .garb files (with --gc accurate). This option overrides
information gleaned from the grades about GC.
Remove some of the magic numbers that were being used for
shape numbers.
*.m:
Changed the way the extra field in the label type is defined. Now
all labels are initially assumed to be 'unknown' and a seperate
profiling pass (to be implemented) will determine whether the label can
be accessed externally.
code*.m & *gen.m:
Implement an improved method of handling negated contexts.
The new method avoids saving things onto the stack before
an if-then-else or negation if it can.
Also, fix the implementation of nondet if-then-else so that
it does the soft cut properly.
switch_detection:
Detect partial switches, i.e. disjunctions in which not all
disjuncts form part of the switch. We give preference to full
switches, and failing that, to partial switches with the most arms.
peephole, opt_util:
Fixed the code for the introduction of succeed_discard.
code_gen:
Fixed spelling error in error message.
code_info:
Made error message somewhat more informative.
cse_detection:
Removed debugging code; we now always repeat cse detection after
finding some cses.
det_analysis:
Added some comments.
value_number, vn_debug, vn_flush:
Changes to make debugging easier.
code_info.m:
Bug fix: change generate_pre_commit and generate_commit so that
the values which need to be saved and restored are always pushed
onto the det stack, even in nondet predicates. The reason is
that if the committed goal fails, curfr is not valid, so we
can't restore the fields from the nondet stack.
(This way may well be more efficient anyway.)
disj_gen.m, ite_gen.m:
Handle the case when the current failure continuation is unknown
on entry to the disjunction or nondet if-then-else by creating
a new frame on the nondet stack. (Originally we just aborted
in this case; recently we "fixed" this, but it turned out that
the fix was not correct, for the same reason as the above-mentioned
bug in pre_commit/commit.
llds.m:
Add succfr/1 and prevfr/1 to the rval type in llds.m,
since they were needed by the above bug fixes.
(This caused dozens of changes elsewhere to handle the
new types.)
Also fix a trivial bug that I recently introduced which
prevented --mod-comments from working.
live_vars.m:
Fix bug in allocation of stack slots for nondet code.
(This is the one that caused the bug that ksiew and I found
when writing a calculator program.)
peephole.m:
Disable the succeed_discard() optimization, since it
causes incorrect code to be generated. It was replacing
modframe(do_fail) ... succeed() with
modframe(do_fail) ... succeed_discard() even when there were
instructions such as mkframe() in between.
modes.m, hlds.m:
When modechecking switches, record the binding of the switch variable
as we enter each case, so that we get the determinism analysis
right.
mercury_compile.pp:
Make sure that we set the exit status to be non-zero if we
find any errors.
typecheck.m, modes.m, undef_types.m, undef_modes.m:
Don't invoke type-checking if there are undefined types.
Don't invoke mode-checking if there are undefined modes.
This avoids the problem of the compiler aborting with an
internal error if there are undefined types/modes.
code_info.m:
Undo my recent changes to generate_pre_commit/generate_commit,
since they made the compiler buggy. I'm still not 100% sure why,
but I think that the optimization I was trying to make (to reduce
the number of instructions for a pre-commit/commit from 6 to 4) is
in fact not possible, since it doesn't preserve `curcp' (???).
Apologies to everyone for introducing the bug, and for
being so suspicious of everyone else's changes but not
suspicious enough of my own.
I can now build an almost-working stage2 compiler.
Unfortunately the stage2 compiler now fails when compiling
builtin_unify_float in mercury_builtin.m.
options.m call_gen.m code_gen.pp code_info.m code_util.m llds.m unify_gen.m:
A bunch of changes to implement the procs-per-c-function option.
This default is now `--procs-per-c-function 1', for reasonable
efficiency of compilation, but for efficiency of generated code
(e.g. when compiling benchmarks!)
use `--procs-per-c-function 0' (0 really means infinity).
I haven't tested this in any mode except asm_fast, so it's possible
that this change might break the other modes. If that turns out
to be the case, let me know. The symptom will be an error from
the C compiler or linker.
prog_io, hlds: Added the functor "multidet" to the type determinism.
Added types and predicates to relate determinism to its
two components, can_fail and soln_count.
Removed the functor "unspecified" from the type determinism,
substituting maybe(determinism) for determinism in proc_info.
Replaced the type category with the type code_model,
and added predicates to compute it from determinism.
det_analysis: Redone the analyses to work with determinism, not category
(or code_model). This should enable programmers to write
their own erroneous (and failure) predicates.
other files: Use the new and renamed types and access predicates.
frameopt:
fix the problem with destroying stack frames and creating
them again later, accessing detstackvars that were earlier
nominally destroyed.
vn_livemap:
renamed it to livemap since frameopt now uses it also.
value_number, vn_*:
Fixed some bugs. Reorganized the handling of blocks: they are now
put in at the last minute before llds writes out the code.
Made a start towards exploiting info about cheaper copies of
values.
optimize, options:
Made value_numbering an iterated optimization. Added a new
option to control how many times it is iterated together
with other the jumpopt, peephole and labelopt.
llds, call_gen, code_gen, code_info, middle_rec, opt_debug:
changed type of the argument of livevals to plain set.
Warning: in more than a week I haven't been able to fully test this change,
dur to kryten's flakiness and bugs upstream of the optimizer.
code_info.m:
Fix serious bug in code generation introduced by my last change
to code_info.m - in generate_commit, it was saving the redoip
of maxfr but restoring it into curfr.