fitzgen requested alexcrichton for a review on PR #11918.
fitzgen requested wasmtime-core-reviewers for a review on PR #11918.
fitzgen requested wasmtime-default-reviewers for a review on PR #11918.
fitzgen opened PR #11918 from fitzgen:compose-compile-time-builtins to bytecodealliance:main:
Compile-time builtins, as described in the RFC, are effectively the sum of three parts:
- Function inlining
- Unsafe intrinsics
- Component composition
The first two have already been implemented in Wasmtime. This commit implements the final part, leveraging
wasm-composeto link host-defined compile-time builtin components with guest-defined main components. It exposes Wasmtime's unsafe intrinsics only to the host-defined compile-time builtins, not the guest-defined main Wasm component.Why
wasm-composeand notwac? Because it is in the same repo as the rest of thewasm-toolscrates, and therefore it is easy to depend on without bringing in duplicate copies of that family of crates into our workspace and builds. Also its programmatic API is somewhat easier to use, and is not spread across multiple crates.<!--
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
-->
fitzgen edited PR #11918:
Compile-time builtins, as described in the RFC, are effectively the sum of three parts:
- Function inlining
- Unsafe intrinsics
- Component composition
The first two have already been implemented in Wasmtime. This commit implements the final part, leveraging
wasm-composeto link host-defined compile-time builtin components with guest-defined main components. It exposes Wasmtime's unsafe intrinsics only to the host-defined compile-time builtins, not the guest-defined main Wasm component.Why
wasm-composeand notwac? Because it is in the same repo as the rest of thewasm-toolscrates, and therefore it is easy to depend on without bringing in duplicate copies of that family of crates into our workspace and builds. Also its programmatic API is somewhat easier to use, and is not spread across multiple crates.<!--
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
-->
fitzgen updated PR #11918.
fitzgen updated PR #11918.
fitzgen updated PR #11918.
alexcrichton submitted PR review.
alexcrichton created PR review comment:
Given the weight of wasm-compose/tempfile would you be ok leaving this feature off-by-default?
alexcrichton created PR review comment:
alexcrichton created PR review comment:
Could this delegate to
compile_time_builtins_binary_or_textto avoid duplicating internals? Also,wat::parse_filemight be useful here
alexcrichton created PR review comment:
Personally I'd say that the builder should just go ahead and read all of the files. It's an API quirk of wasm-compose that it requires files on the filesystem, but otherwise I'd imagine that the builder does all I/O during configuration and then compilation is less heavy on the I/O
alexcrichton created PR review comment:
To help out with #[cfg]
in lots of places, how aboutcrates/wasmtime/src/compile/compile_time_builtins.rswhich itself hasimpl CodeBuilder<'a, 'b>` and all the methods over there?
alexcrichton created PR review comment:
Would it make sense to plumb this feature in more locations? For example the preexisting
expose_unsafe_intrinsicsisn't gated by this feature but arguably may want to be? I'm not sure how beneficial that would be though.
alexcrichton created PR review comment:
This
.clone()I think may not be desired since that clones the ownedCowif it's owned. I think you still want theas_dereffrom before?
alexcrichton created PR review comment:
I'm a bit surprised in that I thought
CodeBuilderusage was pretty rare throughout this repo as external helpers are primarily used. What are some of the locations that stop compiling with just one lifetime?
alexcrichton created PR review comment:
You could replace these by looking for
Payload::Versiontoo and then change the level condition to "level 1 == do the thing, everything else == skip the thing"
fitzgen submitted PR review.
fitzgen created PR review comment:
Ah, good to know, thanks
fitzgen submitted PR review.
fitzgen created PR review comment:
The intrinsics themselves aren't worth gating, in my opinion. There isn't that much code there.
In contrast, pulling in
wasm-composeis worth feature-gating, IMO.
fitzgen submitted PR review.
fitzgen created PR review comment:
FWIW, they won't be in our CLI release artifacts because there is not any way to define compile-time builtins via the CLI at the moment.
But all else being equal I'd rather have them enabled by default just because that seems like it is on the path for making things production ready, and I feel that this feature is fairly production ready already. If we disabled everything by default, and required opt-in for all features, disabling it would make sense to me, but we have a bunch of other stuff on by default that isn't as baked as this already is yet (stack switching, guest debugging, core dumps) so disabling this now doesn't really make sense to me.
fitzgen submitted PR review.
fitzgen created PR review comment:
Basically all my unsafe intrinsics tests and the unsafe intrinsics / compile-time builtins example as well. Wouldn't be the end of the world to fix them all, just annoying, and I figured it might be annoying for existing embedders as well.
fitzgen submitted PR review.
fitzgen created PR review comment:
Ah this might have been accidental fallout from my hunt for understanding the borrow checking errors I was seeing from putting the
'alifetime into a type with aDropimplementation, and might not be necessary.
fitzgen updated PR #11918.
fitzgen updated PR #11918.
fitzgen submitted PR review.
fitzgen created PR review comment:
fitzgen updated PR #11918.
fitzgen submitted PR review.
fitzgen created PR review comment:
fitzgen submitted PR review.
fitzgen created PR review comment:
fitzgen updated PR #11918.
fitzgen submitted PR review.
fitzgen created PR review comment:
fitzgen updated PR #11918.
fitzgen submitted PR review.
fitzgen created PR review comment:
fitzgen updated PR #11918.
fitzgen submitted PR review.
fitzgen created PR review comment:
fitzgen updated PR #11918.
alexcrichton has enabled auto merge for PR #11918.
fitzgen updated PR #11918.
fitzgen has enabled auto merge for PR #11918.
fitzgen merged PR #11918.
Last updated: Dec 06 2025 at 06:05 UTC