Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-104615: don't make unsafe swaps in apply_static_swaps#104620

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
carljm merged 4 commits intopython:mainfromcarljm:staticswaps
May 18, 2023

Conversation

carljm
Copy link
Member

@carljmcarljm commentedMay 18, 2023
edited by bedevere-bot
Loading

It's not safe to apply SWAP statically if it would reorder two instructions that store to the same location.

@carljm
Copy link
MemberAuthor

One thing I'm not clear on is whether we want to bump bytecode magic number for a fix like this. The old bytecode still works as well it ever did (no incompatible changes in the interpreter), so maybe no? But OTOH, nobody will see this bugfix until their pycs are invalidated.

Basically: do we bump bytecode magic number on any change to the compiler that results in different compiler output, or only when we change the interpreter in a way that makes it incompatible with previous bytecode?

@JelleZijlstra
Copy link
Member

One thing I'm not clear on is whether we want to bump bytecode magic number for a fix like this. The old bytecode still works as well it ever did (no incompatible changes in the interpreter), so maybe no? But OTOH, nobody will see this bugfix until their pycs are invalidated.

Basically: do we bump bytecode magic number on any change to the compiler that results in different compiler output, or only when we change the interpreter in a way that makes it incompatible with previous bytecode?

I was wondering a bit about that too. Several other recent fixes around comprehensions would also change the compiler output, so theoretically we should have bumped the magic number a few times. On the other hand, the only people who are really affected would be people who built from main directly after the PEP 695 change was merged (which did bump the magic number), so realistically there's not much of an issue. It's probably enough if we bump the magic number one last time before the beta is finalized.

@brandtbucher
Copy link
Member

brandtbucher commentedMay 18, 2023
edited
Loading

My thought has mostly been that magic numbers should only be bumped if the bytecode itself is incompatible (meaning opcodes or the meanings of opargs have changed). I don't think we've bumped it for miscompilations before (but I could be wrong).

(We also bump it when changing how code objects are unmarshalled, which is arguably an abuse of the magic number and should be a marshal version bump instead.)

carljm reacted with thumbs up emoji

}
for (int idx = j + 1; idx < k; idx++) {
int store_idx = STORES_TO(block->b_instr[idx]);
if (store_idx >= 0 && (store_idx == store_j || store_idx == store_k)) {
Copy link
Member

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?

Copy link
MemberAuthor

@carljmcarljmMay 18, 2023
edited
Loading

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 likea, 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.

iritkatriel reacted with thumbs up emoji
Copy link
Member

@brandtbucherbrandtbucher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Thanks for the quick fix!

@carljmcarljmenabled auto-merge (squash)May 18, 2023 21:00
@carljmcarljm merged commit0589c6a intopython:mainMay 18, 2023
@carljmcarljm deleted the staticswaps branchMay 18, 2023 21:31
@carljm
Copy link
MemberAuthor

Oh, I forgot: this should be backported to 3.11, since it's a bug that exists there as well.

@carljmcarljm added the needs backport to 3.11only security fixes labelMay 18, 2023
@miss-islington
Copy link
Contributor

Thanks@carljm for the PR 🌮🎉.. I'm working now to backport this PR to: 3.11.
🐍🍒⛏🤖

@miss-islington
Copy link
Contributor

Sorry@carljm, I had trouble checking out the3.11 backport branch.
Please retry by removing and re-adding the "needs backport to 3.11" label.
Alternatively, you can backport usingcherry_picker on the command line.
cherry_picker 0589c6a4d3d822cace42050198cb9a5e99c879ad 3.11

@carljmcarljm added needs backport to 3.11only security fixes and removed needs backport to 3.11only security fixes labelsMay 18, 2023
@miss-islington
Copy link
Contributor

Thanks@carljm for the PR 🌮🎉.. I'm working now to backport this PR to: 3.11.
🐍🍒⛏🤖

@miss-islington
Copy link
Contributor

Sorry,@carljm, I could not cleanly backport this to3.11 due to a conflict.
Please backport usingcherry_picker on command line.
cherry_picker 0589c6a4d3d822cace42050198cb9a5e99c879ad 3.11

carljm added a commit to carljm/cpython that referenced this pull requestMay 18, 2023
* main:pythongh-74690: Don't set special protocol attributes on non-protocol subclasses of protocols (python#104622)pythongh-104623: Update Windows installer to use SQLite 3.42.0 (python#104625)pythongh-104050: Add more type annotations to Argument Clinic (python#104628)pythongh-104629: Don't skip test_clinic if _testclinic is missing (python#104630)pythongh-104549: Set __module__ on TypeAliasType (python#104550)pythongh-104050: Improve some typing around `default`s and sentinel values (python#104626)pythongh-104146: Remove unused vars from Argument Clinic (python#104627)pythongh-104615: don't make unsafe swaps in apply_static_swaps (python#104620)pythonGH-104484: Add case_sensitive argument to `pathlib.PurePath.match()` (pythonGH-104565)pythonGH-96803: Document and test new unstable internal frame API functions (pythonGH-104211)pythonGH-104580: Don't cache eval breaker in interpreter (pythonGH-104581)
carljm added a commit to carljm/cpython that referenced this pull requestMay 19, 2023
…pythonGH-104620).(cherry picked from commit0589c6a)Co-authored-by: Carl Meyer <carl@oddbird.net>
@bedevere-bot
Copy link

GH-104636 is a backport of this pull request to the3.11 branch.

@bedevere-botbedevere-bot removed the needs backport to 3.11only security fixes labelMay 19, 2023
carljm added a commit that referenced this pull requestMay 19, 2023
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@iritkatrieliritkatrieliritkatriel approved these changes

@brandtbucherbrandtbucherbrandtbucher approved these changes

@markshannonmarkshannonAwaiting requested review from markshannonmarkshannon is a code owner

Assignees

@carljmcarljm

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

6 participants
@carljm@JelleZijlstra@brandtbucher@miss-islington@bedevere-bot@iritkatriel

[8]ページ先頭

©2009-2025 Movatter.jp