mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-17 14:57:03 +00:00
056fd7d26c489897f29cbba337292989ffbc175d
296 Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
056fd7d26c |
Hopefully finish the breakup of the monster module prog_io.m.
Estimated hours taken: 2 Branches: main Hopefully finish the breakup of the monster module prog_io.m. It is now way out of the list of the ten biggest modules. More important, it now has much more coherence: it consists mainly of - the top level loop for reading in items, and - the code for parsing predicate, function and mode declarations. There are still some other misc things that don't fit here (e.g. checking insts for consistency), but they don't fit that well in other modules either. compiler/prog_io.m: compiler/prog_io_mode_defn.m: compiler/prog_io_type_defn.m: Move the code in prog_io.m for dealing with definitions of insts, modes and types into two new modules. Delete some obsolete comments at the top of prog_io.m.. compiler/prog_io_util.m: Move some generic stuff for dealing with declaration attributes and (nonsupported) conditions here from prog_io.m, since the module prog_io_type_defn.m also needs them. compiler/parse_tree.m: compiler/notes/compiler_design.html: Add the new modules. compiler/*.m: Import the new modules where needed. |
||
|
|
1abc2f39a0 |
Continue the breakup of the monster module prog_io.m.
Estimated hours taken: 3 Branches: main Continue the breakup of the monster module prog_io.m. compiler/prog_io.m: compiler/prog_io_mutable.m: compiler/prog_io_sym_name.m: Move the code in prog_io.m for dealing with declarations for mutables and for parsing symbol names and specifiers into two new modules. compiler/parse_tree.m: compiler/notes/compiler_design.html: Add the new modules. compiler/*.m: Import prog_io_sym_name instead of (or, in a couple of cases, as well as) prog_io. |
||
|
|
b445b51205 |
Add a sequence number to the information we collect for each kind of item.
Estimated hours taken: 4 Branches: main Add a sequence number to the information we collect for each kind of item. The purpose of this is to prepare for a later change that will switch from representing the stuff we read in from a file as a list of items to representing it is a data structure that groups all items of a given kind together. This will lose the original order of the items. The sequence number will allow us to recreate it if necessary, e.g. for pretty-printing. compiler/prog_item.m: Add the sequence number field to the information we have about each kind of item. compiler/prog_io.m: compiler/prog_io_dcg.m: compiler/prog_io_pragma.m: compiler/prog_io_typeclass.m: Add code to generate the item sequence numbers. In prog_io.m, change some predicates that used to return an intermediate type such as processed_type_body to make them return an item, since this simplifies adding sequence numbers; it also simplifies the code in general and reduces memory allocation. Rename some uninformatively-named variables that I missed in my last diff. compiler/*.m: Minor changes to conform to the above. Mostly this involves either ignoring the seqnum field, or copying it when an item is updated. |
||
|
|
ec7e2f28ef |
More cleanups. Replace Term0, Term1 etc with meaningful variable
Estimated hours taken: 5
Branches: main
compiler/prog_io.m:
More cleanups. Replace Term0, Term1 etc with meaningful variable
names, and use better variable names in general. Rename some
predicates as well when the old names didn't tell you what the
predicate did, and where the name was ambiguous. Convert several
predicates to disjunctions where this allows factoring out common
code or giving consistent names to arguments.
Inline some more auxiliary predicates whose purpose of indexing
on Prolog systems has long expired. In one case, the simplification
that this made possible showed an opportunity to generate more
comprehensive error messages.
Reorder the predicates in this module to form blocks of code each
dealing with one kind of Mercury construct, e.g. type definitions,
mode definitions, predicate and function declarations, etc.
compiler/prog_io_util.m:
A few changes of the same sort as in prog_io.m.
compiler/prog_io_goal.m:
Conform to the new name of a predicate in prog_io.m.
tests/invalid/func_errors.err_exp:
Expect the more comprehensive error messages.
|
||
|
|
a00596c283 |
The file modules.m contains lots of different kinds of functionality.
Estimated hours taken: 16 Branches: main The file modules.m contains lots of different kinds of functionality. While much of it belongs together, much of it does not. This diff moves most of the functionality that does not belong with the rest to several new modules: libs.file_util parse_tree.deps_map parse_tree.file_names parse_tree.module_cmds parse_tree.module_imports parse_tree.read_module parse_tree.write_deps_file To make them coherent, move some predicates from hlds.passes_aux, parse_tree.prog_io and parse_tree.prog_out to the new modules, making them more accessible, reducing the required access from the hlds package to parse_tree, or from the parse_tree package to libs. In the same spirit, this diff also moves some simple predicates and functions dealing with sym_names from prog_util.m to mdbcomp/prim_data.m. This allows several modules to avoid depending on parse_tree.prog_util. Rename some of the moved predicates and function symbols where this avoids ambiguity. (There were several that differed from other predicates or function symbols only in arity.) Replace several uses of bools with purpose-specific types. This makes some of the code significantly easier to read. This diff moves modules.m from being by far the largest module, to being only the seventh largest, from 8900+ lines to just 4200+. It also reduces the number of modules that import parse_tree.modules considerably; most modules that imported it now import only one or two of the new modules instead. Despite the size of the diff, there should be no algorithmic changes. compiler/modules.m: compiler/passes_aux.m: compiler/prog_io.m: compiler/prog_out.m: Delete the moved functionality. compiler/file_util.m: New module in the libs package. Its predicates search for files and do simple error or progress reporting. compiler/file_names.m: New module in the parse_tree package. It contains predicates for converting module names to file names. compiler/module_cmds.m: New module in the parse_tree package. Its predicates handle the commands for manipulating interface files of various kinds. compiler/module_import.m: New module in the parse_tree package. It contains the module_imports type and its access predicates, and the predicates that compute various sorts of direct dependencies (those caused by imports) between modules. compiler/deps_map.m: New module in the parse_tree package. It contains the data structure for recording indirect dependencies between modules, and the predicates for creating it. compiler/read_module.m: New module in the parse_tree package. Its job is reading in modules, both human-written and machine-written (such as interface and optimization files). compiler/write_deps_file.m: New module in the parse_tree package. Its job is writing out makefile fragments. compiler/libs.m: compiler/parse_tree.m: Include the new modules. compiler/notes/compiler_design.m: Document the new modules. mdbcomp/prim_data.m: compiler/prog_util.m: Move the predicates that operate on nothing but sym_names from prog_util to prim_data. Move get_ancestors from modules to prim_data. compiler/prog_item.m: Move stuff that looks for foreign code in a list of items here from modules.m. compiler/source_file_map.m: Note why this module needs to be in the parse_tree package. compiler/add_pred.m: compiler/add_special_pred.m: compiler/analysis.file.m: compiler/analysis.m: compiler/assertion.m: compiler/check_typeclass.m: compiler/compile_target_code.m: compiler/cse_detection.m: compiler/det_analysis.m: compiler/elds_to_erlang.m: compiler/exception_analysis.m: compiler/export.m: compiler/fact_table.m: compiler/higher_order.m: compiler/hlds_module.m: compiler/hlds_pred.m: compiler/intermod.m: compiler/llds_out.m: compiler/make.dependencies.m: compiler/make.m: compiler/make.module_dep_file.m: compiler/make.module_target.m: compiler/make.program_target.m: compiler/make.util.m: compiler/make_hlds_passes.m: compiler/maybe_mlds_to_gcc.pp: compiler/mercury_compile.m: compiler/mlds.m: compiler/mlds_to_c.m: compiler/mlds_to_gcc.m: compiler/mlds_to_ilasm.m: compiler/mlds_to_java.m: compiler/mmc_analysis.m: compiler/mode_constraints.m: compiler/mode_debug.m: compiler/modes.m: compiler/module_qual.m: compiler/optimize.m: compiler/passes_aux.m: compiler/proc_gen.m: compiler/prog_foreign.m: compiler/prog_io.m: compiler/prog_io_util.m: compiler/prog_mutable.m: compiler/prog_out.m: compiler/pseudo_type_info.m: compiler/purity.m: compiler/recompilation.check.m: compiler/recompilation.usage.m: compiler/simplify.m: compiler/structure_reuse.analysis.m: compiler/structure_reuse.direct.detect_garbage.m: compiler/structure_reuse.direct.m: compiler/structure_sharing.analysis.m: compiler/tabling_analysis.m: compiler/term_constr_main.m: compiler/termination.m: compiler/trailing_analysis.m: compiler/trans_opt.m: compiler/type_util.m: compiler/typecheck.m: compiler/typecheck_info.m: compiler/unify_proc.m: compiler/unused_args.m: compiler/unused_imports.m: compiler/xml_documentation.m: Minor changes to conform to the changes above. |
||
|
|
cc42c8fac5 |
Switch to using error_util to generate error message during the process of
Estimated hours taken: 40 Branches: main Switch to using error_util to generate error message during the process of converting terms to prog_items. In many predicates, we used to return error messages as a string/term pair, with the string being the error message and a term, which both provided the context and was printed after the message. We now return error indications as lists of error_specs. These include a printout of the relevant term only if this helps users understand the nature or the location of the error. To make the printouts easier to understand we print variable names in them using the applicable varsets. (The old version of the compiler used to print each error term long after it lost track of the right varset, and thus used a dummy varset that yielded error messages referring to _1, _2 etc instead of the variable names used by the programmer.) Sometimes the callers of some parse predicates prepended other strings indicating the context of the error in front of the error string. This diff changes things so that now the caller instead passes a list of format components describing the context to the predicates that construct the error_specs. In some places, simplify the code, e.g. by factoring out common code, and by inlining some auxiliary predicates (we used to need these auxiliary predicates for indexing when we executed the compiler using Prolog, but those days are long past). Mark with XXXs places where I think the error messages or their contexts could be improved, and places where the structure of the code could be improved. compiler/prog_io_util.m: Change the representation of the maybeN types to use error_spec lists. compiler/prog_io.m: compiler/prog_io_dcg.m: compiler/prog_io_goal.m: compiler/prog_io_pragma.m: compiler/prog_io_typeclass.m: compiler/prog_io_util.m: Change the way we generate error messages along the lines described at the top. In several cases, this required adding extra arguments (varsets, context descriptions) to predicates for use in error messages. Some of these predicates were also used in contexts where the caller was interested only in success, and would ignore any error messages. In these cases, add a version of the predicate that does not require the extra arguments, and which is semidet (to allow the caller to avoid a test for ok). compiler/error_util.m: Add a mechanism for changing the case of the next format_component, to allow an error message to be appended to a list of format_components providing the context that generates good-looking output whether or not that context is empty. Replace some bools with purpose-specific types. Make sort_error_specs internal to the module, since outside modules should never need to use it. Use cords instead of reversed lists to simplify some parts of the internal implementation. compiler/mercury_to_mercury.m: Provide a mechanism to print out terms only if they aren't too big, for use in our error messages. compiler/prog_item.m: Delete the message_list type, and note a future improvement. compiler/prog_out.m: Delete the predicates for printing message_lists. compiler/intermod.m: compiler/modules.m: Change the way we print out error messages along the lines described at the top. compiler/add_clause.m: compiler/field_access.m: compiler/recompilation.check.m: compiler/recompilation.version.m: compiler/superhomogeneous.m: Conform to the changes above by modifying how we generate error messages. compiler/add_class.m: compiler/add_pragma.m: compiler/check_typeclass.m: compiler/common.m: compiler/make.module_dep_file.m: compiler/make_hlds_error.m: compiler/make_hlds_passes.m: compiler/mercury_compile.m: compiler/mode_errors.m: compiler/modes.m: compiler/options_file.m: compiler/prog_ctgc.m: compiler/prog_event.m: compiler/purity.m: compiler/trans_opt.m: compiler/typecheck.m: Trivial updates to conform to the changes above. compiler/prog_data.m: Add some field names and access functions for use in the modules above. library/list.m: Add list.contains, which is list.member with the arguments reversed to make it possibly to partially apply it. tests/invalid/bad_finalise_decl.err_exp: tests/invalid/bad_initialise_decl.err_exp: tests/invalid/bad_mutable.err_exp: tests/invalid/bigtest.err_exp: tests/invalid/conflicting_fs.err_exp: tests/invalid/constrained_poly_insts.err_exp: tests/invalid/errors.err_exp: tests/invalid/func_errors.err_exp: tests/invalid/fundeps_unbound_in_ctor.err_exp: tests/invalid/fundeps_vars.err_exp: tests/invalid/impl_def_literal_syntax.err_exp: tests/invalid/inst_list_dup.err_exp: tests/invalid/invalid_typeclass.err_exp: tests/invalid/kind.err_exp: tests/invalid/null_char.err_exp: tests/invalid/pragma_source_file.err_exp: tests/invalid/predmode.err_exp: tests/invalid/reserve_tag.err_exp: tests/invalid/some.err_exp: tests/invalid/specified.err_exp: tests/invalid/trace_goal_env.err_exp: tests/invalid/type_vars.err_exp: tests/invalid/typeclass_test_1.err_exp: tests/invalid/typeclass_test_11.err_exp: tests/invalid/typeclass_test_2.err_exp: tests/invalid/unbound_type_vars.err_exp: tests/invalid/unicode1.err_exp: tests/invalid/unicode2.err_exp: tests/invalid/uu_type.err_exp: tests/invalid/vars_in_wrong_places.err_exp: tests/invalid/with_type.err_exp: tests/invalid/purity/purity_nonsense2.err_exp: Update the expected error messages. |
||
|
|
9854006d68 |
Make some long-overdue simplifications.
Estimated hours taken: 1 Branches: main Make some long-overdue simplifications. compiler/prog_item.m: Delete the varset from item_module_defn_infos, since it wasn't being used anywhere. compiler/prog_data.m: compiler/prog_item.m: Remove all the stuff related to importing predicates, functions, ADTs, operators, etc, which have never been implemented. (If we ever wanted to implement them, we would need different code anyway.) Keep only the stuff relating to importing modules. compiler/*.m: Conform to the changes above. tests/invalid/bigtest.err_exp: Update error messages for the never-implemented language features. |
||
|
|
801125616f |
A first step towards rationalizing the parse tree representation of the
Estimated hours taken: 24 Branches: main A first step towards rationalizing the parse tree representation of the program. This step moves the information specific to each kind of item into a structure specific to that kind of item. In the short term, this allows us to express some old invisible invariants as types. For example, we used to store general items in method definitions; we now store clause-specific data there. This allows us to simplify some code and eliminate some old "can't fail" tests. In the longer term, this change will allow us to replace the old list of items representation of the parse tree with a more structured representation, which aggregates each kind of item differently. For example, we could keep clause items in a list, but map module imports to the contexts of their :- import_module items, which would allow us to detect duplicate imports. We could also change the current three pass structure of the parse tree to HLDS conversion step, where each pass processes *all* items, to a much more flexible structure where each pass processes only what it needs to process, new passes could be added much more simply, and in fact the whole notion of a "pass" could be eliminated. In a bunch of places, factor out some common code. compiler/prog_item.m: Make the change to the item type as above. Rename the old item_pred_or_func as item_pred_decl (it already had a field to indicate predicate or function) and item_pred_or_func_mode as item_mode_decl. These names are much more consistent with the other item names. Eliminate the item_and_context type by moving the context into the items themselves. In code that cares about contexts, this makes it easier to match up each item with its context. In code that doesn't care about contexts, this avoids the extra code that would be required to discard the item_and_context wrapper. compiler/prog_data.m: Store item_clause_infos instead of items in method definitions. compiler/prog_io.m: compiler/prog_io_dcg.m: compiler/prog_io_pragma.m: compiler/prog_io_typeclass.m: Construct the new item structure when creating the parse tree. Instead of constructing items and later attaching the context to them, pass the context down, since we now need to include them in items. Some old code was assuming that term.variables had no contexts; update such code. In prog_io_pragma.m, replace a single predicate that parsed all kinds of pragmas, which spanned more than one thousand lines and whose clauses had been interspersed with the clauses of other predicates, with a predicate whose only job is to select which of a bunch of pragma-type-specific parse predicates to invoke. Each of these pragma-type-specific parse predicates corresponds to one of the clauses of the old predicate. In that form, the predicates can be declared det, even though the predicate as a whole is semidet (since not all pragma names are valid). This actually exposed an old bug; the case MaybeAttributes = error1(_) was not handled in foreign_export_enum pragmas. To make the diff easier to check, I left the predicates in the original order of the clauses, even though that order does not make sense (it does not group related pragmas together). I did leave an XXX comment about this. The matter will be addressed in a later diff. (A similar problem occurs in some of the other modules in which I broke up very large predicates.) compiler/prog_io_util.m: Remove some stuff that the new item structure makes unnecessary. compiler/make_hlds_passes.m: compiler/add_class.m: compiler/add_mode.m: compiler/add_pragma.m: compiler/add_solver.m: Conform to the new item structure when converting it to HLDS. Break up excessively large predicates. compiler/prog_foreign.m: Provide a function to return all supported foreign languages, instead of requiring callers to call solutions to compute this list. compiler/mercury_to_mercury.m: Print out the new item structure. Break up excessively large predicates. Rename some predicates to avoid name collisions. compiler/equiv_type.m: compiler/hlds_module.m: compiler/intermod.m: compiler/make.module_dep_file.m: compiler/mercury_compile.m: compiler/module_qual.m: compiler/modules.m: compiler/prog_mutable.m: compiler/recompilation.check.m: compiler/recompilation.version.m: compiler/state_var.m: compiler/trans_opt.m: Operate on the new item structure. Factor out code (usually tests) where the new item structure makes this possible and desirable. Turn if-then-elses into switches where this is desirable. Build up large terms from named pieces instead of all at once. Break up excessively large predicates. In equiv_type.m, rename a predicate to clarify its function, and add an XXX about a possible improvement in abstraction. In modules.m, simplify the interface between some predicates and their callers, turn some predicates into functions, and make some code return error specifications instead of doing raw printing of error messages. Note that this module still has plenty of scope for improvement (I marked some with XXXs), but that is for a later date. In some cases, mark potential bugs with XXXs. compiler/equiv_type_hlds.m: Conform to the change in equiv_type.m. library/term.m: compiler/recompilation.check.m: Move the function for getting the context out of a term from recompilation.check.m to term.m, so it can be used from other modules. (Also, adding such a function to the standard library is long overdue.) NEWS: Note the change to term.m. |
||
|
|
7460aadbf8 |
Implement higher-order any' insts. Pred or func expressions with an any'
Estimated hours taken: 100 Branches: main Implement higher-order `any' insts. Pred or func expressions with an `any' inst may bind non-local solver variables, but themselves must not be called in a negated context. (The existing ground pred and func expressions may not bind non-local solver variables, but may be called in a negated context.) Higher-order `any' insts are specified by using `any_pred' and `any_func' in place of `pred' and `func', respectively. We implement these insts by adding a new field to the any/1 constructor of mer_inst, which is identical to the ground_inst_info field of the ground/2 constructor. Both are given the new type `ho_inst_info'. We then relax the locking of non-local variables in these pred and func expressions, and extend call/N and apply/N to also accept the new insts (provided the variables are not locked). We also store the groundness (ho_ground or ho_any) of each lambda expression in a unification, in a new field in the rhs_lambda_goal constructor. NEWS: Mention the new feature. compiler/prog_data.m: Rename the ground_inst_info type ho_inst_info, and update its documentation. Add the ho_inst_info field to the any constructor in mer_inst. compiler/hlds_goal.m: Add the rhs_groundness field to rhs_lambda_goal in unify_rhs. compiler/inst_match.m: Propagate inst matching into the pred_inst_infos of any insts, if they exist. compiler/inst_util.m: Propagate abstract unification and inst merging into the pred_inst_infos of any insts, if they exist. May use of this information when building ground, any, shared and mostly_unique versions of insts. compiler/modecheck_call.m: Allow an `any' inst as the pred (func) argument to call/N (apply/N), but check that the variable is not locked. If the variable is locked, report a mode error which suggests using the ground inst. (We could also suggest that the goal be made impure, but it is best to point users towards the pure approach.) compiler/modecheck_unify.m: Relax the locking of non-locals when processing non-ground lambda goals. Update documentation. compiler/mode_util.m: Propagate type information into the pred_inst_infos of any insts. compiler/mode_errors.m: Change the purity error "lambda should be impure" to "lambda should be any", since this is better advice. Also provide an example of correct syntax if the verbose errors option is given. compiler/prog_io_goal.m: Parse the new kinds of expressions, returning the groundness along with the existing information about lambda expressions. compiler/superhomogeneous.m: Use the above groundness when building the lambda unification. compiler/prog_io_util.m: Parse the new kind of insts, filling in the new ho_inst_info field where appropriate. compiler/polymorphism.m: Handle the new fields. Assume that the shorthand form of lambda expressions always defines a ground inst -- if users want non-ground higher-order expressions they will need to use an explicit any_pred or any_func expression. compiler/equiv_type_hlds.m: Replace equivalent types in the pred_inst_infos of `any' insts. compiler/module_qual.m: Module qualify the pred_inst_infos of `any' insts. compiler/recompilation.usage.m: compiler/unused_imports.m: Look for items or imports used by insts in the pred_inst_infos of `any' insts. compiler/hlds_out.m: compiler/mercury_to_mercury.m: Output the new lambda expressions and insts in the correct format. compiler/type_util.m: Treat all pred and func types as solver types. (Effectively they are, since all such types can now have non-ground values, with call/N and apply/N acting as constraints.) compiler/lambda.m: Pass the groundness value when building procedures for lambda expressions. This is not currently required for anything. doc/reference_manual.texi: Document the new feature, and update existing documentation on solver types and negated contexts. tests/valid/Mmakefile: tests/valid/ho_any_inst.m: New test case for some valid code using higher-order any insts. tests/invalid/Mmakefile: tests/invalid/ho_any_inst.err_exp: tests/invalid/ho_any_inst.m: New test case for some illegal code. tests/invalid/anys_in_negated_contexts.err_exp: Update expected error message for this test case. We now report that the expression should be `any', rather than impure. compiler/*.m: Handle the new fields. |
||
|
|
5c4ef16fdc |
Improve the style of some predicates.
Estimated hours taken: 0.2
Branches: main
compiler/prog_io.m:
Improve the style of some predicates.
|
||
|
|
0bb49f40d2 |
Fix one of the problems that causes the compiler to run out of stack
Estimated hours taken: 2 Branches: main Fix one of the problems that causes the compiler to run out of stack space when compiling a discriminated unions that has a large numbers of constructors. This speeds up compilation of a type with 200000 constructors by about 1% -- it doesn't have a measurable impact on discriminated unions of a more usual size. compiler/prog_io.m: When checking that the constructors of a discriminated union are well-formed, iterate through the list of constructors once instead of four times. |
||
|
|
bcec8a99e7 |
Remove support for the `initialisation is ...' attribute from solver types.
Estimated hours taken: 2 Branches: main Remove support for the `initialisation is ...' attribute from solver types. This attribute is now a syntax error, unless the developer-only option `--solver-type-auto-init' is enabled -- in which case things will work as before. Update the test suite to conform to the above change. compiler/globals.m: Add a mutable that stores whether or not we support automatic solver type initialisation. The value of this mutable is used in the parser to decide if `initialisation is ...' attributes in solver type definitions are legal syntax or not. compiler/prog_io.m: Only accept `initialisation is ...' attributes in solver type definitions as legal syntax if the value of the above mutable indicates that `--solver-type-auto-init' is enabled. NEWS: Announce the removal of support for automatic initialisation. tests/debugger/Mercury.options: Run the solver_test test with `--solver-type-auto-init' enabled. tests/hard_coded/Mercury.options: Run tests that check if automatic initialisation is working with `--solver-type-auto-init' enabled. Delete a reference to a test case was deleted some time ago. tests/warnings/Mercury.options: tests/invalid/Mercury.options: Enable `--solver-type-auto-init' for some tests. tests/invalid/any_mode.m: tests/invalid/any_passed_as_ground.m: tests/invalid/any_should_not_match_bound.m: tests/invalid/any_ground_in_ite_cond.m: tests/valid/solv.m: tests/hard_coded/any_call_hoist_bug.m: tests/hard_coded/any_free_unify.m: tests/hard_coded/sub-modules/ts.m: Remove `initialisation is ...' attributes from the solver type definitions in these tests. |
||
|
|
f5667464c7 |
Remove support for automatic initialisation of solver types from the language.
Estimated hours taken: 10 Branches: main Remove support for automatic initialisation of solver types from the language. This is being done because: * the current implementation of automatic initialisation means we cannot support polymorphic solver types, e.g. you cannot have the type foo(bar) where: :- solver type foo(T). :- solver type bar. * the current initialisation strategy is fairly ad-hoc anyway; in particular it has a tendency to unnecessarily change the determinism of procedures. * mode error messages are often quite poor because of the interaction between automatic initialisation and impure code. * automatic initialisation is not used in practice. All of the G12 solver libraries that use solver types recommend explicitly initialising solver variables. This change removes support for automatic solver initialisation from the language. The code for supporting it remains in the implementation, but it is now dependent upon the developer-only `--solver-type-auto-init' option. As a transitional measure the compiler will still accept `initialisation is ...' attributes in solver type definitions even when `--no-solver-type-auto-init' is enabled. After this change has bootstrapped, and the relevant updates have been made to the G12 solver libraries, this will be changed so that `initialisation is ...' attributes are considered a syntax error unless `--solver-type-auto-init' is enabled. doc/reference_manual.texi: Document that solver type definitions no longer allow initialisation predicates to be supplied. (The section documenting initialisation predicates has been commented out rather than deleted since the implementation of automatic initialisation still exists.) Remove the section documenting the restrictions on polymorphic solver types. These restrictions no longer apply in the absence of automatic initialisation. compiler/options.m: Add a new developer-only option, `--solver-type-auto-init', that controls whether automatic initialisation of solver variables is allowed (for those solver types that have initialisation predicates specified.) compiler/prog_data.m: Add a type that represents whether a solver type allows automatic initialisation or not. Extend the solver_type_details structure to allow initialisation predicates to be optional. compiler/prog_io.m: Allow initialisation predicates to be optional in solver type definitions. compiler/modes.m: compiler/modecheck_call.m: compiler/modecheck_unify.m: Only insert calls to solver type initialisation predicates if the solver type has an initialisation predicate and the developer-only option `--solver-type-auto-init' is enabled. compiler/unify_proc.m: Handle the situation where a solver type does not have an initialise predicate. compiler/add_special_pred.m: Only add initialisation special predicates for those solver types whose definition provides an initialisation predicate. compiler/mode_info.m: Add a utility predicate that tests whether the support for automatic solver type initialisation is enabled. compiler/type_util.m: Add a predicate that tests whether a type is a solver type that supports automatic initialisation. Add an XXX comment about such types and abstract equivalence types. compiler/mercury_to_mercury.m: Conform to the above changes. compiler/special_pred.m: Fix some typos. samples/solver_types/eqneq.m: Delete the `initialisation is ...' from the definition of the solver type eqneq/1. tests/hard_coded/Mercury.options: Enable `--solver-type-auto-init' for the solver_construction_init_test test. tests/hard_coded/solver_build_call.m: tests/invalid/any_pass_as_ground.m: Don't use automatic solver variable initialisation in these test cases. tests/invalid/partial_implied_mode.err_exp: Conform to the above changes in the mode analyser. tests/valid/Mercury.options: Compile some tests cases with `--solver-type-auto-init' enabled. |
||
|
|
1d61e9a681 |
Fix a bug where a ":- pragma source_file" declaration was effectively
Estimated hours taken: 4
Branches: main
Fix a bug where a ":- pragma source_file" declaration was effectively
ignored if it appeared before the ":- module" declaration. The problem was
that prog_io.read_first_term was not passing the source file name to the
predicates that read the subsequent terms.
compiler/options_file.m:
Fix a typo in a comment.
compiler/prog_io.m:
Change read_first_item to return the source file name, in case this
has been changed by a ":- pragma source_file" declaration.
tests/invalid/Mmakefile:
tests/invalid/pragma_source_file.err_exp:
tests/invalid/pragma_source_file.m:
Add a regression test.
|
||
|
|
057246b934 |
Fix a bug which caused the presence of a file named write.m
Estimated hours taken: 2 Branches: main compiler/modules.m: compiler/prog_io.m: Fix a bug which caused the presence of a file named write.m in the current directory to stop the compiler finding a module bit_buffer.write in a library. The test case for this is tests/hard_coded/bit_buffer_test.m. `mmc --make' already handled this correctly. |
||
|
|
b56885be93 |
Fix a bug that caused bootchecks with --optimize-constructor-last-call to fail.
Estimated hours taken: 12 Branches: main Fix a bug that caused bootchecks with --optimize-constructor-last-call to fail. The problem was not in lco.m, but in follow_code.m. In some cases, (specifically, the LCMC version of insert_2 in sparse_bitset.m), follow_code.m moved an impure goal (store_at_ref) into the arms of an if-then-else without marking those arms, or the if-then-else, as impure. The next pass, simplify, then deleted the entire if-then-else, since it had no outputs. (The store_at_ref that originally appeared after the if-then-else was the only consumer of its only output.) The fix is to get follow_code.m to make branched control structures such as if-then-elses, as well as their arms, semipure or impure if a goal being moved into them is semipure or impure, or if they came from an semipure or impure conjunction. Improve the optimization of the LCMC version of sparse_bitset.insert_2, which had a foreign_proc invocation of bits_per_int in it: replace such invocations with a unification of the bits_per_int constant if not cross compiling. Add a new option, --optimize-constructor-last-call-null. When set, LCMC will assign NULLs to the fields not yet filled in, to avoid any junk happens to be there from being followed by the garbage collector's mark phase. This diff also makes several other changes that helped me to track down the bug above. compiler/follow_code.m: Make the fix described above. Delete all the provisions for --prev-code; it won't be implemented. Don't export a predicate that is not now used anywhere else. compiler/simplify.m: Make the optimization described above. compiler/lco.m: Make sure that the LCMC specialized procedure is a predicate, not a function: having a function with the mode LCMC_insert_2(in, in) = in looks wrong. To avoid name collisions when a function and a predicate with the same name and arity have LCMC applied to them, include the predicate vs function status of the original procedure included in the name of the new procedure. Update the sym_name of calls to LCMC variants, not just the pred_id, because without that, the HLDS dump looks misleading. compiler/pred_table.m: Don't have optimizations like LCMC insert new predicates at the front of the list of predicates. Maintain the list of predicates in the module as a two part list, to allow efficient addition of new pred_ids at the (logical) end without using O(N^2) algorithms. Having predicates in chronological order makes it easier to look at HLDS dumps and .c files. compiler/hlds_module.m: Make module_info_predids return a module_info that is physically updated though logically unchanged. compiler/options.m: Add --optimize-constructor-last-call-null. Make the options --dump-hlds-pred-id, --debug-opt-pred-id and --debug-opt-pred-name into accumulating options, to allow the user to specify more than one predicate to be dumped (e.g. insert_2 and its LCMC variant). Delete --prev-code. doc/user_guide.texi: Document the changes in options.m. compiler/code_info.m: Record the value of --optimize-constructor-last-call-null in the code_info, to avoid lookup at every cell construction. compiler/unify_gen.m: compiler/var_locn.m: When deciding whether a cell can be static or not, make sure that we never make static a cell that has some fields initialized with dummy zeros, to be filled in for real later. compiler/hlds_out.m: For goals that are semipure or impure, note this fact. This info was lost when I changed the representation of impurity from markers to a field. mdbcomp/prim_data.m: Rename some ambiguous function symbols. compiler/intermod.m: compiler/trans_opt.m: Rename the main predicates (and some function symbols) of these modules to avoid ambiguity and to make them more expressive. compiler/llds.m: Don't print line numbers for foreign_code fragments if the user has specified --no-line-numbers. compiler/make.dependencies.m: compiler/mercury_to_mercury.m: compiler/recompilation.usage.m: Don't use io.write to write out information to files we may need to parse again, because this is vulnerable to changes to the names of function symbols (e.g. the one to mdbcomp/prim_data.m). The compiler still contains some uses of io.write, but they are for debugging. I added an item to the todo list of the one exception, ilasm.m. compiler/recompilation.m: Rename a misleading function symbol name. compiler/parse_tree.m: Don't import recompilation.m here. It is not needed (all the components of parse_tree that need recompilation.m already import it themselves), and deleting the import avoids recompiling almost everything when recompilation.m changes. compiler/*.m: Conform to the changes above. compiler/*.m: browser/*.m: slice/*.m: Conform to the change to mdbcomp. library/sparse_bitset.m: Use some better variable names. |
||
|
|
81b8e55825 |
Add support for thread-local mutables. These can take on a different value for
Estimated hours taken: 15 Branches: main Add support for thread-local mutables. These can take on a different value for each Mercury thread. Child threads automatically inherit the thread-local values of the parent thread that spawned it. compiler/make_hlds_passes.m: compiler/prog_io.m: compiler/prog_item.m: compiler/prog_mutable.m: Accept a `thread_local' attribute for mutables and update the source-to-source transformation. doc/reference_manual.texi: Document the `thread_local' attribute as a Melbourne Mercury compiler extension. runtime/mercury_context.c: runtime/mercury_context.h: Add a `thread_local_mutables' field to MR_Context, which points to an array which holds all the values of thread-local mutables in the program. Each thread-local mutable has an associated index into the array, which is allocated during initialisation. A child thread inherits the parent's thread-locals simply by copying the array. Add a `thread_local_mutables' field to MR_Spark and update the parallel conjunction implementation to take into account thread-locals. runtime/mercury_thread.c: runtime/mercury_thread.h: Add the functions and macros which are used by the code generated for thread-local mutables. runtime/mercury_wrapper.c: Allocate a thread-local mutable array for the initial context at startup. extras/concurrency/spawn.m: Update the spawn/3 implementation to make child threads inherit the thread-local values of the parent. Make different threads in high-level C grades use different MR_Contexts. This makes it possible to use the same implementation of thread-local mutables as in the low-level C grades. tests/hard_coded/mutable_decl.exp: tests/hard_coded/mutable_decl.m: tests/hard_coded/pure_mutable.exp: tests/hard_coded/pure_mutable.m: tests/invalid/bad_mutable.err_exp: tests/invalid/bad_mutable.m: Add some thread-local mutables to these test cases. NEWS: Announce the addition. |
||
|
|
ba93a52fe7 |
This diff changes a few types from being defined as equivalent to a pair
Estimated hours taken: 10 Branches: main This diff changes a few types from being defined as equivalent to a pair to being discriminated union types with their own function symbol. This was motivated by an error message (one of many, but the one that broke the camel's back) about "-" being used in an ambiguous manner. It will reduce the number of such messages in the future, and will make compiler data structures easier to inspect in the debugger. The most important type changed by far is hlds_goal, whose function symbol is now "hlds_goal". Second and third in importance are llds.instruction (function symbol "llds_instr") and prog_item.m's item_and_context (function symbol "item_and_context"). There are some others as well. In several places, I rearranged predicates to factor the deconstruction of goals into hlds_goal_expr and hlds_goal_into out of each clause into a single point. In many places, I changed variable names that used "Goal" to refer to just hlds_goal_exprs to use "GoalExpr" instead. I also changed variable names that used "Item" to refer to item_and_contexts to use "ItemAndContext" instead. This should make reading such code less confusing. I renamed some function symbols and predicates to avoid ambiguities. I only made one algorithmic change (at least intentionally). In assertion.m, comparing two goals for equality now ignores goal_infos for all kinds of goals, whereas previously it ignored them for most kinds of goals, but for shorthand goals it was insisting on them being equal. This seemed to me to be a bug. Pete, can you confirm this? |
||
|
|
b4c3bb1387 |
Clean up in unused module imports in the Mercury system detected
Estimated hours taken: 3 Branches: main Clean up in unused module imports in the Mercury system detected by --warn-unused-imports. analysis/*.m: browser/*.m: deep_profiler/*.m: compiler/*.m: library/*.m: mdbcomp/*.m: profiler/*.m: slice/*.m: Remove unused module imports. Fix some minor departures from our coding standards. analysis/Mercury.options: browser/Mercury.options: deep_profiler/Mercury.options: compiler/Mercury.options: library/Mercury.options: mdbcomp/Mercury.options: profiler/Mercury.options: slice/Mercury.options: Set --no-warn-unused-imports for those modules that are used as packages or otherwise break --warn-unused-imports, e.g. because they contain predicates with both foreign and Mercury clauses and some of the imports only depend on the latter. |
||
|
|
f08f22a7de |
Generate an XML representation of the du types in the current module.
Estimated hours taken: 24 Branches: main Generate an XML representation of the du types in the current module. The XML representation contains all the information about the type, as well as associating with each type, data constructor and data field any comments located near the comment. The current strategy associates the comment starting on the same line as the type declaration, and if there is none then the comment directly above. At a later date, this strategy needs to be made more flexible. This required two main changes to the compiler. Change one was to associate with a term.variable the context of that variable. Then the constructor and constructor_arg types had to have their context recorded. compiler/xml_documentation.m: Add a pass that generates an XML documentation for the du types in the current module. compiler/handle_options.m: compiler/mercury_compile.m: compiler/options.m: Call the xml_documentation phase and stop afterwards. compiler/error_utils.m: Add a utitily predicate for reporting errors where a file is unable to be opened. library/term.m: Add the term.context to term.variables. Remove the backwards mode of var_list_to_term_list as it no longer works. Make the predicate version of term_list_to_var_list semidet as we can no longer use the backwards version var_list_to_term_list. NEWS: Mention the changes to the term module. library/parser.m: Fill in the term.context of term.variables while parsing. compiler/prog_data.m: Add the context to the constructor and constructor_arg types. compiler/prog_io.m: Fill in the context fields in the constructor and constructor_arg types. compiler/add_clause.m: compiler/prog_io.m: compiler/prog_io_typeclass.m: compiler/typecheck.m: Call the correct version of term_list_to_var_list, to deal with the fact that we removed the reverse mode of var_list_to_term_list. compiler/notes/compiler_design.html: doc/user_guide.texi: Document the new module. compiler/add_clause.m: compiler/det_util.m: compiler/fact_table.m: compiler/hlds_out.m: compiler/inst_graph.m: compiler/intermod.m: compiler/make_hlds_passes.m: compiler/mercury_to_mercury.m: compiler/prog_ctgc.m: compiler/prog_io.m: compiler/prog_io_dcg.m: compiler/prog_io_goal.m: compiler/prog_io_pragma.m: compiler/prog_io_typeclass.m: compiler/prog_io_util.m: compiler/prog_io_util.m: compiler/prog_util.m: compiler/state_var.m: compiler/superhomogeneous.m: compiler/switch_detection.m: compiler/typecheck_errors.m: library/term_io.m: library/varset.m: Handle the context in the term.variable structure. compiler/add_type.m: compiler/check_typeclass.m: compiler/equiv_type.m: compiler/hhf.m: compiler/hlds_out.m: compiler/inst_check.m: compiler/make_tags.m: compiler/mercury_to_mercury.m: compiler/ml_type_gen.m: compiler/ml_unify_gen.m: compiler/mode_util.m: compiler/module_qual.m: compiler/post_typecheck.m: compiler/prog_io.m: compiler/prog_mode.m: compiler/prog_type.m: compiler/recompilation.check.m: compiler/recompilation.usage.m: compiler/special_pred.m: compiler/term_constr_build.m: compiler/term_norm.m: compiler/type_ctor_info.m: compiler/type_util.m: compiler/typecheck.m: compiler/unify_proc.m: compiler/untupling.m: compiler/unused_imports.m: Handle the context field in the constructor and constructor_arg types. compiler/check_hlds.m: Add the xml_documentation module. |
||
|
|
863874df85 |
Document my recent change implementing coverage testing.
Estimated hours taken: 6 Branches: main Document my recent change implementing coverage testing. At the same time, eliminate the old hack that allowed a file containing a list of file names to be considered a trace count file. We haven't needed it since the addition of mtc_union, and it can lead to incomprensible error messages. (The presence of the old hack made documenting coverage testing harder.) In the process, fix the tools code for rerunning failed test cases only. doc/user_guide.texi: Document my recent change implementing coverage testing, and the elimination of the old hack. mdbcomp/trace_counts.m: Modify the predicates for reading in trace count files along the lines above. mdbcomp/slice_and_dice.m: Modify the predicates for reading in slices and dices along the lines above. Rename some function symbols to avoid ambiguities. compiler/tupling.m: slice/mcov.m: slice/mtc_diff.m: slice/mtc_union.m: trace/mercury_trace_declarative.c: Conform to the changes above. slice/mcov.m: Fix the usage message, which referred to this program by its old name mct. Allow the output to be restricted to a set of named modules only. This is to make testing easier. slice/mtc_diff.m: Rename the long form of the -o option from --out to --output-file, to make it consistent with the other programs. tests/run_one_test: tools/bootcheck: Modify the algorithm we use to gather trace counts for the Mercury compiler from both passed and failed test cases to run mtc_union periodically instead of gathering all the trace counts file and keeping them to the end (which takes far too much disk space). Fix an old bug: gather trace counts from executions of the Mercury compiler only. tests/debugger/Mmakefile: tests/debugger/dice.passes: Modify the dice test case to compute the union of the trace counts for the passed versions of this test case to use mtc_union to create dice.passes, instead of having dice.passes statically contain the list of the names of the passed trace count files (since that capability is deleted by this diff). tools/bootcheck: tests/Mmake.common: Fix the code for rerunning failed tests only. mdbcomp/prim_data.m: Eliminate some ambiguities in predicate names. compiler/*.m: Conform to the change to prim_data.m. compiler/error_util.m: Add reading files as a phase in error messages. compiler/mercury_compile.m: Use the new facilities in error_util for printing an error message. |
||
|
|
f9cac21e3e |
Get rid of a bunch more ambiguities by renaming predicates, mostly
Estimated hours taken: 8
Branches: main
Get rid of a bunch more ambiguities by renaming predicates, mostly
in polymorphism.m, {abstract,build,ordering}_mode_constraints.m, prog_type.m,
and opt_debug.m in the compiler directory and term_io.m, term.m, parser.m,
and string.m in the library.
In some cases, when the library and the compiler defined the same predicate
with the same code, delete the compiler's copy and give it access to the
library's definition by exporting the relevant predicate (in the undocumented
part of the library module's interface).
NEWS:
Mention that the names of some library functions have changed.
library/*.m:
compiler/*.m:
mdbcomp/*.m:
browser/*.m:
Make the changes mentioned above, and conform to them.
test/general/string_test.m:
test/hard_coded/string_strip.m:
test/hard_coded/string_strip.exp:
Conform to the above changes.
|
||
|
|
586cbb16ac |
Change the implementation of map.merge/3 so that it throws an exception if the
Estimated hours taken: 1.5
Branches: main, release
Change the implementation of map.merge/3 so that it throws an exception if the
sets of keys of the input maps are not disjoint. This is more in keeping with
the documentation for that predicate which says they should be disjoint.
The existing implementation handled duplicate keys by inserting the key and
the smallest of the corresponding values into the output map. Some of the
code in the compiler seems to rely on this behaviour - this is (probably) a
bug but in at least in one instance, to do with merging RTTI varmaps
during higher-order specialisation, it's going to be a bit tricky to fix.
Rather than modify the compiler at the moment the old version of map.merge/3
is available as map.old_merge/3 and the compiler still uses this. (This
predicate is not included in the library reference manual.)
library/map.m:
Make map.merge/3 throw an exception if the sets of keys of the
input maps are not disjoint.
Add the implementor-only predicate map.old_merge/3 for use by the
compiler.
compiler/hlds_rtti.m:
compiler/interval.m:
compiler/prog_io.m:
compiler/tupling.m:
Conform to the above changes.
tests/hard_coded/map_merge_test.{m,exp}:
Test for the new behaviour.
tests/hard_coded/Makefile:
Don't run the above test in deep profiling grades since it
catches exceptions which the deep profiler cannot currently handle.
|
||
|
|
f070e2a1b7 |
Convert the make_hlds stage of the compiler from printing out error messages
Estimated hours taken: 14 Branches: main Convert the make_hlds stage of the compiler from printing out error messages one at a time to gathering them all up and printing them all at once after sorting and deleting duplicates. This approach makes it much easier to be consistent about updating the exit status in the I/O state and the error count in the module info, and indeed this diff fixes some bugs in this area. This approach also means that instead of threading a pair of I/O states through these modules, we now mostly thread through a list of error specifications. In a couple of places, we create the I/O states we need for printing progress messages using trace goals. configure.in: Check that the installed compiler supports trace goals (perhaps with warnings), since the compiler now uses them. compiler/Mercury.options: Temporarily compensate for a bug in the handling of trace goals. compiler/add_class.m: compiler/add_clause.m: compiler/add_mode.m: compiler/add_pragma.m: compiler/add_pred.m: compiler/add_solver.m: compiler/add_type.m: compiler/field_access.m: compiler/foreign.m: compiler/make_hlds_error.m: compiler/make_hlds_passes.m: compiler/make_hlds_warn.m: compiler/module_qual.m: compiler/modules.m: compiler/qual_info.m: compiler/state_var.m: compiler/superhomogeneous.m: Make the change described at the top. In many cases, this required changing code to error util instead of io.write_strings to create the error messages. In some cases, move a predicate used in one module but defined in another module to the first module. Delete some predicates whose job used to be to test options to see whether a message should be generated, since we can now embed the option value that a message depends on in the error message itself. In module_qual.m, remove unnecessary module qualifications. In modules.m, give explicit names to a bunch of lambda expressions. Reformat comments to exploit the available columns. compiler/check_typeclass.m: Conform to the changes above. Mark with XXX the places where we are ignoring the proper update of the error count in module_infos. compiler/modes.m: compiler/post_typecheck.m: compiler/stratify.m: compiler/table_gen.m: compiler/unused_args.m: Use error_specs instead of plain pieces to print error messages. compiler/options.m: Rename an option that conflicts with a language keyword. compiler/handle_options.m: Conform to the change to options.m. compiler/prog_data.m: Rename some function symbols that conflict with language keywords. compiler/prog_out.m: compiler/prog_io_util.m: Conform the change above, and delete some predicates that have now become unused. compiler/mercury_compile.m: Rename a predicate to avoid an ambiguity. Conform to the changes above. compiler/hlds_out.m: compiler/make.module_dep_file.m: compiler/make_hlds.m: compiler/mercury_to_mercury.m: compiler/mode_errors.m: compiler/prog_io.m: Conform to the changes above. In some cases, delete predicates that aren't needed anymore. tests/invalid/errors.err_exp: tests/invalid/errors1.err_exp: tests/invalid/state_vars_test3.err_exp: tests/invalid/undef_inst.err_exp: Update this expected output to reflect the fact that we now sort the error messages. tests/invalid/missing_interface_import2.err_exp: tests/warnings/double_underscore.exp: Update this expected output to reflect the fact that we no longer print the same error message twice. tests/invalid/missing_det_decls.err_exp: Update this expected output to reflect the fact that we now indent an error messages correctly. tests/invalid/multimode_syntax.err_exp: Update this expected output to reflect the fact that we now use error_util instead of plain io.writes to create an error message. tests/invalid/typeclass_test.err_exp: tests/invalid/unsatisfiable_constraint.err_exp: Update this expected output to reflect minor improvements in the formatting of an error message. |
||
|
|
5eee81204e |
A big step towards cleaning up the way we handle errors.
Estimated hours taken: 28 Branches: main A big step towards cleaning up the way we handle errors. The main changes are - the provision, in error_util.m, of a mechanism for completely specifying everything to do with a single error in one data structure, - the conversion of typecheck_errors.m from using io.write_string to using this new capability, - the conversion of mode_errors.m and det_report.m from using write_error_pieces to using this new capability, and - consistently using the quoting style `symname'/N instead of `symname/N' in error_util and hlds_error_util (previously, error_util used the former but hlds_error_util used the latter). This diff sets up later diffs which will collect all error specifications in a central place and print them all at once, in order. compiler/error_util.m: The new type error_spec, which completely specifies an error. An error_spec may have multiple components with different contexts and may have parts which are printed only under certain conditions, e.g. a given option being set. Each error_spec has a severity and also records which phase found the error. The new predicate write_error_spec takes care of updates of the exit status for errors and (if --halt-at-warn is set) for warnings. It also takes care of setting the flag that calls for the reminder about -E at the end. This diff also makes it simpler to use the ability to print arbitrary output. It adds the ability to include integers in messages directly, and the ability to create blank lines. It renames some function symbols to avoid ambiguities. Move a predicate that only used by typecheck_errors.m to that file. compiler/hlds_error_util.m: Switch to the `symname'/N quoting style for describing predicates and procedures. compiler/prog_util.m: Switch to the `symname'/N quoting style for describing sym_name_and_arity. compiler/hlds_module.m: Provide a predicate to increment the number of errors not by one, but by the number of errors printed by write_error_spec. Fix some documentation rot. compiler/typecheck_errors.m: Use write_error_spec instead of io.write_strings to print error messages. In several cases, improve the formatting of the messages printed. Mark a number of places where we don't (yet) update the number of errors in the module_info correctly. Rename the checkpoint predicate to avoid potential ambiguity with similar predicates in e.g. mode_info. compiler/typecheck_info.m: Group the code for writing stuff out together in one bunch. For each such predicate, create another that returns a list of format components instead of doing I/O directly. compiler/typecheck.m: Move the code for writing inference messages here from typecheck_errors.m, since these messages aren't errors. compiler/mode_errors.m: compiler/det_report.m: Use write_error_spec instead of write_error_pieces. In the case of mode_errors.m, this means we now get correct the set of circumstances in which we set the flag that calls for the reminder about -E. compiler/add_pragma.m: compiler/add_type.m: Convert some code that used to use write_error_pieces to print error messages to use write_error_spec instead. compiler/assertion.m: compiler/hlds_pred.m: compiler/post_typecheck.m: Assertion.m used to contain some code to check for assertions in the interface that mention predicates that are not exported. Move most of this code to post_typecheck.m (which is where this code used to be called from). One small part, which is a test for a particular property of import_statuses, is moved to hlds_pred.m to be with all the other similar tests of import_statuses. compiler/prog_util.m: Change unqualify_name from a predicate to a function. compiler/pred_table.m: compiler/hlds_out.m: Avoid some ambiguities by adding a suffix to the names of some predicates. compiler/*.m: Conform to the changes above. library/list.m: Add a function that was previously present (with different names) in two compiler modules. tests/hard_coded/allow_stubs.exp: Update the format of the expected exception. tests/invalid/errors2.err_exp2: Remove this file. As far as I can tell, it was never the correct expected output on the main branch. (It originated on the alias branch way back in the mists of time.) tests/invalid/*.err_exp: tests/invalid/purity/*.err_exp: tests/warnings/*.exp: Update the format of the expected error messages. tests/recompilation/*.err_exp.2: Update the format of the expected messages about what was modified. |
||
|
|
e35f5832d2 |
Make the get and set operations for non-constant mutables thread safe.
Estimated hours taken: 12
Branches: main
Make the get and set operations for non-constant mutables thread safe. (The
get operation for constant mutables is thread safe by definition.) The
source-to-source transformation for (non-constant) mutables is modified as
follows: we introduce four primitive operations: unsafe_get, unsafe_set, lock
and unlock. These operations are private implementation details. The first
two read and write the value of the mutable. In .par grades lock and unlock
are used to respectively acquire and release the mutex associated with the
mutable. In non .par grades they are no-ops.
The user-level mutable operations are now defined in terms of these
primitives. In particular get and set must acquire the mutable's mutex before
they can read or modify its value. (We will shortly add support for atomic
updates to mutables - defined in terms of the above primitives - as well.)
Fix intermodule inlining so that the clauses for the mutable access predicates
are written to .opt files even though they contain calls to impure predicates.
This is usually not allowed because of problems caused by reordering what were
headvar unifications in the original source file. It's okay to do this for
the mutable access predicates since we can guarantee that they won't need to
be reordered by construction.
compiler/make_hlds_passes.m:
Add declarations and implementation for: unsafe_{get,set}, lock
and unlock.
Redefine get/1, set/1, get/3 and set/3 in terms of the above
operations. In .par grades acquire the mutable's mutex before reading
or writing to it and release it afterwards.
Fill in the item_origin field for predicate declarations introduced by
the source-to-source transformation for mutables.
compiler/prog_mutable.m:
Add auxiliary predicates required by the above.
Update the description of the mutable source-to-source transformation.
compiler/prog_util.m:
Add a function: goal_list_to_conj/2. This is needed by the mutable
transformation.
compiler/add_clauses.m:
Delete the function goal_list_to_goal/2 which is identical
to goal_list_to_conj/2 but for the name.
compiler/prog_item.m:
Add an origin field to the pred_or_func item.
compiler/hlds_pred.m:
Add a new pred_marker for identifying predicates that were introduced
by the mutable source-to-source transformation.
compiler/add_pragma.m:
Fill in the item_origin field for the predicate declarations introduced
by tabling pragmas.
compiler/intermod.m:
Mutable access predicates should always be written to the .opt files
if they are referred to by an opt_exported predicate.
Remove the restriction that clauses that call impure predicates should
not be opt_exported in the case where the clause in question was
introduced by the mutable transformation. For those clauses we can
guarantee that there won't be any problems associated with reordering
(the reason given for the restriction) by construction.
Rename some variables.
compiler/prog_io.m:
Fill in the origin field for pred_or_func items.
compiler/add_pred.m:
compiler/equiv_type.m:
compiler/hlds_out.m:
compiler/inlining:
compiler/mercury_to_mercury.m:
compiler/module_qual.m:
compiler/modules.m:
compiler/prog_io_goal.m:
compiler/prog_io_typeclass.m:
compiler/recompilation.check.m:
compiler/recompilation.version.m:
compiler/table_gen.m:
Conform to the above changes.
TODO: update reference manual to mention the new behaviour of mutables in
grades that support concurrency.
|
||
|
|
00741b0162 |
This diff contains no algorithmic changes.
Estimated hours taken: 6 Branches: main This diff contains no algorithmic changes. It merely renames apart a bunch more function symbols to reduce ambiguity. After this diff, the summary line from the mdb command "ambiguity -f" is Total: 351 names used 975 times, maximum 31, average: 2.78 browser/*.m: compiler/*.m: Rename function symbols to eliminate ambiguities. tests/debugger/declarative/dependency.exp: tests/debugger/declarative/dependency2.exp: Update the expected out where some internal function symbol names appear in the output of the debugger. (This output is meant for implementors only.) |
||
|
|
2b2f3d3cbe |
This diff contains no algorithmic changes.
Estimated hours taken: 8 Branches: main This diff contains no algorithmic changes. It merely renames apart a bunch of function symbols to reduce ambiguity. Basically I went through prog_data.m, prog_item.m, hlds_data.m, hlds_goal.m and hlds_pred.m looking for type definitions containing function symbol names that were either language "keywords" (e.g. "terminates", which is an annotation on foreign_procs), used with slightly different meanings in several types (e.g. "sym"), or both (e.g. "call"). When I found such type definitions, I changed the names of the function symbols, usually by adding a prefix or suffix indicating the type to all function symbols of the type. For example, the old function symbol "foreign_proc" in type "pragma_type" is now named "pragma_foreign_proc", and the names of all other function symbols in that type also start with "pragma_". All of this should yield simpler compiler error messages when we make mistakes, and will make it more likely that looking up a function symbol using a tags file will take you to the actual definition of the relevant instance of that function symbol. However, the most important benefit is the increase in the readability of unfamiliar code; the reader won't have to emulate the compiler's type ambiguity resolution algorithm (which in many cases used to require distinguishing between f/14 and f/15 by counting the arguments, e.g. for "pred_or_func"). compiler/prog_data.m: compiler/prog_item.m: compiler/hlds_data.m: compiler/hlds_goal.m: compiler/hlds_pred.m: Rename function symbols as explained above. compiler/*.m: Conform to the function symbol renames. In some cases, rename other function symbols as well. Minor style fixes, e.g. replace if-then-elses with switches, or simple det predicates with functions. |
||
|
|
16184103d7 |
Add new documentation for the implementation of mutables.
Estimated hours taken: 1 Branches: main Add new documentation for the implementation of mutables. compiler/prog_mutable.m: Provide an up-to-date description of the source-to-source transformation used to implement mutables. compiler/prog_io.m: Delete the old description of the transformation. (This hadn't been maintained and was quite out-of-date.) Minor documentation update caused by the removal of the mutable `thread_safe' attribute. compiler/make_hlds_passes.m: Add a pointer to the new documentation in prog_mutable.m. |
||
|
|
fe65fe427e |
Get rid of the `thread_safe' mutable attribute, since this doesn't actually
Estimated hours taken: 1
Branches: main, release
Get rid of the `thread_safe' mutable attribute, since this doesn't actually
make access to a mutable thread safe (in fact it makes them less thread
safe than the `not_thread_safe' version).
By extension this also removes support for the `not_thread_safe' mutable
attribute.
compiler/prog_io.m:
compiler/prog_item.m:
compiler/prog_mutable.m:
Remove support for the `thread_safe' mutable attribute.
compiler/make_hlds_passes.m:
Remove support for the `thread_safe' mutable attribute.
Mark the foreign clauses for `get' predicates for constant
mutables as thread safe.
doc/reference_manual.texi:
Delete the documentation for the `thread_safe' mutable attribute.
tests/hard_coded/mutable_decl.m:
tests/hard_coded/pure_mutable.m:
tests/hard_coded/trace_goal_env_1.m:
tests/hard_coded/trace_goal_env_2.m:
tests/hard_coded/unusual_name_mutable.m:
tests/hard_coded/sub-modules/mutable_child.m:
tests/hard_coded/sub-modules/mutable_grandchild.m:
tests/hard_coded/sub-modules/mutable_parent.m:
tests/invalid/bad_mutable.{err_exp,m}:
tests/invalid/not_in_interface.m:
Conform to the above change.
|
||
|
|
9d23d8e2e7 |
Implement the trace goal construct we discussed, for now for the LLDS backends
Estimated hours taken: 70
Branches: main
Implement the trace goal construct we discussed, for now for the LLDS backends
only.
Since the syntax of trace goals is non-trivial, useful feedback on syntax
errors inside trace goal attributes is essential. With the previous setup, this
wasn't possible, since the code that turned terms into parse tree goals turned
*all* terms into goals; it couldn't recognize any errors, sweeping them under
the rug as calls. This diff changes that. Now, if this code recognizes a
keyword that indicates a particular construct, it insists on the rest of the
code following the syntax required for that construct, and returns error
messages if it doesn't.
We handle the trace goal attributes that specify state variables to be threaded
through the trace goal (either the I/O state or a mutable variable) in
add_clause.m, at the point at which we transform the list of items to the HLDS.
We handle the compile-time condition on trace goals in the invocation of
simplify at the end of semantics analysis, by eliminating the goal if the
compile-time condition isn't met. We handle run-time conditions on trace goals
partially in the same invocation of simplify: we transform trace goals with
runtime conditions into an if-then-else with the trace goal as the then part
and `true' as the else part, the condition being a foreign_proc that is handled
specially by the code generator, that special handling being to replace
the actual code of the foreign_proc (which is a dummy) with the evaluation of
the runtime condition.
Since these changes require significant changes to some of our key data
structures, I took the liberty of doing some renaming of function symbols
at the same time to avoid using ambiguities with respect to language keywords.
library/ops.m:
Add "trace" as an operator.
compiler/prog_data.m:
Define data types to represent the various attributes of trace goals.
Rename some function symbols to avoid ambiguities.
compiler/prog_item.m:
Extend the parse tree representation of goals with a trace goal.
compiler/mercury_to_mercury.m:
Output the new kind of goal and its components.
compiler/hlds_goal.m:
Extend the HLDS representation of scopes with a scope_reason
representing trace goals.
Add a mechanism (an extra argument in foreign_procs) to allow
the representation of goals that evaluate runtime trace conditions.
Since this requires modifying all code that traverses the HLDS,
do some renames that were long overdue: rename not as negation,
rename call as plain_call, and rename foreign_proc as
call_foreign_proc. These renames all avoid using language keywords
as function symbols.
Change the way we record goals' purities. Instead of optional features
to indicate impure or semipure, which is error-prone, use a plain
field in the goal_info, accessed in the usual way.
Add a way to represent that a goal contains a trace goal, and should
therefore be treated as if it were impure when considering whether to
optimize it away.
Reformat some comments describing function symbols.
compiler/hlds_out.m:
Output the new construct in the HLDS.
compiler/prog_io_util.m:
Generalize the maybe[123] types to allow the representation of more
than one error message. Add functions to extract the error messages.
Add a maybe4 type. Rename the function symbols of these types to
avoid massive ambiguity.
Change the order of some predicates to bring related predicates
next to each other.
compiler/prog_io.m:
compiler/prog_io_dcg.m:
compiler/prog_io_goal.m:
compiler/prog_io_pragma.m:
Rework these modules almost completely to find and accumulate syntax
errors as terms are being parsed. In some cases, this allowed us to
replace "XXX this is a hack" markers with meaningful error-reporting
code.
In prog_io_goal.m, add code for parsing trace goals.
In a bunch of places, update obsolete coding practices, such as using
nested chains of closures instead of simple sequential code, and
using A0 and A to refer to values of different types (terms and goals
respectively). Use more meaningful variable names.
Break up some too-large predicates.
compiler/superhomogeneous.m:
Find and accumulate syntax errors as terms are being parsed.
compiler/add_clause.m:
Add code to transform trace goals from the parse tree to the HLDS.
This is where the IO state and mutable variable attributes of trace
goals are handled.
Eliminate the practice of using the naming scheme Body0 and Body
to refer to values of different types (prog_item.goal and hlds_goal
respectively).
Use error_util for some error messages.
library/private_builtin.m:
Add the predicates referred to by the transformation in add_clause.m.
compiler/goal_util.m:
Rename a predicate to avoid ambiguity.
compiler/typecheck.m:
Do not print error messages about missing clauses if some errors have
been detected previously.
compiler/purity.m:
Instead of just computing purity, compute (and record) also whether
a goal contains a trace goal. However, treat trace goals as pure.
compiler/mode_info.m:
Add trace goals as a reason for locking variables.
Rename some function symbols to avoid ambiguity.
compiler/modes.m:
When analyzing trace goal scopes, lock the scope's nonlocal variables
to prevent them from being further instantiated.
compiler/det_analysis.m:
Insist on the code in trace goal scopes being det or cc_multi.
compiler/det_report.m:
Generate the error message if the code in a trace goal scope isn't det
or cc_multi.
compiler/simplify.m:
At the end of the front end, eliminate trace goal scopes if their
compile-time condition is false. Transform trace goals with runtime
conditions as described at the top.
Treat goals that contain trace goals as if they were impure when
considering whether to optimize them away.
compiler/mercury_compile.m:
Tell simplify when it is being invoked at the end of the front end.
Rename a predicate to avoid ambiguity.
compiler/trace_params.m:
Provide the predicates simplify.m need to be able to evaluate the trace
goal conditions regarding trace levels.
compiler/trace.m:
compiler/trace_gen.m:
Rename the trace module as trace_gen, since "trace" is now an operator.
Rename some predicates exported by the module, now that it is no longer
possible to preface calls with "trace." as a module qualifier.
compiler/notes/compiler_design.html:
Document this name change.
compiler/options.m:
Rename the trace option as trace_level internally, since "trace"
is now an operator. The user-visible name remains the same.
Add the new --trace-flag option.
Delete an obsolete option.
compiler/handle_options.m:
Rename the function symbols of the grade_component type,
since "trace" is now an operator.
compiler/llds.m:
Extend the LLDS with a mechanism to refer to C global variables.
For now, these are used to refer to C globals that will be created
by mkinit to represent the initial values of the environment variables
referred to by trace goals.
compiler/commit_gen.m:
Check that no trace goal with a runtime condition survives to code
generation; they should have been transformed by simplify.m.
compiler/code_gen.m:
Tell commit_gen.m what kind of scope it is generating code for.
compiler/pragma_c_gen.m:
Generate code for runtime conditions when handling the foreign_procs
created by simplify.m.
compiler/code_info.m:
Allow pragma_c_gen.m to record what environment variables it has
generated references to.
compiler/proc_gen.m:
Record the set of environment variables a procedure refers to
in the LLDS procedure header, for efficient access by llds_out.m.
compiler/llds_out.m:
Handle the new LLDS construct, and tell mkinit which environment
variables need C globals created for them.
compiler/pd_util.m:
Rename some predicates to avoid ambiguity.
compiler/*.m:
Conform to the changes above, mainly the renames of function symbols
and predicates, the changed signatures of some predicates, and the new
handling of purity.
util/mkinit.c:
Generate the definitions and the initializations of any C globals
representing the initial status (set or not set) of environment
variables needed by trace goals.
library/assoc_list.m:
Add some predicates that are useful in prog_io*.m.
library/term_io.m:
Minor cleanup.
tests/hard_coded/trace_goal_{1,2}.{m,exp}:
New test cases to test the new construct, identical except for whether
the trace goal is enabled at compile time.
tests/hard_coded/trace_goal_env_{1,2}.{m,exp}:
New test cases to test the new construct, identical except for whether
the trace goal is enabled at run time.
tests/hard_coded/Mercury.options:
tests/hard_coded/Mmakefile:
Enable the new test cases.
tests/invalid/*.err_exp:
Update the expected output for the new versions of the error messages
now being generated.
|
||
|
|
c3b1c2003e |
Support constant "mutables". Though this sounds like a contradiction in terms,
Estimated hours taken: 3
Branches: main
Support constant "mutables". Though this sounds like a contradiction in terms,
they can be useful, because in some cases they are the best alternative.
- For some types, e.g. arrays, there is no way to write manifest constants.
- For some other types, one can write manifest constants, but the compiler
may be too slow in compiling clauses containing them if the constant is
very large (even after my recent improvements).
- Using a tabled zero-arity function incurs overhead on every access to check
whether the result was recorded previously or not. This is a bad idea e.g.
in the inner loop of a scanner (which may want to use an array for the
representation of the DFA).
compiler/prog_item.m:
Add a new attribute to say whether the mutable is constant or not.
compiler/prog_io.m:
Recognize the "constant" mutable attribute.
compiler/prog_mutable.m:
Provide predicates to construct the signatures of the get and set
predicates of constant mutables. Rename some existing predicates
to better reflect their purpose.
compiler/make_hlds_passes.m:
compiler/modules.m:
Modify the code for creating mutables' get, set and init predicates
to do the right thing for constant mutables.
doc/reference_manual.texi:
Document the new attribute.
tests/hard_coded/pure_mutable.{m,exp}:
Test the new attribute.
|
||
|
|
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. |
||
|
|
19159de6b7 |
Add a new goal form, as discussed on our mailing lists:
Estimated hours taken: 12
Branches: main
Add a new goal form, as discussed on our mailing lists:
promise_equivalent_solution_sets [Vars] (
arbitrary [Vars1] Goal1,
arbitrary [Vars2] Goal2,
...
)
NEWS:
Mention the new goal form.
doc/reference_manual.texi:
Document the new goal form.
library/ops.m:
Add "promise_equivalent_solution_sets" and "arbitrary" as new
operators.
compiler/prog_item.m:
Add a parse_tree representation of new constructs.
Change the representation of goal forms in the parse tree to avoid
using punctuation marks as function symbols, to avoid function symbols
that need quoting, and to avoid ambiguity with hlds_goal_expr.
Delete the obsolete if_then (no else) goal form.
compiler/hlds_goal.m:
Provide a HLDS representation of the new constructs.
compiler/det_analysis.m:
Implement the rules for processing the new constructs.
compiler/det_report.m:
Implement the messages for the errors that can occur with the
new constructs.
Add quotes around `promise_equivalent_solutions' in an existing error
message, for consistency.
compiler/prog_io_goal.m:
Parse the new goal constructs.
compiler/add_clause.m:
compiler/hlds_out.m:
compiler/make_hlds_passes.m:
compiler/make_hlds_warn.m:
compiler/mercury_to_mercury.m:
compiler/module_qual.m:
compiler/pd_util.m:
compiler/prog_io.m:
compiler/prog_io_dcg.m:
compiler/prog_io_goal.m:
compiler/prog_util.m:
compiler/saved_vars.m:
compiler/simplify.m:
Conform to the changes to prog_item.m and hlds_goal.m.
tests/hard_coded/one_member.{m,exp}:
New test case to test the proper functioning of the new construct.
tests/invalid/one_member.{m,err_exp}:
New test case to test the kinds of errors that can occur when using
the new construct.
tests/hard_coded/Mmakefile:
tests/invalid/Mmakefile:
Enable the new test cases.
tests/invalid/promise_equivalent_solutions_test.err_exp:
Expect quotes around an old construct name, after the change to
det_report.m.
|
||
|
|
007ca75f87 |
Fix a bug with solver types and mutables that was causing the compiler to
Estimated hours taken: 6 Branches: main Fix a bug with solver types and mutables that was causing the compiler to abort in deep profiling grades (The HLDS was incorrect in all grades, it just didn't show in most of them). The bug occurred when a mutable was initialised with a non-ground value, as in the following example derived from Ralph's sat solver: :- mutable(global, sat_literal, _, any, [untrailed]). (sat_literal is some solver type). The problem was that when adding the clauses for the mutable initialisation predicates to the HLDS we did not consider that the initial value might be a variable, as in this case, and attached an empty varset to the clause instead of one containing the variable. For the intialisation predicate for the above mutable, we have the following at stage 197: msat.initialise_mutable_global :- msat.'__Initialise__'(V_1), impure msat.set_global(V_1). The prog_varset is (incorrectly) empty at this point - it should contain V_1. Deep profiling, stage 205, now comes along and starts allocating fresh variables. The results pretty much speak for themselves ;-) msat.initialise_mutable_global :- ProcStaticLayout = deep_profiling_proc_layout(...), impure det_call_port_code_sr(ProcStaticLayout, TopCSD, MiddleCSD, ActivationPtr), SiteNum = 0, impure prepare_for_normal_call(SiteNum), msat.'__Initialise__'(TopCSD), % *** should be V_1 SiteNum = 1, impure prepare_for_normal_call(SiteNum), impure msat.set_global(TopCSD), % *** should be V_1 impure det_exit_port_code_sr(TopCSD, MiddleCSD, ActivationPtr). The fix is to attach the varset we use at parse time to the mutable items and when adding the clauses for the mutable initialisation predicate to the HLDS, to use that varset instead of an empty one. compiler/prog_item.m: compiler/prog_io.m: Attach the varset to the mutable item, in case the initial value term has a non-ground value. compiler/make_hlds_passes.m: Use the above varset when constructing the clauses for the mutable initialisation predicates in order to avoid the bug outlined above. compiler/equiv_type.m: compiler/mercury_to_mercury.m: compiler/module_qual.m: compiler/modules.m: compiler/recompilation.check.m: compiler/recompilation.version.m: Conform to the above changes to the mutable item. tests/valid/Mmakefile: tests/valid/solver_type_mutable_bug.m: Test case for the above derived from msat.m by Ralph. |
||
|
|
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. |
||
|
|
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. |
||
|
|
a8d3e06db7 |
Add support for `constraint_store is mutable(...)' or
Estimated hours taken: 3 Branches: main Add support for `constraint_store is mutable(...)' or `constraint_store is [mutable(...), ...]' attributes on solver type definitions. compiler/equiv_type.m: compiler/equiv_type_hlds.m: compiler/module_qual.m: compiler/prog_data.m: The solver_type_details structure now contains the list of mutable declatations given in the constraint_store attribute (empty if this attribute was not provided). compiler/make_hlds_passes.m: Process the constraint_store mutable items for solver types. compiler/mercury_to_mercury.m: Output the constraint_store attribute value for solver types if present. compiler/prog_io.m: Parse the new attribute. doc/reference_manual.texi: Document the addition of constraint_store solver type attributes. |
||
|
|
2a477fb7e7 |
Split the parse tree (currently defined in prog_data.m) into two
Estimated hours taken: 3.5 Branches: main Split the parse tree (currently defined in prog_data.m) into two separate modules. The reason for doing this is that while over 80% of the modules in the compiler import prog_data, very few of them actually require access to the types that define the parse tree (principally the item type). At the moment even small changes to these types can result in recompiles that rebuild almost all of the compiler. This change shifts the item type (and related types) into a new module, prog_item, that is only imported where these types are required (mostly at the frontend of the compiler). This should reduce the size of recompiles required when the parse tree is modified. This diff does not change any algorithms; it just shifts things around. compiler/prog_data.m: Move the item type and any related types that are not needed after the HLDS has been built to the new prog_item module. Fix bitrot in comments. Fix formatting and layout of comments. Use unexpected/2 in place of error/1 in a spot. compiler/prog_item.m: New file. This module contains any parts of the parse tree that are not needed by the rest of the compiler after the HLDS has been built. compiler/check_typeclass.m: s/list(instance_method)/instance_methods/ compiler/equiv_type.m: compiler/hlds_module.m: compiler/intermod.m: compiler/make.module_dep_file.m: compiler/make_hlds.m: compiler/mercury_compile.m: compiler/mercury_to_mercury.m: compiler/module_qual.m: compiler/modules.m: compiler/parse_tree.m: compiler/prog_io.m: compiler/prog_io_dcg.m: compiler/prog_io_goal.m: compiler/prog_io_pragma.m: compiler/prog_io_typeclass.m: compiler/prog_io_util.m: compiler/prog_out.m: compiler/prog_util.m: compiler/recompilation.check.m: compiler/recompilation.usage.m: compiler/recompilation.version.m: compiler/trans_opt.m: Conform to the above changes. compiler/notes/compiler_design.html: Mention the new module. |
||
|
|
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'. |
||
|
|
d7554de953 |
Convert a bunch more modules to four-space indentation.
Estimated hours taken: 5 Branches: main browser/*.m: compiler/*.m: mdbcomp/*.m: Convert a bunch more modules to four-space indentation. |
||
|
|
192a58021b |
Add optional support for generating a pure interface to mutables.
Estimated hours taken: 8 Branches: main Add optional support for generating a pure interface to mutables. This is done by adding a new mutable attribute, `attach_to_io_state'. If this attribute is specified in the mutable declaration then in addition to the usual non-pure access predicates, the compiler will also add a pair of access predicates that take the IO state. compiler/prog_data.m: Add the `attach_to_io_state' mutable attribute. Add the necessary access predicates for the mutable_var_attributes structure. compiler/prog_io.m: Parse the `attach_to_io_state' attribute. compiler/prog_mutable.m: Shift some of the code for constructing items related to mutables to this module from make_hlds_passes. This reduces unnecessary clutter in the latter. Remove the XXX comment about needing to mangle the names of the globals - we now do that. compiler/make_hlds_passes.m: If a mutable has the `attach_to_io_state' attribute specified then create pure access predicates that take the IO state in addition to the non-pure ones. compiler/modules.m: If we are generating the pure access predicates then output the declarations for these predicates in private interfaces. compiler/type_util.m: Replace the use of ':' as a module qualifier in some comments. doc/reference_manual.texi: Document the `attach_to_io_state' mutable attribute. vim/syntax/mercury.vim: Highlight various mutable attributes appropriately. tests/hard_coded/Mmakefile: tests/hard_coded/pure_mutable.m: tests/hard_coded/pure_mutable.exp: Test mutables with pure access predicates. tests/hard_coded/ppc_bug.m: Unrelated change: update the comments in this test case so they describe what the cause of the bug and the fix were. |
||
|
|
2755655989 |
Support impure initialise and finalise predicates in user code.
Estimated hours taken: 4 Branches: main Support impure initialise and finalise predicates in user code. In order to support this the arity of the initialise or finalise predicate can no longer be optionally omitted from the declaration. Supporting impure arity zero initialise/finalise declarations removes the restriction that every module that has an initialise/finalise declaration must import the io module. Allow initialize/finalize to be used as synonyms for initialise/finalise. Improve the documentation of initialise/finalise declarations. In particular: - mention the above changes. - mention that they may be cc_multi. - specify the order in which they invoked with respect to standard library initialisation/finalisation. - mention that these declarations are not currently available on non-C backends. compiler/make_hlds_passes.m: Support impure user initialise/finalise predicates. compiler/mercury_to_mercury.m: Write out the arities of the predicates specified in initialise and finalise declarations. compiler/prog_data.m: Add an arity field to the initialise and finalise items. compiler/prog_io.m: Don't allow the arity to be omitted in initialise and finalise declarations. compiler/module_qual.m: compiler/modules.m: compiler/recompilation.check.m: compiler/recompilation.version.m: Conform to the changes in the initialise and finalise items. library/ops.m: Add the alternate spellings of initialise and finalise to the ops table. doc/reference_manual.texi: Update the ops table. Mention that initialise and finalise predicates may be cc_multi. Document impure initialisation and finalisation predicates. Add some disclaimers: mutable, initialise and finalise declarations are not implemented for the non-C backends. tests/hard_coded/Mmakefile: tests/hard_coded/impure_init_and_final.m: tests/hard_coded/impure_init_and_final.exp: Test impure initialise and finalise declarations. tests/hard_coded/finalise_decl.m: tests/hard_coded/intialise_decl.m: Conform to the above changes. Also test the versions of the declarations that use the -ize ending. tests/hard_coded/sub-modules/finalise_parent.m: tests/hard_coded/sub-modules/initialise_child.m: tests/hard_coded/sub-modules/initialise_parent.m: Conform to the above changes. tests/invalid/bad_finalise.m: tests/invalid/bad_finalise.err_exp: tests/invalid/bad_initialise.m: tests/invalid/bad_initialise.err_exp: Extend these tests to check for missing or bad arities in intialise or finalise declarations. vim/syntax/mercury.vim: Highlight recently added syntax appropriately. |
||
|
|
f57fe1b7df |
Add language and compiler support for finalise declarations.
Estimated hours taken: 8
Branches: main
Add language and compiler support for finalise declarations.
NEWS:
Mention finalise declarations.
compiler/prog_data.m:
Add a new item type for finalise declarations.
Add a new kind of item origin - items can now be introduced as part of
the source-to-source transformation that implements finalise
declarations.
compiler/prog_io.m:
Parse finalise declarations.
compiler/modules.m:
Don't write out finalise declarations in private interfaces.
compiler/hlds_module.m:
Add a slot to the HLDS that stores the names of the predicates in
finalise declarations.
Add access predicates for the above.
compiler/add_pragma.m:
compiler/make_hlds_passes.m:
Fix in incorrect comment: we add initialise declarations on third, not
second, pass.
Restore the code that use the enhanced switch detection capability.
Implement the source-to-source transformation that implements finalise
declarations. This is almost identical to that for intitialise
declarations.
compiler/llds.m:
compiler/llds_out.m:
compiler/transform_llds.m:
Add a slot to the LLDS to hold the name of the predicates specified in
the finalise declarations.
Emit the necessary code to call these predicates after main has finished.
compiler/mlds.m:
compiler/ml_code_gen.m:
compiler/ml_elim_nested.m:
compiler/ml_optimize.m:
compiler/ml_tailcall.m:
compiler/mlds_to_c.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_il.m:
compiler/mlds_to_ilasm.m:
compiler/mlds_to_java.m:
compiler/mlds_to_managed.m:
As above, but for the MLDS.
compiler/mercury_compile.m:
Conform to changes in the MLDS.
XXX This module probably shouldn't manipulating the MLDS directly.
compiler/module_qual.m:
compiler/mercury_to_mercury.m:
compiler/recompilation.check.m:
compiler/recompilation.version.m:
Conform to the above changes.
library/ops.m:
Add `finalise' as an operator.
runtime/mercury_wrapper.c:
Call any user specified finalise predicates from
mercury_runtime_terminate.
doc/reference_manual.texi:
Document finalise declarations.
tests/hard_coded/Mmakefile:
tests/hard_coded/finalise_decl.m:
tests/hard_coded/finalise_decl.exp:
Tests finalise declarations.
tests/hard_coded/sub-modules/Mmakefile:
tests/hard_coded/sub-modules/finalise_child.m:
tests/hard_coded/sub-modules/finalise_parent.m:
tests/hard_coded/sub-modules/finalise_parent.{exp,exp2}:
Test finalise declarations and sub-modules. There are two expected
outputs because the order of execution between a parent module and its
children of any finalisers is arbitrary.
tests/invalid/Mmakefile:
tests/invalid/bad_finalise_decl.m:
tests/invalid/bad_finalise_decl.err_exp:
Test error messages associated with finalise declarations.
|
||
|
|
2856c276d5 |
Make the declarations for the globals variables used to implement mutables
Estimated hours taken: 8
Branches: main
Make the declarations for the globals variables used to implement mutables
visible across module boundaries. Not doing so means that we cannot inline
the access predicates across module boundaries (this is currently causing
the tests for mutables and sub-modules to fail on that compile with
--intermodule-optimization).
Doing so requires us to module qualify the globals in the generated code, this
diff also fixes an earlier XXX about not mangling the names of mutables.
Add another mutable attribute, foreign_name, that allows the user to override
the compiler's choice of name for the global variable. This is useful where
foreign code needs also needs to access the mutable, e.g. in library
bindings. Currently, we only support this facility in the C backends.
(Actually, it's almost implemented for the other backends as well, but
there's no way to test it at the moment).
Support `trailed' and `not_thread_safe' as mutable attributes. These are
the defaults so in practice they will probably rarely be used.
compiler/make_hlds_passes.m:
If there is a foreign_name attribute for a mutable, then use that name
rather than a compiler generated one.
Make sure that there is a declaration for the global variable in the
module's .mh file.
Emit an error message if an attempt is made to use a trailed mutable
in a non-trailing grade.
compiler/prog_mutable.m:
Append the module name to the name of the global variable used to
implement the mutable.
compiler/prog_data.m:
Make the set of mutable attributes into an abstract type. Handle this
in a similar fashion to foreign code attributes.
Add access predicates for the above type.
Fix the positioning of comments and section headings in this module.
Unrelated change: add a comment explaining why the intermediate
form of the constraints in the termination2_info pragmas is necessary.
compiler/prog_io.m:
Parse the new mutable attributes.
Update the description of the source-to-source transformation used to
implement mutable variables.
compiler/prog_io_pragma.m:
Export the predicate parse_foreign_language/2. It is now needed
by the code that parses mutable declarations.
compiler/globals.m:
Add a function that returns the compilation target as a string.
doc/reference_manual.m:
Document the new attributes.
tests/invalid/Mmakefile:
tests/invalid/Mercury.options:
tests/invalid/trailed_mutable.m:
tests/invalid/trailed_mutable.err_exp:
Test the error message that results if a trailed mutable is used in a
non-trailing grade.
tests/hard_coded/bad_mutable.{m,err_exp}:
Extend this test case to cover the new attributes.
tests/hard_coded/Mmakefile:
tests/hard_coded/foreign_name_mutable.{m,exp}:
tests/hard_coded/unusual_name_mutable.{m,exp}:
Further test for mutable variables.
|
||
|
|
168cb85743 |
Make ':' into an infix type qualification operator, equivalent to with_type.
Estimated hours taken: 2 Branches: main Make ':' into an infix type qualification operator, equivalent to `with_type`. compiler/prog_io.m: Handle type qualifications in pred and func declarations that use ':'. compiler/superhomogeneous.m: Handle type qualifications using ':' in clauses. library/ops.m: Change the precedence of ':' so that it is identical to `with_type`. doc/reference_manual.texi: Update the list of operators. Update the section on explicit type qualification expressions. tests/hard-coded/type_qual.m: Use the new syntax in this test case. (There are lots of other test cases that exercise the old syntax.) NEWS: Mention that ':' is now the type qualification operator. |
||
|
|
f3ecb78195 |
Remove supported for deprecated syntax. The syntax removed is:
Estimated hours taken: 0.5 Branches: main Remove supported for deprecated syntax. The syntax removed is: - ':' as a module qualifier. - '::' and '->' for mode definitions. - the old-style pragma syntax. The 0.12 release issues warnings for uses of this syntax. XXX This also needs to be mentioned in the news file, but since I need to clean up the main branch news file I'll do that as a separate change. compiler/prog_io.m: compiler/prog_io_pragma.m: compiler/prog_io_util.m: Remove support for the syntax mentioned above. Break up an overlong line. doc_reference_manual.texi: Remove the documentation for the above syntax. compiler/recompilation.m: compiler/rl_info.m: compiler/fact_table.m: Remove deprecated syntax from these modules. |
||
|
|
3fc6b3f128 |
Change the representation of types in the compiler.
Estimated hours taken: 30 Branches: main Change the representation of types in the compiler. We also add some support for handling kinds, which will be used later when we have a kind system. There are a number of places where kinds are not yet handled correctly -- we assume that all kinds will be `star'. Each of these locations is flagged with a comment that contains "XXX kind inference:". compiler/prog_data.m: Implement the new version of type (type). Change the definition of type_param to be a variable instead of a term, since all parameters must be variables anyway. Implement versions of varset.merge_* which work with tvarsets and produce renamings instead of substitutions. Renamings are more convenient than substitutions because we don't need to know the kinds of type variables in order to build the renaming, and in any case the substitutions shouldn't have anything other than variables in the range so renamings will be more efficient and safe. Define the type of kinds, and provide a couple of utility predicates to operate on them. compiler/prog_io.m: Parse type definition heads as a sym_name and list of type_params, rather than a functor. Handle this change in other predicates. Allow parse errors to be returned by get_with_type/3, and handle these errors. Remove parse_type/2. This predicate didn't do any processing, it just forwarded handling to convert_type/2. compiler/prog_io_typeclass.m: Change type_is_functor_and_vars to handle the new representation of types. In doing so, we retain the old behaviour that pure predicates pass this test, but no other pred or func types. This behaviour is arguably incorrect, but there is little point changing the behaviour at the moment. Instead we should remove these kind of restrictions entirely, but that should be done later. compiler/prog_io_util.m: Provide predicates to both parse and unparse types. We need to unparse types before printing them out, since we do a lot of special case handling when printing out terms and we don't want to duplicate this functionality for types. compiler/module_qual.m: Remove report_invalid_type. We now report ill-formed types during parsing. compiler/superhomogeneous.m: Handle errors from the parsing of type expressions. compiler/prog_out.m: Provide a predicate to convert builtin_types to their string names, and vice-versa. compiler/prog_type.m: Add a bunch of simple tests to use on types which may have kind annotations present. In such cases, types do not have a canonical representation so the simple handling of these tests is not what we want. (Note that these are only required in early phases. The kind annotations -- when they are implemented -- will be removed before type checking.) Consistently handle the application of renamings, substitutions and recursive substitutions to various data structures. compiler/mercury_to_mercury.m: Implement mercury_output_type, mercury_format_type and mercury_type_to_string. These convert the type to a term before formatting -- the reason for this is so that appropriate parentheses are used when formatting operators. This results in some slight changes to error messages, which are reflected in changes to the expected output files in the tests. Remove the old version of mercury_type_to_string. Change the argument ordering of mercury_format_var to be consistent with mercury_format_type. (Other predicates in this module should probably be changed in a similar way, since this argument ordering is more amenable to higher-order programming. But that can be left for another change.) compiler/type_util.m: Implement type unification. The behaviour is much the same as the previous behaviour, except that we now handle apply/N types properly, and we also allow for kind annotations. Implement an occurs check for types. Remove the example definition of replace_eqv_type. It isn't used and would no longer work anyway even if it would have worked before. Add a tvar_kind_map field to ctor_defn. The functions type_info_type and type_ctor_info_type now return types with `void' as their argument, rather than the type that the type_info or type_ctor_info was for. Remove type_util.real_vars/2, since it no longer does anything different from prog_type.vars/2. Remove the commented out implementation of type_to_ctor_and_args/3. Its implementation is in prog_type.m, and has changed significantly in any case. compiler/add_clause.m: Move parse_purity_annotation/3 to prog_io_util.m. compiler/check_typeclass.m: Remove apply_substitution_to_var_list/3, since we now have predicates in prog_type.m to handle such things. compiler/continuation_info.m: compiler/trace.m: Use prog_type.vars/2 instead of type_util.real_vars/2. The two predicates have the same meaning now since type_infos don't contain any type variables. compiler/hlds_data.m: Add tvar_kind_map fields to hlds_type_defn and hlds_class_defn. compiler/hlds_pred.m: Add a tvar_kind_map field to pred_info. compiler/polymorphism.m: Add a tvar_kind_map field to poly_info. Remove unify_corresponding_types, which is no longer used. compiler/hlds_out.m: Use mercury_output_type/5 instead of term_io__write_term/4 and mercury_output_term/5. compiler/post_typecheck.m: Build the void substitution directly rather than building intermediate lists. compiler/recompilation.version.m: Use term__list_subsumes instead of type_list_subsumes, which now operates only on types. This follows up on what was suggested in an XXX comment. compiler/typecheck_errors.m: Use unparse_type/2 to format error messages. compiler/typecheck_info.m: Don't export write_type_with_bindings/5. It is no longer used outside of this module. compiler/*.m: Conform to the above changes. library/rtti_implementation.m: Fix a syntax error that went undetected in our previous implementation, and amazingly enough was compiled correctly anyway. library/term.m: Move the versions of term__unify, term__unify_list and term__list_subsumes that were implemented specifically for types to here. The version of term_unify that takes a list of bound variables (i.e., variables that should not be bound any further) is used by the subsumption check, which in turn is used by recompilation.version.m. tests/invalid/kind.err_exp: tests/invalid/tc_err1.err_exp: tests/invalid/tc_err2.err_exp: tests/misc_tests/pretty_print_test.exp: Update the expected output of these tests to match what we now do. |
||
|
|
a25ba19ea0 |
Improve the error checking for mutable declarations.
Estimated hours taken: 12 Branches: main Improve the error checking for mutable declarations. Fix a bug with solver types and sub-modules reported by Peter Hawkins. Workaround a bug with mutable declarations and sub-modules. Currently, the compiler aborts if there is a mutable declaration in the parent module. With this change mutable declarations will not be visible in child modules. XXX This is not correct since they should be visible, but this can be fixed as a separate change. compiler/prog_data.m: Extend the item_origin type with information about what source-to-source transformations are responsible for compiler introduced items. We need this information for error checking mutable declarations. It also provides an additional layer of sanity checking in the parse tree. Add origin fields to the clause and initialise items, since they can both now be introduced by source-to-source transformations. compiler/prog_io.m: compiler/prog_io_dcg.m: compiler/prog_io_typeclass.m: Conform to the above change. compiler/make_hlds_passes.m: Don't issue spurious errors about initialise declarations that were introduced by the transformation for mutable declarations. Abort if invalid initialise declarations were introduced by other compiler passes since this indicates a bug in the compiler. Check if mutable declarations occur in the interface of a module and emit an error if they do. Don't generate initialise items and foreign code from a mutable declaration unless we are in the defining module for the mutable declaration. Don't generate foreign_procs for solver types *unless* we are in the defining module. Doing otherwise breaks the compiler when using solver types and sub-modules. Fix the formatting of an error message concerning initialise decls. s/foreign_code/foreign_proc/ in a spot. compiler/add_solver.m: compiler/mercury_to_mercury.m: compiler/recompilation.check.m: compiler/recompilation.version.m: compiler/add_class.m: compiler/add_pragma.m: compiler/state_var.m: Conform to the above changes. compiler/modules.m: Handle mutable declarations in private interfaces. Clean up some code related to foreign_import_module decls. Conform to the changes in prog_data.m. compiler/prog_util.m: Shift the functions for mutable access predicates and variables to this module. The code that generates interface files also needs to be able to access them. compiler/module_qual.m: Conform to the above changes. Fix a bug where the context in the mq_info structure was not being updated. This caused error messages for mutable declarations that contain undefined types or insts to have the wrong context. compiler/hlds_data.m: Fix a typo. vim/syntax/mercury.vim: Highlight `mutable' and `untrailed' appropriately. tests/hard_coded/sub-modules/Mmakefile: tests/hard_coded/sub-modules/ts.m: tests/hard_coded/sub-modules/ts.tsub.m: tests/hard_coded/sub-modules/ts.exp: Add Peter Hawkin's test case for the bug with solver types and sub-modules. tests/invalid/Mmakefile: tests/invalid/bad_mutable.m: tests/invalid/bad_mutable.err_exp: Add a test for the various sorts of errors that can occur with mutable declarations. |