alexcrichton opened PR #13394 from alexcrichton:reimplement-passive-data-segments to bytecodealliance:main:
This commit refactors and reimplements how passive data segments are implemented in Wasmtime. The goal of this commit is to push towards #13387 where bulk operations are done in wasm and have fuel/epoch checks as appropriate. A secondary goal here is to continue to reduce the number of libcalls we have and push more of the implementation into Cranelift-generated code.
The set of dropped data segments is removed from
vm::Instanceand conceptually moved toVMContext. A new area of theVMContextis initialized with an entry-per-passive-data-segment which contains the current length of the data segment, either 0 or the initial length. This is then used to fully implementmemory.init,array.new_data, andarray.init_datawithin Cranelift-generated code. The bounds check happens entirely in wasm now. Preexisting libcalls were all removed and the only remaining libcall is a new one to acquire the host's data pointer for a passive data segment. Combining all of this together all of these instructions can now use thememory_copylibcall in the same manner as other instructions, narrowing the funnel of "bulk data copy" instructions.<!--
Please make sure you include the following information:
If this work has been discussed elsewhere, please include a link to that
conversation. If it was discussed in an issue, just mention "issue #...".Explain why this change is needed. If the details are in an issue already,
this can be brief.Our development process is documented in the Wasmtime book:
https://docs.wasmtime.dev/contributing-development-process.htmlPlease ensure all communication follows the code of conduct:
https://github.com/bytecodealliance/wasmtime/blob/main/CODE_OF_CONDUCT.md
-->
alexcrichton requested cfallin for a review on PR #13394.
alexcrichton requested wasmtime-compiler-reviewers for a review on PR #13394.
alexcrichton requested wasmtime-core-reviewers for a review on PR #13394.
alexcrichton updated PR #13394.
github-actions[bot] added the label wasmtime:api on PR #13394.
github-actions[bot] added the label wasmtime:ref-types on PR #13394.
github-actions[bot] commented on PR #13394:
Subscribe to Label Action
cc @fitzgen
<details>
This issue or pull request has been labeled: "wasmtime:api", "wasmtime:ref-types"Thus the following users have been cc'd because of the following labels:
- fitzgen: wasmtime:ref-types
To subscribe or unsubscribe from this label, edit the <code>.github/subscribe-to-label.json</code> configuration file.
Learn more.
</details>
fitzgen commented on PR #13394:
(Haven't looked at the code yet, but)
the only remaining libcall is a new one to acquire the host's data pointer for a passive data segment.
Why not put the data segment's pointer into the
vmctxtoo, so that we have ~effectivelystruct VMContext { // ... passive_data: PrimaryMap<PassiveDataIndex, (NonNull<u8>, usize)> // ... }and then we wouldn't even need that last libcall?
fitzgen edited a comment on PR #13394:
(Haven't looked at the code yet, but)
the only remaining libcall is a new one to acquire the host's data pointer for a passive data segment.
Why not put the data segment's pointer into the
vmctxtoo, so that we have ~effectivelystruct VMContext { // ... passive_data: PrimaryMap<PassiveDataIndex, (NonNull<u8>, usize)> // ... }and then we wouldn't even need that last libcall?
fitzgen edited a comment on PR #13394:
(Haven't looked at the code yet, but)
the only remaining libcall is a new one to acquire the host's data pointer for a passive data segment.
Why not put the data segment's pointer into the
vmctxtoo, so that we have ~effectivelystruct VMContext { // ... passive_data: PrimaryMap<PassiveDataIndex, (NonNull<u8>, usize)>, // ... }and then we wouldn't even need that last libcall?
:memo: fitzgen submitted PR review:
(Holding off on approval until we talk through my other comment.)
:speech_balloon: fitzgen created PR review comment:
Small doc clarification:
/// Index type of a passive data segment inside the WebAssembly module. /// /// Not a spec-level concept, just used to get dense index spaces for passive /// data segments inside of Wasmtime. #[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug, Serialize, Deserialize)]
alexcrichton updated PR #13394.
alexcrichton updated PR #13394.
alexcrichton commented on PR #13394:
Oh, good point! I've refactored to do just that now.
:thumbs_up: fitzgen submitted PR review:
Probably better locality to put the base and index in a tuple in the same array, rather than have two arrays, since they are accessed together at the same time, but that would require a little more work and also padding I guess, so not a big deal and always something we can revisit. Thanks!
alexcrichton updated PR #13394.
alexcrichton has enabled auto merge for PR #13394.
alexcrichton added PR #13394 Reimplement passive data segments to the merge queue.
github-merge-queue[bot] removed PR #13394 Reimplement passive data segments from the merge queue.
alexcrichton updated PR #13394.
alexcrichton has enabled auto merge for PR #13394.
alexcrichton updated PR #13394.
alexcrichton added PR #13394 Reimplement passive data segments to the merge queue.
github-merge-queue[bot] removed PR #13394 Reimplement passive data segments from the merge queue.
github-actions[bot] added the label cranelift on PR #13394.
alexcrichton added PR #13394 Reimplement passive data segments to the merge queue.
:check: alexcrichton merged PR #13394.
alexcrichton removed PR #13394 Reimplement passive data segments from the merge queue.
Last updated: Jun 01 2026 at 09:49 UTC