[m-rev.] help needed: fix rtti bug
Zoltan Somogyi
zs at cs.mu.OZ.AU
Tue Dec 23 13:51:00 AEDT 2003
On 21-Dec-2003, Fergus Henderson <fjh at cs.mu.OZ.AU> wrote:
> The arity is stored in the first field of the type_info;
> i.e., since the type_info has type Object[], the arity
> will be "(int) type_info[0]".
>
> > +++ library/rtti_implementation.m 19 Dec 2003 10:58:51 -0000
> > @@ -919,7 +919,15 @@
> > type_ctor_name_and_arity(TypeCtorInfo, ModuleName, Name, Arity) :-
> > ModuleName = type_ctor_module_name(TypeCtorInfo),
> > Name = type_ctor_name(TypeCtorInfo),
> > - Arity = type_ctor_arity(TypeCtorInfo).
> > + ( type_ctor_is_variable_arity(TypeCtorInfo) ->
> > + Arity = type_ctor_va_arity(TypeCtorInfo)
> > + ;
> > + Arity = type_ctor_arity(TypeCtorInfo)
> > + ).
>
> The interface to this predicate is wrong. Given a type_ctor, there is
> no way to compute the arity. You need the type_info.
Given a type_ctor, there is no way to compute the arity *in general*.
However, there are only three type_ctors of variable arity: pred, func
and tuple.
I believe the original ancestor of the code above was initially used for
purposes (such as io__read and io__write) that didn't need support for preds
and func, so detecting them and reporting an error was sufficient, and didn't
need knowledge of the arity. The original code didn't worry about tuples
because tuples weren't part of the language at the time.
However, Fergus is right when he condems the code fragment below:
( type_ctor_is_variable_arity(TypeCtorInfo) ->
Arity = type_ctor_va_arity(TypeCtorInfo)
For the three variable arity types, you can't tell the Arity from the
TypeCtorInfo; you need the TypeInfo the TypeCtorInfo came from.
Zoltan.
--------------------------------------------------------------------------
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