[m-rev.] for review: make get_functor handle existential types

Ian MacLarty maclarty at cs.mu.OZ.AU
Mon Dec 13 16:51:12 AEDT 2004


On Mon, Dec 13, 2004 at 01:25:01PM +1100, Zoltan Somogyi wrote:

> compiler/ml_util.m:
> compiler/rtti.m:
> compiler/type_ctor_info.m:
> 	Make sure we handle the new builtin type as a builtin type, and not
> 	try to have the compiler create a type_ctor_into for it.

s/type_ctor_into/type_ctor_info

> Index: library/std_util.m
> ===================================================================
> @@ -1707,12 +1708,22 @@
>  
>  get_functor(TypeDesc, FunctorNumber, FunctorName, Arity, TypeInfoList) :-
>  	construct__get_functor(TypeDesc, FunctorNumber, FunctorName,
> -		Arity, TypeInfoList).
> -
> -get_functor(TypeDesc, FunctorNumber, FunctorName, Arity, TypeInfoList,
> -		ArgNameList) :-
> -	construct__get_functor(TypeDesc, FunctorNumber, FunctorName,
> -		Arity, TypeInfoList, ArgNameList).
> +		Arity, PseudoTypeInfoList),
> +	% If a pseudo_type_info in PseudoTypeInfoList is not ground,
> +	% then the resulting TypeInfoList will be silently invalid and
> +	% will cause a core dump sooner or later. This is 

Should there be something after "This is" other than the next line of 
code?

> +	TypeInfoList = list__map(ground_pseudo_type_desc_to_type_desc_det,
> +		PseudoTypeInfoList).
> +
> +get_functor_with_names(TypeDesc, FunctorNumber, FunctorName, Arity,
> +		TypeInfoList, ArgNameList) :-
> +	construct__get_functor_with_names(TypeDesc, FunctorNumber, FunctorName,
> +		Arity, PseudoTypeInfoList, ArgNameList),
> +	% If a pseudo_type_info in PseudoTypeInfoList is not ground,
> +	% then the resulting TypeInfoList will be silently invalid and
> +	% will cause a core dump sooner or later. This is 

And here?

> +	TypeInfoList = list__map(ground_pseudo_type_desc_to_type_desc_det,
> +		PseudoTypeInfoList).
>  
>  get_functor_ordinal(TypeDesc, FunctorNumber, Ordinal) :-
>  	construct__get_functor_ordinal(TypeDesc, FunctorNumber, Ordinal).

