mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-18 07:15:19 +00:00
faa18a15bd332b51ec6d6fdae4d999ec2bf3fa82
112 Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
459847a064 |
Move the univ, maybe, pair and unit types from std_util into their own
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. |
||
|
|
12deb40264 |
Rename all the get access predicates in these modules that don't
Estimated hours taken: 0.1 Branches: main compiler/hlds_clauses.m: compiler/hlds_pred.m: Rename all the get access predicates in these modules that don't already have put "get" in their name. (The names of the set access predicates were OK already.) compiler/*.m: Conform to the above. All this was done by this sed script: s/clauses_info_varset/clauses_info_get_varset/ s/clauses_info_explicit_vartypes/clauses_info_get_explicit_vartypes/ s/clauses_info_vartypes/clauses_info_get_vartypes/ s/clauses_info_headvars/clauses_info_get_headvars/ s/clauses_info_clauses_rep/clauses_info_get_clauses_rep/ s/clauses_info_rtti_varmaps/clauses_info_get_rtti_varmaps/ s/pred_info_import_status/pred_info_get_import_status/ s/pred_info_arg_types/pred_info_get_arg_types/ s/pred_info_typevarset/pred_info_get_typevarset/ s/pred_info_tvar_kinds/pred_info_get_tvar_kinds/ s/pred_info_procedures/pred_info_get_procedures/ s/proc_info_context/proc_info_get_context/ s/proc_info_varset/proc_info_get_varset/ s/proc_info_vartypes/proc_info_get_vartypes/ s/proc_info_headvars/proc_info_get_headvars/ s/proc_info_inst_varset/proc_info_get_inst_varset/ s/proc_info_maybe_declared_argmodes/proc_info_get_maybe_declared_argmodes/ s/proc_info_argmodes/proc_info_get_argmodes/ s/proc_info_maybe_arglives/proc_info_get_maybe_arglives/ s/proc_info_declared_determinism/proc_info_get_declared_determinism/ s/proc_info_inferred_determinism/proc_info_get_inferred_determinism/ s/proc_info_goal/proc_info_get_goal/ s/proc_info_can_process/proc_info_get_can_process/ s/proc_info_rtti_varmaps/proc_info_get_rtti_varmaps/ s/proc_info_eval_method/proc_info_get_eval_method/ s/proc_info_is_address_taken/proc_info_get_is_address_taken/ s/proc_info_stack_slots/proc_info_get_stack_slots/ s/proc_info_liveness_info/proc_info_get_liveness_info/ s/proc_info_context/proc_info_get_context/ s/proc_info_context/proc_info_get_context/ s/proc_info_context/proc_info_get_context/ s/proc_info_context/proc_info_get_context/ s/proc_info_context/proc_info_get_context/ s/proc_info_context/proc_info_get_context/ s/proc_info_context/proc_info_get_context/ |
||
|
|
3ebda6545f |
Move the stuff currently in hlds_pred.m that deals with clauses into a new
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. |
||
|
|
be5b71861b |
Convert almost all the compiler modules to use . instead of __ as
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. |
||
|
|
5b8f96f61d |
Prepare for an extension of promise_equivalent_solutions that will allow us
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). |
||
|
|
5af71b60ac |
Remove support for the Aditi backend. It is a pain to have to update it every
Estimated hours taken: 2 Branches: main Remove support for the Aditi backend. It is a pain to have to update it every time a data structure changes when we don't see any benefit from it, and its presence makes compilation of the compiler directory take about 10% longer (since the Aditi backend modules are roughly 10% of the code in the compiler directory). Deleting the Aditi-specific data structures from the HLDS should also speed up compilation a little bit. I have spoken to Rao and he is fine with this step. Aditi users, if there are any, can continue to use the Aditi support in release 0.12.*. I also tagged the last version on the trunk to support aditi with the name "last_aditi". The need for modifications in this Aditi support is likely to be very rare to nonexistent, if the recent past is any guide: the Aditi backend hasn't seen a nontrivial modification in a year or more. This diff removes a net 31492 lines. compiler/add_aditi.m: compiler/aditi_backend.pp: compiler/aditi_builtin_ops.m: compiler/context.m: compiler/dnf.m: compiler/magic.m: compiler/magic_util.m: compiler/rl.m: compiler/rl_analyse.m: compiler/rl_block.m: compiler/rl_block_opt.m: compiler/rl_code.m: compiler/rl_dump.m: compiler/rl_exprn.m: compiler/rl_file.pp: compiler/rl_gen.m: compiler/rl_info.m: compiler/rl_key.m: compiler/rl_liveness.m: compiler/rl_loop.m: compiler/rl_opt.m: compiler/rl_out.pp: compiler/rl_relops.m: compiler/rl_sort.m: compiler/rl_stream.m: Remove these compiler modules, since they existed only to support the Aditi backend. compiler/hlds_goal.m: Delete the Aditi-specific components of goals (e.g. the aditi-builtin kind of generic calls and Aditi-evaluated lambdas). compiler/hlds_pred.m: Delete the Aditi-specific components of pred_infos. compiler/prog_data.m: Delete the Aditi-specific items. compiler/passes_aux.m: Don't worry about processing all procedures or just all non-Aditi procedures. compiler/add_clause.m: Add a predicate from a deleted module that is now used only here. compiler/*.m: Conform to the data structure changes above. compiler/notes/*.html: Remove references to the Aditi backend. tests/invalid/aditi.m: tests/invalid/aditi_errors.err_exp: tests/invalid/aditi_errors.m: tests/invalid/aditi_private_builtin.m: tests/invalid/aditi_state_errors.err_exp: tests/invalid/aditi_state_errors.m: tests/invalid/aditi_update_derived_relation.err_exp: tests/invalid/aditi_update_derived_relation.m: tests/invalid/aditi_update_errors.err_exp: tests/invalid/aditi_update_errors.m: tests/invalid/aditi_update_mode_errors.err_exp: tests/invalid/aditi_update_mode_errors.m: tests/valid/aditi.m: tests/valid/aditi_calls_mercury.m: tests/valid/aditi_error_bug.m: tests/valid/aditi_error_bug2.m: tests/valid/aditi_error_bug3.m: tests/valid/aditi_private_builtin.m: tests/valid/aditi_query.m: tests/valid/aditi_update.m: tests/valid/base_relation.m: tests/valid/base_relation2.m: tests/valid/ite_to_disj.m: Remove these Aditi-specific tests. tests/*/Mmakefile: Remove the references to these Aditi-specific tests. |
||
|
|
45fdb6c451 |
Use expect/3 in place of require/2 throughout most of the
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. |
||
|
|
5f589e98fb |
Various cleanups for the modules in the compiler directory.
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. |
||
|
|
f9fe8dcf61 |
Improve the error messages generated for determinism errors involving committed
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.
|
||
|
|
b2012c0c0e |
Rename the types 'type', 'inst' and 'mode' to 'mer_type', 'mer_inst'
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'. |
||
|
|
b54ab42d70 |
A simple tool for performing substitutions on the source files of the
Estimated hours taken: 0.5 Branches: main tools/subst: A simple tool for performing substitutions on the source files of the compiler. compiler/*.m: Change the names of the get predicates operating on module_infos to include "get" in the name, for uniformity. This was done mostly by the following sed script, with some manual cleanup afterwards to reduce excessive line lengths. s/module_info_types/module_info_get_type_table/ s/module_info_set_types/module_info_set_type_table/ s/module_info_insts/module_info_get_inst_table/ s/module_info_set_insts/module_info_set_inst_table/ s/module_info_modes/module_info_get_mode_table/ s/module_info_set_modes/module_info_set_mode_table/ s/module_info_ctors/module_info_get_cons_table/ s/module_info_set_ctors/module_info_set_cons_table/ s/module_info_classes/module_info_get_class_table/ s/module_info_set_classes/module_info_set_class_table/ s/module_info_instances/module_info_get_instance_table/ s/module_info_set_instances/module_info_set_instance_table/ s/module_info_superclasses/module_info_get_superclass_table/ s/module_info_set_superclasses/module_info_set_superclass_table/ s/module_info_assertion_table/module_info_get_assertion_table/ s/module_info_exclusive_table/module_info_get_exclusive_table/ s/module_info_ctor_field_table/module_info_get_ctor_field_table/ s/module_info_name/module_info_get_name/ s/module_info_globals/module_info_get_globals/ s/module_info_contains_foreign_types/module_info_get_contains_foreign_types/ s/module_info_num_errors/module_info_get_num_errors/ s/module_info_type_ctor_gen_infos/module_info_get_type_ctor_gen_infos/ s/module_info_stratified_preds/module_info_get_stratified_preds/ s/module_info_unused_arg_info/module_info_get_unused_arg_info/ s/module_info_exception_info/module_info_get_exception_info/ s/module_info_type_spec_info/module_info_get_type_spec_info/ s/module_info_no_tag_types/module_info_get_no_tag_types/ s/module_info_analysis_info/module_info_get_analysis_info/ s/module_info_aditi_top_down_procs/module_info_get_aditi_top_down_procs/ |
||
|
|
6df9a05856 |
This diff cleans up a bunch of modules. It has no algorithmic changes
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. |
||
|
|
0a58be4096 |
Fix several performance problems that arose when compiling predicates defined
Estimated hours taken: 10
Branches: main
Fix several performance problems that arose when compiling predicates defined
by lots of facts, e.g. 16000 facts of the edge relation used in my recent
paper with Kostis on tabling. We couldn't use fact tables because they return
solutions in a different order, which would be OK semantically but which
invalidated the performance comparison we tried to make. I had to either fix
fact tables to use standard order or fix the performance problems of the usual
path of compilation. The latter is more generally useful, and reduces the
chances of any similar surprises.
The first performance problem was the quadratic complexity of always adding
clauses at the end of the clause list. The fix is to keep the list in reverse
order while it is being added to. This takes the time to read in the 16000-fact
predicate from 80+s to ~1s.
The second performance problem was our use of generate/test to check whether
any clause had impure code when copying the clauses to procs. Since we don't
have tail recursion for model_non code, this couldn't reuse stack frames, and
as a result ran at memory speed, not cache speed. The fix is to use an explicit
recursive predicate. (A better fix would be to implement proper tail recursion
for model_non code, but that would take significantly longer.) This fix
doesn't make much difference in the usual grades, but makes a significant
difference in debug grades.
The third performance problem is the quadratic or worse behavior of the mode
checker when merging the instmaps of disjuncts at the ends of large
disjunctions. With our old setup, this was inevitable, since given a bunch of
facts of the form
edge(1, 2).
edge(2, 3).
edge(3, 4).
...
etc, the instmap delta the mode checker builds for HeadVar__1 for the
disjunction of clauses is free -> bound(1; 2; 3; ...). The solution to that
is to add a new pragma, mode_check_clauses, that causes the mode checker
to check each clause individually, and to create a simple free -> ground
(or whatever the declared mode calls for) instmap delta for HeadVar__1.
We should consider making this pragma be implied for predicates defined
by lots of facts, but this diff does not do that. This change takes the
time to modecheck that 16000-fact predicate from ~360s to ~5s.
Theoretically, another way of tackling the problem would have been to
introduce widening, in which any list of functors inside "bound()" whose
length was above the threshold would be replaced by "ground", if the arguments
of the functors themselves were bound. However, that change would be much more
complex, and its behavior would be hard for users to predict. In a future
constraint-based mode system with separate passes for computing
producers/consumers and for computing the set of function symbols a
variable can be bound to, we could simply disable the latter pass
for predicates like this.
There are at least three other performance problems left. The fourth is
the same as the third, except for unique mode checking. The fifth is in
simplification, and the sixth is in equiv_type_hlds. I'll work on those next.
compiler/hlds_pred.m:
Instead of exposing the clause list part of the clause_info, make it
an abstract type. Make the abstract type keep the reverse list when
adding clauses to the list, the forward list when the later parts
of the compiler manipulate the clause list, and both when it is
convenient to do so. Add the predicates necessary to manipulate
this more complex representation. Move the code manipulating
clauses_infos into its own implementation section, next to its
declarations.
Add a new mode_check_clauses predicate marker, which records the
presence of the new pragma.
Fix departures from our coding standard.
compiler/clause_to_proc.m:
Replace the generate/test code with an explicit loop, as
mentioned above.
compiler/prog_data.m:
Add the new pragma.
compiler/prog_io_pragma.m:
Recognize the new pragma.
compiler/modes.m:
Implement separate mode checking of clauses.
Convert the file to use four-space indentation to reduce the number of
bad line breaks. Give some predicates more meaningful names.
Use error_util to print some error messages. Fix departures from
our coding standard.
compiler/make_hlds.m:
compiler/hlds_out.m:
compiler/intermod.m:
compiler/mercury_to_mercury.m:
compiler/module_qual.m:
compiler/modules.m:
compiler/recompilation.version.m:
Handle the new pragma.
compiler/*.m:
Conform to the change in hlds_pred.m and/or prog_data.m.
In some cases, convert files to four-space indentation.
tests/hard_coded/mode_check_clauses.{m,exp}:
A new test case to check that the mode_check_clauses pragma works
correctly.
tests/hard_coded/Mmakefile:
Enable the new test case.
|
||
|
|
d075d35702 |
Implement functional dependencies for the typeclass system.
Estimated hours taken: 240 Branches: main Implement functional dependencies for the typeclass system. The implementation has two major parts. First, some of the basic checks of constraints are relaxed. These used to occur in make_hlds but that functionality has now been moved to check_typeclass. We also add a range of new tests to ensure that the FDs are used correctly. Second, an "improvement" pass to context reduction is added. This looks for constraints which match certain rules, and when it finds them updates the current bindings. The general rule is that type variables become more instantiated, but only in a way which provably does not affect the satisfiability of the constraints. XXX The plan for this change is to put the context reduction into a new module check_hlds.typeclasses.m, but I have left the code in typecheck.m for the moment because the diff will be easier to review that way. Moving to the new module will also remove the problem of one particular function being implemented in both typecheck and hlds_data, which is flagged by an XXX in the code. XXX the check for consistency of instances is not yet complete. We check all visible instances, but not instances that are only present at link time. We could check these in a similar way to the check for overlapping instances (that is, by defining a symbol that will conflict and cause a link error if there are overlapping instances), but in the long run a better solution will be required. Producing this is left for a later change. compiler/check_typeclass.m: Check for ambiguities in typeclass constraints here, rather than make_hlds. We check by calculating the closure of the bound type variables under the induced functional dependencies. This pass is merged in with the already existing pass that checks the quantifiers on constrained type variables. Check instances for range-restrictedness and for consistency. When checking for cycles in the typeclass hierarchy, build up the set of ancestors of a class which have FDs on them. This set is used when searching for opportunities to apply improvement rules during type checking. compiler/hlds_data.m: Define hlds_class_fundeps and add it to to hlds_class_defn. Add a field to hlds_class_defn to store the ancestors which have functional dependencies. Define the type 'instance_id', which is just an integer. This is what is used in proofs to identify instances. In hlds_constraints and in constraint_ids, use the terms 'assumed' and 'unproven' rather than 'existential' and 'universal'. The latter are confusing to use since the treatment of constraints differs depending on whether the constraint is on the head or the body of a clause. Add a field to the hlds_constraints for redundant constraints. These are constraints that have either already been reduced or don't need to be reduced, which may contribute to improvement of types. Define some new predicates for initialising and updating the hlds_constraints. compiler/type_util.m: Accommodate the change to hlds_constraints. compiler/hlds_out.m: Output the functional dependencies. compiler/intermod.m: Reconstruct a functional dependency from the HLDS, for outputting. compiler/make_hlds.m: Convert functional dependencies from parse tree form and add them to the HLDS. Check that functional dependencies are identical in subsequent definitions of the same typeclass. Don't check for ambiguity here. That is now done in check_typeclass. compiler/mercury_to_mercury.m: Output functional dependencies in typeclass declarations. compiler/prog_data.m: Define prog_fundeps and add them to the parse tree. compiler/prog_io_typeclass.m: Parse functional dependencies on typeclass declarations. compiler/typecheck.m: Require the class_table to be passed to reduce_context_by_rule_application, since the functional dependencies are stored here. Also thread the bindings argument through, since the bindings may be improved by context reduction. Save the resulting bindings in the type_assign. Instead of passing a list of assumed constraints and threading the unproven constraints through context reduction, thread through a hlds_constraints structure. This contains more information about redundant constraints than just the two lists. Extend context reduction with two new passes. The first applies the "class" FD rule, which tries to find two constraints which are identical on the domain of some FD, and then unifies the range arguments. The pair of constraints are either both redundant constraints, or one redundant constraint and one assumed constraint. The second applies the "instance" FD rule, which for each constraint tries to find an instance which is more general on the domain arguments. It then binds the instance arguments and unifies the range arguments of the instance with those of the constraint. When calculating the head_type_params for a predicate, include all variables that occur in universal constraints, since these may not necessarily occur in the arguments. Rename some variables: use variable prefixes "Pred" and "Parent" for types that are from the callee or that have been renamed apart respectively. This follows the same naming scheme used in polymorphism. Remove the headtypes/0 type, and use head_type_params/0 throughout. Add a new kind of cons_error for using "new" on a constructor that is not existentially typed. We check for this situation in convert_cons_defn, and report it in report_cons_error. Pass a value to convert_cons_defn indicating whether the constraints should be flipped or not, and whether the context is a constructor that uses 'new'. We flip the constraints here rather than after the fact, since creating the constraints now requires some extra processing to be done, and we don't want to have to redo that processing. Add a constant function that specifies whether variable numbers should be displayed as part of the debugging output. This is currently set to 'yes' but the previous behaviour can be achieved by changing the value to 'no'. doc/reference_manual.texi: Document the new feature. NEWS: Announce the new feature. tests/*: New test cases. compler/*.m: Minor changes related to the above. compiler/error_util.m: Fix comment grammar. compiler/prog_type.m: Fix an incorrect comment. |
||
|
|
34d5181f3a |
Bring these modules up to date with our current style guidelines.
Estimated hours taken: 4 Branches: main compiler/mercury_to_mercury.m: compiler/make.dependencies.m: compiler/make.module_target.m: compiler/make.module_dep_file.m: compiler/make.util.m: compiler/make.m: Bring these modules up to date with our current style guidelines. Use predmode declarations where appropriate. Use state variable syntax where appropriate. Switch to four-space indentation where this reduces the number of places with excessive indentation. Use explicit predicates instead of lambda expressions where appropriate. compiler/*.m: Minor style fixes. |
||
|
|
8b8b3b7d3f |
Replace the some() HLDS goal with a more general scope() goal, which can be
Estimated hours taken: 12
Branches: main
Replace the some() HLDS goal with a more general scope() goal, which can be
used not just for existential quantification but also for other purposes.
The main such purposes are new goal types that allow the programmer
to annotate arbitrary goals, and not just whole procedure bodies, with the
equivalents of promise_pure/promise_semipure and promise_only_solution:
promise_pure ( <impure/semipure goal> )
promise_semipure ( <impure goal> )
promise_equivalent_solutions [OutVar1, OutVar2] (
<cc_multi/cc_nondet goal that computed OutVar1 & OutVar2>
)
Both are intended to be helpful in writing constraint solvers, as well as in
other situations.
doc/reference_manual.texi:
Document the new constructs.
library/ops.m:
Add the keywords of the new constructs to the list of operators.
Since they work similarly to the "some" operator, they have the same
precedence.
compiler/hlds_goal.m:
Replace the some(Vars, SubGoal) HLDS construct, with its optional
keep_this_commit attribute, with the new scope(Reason, SubGoal)
construct. The Reason argument may say that this scope is an
existential quantification, but it can also say that it represents
a purity promise, the introduction of a single-solution context
with promise_equivalent_solutions, or a decision by a compiler pass.
It can also say that the scope represents a set of goals that all arise
from the unraveling of a unification between a variable and a ground
term. This was intended to speed up mode checking by significantly
reducing the number of delays and wakeups, but the cost of the scopes
themselves turned out to be bigger than the gain in modechecking speed.
Update the goal_path_step type to refer to scope goals instead of just
existential quantification.
compiler/prog_data.m:
Add new function symbols to the type we use to represent goals in items
to stand for the new Mercury constructs.
compiler/prog_io_goal.m:
Add code to read in the new language constructs.
compiler/prog_io_util.m:
Add a utility predicate for use by the new code in prog_io_goal.m.
compiler/make_hlds.m:
Convert the item representation of the new constructs to the HLDS
representation.
Document how the from_ground_term scope reason would work, but do not
enable the code.
compiler/purity.m:
When checking the purity of goals, respect the new promise_pure and
promise_semipure scopes. Generate warnings if such scopes are
redundant.
compiler/det_analysis.m:
Make the insides of promise_equivalent_solutions goals single solution
contexts.
compiler/det_report.m:
Provide mechanisms for reporting inappropriate usage of
promise_equivalent_solutions goals.
compiler/instmap.m:
Add a utility predicate for use by one of the modules above.
compiler/deep_profiling.m:
Use one of the new scope reasons to prevent simplify from optimizing
away commits of goals that have been made impure, instead of the old
keep_this_commit goal feature.
compiler/modes.m:
Handle from_ground_term scopes when present; for now, they won't be
present, since make_hlds isn't creating them.
compiler/options.m:
Add two new compiler options, for use by implementors only, to allow
finer control over the amount of output one gets with --debug-modes.
(I used them when debugging the performance of the from_ground_term
scope reason.) The options are --debug-modes-minimal and
--debug-modes-verbose.
compiler/handle_options.m:
Make the options that are meaningful only in the presence of
--debug-modes imply --debug-modes, since this allows more convenient
(shorter) invocations.
compiler/mode_debug.m:
Respect the new options when deciding how much data to print
when debugging of the mode checking process is enabled.
compiler/switch_detect.m:
Rename a predicate to make it differ from another predicate by more
than just its arity.
compiler/passes_aux.m:
Bring this module up to date with our current style guidelines,
by using state variable syntax where appropriate.
compiler/*.m:
Minor changes to conform to the change in the HLDS and/or parse tree
goal type.
mdbcomp/program_representation.m:
Rename the some goal to the scope goal, and the same for path steps,
to keep them in sync with the HLDS.
browser/declarative_tree.m:
Conform to the change in goal representations.
tests/hard_coded/promise_equivalent_solutions_test.{m,exp}:
A new test case to test the handling of the
promise_equivalent_solutions construct.
tests/hard_coded/Mmakefile:
Enable the new test.
tests/hard_coded/purity/promise_pure_test.{m,exp}:
A new test case to test the handling of the promise_pure and
promise_semipure constructs.
tests/hard_coded/purity/Mmakefile:
Enable the new test.
tests/invalid/promise_equivalent_solutions.{m,err_exp}:
A new test case to test the error messages for improper use of the
promise_pure and promise_semipure constructs.
tests/invalid/Mmakefile:
Enable the new test.
|
||
|
|
c08ca7fbc8 |
Import only one module per line in the modules of the compiler
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. |
||
|
|
9521818650 |
Get the purity check pass to not issue warnings about unnecessary purity
Estimated hours taken: 16 Branches: main Get the purity check pass to not issue warnings about unnecessary purity annotations on compiler-generated predicates. The problem I am addressing is that when an optimization such as type specialization creates a clone of a predicate, that predicate gets all the original predicate's annotations. During the creation of a .opt file, purity checking sees the clauses of the original predicate and knows that the annotation is not redundant, but doesn't know that about the copy, since it has no definition at all (it doesn't need one). The fix is to put into each pred_info an indication of where the predicate came from, and to never warn about unnecessary purity annotations of predicates that the programmer didn't write. This diff also uses the origin indication to record human-usable names of compiler-generated or compiler-transformed predicates in RTTI for use by the debugger. compiler/hlds_pred.m: Replace two fields in pred_infos, that say (a) whether the predicate is a special (unify/compare/index/init) predicate and (b) whether it is a type class method implementation, with an origin field saying where the predicate came from. This field has several alternatives, special preds and type class method implementation being only two. Make the predicates that create pred_infos take an argument specifing where the predicate comes from. Replace a copy of one of the old fields in rtti_proc_labels with the new one. Make the name of the existing function more descriptive. compiler/purity.m: Use the origin field to suppress unnecessary annotation warnings for compiler-generated predicates. compiler/layout_out.m: Use the origin field to generate more human-friendly names for predicates, instead of the existing linker-friendly names. The debugger doesn't insist on predicate names being unique, even within a module. compiler/*.m: Conform to the changed interface of hlds_pred.m. The most significant changes were for recording the origin of new predicates. In one case (dnf.m) it also involved passing the required information down to the place where the new predicates were created through the dnf_info tuple instead of separate arguments, and switching to state variable notation. tests/debugger/*.exp*: tests/debugger/declarative/*.exp*: tests/hard_coded/*.exp*: Update the expected outputs to expect human-friendly predicate names. |
||
|
|
59d2d4a573 |
This adds a module mdbcomp__trace_counts that reads in the
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. |
||
|
|
9187c0d911 |
Bring these modules up to date with our current style guidelines.
Estimated hours taken: 8 Branches: main compiler/hlds_out.m: compiler/llds_out.m: Bring these modules up to date with our current style guidelines. Use state variables in the few places where we weren't doing so already. compiler/purity.m: Bring this module up to date with our current style guidelines. Use the predicates of error_util and hlds_error_util to print error messages. Be more consistent in using quotations. Fix indentation. compiler/error_util.m: Add a long needed facility: the ability to glue some punctuation at the end of a previous word. Add a mechanism for turning a list of components into a string, instead of printing them out. Make the interface of this module more consistent by making list_to_pieces a function just like component_lists_to_pieces. compiler/hlds_error_util.m: Change the way we describe predicates and procedures. Instead of returning their descriptions as single fixed strings that error_util can't break up across lines, return them as separate components that can be split across lines. This makes error output look nicer. Fix a mismatch between what were supposed to be corresponding pieces of code in hlds_error_util and hlds_out. Turn the appropriate predicates into functions. compiler/*.m: Conform to the changed interfaces of some of the above modules. tests/invalid/*.err_exp: tests/invalid/purity/*.err_exp: tests/recompilation/*.err_exp: tests/warnings/*.exp: Update the expected outputs for the better looking error messages we now generate. |
||
|
|
885fd4a387 |
Remove almost all dependencies by the modules of parse_tree.m on the modules
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. |
||
|
|
7bf0cd03af |
Reduce the overhead of all forms of tabling by eliminating in many cases
Estimated hours taken: 32
Branches: main
Reduce the overhead of all forms of tabling by eliminating in many cases
the overhead of transferring data across the C/Mercury boundary. These
involve lots of control transfers as well as assignments to and from
Mercury abstract machine registers, which are not real machine registers
on x86 machines. Benchmarking in Uppsala revealed this overhead to be
a real problem.
The way we do that is by changing the tabling transformation so that instead
of generating sequences of calls to predicates from library/table_builtin.m,
we generate sequences of calls to C macros from runtime/mercury_tabling_pred.h,
and emit the resulting code string as the body of a foreign_proc goal.
(The old transformation is still available via a new option,
--no-tabling-via-extra-args.)
Since the number of inputs and outputs of the resulting C code sequences
are not always fixed (they can depend on the number of input or output
arguments of predicate being transformed), implementing this required
adding to foreign_procs a new field that allows the specification of extra
arguments to be passed to and from the given foreign code fragment. For now,
this mechanism is implemented only by the C backends, since it is needed
only by the C backends. (We don't support yet tabling on other backends.)
To simplify the new implementation of the field on foreign_procs, consolidate
three existing fields into one. Each of these fields was a list with one
element per argument, so turning them into a single list with a combined record
per argument should also improve reliability, since it reduces the likelyhood
of updates leaving the data structure inconsistent.
The goal paths of components of a tabled predicate depend on whether
-no-tabling-via-extra-args was specified. To enable the expected outputs
of the debugger test cases testing tabling, we add a new mdb command,
goal_paths, that controls whether goal paths are printed by the debugger
at events, and turn off the printing of events in the relevant test cases.
Also, prepare for a future change to optimize the trie structure for
user-defined types by handling type_infos (and once we support them,
typeclass_infos) specially.
compiler/table_gen.m:
Change the tabling transformation along the lines described above.
To allow us to factor out as much of the new code as possible,
we change the meaning of the call_table_tip variable for minimal
model subgoals: instead of the trie node at the end of the answer
table, it is not now the subgoal reachable from it. This change
has no effect as yet, because we use call_table_tip variables
only to perform resets across retries in the debugger, and we
don't do retries across calls to minimal model tabled predicates.
Put predicates into logical groups.
library/table_builtin.m:
runtime/mercury_tabling_preds.h:
When the new transformations in table_gen.m generate foreign_procs
with variable numbers of arguments, the interfaces of those
foreign_procs often do not match the interfaces of the existing
library predicates at their core: they frequently have one more
or one fewer argument. To prevent any possible confusion, in such
cases we add a new variant of the predicate. These predicates
have the suffix _shortcut in their name. Their implementations
are dummy macros that do nothing; they serve merely as placeholders
before or after which the macros that actually do the work are
inserted.
Move the definitions of the lookup, save and restore predicates
into mercury_tabling_preds.h. Make the naming scheme of their
arguments more regular.
runtime/mercury_minimal_model.c:
runtime/mercury_tabling_preds.h:
Move the definition of a predicate from mercury_minimal_model.c
to mercury_tabling_preds.h, since the compiler now needs to be
able to generate an inlined version of it.
compiler/hlds_goal.m:
Replace the three existing fields describing the arguments of
foreign_procs with one, and add a new field describing the extra
arguments that may be inserted by table_gen.m.
Add utility predicates for processing the arguments of foreign_procs.
Change the order of some existing groups of declarations make it
more logical.
compiler/hlds_pred.m:
runtime/mercury_stack_layout.h:
Extend the data structures recording the structure of tabling tries
to allow the representation of trie steps for type_infos and
typeclass_infos.
runtime/mercury_tabling_macros.c:
Fix a bug regarding the tabling of typeclass_infos, which is now
required for a clean compile.
compiler/pragma_c_gen.m:
compiler/ml_code_gen.m:
Modify the generation of code for foreign_procs to handle extra
arguments, and to conform to the new data structures for foreign_proc
arguments.
compiler/llds.m:
The tabling transformations can now generate significantly sized
foreign_procs bodies, which the LLDS code generator translates to
pragma_c instructions. Duplicating these by jump optimization
may lose more by worsening locality than it gains in avoiding jumps,
so we add an extra field to pragma_c instructions that tells jumpopt
not to duplicate code sequences containing such pragma_cs.
compiler/jumpopt.m:
Respect the new flag on pragma_cs.
compiler/goal_util.m:
Add a predicate to create foreign_procs with specified contents,
modelled on the existing predicate to create calls.
Change the order of the arguments of that existing predicate
to make it more logical.
compiler/polymorphism.m:
Conform to the new definition of foreign_procs. Try to simplify
the mechanism for generating the type_info and typeclass_info
arguments of foreign_proc goals, but it is not clear that this
code is even ever executed.
compiler/aditi_builtin_ops.m:
compiler/assertion.m:
compiler/bytecode_gen.m:
compiler/clause_to_proc.m:
compiler/code_gen.m:
compiler/code_info.m:
compiler/code_util.m:
compiler/constraint.m:
compiler/deep_profiling.m:
compiler/deforest.m:
compiler/delay_construct.m:
compiler/dependency_graph.m:
compiler/det_analysis.m:
compiler/det_report.m:
compiler/dnf.m:
compiler/dupelim.m:
compiler/equiv_type_hlds.m:
compiler/exprn_aux.m:
compiler/follow_code.m:
compiler/follow_vars.m:
compiler/frameopt.m:
compiler/goal_form.m:
compiler/goal_path.m:
compiler/higher_order.m:
compiler/higher_order.m:
compiler/hlds_module.m:
compiler/hlds_out.m:
compiler/inlining.m:
compiler/ite_gen.m:
compiler/layout_out.m:
compiler/livemap.m:
compiler/liveness.m:
compiler/llds_out.m:
compiler/loop_inv.m:
compiler/magic.m:
compiler/make_hlds.m:
compiler/mark_static_terms.m:
compiler/middle_rec.m:
compiler/modes.m:
compiler/modules.m:
compiler/opt_debug.m:
compiler/pd_cost.m:
compiler/prog_rep.m:
compiler/purity.m:
compiler/quantification.m:
compiler/reassign.m:
compiler/rl_exprn.m:
compiler/saved_vars.m:
compiler/simplify.m:
compiler/size_prof.m:
compiler/store_alloc.m:
compiler/stratify.m:
compiler/switch_detection.m:
compiler/term_pass1.m:
compiler/term_traversal.m:
compiler/termination.m:
compiler/trace.m:
compiler/typecheck.m:
compiler/unify_proc.m:
compiler/unique_modes.m:
compiler/unneeed_code.m:
compiler/unused_args.m:
compiler/use_local_vars.m:
Conform to the new definition of foreign_procs, pragma_cs and/or
table trie steps, or to changed argument orders.
compiler/add_heap_ops.m:
compiler/add_trail_ops.m:
compiler/cse_detection.m:
compiler/dead_proc_elim.m:
compiler/equiv_type.m:
compiler/intermod.m:
compiler/lambda.m:
compiler/lco.m:
compiler/module_util.m:
compiler/opt_util.m:
compiler/stack_opt.m:
compiler/trans_opt.m:
Conform to the new definition of foreign_procs.
Bring these modules up to date with our current code style guidelines,
using predmode declarations, state variable syntax and unification
expressions as appropriate.
compiler/mercury_compile.m:
Conform to the changed argument order of a predicate in trans_opt.m.
compiler/options.m:
Add the --no-tabling-via-extra-args option, but leave the
documentation commented out since the option is for developers only.
doc/user_guide.texi:
Document --no-tabling-via-extra-args option, though leave the
documentation commented out since the option is for developers only.
doc/user_guide.texi:
doc/mdb_categories:
Document the new goal_paths mdb command.
trace/mercury_trace_internals.c:
Implement the new goal_paths mdb command.
tests/debugger/completion.exp:
Conform to the presence of the goal_paths mdb command.
tests/debugger/mdb_command_test.inp:
Test the existence of documentation for the goal_paths mdb command.
tests/debugger/print_table.{inp,exp*}:
tests/debugger/retry.{inp,exp*}:
Use the goal_paths command to avoid having the expected output
depend on the presence or absence of --tabling-via-extra-args.
tests/tabling/table_foreign_output.{m,exp}:
Add a new test case to test the save/restore of arguments of foreign
types.
tests/tabling/Mmakefile:
Enable the new test case.
tests/tabling/test_tabling:
Make this script more robust.
Add an option for testing only the standard model forms of tabling.
|
||
|
|
bc56e927b6 |
Detect when a predicate has a pair of I/O states but isn't det or cc_multi.
Estimated hours taken: 6 Branches: main Detect when a predicate has a pair of I/O states but isn't det or cc_multi. Improve the generation of determinism error messages. compiler/det_analysis.m: Detect when a predicate has a pair of I/O states but isn't det or cc_multi. Factor out some common code. compiler/det_report.m: Add the new error type for predicates with I/O states. Use error_util much more extensively to generate error messages. compiler/hlds_out.m: For several existing predicates that write out various HLDS constructs, provide versions that return representations of those constructs as strings or as error_util pieces, for use by det_report.m. Redefine the old predicates as simply printing the output of the new predicates where relevant, to avoid code duplication. compiler/error_util.m: When describing a predicate name, specify whether we want to module qualify the name or not. The intention is that when generating a kind of error message which can only be generated for predicates defined in the current module, the module prefix should be omitted in the interest of clarity. compiler/accumulator.m: compiler/dead_proc_elim.m: compiler/magic_util.m: compiler/table_gen.m: compiler/term_errors.m: compiler/termination.m: compiler/typecheck.m: Conform to the changes in error_util.m. compiler/globals.m: Reorder arguments to allow the use of state variable notation. compiler/handle_globals.m: compiler/mercury_compile.m: compiler/source_file_map.m: Conform to the changed argument order in globals.m. tests/invalid/aditi_update_errors.err_exp: tests/invalid/errors2.err_exp2: tests/invalid/external.err_exp: tests/invalid/ho_unique_error.err_exp: tests/invalid/magicbox.err_exp: tests/invalid/missing_det_decls.err_exp: tests/invalid/mostly_uniq1.err_exp: tests/invalid/mostly_uniq2.err_exp: tests/invalid/multimode_syntax.err_exp: tests/invalid/multisoln_func.err_exp: tests/invalid/pragma_c_code_dup_var.err_exp: tests/invalid/pragma_c_code_no_det.err_exp: tests/invalid/prog_io_erroneous.err_exp2: tests/invalid/qualified_cons_id2.err_exp: tests/invalid/record_syntax_errors.err_exp: tests/invalid/state_vars_test1.err_exp: tests/invalid/state_vars_test2.err_exp: tests/invalid/state_vars_test3.err_exp: tests/invalid/typeclass_mode.err_exp: tests/invalid/types.err_exp2: tests/invalid/undef_mode_and_no_clauses.err_exp: tests/recompilation/typeclass_method_pragma_r.err_exp.2: tests/warnings/ambiguous_overloading.exp: tests/warnings/duplicate_call.exp: tests/warnings/duplicate_const.exp: tests/warnings/infinite_recursion.exp: tests/warnings/simple_code.exp: tests/warnings/warn_dead_procs.exp: tests/warnings/warn_stubs.exp: Update these files to expect the better error messages we now generate. |
||
|
|
ff60134ee9 |
Bring these modules up to our current coding standards.
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. |
||
|
|
5d6fd3bd6f |
Reduce the dependence of earlier parts of the compiler on the later ones.
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. |
||
|
|
c91313b32f |
Bring these modules up to date with our current coding style.
Estimated hours taken: 8
Branches: main
compiler/modules.m:
compiler/compile_target_code.m:
compiler/handle_options.m:
compiler/bytecode_data.m:
compiler/prog_io_util.m:
Bring these modules up to date with our current coding style. Use
predmode declarations and state variable syntax where appropriate.
Fix inconsistent indentation. Print more error messages using
error_util.m for printing error messages.
compiler/trace_param.m:
Add a new predicate for use by the updated code in handle_options.m.
compiler/error_util.m:
compiler/hlds_error_util.m:
Make error_util.m to be a submodule of parse_tree.m, not hlds.m.
Most of its predicates are not dependent on HLDS data structures.
Move the ones that are into a new module, hlds_error_util, that
is a submodule of hlds.m. Overall, this reduces the dependence
of submodules of parse_tree.m, including modules.m, on submodules
of hlds.m.
compiler/notes/compiler_design.html:
Update the documentation of compiler modes to account for
hlds_error_util.m.
compiler/hlds.m:
compiler/parse_tree.m:
Update the list of included submodules.
compiler/*.m:
Update module imports and module qualifications as needed for the
change above.
tests/invalid/*.{exp,exp2}:
Update the expected outputs of a bunch of test cases to reflect the new
format of some warning messages due to the user error_util; they now
observe line length limits, and print contexts in some cases where they
were previously missing.
|
||
|
|
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. |
||
|
|
a2bf36e49a |
This diff contains no changes in algorithms whatsoever.
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. |
||
|
|
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. |
||
|
|
c3bc0286d7 |
Add a new warning option `--warn-dead-procs' that warns about procedures
Estimated hours taken: 8 Branches: main Add a new warning option `--warn-dead-procs' that warns about procedures which are never called. doc/user_guide.texi: Document the new option. compiler/options.m: Add the new option. compiler/mercury_compile.m: If the new option is enabled, invoke dead_proc_elim to issue warnings for dead procedures. (The new pass occurs after type_ctor_info generation, but before higher-order specialization and inlining.) compiler/dead_proc_elim.m: Add a new `dead_proc_pass' argument to the dead_proc_elim predicate, specifying whether it should issue warnings or just do the optimizations. If this argument is warning_pass, issue warnings for dead procedures with import_status local (except for automatically generated procedures) and don't eliminate opt_imported procedures. compiler/magic.m: Pass the new argument to dead_proc_elim. tests/warnings/Mmakefile: tests/warnings/warn_dead_procs.m: tests/warnings/warn_dead_procs.exp: A test case to test the new warning. |
||
|
|
d7aafc7b38 |
Delete the const_addr cons_id and the code_addr_constant tag value,
Estimated hours taken: 0.2 Branches: main compiler/hlds_data.m: Delete the const_addr cons_id and the code_addr_constant tag value, since they have not been needed for a long time. The HLDS hasn't needed to handle raw code addresses since we stopped generating type_ctor_infos dynamically, and made them static data structures. The code address representations in the MLDS, LLDS and bytecode backends are still needed in the implementation of closures. compiler/bytecode.m: Delete the code_addr_const (the equivalent of the code_addr_constant tag value) in the bytecode representation, since it was used only to implement code_addr cons_ids; closures use pred_consts instead. compiler/*.m: Delete the code that dealt with the deleted function symbols as inputs (which in several cases threw exceptions anyway). |
||
|
|
6554ef7daa |
Replace "is" with "=".
Estimated hours taken: 2 Branches: main Replace "is" with "=". Add field names where relevant. Replace integers with counters where relevant. |
||
|
|
f7dba9b8f8 |
Change "compiler_generated" in predicate names and field names
Estimated hours taken: 0.5 Branches: main compiler/*.m: Change "compiler_generated" in predicate names and field names to "is_unify_or_compare_pred", because that is the actual meaning of those predicates and fields. Delete the XXXs warning about the old misleading name. |
||
|
|
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. |
||
|
|
efdaf1f224 |
Fix a performance bug where dead_pred_elim was taking a significant
Estimated hours taken: 6 Branches: main Fix a performance bug where dead_pred_elim was taking a significant amount of time to delete entries from the predicate_table. With this change dead_pred_elim goes from 12 minutes to 55 seconds CPU time in the IL grade when compiling accumulator.m with --intermodule-optimization turned on. compiler/hlds_module.m: Implement a new predicate, predicate_table_restrict, which restricts the predicate_table to include only a subset of the predicates. Rather than deleting all the non-needed entries, this predicate builds the predicate_table from scratch again, hence this predicate is only useful when the number of predicates to keep is significantly less than the number of predicates to delete. Change predicate_table_do_insert so that it records in the pred_info whether or not a predicate can only be accessed by its fully qualified name, this is needed so that the predicate_table can be rebuilt correctly. compiler/dead_proc_elim.m: Use predicate_table_restrict to restrict the set of pred_ids in the predicate_table rather than module_info_remove_predicate as the amount of predicates to keep is in general significantly smaller than the number of predicates to keep. compiler/hlds_pred.m: Add a new pred_marker which indicates whether or not a predicate can only be accessed by its fully qualified name. compiler/hlds_out.m: compiler/intermod.m: Handle the new pred_marker. |
||
|
|
9aeb2516ec |
Avoid dependencies on ll_backend.code_util in *hlds.*.
Estimated hours taken: 1 Branches: main Avoid dependencies on ll_backend.code_util in *hlds.*. compiler/code_util.m: compiler/hlds_pred.m: Move the predicates to identify builtins into hlds_pred.m. compiler/*.m: Update calls and remove unnecessary imports. |
||
|
|
660a24a7ad |
Fix a bug reported by Michael Day which caused spurious
Estimated hours taken: 8 Branches: main, release Fix a bug reported by Michael Day which caused spurious "predicate multiply defined" errors if there were predicates `module1.p' and `module2.module1.p'. compiler/hlds_module.m: For each of the predicate table search predicates which takes a module, add an extra argument which states whether the module name passed in is fully qualified. If it is, then a search for `module1.p' will not return `module2.module1.p'. The module name is guaranteed to be fully qualified for the head of predicate, clause, etc. items, and for calls occurring in `.opt' files. Add a predicate `lookup_builtin_pred_proc_id', for looking up the builtin predicates in the predicate table. compiler/goal_util.m: Move code to look up builtin predicates into hlds_module.m. Set the builtin_state field of the call goal returned by generate_simple_call correctly. compiler/hlds_pred.m: Add a function `calls_are_fully_qualified' which takes an import_status, and returns whether calls from goals with that status are always fully qualified, which is true iff the call is in a `.opt' file. compiler/prog_io.m: Module qualify the sym_names in `:- external' items. compiler/*.m: Fill in the extra argument of predicate table searches. Use `lookup_builtin_pred_proc_id' rather than `predicate_table_search_*'. compiler/prog_util.m: Add function versions of mercury_*_builtin_module. compiler/polymorphism.m: compiler/simplify.m: compiler/unify_proc.m: Use goal_util__generate_simple_call to call builtins, rather than duplicating the code. tests/valid/Mmakefile: tests/valid/nested_module_bug.m: tests/valid/intermod_bug_nested.m: Test cases. |
||
|
|
ef7ed9c2f5 |
Support impurity declarations for higher-order code.
Estimated hours taken: 24 Branches: main Support impurity declarations for higher-order code. In particular, allow `impure' and `semipure' annotations on higher-order types, higher-order calls, and lambda expresions. NEWS: doc/reference_manual.texi: Document the new language feature. compiler/hlds_goal.m: compiler/hlds_pred.m: Add `purity' field to - the `higher_order' alternative of the hlds_goal.generic_call type - the `higher_order' alternative of the hlds_pred.generic_call_id type - the `lambda_goal' alternative of the hlds_goal.unify_rhs type compiler/type_util.m: Add a new `purity' argument to the procedures dealing with higher-order types. Add code for parsing impure/semipure higher-order types. compiler/lambda.m: compiler/make_hlds.m: compiler/typecheck.m: compiler/post_typecheck.m: compiler/purity.m: compiler/polymorphism.m: Various minor changes to support impure/semipure higher-order lambda expressions. compiler/polymorphism.m: compiler/pseudo_type_info.m: XXX ought to change these to include purity in the RTTI for higher-order function types. compiler/simplify.m: Don't try to optimize semipure/impure higher-order calls. compiler/assertion.m: compiler/bytecode_gen.m: compiler/call_gen.m: compiler/continuation_info.m: compiler/cse_detection.m: compiler/dead_proc_elim.m: compiler/deep_profiling.m: compiler/det_analysis.m: compiler/det_util.m: compiler/equiv_type.m: compiler/goal_util.m: compiler/higher_order.m: compiler/hlds_out.m: compiler/intermod.m: compiler/magic.m: compiler/magic_util.m: compiler/ml_call_gen.m: compiler/ml_closure_gen.m: compiler/mode_util.m: compiler/modecheck_call.m: compiler/modecheck_unify.m: compiler/modes.m: compiler/module_qual.m: compiler/pd_util.m: compiler/prog_rep.m: compiler/pseudo_type_info.m: compiler/quantification.m: compiler/recompilation.usage.m: compiler/rl_gen.m: compiler/stratify.m: compiler/switch_detection.m: compiler/term_traversal.m: compiler/term_util.m: compiler/unify_gen.m: compiler/unique_modes.m: Trivial changes to handle the new purity fields and/or arguments. tests/hard_coded/purity/Mmakefile: tests/hard_coded/purity/impure_func_t5_fixed2.m: tests/hard_coded/purity/impure_func_t5_fixed2.exp: tests/hard_coded/purity/impure_func_t5_fixed2.exp2: tests/hard_coded/purity/impure_pred_t1_fixed3.m: tests/hard_coded/purity/impure_pred_t1_fixed3.exp: tests/invalid/purity/Mmakefile: tests/invalid/purity/impure_func_t5_fixed.m: tests/invalid/purity/impure_func_t5_fixed.err_exp: tests/invalid/purity/impure_pred_t1_fixed.m: tests/invalid/purity/impure_pred_t1_fixed.err_exp: Add new test cases to test the new feature. tests/invalid/purity/impure_func_t5.err_exp: tests/invalid/purity/impure_pred_t1.err_exp: tests/invalid/purity/impure_pred_t2.err_exp: tests/invalid/purity/purity.err_exp: tests/invalid/purity/purity_nonsense.err_exp: Update the expected error messages for existing test cases. tests/invalid/purity/.cvsignore: New file, copied from tests/invalid/.cvsignore. |
||
|
|
404abb0c57 |
Another step towards RTTI in Mercury.
Estimated hours taken: 32
Branches: main
Another step towards RTTI in Mercury.
This step redefines the representation of type_ctor_infos inside the compiler
to be identical to the representation we will need for efficient interpretation
of RTTI data structures in Mercury, following on from an earlier step which
did the same for (pseudo)typeinfos.
Instead of the type_ctor_info being broken down into its components in
type_ctor_info.m, the breakdown process is now performed in rtti_out.m (for the
LLDS backend) and rtti_to_mlds.m (for the MLDS backend). Eventually, the IL and
Java backends will stop using rtti_to_mlds.m for this purpose, and will instead
write out the type_ctor_data structures as static data to be interpreted
directly.
We now predefine the C types representing type_info and pseudo_type_infos
for types of arity up to 20 for the LLDS C backend as well as for the
MLDS C backend. The LLDS backend can define them for higher arities
on demand; the MLDS backend (for now) still cannot.
runtime/mercury_type_info.h:
To be able to represent all the kinds of types we now support
- add a data structure for converting values of reserved_addr types
from their printable representation to their internal representation
(it was previously missing), and
- add a type_ctor_rep to represent foreign types.
Add missing MR_ prefixes on some field names.
Add typedefs for all the types that the rtti_names can refer to.
There were already such typedefs in runtime/mercury.h for the MLDS
grades, we now have them for the LLDS grades too.
Predefine the C types representing type_info and pseudo_type_infos
for types of arity up to 20. There were already such typedefs in
runtime/mercury.h for the MLDS grades, we now have them for the
LLDS grades too.
runtime/mercury.h:
Delete the typedefs that are now in mercury_type_info.h.
runtime/mercury.h:
Delete the definitions of the C types representing type_info and
pseudo_type_infos, since these are now in mercury_type_info.h.
#include mercury_type_info.h.
compiler/rtti.m:
Add new, purely Mercury data structures for representing
type_ctor_infos and their components, designed both for efficient
interpretation and as a source for the generation of static data
structures in C.
This entailed deleting most of the alternatives of the rtti_data type
while preserving their rtti_name equivalents; the deleted alternatives
represent tables are no longer created in type_ctor_info.m but which
are created dynamically in rtti_out.m and rtti_to_mlds.m (which need
a way for one table to refer to another).
Centralize the correspondence between rtti_names and the C and Java
types of the corresponding structures (the C and Java names differ in
prefixes only). Among other things, this remove the double maintenance
problem we have previously with the LLDS and MLDS backends maintaining
their own maps of the correspondence.
Add utility predicates on the new data structures for use by both
rtti_out.m and rtti_to_mlds.m.
compiler/hlds_module.m:
Always store the ids of unification and comparison procedures in
type_ctor_gen_infos, to simplify their handling.
compiler/type_ctor_info.m:
Generate the new data structures for representing type_ctor_infos.
Conform to the changed data structures for type_ctor_gen_infos.
compiler/rtti_out.m:
compiler/rtti_to_mlds.m:
Rewrite substantial parts of these modules to convert the new data
structures for representing type_ctor_infos to sets of discrete
structures dynamically.
Most of the dynamically created structures are unique by construction,
but this is not true for typeinfos and pseudo-typeinfos. Therefore
add mechanisms to ensure that we don't generate redundant structures
representing typeinfos and pseudo-typeinfos.
compiler/mlds_to_c.m:
compiler/mlds_to_java.m:
Use the standard mechanisms for creating C and Java type names.
compiler/mlds_to_gcc.m:
Conform to the changed data structures in rtti.m and
mercury_type_info.h.
compiler/opt_debug.m:
Conform to the changed data structures in rtti.m.
compiler/dead_proc_elim.m:
Conform to the changed data structures for type_ctor_gen_infos.
compiler/pseudo_type_info.m:
Add a predicate to construct a representation of a type that may or may
not be ground.
compiler/mlds_to_gcc.m:
java/runtime/TypeCtorRep.java:
library/private_builtin.m:
library/rtti_implemenation.m:
runtime/mercury_mcpp.{cpp,h}:
Add the type_ctor_rep for foreign types to the lists of type_ctor_reps.
library/construct.m:
library/deconstruct.m:
Add missing MR_ prefixes on field names.
runtime/mercury_construct.c:
runtime/mercury_deconstruct.c:
runtime/mercury_deep_copy_body.h:
runtime/mercury_ml_expand_body.h:
runtime/mercury_tabling.c:
runtime/mercury_type_info.c:
runtime/mercury_unify_compare_body.h:
Handle the type_ctor_rep for foreign types.
Add missing MR_ prefixes on field names.
library/list.m:
Add two utility predicates, is_empty and is_not_empty, for use with
higher order code.
NEWS:
Mention the new predicates in list.m. Delete a duplicate entry.
|
||
|
|
9dbcf4714a |
Fix a bug which caused type-incorrect HLDS to be generated by mode
Estimated hours taken: 5
Branches: main
Fix a bug which caused type-incorrect HLDS to be generated by mode
analysis, which then caused a compiler abort in simplification.
In the code below, mode analysis must treat the headvar unification
as a construction followed by a var-var unification. If it is treated
as a deconstruction, the argument unifications will be ill-typed.
:- type t ---> some [T] f(T) => enum(T).
:- pred p(t::in) is semidet.
p('new f'(1)).
compiler/modecheck_unify.m:
Make sure unifications with a RHS of the form 'new f(X)'
are always classified as constructions.
compiler/hlds_goal.m:
compiler/*.m:
Add a field to var-functor unifications which identifies
those which must be treated as constructions.
compiler/polymorphism.m:
Fill in the field.
tests/hard_coded/Mmakefile:
tests/hard_coded/unify_existq_cons.{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. |
||
|
|
41a27af862 |
Change type_id to the more descriptive type_ctor everywhere.
Estimated hours taken: 6 Branches: main compiler/*.m: Change type_id to the more descriptive type_ctor everywhere. |
||
|
|
c0ec782364 |
Added initial error checking of promise ex declarations, and adding
Estimated hours taken: 150 Branches: main Added initial error checking of promise ex declarations, and adding the declarations into the HLDS as dummy predicates to leverage off the error checking done for predicates (similarly to how assertions were done). Following this, `promise_exclusive' and `promise_exclusive_exhaustive' declarations are added into a separate table in the HLDS. assertion.m: Moved the pred declaration for assertion__normalise_goal into the interface. goal_util.m: Added a predicate to get the predids of a goal or list of goals. hlds_data.m: hlds_module.m: Added exclusive_table to HLDS, and operations on it. hlds_out.m: Added printing of promise ex declaration error messages (also improves assertion error messages). hlds_pred.m: Change to type `goal_type' to add constructor for general promise declarations (merged with assertions). dead_proc_elim.m: error_util.m: intermod.m: typecheck.m: Updated to handle promise declarations similarly to how assertions were handled. make_hlds.m: Perform initial typechecking of promise ex declarations, then add them to the HLDS as dummy predicates. purity.m: post_typecheck.m: Post typechecking routine to add exclusivity declarations to the exclusive_table. |
||
|
|
b5c571c500 |
This is the first half of a change that removes redundant fields from
Estimated hours taken: 12 Branches: main This is the first half of a change that removes redundant fields from type_ctor_info structures. configure.in: Do not require an exact match on the RTTI version number. runtime/mercury_type_info.h: Update the RTTI version number. Add the new definition of type_ctor_infos. Add prefixes to the fields in type_ctor_infos that did not already have them. Provide macros to access the fields in the changed part of type_ctor_infos in a way that works with both the old and new type_ctor_info structures. Move some stuff so that macros that logically belong together are next to each other. runtime/mercury_mcpp.h: Update the RTTI version number and the macros for defining type_ctor_infos. library/rtti_implementation.m: Update the mechanism for access to type_ctor_info fields. Add prefixes to field names and use RTTI-version-independent macros as necessary. compiler/hlds_module.m: compiler/rtti.m: Delete obsolete fields from the terms from which type_ctor_info structures are derived. compiler/dead_proc_elim.m: Minor changes to conform to this change in data structure. compiler/type_ctor_info.m: Minor changes to conform to this change in data structure. Update the RTTI version number. compiler/rtti_out.m: compiler/rtti_to_mlds.m: Output the new type_ctor_info structure. compiler/llds_out.m: compiler/mlds_to_c.m: Emit a #define to select the new type_ctor_info structure. library/std_util.m: runtime/mercury.c: runtime/mercury_deconstruct.c: runtime/mercury_deep_copy_body.h: runtime/mercury_ho_call.c: runtime/mercury_ml_expand_body.h: runtime/mercury_tabling.c: runtime/mercury_type_info.c: runtime/mercury_type_tables.c: runtime/mercury_unify_compare_body.h: tests/hard_coded/type_tables.m: trace/mercury_trace.c: Add prefixes to field names and use RTTI-version-independent macros as necessary. |
||
|
|
cdbbaa5ac2 |
Support multiple language foreign_procs in the one file.
Estimated hours taken: 16 Branches: main Support multiple language foreign_procs in the one file. If there is more then one applicable foreign_proc for a given clause, select the most "preferred" programming language to use as the implementation. Currently only the IL backend has multiple languages supported by the backend, and C# is preferred over MC++. compiler/options.m: compiler/handle_options.m: Rename backend_foreign_language as backend_foreign_languages, and use it to record the list of foreign languages the selected backend can handle. Remove --use-foreign-language as it doesn't do anything right now. compiler/foreign.m: Update code to use the list of backend foreign languages. Add prefer_foreign_language function, to compute the preferred foreign language ordering for each backend. Move simple_foreign_language_string here from globals.m, and add foreign_language_file_extension and foreign_language_module_name functions. (much of the rest of the code in this module is intended to deal with the case where the backend *doesn't* handle the foreign language, but we don't have any working support for that at the moment). compiler/globals.m: Add globals__io_get_backend_foreign_languages and globals__get_backend_foreign_languages. compiler/make_hlds.m: Handle selection of foreign_proc code depending upon the preferred language. Rename a few *_foreign_code predicates as *_foreign_proc predicates. Handle the extra field in clause. compiler/ml_code_gen.m: compiler/mlds.m: Generate different mlds__foreign_code for each language (only one language is selected for each predicate, but there can be multiple languages in the onle module). and put them in a map which is indexed on foreign language. compiler/modules.m: Generate appropriate dependencies for foreign language modules. We now record which languages a list of items uses (taking into account the preferred foreign language for foreign_proc). We also allow for the fact that some foreign_proc declarations won't generate any external modules. compiler/hlds_pred.m: Add an extra field to clause which records which language this clause has been implemented in. compiler/assertion.m: compiler/clause_to_proc.m: compiler/dead_proc_elim.m: compiler/goal_util.m: compiler/hlds_out.m: compiler/inlining.m: compiler/intermod.m: compiler/modes.m: compiler/polymorphism.m: compiler/purity.m: compiler/typecheck.m: compiler/unify_proc.m: Handle the extra field in clause. compiler/mlds_to_c.m: compiler/mlds_to_csharp.m: compiler/mlds_to_gcc.m: compiler/mlds_to_mcpp.m: Select the appropriate mlds__foreign code from the map and generate code for it. |
||
|
|
1c65d003f7 |
Add the shorthand_goal_expr wrapper type to ease hlds->hlds transformations.
Estimated hours taken: 4.5
Branches: main
Add the shorthand_goal_expr wrapper type to ease hlds->hlds transformations.
compiler/hlds_goal.m
Create a new type, the `shorthand_goal_expr', for goals kinds that
are implemented by a (ordinary_hlds + shorthand) -> (ordinary_hlds)
transformation. At present, bi_implication is the only kind of
of goal that is implemented in this way.
Moved bi_implication functor from the type goal_expr to the new
shorthand_goal_expr type.
Added the functor shorthand to the goal_expr type.
compiler/*.m
Change switches on hlds_goal_expr that call error when they recognise
`bi_implication' from calling error when they recognise
`bi_implication' to calling error when they recognise `shorthand'.
For all predicates K that
a) switch on hlds_goal_expr and
b) perform non-trivial processing when they recognise
`bi_implication'
change K such that it now calls K_shorthand upon recognising the
functor `shorthand'. Define K_shorthand to switch on
shorthand_goal_expr, where the code for the `bi_implication' case
formerly contained in K is now contained in K_shorthand.
|
||
|
|
711da78188 |
Rename foreign_code as foreign_proc where appropriate in the compiler.
Estimated hours taken: 4.0 Branches: main Rename foreign_code as foreign_proc where appropriate in the compiler. The rationale for this change is that it makes maintaining the code much simpler because it is clear whether `foreign' refers to a slab of code (foreign_code) or a procedure (foreign_proc). :- type pragma_foreign_code_attributes :- type pragma_foreign_proc_attributes The functors for pragma_type foreign(Lang, BodyCode) foreign(Attributes, Name, PredOrFunc, Vars, Varset, Impl) become foreign_code(Lang, BodyCode) foreign_proc(Attributes, Name, PredOrFunc, Vars, Varset, Impl) And the HLDS goal `pragma_foreign_code' becomes `foreign_proc'. compiler/*.m: Update the compiler to use the new names. |
||
|
|
477ecb18f6 |
Implement pragma foreign_code for Managed C++.
Estimated hours taken: 60 Implement pragma foreign_code for Managed C++. Currently you can only write MC++ code if your backend is capable of generating use MC++ as its "native" foreign language. The IL backend is the only backend that does this at the moment (the other backends have C as their "native" foreign language). Most of the machinery is in place to call from C to (normal) C++ but there is little work done on actually spitting out the C++ code into a separate file. The IL backend does this step already with managed C++. The intention is to turn foreign_code for C++ into a pragma import (which imports the C++ function from a separate file) and foreign_code for C (which calls the imported function). The C++ code will be inserted into a separate file that is compiled using C linkage. The important improvement this change gives is that you can write a module with a C and a MC++ implementations side-by-side. The target backend will select the most appropriate foreign language to use. You can override its choice using --use-foreign-language. Later on we will probably want more flexibility than just a single language selection option). This change also implements :- pragma foreign_decl, which allows header file style declarations to be written in languages other than C. compiler/code_gen.m: Reject code that is not C when generating LLDS. compiler/export.m: Start renaming C as foreign. Reject code that is not C when generating exports. compiler/foreign.m: A new module to handle foreign language interfacing. The bulk of the code for pragma import has been moved here from make_hlds. compiler/globals.m: Convert foreign language names to foreign_language. This code has been moved closer to the similar conversion we do for target language names. Add globals__io_lookup_foreign_language_option to make it easier to deterministically lookup the options relating to foreign languages. compiler/hlds_module.m: Move module_add_foreign_decl and module_add_foreign_body_code from make_hlds.m (where they were called module_add_c_header and module_add_c_code). compiler/hlds_out.m: Write the foreign language out in HLDS dumps. compiler/llds.m: Change foreign_header_info to foreign_decl_info. Change definitions of foreign_decl_code and foreign_body_code to include the language. compiler/llds_out.m: Reject code that is not C when writing out LLDS. compiler/make_hlds.m: Add foreign language information to the bodys and decls when creating them. Update error messages to refer to foreign code instead of C code. Use foreign.m to generate interfaces from the backend language to the foreign language. Hardcode C as the language for fact tables. compiler/mercury_compile.m: Collect the appropriate foreign language code together for output to the backend. compiler/intermod.m: compiler/mercury_to_mercury.m: Output the foreign language string. Change a few names to foreign_code instead of c_code. compiler/ml_code_gen.m: Filter the foreign language bodys and decls so that we only get the ones we are in (given by the use-foreign-language option). compiler/mlds_to_c.m: Abort if we are given non C foreign language code to output (we might handle it here in future, or we might handle it elsewhere). compiler/mlds_to_ilasm.m: Abort if we are given non MC++ foreign language code to output (we might handle it here in future, or we might handle it elsewhere). compiler/options.m: compiler/handle_options.m: Add --use-foreign-language as a user option to control the preferred foreign language to use as the implementation of this module. Add backend_foreign_language as an internal option which stores the foreign language that the compiler will use as a default (e.g. the natural foreign language for the backend to use). Set the preferred backend foreign language depending on the target. compiler/prog_data.m: Add managedcplusplus as a new alternative for the foreign_language type. Make c_header_code into foreign_decl. Give the foreign language for foreign_code as an attribute of the code. Write code to turn attributes into a list of strings (suitable for writing out by mercury_to_mercury). This fixes what appears to be a bug in tabled_for_io -- the tabled_for_io attribute was not being written out. Structure the code so this bug is difficult to repeat in future. compiler/prog_io_pragma.m: Parse foreign_decl. Turn c_header_code into a special case of foreign_decl. compiler/*.m: Remove the language field from pragma_foreign_code, it is now an attribute of the code. Various type and variable renamings. tests/invalid/pragma_c_code_and_clauses1.err_exp: tests/invalid/pragma_c_code_dup_var.err_exp: tests/warnings/singleton_test.exp: Update the tests to reflect the new error messages talking about :- pragma foreign_code rather than :- pragma c_code. |