Skip to content

Inline {enter,exit}_sync_call trampolines into sync-to-sync fused adapters#13695

Merged
fitzgen merged 17 commits into
bytecodealliance:mainfrom
fitzgen:inline-enter-exit-sync-call-in-sync-to-sync-adapters
Jun 26, 2026
Merged

Inline {enter,exit}_sync_call trampolines into sync-to-sync fused adapters#13695
fitzgen merged 17 commits into
bytecodealliance:mainfrom
fitzgen:inline-enter-exit-sync-call-in-sync-to-sync-adapters

Conversation

@fitzgen

@fitzgen fitzgen commented Jun 19, 2026

Copy link
Copy Markdown
Member

See each commit for details.

@fitzgen fitzgen requested a review from alexcrichton June 19, 2026 00:08
@fitzgen fitzgen requested review from a team as code owners June 19, 2026 00:08
@github-actions github-actions Bot added the wasmtime:api Related to the API of the `wasmtime` crate itself label Jun 19, 2026
Comment thread crates/cranelift/src/alias_region.rs
Comment thread crates/cranelift/src/func_environ.rs
Comment thread crates/environ/src/fact/trampoline.rs
Comment thread crates/environ/src/key.rs
Comment thread crates/wasmtime/src/runtime/component/store.rs
Comment thread crates/wasmtime/src/runtime/component/store.rs
Comment thread crates/wasmtime/src/runtime/vm/vmcontext.rs Outdated
Comment thread crates/wasmtime/src/runtime/vm/vmcontext.rs
Comment thread crates/wasmtime/src/runtime/func.rs Outdated
Comment thread tests/all/component_model/sync_call_inline.rs Outdated

@alexcrichton alexcrichton left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Actually I'll go ahead and flag this for merge. One thing I'd recommend, if you can, is to get an LLM review locally as well to double-check this signs off with no known bugs. If nothing materially changes from my suggestions/comments though seems fine to land.

@fitzgen fitzgen force-pushed the inline-enter-exit-sync-call-in-sync-to-sync-adapters branch 2 times, most recently from 00b1e84 to 63b1449 Compare June 25, 2026 17:20
@fitzgen fitzgen enabled auto-merge June 25, 2026 18:32
@fitzgen fitzgen added this pull request to the merge queue Jun 25, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jun 25, 2026
@fitzgen fitzgen force-pushed the inline-enter-exit-sync-call-in-sync-to-sync-adapters branch from c0302e3 to fe5b1e1 Compare June 26, 2026 15:52
@fitzgen fitzgen enabled auto-merge June 26, 2026 15:52
@fitzgen fitzgen force-pushed the inline-enter-exit-sync-call-in-sync-to-sync-adapters branch from 6974e54 to 87c74a8 Compare June 26, 2026 17:22
@fitzgen fitzgen added this pull request to the merge queue Jun 26, 2026
Merged via the queue into bytecodealliance:main with commit 946f763 Jun 26, 2026
388 of 390 checks passed
@fitzgen fitzgen deleted the inline-enter-exit-sync-call-in-sync-to-sync-adapters branch June 26, 2026 18:57
Comment on lines +52 to +57
/// TODO FITZGEN
#[derive(Clone, Debug)]
pub enum KnownFunc {
/// TODO FITZGEN
FuncKey(FuncKey),
/// TODO FITZGEN

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

TODO FITZGEN

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Whoops, thanks for catching this

// `VMDeferredThread` inside an old, since-unwound stack
// frame. Therefore, we must reset `current_thread` to avoid
// potential use-after-free bugs.
let forced = builder.ins().iconst(pointer_type, 1);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could this "1" constant be moved to the wasmtime_environ crate or similar?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Either that or could there be a compile-time assertion that "1" is the pattern used here, with a comment saying that if the constant changes it needs to update the compiler too?

pub(crate) fn component_task_state_mut(&mut self) -> &mut ComponentTaskState {
&mut self.component_data_mut().task_state
pub(crate) fn component_task_state_mut(&mut self) -> Result<&mut ComponentTaskState> {
// NB: Force the deferred lazy thread, if any, before handing out task

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

How come this is necessary? (same for the one below too)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It's more defensive than strictly required as the code exists today. The problem is that we hand out ComponentTaskState which contains the concurrent state, which contains the unforced current thread, but by doing so the code that gets that state can't have access to the store at teh same time due to borrow rules so it can't get the actual/forced current thread, so we defensively update the unforced current thread eagerly before passing out the ComponentTaskState.

I think ideally we would completely remove the current thread from the concurrent state and only have it on store and refactor the rest of the code accordingly, but that seemed like a pretty big task to do in this PR.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Code isn't expected to access unforced_current_thread though, right? I'd expect that if the current thread was needed it'd be done with StoreOpaque before getting ComponentTaskState, and by getting ComponentTaskState code would otherwise follow the convention of not even looking at unforced_current_state due to the scary name.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ideally, yes, but there is a lot of existing code that doesn't have access to a store and only has the ComponentTaskState. I felt it was better to be safe than sorry.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Makes sense yeah, I've addressed these in #13758 and #13759

natanjunges pushed a commit to ignea-lp/wasmtime that referenced this pull request Jun 29, 2026
Some little fixes to stuff that was pointed out after
bytecodealliance#13695 landed
alexcrichton added a commit to alexcrichton/wasmtime that referenced this pull request Jun 29, 2026
Juggle some things around to remove an otherwise-needed promotion.

Follow-up from bytecodealliance#13695
pull Bot pushed a commit to Haofei/wasmtime that referenced this pull request Jun 29, 2026
* Remove an accessor of `unforced_current_thread`

Juggle some things around to remove an otherwise-needed promotion.

Follow-up from bytecodealliance#13695

* Fix some test compiles

* Defer requiring a scope to a bit later
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

wasmtime:api Related to the API of the `wasmtime` crate itself

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants