Estimated hours taken: 1
Branches: main
compiler/ml_elim_nested.m:
compiler/ml_code_gen.m:
Improve the documentation about what's missing for accurate GC.
Estimated hours taken: 1
Branches: main
Fix a bug where the MLDS back-end was generating references to `dummy_var',
for calls to builtins such as unsafe_promise_unique and unsafe_type_cast
with dummy types such as `io__state'. Referencing a dummy variable is OK for
`--low-level-data', but it doesn't work with `--high-level-data' (e.g. for
the .NET back-end), because we'd need different dummy variables for each
different type. It's better to avoid generating such assignments in the
first place.
compiler/ml_code_gen.m:
Avoiding generating references to dummy_var for calls to
unsafe_type_cast.
compiler/ml_call_gen.m:
Avoiding generating references to dummy_var for calls to other
builtins, such as unsafe_promise_unique.
Estimated hours taken: 2
Branches: main
Ensure that in MLDS grades, arguments with arg_mode `top_unused' do not
get passed.
Previously, different parts of the compiler had different and inconsistent
ideas about if/how they should get passed, which caused problems,
including an internal error for tests/hard_coded/foreign_type2.m in grade
`java'. The comments in mlds.m said they should not get passed, the
code in ml_call_gen.m passed them as if they were output arguments, and
the code in ml_code_util declared them as if they were input arguments.
compiler/hlds_pred.m:
Add some detailed comments about the meaning of the `arg_mode' type.
compiler/ml_call_gen.m:
compiler/ml_code_util.m:
compiler/ml_code_gen.m:
Ensure that arguments with arg_mode `unused' do not get passed,
declared, or converted (respectively).
runtime/mercury_grade.h:
Bump the binary compatibility version number for MLDS grades.
This is needed because the calling convention for procedures
with `unused' mode arguments has changed.
Estimated hours taken: 10
Branches: main
Allow user-defined comparison functions using the syntax
:- type t ---> t where equality is t_equal, comparison is t_compare.
.
Allow user-defined equality and comparison for foreign types using the syntax
:- pragma foreign_type(c, t, "c_t") where
equality is t_equal, comparison is t_compare.
compiler/prog_data.m:
compiler/mercury_to_mercury.m:
compiler/hlds_out.m:
compiler/*.m:
Allow comparison predicates in `type' and `pragma foreign_type'
declarations
compiler/hlds_data.m:
compiler/*.m:
Allow equality and comparison predicates to be attached
to foreign types.
compiler/prog_io.m:
compiler/prog_io_pragma.m:
Parse the new syntax.
compiler/make_hlds.m:
Don't add the types to the HLDS or do typechecking if
there are errors in the type declarations.
Test case: tests/invalid/foreign_type_visibility.m.
compiler/foreign.m:
compiler/special_pred.m:
compiler/type_util.m:
Check whether foreign types have user-defined equality.
compiler/unify_proc.m:
Generate clauses for user-defined comparison,
and clauses for unification for foreign types.
compiler/intermod.m:
Resolve overloading before writing the `.opt' files.
library/builtin.m:
Add `uo' modes for promise_only_solution, for use in
user-defined comparison predicates.
Add types and insts to allow declaration of user-defined
comparison predicates using `with_type` and `with_inst`.
We already have types and insts `builtin__comparison_pred',
but they have a different argument ordering to `compare/3'.
NEWS:
doc/reference_manual.texi:
Document the change.
tests/hard_coded/Mmakefile:
tests/hard_coded/user_compare.{m,exp}:
Test case.
tests/invalid/Mmakefile:
tests/invalid/typeclass_test_{9,10}.{m,err_exp}:
tests/invalid/purity/purity_nonsense{,2}.{m,err_exp}:
The change to error-checking in make_hlds.m meant that
the compilation stopped before some errors in
typeclass_test_9.m were detected. The code which
tests for those errors is now in typeclass_test_10.m.
Estimated hours taken: 70
Branches: main
Add Java support to the foreign language interface.
mercury/compiler/compile_target_code.m:
mercury/compiler/make.module_target.m:
mercury/compiler/mercury_compile.m:
Pass `compile_java_file' a Java filename rather than a module name.
mercury/compiler/globals.m:
Add `java' as a `foreign_language'.
mercury/compiler/handle_options.m:
Allow Java as a back-end foreign language if the target language
is Java.
mercury/compiler/hlds_data.m:
Allow Java foreign_types.
mercury/compiler/intermod.m:
mercury/compiler/foreign.m:
mercury/compiler/make.util.m:
mercury/compiler/make_hlds.m:
mercury/compiler/mercury_compile.m:
mercury/compiler/mercury_to_mercury.m:
mercury/compiler/ml_code_gen.m:
mercury/compiler/mlds.m:
mercury/compiler/mlds_to_c.m:
mercury/compiler/mlds_to_il.m:
mercury/compiler/mlds_to_ilasm.m:
mercury/compiler/mlds_to_java.m:
mercury/compiler/pragma_c_gen.m:
mercury/compiler/prog_data.m:
mercury/compiler/prog_io_pragma.m:
Add or modify existing code to support `java' as a `foreign_language'
and Java `foreign_type's.
mercury/compiler/mlds_to_java.m:
Nicely indent the generated code that unboxes arguments from
return-argument arrays which are used for methods with multiple
return arguments.
Estimated hours taken: 28
Branches: main
Change `mmc --make' so that it no longer builds the external foreign
object files at the same time as it builds the target object file.
This allows one to build on the IL backend where building an external
foreign file assembly depends on having all the imported Mercury
assemblies built first.
Various fixes were also added so that `mmc --make --grade il' could make
an executable.
compiler/compile_target_code.m:
Change il_assemble so that we always build a .dll version
irrespective of whether it contains main or not, as MC++ or C#
code may refer to the dll.
Add Mercury/dlls to the search path for the C# and MC++
compilers.
s,/,\\\\,g in the C# filename as the MS C# compiler doesn't
understand / as a directory seperator.
Add the referenced dlls to the C# compilers command line.
Export maybe_pic_object_file_extension.
compiler/handle_options.m:
Fix a bug where copmute_grade incorrectly generated `hl.il'
instead of `il' as the grade name because we weren't always
considering the --target option.
compiler/make.m:
Add to the compilation_task_type type the alternatives
foreign_code_to_object_code and fact_table_foreign_code_file.
Add to the module_target_type type the alternatives
foreign_asm, foreign_object and factt_object.
compiler/make.dependencies.m:
Add code to handle the new module_target_type alternatives.
Add code to build the new alternatives to
compilation_task_type.
compiler/make.module_target.m:
Add rules to build the foreign_code_to_object_code and
fact_table_code_to_object_code.
compiler/make.program_target.m:
Determine the targets needed to be built for all the external
foreign files and add them to build target list.
compiler/make.util.m:
Add code to handle the new module_target_type alternatives.
Change write_target_file to output the correct name when
building the foreign_asm and foreign_object targets.
compiler/modules.m:
Move referenced_dlls into the interface for use by
`compile_target_code.m'.
Don't place dlls in a sub-directory because on the IL backend
the dlls are `part' of the executable file.
Add a `MkDir' argument to fact_table_file_name which
optionally creates a directory to store the generated
file_name in.
tests/hard_coded/foreign_proc_make.exp:
tests/hard_coded/foreign_proc_make.m:
tests/hard_coded/foreign_proc_make2.m:
Add a test case.
Estimated hours taken: 2
Branches: main
Fix a bug that meant we generated invalid code for foreign_proc IL.
Recent changes to variable naming unifications uncovered this bug.
compiler/ml_code_gen.m:
Use the user's names for variables when generating locals for
use in foreign_proc for IL, so that they match the names given
in the foreign code.
Estimated hours taken: 10
Branches: main
Improvements for `:- pragma foreign_type'.
- Allow default Mercury definitions. The Mercury definition must define
a discriminated union type. The constructors of the Mercury type are
only visible in predicates which have implementations for all the
foreign languages the type has implementations for. In all other
predicates the type is treated as an abstract type (the check for
this isn't quite right).
- Allow polymorphic foreign types.
- Don't require the `:- pragma foreign_type' for exported foreign types
to be in the interface. We now only require that all definitions
have the same visibility.
compiler/prog_data.m:
compiler/prog_io_pragma.m:
Allow polymorphic foreign types.
compiler/prog_io.m:
Export code to parse the type name in a type definition for
use by prog_io_pragma.m.
compiler/make_hlds.m:
Handle Mercury definitions for foreign types.
Separate out the code to add constructors and special predicates
to the HLDS into a separate pass. For foreign types, we don't know
what to add until all type definitions have been seen.
Use the C definition for foreign types with `--target asm'.
compiler/modules.m:
Distinguish properly between `exported' and `exported_to_submodules'.
Previously, if a module had sub-modules, all declarations,
including those in the interface, had import_status
`exported_to_submodules'. Now, the declarations in the
interface have status `exported' or `abstract_exported'.
This is needed to check that the visibility of all the
definitions of a type is the same.
compiler/hlds_pred.m:
Add a predicate status_is_exported_to_non_submodules, which
fails if an item is local to the module and its sub-modules.
compiler/hlds_data.m:
compiler/*.m:
Record whether a du type has foreign definitions as well.
Also record whether uses of the type or its constructors
need to be qualified (this is needed now that adding
the constructors to the HLDS is a separate pass).
compiler/typecheck.m:
Check that a predicate or function has foreign clauses before
allowing the use of a constructor of a type which also has
foreign definitions.
compiler/hlds_pred.m:
compiler/make_hlds.m:
Simplify the code to work out the goal_type for a predicate.
compiler/hlds_out.m:
Don't abort on foreign types.
Print the goal type for each predicate.
compiler/error_util.m:
Handle the case where the message being written is a
continuation of an existing message, so the first line
should be indented.
compiler/module_qual.m:
Remove unnecessary processing of foreign types.
doc/reference_manual.tex:
Document the change.
Update the documentation for mixing Mercury and foreign clauses.
The Mercury clauses no longer need to be mode-specific.
tests/hard_coded/Mmakefile:
tests/hard_coded/foreign_type2.{m,exp}:
tests/hard_coded/foreign_type.m:
tests/hard_coded/intermod_foreign_type.{m,exp}:
tests/hard_coded/intermod_foreign_type2.m:
tests/invalid/Mmakefile:
tests/invalid/foreign_type_2.{m,err_exp}:
tests/invalid/foreign_type_visibility.{m,err_exp}:
Test cases.
tests/invalid/record_syntax.err_exp:
Update expected output.
Estimated hours taken: 40
Branches: main
Output Managed C++ code using the same mechanisms as we do for C#
code, rather than using pragma_c_gen to generate MC++ code. This
fixes the problem that functions couldn't be defined in MC++, and also
should make the code more maintainable in the future as MC++ is much
more similar to C# than to C.
compiler/mlds.m:
Add a new field to outline_foreign_proc. This field has
information which links the mlds variables with the variable
names used in the foreign code.
compiler/ml_code_gen.m:
Generate a foreign proc for MC++ the same way we generate a
foreign proc for C#.
Generate the data for the new field in outline_foreign_proc.
Use the context of the string which contains the pragma foreign
proc body for the context of the foreign proc. This ensures that
error messages refer to the correct line number.
compiler/mlds_to_il.m:
Add to the list of foreign languages defined in the module to
include those which don't have a foreign_proc defined in them.
Move the relevant code from atomic_statement_to_il to
generate_method so that we handle external procedures correctly.
compiler/mlds_to_ilasm.m:
Call mlds_to_managed.
compiler/ml_backend.m:
Add the new module and remove mlds_to_mcpp and mlds_to_csharp.
compiler/ml_elim_nested.m:
compiler/ml_optimize.m:
compiler/ml_util.m:
compiler/mlds_to_c.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_java.m:
Minor changes to handling the new field in outline_foreign_proc.
compiler/mlds_to_csharp.m:
compiler/mlds_to_mcpp.m:
Removed files whose functionality has been subsumed by
mlds_to_managed.
library/construct.m:
library/float.m:
library/io.m:
library/std_util.m:
library/type_desc.m:
Changes required to get the library to be able compile in the
ilc grade.
Estimated hours taken: 20
Branches: main
Implement the last remaining bits needed to do accurate GC for
closure wrappers.
compiler/ml_call_gen.m:
Add an extra boolean argument to ml_gen_call and
ml_gen_box_or_unbox_lval specifying whether or not
the calling procedure is a closure wrapper.
If it is, declare any local variables allocated
to hold temporaries needed for boxing/unboxing
using ml_gen_local_for_output_arg from ml_closure_gen.m,
so that the GC tracing code gets handled right.
Also add an extra int argument to ml_gen_box_or_unbox_lval,
specifying the argument number, since this is needed by
ml_gen_local_for_output_arg.
compiler/ml_closure_gen.m:
Pass `yes' for the new boolean argument to ml_gen_call.
Fix a bug where the `allocated_memory_cells' list was not being
initialized.
Export ml_gen_local_for_output_arg, for use by ml_call_gen.m.
Fix an off-by-one bug in ml_gen_local_for_output_arg.
compiler/ml_code_gen.m:
Pass `no' for the new boolean argument to ml_gen_call
and ml_gen_box_or_unbox_lval.
Estimated hours taken: 25
Branches: main
Fix problems with the compiler-generated header files:
1. the header files are grade dependent, but the header files
can only be installed for one grade.
2. the generated header files can clash with system headers.
To solve these problems, the compiler now generates a
grade dependent `.mih' file containing the declarations
needed when a module is imported in a high-level C code
grade, and a grade independent `.mh' file, which contains
the prototypes for `:- pragma export' declarations.
compiler/export.m:
Generate a `.mh' rather than a `.h' file for the `:- pragma export'
declarations.
Allow the header file generated by export.m to be used with
`--high-level-code'.
compiler/modules.m:
library/Mmakefile:
Add a module.install_grade_hdrs target to install the `.mih'
files in a grade-dependent directory.
compiler/arg_info.m:
compiler/hlds_out.m:
compiler/hlds_pred.m:
Make it easier to tell if the arg_info field of the proc_info
has been set.
compiler/mlds_to_c.m:
Include both the `.mh' and `.mih' files for imported modules.
The type used as the return value for a semidet procedure
exported to C is `MR_bool', not `MR_Word'.
compiler/mlds_to_c.m:
compiler/modules.m:
Don't add a `mercury.' prefix to the standard library
header file names. They can't clash with the system
headers any more.
compiler/mercury_compile.m:
compiler/mlds_to_c.m:
Use export.m to generate the header file for `:- pragma export'
declarations even in hlc grades.
compiler/mlds.m:
compiler/ml*.m:
Distinguish between the `.mh' and `.mih' files
in `mlds__import's.
compiler/handle_options.m:
scripts/Mmake.vars.in:
scripts/mgnuc.in:
Add C include directory options for the installed grade
dependent `.mih' files.
Mmakefile:
scripts/Mmake.rules:
s/h/mih/ in the commands to save the grade dependent
files when installing the library grades.
compiler/make.m:
compiler/make.dependencies.m:
compiler/make.module_target.m:
compiler/make.util.m:
Handle dependencies on `.mh' and `.mih' files.
NEWS:
doc/user_guide.texi:
Document the change.
Estimated hours taken: 1
Branches: main
compiler/ml_code_gen.m:
Fix a bug in the code generation for nondet pragma c_code.
It was not resetting the MR_succeeded variable after each success,
so if the C code did a SUCCEED and then when retried did a FAIL,
then the FAIL was being treated as a SUCCEED_LAST.
tests/hard_coded/nondet_pragma_c_bug.m:
tests/hard_coded/nondet_pragma_c_bug.exp:
A regression test.
Estimated hours taken: 16
Branches: main
Implement C `pragma foreign_type' properly.
compiler/mlds.m:
Allow C `pragma foreign_type' on the `--target asm' back-end.
compiler/mlds_to_c.m:
Output foreign types as MR_Box internally (i.e. for the ordinary
code that we generate), for compatibility with the `--target asm'
back-end. But output foreign types as the C type name for
`pragma foreign_proc' and `pragma export'.
runtime/mercury_heap.h:
Add macros MR_MAYBE_(UN)BOX_FOREIGN_TYPE,
for boxing/unboxing foreign_type values.
compiler/export.m:
compiler/ml_code_gen.m:
Change the LLDS/MLDS (respectively) back-end code for
`pragma export' to call the above macros when required.
compiler/llds_out.m:
compiler/mlds_to_c.m:
Change the LLDS/MLDS (respectively) back-end code for
C `pragma foreign_proc' to call the above macros when required.
compiler/mlds_to_c.m:
Don't output #line directives for target_code_components
other than user_target_code. This is nedded because #line
directives are not permitted inside invocations of macros
(such as MR_MAYBE_(UN)BOX_FOREIGN_TYPE).
compiler/foreign.m:
- Add a new boolean function foreign__is_foreign_type,
which tests whether an exported_type is a foreign_type or not.
- Delete the predicate llds_exported_type_string
(I changed the callers to use foreign__to_type_string instead).
compiler/ml_code_gen.m:
compiler/mlds_to_c.m:
compiler/pragma_c_gen.m:
Add an explicit module qualifier to calls to foreign__to_type_string.
doc/reference_manual.texi:
Update the documentation to reflect the changes:
- various unnecessary restrictions have been removed
- foreign_type now works properly with `pragma export'
Estimated hours taken: 16
Branches: main
Get pragma foreign_type working for the C backend.
doc/reference_manual.texi:
Document C pragma foreign_types.
compiler/prog_data.m:
Add il_foreign_type and c_foreign_type which contain all the
necessary data to output a foreign_type on the respective backends.
Change foreign_language_type to refer to these new types.
compiler/prog_io_pragma.m:
Handle the changes to foreign_language_type, and parse C
foreign_type declarations.
compiler/hlds_data.m:
Change the hlds_data__foreign_type type so that it records both the
C and IL foreign types. This will allow one to output both foreign
type declarations when doing intermodule optimization.
compiler/make_hlds.m:
Changes so that we store both the IL and C foreign types in
hlds_data__foreign_type.
Also add an error checking pass where we check that there is a
foreign type for the back-end we are currently compiling to.
compiler/foreign.m:
Change to_exported_type so that it works for both the C and IL
backends by getting either the C or IL foreign_type definition.
compiler/llds.m:
compiler/pragma_c_gen.m:
Change pragma_c_input and pragma_c_output so that they record
whether or not a type is a foreign_type and if so what is the string
which represents that foreign_type.
compiler/llds_out.m:
When outputting pragma c_code variables that represent foreign_types
get the casts correct. Note that this adds the constraint on C
foreign types that they are word sized, as all we are doing is
casts, not boxing and unboxing.
compiler/mlds.m:
Change mlds__foreign_type so that we store whether a type is an IL
type or a C type. It is the responsibility of the code generator
that we never create a reference to a IL foreign type when on the C
back-end, and vice versa.
compiler/mercury_to_mercury.m:
Handle changes to prog_data__foreign_type.
compiler/hlds_out.m:
compiler/intermod.m:
compiler/magic_util.m:
compiler/ml_code_gen.m:
compiler/ml_type_gen.m:
compiler/recompilation_usage.m:
compiler/term_util.m:
compiler/type_ctor_info.m:
compiler/unify_proc.m:
Handle changes to hlds_data__foreign_type.
compiler/exprn_aux.m:
compiler/livemap.m:
compiler/middle_rec.m:
compiler/opt_util.m:
Handle changes to the pragma_c_input and pragma_c_output types.
compiler/ml_code_util.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_il.m:
compiler/mlds_to_java.m:
compiler/mlds_to_c.m:
Handle changes to mlds__foreign_type.
Estimated hours taken: 4
Branches: main
Fix a bug with accurate GC.
compiler/mlds.m:
Rename the `is_tail_call' enumeration as `call_kind',
rename the `call' alternative as `ordinary_call', and
and add a new alternative `no_return_call'.
compiler/ml_call_gen.m:
Use `no_return_call' rather than `tail_call' for calls to
procecures with determinism `erroneous'.
compiler/ml_elim_nested.m:
Fix a bug: when adding code to unchain the stack frame before
tail calls, add a `return' statement after each tail call, to
ensure that we don't try to unchain the stack frame twice.
But don't do this for calls marked `no_return_call', since
it's not needed in that case. (This is mandatory, not just
an optimization: we can't construct a proper return statement
for no_return_calls, since the return values in a `no_return_call'
might not match the return types of the caller.)
compiler/mlds_to_c.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_il.m:
compiler/mlds_to_java.m:
compiler/ml_util.m:
compiler/ml_tailcall.m:
compiler/ml_code_gen.m:
compiler/ml_code_util.m:
Minor changes to handle the new `no_return_call' alternative
and the renaming of `call' as `ordinary_call'.
Estimated hours taken: 400
Branches: main
This diff implements stack slot optimization for the LLDS back end based on
the idea that after a unification such as A = f(B, C, D), saving the
variable A on the stack indirectly also saves the values of B, C and D.
Figuring out what subset of {B,C,D} to access via A and what subset to access
via their own stack slots is a tricky optimization problem. The algorithm we
use to solve it is described in the paper "Using the heap to eliminate stack
accesses" by Zoltan Somogyi and Peter Stuckey, available in ~zs/rep/stackslot.
That paper also describes (and has examples of) the source-to-source
transformation that implements the optimization.
The optimization needs to know what variables are flushed at call sites
and at program points that establish resume points (e.g. entries to
disjunctions and if-then-elses). We already had code to compute this
information in live_vars.m, but this code was being invoked too late.
This diff modifies live_vars.m to allow it to be invoked both by the stack
slot optimization transformation and by the code generator, and allows its
function to be tailored to the requirements of each invocation.
The information computed by live_vars.m is specific to the LLDS back end,
since the MLDS back ends do not (yet) have the same control over stack
frame layout. We therefore store this information in a new back end specific
field in goal_infos. For uniformity, we make all the other existing back end
specific fields in goal_infos, as well as the similarly back end specific
store map field of goal_exprs, subfields of this new field. This happens
to significantly reduce the sizes of goal_infos.
To allow a more meaningful comparison of the gains produced by the new
optimization, do not save any variables across erroneous calls even if
the new optimization is not enabled.
compiler/stack_opt.m:
New module containing the code that performs the transformation
to optimize stack slot usage.
compiler/matching.m:
New module containing an algorithm for maximal matching in bipartite
graphs, specialized for the graphs needed by stack_opt.m.
compiler/mercury_compile.m:
Invoke the new optimization if the options ask for it.
compiler/stack_alloc.m:
New module containing code that is shared between the old,
non-optimizing stack slot allocation system and the new, optimizing
stack slot allocation system, and the code for actually allocating
stack slots in the absence of optimization.
Live_vars.m used to have two tasks: find out what variables need to be
saved on the stack, and allocating those variables to stack slots.
Live_vars.m now does only the first task; stack_alloc.m now does
the second, using code that used to be in live_vars.m.
compiler/trace_params:
Add a new function to test the trace level, which returns yes if we
want to preserve the values of the input headvars.
compiler/notes/compiler_design.html:
Document the new modules (as well as trace_params.m, which wasn't
documented earlier).
compiler/live_vars.m:
Delete the code that is now in stack_alloc.m and graph_colour.m.
Separate out the kinds of stack uses due to nondeterminism: the stack
slots used by nondet calls, and the stack slots used by resumption
points, in order to allow the reuse of stack slots used by resumption
points after execution has left their scope. This should allow the
same stack slots to be used by different variables in the resumption
point at the start of an else branch and nondet calls in the then
branch, since the resumption point of the else branch is not in effect
when the then branch is executed.
If the new option --opt-no-return-calls is set, then say that we do not
need to save any values across erroneous calls.
Use type classes to allow the information generated by this module
to be recorded in the way required by its invoker.
Package up the data structures being passed around readonly into a
single tuple.
compiler/store_alloc.m:
Allow this module to be invoked by stack_opt.m without invoking the
follow_vars transformation, since applying follow_vars before the form
of the HLDS code is otherwise final can be a pessimization.
Make the module_info a part of the record containing the readonly data
passed around during the traversal.
compiler/common.m:
Do not delete or move around unifications created by stack_opt.m.
compiler/call_gen.m:
compiler/code_info.m:
compiler/continuation_info.m:
compiler/var_locn.m:
Allow the code generator to delete its last record of the location
of a value when generating code to make an erroneous call, if the new
--opt-no-return-calls option is set.
compiler/code_gen.m:
Use a more useful algorithm to create the messages/comments that
we put into incr_sp instructions, e.g. by distinguishing between
predicates and functions. This is to allow the new scripts in the
tool directory to gather statistics about the effect of the
optimization on stack frame sizes.
library/exception.m:
Make a hand-written incr_sp follow the new pattern.
compiler/arg_info.m:
Add predicates to figure out the set of input, output and unused
arguments of a procedure in several different circumstances.
Previously, variants of these predicates were repeated in several
places.
compiler/goal_util.m:
Export some previously private utility predicates.
compiler/handle_options.m:
Turn off stack slot optimizations when debugging, unless
--trace-optimized is set.
Add a new dump format useful for debugging --optimize-saved-vars.
compiler/hlds_llds.m:
New module for handling all the stuff specific to the LLDS back end
in HLDS goal_infos.
compiler/hlds_goal.m:
Move all the relevant stuff into the new back end specific field
in goal_infos.
compiler/notes/allocation.html:
Update the documentation of store maps to reflect their movement
into a subfield of goal_infos.
compiler/*.m:
Minor changes to accomodate the placement of all back end specific
information about goals from goal_exprs and individual fields of
goal_infos into a new field in goal_infos that gathers together
all back end specific information.
compiler/use_local_vars.m:
Look for sequences in which several instructions use a fake register
or stack slot as a base register pointing to a cell, and make those
instructions use a local variable instead.
Without this, a key assumption of the stack slot optimization,
that accessing a field in a cell costs only one load or store
instruction, would be much less likely to be true. (With this
optimization, the assumption will be false only if the C compiler's
code generator runs out of registers in a basic block, which for
the code we generate should be unlikely even on x86s.)
compiler/options.m:
Make the old option --optimize-saved-vars ask for both the old stack
slot optimization (implemented by saved_vars.m) that only eliminates
the storing of constants in stack slots, and the new optimization.
Add two new options --optimize-saved-vars-{const,cell} to turn on
the two optimizations separately.
Add a bunch of options to specify the parameters of the new
optimizations, both in stack_opt.m and use_local_vars.m. These are
for implementors only; they are deliberately not documented.
Add a new option, --opt-no-return-cells, that governs whether we avoid
saving variables on the stack at calls that cannot return, either by
succeeding or by failing. This is for implementors only, and thus
deliberately documented only in comments. It is enabled by default.
compiler/optimize.m:
Transmit the value of a new option to use_local_vars.m.
doc/user_guide.texi:
Update the documentation of --optimize-saved-vars.
library/tree234.m:
Undo a previous change of mine that effectively applied this
optimization by hand. That change complicated the code, and now
the compiler can do the optimization automatically.
tools/extract_incr_sp:
A new script for extracting stack frame sizes and messages from
stack increment operations in the C code for LLDS grades.
tools/frame_sizes:
A new script that uses extract_incr_sp to extract information about
stack frame sizes from the C files saved from a stage 2 directory
by makebatch and summarizes the resulting information.
tools/avg_frame_size:
A new script that computes average stack frame sizes from the files
created by frame_sizes.
tools/compare_frame_sizes:
A new script that compares the stack frame size information
extracted from two different stage 2 directories by frame_sizes,
reporting on both average stack frame sizes and on specific procedures
that have different stack frame sizes in the two versions.
The main aim of this change is to make the overall, high-level structure
of the compiler clearer, and to encourage better encapsulation of the
major components.
compiler/libs.m:
compiler/backend_libs.m:
compiler/parse_tree.m:
compiler/hlds.m:
compiler/check_hlds.m:
compiler/transform_hlds.m:
compiler/bytecode_backend.m:
compiler/aditi_backend.m:
compiler/ml_backend.m:
compiler/ll_backend.m:
compiler/top_level.m:
New files. One module for each of the major components of the
Mercury compiler. These modules contain (as separate sub-modules)
all the other modules in the Mercury compiler, except gcc.m and
mlds_to_gcc.m.
Mmakefile:
compiler/Mmakefile:
Handle the fact that the top-level module is now `top_level',
not `mercury_compile' (since `mercury_compile' is a sub-module
of `top_level').
compiler/Mmakefile:
Update settings of *FLAGS-<modulename> to use the appropriate
nested module names.
compiler/recompilation_check.m:
compiler/recompilation_version.m:
compiler/recompilation_usage.m:
compiler/recompilation.check.m:
compiler/recompilation.version.m:
compiler/recompilation.version.m:
Convert the `recompilation_*' modules into sub-modules of the
`recompilation' module.
compiler/*.m:
compiler/*.pp:
Module-qualify the module names in `:- module', `:- import_module',
and `:- use_module' declarations.
compiler/base_type_info.m:
compiler/base_type_layout.m:
Deleted these unused empty modules.
compiler/prog_data.m:
compiler/globals.m:
Move the `foreign_language' type from prog_data to globals.
compiler/mlds.m:
compiler/ml_util.m:
compiler/mlds_to_il.m:
Import `globals', for `foreign_language'.
Mmake.common.in:
trace/Mmakefile:
runtime/Mmakefile:
Rename the %.check.c targets as %.check_hdr.c,
to avoid conflicts with compiler/recompilation.check.c.
Estimated hours taken: 2
Branches: main
Fix some bugs with the hlc.agc grade where the compiler was generating
references to type_info variables that were not in scope.
compiler/hlds_pred.m:
Document the invariant that type_info arguments must precede
non-type_info arguments, since MLDS->C accurate GC relies on this.
compiler/type_util.m:
Add new function put_typeinfo_vars_first, for use by lamdbda.m
and ml_code_gen.m.
compiler/lambda.m:
Call put_typeinfo_vars_first on the arguments of the introduced
procedures, to ensure that invariant documented in hlds_pred.m holds.
compiler/ml_code_gen.m:
Call put_typeinfo_vars_first on the list of local variables
that we generate for each subgoal, to avoid referring to type_info
variables that are not in scope in the GC tracing code.
Estimated hours taken: 4
Branches: main
Add MR_ prefixes to the remaining non-prefixed symbols.
This change will require all workspaces to be updated
The compiler will start generating references to MR_TRUE,
MR_bool, etc., which are not defined in the old runtime
header files.
runtime/mercury_std.h:
Add MR_ prefixes to bool, TRUE, FALSE, max, min,
streq, strdiff, strtest, strntest, strneq, strndiff,
strntest, NO_RETURN.
Delete a commented out definition of `reg'.
runtime/mercury_tags.h:
Add an MR_ prefix to TAGBITS.
configure.in:
runtime/mercury_goto.h:
runtime/machdeps/i386_regs.h/mercury_goto.h:
Add an MR_ prefix to PIC.
runtime/mercury_conf_param.h:
Allow non-prefixed PIC and HIGHTAGS to be defined on
the command line.
runtime/mercury_bootstrap.h:
Add backwards compatibility definitions.
RESERVED_MACRO_NAMES:
Remove the renamed macros.
compiler/export.m:
compiler/ml_code_gen.m:
Use MR_bool rather than MR_Bool (MR_Bool is
meant to be for references to the Mercury type
bool__bool).
runtime/mercury_types.h:
Add a comment the MR_Bool is for references to
bool__bool.
*/*.c:
*/*.h:
*/*.m:
Add MR_ prefixes.
Estimated hours taken: 2
Fix a bug where we weren't getting proper tail recursion optimization in
the MLDS->C back-end for procedures with output arguments and determinism
`erroneous'.
compiler/ml_call_gen.m:
Mark calls with determinism `erroneous' or `failure' as tail calls.
compiler/ml_code_gen.m:
Pass the determinism (instead of the code_model) to ml_call_gen.m.
compiler/ml_tailcall.m:
Add a comment.
tests/hard_coded/exceptions/Mmakefile:
tests/hard_coded/exceptions/looptest.m:
tests/hard_coded/exceptions/looptest.exp:
Add a regression test.
Estimated hours taken: 4
Branches: main
Allow the foreign_type declaration to accept value types.
compiler/prog_data.m:
Add an indicator to il foreign types whether or not they are
reference or value types.
compiler/prog_io_pragma.m:
Parse whether or not the foreign type is a reference or a value type.
compiler/make_hlds.m:
Decide whether or not a foreign_type is already boxed.
compiler/hlds_data.m:
compiler/mlds.m:
Add to the foreign_type an indicator of whether or not it is already
boxed.
compiler/mlds_to_il.m:
Remove code which attempted to determine when a value type was
incorrectly defined as a reference type.
Unboxed types on the .NET backend are value types.
Fix a bug where converting a value_class to a value_class was
failing.
compiler/ilasm.m:
Remove name_to_simple_type from the interface as it is no longer
needed in mlds_to_il.
compiler/mercury_to_mercury.m:
Output the new foreign_type format.
compiler/foreign.m:
compiler/hlds_out.m:
compiler/intermod.m:
compiler/magic_util.m:
compiler/ml_code_gen.m:
compiler/ml_code_util.m:
compiler/ml_type_gen.m:
compiler/mlds_to_c.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_java.m:
compiler/recompilation_usage.m:
compiler/term_util.m:
compiler/type_ctor_info.m:
compiler/unify_proc.m:
Changes to handle the boxed indicator.
doc/reference_manual.texi:
Document how to specify a value type.
Branches: main
Estimated hours taken: 50
Another substantial step towards supporting accurate garbage
collection for the MLDS->C back-end: generate code for the
GC tracing functions.
compiler/mlds.m:
Add new fields to store, with each local variable or argument
declaration, the code for the GC to trace that local variable
or argument.
compiler/ml_code_util.m:
Add a new procedure ml_gen_maybe_gc_trace_code to generate the
code for GC tracing a variable. The generated MLDS code calls
private_builtin:gc_trace/1, passing the variable's address and
the type_info for that variable. This code is generated by
invoking polymorphism__make_type_info_var to generate HLDS code
to build the type_infos needed, and then calling ml_code_gen.m
to convert that to MLDS.
library/private_builtin.m:
Add a new procedure gc_trace, which calls MR_agc_deep_copy().
This gets invoked by the code generated by ml_code_util.m.
compiler/polymorphism.m:
Export polymorphism__make_type_info_var, for use by ml_code_util.m.
compiler/mercury_compile.m:
Invoke the chain_gc_stack_frames pass before invoking the
hoist_nested_functions pass, since otherwise it doesn't work.
compiler/handle_options.m
Add a couple of checks for options that are not supported
in combination with `--gc accurate'.
compiler/ml_call_gen.m:
compiler/ml_code_gen.m:
compiler/ml_elim_nested.m:
compiler/ml_optimize.m:
compiler/ml_string_switch.m:
compiler/ml_tailcall.m:
compiler/ml_type_gen.m:
compiler/ml_unify_gen.m:
compiler/ml_util.m:
compiler/mlds_to_c.m:
compiler/mlds_to_csharp.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_il.m:
compiler/mlds_to_java.m:
compiler/mlds_to_mcpp.m:
compiler/rtti_to_mlds.m:
Various changes to handle the GC trace code field for variable and
argument declarations.
Estimated hours taken: 10
Implement `:- pragma foreign_import_module(Lang, Module)', which tells
the compiler that the foreign code in the module containing the
declaration uses `:- pragma export'ed procedures from module `Module'.
This information is needed for mmake to build things in the right order.
Currently programmers can hand code the required mmake rules, but
`mmc --make' will have no mechanism for doing this.
`:- pragma c_import_module(Module)' is a synonym for
`:- pragma foreign_import_module("C", Module)'.
compiler/prog_io_pragma.m:
Parse the new pragmas.
compiler/prog_data.m:
compiler/foreign.m:
compiler/hlds_module.m:
compiler/mlds.m:
compiler/modules.m:
Add the `:- pragma foreign_import_module' to the
compiler's datastructures.
compiler/make_hlds.m:
Insert `:- pragma foreign_import_module' declarations
into the HLDS.
compiler/modules.m:
Add the extra dependency information from
`:- pragma foreign_import_module' declarations
to the `.d' files.
compiler/llds.m:
compiler/foreign.m:
Move some non-backend-specific types describing the foreign
language interface from llds.m to foreign.m.
compiler/intermod.m:
Write `:- pragma foreign_import_module' declarations
to `.opt' files. XXX mmake doesn't support this properly yet.
compiler/mercury_compile.m:
compiler/foreign.m:
compiler/ml_code_gen.m:
compiler/ml_code_gen.m:
compiler/mlds_to_c.m:
compiler/mlds_to_csharp.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_mcpp.m:
Convert `:- pragma foreign_import_module' to `#include'
statements where appropriate depending on the target
language.
compiler/*.m:
Handle `:- pragma foreign_import_module'.
Import foreign.m rather than llds.m for the foreign
interface types.
doc/reference_manual.texi:
NEWS:
Document the new pragmas.
Minor fixes for the foreign code documentation.
tests/hard_coded/Mmakefile:
tests/hard_coded/foreign_import_module.m:
tests/hard_coded/foreign_import_module_2.m:
tests/hard_coded/foreign_import_module.exp:
Test case.
Estimated hours taken: 0.5
Branches: main
Port the change to handle foreign imports onto the main branch.
If we wish to use the following foreign type
:- pragma foreign_type(xmldoc, 'System__Xml__XmlDoc', il("System.Xml")).
then we must include in the generated code a reference to the assembly
System.Xml so as to obtain the definition of System.Xml.XmlDoc. This
change implements this.
compiler/mlds.m:
Change the import type so that it distinguishes between mercury and
foreign imports.
compiler/ml_code_gen.m:
For each foreign type add its location to the list of mlds imports.
compiler/mlds_to_il.m:
Changes due to the new mlds__import definition.
Only output calls to the class constructors for those modules which
are mercury modules.
compiler/mlds_to_c.m:
compiler/mlds_to_java.m:
Changes due to the new mlds__import definition.
Estimated hours taken: 10
Branches: main
Merge the foreign_type pragma changes from the dotnet branch to the main
branch, plus do some more development work to generalise the change.
compiler/prog_data.m:
Add a type to hold the data from parsing a pragma foreign_type decl.
compiler/prog_io_pragma.m:
Parse the pragma foreign_type. This code is currently commented
out, while we decide on the syntax.
compiler/hlds_data.m:
Add a new alternative to hlds_type_body where the body of the type
is a foreign type.
compiler/make_hlds.m:
Place the foreign_type pragmas into the HLDS.
compiler/foreign.m:
Implement to_type_string which replaces export__type_to_type_string,
unlike export__type_to_type_string foreign__to_type_string takes an
argument specifying which language the representation is meant to be
in. to_type_string also needs to take a module_info to handle
foreign_types correctly. To avoid the need for the module_info to
be passed around the MLDS backend we provide a new type
exported_type which provides enough information for an alternate
version of to_type_string to be called.
compiler/export.m:
Delete export__type_to_type_string.
compiler/llds.m:
Since foreign__to_type_string needs a module_info, we add a new
field to pragma_c_arg_decl which is the result of calling
foreign__to_type_string. This avoids threading the module_info
around various llds passes.
compiler/mlds.m:
Record with in the mercury_type the exported_type, this avoids
passing the module_info around the MLDS backend.
Also add the foreign_type alternative to mlds__type.
Update mercury_type_to_mlds_type so that it handles types which are
foreign types.
compiler/mlds_to_il.m:
Convert a mlds__foreign_type into an ilds__type.
compiler/ilds.m:
The CLR spec requires that System.Object and System.String be
treated specially in the IL assembly so add them as simple types.
compiler/ilasm.m:
Before outputting a class name into the IL assembly check whether it
it can be simplified to a builtin type, and if so output that name
instead as required by the ECMA spec.
Changes for the addition of string and object as simple types.
doc/reference_manual.texi:
Document the new pragma, this is currently commented out because it
refers to syntax that has not yet been finalised.
compiler/fact_table.m:
compiler/llds_out.m:
compiler/ml_code_gen.m:
compiler/ml_code_util.m:
compiler/ml_simplify_switch.m:
compiler/ml_switch_gen.m:
compiler/ml_unify_gen.m:
compiler/mlds_to_c.m:
compiler/mlds_to_csharp.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_java.m:
compiler/mlds_to_mcpp.m:
compiler/pragma_c_gen.m:
compiler/rtti_to_mlds.m:
Changes to handle using foreign__to_type_string.
compiler/hlds_out.m:
compiler/intermod.m:
compiler/magic_util.m:
compiler/ml_type_gen.m:
compiler/recompilation_usage.m:
compiler/recompilation_version.m:
compiler/term_util.m:
compiler/type_ctor_info.m:
compiler/unify_proc.m:
Changes to handle the new hlds_type_body.
compiler/mercury_to_mercury.m:
Output the pragma foreign_type declaration.
compiler/module_qual.m:
Qualify the pragma foreign_type declarations.
compiler/modules.m:
Pragma foreign_type is allowed in the interface.
Estimated hours taken: 10
Branches: main
Fix semidet C# code to use SUCCESS_INDICATOR.
Represent mlds__native_bool_type as bool, not int32.
In the library, fix incorrect uses of MC++ to implement functions -- these
weren't being caught because they returned int32, and we assumed
this was a semidet return value, not an actual integer.
These incorrect uses were all buggy -- functions don't work in MC++.
The compiler is now catches cases where functions returning int are
implemented in MC++ -- but it won't catch cases where
IL's bool type is returned, but that should not be a such a problem.
compiler/ilasm.m:
Handle the output of boolean integer constants.
compiler/ml_code_gen.m:
Add SUCCESS_INDICATOR to the locals of the MLDS for semidet C# code,
copy SUCCESS_INDICATOR into succeeded after the execution of the
user's code.
compiler/mlds_to_csharp.m:
Implement assignments (so we can copy SUCCESS_INDICATOR to
succeeded).
compiler/mlds_to_il.m:
Copy return values into SUCCESS_INDICATOR for forwarded
predicates (it will then be copied into succeeded).
This all gets optimized away in the generated IL anyway.
Represent native_bool_type as bool, not int32.
Check for MC++ functions returning bool (not int32).
Output true and false as boolean constants for 1 and 0.
compiler/mlds_to_mcpp.m:
Map bool to MR_Bool, not MR_Integer.
library/int.m:
Implement much of the code in Mercury rather than C# or MC++.
The more efficient C bindings remain, but for other backends we
fall back on the Mercury bindings.
library/io.m:
Implement io__get_stream_id as a pred in MC++.
It is easier to keep this as MC++ at the moment as that is what
the rest of the io.m code is implemented in (including the
Mercury stream data structure).
library/std_util.m:
Add some missing assignments to SUCCESS_INDICATOR.
Estimated hours taken: 2
Branches: main
Merge changes to add attributes to the HLDS, MLDS and ILDS from the
dotnet-foreign branch. We don't merge the changes to add syntax for
attributes, as the syntax is still very experimental.
compiler/hlds_pred.m:
compiler/prog_data.m:
Add attributes to the pred_info (they are a bit like markers,
but are more than just boolean flags).
compiler/ilasm.m:
Add custom attributes to appropriate positions (on assemblies,
IL types and methods).
compiler/ml_code_gen.m:
compiler/ml_code_util.m:
compiler/ml_elim_nested.m:
compiler/ml_optimize.m:
compiler/ml_tailcall.m:
compiler/ml_type_gen.m:
compiler/ml_util.m:
compiler/mlds.m:
compiler/mlds_to_c.m:
compiler/mlds_to_csharp.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_java.m:
compiler/mlds_to_mcpp.m:
Add mlds__attributes, which are the MLDS version of custom attributes.
Convert hlds_pred__attributes into mlds__attributes.
Add a list of mlds__attributes to the mlds__function defn.
compiler/mlds_to_il.m:
Convert MLDS attributes to IL custom attributes.
Estimated hours taken: 8
Branches: main
Implement pragma export on the .NET backend.
We just generate a forwarding call from the "exported" name (which
occurs in the same class and module) to the specified predicate.
compiler/ml_code_gen.m:
Generate exports for IL as well as C.
compiler/mlds_to_il.m:
Generate a forwarding function for each exported predicate.
Put the forwarding function inside the wrapper class.
Generate a more specific error message if an return statement
has an empty list of return values.
Estimated hours taken: 1
Branches: main
compiler/ml_code_gen.m:
Address fjh's review comments regarding the fixes required to
get solutions working in the .NET backend.
Estimated hours taken: 16
Branches: main
Support multiple language foreign_procs in the one file.
If there is more then one applicable foreign_proc for a
given clause, select the most "preferred" programming
language to use as the implementation.
Currently only the IL backend has multiple languages
supported by the backend, and C# is preferred over MC++.
compiler/options.m:
compiler/handle_options.m:
Rename backend_foreign_language as backend_foreign_languages,
and use it to record the list of foreign languages the selected
backend can handle.
Remove --use-foreign-language as it doesn't do anything right now.
compiler/foreign.m:
Update code to use the list of backend foreign languages.
Add prefer_foreign_language function, to compute the preferred
foreign language ordering for each backend.
Move simple_foreign_language_string here from globals.m,
and add foreign_language_file_extension and
foreign_language_module_name functions.
(much of the rest of the code in this module is intended to deal with
the case where the backend *doesn't* handle the foreign
language, but we don't have any working support for that at the
moment).
compiler/globals.m:
Add globals__io_get_backend_foreign_languages and
globals__get_backend_foreign_languages.
compiler/make_hlds.m:
Handle selection of foreign_proc code depending upon the preferred
language.
Rename a few *_foreign_code predicates as *_foreign_proc
predicates.
Handle the extra field in clause.
compiler/ml_code_gen.m:
compiler/mlds.m:
Generate different mlds__foreign_code for each language (only
one language is selected for each predicate, but there can be
multiple languages in the onle module).
and put them in a map which is indexed on foreign language.
compiler/modules.m:
Generate appropriate dependencies for foreign language modules.
We now record which languages a list of items uses (taking into
account the preferred foreign language for foreign_proc).
We also allow for the fact that some foreign_proc declarations
won't generate any external modules.
compiler/hlds_pred.m:
Add an extra field to clause which records which language this
clause has been implemented in.
compiler/assertion.m:
compiler/clause_to_proc.m:
compiler/dead_proc_elim.m:
compiler/goal_util.m:
compiler/hlds_out.m:
compiler/inlining.m:
compiler/intermod.m:
compiler/modes.m:
compiler/polymorphism.m:
compiler/purity.m:
compiler/typecheck.m:
compiler/unify_proc.m:
Handle the extra field in clause.
compiler/mlds_to_c.m:
compiler/mlds_to_csharp.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_mcpp.m:
Select the appropriate mlds__foreign code from the map and
generate code for it.
Estimated hours taken: 50
Branches: main
Add support for foreign_proc("il", ....)
To use it, you need to give the options
--use-foreign-language il
--backend-foreign-language il
Begin documenting foreign_proc.
compiler/foreign.m:
compiler/globals.m:
Handle the addition of il as a language option.
compiler/inlining.m:
Mention that we don't allow il code to be inlined yet and give a
pointer into ml_code_gen.m which has the reason along with the
offending code.
compiler/il_peephole.m:
compiler/ilasm.m:
Handle the addition of il_asm_code as inlineable code.
compiler/ilds.m:
Add a handwritten scope to the different scope types.
compiler/ml_code_gen.m:
Handle the generation of code for IL foreign language interfacing.
Put the max_stack_size attribute into IL foreign language code.
Document the problem with inlining.
compiler/ml_elim_nested.m:
Handle the new field in blocks indicating whether the block contains
handwritten code.
compiler/mlds.m:
Add lang_il as a possible target language.
Add attributes to target code (max_stack_size is the only one so far).
compiler/mlds_to_c.m:
compiler/mlds_to_csharp.m:
compiler/mlds_to_java.m:
compiler/mlds_to_mcpp.m:
Handle the addition of il as a language option.
compiler/mlds_to_il.m:
compiler/mlds_to_ilasm.m:
Generate inline code for foreign_proc using IL.
compiler/prog_data.m:
Add il as a language option.
Add extra attributes to the pragma_foreign_proc_attributes.
Currently there is just one extra attribute, max_stack_size.
compiler/prog_io_pragma.m:
Parse max_stack_size as an attribute on foreign_proc.
Improve error message output: previously we tried to parse the
third term of a foreign_proc, and then tried to parse the second term
(which we will accept for "c_code" but not foreign_proc).
But we should give the error message as if the "c_code" handling is
not present, as this will eventually go away.
Check for foreign_language attributes such as max_stack_size.
doc/reference_manual.texi:
Add a section for foreign_proc (and other multi-language foreign
language interfacing pragmas).
At the moment we have some reasonable documentation for "C" and
"IL" foreign_proc, and some documentation on foreign_decl and
foreign_code for C.
doc/user_guide.texi:
The language and implementation specific documentation of
the foreign language interface.
Estimated hours taken: 4
Branches: main
Get solutions working on the IL backend.
compiler/ml_code_gen.m:
Avoid generating casts and assignments from MR_Box to MR_Word as
these operations aren't type-safe on the IL backend.
compiler/mlds_to_il.m:
Workaround a bug where private classes aren't accessible from
classes in the same assembly when that assembly is created by
al.exe. The workaround is to make the class public. The only
assembly which is created by al.exe currently is the mercury std
library.
library/std_util.m:
Implement the MC++ code required for builtin__aggregate to work.
Estimated hours taken: 1
Branches: main
Improve the efficiency and maintainability of the way we handle
commits for the IL back-end.
compiler/ml_code_gen.m:
Delete the IL-specific code for commit handling.
This code belongs in mlds_to_il.m.
compiler/mlds_to_il.m:
Handle do_commit instructions by just doing the equivalent of
"throw new mercury::runtime::Commit();". This is more efficient
than the old code that we used to generate, which would assign
the result of the newobj instruction to a variable or environment
field, only to immediately get it back again.
Estimated hours taken: 5
Branches: main
compiler/ml_code_gen.m:
Back out part of Tyson's earlier change (-r1.90) that was not
documented in the log message, since it breaks the IL back-end;
`cd library; mmc --grade ilc ops.m' fails.
Estimated hours taken: 0.75
Branches: main
Use a new mlds__function_body type to represent function bodies, as the old
usage of maybe/1 was error prone ("no" meant the function had been declared
using :- pragma external, not merely that the body was missing).
compiler/mlds.m:
Add mlds__function_body type.
compiler/ml_code_gen.m:
compiler/ml_code_util.m:
compiler/ml_elim_nested.m:
compiler/ml_optimize.m:
compiler/ml_tailcall.m:
compiler/ml_util.m:
compiler/mlds_to_c.m:
compiler/mlds_to_csharp.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_il.m:
compiler/mlds_to_java.m:
compiler/mlds_to_mcpp.m:
Handle this change.
Estimated hours taken: 1
Branches: main
Fix the handling of commits in .NET.
compiler/ml_code_gen.m:
Initialize (new_object) the commit object just before we throw it.
compiler/ml_elim_nested.m:
Don't initialize the commit object inside the constructor for the
class -- this hard to maintain and may not always be correct.
compiler/mlds_to_il.m:
Fix rval_to_type to correct get the type from var references, and
handle box/unbox and cast unops.
Estimated hours taken: 4
Branches: main
The .NET backend requires that names are not only qualified with their
namespace but the source package the name comes from. In this change we
back out a previous solution to this problem and implement a much
neater solution where we hide the package name in the abstract type
mlds_module_name.
This solution is neater because the package name shouldn't change once
the name is defined. All that we may have to change is the qualifiers
to the name.
compiler/mlds.m:
Add the package name to the abstract type mlds_module_name.
compiler/ml_call_gen.m:
compiler/ml_code_gen.m:
compiler/ml_code_util.m:
compiler/ml_elim_nested.m:
compiler/ml_optimize.m:
compiler/ml_tailcall.m:
compiler/ml_type_gen.m:
compiler/ml_unify_gen.m:
compiler/ml_util.m:
compiler/mlds_to_c.m:
compiler/mlds_to_csharp.m:
compiler/mlds_to_il.m:
compiler/mlds_to_java.m:
compiler/mlds_to_mcpp.m:
compiler/rtti_to_mlds.m:
Back out previous solution.
Estimated hours taken: 16
Branches: main
The .NET backend requires that names are not only qualified with their
namespace but the source package the name comes from. In this change we
add to the name type the name of the source package which this name is
defined in. This change will be needed for implementing foreign_class
in the .NET backend where it will no longer be possible to determine
the package name from the fully qualified name.
compiler/mlds.m:
Add the new field to the mlds__fully_qualified_name type.
compiler/ml_call_gen.m:
compiler/ml_code_gen.m:
compiler/ml_code_util.m:
compiler/ml_elim_nested.m:
compiler/ml_optimize.m:
compiler/ml_tailcall.m:
compiler/ml_type_gen.m:
compiler/ml_unify_gen.m:
compiler/ml_util.m:
compiler/mlds_to_c.m:
compiler/mlds_to_csharp.m:
compiler/mlds_to_il.m:
compiler/mlds_to_java.m:
compiler/mlds_to_mcpp.m:
compiler/rtti_to_mlds.m:
Propogate the changes around.
Estimated hours taken: 5
Branches: main, dotnet-foreign
Minimize the amount of procedure name mangling done by the .NET backend.
compiler/ml_code_gen.m:
compiler/ml_code_util.m:
compiler/ml_elim_nested.m:
compiler/ml_util.m:
compiler/mlds.m:
compiler/mlds_to_c.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_java.m:
compiler/rtti_to_mlds.m:
Add the code_model and a boolean indicating whether this
function (if it is a function) *doesn't* have a return value
(i.e. it has a non-default mode).
Also move is_output_det_function into ml_code_util.m and rename it
ml_is_output_det_function.
compiler/mlds_to_il.m:
Mangle much more carefully. We still mangle in a predictable,
context-insensitive manner, however we take advantage of the
overloading available in the .NET backend to avoid name clashes
in most cases.
Estimated hours taken: 1
Branches: main, dotnet-foreign
compiler/ml_code_gen.m:
Generate foreign language code using MR_Bool instead of bool.
MC++ doesn't like us using "bool", and we should use the typedef
in mercury_types.h instead anyway.
Estimated hours taken: 45
Branches: main
Implement a C# interface for the .NET backend.
To use it, you currently need to set
--backend-foreign-language csharp --use-foreign-language csharp
in your MCFLAGS.
The C# foreign language interface works by introducing a new sort of
MLDS statement called outline_foreign_proc. outline_foreign_proc is expected
to be turned into a separate procedure in a separate file. This is
quite different to normal foreign code which has been renamed as inline
target code, as it is really intended to be generated inline, inside the
generated code.
Because outline_foreign_proc is expected to be generated outside the
normal code, we don't need to generate variable renamings,
initializations, casts and other complicated interfacing code.
Any marshalling is done by the backend, which knows how to marshall
arguments across the boundary into the outline code and back. In the
case of marshalling to C# from the .NET backend, we currently don't do
anything special (part of the point of .NET is that data
representation don't have to change very often just because you are
using different languages, so this is a property we should try to
preserve).
The actual implementation of the foreign code is therefore very simple.
Simply generate an appropriate procedure, and insert the user's code in
the middle.
The bulk of this change to delay the mangling of MLDS var names, so we
can still use the original user's var name when we output the outline
procedure (since the user's foreign code will refer to these var names,
it's important to keep them around).
compiler/foreign.m:
Handle the csharp foreign language.
compiler/globals.m:
Fix an XXX about converting to lowercase to do language name
comparisons.
Add new predicates to make conversion of foreign languages
to strings more uniform.
compiler/handle_options.m:
Don't set backend_foreign_language to the default if it has
already been set by hand.
compiler/ml_call_gen.m:
compiler/ml_code_gen.m:
compiler/ml_code_util.m:
Delay the mangling of MLDS var names by keeping the variable
number around until the output phase.
Slightly generalize the handling of foreign language interfacing.
Handle C# foreign language interfacing.
Add value_output_vars to the ml_gen_info, which are the variables
returned rather than passed by reference. We need to know
these variables for C# interfacing so that we can handle the return
value of the forwarding function.
Mark the beginning and end of the MLDS foreign language processing as
a "sub-module" (in comments at least). Later I may put this code
into a separate module.
Rename some predicates from c_code to foreign_code.
compiler/ml_elim_nested.m:
compiler/ml_optimize.m:
compiler/ml_string_switch.m:
compiler/ml_type_gen.m:
compiler/ml_unify_gen.m:
compiler/ml_util.m:
compiler/rtti_to_mlds.m:
Handle the new var_name type, and the new target_code constructors.
compiler/mlds.m:
Add outline_foreign_proc which is handled differently to the old
target_code (which has been renamed inline_target_code).
Change the definiton for mlds__var_name.
compiler/mlds_to_c.m:
Factor out mlds_output_to_file.
Handle the new var_name type, and the new target_code constructors.
compiler/mlds_to_csharp.m:
A new module to generate C# code suitable for foreign language
interfacing. This is largely lifted from the MC++ code, with a few
changes to the output syntax.
compiler/mlds_to_il.m:
Return the set of foreign languages processed instead of a bool
saying wither MC++ was present. This is so we can generate the
appropriate output .cs or .cpp files, and because we need to keep
track of all the external assembly references we need to put in the
.il file.
Handle the inline_target_code and mlds__var_name changes.
compiler/mlds_to_ilasm.m:
Output .cpp and .cs files conditionally.
Factor out output_to_file.
Move MC++ output code to mlds_to_mcpp.m
compiler/mlds_to_java.m:
Factor out output_to_file.
Handle the new var_name type, and the new target_code constructors.
compiler/mlds_to_mcpp.m:
New file to handle generating MC++ code suitable for foreign language
interfacing.
compiler/options.m:
Add a way of setting the backend-foreign-language option.
compiler/passes_aux.m:
Add output_to_file which is used by the MLDS backend to generate
output files.
compiler/prog_data.m:
Uncomment csharp as a foreign language.
Estimated hours taken: 2
Branches: main, release
compiler/ml_code_gen.m:
Fix a bug that occaisionally caused some type errors in the
generated code for --high-level-code grades (gcc was just issuing
a warning, but lcc was reporting an error message). The bug was
that we were using the wrong type when determining whether or
not a cast was needed for some code emitted for `pragma c_code'
procedures -- the type we need to use is the variable's original
type, not the type after inlining (which can be an instance
of the original type, if the original type is polymorphic).
Estimated hours taken: 4.5
Branches: main
Add the shorthand_goal_expr wrapper type to ease hlds->hlds transformations.
compiler/hlds_goal.m
Create a new type, the `shorthand_goal_expr', for goals kinds that
are implemented by a (ordinary_hlds + shorthand) -> (ordinary_hlds)
transformation. At present, bi_implication is the only kind of
of goal that is implemented in this way.
Moved bi_implication functor from the type goal_expr to the new
shorthand_goal_expr type.
Added the functor shorthand to the goal_expr type.
compiler/*.m
Change switches on hlds_goal_expr that call error when they recognise
`bi_implication' from calling error when they recognise
`bi_implication' to calling error when they recognise `shorthand'.
For all predicates K that
a) switch on hlds_goal_expr and
b) perform non-trivial processing when they recognise
`bi_implication'
change K such that it now calls K_shorthand upon recognising the
functor `shorthand'. Define K_shorthand to switch on
shorthand_goal_expr, where the code for the `bi_implication' case
formerly contained in K is now contained in K_shorthand.
Estimated hours taken: 4.0
Branches: main
Rename foreign_code as foreign_proc where appropriate in the compiler.
The rationale for this change is that it makes maintaining the code much
simpler because it is clear whether `foreign' refers to a slab of code
(foreign_code) or a procedure (foreign_proc).
:- type pragma_foreign_code_attributes
:- type pragma_foreign_proc_attributes
The functors for pragma_type
foreign(Lang, BodyCode)
foreign(Attributes, Name, PredOrFunc, Vars, Varset, Impl)
become
foreign_code(Lang, BodyCode)
foreign_proc(Attributes, Name, PredOrFunc, Vars, Varset, Impl)
And the HLDS goal `pragma_foreign_code' becomes `foreign_proc'.
compiler/*.m:
Update the compiler to use the new names.
Estimated hours taken: 1
Fix a bug that broke tabling for the GCC back-end.
compiler/mlds.m:
Document that `one_copy' (static) variables
must have initializers.
compiler/ml_code_gen.m:
Explicitly initialize the tabling_pointer variables to null.