Fix Bug 286: Returning AA value whose key is a RefCounted type gets wrong value. #640
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, but:
- No Changelog?
- Testcase is not completely reduced. Is it possible the test case may no longer test this issue correctly if phobos changes?
- Could you summarize what this changes exactly? In which cases do we need to stabilize the LHS, in which should we not do that?
I'll see if it could be reduced further but I chose to be as close to the original code where the problem was found.
Where set is a recounted type and having the codegen rewrite in stabilize_expr meant that the side effect was not saved. And so matcherCache was accessed twice by two different keys - first for assignment and second for return. |
I'll open a bug report anyway about these routines, as they could be better organized as to what should handle performing an unary operation on a comprex expression and what should remove all side effects. Currently there's some conflation going on between the two that was quickly done to support struct types that are never copied to temp. Preferably we'll agree something this weekend as its affecting dub in ubuntu 18.04, and so would like it in before the freeze. |
I understand the motivation, but what if
So the key differs depending on the current reference count? Isn't that already a phobos bug by itself?
OK. The current solution is fine by me, feel free to merge at any time. I'm just trying to understand this in detail to ensure the fix really is general enough to fix similar problems. So if we have So we do we need that special case for |
It's a bug on our side because.
Should lower to (pseudo-code).
Whereas we were instead generating.
The rewrite erroneously removed the side effect, so |
Yes, it's a bit of a mess, in part related to just getting rvo working. I think Then what the function is currently used for renamed to something like e.g:
Then go though the painful process of splitting out what really needs a side-effect stabilized, and what just wants to apply an operation to the relevant part of the expression. |
This approach is specific to binop_assignment, putting it in as a generic rewrite was a mistake. But I think things could be simplified as per previous comment. |
I get that part and that's a bug in GDC for sure.
Ok thanks for explaining. So this fix should really be fine for now. |
Just to clarify, this is the actual generated code in release mode.
As it's release mode there is no And because all the rewrite does is look for And so the bad codegen does:
In the first call of Why does it increment inside every call to |
88736f4
to
a1c4b11
Compare
OK, replaced test with one that doesn't depend on phobos. |
Thanks for explaining again in detail. I understand that part, but I question that the reference count should even be considered when treating a
Looks good, this should be ready for merging 👍 |
@jpf91 it may be worth asking about. There might be some explanation for it that I can't think of. |
Though waiting for the first test result, as this code-gen rewrite was added for a reason, but the test case is hidden somewhere in #571.