python / python/cpython

refactor the implementation of inlined comprehensions

Offen
#124,697 5 Kommentare 4 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

interpreter-core type-refactor
Vorherrschende Sprache
Python
Sterne
77.2k
Forks
35.9k
PR-Merge-Kennzahlen
PR-Kennzahlen ausstehend

Beschreibung

The current implementation of comprehension inlining is a pile of special cases that is quite difficult to understand and debug. The root cause of this is that it attempts to flatten the inlined scope into the enclosing scope in the symbol table, to avoid the compiler needing to generally understand the concept of inlined sub-scopes, but this flattening loses information and requires a number of special cases. And then the compiler implementation of inlining modifies the flattened scope as it traverses the inlined comprehension(s) in order to ensure correct handling of the names within the inlined sub-scope; ideally the compiler would not modify the symbol table as it generates code.

A better implementation would leave the scopes separate in the symbol table, losing no information but just marking the comprehension scope as an inlined sub-scope, and then add explicit support for inlined sub-scopes in the compiler (with appropriate query methods in the symtable.)

Linked PRs
  • gh-156819

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Prüfe zuerst den verlinkten PR gh-156819, da der Issue angibt, dass die Arbeit dorthin verlagert wurde. Andernfalls verfolge das Inlining von Comprehensions durch CPythons symbol-table- und compiler-Implementierung; als abgeschlossen gilt die Arbeit, wenn separate inline eingefügte Subscopes in der symbol table erhalten bleiben und explizite compiler-Unterstützung hinzugefügt wird, ohne die symbol table während der Codegenerierung zu ändern.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
compilers
Issue-Typ
Refactoring
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Muss geklärt werden
Anfängerfreundlichkeit
20/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.