python / python/cpython

Compiler RecursionError more likely to occur in 3.13

未關閉
#120,331 4 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

topic-parser type-bug
主要語言
Python
星號
77.2k
分支
35.9k
PR 合併指標
PR 指標待擷取

描述

Bug report

Bug description:

Reference: https://github.com/sympy/sympy/issues/26692

There's a long expression in sympy that's causing a RecursionError in ast.c. The source of the RecursionError is https://github.com/python/cpython/blob/ffc8e21c80627c46be7a7467ee5427924fdeb885/Python/ast.c#L217.

This seems to happen with a 3.13 debug build due to a lower recursion limit. The error doesn't happen in 3.13 release.

Interestingly, the error doesn't happen in the 3.12 debug build, even though the recursion limit appears to be the same. This leads me to believe that 3.13 is causing more recursive calls than expected. I think we should investigate why 3.13 is making additional calls and/or raise the recursion limit.

Simple repro:

import ast
contents = "x = " + " * ".join(["1"] * 2000)
result = ast.parse(contents)

On 3.12 debug, this code runs fine. On 3.13 debug, this code causes a RecursionError even when we change 2000 to 500 (leading me to believe that it is not the case that 3.13 is just adding a constant number of additional calls).

CPython versions tested on:

3.12, 3.13

Operating systems tested on:

Linux

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

首先在 3.12 和 3.13 的 debug 建置中使用 ast.parse 重現該運算式,然後檢查 Python/ast.c 中回報的第 217 行附近的遞迴檢查。確定 3.13 為什麼會進行額外的遞迴呼叫,或遞迴限制是否不恰當;完成的標準是解決該回歸問題,並驗證所提供的重現不再失敗。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
python
領域
compilers
Issue 類型
缺陷
難度
4/5
預估耗時
3-5 天
活躍度
停滯
描述清晰度
基本清楚
新手友好度
32/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。