-
Notifications
You must be signed in to change notification settings - Fork 33
Restore _GUARD_KEYS_VERSION in LOAD_ATTR specializations #130
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
Open
ddorian
wants to merge
3
commits into
facebookincubator:main
Choose a base branch
from
ddorian:fix-load-attr-keys-version
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
109 changes: 109 additions & 0 deletions
109
cinderx/PythonLib/test_cinderx/test_load_attr_keys_version.py
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 |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| # Copyright (c) Meta Platforms, Inc. and affiliates. | ||
|
|
||
| # pyre-strict | ||
|
|
||
| """Regression tests for gh-115: a load site specialized to | ||
| LOAD_ATTR_NONDESCRIPTOR_WITH_VALUES or LOAD_ATTR_METHOD_WITH_VALUES must | ||
| deopt once the attribute is stored on an instance. Runs in a subprocess | ||
| because it depends on precise interpreter warm-up state.""" | ||
|
|
||
| import subprocess | ||
| import sys | ||
| import unittest | ||
|
|
||
| import cinderx | ||
|
|
||
| cinderx.init() | ||
|
|
||
| from cinderx.test_support import ENCODING, subprocess_env | ||
|
|
||
|
|
||
| def run_snippet(source: str) -> "subprocess.CompletedProcess[str]": | ||
| return subprocess.run( | ||
| [sys.executable, "-c", source], | ||
| stdout=subprocess.PIPE, | ||
| stderr=subprocess.STDOUT, | ||
| encoding=ENCODING, | ||
| env=subprocess_env(), | ||
| ) | ||
|
|
||
|
|
||
| class LoadAttrKeysVersionTests(unittest.TestCase): | ||
| @unittest.skipUnless(sys.version_info >= (3, 14), "3.14+ opcodes") | ||
| def test_instance_attr_shadows_class_default(self) -> None: | ||
| proc = run_snippet( | ||
| """if 1: | ||
| import cinderx.jit | ||
| cinderx.jit.auto() | ||
| import dis | ||
|
|
||
| class C: | ||
| rcs = None | ||
|
|
||
| def make_without(): | ||
| o = C.__new__(C) | ||
| o.x1 = 1 | ||
| return o | ||
|
|
||
| def make_with(): | ||
| o = C.__new__(C) | ||
| o.x1 = 1 | ||
| o.rcs = (1, 2, 3) | ||
| return o | ||
|
|
||
| def read(o): | ||
| return o.rcs | ||
|
|
||
| for _ in range(300): | ||
| assert read(make_without()) is None | ||
|
|
||
| names = {i.opname for i in dis.get_instructions(read, adaptive=True)} | ||
| assert "LOAD_ATTR_NONDESCRIPTOR_WITH_VALUES" in names, sorted(names) | ||
|
|
||
| got = read(make_with()) | ||
| assert got == (1, 2, 3), f"stale class default returned: {got!r}" | ||
| """ | ||
| ) | ||
| self.assertEqual(proc.returncode, 0, proc.stdout) | ||
|
|
||
| @unittest.skipUnless(sys.version_info >= (3, 14), "3.14+ opcodes") | ||
| def test_instance_attr_shadows_method(self) -> None: | ||
| proc = run_snippet( | ||
| """if 1: | ||
| import cinderx.jit | ||
| cinderx.jit.auto() | ||
| import dis | ||
|
|
||
| class C: | ||
| def m(self): | ||
| return "class-method" | ||
|
|
||
| def make_plain(): | ||
| o = C.__new__(C) | ||
| o.x1 = 1 | ||
| return o | ||
|
|
||
| def make_shadowed(): | ||
| o = C.__new__(C) | ||
| o.x1 = 1 | ||
| o.m = lambda: "instance-attr" | ||
| return o | ||
|
|
||
| def call_m(o): | ||
| return o.m() | ||
|
|
||
| for _ in range(300): | ||
| assert call_m(make_plain()) == "class-method" | ||
|
|
||
| names = {i.opname for i in dis.get_instructions(call_m, adaptive=True)} | ||
| assert "LOAD_ATTR_METHOD_WITH_VALUES" in names, sorted(names) | ||
|
|
||
| got = call_m(make_shadowed()) | ||
| assert got == "instance-attr", f"shadowed method ignored: {got!r}" | ||
| """ | ||
| ) | ||
| self.assertEqual(proc.returncode, 0, proc.stdout) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() | ||
Oops, something went wrong.
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.
Same feedback as #129, put this in
test_jit_specialization.pyand drop thecinderx.init().