mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-18 07:15:19 +00:00
d74eb22905015e657d233c7d44218183cf35d2a2
41 Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
d74eb22905 |
Fix a bug in the module import mechanism -- use_module should
Estimated hours taken: 8
Fix a bug in the module import mechanism -- use_module should
not be transitive. This change is needed for smart recompilation
to avoid needing to check whether the removal of a transitive
import could cause compilation errors -- it never should.
Also fix some bugs in the handling of type class declarations.
compiler/prog_data.m:
Add a `transitively_imported' pseudo-declaration, which
is placed before the items from `.int2' files and `.opt'
files.
Fix the representation of type class bodies.
`:- typeclass foo where [].' declares a typeclass with no
methods. `:- typeclass foo.' declares an abstract typeclass.
The old representation made no distinction between these cases.
compiler/hlds_data.m:
compiler/prog_data.m:
compiler/module_qual.m:
Move the declaration of type type_id from hlds_data.m to prog_data.m.
This avoids a duplicate declaration in module_qual.m.
compiler/modules.m:
Add a `transitively_imported' pseudo-declaration before the
items from `.int2' files.
Remove the bodies of typeclass declarations placed in `.int2'
files -- the methods should not be available unless the module
is explicitly imported.
compiler/module_qual.m:
Items after the `transitively_imported' pseudo-declaration
should not be considered when module qualifying locally
declared items.
compiler/equiv_type.m:
compiler/mercury_to_mercury.m:
compiler/prog_io_typeclass.m:
Handle the change to the representation of typeclass bodies.
compiler/prog_io_typeclass.m:
Check that the arguments of a typeclass declaration
are distinct variables.
compiler/make_hlds.m:
Handle abstract typeclass declarations.
compiler/check_typeclass.m:
Check that all typeclasses have a definition somewhere.
compiler/intermod.m:
Write abstract_exported typeclasses to the `.opt' file.
compiler/add_trail_ops.m:
compiler/context.m:
compiler/llds.m:
compiler/vn_type.m:
Add missing imports.
compiler/magic_util.m:
compiler/ml_type_gen.m:
Remove unnecessary imports.
NEWS:
Note that this change may break existing programs.
compiler/notes/todo.html:
Remove the item relating to this change.
tests/invalid/transitive_import.{m,err_exp}:
Add some tests for uses of transitively imported items.
tests/invalid/transitive_import_class.m:
tests/invalid/transitive_import_class2.m:
tests/invalid/transitive_import_class3.m:
tests/invalid/transitive_import_class.err_exp:
Add a test for use of transitively imported class methods.
tests/invalid/invalid_typeclass.{m,err_exp}:
Add some tests for invalid typeclass declarations.
tests/invalid/Mmakefile:
Add the new tests.
|
||
|
|
36bb97d223 |
Fix a bug where the compiler was silently accepting invalid code.
Estimated hours taken: 6 Branches: main, release Fix a bug where the compiler was silently accepting invalid code. doc/reference_manual.texi: Document that type class methods must have their modes and determinism explicitly declared. compiler/make_hlds.m: Report errors for predicate type class methods with no modes or with modes but no determinism. compiler/check_typeclass.m: compiler/polymorphism.m: Handle the case where a method has no declared determinism: since make_hlds.m will have already reported the error, we just need to avoid aborting or issuing spurious flow-on errors. tests/invalid/Mmakefile: tests/invalid/typeclass_missing_mode.m: tests/invalid/typeclass_missing_mode.err_exp: tests/invalid/typeclass_missing_mode_2.m: tests/invalid/typeclass_missing_mode_2.err_exp: tests/invalid/typeclass_missing_det.m: tests/invalid/typeclass_missing_det.err_exp: tests/invalid/typeclass_missing_det_2.m: tests/invalid/typeclass_missing_det_2.err_exp: tests/invalid/typeclass_missing_det_3.m: tests/invalid/typeclass_missing_det_3.err_exp: Add some regression tests. tests/invalid/tc_err1.err_exp: Update the expected output for this existing test. |
||
|
|
7fc6ce8792 |
Fix a bug which caused some programs using typeclasses to
Estimated hours taken: 6
Fix a bug which caused some programs using typeclasses to
crash with a segmentation fault.
compiler/polymorphism.m:
For typeclass method implementations, make sure the
order of the type-info and typeclass-info arguments
matches the order used by do_call_class_method.
The type-infos for the unconstrained type variables in
the instance declaration and the typeclass-infos for the
constraints on the instance declaration must come
before any other type-infos and typeclass-infos.
compiler/hlds_pred.m:
Add a field to the pred_info type to record for each
typeclass method implementation which class constraints
come from the `:- instance' declaration and which come
from the predicate or function declaration in the
`:- typeclass' declaration.
compiler/check_typeclass.m:
Fill in the new field in the pred_info.
compiler/typecheck.m:
Apply the necessary renamings to the types and
class constraints in the new field in the pred_info.
tests/hard_coded/typeclasses/Mmakefile:
tests/hard_coded/typeclasses/typeclass_order_bug.{m,exp}
tests/hard_coded/typeclasses/typeclass_order_bug2.{m,exp}
tests/hard_coded/typeclasses/typeclass_order_bug3.{m,exp}
Test cases.
|
||
|
|
e29f9a3d2f |
Fix a bug whereby polymorphism was not using the complete set of class
Estimated hours taken: 5
Fix a bug whereby polymorphism was not using the complete set of class
constraint proofs when generating a type class info, resulting in a map
lookup failure under certain conditions.
compiler/polymorphism.m:
When generating a type class info, don't just pass the proofs for
the instance declaration that we calculated in check_typeclass.m.
These proofs just specify how to build the type class infos for any
superclass constraints *given the constraints on the instance
declaration*. Instead, we pass the union of those constraints and
those local to the predicate. This provides proofs for the constraints
on the instance declaration too.
compiler/typecheck.m:
Rather than using the headvars as the set of variables that must not
be bound when searching the superclass relation, use all the variables
in the varset. This remove a parameter from the exported constraint
reduction predicate.
compiler/check_typeclass.m:
Remove the redundant parameter.
tests/hard_coded/typeclasses/Mmakefile:
tests/hard_coded/typeclasses/superclass_bug2.exp:
tests/hard_coded/typeclasses/superclass_bug2.m:
A test case for this.
|
||
|
|
22e418f610 |
Improve the error message for errors in type class instance
Estimated hours taken: 1 Improve the error message for errors in type class instance definitions that use the named (e.g. "pred(foo/N) is bar") syntax, as suggested by Ralph Becket: for such procedures, just output "in bar/N" rather than "in call to bar/N", since the user didn't write any explicit call. compiler/hlds_pred.m: Add a new marker `named_class_instance_method' to the pred_marker type. compiler/hlds_out.m: compiler/intermod.m: Handle the new marker. compiler/check_typeclass.m: For instance methods defined using the named syntax, add the `named_class_instance_method' marker to their markers. compiler/typecheck.m: compiler/mode_errors.m: Pass the pred_markers down to hlds_out__write_call_arg_id. compiler/hlds_out.m: Change hlds_out__write_call_arg_id so that for predicates with the `named_class_instance_method' marker, it doesn't output the "call to". tests/invalid/Mmakefile: tests/invalid/method_impl.m: tests/invalid/method_impl.exp: A regression test. |
||
|
|
e6769ef622 |
Record the module that each instance declaration came from.
Estimated hours taken: 8 Record the module that each instance declaration came from. This is needed for the IL back-end, which includes that module name in the symbol name that it generates for each instance declaration. compiler/prog_data.m: Add a module_name field to the `instance' item. compiler/prog_io_typeclass.m: When parsing `instance' declarations, store the module name that they came from in the module_name field of the `instance' item. compiler/hlds_data.m: Add a module_name field to the `hlds_instance_defn' structure. compiler/make_hlds.m: Copy the module_name field from the `instance' item to the `hlds_instance_defn' structure. compiler/polymorphism.m: Fix an old XXX: when constructing `base_typeclass_info_const's, use the module name from the `hlds_instance_defn', rather than hard-coding the invalid value "some bogus module name". compiler/rtti.m: Add a module_name field to the `base_typeclass_info' rtti_name and rtti_data. compiler/base_typeclass_info.m: Copy the module_name field in the `hlds_instance_defn' to the module_name field in the `base_typeclass_info' rtti_data and rtti_name. compiler/rtti_to_mlds.m: When constructing mlds `data_addr's, use the module_name from the `base_typeclass_info' rtti_name, rather than assuming that such references always refer to instance declarations in the current module. (That assumption would be a safe one currently, but doing it this way is probably a bit more robust against future changes.) compiler/*.m: Trivial changes to reflect the above data structure changes. |
||
|
|
64111f4303 |
Fix a bug reported by petdr.
Estimated hours taken: 5
Fix a bug reported by petdr.
compiler/typecheck.m:
When searching the superclass relation trying to reduce a constraint C,
we were holding all the variables in C as constant and allowing any
others to be bound. (The theory being that any other variables must be
variables introduced during the search eg. by a multiparameter
typeclass that uses less than all of its parameters in one of its
superclass constraint. These variables are effectively existentially
quantified).
However, this is not enough: variables from *other* assumed constraints
must also not be bound, otherwise you risk binding the variables from
another assumed constraint to the variables in C.
So... now we do not bind any of the head_type_params (which makes sense
given that these are the variables that are universally quantified from
the head or existentially quantified from the body).
This required passing the head_type_params down a couple of levels,
including typecheck__reduce_context_by_rule_application, which is
exported.
compiler/check_typeclass.m:
Add the new argument to the call to
typecheck__reduce_context_by_rule_application.
tests/hard_coded/typeclasses/Mmakefile:
tests/hard_coded/typeclasses/superclass_bug.exp:
tests/hard_coded/typeclasses/superclass_bug.m:
A test case for this. This test case was giving an abort during
polymorphism because the constraint proof that had been recorded
was invalid. (The program was still type correct, but the type
checker had recorded a bogus proof).
|
||
|
|
82378c381b |
Allow polymorphic ground insts. This change assumes that all inst
Estimated hours taken: 80 Allow polymorphic ground insts. This change assumes that all inst parameters in the mode declaration for a predicate or function are constrained to be ground-shared. This is a temporary measure until we work out a nice syntax to allow the programmer to tell the compiler that certain inst parameters may be treated as ground insts. Since we don't currently support unconstrained inst parameters anyway, this shouldn't cause a problem. TODO: - Add syntax, something like `:- mode p(in(I)) <= ground(I).', to specify that an inst parameter represents a ground inst. - Allow abstract ground insts that are treated in a similar way to what we've done here with ground inst parameters. - Make mode checking more efficient (i.e. rewrite the mode system). compiler/inst.m: Add a new alternative for ground insts: `constrained_inst_var(inst_var)'. Define the type `inst_var_sub'. compiler/inst_match.m: Change inst_matches_initial so that it: - handles constrained_inst_vars correctly; - returns the inst_var substitutions necessary for the call; - handles inst_matches_initial(ground(...), bound(...), ...) properly (this requires knowing the type of the variable). The last change has also been made for inst_matches_final and inst_matches_binding. However, the check is disabled for now because, without alias tracking, the mode checker becomes too conservative. compiler/hlds_pred.m: compiler/mode_info.m: compiler/simplify.m: compiler/det_util.m: Include the inst_varset in the proc_info, mode_info and simplify_info. Add a vartypes field to the det_info. Remove the vartypes field from the simplify_info since it is now in the det_info. Use record syntax for these data structures and their access predicates to make future changes easier. compiler/prog_io.m: When processing pred and func mode declarations, convert all inst_var(V) insts to ground(shared, constrained_inst_var(V)). compiler/prog_data.m: compiler/hlds_data.m: compiler/make_hlds.m: compiler/mode_util.m: Use inst_vars instead of inst_params. compiler/modes.m: compiler/modecheck_call.m: compiler/unique_modes.m: compiler/mode_util.m: When checking or recomputing initial insts of a call, build up an inst_var substitution (using the modified inst_matches_initial) and apply this to the final insts of the called procedure before checking/recomputing them. compiler/mode_util.m: Make sure that recompute_instmap_delta recomputes the instmap_deltas for lambda_goals even when RecomputeAtomic = no. compiler/type_util.m: Add a new predicate, type_util__cons_id_arg_types which nondeterministically returns the cons_ids and argument types for a given type. Add a new predicate type_util__get_consid_non_existential_arg_types which is the same as type_util__get_existential_arg_types except that it fails rather than aborting for existenially typed arguments. compiler/accumulator.m: compiler/check_typeclass.m: compiler/clause_to_proc.m: compiler/common.m: compiler/continuation_info.m: compiler/deforest.m: compiler/det_analysis.m: compiler/det_report.m: compiler/det_util.m: compiler/dnf.m: compiler/follow_code.m: compiler/goal_store.m: compiler/goal_util.m: compiler/higher_order.m: compiler/inst_util.m: compiler/instmap.m: compiler/lambda.m: compiler/magic.m: compiler/magic_util.m: compiler/mercury_to_mercury.m: compiler/modecheck_unify.m: compiler/module_qual.m: compiler/pd_info.m: compiler/pd_util.m: compiler/polymorphism.m: compiler/post_typecheck.m: compiler/prog_io_util.m: compiler/prog_rep.m: compiler/saved_vars.m: compiler/stack_layout.m: compiler/table_gen.m: compiler/unify_proc.m: compiler/unneeded_code.m: compiler/unused_args.m: Pass inst_varsets and types where needed. Changes to reflect change in definition of the inst data type. compiler/inlining.m: Recompute the instmap deltas for a procedure after inlining. This bug showed up compiling tests/hard_coded/lp.m with inlining and deforestation turned on: deforestation was getting incorrect instmap deltas from inlining, causing the transformation to break mode-correctness. It has only just shown up because of the added call to `inst_matches_initial' from within `recompute_instmap_delta'. tests/invalid/Mmakefile: tests/invalid/unbound_inst_var.m: tests/invalid/unbound_inst_var.err_exp: tests/valid/Mmakefile: tests/valid/unbound_inst_var.m: Move the `unbound_inst_var' test case from `invalid' to `valid' and extend its coverage a bit. |
||
|
|
da9dc64c8f |
Allow typeclass instance declarations to contain more than one clause
Estimated hours taken: 5 Allow typeclass instance declarations to contain more than one clause for each method. Also improve some error messages. compiler/check_typeclass.m: Allow typeclass instance declarations to contain more than one clause for each method, by combining the different clauses for each method into a single definition. Rewrite the code to check for bogus method names in instance declarations. This rewrite was necessitated by the change mentioned above, but also improved the quality of the error message (it now prints the name of the bogus method) and fixed some bugs that sometimes resulted in spurious flow-on error messages. Fix some problems where we were not passing the correct arity for functions (e.g. to make_introduced_pred_name). tests/invalid/Mmakefile: tests/invalid/typeclass_bogus_method.m: tests/invalid/typeclass_bogus_method.err_exp: Add a new regression test. tests/invalid/tc_err*.err_exp: tests/invalid/typeclass_test_*.err_exp: Update the expected output for these test cases, to reflect the improved error messages. doc/reference_manual.texi: Update the documentation to reflect this change. NEWS: Mention that we now allow clauses in instance declarations. |
||
|
|
4d0dff1860 |
Allow typeclass instance declarations to contain clauses, as an
Estimated hours taken: 10 Allow typeclass instance declarations to contain clauses, as an alternative to the current `pred(<MethodName>) is <ImplName>)' syntax. This avoids the need for the user to explicitly define names for procedures that just implement type class methods. XXX Note that currently we only permit one clause per method. compiler/prog_data.m: Change the second `sym_name' field of `instance_method' into a new type `instance_proc_def', which has two alternatives. The first, `name(sym_name)', is for the old syntax. The second, `clauses(list(item))', is for the new syntax. compiler/prog_io_typeclass.m: Parse the new syntax. compiler/make_hlds.m: Add new predicate `produce_instance_method_clauses', for use by check_typeclass.m. This handles the generation of HLDS clauses_infos for both the old and new syntax for instance method definitions. Return the qual_info produced by `parse_tree_to_hlds', so that it can be passed to `produce_instance_method_clauses'. compiler/mercury_compile.m: Pass the qual_info returned by make_hlds.m to check_typeclass.m. compiler/check_typeclass.m: Move the code which produces HLDS definitions for instance methods into `produce_instance_method_clauses' in make_hlds.m. Thread the io__state and qual_info throughout most of the code, since this they are needed to process the new syntax. (The io__state is needed so we can spit out warnings about singleton variables in clauses in type class methods, and the qual_info is needed to handle explicit type qualifiers in such clauses.) compiler/mercury_to_mercury.m: Output the new syntax. tests/hard_coded/typeclasses/Mmakefile: tests/hard_coded/typeclasses/instance_clauses.m: tests/hard_coded/typeclasses/instance_clauses.exp: A test case for the new feature. doc/reference_manual.texi: Document the new feature. |
||
|
|
a033b2e748 |
Fix a bug which caused intermod.m to abort when a type class
Estimated hours taken: 2 Fix a bug which caused intermod.m to abort when a type class contained a predicate or function with more than one mode. compiler/check_typeclass.m: Reorder the method declarations in each instance so that they match the order of the list of pred_proc_ids for the instance implementation. compiler/intermod.m: Remove duplicate pred_ids from the list of methods in an instance declaration when module qualifying the original instance declaration before writing it to the `.opt' file. Make sure that predicates referred to by an instance declaration in a `.opt' file are made exported. compiler/prog_data.m: Simplify the code by replacing the `pred_instance' and `func_instance' constructors of the `instance_method/0' type with a single constructor with a `pred_or_func' argument. compiler/mercury_to_mercury.m: compiler/check_typeclass.m: compiler/prog_io_typeclass.m: compiler/intermod.m: Handle the change to the `instance_method/0' type. tests/hard_coded/typeclasses/Mmakefile: tests/hard_coded/typeclasses/intermod_typeclass_bug.m: tests/hard_coded/typeclasses/intermod_typeclass_bug2.m: tests/hard_coded/typeclasses/intermod_typeclass_bug.exp: Test case. |
||
|
|
0dab66d926 |
Allow class methods to be impure or semipure.
Estimated hours taken: 6
Allow class methods to be impure or semipure. Previously any purity annotation
on a class method was ignored, and the method assumed to be pure. (We have
for some time caught the case of providing an impure implementation for
a (pure) class method, though).
compiler/prog_data.m:
Add purity to the information we store about each method.
compiler/prog_io_typeclass.m:
Record the declared purity of each method.
compiler/make_hlds.m:
For the predicate we generate corresponding to a method, add any
purity annotations that the method has.
compiler/check_typeclass.m:
Add the appropriate impurity marker to the predicate we generate for
each instance method.
compiler/purity.m:
Be careful not to spit out spurious purity warnings:
- Never warn about excessive impurity for a class methods.
(The body of the method is just class_method_call, which
never looks impure as far as it is concerned).
- Never warn about excessive impurity for class instance
method. The fact that a method is impure doesn't mean that
its instances need to be impure, and it would be excessive
to warn about it, seeing that there is no way for the user
to avoid it (other than actually making their implementation
impure...).
compiler/mercury_to_mercury.m:
Print out method purity in interface files.
compiler/module_qual.m:
compiler/equiv_type.m:
Handle the fact that we now store purity info for class methods.
tests/hard_coded/typeclasses/impure_methods.{m,exp}:
A test case for this change.
tests/hard_coded/typeclasses/Mmakefile:
Turn this change on.
tests/invalid/impure_methods.{m,err_exp}:
A test case for invalid use of impurity and class methods
tests/invalid/Mmakefile:
Turn this change on.
|
||
|
|
38dfae4f7c |
Implement handling of typeclasses for inter-module optimization.
Estimated hours taken: 15 Implement handling of typeclasses for inter-module optimization. compiler/hlds_data.m: compiler/*.m: Add fields to type hlds_class_defn for use by intermod.m - the import_status of the `:- typeclass' declaration. - the original class interface from the `:- typeclass' declaration. compiler/intermod.m: Write all local typeclasses, instances, types, insts and modes to the `.opt' file, instead of trying to work out which are needed. The old code to do this missed some types, insts and modes (test case tests/valid/intermod_test.m). compiler/polymorphism.m: Expand class method bodies for imported predicates so that method lookups for those classes can be optimized. compiler/hlds_pred.m: compiler/check_typeclass.m: compiler/higher_order.m: compiler/hlds_out.m: Add a marker `class_instance_method', used to identify predicates introduced by check_typeclass.m to call the methods for each instance. Don't export `check_typeclass__introduced_pred_name_prefix/0' - higher_order.m now checks for a `class_instance_method' marker instead. compiler/dead_proc_elim.m: Analyse all instance declarations, not just those defined in the current module, so that declarations for imported instance methods are not removed before method lookups have been specialized. tests/valid/Mmakefile: tests/valid/intermod_test.m: tests/valid/intermod_test2.m: Check that nested types and modes are written to the `.opt' file. tests/valid/intermod_typeclass.m: tests/valid/intermod_typeclass2.m: Check that local typeclass and instance declarations are written to the `.opt' file. |
||
|
|
5d37b1bae8 |
After creating the procs to go in the dictionary for an instance
Estimated hours taken: 3
compiler/check_typeclass.m:
After creating the procs to go in the dictionary for an instance
decl, check that:
- there is one proc per proc in the typeclass inteface
- we created on pred per entry in the instance
interface.
tests/invalid/Mmakefile:
Turn the typeclass_test_9 test on again. We now pass this test.
|
||
|
|
9b5d3cbb3d |
Fix a spurious error when there is a typeclass method with multiple modes.
Estimated hours taken: 1
Fix a spurious error when there is a typeclass method with multiple modes.
compiler/check_typeclass.m:
Compare the number of generated procedures with the number of methods in
the typeclass, not the instance declarations since the typeclass has
one per proc put the instance has one per pred.
tests/hard_coded/typeclasses/multi_moded.{m,exp}:
A test case for this.
tests/hard_coded/typeclasses/Mmakefile:
Turn this test case on.
|
||
|
|
d8cfbaf07a |
Fix the remaining bugs with the handling of partial qualifiers
Estimated hours taken: 10 Fix the remaining bugs with the handling of partial qualifiers for nested modules. compiler/module_qual.m: Define a new abstract type partial_qualifier_info, and a predicate mq_info_get_partial_qualifier_info to get this type from the mq_info. Define a new predicate get_partial_qualifiers/3 in module_qual.m which is like the old get_partial_qualifiers/2 predicate from modules.m except that it takes a partial_qualifier_info and uses the information in this to return only the partial qualifiers for modules which are visible, rather than returning all partial qualifier regardless of whether the modules that they refer to are in scope or not. compiler/prog_util.m: Export the `insert_module_qualifier' predicate, for use in the definition of get_partial_qualifiers/3. compiler/hlds_module.m: compiler/make_hlds.m: Change the code for make_hlds__ctors_add and hlds_module__pred_table_insert/5 so that they handles partial qualifiers properly, computing the partial qualifiers by calling get_partial_qualifiers/3 rather than by checking the NeedQual variable and calling get_partial_qualifiers/2. compiler/modules.m: Delete the old get_partial_qualifiers/2 predicate. compiler/hlds_module.m: Add a new field to the HLDS containing the partial_qualifier_info. Add a partial_qualifier_info parameter to pred_table_insert/5. compiler/check_typeclass.m: compiler/make_hlds.m: When calling pred_table_insert/5, get the partial_qualifier_info from the HLDS and pass it as an extra argument. tests/hard_coded/sub-modules/nested.m: tests/hard_coded/sub-modules/nested3.m: tests/hard_coded/sub-modules/parent.m: tests/hard_coded/sub-modules/nested.exp: tests/hard_coded/sub-modules/nested3.exp: tests/hard_coded/sub-modules/parent.exp: Uncomment parts of these test cases which were previously commented out because they were not yet supported. doc/reference_manual.texi: Delete the description of this bug. |
||
|
|
ec86c88404 |
Merge in the changes from the existential_types_2 branch.
Estimated hours taken: 4 Merge in the changes from the existential_types_2 branch. This change adds support for mode re-ordering of code involving existential types. The change required modifying the order of the compiler passes so that polymorphism comes before mode analysis, so that mode analysis can check the modes of the `type_info' or `typeclass_info' variables that polymorphism introduces, so that it can thus re-order the code accordingly. This change also includes some more steps towards making existential data types work. In particular, you should be able to declare existentially typed data types, the compiler will generate appropriate unification and compare/3 routines for them, and deconstruction unifications for them should work OK. However, currently there's no way to construct them except via `pragam c_code', and we don't generate correct RTTI for them, so you can't use `io__write' etc. on them. library/private_builtin.m: compiler/accumulator.m: compiler/bytecode_gen.m: compiler/check_typeclass.m: compiler/clause_to_proc.m: compiler/code_util.m: compiler/common.m: compiler/dead_proc_elim.m: compiler/dependency_graph.m: compiler/det_analysis.m: compiler/det_report.m: compiler/follow_code.m: compiler/follow_vars.m: compiler/goal_util.m: compiler/higher_order.m: compiler/hlds_goal.m: compiler/hlds_out.m: compiler/hlds_pred.m: compiler/intermod.m: compiler/lambda.m: compiler/live_vars.m: compiler/magic.m: compiler/make_hlds.m: compiler/mercury_compile.m: compiler/mercury_to_c.m: compiler/mode_errors.m: compiler/mode_info.m: compiler/mode_util.m: compiler/modecheck_call.m: compiler/modecheck_unify.m: compiler/modes.m: compiler/pd_cost.m: compiler/polymorphism.m: compiler/post_typecheck.m: compiler/purity.m: compiler/quantification.m: compiler/rl_exprn.m: compiler/rl_key.m: compiler/simplify.m: compiler/table_gen.m: compiler/term_traversal.m: compiler/type_util.m: compiler/typecheck.m: compiler/unify_gen.m: compiler/unify_proc.m: compiler/unique_modes.m: compiler/unused_args.m: compiler/notes/compiler_design.html: doc/reference_manual.texi: tests/hard_coded/typeclasses/Mmakefile: tests/hard_coded/typeclasses/existential_data_types.m: tests/hard_coded/typeclasses/existential_data_types.exp: tests/warnings/simple_code.exp: tests/hard_coded/Mmakefile: tests/term/arit_exp.trans_opt_exp: tests/term/associative.trans_opt_exp: tests/term/pl5_2_2.trans_opt_exp: tests/term/vangelder.trans_opt_exp: tests/term/arit_exp.trans_opt_exp: tests/term/associative.trans_opt_exp: tests/term/pl5_2_2.trans_opt_exp: tests/term/vangelder.trans_opt_exp: tests/invalid/errors2.err_exp2: tests/invalid/prog_io_erroneous.err_exp2: tests/invalid/type_inf_loop.err_exp2: tests/invalid/types.err_exp2: tests/invalid/polymorphic_unification.err_exp: tests/invalid/Mmakefile: tests/warnings/simple_code.exp: tests/debugger/queens.exp: tests/hard_coded/Mmakefile: tests/hard_coded/existential_reordering.m: tests/hard_coded/existential_reordering.exp: Merge in the changes from the existential_types_2 branch. |
||
|
|
c6812299c2 |
Remove support for --args simple. We don't use it, we won't use it even for
Estimated hours taken: 4.5 Remove support for --args simple. We don't use it, we won't use it even for experiments, and it is unnecessary complication. If anybody were using --args simple, this would need bootstrapping, but since nobody does, there is no need, and this can be committed as an ordinary change. compiler/options.m: doc/user_guide.texi: scripts/*.in: scripts/*.sh-subr: Remove the --args option. compiler/globals.m: Remove the args_method global and its access predicates. compiler/handle_options.m: Don't set the args_method global from the option. compiler/arg_info.m: Remove support for --args simple. This allows us to remove a now redundant argument from an exported predicate. compiler/mercury_compile.m: Remove the code for passing -DCOMPACT_ARGS to the C compiler. compiler/bytecode_gen.m: compiler/fact_table.m: compiler/follow_vars.m: compiler/live_vars.m: compiler/call_gen.m: Don't pass the unnecessary argument to arg_info. compiler/call_gen.m: compiler/unify_gen.m: Remove now unnecessary assertions. compiler/hlds_pred.m: Don't include an args_method in proc_infos; instead, include a slot that says whether the procedure's address is taken or not. (In most cases, this determined whether the args_method was simple or compact.) We will need this bool in the near future (when we generate layout structures for procedures whose address is taken). Modify the signatures of exported predicates to accommodate this change to the data structure. compiler/hlds_out.m: Print the new slot, not the args_method. compiler/lambda.m: When creating procedures from lambdas, set the address-taken slot to address_is_taken instead of setting up its args_method. compiler/make_hlds.m: Minor changes to conform to the changes in the signatures of the predicates exported from hlds_pred.m. compiler/check_typeclass.m: compiler/clause_to_proc.m: compiler/dnf.m: compiler/magic.m: compiler/magic_util.m: compiler/modecheck_call.m: compiler/pd_info.m: compiler/post_typecheck.m: compiler/unify_gen.m: Minor changes to conform to the changes in the signatures of the predicates exported from hlds_pred.m and make_hlds.m. runtime/mercury_type_info.h: Remove the conditional definition of the macros that provided an argument-method-independent way of referring to the registers holding the inputs and outputs of e.g. unification procedures. We don't need the independence anymore, and using registers instead of macros in the code ensures that maintainers are aware of register reuse issues (e.g. they copy an input from r1 before overwriting it with an output). runtime/mercury_conf_param.h: runtime/mercury_grade.h: Remove support for the args method component of the grade. runtime/mercury_ho_call.c: runtime/mercury_tabling.c: library/*.m: Conform to the changes in runtime/mercury_type_info.h by effectively applying the #defines appropriate to compact args by hand. Remove code and data structures only needed for simple args. Remove comments needed only in the presence of uncertainty about the args method. |
||
|
|
79dcbbef15 |
User-guided type specialization.
Estimated hours taken: 60 User-guided type specialization. compiler/prog_data.m: compiler/prog_io_pragma.m: compiler/modules.m: compiler/module_qual.m: compiler/mercury_to_mercury.m: Handle `:- pragma type_spec'. compiler/prog_io_pragma.m: Factor out some common code to parse predicate names with arguments. compiler/hlds_module.m: Added a field to the module_sub_info to hold information about user-requested type specializations, filled in by make_hlds.m and not used by anything after higher_order.m. compiler/make_hlds.m: For each `:- pragma type_spec' declaration, introduce a new predicate which just calls the predicate to be specialized with the specified argument types. This forces higher_order.m to produce the specialized versions. compiler/higher_order.m: Process the user-requested type specializations first to ensure that they get the correct names. Allow partial matches against user-specified versions, e.g. map__lookup(map(int, list(int)), int, list(int)) matches map__lookup(map(int, V), int, V). Perform specialization where a typeclass constraint matches a known instance, but the construction of the typeclass_info is done in the calling module. Give slightly more informative progress messages. compiler/dead_proc_elim.m: Remove specializations for dead procedures. compiler/prog_io_util.m: Change the definition of the `maybe1' and `maybe_functor' types to avoid the need for copying to convert between `maybe1' and `maybe1(generic)'. Changed the interface of `make_pred_name_with_context' to allow creation of predicate names for type specializations which describe the type substitution. compiler/make_hlds.m: compiler/prog_io_pragma.m: Make the specification of pragma declarations in error messages consistent. (There are probably some more to be fixed elsewhere for termination and tabling). compiler/intermod.m: Write type specialization pragmas for predicates declared in `.opt' files. compiler/mercury_to_mercury.m: Export `mercury_output_item' for use by intermod.m. compiler/options.m: Add an option `--user-guided-type-specialization' enabled with `-O2' or higher. compiler/handle_options.m: `--type-specialization' implies `--user-guided-type-specialization'. compiler/hlds_goal.m: Add predicates to construct constants. These are duplicated in several other places, I'll fix that as a separate change. compiler/type_util.m: Added functions `int_type/0', `string_type/0', `float_type/0' and `char_type/0' which return the builtin types. These are duplicated in several other places, I'll fix that as a separate change. library/private_builtin.m: Added `instance_constraint_from_typeclass_info/3' to extract the typeclass_infos for a constraint on an instance declaration. This is useful for specializing class method calls. Added `thread_safe' to various `:- pragma c_code's. Added `:- pragma inline' declarations for `builtin_compare_*', which are important for user-guided type specialization. (`builtin_unify_*' are simple enough to go in the `.opt' files automatically). compiler/polymorphism.m: `instance_constraint_from_typeclass_info/3' does not need type_infos. Add `instance_constraint_from_typeclass_info/3' to the list of `typeclass_info_manipulator's which higher_order.m can interpret. NEWS: doc/reference_manual.texi: doc/user_guide.texi Document the new pragma and option. tests/invalid/Mmakefile: tests/invalid/type_spec.m: tests/invalid/type_spec.err_exp: Test error reporting for invalid type specializations. tests/hard_coded/Mmakefile: tests/invalid/type_spec.m: tests/invalid/type_spec.exp: Test type specialization. |
||
|
|
1f535128ae |
Fix a bug with the handling of instance declarations with no methods.
Estimated hours taken: 0.5 Fix a bug with the handling of instance declarations with no methods. compiler/check_typeclass.m: Ensure that the MaybePredProcs field of the HLDS instance definition for instance definitions with no methods is set to `yes([])' rather than `no' -- the latter would indicate that this pass hasn't been run yet. |
||
|
|
59fda6bfdf |
Implement abstract instance declarations.
Estimated hours taken: 9 Implement abstract instance declarations. compiler/prog_data.m: Rename the `instance_interface' type as `instance_body', and make it a discriminated union: either `abstract', or `concrete(Methods)'. compiler/prog_io_typeclass.m: compiler/hlds_data.m: compiler/hlds_out.m: compiler/equiv_type.m: compiler/check_typeclass.m: Change the code to reflect the new name and representation of `instance_interface'. compiler/prog_io_typeclass.m: Parse abstract instance declarations. compiler/make_hlds.m: Clean up the code a bit, and make sure that it detects some errors which previously we didn't detect: duplicate or overlapping instance declarations, and instance declarations with methods for classes with no methods. compiler/check_typeclass.m: If an instance is abstract, then we don't need to check that the methods in the instance body match those in the class. compiler/base_typeclass_info.m: Only generate base_typeclass_infos for concrete instance declarations, not for abstract ones. doc/reference_manual.texi: Document the change. tests/hard_coded/typeclasses/Mmakefile: tests/hard_coded/typeclasses/abstract_instance.m: tests/hard_coded/typeclasses/use_abstract_instance.m: tests/hard_coded/typeclasses/use_abstract_instance.exp: tests/invalid/Mmakefile: tests/invalid/typeclass_test_9.m: tests/invalid/typeclass_test_9.err_exp: Some test cases. tests/hard_coded/typeclasses/Mmakefile: Uncomment typeclass_test_5.m, since we pass that now (and have done so for quite some time). tests/invalid/typeclass_test_[3-5].err_exp: Update to reflect additional error messages produced by the improved error checking in compiler/make_hlds.m. |
||
|
|
18430aaef1 |
Aditi compilation.
Estimated hours taken: 1200
Aditi compilation.
compiler/options.m:
The documentation for these is commented out because the Aditi
system is not currently useful to the general public.
--aditi: enable Aditi compilation.
--dump-rl: write the intermediate RL to `<module>.rl_dump'.
--dump-rl-bytecode: write a text version of the bytecodes
to `<module>.rla'
--aditi-only: don't produce a `.c' file.
--filenames-from-stdin: accept a list of filenames to compile
from stdin. This is used by the query shell.
--optimize-rl, --optimize-rl-cse, --optimize-rl-invariants,
--optimize-rl-index, --detect-rl-streams:
Options to control RL optimization passes.
--aditi-user:
Default owner of any Aditi procedures,
defaults to $USER or "guest".
--generate-schemas:
write schemas for base relations to `<module>'.base_schema
and schemas for derived relations to `<module>'.derived_schema.
This is used by the query shell.
compiler/handle_options.m:
Handle the default for --aditi-user.
compiler/hlds_pred.m:
compiler/prog_data.m:
compiler/prog_io_pragma.m:
compiler/make_hlds.m:
Add some Aditi pragma declarations - `aditi', `supp_magic', `context',
`naive', `psn' (predicate semi-naive), `aditi_memo', `aditi_no_memo',
`base_relation', `owner' and `index'.
Separate out code to parse a predicate name and arity.
compiler/hlds_pred.m:
Add predicates to identify Aditi procedures.
Added markers `generate_inline' and `aditi_interface', which
are used internally for Aditi code generation.
Add an `owner' field to pred_infos, which is used for database
security checks.
Add a field to pred_infos to hold the list of indexes for a base
relation.
compiler/make_hlds.m:
Some pragmas must be exported if the corresponding predicates
are exported, check this.
Make sure stratification of Aditi procedures is checked.
Predicates with a mode declaration but no type declaration
are no longer assumed to be local.
Set the `do_aditi_compilation' field of the module_info if there
are any local Aditi procedures or base relations.
Check that `--aditi' is set if Aditi compilation is required.
compiler/post_typecheck.m:
Check that every Aditi predicate has an `aditi__state' argument,
which is used to ensure sequencing of updates and that Aditi
procedures are only called within transactions.
compiler/dnf.m:
Changed the definition of disjunctive normal form slightly
so that a call followed by some atomic goals not including
any database calls is considered atomic. magic.m can handle
this kind of goal, and it results in more efficient RL code.
compiler/hlds_module.m:
compiler/dependency_graph.m:
Added dependency_graph__get_scc_entry_points which finds
the procedures in an SCC which could be called from outside.
Added a new field to the dependency_info, the
aditi_dependency_ordering. This contains all Aditi SCCs of
the original program, with multiple SCCs merged where
possible to improve the effectiveness of differential evaluation
and the low level RL optimizations.
compiler/hlds_module.m:
Add a field to record whether there are any local Aditi procedures
in the current module.
Added versions of module_info_pred_proc_info and
module_info_set_pred_proc_info which take a pred_proc_id,
not a separate pred_id and proc_id.
compiler/polymorphism.m:
compiler/lambda.m:
Make sure that predicates created for closures in Aditi procedures
have the correct markers.
compiler/goal_util.m:
Added goal_util__switch_to_disjunction,
goal_util__case_to_disjunct (factored out from simplify.m)
and goal_util__if_then_else_to_disjunction. These are
require because supplementary magic sets can't handle
if-then-elses or switches.
compiler/type_util.m:
Added type_is_aditi_state/1.
compiler/mode_util.m:
Added partition_args/5 which partitions a list of arguments
into inputs and others.
compiler/inlining.m:
Don't inline memoed procedures.
Don't inline Aditi procedures into non-Aditi procedures.
compiler/intermod.m:
Handle Aditi markers.
Clean up handling of markers which should not appear in `.opt' files.
compiler/simplify.m:
Export a slightly different interface for use by magic.m.
Remove explicit quantifications where possible.
Merge multiple nested quantifications.
Don't report infinite recursion warnings for Aditi procedures.
compiler/prog_out.m:
Generalised the code to output a module list to write any list.
compiler/code_gen.m:
compiler/arg_info.m:
Don't process Aditi procedures.
compiler/mercury_compile.m:
Call magic.m and rl_gen.m.
Don't perform the low-level annotation passes on Aditi procedures.
Remove calls to constraint.m - sometime soon a rewritten version
will be called directly from deforestation.
compiler/passes_aux.m:
Add predicates to process only non-Aditi procedures.
compiler/llds.m:
compiler/llds_out.m:
Added new `code_addr' enum members, do_{det,semidet,nondet}_aditi_call,
which are defined in extras/aditi/aditi.m.
compiler/call_gen.m:
Handle generation of do_*_aditi_call.
compiler/llds_out.m:
Write the RL code for the module as a constant char array
in the `.c' file.
compiler/term_errors.m:
compiler/error_util.m:
Move code to describe predicates into error_util.m
Allow the caller to explicitly add line breaks.
Added error_util:list_to_pieces to format a list of
strings.
Reordered some arguments for currying.
compiler/hlds_out.m:
Don't try to print clauses if there are none.
runtime/mercury_init.h:
util/mkinit.c:
scripts/c2init.in:
Added a function `mercury__load_aditi_rl_code()' to the generated
`<module>_init.c' file which throws all the RL code for the program
at the database. This should be called at connection time by
`aditi__connect'.
Added an option `--aditi' which controls the output
`mercury__load_aditi_rl_code()'.
compiler/notes/compiler_design.html:
Document the new files.
Mmakefile:
bindist/Mmakefile:
Don't distribute extras/aditi yet.
New files:
compiler/magic.m:
compiler/magic_util.m:
Supplementary magic sets transformation. Report errors
for constructs that Aditi can't handle.
compiler/context.m:
Supplementary context transformation.
compiler/rl_gen.m:
compiler/rl_relops.m:
Aditi code generation.
compiler/rl_info.m:
Code generator state.
compiler/rl.m:
Intermediate RL representation.
compiler/rl_util:
Predicates to collect information about RL instructions.
compiler/rl_dump.m:
Print out the representation in rl.m.
compiler/rl_opt.m:
Control low-level RL optimizations.
compiler/rl_block.m:
Break a procedure into basic blocks.
compiler/rl_analyse.m:
Generic dataflow analysis for RL procedures.
compiler/rl_liveness.m:
Make sure all relations are initialised before used, clear
references to relations that are no longer required.
compiler/rl_loop.m:
Loop invariant removal.
compiler/rl_block_opt.m:
CSE and instruction merging on basic blocks.
compiler/rl_key.m:
Detect upper/lower bounds for which a goal could succeed.
compiler/rl_sort.m:
Use indexing for joins and projections.
Optimize away unnecessary sorting and indexing.
compiler/rl_stream.m:
Detect relations which don't need to be materialised.
compiler/rl_code.m:
RL bytecode definitions. Automatically generated from the Aditi
header files.
compiler/rl_out.m:
compiler/rl_file.m:
Output the RL bytecodes in binary to <module>.rlo (for use by Aditi)
and in text to <module>.rla (for use by the RL interpreter).
Also output the schema information if --generate-schemas is set.
compiler/rl_exprn.m:
Generate bytecodes for join conditions.
extras/aditi/Mmakefile:
extras/aditi/aditi.m:
Definitions of some Aditi library predicates and the
interfacing and transaction processing code.
|
||
|
|
67baf3fd60 |
Add an indication of whether or not the type class method for which
Estimated hours taken: 1
compiler/check_typeclass.m:
Add an indication of whether or not the type class method for which
we are reporting an error is a predicate or a function.
tests/invalid/typeclass_test_3.err_exp:
tests/invalid/typeclass_test_4.err_exp:
tests/invalid/typeclass_test_5.err_exp:
Updated to reflect the new error message format.
|
||
|
|
5c955626f2 |
These changes make var' and term' polymorphic.
Estimated hours taken: 20 These changes make `var' and `term' polymorphic. This allows us to make variables and terms representing types of a different type to those representing program terms and those representing insts. These changes do not *fix* any existing problems (for instance there was a messy conflation of program variables and inst variables, and where necessary I've just called varset__init(InstVarSet) with an XXX comment). NEWS: Mention the changes to the standard library. library/term.m: Make term, var and var_supply polymorphic. Add new predicates: term__generic_term/1 term__coerce/2 term__coerce_var/2 term__coerce_var_supply/2 library/varset.m: Make varset polymorphic. Add the new predicate: varset__coerce/2 compiler/prog_data.m: Introduce type equivalences for the different kinds of vars, terms, and varsets that we use (tvar and tvarset were already there but have been changed to use the polymorphic var and term). Also change the various kinds of items to use the appropriate kinds of var/varset. compiler/*.m: Thousands of boring changes to make the compiler type correct with the different types for type, program and inst vars and varsets. |
||
|
|
a30437fd21 |
Minor improvements to some compiler error messages.
Estimated hours taken: 1 Minor improvements to some compiler error messages. compiler/modules.m: Fix a missing close-quote in an error message. Also improve the wording of the message slightly. compiler/check_typeclass.m: compiler/typecheck.m: Add quotes (`...') in a couple of places tests/invalid/sub*.err_exp: tests/invalid/typeclass_test*.err_exp: Update to reflect the new error messages. tests/invalid/Mmakefile: Delete an obsolete comment about a poor error message. |
||
|
|
ab5d46e271 |
Improve the error messages generated by check_typeclass.m.
Estimated hours taken: 10
Improve the error messages generated by check_typeclass.m.
check_typeclass.m:
Write decent error messages, including term__contexts for the
appropriate lines, for the errors detected by this module. These errors
are missing or multiple definitions of instance methods and unsatisfied
superclass constraints on instance decls.
mercury_to_mercury.m:
Add predicates which convert class_constraints and types into strings.
This is needed so that an error message can be created as a string,
then formatted to fit the line, rather than writing out the error
message as you go.
hlds_data.m:
Add a term__context to the hlds_instance_defn.
base_typeclass_info.m:
dead_proc_elim.m:
higher_order.m:
hlds_out.m:
polymorphism.m:
typecheck.m:
Ignore the term__context field of the hlds_instance_defn.
make_hlds.m:
Insert the term__context field into the hlds_instance_defn when it
is created.
|
||
|
|
bbeeabf50e |
Make the mangled name we choose for introduced instance method preds
Estimated hours taken: 1
compiler/check_typeclas.m:
Make the mangled name we choose for introduced instance method preds
a little nicer: remove all spaces and colons, replacing them with
underscores. This makes the names that end up in the C code much nicer
since they don't need to use character codes.
compiler/hlds_out.m:
Check for the new form of mangled name.
|
||
|
|
4556cccae8 |
Remember the term__context of where we read an instance method from so that
Estimated hours taken: 2
Remember the term__context of where we read an instance method from so that
we can give more accurate error messages. Also (slightly) improve the text of
the error message for instance methods.
check_typeclass.m:
Use the term__context of the instance method declaration as the
term__context for the introduced pred.
hlds_out.m:
If the pred is one introduced as an instance method, give a
(slightly) better error message.
mercury_to_mercury.m:
Ignore the term context.
module_qual.m:
Pass along the term context.
prog_data.m:
Add a term__context to the instance_method
prog_io_typeclass.m:
Store the term__context in the instance_method
|
||
|
|
227f5b981d |
Fix a bug: when generating the goal for the introduced predicate
Estimated hours taken: 1 compiler/check_typeclass.m: Fix a bug: when generating the goal for the introduced predicate (function) for each function method in an instance declarations, it was not setting the goal_info correctly. |
||
|
|
6455e041cb |
Merge in the changes from the existential types branch,
Estimated hours taken: 6
(plus another 80 or so already recorded for
my commits on the existential_types branch)
Merge in the changes from the existential types branch,
and make some modifications to address dgj's code review comments.
These changes add support for existentially quantified type variables
and type class constraints on functions and predicates.
(Existential data types, however, are not supported -- see below.)
Existentially quantified type variables are introduced with
an explicit `some [T]', e.g. `:- some [T] pred foo(T)'.
Existentially quantified type class constraints are introduced
with `&' instead of `<=', e.g. `:- some [T] (pred foo(T) & ord(T))'.
There's still several limitations:
0. XXX It's not yet documented in the language reference manual.
1. XXX It doesn't do any mode checking or mode reordering.
If you write code that uses existentially typed procedures in the
wrong order, then you'll get an internal error in polymorphism.m
or in the code generator. (Cases where a type_info has no
producer at all are caught by the check for unbound type
variables in post_typecheck.m.)
To support this, we need to change things so that polymorphism.m
gets invoked before mode checking.
2. Using `in' modes on arguments of existential type won't work.
If you try, you will get a compile error.
It would be nice to extend things to allow this kind of
"implied mode" for type_infos, where an existential type
becomes a universal type if some value of that type is
input. Supporting this would require first fixing
limitation 1 (described above) and then
3. There's no support for `pragma c_code' for procedures
with existential type class constraints.
(In fact, there's not really any support for `pragma c_code'
for procedures with universal type class constraints either --
the C code has no way of getting access to the type class info.)
4. XXX Taking the address of something which is existentially typed
should be illegal, but we don't check this.
In addition, these changes in this batch make a start towards allowing
existentially typed data types. The compiler now accepts existential
quantifiers and type class constraints on type definitions, and type
checks them accordingly (assuming all functor occurrences are
deconstructors, not constructors -- see limitation 2 above). But
there's no special handling for them in polymorphism.m, so if you try
to use them, it will abort with an internal error.
The changes also includes fixes for a couple of bugs in typechecking
and polymorphism that I discovered while making the above changes,
and an improvement to the error reporting from typecheck.m in one case.
Those changes are listed separately below.
compiler/prog_data.m:
Add a new type `class_constraints', which holds two different
lists of constraints, namely the existentially quantified constraints
and the universally quantified ones.
Add a new field to the parse tree representation of pred and
func declarations to hold a list of the existentially quantified
type variables, and change the `list(class_constraint)' into
`class_constraints' so that we can store existential constraints too.
Add new fields to the `constructor' data type (formerly just a pair)
to hold the existentially quantified type variables and
type class constraints.
compiler/hlds_pred.m:
Add several new fields to the pred_info:
- a list of the existentially quantified type variables;
- a list of the "HeadTypeParams": type variables which
cannot be bound by this predicate (i.e. those whose type_infos
come from this pred's caller or are returned from
other preds called by this one);
- and a list of unsatisfied type class constraints.
Add a predicate pred_info_get_univ_quant_tvars to compute the
universally quantified type variables.
Change the pred constraints field from `list(class_constraint)'
to `class_constraints' so that it can hold existential constraints too.
compiler/hlds_data.m:
Add new fields to hlds_cons_defn to hold the existentially
quantified type variables and type class constraints.
compiler/*.m:
Minor changes to reflect the above-mentioned data structure
changes in prog_data.m, hlds_pred.m, and hlds_data.m.
compiler/prog_io.m:
Add code to parse the new constructs.
Also rewrite the code for parsing purity specifiers,
type quantifiers and type class constraints, using basically
the method suggested by Peter Schachte: treat these as
"declaration attributes", and have parse_decl strip off
all the declaration attributes into a seperate list and
then pass that list to process_decl, which for each different
kind of declaration processes the attributes which are
appropriate for that declaration and then calls check_no_attributes
to ensure that there were no inappropriate attributes.
The purpose of this rewrite was to allow it to handle the new
constructs properly, and to avoid unnecessary code duplication.
compiler/mercury_to_mercury.m:
Add code to pretty-print the new constructs.
compiler/make_hlds.m:
Copy the new fields in the parse tree into the
corresponding new fields in the pred_info.
Add code to check for various misuses of quantifiers.
compiler/hlds_out.m:
Print out the new fields in the pred_info (except the
unsatisfied type class constraints -- if these are non-empty,
post_typecheck.m will print them out in the error message).
When printing out types, pass the AppendVarNums parameter down,
so that HLDS dumps will distinguish between different type
variables that have the same name.
Delete hlds_out__write_constructor, since it was doing exactly
the same thing as mercury__output_ctor.
compiler/typecheck.m:
Lots of changes to handle existential types and existential
type class constraints.
compiler/post_typecheck.m:
When checking for unbound type variables,
use the value of HeadTypeParams from the pred_info.
compiler/type_util.m:
Delete `type_and_constraint_list_matches_exactly', since it was not
used. Add various `apply_variable_renaming_to_*' predicates for
renaming constraints.
compiler/polymorphism.m:
Lots of changes to handle existential types and existential
type class constraints.
Also some changes to make the code more maintainable:
compiler/prog_data.m:
compiler/hlds_goal.m:
compiler/mercury_to_mercury.m:
Put curly braces around the definitions of 'some'/2 and '&'/2 functors
in `:- type' definitions, to avoid them being misinterpreted as
existential type constraints.
compiler/goal_util.m:
compiler/polymorphism.m:
compiler/hlds_pred.m:
compiler/lambda.m:
Include type_infos for existentially quantified type variables
and type_class_infos for existential constraints
in the set of extra variables computed by
goal_util__extra_type_info_vars.
compiler/inlining.m:
Change inlining__do_goal to handle inlining of calls to
existentially typed predicates -- for them, instead of not
binding any type variables at all in the caller, it allows the
call to bind any type variables in the caller except for those
that are universally quantified.
compiler/inlining.m:
compiler/deforest.m:
Call pred_info_get_univ_quant_tvars and pass the
result to inlining__do_inline_goal.
tests/hard_coded/Mmakefile:
tests/hard_coded/existential_types_test.{m,exp}:
tests/hard_coded/typeclasses/Mmakefile:
tests/hard_coded/typeclasses/existential_type_classes.{m,exp}:
Test cases for the use of existential types and
existential type class constraints.
----------
Improve an error message.
compiler/typecheck.m:
Improve error reporting by checking type class constraints for
satisfiability as we go and thus reporting unsatisfiable constraints
as soon as possible, rather than only at the end of the clause.
Previously we already did that for the case of ground constraints,
but they are not the only unsatsfiable constraints: constraints
on head type params (type variables which cannot be bound) are
also unsatisfiable if they can't be eliminated straight away
by context reduction.
tests/invalid/Mmakefile:
tests/invalid/typeclass_test_7.{m,err_exp}:
Regression test for the above change.
----------
Avoid problems where type inference was reporting some
spurious errors for predicates using type classes,
because the check for unsatisfied type class constraints
was being done before the final pass of type inference
had finished.
compiler/hlds_pred.m:
Add new field to the pred_info containing the unproven
type class constraints.
compiler/typecheck.m:
When inferring type class constraints, make sure that before
we save the results back in the pred_info, we restrict the
constraints to the head type variables. Constraints
on other type variables should be treated as
unsatisfied constraints.
Don't check for unsatisfied type class constraints at the
end of each pass; instead, just save the unproven type class
constraints in the pred_info.
compiler/post_typecheck.m:
Check for unsatisfied type class constraints, using
the new field in the pred_info.
tests/hard_coded/typeclasses/Mmakefile:
tests/hard_coded/typeclasses/inference_test_2.{m,exp}:
tests/invalid/Mmakefile:
tests/invalid/typeclass_test_8.{m,err_exp}:
Add regression tests for this change.
----------
Fix a bug with the computation of the non-locals for
predicates with more than one constraint on the same type variable --
it was only including one of the type-class-infos, rather than all of them.
compiler/goal_util.m:
Change `goal_util__extra_nonlocal_typeinfos' so that it gets
passed the TypeClassInfoVarMap and uses this to include all
the appropriate typeclass infos in the extra nonlocals.
compiler/hlds_pred.m:
compiler/lambda.m:
compiler/polymorphism.m:
Pass the TypeClassInfoVarMap to `goal_util__extra_nonlocal_typeinfos'.
tests/hard_coded/typeclasses/Mmakefile:
tests/hard_coded/typeclasses/lambda_multi_constraint_same_tvar.{m,exp}:
Regression test for the above-mentioned bug.
|
||
|
|
fd691889bf |
Get rid of unnecessary type variables when creating the auxiliary predicate
Estimated hours taken: 3
Get rid of unnecessary type variables when creating the auxiliary predicate
for an instance method. This will hopefully be a little more robust than
the current approach since typecheck.m is now able to get rid of any unused
tvars... they *must* have been introduced by type inference.
library/varset.m:
Add a predicate varset__squash which gets rid of unused variables.
compiler/check_typeclass.m:
Call varset__squash to get rid of the unnecessary tvars.
compiler/typecheck.m:
Call varset__squash to get rid of the unnecessary tvars, rather than
doing it "manually".
compiler/type_util.m:
Add a new pred apply_variable_renaming_to_constraint.
|
||
|
|
1b0472461c |
Disable the often erroneous "optimisation" in check_typeclass.m whereby we
Estimated hours taken: 3
Disable the often erroneous "optimisation" in check_typeclass.m whereby we
skipped the level of indirection for instance methods if there was an exact
match for the types, modes and determinisms of the instance method.
Consequently rip out lots of useless stuff from check_typeclass.m.
Also, for methods which are functions, introduce unifications for the body
rather than calls.
Also improve a couple of error messages slightly.
compiler/check_typeclass.m:
Disable the "optimisation".
|
||
|
|
d206d5a3e7 |
Fix a bug where variable names were getting mixed up for certain introduced
Estimated hours taken: 15 Fix a bug where variable names were getting mixed up for certain introduced instance method predicates. compiler/check_typeclass.m: Calculate the variables names correctly (ie. get the renaming right). compiler/typecheck.m: Make typecheck_info_get_final_info also rename the declared constraints for the predicate. After getting the final info, store the new versions of the arg types and the renamed constraints, regardless of whether we are doing type inference or not. Although the intention was originally that the var numbers would only be changed in typecheck_info_get_final_info when doing inference (since that is the only time that redundant type vars would be present), this is no longer the case. Preds introduced in typecheck.m can also have redundant type vars in the varset at the time of creation since they have the *class declarations's* tvarset. This meant that typecheck_info_get_final_info was getting rid of some variables, then updating the proofs, but not updating the constraints, arg types etc. |
||
|
|
24db091286 |
Fix a variable renaming bug in the recently introduced changes to
Estimated hours taken: 4
Fix a variable renaming bug in the recently introduced changes to
check_typeclass.m.
compiler/check_typeclass.m:
When adding constraints from the instance declaration to the
generated predicate, rename them apart from the vars of the
class declaration.
This is only a concern where a class method uses type variables
that are not parameters of the class, so was missed by the test
cases.
Test case coming soon (as soon as I can cut it down a bit).
|
||
|
|
c273ecdbcc |
A re-work of check_typeclass.m. Now, rather than the ad-hoc approach of
Estimated hours taken: 25 A re-work of check_typeclass.m. Now, rather than the ad-hoc approach of checking each method of each instance declaration for *exact* type and mode correctness, we generate a new predicate that gets inserted into the HLDS. This predicate is checked for type, mode, uniqueness and determinism correctness in the appropriate compiler pass. As a consequence, the check_typeclass pass now has to come before typecheck.m. Previously, it was the final semantic analysis pass because it had to use type, mode, uniqueness and determinism information. The new approach does not need that information to be available. This has the following user-visible improvements: - constraints on class methods are now checked properly. An instance's implementation of a method may be less constrained. (Previously, these constraints weren't even checked at all. Oops). - a method implementation may be more polymorphic than expected - implied modes will be used for methods if necessary This is a much more robust approach (and it co-incides with the typeclass paper ;-) ). compiler/check_typeclass.m: Introduce the auxiliary predicate for the instance method. As an optimisation, do not introduce the predicate if the implementation given is an *exact* match (in terms of types, modes and determinism). compiler/mercury_compile.m: Put the check_typeclass pass before typechecking. compiler/type_util.m: Change type_list_matches_exactly to type_and_constraint_list_matches_exactly since check_typeclass is also responsible for checking constraints on method implementations. (This is only used in the optimisation mentioned above). |
||
|
|
128b630a9a |
Re-implement the part of context reduction which seeks to eliminate a
Estimated hours taken: 15
Re-implement the part of context reduction which seeks to eliminate a
typeclass constraint by using the fact that one class is a superclass of
another. This achieves two things:
- Fixes a bug, in that the new algorithm (correctly) searches the whole
superclass relation to find a path from one constraint to
another.
- It makes the algorithm the same as what we put in the type class
paper. :-)
compiler/check_typeclass.m:
Pass the super class table to the context reduction predicate
compiler/hlds_data.m:
Declare the types which (explicitly) hold the superclass information
compiler/hlds_module.m:
Store the superclass information explicitly in the module_info, rather
than just implicitly in the class_table
compiler/make_hlds.m:
Explicitly construct the superclass information as classes are added.
This saves re-computing it for each constraint in typecheck.m
compiler/typecheck.m:
Use the explicit superclass information for context reduction, rather
than just the class table.
When reducing the context using superclasses, recursively search the
whole superclass relation until a match is found.
|
||
|
|
5e86fb5715 |
Fix some bugs in the handling of "non-simple" type class constraints
Estimated hours taken: 12 Fix some bugs in the handling of "non-simple" type class constraints (ones for which the types being constrained are not just type variables). compiler/prog_io_typeclass.m: Ensure that constraints on type class declarations must be "simple". This is needed the ensure termination of type checking. (We already did this for instance declarations, but not for superclass constraints on type class declarations.) compiler/prog_data.m: Document the invariant that the types in a type class constraint must not contain any information in their term__context fields. compiler/type_util.m: compiler/equiv_type.m: compiler/polymorphism.m: compiler/prog_io_typeclass.m: Enforce the above-mentioned invariant. compiler/typecheck.m: Allow the declared constraints to be a superset of the inferred constraints. When performing context reduction, eliminate declared constraints at each step rather than only at the end. Remove declared constraints and apply superclass rules before applying instance rules. When applying instance rules, make sure that it is a type error if there is no matching instance rule for a ground constraint. If context reduction results in an error, restore the original type assign set, to avoid repeating the same error message at every subsequent call to perform_context_reduction. compiler/check_typeclass.m: Change the way we superclass conformance for instance declarations to take advantage of the new "DeclaredConstraints" argument to typecheck__reduce_context_by_rule_application. |
||
|
|
11d8161692 |
Add support for nested modules.
Estimated hours taken: 50
Add support for nested modules.
- module names may themselves be module-qualified
- modules may contain `:- include_module' declarations
which name sub-modules
- a sub-module has access to all the declarations in the
parent module (including its implementation section).
This support is not yet complete; see the BUGS and LIMITATIONS below.
LIMITATIONS
- source file names must match module names
(just as they did previously)
- mmc doesn't allow path names on the command line any more
(e.g. `mmc --make-int ../library/foo.m').
- import_module declarations must use the fully-qualified module name
- module qualifiers must use the fully-qualified module name
- no support for root-qualified module names
(e.g. `:parent:child' instead of `parent:child').
- modules may not be physically nested (only logical nesting, via
`include_module').
BUGS
- doesn't check that the parent module is imported/used before allowing
import/use of its sub-modules.
- doesn't check that there is an include_module declaration in the
parent for each module claiming to be a child of that parent
- privacy of private modules is not enforced
-------------------
NEWS:
Mention that we support nested modules.
library/ops.m:
library/nc_builtin.nl:
library/sp_builtin.nl:
compiler/mercury_to_mercury.m:
Add `include_module' as a new prefix operator.
Change the associativity of `:' from xfy to yfx
(since this made parsing module qualifiers slightly easier).
compiler/prog_data.m:
Add new `include_module' declaration.
Change the `module_name' and `module_specifier' types
from strings to sym_names, so that module names can
themselves be module qualified.
compiler/modules.m:
Add predicates module_name_to_file_name/2 and
file_name_to_module_name/2.
Lots of changes to handle parent module dependencies,
to create parent interface (`.int0') files, to read them in,
to output correct dependencies information for them to the
`.d' and `.dep' files, etc.
Rewrite a lot of the code to improve the readability
(add comments, use subroutines, better variable names).
Also fix a couple of bugs:
- generate_dependencies was using the transitive implementation
dependencies rather than the transitive interface dependencies
to compute the `.int3' dependencies when writing `.d' files
(this bug was introduced during crs's changes to support
`.trans_opt' files)
- when creating the `.int' file, it was reading in the
interfaces for modules imported in the implementation section,
not just those in the interface section.
This meant that the compiler missed a lot of errors.
library/graph.m:
library/lexer.m:
library/term.m:
library/term_io.m:
library/varset.m:
compiler/*.m:
Add `:- import_module' declarations to the interface needed
by declarations in the interface. (The previous version
of the compiler did not detect these missing interface imports,
due to the above-mentioned bug in modules.m.)
compiler/mercury_compile.m:
compiler/intermod.m:
Change mercury_compile__maybe_grab_optfiles and
intermod__grab_optfiles so that they grab the opt files for
parent modules as well as the ones for imported modules.
compiler/mercury_compile.m:
Minor changes to handle parent module dependencies.
(Also improve the wording of the warning about trans-opt
dependencies.)
compiler/make_hlds.m:
compiler/module_qual.m:
Ignore `:- include_module' declarations.
compiler/module_qual.m:
A couple of small changes to handle nested module names.
compiler/prog_out.m:
compiler/prog_util.m:
Add new predicates string_to_sym_name/3 (prog_util.m) and
sym_name_to_string/{2,3} (prog_out.m).
compiler/*.m:
Replace many occurrences of `string' with `module_name'.
Change code that prints out module names or converts
them to strings or filenames to handle the fact that
module names are now sym_names intead of strings.
Also change a few places (e.g. in intermod.m, hlds_module.m)
where the code assumed that any qualified symbol was
fully-qualified.
compiler/prog_io.m:
compiler/prog_io_goal.m:
Move sym_name_and_args/3, parse_qualified_term/4 and
parse_qualified_term/5 preds from prog_io_goal.m to prog_io.m,
since they are very similar to the parse_symbol_name/2 predicate
already in prog_io.m. Rewrite these predicates, both
to improve maintainability, and to handle the newly
allowed syntax (module-qualified module names).
Rename parse_qualified_term/5 as `parse_implicit_qualified_term'.
compiler/prog_io.m:
Rewrite the handling of `:- module' and `:- end_module'
declarations, so that it can handle nested modules.
Add code to parse `include_module' declarations.
compiler/prog_util.m:
compiler/*.m:
Add new predicates mercury_public_builtin_module/1 and
mercury_private_builtin_module/1 in prog_util.m.
Change most of the hard-coded occurrences of "mercury_builtin"
to call mercury_private_builtin_module/1 or
mercury_public_builtin_module/1 or both.
compiler/llds_out.m:
Add llds_out__sym_name_mangle/2, for mangling module names.
compiler/special_pred.m:
compiler/mode_util.m:
compiler/clause_to_proc.m:
compiler/prog_io_goal.m:
compiler/lambda.m:
compiler/polymorphism.m:
Move the predicates in_mode/1, out_mode/1, and uo_mode/1
from special_pred.m to mode_util.m, and change various
hard-coded definitions to instead call these predicates.
compiler/polymorphism.m:
Ensure that the type names `type_info' and `typeclass_info' are
module-qualified in the generated code. This avoids a problem
where the code generated by polymorphism.m was not considered
type-correct, due to the type `type_info' not matching
`mercury_builtin:type_info'.
compiler/check_typeclass.m:
Simplify the code for check_instance_pred and
get_matching_instance_pred_ids.
compiler/mercury_compile.m:
compiler/modules.m:
Disallow directory names in command-line arguments.
compiler/options.m:
compiler/handle_options.m:
compiler/mercury_compile.m:
compiler/modules.m:
Add a `--make-private-interface' option.
The private interface file `<module>.int0' contains
all the declarations in the module; it is used for
compiling sub-modules.
scripts/Mmake.rules:
scripts/Mmake.vars.in:
Add support for creating `.int0' and `.date0' files
by invoking mmc with `--make-private-interface'.
doc/user_guide.texi:
Document `--make-private-interface' and the `.int0'
and `.date0' file extensions.
doc/reference_manual.texi:
Document nested modules.
util/mdemangle.c:
profiler/demangle.m:
Demangle names with multiple module qualifiers.
tests/general/Mmakefile:
tests/general/string_format_test.m:
tests/general/string_format_test.exp:
tests/general/string__format_test.m:
tests/general/string__format_test.exp:
tests/general/.cvsignore:
Change the `:- module string__format_test' declaration in
`string__format_test.m' to `:- module string_format_test',
because with the original declaration the `__' was taken
as a module qualifier, which lead to an error message.
Hence rename the file accordingly, to avoid the warning
about file name not matching module name.
tests/invalid/Mmakefile:
tests/invalid/missing_interface_import.m:
tests/invalid/missing_interface_import.err_exp:
Regression test to check that the compiler reports
errors for missing `import_module' in the interface section.
tests/invalid/*.err_exp:
tests/warnings/unused_args_test.exp:
tests/warnings/unused_import.exp:
Update the expected diagnostics output for the test cases to
reflect a few minor changes to the warning messages.
tests/hard_coded/Mmakefile:
tests/hard_coded/parent.m:
tests/hard_coded/parent.child.m:
tests/hard_coded/parent.exp:
tests/hard_coded/parent2.m:
tests/hard_coded/parent2.child.m:
tests/hard_coded/parent2.exp:
Two simple tests case for the use of nested modules with
separate compilation.
|
||
|
|
d7d5e25d18 |
Bug fix. When there are no methods for a class, the maybe(list(pred_proc_id))
Estimated hours taken: 1
Bug fix. When there are no methods for a class, the maybe(list(pred_proc_id))
field of the hlds_instance_defn was left as no, rather than yes([]), so
base_typeclass_info.m bombed out when trying to generate the pointers to the
typeclass methods.
compiler/base_typeclass_info.m:
Explicitly check for typeclasses with no methods, and set the
mybe(list(pred_proc_id)) field to yes([]).
|
||
|
|
bb4442ddc1 |
Update copyright dates for 1998.
Estimated hours taken: 0.5 compiler/*.m: Update copyright dates for 1998. |
||
|
|
7406335105 |
This change implements typeclasses. Included are the necessary changes to
Estimated hours taken: 500 or so This change implements typeclasses. Included are the necessary changes to the compiler, runtime and library. compiler/typecheck.m: Typecheck the constraints on a pred by adding constraints for each call to a pred/func with constraints, and eliminating constraints by applying context reduction. While reducing the constraints, keep track of the proofs so that polymorphism can produce the tyepclass_infos for eliminated constraints. compiler/polymorphism.m: Perform the source-to-source transformation which turns code with typeclass constraints into code without constraints, but with extra "typeclass_info", or "dictionary" parameters. Also, rather than always having a type_info directly for each type variable, sometimes the type_info is hidden inside a typeclass_info. compiler/bytecode*.m: Insert some code to abort if bytecode generation is used when typeclasses are used. compiler/call_gen.m: Generate code for a class_method_call, which forms the body of a class method (by selecting the appropriate proc from the typeclass_info). compiler/dead_proc_elim.m: Don't eliminate class methods if they are potentially used outside the module compiler/hlds_data.m: Define data types to store: - the typeclass definitions - the instances of a class - "constraint_proof". ie. the proofs of redundancy of a constraint. This info is used by polymorphism to construct the typeclass_infos for a constraint. - the "base_tyepclass_info_constant", which is analagous the the base_type_info_constant compiler/hlds_data.m: Define the class_method_call goal. This goal is inserted into the body of class method procs, and is responsible for selecting the appropriate part of the typeclass_info to call. compiler/hlds_data.m: Add the class table and instance table to the module_info. compiler/hlds_out.m: Output info about base_typeclass_infos and class_method_calls compiler/hlds_pred.m: Change the representation of the locations of type_infos from "var" to type_info_locn, which is either a var, or part of a typeclass_info, since now the typeclass_infos contain the type_infos for the type that they constrain. Add constraints to the pred_info. Add constraint_proofs to the pred_info (so that typeclass.m can annotate the pred_info with the reasons that constraints were eliminated, so that polymorphism.m can in turn generate the typeclass_infos for the constraints). Add the "class_method" marker. compiler/lambda.m: A feable attempt at adding class ontexts to lambda expressions, untested and almost certainly not working. compiler/llds_out.m: Output the code addresses for do_*det_class_method, and output appropriately mangled symbol names for base_typeclass_infos. compiler/make_hlds.m: Add constraints to the types on pred and func decls, and add class and instance declarations to the class_table and instance_table respectively. compiler/mercury_compile.m: Add the check_typeclass pass. compiler/mercury_to_mercury.m: Output constraints of pred and funcs, and output typeclass and instance declarations. compiler/module_qual.m: Module qualify typeclass names in pred class contexts, and qualify the typeclass and instance decls themselves. compiler/modules.m: Output typeclass declarations in the short interface too. compiler/prog_data.m: Add the "typeclass" and "instance" items. Define the types to store information about the declarations, including class contexts on pred and func decls. compiler/prog_io.m: Parse constraints on pred and func declarations. compiler/prod_out.m: Output class contexts on pred and func decls. compiler/type_util.m: Add preds to apply a substitution to a class_constraint, and to a list of class constraints. Add type_list_matches_exactly/2. Also add typeclass_info and base_typeclass_info as types which should not be optimised as no_tag types (seeing that we cheat a bit about their representation). compiler/notes/compiler_design.html: Add notes on module qualification of class contexts. Needs expansion to include more stuff on typeclasses. compiler/*.m: Various minor changes. New Files: compiler/base_typeclass_info.m: Produce one base_typeclass_info for each instance declaration. compiler/prog_io_typeclass.m: Parse typeclass and instance declarations. compiler/check_typeclass.m: Check the conformance of an instance declaration to the typeclass declaration, including building up a proof of how superclass constraints are satisfied so that polymorphism.m is able to construct the typeclass_info, including the superclass typeclass_infos. library/mercury_builtin.m: Implement that base_typeclass_info and typeclass_info types, as well as the predicates type_info_from_typeclass_info/3 to extract a type_info from a typeclass_info, and superclass_from_typeclass_info/3 for extracting superclasses. library/ops.m: Add "typeclass" and "instance" as operators. library/string.m: Add a (in, uo) mode for string__length/3. runtime/mercury_ho_call.c: Implement do_call_*det_class_method, which are the pieces of code responsible for extracting the correct code address from the typeclass_info, setting up the arguments correctly, then executing the code. runtime/mercury_type_info.h: Macros for accessing the typeclass_info structure. |