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-132775: Add _PyCode_VerifyStateless()#133221

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

Conversation

ericsnowcurrently
Copy link
Member

@ericsnowcurrentlyericsnowcurrently commentedApr 30, 2025
edited by bedevere-appbot
Loading

"Stateless" code is a function or code object which does not rely on external state or internal state. It may rely on arguments and
builtins, but not globals or a closure. I've left a comment in pycore_code.h that provides more detail.

We also add_PyFunction_VerifyStateless(). The new functions will be used in several later changes that facilitate "sharing" functions and code objects between interpreters.

@ericsnowcurrently
Copy link
MemberAuthor

!buildbot s390x RHEL8 LTO + PGO

@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by@ericsnowcurrently for commitd45c0e0 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F133221%2Fmerge

The command will test the builders whose names match following regular expression:s390x RHEL8 LTO \+ PGO

The builders matched are:

  • s390x RHEL8 LTO + PGO PR


// The last instruction either returns or raises. We can take advantage
// of that for a quick exit.
_Py_CODEUNIT final = _Py_GetBaseCodeUnit(co, len-1);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the warning on Windows fixable on this PR?

ericsnowcurrently reacted with thumbs up emoji
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

fixed

@ericsnowcurrentlyericsnowcurrentlyenabled auto-merge (squash)May 5, 2025 21:29
@ericsnowcurrentlyericsnowcurrently merged commitd270bb5 intopython:mainMay 5, 2025
38 checks passed
@ericsnowcurrentlyericsnowcurrently deleted the add-pycode-verify-stateless branchMay 5, 2025 21:49
@nascheme
Copy link
Member

nascheme commentedMay 6, 2025
edited by hugovk
Loading

This looks to be failing on the iOS buildbot.

test_code (test)Doctest:test.test_code ... ok======================================================================ERROR:test_stateless (test.test_code.CodeTest.test_stateless) [(<function spam_N at 0x10fab5b50>, '(code)')]----------------------------------------------------------------------Traceback (most recent call last):  File"/Users/buildbot/Library/Developer/XCTestDevices/3749308D-3FDE-41E4-B27C-3A4DD1FCF87A/data/Containers/Bundle/Application/40457EBF-BF74-4E58-B5DB-F52F8BC085A9/iOSTestbed.app/python/lib/python3.14/test/test_code.py", line1049, intest_stateless    _testinternalcapi.verify_stateless_code(func.__code__)~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^ValueError:only basic code objects are supported======================================================================ERROR:test_stateless (test.test_code.CodeTest.test_stateless) [(<function spam_C at 0x10fab4a10>, '(code)')]----------------------------------------------------------------------Traceback (most recent call last):  File"/Users/buildbot/Library/Developer/XCTestDevices/3749308D-3FDE-41E4-B27C-3A4DD1FCF87A/data/Containers/Bundle/Application/40457EBF-BF74-4E58-B5DB-F52F8BC085A9/iOSTestbed.app/python/lib/python3.14/test/test_code.py", line1049, intest_stateless    _testinternalcapi.verify_stateless_code(func.__code__)~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^ValueError:only basic code objects are supported

https://buildbot.python.org/#/builders/1380/builds/3582/

@encukou
Copy link
Member

The test fails when it's run twice:

./python -m test test_code test_code

@encukou
Copy link
Member

encukou commentedMay 6, 2025
edited by hugovk
Loading

Looks like settingsys.settrace with opcode tracing causes all code to be instrumented when it's next run.

importsysimport_testinternalcapideffoo():passdeftrace_temporarily():sys._getframe().f_trace_opcodes=Truesys.settrace(print)sys.settrace(None)sys._getframe().f_trace_opcodes=Falsetrace_temporarily()_testinternalcapi.verify_stateless_code(foo.__code__)foo()_testinternalcapi.verify_stateless_code(foo.__code__)# fails

In this case,test_code_equal_with_instrumentation does this. If it runs first, then some test that exepcutes the tested functions (to get the closures I guess), thentest_stateless will fail.

@encukou
Copy link
Member

I'm not sure what exactly "statelessness" is used for in the subinterpreters code. But, it looks like if it is to be useful, it either

  • needs to be treated as an important property that can't be broken by optimizations, or
  • the function should be_PyCode_IsStateless, returning a bool, with typical users needing to implement a fallback (copying the code object should be enough?)

Unfortunately, given the timing, I think this needs to be reverted for 3.14 :(

@hugovk
Copy link
Member

@encukou Please could you open a revert PR?

@encukou
Copy link
Member

Will do. Resolving conflicts.

hugovk reacted with thumbs up emoji

encukou added a commit to encukou/cpython that referenced this pull requestMay 6, 2025
…)"This reverts commitd270bb5.Note that the test functions in _code_definitions are not reverted.
@hugovk
Copy link
Member

Reverted in#133497.

@ericsnowcurrently
Copy link
MemberAuthor

Thanks for jumping on this. I'll sort it out. FYI, the relevant code is_PyCode_CheckNoInternalState(). It isn't clear to me howtest_code_equal_with_instrumentation is affecting the functions used intest_stateless, but it probably doesn't matter. :)

ericsnowcurrently added a commit to ericsnowcurrently/cpython that referenced this pull requestMay 6, 2025
ericsnowcurrently added a commit that referenced this pull requestMay 8, 2025
This reverts commit 3c73cf5 (gh-133497), which itself revertedthe original commitd270bb5 (gh-133221).We reverted the original change due to failing android tests.The checks in _PyCode_CheckNoInternalState() were too strict,so we've relaxed them.
ericsnowcurrently added a commit that referenced this pull requestMay 8, 2025
This reverts commit 3c73cf5 (gh-133497), which itself revertedthe original commitd270bb5 (gh-133221).We reverted the original change due to failing android tests.The checks in _PyCode_CheckNoInternalState() were too strict,so we've relaxed them.
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@iritkatrieliritkatrieliritkatriel left review comments

@ZeroIntensityZeroIntensityZeroIntensity left review comments

@neoneneneoneneneonene left review comments

@markshannonmarkshannonAwaiting requested review from markshannonmarkshannon is a code owner

Assignees
No one assigned
Labels
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

8 participants
@ericsnowcurrently@bedevere-bot@nascheme@encukou@hugovk@iritkatriel@ZeroIntensity@neonene

[8]ページ先頭

©2009-2025 Movatter.jp