Estimated hours taken: 18
Branches: main
Move the univ, maybe, pair and unit types from std_util into their own
modules. std_util still contains the general purpose higher-order programming
constructs.
library/std_util.m:
Move univ, maybe, pair and unit (plus any other related types
and procedures) into their own modules.
library/maybe.m:
New module. This contains the maybe and maybe_error types and
the associated procedures.
library/pair.m:
New module. This contains the pair type and associated procedures.
library/unit.m:
New module. This contains the types unit/0 and unit/1.
library/univ.m:
New module. This contains the univ type and associated procedures.
library/library.m:
Add the new modules.
library/private_builtin.m:
Update the declaration of the type_ctor_info struct for univ.
runtime/mercury.h:
Update the declaration for the type_ctor_info struct for univ.
runtime/mercury_mcpp.h:
runtime/mercury_hlc_types.h:
Update the definition of MR_Univ.
runtime/mercury_init.h:
Fix a comment: ML_type_name is now exported from type_desc.m.
compiler/mlds_to_il.m:
Update the the name of the module that defines univs (which are
handled specially by the il code generator.)
library/*.m:
compiler/*.m:
browser/*.m:
mdbcomp/*.m:
profiler/*.m:
deep_profiler/*.m:
Conform to the above changes. Import the new modules where they
are needed; don't import std_util where it isn't needed.
Fix formatting in lots of modules. Delete duplicate module
imports.
tests/*:
Update the test suite to confrom to the above changes.
Estimated hours taken: 4
Branches: main
Move the all-solutions predicates from the library module std_util into their
own module, solutions.
Move semidet_fail, semidet_succeed, cc_multi_equal and dynamic cast from
std_util.m into builtin.m.
Add some more utility functions for performing determinism or purity casts.
(The later are primarily intended for use by solver implementors.)
library/std_util.m:
Move the all-solutions predicates into their own module, solutions.m.
For now there are (obsolete) forwarding predicates from this module to
the new one. The forwarding predicates will be included in the
upcoming 0.13 release and then removed in later versions.
Move semidet_succeed, semidet_fail, cc_multi_equal and dynamic_cast
to builtin.m
library/solutions.m:
New file. This is the new home for the all-solutions predicates.
This is pretty much cut and pasted from std_util (with module
qualifiers updated accordingly). I've rearranged the code in a more
top-down fashion as per our current coding standard.
library/builtin.m:
Move semidet_fail/0, semidet_succeed/0, cc_multi_equal/2 and
dynamic_cast/2 to this module.
Add semidet_true/0 and semidet_false/0 as synonyms for semidet_fail/0
and semidet_succeed/0.
Add impure_true/0 and semipure_true/0. These are useful for performing
purity casts, e.g. in solver implementations.
library/library.m:
Add the new module.
NEWS:
Announce the changes.
library/*.m:
Update to conform to the above.
compiler/const_prop.m:
Update evaluate_semidet_call/5 with the new module name for
dynamic_cast.
compiler/*.m:
Module qualify calls to solutions to either disambiguate them from the
versions in std_util (where they weren't module qualified) or change
the module qualifier where they were (to avoid warnings about calls to
the now deprecated versions).
tests/debugger/declarative/solutions.*:
Rename this module as the name conflicts with the new library module.
tests/debugger/declarative/solns.*:
Renamed version of above (with updated expected output).
tests/debugger/declarative/Mmakefile:
Handle the renamed version of the solutions test.
tests/debugger/all_solutions.m:
tests/debugger/declarative/args.m:
tests/debugger/declarative/library_forwarding.m:
tests/hard_coded/constant_prop_2.m:
tests/invalid/multisoln_func.m:
tests/invalid/one_member.m:
tests/invalid/promise_equivalent_claueses.m:
tests/valid/simplify_bug2.m:
tests/valid/solv.m:
Update to conform to the above changes.
sample/solutions/*.m:
Update to conform to the above changes.
Estimated hours taken: 1.5
Branches: main
Move the stuff currently in hlds_pred.m that deals with clauses into a new
module, hlds_clauses.m.
Move the stuff currently in hlds_pred.m that deals with RTTI into a new
module, hlds_rtti.m.
Move the stuff currently in hlds_module.m that deals with predicate tables
into a new module, pred_table.m.
These changes make hlds_pred.m and hlds_module.m much more cohesive, but there
are no changes in algorithms.
compiler/hlds_clauses.m:
compiler/hlds_rtti.m:
compiler/pred_table.m:
New modules as described above. In some cases, fix mixleading or
ambiguous predicate names in the process, and convert a few predicates
to functions.
compiler/hlds_pred.m:
compiler/hlds_module.m:
Delete the stuff moved to other modules.
compiler/*.m:
In modules that need the functionality moved a new module, import
the new module. It is rare for all the new modules to be needed,
and many modules don't need any of the new modules at all. (For
example, of the 200+ modules that import hlds_module.m, only about 40
need pred_table.m.)
Conform to the few minor changes to e.g. predicate names.
compiler/notes/compiler_design.html:
Document the new modules.
Estimated hours taken: 6
Branches: main
compiler/*.m:
Convert almost all the compiler modules to use . instead of __ as
the module qualifier.
In some cases, change the names of predicates and types to make them
meaningful without the module qualifier. In particular, most of the
types that used to be referred to with an "mlds__" prefix have been
changed to have a "mlds_" prefix instead of changing the prefix to
"mlds.".
There are no algorithmic changes.
Estimated hours taken: 5
Branches: main
Prepare for an extension of promise_equivalent_solutions that will allow us
to better handle values of user-defined types. The problem is that currently,
the deconstruction of a value of such a type can be followed only by code that
cannot fail, otherwise the cc_multi deconstruction is not in the required
single-solution context. If the following code is naturally semidet, this
can be worked around by turning it into det code returning a maybe and testing
the maybe outside the promise_equivalent_solutions, but this is inefficient,
and in any case it does not generalize to nondet code without even more
horrendous inefficiency and inconvenience. (You have to create a nondet closure
and call it outside the promise_equivalent_solutions.)
The solution I came up with is something is to have a construct that contains
- a list of deconstructions on types with user-defined equality,
- a goal, and
- the list of outputs of that goal.
The idea is that this would be transformed into a conjunction of the first and
second items, and wrapped inside a special kind of conj that provides a scope
for the implicit promise, which is that the set of solutions of the goal in
the second item doesn't depend on what concrete terms the deconstructions
in the first item return out of the set of concrete terms they *could* return.
The deconstructions in the first item would be marked to tell determinism
analysis to effectively ignore the fact that they involve user-defined
equality.
The actual addition of that construct is left for a future change, after we
agree on the syntax.
compiler/hlds_goal.m:
Generalize the existing promise_equivalent_solutions scope to a
promise_solutions scope with a flag that says whether in the source
code it was originally the existing "promise_equivalent_solutions"
construct or the new construct (which doesn't exist yet, but is
indicated by the symbol "same_solutions" for now).
Replace the conj and par_conj hlds_goal_exprs with a single goal
expression: conj with an additional argument which is either plain_conj
or parallel_conj. This was part of an earlier design in which a third
kind of disjunction took the role now assigned to the new kind of
promise_solutions scope, but turned out to be a good idea anyway,
since in many places the compiler does treat the two kinds of
conjunctions the same. This part of the change is responsible for the
fact that this change results in a net *reduction* of about 40 lines.
Move the most frequently used kinds of goal expressions to the front
of the type declaration to allow the compiler to make better decisions
about tag allocation.
Add the goal marker we will add to the deconstructions in the first
item.
Replace the true_goal and fail_goal predicates with functions to make
them easier to use, and rename their variants that take a context
argument to avoid unnecessary ambiguity.
compiler/*.m:
Conform to the change in hlds_goal.m.
Misc changes to make code more robust, e.g. replacing semidet
predicates on goal expressions with functions returning bool.
Misc cleanups, e.g. removal of unnecessary module qualifications
that made lines too long, renaming predicates whose names include
"disj" if they are also used to process parallel conjunctions (since in
both parallel conjunctions and in disjunctions the goals are
independent), and turning semidet predicates that switch on goal
expressions into bool functions (to make similar changes more rebust
in the future).
Estimated hours taken: 4
Branches: main
compiler/*.m:
Use expect/3 in place of require/2 throughout most of the
compiler.
Use unexpected/2 (or sorry/2) in place of error/1 in more
places.
Fix more dodgy assertion error messages.
s/map(prog_var, mer_type)/vartypes/ where the latter is meant.
Estimated hours taken: 4
Branches: main
Various cleanups for the modules in the compiler directory. The are
no changes to algorithms except the replacement of some if-then-elses
that would naturally be switches with switches and the replacement of
most of the calls to error/1.
compiler/*.m:
Convert calls to error/1 to calls to unexpected/2 or sorry/2 as
appropriate throughout most or the compiler.
Fix inaccurate assertion failure messages, e.g. identifying the
assertion failure as taking place in the wrong module.
Add :- end_module declarations.
Fix formatting problems and bring the positioning of comments
into line with our current coding standards.
Fix some overlong lines.
Convert some more modules to 4-space indentation. Fix some spots
where previous conversions to 4-space indentation have stuffed
the formatting of the code up.
Fix a bunch of typos in comments.
Use state variables in more places; use library predicates
from the sv* modules where appropriate.
Delete unnecessary and duplicate module imports.
Misc. other small cleanups.
Estimated hours taken: 8
Branches: main
Improve the error messages generated for determinism errors involving committed
choice contexts. Previously, we printed a message to the effect that e.g.
a cc pred is called in context that requires all solutions, but we didn't say
*why* the context requires all solutions. We now keep track of all the goals
to the right that could fail, since it is these goals that may reject the first
solution of a committed choice goal.
The motivation for this diff was the fact that I found that locating the
failing goal can be very difficult if the conjunction to the right is
a couple of hundred lines long. This would have been a nontrivial problem,
since (a) unifications involving values of user-defined types are committed
choice goals, and (b) we can expect uses of user-defined types to increase.
compiler/det_analysis.m:
Keep track of goals to the right of the current goal that could fail,
and include them in the error representation if required.
compiler/det_report.m:
Include the list of failing goals to the right in the representations
of determinism errors involving committed committed choice goals.
Convert the last part of this module that wasn't using error_util
to use error_util. Make most parts of this module just construct
error message specifications; print those specifications (using
error_util) in only a few places.
compiler/hlds_out.m:
Add a function for use by the new code in det_report.m.
compiler/error_util.m:
Add a function for use by the new code in det_report.m.
compiler/error_util.m:
compiler/compiler_util.m:
Error_util is still changing reasonably often, and yet it is
included in lots of modules, most of which need only a few simple
non-parse-tree-related predicates from it (e.g. unexpected).
Move those predicates to a new module, compiler_util.m. This also
eliminates some undesirable dependencies from libs to parse_tree.
compiler/libs.m:
Include compiler_util.m.
compiler/notes/compiler_design.html:
Document compiler_util.m, and fix the documentation of some other
modules.
compiler/*.m:
Import compiler_util instead of or in addition to error_util.
To make this easier, consistently use . instead of __ for module
qualifying module names.
tests/invalid/det_errors_cc.{m,err_exp}:
Add this new test case to test the error messages for cc contexts.
tests/invalid/det_errors_deet.{m,err_exp}:
Add this new test case to test the error messages for unifications
inside function symbols.
tests/invalid/Mmakefile:
Add the new test cases.
tests/invalid/det_errors.err_exp:
tests/invalid/magicbox.err_exp:
Change the expected output to conform to the change in det_report.m,
which is now more consistent.
Estimated hours taken: 8
Branches: main
compiler/*.m:
Rename the types 'type', 'inst' and 'mode' to 'mer_type', 'mer_inst'
and 'mer_mode'. This is to avoid the need to parenthesize these type
names in some contexts, and to prepare for the possibility of a parser
that considers those words to be reserved words.
Rename some other uses of those names (e.g. as item types in
recompilation.m).
Delete some redundant synonyms (prog_type, mercury_type) for mer_type.
Change some type names (e.g. mlds__type) and predicate names (e.g.
deforest__goal) to make them unique even without module qualification.
Rename the function symbols (e.g. pure, &) that need to be renamed
to avoid the need to parenthesize them. Make their replacement names
more expressive.
Convert some more modules to four space indentation.
Avoid excessively long lines, such as those resulting from the
automatic substitution of 'mer_type' for 'type'.
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: 3
Branches: main
compiler/*.m:
Import only one module per line in the modules of the compiler
where my previous diff did not already do so.
Misc other cleanups.
Where relevant, use the new mechanism in tree.m.
compiler/tree.m:
Fix a performance problem I noticed while update :- import_module
items. Instead of supplying a function to convert lists of trees
to a tree, make the tree data structure able to hold a list of
subtrees directly. This reduces the number of times where we have to
convert list of trees to trees that are sticks just to stay within
the old definition of what a tree is.
Estimated hours taken: 17
Branches: main
This adds a module mdbcomp__trace_counts that reads in the
.mercury_trace_counts files produced by the compiler's trace mechanism.
The format of said files was slightly changed.
As the new module is to be used by the compiler and the debugger, it is
placed in the mdbcomp module. This required bringing some types from the
compiler into a new module within mdbcomp.
browser/trace_counts.m:
New module for reading execution trace summaries.
browser/prim_data.m:
New module holding types and predicates moved in from the compiler.
Types:
pred_or_func, sym_name, module_name, proc_label,
special_pred_id, trace_port
Predicates:
string_to_sym_name, insert_module_qualifier
The mode field of proc_label is now an int instead of a proc_id
to avoid pulling proc_id into mdbcomp.
browser/mdbcomp.m:
Add trace_counts and prim_data to the mdbcomp module.
browser/declarative_execution.m:
Renamed mdb's definition of module_name to flat_module_name
to avoid conflicts with the definition in mdbcomp__prim_data.
runtime/mercury_trace_base.c:
In the format of .mercury_trace_counts, write module and predicate
names now use quoted atom syntax so that names with spaces and
non-printable characters can be machine-parsed.
browser/:
compiler/:
Many changes to account for movement of types, and the change to
proc_label.
Estimated hours taken: 12
Branches: main
Remove almost all dependencies by the modules of parse_tree.m on the modules
of hlds.m. The only such dependencies remaining now are on type_util.m.
compiler/hlds_data.m:
compiler/prog_data.m:
Move the cons_id type from hlds_data to prog_data, since several parts
of the parse tree data structure depend on it (particularly insts).
Remove the need to import HLDS modules in prog_data.m by making the
cons_ids that refer to procedure ids refer to them via a new type
that contains shrouded pred_ids and proc_ids. Since pred_ids and
proc_ids are abstract types in hlds_data, add predicates to hlds_data
to shroud and unshroud them.
Also move some other types, e.g. mode_id and class_id, from hlds_data
to prog_data.
compiler/hlds_data.m:
compiler/prog_util.m:
Move predicates for manipulating cons_ids from hlds_data to prog_util.
compiler/inst.m:
compiler/prog_data.m:
Move the contents of inst.m to prog_data.m, since that is where it
belongs, and since doing so eliminates a circular dependency.
The separation doesn't serve any purpose any more, since we don't
need to import hlds_data.m anymore to get access to the cons_id type.
compiler/mode_util.m:
compiler/prog_mode.m:
compiler/parse_tree.m:
Move the predicates in mode_util that don't depend on the HLDS to a new
module prog_mode, which is part of parse_tree.m.
compiler/notes/compiler_design.m:
Mention prog_mode.m, and delete the mention of inst.m.
compiler/mercury_to_mercury.m:
compiler/hlds_out.m:
Move the predicates that depend on HLDS out of mercury_to_mercury.m
to hlds_out.m. Export from mercury_to_mercury.m the predicates needed
by the moved predicates.
compiler/hlds_out.m:
compiler/prog_out.m:
Move predicates for printing parts of the parse tree out of hlds_out.m
to prog_out.m, since mercury_to_mercury.m needs to use them.
compiler/purity.m:
compiler/prog_out.m:
Move predicates for printing purities from purity.m, which is part
of check_hlds.m, to prog_out.m, since mercury_to_mercury.m needs to use
them.
compiler/passes_aux.m:
compiler/prog_out.m:
Move some utility predicates (e.g. for printing progress messages) from
passes_aux.m to prog_out.m, since some predicates in submodules of
parse_tree.m need to use them.
compiler/foreign.m:
compiler/prog_data.m:
Move some types from foreign.m to prog_data.m to allow the elimination
of some dependencies on foreign.m from submodules of parse_tree.m.
compiler/*.m:
Conform to the changes above, mostly by updating lists of imported
modules and module qualifications. In some cases, also do some local
cleanups such as converting predicate declarations to predmode syntax
and fixing white space.
Estimated hours taken: 8
Branches: main
analysis/analysis.m:
browser/browse.m:
compiler/accumulator.m:
compiler/assertion.m:
compiler/atsort.m:
compiler/c_util.m:
compiler/check_typeclass.m:
compiler/clause_to_proc.m:
compiler/code_gen.m:
compiler/code_model.m:
compiler/const_prop.m:
compiler/constraint.m:
compiler/dead_proc_elim.m:
compiler/delay_construct.m:
compiler/dependency_graph.m:
compiler/det_analysis.m:
compiler/det_report.m:
compiler/export.m:
compiler/fact_table.m:
compiler/follow_code.m:
compiler/graph_colour.m:
compiler/hlds_module.m:
compiler/inlining.m:
compiler/llds.m:
compiler/make_hlds.m:
compiler/mercury_to_mercury.m:
compiler/ml_tailcall.m:
compiler/ml_unify_gen.m:
compiler/mmc_analysis.m:
compiler/mode_errors.m:
compiler/passes_aux.m:
compiler/post_typecheck.m:
compiler/size_prof.m:
compiler/switch_util.m:
compiler/table_gen.m:
compiler/term_errors.m:
compiler/transform_llds.m:
compiler/type_util.m:
compiler/unify_gen.m:
compiler/unneeded_code.m:
compiler/unused_args.m:
Bring these modules up to our current coding standards. Use predmode
declarations and state variable syntax where relevant. Reorder
arguments where this is needed for the use state variables. Make the
orders of predicate definitions correspond to the order of their
declarations. Replace some overly large lambda expressions with named
predicates. Convert some predicates to functions where this makes
their use more convenient. Use field access notation where convenient.
Fix any inconsistent indentation. Remove module prefixes on predicate
names where this is necessary to allow sane indentation.
In several places, use predicates from error_util.m to print error
messages. Apart from this, there are no changes in algorithms.
In some places, conform to the changes below.
compiler/error_util.m:
compiler/hlds_error_util.m:
Add new variants of existing predicates for use in some of the
changed modules above.
compiler/hlds_out.m:
Add some functions to convert values of some HLDS types as strings,
for use in preparing the arguments of the new calls to predicates in
error_util.m. Change the implementations of the predicates that print
values of those types to call those functions instead of allowing
code duplication.
compiler/llds.m:
Add some field names to allow use of field updates where relevant.
tests/invalid/assert_in_interface.err_exp:
tests/invalid/multisoln_func.err_exp:
tests/invalid/tricky_assert1.err_exp:
Update the expected outputs of these test cases to allow for them being
generated by error_util.m, and hence being better formatted than
before.
Estimated hours taken: 4
Branches: main
Reduce the dependence of earlier parts of the compiler on the later ones.
Unnecessary import_module declarations in top level modules such as hlds.m
cause unnecessary recompilations when adding new types in later modules,
such as submodules of ll_backend.m. This change reduces the number of such
unnecessary imports.
There are no changes in algorithms, only functionality being moved around.
compiler/code_model.m:
Change this module from being a submodule of backend_libs.m to being a
submodule of hlds.m, since nothing in it is dependent on any backend.
compiler/arg_info.m:
compiler/code_util.m:
Change arg_info.m from being a submodule of ll_backend.m to being a
submodule of hlds.m, since most of it is applicable to all current
and foreseeable backends. Move the one exported predicate that is
ll_backend dependent, and its support predicates, to code_util.m.
compiler/backend_libs.m:
compiler/ll_backend.m:
compiler/hlds.m:
Update include_module declarations in accordance with the above.
compiler/prog_data.m:
compiler/term_util.m:
Instead of defining two separate types for holding argument size and
termination information, one including HLDS-specific information (in
term_util.m) and one not (in prog_data.m), use a polymorphic type
defined in prog_data.m and two monomorphic instances.
compiler/termination.m:
compiler/mercury_to_mercury.m:
Change the predicates for writing out argument size and termination
information to handle the polymorphic type (we don't need special
handling of the monomorphic versions), and move them from termination.m
to mercury_to_mercury.m, since this allows us to avoid some
undesirable dependencies.
compiler/base_typeclass_info.m:
compiler/hlds_code_util.m:
Move the predicate make_instance_string from base_typeclass_info.m
to hlds_code_util.m, again because it allows us to remove some
undesirable dependencies.
compiler/top_level.m:
compiler/backend_libs.m:
compiler/check_hlds.m:
compiler/hlds.m:
compiler/ll_backend.m:
compiler/parse_tree.m:
compiler/transform_hlds.m:
Delete some import_module declarations of other top level modules
in these top level modules. Some imports were totally unnecessary.
Some imports were useful in only a small minority of submodules;
those submodules now import the necessary top level modules directly.
Move remaining import_module declarations to the implementation section
where this is feasible.
Where we still need to import modules we ideally shouldn't, note why.
compiler/*.m:
Update imports of code_util and arg_info.
In some cases, import top level modules no longer imported by the
parent module.
In some cases, delete unnecessary imports.
Estimated hours taken: 4
Branches: main
Do constant propagation for calls to private_builtin.typed_unify and
std_util.dynamic_cast, i.e. evaluate them at compile time if the types
are known, and optimize the implementation of dynamic_cast.
Also clean up the code in const_prop.m.
library/std_util.m:
Implement dynamic_cast more efficiently, using typed_unify(X, Y)
rather than univ_to_type(univ(X), Y). This avoids allocating a
cell on the heap.
compiler/const_prop.m:
Keep track of the types of the arguments.
Add new code for evaluating semidet calls with one output,
and use this to evaluate calls to dynamic_cast and typed_unify.
Rename evaluate_builtin to evaluate_call, since it may evaluate
any standard library procedure, not just those which are builtin
(in the sense of pred_info_is_builtin). Likewise for its subroutines.
Various other clean-ups, e.g. combine evaluate_builtin_bi and
evaluate_builtin_tri into a single predicate evaluate_det_call,
delete unused arguments, reorder arguments so that inputs precede
outputs, use combined pred-mode declarations, and add some comments.
compiler/simplify.m:
Update to reflect the new interface to const_prop.m.
tests/hard_coded/constant_prop_2.m:
tests/hard_coded/constant_prop_2.exp:
Test that we do constant propagation for calls to typed_unify
and dynamic_cast.
Estimated hours taken: 0.1
Branches: main
Remove the reference to `int:^/2' operator in the constant propagation pass
since that operator was changed into the field access operator some
time ago.
compiler/const_prop.m:
Remove the reference to `int:^/2'.
Estimated hours taken: 4
Branches: main
This diff contains no changes in algorithms whatsoever.
browser/*.m:
compiler/*.m:
library/*.m:
Replace old-style lambdas with new-style lambdas or with named
procedures.
Estimated hours taken: 2
Branches: main
compiler/*.m:
Import only one compiler module per line. Sort the blocks of imports.
This makes it easier to merge in changes.
In a couple of places, remove unnecessary imports.
Estimated hours taken: 0.25
Branches: main
compiler/const_prop.m:
Delete an obsolete XXX comment that was referring to a file
which has since been deleted.
Estimated hours taken: 400
Branches: main
This diff implements stack slot optimization for the LLDS back end based on
the idea that after a unification such as A = f(B, C, D), saving the
variable A on the stack indirectly also saves the values of B, C and D.
Figuring out what subset of {B,C,D} to access via A and what subset to access
via their own stack slots is a tricky optimization problem. The algorithm we
use to solve it is described in the paper "Using the heap to eliminate stack
accesses" by Zoltan Somogyi and Peter Stuckey, available in ~zs/rep/stackslot.
That paper also describes (and has examples of) the source-to-source
transformation that implements the optimization.
The optimization needs to know what variables are flushed at call sites
and at program points that establish resume points (e.g. entries to
disjunctions and if-then-elses). We already had code to compute this
information in live_vars.m, but this code was being invoked too late.
This diff modifies live_vars.m to allow it to be invoked both by the stack
slot optimization transformation and by the code generator, and allows its
function to be tailored to the requirements of each invocation.
The information computed by live_vars.m is specific to the LLDS back end,
since the MLDS back ends do not (yet) have the same control over stack
frame layout. We therefore store this information in a new back end specific
field in goal_infos. For uniformity, we make all the other existing back end
specific fields in goal_infos, as well as the similarly back end specific
store map field of goal_exprs, subfields of this new field. This happens
to significantly reduce the sizes of goal_infos.
To allow a more meaningful comparison of the gains produced by the new
optimization, do not save any variables across erroneous calls even if
the new optimization is not enabled.
compiler/stack_opt.m:
New module containing the code that performs the transformation
to optimize stack slot usage.
compiler/matching.m:
New module containing an algorithm for maximal matching in bipartite
graphs, specialized for the graphs needed by stack_opt.m.
compiler/mercury_compile.m:
Invoke the new optimization if the options ask for it.
compiler/stack_alloc.m:
New module containing code that is shared between the old,
non-optimizing stack slot allocation system and the new, optimizing
stack slot allocation system, and the code for actually allocating
stack slots in the absence of optimization.
Live_vars.m used to have two tasks: find out what variables need to be
saved on the stack, and allocating those variables to stack slots.
Live_vars.m now does only the first task; stack_alloc.m now does
the second, using code that used to be in live_vars.m.
compiler/trace_params:
Add a new function to test the trace level, which returns yes if we
want to preserve the values of the input headvars.
compiler/notes/compiler_design.html:
Document the new modules (as well as trace_params.m, which wasn't
documented earlier).
compiler/live_vars.m:
Delete the code that is now in stack_alloc.m and graph_colour.m.
Separate out the kinds of stack uses due to nondeterminism: the stack
slots used by nondet calls, and the stack slots used by resumption
points, in order to allow the reuse of stack slots used by resumption
points after execution has left their scope. This should allow the
same stack slots to be used by different variables in the resumption
point at the start of an else branch and nondet calls in the then
branch, since the resumption point of the else branch is not in effect
when the then branch is executed.
If the new option --opt-no-return-calls is set, then say that we do not
need to save any values across erroneous calls.
Use type classes to allow the information generated by this module
to be recorded in the way required by its invoker.
Package up the data structures being passed around readonly into a
single tuple.
compiler/store_alloc.m:
Allow this module to be invoked by stack_opt.m without invoking the
follow_vars transformation, since applying follow_vars before the form
of the HLDS code is otherwise final can be a pessimization.
Make the module_info a part of the record containing the readonly data
passed around during the traversal.
compiler/common.m:
Do not delete or move around unifications created by stack_opt.m.
compiler/call_gen.m:
compiler/code_info.m:
compiler/continuation_info.m:
compiler/var_locn.m:
Allow the code generator to delete its last record of the location
of a value when generating code to make an erroneous call, if the new
--opt-no-return-calls option is set.
compiler/code_gen.m:
Use a more useful algorithm to create the messages/comments that
we put into incr_sp instructions, e.g. by distinguishing between
predicates and functions. This is to allow the new scripts in the
tool directory to gather statistics about the effect of the
optimization on stack frame sizes.
library/exception.m:
Make a hand-written incr_sp follow the new pattern.
compiler/arg_info.m:
Add predicates to figure out the set of input, output and unused
arguments of a procedure in several different circumstances.
Previously, variants of these predicates were repeated in several
places.
compiler/goal_util.m:
Export some previously private utility predicates.
compiler/handle_options.m:
Turn off stack slot optimizations when debugging, unless
--trace-optimized is set.
Add a new dump format useful for debugging --optimize-saved-vars.
compiler/hlds_llds.m:
New module for handling all the stuff specific to the LLDS back end
in HLDS goal_infos.
compiler/hlds_goal.m:
Move all the relevant stuff into the new back end specific field
in goal_infos.
compiler/notes/allocation.html:
Update the documentation of store maps to reflect their movement
into a subfield of goal_infos.
compiler/*.m:
Minor changes to accomodate the placement of all back end specific
information about goals from goal_exprs and individual fields of
goal_infos into a new field in goal_infos that gathers together
all back end specific information.
compiler/use_local_vars.m:
Look for sequences in which several instructions use a fake register
or stack slot as a base register pointing to a cell, and make those
instructions use a local variable instead.
Without this, a key assumption of the stack slot optimization,
that accessing a field in a cell costs only one load or store
instruction, would be much less likely to be true. (With this
optimization, the assumption will be false only if the C compiler's
code generator runs out of registers in a basic block, which for
the code we generate should be unlikely even on x86s.)
compiler/options.m:
Make the old option --optimize-saved-vars ask for both the old stack
slot optimization (implemented by saved_vars.m) that only eliminates
the storing of constants in stack slots, and the new optimization.
Add two new options --optimize-saved-vars-{const,cell} to turn on
the two optimizations separately.
Add a bunch of options to specify the parameters of the new
optimizations, both in stack_opt.m and use_local_vars.m. These are
for implementors only; they are deliberately not documented.
Add a new option, --opt-no-return-cells, that governs whether we avoid
saving variables on the stack at calls that cannot return, either by
succeeding or by failing. This is for implementors only, and thus
deliberately documented only in comments. It is enabled by default.
compiler/optimize.m:
Transmit the value of a new option to use_local_vars.m.
doc/user_guide.texi:
Update the documentation of --optimize-saved-vars.
library/tree234.m:
Undo a previous change of mine that effectively applied this
optimization by hand. That change complicated the code, and now
the compiler can do the optimization automatically.
tools/extract_incr_sp:
A new script for extracting stack frame sizes and messages from
stack increment operations in the C code for LLDS grades.
tools/frame_sizes:
A new script that uses extract_incr_sp to extract information about
stack frame sizes from the C files saved from a stage 2 directory
by makebatch and summarizes the resulting information.
tools/avg_frame_size:
A new script that computes average stack frame sizes from the files
created by frame_sizes.
tools/compare_frame_sizes:
A new script that compares the stack frame size information
extracted from two different stage 2 directories by frame_sizes,
reporting on both average stack frame sizes and on specific procedures
that have different stack frame sizes in the two versions.
The main aim of this change is to make the overall, high-level structure
of the compiler clearer, and to encourage better encapsulation of the
major components.
compiler/libs.m:
compiler/backend_libs.m:
compiler/parse_tree.m:
compiler/hlds.m:
compiler/check_hlds.m:
compiler/transform_hlds.m:
compiler/bytecode_backend.m:
compiler/aditi_backend.m:
compiler/ml_backend.m:
compiler/ll_backend.m:
compiler/top_level.m:
New files. One module for each of the major components of the
Mercury compiler. These modules contain (as separate sub-modules)
all the other modules in the Mercury compiler, except gcc.m and
mlds_to_gcc.m.
Mmakefile:
compiler/Mmakefile:
Handle the fact that the top-level module is now `top_level',
not `mercury_compile' (since `mercury_compile' is a sub-module
of `top_level').
compiler/Mmakefile:
Update settings of *FLAGS-<modulename> to use the appropriate
nested module names.
compiler/recompilation_check.m:
compiler/recompilation_version.m:
compiler/recompilation_usage.m:
compiler/recompilation.check.m:
compiler/recompilation.version.m:
compiler/recompilation.version.m:
Convert the `recompilation_*' modules into sub-modules of the
`recompilation' module.
compiler/*.m:
compiler/*.pp:
Module-qualify the module names in `:- module', `:- import_module',
and `:- use_module' declarations.
compiler/base_type_info.m:
compiler/base_type_layout.m:
Deleted these unused empty modules.
compiler/prog_data.m:
compiler/globals.m:
Move the `foreign_language' type from prog_data to globals.
compiler/mlds.m:
compiler/ml_util.m:
compiler/mlds_to_il.m:
Import `globals', for `foreign_language'.
Mmake.common.in:
trace/Mmakefile:
runtime/Mmakefile:
Rename the %.check.c targets as %.check_hdr.c,
to avoid conflicts with compiler/recompilation.check.c.
Estimated hours taken: 0.25
library/int.m:
Add a clause for `int__rem/2' which throws an exception if
the right operand is zero.
Add declarations for the `int__unchecked_rem/2', which
does not perform any checking.
compiler/builtin_ops.m:
`int__rem/2' is no longer a builtin.
compiler/const_prop.m:
Handle `int__unchecked_rem/2'.
NEWS:
Document the changes.
Estimated hours taken: 0.1
Branches: main
compiler/const_prop.m:
Remove code to handle the reverse modes of the
builtin float arithmetic functions, which have
been removed. Remove commented out code to handle
the reverse modes of integer multiplication and
division, which are unlikely to ever be implemented.
Handle {int,float}__unchecked_quotient.
Estimated hours taken: 0.5
Make `int:^/2' obsolete.
Bootstrap CVS tag: bootstrap_19991103_xor
library/int.m:
Uncomment the `:- pragma obsolete' declaration for `int:^/2'.
NEWS:
Mention that `int:^/2' is now obsolete.
configure.in:
Check for `int__xor/2' when checking that
the current compiler is up-to-date.
compiler/ml_code_gen.m:
Handle `int__xor/2' as a builtin.
compiler/const_prop.m:
library/string.m:
Rename calls to `int:^/2' to `int__xor/2'.
Estimated hours taken: 60
User-guided type specialization.
compiler/prog_data.m:
compiler/prog_io_pragma.m:
compiler/modules.m:
compiler/module_qual.m:
compiler/mercury_to_mercury.m:
Handle `:- pragma type_spec'.
compiler/prog_io_pragma.m:
Factor out some common code to parse predicate names with arguments.
compiler/hlds_module.m:
Added a field to the module_sub_info to hold information about
user-requested type specializations, filled in by make_hlds.m
and not used by anything after higher_order.m.
compiler/make_hlds.m:
For each `:- pragma type_spec' declaration, introduce a new predicate
which just calls the predicate to be specialized with the
specified argument types. This forces higher_order.m to produce
the specialized versions.
compiler/higher_order.m:
Process the user-requested type specializations first to ensure
that they get the correct names.
Allow partial matches against user-specified versions, e.g.
map__lookup(map(int, list(int)), int, list(int)) matches
map__lookup(map(int, V), int, V).
Perform specialization where a typeclass constraint matches a
known instance, but the construction of the typeclass_info is
done in the calling module.
Give slightly more informative progress messages.
compiler/dead_proc_elim.m:
Remove specializations for dead procedures.
compiler/prog_io_util.m:
Change the definition of the `maybe1' and `maybe_functor' types
to avoid the need for copying to convert between `maybe1'
and `maybe1(generic)'.
Changed the interface of `make_pred_name_with_context' to allow
creation of predicate names for type specializations which describe
the type substitution.
compiler/make_hlds.m:
compiler/prog_io_pragma.m:
Make the specification of pragma declarations in error
messages consistent. (There are probably some more to
be fixed elsewhere for termination and tabling).
compiler/intermod.m:
Write type specialization pragmas for predicates declared
in `.opt' files.
compiler/mercury_to_mercury.m:
Export `mercury_output_item' for use by intermod.m.
compiler/options.m:
Add an option `--user-guided-type-specialization' enabled
with `-O2' or higher.
compiler/handle_options.m:
`--type-specialization' implies `--user-guided-type-specialization'.
compiler/hlds_goal.m:
Add predicates to construct constants. These are duplicated
in several other places, I'll fix that as a separate change.
compiler/type_util.m:
Added functions `int_type/0', `string_type/0', `float_type/0'
and `char_type/0' which return the builtin types.
These are duplicated in several other places,
I'll fix that as a separate change.
library/private_builtin.m:
Added `instance_constraint_from_typeclass_info/3' to extract
the typeclass_infos for a constraint on an instance declaration.
This is useful for specializing class method calls.
Added `thread_safe' to various `:- pragma c_code's.
Added `:- pragma inline' declarations for `builtin_compare_*', which
are important for user-guided type specialization. (`builtin_unify_*'
are simple enough to go in the `.opt' files automatically).
compiler/polymorphism.m:
`instance_constraint_from_typeclass_info/3' does not need type_infos.
Add `instance_constraint_from_typeclass_info/3' to the
list of `typeclass_info_manipulator's which higher_order.m
can interpret.
NEWS:
doc/reference_manual.texi:
doc/user_guide.texi
Document the new pragma and option.
tests/invalid/Mmakefile:
tests/invalid/type_spec.m:
tests/invalid/type_spec.err_exp:
Test error reporting for invalid type specializations.
tests/hard_coded/Mmakefile:
tests/invalid/type_spec.m:
tests/invalid/type_spec.exp:
Test type specialization.
Estimated hours taken: 0.1
compiler/const_prop.m:
compiler/vn_util.m:
Add XXX comments about checking for overflow and sharing code
between these modules.
Estimated hours taken: 20
These changes make `var' and `term' polymorphic. This allows us to make
variables and terms representing types of a different type to those
representing program terms and those representing insts.
These changes do not *fix* any existing problems (for instance
there was a messy conflation of program variables and inst variables,
and where necessary I've just called varset__init(InstVarSet) with
an XXX comment).
NEWS:
Mention the changes to the standard library.
library/term.m:
Make term, var and var_supply polymorphic.
Add new predicates:
term__generic_term/1
term__coerce/2
term__coerce_var/2
term__coerce_var_supply/2
library/varset.m:
Make varset polymorphic.
Add the new predicate:
varset__coerce/2
compiler/prog_data.m:
Introduce type equivalences for the different kinds of
vars, terms, and varsets that we use (tvar and tvarset
were already there but have been changed to use the
polymorphic var and term).
Also change the various kinds of items to use the appropriate
kinds of var/varset.
compiler/*.m:
Thousands of boring changes to make the compiler type correct
with the different types for type, program and inst vars and
varsets.
Estimated hours taken: 50
Add support for nested modules.
- module names may themselves be module-qualified
- modules may contain `:- include_module' declarations
which name sub-modules
- a sub-module has access to all the declarations in the
parent module (including its implementation section).
This support is not yet complete; see the BUGS and LIMITATIONS below.
LIMITATIONS
- source file names must match module names
(just as they did previously)
- mmc doesn't allow path names on the command line any more
(e.g. `mmc --make-int ../library/foo.m').
- import_module declarations must use the fully-qualified module name
- module qualifiers must use the fully-qualified module name
- no support for root-qualified module names
(e.g. `:parent:child' instead of `parent:child').
- modules may not be physically nested (only logical nesting, via
`include_module').
BUGS
- doesn't check that the parent module is imported/used before allowing
import/use of its sub-modules.
- doesn't check that there is an include_module declaration in the
parent for each module claiming to be a child of that parent
- privacy of private modules is not enforced
-------------------
NEWS:
Mention that we support nested modules.
library/ops.m:
library/nc_builtin.nl:
library/sp_builtin.nl:
compiler/mercury_to_mercury.m:
Add `include_module' as a new prefix operator.
Change the associativity of `:' from xfy to yfx
(since this made parsing module qualifiers slightly easier).
compiler/prog_data.m:
Add new `include_module' declaration.
Change the `module_name' and `module_specifier' types
from strings to sym_names, so that module names can
themselves be module qualified.
compiler/modules.m:
Add predicates module_name_to_file_name/2 and
file_name_to_module_name/2.
Lots of changes to handle parent module dependencies,
to create parent interface (`.int0') files, to read them in,
to output correct dependencies information for them to the
`.d' and `.dep' files, etc.
Rewrite a lot of the code to improve the readability
(add comments, use subroutines, better variable names).
Also fix a couple of bugs:
- generate_dependencies was using the transitive implementation
dependencies rather than the transitive interface dependencies
to compute the `.int3' dependencies when writing `.d' files
(this bug was introduced during crs's changes to support
`.trans_opt' files)
- when creating the `.int' file, it was reading in the
interfaces for modules imported in the implementation section,
not just those in the interface section.
This meant that the compiler missed a lot of errors.
library/graph.m:
library/lexer.m:
library/term.m:
library/term_io.m:
library/varset.m:
compiler/*.m:
Add `:- import_module' declarations to the interface needed
by declarations in the interface. (The previous version
of the compiler did not detect these missing interface imports,
due to the above-mentioned bug in modules.m.)
compiler/mercury_compile.m:
compiler/intermod.m:
Change mercury_compile__maybe_grab_optfiles and
intermod__grab_optfiles so that they grab the opt files for
parent modules as well as the ones for imported modules.
compiler/mercury_compile.m:
Minor changes to handle parent module dependencies.
(Also improve the wording of the warning about trans-opt
dependencies.)
compiler/make_hlds.m:
compiler/module_qual.m:
Ignore `:- include_module' declarations.
compiler/module_qual.m:
A couple of small changes to handle nested module names.
compiler/prog_out.m:
compiler/prog_util.m:
Add new predicates string_to_sym_name/3 (prog_util.m) and
sym_name_to_string/{2,3} (prog_out.m).
compiler/*.m:
Replace many occurrences of `string' with `module_name'.
Change code that prints out module names or converts
them to strings or filenames to handle the fact that
module names are now sym_names intead of strings.
Also change a few places (e.g. in intermod.m, hlds_module.m)
where the code assumed that any qualified symbol was
fully-qualified.
compiler/prog_io.m:
compiler/prog_io_goal.m:
Move sym_name_and_args/3, parse_qualified_term/4 and
parse_qualified_term/5 preds from prog_io_goal.m to prog_io.m,
since they are very similar to the parse_symbol_name/2 predicate
already in prog_io.m. Rewrite these predicates, both
to improve maintainability, and to handle the newly
allowed syntax (module-qualified module names).
Rename parse_qualified_term/5 as `parse_implicit_qualified_term'.
compiler/prog_io.m:
Rewrite the handling of `:- module' and `:- end_module'
declarations, so that it can handle nested modules.
Add code to parse `include_module' declarations.
compiler/prog_util.m:
compiler/*.m:
Add new predicates mercury_public_builtin_module/1 and
mercury_private_builtin_module/1 in prog_util.m.
Change most of the hard-coded occurrences of "mercury_builtin"
to call mercury_private_builtin_module/1 or
mercury_public_builtin_module/1 or both.
compiler/llds_out.m:
Add llds_out__sym_name_mangle/2, for mangling module names.
compiler/special_pred.m:
compiler/mode_util.m:
compiler/clause_to_proc.m:
compiler/prog_io_goal.m:
compiler/lambda.m:
compiler/polymorphism.m:
Move the predicates in_mode/1, out_mode/1, and uo_mode/1
from special_pred.m to mode_util.m, and change various
hard-coded definitions to instead call these predicates.
compiler/polymorphism.m:
Ensure that the type names `type_info' and `typeclass_info' are
module-qualified in the generated code. This avoids a problem
where the code generated by polymorphism.m was not considered
type-correct, due to the type `type_info' not matching
`mercury_builtin:type_info'.
compiler/check_typeclass.m:
Simplify the code for check_instance_pred and
get_matching_instance_pred_ids.
compiler/mercury_compile.m:
compiler/modules.m:
Disallow directory names in command-line arguments.
compiler/options.m:
compiler/handle_options.m:
compiler/mercury_compile.m:
compiler/modules.m:
Add a `--make-private-interface' option.
The private interface file `<module>.int0' contains
all the declarations in the module; it is used for
compiling sub-modules.
scripts/Mmake.rules:
scripts/Mmake.vars.in:
Add support for creating `.int0' and `.date0' files
by invoking mmc with `--make-private-interface'.
doc/user_guide.texi:
Document `--make-private-interface' and the `.int0'
and `.date0' file extensions.
doc/reference_manual.texi:
Document nested modules.
util/mdemangle.c:
profiler/demangle.m:
Demangle names with multiple module qualifiers.
tests/general/Mmakefile:
tests/general/string_format_test.m:
tests/general/string_format_test.exp:
tests/general/string__format_test.m:
tests/general/string__format_test.exp:
tests/general/.cvsignore:
Change the `:- module string__format_test' declaration in
`string__format_test.m' to `:- module string_format_test',
because with the original declaration the `__' was taken
as a module qualifier, which lead to an error message.
Hence rename the file accordingly, to avoid the warning
about file name not matching module name.
tests/invalid/Mmakefile:
tests/invalid/missing_interface_import.m:
tests/invalid/missing_interface_import.err_exp:
Regression test to check that the compiler reports
errors for missing `import_module' in the interface section.
tests/invalid/*.err_exp:
tests/warnings/unused_args_test.exp:
tests/warnings/unused_import.exp:
Update the expected diagnostics output for the test cases to
reflect a few minor changes to the warning messages.
tests/hard_coded/Mmakefile:
tests/hard_coded/parent.m:
tests/hard_coded/parent.child.m:
tests/hard_coded/parent.exp:
tests/hard_coded/parent2.m:
tests/hard_coded/parent2.child.m:
tests/hard_coded/parent2.exp:
Two simple tests case for the use of nested modules with
separate compilation.
Estimated hours taken: 0.75
compiler/bytecode.m:
compiler/code_util.m:
compiler/const_prop.m:
compiler/hlds_out.m:
compiler/intermod.m:
compiler/llds_out.m:
compiler/make_hlds.m:
compiler/mercury_to_c.m:
compiler/modes.m:
compiler/special_pred.m:
compiler/term_errors.m:
compiler/trace.m:
Delete all the obsolete code using magic numbers (e.g. 10000)
for proc_ids. This old hack, whereby make_hlds.m assigned
mode numbers based on the priority given to the determinism of
each mode, is not needed anymore. It is no longer needed
because modecheck_call.m now chooses the mode that is the best
fit (based on a variety of factors) rather than just picking
the first allowable mode.
tests/invalid/duplicate_modes.err_exp:
The output for this test changed, in insignificant ways:
the order in which it reported the duplicates modes changed,
because the mode numbers had changed.
Estimated hours taken: 0.75
library/*.m:
compiler/*.m:
Undo Zoltan's bogus update of all the copyright dates.
The dates in the copyright header should reflect the years
in which the file was modified (and no, changes to the
copyright header itself don't count as modifications).
Estimated hours taken: 10
Add constant propagation within modules. This occurs during simplification
and simply attempts to evaluate "known" calls that have all their inputs
bound to constants and replaces the call with constructions of the outputs.
Currently the "known" calls are (most) of the arithmetic predicates, and
the comparison of ints and floats.
compiler/instmap.m:
add merge_instmap_deltas which merges a list of intmap deltas
rather than just two of them.
compiler/mercury_compile.m:
compiler/options.m:
add (and use) the option --optimize-constant-propagation
compiler/simplify.m:
add a bool to the simplify struct to turn on/off constant
propagation.
in the simplification of calls, check to see if all the inputs
are bound to constants. If we know how to evaluate this call
at compile time, then do so. This may change the instmap delta.
For branched goals, we merge the instmap deltas to recompute the
instmap delta for the goal as a whole so that we know when every
branch binds a variable to the same constant.
compiler/notes/compiler_design.html:
mention constant propagation.
doc/user_guide.texi:
mention constant propagation.
compiler/const_prop.m:
code that attempts to evaluate calls at compile time.
It contains tables of calls that we know how to evaluate.