[Cython] Assignments in cdefs
Robert Bradshaw
robertwb at math.washington.edu
Wed Jul 23 10:15:59 CEST 2008
On Jul 20, 2008, at 5:51 AM, Dag Sverre Seljebotn wrote:
> Just want to inform you about some particularily intrusive changes on
> cdef variables (see the latest dagss changes). I'll discuss it
> thoroughly because it is a nice example of reducing the number of
> variable assignment cases (more on that in another post). I'd really
> like to have this change go in, but it is not trivial and I can
> understand it if you resist it.
>
> 1) Bug fix: We generated erronous C code for cdef assignments in class
> bodies, I now raise a compiler error on this.
Good. This is actually related to the recent feature request that we
had on default cdef values...
> 2) Basically I turn "cdef int x = 4" into "cdef int x; x = 4".
Nice. This is almost the poster example of turning complex Python
code into simpler statements--well worth it in this case.
> 3) Also I added the "first" attribute to SingleAssignmentNode to
> generalize the concept of first assignment (which takes care of
> optimal
> refcounting). Optimizing first assignments in the more general case is
> now as simple as running through the tree and setting that attribute
> (after analysis, prior to generation), though I didn't do this. This
> kind of clashes with Robert's flow control endaveours, but I feel that
> the beginnings of flow control is overkill for this specific case, a
> single pass with a transform should do it...
I'll be the first to say it, the control flow as it is now is quite
the unfinished hack, and I'm not even sure it's the right way to go.
Really, the only reason it is there is so it can detect when it can
save on increfing the arguments (in other words, detecting if they're
ever assigned to).
Real control flow was one of the things I was most sad about loosing
the other GSoC project...
> Results:
> - C code looks exactly like before (I diffed it), except for comments.
> - The buffer just started working without any extra efforts (and it
> made
> it very easy to optimize some refcounting for buffers, though that
> needed five lines). Of course, this is why I bothered.
> - No CVarDefNode in the tree after analyse_declarations
Yeah, all those decelerator nodes really should go away after the
types are figured out from them.
> As for the code:
> - Removed about 30 lines and added about 40. However I do feel that
> the
> transform code is less "copy-and-paste-with-modifications" and that
> new
> code is more obvious to beginners (Stefan can pull out his article URL
> by now :-)
>
> I'll follow up with another post to discuss assignments in general.
>
>
> --
> Dag Sverre
>
> _______________________________________________
> Cython-dev mailing list
> Cython-dev at codespeak.net
> http://codespeak.net/mailman/listinfo/cython-dev
More information about the Cython-dev
mailing list