mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-12 12:26:29 +00:00
fa9ca36d03ea23ea3bb94801a5fd41cb703e1baa
26 Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
fa9ca36d03 |
This diff makes several files easier to read and to maintain (as well as
Estimated hours taken: 5 Branches: main This diff makes several files easier to read and to maintain (as well as more than 400 lines shorter), but contains no changes in algorithms whatsoever. compiler/deep_profiling.m: compiler/foreign.m: compiler/hlds_module.m: compiler/hlds_data.m: compiler/make_hlds.m: compiler/post_typecheck.m: compiler/prog_data.m: compiler/purity.m: compiler/type_util.m: Bring these modules into line with our current coding standards. Use predmode declarations and state variable syntax when appropriate. Reorder arguments of predicates where necessary for the use of state variable syntax, and where this improves readability. Replace predicates with functions where appropriate. Standardize indentation. compiler/*.m: Conform to the changes above. |
||
|
|
273a8606c8 |
Add an XXX comment about this module not handling exceptions
Estimated hours taken: 0.5. Branches: main compiler/accumulator.m: Add an XXX comment about this module not handling exceptions and non-termination correctly. |
||
|
|
b39a3d855f |
This diff makes hlds_module.m and many callers of its predicates easier to read
Estimated hours taken: 6 Branches: main This diff makes hlds_module.m and many callers of its predicates easier to read and to maintain, but contains no changes in algorithms whatsoever. compiler/hlds_module.m: Bring (most of) this module into line with our current coding standards. Use predmode declarations, functions, and state variable syntax when appropriate. (The 'most of' is because I left the part of the module dealing with predicate tables alone, not wishing to cause a conflict for Pete.) Reorder arguments of predicates where necessary for the use of state variable syntax, and where this improves readability. Replace old-style lambdas with new-style lambdas or with partially applied named procedures. compiler/*.m: Conform to the changes in hlds_module.m. This mostly means using the new argument orders of predicates exported by hlds_module.m, and switching to state variable notation. Replace old-style lambdas with new-style lambdas or with partially applied named procedures in updated code. Replace unnecessary occurrences of four-space indentation with standard indentation in updated code. library/list.m: library/map.m: library/tree234.m: Add list__foldl4 and map__foldl3, since in some compiler modules, state variable notation is more convenient (and the code more efficient) if we don't have to bundle up several data structures into a tuple just to iterate over them. Change the fold predicates to use state variable notation. NEWS: Mention the new library functions. |
||
|
|
8693e293a2 |
This diff makes hlds_pred.m and many callers of its predicates easier to read
Estimated hours taken: 4 Branches: main This diff makes hlds_pred.m and many callers of its predicates easier to read and to maintain, but contains no changes in algorithms whatsoever. compiler/hlds_pred.m: Bring this module into line with our current coding standards. Use predmode declarations, functions, and state variable syntax when appropriate. Reorder arguments of predicates where necessary for the use of state variable syntax, and where this improves readability. Replace old-style lambdas with new-style lambdas or with partially applied named procedures. Standardize indentation. compiler/*.m: Conform to the changes in hlds_pred.m. This mostly means using the new argument orders of predicates exported by hlds_pred.m. Where this is now conveniently possible, change predicates to use state variable notation. In some modules, using state variable notation required changing the orders of arguments in the module's top predicate. compiler/passes_aux.m: Change the order of arguments in the calls this module makes to allow the callees to use state variable notation. Convert this module to state variable notation too. |
||
|
|
9551640f55 |
Import only one compiler module per line. Sort the blocks of imports.
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. |
||
|
|
129f605d25 |
Fix bugs in the handling of purity in the optimization passes
Estimated hours taken: 8
Branches: main, release
Fix bugs in the handling of purity in the optimization passes
(in particular constraint propagation), which caused purity
annotations on goals to be lost. This caused
tests/tabling/unused_args to fail on earth.
compiler/hlds_goal.m:
Make the version of goal_info_init called from
the optimization passes take the purity as an
argument. Previously, callers were constructing
a goal_info then adding the purity, which was
error prone.
compiler/hlds_goal.m:
compiler/purity.m:
Move the predicates to deal with purity representation
in hlds_goal_infos into hlds_goal.m. Rationale -
goal_info_get_determinism is not in det_analysis.m,
goal_info_get_nonlocals is not in quantification.m, etc.
This makes it easier to make the purity setting code
efficient.
Don't allocate memory in add_goal_info_purity_feature
if the call doesn't change the purity.
compiler/*.m:
Pass the extra argument to goal_info_init.
compiler/polymorphism.m:
Remove a duplicate definition of
hlds_goal__make_int_const_construction.
compiler/magic.m:
Remove some unused code.
tests/hard_coded/purity/Mmakefile:
tests/hard_coded/purity/Mercury.options:
tests/hard_coded/purity/purity_opt.{m,exp}:
Test case.
|
||
|
|
189b9215ae |
This diff implements stack slot optimization for the LLDS back end based on
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.
|
||
|
|
7597790760 |
Use sub-modules to structure the modules in the Mercury compiler directory.
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. |
||
|
|
82378c381b |
Allow polymorphic ground insts. This change assumes that all inst
Estimated hours taken: 80 Allow polymorphic ground insts. This change assumes that all inst parameters in the mode declaration for a predicate or function are constrained to be ground-shared. This is a temporary measure until we work out a nice syntax to allow the programmer to tell the compiler that certain inst parameters may be treated as ground insts. Since we don't currently support unconstrained inst parameters anyway, this shouldn't cause a problem. TODO: - Add syntax, something like `:- mode p(in(I)) <= ground(I).', to specify that an inst parameter represents a ground inst. - Allow abstract ground insts that are treated in a similar way to what we've done here with ground inst parameters. - Make mode checking more efficient (i.e. rewrite the mode system). compiler/inst.m: Add a new alternative for ground insts: `constrained_inst_var(inst_var)'. Define the type `inst_var_sub'. compiler/inst_match.m: Change inst_matches_initial so that it: - handles constrained_inst_vars correctly; - returns the inst_var substitutions necessary for the call; - handles inst_matches_initial(ground(...), bound(...), ...) properly (this requires knowing the type of the variable). The last change has also been made for inst_matches_final and inst_matches_binding. However, the check is disabled for now because, without alias tracking, the mode checker becomes too conservative. compiler/hlds_pred.m: compiler/mode_info.m: compiler/simplify.m: compiler/det_util.m: Include the inst_varset in the proc_info, mode_info and simplify_info. Add a vartypes field to the det_info. Remove the vartypes field from the simplify_info since it is now in the det_info. Use record syntax for these data structures and their access predicates to make future changes easier. compiler/prog_io.m: When processing pred and func mode declarations, convert all inst_var(V) insts to ground(shared, constrained_inst_var(V)). compiler/prog_data.m: compiler/hlds_data.m: compiler/make_hlds.m: compiler/mode_util.m: Use inst_vars instead of inst_params. compiler/modes.m: compiler/modecheck_call.m: compiler/unique_modes.m: compiler/mode_util.m: When checking or recomputing initial insts of a call, build up an inst_var substitution (using the modified inst_matches_initial) and apply this to the final insts of the called procedure before checking/recomputing them. compiler/mode_util.m: Make sure that recompute_instmap_delta recomputes the instmap_deltas for lambda_goals even when RecomputeAtomic = no. compiler/type_util.m: Add a new predicate, type_util__cons_id_arg_types which nondeterministically returns the cons_ids and argument types for a given type. Add a new predicate type_util__get_consid_non_existential_arg_types which is the same as type_util__get_existential_arg_types except that it fails rather than aborting for existenially typed arguments. compiler/accumulator.m: compiler/check_typeclass.m: compiler/clause_to_proc.m: compiler/common.m: compiler/continuation_info.m: compiler/deforest.m: compiler/det_analysis.m: compiler/det_report.m: compiler/det_util.m: compiler/dnf.m: compiler/follow_code.m: compiler/goal_store.m: compiler/goal_util.m: compiler/higher_order.m: compiler/inst_util.m: compiler/instmap.m: compiler/lambda.m: compiler/magic.m: compiler/magic_util.m: compiler/mercury_to_mercury.m: compiler/modecheck_unify.m: compiler/module_qual.m: compiler/pd_info.m: compiler/pd_util.m: compiler/polymorphism.m: compiler/post_typecheck.m: compiler/prog_io_util.m: compiler/prog_rep.m: compiler/saved_vars.m: compiler/stack_layout.m: compiler/table_gen.m: compiler/unify_proc.m: compiler/unneeded_code.m: compiler/unused_args.m: Pass inst_varsets and types where needed. Changes to reflect change in definition of the inst data type. compiler/inlining.m: Recompute the instmap deltas for a procedure after inlining. This bug showed up compiling tests/hard_coded/lp.m with inlining and deforestation turned on: deforestation was getting incorrect instmap deltas from inlining, causing the transformation to break mode-correctness. It has only just shown up because of the added call to `inst_matches_initial' from within `recompute_instmap_delta'. tests/invalid/Mmakefile: tests/invalid/unbound_inst_var.m: tests/invalid/unbound_inst_var.err_exp: tests/valid/Mmakefile: tests/valid/unbound_inst_var.m: Move the `unbound_inst_var' test case from `invalid' to `valid' and extend its coverage a bit. |
||
|
|
10a433374b |
Restore the clipping of instmap deltas to the nonlocals set, undoing most of
Estimated hours taken: 16 Restore the clipping of instmap deltas to the nonlocals set, undoing most of a recent change of mine. (The general cleanup parts of that change, e.g. added field names, stay.) The reason is that the previous diff changed the clipping algorithm only where the instmap deltas were being originally computed, whereas for completeness you also need to do this in places where they are recomputed after optimizations such as deforestation, and doing so would have required changes in several more parts of the compiler, which would have been tedious to maintain. Instead, I now use a different technique to solve the original problem. This technique is to change liveness.m so that it considers the first occurrence of any type(class)info variable to be a value giving occurrence even if the variable is not referred to by the instmap delta of the goal. This assumption is true in the current polymorphism design and in any extension of it that I can foresee. Type(class)info variables will therefore be born in the first goal that refers to them, even if they are not in the nonlocal set of that goal. If there are any later references to variables whose type is described in whole or in part by that typeinfo, the typeinfo will die at the last such reference, otherwise it will die in the goal in which it is born. From now on, the only module of the compile which needs to worry about the extension of the life of type(class)info variables beyond the goals referring to them is liveness.m. compiler/quantification.m: compiler/mode_info.m: compiler/mode_util.m: Reset the interfaces of quantification and mode checking to the old ones, which do not require knowing typeinfo_liveness and typeinfo varmaps. compiler/modes.m: compiler/unique_modes.m: Clip instmap deltas to the nonlocals, not the completed nonlocals. compiler/hlds_goal.m: Add a utility pred which gets the nonlocals from a goal, not a goal_info. compiler/liveness.m: Add special handling for type(class)info vars as described above. compiler/accumulator.m: compiler/cse_detection.m: compiler/deforest.m: compiler/follow_code.m: compiler/higher_order.m: compiler/lambda.m: compiler/magic.m: compiler/make_hlds.m: compiler/pd_util.m: compiler/polymorphism.m: compiler/saved_vars.m: compiler/simplify.m: compiler/unify_proc.m: compiler/unify_proc.m: compiler/unneeded_code.m: compiler/unused_args.m: Use the reset interfaces of quantification and mode checking, and eliminate redundant local copies of goal_get_nonlocals. |
||
|
|
891b89e650 |
Make sure that all parts of the compiler use a consistent idea of which
Estimated hours taken: 4 Make sure that all parts of the compiler use a consistent idea of which predicates should have typeinfo liveness applied to their bodies when the relevant option is set. This set is all predicates except the few in the builtin modules which do not have the required arguments. compiler/hlds_pred.m: Expand the interface of the should_use_typeinfo_liveness family of predicates to include an id of the predicate in question, to enable them to test whether the pred is a no_type_info_builtin. compiler/hlds_pred.m: compiler/polymorphism.m: Move the list of no_type_info_builtins from polymorphism to hlds_pred, since body_should_use_typeinfo_liveness also needs it now. compiler/*.m: Minor changes to pass the right arguments to predicates of the should_use_typeinfo_liveness family, directly or indirectly. |
||
|
|
a0a6daa06f |
If we are using typeinfo liveness, then clip the instmap delta fields in
Estimated hours taken: 16 If we are using typeinfo liveness, then clip the instmap delta fields in goal_infos not to the nonlocals, but to the nonlocals plus the type info or typeclass info variables needed to describe the types of the nonlocals (this set is now called the "typeinfo completed nonlocals"). This is necessary for the proper handling of code such as resume_typeinfos.m in tests/debugger. This involves a call to a procedure with an existentially typed argument, where the returned argument is processed only in ways that do not need the typeinfo describing it. The compiler therefore considered the typeinfo to be local to the call binding it. Its binding was therefore not recorded in the instmap delta, which in turn meant that in the absence of a value-giving occurrence, liveness.m considered it not to be born anywhere. On the other hand, with typeinfo liveness, occurrences of the argument are also considered value-using occurrences of the typeinfo, so the typeinfo was considered to die at the last such occurrence. Therefore the typeinfo died without being born. The current code generator is sloppy enough not to mind this, but the upcoming eager code generator isn't. compiler/hlds_goal.m: Document the new semantics of instmap_deltas. compiler/quantification.m: compiler/mode_util.m: compiler/modes.m: compiler/unique_modes.m: If typeinfo liveness is set, include the relevant typeinfo variables in the set of variables the instmap is limited to. compiler/modes.m: Delete some unused predicates. compiler/hlds_pred.m: Centralize the code for (maybe) completing a set of vars with the set of typeinfo vars describing their types here. compiler/call_gen.m: compiler/live_vars.m: Use the central code in hlds_pred.m. compiler/accumulator.m: compiler/cse_detection.m: compiler/follow_code.m: compiler/higher_order.m: compiler/lambda.m: compiler/liveness.m: compiler/magic.m: compiler/make_hlds.m: compiler/mode_info.m: compiler/pd_util.m: compiler/polymorphism.m: compiler/simplify.m: compiler/unify_proc.m: compiler/unneeded_code.m: compiler/unused_args.m: Call quantification and/or mode_util with the right arguments. In some cases, introduce field names, predmode declarations and/or shorter type names to make this change easier. |
||
|
|
2174d2bd8c |
Fixed a bug where extras/trailed_update/var.m was failing.
Estimated hours taken: 1
Fixed a bug where extras/trailed_update/var.m was failing.
accumulator.m:
In identify_recursive_calls add the constraint that the key must
come from the recursive case.
|
||
|
|
6a46f91412 |
Recalculate the non-locals of the original procedure.
Estimated hours taken: 1
compiler/accumulator.m:
Recalculate the non-locals of the original procedure.
This avoids a problem where an incorrect non-locals set was causing
shadowed variables to be created in the hlc grade for the ite.m test
case.
|
||
|
|
3ea503b60a |
Introduce accumulators into predicates which have if-then-elses and
Estimated hours taken: 4
Introduce accumulators into predicates which have if-then-elses and
disjunctions.
mercury/compiler/accumulator.m:
Introduce accumulators into predicates which have if-then-elses and
disjunctions.
mercury/compiler/options.m:
Add the --introduce-accumulators option at -O3.
tests/general/accumulator/Mmakefile:
The tests no longer require that unused arg elimination needs to be
turned off.
Add the two new tests.
tests/general/accumulator/func.m:
tests/general/accumulator/func.exp:
Add a test case, which makes sure that functions can have
accumulators introduced.
tests/general/accumulator/ite.m:
tests/general/accumulator/ite.exp:
Add a test case for if-then-elses.
tests/general/accumulator/runtests:
Modify the runtests script so that we cut out line number
information from the predicate names. This should mean that the
INTRODUCED file should change less often.
tests/general/accumulator/INTRODUCED:
Add the two new tests results, and cut the line numbers out of all
the old results.
|
||
|
|
e78799f435 |
Call implicitly_quantify_clause_body on the accumulator version of
Estimated hours taken: 1
compiler/accumulator.m:
Call implicitly_quantify_clause_body on the accumulator version of
the procedure. This ensures that the nonlocals of the procedure are
correct. This change fixes a bug where the MLDS backend generated
shadowed variables, for procedures which had accumulators
introduced.
|
||
|
|
05042c60ca |
Rewrite the accumulator introduction algorithm, so that it is a
Estimated hours taken: 70
Rewrite the accumulator introduction algorithm, so that it is a
combination of the algorithms presented in "Making Mercury Programs Tail
Recursive" and "State Update Transformation".
compiler/accumulator.m:
Rewrite and fix two bugs.
The bugs fixed were
* construction unifications which depend on associative calls
are handled correctly (not a problem in 0.9.x as the only
associative call it handled was list__append).
* that commutativity implied associativity, now check to see
whether an associative predicate has the addition property of
commutativity.
compiler/assertion.m:
assertion__is_associativity_assertion now reports the output
variable which is constructed from the two associative input
variables. It can now also handle the case where there is no
explicit existential quantification.
Add assertion__is_construction_equivalence_assertion which
recognises when a predicate is equivalent with a constrution
unification.
Add assertion__is_update_assertion which recognises when a predicate
can update some state in an arbitary order.
compiler/goal_store.m:
A module to associate arbitrary Ids with a hlds_goal and the instmap
before the goal.
library/int.m:
Add associativity declarations for + and *.
library/list.m:
Add the law
:- promise all [L,H,T] ( L = [H|T] <=> list__append([H], T, L)).
|
||
|
|
36985f7773 |
The goal_info of the initial call to the introduced predicate had
Estimated hours taken: 0.5
mercury/compiler/accumulator.m:
The goal_info of the initial call to the introduced predicate had
the incorrect set of nonlocals causing problems for deforestation.
|
||
|
|
d79cc30587 |
Recognise associativity assertions, and use them to introduce
Estimated hours taken: 35
Recognise associativity assertions, and use them to introduce
accumulators.
mercury/compiler/assertion.m:
Add assertion__is_associativity_assertion, which for an assert_id
determines whether the assertion is associative.
mercury/compiler/accumulator.m:
Call assertion__is_associativity_assertion to determine whether a
call is associative.
Rather than failing if a call is associative and nothing is known
about the effect of rearranging the argument order, report a
suppressible warning.
Fix a bug where the mode of the introduced pred wasn't correct.
mercury/compiler/mercury_compile.m:
Move accumulator introduction before inlining and unused_args, as
inlining can inline an associative call making it unrecognisable and
unused_args eliminates arguments which make it difficult to relate
the assertion with the actual call.
mercury/compiler/notes/compiler_design.html:
Document the constraints on when the module accumulator.m can be
called for it to be effective.
mercury/compiler/options.m:
Add the new option "--inhibit-accumulator-warnings".
mercury/doc/user_guide.texi:
Document "--inhibit-accumulator-warnings".
mercury/library/list.m:
Declare list__append to be associative.
tests/general/accumulator/runtests:
Turn the tests back on, they *should* work under different
optimization levels now.
tests/warnings/Mmakefile:
tests/warnings/arg_order_rearrangment.exp:
tests/warnings/arg_order_rearrangment.m:
Test that a warning is output when accumulator introduction reorders
the arguments to a call without knowing the performance
implications.
|
||
|
|
79ab7d373d |
Extend the assertion system by
Estimated hours taken: 56
Extend the assertion system by
* handling assertions in the interface of a module differently to
those in the implementation.
* testing an assertion for the commutivity property.
compiler/polymorphism.m:
Remove the resolving of function calls and data constructors, do it
in post_typecheck instead so that assertions are fully resolved.
compiler/post_typecheck.m:
Add the resolving of function calls and data constructors.
Also call assertion__in_interface_check, if an assertion is in the
interface.
compiler/purity.m:
post_typecheck__finish_assertion can now print error messages so
pass the io__states.
compiler/hlds_data.m:
Add assertion_table_pred_ids, so that intermod knows which pred_ids
are assertions.
compiler/hlds_out.m:
Add predicate hlds_out__write_assertion, which is used by intermod
to write assertions to .opt files.
Change the behaviour of outputing a call, so that if the call is a
function it gets written out in functional syntax. This is
necessary because the resolving of function symbols now occurs in
post_typecheck (pre writing .opt files) rather than in polymorphism
(post writing .opt files).
compiler/intermod.m:
Change intermod so that it writes out any assertion in the
interface to the .opt file.
compiler/modules.m:
Ensure that assertions in the interface are not written to the
.int files. Assertions should only appear in .opt files.
compiler/dead_proc_elim.m:
When intermodule optimization is turned on dead_proc_elim gets run
before typechecking and the assertion predicates are removed. This
change makes dead_proc_elim keep assertions.
compiler/make_hlds.m:
The head variables for an assertion are already known, so initialise
the clause_info structure to those variables rather then creating
Arity fresh variables.
Also don't insert unifications with the head of the assertion, since
we already know that only variables are in the head.
compiler/goal_util.m:
Add mode `goal_calls_pred_id(in, out) is nondet' for use by
assertion__record_preds_used_in.
compiler/assertion.m:
Add a predicate assertion__is_comutativity_assertion, which given
an assertion_id determines whether or not that assertion declares
the commutivity of a pred/func.
Add a predicate assertion__in_interface_check, which checks that an
assertion doesn't refer to any constructors, functions and
predicates defined in the implementation of that module (note
doesn't handle modules imported in the implementation section
correctly).
Rewrite assertion__record_preds_used_in to use the nondet mode of
goal_calls_pred_id.
compiler/accumulator.m:
Remove the facts which declare '+' and '*' to be commutative, and
instead use the new assertion__is_commutivity_assertion predicate.
Also remove the bool from assoc_fact which is the commutivity of the
predicate, since only associative predicates reside in the table
now.
library/int.m:
Add commutivity declarations for '+' and '*', now that they have
been removed from the assoc_fact table. This allows me to test that
all of these changes actually work!
compiler/hlds_goal.m:
Clear up the documentation (I hope) for the type call_unify_context,
so that it is clear that the unification may also have been a
function application.
doc/reference_manual.texi:
doc/transition_guide.texi:
Document assertions.
|
||
|
|
88c3e52881 |
Record in which predicate an assertion is used.
Estimated hours taken: 8
Record in which predicate an assertion is used.
compiler/accumulator.m:
compiler/lambda.m:
compiler/magic.m:
Initialise the assertions field in the new pred_info.
compiler/assertion.m:
An abstract interface to the assertion table (hopefully).
compiler/hlds_data.m:
Modify assertion_table_add_assertion to return the assert_id of the
inserted assertion.
compiler/hlds_pred.m:
Record in the pred_info the set of assertions that mention the pred.
compiler/post_typecheck.m:
Now record which predicates are used in assertions.
compiler/notes/compiler_design.html:
Document assertion.m
|
||
|
|
2725b1a331 |
Aditi update syntax, type and mode checking.
Estimated hours taken: 220
Aditi update syntax, type and mode checking.
Change the hlds_goal for constructions in preparation for
structure reuse to avoid making multiple conflicting changes.
compiler/hlds_goal.m:
Merge `higher_order_call' and `class_method_call' into a single
`generic_call' goal type. This also has alternatives for the
various Aditi builtins for which type declarations can't
be written.
Remove the argument types field from higher-order/class method calls.
It wasn't used often, and wasn't updated by optimizations
such as inlining. The types can be obtained from the vartypes
field of the proc_info.
Add a `lambda_eval_method' field to lambda_goals.
Add a field to constructions to identify which RL code fragment should
be used for an top-down Aditi closure.
Add fields to constructions to hold structure reuse information.
This is currently ignored -- the changes to implement structure
reuse will be committed to the alias branch.
This is included here to avoid lots of CVS conflicts caused by
changing the definition of `hlds_goal' twice.
Add a field to `some' goals to specify whether the quantification
can be removed. This is used to make it easier to ensure that
indexes are used for updates.
Add a field to lambda_goals to describe whether the modes were
guessed by the compiler and may need fixing up after typechecking
works out the argument types.
Add predicate `hlds_goal__generic_call_id' to work out a call_id
for a generic call for use in error messages.
compiler/purity.m:
compiler/post_typecheck.m:
Fill in the modes of Aditi builtin calls and closure constructions.
This needs to know which are the `aditi__state' arguments, so
it must be done after typechecking.
compiler/prog_data.m:
Added `:- type sym_name_and_arity ---> sym_name/arity'.
Add a type `lambda_eval_method', which describes how a closure
is to be executed. The alternatives are normal Mercury execution,
bottom-up execution by Aditi and top-down execution by Aditi.
compiler/prog_out.m:
Add predicate `prog_out__write_sym_name_and_arity', which
replaces duplicated inline code in a few places.
compiler/hlds_data.m:
Add a `lambda_eval_method' field to `pred_const' cons_ids and
`pred_closure_tag' cons_tags.
compiler/hlds_pred.m:
Remove type `pred_call_id', replace it with type `simple_call_id',
which combines a `pred_or_func' and a `sym_name_and_arity'.
Add a type `call_id' which describes all the different types of call,
including normal calls, higher-order and class-method calls
and Aditi builtins.
Add `aditi_top_down' to the type `marker'.
Remove `aditi_interface' from type `marker'. Interfacing to
Aditi predicates is now handled by `generic_call' hlds_goals.
Add a type `rl_exprn_id' which identifies a predicate to
be executed top-down by Aditi.
Add a `maybe(rl_exprn_id)' field to type `proc_info'.
Add predicate `adjust_func_arity' to convert between the arity
of a function to its arity as a predicate.
Add predicates `get_state_args' and `get_state_args_det' to
extract the DCG state arguments from an argument list.
Add predicate `pred_info_get_call_id' to get a `simple_call_id'
for a predicate for use in error messages.
compiler/hlds_out.m:
Write the new representation for call_ids.
Add a predicate `hlds_out__write_call_arg_id' which
replaces similar code in mode_errors.m and typecheck.m.
compiler/prog_io_goal.m:
Add support for `aditi_bottom_up' and `aditi_top_down' annotations
on pred expressions.
compiler/prog_io_util.m:
compiler/prog_io_pragma.m:
Add predicates
- `prog_io_util:parse_name_and_arity' to parse `SymName/Arity'
(moved from prog_io_pragma.m).
- `prog_io_util:parse_pred_or_func_name_and_arity to parse
`pred SymName/Arity' or `func SymName/Arity'.
- `prog_io_util:parse_pred_or_func_and_args' to parse terms resembling
a clause head (moved from prog_io_pragma.m).
compiler/type_util.m:
Add support for `aditi_bottom_up' and `aditi_top_down' annotations
on higher-order types.
Add predicates `construct_higher_order_type',
`construct_higher_order_pred_type' and
`construct_higher_order_func_type' to avoid some code duplication.
compiler/mode_util.m:
Add predicate `unused_mode/1', which returns `builtin:unused'.
Add functions `aditi_di_mode/0', `aditi_ui_mode/0' and
`aditi_uo_mode/0' which return `in', `in', and `out', but will
be changed to return `di', `ui' and `uo' when alias tracking
is implemented.
compiler/goal_util.m:
Add predicate `goal_util__generic_call_vars' which returns
any arguments to a generic_call which are not in the argument list,
for example the closure passed to a higher-order call or
the typeclass_info for a class method call.
compiler/llds.m:
compiler/exprn_aux.m:
compiler/dupelim.m:
compiler/llds_out.m:
compiler/opt_debug.m:
Add builtin labels for the Aditi update operations.
compiler/hlds_module.m:
Add predicate predicate_table_search_pf_sym, used for finding
possible matches for a call with the wrong number of arguments.
compiler/intermod.m:
Don't write predicates which build `aditi_top_down' goals,
because there is currently no way to tell importing modules
which RL code fragment to use.
compiler/simplify.m:
Obey the `cannot_remove' field of explicit quantification goals.
compiler/make_hlds.m:
Parse Aditi updates.
Don't typecheck clauses for which syntax errors in Aditi updates
are found - this avoids spurious "undefined predicate `aditi_insert/3'"
errors.
Factor out some common code to handle terms of the form `Head :- Body'.
Factor out common code in the handling of pred and func expressions.
compiler/typecheck.m:
Typecheck Aditi builtins.
Allow the argument types of matching predicates to be adjusted
when typechecking the higher-order arguments of Aditi builtins.
Change `typecheck__resolve_pred_overloading' to take a list of
argument types rather than a `map(var, type)' and a list of
arguments to allow a transformation to be performed on the
argument types before passing them.
compiler/error_util.m:
Move the part of `report_error_num_args' which writes
"wrong number of arguments (<x>; expected <y>)" from
typecheck.m for use by make_hlds.m when reporting errors
for Aditi builtins.
compiler/modes.m:
compiler/unique_modes.m:
compiler/modecheck_call.m:
Modecheck Aditi builtins.
compiler/lambda.m:
Handle the markers for predicates introduced for
`aditi_top_down' and `aditi_bottom_up' lambda expressions.
compiler/polymorphism.m:
Add extra type_infos to `aditi_insert' calls
describing the tuple to insert.
compiler/call_gen.m:
Generate code for Aditi builtins.
compiler/unify_gen.m:
compiler/bytecode_gen.m:
Abort on `aditi_top_down' and `aditi_bottom_up' lambda
expressions - code generation for them is not yet implemented.
compiler/magic.m:
Use the `aditi_call' generic_call rather than create
a new procedure for each Aditi predicate called from C.
compiler/rl_out.pp:
compiler/rl_gen.m:
compiler/rl.m:
Move some utility code used by magic.m and call_gen.m into rl.m.
Remove an XXX comment about reference counting being not yet
implemented - Evan has fixed that.
library/ops.m:
compiler/mercury_to_mercury.m:
doc/transition_guide.texi:
Add unary prefix operators `aditi_bottom_up' and `aditi_top_down',
used as qualifiers on lambda expressions.
Add infix operator `==>' to separate the tuples in an
`aditi_modify' call.
compiler/follow_vars.m:
Thread a `map(prog_var, type)' through, needed because
type information is no longer held in higher-order call goals.
compiler/table_gen.m:
Use the `make_*_construction' predicates in hlds_goal.m
to construct constants.
compiler/*.m:
Trivial changes to add extra fields to hlds_goal structures.
doc/reference_manual.texi:
Document Aditi updates.
Use @samp{pragma base_relation} instead of
@samp{:- pragma base_relation} throughout the Aditi documentation
to be consistent with other parts of the reference manual.
tests/valid/Mmakefile:
tests/valid/aditi_update.m:
tests/valid/aditi.m:
Test case.
tests/valid/Mmakefile:
Remove some hard-coded --intermodule-optimization rules which are
no longer needed because `mmake depend' is now run in this directory.
tests/invalid/*.err_exp:
Fix expected output for changes in reporting of call_ids
in typecheck.m.
tests/invalid/Mmakefile
tests/invalid/aditi_update_errors.{m,err_exp}:
tests/invalid/aditi_update_mode_errors.{m,err_exp}:
Test error messages for Aditi updates.
tests/valid/aditi.m:
tests/invalid/aditi.m:
Cut down version of extras/aditi/aditi.m to provide basic declarations
for Aditi compilation such as `aditi__state' and the modes
`aditi_di', `aditi_uo' and `aditi_ui'. Installing extras/aditi/aditi.m
somewhere would remove the need for these.
|
||
|
|
cba483823e |
Very minor code reordering.
Estimated hours taken: 0.1
compiler/accumulator.m:
Very minor code reordering.
|
||
|
|
ec86c88404 |
Merge in the changes from the existential_types_2 branch.
Estimated hours taken: 4 Merge in the changes from the existential_types_2 branch. This change adds support for mode re-ordering of code involving existential types. The change required modifying the order of the compiler passes so that polymorphism comes before mode analysis, so that mode analysis can check the modes of the `type_info' or `typeclass_info' variables that polymorphism introduces, so that it can thus re-order the code accordingly. This change also includes some more steps towards making existential data types work. In particular, you should be able to declare existentially typed data types, the compiler will generate appropriate unification and compare/3 routines for them, and deconstruction unifications for them should work OK. However, currently there's no way to construct them except via `pragam c_code', and we don't generate correct RTTI for them, so you can't use `io__write' etc. on them. library/private_builtin.m: compiler/accumulator.m: compiler/bytecode_gen.m: compiler/check_typeclass.m: compiler/clause_to_proc.m: compiler/code_util.m: compiler/common.m: compiler/dead_proc_elim.m: compiler/dependency_graph.m: compiler/det_analysis.m: compiler/det_report.m: compiler/follow_code.m: compiler/follow_vars.m: compiler/goal_util.m: compiler/higher_order.m: compiler/hlds_goal.m: compiler/hlds_out.m: compiler/hlds_pred.m: compiler/intermod.m: compiler/lambda.m: compiler/live_vars.m: compiler/magic.m: compiler/make_hlds.m: compiler/mercury_compile.m: compiler/mercury_to_c.m: compiler/mode_errors.m: compiler/mode_info.m: compiler/mode_util.m: compiler/modecheck_call.m: compiler/modecheck_unify.m: compiler/modes.m: compiler/pd_cost.m: compiler/polymorphism.m: compiler/post_typecheck.m: compiler/purity.m: compiler/quantification.m: compiler/rl_exprn.m: compiler/rl_key.m: compiler/simplify.m: compiler/table_gen.m: compiler/term_traversal.m: compiler/type_util.m: compiler/typecheck.m: compiler/unify_gen.m: compiler/unify_proc.m: compiler/unique_modes.m: compiler/unused_args.m: compiler/notes/compiler_design.html: doc/reference_manual.texi: tests/hard_coded/typeclasses/Mmakefile: tests/hard_coded/typeclasses/existential_data_types.m: tests/hard_coded/typeclasses/existential_data_types.exp: tests/warnings/simple_code.exp: tests/hard_coded/Mmakefile: tests/term/arit_exp.trans_opt_exp: tests/term/associative.trans_opt_exp: tests/term/pl5_2_2.trans_opt_exp: tests/term/vangelder.trans_opt_exp: tests/term/arit_exp.trans_opt_exp: tests/term/associative.trans_opt_exp: tests/term/pl5_2_2.trans_opt_exp: tests/term/vangelder.trans_opt_exp: tests/invalid/errors2.err_exp2: tests/invalid/prog_io_erroneous.err_exp2: tests/invalid/type_inf_loop.err_exp2: tests/invalid/types.err_exp2: tests/invalid/polymorphic_unification.err_exp: tests/invalid/Mmakefile: tests/warnings/simple_code.exp: tests/debugger/queens.exp: tests/hard_coded/Mmakefile: tests/hard_coded/existential_reordering.m: tests/hard_coded/existential_reordering.exp: Merge in the changes from the existential_types_2 branch. |
||
|
|
2a67dd0888 |
Add the ability to add accumulators to if-then-elses and disjunctions.
Estimated hours taken: 10
compiler/accumulator.m:
Add the ability to add accumulators to if-then-elses and disjunctions.
|
||
|
|
8ab130a3b0 |
Add a new pass to the compiler, that attempts to introduce accumulators
Estimated hours taken: 500
Add a new pass to the compiler, that attempts to introduce accumulators
into a procedure so as to make that procedure tail recursive.
WORK_IN_PROGRESS:
Document that the transformation now exists.
compiler/goal_util.m:
Create goal_util__can_reorder_goals, which is a version of
pd_util__can_reorder_goals that will work on the alias branch.
compiler/instmap.m:
Add instmap__changed_vars. This predicate is meant to provide the
same functionality as instmap_delta_changed_vars, but work on the
alias branch.
Also add comment to instmap_delta_changed_vars about using
instmap_changed_vars
compiler/accumulator.m:
The transformation.
compiler/mercury_compile.m:
Call the transformation.
compiler/options.m:
Add the option to turn the transformation on.
doc/user_guide.texi:
Document the option.
profiler/demangle.m:
util/mdemangle.c:
Demangle the accumulator version of the procedure labels.
compiler/notes/compiler_design.html:
Add the new pass to the documentation.
|