[m-dev.] for review: MR_TypeInfo cleanup, part 1
Tyson Dowd
trd at cs.mu.OZ.AU
Thu Mar 23 00:12:22 AEDT 2000
On 22-Mar-2000, Zoltan Somogyi <zs at cs.mu.OZ.AU> wrote:
> This is for Tyson.
It's just like Christmas again.
> Eliminate the code duplication between the implementation of unify
> and compare, which do very similar jobs, by putting the common code
> into the new file mercury_unify_compare_body.h, and including it three times in two different #define contexts. The third time is for defining
> the body of a C function which does the same thing as compare. This
> is necessary for unification and comparison by RTTI, since the
> unification or comparison of two structured terms requires comparing
> their subterms. (There is no need for a separate C function for
> unification; the C comparison function is sufficient.)
You probably want to re-wrap that paragraph.
>
> mercury_unify_compare_body.h has conditional support for unification
> and comparison by RTTI. Although this has been tested and is known
> to work, it is turned off for the moment. This may change after
> benchmarking.
>
> runtime/Mmakefile:
> Add the new include files to the list.
>
> library/std_util.m:
> Rename type_info to type_desc and type_ctor_info to type_info_desc.
> Document their representations.
This is a non-backwards compatible change in a public interface.
Anyone who has written code that refers to `type_info' will have their
code broken by this change.
You should put a public equivalence that type_info == type_desc for
a while (probably until after our next release).
We don't have a way of obsoleting types at the moment, so a comment
saying that std_util:type_info is obsolete would be good too.
I know you are going to move this stuff and redefine it, but the
equivalence will have to stay in std_util with the comment anyway,
so it won't hurt to put it in now (and might help people using the
rotds).
Also you need a NEWS entry (although since you're planning on moving
this stuff, it doesn't matter at this stage).
> tests/hard_coded/existential_rtti.{m,exp}:
> Make the test tougher by printing out now just one deconstructed term,
> but deconstructed versions of all the terms created by this test.
s/now/not
> +/* The `#ifndef ... #define ... #endif' guards against multiple inclusion */
> +#ifndef ML_TYPECTORDESC_GUARD
> +#define ML_TYPECTORDESC_GUARD
> +
> +/*
> +** Values of type `std_util:type_desc' are represented the same way as
> +** values of type `private_builtin:type_info'. Some parts of the library
> +** (e.g. the gc initialization code) depend on this.
> +**
> +** Values of type `std_util:type_ctor_desc' are not guaranteed to be
> +** represented the same way as values of type `private_builtin:type_ctor_info'.
> +** The representations *are* in fact identical for first order types, but they
> +** differ for higher order types. Instead of a type_ctor_desc being a structure
> +** containing a pointer to the type_ctor_info for pred/0 or func/0 and an
> +** arity, we have a single small encoded integer. This integer is double
> +** the arity, plus zero or one; plus zero encodes a predicate, plus one encodes
> +** a function.
> +**
> +** The maximum arity that can be encoded should be set to twice the maximum
> +** number of general purpose registers, since an predicate or function having
> +** more arguments that this would run out of registers when passing the input
> +** arguments, or the output arguments, or both.
> +*/
It's probably a good idea to add an XXX at this point saying that the
type_desc for type_info probably needs to be specially handled because
it lies about its arity.
> @@ -2117,45 +2075,52 @@
> ** calls to this function.
> */
>
> -Word
> -ML_make_type(int arity, MR_TypeCtorInfo type_ctor, Word arg_types_list)
> +MR_TypeInfo
> +ML_make_type(int arity, MR_TypeCtorDesc type_ctor_desc, Word arg_types_list)
> {
> - int i, extra_args;
> - Word type_ctor_info;
> + MR_TypeCtorInfo type_ctor_info;
> + Word *new_type_info_arena;
> + MR_TypeInfo *new_type_info_args;
> + int i;
>
> /*
> ** We need to treat higher-order predicates as a special case here.
> */
> - if (MR_TYPECTOR_IS_HIGHER_ORDER(type_ctor)) {
> - type_ctor_info = MR_TYPECTOR_GET_HOT_TYPE_CTOR_INFO(type_ctor);
> - extra_args = 2;
> +
> + if (MR_TYPECTOR_DESC_IS_HIGHER_ORDER(type_ctor_desc)) {
> + type_ctor_info = MR_TYPECTOR_DESC_GET_HOT_TYPE_CTOR_INFO(
> + type_ctor_desc);
> +
> + restore_transient_registers();
> + /* XXX should use incr_hp_msg() here */
> + incr_hp(LVALUE_CAST(Word, new_type_info_arena),
> + MR_higher_order_type_info_size(arity));
> + save_transient_registers();
> + MR_fill_in_higher_order_type_info(new_type_info_arena,
> + type_ctor_info, arity, new_type_info_args);
Did you plan to fix these XXXs before committing (there's another one
further down)?
Other than that I don't have any particular problems with this section.
Tyson.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to: mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions: mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------
More information about the developers
mailing list