compiler/check_typeclass.m:
As above. This makes future changes to the main code of the module easier.
In some cases, this required carving error message generating code
out of larger predicates.
Some errors were being generated by functions that returned an error_spec,
and others by predicates that added the new error_spec to !Specs.
Standardize on the latter scheme.
Use some recently-added auxiliary functions to generate parts of some
error messages, to present the same info the same way in different
error messages. This part of the diff causes the changes to .err_exp files
below.
Start the name of all the predicates that generate error with "report_".
Return !:Specs. Do not take an an initial !.Specs argument, because
any error_specs in it would screw up a test. Our caller always passed us
[] anyway.
The non-error-reporting code in this module is (currently) divided into
six passes. The code that checks for cycles between typeclasses is the
third pass, but its code was after the code of the fourth pass; fix that.
Turn some functions into predicates to allow the use of state variables.
Rename a function symbol to avoid an ambiguity.
Fix comment rot.
compiler/mercury_compile_front_end.m:
Don't pass [] as the initial !.Specs.
compiler/hlds_class.m:
Move a type definition to its proper place.
tests/invalid/bad_instance2.err_exp:
tests/invalid/constraint_proof_bug_lib.err_exp:
tests/invalid/invalid_instance_declarations.err_exp:
Expect updated error messages.
compiler/check_typeclass.m:
When a type in an instance declaration is not a type constructor,
don't just say what it is; say also what it should be.
When a type in an instance declaration is a type constructor but some
of its arguments are not type variables, don't just say so: say *which*
of their arguments are the problem.
Do not use "argument" to refer to both "the arguments of the instance
declaration" and the "arguments of a type constructor"; use the terminology
"instance type" for the former.
Always end the line after the ":" in the error's top level description.
Omit the module qualification of the typeclass name in error messages,
since the base name of the typeclass, and the context, should always
be enough to eliminate any ambiguity.
Fix a bug in the use of choose_number.
Don't gather the set of seen types, since it was never used.
tests/invalid/invalid_instance_declarations.m:
Extend this test to type classes with more than one type.
tests/invalid/bad_instance2.err_exp:
tests/invalid/constraint_proof_bug_lib.err_exp:
tests/invalid/fundeps_coverage.err_exp:
tests/invalid/instance_var_bug.err_exp:
tests/invalid/invalid_instance_declarations.err_exp:
tests/invalid/range_restrict.err_exp:
tests/invalid/tc_err1.err_exp:
tests/invalid/tc_err2.err_exp:
tests/invalid/typeclass_bogus_method.err_exp:
tests/invalid/typeclass_missing_mode_2.err_exp:
tests/invalid/typeclass_test_10.err_exp:
tests/invalid/typeclass_test_3.err_exp:
tests/invalid/typeclass_test_4.err_exp:
tests/invalid/typeclass_test_5.err_exp:
tests/invalid/typeclass_test_9.err_exp:
Update these expected outputs to account for the changes above.
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.
The Mercury compiler has long required that all of the type variables referred
to in type class instance head be distinct. There is no particularly good
reason for this restriction -- the implication that it helps to ensure that
there are no overlapping instances in the reference manual is misleading, since
the way that we do that (at least in the C grades), by using the names of the
base_typeclass_infos, is not affected by type variables.
The major implementation detail needed to support repeated type variables in
instance declarations is that when doing context reduction, we must do full
matching of instances against constraints (i.e. we need to keep track of the
type variable bindings). Since we already do this, the only change required to
support repeated type variables is to remove the error checking that prevents
it.
compiler/check_typeclass.m:
Do not require that type variables in instance heads be distinct.
doc/reference_manual.texi:
Document that repeated type variables are now allowed in instance
heads.
NEWS:
Announce the change.
tests/invalid/instance_dup_var.m:
Shift this test into the valid directory.
tests/invalid/repeated_instance_vars_unsat.{m,err_exp}:
Check that we get an error if a repeated type variable is bound
to different types.
tests/valid/Mmakefile:
tests/invalid/Mmakefile:
Conform to the above changes.
tests/invalid/invalid_instance_declarations.err_exp:
tests/invalid/invalid_instance_declarations.m:
Remove instances that are now valid.
Estimated hours taken: 1
Branches: main
compiler/check_typeclasses.m:
Do several kinds of cleanups. There are no algorithmic changes.
First, this modules does several different checks. Put the code that
does those checks in the same order as the comment at the top
explaining them, and the order in which they are executed.
Second, give some predicates and variables more meaningful names.
Third, fix the error messages so that they form complete sentences,
and do not use abbreviations unnecessarily.
tests/invalid/bad_instance.err_exp:
tests/invalid/instance_dup_var.err_exp:
tests/invalid/instance_var_bug.err_exp:
tests/invalid/invalid_instance_declarations.err_exp:
tests/invalid/invalid_typeclass.err_exp:
Conform to the third change above.
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.
Estimated hours taken: 8
Branches: main
Improve the detection of invalid instance declarations by doing the check
during hlds checking rather than parsing, as we have more information then.
compiler/check_typeclass.m:
Add check_instance_declaration_types/4, where we check that each type
the instance declaration must be either a type with no arguments, a
polymorphic type whose arguments are all distinct type variables.
compiler/error_util.m:
Add nth_fixed to format_component which returns "first", "second",
"third", "4th" depending on the given integer.
compiler/prog_io_typeclass.m:
Remove the invalid instance check during parsing.
compiler/type_util.m:
Fix a spelling mistake.
tests/hard_coded/typeclasses/fundeps_1.m:
tests/hard_coded/typeclasses/fundeps_2.m:
tests/invalid/ambiguous_method.m:
tests/invalid/ambiguous_method_2.m:
Fix invalid instance declarations.
tests/invalid/bad_instance.err_exp:
tests/invalid/instance_dup_var.err_exp:
Update to the new error messages.
tests/invalid/Mmakefile:
tests/invalid/invalid_instance_declarations.err_exp:
tests/invalid/invalid_instance_declarations.m:
Add a check where we use equivalence types to
hide invalid typeclass declarations.