-
Notifications
You must be signed in to change notification settings - Fork 25.7k
[dynamo 3.11] changes to with contexts #94101
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
Closed
Closed
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
c2554c2
[dynamo 3.11] changes to with contexts
williamwen42 1c0c068
Update on "[dynamo 3.11] changes to with contexts"
williamwen42 7718111
Update on "[dynamo 3.11] changes to with contexts"
williamwen42 0433dad
Update on "[dynamo 3.11] changes to with contexts"
williamwen42 ea84842
Update on "[dynamo 3.11] changes to with contexts"
williamwen42 f16f6b7
Update on "[dynamo 3.11] changes to with contexts"
williamwen42 7a8a6c5
Update on "[dynamo 3.11] changes to with contexts"
williamwen42 773dd1e
Update on "[dynamo 3.11] changes to with contexts"
williamwen42 63a644a
Update on "[dynamo 3.11] changes to with contexts"
williamwen42 fb38134
Update on "[dynamo 3.11] changes to with contexts"
williamwen42 9bc7a81
Update on "[dynamo 3.11] changes to with contexts"
williamwen42 47264cc
Update on "[dynamo 3.11] changes to with contexts"
williamwen42 926166d
Update on "[dynamo 3.11] changes to with contexts"
williamwen42 f90741c
Update on "[dynamo 3.11] changes to with contexts"
williamwen42 41a3fc8
Update on "[dynamo 3.11] changes to with contexts"
williamwen42 0a730c7
Update on "[dynamo 3.11] changes to with contexts"
williamwen42 459f369
Update on "[dynamo 3.11] changes to with contexts"
williamwen42 2d8be29
Update on "[dynamo 3.11] changes to with contexts"
williamwen42 c0b53b0
Update on "[dynamo 3.11] changes to with contexts"
williamwen42 a32f556
Update on "[dynamo 3.11] changes to with contexts"
williamwen42 19e68a8
Update on "[dynamo 3.11] changes to with contexts"
williamwen42 2261640
Update on "[dynamo 3.11] changes to with contexts"
williamwen42 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -102,6 +102,7 @@ def _step_logger(): | |
|
|
||
| @dataclasses.dataclass | ||
| class BlockStackEntry: | ||
| id: int | ||
| target: Instruction | ||
| stack_index: Optional[int] = None | ||
| with_context: ContextWrappingVariable = None | ||
|
|
@@ -878,11 +879,11 @@ def jump(self, inst): | |
|
|
||
| def SETUP_LOOP(self, inst): | ||
| # only exists in python<=3.7 | ||
| self.block_stack.append(BlockStackEntry(inst.target)) | ||
| self.block_stack.append(BlockStackEntry(0, inst.target)) | ||
|
|
||
| def SETUP_EXCEPT(self, inst): | ||
| # only exists in python<=3.7 | ||
| self.block_stack.append(BlockStackEntry(inst.target)) | ||
| self.block_stack.append(BlockStackEntry(0, inst.target)) | ||
|
|
||
| def POP_BLOCK(self, inst): | ||
| self.block_stack.pop() | ||
|
|
@@ -894,10 +895,12 @@ def SETUP_WITH(self, inst): | |
| self.output.guards.update(ctx.guards) | ||
|
|
||
| if isinstance(self, InstructionTranslator): | ||
| self.block_stack.append(BlockStackEntry(inst.target, len(self.stack), ctx)) | ||
| self.block_stack.append( | ||
| BlockStackEntry(0, inst.target, len(self.stack), ctx) | ||
| ) | ||
| else: | ||
| # can't restore this while inlining | ||
| self.block_stack.append(BlockStackEntry(inst.target)) | ||
| self.block_stack.append(BlockStackEntry(0, inst.target)) | ||
| self.push( | ||
| WithExitFunctionVariable( | ||
| ctx, | ||
|
|
@@ -908,7 +911,7 @@ def SETUP_WITH(self, inst): | |
| self.push(ctx.enter(self)) | ||
|
|
||
| def SETUP_FINALLY(self, inst): | ||
| self.block_stack.append(BlockStackEntry(inst.target)) | ||
| self.block_stack.append(BlockStackEntry(0, inst.target)) | ||
|
|
||
| def BEGIN_FINALLY(self, inst): | ||
| self.push(None) | ||
|
|
@@ -1569,6 +1572,13 @@ def CALL(self, inst): | |
| kwargs = {} | ||
| self.call_function(fn, args, kwargs) | ||
| self.kw_names = None | ||
| # 3.11 removed POP_BLOCK, so we manually pop the block stack here | ||
| if ( | ||
| isinstance(fn, WithExitFunctionVariable) | ||
| and len(self.block_stack) > 0 | ||
| and id(fn) == self.block_stack[-1].id | ||
|
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. Could there be more than one associated with this function? |
||
| ): | ||
| self.block_stack.pop() | ||
|
|
||
| def COPY(self, inst): | ||
| self.push(self.stack[-inst.arg]) | ||
|
|
@@ -1592,6 +1602,30 @@ def SWAP(self, inst): | |
| def CACHE(self, inst): | ||
| pass | ||
|
|
||
| def BEFORE_WITH(self, inst): | ||
| ctx = self.pop() | ||
| if not isinstance(ctx, ContextWrappingVariable): | ||
| unimplemented(f"BEFORE_WITH {ctx}") | ||
| self.output.guards.update(ctx.guards) | ||
|
|
||
| exit = WithExitFunctionVariable( | ||
| ctx, | ||
| inst.target, | ||
| **VariableTracker.propagate(ctx), | ||
| ) | ||
| # 3.11 no longer uses a block stack, but we still keep track of one | ||
| # so that we know which contexts are currently active. | ||
| if isinstance(self, InstructionTranslator): | ||
| self.block_stack.append( | ||
| BlockStackEntry(id(exit), inst.target, self.real_stack_len(), ctx) | ||
| ) | ||
| else: | ||
| # can't restore this while inlining | ||
| self.block_stack.append(BlockStackEntry(id(exit), inst.target)) | ||
|
|
||
| self.push(exit) | ||
| self.push(ctx.enter(self)) | ||
|
|
||
| def copy_graphstate(self) -> InstructionTranslatorGraphState: | ||
| """Create a checkpoint of the current state by copying everything""" | ||
| return InstructionTranslatorGraphState( | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
For all these functions that don't exist for 3.11, should we comment them the same way the ones only existing for python<=3.7 are?