Skip to content

refactor(ir): separate callable discovery from interpreter dispatch - #729

Open
zhenrongliew wants to merge 1 commit into
dl/interp-callable-rootfrom
dl/ir-callable-body
Open

refactor(ir): separate callable discovery from interpreter dispatch#729
zhenrongliew wants to merge 1 commit into
dl/interp-callable-rootfrom
dl/ir-callable-body

Conversation

@zhenrongliew

Copy link
Copy Markdown
Collaborator

Stacked on #724.

#724
made callable-body discovery input value-independent and gave every engine one shared callable-root prefix. It left the discovery mechanism in the interpreter. This PR moves it into kirin-ir and makes it derivable from the operation's own declaration.

Previously:
Discovering a callable’s body required routing through InterpDispatch::dispatch_function_entry.
FunctionTarget copied the definition statement, so a linker could contradict the IR. FunctionTarget { stage, function, definition } carried a Statement copied out of the specialization record, even though SpecializedFunctionInfo authoritatively owns it.
The declaration was hand-written and unchecked. Every language enum added FunctionEntry to its derive list and marked #[callable] variants; every dialect wrote the impl by hand.

Fix:
Move callable-body discovery into kirin-ir, so interpreters can discover a definition’s implementation without
dispatch. Dialect now derives HasCallableBody: callable definitions mark one body with #[kirin(callable_body)].

Restrict linking to selecting a stage and specialization (LinkTarget).
Structural discovery reads the specialization’s definition at that stage and returns its body alongside the target (ResolvedCallable).

Remove FunctionEntry, its derive and wrapper markers, andInterpDispatch::dispatch_function_entry. Concrete execution and forward and backward analyses share structural discovery, then apply their own
boundary initialization and traversal.

- Introduced `HasCallableBody` trait for IR-level callable-body discovery, replacing the previous `FunctionEntry` trait.
- Added `Body` enum to represent different computation representations (Block, CFG, DiGraph, UnGraph).
- Updated dialect definitions to support the new callable body mechanism, ensuring only one callable body field is allowed.
- Removed `FunctionEntry` trait and its implementations across various languages.
- Adjusted linker resolution to return `LinkTarget` and `ResolvedCallable` instead of `FunctionTarget` and `CallableBody`.
- Enhanced error handling for invalid callable body definitions, including duplicate and unsupported field types.
- Updated tests to validate new callable body functionality and ensure backward compatibility.
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.

1 participant