Skip to content

Inline stubs#843

Merged
bitwalker merged 2 commits into0xMiden:nextfrom
walnuthq:pr/inline-stubs
Jan 1, 2026
Merged

Inline stubs#843
bitwalker merged 2 commits into0xMiden:nextfrom
walnuthq:pr/inline-stubs

Conversation

@djolertrk
Copy link
Collaborator

Do it in two phases:

  1. Detect and register all linker stubs first (ensures that when we translate function bodies in pass all stubs are known and calls to them will be inlined regard less of function ordering in the WASM file)
  2. Do the inlining

@djolertrk djolertrk mentioned this pull request Dec 29, 2025
@djolertrk djolertrk force-pushed the pr/inline-stubs branch 2 times, most recently from 0d67060 to be9ca44 Compare December 29, 2025 10:12
@bitwalker
Copy link
Collaborator

@djolertrk Is this ready? Looks like you just need to update the expect tests that are failing (since the handling of stubs has changed), but once that is done, I'm guessing there isn't much more planned for this PR correct?

Copy link
Contributor

@greenhat greenhat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good when the stub ends up being an op!
I did not find how the stdlib/tx_kernel function calls transformation is preserved.

// If this is a linker stub, synthesize its body to exec the MASM callee.
// Note: Intrinsics and Miden ABI (SDK/stdlib) calls are expected to be
// surfaced via such linker stubs rather than as core-wasm imports.
if maybe_lower_linker_stub(function_ref, &body_data.body, module_state)? {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe_lower_linker_stub handles cases where the stub is transformed to call the stdlib/tx_kernel function. See for example

(func $miden::active_account::get_id (;27;) (type 6) (param i32)
unreachable
)
(func $miden::active_note::get_assets (;28;) (type 11) (param i32) (result i32)
unreachable
)
(func $miden::active_note::get_inputs (;29;) (type 11) (param i32) (result i32)
unreachable
)
transformed into
private builtin.function @miden::active_account::get_id(v864: i32) {
^block107(v864: i32):
v865, v866 = hir.exec @miden/active_account/get_id() : felt, felt
v867 = hir.bitcast v864 : u32;
v868 = hir.int_to_ptr v867 : ptr<byte, felt>;
hir.store v868, v865;
v869 = arith.constant 4 : u32;
v870 = arith.add v867, v869 : u32 #[overflow = checked];
v871 = hir.int_to_ptr v870 : ptr<byte, felt>;
hir.store v871, v866;
builtin.ret ;
};
private builtin.function @miden::active_note::get_assets(v872: i32) -> i32 {
^block111(v872: i32):
v873, v874 = hir.exec @miden/active_note/get_assets(v872) : i32, i32
builtin.ret v873;
};
private builtin.function @miden::active_note::get_inputs(v876: i32) -> i32 {
^block114(v876: i32):
v877, v878 = hir.exec @miden/active_note/get_inputs(v876) : i32, i32
builtin.ret v877;
};

I don't see them handled anywhere after the deletion of this call.

@djolertrk djolertrk marked this pull request as ready for review December 31, 2025 11:59
Copy link
Contributor

@greenhat greenhat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look good!

@greenhat
Copy link
Contributor

greenhat commented Jan 1, 2026

@djolertrk The first commit is without a signature. Please sign.

@greenhat
Copy link
Contributor

greenhat commented Jan 1, 2026

As a side note, github does not send a notification on PR status change (draft -> ready) so when I get a notification for a new commit I'm not sure if it's ready for review. Re-requesting review or ping in a comment is appreciated since it ends up as a notification in my inbox.

Use two Pass approach:
  - Pass 1: Detect and register ALL linker stubs first
  - Pass 2: Translate non-stub function bodies with all stubs available

This ensures operations like `arith.add` appear directly at call sites
instead of `hir.exec @intrinsics::felt::add` calls.

Add test case as well:

$ litcheck lit run --path bin tests/lit/inline-stubs
In addition, update expect tests.
@bitwalker bitwalker merged commit cbb9eee into 0xMiden:next Jan 1, 2026
11 checks passed
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.

3 participants