[Cython] Treatment of right-hand side after assignment

2017-04-06 Thread Clemens Hofreither
Hey all,

(I hope this list isn't dead.)

I'm reading up on the Cython codebase because I'm trying to implement
a small feature (more on that later). There's one thing that really
confuses me currently, and that's the distinction between
generate_post_assignment_code and generate_disposal_code. From the
comments, it appears that exactly one of these should be called, and
which one it is depends on whether a reference from the rhs was
absorbed into the lhs.

So much for the theory, but in practice it seems to work differently.
I'm looking at NameNode.generate_assignment_code() and
IndexNode.generate_assignment_code(), which should do similar things
(generate code for an assignment) except that the lhs has different
structure.

Yet they treat the cleanup of the rhs completely differently.
IndexNode always calls rhs.generate_disposal_code. NameNode almost
always calls rhs.generate_post_assignment_code.

Can anyone shed light on why this cleanup is handled differently
depending on the target of the assignment?

Thanks,
Clemens
___
cython-devel mailing list
cython-devel@python.org
https://mail.python.org/mailman/listinfo/cython-devel


Re: [Cython] Treatment of right-hand side after assignment

2017-04-10 Thread Clemens Hofreither
On Sun, Apr 9, 2017 at 8:00 AM, Robert Bradshaw  wrote:
> On Sun, Apr 2, 2017 at 9:42 AM, Clemens Hofreither 
> wrote:
>>
>> Hey all,
>>
>> (I hope this list isn't dead.)
>>
>> I'm reading up on the Cython codebase because I'm trying to implement
>> a small feature (more on that later). There's one thing that really
>> confuses me currently, and that's the distinction between
>> generate_post_assignment_code and generate_disposal_code. From the
>> comments, it appears that exactly one of these should be called, and
>> which one it is depends on whether a reference from the rhs was
>> absorbed into the lhs.
>>
>> So much for the theory, but in practice it seems to work differently.
>> I'm looking at NameNode.generate_assignment_code() and
>> IndexNode.generate_assignment_code(), which should do similar things
>> (generate code for an assignment) except that the lhs has different
>> structure.
>>
>> Yet they treat the cleanup of the rhs completely differently.
>> IndexNode always calls rhs.generate_disposal_code. NameNode almost
>> always calls rhs.generate_post_assignment_code.
>>
>> Can anyone shed light on why this cleanup is handled differently
>> depending on the target of the assignment?
>
>
> It's been a while since I've looked at this, but the best explanation is
> that generate_post_assignment_code is used when the rhs is "moved" into the
> lhs whereas generate_post_assignment_code is what happens for a "copy." This
> is mostly relevant for temps, e.g. when a temp holds a reference to a Python
> object, it can be transferred to the assignee (e.g. with NameNodes) or a new
> reference can be created for the assignee (e.g. with IndexNodes) which
> changes whether the temp lhs needs to be decref'ed.
>
> ___
> cython-devel mailing list
> cython-devel@python.org
> https://mail.python.org/mailman/listinfo/cython-devel
>

Thanks for your answer. I understood as much about the difference with
temporaries and copies.

My question was why the RIGHT-hand side is treated differently in
NameNode.generate_assignment_code() and
IndexNode.generate_assignment_code(). My understanding is that
NameNode/IndexNode here refers to the type of the left-hand side. But
I don't see why whether or not the RHS is a temporary should depend on
the type of the LHS. Therefore it seems confusing that the code in
these two methods uses different cleanup for the RHS.

Clemens
___
cython-devel mailing list
cython-devel@python.org
https://mail.python.org/mailman/listinfo/cython-devel