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 two main changes in this commit are:
(1) Use the error_util library's decl/1 and pramga_decl/1 format components in more
places.
(2) Quote type variables that appear in error messages.
compiler/error_util.m:
Add a version of list_to_pieces/1 that places each of the strings in
the input list in single quotes.
compiler/prog_io_type_defn.m:
Quote type variables names in error messages.
compiler/add_class.m:
compiler/add_pragma.m:
compiler/add_pred.m:
compiler/check_typeclass.m:
compiler/make_hlds_error.m:
compiler/post_typecheck.m:
compiler/prog_io.m:
Use the error_util library's decl/1 and pragma_decl/1 format components
in more places.
compiler/mode_errors.m:
Quote program variables and insts in some error messages.
compiler/post_term_analysis.m:
Format a type ctor and arity in an error message properly.
tests/invalid/*.err_exp:
tests/warnings/*.exp:
Conform to the above changes.
Estimated hours taken: 16
Branches: main
Support polymorphic instances of typeclasses with functional dependencies.
We do this by allowing type variables in the range arguments, which must be
distinct according to existing typeclass restrictions, to be determined
from type variables in the domain arguments by the functional dependencies
on the instance constraints.
compiler/check_typeclass.m:
Remove the range-restrictedness check and replace it with a coverage
check, which makes use of the instance constraints when determining
if a type variable is bound.
Explicitly pass the range tvars to get_unbound_tvars, so that it
can be used by the coverage pass as well as the
check_typeclass_constraints pass.
Rearrange the structure of the module, since multiple passes now
make use of the get_unbound_tvars predicate. Separate out the
error reporting code from the main logic.
Clarify the description at the top of this module. It now corresponds
more closely with the structure of the module.
Fix a bug in check_instance_pred_procs/12 whereby the wrong context
was being used in the new instance definition, leading to incorrect
error messages; use field update syntax to avoid this problem.
doc/reference_manual.texi:
Add an example to illustrate the relaxed restrictions.
tests/valid/Mmakefile:
tests/valid/fundeps_poly_instance.m:
Test the new feature.
tests/invalid/Mmakefile:
tests/invalid/fundeps_coverage.err_exp:
tests/invalid/fundeps_coverage.m:
Test the new error reporting.
tests/invalid/range_restrict.err_exp:
Update for the changed error message.
tests/invalid/typeclass_bogus_method.err_exp:
tests/invalid/typeclass_test_10.err_exp:
Update these expected outputs for the bugfix.