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-93143: Don't turnLOAD_FAST intoLOAD_FAST_CHECK#99075

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

Conversation

brandtbucher
Copy link
Member

@brandtbucherbrandtbucher commentedNov 3, 2022
edited by bedevere-bot
Loading

The compiler's dataflow analysis for fast locals can be invalidated by jumps or deletions while tracing. When this happens, rather than changingco_code (which users assume to be constant) to use the less-efficientLOAD_FAST_CHECK everywhere, just display aRuntimeWarning and set any problematic locals toNone instead.

@brandtbucherbrandtbucher added the interpreter-core(Objects, Python, Grammar, and Parser dirs) labelNov 3, 2022
@brandtbucherbrandtbucher self-assigned thisNov 3, 2022
@brandtbucherbrandtbucher marked this pull request as ready for reviewNovember 3, 2022 20:04
@sweeneyde
Copy link
Member

I can look closer this evening, but mutating co_code is not ideal, so I think this is probably a good idea.

@markshannon
Copy link
Member

There are two cases when we need to set locals toNone.

  1. Deletion of locals
  2. Jumping to arbitrary code

In the first case we can set the local toNone and issue the warning cheaply and probably correctly. That's fine.

However when jumping, trying to decide which locals need to be set toNone is going to be complex, expensive and error prone.
So I think we should go with@sweeneyde suggestion of setting all the undefined local variables toNone.
Either don't issue any warning (as it might be confusing), or maybe issue a generic warning only if any locals were set toNone.

@brandtbucher
Copy link
MemberAuthor

I've updated the code to skip scanning the bytecode forLOAD_FAST. Any unbound locals will be assignedNone on jumps, and (if so) a singleRuntimeWarning will be issued for all of them.

Copy link
Member

@markshannonmarkshannon left a comment

Choose a reason for hiding this comment

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

👍
This feels safer and more robust than what we have now.

@@ -0,0 +1,4 @@
Rather than changing :attr:`~types.CodeType.co_code`, the interpreter will
now display a :exc:`RuntimeWarning` and assign :const:`None` to any fast
locals that are incorrectly left unbound after jumps or :keyword:`del`
Copy link
Member

Choose a reason for hiding this comment

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

There aren't necessarily incorrect, so maybe just "locals that are unbound after ..."

brandtbucher reacted with thumbs up emoji
PyErr_WriteUnraisable((PyObject *)frame->frame_obj);
}
value = Py_NewRef(Py_None);
}
Py_XINCREF(value);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Py_XINCREF(value);
Py_INCREF(value);

brandtbucher reacted with thumbs up emoji
@bedevere-bot
Copy link

When you're done making the requested changes, leave the comment:I have made the requested changes; please review again.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@sweeneydesweeneydesweeneyde left review comments

@markshannonmarkshannonmarkshannon approved these changes

Assignees

@brandtbucherbrandtbucher

Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

4 participants
@brandtbucher@sweeneyde@markshannon@bedevere-bot

[8]ページ先頭

©2009-2025 Movatter.jp