[Cython] [Bug] Generator comprehension not compiling

Carlos Pita carlosjosepita at gmail.com
Sun Oct 25 14:20:42 EDT 2015


Hi,

I've been doing some debugging. The problem here is that the cfunc
directive forces an AdjustDefByDirectives visit. This is ok for the f node
but not for the genexpr DefNode (i.e. node.body.stats[0].expr.args[0].def_node,
where node is the f node) which inherits the cfunc directive from f and is
also (but wrongly) transformed to a CFuncDefNode.

I'm not sure whether there is a valid use case for inheriting cfunc or not.
The current implementation just set the visitor directives attribute to the
directives in a CompilerDirectivesNode, so the same directives are active
for the entire recursive descent. An alternative is to look at
node.directives (when available) instead of visitor.directives, this in
cases for which directive inheritance is undesirable. Here [1] is a PR that
does what I've just described, but only for cfunc. I consider it a dirty
hack until more general criteria are discussed and adopted (for example, it
seems inconsistent to me doing this for cfunc and not for ccall).

Cheers
--
Carlos

[1] https://github.com/cython/cython/pull/459



On Fri, Oct 16, 2015 at 3:53 PM, Carlos Pita <carlosjosepita at gmail.com>
wrote:

> Hi,
>
> in cython 0.24.0a0 this:
>
> ----------
> import cython as cy
>
> @cy.cfunc
> def f(cats):
>     ''.join(c for c in cats)
> ----------
>
> fails to compile with: Compiler crash in AnalyseDeclarationsTransform.
>
> Nevertheless the following close variations do compile:
>
> ----------
> import cython as cy
>
> @cy.cfunc
> def f(cats):
>     ''.join([c for c in cats])
> ----------
>
> ----------
> cdef f(cats):
>     ''.join(c for c in cats)
> ----------
>
> Cheers
> --
> Carlos
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cython-devel/attachments/20151025/3bbd2126/attachment.html>


More information about the cython-devel mailing list