-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
[dynamo 3.11] support prefix instructions MAKE_CELL, COPY_FREE_VARS, RETURN_GENERATOR, RESUME #96506
[dynamo 3.11] support prefix instructions MAKE_CELL, COPY_FREE_VARS, RETURN_GENERATOR, RESUME #96506
Changes from 2 commits
66bd1c4
fcb30e9
97c0b85
47aacaa
fc2aa85
6372743
b7408fd
dece9fe
b6e53fb
11f1159
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -432,6 +432,8 @@ class InstructionTranslatorBase(Checkpointable[InstructionTranslatorGraphState]) | |
lineno: int | ||
mutated_closure_cell_contents: Set[str] | ||
kw_names: Optional[ConstantVariable] | ||
accept_prefix_inst: bool | ||
prefix_insts: List[Instruction] | ||
|
||
checkpoint: Optional[Tuple[Instruction, InstructionTranslatorGraphState]] | ||
random_calls: List[ | ||
|
@@ -1508,9 +1510,12 @@ def MATCH_KEYS(self, inst): | |
INPLACE_OR = stack_op(operator.ior) | ||
|
||
# 3.11 opcodes | ||
# note: passed opcodes are intentional | ||
def RESUME(self, inst): | ||
pass | ||
if inst.arg == 0: | ||
self.append_prefix_inst(inst) | ||
self.accept_prefix_inst = False | ||
else: | ||
assert not self.accept_prefix_inst | ||
|
||
def BINARY_OP(self, inst): | ||
if sys.version_info >= (3, 11): | ||
|
@@ -1611,6 +1616,19 @@ def BEFORE_WITH(self, inst): | |
self.push(exit) | ||
self.push(ctx.enter(self)) | ||
|
||
def append_prefix_inst(self, inst): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to enforce the ordering of the inst in here? Or it should always be ok since we add things as we read the original frame? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We add things as read in the original frame, and any instructions that jump necessarily come after the prefix, and they shouldn't jump to before the prefix. |
||
assert self.accept_prefix_inst | ||
self.prefix_insts.append(inst) | ||
|
||
def MAKE_CELL(self, inst): | ||
self.append_prefix_inst(inst) | ||
|
||
def COPY_FREE_VARS(self, inst): | ||
self.append_prefix_inst(inst) | ||
|
||
def RETURN_GENERATOR(self, inst): | ||
self.append_prefix_inst(inst) | ||
|
||
def copy_graphstate(self) -> InstructionTranslatorGraphState: | ||
"""Create a checkpoint of the current state by copying everything""" | ||
return InstructionTranslatorGraphState( | ||
|
@@ -1710,6 +1728,8 @@ def __init__( | |
self.block_stack = [] | ||
self.lineno = code_options["co_firstlineno"] | ||
self.kw_names = None | ||
self.accept_prefix_inst = True | ||
self.prefix_insts = [] | ||
|
||
# Properties of the input/output code | ||
self.instructions: List[Instruction] = instructions | ||
|
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.
Is the
//2
ok here? All opcodes might not be of size 2 here?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.
We follow the implementation of
_co_firsttraceable
in CPython (codeobject.c), which uses bytecode index (2 bytes), not instruction index.