On May 15, 2009, at 11:41 AM, Lisandro Dalcin wrote:

> On Fri, May 15, 2009 at 2:03 PM, Dag Sverre Seljebotn
> <[email protected]> wrote:
>> Lisandro wrote:
>>
>> I tried proposing something similar (unknown size) some time ago  
>> and it
>> was voted down; perhaps the climate has changed now.
>
> I voted it down perhaps because I misunderstood your proposal. I
> understood you were proposing this for the whole type system.
>
> If this is done for external ctypedefs, I would no oppose it.

I just don't see how such a construct would be useful. For everything  
that can be deferred to using sizeof (e.g. conversion to/from Python)  
we are moving to using just this, not using the ranking information  
at all, so there's no gain. Now for the stuff where we do use ranking  
information (only temps and type inference come to mind) we either  
use the ranking the user gave (and blame them if they gave it wrong  
enough that it messed them up) or disallow, e.g., all arithmetic  
between unranked and ranked types. Thus

cdef extern from *:
     ctypedef signed unranked int MyInt

cdef MyInt x = 100
print x*5

would be disallowed. You could make an exception for literals, but then

cdef MyInt x = 100
cdef int y = sys.maxint
print x*y

has issues. They could be solved (e.g. doing the a whole if-then list  
on sizeof(MyInt)) but this doesn't seem needed, unless you want to be  
really pedantic.

I just don't see when/why someone would really find this useful,  
perhaps someone could justify it with a good usecase?

>> I support this anyway for more transparency about what Cython does  
>> (though
>> none of those syntaxes), but I don't think it is really needed:
>
> Well, I have a bit of fear of some user coding "cdef extern: ctypedef
> signed long Something" and then Cython stop treating "Something" as
> EXACTLY a "signed long". A user could complain: Hey, I know
> "Something" is EXACTLY a "signed long", Why aren't you using such
> declaration?

If Something is exactly a signed long, it will always be treated and  
behave as so. The only question is what to do if it's not exactly a  
signed long.

>> This only affects situations where the type size is actually used for
>> something. I can only think of constructing temporaries once this  
>> patch
>> goes in.
>>
>> And how many situations can you think of which constructs  
>> temporaries of
>> the type of the result of a binary operation?
>
> What would happen below?
>
> cdef MyInt a, b
> ....
> cdef object o = a BINOP b

A new PyInt_from_MyInt method would be created and called (as you're  
doing now). If a and b were different types, it gets messy,  
especially if things are carried through for a while (e.g. imagine  
"a / b / c / d" where all types are distinct). I say the solution is  
to be more clear about what the ranking information is used for so  
the user can make the declarations appropriately.

- Robert

_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to