-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
GH-118095: Handle RETURN_GENERATOR
in tier 2
#118180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
markshannon
commented
Apr 23, 2024
•
edited by bedevere-app
bot
Loading
edited by bedevere-app
bot
- Issue: Increase the number of micro-ops that we can handle in tier 2 #118095
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.
Why not add a test? E.g.
def test_return_generator(self):
def gen():
yield None
def testfunc(n):
for i in range(n):
gen()
res, ex = self._run_with_optimizer(testfunc, 20)
self.assertIsNotNone(ex)
self.assertIn("_RETURN_GENERATOR", get_opnames(ex))
@@ -369,7 +369,7 @@ eliminate_pop_guard(_PyUOpInstruction *this_instr, bool exit) | |||
static PyCodeObject * | |||
get_code(_PyUOpInstruction *op) | |||
{ | |||
assert(op->opcode == _PUSH_FRAME || op->opcode == _POP_FRAME); | |||
assert(op->opcode == _PUSH_FRAME || op->opcode == _POP_FRAME || op->opcode == _RETURN_GENERATOR); |
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.
It's a bit inelegant that all places that treat _PUSH_FRAME
and _POP_FRAME
special now also have to check for _RETURN_GENERATOR
. Not sure what to do about it. :-(
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.
Once #118095 is done we can add a flag for all uops that push or pop frames.
ctx->frame->stack_pointer = stack_pointer; | ||
frame_pop(ctx); | ||
stack_pointer = ctx->frame->stack_pointer; | ||
OUT_OF_SPACE_IF_NULL(res = sym_new_unknown(ctx)); |
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.
Am I correct that this is the only line that differs from _POP_FRAME
? The duplication of so much code is unfortunate. At the same time I don't see a better solution. Maybe add a comment to both explaining they need to be kept in sync?
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.
A good candidate for refactoring, but I'd like to get #118095 done first so that we more easily see the common patterns.
def testfunc(n): | ||
for i in range(n): | ||
gen() | ||
res, ex = self._run_with_optimizer(testfunc, 20) |
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.
I'd assert the value of res as well.
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.
done
The four failing tests are the usual suspects. |