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-134584: JIT: Borrow references for immortal promoted globals#142921

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

Open
Fidget-Spinner wants to merge2 commits intopython:main
base:main
Choose a base branch
Loading
fromFidget-Spinner:load_consts_inline_borrow_prmoted
Open
Show file tree
Hide file tree
Changes from1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
NextNext commit
JIT: Borrow references for immortal promoted globals
  • Loading branch information
@Fidget-Spinner
Fidget-Spinner committedDec 18, 2025
commitbaf89716af389c7f1121d4c617959aedb4ac8767
38 changes: 38 additions & 0 deletionsLib/test/test_capi/test_opt.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2972,6 +2972,44 @@ class Obj:
for _ in range(TIER2_THRESHOLD+1):
obj.attr = EvilAttr(obj.__dict__)

def test_promoted_global_refcount_eliminated(self):
result = script_helper.run_python_until_end('-c', textwrap.dedent("""
import _testinternalcapi
import opcode
import _opcode

def get_first_executor(func):
code = func.__code__
co_code = code.co_code
for i in range(0, len(co_code), 2):
try:
return _opcode.get_executor(code, i)
except ValueError:
pass
return None

def get_opnames(ex):
return {item[0] for item in ex}


def testfunc(n):
y = []
for i in range(n):
x = tuple(y)
return x

testfunc(_testinternalcapi.TIER2_THRESHOLD)

ex = get_first_executor(testfunc)
assert ex is not None
uops = get_opnames(ex)
assert "_LOAD_GLOBAL_BUILTIN" not in uops
assert "_LOAD_CONST_INLINE_BORROW" in uops
assert "_POP_TOP_NOP" in uops
assert "_POP_TOP" not in uops
"""), PYTHON_JIT="1")
self.assertEqual(result[0].rc, 0, result)


def global_identity(x):
return x
Expand Down
14 changes: 12 additions & 2 deletionsPython/optimizer_bytecodes.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1370,7 +1370,12 @@ dummy_func(void) {
res=sym_new_not_null(ctx);
}
else {
res=sym_new_const(ctx,cnst);
if (_Py_IsImmortal(cnst)) {
res=PyJitRef_Borrow(sym_new_const(ctx,cnst));
}
else {
res=sym_new_const(ctx,cnst);
}
}
}

Expand DownExpand Up@@ -1405,7 +1410,12 @@ dummy_func(void) {
res=sym_new_not_null(ctx);
}
else {
res=sym_new_const(ctx,cnst);
if (_Py_IsImmortal(cnst)) {
res=PyJitRef_Borrow(sym_new_const(ctx,cnst));
}
else {
res=sym_new_const(ctx,cnst);
}
}
}

Expand Down
14 changes: 12 additions & 2 deletionsPython/optimizer_cases.c.h
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

Loading

[8]ページ先頭

©2009-2025 Movatter.jp