Fix wasm-tools component new for page-size-1 memory - #2666
Conversation
|
Thanks! Personally though this doesn't feel like the right solution to me as it's changing the meaning of the original adapter module. The code here says: but while that's specifically true for the current iteration of the adapter wasmtime publishes this is not something guaranteed to be generally true. Originally the adapter very much did use Does this work correctly if both the adapter and the main module use a 1-byte-size page size? If not then that's definitely a bug to fix, but otherwise I'd lean more on "the adapter should be compiled for 1-byte pages" as opposed to retroactively changing the adapter. |
Is the concern that people would still use this old version of the adapter? We can scan the adapter code, if there is no
Yeah, it's certainly more robust this way. But this means we need to publish the page-size-1 adapter. This adds an extra dimension to the "matrix" of adapters. We will have If we plan to support more custom page sizes, then making sure that the adapter code doesn't assume the 64k page size is a good property to have? If we maintain this property as we currently are, then the rewriting is safe and easier to maintain. |
|
I'm not so concerned about using older versions of the adapter as placing more restrictions on what it can/can't do. Right now the only real restrictions are what sections it contains, which while a major restriction has still provided a great deal of flexibility in changing the implementation of the adapter over time without having to update this crate as well. I do agree though that a better first-class error from For the combinatorial complexity, yeah I can see where this would add to that. In a sense though the adapter and tooling was all developed as a short-term hack to get deleted. The native wasip2/wasip3 targets, for example, no longer depend on the adapter for Rust & C toolchains. In that sense I would personally prefer to either sunset the adapter paradigm entirely or to move development entirely to toolchains which depend on the adapter. Needing a combination of builds is, in my mind, part of the complexity of a toolchain continuing to require an adapter vs updating toolchain support to not require an adapter. |
|
Sounds good. Checking the page size is enough for our use case.
The main use case for the adapter is when targeting |
|
|
||
| /// Returns the `page_size_log2` of the first memory in a module, whether | ||
| /// imported or locally defined. Returns `None` if the module has no memory. | ||
| fn get_memory_page_size_log2(module_bytes: &[u8]) -> Result<Option<u32>> { |
There was a problem hiding this comment.
I'm a bit wary of probing the module like this because this would handle multi-memory, should a module be using that, relatively poorly. The validation.rs step already has a MainModuleMemory payload which carries a MemoryType, and it's also got imported_memory: Option<MemoryType> for what's being imported for adapters I believe. Could those be used directly instead of duplicate-ly probing here? Ideally for example there's some location where where the main module memory is hooked into the adapter's memory, and that's where the type-check happens.
Also on that type there's a page_size method which means you don't have to read the raw fields directly
wasm-tools component new, check if the adapter import memory has the same page size as the core module memory's.realloc_via_memory_growfunction to work with any custom page size.