René's URL Explorer Experiment


Title: JIT: Assertion `PyType_Check((PyObject *)type)` failed · Issue #149112 · python/cpython · GitHub

Open Graph Title: JIT: Assertion `PyType_Check((PyObject *)type)` failed · Issue #149112 · python/cpython

X Title: JIT: Assertion `PyType_Check((PyObject *)type)` failed · Issue #149112 · python/cpython

Description: Crash report What happened? It's possible to make a JIT build abort by running the code below. MRE: def f1(): class C: def __getitem__(self, key): pass c = C() for _ in range(300): c[2] for _ in range(300): f1() Backtrace: python: Python...

Open Graph Description: Crash report What happened? It's possible to make a JIT build abort by running the code below. MRE: def f1(): class C: def __getitem__(self, key): pass c = C() for _ in range(300): c[2] for _ in ra...

X Description: Crash report What happened? It's possible to make a JIT build abort by running the code below. MRE: def f1(): class C: def __getitem__(self, key): pass c = C() for _ in range(300): c[2] for _ i...

Opengraph URL: https://github.com/python/cpython/issues/149112

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"JIT: Assertion `PyType_Check((PyObject *)type)` failed","articleBody":"# Crash report\n\n### What happened?\n\nIt's possible to make a JIT build abort by running the code below.\n\n\nMRE:\n```python\ndef f1():\n    class C:\n        def __getitem__(self, key): pass\n\n    c = C()\n    for _ in range(300):\n        c[2]\n\nfor _ in range(300):\n    f1()\n```\n\nBacktrace:\n```\npython: Python/optimizer_symbols.c:1277: void _Py_uop_sym_set_recorded_type(JitOptContext *, JitOptRef, PyTypeObject *): Assertion `PyType_Check((PyObject *)type)' failed.\n\nProgram received signal SIGABRT, Aborted.\n\n#0  __pthread_kill_implementation (threadid=\u003coptimized out>, signo=6, no_tid=0) at ./nptl/pthread_kill.c:44\n#1  __pthread_kill_internal (threadid=\u003coptimized out>, signo=6) at ./nptl/pthread_kill.c:89\n#2  __GI___pthread_kill (threadid=\u003coptimized out>, signo=signo@entry=6) at ./nptl/pthread_kill.c:100\n#3  0x00007ffff7c45e2e in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26\n#4  0x00007ffff7c28888 in __GI_abort () at ./stdlib/abort.c:77\n#5  0x00007ffff7c287f0 in __assert_fail_base (fmt=\u003coptimized out>, assertion=\u003coptimized out>, file=\u003coptimized out>, line=\u003coptimized out>, function=\u003coptimized out>) at ./assert/assert.c:118\n#6  0x00007ffff7c3c19f in __assert_fail (assertion=\u003coptimized out>, file=\u003coptimized out>, line=\u003coptimized out>, function=\u003coptimized out>) at ./assert/assert.c:127\n#7  0x000055555610a025 in _Py_uop_sym_set_recorded_type (ctx=ctx@entry=0x7bfff480b890, ref=ref@entry=..., type=type@entry=0x7d2ff6e37870) at Python/optimizer_symbols.c:1277\n#8  0x00005555560ebe73 in optimize_uops (tstate=\u003coptimized out>, trace=\u003coptimized out>, trace_len=\u003coptimized out>, curr_stacklen=\u003coptimized out>, output=\u003coptimized out>,\n    dependencies=\u003coptimized out>) at Python/optimizer_cases.c.h:5651\n#9  0x00005555560e4728 in _Py_uop_analyze_and_optimize (tstate=tstate@entry=0x555556a754b8 \u003c_PyRuntime+360760>, buffer=buffer@entry=0x7bfff483e2e0, length=6, length@entry=14,\n    curr_stacklen=curr_stacklen@entry=4, output=0x16, output@entry=0x7bfff484cd40, dependencies=dependencies@entry=0x7bfff5a849a0) at Python/optimizer_analysis.c:796\n#10 0x00005555560d4b0a in uop_optimize (frame=0x7e8ff6de5290, tstate=0x555556a754b8 \u003c_PyRuntime+360760>, progress_needed=false, exec_ptr=\u003coptimized out>) at Python/optimizer.c:1646\n#11 _PyOptimizer_Optimize (frame=\u003coptimized out>, tstate=\u003coptimized out>) at Python/optimizer.c:166\n#12 0x0000555555ef42cb in stop_tracing_and_jit (tstate=0x555556a754b8 \u003c_PyRuntime+360760>, frame=frame@entry=0x7e8ff6de5290) at Python/ceval.c:1088\n#13 0x0000555555eb724a in _PyEval_EvalFrameDefault (tstate=\u003coptimized out>, frame=\u003coptimized out>, throwflag=\u003coptimized out>) at Python/generated_cases.c.h:13130\n#14 0x0000555555e89af8 in _PyEval_EvalFrame (tstate=0x555556a754b8 \u003c_PyRuntime+360760>, frame=0x7e8ff6de5220, throwflag=0) at ./Include/internal/pycore_ceval.h:118\n#15 _PyEval_Vector (tstate=\u003coptimized out>, func=\u003coptimized out>, locals=\u003coptimized out>, args=\u003coptimized out>, argcount=\u003coptimized out>, kwnames=0x0) at Python/ceval.c:2124\n#16 0x0000555555e89515 in PyEval_EvalCode (co=\u003coptimized out>, globals=\u003coptimized out>, locals=0x7c7ff6e89440) at Python/ceval.c:686\n#17 0x000055555617dad0 in run_eval_code_obj (tstate=tstate@entry=0x555556a754b8 \u003c_PyRuntime+360760>, co=co@entry=0x7d1ff6e86cd0, globals=globals@entry=0x7c7ff6e89440,\n    locals=locals@entry=0x7c7ff6e89440) at Python/pythonrun.c:1369\n#18 0x000055555617cc9c in run_mod (mod=\u003coptimized out>, filename=\u003coptimized out>, globals=\u003coptimized out>, locals=\u003coptimized out>, flags=\u003coptimized out>, arena=\u003coptimized out>,\n    interactive_src=\u003coptimized out>, generate_new_source=\u003coptimized out>) at Python/pythonrun.c:1472\n```\n\nOutput of running with `PYTHON_LLTRACE=4 PYTHON_OPT_DEBUG=4`:\n[lltrace_opt_debug.txt](https://github.com/user-attachments/files/27176415/lltrace_opt_debug.txt)\n\n\u003cdetails>\u003csummary>Claude's diagnosis and proposed fix\u003c/summary>\n\u003cp>\n\n## Diagnosis\n\nThe non-type pointer reaching `sym_set_recorded_type` originates as the `operand0` of a `_RECORD_TOS_TYPE` uop in the just-finalized trace. That `operand0` is set from `tracer->prev_state.recorded_values[i]` during translation. The values in those slots were populated by `_PyJit_TryInitializeTracing` (or by the `TRACE_RECORD` step) using the record-function schema for one opcode, but `_PyJit_translate_single_bytecode_to_trace` later interprets those same slots under a *different* opcode's schema, because translation has its own deopt-aware opcode rewrite that initialization does not mirror:\n\n```c\n// Python/optimizer.c, inside _PyJit_translate_single_bytecode_to_trace\nif (_PyOpcode_Caches[_PyOpcode_Deopt[opcode]] > 0) {\n    uint16_t backoff = (this_instr + 1)->counter.value_and_backoff;\n    if (backoff != adaptive_counter_cooldown().value_and_backoff &&\n        backoff != trigger_backoff_counter().value_and_backoff) {\n        opcode = _PyOpcode_Deopt[opcode];\n    }\n}\n```\n\nThe MRE makes this visible with a single seam: each call to `f1()` defines a fresh class `C`, whose specialization cache for `BINARY_OP_SUBSCR_GETITEM` is empty on the first iteration. `_BINARY_OP_SUBSCR_CHECK_FUNC` therefore exits, and a side trace is requested at offset 36 — the same `BINARY_OP` instruction. At that moment:\n\n- the bytecode at offset 36 still reads `BINARY_OP_SUBSCR_GETITEM` (the specialization isn't physically rewritten); but\n- the adaptive counter is in neither cooldown nor trigger state, because tracing just deopted there.\n\nWalking through both functions:\n\n1. `_PyJit_TryInitializeTracing` (`Python/optimizer.c:1156`) reads `curr_instr->op.code` directly:\n   ```c\n   const _PyOpcodeRecordEntry *record_entry =\n       &_PyOpcode_RecordEntries[curr_instr->op.code];\n   ```\n   That's `BINARY_OP_SUBSCR_GETITEM`, whose macro starts with `_RECORD_NOS` — a **value** recorder. So `recorded_values[0]` receives the NOS object itself: `stack[-2]`, which is the `C` *instance* (`Py_TYPE` is never called).\n\n2. `_PyJit_translate_single_bytecode_to_trace` runs the deopt shim shown above. The counter check fires, so `opcode` flips to plain `BINARY_OP`, whose macro is `_SPECIALIZE_BINARY_OP + _RECORD_TOS_TYPE + _RECORD_NOS_TYPE + unused/4 + _BINARY_OP + POP_TOP + POP_TOP`. Translation now emits `_RECORD_TOS_TYPE` and `_RECORD_NOS_TYPE` and consumes `recorded_values[0]` and `recorded_values[1]` as their `operand0`s.\n\n3. The optimizer's abstract interpreter (`case _RECORD_TOS_TYPE` at `Python/optimizer_cases.c.h:5651`):\n   ```c\n   PyTypeObject *tp = (PyTypeObject *)this_instr->operand0;\n   sym_set_recorded_type(tos, tp);\n   ```\n   `tp` is the `C` instance. `PyType_Check(tp)` fails. Abort.\n\n(`recorded_values[1]` is also wrong — it's whatever the slot held before, since the GETITEM schema only ever wrote slot 0 — but it never gets reached because slot 0 trips the assertion first.)\n\nThis isn't specific to subscript: any opcode whose specialized form has a different record schema from its deopted form is vulnerable, since the schemas drive both the *set* of recorded slots and what each slot is assumed to be.\n\nCaptured optimizer trace at the failing site (truncated to the relevant uops):\n\n```\n   0 abs: _START_EXECUTOR (target=36)\n   ...\n   3 abs: _SET_IP (target=36, operand0=\u003cbytecode>)\n   4 abs: _RECORD_TOS_TYPE (oparg=26, target=36, operand0=0x...ec30)  ← C instance\n   ABORT\n```\n\nAnd the lltrace just before:\n\n```\nSIDE EXIT: ... target 36 -> BINARY_OP_SUBSCR_GETITEM\nstack=[range_iter, NULL, \u003cC inst @0x...ec30>, \u003cint 2>]\n```\n\n## Fix\n\nApply the same deopt-aware opcode rewrite inside `_PyJit_TryInitializeTracing` before computing `record_entry`, so initialization and translation agree on which schema is in force. Local change in `Python/optimizer.c`:\n\n```c\n// Mirror the opcode-deopt decision in _PyJit_translate_single_bytecode_to_trace:\n// if the cache backoff indicates a deopt during prior tracing, the translator\n// will use the deopted opcode -- so we must record values for that opcode too,\n// otherwise the recorded_values produced here are interpreted under a\n// different uop-record schema (e.g. BINARY_OP_SUBSCR_GETITEM records 1 NOS\n// value while BINARY_OP records 2 type slots), and the resulting trace gets\n// a non-type pointer as the operand0 of _RECORD_TOS_TYPE.\nint record_opcode = curr_instr->op.code;\nif (_PyOpcode_Caches[_PyOpcode_Deopt[record_opcode]] > 0) {\n    uint16_t backoff = (curr_instr + 1)->counter.value_and_backoff;\n    if (backoff != adaptive_counter_cooldown().value_and_backoff &&\n        backoff != trigger_backoff_counter().value_and_backoff) {\n        record_opcode = _PyOpcode_Deopt[record_opcode];\n    }\n}\nconst _PyOpcodeRecordEntry *record_entry = &_PyOpcode_RecordEntries[record_opcode];\n```\n\n`oparg` doesn't need to change — it's the bytecode-level oparg, identical for the specialization and its deopted form (e.g. `NB_SUBSCR` = 26 for both `BINARY_OP` and `BINARY_OP_SUBSCR_GETITEM`). The translator independently fetches its own `instr_oparg` out of `prev_state`, which `_PyJit_TryInitializeTracing` set from the same source. Only the record schema was inconsistent, and that's exactly what this rewrite repairs.\n\nFactoring the deopt check into a small shared helper used by both functions would also work and would be more robust against future drift; this snippet sticks to the minimum-surface change.\n\n## Verification\n\n- The MRE aborts on unmodified `main` and runs to completion (5/5) with the patch.\n- The same `TRACE_RECORD` path in `Python/generated_cases.c.h:12506` already runs on the *executed* opcode (after the JIT-tracing instruction has been resolved), so it's not affected; the bug is specific to side-trace start, where init reads the bytecode-as-stored.\n\n\u003c/p>\n\u003c/details>\n\nFound using [lafleur](https://github.com/devdanzin/lafleur/).\n\n### CPython versions tested on:\n\nCPython main branch, 3.15\n\n### Operating systems tested on:\n\nLinux\n\n### Output from running 'python -VV' on the command line:\n\nPython 3.15.0a8+ (heads/main-dirty:804c213c893, Apr 28 2026, 08:55:31) [Clang 21.1.2 (2ubuntu6)]","author":{"url":"https://github.com/devdanzin","@type":"Person","name":"devdanzin"},"datePublished":"2026-04-28T17:57:47Z","url":"https://github.com/python/cpython/issues/149112"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:099fef51-a0e6-2366-c0fb-985ca2b0c522
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idC488:3A4875:352F633:46D4A1F:6B0202A4
html-safe-noncea186da3534e84fcc88ea3c504325a3cca51357d70d3fbb0379fa2ebceefde818
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNDg4OjNBNDg3NTozNTJGNjMzOjQ2RDRBMUY6NkIwMjAyQTQiLCJ2aXNpdG9yX2lkIjoiNzk3MTM3MDk0NzEwNDA4MDU0OSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac8dae5a994d09fad272ccabe4bfedfd783aad9969ea7e91d57cfeab10e19b8666
hovercard-subject-tagissue:4345205000
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/149112/issue_layout
twitter:imagehttps://opengraph.githubassets.com/cafe8ea357fe268795dd3edb3cc4fea947c29fd38bbf4f7f6ddf64f0fd3dd70e/python/cpython/issues/149112
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/cafe8ea357fe268795dd3edb3cc4fea947c29fd38bbf4f7f6ddf64f0fd3dd70e/python/cpython/issues/149112
og:image:altCrash report What happened? It's possible to make a JIT build abort by running the code below. MRE: def f1(): class C: def __getitem__(self, key): pass c = C() for _ in range(300): c[2] for _ in ra...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamedevdanzin
hostnamegithub.com
expected-hostnamegithub.com
None87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456
turbo-cache-controlno-preview
go-importgithub.com/python/cpython git https://github.com/python/cpython.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id81598961
octolytics-dimension-repository_nwopython/cpython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id81598961
octolytics-dimension-repository_network_root_nwopython/cpython
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release423dbb54c5e7bfecc838eb387c1435eb3d0e760d
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/python/cpython/issues/149112#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F149112
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F149112
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/issues/149112
Reloadhttps://github.com/python/cpython/issues/149112
Reloadhttps://github.com/python/cpython/issues/149112
pythonhttps://github.com/python
cpythonhttps://github.com/python/cpython
Codehttps://github.com/python/cpython
Issues5k+ (5k+)https://github.com/python/cpython/issues
Pull requests2.4k (2.4k)https://github.com/python/cpython/pulls
Actionshttps://github.com/python/cpython/actions
Projectshttps://github.com/python/cpython/projects
Security and qualityhttps://github.com/python/cpython/security
Insightshttps://github.com/python/cpython/insights
https://github.com/python/cpython
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/149112
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/149112
JIT: Assertion PyType_Check((PyObject *)type) failedhttps://github.com/python/cpython/issues/149112#top
interpreter-core(Objects, Python, Grammar, and Parser dirs)https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%22
topic-JIThttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-JIT%22
type-crashA hard crash of the interpreter, possibly with a core dumphttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-crash%22
https://github.com/devdanzin
devdanzinhttps://github.com/devdanzin
on Apr 28, 2026https://github.com/python/cpython/issues/149112#issue-4345205000
lltrace_opt_debug.txthttps://github.com/user-attachments/files/27176415/lltrace_opt_debug.txt
lafleurhttps://github.com/devdanzin/lafleur/
devdanzinhttps://github.com/devdanzin
interpreter-core(Objects, Python, Grammar, and Parser dirs)https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%22
type-crashA hard crash of the interpreter, possibly with a core dumphttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-crash%22
topic-JIThttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-JIT%22
on Apr 28, 2026https://github.com/python/cpython/issues/149112#event-24959783534
https://github.com/NekoAsakura
NekoAsakurahttps://github.com/NekoAsakura
on May 10, 2026https://github.com/python/cpython/issues/149112#issuecomment-4416556538
@cocolatohttps://github.com/cocolato
#148730https://github.com/python/cpython/pull/148730
devdanzinhttps://github.com/devdanzin
completedhttps://github.com/python/cpython/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on May 11, 2026https://github.com/python/cpython/issues/149112#event-25363940297
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/cpython/issues/149112
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/cpython/issues/149112
interpreter-core(Objects, Python, Grammar, and Parser dirs)https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%22
topic-JIThttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-JIT%22
type-crashA hard crash of the interpreter, possibly with a core dumphttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-crash%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.