C call specialization misses with `METH_CLASS`, `METH_STATIC` or `METH_COEXIST`
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 35/100
Direzione di ricerca
Salva l’esempio fornito come repro.py ed eseguilo con PYTHON_JIT=0 su CPython 3.13 o versione successiva per riprodurre gli adaptive-counter misses. Leggi la specializzazione citata in Python/specialize.c e i controlli del guard e di Tier 2 in Python/bytecodes.c. Il lavoro è completato quando entrambi i call site riportano hit e i test di regressione di Tier 1 e Tier 2 coprono i flags interessati.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Bug report
Bug description:
The specializer ignores METH_CLASS, METH_STATIC and METH_COEXIST when selecting a specialized C-call instruction, but the corresponding flag guards compare all flags. Affected calls fail these guards and fall back to generic CALL, even after repeated specialization. Return values are correct.
Save this as repro.py and run PYTHON_JIT=0 python repro.py with CPython 3.13 or newer:
import dis
import math
def counter(f):
call = [i for i in dis.get_instructions(f, adaptive=True)
if i.baseopname == "CALL"][-1]
cache = {name: data for name, _, data in call.cache_info}
return call.opname, cache["counter"]
def control():
math.gcd(4, 6)
def affected():
dict.fromkeys((), None)
for f in control, affected:
for _ in range(100):
f()
before = counter(f)
for _ in range(10):
f()
print(f.__name__, before[0], "hit" if counter(f) == before else "miss")
Output from an unpatched Linux build of 5539c2a5437 (3.16.0a0):
control CALL_BUILTIN_FAST hit
affected CALL_BUILTIN_FAST miss
Both call sites should report hit. The example detects misses by comparing the adaptive counter before and after ten calls.
For dict.fromkeys, the specializer masks out METH_CLASS and selects CALL_BUILTIN_FAST, but its guard requires exactly METH_FASTCALL. The actual flags are METH_FASTCALL | METH_CLASS. The method-descriptor guards and corresponding Tier 2 optimizer checks have the same mismatch.
I also reproduced the issue on Linux with CPython 3.13.14, 3.14.7, 3.14.7 free-threaded and 3.15.0rc2.
More cases, pystats results, timing measurements and source analysis.
I have a patch with Tier 1 and Tier 2 regression tests and will open a PR.
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Linked PRs
- gh-157834
- Lingua principale
- Python
- Stelle
- 77.2k
- Fork
- 36k
- Merge medio
- 1g 9h
- PR unite (30g)
- 558
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di python/cpython
-
docs pending
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
-
stdlib type-feature
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
-
stdlib type-feature
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
-
build type-bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
-
stdlib topic-email type-feature
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
Tutte le issue di python/cpython
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
qgis/QGIS-Documentation#11275 ·
-
bug priority:normal ready-for-dev
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
OpenHands/extensions#626 · 1 commento ·
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
CSCfi/sd-search-api#39 ·
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
-
please add to porn list Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
StevenBlack/hosts#3255 ·