-
-
Notifications
You must be signed in to change notification settings - Fork 30.8k
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
gh-104615: don't make unsafe swaps in apply_static_swaps #104620
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Fix wrong ordering of assignments in code like ``a, a = x, y``. Contributed by | ||
Carl Meyer. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
How would it happen that there's a STORE_FAST* between j and k?
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.
This can happen with code like
a, a, b = x, y, z
as in some of the added tests. This compiles toLOAD_FAST x; LOAD_FAST y; LOAD_FAST z; SWAP 3; STORE_FAST a; STORE_FAST a; STORE_FAST b
. Before this PR,apply_static_swaps
would optimize that (ignoring the loads) toSTORE_FAST b; STORE_FAST a; STORE_FAST a
(swapping the first and third store), which is invalid because it reorders the two stores toa
.k - j == n - 1
here, wheren
is the oparg to theSWAP
. So for aSWAP 2
,j
andk
will be adjacent, but forSWAP
with oparg > 2, there will be intervening instructions. AndSTORE_FAST
is aSWAPPABLE
instruction, so those intervening instructions can beSTORE_FAST
.