Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
f800609
refactor: rename regions to cfgs and update related tests
zhenrongliew Jul 9, 2026
aed4c23
Refactor terminology from Region to Cfg across the codebase
zhenrongliew Jul 9, 2026
1268950
Add acceptance tests for mixed language interpreter bodies
zhenrongliew Jul 13, 2026
0a27ea6
Refactor interpreter frame structure and update toy language integration
zhenrongliew Jul 15, 2026
162f06c
Merge branch 'rust' into dl/generalize-body
Roger-luo Jul 17, 2026
969914e
refactor: simplify liveness analysis by removing demand pre-pass
zhenrongliew Jul 16, 2026
31bd511
Fixed SSAInfo.uses def-use population at finalize. (#687)
zhenrongliew Jul 22, 2026
e0b99cc
refactor: generalize body handling and update topology queries
zhenrongliew Jul 30, 2026
8bc66df
Refactored the DenseBackwardInterp trait to use point_state and point…
zhenrongliew Jul 30, 2026
e6410e4
refactor: introduce AbstractDiGraphFrame for dependency-ordered graph…
zhenrongliew Jul 30, 2026
2a9e7d6
refactor: enhance body handling and interprocedural analysis in tests
zhenrongliew Jul 30, 2026
e4d50b2
refactor: update frame handling methods for clarity and consistency
zhenrongliew Jul 31, 2026
2b12a2b
refactored topology queries already answered in IR
zhenrongliew Jul 31, 2026
d1801fa
Add call body traversal policy and tests
zhenrongliew Aug 3, 2026
6ec0a31
Decoupled the monolithic trait `ForwardFrameDriver` into smaller trai…
zhenrongliew Aug 3, 2026
a61fb14
Refactor block and graph ownership semantics in IR
zhenrongliew Aug 10, 2026
3979057
Refactor liveness to store both block and statement liveness facts.
zhenrongliew Aug 11, 2026
d423569
Refactor dense backward engine to use scoped fact stores and improve …
zhenrongliew Aug 11, 2026
5d01225
Refactor block predecessor handling to use SmallVec for improved memo…
zhenrongliew Aug 12, 2026
27e901f
Changed to use SmallVec. Liveness Analysis now uses block cursor: Las…
zhenrongliew Aug 12, 2026
f6439fc
Refactor CallContext trait to accept FunctionTarget instead of indivi…
zhenrongliew Aug 13, 2026
22bcc7a
added Symbol entry points for forward interpreter. Renamed function b…
zhenrongliew Aug 17, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions AGENTS.md

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,14 @@ kirin-bitwise = { workspace = true }
kirin-cf = { workspace = true }
kirin-cmp = { workspace = true }
kirin-constant = { workspace = true }
kirin-constprop = { workspace = true }
kirin-function = { workspace = true }
kirin-scf = { workspace = true }
kirin-interpreter = { workspace = true, features = ["derive"] }
kirin-test-languages = { workspace = true, features = [
"arith-function-language",
"graph-function-language",
"interpreter",
"bitwise-function-language",
"callable-language",
"namespaced-language",
Expand Down
6 changes: 4 additions & 2 deletions crates/kirin-chumsky/src/function_text/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub enum FunctionParseErrorKind {
UnknownStage,
InconsistentFunctionName,
MissingStageDeclaration,
BodyParseFailed,
DefinitionParseFailed,
EmitFailed,
}

Expand All @@ -24,7 +24,9 @@ impl Display for FunctionParseErrorKind {
FunctionParseErrorKind::MissingStageDeclaration => {
write!(f, "missing stage declaration")
}
FunctionParseErrorKind::BodyParseFailed => write!(f, "function body parse failed"),
FunctionParseErrorKind::DefinitionParseFailed => {
write!(f, "function definition parse failed")
}
FunctionParseErrorKind::EmitFailed => write!(f, "IR emission failed"),
}
}
Expand Down
34 changes: 17 additions & 17 deletions crates/kirin-chumsky/src/function_text/parse_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
//! - collect `(stage, function) -> staged_function` mappings;
//! - record offsets of `specialize` declarations for pass 2.
//!
//! 2. **Pass 2 (specialize bodies)**
//! 2. **Pass 2 (specialization definitions)**
//! - re-parse only the previously recorded `specialize` declarations;
//! - resolve the target staged function from the pass-1 lookup;
//! - emit specialization bodies into the resolved stage dialect.
//! - emit specialization definitions into the resolved stage dialect.
//!
//! This separation guarantees that specialization emission sees a complete
//! staged-function header set, which keeps behavior deterministic even when
Expand All @@ -27,7 +27,7 @@
//! ## Why stage dispatch is central
//!
//! A pipeline can contain different dialects per stage (for example stage `A`
//! with `FunctionBody`, stage `B` with `LowerBody`). The parser does not guess
//! with `FunctionDefinition`, stage `B` with `LowerDefinition`). The parser does not guess
//! which dialect to use from text alone. Instead it:
//!
//! - resolves/creates the stage symbol first (`@A`, `@B`, ...);
Expand All @@ -39,7 +39,7 @@
//!
//! ## Illustrative examples
//!
//! Same-stage header + body:
//! Same-stage header + definition:
//!
//! ```text
//! stage @A fn @foo(()) -> ();
Expand Down Expand Up @@ -275,7 +275,7 @@ where

let Declaration::Specialize {
stage: _stage_sym,
body_span,
definition_span,
span,
} = declaration
else {
Expand All @@ -286,7 +286,7 @@ where
));
};

