python / python/cpython

refactor the implementation of inlined comprehensions

未关闭
#124,697 5 条评论 4 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

interpreter-core type-refactor
主要语言
Python
星标
77.2k
派生
35.9k
PR 合并指标
PR 指标待抓取

描述

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

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

先查看链接的 PR gh-156819,因为 issue 表明工作已经转移到那里。否则,请通过 CPython 的 symbol-table 和 compiler 实现跟踪 comprehension inlining;完成标准是保留 symbol table 中独立的内联 sub-scope,并添加显式的 compiler 支持,同时不在代码生成期间修改 symbol table。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
compilers
Issue 类型
重构
难度
5/5
预计耗时
一周以上
活跃度
停滞
描述清晰度
需要澄清
新手友好度
20/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。