mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-20 03:43:51 +00:00
083d376e6598628362ee91c2da170febd83590f4
7 Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
29ff7d5732 |
Improve diagnostics for type- and mode-errors.
compiler/mode_errors.m:
When generating an error message for a bad higher order inst,
print the specific cause of the mismatch, instead of just
"actual inst is X, expected inst was Y".
compiler/modecheck_call.m:
Change the code that generates that error to record the specific cause
in the mode_error structure of the error.
tests/invalid/higher_order_mode_mismatch.{m,err_exp}:
Add a new test case for the specific causes that other test cases
don't already cover. (As it happens, most of those causes can't be
caught by mode analysis because typechecking reports them first,
but it did so in ways that could be improved. Hence the change to
typecheck_errors.m and most of the .err_exp files below.)
tests/invalid/Mmakefile:
Enable the new test case.
compiler/typecheck_errors.m:
Instead of generating output of the form
<something> has type `abc',
expected type was `def'
generate output of the form
<something> has type
abc,
expected type was
def
The indentation directs the eye to the differences that matter,
and automatically lines up any corresponding parts of the actual
and expected types. It also replaces the quotes as a method
of separating the types being referred to from their surroundings.
tests/invalid/abstract_eqv.err_exp:
tests/invalid/actual_expected.err_exp:
tests/invalid/anys_in_negated_contexts.err_exp:
tests/invalid/arg_permutation.err_exp:
tests/invalid/bad_statevar_bad_context.err_exp:
tests/invalid/bug197.err_exp:
tests/invalid/comparison.err_exp:
tests/invalid/error_in_list.err_exp:
tests/invalid/ext_type.err_exp:
tests/invalid/ext_type_bug.err_exp:
tests/invalid/foreign_procs_exist_type.err_exp:
tests/invalid/getopt_old.err_exp:
tests/invalid/ho_type_arity_bug.err_exp:
tests/invalid/ho_type_mode_bug.err_exp:
tests/invalid/illtyped_compare.err_exp:
tests/invalid/integral_constant_no_suffix.err_exp:
tests/invalid/method_impl.err_exp:
tests/invalid/mixed_up_streams.err_exp:
tests/invalid/mpj1.err_exp:
tests/invalid/mpj4.err_exp:
tests/invalid/no_method.err_exp:
tests/invalid/nullary_ho_func_error.err_exp:
tests/invalid/overloading.err_exp:
tests/invalid/record_syntax_errors.err_exp:
tests/invalid/try_bad_params.err_exp:
tests/invalid/type_error_ambiguous.err_exp:
tests/invalid/type_error_in_arg.err_exp:
tests/invalid/type_mismatch.err_exp:
tests/invalid/types2.err_exp:
tests/invalid/user_field_access_decl_override2.err_exp:
tests/invalid_nodepend/errors2.err_exp:
tests/invalid_purity/impure_func_t5.err_exp:
tests/invalid_purity/impure_pred_t1.err_exp:
tests/invalid_purity/impure_pred_t1_fixed.err_exp:
tests/invalid_purity/impure_pred_t2.err_exp:
tests/invalid_purity/purity_nonsense2.err_exp:
tests/invalid_purity/purity_type_error.err_exp:
Expect the updated error messages.
tests/invalid/ho_type_mode_bug.m:
Update obsolete comments.
|
||
|
|
fdd141bf77 |
Clean up the tests in the other test directories.
tests/invalid/*.{m,err_exp}:
tests/misc_tests/*.m:
tests/mmc_make/*.m:
tests/par_conj/*.m:
tests/purity/*.m:
tests/stm/*.m:
tests/string_format/*.m:
tests/structure_reuse/*.m:
tests/submodules/*.m:
tests/tabling/*.m:
tests/term/*.m:
tests/trailing/*.m:
tests/typeclasses/*.m:
tests/valid/*.m:
tests/warnings/*.{m,exp}:
Make these tests use four-space indentation, and ensure that
each module is imported on its own line. (I intend to use the latter
to figure out which subdirectories' tests can be executed in parallel.)
These changes usually move code to different lines. For the tests
that check compiler error messages, expect the new line numbers.
browser/cterm.m:
browser/tree234_cc.m:
Import only one module per line.
tests/hard_coded/boyer.m:
Fix something I missed.
|
||
|
|
d9e30aec5b |
Don't write an outer pair of brackets when formatting terms with '.'
Branches: main compiler/mercury_to_mercury.m: Don't write an outer pair of brackets when formatting terms with '.' or ':' as the functor, which made module-qualified types in error messages unnecessarily ugly. tests/hard_coded/impl_def_literal.exp: tests/invalid/actual_expected.err_exp: tests/invalid/bad_instance.err_exp: tests/invalid/errors2.err_exp: tests/invalid/ext_type.err_exp: tests/invalid/ext_type_bug.err_exp: tests/invalid/funcs_as_preds.err_exp: tests/invalid/illtyped_compare.err_exp: tests/invalid/instance_dup_var.err_exp: tests/invalid/invalid_instance_declarations.err_exp: tests/invalid/method_impl.err_exp: tests/invalid/mixed_up_streams.err_exp: tests/invalid/mpj4.err_exp: tests/invalid/nullary_ho_func_error.err_exp: tests/invalid/overloading.err_exp: tests/invalid/purity/impure_func_t5.err_exp: tests/invalid/purity/impure_pred_t1.err_exp: tests/invalid/purity/impure_pred_t1_fixed.err_exp: tests/invalid/purity/impure_pred_t2.err_exp: tests/invalid/record_syntax_errors.err_exp: tests/invalid/tc_err1.err_exp: tests/invalid/tc_err2.err_exp: tests/invalid/try_bad_params.err_exp: tests/invalid/type_error_ambiguous.err_exp: tests/misc_tests/pretty_print_test.exp: tests/warnings/inference_test.exp: Update test cases. |
||
|
|
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. |
||
|
|
835d8315ef |
Do not allow discriminated unions with a single zero-arity constructor to have
Estimated hours taken: 10
Branches: main, release
Do not allow discriminated unions with a single zero-arity constructor to have
user-defined equality or comparison. Defining such types causes an assertion
failure in the compiler because the types are considered to be dummy types and
the runtime currently doesn't support (and probably won't ever) d.u. dummy
types with user-defined equality or comparison.
Fix another bug where the compiler was not printing out the `recompile with
-E' prompt at the appropriate time. The bug was caused by the fact that there
were several copies of the globals structure and the one that was being
checked at the time the prompt was being printed out was not the one that had
been updated during the rest of compilation.
compiler/add_types.m:
Emit an error message if an attempt is made to define a d.u. dummy
type with user-defined equality or comparison.
compiler/globals.m:
Remove the extra_error_info field from the globals structure and turn
it into a mutable. Export access predicates for this mutable. The
reason for doing this is that the compiler was sometimes looking at
the wrong copy of the globals structure when checking the value of
this flag - this meant that sometimes the recompile with `-E' prompt
was not being displayed. Turning this flag into a mutable avoids the
problem because now there is only one copy.
compiler/make_hlds.m:
s/__/./ in a few spots.
doc/reference_manual.texi:
Mention the new restrictions on discriminated union types with
user-defined equality or comparison.
tests/invalid/exported_unify2.m:
tests/invalid/exported_unify3.m:
Change some types with user-defined equality or comparison so that
they are no longer dummy types. These test cases have not been
triggering the assertion failure in the compiler because they are only
error checked and the assertion that is failing occurs further along
in the compilation process.
tests/invalid/user_eq_dummy.{m,err_exp}:
Test the new error message for dummy types with user-defined equality
or comparison.
tests/invalid/extra_info_prompt.{m,err_exp}:
Test that the recompile with `-E' prompt is being displayed when it
should.
tests/invalid/Mercury.options:
tests/invalid/Mmakefile:
Include the new test cases.
Where there is a verbose version of the error message compile with
`-E'.
tests/recompilation/add_type_re.err_exp.2:
tests/invalid/*.err_exp:
Update expected outputs to conform to the above.
|
||
|
|
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. |
||
|
|
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. |