python / python/cpython

Move const folding to the peephole optimizer

Ouverte
#126,835 123 commentaires 6 réactions 2 personnes assignées Voir sur GitHub

@tomasr8 y travaille déjà.

Depuis le 21/12/2024.

interpreter-core type-feature
Langage dominant
Python
Étoiles
77.2k
Forks
35.9k
Métriques de merge des PR
Métriques de PR en attente

Description

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

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.