Stefan Behnel wrote: > Jason Evans wrote: >> Using the latest cython-dev, the following program causes a C compiler >> warning: >> >> --------------------------------------------------------------------- >> cdef foo(): >> cdef x = 42 >> >> if x == 42 and x == 43: >> print "foo" >> >> foo() >> --------------------------------------------------------------------- >> foo.c: In function ‘__pyx_f_3foo_foo’: >> foo.c:214: warning: unused variable ‘__pyx_3’ > > I've seen things like this happen when the switch transform optimisation > hits. It can leave already allocated temp variables unused.
However x isn't C-typed so the switch transform shouldn't kick in here? > Does anyone know if there is an easy way to move the temp allocation to a > later time in cases like this? It would be best to move it after the tree > optimisation transformations. First of all, temp allocation is a bit fragile, and I strongly recommend waiting until after the release before fixing this one. There's plans to move all temp allocation to code generation. There's two things one can use, depending on the case: 1) Manually allocated temps can be allocated through the code.funcscope object instead of the env object 2) I made a transition class "NewTempExprNode" (near top of ExprNodes.py) which does temp allocation during code generation, after all tranforms have been run. To start having the temporary result of an expression node be allocated later in the pipeline, the class should simply inherit from NewTempsExprNode rather than ExprNode. This does however not work with some expression nodes which makes assumptions about earlier availability of the temp expression, which have to be refactored and/or rewritten first. Once all ExprNodes works using this node as ancestor, its alternative temp implementation should be folded into ExprNode and the class removed. -- Dag Sverre _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
