Stefan Behnel wrote:
> Dag Sverre Seljebotn wrote:
>   
>> Is it impossible for constant folding to happen before type annotation?
>> After all, the type should be hard-coded in the class for constants?
>>     
>
> Not sure. At least, it needs scope and target type information in its
> current way of working, as it does type coercions. It might be possible to
> remove that completely, and to determine the widest target type of two
> operands instead. Want to have fun giving it a try? :)
>   
Unfortunately email activity == procrastination != real opportunity for 
Cython activity; at least for the rest of this week. (And unfortunately 
procrastination doesn't work the way that one can simply "bottle it up" 
and use it for real coding :-) ).

(I think that when I get a peaceful Cython moment, I'll focus on e.g. 
getting more nodes over to new temps; the constant folding has a 
learning curve and I should focus on the 0.12 stuff which doesn't 
involve a learning curve first; more effective use of manpower that way.)
>
> BTW, I'm not sure how type casts should be handled. What about something
> like this:
>
>     cdef int x = 3 + <long><char>(2**10)
>   
This is asking for a wraparound if you ask me. I'd say 2**10 folds, then 
leave it to runtime, because we cannot know the type sizes (at least of 
long).
> ? Whereas
>
>     cdef int x = 3 + <int>(2**10)
>
> would simplify just fine...
>   
However,
cdef long x = 3 + <long>(2**34)

would simplify fine on non-Windows 64-bit but not otherwise. I'd be 
reluctant to simplify casts at all because the only intention I can find 
in code like that is to do a "& MAX_VALUE_OF_TYPE", and that stuff is 
much better left to the compiler.

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

Reply via email to