Skip to content

refactor(agentic): decompose queue frontend foundations and lowering - #148

Merged
zhoubot merged 17 commits into
PTO-ISA:mainfrom
hmljy2020:refactor/queue-frontend-foundations
Sep 17, 2026
Merged

zhoubot merged 17 commits into
PTO-ISA:mainfrom
hmljy2020:refactor/queue-frontend-foundations

Conversation

@hmljy2020

@hmljy2020 hmljy2020 commented Sep 16, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • decompose the monolithic Queue frontend into the private _queue_compiler package: source/provenance helpers, AST normalization, immutable model definitions, static type analysis, ACIR text rendering, expression emission, QueueProgram -> raw ACIR lowering, parser state/context, module specialization, and ordered Queue/Memory/Table/Slot/endpoint statement handlers
  • keep _queue_frontend.py as the compatibility and source-lowering facade
  • explicitly re-export all 131 legacy top-level frontend definitions with canonical object identity; preserve existing private import paths during the staged [Agentic Circuit/Frontend] 渐进拆分 _queue_frontend.py 的解析、分析与 lowering 职责 #147 migration
  • preserve ACPy, raw ACIR, direct GFSim C++, diagnostics, source locations, specialization metadata, SSA order, and public behavior
  • reduce _queue_frontend.py from about 19,700 lines to under 200 lines without redesigning parsing or semantics

Issue #147 Progress

This PR completes the mechanical extraction through source/normalization, model/static types, expression/lowering, explicit parser state/context, resource statement handlers, and module orchestration.

Still intentionally deferred:

  • separation of rule parsing from effect analysis
  • removal of parser-time expression validation coupling
  • replacement of inherited selection-alias shadowing
  • final removal of temporary private facade re-exports after repository callers migrate

Lowering consumes the captured QueueProgram and its stored expression ASTs; it does not reparse Python source or recompute parser effects.

pyc6 Decision / Contract Impact

  • Decision 0148 is preserved; no semantic change
  • no dialect, verifier, pass, backend, scheduling, or runtime behavior changes
  • diagnostic registry changes update source provenance only

Review Fixes

  • restored the complete legacy facade compatibility inventory after review found dropped private imports
  • moved semantic type rendering into dependency-free _queue_compiler/type_rendering.py
  • restored package-wide enforcement that .mlir() is called only through _render_type
  • removed dead parser aliases while retaining the intentional source_frame compatibility re-export

Validation

  • required GitHub G0 checks passed on the original head; refreshed checks are required for the review fix commit
  • frontend: 410 tests passed, 5 skipped
  • contracts: 57 passed
  • root unit suite: 147 passed
  • import-order matrix: 21/21 passed
  • facade/type-hygiene focused tests: 12/12 passed
  • 217 representative base/head differential lowerings: zero mismatches
  • repeated lowering: zero determinism mismatches
  • import graph: acyclic
  • contract checker, diagnostic catalog, compileall, changed-file pre-commit, API hygiene, and diff check passed

The one native JIT frontend case also passed when pointed at the current acir-opt and acir-queue-cxxgen tools. Release-only AC G1/G2, Verilator, and release closure remain outside this Python-only refactor PR.

Risk / Compatibility

Related Issues

@hmljy2020 hmljy2020 changed the title refactor(agentic): isolate queue frontend foundations refactor(agentic): decompose queue frontend foundations and lowering Sep 16, 2026
@hmljy2020

Copy link
Copy Markdown
Collaborator Author

已推送 Queue parser 第一轮内部拆分,PR head 已从 48d981be fast-forward 到 fd08d0bd

本轮新增三个可独立审阅和回退的提交:

  • 0d292704 refactor(agentic): introduce queue parser state
  • 78a90cd3 refactor(agentic): extract queue graph statement handlers
  • fd08d0bd refactor(agentic): extract queue terminal statement handlers

完成内容:

  • 增加私有 _ParserEnvironment_ParserState,统一保存只读类型、静态参数、rule 定义、binding、名称索引、source frame 和唯一的 statement order
  • 建立显式有序 HANDLED / UNHANDLED handler 协议,调用优先级、递归和 continue 仍由 parser 明确控制;
  • 迁移 merge、reorder、depend、collection select、credit、selected/direct memory request 和已移除 Queue.memory 的诊断;
  • 迁移 barrier、route、fork、expect、observe、sink 和 return;
  • 更新 diagnostic registry 的实现源码位置;
  • visit() 已缩减到 2,937 行;handler 不反向导入 parser/facade,parser 未重新依赖 _queue_frontend.py

最终验证:

  • frontend:406 passed,2 skipped;
  • contracts:53 passed;
  • pytest tests/unit -m unit:147 passed;
  • frontend/compile 确定性检查:5 passed;
  • diagnostic catalog、compileall、changed-file pre-commit、import/unused-import 检查和 git diff --check 均通过。

完整 CLI lane 仍报告本机环境/已有构建库存问题:48 passed、6 failed、2 errors、1 skipped。失败集中于 linux-aarch64 SDK planning 未支持、staged runtime fixture 仍含 LLVM header,以及本地 native extension 的 module inventory/order 与当前源码不一致;没有失败指向本轮 parser/handler 文件。

本轮保持纯结构重构,不改变 Python 语法、QueueProgram、诊断文本、ACIR 或 GFSim C++ 语义,也未触及 dialect/pass/verifier/backend,因此未扩大到 G1/G2/Verilator。

@zhoubot zhoubot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed at 7f8cd41. Independent code review: APPROVE; architectural status: CLEAR. The legacy facade compatibility blocker, package-wide type-rendering boundary, and dead extraction aliases are fixed. Frontend 410/410 (5 skipped), contracts 57/57, unit 147/147, import-order 21/21, differential lowering 217/217, and both required G0 checks pass.

@zhoubot
zhoubot merged commit 6752411 into PTO-ISA:main Sep 17, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants