Estimated hours taken: 12
Branches: main
Improve the error checking for mutable declarations.
Fix a bug with solver types and sub-modules reported by Peter Hawkins.
Workaround a bug with mutable declarations and sub-modules. Currently,
the compiler aborts if there is a mutable declaration in the parent module.
With this change mutable declarations will not be visible in child modules.
XXX This is not correct since they should be visible, but this can be fixed
as a separate change.
compiler/prog_data.m:
Extend the item_origin type with information about what
source-to-source transformations are responsible for compiler
introduced items. We need this information for error checking mutable
declarations. It also provides an additional layer of sanity checking
in the parse tree.
Add origin fields to the clause and initialise items, since they can
both now be introduced by source-to-source transformations.
compiler/prog_io.m:
compiler/prog_io_dcg.m:
compiler/prog_io_typeclass.m:
Conform to the above change.
compiler/make_hlds_passes.m:
Don't issue spurious errors about initialise declarations that were
introduced by the transformation for mutable declarations. Abort if
invalid initialise declarations were introduced by other compiler
passes since this indicates a bug in the compiler.
Check if mutable declarations occur in the interface of a module and
emit an error if they do.
Don't generate initialise items and foreign code from a mutable
declaration unless we are in the defining module for the mutable
declaration.
Don't generate foreign_procs for solver types *unless* we are in the
defining module. Doing otherwise breaks the compiler when using
solver types and sub-modules.
Fix the formatting of an error message concerning initialise decls.
s/foreign_code/foreign_proc/ in a spot.
compiler/add_solver.m:
compiler/mercury_to_mercury.m:
compiler/recompilation.check.m:
compiler/recompilation.version.m:
compiler/add_class.m:
compiler/add_pragma.m:
compiler/state_var.m:
Conform to the above changes.
compiler/modules.m:
Handle mutable declarations in private interfaces.
Clean up some code related to foreign_import_module decls.
Conform to the changes in prog_data.m.
compiler/prog_util.m:
Shift the functions for mutable access predicates and variables to
this module. The code that generates interface files also needs to be
able to access them.
compiler/module_qual.m:
Conform to the above changes.
Fix a bug where the context in the mq_info structure was not being
updated. This caused error messages for mutable declarations that
contain undefined types or insts to have the wrong context.
compiler/hlds_data.m:
Fix a typo.
vim/syntax/mercury.vim:
Highlight `mutable' and `untrailed' appropriately.
tests/hard_coded/sub-modules/Mmakefile:
tests/hard_coded/sub-modules/ts.m:
tests/hard_coded/sub-modules/ts.tsub.m:
tests/hard_coded/sub-modules/ts.exp:
Add Peter Hawkin's test case for the bug with solver
types and sub-modules.
tests/invalid/Mmakefile:
tests/invalid/bad_mutable.m:
tests/invalid/bad_mutable.err_exp:
Add a test for the various sorts of errors that can occur with mutable
declarations.
Estimated hours taken: 3
Branches: main
Auto-generate the code for performing higher order calls and method calls.
This way, we can vary the number of explicit arguments we specialize for
independently of the number of hidden arguments we specialize for.
(Previously, we did not specialize on the number of hidden arguments at all.)
tools/make_spec_ho_call:
A new script to auto-generate the code for performing higher order
calls.
tools/make_spec_method_call:
A new script to auto-generate the code for performing method calls.
runtime/mercury_ho_call.c:
Replace the old handwritten code for performing higher order and
method calls with #includes of the auto-generated files.
runtime/Mmakefile:
Make the object files of mercury_ho_call.c depend on the auto-generated
files, and through them, on the scripts.
compiler/options.m:
Conform to the new parameters in the scripts.
Estimated hours taken: 2
Branches: main, release
Fix a bug in the polymorphism transformation.
compiler/polymorphism.m:
Make sure extra arguments are added in the proper order when
processing calls to polymorphic procedures.
Clarify the comments at the top of the file regarding the order
of extra arguments.
Rename some variables to make them more consistent.
tests/hard_coded/Mmakefile:
tests/hard_coded/type_info_order.exp:
tests/hard_coded/type_info_order.m:
A test case which exposes the bug.
Estimated hours taken: 3
Branches: main
Fix a bug where an inst any list containing a solver type was being
passed without complaint to list.member, which clearly expected it
to have inst ground.
compiler/inst_match.m:
Fix a bug where under certain situations inst_is_ground_1/5 would
erroneously add any(_) to the set of insts it would treat as
ground.
tests/invalid/Mmakefile:
tests/invalid/any_passed_as_ground.err_exp:
tests/invalid/any_passed_as_ground.m:
tests/invalid/any_to_ground_in_ite_cond.err_exp:
tests/invalid/any_to_ground_in_ite_cond.m:
Add test cases covering some any/ground situations.
Estimated hours taken: 1
Branches: main
By optimizing away frames in some frequently used predicates such as
tree234__search and list__member, this diff speeds up the compiler by 0.5%.
compiler/frameopt.m:
Previously, if the procedure had any tail calls to itself, we always
kept the procedure's stack frame, preferring to optimize away the stack
frame teardown just before the tail call and the stack frame
allocation just after it. However, there is no point in doing this
transformation if none of the procedure's blocks actually needs
a stack frame, so after this diff, in such situations we will now
optimize the frame away.
Ideally, if a procedure (such as the deriv benchmark) has
(1) some paths through it that don't need a stack frame,
AND
(2) some paths through it that do need a stack frame and jump back to
the start of the procedure, making it profitable to reuse the stack
frame,
we should do something (such as duplicating the procedure body)
to make both possible. However, that is future work.
Estimated hours taken: 10
Branches: main and 0.12
Various changes to make Mercury more compatible with Windows.
configure.in:
Turn off symbolic links when compiling in cygwin.
Previously the configure script checked for certain compiler
names or whether the --mno-cygwin option was passed to gcc,
however this check is not good enough since the user may specify
the mingw version of gcc using the --with-cc option.
compiler/mercury_compile.m:
mdbcomp/trace_counts.m:
Use rstrip to remove trailing newlines, since on Windows there
may be more than one character at the end of each line
(a newline and a carriage return or line feed
- I can't remember which).
compiler/passes_aux.m:
Remove invoke_shell_command since it is not used anywhere and
according to the comment won't work on Windows.
If on windows do not use `2>&1' to redirect standard error since this
doesn't work on windows 98 and 95 (and possibly other versions too).
runtime/mercury_conf_param.h:
Use #ifdef instead of just #if when checking for _WIN32.
Previously this caused Mercury to use `/' as the directory
separator on Windows when it should have used `\'.
Estimated hours taken: 16
Branches: main
Generate better code for base relations such as the ones in the transitive
closure benchmarkings in the paper on minimal model tabling. These improvements
yield speedups ranging from 5 to 25% on those benchmarks.
compiler/use_local_vars.m:
Make this optimization operate on extended basic blocks instead of
plain basic blocks. The greater length of extended basic blocks
allows the local variables to have maximum scope possible. The price
is that the test for whether assignment to a given lvalue can be
avoided or not is now dependent on which of the constituent basic
blocks of extended basic block contains the assignment, and thus the
test has to be evaluate once for each assignment we try to optimize
instead of once per block.
Don't allocate temporary variables if the optimization they are
intended for turns out not to be allowed. This change avoids having
declarations for unused temporary variables in the resulting C code.
If --auto-comments is set, insert use_local_vars.m's main data
structure, the livemap, into the generated LLDS code as a comment.
compiler/peephole.m:
Look for the pattern
mkframe(Size, Redoip)
<straight line instructions that don't use stack slots>
succeed
and optimize away the mkframe. This pattern always arises for
procedures that are actually semidet but are declared nondet (such
as the base relations in the tabling benchmarks), and may also arise
for semidet branches of nondet procedures.
compiler/llds.m:
Allow an existing peephole pattern to work better. The pattern is
mkframe(Seize, do_fail)
<straight line instructions>
redoip(curfr) = Redoip
Previously, if some compiler-generated C code was among the straight
line instructions, the pattern couldn't be applied, since peephole.m
couldn't know whether it branched away through the redoip slot of the
frame. This diff adds an extra slot to the relevant pragma_c component
that tells peephole.m (actually, the predicate in opt_util.m that
peephole relies on) whether this is the case.
compiler/basic_block.m:
Provide functionality for merging basic blocks into extended basic
blocks.
compiler/dupelim.m:
Conform to the change in basic_block.m's interface.
Convert to four-space indentation, and fix departures from our style
guidelines.
compiler/opt_util.m:
Provide extra information now needed by use_local_vars.
Convert to four-space indentation, and fix departures from our style
guidelines.
compiler/opt_debug.m:
Show the user friendly versions of label names when dumping livemaps
and instructions.
Shorten the dumped descriptions of registers and stack slots.
Dump instructions inside blocks.
compiler/frameopt.m:
Conform to the changes in opt_util and opt_debug's interfaces.
compiler/optimize.m:
Use the facilities of opt_debug instead of llds_out when dumping the
LLDS after each optimization, since these are now more compact and
thus reader friendly.
Print unmangled names when writing progress messages.
Put the dump files we generate with --opt-debug in a separate
subdirectory, since when compiling e.g. tree234.m, the process
can generate more than a thousand files. Give the dump files
minimally mangled names.
compiler/code_gen.m:
compiler/pragma_c_gen.m:
Convert to four-space indentation, and fix departures from our style
guidelines.
Conform to the change in llds.m.
compiler/code_info.m:
compiler/exprn_aux.m:
compiler/ite_gen.m:
compiler/jumpopt.m:
compiler/livemap.m:
compiler/llds_out.m:
compiler/middle_rec.m:
compiler/trace.m:
Conform to the change in llds.m.
Estimated hours taken: 3
Branches: main
More work to ensure the type_info argument is not referred to anywhere. This
also fixes a problem with the handling of poly_infos which are created for
inititialisation predicates.
compiler/modes.m:
Construct the poly_info using the caller pred_info and proc_info.
It is the caller that is updated with new program and type variables,
not the callee.
Pass the callee pred_info and proc_info as separate arguments to
polymorphism__process_new_call, but don't return new versions
since they should not be updated.
Update the module_info with the new pred_info and proc_info for the
caller. Update the mode_info with the new info for the caller.
compiler/polymorphism.m:
Delete the predicate create_poly_info_for_new_call. It is not used
any more, and could only be used to build an inconsistent poly_info
anyway.
Add two arguments to process_new_call, for the callee pred_info and
proc_info. Calculate the appropriate type substitution by renaming
apart and then unifying the callee argument types with the call
argument types. Calculate the type_infos to pass by looking up the
callee rtti_varmaps to determine which callee type variables the
type_infos are for, and then applying the above type substitution.
(We also check that none of the extra arguments are for
typeclass_infos, which are not supported at the moment.)
Estimated hours taken: 2
Branches: main
Improve error reporting for initialise declarations.
Make clauses in module interfaces an error rather than a warning.
Do the same for pragmas that should not occur in a module interface.
compiler/make_hlds_error.m:
Add two new predicates that handle error reporting for items that
should not occur in module interfaces.
compiler/make_hlds_warn.m:
Remove the predicate for warning about items that should not occur in
module interfaces. It is now unused.
compiler/make_hlds_passes.m:
Do not emit an error for export declarations that have ended up in the
interface of a module as a result of the source-to-source
transformation used to implement initialise declarations.
Report initialise declarations that refer to predicates that do not
exist directly rather than reporting that the introduced export
pragmas are incorrect. The latter is confusing since the pragmas
do not appear in the source code
Delete the XXX comment about the above. Also fix the description of
the transformation used to implement initialise declarations.
Make clauses in a module interface an error rather than a warning.
When reporting this also print out the name and arity of the predicate
or function to which the clauses belong.
Make it an error for pragmas that are not allowed in a module
interface to occur in a module interface.
compiler/prog_data.m:
Add a type that allows us to distinguish between items that originated
with user code and those introduced by source-to-source
transformations on the parse tree.
compiler/recompilation.version.m:
compiler/recompilation.check.m:
compiler/prog_io_pragam.m:
compiler/prog_io.m:
compiler/module_qual.m:
compiler/modules.m:
compiler/add_pragma.m:
compiler/add_solver.m:
compiler/equiv_type.m:
compiler/intermod.m:
Conform to the above changes.
tests/invalid/Mmakefile:
tests/invalid/not_in_interface.m:
tests/invalid/not_in_interface.err_exp.m:
Test cases for the above errors.
tests/invalid/bad_initialise_decl.m:
tests/invalid/bad_initialise_decl.err_exp:
Update this test case.
Estimated hours taken: 24
Branches: main
Add `:- mutable' directives to the language, providing modules with private
mutable variables. A directives
:- mutable(x, int, 0, ground, [thread_safe]).
leads to the compiler generating the following:
:- semipure pred get_x(int::out(ground)) is det.
:- impure pred set_x(int::in(ground)) is det.
:- pred initialise_mutable_x(io::di, io::uo) is det.
:- initialise initialise_mutable_x/2.
initialise_mutable_x(!IO) :-
promise_pure(
impure set_x(0)
).
:- pragma foreign_decl("C", "MR_Word mutable_variable_x;").
:- pragma foreign_proc("C", get_x(X::out(ground)),
[thread_safe, promise_semipure],
"MR_trail_current_value(&mutable_variable_x); X = mutable_variable_x;").
:- pragma foreign_proc("C", set_x(X::in(ground)),
[thread_safe],
"mutable_variable_x = X;").
Possible attributes for a mutable variable are `thread_safe' and
`untrailed'.
NEWS:
Mention the new language feature.
compiler/make_hlds_passes.m:
Handle the new mutable/5 item.
Pass 1 expands a mutable directives into the pred
declaration items.
Pass 2 expands a mutable directives into the initialise
and foreign_decl declaration items.
Pass 3 expands a mutable directives into the initialise
declaration and the clauses for the preds.
compiler/mercury_to_mercury.m:
compiler/mercury_qual.m:
compiler/modules.m:
compiler/recompilation.check.m:
compiler/recompilation.version.m:
Cover the new mutable/5 item.
compiler/prog_data.m:
Add a new mutable/5 program item.
compiler/prog_io.m:
Parse `:- mutable' directives.
compiler/prog_io_typeclass.m:
compiler/prog_io_util.m:
Move list_term_to_term_list from prog_io_typeclass to prog_io_util
(it's a generally useful predicate).
doc/reference_manual.texi:
Document the new `:- mutable' directive.
tests/hard_coded/Mmakefile:
tests/hard_coded/mutable_decl.m:
tests/hard_coded/mutable_decl.exp:
Added a test case that only runs in trailing grades.
Estimated hours taken: 3
Branches: main
Remove dependencies on the argument of type_info/1.
compiler/equiv_type_hlds.m:
Look up the rtti_varmaps data instead of using the type_info
argument.
compiler/simplify.m:
Ensure that updates to the rtti_varmaps performed by the call to
polymorphism.m are reflected in the proc_info and the simplify_info.
Estimated hours taken: 2
Branches: main
compiler/switch_detect.m:
Allow the detection of switches in which some disjuncts start not
with a unification, but with disjunction of unifications. In such
cases, the rest of the disjunct is duplicated for all the switch arms
we can create.
compiler/hard_coded/switch_detect.{m,inp,exp}:
New test case to test the new functionality.
compiler/hard_coded/Mmakefile:
Enable the new test case.
Estimated hours taken: 1.5
Branches: main
Implement initialise declarations for the high-level C backend.
compiler/mlds.m:
Add a slot to the MLDS to hold the name of module intialisation
predicates.
XXX We should use a higher level representation of the names
here in case we need to treat them differently in the other
target languages.
compiler/mlds_to_c.m:
Output the necessary INIT and REQUIRED_INIT comments.
compiler/mercury_compile.m:
compiler/ml_code_gen.m:
compiler/ml_elim_nested.m:
compiler/ml_optimize.m:
compiler/ml_tailcall.m:
Handle the extra field in the MLDS.
compiler/mlds_to_il.m:
compiler/mlds_to_ilasm.m:
compiler/mlds_to_java.m:
compiler/mlds_to_managed.m:
compiler/mlds_to_gcc.m:
Handle the extra field in the MLDS. We don't
yet support initialise declarations on these backends.
Estimated hours taken: 2
Branches: main
This diff cleans up two modules. It has no algorithmic changes.
compiler/globals.m:
Convert to four-space indentation.
Add a missing predicate variant for use in handle_options.m.
compiler/handle_options.m:
Convert to four-space indentation. Convert to state variable notation
from DCGs.
Instead of continually getting the globals from the I/O state and
stuffing back an updated version, thread the globals themselves
through the relevant predicates.
Estimated hours taken: 1.5
Branches: main
Fix a problem with the new initialise declarations and sub-modules.
compiler/modules.m:
Don't write `:- initialise' declarations to private interfaces.
The compiler cannot read them back in and in any case child
modules don't need to know about them.
tests/hard_coded/sub-modules/Mmakefile:
tests/hard_coded/sub-modules/initialise_parent.m:
tests/hard_coded/sub-modules/initialise_child.m:
tests/hard_coded/sub-modules/initialise_parent.exp:
tests/hard_coded/sub-modules/initialise_parent.exp2:
Test case for the above. (There are two expected outputs
because the ordering of calls to module initialisers between
a parent and its children is arbitrary.)
vim/syntax/mercury.vim:
Highlight initialise declarations appropriately.
Estimated hours taken: 0.5
Branches main, 0.12
Do not output trigraphs in string literals in generated C code.
compiler/c_util.m:
Break strings containing trigraphs into multiple chunks, so the
C compiler doesn't convert the trigraphs into other characters.
For example "??-" is converted to "?" "?-" in the generated C code.
tests/hard_coded/Mmakefile:
tests/hard_coded/trigraphs.exp:
tests/hard_coded/trigraphs.m:
Add a regression test. Previously this test generated incorrect
output.
Estimated hours taken: 10
Branches: main
This diff cleans up a bunch of modules. It has no algorithmic changes
other than in the formatting of error messages.
compiler/error_util.m:
Delete the obsolete predicate append_punctuation, since the suffix
format component can now do more, and do it more easily.
compiler/goal_util.m:
compiler/hlds_goal.m:
compiler/hlds_llds.m:
compiler/instmap.m:
compiler/const_prop.m:
Change the argument order of some the predicates exported by these
modules to make them easier to use with state variable syntax.
compiler/*.m:
Convert a bunch of these modules to four space indentation, and fix
departures from our coding style.
Conform to the changed argument order above.
Use suffixes instead of append_punctuation.
library/string.m:
Add string.foldl2.
tests/invalid/circ_*.err_exp:
tests/warnings/unused_args_*.exp:
Expect the updated error messages, which format sym_names consistently
the same way as other messages.
Estimated hours taken: 6
Branches: main
Optimize higher order calls by providing variants of the relevant code that
are specialized to a given number of explicitly given arguments.
runtime/mercury_ho_call.[ch]:
Define variants of do_call_closure and do_call_class_method
specialized to 0, 1, 2 or 3 explicit input arguments. Apart from
not needing to be passed the number of explicit input arguments
in a register, these avoid some runtime tests and unroll loops.
Harmonize the variable names used in the do_call_closure and
do_call_class_method variants. Since they are near-copies of each
other, factor out their documentation. (Factoring out the code itself
would be possible, but would not make maintenance easier and would make
the code harder to read.)
Provide a mechanism to gather statistics about the numbers of hidden
and explicit arguments if the macro MR_DO_CALL_STATS is set.
compiler/options.m:
Add options that specify how many of these variants exist. These
provide the necessary synchronization between the runtime and the
compiler. They are not meant to be set from the command line, even by
implementors.
runtime/mercury_conf_params.h:
Document MR_DO_CALL_STATS.
runtime/mercury_wrapper.c:
If MR_DO_CALL_STATS is set, print the gathered statistics when
execution ends.
runtime/mecury_mm_own_stack.c:
Fix a typo that prevented the stage2 library from linking in jump.gc
grade.
compiler/llds.m:
Provide a way to represent the labels of the new specialized variants.
compiler/llds__out.m:
Output the labels of the new specialized variants if required.
Convert to four-space indentation.
compiler/call_gen.m:
Call the specialized variants of do_call_closure or
do_call_class_method if they are applicable.
code_info/follow_vars.m:
code_info/interval.m:
code_info/tupling.m:
Conform to the change in call_gen.m.
code_info/dupproc.m:
code_info/exprn_aux.m:
code_info/livemap.m:
code_info/opt_util.m:
Conform to the change in llds.m.
compiler/code_info.m:
Minor style cleanups.
tools/bootcheck:
Enable the collection of statistics from the compilation of stage 3
and the test cases, for use when the stage 2 is built with
MR_DO_CALL_STATS enabled.
tools/ho_call_stats:
A new script to analyze the statistics collected.
tools/makebatch:
Add a new option --save-stage2-on-no-compiler, which is a variant of
the existing option --save-stage2-on-error.
Estimated hours taken: 0.1
Branches: main
compiler/add_special_pred.m:
compiler/post_term_analysis.m:
compiler/special_pred.m:
compiler/term_constr_initial.m:
compiler/trace_params.m:
compiler/unify_proc.m:
compiler/termination.m:
mdbcomp/prim_data.m:
Workaround syntax errors that are caused by the addition
of `:- initialise' declarations. In the long run we
should just change the special_pred_id type.
Estimated hours taken: 0.1
Branches: main
compiler/add_special_pred.m:
compiler/post_term_analysis.m:
compiler/special_pred.m:
compiler/term_constr_initial.m:
compiler/trace_params.m:
compiler/unify_proc.m:
mdbcomp/prim_data.m:
Workaround syntax errors that are caused by the addition
of `:- initialise' declarations. In the long run we
should just change the special_pred_id type.
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).
Estimated hours taken: 6
Branches: main
Don't just detect when successive unifications unify the same variable with
incompatible function symbols: also issue a warning.
compiler/ml_code_gen.m:
compiler/stratify.m:
compiler/table_gen.m:
mdbcomp/trace_counts.m:
Fix pieces of code that get the new warning.
compiler/modecheck_unify.m:
When detecting such unifications, add warnings for them, except if
the initial inst of the current restricts the set of allowed bindings
of the input arguments. If the initial inst of X is bound(f), then
an otherwise correct unification Y = g may fail if Y has been computed
from X. (We don't whether it has, so we have to be conservative.)
There are examples of such code in the library, e.g. functor in
deconstruct.m.
Factor out some common code.
compiler/mode_errors.m:
Add the infrastructure needed for printing warnings, and the two forms
of this warning in particular.
compiler/mode_info.m:
Extend the mode_info structure to make room for warnings, and for the
initial inst of the procedure arguments.
Switch to four-space indentation.
compiler/inst_util.m:
Add a predicate that tests whether an inst may restrict the set of
possible cons_ids a variable may be bound to.
Change the argument order of some predicates to allow them to be
used in higher order code. We don't need to make the switched-on
argument the first argument anymore.
Switch to four-space indentation.
compiler/hlds_goal.m:
Change the argument order of some predicates to allow the use of state
variables.
compiler/higher_order.m:
compiler/instmap.m:
compiler/mode_constraints.m:
compiler/mode_debug.m:
compiler/mode_ordering.m:
compiler/modecheck_call.m:
compiler/trace.m:
Conform to the changed argument orders described above.
Switch to four-space indentation.
compiler/common.m:
compiler/inst_match.m:
compiler/hlds_pred.m:
compiler/lambda.m:
compiler/magic.m:
compiler/magic_util.m:
compiler/modes.m:
compiler/pd_util.m:
compiler/post_typecheck.m:
compiler/unique_modes.m:
Conform to the changed argument orders described above.
tests/invalid/occurs.err_exp:
Expect the extra warning.
tests/warnings/Mmakefile:
Enable the unify_f_g test case I accidentally committed earlier.
tests/warnings/unify_f_g.{m,err_exp}:
Finalize that test case.
tests/warnings/simple_code.err_exp:
Expect the extra warning.
Estimated hours taken: 20
Branches: main
Significantly improve the capabilities of the LLDS optimization that tries
to delay the creation of the stack frame, in the hope that on some computation
paths the frame won't need to be created at all. Previously, the delayed
setup of the stack frame could take place only when a block without a stack
frame fell through to a block that needed a stack frame. If block B1 jumped
to another block B2 that needed a frame, this was taken as meaning that B1
also had to have a frame. This was a problem, because if B1 ends with a
computed goto, some of whose targets need stack frames and some do not,
this limitation effectively gave all of them a stack frame, whether they
wanted it or not, and thus required them to execute the stack frame teardown
code.
This diff removes the limitation, optimization allows B1 in this case to not
have a stack frame. Instead of jumping to B2, B1 will not jump to a label B3
it inserts immediately before B2, the code at B3 setting up the stack frame
and falling through to B2. (We also insert code to jump around B3 if the
code immediately preceding it could fall into it accidentally.)
The new code in frameopt is conceptually cleaner than it was before, because
we now handle transitions from blocks that don't have a stack stack to blocks
that do in a much more uniform manner.
Most of the changes to other modules are to make the change to frameopt.m
easier to debug.
The motivation for the change was that we were beaten by YAP (Yet Another
Prolog) on the deriv benchmark due to the limitation of frameopt. I haven't
measured against YAP yet, but the runtime for 1.5 million iterations has been
reduced from about 20 seconds to about 13.
Since the compiler doesn't have any predicates that are both frequently used
and can benefit from the removal of that old limitation (which is why the
limitation wasn't really noticed before), there is no measurable effect
on the speed of the compiler itself.
compiler/frameopt.m:
Effectively rewrite the optimization that delays stack frame creation
along the lines above. The code for the optimization that keeps the
stack frame for recursive calls if possible is unaffected.
If the new option --frameopt-comments is specified, insert into the
generated LLDS code a nicely formatted description of the main
frameopt.m data structures. These are much easier to read that the
term browser in the debugger.
compiler/options.m:
Add the new developer-only option --frameopt-comments.
compiler/llds_out.m:
Change the way we output comments to make the coments generated by
frameopt.m easier to read. (We output comments only if --auto-comments
is given, which it usually isn't.)
compiler/opt_debug.m:
Provide the functionality of printing local labels in an easier-to-read
form that doesn't repeat the (possibly long) procedure name. Local
labels can now be printed as e.g. local_15.
Rewrite the module to use functions instead of predicates for appending
strings, since this makes the code shorter, easier to use and to read.
The original code was written before Mercury had functions.
compiler/switch_util.m:
When gathering information about switches, return the cons_id with each
goal.
Switch to four-space indentation.
compiler/tag_switch.m:
When generating code for switches, insert a comment at the start of
each case saying what cons_id it is for, using the new information from
switch_util. This is to make the generated code easier to understand.
Switch to four-space indentation.
compiler/ml_tag_switch.m:
Conform to the change in switch_util.
compiler/optimize.m:
Conform to the slightly modified interface of frameopt.m.
Switch to four-space indentation.
compiler/peephole.m:
Switch to four-space indentation, and fix some coding style issues.
compiler/basic_block.m:
When dividing a procedure body into basic blocks, remember for each
block whether it could be fallen into. This modification is not
strictly required for this change, since frameopt has its own
(specialized) code for creating basic blocks, but it could be useful
in the future.
compiler/dupelim.m:
compiler/use_local_vars.m:
Conform to the change in basic_block.m.
Estimated hours taken: 1
Branches: main
Clean up higher_order.m and bring it into line with our current
coding standards.
compiler/higher_order.m:
Use 4 space indentation throughout this module.
Call unexpected/2 instead of error/1.
Reposition and reformat comments acoording to our
current coding standard.
Use a single module qualifier throughout this module.
Various other minor cleanups.
Estimated hours taken: 8
Branches: main
Move the rest of mode_errors.m to use error_util.
compiler/mode_errors.m:
The parts of this module that generate error messages (as opposed to
progress messages) now all return a description of the error to a
central place for printing by error_util.m. This should make it
significantly easier to add new error messages.
compiler/error_util.m:
Add the new capability to support mode_errors.m: that of describing
in one data structure a sequence of calls to write_error_pieces.
compiler/hlds_out.m:
Given a bunch of existing predicates that print various things,
provide versions that convert those things to strings, for use
in mode_errors.m.
Write_unify_context had two versions for printing and only one version
for conversion to pieces; add the second version for conversion to
pieces. Change the order of arguments of the five-argument version
of write_unify_context to allow the use of state variables.
compiler/mercury_to_mercury.m:
compiler/prog_out.m:
Given a bunch of existing predicates that print various things,
provide versions that convert those things to strings, for use
in hlds_out.m and mode_errors.m.
compiler/det_report.m:
Conform to the changed argument order of write_unify_context.
library/term_io.m:
Fix an old bug: the code of add_escaped_char wasn't actually doing
any escaping. hlds_out.m now relies on it doing so.
tests/hard_coded/xmlable_test.m:
Due to the bugfix in term_io.m, string__string now protects &s with
backslashes; expect this.
tests/invalid/*.err_exp:
Expect mode error messages in the new, better format.
Estimated hours taken: 0.2
Branches: main
compiler/intermod.m:
Convert this module to four space indentation, and fix some departures
from our coding standard.
Estimated hours taken: 1
Branches: main
compiler/det_analysis.m:
Convert this module to four-space indentation to reduce the number
of bad line breaks. Use consistent naming of the arguments of the
main predicate of the module, and delete the arguments that turn out
to be unused. Make the order of some arguments more logical. Give more
expressive names to some variables.
compiler/pd_util.m
compiler/simplify.m
Conform to the new argument order.
Estimated hours taken: 4
Branches: main
compiler/mode_errors.m:
Convert this module to four-space indentation to reduce the number
of bad line breaks. Fix some departures from our coding standards.
Convert most of this module to use error_util.m to format error
messages instead just io__write_strings. (Converting the rest
will require some changes in hlds_out.m.)
compiler/error_util.m:
Provide the ability to add prefixes in front of following format
components, and the ability to influence the indentation level
when starting a new line. This is needed to support some of the new
uses of error_util in mode_errors.m.
compiler/state_var.m:
Remove a redundant format component that causes a minor test case
discrepancy with the new code in error_util.m.
compiler/modes.m:
Minor style fixes.
tests/invalid/*.err_exp:
Expect better format in mode error messages.
Estimated hours taken: 1
Branches: main and 0.12
Work around an incompatibility between the C code generated by the Mercury
compiler which uses global registers and the -floop-optimize gcc option on
Darwin PowerPC architectures.
compiler/compile_target_code.m:
scripts/mgnuc.in:
Disable the -floop-optimize optimization when using global registers
in an LLDS grade on Darwin PowerPC.
Estimated hours taken: 1
Branches: main, release
Fix some problems caught by the nightly tests and reorder part of the
reference manual.
tabling/specified was failing because the compiler was attempting to perform
unused argument optimization on a tabled predicate. The fix is to
disable unused argument optimization for all predicates that do not have an
evaluation method of eval_normal.
debugger/interactive was failing because of the recent change to how the
superhomogenous form of lambda expressions is constructed. The fix is to
update the expected output. This diff also removes an older expected output
for this test case that is no longer applicable.
Reorder the C specific section on the FLI pragmas in the reference
manual so that it matches that of the other languages.
compiler/unused_args.m:
Do not optimize unused arguments for tabled predicates.
doc/reference_manual.texi:
Rearrange the ordering of the foreign pragmas for C so that it matches
that of the other languages.
tests/debugger/interactive.exp:
Update the expected output for this test case. The change in expected
output is due to the recent change in how the compiler processes lambda
expressions.
tests/debugger/interactive.exp2:
Remove the contents of this file and replace them with a message
saying that the file is currently unused. This is expected output is
out-of-date with respect to the .inp file. (This version of the
expected output was originally added because the compiler generated
different output at -O1, however it no longer does that.)
Estimated hours taken: 25
Branches: main
Another step towards the removal of constraints and types from the arguments
of typeclass_info/1 and type_info/1. This involves ensuring that the
rtti_varmaps structure contains enough information for any code that
previously needed to refer to these arguments.
compiler/common.m:
When generating assignments between variables that hold type infos
or typeclass infos, calculate a type substitution representing the
aliasing of any type variables that results. This aliasing can
occur if the same existentially typed data structure is deconstructed
twice. The resulting substitution is applied to the simplify_info.
Update the rtti_varmaps if there is information stored for one of
the variables in the assignment, but not the other.
compiler/simplify.m:
Provide a means to apply a type substitution to the fields in
a simplify_info that may contain types.
compiler/hlds_pred.m:
Don't use an injection to model the typeclass_info_varmap. The
previous forward mapping was never intended to be complete: it
only covered constraints that could be reused by later goals when
doing the polymorphism transformation. Some prog_vars which hold
typeclass_infos cannot be reused since they may no longer be in
scope, for example, prog_vars for typeclass_infos that were
constructed in an earlier disjunct.
Instead of an injection we just use two separate maps. The reverse
map (from prog_vars to constraints) includes all known constraints.
The forward map (from constraints to prog_vars) only covers
constraints for which it is safe to reuse the prog_var. These
two maps are kept consistent be the fact that the latter map is
never updated directly; it only has entries added when a particular
prog_var is flagged as reusable.
Document the fact that when looking up a typeclass_info var, we only
consider those prog_vars which have been flagged as reusable.
Export a predicate to update already existing type_info_type
information. This is used when introducing exists_cast goals.
Export a predicate to duplicate the rtti_var_info from one variable
to another. This is used when introducing new variables in
saved_vars.m, and when updating the rtti_varmaps in common.m.
Export a predicate to return all known type_info and typeclass_info
vars. This is used by hlds_out to print out the table.
When applying substitutions to the rtti_varmaps, add a sanity check
to ensure that the various maps remain consistent.
Don't provide an interface to transform constraints. Instead,
provide an interface to transform types (which is also applied to
the constraint arguments). This interface is required when
fully expanding equivalence types, in which case all types need
to be expanded, not just those appearing in constraints.
compiler/clause_to_proc.m:
When adding exists_cast goals, ensure that the rtti_varmaps structure
is updated with the new information. This addresses an XXX comment
that was left here from an earlier change.
compiler/equiv_type_hlds.m:
Fully expand equivalence types in all types in the rtti_varmaps,
not just those types appearing in constraints.
compiler/goal_util.m:
compiler/lambda.m:
When calculating extra nonlocal typeinfos or constraints on lambda
expressions, only consider those constraints that are able to be
reused. These are the only constraints that the goal in question
could possibly have used.
compiler/hlds_out.m:
When printing out the typeclass_info_varmap, only consider the
reusable constraints. These are the only ones that have entries
in the typeclass_info_varmap.
Print out the available variable info for any type_info or
typeclass_info variables.
compiler/polymorphism.m:
Thread the entire poly_info through
polymorphism__new_typeclass_info_var, since it now makes use of
three fields within this structure. Ensure that the rtti_varmaps
field is updated with the information about the new typeclass_info
var.
Flag all universal constraints from the head and existential
constraints from the body as being reusable. The program variables
for these typeclass_infos will always be in scope wherever the
constraint could appear. Typeclass infos that have been constructed
from proofs within the current procedure may not be still in scope,
so they are not flagged as reusable.
compiler/saved_vars.m:
Make sure the rtti_varmaps is updated if we rename a variable that
contains a type_info or typeclass_info.
Estimated hours taken: 0.2
Branches: main
compiler/hlds_goal.m:
Convert this modules to four-space indentation to reduce the number
of bad line breaks. Fix some departures from our coding standards.
Change the can_cgc type from a synonym of bool to a discriminated union
type isomorphic to bool. Make goal_is_atomic more robust. Delete
duplicate comments.
compiler/*.m:
Conform to the change to can_cgc.
Estimated hours taken: 0.2
Branches: main
compiler/modecheck_unify.m:
Convert this modules to four-space indentation to reduce the number
of bad line breaks. Fix some departures from our coding standards.
compiler/mercury_compile.m:
compiler/simplify.m:
Fix some formatting.
Estimated hours taken: 4
Branches: main
Fix a problem exposed by the exists_cast transformation.
compiler/saved_vars.m:
Don't duplicate variables holding type_infos if type_info liveness
is set. Doing so could leave the rtti_varmaps in an inconsistent
state, since there may no longer be a unique location which holds
the type_info for a given type. This can cause an exception to be
thrown by liveness.m, for example, when compiling version_store.m
in a debug grade with --optimize-saved-vars-const set.
library/Mercury.options:
Undo the workaround for this bug.
tests/valid/Mercury.options:
tests/valid/Mmakefile:
tests/valid/exists_cast_bug.m:
A test case. This is compiled with deep tracing and
--optimize-saved-vars-const even if version_store is not.
tests/valid/aditi_calls_mercury.m:
Modify this test case so that the Aditi predicate no longer uses
polymorphism. Without this, we get the error "the code uses
polymorphism or type-classes which are not supported by Aditi".
Estimated hours taken: 0.2
Branches: main
compiler/term_traversal.m:
Shift to 4-space indentation throughout.
Use '.' as a module qualifier throughout; previously
we only used it some places.
s/map(prog_var, (type))/vartypes/
Improve the comment about why pass 1 traverses negated goals.
The existing comment gives the impression that this is optional;
it isn't, because pass 1 is also responsible for detecting calls
to non-terminating procedures and pass 2 relies on this having been
done.
Other minor formatting changes, e.g. positioning of comments etc.
Estimated hours taken: 1.5
Branches: main
compiler/det_report.m:
compiler/hlds_out.m:
compiler/llds.m:
compiler/type_ctor_info.m:
compiler/unify_proc.m:
compiler/unneeded_code.m:
compiler/use_local_vars.m:
compiler/var_locn.m:
Convert these modules to four-space indentation to reduce the number
of bad line breaks. Fix some departures from our coding standards.
compiler/hlds_pred.m:
Fix some formatting.
Estimated hours taken: 4
Branches: main
The transformation that introduces exists_cast goals occurs at the end of
polymorphism and operates on proc_infos which have just been copied from
clauses. A problem with this is that when inferring modes it is possible
that proc_infos may be reinitialised by copying the bodies from the clauses
again. This results in the exists_cast transformation being overwritten.
This change solves the problem by redoing the exists_cast transformation
after clauses are copied into procs during mode inference.
compiler/clause_to_proc.m:
Move the exists_cast transformation from polymorphism.m to
clause_to_proc.m, where it will be readily accessible to any stage
that needs to copy clauses to procs. The algorithm is changed
in two ways. First, it now uses the orig_arity field to determine
how many type_info and typeclass_info arguments have been added,
because the number of extra arguments is not directly available in
clause_to_proc. Second, the external type is derived from the arg
types in the pred_info instead of the vartypes in the proc_info,
because when called from modes.m the vartypes have already been
updated with different information.
Abstract out the decision whether or not copying clauses should be
done. The same decision needs to be made when redoing the exists_cast
transformation.
Provide an interface convenient for modes.m, which operates on a
module_info and list of pred_ids.
compiler/polymorphism.m:
Replace an XXX comment which this change addresses.
compiler/modes.m:
Perform the exists_cast transformation after copying clauses to procs.
compiler/hlds_pred.m:
Add a field to pred_info which stores the statically known binding
of existentially quantified type variables by a predicate. This
field is initialised to the empty substitution, and is set to its
correct value by polymorphism.m.
compiler/polymorphism.m:
Set the above field at the end of the polymorphism stage.
Estimated hours taken: 0.3
Branches: main
compiler/det_report.m:
compiler/hlds_out.m:
Convert these modules to four-space indentation to reduce the number
of bad line breaks. Fix some departures from our coding standards.
Estimated hours taken: 20
Branches: main
Add a new tabling method, one which specifies how each argument should
be treated, like this:
:- pragma memo(p(in, in, in, out), [value, addr, promise_implied, output]).
doc/reference_manual.texi:
Document the new tabling method.
compiler/prog_data.m:
Add a new tabling method, one which specifies how each argument should
be treated.
compiler/hlds_pred.m:
Provide for the description of untabled input arguments of tabled
procedures.
compiler/prog_io_pragma.m:
Parse the new tabling method.
Fix a bunch of formatting problems.
compiler/add_pragma.m:
When adding a tabling pragma to the HLDS, check that if the pragma
individually specifies the tabling methods of a procedure's arguments,
then those tabling methods agree with the modes of those arguments.
Fix an old bug: check whether a tabled predicate's arguments are
fully input or fully output, and print an error message if not.
We used to check this only in table_gen.m, but there we could only
abort the compiler if the check failed.
Factor out some common code and thereby fix an old bug: check for
conflicting tabling pragmas not just when adding the pragma to all
procedures of a predicate, but also when adding it to only a
specified procedure.
compiler/table_gen.m:
Implement the new tabling method.
compiler/prog_out.m:
compiler/layout_out.m:
Conform to the changes above.
runtime/mercury_stack_layout.h:
Provide for the description of untabled input arguments of tabled
procedures.
trace/mercury_trace.c:
Handle the new tabling method.
trace/mercury_trace_internal.c:
Handle the new tabling method. Delete the defaults from some switches
on enums to allow gcc to recognize missing cases.
Handle the untabled input arguments of tabled procedures: skip over
them when printing procedures' call tables.
Enable better completion for mdb's "table" command.
trace/mercury_trace_tables.[ch]:
Rename the breakpoint completer the proc_spec completer, since it does
completions on procedure specifications.
tests/debugger/print_table.{m,inp,exp}:
Modify this test case to test the ability to print the tables of
predicates with some untabled arguments.
tests/tabling/specified.{m,exp}:
New test case to check the functioning of the new tabling method
by testing whether it is in fact faster to table the address of
an argument instead of its value, or to not table it at all.
Since the gains here are not quite as dramatic as tabled vs untabled,
use a slightly looser criterion for comparing speeds than we use
in the various versions of the fib test case.
tests/tabling/Mmakefile:
tests/tabling/Mercury.options:
Enable the new test case, and set up the option it needs.
tests/invalid/specified.{m,err_exp}:
New test case, a slight variant of tests/tabling/specified.m,
to check the compiler's ability to detect errors in the new form
of tabling pragma.
tests/invalid/Mmakefile:
Enable the new test case.
Estimated hours taken: 15
Branches: main
Introduce a distinction between variables that are typed according to the
external view of a procedure, in which the types may contain an existentially
quantified type variable, and variables that are typed according to the
internal view of a procedure, in which existentially quantified type
variables may be bound to a known type. The distinction is maintained by
adding "exists_cast" goals which assign an internal variable to its
corresponding external variable.
Any output head variable which is existentially typed and for which the
external view differs from the internal view is replaced by a new variable.
An exists_cast goal is added to the end of the procedure which casts the
old headvar to the new one. We also do the same for any type_infos and
typeclass_infos that are output.
Exists casts are implemented as a variant on unsafe_cast generic calls.
We also add other variants to distinguish the different kinds of casts:
- equiv_casts for when the types are the same modulo equivalence
types;
- unsafe_type_casts for when the types are different but the insts
are compatible; and
- unsafe_type_inst_casts for when the type and inst are changed by
the cast.
The purpose of this change is to make it possible to include both the
internal and external views in the rtti_varmaps structure.
compiler/polymorphism.m:
Perform the transformation on proc_infos to include the exists_cast
goals. This is done at the end of the polymorphism transformation,
when we recompute the argument types for the newly transformed
procedure. The clauses_infos are left untouched by this
transformation, since after this stage they should no longer be used.
compiler/hlds_goal.m:
Modify the generic_call type to include the type of cast.
compiler/hlds_pred.m:
Modify the generic_call_id type to include the type of cast.
compiler/goal_util.m:
Add an argument to `generate_unsafe_cast' which specifies the type
of cast to generate.
compiler/higher_order.m:
Use the predicate in goal_util to generate the cast, instead of doing
it manually.
compiler/prog_rep.m:
All variants of the cast generic call are represented in the same
way. This is to avoid to the need to change the format of static
data in programs compiled with full declarative debugging. If we
do need the distinction to be made here, then that can be done as
a separate change.
compiler/purity.m:
Calls to private_builtin.unsafe_type_cast are translated into
unsafe_type_cast generic calls.
compiler/aditi_builtin_ops.m:
Use unsafe_type_inst_cast when casting between aditi_bottom_up
closures and their transformed versions.
compiler/common.m:
Use unsafe_type_cast when generating assignments for variables whose
types do not match exactly.
compiler/unify_proc.m:
Use equiv_type_cast when generating casts in unification, comparison
and initialisation clauses for equivalence types.
Use unsafe_type_cast when casting enum types to integers for the
purposes of comparison or unification.
compiler/*.m:
Handle the new generic_calls.
Estimated hours taken: 0.5
Branches: main
Cleanups for mode_util.m.
There are no changes to any algorithms.
compiler/mode_util.m:
Switch to four-space indentation throughout.
Reformat comments to conform to our current coding standard.
For some of the predicates, describe the conditions for
which they may throw an exception.
Use unexpected/2 in place of error/1
Estimated hours taken: 8
Branches: main, release
Fix a bug reported by Peter Hawkins.
compiler/superhomogeneous.m:
When converting lambda expressions into superhomogeneous form,
position the compiler created unifications that correspond to
output arguments *after* the original body of the lambda.
Placing them all before the body, leads to problems if the body
is impure because mode analysis cannot reorder the unifications
over the impure goal as it needs to in order for the lambda to
be mode correct.
XXX According to a comment, intermod.m:643, we allow head
unifications to be reordered w.r.t impure goals, but this doesn't
seem to extend to lambda expressions for some reason. Actually,
the rules for reordering over impure goals should be less
strict then they currently are, at least for construction
and assignment unifications. (I'll look into this separately though).
compiler/arg_info.m:
Mention how the predicates in this module diff from the newly
introduced partition_args_and_lambda_vars in superhomogenous.m.
(Because the former cannot handle undefined modes.)
compiler/state_var.m:
Generalise the predicate finish_head_and_body/6 so that it works
on an arbitrary number of conjoined goals.
compiler/mode_util.m:
Add a predicate to test whether a mode is undefined.
compiler/add_aditi.m:
compiler/add_clause.m:
Conform to the above changes.
tests/valid/Mmakefile:
tests/valid/impure_lambda_bug.m:
Test case for the above bug.
Estimated hours taken: 0.3
Branches: main
compiler/hlds_pred.m:
Convert this module to four-space indentation to reduce the number
of bad line breaks. Fix some departures from our coding standards.