Generalize interpreter traversal over CFG, Block, DiGraph, and UnGraph bodies - #684
Open
zhenrongliew wants to merge 21 commits into
Open
Generalize interpreter traversal over CFG, Block, DiGraph, and UnGraph bodies#684zhenrongliew wants to merge 21 commits into
zhenrongliew wants to merge 21 commits into
Conversation
This commit introduces a new test file `body_kinds.rs` that contains acceptance tests for the generic interpreter bodies. The tests cover various scenarios including: - A Cfg-bodied `main` calling a DiGraph-bodied function. - A statement inside a Cfg block that owns a DiGraph body. - A linear callable with a flat instruction list. - Ensuring that graph nodes run in topological order. These tests aim to validate the interaction between Cfg-SSA code and DiGraph computational graphs, ensuring correct execution and error handling.
- Renamed `BodyFrame` to `BlockFrame` and adjusted related documentation to reflect the new terminology. - Enhanced the `ToyFrame` enum to include `BlockFrame` and `CfgFrame`, replacing `BodyFrame`. - Updated `FrameBuild` implementations in `ToyFrame` and `TracingFrame` to accommodate the new frame types. - Revised tests in `tests/body_kinds.rs` to ensure compatibility with the updated frame structure. - Added comprehensive tests for structured control flow (SCF) operations, including `scf.if` and `scf.for`, demonstrating their integration with the new frame types. - Implemented a custom callable-UnGraph policy to handle ungraph traversal, ensuring proper execution order and output handling.
Resolve conflicts from the Region->CFG rename (#683, now in rust): - Apply the same Cfg->CFG / CFGs->CFG naming to this branch's changes. - Keep this branch's restructure of concrete/frames.rs into concrete/frames/ (drop the stale single-file frames.rs that rust only renamed). - Drop now-unused CFG imports surfaced by the merge. All tests (1234) and doctests pass; fmt and clippy clean.
Roger-luo
reviewed
Jul 17, 2026
Builders set `SSAInfo.kind` (use→def) but nobody ever populated
`SSAInfo.uses` (def→use). Both finalize paths just copied an
always-empty vec through. So finalized IR shipped an empty def-use.
- `StageInfo::rebuild_use_index()`: clears every live value's `uses,`
then scans each live statement's operands (`HasArguments` order) and
records one `Use { stmt, operand_index } `on the value each slot reads.
Idempotent, so the future rewriter can re-run it. Skips deleted
statements/tombstoned SSAs.
- both `finalize()` and `finalize_unchecked()` call it before returning.
- `Use` gains `new()` + `stmt()/operand_index()` accessors, `Copy`, and
serde parity with its container `SSAInfo`.
- `rebuild_use_index` now scan over nodes.digraphs, pushing a
`DiGraphYield { graph, index }` into `SSAInfo.uses`.
```rust
pub enum Use {
StatementOperand { stmt: Statement, index: usize },
DiGraphYield { graph: DiGraph, index: usize },
}
```
Roger-luo
reviewed
Jul 24, 2026
Roger-luo
reviewed
Jul 24, 2026
Roger-luo
reviewed
Jul 24, 2026
Roger-luo
reviewed
Jul 24, 2026
Roger-luo
reviewed
Jul 24, 2026
Roger-luo
reviewed
Jul 24, 2026
Roger-luo
reviewed
Jul 24, 2026
Roger-luo
reviewed
Jul 24, 2026
…_state_mut methods for state management. - Introduced the DenseBackwardState trait to handle state renaming and forgetting. - Updated the LiveSet implementation to conform to the DenseBackwardState contract. - Modified various interpreters and frames to utilize the new DenseBackwardState trait. - Enhanced documentation to clarify the role of DenseBackwardState in the context of classic liveness and dense backward analysis. - Added tests to validate the behavior of the new forward dataflow engine with constant propagation.
… traversal - Added AbstractDiGraphFrame to handle graph bodies in a single pass. - Updated Owner enum to include Graph variant for executable graph bodies. - Enhanced SparseForwardInterpreter to support DiGraph bodies. - Modified tests to validate the new graph handling and ensure correct execution order.
Roger-luo
reviewed
Jul 31, 2026
Roger-luo
left a comment
Collaborator
There was a problem hiding this comment.
just need to address the leftover comments
- Added a test to validate the mismatch between callable-body policies when the `#[interpret(body_frames = ...)]` attribute is not specified
…ts split by consumer.
This was
linked to
issues
Aug 5, 2026
Roger-luo
requested changes
Aug 7, 2026
- Introduced `BlockParent` enum to represent the immediate owner of a block, allowing for clearer ownership semantics between CFGs and statements. - Updated `BlockInfo` to include a `predecessors` field for reverse control-flow indexing, facilitating demand analysis. - Modified builders to correctly assign parents to blocks and graphs, ensuring ownership integrity during construction. - Removed unused boundary location structures and related code to streamline the anchor module.
…point fact retrieval
…tStatement + PreviousStatement
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Generalize interpreter body traversal beyond CFGs
Part of #667. This addresses the second follow-up identified in the issue:
Depends on the Region → CFG rename PR.
Summary
Bodyvocabulary covering:CfgBlockDiGraphUnGraphCfgFrametraverses CFGs.BlockFrametraverses one Block.DiGraphFrametraverses a directed computational graph.CallFramemanages callee resolution, activation lifetime, returns, and caller result binding.FrameBuild::from_ungraph_entry; otherwise the interpreter reportsNoDefaultWalker.Scope
Bodyremains an intentionally closed enum of Kirin’s built-in body representations. The extensibility point for UnGraph is its traversal policy, since an undirected graph has no inherent execution order.The remaining toy-lang sparse/dense liveness simplification from #667 is left for a separate PR.