python / python/cpython

Move const folding to the peephole optimizer

未關閉
#126,835 123 則留言 6 個 reaction 已指派 2 人 在 GitHub 檢視

@tomasr8 已經在處理了。

開始於 2024年12月21日。

interpreter-core type-feature
主要語言
Python
星號
77.2k
分支
36k
PR 合併指標
PR 指標待擷取

描述

Feature or enhancement

Proposal:

For additional context see https://github.com/python/cpython/pull/126830#issuecomment-2476525196.

Flow graph optimizer has more information and can do better job.

The problem is that we need to convert from UNARY_OP(-, CONST(1)) to CONST(-1), still before the code generation phase, because this leads to a few problems, one of which is shown below.

x = 1

match x:
    case -0:
        y = 0
eclips4@nixos ~/p/p/cpython (remove-ast-optimizer)> ./python example.py
  File "/home/eclips4/programming/programming-languages/cpython/example.py", line 4
    case -0:
         ^^
SyntaxError: patterns may only match literals and attribute lookups

cc @markshannon

Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

No response

Linked PRs
  • gh-128802
  • gh-129426
  • gh-129550
  • gh-129568
  • gh-129634
  • gh-129703
  • gh-129963
  • gh-130016
  • gh-130032
  • gh-130109
  • gh-130769
  • gh-131054
  • gh-131826
  • gh-131830
  • gh-146631
  • gh-147187

貢獻指南

開啟貢獻指南

從這裡開始

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

評估

這個 Issue 還沒有評估資料。

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

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