Skip to content

Interpreter associated types#677

Open
zhenrongliew wants to merge 7 commits into
rustfrom
dl/interp-associated-types
Open

Interpreter associated types#677
zhenrongliew wants to merge 7 commits into
rustfrom
dl/interp-associated-types

Conversation

@zhenrongliew

Copy link
Copy Markdown
Collaborator

Summary

This PR focuses on interpreter refactor to consolidate type parameters :

  • collapses Interpretable<L, I, F, C, E, T> into Interpretable<I>
  • moves Value, Error, and statement Effect onto Interp associated types
  • keeps Ctx as the statement-local read/write helper
  • makes ForwardEffect the forward-only statement-to-frame algebra
  • removes the framework-owned Scope / ScopeHook abstraction
  • restores structured traversal as dialect-owned frames: scf.if and scf.for now push SCF-owned concrete/abstract frames

Notes

Enter / EnterAny are gone. Their abstract behavior is now owned by SCF frames. New focused constprop tests cover unknown scf.if joining:

  • same constants join to Const(1)
  • different constants join to Top

Backward/liveness analysis is intentionally deferred to a follow-up PR with its own effect algebra.

zhenrongliew and others added 2 commits June 22, 2026 16:12
…fect algebra

Collapse Interpretable<L, I, F, C, E, T> into Interpretable<I>, moving
Value/Error/Effect onto associated types of Interp. Rename the forward control
enum Effect -> ForwardEffect and expose it as the per-analysis I::Effect
(forward/concrete/constprop engines set type Effect = ForwardEffect<Value, Error>)
via a ForwardInterp helper trait. ForwardEffect stays forward-only (Next, Jump,
Branch, Call, Yield, Return, Enter, EnterAny); future analyses define their own
I::Effect. Frames remain customizable and own traversal. No liveness.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- Introduced total frame types for the toy language, embedding standard framework frames with SCF if/for frames.
- Updated the `Frame` and `AbstractFrame` implementations to support new SCF frames.
- Enhanced documentation to clarify the role of structured control flow in dialects.
- Added tests for constant propagation analysis with `scf.if` constructs, ensuring correct behavior for both identical and differing constant yields.
- Refactored existing tests to accommodate changes in frame handling and analysis.
@zhenrongliew zhenrongliew requested a review from Roger-luo June 23, 2026 16:06
@zhenrongliew zhenrongliew self-assigned this Jun 23, 2026
@zhenrongliew zhenrongliew added area: interpreter Area: issues related to the interpreter. area: Rust Area: issues and pull requests related to Rust code. labels Jun 23, 2026
Comment thread crates/kirin-arith/src/interpreter.rs Outdated
- Updated the implementation of Interpretable and FunctionEntry traits to specialize on ForwardContext instead of Ctx, allowing for a clearer separation of context types for different analyses.
- Modified various interpreter implementations (e.g., If, For, Yield) to utilize ForwardContext for SSA read/write operations.
- Enhanced documentation to reflect the changes in context handling and the specialization boundary between forward and future analyses.
- Adjusted related tests and snapshots to align with the new context structure, ensuring consistency across the interpreter's functionality.
- Renamed `Env` trait to `Store` for clarity in the context of storage capabilities.
- Updated references to `Env` in the `FrameDriver` and `ForwardFrameDriver` traits to reflect the new naming.
- Introduced `ForwardAbstractInterpreter` as the forward dataflow engine, replacing `AbstractInterpreter` in relevant contexts.
- Adjusted documentation to clarify the distinction between shared protocols and forward-specific capabilities.
- Updated example implementations and tests to utilize the new forward dataflow structures.
- Ensured backward compatibility by retaining aliases for the previous frame driver capabilities.
- Introduced `ValueContext` to replace `ForwardContext` across various modules, enhancing clarity and consistency in the interpreter's context management.
- Updated implementations of `Interpretable` and `FunctionEntry` traits to utilize `ValueContext`, ensuring all dialects and functions align with the new context structure.
- Adjusted related documentation to reflect the changes in context usage, emphasizing the role of `ValueContext` in both execution and analysis.
- Removed unnecessary dependencies on `HasTop` in the `AbstractInterpreter` trait, streamlining the trait's requirements.
- Introduced `ForwardAbstractInterpreter` to facilitate forward lattice-based abstract interpretation.
- Added traits for customizable analysis policies: `CallContext` and `WideningStrategy`.
- Implemented context-insensitive analysis with join-until-widen behavior.
- Created `FnInfo` struct to manage function summaries and their associated data.
- Developed methods for analyzing functions by name and running interprocedural fixpoints.
- Added `Interp` and `Env` traits to define shared contracts for concrete execution and analyses.
- Introduced `ForwardEval` and `BackwardLiveness` markers for semantic evaluation types.
- Enhanced SSA storage access with `ForwardEvalInterp` for reading and writing SSA values.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: interpreter Area: issues related to the interpreter. area: Rust Area: issues and pull requests related to Rust code.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants