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.
Estimated hours taken: 18
Branches: main
Move the univ, maybe, pair and unit types from std_util into their own
modules. std_util still contains the general purpose higher-order programming
constructs.
library/std_util.m:
Move univ, maybe, pair and unit (plus any other related types
and procedures) into their own modules.
library/maybe.m:
New module. This contains the maybe and maybe_error types and
the associated procedures.
library/pair.m:
New module. This contains the pair type and associated procedures.
library/unit.m:
New module. This contains the types unit/0 and unit/1.
library/univ.m:
New module. This contains the univ type and associated procedures.
library/library.m:
Add the new modules.
library/private_builtin.m:
Update the declaration of the type_ctor_info struct for univ.
runtime/mercury.h:
Update the declaration for the type_ctor_info struct for univ.
runtime/mercury_mcpp.h:
runtime/mercury_hlc_types.h:
Update the definition of MR_Univ.
runtime/mercury_init.h:
Fix a comment: ML_type_name is now exported from type_desc.m.
compiler/mlds_to_il.m:
Update the the name of the module that defines univs (which are
handled specially by the il code generator.)
library/*.m:
compiler/*.m:
browser/*.m:
mdbcomp/*.m:
profiler/*.m:
deep_profiler/*.m:
Conform to the above changes. Import the new modules where they
are needed; don't import std_util where it isn't needed.
Fix formatting in lots of modules. Delete duplicate module
imports.
tests/*:
Update the test suite to confrom to the above changes.
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.