gh-98831: Support conditional effects; use for LOAD_ATTR#101333
Conversation
(Semantics aren't there yet, and the test fails.)
First use of conditional stack effects.
- UndefinedLocalError when generating metadata for an 'op' - Accidental newline inserted in test_generator.py
gvanrossum
left a comment
There was a problem hiding this comment.
Notes to self.
Sorry, something went wrong.
|
I don't understand what this warning is about:
|
Sorry, something went wrong.
I assume it's about this line (L1797): The compiler probably reasons that That's silly since it doesn't warn us about the equally trivial I'm not sure what to do about it. PS. I'm still looking into your suggestion to assign the condition to a flag variable, it's a bit messy. |
Sorry, something went wrong.
|
Here's the new version. Let me know if you like it enough to go ahead -- if not, I can easily roll it back. Note that I also fixed a bunch of typing issues (which caught one genuine bug). |
Sorry, something went wrong.
I think this is easier to read. The warning about the bool comparison is gone too. There's just the one about res being potentially unassigned. |
Sorry, something went wrong.
This hopefully avoids a silly compiler warning.
8f4219a to
81e5236
Compare
January 28, 2023 23:16
|
Finally this has no compiler warnings on GitHub. I prefer this version, the changes to generate_cases.py are simpler than the version with flags. |
Sorry, something went wrong.
We can now write
which pops
foooff the stack ifoparg & 1, otherwise setting it toNULL, and pushesbaronto the stack ifoparg & 2(otherwise ignoring it).This syntax cannot be combined with an array size on the same effect, but it can be combined with a type (untested). In addition, it is incompatible with an array size closer to the stack top, e.g.
foo if (oparg&1), bar[oparg>>1]is not supported (I don't think it's used, and generating code for it would be slightly awkward, but could be done if needed).The implementation switches to using
POP()andPUSH()(fromPEEK()andPOKE()) for those variables that are either conditional or whose position relative to the bottom (!) of the stack depends on a condition. (See the added test for details.)To demonstrate this, I converted
LOAD_ATTR(but not its specializations).