> Index: library/term_to_xml.m
> ===================================================================
...
> -:- pred write_dtd_from_type(type_desc::in, 
> +:- pred write_dtd_from_type(type_desc__type_desc::in, 
>  	element_mapping::in(element_mapping), dtd_generation_result::out, 
>  	io::di, io::uo) is det.
>  

It would be better to use dot as a module qualifier here as that is what is
used elsewhere in this module, however I can change this when I update
term_to_xml to use construct.get_functor.

> Index: library/type_desc.m
> ===================================================================
...
>  	% type_ctor(Type) = TypeCtor :-
>  	%	type_ctor_and_args(Type, TypeCtor, _).
>  	%
>  :- func type_ctor(type_desc__type_desc) = type_desc__type_ctor_desc.
>  
> +	% pseudo_type_ctor(Type) = TypeCtor :-
> +	%	type_ctor_and_args(Type, TypeCtor, _).

/s/type_ctor_and_args/pseudo_type_ctor_and_args

> Index: runtime/mercury_ml_expand_body.h
> ===================================================================
...
> +                if (noncanon == MR_NONCANON_ALLOW) {
> +                    /* XXX should be MR_collapse_equivalences_pseudo */

Why isn't it MR_collapse_equivalences_pseudo?

> +                    data_pseudo_type_info = (MR_PseudoTypeInfo)
> +                        MR_collapse_equivalences(
> +                            (MR_TypeInfo) data_pseudo_type_info);
> +                }

> Index: runtime/mercury_type_desc.h
> ===================================================================
...
>  /*
> -** Values of type `types:type_desc' are represented the same way as
> +** Values of type `type_ctor.type_desc' are represented the same way as
>  ** values of type `private_builtin:type_info' (this representation is
>  ** documented in compiler/polymorphism.m). Some parts of the library
>  ** (e.g. the gc initialization code) depend on this.
>  ** The C type corresponding to these Mercury types is `MR_TypeInfo'.
>  **
> -** Values of type `types:type_ctor_desc' are not guaranteed to be
> +** Values of type `type_ctor.pseudo_type_desc' are represented the same way as
> +** values of type `private_builtin:pseudo_type_info' (this representation is
> +** documented in compiler/polymorphism.m).
> +** The C type corresponding to these Mercury types is `MR_PseudoTypeInfo'.
> +**
> +** Values of type `type_ctor.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 fixed arity types, but they
>  ** differ for higher order and tuple 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 four times the arity, plus zero, one or two; plus zero encodes a
> -** predicate, plus one encodes a function, plus two encodes a tuple.
> +** integer is four times the arity, plus zero, one or two; plus zero encodes
> +** a predicate, plus one encodes a function, plus two encodes a tuple.
>  ** The maximum arity that can be encoded is given by MR_MAX_VARIABLE_ARITY
>  ** (see below).
> -** The C type corresponding to types:type_ctor_desc is `MR_TypeCtorDesc'.
> +** The C type corresponding to type_ctor.type_ctor_desc is `MR_TypeCtorDesc'.
>  */

The mix of `.' and `:' module qualifiers in the above comment looks a bit strange.

>  ** Given type_info, return the MR_TypeCtorDesc describing its outermost type
> -** constructor in *type_ctor_desc_ptr and a list of the typeinfos of its
> +** constructor in *type_ctor_desc_ptr and a list of the typei_nfos of its

s/typei_nfos/type_infos

>  /*
> +** Given pseudo_type_info representing a variable, return MR_FALSE. Given a
> +** pseudo_type_info representing a nonvariable type, return MR_TRUE, and
> +** the return MR_TypeCtorDesc describing its outermost type constructor

s/the return/return the

> Index: runtime/mercury_type_info.c
> ===================================================================
...
>  int
> +MR_compare_pseudo_type_info(MR_PseudoTypeInfo pti1, MR_PseudoTypeInfo pti2)
...
> +    if (pti1 == pti2) {
> +        return MR_COMPARE_EQUAL;
> +    }
> +
> +    /*
> +    ** Handle the comparison if either pseudo_type_info is a variable.
> +    ** Any non-variable is greater than a nonvariable
> +    */

Should that be "Any non-variable is greater than a variable."?

> +
> +    if (MR_PSEUDO_TYPEINFO_IS_VARIABLE(pti1) &&
> +        MR_PSEUDO_TYPEINFO_IS_VARIABLE(pti2))
> +    {
> +        if ((int) pti1 < (int) pti2) {
> +            return MR_COMPARE_LESS;
> +        } else if ((int) pti1 > (int) pti2) {
> +            return MR_COMPARE_GREATER;
> +        } else {
> +            return MR_COMPARE_EQUAL;
> +        }
> +    }
> +
> +    if (MR_PSEUDO_TYPEINFO_IS_VARIABLE(pti1)) {
> +        return MR_COMPARE_LESS;
> +    }
> +
> +    if (MR_PSEUDO_TYPEINFO_IS_VARIABLE(pti2)) {
> +        return MR_COMPARE_GREATER;
> +    }
> +
...
> +MR_bool
> +MR_unify_pseudo_type_info(MR_PseudoTypeInfo pti1, MR_PseudoTypeInfo pti2)
...
> +
> +    /*
> +    ** Handle the comparison if either pseudo_type_info is a variable.
> +    ** Any non-variable is greater than a nonvariable
> +    */
> +

Should be: Any non-variable is greater than a variable.

> Index: runtime/mercury_type_info.h
> ===================================================================
> @@ -1484,6 +1523,58 @@
>  /*---------------------------------------------------------------------------*/
>  
>  /*
> +** Compare two pseudo_type_info structures, using an ordering based on the
> +** module names, type names and arities of the types inside the type_info.
> +** Return MR_COMPARE_GREATER, MR_COMPARE_EQUAL, or MR_COMPARE_LESS,
> +** depending on whether pti1 is greater than, equal to, or less than pti2.
> +**
> +** You need to wrap MR_{save/restore}_transient_hp() around
> +** calls to this function.
> +*/
> +
> +extern  int     MR_compare_pseudo_type_info(MR_PseudoTypeInfo pti1,
> +                    MR_PseudoTypeInfo pti2);
> +
> +/*
> +** Unify two pseudo_type_info structures, using an ordering based on the
> +** module names, type names and arities of the types inside the type_info.
> +** Return MR_TRUE if ti1 represents the same type as ti2, and MR_FALSE

s/ti1/pti1 and s/ti2/pti2 or change the prototype below.

> +** otherwise.
> +**
> +** You need to wrap MR_{save/restore}_transient_hp() around
> +** calls to this function.
> +*/
> +
> +extern  MR_bool MR_unify_pseudo_type_info(MR_PseudoTypeInfo pti1,
> +                    MR_PseudoTypeInfo pti2);
> +
> +/*
> +** Compare two pseudo_type_info structures, using an ordering based on the
> +** module names, type names and arities of the types inside the type_info.
> +** Return MR_COMPARE_GREATER, MR_COMPARE_EQUAL, or MR_COMPARE_LESS,
> +** depending on whether ti1 is greater than, equal to, or less than ti2.
> +**
> +** You need to wrap MR_{save/restore}_transient_hp() around
> +** calls to this function.
> +*/
> +
> +extern  int     MR_compare_pseudo_type_info(MR_PseudoTypeInfo ti1,
> +                    MR_PseudoTypeInfo ti2);
> +


Otherwise that looks fine.

Ian.

--------------------------------------------------------------------------
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