Skip to content

Commit 4eb3e98

Browse files
authored
Merge branch 'main' into gh-148380/remove-LookupByVersion
2 parents c84a36a + 4286227 commit 4eb3e98

File tree

7 files changed

+74
-6
lines changed

7 files changed

+74
-6
lines changed

Doc/library/argparse.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2032,6 +2032,9 @@ Argument groups
20322032
Note that any arguments not in your user-defined groups will end up back
20332033
in the usual "positional arguments" and "optional arguments" sections.
20342034

2035+
Within each argument group, arguments are displayed in help output in the
2036+
order in which they are added.
2037+
20352038
.. deprecated-removed:: 3.11 3.14
20362039
Calling :meth:`add_argument_group` on an argument group now raises an
20372040
exception. This nesting was never supported, often failed to work

Include/internal/pycore_opcode_metadata.h

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Lib/test/test_capi/test_opt.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3435,6 +3435,25 @@ def f(n):
34353435
self.assertNotIn("_LOAD_ATTR_METHOD_NO_DICT", uops)
34363436
self.assertIn("_LOAD_CONST_INLINE_BORROW", uops)
34373437

3438+
def test_cached_load_special(self):
3439+
class CM:
3440+
def __enter__(self):
3441+
return self
3442+
def __exit__(self, *args):
3443+
pass
3444+
def f(n):
3445+
cm = CM()
3446+
x = 0
3447+
for _ in range(n):
3448+
with cm:
3449+
x += 1
3450+
return x
3451+
res, ex = self._run_with_optimizer(f, TIER2_THRESHOLD)
3452+
self.assertIsNotNone(ex)
3453+
self.assertEqual(res, TIER2_THRESHOLD)
3454+
uops = get_opnames(ex)
3455+
self.assertNotIn("_LOAD_SPECIAL", uops)
3456+
34383457
def test_store_fast_refcount_elimination(self):
34393458
def foo(x):
34403459
# Since x is known to be

Python/bytecodes.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3884,6 +3884,7 @@ dummy_func(
38843884
}
38853885

38863886
macro(LOAD_SPECIAL) =
3887+
_RECORD_TOS_TYPE +
38873888
_INSERT_NULL +
38883889
_LOAD_SPECIAL;
38893890

Python/optimizer_bytecodes.c

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1845,8 +1845,30 @@ dummy_func(void) {
18451845
}
18461846

18471847
op(_LOAD_SPECIAL, (method_and_self[2] -- method_and_self[2])) {
1848-
method_and_self[0] = sym_new_not_null(ctx);
1849-
method_and_self[1] = sym_new_unknown(ctx);
1848+
bool optimized = false;
1849+
PyTypeObject *type = sym_get_probable_type(method_and_self[1]);
1850+
if (type != NULL) {
1851+
PyObject *name = _Py_SpecialMethods[oparg].name;
1852+
PyObject *descr = _PyType_Lookup(type, name);
1853+
if (descr != NULL && (Py_TYPE(descr)->tp_flags & Py_TPFLAGS_METHOD_DESCRIPTOR)) {
1854+
ADD_OP(_GUARD_TYPE_VERSION, 0, type->tp_version_tag);
1855+
bool immortal = _Py_IsImmortal(descr) || (type->tp_flags & Py_TPFLAGS_IMMUTABLETYPE);
1856+
ADD_OP(immortal ? _LOAD_CONST_INLINE_BORROW : _LOAD_CONST_INLINE,
1857+
0, (uintptr_t)descr);
1858+
ADD_OP(_SWAP, 3, 0);
1859+
ADD_OP(_POP_TOP, 0, 0);
1860+
if ((type->tp_flags & Py_TPFLAGS_IMMUTABLETYPE) == 0) {
1861+
PyType_Watch(TYPE_WATCHER_ID, (PyObject *)type);
1862+
_Py_BloomFilter_Add(dependencies, type);
1863+
}
1864+
method_and_self[0] = sym_new_const(ctx, descr);
1865+
optimized = true;
1866+
}
1867+
}
1868+
if (!optimized) {
1869+
method_and_self[0] = sym_new_not_null(ctx);
1870+
method_and_self[1] = sym_new_unknown(ctx);
1871+
}
18501872
}
18511873

18521874
op(_JUMP_TO_TOP, (--)) {

Python/optimizer_cases.c.h

Lines changed: 24 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/record_functions.c.h

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)