[Cython] Some more optimisations
Stefan Behnel
stefan_ml at behnel.de
Fri Feb 1 11:59:20 CET 2008
Hi,
Martin C. Martin wrote:
> Stefan Behnel wrote:
>
>> One thing I'm not sure about is how to propagate undeclared function
>> result
>> types. If we can figure out what type a function has, we can use that
>> type.
>> But the function might be declared later in the code, so we wouldn't
>> have that
>> information early enough. I think that's where two passed are required.
>
> I think you're absolutely right, and that's the standard answer to this.
Now that I give it another thought, there's one very ugly thing to deal with.
Imagine this:
cdef f1(a):
d = f2(a)
d[1] = 1
return d
cdef f2(a):
d = f3(a)
d[2] = 2
return d
cdef f3(a):
d = f4(a)
d[3] = 3
return d
cdef f4(a):
return {4:a}
Here, we will traverse all functions, and at the last one, we can decide that
f4 will always return a dict. Then, we traverse again, and we can decide that
f3 will always return a dict, and so on.
That would let us run through as many passes as we have functions.
We could use something like 'dependent' types, i.e. types that depend on the
result of something that we do not know yet. But that would still require us
to do at least two passes, one to find out what's going on outside and one
that tells what's happening inside. And if the thing that happens inside
changes the way things look to the outside world - bad luck...
Couldn't someone just write code for this? ;)
Stefan
More information about the Cython-dev
mailing list