let body_text = &ctx.src[body_span.start..body_span.end];
let definition_text = &ctx.src[definition_span.start..definition_span.end];

// Use the function name from parse_declaration_head (always available),
// not from the chumsky Declaration (empty for dialect-controlled format).
Expand All @@ -300,7 +300,7 @@ where
stage_id,
&function_name,
ctx.function_symbol,
body_text,
definition_text,
span,
&mut *ctx.function_lookup,
&mut *ctx.staged_lookup,
Expand Down Expand Up @@ -607,7 +607,7 @@ fn apply_specialize_declaration<L>(
stage_id: CompileStage,
function_name: &SymbolName<'_>,
function_symbol: GlobalSymbol,
body_text: &str,
definition_text: &str,
span: SimpleSpan,
function_lookup: &mut FxHashMap<String, Function>,
staged_lookup: &mut FxHashMap<StagedKey, StagedFunction>,
Expand All @@ -617,14 +617,14 @@ where
L: Dialect + ParseEmit<L> + kirin_ir::HasSignature<L>,
L::Type: kirin_ir::Placeholder,
{
// Parse and emit the body first — we need it to extract signature if needed
let body_statement = stage
// Parse and emit the definition first — we need it to extract the signature.
let definition = stage
.with_builder(|builder| {
let mut emit_ctx = EmitContext::new(builder);
L::parse_and_emit(body_text, &mut emit_ctx).map_err(|err| {
L::parse_and_emit(definition_text, &mut emit_ctx).map_err(|err| {
let (kind, message) = match &err {
crate::ChumskyError::Parse(errs) => (
FunctionParseErrorKind::BodyParseFailed,
FunctionParseErrorKind::DefinitionParseFailed,
errs.iter()
.map(|e| e.to_string())
.collect::<Vec<_>>()
Expand All @@ -645,11 +645,11 @@ where
)
})?;

// Get signature from HasSignature on the body statement.
// Get the signature from HasSignature on the definition statement.
// The Signature field is populated by the statement parser from format string elements.
let def = body_statement.expect_info(stage).definition();
let signature = def.signature().unwrap_or_else(|| {
// Fallback: create a placeholder signature if the body type
let definition_value = definition.expect_info(stage).definition();
let signature = definition_value.signature().unwrap_or_else(|| {
// Fallback: create a placeholder signature if the definition type
// doesn't carry one (e.g., no Signature field).
kirin_ir::Signature::placeholder()
});
Expand All @@ -673,7 +673,7 @@ where
.specialize()
.staged_func(staged_function)
.signature(signature.clone())
.body(body_statement)
.definition(definition)
.new()
.map_err(|err| {
FunctionParseError::new(
Expand Down
18 changes: 9 additions & 9 deletions crates/kirin-chumsky/src/function_text/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ pub(super) enum Declaration<'src, T> {
Stage(Header<'src, T>),
Specialize {
stage: SymbolName<'src>,
/// Span of the body portion (from keyword through closing `}`).
body_span: SimpleSpan,
/// Span of the definition (from keyword through closing `}`).
definition_span: SimpleSpan,
/// Span of the entire specialize declaration.
span: SimpleSpan,
},
Expand Down Expand Up @@ -69,11 +69,11 @@ where
.labelled("function signature")
}

/// Body span scanner. Matches an optional keyword prefix (e.g. `digraph`,
/// Definition span scanner. Matches an optional keyword prefix (e.g. `digraph`,
/// `ungraph`) followed by a brace-balanced `{ ... }` CFG. Returns the
/// span covering everything from the first non-brace token (or the opening
/// brace) through the matching closing brace. Does not parse body contents.
fn body_span<'src, I>() -> impl Parser<'src, I, SimpleSpan, ParserError<'src>>
/// brace) through the matching closing brace. Does not parse the definition.
fn definition_span<'src, I>() -> impl Parser<'src, I, SimpleSpan, ParserError<'src>>
where
I: TokenInput<'src>,
{
Expand All @@ -88,7 +88,7 @@ where
None => {
return Err(Rich::custom(
input.span_since(&start),
"expected '{' in body",
"expected '{' in function definition",
));
}
}
Expand Down Expand Up @@ -132,10 +132,10 @@ where
// The function name is extracted post-parse from EmitContext::function_name().
let specialize_decl = identifier("specialize")
.ignore_then(symbol())
.then(body_span::<I>()) // captures from keyword (e.g. `fn`) through closing `}`
.map_with(|(stage, body_span), extra| Declaration::Specialize {
.then(definition_span::<I>()) // captures from keyword (e.g. `fn`) through closing `}`
.map_with(|(stage, definition_span), extra| Declaration::Specialize {
stage,
body_span,
definition_span,
span: extra.span(),
});

Expand Down
Loading