Commit Graph

8 Commits

Author SHA1 Message Date
Zoltan Somogyi
748a22a882 Improve diagnostics for bad instance declarations.
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.
2018-06-27 19:57:03 +02:00
Zoltan Somogyi
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.
2015-02-16 12:32:18 +11:00
Julien Fischer
d5cdd701b1 Further consistency improvements for error and warning messages.
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.
2014-07-30 23:09:39 +10:00
Mark Brown
2c8630fdde Support polymorphic instances of typeclasses with functional dependencies.
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.
2006-10-29 03:18:59 +00:00
Mark Brown
0da87c5ece Enforce the requirement that type variables in instance declarations
Estimated hours taken: 1.5
Branches: main

compiler/prog_io_typeclass.m:
	Enforce the requirement that type variables in instance declarations
	are distinct.

tests/invalid/Mmakefile:
tests/invalid/instance_dup_var.err_exp:
tests/invalid/instance_dup_var.m:
	Test case.

tests/hard_coded/typeclasses/Mmakefile:
	Disable the instance_unconstrained_tvar_dup test case, since we
	don't support the feature that it tests.

tests/invalid/range_restrict.err_exp:
tests/invalid/range_restrict.m:
tests/valid/mpj5.m:
	Comment out the parts of these test cases which use duplicated
	instance variables, and adjust the expected output where applicable.
2006-10-19 07:29:56 +00:00
Zoltan Somogyi
411b45846a Modify check_typeclass.m to gather up all error messages, and print them all
Estimated hours taken: 12
Branches: main

Modify check_typeclass.m to gather up all error messages, and print them all
at once after sorting.

Modify the determinism analysis pass to generate error_specs directly, instead
of generating context_det_msgs and converting those to error_specs later.

Separate the simplify pass's mechanism for generating error messages from
the determinism pass.

compiler/check_typeclass.m:
	Return all error messages instead of printing them when generated.

	Keep the error messages outside the instance_method_info structure,
	and give the fields of the structure names.

compiler/det_analysis.m:
	Generate error specs directly.

compiler/det_report.m:
	Delete the context_det_msg data type and the predicates that operated
	on it, since they are no longer needed. The code that used to convert a
	context_det_msg into an error_spec is now dispersed to the sites that
	generate the error report in the first place. These sites are mostly
	in det_analysis.m and simplify.m, with a few in other modules
	(e.g. common.m and format_call.m). Export some auxiliary functions
	that the these sites now need.

compiler/simplify.m:
	Generate error_specs directly, instead of through context_det_msgs,
	and return them to the caller for printing.

compiler/common.m:
compiler/format_call.m:
	Conform to the change to det_report.m.

compiler/unused_import.m:
	Return all error messages instead of printing them when generated.

compiler/mercury_compile.m:
	Print the error message batches returned by the modified passes.

	Use the version of globals in module_infos in preference to the one
	in the I/O state, since we would like to phase out the latter.

	Don't explicitly sort error_specs, since write_error_specs will do
	it anyway.

compiler/error_util.m:
	Separate the error messages of the simplify pass from those of
	determinism analysis.

	Provide a standard way to format type constructor names.

	Require the calls to provide the globals when printing error_specs.
	This is to allow callers to provide the globals from a module_info,
	instead of the one in the I/O state.

compiler/passes_aux.m:
	Provide support for passes that have lists of error_specs threaded
	through them, as simplify now does.

	Rename some predicates to avoid some ambiguities.

compiler/deforest.m:
compiler/pd_util.m:
compiler/unify_proc.m:
compiler/unused_args.m:
	Conform to the change to the interface of determinism analysis.

compiler/inlining.m:
	Do not thread the I/O state through this module.

compiler/make.module_dep_file.m:
compiler/make_hlds_passes.m:
compiler/ml_tailcall.m:
compiler/mode_errors.m:
compiler/modes.m:
compiler/modules.m:
compiler/stratify.m:
compiler/table_gen.m:
	Conform to the change in error_util.

compiler/prog_data.m:
	Rename some function symbols to avoid some ambiguities.

compiler/add_class.m:
compiler/base_typeclass_info.m:
compiler/hlds_out.m:
compiler/intermod.m:
compiler/module_qual.m:
compiler/prog_io_typeclass.m:
compiler/recompilation.check.m:
compiler/recompilation.usage.m:
compiler/recompilation.version.m:
compiler/type_class_info.m:
	Conform to the change in prog_data.m.

tests/invalid/*err_exp:
	Update the expected output files to conform to the changes above.
	This mosly involves expecting sorted messages without duplicates.
2006-10-13 04:52:38 +00:00
Julien Fischer
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.
2005-09-14 05:27:11 +00:00
Mark Brown
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.
2005-04-20 12:57:59 +00:00