Estimated hours taken: 0.5
compiler/ml_code_util.m:
compiler/ml_call_gen.m:
compiler/ml_unify_gen.m:
Eliminate some code duplication, by using the existing
subroutines ml_gen_assign and ml_qualify_var in a number
of places where there code was duplicated.
Estimated hours taken: 12
Fix several bugs in the MLDS back-end:
- a bug in tail recursion optimization
- a bug that lead to duplicate field names in environment structs
- a few miscellaneous fixes for runtime/mercury.{h,c}.
compiler/mlds_to_c.m:
Fix a bug with tail recursion optimization:
for the tail recursive call `p(H1, H2) :- ... p(H2, H1) ...',
it was generating code of the form
void p(MR_Word H1, MR_Word H2) {
for(;;) {
...
{
H1 = H2;
H2 = H1;
continue;
}
...
}
}
which clobbered the value of H1. The fix was to change
it to generate code which assigns the new arguments to
temporary local variables before assigning them to the
headvars:
void p(MR_Word H1, MR_Word H2) {
for(;;) {
...
{
MR_Word H1__tmp_copy = H2;
MR_Word H2__tmp_copy = H1;
H1 = H1__tmp_copy;
H2 = H2__tmp_copy;
continue;
...
}
}
compiler/ml_code_util.m:
Add a new function ml_gen_mlds_var_decl/4, for use by
mlds_to_c.m for the tempoaries it now generates when handling
tail recursion.
compiler/ml_call_gen.m:
Ensure that the temporary conversion variables generated by
ml_gen_box_or_unbox_lval all have distinct names, by including
a sequence number in the name. This is needed because
ml_elim_nested.m assumes that all variables defined in a
function have different names; if two variables are defined in
different scopes with the same name, then when ml_elim_nested
hoists them out, this leads to a duplicate field name in the
environment struct.
compiler/ml_code_util.m:
Add a new counter field to the ml_gen_info and a new predicate
ml_gen_info_new_conv_var for accessing it, for use by
ml_gen_box_or_unbox_lval in ml_call_gen.m.
runtime/mercury.c:
Add definitions for some functions declared `extern inline'
in runtime/mercury_heap.h.
runtime/mercury.h:
- Delete some unnecessary `#ifdef ... #define ... #endif' guards;
everything in this file is already protected by the
`#ifndef MERCURY_H' guard at the top of the file.
- Increase the fixed limit here on the arity of types from 5 to 10,
since some files in the compiler directory use higher-order
types with arities greater than 5.
- Add a macro version of MR_box_float(), using gcc's `({...})'
extension.
Estimated hours taken: 15
Implement typeclasses for the MLDS back-end.
compiler/rtti.m:
Add base_typeclass_info as a new alternative in the
rtti_name and rtti_data types.
compiler/base_typeclass_info.m:
Change it to define base_typeclass_infos as rtti_data
rather than comp_gen_c_data.
compiler/mercury_compile.m:
Modify to reflect the changes to base_typeclass_info.m's
interface.
Also change the order in which we run the MLDS passes: make
sure to generate all the MLDS, including that generated by
rtti_to_mlds.m, before running the MLDS transformation passes
ml_tailcall.m and ml_elim_nested.m, since the wrapper
functions that rtti_to_mlds.m generates for typeclass methods
can contain code which those two MLDS transformation passes
need to transform.
compiler/rtti_out.m:
compiler/rtti_to_mlds.m:
compiler/mlds_to_c.m:
compiler/opt_debug.m:
Handle base_typeclass_infos.
compiler/mlds_to_c.m:
Fix a bug where it was not properly mangling variable names.
Note that polymorphism.m can introduce variable names
that contain operators, e.g. `TypeClassInfo_for_+'.
This bug broke tests/hard_coded/operator_classname.m.
I also changed it to mangle label names.
compiler/rtti_to_mlds.m:
Pass down the module_info, so that ml_gen_init_method
can use it when generate wrapper functions for type
class methods.
compiler/ml_unify_gen.m:
Export the ml_gen_closure_wrapper procedure, for use by
rtti_to_mlds for type class methods.
compiler/ml_code_util.m:
Add a new predicate `ml_gen_info_bump_func_label',
for use by rtti_to_mlds.m when generating wrapper
Add some functions defining magic numbers related to
the representation of type_infos, base_typeclass_infos,
and closures.
compiler/ml_call_gen.m:
Handle type class method calls.
compiler/llds_out.m:
Split the code for outputting a base_typeclass_info name
into a separate subroutine, and export that subroutine,
for use by rtti_out.m.
compiler/llds_out.m:
compiler/rtti_out.m:
Change llds_out.m so that it calls a new predicate
output_base_typeclass_info_storage_type_name, defined in
rtti_out.m, when outputting base_typeclass_info declarations.
This is needed because base_typeclass_infos are now defined
as RTTI constants with type `Code * []', and so need to be
handled as such by rtti_out.m rather than being assumed to
be structs like the other LLDS data_names.
Also move the code for handling dynamic initialization of
method pointers from llds_out.m to rtti_out.m,
at the same time changing it to handle their new definitions
as rtti_data rather than comp_gen_c_data.
compiler/mlds.m:
Delete the type `base_data', since it is no longer needed.
compiler/notes/type_class_transformation.html:
Fix a documentation bug: the second field of
base_typeclass_infos is the number of instance constraints,
not the number of unconstrained type variables.
compiler/notes/compiler_design.html:
Document the use of the rtti modules in the MLDS back-end,
and improve the documentation of their use in the LLDS back-end.
runtime/mercury.h:
Add a typedef for `MR_BaseTypeclassInfo', for use by the
code generated by rtti_to_mlds.m and mlds_to_c.m
for base_typeclass_infos.
Also add another work-around declaration of an MR_TypeCtorInfo;
with this, the browser directory now compiles.
Estimated hours taken: 2
Fix a bug in the MLDS back-end's code generation for
if-then-else goals with nondet conditions.
compiler/ml_code_gen.m:
When generating code for if-then-elses with nondet conditions,
allocate a fresh `cond_<N>' variable for each such
if-then-else, rather than reusing the `succeeded' variable.
This ensures that the boolean variable that we use to figure
out if the condition succeeded won't be clobbered by the
condition or the "then" part of the if-then-else.
compiler/ml_code_util.m:
Add routines for generating `cond_<N>' variables.
Add a new cond_var field to the ml_gen_info;
this is a sequence number used to generate those
variables.
Estimated hours taken: 1
Fix a bug in the MLDS back-end that broke samples/muz.
compiler/ml_code_util.m:
Fix a bug: it was getting the defining module
wrong when generating references to complicated
modes of unification procedures for types defined
in different modules (and likewise for opt_imported
procedures).
Estimated hours taken: 10
Implement RTTI support for the MLDS back-end using the rtti module.
compiler/ml_base_type_info.m:
Delete this file.
compiler/rtti_to_mlds.m:
New file, replaces ml_base_type_info.
This generates MLDS code from the RTTI data structures.
compiler/ml_code_gen.m:
Don't call ml_base_type_info.
compiler/mercury_compile.m:
Call rtti_to_mlds.
Also add a few more comments to the list of
imported modules.
compiler/mercury_compile.m:
compiler/type_ctor_info.m:
Delete the unnecessary second `module_info' parameter from
type_ctor_info_generate_rtti.
compiler/ml_code_util.m:
Add ml_gen_proc_params_from_rtti, for use by gen_init_proc_id
in rtti_to_mlds.
Fix a bug where it was using Arity for both the PredArity
and the TypeArity.
compiler/rtti.m:
compiler/rtti_out.m:
Change the documentation for rtti_out.m to say that it
_is_ intended to depend on LLDS.
Move rtti_data_to_name from rtti_out.m to rtti.m,
since that does not depend on the LLDS.
Add rtti__name_is_exported/1, and implement
rtti_name_linkage using that.
Add some new fields to rtti_proc_label, for use by
ml_gen_proc_params_from_rtti.
compiler/mlds.m:
Add a new alternative `rtti_type(rtti_name)' to mlds__type type,
and a new alternative `rtti_data(rtti_type_id, rtti_name)' to
the mlds__data_name type, so we can represent the names and
types of the RTTI data.
Change the mlds__initializer type to make it a bit more expressive,
so that it can represent e.g. initializers for arrays of structs,
since this is needed for some of the RTTI data.
compiler/ml_code_util.m:
compiler/ml_elim_nested.m:
compiler/mlds_to_c.m:
Handle the new definition of mlds__initializer,
and the new alternatives in the rtti_name and
mlds__data_name types.
Estimated hours taken: 7
Restructure the RTTI implementation to eliminate dependencies on the LLDS,
so that it can be used for the MLDS back-end as well as the LLDS back-end.
(Note that I have not yet modified the MLDS back-end to actually make
use of it; that will be a separate change.)
compiler/rtti.m:
Eliminate the dependency on LLDS, by replacing code_addr with a new
type `rtti_proc_label'. Add a procedure `rtti__make_proc_label' for
constructing these.
compiler/type_ctor_info.m:
Eliminate the dependency on LLDS, by calling rtti__make_proc_label
rather than code_util__make_entry_label.
compiler/ml_code_util.m:
Add a new procedure `ml_gen_pred_label_from_rtti',
for (eventual) use by ml_base_type_info.m.
Restructure the implementation of ml_gen_pred_label so that it
works by first calling rtti__make_proc_label and then calling
ml_gen_pred_label_from_rtti.
compiler/code_util.m:
Add new procedure `make_entry_label_from_rtti', for use by rtti_out.m.
Restructure the implementation of the predicates make_entry_label,
make_local_entry_label, and make_proc_label so that they work by first
calling rtti__make_proc_label. Change make_user_proc_label to take
a boolean rather than an import_status.
Also update the documentation for code_util__compiler_generated,
adding an XXX comment saying that the name is misleading.
compiler/rtti_out.m:
Call code_util__make_entry_label_from_rtti to
convert the rtti_proc_labels in the RTTI into code_addrs.
compiler/rl.m:
Update to reflect the changed interface to
code_util__make_user_proc_label.
Estimated hours taken: 16 (some work done in tandem with fjh)
Extend MLDS to cope with alternate backends, and hopefully to allow
easier implementation of high level data structures in the C backend.
Add type information that is required for more heavily typed backends
(with C you can just cast to void * to escape the type system when it is
inconvenient, with other systems this is impossible, e.g. a Java backend).
Introduce new "cast" unop, that does casts.
compiler/mercury_compile.m:
Split the generation of MLDS from outputting high-level C code.
MLDS can be connected up to other backends.
compiler/ml_base_type_info.m:
compiler/ml_call_gen.m:
compiler/ml_code_gen.m:
compiler/ml_code_util.m:
compiler/ml_tailcall.m:
compiler/ml_unify_gen.m:
Add a type to code address constants (the type signature of the
function).
Add the type of the field and the type of the object to field
instructions.
Add a type to mem_ref (the type of the reference).
Don't create local definitions if the locals are dummy types.
compiler/ml_elim_nested.m:
Add types to code addresses, fields and mem_refs.
Use cast where appropriate.
compiler/mlds.m:
Add cast statement.
Add types to code addresses, fields and mem_refs.
compiler/mlds_to_c.m:
Output casts, generally ignore the types in code addresses,
fields and mem_refs (high level C code doesn't really need them,
although it might be nice to use them in future).
Estimated hours taken: 0.25
compiler/mlds.m:
compiler/mlds_to_c.m:
compiler/ml_unify_gen.m:
compiler/ml_code_util.m:
Rename mlds__int_type, mlds__float_type, etc.
to mlds__native_int_type, mlds__native_float_type, etc.,
to make it clearer that these types are for the native
MLDS types, which may be different from the MLDS types
used to represent the correspondingly-named Mercury types.
Estimated hours taken: 1
Add support for `pragma memo' and `pragma loopcheck'
to the MLDS back-end.
compiler/ml_code_util.m:
Change the interface to ml_gen_mlds_var_decl so that it takes
an mlds__data_name rather than an mlds__var_name, so that it
can be used to generate declarations for tabling_pointer
variables.
compiler/ml_code_gen.m:
compiler/ml_code_util.m:
compiler/ml_unify_gen.m:
Change calls to ml_gen_mlds_var_decl to match its new interface.
compiler/ml_code_gen.m:
For tabled procedures, generate a definition of the
variable which holds the table.
compiler/mlds_to_c.m:
Add code to handling output the names of the variables
used to hold tables.
Estimated hours taken: 4
Split up ml_code_gen.m into four modules.
compiler/ml_call_gen.m:
New module, contains the MLDS code generation for
calls and builtins.
compiler/ml_unify_gen.m:
New module, contains the MLDS code generation for
unifications.
compiler/ml_code_util.m:
New module, contains stuff shared between
ml_call_gen.m, ml_unify_gen.m, and ml_code_gen.m.
compiler/ml_code_gen.m:
Move about 60% of the code here into the three new
modules.