[Cython] Declaration syntax change

Stefan Behnel stefan_ml at behnel.de
Thu Oct 3 13:34:21 CEST 2013


Robert Bradshaw, 03.10.2013 05:38:
> In thinking about 1.0, this would be a chance to make
> backwards-incompatible changes. One thing that has always bothered me
> is the C-delclarator decoration for specifying complex types.
> Specifically,
> 
>     cdef int *a, b, c, *d[3]
> 
> is IMHO quite ugly but also adds a lot of complexity to the parser.
> What if instead we required
> 
>     cdef int* a
>     cdef int b, c
>     cdef int[3]* d

I think we've tossed this around long enough to consider it set.


> In this case our grammar could be almost identical to the Python
> grammar, with the addition of a "type declaration" that could occur in
> certain situations plus a new type token.

I don't expect the parser/grammar simplifications to be all that large.
There are still cdef functions, C function pointers and typed function
argument lists, for example, which will stay as they are and involve quite
a bit of parsing complexity all by themselves. Only type declaration
statements would benefit.

I guess we should give it a try in a branch to see what the code gain is.
There may still be a couple of nasty little details.


> We could have a period where we warned if declarators were used, or
> simply disallow them outright before changing the meaning.

If that means that people get urged into manually changing their code to
have one variable declaration per line in order to be future proof, then
that's asking a bit too much, I think. Better do a clean cut and provide a
tool that migrates the code to the next Cython major release. We've always
encouraged people not to depend on Cython in released sources, so the
situation is very different from the Py2/3 change where people necessarily
needed to support older versions.


> It'd be easy to create a tool one could run on your sources that would
> "expand" such declarations as well.

Yes, we should definitely provide something here. I'm pretty sure this
change is going to require modifications to almost all Cython code out there.

(Then again, if we actually break all that code anyway, maybe there are
other things to change as well? I'm not aware of any...)

Stefan



More information about the cython-devel mailing list