Thanks Kurt. That was helpful. Looks like the optimization is happening at IterationTransform() in the pipeline.
On Wed, Mar 18, 2009 at 9:59 PM, Kurt Smith <[email protected]> wrote: > 2009/3/18 Anoop Saldanha <[email protected]>: > > [snip] > > > > > But > > > > cdef int g(): > > print "g called" > > return 5 > > > > def f(): > > cdef int i > > for i in range(g()): > > print i > > print i > > > > uses a ForFromStatNode for the "for in" loop! > > I'm not a core developer, so this is open to correction, but putting > in some PrintTree() calls into > Cython/Compiler/Main.py:create_pipeline() shows that it starts out as > a ForInStatNode and is changed to a ForFromStatNode. Perhaps because > cython inferrs that g returns a C int and it triggers the 'range' > optimization. > > Before any transformations: > > - (root): ModuleNode(pos=(foo.pyx:1:0)) > - body: StatListNode(pos=(foo.pyx:1:0)) > - stats[0]: CFuncDefNode(pos=(foo.pyx:1:5)) > [removing cdef int g() stuff] > - stats[1]: DefNode(name="f") > - body: StatListNode(pos=(foo.pyx:6:4)) > - stats[0]: CVarDefNode(pos=(foo.pyx:6:9)) > - base_type: CSimpleBaseTypeNode(pos=(foo.pyx:6:9)) > - declarators[0]: CNameDeclaratorNode(pos=(foo.pyx:6:13)) > - stats[1]: ForInStatNode(pos=(foo.pyx:8:4)) <== starts out as > as ForInStatNode > [snip rest of def f() function body] > > After all transformations: > > - (root): ModuleNode(pos=(foo.pyx:1:0)) > - body: StatListNode(pos=(foo.pyx:1:0)) > - stats[0]: CFuncDefNode(pos=(foo.pyx:1:5)) > [snip func body] > - stats[1]: DefNode(name="f") > - body: StatListNode(pos=(foo.pyx:6:4)) > - stats[0]: ForFromStatNode(pos=(foo.pyx:8:4)) <== Changed to > a ForFromStatNode. > - target: NameNode(type=<CNumericType int>, name="i") > - bound1: IntNode(type=<CNumericType long>) > - bound2: SimpleCallNode(type=<CNumericType int>) > - function: NameNode(type=<CFuncType <CNumericType int> > []>, name="g") > - step: IntNode(type=<CNumericType long>) > - body: StatListNode(pos=(foo.pyx:9:8)) > - stats[0]: PrintStatNode(pos=(foo.pyx:9:8)) > - arg_tuple: TupleNode(type=<PyTuple_Type>) > - args[0]: CoerceToPyTypeNode(type=<PyObjectType>) > - arg: NameNode(type=<CNumericType int>, name="i") > - stats[1]: PrintStatNode(pos=(foo.pyx:10:4)) > - arg_tuple: TupleNode(type=<PyTuple_Type>) > - args[0]: CoerceToPyTypeNode(type=<PyObjectType>) > - arg: NameNode(type=<CNumericType int>, name="i") > > Kurt > _______________________________________________ > Cython-dev mailing list > [email protected] > http://codespeak.net/mailman/listinfo/cython-dev > -- Regards, Anoop S. People who says, "It's not winning or losing that matters, but participation", probably lost.
_______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
