Skip to content

Add lattice anchors and liveness analysis (strong demand and classic liveness)#682

Open
zhenrongliew wants to merge 5 commits into
dl/interp-associated-typesfrom
dl/liveness
Open

Add lattice anchors and liveness analysis (strong demand and classic liveness)#682
zhenrongliew wants to merge 5 commits into
dl/interp-associated-typesfrom
dl/liveness

Conversation

@zhenrongliew

Copy link
Copy Markdown
Collaborator

Stacked on #677.

This PR adds the liveness analysis layer on top of the interpreter framework:

  • Adds LatticeAnchor plus sparse/dense fact anchors and scoped fact stores
  • Splits semantic keys from analysis shapes: sparse/dense × forward/backward
  • Adds sparse backward demand for strong liveness
  • Adds dense backward per-point liveness with block summaries
  • Wires dialect rules for StrongDemand and ClassicLiveness

After #677 lands, this PR can be retargeted from dl/interp-associated-types to rust.

- Introduced `analyze_liveness` function to perform strong demand and classic per-point liveness analysis on toy programs.
- Updated `ToyDenseLiveness` to support dense backward liveness analysis with SCF dense frames.
- Updated the main interpreter module to include new dependencies and types for liveness analysis.
- Introduced `SemanticKey` trait and various implementations for forward evaluation, strong demand, and classic liveness in `keys.rs`.
- Created `AnalysisShape` trait and its implementations for sparse and dense shapes in `shape.rs`.
@zhenrongliew zhenrongliew requested review from Roger-luo and Copilot July 6, 2026 15:21
@zhenrongliew zhenrongliew added area: interpreter Area: issues related to the interpreter. area: Rust Area: issues and pull requests related to Rust code. area: Kirin-rs Area: Rust-version Kirin related components. labels Jul 6, 2026

Copilot AI 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.

Pull request overview

This PR layers liveness analysis on top of the interpreter framework by introducing explicit “semantic keys” vs “analysis shapes”, adding sparse backward demand (strong liveness) and dense backward classic per-point liveness, and wiring dialect/CLI support for running both analyses.

Changes:

  • Introduce semantic keys (ForwardEval, StrongDemand, ClassicLiveness) decoupled from solver mechanics via analysis shapes (sparse/dense × forward/backward), plus new fact anchors/stores and region topology queries.
  • Add a new kirin-liveness crate with results types and integration tests exercising both sparse demand and dense classic liveness over parsed CFG programs.
  • Update dialect interpreters (arith/cf/bitwise/cmp/constant/function/tuple) and toy-lang CLI to support demand + classic liveness alongside existing forward evaluation / constprop.

Reviewed changes

