Craig, I hope you don't mind if I send my reply to cython-dev.

Craig Citro, 14.07.2010 22:45:
> So Robert and I chatted about this over lunch -- we came up with a
> very different fix, which was along these lines: we want to do a
> source->source transformation (actually implemented with
> ParseTreeFragments) early on in the pipeline, and then let the type
> analysis/temp allocation/etc get handled automagically.

This can be done in some but not many cases, and it's not easy. One of the 
problems is that some information that has an impact on the optimisation is 
context specific and is just not known before type analysis. In most cases, 
nodes and their results have to be reused, and there isn't currently a good 
way to do that, especially not before type inference and analysis, which 
may end up wanting to assign different types to the same node result in the 
different contexts.

I had started thinking about this more than once already. There's a 
transform called EarlyReplaceBuiltinCalls, for example, which tries to do 
some of the tree restructuring before type analysis, but all(?) of the 
later optimisations in OptimizeBuiltinCalls just don't fit in there, as 
they need too many details about the types they work on.

The min/max issue at hand is also a serious one, as it shows that the reuse 
of node results can be truly hard to get right w.r.t. ref-counting across 
multiple reassignments from different types.

That being said, any additional transformation that we can move before type 
analysis is certainly worth it, and any infrastructure that we can build up 
for that is a major step forward.

Also note that we decided to modify the type analysis step into a 
transform-like operation that is allowed to replace the current node based 
on the type that was determined for the original AST nodes. This would 
actually combine the best of both worlds: enough type information to take a 
decision, but at a point where the rest of the type analysis can still 
react on it.


> Robert also
> noticed a clever way to thread the type information back through to
> avoid extra conversions, which would be another bonus.

Happy to hear more.

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

Reply via email to