[m-rev.] for review: pseudo-typeinfo RTTI in Mercury
Peter Ross
pro at missioncriticalit.com
Wed Apr 10 23:45:39 AEST 2002
On Wed, Apr 10, 2002 at 07:00:17PM +1000, Zoltan Somogyi wrote:
>
> For review by anyone. Maybe Pete, since it is mostly for him.
>
> Estimated hours taken: 40
> Branches: main
>
> A step towards RTTI in Mercury.
>
> This step redefines the representation of pseudo-typeinfos inside the
> compiler to be identical to the representation we will need for
> efficient interpretation of RTTI data structures in Mercury. Later
> steps will do likewise for typectorinfos. In the end, we will have two
> implementations of RTTI: the current low-level, very efficient one
> written in C, which will be used by the C backends (both LLDS and
> MLDS), and a new, higher-level one which will use Mercury data
> structures and Mercury predicates for interpretation (along the lines
> of library/rtti_implementation.m)
> for the Java and IL backends.
>
> A large part of this change concerns the fact that pseudo-typeinfos
> can now contain typeinfos as well as other pseudo-typeinfos, and they
> do in the frequent case that the type of an argument is ground. Given
> that typeinfos are just special cases of pseudo-typeinfos, the code
> for handling the two types is usually similar, with common code
> factored out when relevant.
>
> In the process of redesigning the data structures concerning (pseudo-)
> typeinfos, I also fixed an old naming scheme that has become
> misleading. The representation of a (pseudo-) typeinfo depends on
> whether the principal type constructor is fixed arity or not. We used
> to denote this distinction with the phrases first-order vs
> higher-order, since at first the only variable arity type constructors
> were pred and func. However, this hasn't been true since we added
> tuples. I have changed the naming scheme to be fixed-arity vs
> variable-arity.
>
> compiler/rtti.m:
> Add new, purely Mercury data structures for representing typeinfos
> and pseudo-typeinfos, designed both for efficient interpretation
> and as a source for the generation of static data structures in C.
>
> compiler/pseudo_type_info.m:
> Delete the type definitions here, since they are superseded by the new
> definitions in rtti.m.
>
> Add predicates for constructing typeinfos as well as pseudo-typeinfos,
> since now we need those too.
>
> Conform to the changed data structures for (pseudo-) typeinfos.
>
> compiler/ll_pseudo_type_info.m:
> compiler/ml_closure_gen.m:
> compiler/rtti_out.m:
> compiler/rtti_to_mlds.m:
> compiler/opt_debug.m:
> compiler/type_ctor_info.m:
> Conform to the changed data structures for (pseudo-) typeinfos.
>
> compiler/mlds.m:
> Since the MLDS now refers to type_infos, add their type
> (mlds__type_info_type) to the list of types the MLDS knows about.
>
Is there a reason why you can't just use mlds__rtti_type? I guess you do it
this way because mlds__pseudo_type_info_type appears to be defined specially,
however one can also define a type mlds__rtti_type(pseudo_type_info(...)), so
I am not sure what the correct thing to do is here.
This is my only major issue with this change, otherwise it looks fine.
> compiler/ml_code_util.m:
> compiler/mlds_to_c.m:
> compiler/mlds_to_il.m:
> compiler/mlds_to_java.m:
> Handle mlds__type_info_type.
>
> compiler/mlds_to_gcc.m:
> Conform to the changed data structures for (pseudo-) typeinfos,
> and handle mlds__type_info_type.
>
> runtime/mercury_bootstrap.h:
> Override the compiler-generated names of the type_ctor_infos of the
> variable arity type constructors. The MLDS backend requires these
> to be module qualified; the LLDS backend requires them to be
> unqualified. This is a problem because the same code now generates
> the compiler's internal representation of pseudo-typeinfos for both
> backends.
>
> The temporary solution is to have the compiler generate these names
> module qualified, and have these macros convert them to the unqualified
> form. (The long term solution should be to always module qualify
> everything, but doing that is for another change.)
>
> runtime/mercury_type_info.h:
> Change the naming scheme from first order vs higher order to fixed
> arity vs variable arity.
>
> library/construct.m:
> library/deconstruct.m:
> runtime/mercury.c:
> runtime/mercury_construct.c:
> runtime/mercury_deconstruct.c:
> runtime/mercury_deep_copy_body.h:
> runtime/mercury_make_type_info_body.h:
> runtime/mercury_ml_expand_body.h:
> runtime/mercury_tabling.c:
> runtime/mercury_type_desc.c:
> runtime/mercury_type_info.c:
> runtime/mercury_unify_compare_body.h:
> Conform to the new naming scheme.
>
> runtime/mercury.h:
> Conform to the new naming scheme.
>
> Declare fixed and variable arity types for typeinfos as well as
> pseudo-typeinfos, since pseudo-typeinfos can now refer to typeinfos.
>
> cvs diff: Diffing .
> cvs diff: Diffing bindist
> cvs diff: Diffing boehm_gc
> cvs diff: Diffing boehm_gc/Mac_files
> cvs diff: Diffing boehm_gc/cord
> cvs diff: Diffing boehm_gc/cord/private
> cvs diff: Diffing boehm_gc/doc
> cvs diff: Diffing boehm_gc/include
> cvs diff: Diffing boehm_gc/include/private
> cvs diff: Diffing boehm_gc/tests
> cvs diff: Diffing browser
> cvs diff: Diffing bytecode
> cvs diff: Diffing bytecode/test
> cvs diff: Diffing compiler
> Index: compiler/mlds_to_il.m
> ===================================================================
> RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_il.m,v
> retrieving revision 1.111
> diff -u -b -r1.111 mlds_to_il.m
> --- compiler/mlds_to_il.m 2 Apr 2002 16:36:15 -0000 1.111
> +++ compiler/mlds_to_il.m 3 Apr 2002 06:01:07 -0000
> @@ -2962,6 +2962,9 @@
> mlds_type_to_ilds_type(DataRep, mlds__array_type(ElementType)) =
> ilds__type([], '[]'(mlds_type_to_ilds_type(DataRep, ElementType), [])).
>
> + % XXX should be checked by Tyson
> +mlds_type_to_ilds_type(_, mlds__type_info_type) = il_generic_type.
> +
The only other option is for the type to be a il__object_array_type.
However since plain type infos with an arity of zero are represented by a
System.Object (I think) I guess this will need to be il_generic_type.
> % This is tricky. It could be an integer, or it could be
> % a System.Array.
> mlds_type_to_ilds_type(_, mlds__pseudo_type_info_type) = il_generic_type.
> Index: compiler/rtti.m
> ===================================================================
> RCS file: /home/mercury1/repository/mercury/compiler/rtti.m,v
> retrieving revision 1.17
> diff -u -b -r1.17 rtti.m
> --- compiler/rtti.m 20 Mar 2002 12:37:20 -0000 1.17
> +++ compiler/rtti.m 10 Apr 2002 07:00:22 -0000
> @@ -413,16 +463,21 @@
> methods :: list(rtti_proc_label)
> ).
>
> - % convert a rtti_data to an rtti_type_ctor and an rtti_name.
> + % Convert a rtti_data to an rtti_type_ctor and an rtti_name.
seeing you are already fixing this sentence: s/an /a /g
> @@ -584,16 +673,25 @@
> rtti_name_is_exported(du_ptag_ordered_table) = no.
> rtti_name_is_exported(reserved_addr_table) = no.
> rtti_name_is_exported(type_ctor_info) = yes.
> -rtti_name_is_exported(pseudo_type_info(Pseudo)) =
> - pseudo_type_info_is_exported(Pseudo).
> +rtti_name_is_exported(type_info(TypeInfo)) =
> + type_info_is_exported(TypeInfo).
> +rtti_name_is_exported(pseudo_type_info(PseudoTypeInfo)) =
> + pseudo_type_info_is_exported(PseudoTypeInfo).
> rtti_name_is_exported(base_typeclass_info(_, _, _)) = yes.
> rtti_name_is_exported(type_hashcons_pointer) = no.
>
> -:- func pseudo_type_info_is_exported(pseudo_type_info) = bool.
> +:- func type_info_is_exported(rtti_type_info) = bool.
> +
> +type_info_is_exported(plain_arity_zero_type_info(_)) = yes.
> +type_info_is_exported(plain_type_info(_, _)) = no.
> +type_info_is_exported(var_arity_type_info(_, _)) = no.
> +
> +:- func pseudo_type_info_is_exported(rtti_pseudo_type_info) = bool.
> +
> +pseudo_type_info_is_exported(plain_arity_zero_pseudo_type_info(_)) = yes.
> +pseudo_type_info_is_exported(plain_pseudo_type_info(_, _)) = no.
> +pseudo_type_info_is_exported(var_arity_pseudo_type_info(_, _)) = no.
> pseudo_type_info_is_exported(type_var(_)) = no.
> -pseudo_type_info_is_exported(type_ctor_info(_)) = yes.
> -pseudo_type_info_is_exported(type_info(_, _)) = no.
> -pseudo_type_info_is_exported(higher_order_type_info(_, _, _)) = no.
>
Why are only the zero arity types exported?
The question is purely for improving my understanding of what is going on.
> Index: compiler/rtti_to_mlds.m
> ===================================================================
> RCS file: /home/mercury1/repository/mercury/compiler/rtti_to_mlds.m,v
> retrieving revision 1.29
> diff -u -b -r1.29 rtti_to_mlds.m
> --- compiler/rtti_to_mlds.m 20 Mar 2002 12:37:21 -0000 1.29
> +++ compiler/rtti_to_mlds.m 21 Mar 2002 00:45:38 -0000
> @@ -459,9 +486,16 @@
> % corresponding to the type which they are for.
> %
> (
> + (
> + RttiName = type_info(TypeInfo),
> + ( TypeInfo = plain_type_info(_, _)
> + ; TypeInfo = var_arity_type_info(_, _)
> + )
> + ;
> RttiName = pseudo_type_info(PseudoTypeInfo),
> - ( PseudoTypeInfo = type_info(_, _)
> - ; PseudoTypeInfo = higher_order_type_info(_, _, _)
> + ( PseudoTypeInfo = plain_pseudo_type_info(_, _)
> + ; PseudoTypeInfo = var_arity_pseudo_type_info(_, _)
> + )
> )
> ->
> ModuleName = ThisModuleName,
The indentation here is a bit screwy, please fix if it is not an
artifact from diff.
> Index: runtime/mercury_bootstrap.h
> ===================================================================
> RCS file: /home/mercury1/repository/mercury/runtime/mercury_bootstrap.h,v
> retrieving revision 1.28
> diff -u -b -r1.28 mercury_bootstrap.h
> --- runtime/mercury_bootstrap.h 27 Mar 2002 07:21:45 -0000 1.28
> +++ runtime/mercury_bootstrap.h 9 Apr 2002 06:57:39 -0000
> @@ -16,19 +16,23 @@
> #define MERCURY_BOOTSTRAP_H
>
> /*
> -** This stuff is enabled by default,
> -** but you can disable it by defining MR_NO_BACKWARDS_COMPAT.
> +** These will be needed until we regularize the module-qualification
> +** of builtin types.
> */
>
> -#ifndef MR_NO_BACKWARDS_COMPAT
> +#define mercury_data_builtin__type_ctor_info_func_0 \
> + mercury_data___type_ctor_info_func_0
> +#define mercury_data_builtin__type_ctor_info_pred_0 \
> + mercury_data___type_ctor_info_pred_0
> +#define mercury_data_builtin__type_ctor_info_tuple_0 \
> + mercury_data___type_ctor_info_tuple_0
>
> /*
> -** The next two #defines are needed for bootstrapping the new type constructor
> -** structure.
> +** This stuff is enabled by default,
> +** but you can disable it by defining MR_NO_BACKWARDS_COMPAT.
> */
>
> -#define MR_TypeCtorInfo_struct MR_TypeCtorInfo_Struct
> -#define MR_NewTypeCtorInfo_struct MR_TypeCtorInfo_Struct
> +#ifndef MR_NO_BACKWARDS_COMPAT
>
> /*
> ** bool, TRUE and FALSE appear in the generated code.
The removal of the above two #defines isn't mentioned in the log message.
--------------------------------------------------------------------------
mercury-reviews mailing list
post: mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the reviews
mailing list