Estimated hours taken: 1.5
Add version information to type_ctor_infos. This way bootstrapping is
easier and binary compatibility can be broken more slowly.
RTTI code can check version numbers before performing operations on
data structures that have recently changed their representation.
At the least they can abort cleanly and let you know that it's time
to re-compile, at best they can handle both forms of the data structure.
It is a bootstrapping problem that currently there is no version number
information in the appropriate slot in pre-built systems.
The version numbers start at 2 simply because 2 "occurs naturally"
much less often than 1 or 0. And 42 was becoming trite.
compiler/base_type_info.m:
Generate RTTI version numbers in compiler-generated
type_ctor_infos.
library/builtin.m:
library/private_builtin.m:
library/std_util.m:
runtime/mercury_bootstrap.c:
runtime/mercury_type_info.c:
Add RTTI version numbers for handwritten type_ctor_infos.
runtime/mercury_type_info.h:
Add MR_RTTI_VERSION to define the current version of the RTTI
info and the first version: MR_RTTI_VERSION_INITIAL which
happens to have the value of 2.
Estimated hours taken: 0.25
runtime/mercury_bootstrap.c:
Fix a problem where it was getting compile errors in grades
`jump' and `fast', due to use of the ENTRY() macro in initializers.
Also fix a warning about "no previous prototype" for call_engine().
Estimated hours taken: 16
Add support for Mercury exception handling to call_engine().
Currently that support is not yet used, but the idea is to eventually
use this to e.g. allow Mercury exceptions to be automatically
converted into C++ exceptions when you export a Mercury procedure
to C++.
runtime/mercury_stacks.h:
Add stuff for exception handling, adapted from code in
library/exception.m, for use by mercury_engine.c.
runtime/mercury_engine.c:
Rename call_engine as MR_call_engine().
Add a new parameter `bool catch_exceptions', and change
the result type from `void' to `Word *'.
If the catch_exceptions is true, then it installs an exception handler
to catch Mercury exceptions and returns the Mercury exception thrown,
if any.
runtime/mercury_engine.h:
Add a new field e_exception to the MercuryEngine structure.
This thread-local variable is used to hold the Mercury exception
object thrown, if any, when call_engine_inner() returns via longjmp().
Update the prototype for call_engine() to match its new
MR_call_engine() interface.
runtime/mercury_bootstrap.c:
Add a definition of call_engine() that calls MR_call_engine(),
for bootstrapping.
runtime/mercury_wrapper.c:
runtime/mercury_thread.c:
compiler/export.m:
Call MR_call_engine() rather than call_engine().
runtime/mercury_wrapper.c:
Ensure that we do not clobber the value of MR_curfr in do_interpreter,
since it may be needed for the exception handler frame in
MR_call_engine() if do_interpreter were invoked via
MR_call_engine(ENTRY(do_interpreter), TRUE).
library/exception.m:
Simplify the code for the different builtin_catch procedures by
using the MR_create_exception_handler() macro defined in
mercury_stacks.h (this avoids quite a bit of code duplication
in the old code).
Modify the code for builtin_throw to allow the exception handler
to be C code; in that case, we save the exception object
in the e_exception field of the MercuryEngine and then jump to
the exception handler using longjmp().
Estimated hours taken: 16
Changed all type_ctor_info structures to use the MR_TypeCtorInfo type. This
is primarily to reduce the number of conflicts when merging independent
changes to the type_ctor_info structures. As part of this, changed the type
of `string_const' to be `String' rather than `Word *', to avoid type errors
in the initialisers for compiler-generated type_ctor_infos.
compiler/llds_out.m:
Don't emit definitions for type_ctor_info structs; instead use
`MR_TypeCtorInfo_struct'.
Removed a couple of casts of `string_const's to type `String', since
they are no longer necessary.
compiler/llds.m:
Changed the entries for `string_const' and `multi_string_const' in
llds__const_type/2 to be `string' rather than `data_ptr'.
library/array.m:
library/builtin.m:
library/private_builtin.m:
library/std_util.m:
runtime/mercury_bootstrap.c:
runtime/mercury_type_info.c:
Changed all the hand-defined type_ctor_info structures to just use
`MR_TypeCtorInfo_struct', and added appropriate casts to the
initialisers. This included removing what appears to have been the
last vestiges of `USE_TYPE_LAYOUT' conditionals since their use was
so broken that it would probably be easier to re-implement the same
functionality from scratch than to debug and rebuild on what was left.
runtime/mercury_type_info.h:
Introduced `struct MR_TypeCtorInfo_struct' as the name of the
(previously anonymous) struct which `MR_TypeCtorInfo' was a pointer
to.
Introduced `MR_DECLARE_TYPE_CTOR_INFO_STRUCT' for declaring
type_ctor_info structures, since `MR_DECLARE_STRUCT' generates
old-style names for type_ctor_infos.
runtime/mercury_deep_copy.c:
runtime/mercury_tabling.c:
library/std_util.m:
extras/exceptions/exception.m:
Changed some uses of `MR_DECLARE_STRUCT' to use
`MR_DECLARE_TYPE_CTOR_INFO_STRUCT' instead.
runtime/mercury_bootstrap.h:
Added some `#define's of some old type_ctor_info type names to be
`MR_TypeCtorInfo_struct', so that during bootstrapping the type
names generated by the old version of the compiler work with the new
scheme used in the manual definitions.
runtime/mercury_string.h:
Changed the type of the macro `string_const/2'. It used to cast to
`Word *', now it casts to `String'.
Estimated hours taken: 4
Fix a bug that was causing the compiler to fail the debugger
tests with an unknown layout error. std_util:type_info/0 needs
to be defined by hand so we can tell the RTTI system that it is
a type_info.
This change breaks bootstrapping with earlier compilers.
Use the CVS tag bootstrap_19990719_handdefine_typeinfo to
bootstrap this change.
compiler/type_util.m:
Add std_util:type_info/0 to the hand defined types.
This is different to private_builtin:type_info/1 which
was already there. It was type_info/0 that the debugger
was failing on.
library/builtin.m:
Move the type_ctor_info for c_pointer back into this module.
It should have finished bootstrapping by now.
library/std_util.m:
Define type_ctor_info as (abstractly) equivalent to a type_info
instead of equivalent to a c_pointer. This will allow this type
to be handled by the garbage collector or debugger.
runtime/mercury_bootstrap.c:
Move the RTTI info for c_pointer out of this module.
Add the type_ctor_info for type_info/0 as it is now a hand
defined type.
tests/hard_coded/higher_order_type_manip.exp:
Fix expected test results not that type_ctor_info is equivalent
to type_info/0.
Estimated hours taken: _____
<overview or general description of changes>
<directory>/<file>:
<detailed description of changes>
Estimated hours taken: 30 (including debugging)
Add MR_TYPECTOR_REP_* to the type_ctor_info to describe the
representation of this type.
We want to do this because it allows us to check quickly to see
what kind of data representation is being used. Previously this
information was spread throughout the type_ctor_layout and
type_ctor_functors data structures. It was complex to interpret
and contained a lot of unnecessary duplication.
We can now omit data structures such as the type_ctor_layout in many
cases (it is only necessary for discriminated unions). Because we rule
out some of the possible alternatives, the encodings used in the
type_ctor_layout can be simplified. Also, the functors indicator in
type_ctor_functors can be removed, as it subsumed by this data
structure.
Use this representation in code that uses RTTI.
compiler/base_type_info.m:
Add a missing alternative to the type_ctor_rep (this was a
bug).
library/array.m:
library/builtin.m:
library/private_builtin.m:
runtime/mercury_bootstrap.c:
Use MR_TYPECTOR_REP_* in the type_ctor_infos for builtin types.
library/std_util.m:
runtime/mercury_deep_copy_body.h:
runtime/mercury_tabling.c:
Use MR_TYPECTOR_REP_* and MR_DISCUNION_TAG_* to dispatch on
data representations.
Also, fix a bug in deep_copy when copying floating point values.
I'm not sure when this stopped working, or if this is exactly
the right fix, but it is more correct than the previous code.
runtime/mercury_type_info.c:
runtime/mercury_type_info.h:
Update code to use MR_TYPECTOR_REP_*.
Use a struct for type_ctor_info.
tests/hard_coded/Mmakefile:
tests/hard_coded/deep_copy.m:
tests/hard_coded/deep_copy.exp:
Add a test case for deep_copy.
Estimated hours taken: 1
runtime/mercury_bootstrap.c:
Fix a bug: the INIT line was missing the `_bootstrap' suffix that
is needed to distinguish this module from the real one.
This was causing the initialization for unify_c_pointer_module()
to be run twice, rather than having it run once and having the
initialization for unify_c_pointer_module_bootstrap() run once.
This in turn caused the Mercury profiler to fail.
Also the function sys_init_unify_c_pointer_module_bootstrap()
was missing, so I added a definition for it.
Estimated hours taken: 0.5
c_pointer needs to be a hand defined type -- up until now everything but
the type_ctor_info is hand defined. We need to be able to change the
contents of the type_ctor_info, however.
compiler/type_util.m:
library/builtin.m:
runtime/mercury_bootstrap.c:
Make builtin:c_pointer a hand-defined type, doing the usual
bootstrapping trick.
Estimated hours taken: 0.5
Move the type_ctor_infos for array and univ into their proper places.
This change has bootstrapped on most of our platforms, but actually
causes trouble linking small programs (because it creates runtime ->
library dependencies). So we should move it as soon as possible.
library/array.m:
library/std_util.m:
Add type_ctor_info for array and univ.
runtime/mercury_bootstrap.c:
Remove type_ctor_info for array and univ.
Estimated hours taken: 2
Making changes to type_ctor_infos for the builtin types array and univ
is much easier if we can simply change their type_ctor_info by hand
rather than detecting them as simple cases. They already have their
type_ctor_functors and layouts defined by hand anyway.
compiler/type_util.m:
Turn off the generation of type_ctor_info for the types array:array
and std_util:univ.
runtime/mercury_bootstrap.c:
Put type_ctor_infos for these types into the bootstrapping file.
They are not needed (or wanted) for stage 1, but needed for stage 2.
We rename the functors and layouts slightly so that the stage 2
linking doesn't have them multiply defined.
Estimated hours taken: 0.3
library/private_builtin.m:
runtime/mercury_bootstrap.c:
Move the type_ctor_infos for typeclass_info and base_typeclass_info
into private_builtin since they have almost certainly
bootstrapped by now (they have been there since November).
Estimated hours taken: 7
Start the changes needed to simplify type_ctor_*.
This simplification involves lifting the most important information
about the type representation out of type_ctor_layout and
type_ctor_functors and putting it into type_ctor_info. In many
cases this will mean we can do without type_ctor_layout altogether,
and we will be able to remove the "functors indicator" from
type_ctor_functors. The type_ctor_layout can be simplified quite a bit
because it only needs to describe discriminated unions.
compiler/base_type_info.m:
compiler/base_type_layout.m:
compiler/dead_proc_elim.m:
compiler/hlds_data.m:
compiler/hlds_module.m:
compiler/polymorphism.m:
Add code to generate the new MR_TypeCtorRepresentation
field.
Don't actually generate it yet, we need to bootstrap this
change. So we create two references to type_info_layouts
instead. When the compiler has bootstrapped we can change
the runtime to use the later reference, and convert the
earlier reference into MR_TypeCtorRepresentation.
library/builtin.m:
library/private_builtin.m:
runtime/mercury_bootstrap.c:
runtime/mercury_type_info.c:
Add the new field to type_ctor_infos defined in C.
Fix a few minor bugs with these type_ctor_infos (incorrect
lengths of string constants, lingering references to
term_to_type preds.
runtime/mercury_type_info.h:
Move the offset for type name and module name down one.
This won't cause any bootstrapping problems because the compiler
barely uses such names.
Add new types:
MR_TypeCtorInfo
This struct will replace MR_TYPE_CTOR_INFO_*
macros and offsets.
MR_TypeCtorRepresentation
MR_DiscUnionTagRepresentation
Will replace the more expensive to compute
MR_DataRepresentation.
Estimated hours taken: 8
During the writing of the RTTI paper, we decided that type_ctor_info
was a much better name than base_type_info.
Rename base_type* as type_ctor*, except we don't rename the modules
base_type_info and base_type_layout just yet.
Most of these changes were made using the following sed patterns:
s/base_type_info/type_ctor_info/g
s/base_type_layout/type_ctor_layout/g
s/base_type_functors/type_ctor_functors/g
s/BASETYPE_INFO/TYPE_CTOR_INFO/g
s/TYPEFUNCTORS/TYPE_CTOR_FUNCTORS/g
s/TYPELAYOUT/TYPE_CTOR_LAYOUT/g
s/BASE_TYPEINFO/TYPE_CTOR_INFO/g
s/BASE_TYPE_INFO/TYPE_CTOR_INFO/g
s/BaseTypeInfo/TypeCtorInfo/g
s/BaseTypeLayout/TypeCtorLayout/g
s/base_type(/type_ctor(/g
s/:- module type_ctor_info/:- module base_type_info/g
s/:- module type_ctor_layout/:- module base_type_layout/g
s/type_ctor_info__/base_type_info__/g
s/type_ctor_layout__/base_type_layout__/g
/import_module/s/type_ctor_info/base_type_info/g
/import_module/s/type_ctor_layout/base_type_layout/g
compiler/*.m:
library/*.m:
runtime/*.{c,h}:
profiler/demangle.m:
util/mdemangle.c:
Applied the above sed commands.
runtime/mercury_bootstrap.h:
Add bootstrapping #defines so the type_ctor_* substitutions in
the library don't cause link problems.
Delete some redundant bootstrapping definitions.
Estimated hours taken: 18
Make it possible to compile a module (e.g. std_util) without debugging,
while still allowing debuggable code called from that module via higher-order
predicates (e.g. solutions) to have a proper stack trace.
compiler/options.m:
Add the new option --stack-trace-higher-order.
compiler/mercury_compile.m:
Always invoke continuation_info and stack_layout, since it is no
longer the case that either all procedures or none get layout
structures generated for them, and the other modules are in a better
position to make that decision.
compiler/continuation_info.m:
Handle the extra tests required by the change to mercury_compile.m.
When we gather info about a procedure, remember whether that
procedure must have a procedure layout that includes the procedure id
section.
compiler/stack_layout.m:
Use the flag remembered by continuation_info to help decide
whether we need procedure layout structures.
Fix an old space wastage: after generating marker saying that
the second and later groups of fields of a procedure layout are
not present, do not generate another marker saying that the
third group of fields is not present. Since it was in the wrong
position, it did not have the right meaning; it only worked because,
due to the presence of the first marker, it was never looked at anyway.
compiler/code_gen.m:
Use the new capability of continuation_info.m to require
procedure layouts including procedure id sections for any predicate
that has higher-order arguments, if --stack-trace-higher-order is set.
compiler/globals.m:
Rename want_return_layouts as want_return_var_layouts, since this
is a more accurate representation of what the predicate does.
compiler/call_gen.m:
compiler/code_info.m:
Conform to the change in globals.m.
compiler/llds_out.m:
Separate the c_modules containing compiler-generated code into two
groups, those that define labels that have stack layouts and those
that don't. In most cases one or the other category will be empty,
but with --stack-trace-higher-order, the c_modules containing
higher-order procedures will have stack layouts, while others will
not.
Reorganize the way the way the initialization functions are generated,
by putting c_modules falling into different categories into different
bunches. c_module falling into the first category always have their
initialization code included, while those in the second category
have it included only if the old flag MR_MAY_NEED_INITIALIZATION
is set.
Delete the obsolete #define of MR_STACK_TRACE_THIS_MODULE.
Improve some predicate names, in an effort to prevent confusion
about what a "file" is (since the code uses more than one meaning,
given the presence of --split-c-files).
compiler/pragma_c_gen.m:
Fix an old bug: s/NONDET_FIXED_SIZE/MR_NONDET_FIXED_SIZE/.
Required for the change to library/string.m.
doc/user_guide.texi:
Document the new option.
runtime/mercury_goto.c:
Simplify the conditions under which labels get added to the label
table with:
- The macros init_{entry,label,local}_ai always add
the label to the label table without a layout structure.
- The macros init_{entry,label,local}_sl always add it with a layout
structure.
- Whether the macros init_{entry,label,local} with no suffix
add the label to the label table depends on the values of other
configuration parameters, but they will never include a layout
structure.
The intended use is that any label that has a layout structure should
be initialized with a _sl macro. Any other label that should always
be in the label table if the label table is needed at all (labels
such as do_fail) should be initialized with _ai. Everything else
should be initialized with a suffixless macro.
runtime/mercury_conf_params.c:
Remove MR_USE_STACK_LAYOUTS and MR_STACK_TRACE_THIS_MODULE, since
due to the simplification of mercury_goto.h, they are not used anymore.
runtime/mercury_stack_layout.h:
Remove the old macros for creating layout structures with bogus
contents, and replace them with new macros for creating layout
structures with meaningful contents.
runtime/mercury_engine.c:
runtime/mercury_wrapper.c:
Remove bogus layout structures. Ensure the labels defined here
always get into the label table.
runtime/mercury_ho_call.c:
Remove bogus layout structures. Add proper ones where necessary.
runtime/mercury_bootstrap.c:
runtime/mercury_type_info.c:
Remove bogus layout structures.
runtime/mercury_boostrap.h:
Add this new file for bootstrapping purposes.
Temporarily #define NONDET_FIXED_SIZE as MR_NONDET_FIXED_SIZE, since
pragma_c_gen.m refers to the former until the update to it gets
installed.
runtime/Mmakefile:
Add a reference to mercury_boostrap.h.
library/builtin.m:
Remove bogus layout structures.
library/array.m:
library/benchmarking.m:
library/private_builtin.m:
Remove bogus layout structures. Add proper ones.
library/std_util.m:
Remove bogus layout structures. Add proper ones.
Replace references to framevar(n) with references to MR_framevar(n+1).
Fix an old bug in code under #ifndef COMPACT_ARGS: in the
implementation of mercury____Compare___std_util__univ_0_0_i1, the
succip register was not being saved across the call to
mercury__compare_3_0.
library/string.m:
Remove the need for bogus layout structures, by converting the
implementation of string__append(out, out, in) from hand-written
C module into nondet pragma C code.
Estimated hours taken: 3
Define the types typeclass_info and base_typeclass_info by hand,
so that they can be recognized as special cases in the runtime
system.
At the same time, move the definitions of type_info and base_type_info
back into private_builtin.m. They had been placed in
runtime/mercury_bootstrap for bootstrapping purposes, but have now been
bootstrapped (and will be replaced by typeclass_info which will undergo
the same process).
compiler/base_type_layout.m:
Add typeclass_info to the special cases.
compiler/type_util.m:
Turn off base_type_info generation for typeclass_info
and base_typeclass_info.
library/private_builtin.m:
Move the definitions of type_info and base_type_info to here.
runtime/mercury_bootstrap.c:
Add handwritten definitions of the typeclass_info and
base_typeclass_info types.
runtime/mercury_type_info.c:
runtime/mercury_type_info.h:
Rename all the TYPELAYOUT_*_VALUE #defines as
MR_TYPELAYOUT_*_VALUE enum values. Leave forwarding
definitions for backwards compatability (temporary).
Add MR_TYPELAYOUT_TYPECLASSINFO_VALUE to the MR_TypeLayoutValue.
Add MR_DATAREP_TYPECLASSINFO.
Estimated hours taken: 1
Fix a bootstrapping problem.
runtime/Mmakefile:
runtime/mercury_bootstrap.c:
Add definitions that are generated in stage 1 compiler, but
not stage 2. Since runtime is a library, they will be linked
only if they are not generated.
When the compilers are installed everywhere, this code can
be moved into library/mercury_private_builtin.m.