mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-20 16:31:04 +00:00
ff13f1380fc314c20dca490a8e2c65c9ddb2a09e
78 Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
e069d16ab1 |
Do not display the For more information try recompiling with -E'' prompt
Estimated hours taken: 1.5 Branches: main Do not display the `For more information try recompiling with `-E'' prompt unless we really mean it, i.e. there is actually more information available. XXX This change is incomplete for the mode_errors module because that module requires more substantial changes to make this work - I'll do that as a separate diff. compiler/globals.m Add a new global (and access predicates) that keeps track of whether we have any verbose error information that could be displayed if we recompiled with `-E'. compiler/mercury_compile.m Check the new global flag before prompting the user to recompile with `-E'. compiler/mode_errors.m Add an XXX comment about needing to respect the extra error info flag properly. compiler/accumulator.m compiler/add_clause.m compiler/add_pred.m compiler/add_type.m compiler/assertion.m compiler/check_typeclass.m compiler/det_report.m compiler/magic_util.m compiler/make_hlds_error.m compiler/modes.m compiler/module_qual.m compiler/modules.m compiler/post_typecheck.m compiler/purity.m compiler/stratify.m compiler/typecheck_errors.m Set the new global flag when we come across an error for which we have a verbose error message. tests/recompilation/*: tests/invalid/*: Update expected error files. |
||
|
|
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. |
||
|
|
10536c5ee0 |
Divide make_hlds.m into submodules of manageable size.
Estimated hours taken: 12 Branches: main Divide make_hlds.m into submodules of manageable size. compiler/make_hlds.m: Distribute all the code that was previously here to new submodules. Include those submodules. Keep the existing interface of this module by defining predicates that do nothing except call the actual implementation in one of those submodules. The only changes visible from outside are the renaming of a predicate and the creation of a second name, make_hlds_qual_info, for qual_info. Both changes are designed to avoid ambiguity in the presence of intermodule optimization. compiler/add_aditi.m: Submodule for dealing with aditi-specific issues. compiler/add_class.m: Submodule for handling typeclasses. compiler/add_clause.m: Submodule for handling the general processing of clauses. compiler/add_pred.m: Submodule for handling new predicates. compiler/add_special_pred.m: Submodule for handling special (unify/compare/index/init) predicates. compiler/add_type.m: Submodule for handling new types. compiler/add_mode.m: Submodule for handling new insts and modes. compiler/add_solver.m: Submodule for handling new solver types. compiler/add_pragma.m: Submodule for handling new pragmas. compiler/state_var.m: Submodule for handling the state variable transformation. compiler/superhomogeneous.m: Submodule for converting clauses to superhomogeneous form. compiler/field_access.m: Submodule for field access syntax. compiler/make_hlds_passes.m: Submodule containing the code that performs passes on the item list, adding things to the HLDS, calling the other submodules as necessary. compiler/make_hlds_warn.m: Submodule that looks for constructs that merit warnings. compiler/make_hlds_error.m: Submodule containing error messages used by more than one submodule. compiler/hlds_pred.m: Since this module defines the clauses_info and proc_id types, move the predicates that initialize values of that type here as well from make_hlds.m (deleting an unnecessary parameter from one). compiler/hlds_pred.m: compiler/prog_data.m: Move the type tvar_name_map from from hlds_pred.m to prog_data.m, since that is where similar maps are. compiler/check_typeclass.m: compiler/mercury_compile.m: Conform to the change to make_hlds_qual_info. compiler/hlds_out.m: compiler/prog_out.m: Replace two identical predicates for printing out lists of strings in hlds_out.m and make_hlds.m with just one in prog_out.m, since that is where it belongs in the compiler. compiler/prog_util.m: Move some utility predicates for substitutions and term recognition here from make_hlds.m, since they are needed by more than one submodule. Make this module conform to our coding guidelines, and convert it to four-space indentation to eliminate bad line breaks. compiler/clause_to_proc.m: compiler/hlds_code_util.m: compiler/make_tags.m: compiler/prog_mode.m: compiler/quantification.m: compiler/type_util.m: Trivial formatting changes. compiler/notes/compiler_design.html: Describe the new modules. |
||
|
|
386d7b7dec |
Add a verbose error message to explain what is meant by a type
Estimated hours taken: 0.5 Branches: main compiler/check_typeclass.m: Add a verbose error message to explain what is meant by a type variable being "determined" by the arguments of a predicate, function or constructor. |
||
|
|
943f590bfb |
Relax the restriction on the constraints on existentially quantified data
Estimated hours taken: 1.5 Branches: main Relax the restriction on the constraints on existentially quantified data structures. The type variables in constraints must be determined by the constructor arguments and functional dependencies, but don't necessarily have to appear directly in the constructor arguments. compiler/check_typeclass.m: Implement a check for type declarations which is analogous to the existing check for pred/func declarations. compiler/prog_io.m: Relax the existing restriction, which was applied at parse-time. Now we just check that all existentially quantified type vars appear somewhere, either in the arguments or in the constraints. Remove an XXX comment that asked whether the check that all constrained variables were existentially quantified was overly restrictive. The answer is no: we don't support existential constraints with universal arguments, and we won't support it in the foreseeable future. tests/invalid/Mmakefile: tests/invalid/fundeps_unbound_in_ctor.err_exp: tests/invalid/fundeps_unbound_in_ctor.m: New test case for the new and changed error messages. tests/invalid/type_vars.err_exp: Updated test case. tests/valid/Mmakefile: tests/valid/fundeps.m: New test case. |
||
|
|
a5eb58d00b |
Update the design document after the recent changes to add functional
Estimated hours taken: 0.2 Branches: main compiler/notes/compiler_design.html: Update the design document after the recent changes to add functional dependencies and split up typecheck.m. compiler/check_typeclass.m: Fix a typo. |
||
|
|
cb2c3ec8bf |
Split typecheck.m into smaller modules.
Estimated hours taken: 3 Branches: main Split typecheck.m into smaller modules. compiler/typecheck.m: The main typechecking pass. compiler/typecheck_errors.m: New module. Error messages and debugging messages. compiler/typecheck_info.m: New module. The typecheck_info and type_assign data structures, plus some basic predicates. compiler/typeclasses.m: New module. The context reduction and improvement rules. compiler/check_hlds.m: Register the new modules. compiler/check_typeclass.m: Call typeclasses instead of typecheck to do context reduction. compiler/prog_type.m: Move strip_builtin_qualifiers_from_type(_list) to here. compiler/hlds_data.m: Define restrict_list_elements here instead of in typecheck.m and check_typeclass.m. |
||
|
|
80ec927808 |
Module qualify calls to list.member so that the compiler
Estimated hours taken: 0.1 Branches: main compiler/check_typeclass.m: Module qualify calls to list.member so that the compiler builds with intermodule-optimization enabled. |
||
|
|
d075d35702 |
Implement functional dependencies for the typeclass system.
Estimated hours taken: 240 Branches: main Implement functional dependencies for the typeclass system. The implementation has two major parts. First, some of the basic checks of constraints are relaxed. These used to occur in make_hlds but that functionality has now been moved to check_typeclass. We also add a range of new tests to ensure that the FDs are used correctly. Second, an "improvement" pass to context reduction is added. This looks for constraints which match certain rules, and when it finds them updates the current bindings. The general rule is that type variables become more instantiated, but only in a way which provably does not affect the satisfiability of the constraints. XXX The plan for this change is to put the context reduction into a new module check_hlds.typeclasses.m, but I have left the code in typecheck.m for the moment because the diff will be easier to review that way. Moving to the new module will also remove the problem of one particular function being implemented in both typecheck and hlds_data, which is flagged by an XXX in the code. XXX the check for consistency of instances is not yet complete. We check all visible instances, but not instances that are only present at link time. We could check these in a similar way to the check for overlapping instances (that is, by defining a symbol that will conflict and cause a link error if there are overlapping instances), but in the long run a better solution will be required. Producing this is left for a later change. compiler/check_typeclass.m: Check for ambiguities in typeclass constraints here, rather than make_hlds. We check by calculating the closure of the bound type variables under the induced functional dependencies. This pass is merged in with the already existing pass that checks the quantifiers on constrained type variables. Check instances for range-restrictedness and for consistency. When checking for cycles in the typeclass hierarchy, build up the set of ancestors of a class which have FDs on them. This set is used when searching for opportunities to apply improvement rules during type checking. compiler/hlds_data.m: Define hlds_class_fundeps and add it to to hlds_class_defn. Add a field to hlds_class_defn to store the ancestors which have functional dependencies. Define the type 'instance_id', which is just an integer. This is what is used in proofs to identify instances. In hlds_constraints and in constraint_ids, use the terms 'assumed' and 'unproven' rather than 'existential' and 'universal'. The latter are confusing to use since the treatment of constraints differs depending on whether the constraint is on the head or the body of a clause. Add a field to the hlds_constraints for redundant constraints. These are constraints that have either already been reduced or don't need to be reduced, which may contribute to improvement of types. Define some new predicates for initialising and updating the hlds_constraints. compiler/type_util.m: Accommodate the change to hlds_constraints. compiler/hlds_out.m: Output the functional dependencies. compiler/intermod.m: Reconstruct a functional dependency from the HLDS, for outputting. compiler/make_hlds.m: Convert functional dependencies from parse tree form and add them to the HLDS. Check that functional dependencies are identical in subsequent definitions of the same typeclass. Don't check for ambiguity here. That is now done in check_typeclass. compiler/mercury_to_mercury.m: Output functional dependencies in typeclass declarations. compiler/prog_data.m: Define prog_fundeps and add them to the parse tree. compiler/prog_io_typeclass.m: Parse functional dependencies on typeclass declarations. compiler/typecheck.m: Require the class_table to be passed to reduce_context_by_rule_application, since the functional dependencies are stored here. Also thread the bindings argument through, since the bindings may be improved by context reduction. Save the resulting bindings in the type_assign. Instead of passing a list of assumed constraints and threading the unproven constraints through context reduction, thread through a hlds_constraints structure. This contains more information about redundant constraints than just the two lists. Extend context reduction with two new passes. The first applies the "class" FD rule, which tries to find two constraints which are identical on the domain of some FD, and then unifies the range arguments. The pair of constraints are either both redundant constraints, or one redundant constraint and one assumed constraint. The second applies the "instance" FD rule, which for each constraint tries to find an instance which is more general on the domain arguments. It then binds the instance arguments and unifies the range arguments of the instance with those of the constraint. When calculating the head_type_params for a predicate, include all variables that occur in universal constraints, since these may not necessarily occur in the arguments. Rename some variables: use variable prefixes "Pred" and "Parent" for types that are from the callee or that have been renamed apart respectively. This follows the same naming scheme used in polymorphism. Remove the headtypes/0 type, and use head_type_params/0 throughout. Add a new kind of cons_error for using "new" on a constructor that is not existentially typed. We check for this situation in convert_cons_defn, and report it in report_cons_error. Pass a value to convert_cons_defn indicating whether the constraints should be flipped or not, and whether the context is a constructor that uses 'new'. We flip the constraints here rather than after the fact, since creating the constraints now requires some extra processing to be done, and we don't want to have to redo that processing. Add a constant function that specifies whether variable numbers should be displayed as part of the debugging output. This is currently set to 'yes' but the previous behaviour can be achieved by changing the value to 'no'. doc/reference_manual.texi: Document the new feature. NEWS: Announce the new feature. tests/*: New test cases. compler/*.m: Minor changes related to the above. compiler/error_util.m: Fix comment grammar. compiler/prog_type.m: Fix an incorrect comment. |
||
|
|
624ec2ef16 |
Only allow existential constraints to constrain existentially quantified
Estimated hours taken: 2 Branches: main, release-0.12 Only allow existential constraints to constrain existentially quantified type variables. Likewise only allow universal constraints to constrain universally quantified type variables. We previously didn't check these conditions, and in fact the reference manual allowed otherwise. However, the implementation did not support existential constraints on universally quantified type variables, and will not do so for the foreseeable future. The implementation does support universal constraints on existentially quantified variables, however these are not useful since no caller will ever be able to satisfy the constraints. compiler/check_typeclass.m: Check these conditions as part of typeclass checking. Also return a bool from the recently added check for concrete instances, indicating whether errors were found or not. compiler/error_util.m: compiler/hlds_error_util.m: Add a couple of utility functions for constructing error messages. compiler/mercury_compile.m: Stop compilation after checking typeclasses if errors were encountered. If the above conditions are not met then typechecking may abort. doc/reference_manual.texi: Document the condition on typeclass constraints. tests/invalid/Mmakefile: tests/invalid/quant_constraint_1.err_exp: tests/invalid/quant_constraint_1.m: tests/invalid/quant_constraint_2.err_exp: tests/invalid/quant_constraint_2.m: Test cases for the new error messages. tests/invalid/unbound_type_vars.err_exp: Update this test case. |
||
|
|
df11eb7a3c |
Have the compiler emit an error if an abstract instance declaration
Estimated hours taken: 3 Branches: main, release Have the compiler emit an error if an abstract instance declaration in the interface of a module does not have a corresponding concrete instance declaration in the implementation of the module. Currently the compiler just ignores this situation which leads to C compilation errors in the MLDS grades and link-time errors in the LLDS grades. compiler/check_typeclass.m: Emit an error message if an abstract instance declaration in the interface of a module does not have a corresponding concrete instance in the implementation. Use unexpected/2 in place of error/2. Fix the positioning of a few comments. Add an end_module declaration. compiler/hlds_data.m: Make the instance_table type a multi_map (which it already effectively was). tests/invalid/Mmakefile: tests/invalid/missing_concrete_instance.m: tests/invalid/missing_concrete_instance.err_exp: Test case for the above. |
||
|
|
a0e5667af5 |
Do not allow non-abstract instance declarations to occur in module
For review by anyone. Estimated hours taken: 10 Branches: main, release Do not allow non-abstract instance declarations to occur in module interfaces. Emit an error message if this occurs. Fix the formatting of some error messages regarding typeclasses and instances. compiler/check_typeclass.m: Use error_util to generate the error messages from this module. This fixes a problem where the printing of sym_names and arities differed in the same error message. compiler/error_util.m: Add a format component for the pred_or_func type. Add the equivalence type format_components. compiler/make_hlds.m: Make the format of some error messages concerning typeclasses more consistent. compiler/modules.m: Check for non-abstract instance declarations in module interfaces and emit an error message if they do. tests/invalid/Mmakefile: tests/invalid/instance_bug.m: tests/invalid/instance_bug.err_exp: Test case for the above. tests/hard_coded/typeclasses/*: tests/invalid/*: tests/recompilation/*: tests/valid/*: Update test cases as necessary. |
||
|
|
c52d4c114c |
Move some predicates dealing with typeclass constraints from
Estimated hours taken: 0.1 Branches: main compiler/prog_type.m: compiler/prog_util.m: Move some predicates dealing with typeclass constraints from prog_util to prog_type. compiler/check_typeclass.m: compiler/cse_detection.m: compiler/recompilation.version.m: Minor changes to the imported modules. |
||
|
|
4427723508 |
Remove the assumption made by polymorphism.m that all type variables
Estimated hours taken: 240
Branches: main
Remove the assumption made by polymorphism.m that all type variables
appearing in class constraints also appear in the type being constrained.
This is a first step towards adding functional dependencies, since in the
presence of functional dependencies (or "improvement" in general) this
assumption no longer holds.
The assumption made by polymorphism manifests itself in the fact that
constraints on atomic goals are reconstructed by unifying the types of
formal parameters with the types of actual arguments, and then applying
the resulting substitution to the constraints. Any type variables in
constraints that don't appear in the formal parameters will therefore
remain unbound.
This change overcomes the assumption by building up a map from constraint
identifiers to constraints during typechecking, and then looking up this
map in order to reconstruct the constraint during the polymorphism
transformation.
To support this, the type 'class_constraint' has been removed and replaced
by two distinct types, 'prog_constraint' and 'hlds_constraint'. The former
is part of the parse tree and holds the same information as the old
class_constraint. The latter is part of the HLDS, and is used during
typechecking; in addition to the information in prog_constraints, it also
stores a set of identifiers that represent where the constraint came from.
These identifiers are used as the keys in the aforementioned map.
At this stage the constraint identifiers are only used by typechecking to
build the constraint map. Other passes use either prog_constraints or
hlds_constraints with an empty set of identifiers.
compiler/hlds_data.m:
Define the constraint_id type, which is used to uniquely identify
class constraints. A better scheme than this one has been suggested,
but that will be left to a later change. An XXX comment to that
effect has been added.
Define the hlds_constraint type, which is like prog_constraint but
it also includes a set of constraint_ids. Define a set of predicates
to initialise and manipulate these.
Define the constraint_map type here. Move the definition of
constraint_proof_map to here, where it more sensibly belongs.
Update the comments in hlds_instance_defn slightly, with information
that I found I needed to know when making this change.
compiler/hlds_pred.m:
Add a field to the pred_info to store the constraint_map.
Move the definition of constraint_proof_map from here.
compiler/hlds_out.m:
Print out a representation of the constraint map if it isn't empty.
compiler/type_util.m:
Change the predicates that used to operate on class_constraints so
that they now operate on hlds_constraints. The old versions of these
predicates have now moved to prog_util.
Add some utility predicates to manipulate constraint_maps.
Add a predicate to apply a variable renaming to constraint_proof_maps.
compiler/prog_data.m:
Rename class_constraint(s) to prog_constraint(s).
compiler/prog_util.m:
Provide a set of predicates for manipulating prog_constraints.
compiler/typecheck.m:
Ensure that goal_paths are filled in before the first iteration
of typechecking.
Pass the hlds_goal_info down through typecheck_goal_2 so that the
goal_path can be retrieved when needed to assign identifiers to
constraints. Thread the goal_path through to wherever it is needed.
Store hlds_constraints in the args_type_assign rather than
prog_constraints, so that the required information is available
when creating the new set of type_assigns. Do likewise for the
cons_type_info type. Don't pass the module_info through
make_pred_cons_info*, since it isn't used. Do pass the goal_path,
though, so that constraints in cons_type_infos can be given the
correct identifier.
Add a constraint_map field to the typecheck_info, initialised to empty.
When retrieving the final information from a typecheck_info, return
the resulting constraint_map, after applying any type bindings.
Ensure that any constraints that may not have been entered into the
constraint_map are put there now. Call the new predicate in type_util
to rename the constraint_proof_map, rather than doing it longhand
here.
Make the following changes to context reduction:
- Thread the constraint_map through, so that it can be updated
as constraints are eliminated.
- Instead of simply calling sort_and_remove_dups on the
set of constraints remaining after one iteration, merge the
constraints in such a way that the complete set of
constraint_ids is retained.
- Disregard the constraint_ids when deleting newly introduced
constraints that are equivalent to constraints that have
already been seen.
- Simplify the code of find_matching_instance_rule_2 by
moving the deterministic code out of the condition of the
if-then-else.
Move find_first_map into the library.
compiler/polymorphism.m:
Ensure that the goal_path is set when constructing lambda goals.
In process_call, look up the constraints in the constraint_map
using the goal_path as part of the key, rather than calculating
the constraints by applying the ParentToActual type substitution.
Rearrange this code so that it is divided into easier to understand
blocks.
Add a field to the poly_info to store the constraint_map, and
initialise it from the pred_info.
compiler/goal_path.m:
Fill slots in lambda_goals, since constraints inside these will
otherwise not be identified properly. The goal_paths inside here
do not entirely make sense, since there is no goal_path_step for
the lambda_goal itself. However, there is enough information
retained to distinguish these goal_paths from any other possible
goal_path, which is all that we require to identify constraints.
Add a warning not to fill in the goal slots between the typechecking
and polymorphism passes, since doing so could potentially render the
constraint_maps incorrect.
compiler/make_hlds.m:
Initialise the constraint_map to empty in pred_infos.
Move the code for updating the superclass_table into a separate
predicate. Initially this change was made because, in an earlier
version of the change, the superclass_table had some extra
information that needed to be filled in. That part of the change
is not needed in this diff, but the new predicate simplifies the
code a bit so I've left it there.
compiler/check_typeclass.m:
Convert the prog_constraints into hlds_constraints before passing
them to typecheck.reduce_context_by_rule_application. They are
assigned no identifiers, since these constraints are not required
to be put into the constraint map.
Change the name of the function get_constraint_id to
get_constraint_class_id, since it would now be ambiguous otherwise.
compiler/cse_detection.m:
Import parse_tree__prog_util, since that is where renamings of
prog_constraints are now defined.
compiler/higher_order.m:
Initialise pred_infos here with an empty constraint_map.
compiler/post_typecheck.m:
When binding type vars to void, apply the void substitution to the
constraint_map.
compiler/table_gen.m:
Pass the constraint_map when creating a new pred_info.
compiler/unused_args.m:
Create the pred_info with an empty constraint_map. The constraint_map
won't be used by this stage anyway.
compiler/*.m:
Update to use the new type names. Also update to use the existing
type synonyms typeclass_info_varmap and constraint_proof_map.
Change names of predicates and functions to use prog_constraint
instead of class_constraint, where applicable.
library/list.m:
Add find_first_map from typecheck. Also add find_first_map{2,3},
since at one stage during development I needed find_first_map3, and,
although it's not used in the current diff, there is little point
removing it now.
|
||
|
|
c08ca7fbc8 |
Import only one module per line in the modules of the compiler
Estimated hours taken: 3 Branches: main compiler/*.m: Import only one module per line in the modules of the compiler where my previous diff did not already do so. Misc other cleanups. Where relevant, use the new mechanism in tree.m. compiler/tree.m: Fix a performance problem I noticed while update :- import_module items. Instead of supplying a function to convert lists of trees to a tree, make the tree data structure able to hold a list of subtrees directly. This reduces the number of times where we have to convert list of trees to trees that are sticks just to stay within the old definition of what a tree is. |
||
|
|
4970242093 |
Use proc_label data structure defined in mdbcomp.prim_data instead of proc_id
Estimated hours taken: 4 Branches: main Use proc_label data structure defined in mdbcomp.prim_data instead of proc_id defined in mdb.declarative_execution and delete proc_id, since these data structures are almost identical. browser/declarative_execution.m Remove proc_id and flat_module_name types. Use mdbcomp.prim_data.proc_label and mdbcomp.prim_data.module_name instead. browser/declarative_debugger.m browser/declarative_oracle.m browser/declarative_tree.m browser/declarative_user.m Use mdbcomp.prim_data.proc_label and mdbcomp.prim_data.module_name instead of mdb.declarative_execution.proc_id and mdb.declarative_execution.module_name. mdbcomp/prim_data.m compiler/prog_out.m Move sym_name_to_string from prog_out to prim_data. Fix comment for prog_out.sym_name_and_arity_to_string. compiler/bytecode.m compiler/check_typeclass.m compiler/code_gen.m compiler/deforest.m compiler/higher_order.m compiler/hlds_code_util.m compiler/hlds_error_util.m compiler/hlds_module.m compiler/hlds_out.m compiler/intermod.m compiler/layout_out.m compiler/make.module_target.m compiler/make_hlds.m compiler/mercury_compile.m compiler/mercury_to_mercury.m compiler/ml_elim_nested.m compiler/mlds_to_c.m compiler/mlds_to_gcc.m compiler/mlds_to_il.m compiler/mlds_to_java.m compiler/mlds_to_managed.m compiler/modes.m compiler/modules.m compiler/opt_debug.m compiler/options_file.m compiler/polymorphism.m compiler/prog_io.m compiler/prog_rep.m compiler/rl.m compiler/rl_exprn.m compiler/rl_gen.m compiler/rl_info.m compiler/rl_out.pp compiler/rtti.m compiler/rtti_out.m compiler/rtti_to_mlds.m compiler/source_file_map.m compiler/table_gen.m compiler/trans_opt.m compiler/unify_gen.m compiler/unique_modes.m compiler/unused_args.m Use mdbcomp.prim_data.sym_name_to_string instead of prog_out.sym_name_to_string. |
||
|
|
9521818650 |
Get the purity check pass to not issue warnings about unnecessary purity
Estimated hours taken: 16 Branches: main Get the purity check pass to not issue warnings about unnecessary purity annotations on compiler-generated predicates. The problem I am addressing is that when an optimization such as type specialization creates a clone of a predicate, that predicate gets all the original predicate's annotations. During the creation of a .opt file, purity checking sees the clauses of the original predicate and knows that the annotation is not redundant, but doesn't know that about the copy, since it has no definition at all (it doesn't need one). The fix is to put into each pred_info an indication of where the predicate came from, and to never warn about unnecessary purity annotations of predicates that the programmer didn't write. This diff also uses the origin indication to record human-usable names of compiler-generated or compiler-transformed predicates in RTTI for use by the debugger. compiler/hlds_pred.m: Replace two fields in pred_infos, that say (a) whether the predicate is a special (unify/compare/index/init) predicate and (b) whether it is a type class method implementation, with an origin field saying where the predicate came from. This field has several alternatives, special preds and type class method implementation being only two. Make the predicates that create pred_infos take an argument specifing where the predicate comes from. Replace a copy of one of the old fields in rtti_proc_labels with the new one. Make the name of the existing function more descriptive. compiler/purity.m: Use the origin field to suppress unnecessary annotation warnings for compiler-generated predicates. compiler/layout_out.m: Use the origin field to generate more human-friendly names for predicates, instead of the existing linker-friendly names. The debugger doesn't insist on predicate names being unique, even within a module. compiler/*.m: Conform to the changed interface of hlds_pred.m. The most significant changes were for recording the origin of new predicates. In one case (dnf.m) it also involved passing the required information down to the place where the new predicates were created through the dnf_info tuple instead of separate arguments, and switching to state variable notation. tests/debugger/*.exp*: tests/debugger/declarative/*.exp*: tests/hard_coded/*.exp*: Update the expected outputs to expect human-friendly predicate names. |
||
|
|
7234e16972 |
Check for cycles in the typeclass hierarchy.
Estimated hours taken: 3 Branches: main Check for cycles in the typeclass hierarchy. This fixes a long-standing bug whereby the compiler could go into an infinite loop in the polymorphism stage if cycles were present. compiler/check_typeclass.m: Add a pass to check through all visible typeclass declarations and report when a cycle is found. The interface to this module has been made more general, to reflect the fact that it checks the superclass relation as well as instance declarations. compiler/mercury_compile.m: Use the new interface to the check_typeclass module. compiler/error_util.m: Add a new format_component for sym_name_and_arity. BUGS: Remove the bug report from this file. tests/invalid/Mmakefile: test/invalid/cyclic_typeclass.err_exp: Enable the cyclic_typeclass test, since we now pass it, and add an expected output file. Also add a couple of new tests. test/invalid/cyclic_typeclass_2.m: test/invalid/cyclic_typeclass_2.err_exp: test/invalid/cyclic_typeclass_3.m: test/invalid/cyclic_typeclass_3.err_exp: New test cases. |
||
|
|
59d2d4a573 |
This adds a module mdbcomp__trace_counts that reads in the
Estimated hours taken: 17 Branches: main This adds a module mdbcomp__trace_counts that reads in the .mercury_trace_counts files produced by the compiler's trace mechanism. The format of said files was slightly changed. As the new module is to be used by the compiler and the debugger, it is placed in the mdbcomp module. This required bringing some types from the compiler into a new module within mdbcomp. browser/trace_counts.m: New module for reading execution trace summaries. browser/prim_data.m: New module holding types and predicates moved in from the compiler. Types: pred_or_func, sym_name, module_name, proc_label, special_pred_id, trace_port Predicates: string_to_sym_name, insert_module_qualifier The mode field of proc_label is now an int instead of a proc_id to avoid pulling proc_id into mdbcomp. browser/mdbcomp.m: Add trace_counts and prim_data to the mdbcomp module. browser/declarative_execution.m: Renamed mdb's definition of module_name to flat_module_name to avoid conflicts with the definition in mdbcomp__prim_data. runtime/mercury_trace_base.c: In the format of .mercury_trace_counts, write module and predicate names now use quoted atom syntax so that names with spaces and non-printable characters can be machine-parsed. browser/: compiler/: Many changes to account for movement of types, and the change to proc_label. |
||
|
|
9187c0d911 |
Bring these modules up to date with our current style guidelines.
Estimated hours taken: 8 Branches: main compiler/hlds_out.m: compiler/llds_out.m: Bring these modules up to date with our current style guidelines. Use state variables in the few places where we weren't doing so already. compiler/purity.m: Bring this module up to date with our current style guidelines. Use the predicates of error_util and hlds_error_util to print error messages. Be more consistent in using quotations. Fix indentation. compiler/error_util.m: Add a long needed facility: the ability to glue some punctuation at the end of a previous word. Add a mechanism for turning a list of components into a string, instead of printing them out. Make the interface of this module more consistent by making list_to_pieces a function just like component_lists_to_pieces. compiler/hlds_error_util.m: Change the way we describe predicates and procedures. Instead of returning their descriptions as single fixed strings that error_util can't break up across lines, return them as separate components that can be split across lines. This makes error output look nicer. Fix a mismatch between what were supposed to be corresponding pieces of code in hlds_error_util and hlds_out. Turn the appropriate predicates into functions. compiler/*.m: Conform to the changed interfaces of some of the above modules. tests/invalid/*.err_exp: tests/invalid/purity/*.err_exp: tests/recompilation/*.err_exp: tests/warnings/*.exp: Update the expected outputs for the better looking error messages we now generate. |
||
|
|
c7ff2bd6ef |
Cleanup of parts of hlds_pred.m and hlds_out.m.
Estimated hours taken: 2 Branches: main Cleanup of parts of hlds_pred.m and hlds_out.m. compiler/hlds_pred.m.m: Simplify the part of this file dealing with pred_infos. Order the arguments of pred_info in a meaningful manner, put the declarations and definitions of get/set predicates in the corresponding order, and put the arguments of the predicates that create pred_infos in the corresponding order. Delete the cond field, since it won't be used in its current form. compiler/hlds_out.m: Redefine write_cons_id in terms of cons_id_to_string, since having both definitions is a double maintenance problem. This also eliminates the unnecessary differences between the two old definitions. Fix an old FIXME: when printing clauses, don't print the goal annotations that do not make sense in clauses. Print clause numbers next to each clause to make confusion between clauses and procedures even less likely. compiler/prog_out.m: Add function versions of some utility predicates for use by the new version of cons_id_to_string. compiler/*.m: Conform to the changes in hlds_pred.m. In some cases, clean up nearby code. tests/invalid/purity/purity_nonsense.m: Conform to the fact that write_cons_id doesn't now do unnecessary quoting of a predicate name. |
||
|
|
ff60134ee9 |
Bring these modules up to our current coding standards.
Estimated hours taken: 8 Branches: main analysis/analysis.m: browser/browse.m: compiler/accumulator.m: compiler/assertion.m: compiler/atsort.m: compiler/c_util.m: compiler/check_typeclass.m: compiler/clause_to_proc.m: compiler/code_gen.m: compiler/code_model.m: compiler/const_prop.m: compiler/constraint.m: compiler/dead_proc_elim.m: compiler/delay_construct.m: compiler/dependency_graph.m: compiler/det_analysis.m: compiler/det_report.m: compiler/export.m: compiler/fact_table.m: compiler/follow_code.m: compiler/graph_colour.m: compiler/hlds_module.m: compiler/inlining.m: compiler/llds.m: compiler/make_hlds.m: compiler/mercury_to_mercury.m: compiler/ml_tailcall.m: compiler/ml_unify_gen.m: compiler/mmc_analysis.m: compiler/mode_errors.m: compiler/passes_aux.m: compiler/post_typecheck.m: compiler/size_prof.m: compiler/switch_util.m: compiler/table_gen.m: compiler/term_errors.m: compiler/transform_llds.m: compiler/type_util.m: compiler/unify_gen.m: compiler/unneeded_code.m: compiler/unused_args.m: Bring these modules up to our current coding standards. Use predmode declarations and state variable syntax where relevant. Reorder arguments where this is needed for the use state variables. Make the orders of predicate definitions correspond to the order of their declarations. Replace some overly large lambda expressions with named predicates. Convert some predicates to functions where this makes their use more convenient. Use field access notation where convenient. Fix any inconsistent indentation. Remove module prefixes on predicate names where this is necessary to allow sane indentation. In several places, use predicates from error_util.m to print error messages. Apart from this, there are no changes in algorithms. In some places, conform to the changes below. compiler/error_util.m: compiler/hlds_error_util.m: Add new variants of existing predicates for use in some of the changed modules above. compiler/hlds_out.m: Add some functions to convert values of some HLDS types as strings, for use in preparing the arguments of the new calls to predicates in error_util.m. Change the implementations of the predicates that print values of those types to call those functions instead of allowing code duplication. compiler/llds.m: Add some field names to allow use of field updates where relevant. tests/invalid/assert_in_interface.err_exp: tests/invalid/multisoln_func.err_exp: tests/invalid/tricky_assert1.err_exp: Update the expected outputs of these test cases to allow for them being generated by error_util.m, and hence being better formatted than before. |
||
|
|
5d6fd3bd6f |
Reduce the dependence of earlier parts of the compiler on the later ones.
Estimated hours taken: 4 Branches: main Reduce the dependence of earlier parts of the compiler on the later ones. Unnecessary import_module declarations in top level modules such as hlds.m cause unnecessary recompilations when adding new types in later modules, such as submodules of ll_backend.m. This change reduces the number of such unnecessary imports. There are no changes in algorithms, only functionality being moved around. compiler/code_model.m: Change this module from being a submodule of backend_libs.m to being a submodule of hlds.m, since nothing in it is dependent on any backend. compiler/arg_info.m: compiler/code_util.m: Change arg_info.m from being a submodule of ll_backend.m to being a submodule of hlds.m, since most of it is applicable to all current and foreseeable backends. Move the one exported predicate that is ll_backend dependent, and its support predicates, to code_util.m. compiler/backend_libs.m: compiler/ll_backend.m: compiler/hlds.m: Update include_module declarations in accordance with the above. compiler/prog_data.m: compiler/term_util.m: Instead of defining two separate types for holding argument size and termination information, one including HLDS-specific information (in term_util.m) and one not (in prog_data.m), use a polymorphic type defined in prog_data.m and two monomorphic instances. compiler/termination.m: compiler/mercury_to_mercury.m: Change the predicates for writing out argument size and termination information to handle the polymorphic type (we don't need special handling of the monomorphic versions), and move them from termination.m to mercury_to_mercury.m, since this allows us to avoid some undesirable dependencies. compiler/base_typeclass_info.m: compiler/hlds_code_util.m: Move the predicate make_instance_string from base_typeclass_info.m to hlds_code_util.m, again because it allows us to remove some undesirable dependencies. compiler/top_level.m: compiler/backend_libs.m: compiler/check_hlds.m: compiler/hlds.m: compiler/ll_backend.m: compiler/parse_tree.m: compiler/transform_hlds.m: Delete some import_module declarations of other top level modules in these top level modules. Some imports were totally unnecessary. Some imports were useful in only a small minority of submodules; those submodules now import the necessary top level modules directly. Move remaining import_module declarations to the implementation section where this is feasible. Where we still need to import modules we ideally shouldn't, note why. compiler/*.m: Update imports of code_util and arg_info. In some cases, import top level modules no longer imported by the parent module. In some cases, delete unnecessary imports. |
||
|
|
c91313b32f |
Bring these modules up to date with our current coding style.
Estimated hours taken: 8
Branches: main
compiler/modules.m:
compiler/compile_target_code.m:
compiler/handle_options.m:
compiler/bytecode_data.m:
compiler/prog_io_util.m:
Bring these modules up to date with our current coding style. Use
predmode declarations and state variable syntax where appropriate.
Fix inconsistent indentation. Print more error messages using
error_util.m for printing error messages.
compiler/trace_param.m:
Add a new predicate for use by the updated code in handle_options.m.
compiler/error_util.m:
compiler/hlds_error_util.m:
Make error_util.m to be a submodule of parse_tree.m, not hlds.m.
Most of its predicates are not dependent on HLDS data structures.
Move the ones that are into a new module, hlds_error_util, that
is a submodule of hlds.m. Overall, this reduces the dependence
of submodules of parse_tree.m, including modules.m, on submodules
of hlds.m.
compiler/notes/compiler_design.html:
Update the documentation of compiler modes to account for
hlds_error_util.m.
compiler/hlds.m:
compiler/parse_tree.m:
Update the list of included submodules.
compiler/*.m:
Update module imports and module qualifications as needed for the
change above.
tests/invalid/*.{exp,exp2}:
Update the expected outputs of a bunch of test cases to reflect the new
format of some warning messages due to the user error_util; they now
observe line length limits, and print contexts in some cases where they
were previously missing.
|
||
|
|
78383ec26f |
Remove code that duplicates functionality that is now in the
Estimated hours taken: 0.1 Branches: main Remove code that duplicates functionality that is now in the standard library. compiler/check_typeclass.m: Use list.map_foldl2 from the standard library. Delete the the predicate check_typclass.list_map_foldl2. |
||
|
|
e64c6cab22 |
Bring this module up to date with our current coding standards.
Estimated hours taken: 2 Branches: main compiler/mercury_compile.m: Bring this module up to date with our current coding standards. Use predmode declarations and state variable syntax where appropriate. Reorder predicate arguments where this is needed for the use of state variable syntax. Replace lambda expressions with explicitly named predicates where appropriate. Break up predicates that are excessively long and/or excessively deeply indented. Fix inconsistent indentation and wrap 80+ column lines. The only algorithmic change is the replacement of some calls to io__write with calls to predicates in error_util. compiler/error_util.m: Add a predicate for printing messages without context, for use by mercury_compile.m to report problems that are not specific to a single predicate, e.g. inconsistent options. Bring this module up to date with our coding standards. Use predmode declarations and state variable syntax where appropriate. compiler/check_typeclass.m: compiler/dnf.m: compiler/optimize.m: Reorder arguments of predicates exported to mercury_compile.m to allow the use of state variable syntax. compiler/globals.m: Wrap an 80+ column line. |
||
|
|
fa9ca36d03 |
This diff makes several files easier to read and to maintain (as well as
Estimated hours taken: 5 Branches: main This diff makes several files easier to read and to maintain (as well as more than 400 lines shorter), but contains no changes in algorithms whatsoever. compiler/deep_profiling.m: compiler/foreign.m: compiler/hlds_module.m: compiler/hlds_data.m: compiler/make_hlds.m: compiler/post_typecheck.m: compiler/prog_data.m: compiler/purity.m: compiler/type_util.m: Bring these modules into line with our current coding standards. Use predmode declarations and state variable syntax when appropriate. Reorder arguments of predicates where necessary for the use of state variable syntax, and where this improves readability. Replace predicates with functions where appropriate. Standardize indentation. compiler/*.m: Conform to the changes above. |
||
|
|
a2bf36e49a |
This diff contains no changes in algorithms whatsoever.
Estimated hours taken: 4 Branches: main This diff contains no changes in algorithms whatsoever. browser/*.m: compiler/*.m: library/*.m: Replace old-style lambdas with new-style lambdas or with named procedures. |
||
|
|
b39a3d855f |
This diff makes hlds_module.m and many callers of its predicates easier to read
Estimated hours taken: 6 Branches: main This diff makes hlds_module.m and many callers of its predicates easier to read and to maintain, but contains no changes in algorithms whatsoever. compiler/hlds_module.m: Bring (most of) this module into line with our current coding standards. Use predmode declarations, functions, and state variable syntax when appropriate. (The 'most of' is because I left the part of the module dealing with predicate tables alone, not wishing to cause a conflict for Pete.) Reorder arguments of predicates where necessary for the use of state variable syntax, and where this improves readability. Replace old-style lambdas with new-style lambdas or with partially applied named procedures. compiler/*.m: Conform to the changes in hlds_module.m. This mostly means using the new argument orders of predicates exported by hlds_module.m, and switching to state variable notation. Replace old-style lambdas with new-style lambdas or with partially applied named procedures in updated code. Replace unnecessary occurrences of four-space indentation with standard indentation in updated code. library/list.m: library/map.m: library/tree234.m: Add list__foldl4 and map__foldl3, since in some compiler modules, state variable notation is more convenient (and the code more efficient) if we don't have to bundle up several data structures into a tuple just to iterate over them. Change the fold predicates to use state variable notation. NEWS: Mention the new library functions. |
||
|
|
8693e293a2 |
This diff makes hlds_pred.m and many callers of its predicates easier to read
Estimated hours taken: 4 Branches: main This diff makes hlds_pred.m and many callers of its predicates easier to read and to maintain, but contains no changes in algorithms whatsoever. compiler/hlds_pred.m: Bring this module into line with our current coding standards. Use predmode declarations, functions, and state variable syntax when appropriate. Reorder arguments of predicates where necessary for the use of state variable syntax, and where this improves readability. Replace old-style lambdas with new-style lambdas or with partially applied named procedures. Standardize indentation. compiler/*.m: Conform to the changes in hlds_pred.m. This mostly means using the new argument orders of predicates exported by hlds_pred.m. Where this is now conveniently possible, change predicates to use state variable notation. In some modules, using state variable notation required changing the orders of arguments in the module's top predicate. compiler/passes_aux.m: Change the order of arguments in the calls this module makes to allow the callees to use state variable notation. Convert this module to state variable notation too. |
||
|
|
9551640f55 |
Import only one compiler module per line. Sort the blocks of imports.
Estimated hours taken: 2 Branches: main compiler/*.m: Import only one compiler module per line. Sort the blocks of imports. This makes it easier to merge in changes. In a couple of places, remove unnecessary imports. |
||
|
|
660a24a7ad |
Fix a bug reported by Michael Day which caused spurious
Estimated hours taken: 8 Branches: main, release Fix a bug reported by Michael Day which caused spurious "predicate multiply defined" errors if there were predicates `module1.p' and `module2.module1.p'. compiler/hlds_module.m: For each of the predicate table search predicates which takes a module, add an extra argument which states whether the module name passed in is fully qualified. If it is, then a search for `module1.p' will not return `module2.module1.p'. The module name is guaranteed to be fully qualified for the head of predicate, clause, etc. items, and for calls occurring in `.opt' files. Add a predicate `lookup_builtin_pred_proc_id', for looking up the builtin predicates in the predicate table. compiler/goal_util.m: Move code to look up builtin predicates into hlds_module.m. Set the builtin_state field of the call goal returned by generate_simple_call correctly. compiler/hlds_pred.m: Add a function `calls_are_fully_qualified' which takes an import_status, and returns whether calls from goals with that status are always fully qualified, which is true iff the call is in a `.opt' file. compiler/prog_io.m: Module qualify the sym_names in `:- external' items. compiler/*.m: Fill in the extra argument of predicate table searches. Use `lookup_builtin_pred_proc_id' rather than `predicate_table_search_*'. compiler/prog_util.m: Add function versions of mercury_*_builtin_module. compiler/polymorphism.m: compiler/simplify.m: compiler/unify_proc.m: Use goal_util__generate_simple_call to call builtins, rather than duplicating the code. tests/valid/Mmakefile: tests/valid/nested_module_bug.m: tests/valid/intermod_bug_nested.m: Test cases. |
||
|
|
7597790760 |
Use sub-modules to structure the modules in the Mercury compiler directory.
The main aim of this change is to make the overall, high-level structure of the compiler clearer, and to encourage better encapsulation of the major components. compiler/libs.m: compiler/backend_libs.m: compiler/parse_tree.m: compiler/hlds.m: compiler/check_hlds.m: compiler/transform_hlds.m: compiler/bytecode_backend.m: compiler/aditi_backend.m: compiler/ml_backend.m: compiler/ll_backend.m: compiler/top_level.m: New files. One module for each of the major components of the Mercury compiler. These modules contain (as separate sub-modules) all the other modules in the Mercury compiler, except gcc.m and mlds_to_gcc.m. Mmakefile: compiler/Mmakefile: Handle the fact that the top-level module is now `top_level', not `mercury_compile' (since `mercury_compile' is a sub-module of `top_level'). compiler/Mmakefile: Update settings of *FLAGS-<modulename> to use the appropriate nested module names. compiler/recompilation_check.m: compiler/recompilation_version.m: compiler/recompilation_usage.m: compiler/recompilation.check.m: compiler/recompilation.version.m: compiler/recompilation.version.m: Convert the `recompilation_*' modules into sub-modules of the `recompilation' module. compiler/*.m: compiler/*.pp: Module-qualify the module names in `:- module', `:- import_module', and `:- use_module' declarations. compiler/base_type_info.m: compiler/base_type_layout.m: Deleted these unused empty modules. compiler/prog_data.m: compiler/globals.m: Move the `foreign_language' type from prog_data to globals. compiler/mlds.m: compiler/ml_util.m: compiler/mlds_to_il.m: Import `globals', for `foreign_language'. Mmake.common.in: trace/Mmakefile: runtime/Mmakefile: Rename the %.check.c targets as %.check_hdr.c, to avoid conflicts with compiler/recompilation.check.c. |
||
|
|
6efe2aeb3c |
When creating a new pred for a type class instance method,
Estimated hours taken: 4 Branches: main compiler/check_typeclass.m: When creating a new pred for a type class instance method, use the module_name of the instance declaration rather than the name of the current module. |
||
|
|
f4b091cb5b |
When printing messages about errors involving overloaded types, print each
Estimated hours taken: 14
Branches: main
When printing messages about errors involving overloaded types, print each
type only once.
compiler/typecheck.m:
Detect and eliminate duplicate type names in error messages about
overloaded types.
When a variable has more than one type, print each type on a line of
its own, to make the output easier to read. (Since type names currently
have too many parentheses, further improvements are still possible.)
compiler/mercury_to_mercury.m:
Provide a mechanism to turn a type into a string without printing it,
so that it can be checked againt the representations of other types.
This required changing many of the predicates in this module so that
instead of doing I/O directly, they go through a typeclass interface
which has two implementations: one does I/O while the other gathers
output in a string.
The performance impact of this change should be acceptable, since I/O
is slow compared to computation anyway.
compiler/purity.m:
Provide a predicate that returns a purity prefix as a string, to
accompany another that prints it out.
compiler/check_typeclass.m:
compiler/prog_util.m:
Minor changes to conform to the naming scheme now used in
mercury_to_mercury.m, in particular to the fact the operations of the
form x_to_string are now functions, not predicates.
The functionality of prog_util should be unaffected. In check_typeclass
we may now print more detailed error messages than before.
library/string.m:
Declare the outputs append, append_list and join_list to be unique.
Their implementations already return unique strings; declaring them to
be unique help avoid redundant copying in mercury_to_mercury.m.
library/term_io.m:
Add alternative versions of some output predicates that return their
"output" in a string instead.
Factor out some common code.
tests/invalid/overloading.{m,exp}:
A test exercising the error message affected by the change.
tests/invalid/Mmakefile:
Enable the new test.
NEWS:
Announce the changes in the library.
|
||
|
|
58e612321c |
Change the scheme we use to form the name of the predicate we introduce
Estimated hours taken: 1 Branches: main compiler/check_typeclass.m: Change the scheme we use to form the name of the predicate we introduce for typeclass methods to make it reversible, i.e. to allow a demangler to use the predicate name to find out the names of the class, the method, and the instance types *unambiguously*; The old scheme was ambiguous. Also change the prefix used by the scheme to something more relevant. tests/debugger/*.exp: Update the names of method predicates in the expected outputs of the tests using typeclasses. |
||
|
|
9dd11b2fc6 |
Smart recompilation. Record version numbers for each item
Estimated hours taken: 400
Smart recompilation. Record version numbers for each item
in interface files. Record which items are used in each compilation.
Only recompile a module if the output file does not exist or
nothing has changed.
There is still some work to do on this:
- it doesn't work with inter-module optimization.
- it doesn't work when the module name doesn't match the file name.
(this problem will go away when mmake functionality is moved into
the compiler.
I'll hold off documenting this change in the NEWS file and
on the web page for a month or so, until I've had a bit more
experience using it.
compiler/options.m:
compiler/handle_options.m:
doc/user_guide.texi:
Add an option `--smart-recompilation', currently off by default.
Add an internal option `--generate-version-numbers' to control
whether version numbers are written to the interface files. If
`--smart-recompilation' is disabled because the module
is being compiled with `--intermodule-optimization' (e.g. in the
standard library), we still want to write the version numbers
to the interface files.
Add an option `--verbose-recompilation' (default off)
to write messages describing why recompilation is needed.
Add an option `--warn-smart-recompilation' (default on)
to control warnings relating to the smart recompilation
system. Warn if smart recompilation will not work with
the output and inter-module optimization options given.
compiler/recompilation.m:
Type declarations for smart recompilation.
Predicates to record program items used by compilation.
compiler/recompilation_version.m:
Compute version numbers for program items in interface files.
compiler/recompilation_usage.m:
Find all items used by a compilation.
compiler/recompilation_check.m:
Check whether recompilation is necessary.
compiler/timestamp.m:
Timestamp ADT for smart recompilation.
compiler/mercury_compile.m:
Invoke the smart recompilation passes.
compiler/modules.m:
compiler/prog_io.m:
Return timestamps for modules read.
When reading a module make sure the current input stream
is reset to its old value, not stdin.
Handle version number items in interface files.
compiler/module_qual.m:
compiler/unify_proc.m:
compiler/make_hlds.m:
Record all items used by local items.
compiler/make_hlds.m:
Process `:- pragma type_spec' declarations in
add_item_list_clauses. The qual_info is needed
when processing `:- pragma type_spec' declarations
so that any equivalence types used by the declaration
can be recorded as used by the predicate or function to
which the `:- pragma type_spec' applies.
compiler/equiv_type.m:
For each imported item, record which equivalence types
are used by that item.
compiler/hlds_module.m:
Add a field to the module_info to store information about
items used during compilation of a module.
compiler/check_typeclass.m:
Make sure any items used in clauses for typeclass method
implementations are recorded in the `.used' file.
compiler/prog_data.m:
compiler/*.m:
Factor out some duplicated code by combining the
pred and func, and pred_mode and func_mode items.
Make it easier to extract the name of a type, inst or mode
from its declaration.
Add an item type to hold the version numbers for an interface file.
Allow warnings to be reported for `nothing' items (used for
reporting when version numbers are written using an
obsolete format).
compiler/prog_io.m:
compiler/prog_io_util.m:
compiler/typecheck.m:
compiler/type_util.m:
compiler/*.m:
Strip contexts from all types, not just those in class constraints.
This makes it possible to use ordinary unification to check
whether items have changed (with the exception of clauses).
Remove code to create types with contexts in typechecking.
Remove code scattered through the compiler to remove contexts
from types in class constraints.
compiler/hlds_pred.m:
compiler/prog_util.m:
Move hlds_pred__adjust_func_arity to prog_util, so that it
can be used by the pre-hlds passes.
compiler/typecheck.m:
compiler/hlds_module.m:
Move typecheck__visible_modules to hlds_module.m, so it can
be used by recompilation_usage.m.
compiler/typecheck.m:
Add a comment telling where updates may be required if the
code to typecheck a var-functor unification changes.
compiler/error_util.m:
Allow writing messages without contexts (used for the verbose
recompilation messages).
Add functions to format sym_name and sym_name_and_arity,
and to add punctuation to the end of an error message
without unwanted line breaks before the punctuation.
scripts/Mmake.rules:
compiler/modules.m:
Don't remove the output file before running the compiler. We need
to leave the old output file intact if smart recompilation detects
that recompilation is not needed.
compiler/notes/compiler_design.html:
Document the new modules.
library/io.m:
NEWS:
Add predicates to find the modification time of files
and input_streams.
library/set.m:
NEWS:
Add a predicate version of set__fold
Don't sort the output of set__filter, it's already sorted.
library/std_util.m:
NEWS:
Add a predicate `std_util__map_maybe/3' and a function
`std_util__map_maybe/2' to apply a predicate or a function to
a value stored in a term of type `std_util__maybe'.
configure.in:
runtime/mercury_conf.h.in:
runtime/RESERVED_MACRO_NAMES:
When checking whether the compiler is recent enough, check for
the --warn-smart-recompilation option.
Check for stat().
library/Mmakefile:
Disable warnings about smart recompilation not working with
`--intermodule-optimization'.
browser/Mmakefile:
Disable warnings about smart recompilation not working when
the module name doesn't match the file name.
runtime/mercury_string.h:
Add a macro MR_make_string_const() which automates computation
of the length of string argument to MR_string_const().
tests/recompilation/Mmakefile:
tests/recompilation/runtests:
tests/recompilation/test_functions:
tests/recompilation/TESTS:
tests/recompilation/README:
A framework for testing smart recompilation.
The option currently only works for the recompilation directory.
tests/recompilation/TEST.m.{1,2}:
tests/recompilation/TEST_2.m.{1,2}:
tests/recompilation/TEST.exp.{1,2}:
tests/recompilation/TEST.err_exp.2:
Test cases, where TEST is one of add_constructor_r, add_instance_r,
add_instance_2_r, add_type_nr, change_class_r, change_instance_r,
change_mode_r, field_r, func_overloading_nr, func_overloading_r,
lambda_mode_r, nested_module_r, no_version_numbers_r,
pragma_type_spec_r, pred_ctor_ambiguity_r, pred_overloading_r,
add_type_re, remove_type_re, type_qual_re.
tests/handle_options:
Add an option `-e' to generate any missing expected output files.
|
||
|
|
d74eb22905 |
Fix a bug in the module import mechanism -- use_module should
Estimated hours taken: 8
Fix a bug in the module import mechanism -- use_module should
not be transitive. This change is needed for smart recompilation
to avoid needing to check whether the removal of a transitive
import could cause compilation errors -- it never should.
Also fix some bugs in the handling of type class declarations.
compiler/prog_data.m:
Add a `transitively_imported' pseudo-declaration, which
is placed before the items from `.int2' files and `.opt'
files.
Fix the representation of type class bodies.
`:- typeclass foo where [].' declares a typeclass with no
methods. `:- typeclass foo.' declares an abstract typeclass.
The old representation made no distinction between these cases.
compiler/hlds_data.m:
compiler/prog_data.m:
compiler/module_qual.m:
Move the declaration of type type_id from hlds_data.m to prog_data.m.
This avoids a duplicate declaration in module_qual.m.
compiler/modules.m:
Add a `transitively_imported' pseudo-declaration before the
items from `.int2' files.
Remove the bodies of typeclass declarations placed in `.int2'
files -- the methods should not be available unless the module
is explicitly imported.
compiler/module_qual.m:
Items after the `transitively_imported' pseudo-declaration
should not be considered when module qualifying locally
declared items.
compiler/equiv_type.m:
compiler/mercury_to_mercury.m:
compiler/prog_io_typeclass.m:
Handle the change to the representation of typeclass bodies.
compiler/prog_io_typeclass.m:
Check that the arguments of a typeclass declaration
are distinct variables.
compiler/make_hlds.m:
Handle abstract typeclass declarations.
compiler/check_typeclass.m:
Check that all typeclasses have a definition somewhere.
compiler/intermod.m:
Write abstract_exported typeclasses to the `.opt' file.
compiler/add_trail_ops.m:
compiler/context.m:
compiler/llds.m:
compiler/vn_type.m:
Add missing imports.
compiler/magic_util.m:
compiler/ml_type_gen.m:
Remove unnecessary imports.
NEWS:
Note that this change may break existing programs.
compiler/notes/todo.html:
Remove the item relating to this change.
tests/invalid/transitive_import.{m,err_exp}:
Add some tests for uses of transitively imported items.
tests/invalid/transitive_import_class.m:
tests/invalid/transitive_import_class2.m:
tests/invalid/transitive_import_class3.m:
tests/invalid/transitive_import_class.err_exp:
Add a test for use of transitively imported class methods.
tests/invalid/invalid_typeclass.{m,err_exp}:
Add some tests for invalid typeclass declarations.
tests/invalid/Mmakefile:
Add the new tests.
|
||
|
|
36bb97d223 |
Fix a bug where the compiler was silently accepting invalid code.
Estimated hours taken: 6 Branches: main, release Fix a bug where the compiler was silently accepting invalid code. doc/reference_manual.texi: Document that type class methods must have their modes and determinism explicitly declared. compiler/make_hlds.m: Report errors for predicate type class methods with no modes or with modes but no determinism. compiler/check_typeclass.m: compiler/polymorphism.m: Handle the case where a method has no declared determinism: since make_hlds.m will have already reported the error, we just need to avoid aborting or issuing spurious flow-on errors. tests/invalid/Mmakefile: tests/invalid/typeclass_missing_mode.m: tests/invalid/typeclass_missing_mode.err_exp: tests/invalid/typeclass_missing_mode_2.m: tests/invalid/typeclass_missing_mode_2.err_exp: tests/invalid/typeclass_missing_det.m: tests/invalid/typeclass_missing_det.err_exp: tests/invalid/typeclass_missing_det_2.m: tests/invalid/typeclass_missing_det_2.err_exp: tests/invalid/typeclass_missing_det_3.m: tests/invalid/typeclass_missing_det_3.err_exp: Add some regression tests. tests/invalid/tc_err1.err_exp: Update the expected output for this existing test. |
||
|
|
7fc6ce8792 |
Fix a bug which caused some programs using typeclasses to
Estimated hours taken: 6
Fix a bug which caused some programs using typeclasses to
crash with a segmentation fault.
compiler/polymorphism.m:
For typeclass method implementations, make sure the
order of the type-info and typeclass-info arguments
matches the order used by do_call_class_method.
The type-infos for the unconstrained type variables in
the instance declaration and the typeclass-infos for the
constraints on the instance declaration must come
before any other type-infos and typeclass-infos.
compiler/hlds_pred.m:
Add a field to the pred_info type to record for each
typeclass method implementation which class constraints
come from the `:- instance' declaration and which come
from the predicate or function declaration in the
`:- typeclass' declaration.
compiler/check_typeclass.m:
Fill in the new field in the pred_info.
compiler/typecheck.m:
Apply the necessary renamings to the types and
class constraints in the new field in the pred_info.
tests/hard_coded/typeclasses/Mmakefile:
tests/hard_coded/typeclasses/typeclass_order_bug.{m,exp}
tests/hard_coded/typeclasses/typeclass_order_bug2.{m,exp}
tests/hard_coded/typeclasses/typeclass_order_bug3.{m,exp}
Test cases.
|
||
|
|
e29f9a3d2f |
Fix a bug whereby polymorphism was not using the complete set of class
Estimated hours taken: 5
Fix a bug whereby polymorphism was not using the complete set of class
constraint proofs when generating a type class info, resulting in a map
lookup failure under certain conditions.
compiler/polymorphism.m:
When generating a type class info, don't just pass the proofs for
the instance declaration that we calculated in check_typeclass.m.
These proofs just specify how to build the type class infos for any
superclass constraints *given the constraints on the instance
declaration*. Instead, we pass the union of those constraints and
those local to the predicate. This provides proofs for the constraints
on the instance declaration too.
compiler/typecheck.m:
Rather than using the headvars as the set of variables that must not
be bound when searching the superclass relation, use all the variables
in the varset. This remove a parameter from the exported constraint
reduction predicate.
compiler/check_typeclass.m:
Remove the redundant parameter.
tests/hard_coded/typeclasses/Mmakefile:
tests/hard_coded/typeclasses/superclass_bug2.exp:
tests/hard_coded/typeclasses/superclass_bug2.m:
A test case for this.
|
||
|
|
22e418f610 |
Improve the error message for errors in type class instance
Estimated hours taken: 1 Improve the error message for errors in type class instance definitions that use the named (e.g. "pred(foo/N) is bar") syntax, as suggested by Ralph Becket: for such procedures, just output "in bar/N" rather than "in call to bar/N", since the user didn't write any explicit call. compiler/hlds_pred.m: Add a new marker `named_class_instance_method' to the pred_marker type. compiler/hlds_out.m: compiler/intermod.m: Handle the new marker. compiler/check_typeclass.m: For instance methods defined using the named syntax, add the `named_class_instance_method' marker to their markers. compiler/typecheck.m: compiler/mode_errors.m: Pass the pred_markers down to hlds_out__write_call_arg_id. compiler/hlds_out.m: Change hlds_out__write_call_arg_id so that for predicates with the `named_class_instance_method' marker, it doesn't output the "call to". tests/invalid/Mmakefile: tests/invalid/method_impl.m: tests/invalid/method_impl.exp: A regression test. |
||
|
|
e6769ef622 |
Record the module that each instance declaration came from.
Estimated hours taken: 8 Record the module that each instance declaration came from. This is needed for the IL back-end, which includes that module name in the symbol name that it generates for each instance declaration. compiler/prog_data.m: Add a module_name field to the `instance' item. compiler/prog_io_typeclass.m: When parsing `instance' declarations, store the module name that they came from in the module_name field of the `instance' item. compiler/hlds_data.m: Add a module_name field to the `hlds_instance_defn' structure. compiler/make_hlds.m: Copy the module_name field from the `instance' item to the `hlds_instance_defn' structure. compiler/polymorphism.m: Fix an old XXX: when constructing `base_typeclass_info_const's, use the module name from the `hlds_instance_defn', rather than hard-coding the invalid value "some bogus module name". compiler/rtti.m: Add a module_name field to the `base_typeclass_info' rtti_name and rtti_data. compiler/base_typeclass_info.m: Copy the module_name field in the `hlds_instance_defn' to the module_name field in the `base_typeclass_info' rtti_data and rtti_name. compiler/rtti_to_mlds.m: When constructing mlds `data_addr's, use the module_name from the `base_typeclass_info' rtti_name, rather than assuming that such references always refer to instance declarations in the current module. (That assumption would be a safe one currently, but doing it this way is probably a bit more robust against future changes.) compiler/*.m: Trivial changes to reflect the above data structure changes. |
||
|
|
64111f4303 |
Fix a bug reported by petdr.
Estimated hours taken: 5
Fix a bug reported by petdr.
compiler/typecheck.m:
When searching the superclass relation trying to reduce a constraint C,
we were holding all the variables in C as constant and allowing any
others to be bound. (The theory being that any other variables must be
variables introduced during the search eg. by a multiparameter
typeclass that uses less than all of its parameters in one of its
superclass constraint. These variables are effectively existentially
quantified).
However, this is not enough: variables from *other* assumed constraints
must also not be bound, otherwise you risk binding the variables from
another assumed constraint to the variables in C.
So... now we do not bind any of the head_type_params (which makes sense
given that these are the variables that are universally quantified from
the head or existentially quantified from the body).
This required passing the head_type_params down a couple of levels,
including typecheck__reduce_context_by_rule_application, which is
exported.
compiler/check_typeclass.m:
Add the new argument to the call to
typecheck__reduce_context_by_rule_application.
tests/hard_coded/typeclasses/Mmakefile:
tests/hard_coded/typeclasses/superclass_bug.exp:
tests/hard_coded/typeclasses/superclass_bug.m:
A test case for this. This test case was giving an abort during
polymorphism because the constraint proof that had been recorded
was invalid. (The program was still type correct, but the type
checker had recorded a bogus proof).
|
||
|
|
82378c381b |
Allow polymorphic ground insts. This change assumes that all inst
Estimated hours taken: 80 Allow polymorphic ground insts. This change assumes that all inst parameters in the mode declaration for a predicate or function are constrained to be ground-shared. This is a temporary measure until we work out a nice syntax to allow the programmer to tell the compiler that certain inst parameters may be treated as ground insts. Since we don't currently support unconstrained inst parameters anyway, this shouldn't cause a problem. TODO: - Add syntax, something like `:- mode p(in(I)) <= ground(I).', to specify that an inst parameter represents a ground inst. - Allow abstract ground insts that are treated in a similar way to what we've done here with ground inst parameters. - Make mode checking more efficient (i.e. rewrite the mode system). compiler/inst.m: Add a new alternative for ground insts: `constrained_inst_var(inst_var)'. Define the type `inst_var_sub'. compiler/inst_match.m: Change inst_matches_initial so that it: - handles constrained_inst_vars correctly; - returns the inst_var substitutions necessary for the call; - handles inst_matches_initial(ground(...), bound(...), ...) properly (this requires knowing the type of the variable). The last change has also been made for inst_matches_final and inst_matches_binding. However, the check is disabled for now because, without alias tracking, the mode checker becomes too conservative. compiler/hlds_pred.m: compiler/mode_info.m: compiler/simplify.m: compiler/det_util.m: Include the inst_varset in the proc_info, mode_info and simplify_info. Add a vartypes field to the det_info. Remove the vartypes field from the simplify_info since it is now in the det_info. Use record syntax for these data structures and their access predicates to make future changes easier. compiler/prog_io.m: When processing pred and func mode declarations, convert all inst_var(V) insts to ground(shared, constrained_inst_var(V)). compiler/prog_data.m: compiler/hlds_data.m: compiler/make_hlds.m: compiler/mode_util.m: Use inst_vars instead of inst_params. compiler/modes.m: compiler/modecheck_call.m: compiler/unique_modes.m: compiler/mode_util.m: When checking or recomputing initial insts of a call, build up an inst_var substitution (using the modified inst_matches_initial) and apply this to the final insts of the called procedure before checking/recomputing them. compiler/mode_util.m: Make sure that recompute_instmap_delta recomputes the instmap_deltas for lambda_goals even when RecomputeAtomic = no. compiler/type_util.m: Add a new predicate, type_util__cons_id_arg_types which nondeterministically returns the cons_ids and argument types for a given type. Add a new predicate type_util__get_consid_non_existential_arg_types which is the same as type_util__get_existential_arg_types except that it fails rather than aborting for existenially typed arguments. compiler/accumulator.m: compiler/check_typeclass.m: compiler/clause_to_proc.m: compiler/common.m: compiler/continuation_info.m: compiler/deforest.m: compiler/det_analysis.m: compiler/det_report.m: compiler/det_util.m: compiler/dnf.m: compiler/follow_code.m: compiler/goal_store.m: compiler/goal_util.m: compiler/higher_order.m: compiler/inst_util.m: compiler/instmap.m: compiler/lambda.m: compiler/magic.m: compiler/magic_util.m: compiler/mercury_to_mercury.m: compiler/modecheck_unify.m: compiler/module_qual.m: compiler/pd_info.m: compiler/pd_util.m: compiler/polymorphism.m: compiler/post_typecheck.m: compiler/prog_io_util.m: compiler/prog_rep.m: compiler/saved_vars.m: compiler/stack_layout.m: compiler/table_gen.m: compiler/unify_proc.m: compiler/unneeded_code.m: compiler/unused_args.m: Pass inst_varsets and types where needed. Changes to reflect change in definition of the inst data type. compiler/inlining.m: Recompute the instmap deltas for a procedure after inlining. This bug showed up compiling tests/hard_coded/lp.m with inlining and deforestation turned on: deforestation was getting incorrect instmap deltas from inlining, causing the transformation to break mode-correctness. It has only just shown up because of the added call to `inst_matches_initial' from within `recompute_instmap_delta'. tests/invalid/Mmakefile: tests/invalid/unbound_inst_var.m: tests/invalid/unbound_inst_var.err_exp: tests/valid/Mmakefile: tests/valid/unbound_inst_var.m: Move the `unbound_inst_var' test case from `invalid' to `valid' and extend its coverage a bit. |
||
|
|
da9dc64c8f |
Allow typeclass instance declarations to contain more than one clause
Estimated hours taken: 5 Allow typeclass instance declarations to contain more than one clause for each method. Also improve some error messages. compiler/check_typeclass.m: Allow typeclass instance declarations to contain more than one clause for each method, by combining the different clauses for each method into a single definition. Rewrite the code to check for bogus method names in instance declarations. This rewrite was necessitated by the change mentioned above, but also improved the quality of the error message (it now prints the name of the bogus method) and fixed some bugs that sometimes resulted in spurious flow-on error messages. Fix some problems where we were not passing the correct arity for functions (e.g. to make_introduced_pred_name). tests/invalid/Mmakefile: tests/invalid/typeclass_bogus_method.m: tests/invalid/typeclass_bogus_method.err_exp: Add a new regression test. tests/invalid/tc_err*.err_exp: tests/invalid/typeclass_test_*.err_exp: Update the expected output for these test cases, to reflect the improved error messages. doc/reference_manual.texi: Update the documentation to reflect this change. NEWS: Mention that we now allow clauses in instance declarations. |
||
|
|
4d0dff1860 |
Allow typeclass instance declarations to contain clauses, as an
Estimated hours taken: 10 Allow typeclass instance declarations to contain clauses, as an alternative to the current `pred(<MethodName>) is <ImplName>)' syntax. This avoids the need for the user to explicitly define names for procedures that just implement type class methods. XXX Note that currently we only permit one clause per method. compiler/prog_data.m: Change the second `sym_name' field of `instance_method' into a new type `instance_proc_def', which has two alternatives. The first, `name(sym_name)', is for the old syntax. The second, `clauses(list(item))', is for the new syntax. compiler/prog_io_typeclass.m: Parse the new syntax. compiler/make_hlds.m: Add new predicate `produce_instance_method_clauses', for use by check_typeclass.m. This handles the generation of HLDS clauses_infos for both the old and new syntax for instance method definitions. Return the qual_info produced by `parse_tree_to_hlds', so that it can be passed to `produce_instance_method_clauses'. compiler/mercury_compile.m: Pass the qual_info returned by make_hlds.m to check_typeclass.m. compiler/check_typeclass.m: Move the code which produces HLDS definitions for instance methods into `produce_instance_method_clauses' in make_hlds.m. Thread the io__state and qual_info throughout most of the code, since this they are needed to process the new syntax. (The io__state is needed so we can spit out warnings about singleton variables in clauses in type class methods, and the qual_info is needed to handle explicit type qualifiers in such clauses.) compiler/mercury_to_mercury.m: Output the new syntax. tests/hard_coded/typeclasses/Mmakefile: tests/hard_coded/typeclasses/instance_clauses.m: tests/hard_coded/typeclasses/instance_clauses.exp: A test case for the new feature. doc/reference_manual.texi: Document the new feature. |
||
|
|
a033b2e748 |
Fix a bug which caused intermod.m to abort when a type class
Estimated hours taken: 2 Fix a bug which caused intermod.m to abort when a type class contained a predicate or function with more than one mode. compiler/check_typeclass.m: Reorder the method declarations in each instance so that they match the order of the list of pred_proc_ids for the instance implementation. compiler/intermod.m: Remove duplicate pred_ids from the list of methods in an instance declaration when module qualifying the original instance declaration before writing it to the `.opt' file. Make sure that predicates referred to by an instance declaration in a `.opt' file are made exported. compiler/prog_data.m: Simplify the code by replacing the `pred_instance' and `func_instance' constructors of the `instance_method/0' type with a single constructor with a `pred_or_func' argument. compiler/mercury_to_mercury.m: compiler/check_typeclass.m: compiler/prog_io_typeclass.m: compiler/intermod.m: Handle the change to the `instance_method/0' type. tests/hard_coded/typeclasses/Mmakefile: tests/hard_coded/typeclasses/intermod_typeclass_bug.m: tests/hard_coded/typeclasses/intermod_typeclass_bug2.m: tests/hard_coded/typeclasses/intermod_typeclass_bug.exp: Test case. |
||
|
|
0dab66d926 |
Allow class methods to be impure or semipure.
Estimated hours taken: 6
Allow class methods to be impure or semipure. Previously any purity annotation
on a class method was ignored, and the method assumed to be pure. (We have
for some time caught the case of providing an impure implementation for
a (pure) class method, though).
compiler/prog_data.m:
Add purity to the information we store about each method.
compiler/prog_io_typeclass.m:
Record the declared purity of each method.
compiler/make_hlds.m:
For the predicate we generate corresponding to a method, add any
purity annotations that the method has.
compiler/check_typeclass.m:
Add the appropriate impurity marker to the predicate we generate for
each instance method.
compiler/purity.m:
Be careful not to spit out spurious purity warnings:
- Never warn about excessive impurity for a class methods.
(The body of the method is just class_method_call, which
never looks impure as far as it is concerned).
- Never warn about excessive impurity for class instance
method. The fact that a method is impure doesn't mean that
its instances need to be impure, and it would be excessive
to warn about it, seeing that there is no way for the user
to avoid it (other than actually making their implementation
impure...).
compiler/mercury_to_mercury.m:
Print out method purity in interface files.
compiler/module_qual.m:
compiler/equiv_type.m:
Handle the fact that we now store purity info for class methods.
tests/hard_coded/typeclasses/impure_methods.{m,exp}:
A test case for this change.
tests/hard_coded/typeclasses/Mmakefile:
Turn this change on.
tests/invalid/impure_methods.{m,err_exp}:
A test case for invalid use of impurity and class methods
tests/invalid/Mmakefile:
Turn this change on.
|
||
|
|
38dfae4f7c |
Implement handling of typeclasses for inter-module optimization.
Estimated hours taken: 15 Implement handling of typeclasses for inter-module optimization. compiler/hlds_data.m: compiler/*.m: Add fields to type hlds_class_defn for use by intermod.m - the import_status of the `:- typeclass' declaration. - the original class interface from the `:- typeclass' declaration. compiler/intermod.m: Write all local typeclasses, instances, types, insts and modes to the `.opt' file, instead of trying to work out which are needed. The old code to do this missed some types, insts and modes (test case tests/valid/intermod_test.m). compiler/polymorphism.m: Expand class method bodies for imported predicates so that method lookups for those classes can be optimized. compiler/hlds_pred.m: compiler/check_typeclass.m: compiler/higher_order.m: compiler/hlds_out.m: Add a marker `class_instance_method', used to identify predicates introduced by check_typeclass.m to call the methods for each instance. Don't export `check_typeclass__introduced_pred_name_prefix/0' - higher_order.m now checks for a `class_instance_method' marker instead. compiler/dead_proc_elim.m: Analyse all instance declarations, not just those defined in the current module, so that declarations for imported instance methods are not removed before method lookups have been specialized. tests/valid/Mmakefile: tests/valid/intermod_test.m: tests/valid/intermod_test2.m: Check that nested types and modes are written to the `.opt' file. tests/valid/intermod_typeclass.m: tests/valid/intermod_typeclass2.m: Check that local typeclass and instance declarations are written to the `.opt' file. |