Copilot reviewed 81 out of 84 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
example/toy-lang/src/main.rs Adds --liveness CLI path and prints demanded set + dense boundary sets.
example/toy-lang/src/interpreter/mod.rs Adds toy-lang liveness entrypoints and region selection for analysis.
example/toy-lang/src/interpreter/frame.rs Updates forward frame bounds and adds dense-backward total frame composition for SCF.
example/toy-lang/Cargo.toml Adds kirin-liveness dependency.
docs/design/formalism/type-system-and-abstract-interpretation.md Updates forward engine naming references (SparseForwardInterpreter).
docs/design/formalism/state-environment-model.md Updates forward helper naming references (SparseForwardInterp).
docs/design/formalism/operational-semantics.md Updates forward abstract engine naming references.
docs/design/formalism/index.md Updates forward helper naming reference in the formalism overview.
crates/kirin-tuple/src/tests.rs Updates purity expectations for tuple ops.
crates/kirin-tuple/src/lib.rs Marks tuple dialect/ops as #[kirin(pure)].
crates/kirin-tuple/src/interpreter.rs Adds backward demand + classic liveness rules; updates forward effect naming.
crates/kirin-test-languages/src/arith_function_language.rs Adds manual backward demand and classic-liveness dispatch for test language.
crates/kirin-test-languages/Cargo.toml Adds optional kirin-interpreter dep and interpreter feature.
crates/kirin-scf/src/lib.rs Re-exports new dense-backward SCF frame builders/frames.
crates/kirin-liveness/tests/cfg.rs New integration tests for strong demand + dense classic liveness.
crates/kirin-liveness/src/result.rs Result types for demanded set and dense per-point/boundary sets (+ composition helpers).
crates/kirin-liveness/src/live.rs Defines Live lattice and LiveSet point-facts set.
crates/kirin-liveness/src/lib.rs Public API: analyze_demand and analyze_dense, engine type aliases.
crates/kirin-liveness/Cargo.toml New crate manifest.
crates/kirin-interpreter/src/semantics/shape.rs Introduces analysis-shape markers and per-shape semantic families.
crates/kirin-interpreter/src/semantics/mod.rs Documents and re-exports semantics vs shape split.
crates/kirin-interpreter/src/semantics/keys.rs Defines shipped semantic keys and binds them to shapes.
crates/kirin-interpreter/src/lib.rs Major re-org: core/engines/facts/fixpoint/semantics split and new exports.
crates/kirin-interpreter/src/fixpoint/traits.rs Adds fixpoint driver vocabulary (phases, summaries, owner semantics).
crates/kirin-interpreter/src/fixpoint/tests/support.rs Adds minimal Interp for fixpoint backbone tests.
crates/kirin-interpreter/src/fixpoint/tests/phase.rs Tests widen-then-narrow phase behavior.
crates/kirin-interpreter/src/fixpoint/tests/mod.rs Wires fixpoint backbone tests.
crates/kirin-interpreter/src/fixpoint/tests/deps.rs Tests dependency scheduling behavior.
crates/kirin-interpreter/src/fixpoint/tests/counter.rs Tests owner reanalysis until summary fixpoint.
crates/kirin-interpreter/src/fixpoint/solver.rs Implements owner worklist convergence loop.
crates/kirin-interpreter/src/fixpoint/runner.rs Implements intra-owner drive_frames wrapper.
crates/kirin-interpreter/src/fixpoint/profile.rs Defines the fixpoint profile type family.
crates/kirin-interpreter/src/fixpoint/mod.rs Fixpoint module wiring and exports.
crates/kirin-interpreter/src/fixpoint/driver.rs Implements StandardFixpointInterpreter wrapper and storage.
crates/kirin-interpreter/src/fixpoint/deps.rs Dependency index implementations (owner/self, forward, backward).
crates/kirin-interpreter/src/fixpoint/delegates.rs Delegates Interp/Env to wrapped interpreter.
crates/kirin-interpreter/src/facts/topology.rs Adds dialect-neutral region topology enumeration for backward analyses.
crates/kirin-interpreter/src/facts/store.rs Adds generic fact store + sparse/dense store aliases/wrappers.
crates/kirin-interpreter/src/facts/mod.rs Exposes anchors/stores/topology vocabulary.
crates/kirin-interpreter/src/facts/anchor.rs Defines lattice anchors, scoping, and change tracking.
crates/kirin-interpreter/src/engines/sparse_forward/mod.rs New sparse-forward engine module surface.
crates/kirin-interpreter/src/engines/sparse_forward/frames.rs Refactors abstract forward frames around SparseForwardEffect.
crates/kirin-interpreter/src/engines/sparse_backward/mod.rs New sparse-backward engine module surface.
crates/kirin-interpreter/src/engines/mod.rs New engines module wiring.
crates/kirin-interpreter/src/engines/dense_backward/mod.rs New dense-backward engine module surface.
crates/kirin-interpreter/src/engines/dense_backward/frames.rs Adds dense-backward block frame + default total frame.
crates/kirin-interpreter/src/engines/concrete/mod.rs Moves concrete engine into engines::concrete.
crates/kirin-interpreter/src/engines/concrete/interp.rs Updates concrete interpreter to Semantics + SparseForwardEffect.
crates/kirin-interpreter/src/engines/concrete/frames.rs Updates concrete frames to consume SparseForwardEffect.
crates/kirin-interpreter/src/dispatch.rs Removes old dispatch trait keyed on (I, Kind).
crates/kirin-interpreter/src/core/value.rs Moves value helpers (BranchCondition, HasProductValue, expect_single) into core.
crates/kirin-interpreter/src/core/query.rs Adds new stage queries (SSA kind, terminator args, region topology).
crates/kirin-interpreter/src/core/mod.rs New “core chassis” module and exports.
crates/kirin-interpreter/src/core/linker.rs Updates linker to new query module path.
crates/kirin-interpreter/src/core/interp.rs Replaces Kind with Semantics: SemanticKey; introduces SparseForwardInterp.
crates/kirin-interpreter/src/core/frame.rs Updates comments/refs for new engine naming.
crates/kirin-interpreter/src/core/error.rs Adds MissingValue error variant.
crates/kirin-interpreter/src/core/env.rs Moves env/store implementation into core.
crates/kirin-interpreter/src/core/effect.rs Renames forward effect enum to SparseForwardEffect.
crates/kirin-interpreter/src/core/dispatch.rs New dispatch trait keyed only on engine I (dispatches I::Semantics).
crates/kirin-function/src/interpreter.rs Adds backward demand + classic liveness rules; updates forward effect naming.
crates/kirin-derive-interpreter/src/snapshots/kirin_derive_interpreter__interpretable__tests__interpretable_enum_level_wraps.snap Updates snapshot for semantics-generic Interpretable derive.
crates/kirin-derive-interpreter/src/interpretable.rs Makes Interpretable derive generic over __Semantics.
crates/kirin-derive-interpreter/src/interp_dispatch.rs Makes stage dispatch derive keyed only on __InterpI (uses __InterpI::Semantics).
crates/kirin-constprop/src/lib.rs Updates docs/alias to SparseForwardInterpreter.
crates/kirin-constant/src/interpreter.rs Adds backward demand + classic liveness rules; updates forward effect naming.
crates/kirin-cmp/src/typeinfer.rs Removes stale future typeinfer sketch file.
crates/kirin-cmp/src/liveness.rs Removes stale future liveness sketch file.
crates/kirin-cmp/src/interpreter.rs Adds backward demand + classic liveness rules; updates forward effect naming.
crates/kirin-cf/src/interpreter.rs Adds backward demand + classic liveness rules for branching/edge mapping.
crates/kirin-bitwise/src/interpreter.rs Adds backward demand + classic liveness rules; updates forward effect naming.
crates/kirin-arith/src/interpreter.rs Adds backward demand + classic liveness rules; updates forward effect naming.
Cargo.toml Adds crates/kirin-liveness to workspace and workspace deps.
Cargo.lock Records new kirin-liveness package and dependency edges.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread example/toy-lang/src/main.rs
Comment thread example/toy-lang/src/interpreter/mod.rs Outdated
Comment thread example/toy-lang/src/interpreter/mod.rs Outdated
Comment thread crates/kirin-interpreter/src/fixpoint/traits.rs Outdated
zhenrongliew and others added 3 commits July 6, 2026 11:42
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@zhenrongliew zhenrongliew self-assigned this Jul 6, 2026
@Roger-luo Roger-luo mentioned this pull request Jul 8, 2026
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: Kirin-rs Area: Rust-version Kirin related components. 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