wasm-tools
wasm-tools copied to clipboard
Make wasmparser no_std again
There is still intent to support "no_std" feature for this crate. There is no need to support allocation hungry API such as WasmParser
/WasmDecoder
, so it will be beneficial to make this legacy API under feature -- the section readers is more performant API and has to be used at this moment.
TODOs:
- [ ] Make
WasmParser
and friends optional via feature (and/or deprecate) - [ ] Cleanup sections readers to not use dynamic memory
Box
,Vec
,HashMap
I think that will allow us to be no_std
without depending on alloc
or hashbrown
crates.
What API are you imagining for things like BrTable::read_table
where we allocate a Box<[..]>
? Instead taking a user-provided callbacks-style trait to incrementally report the entries and let the trait implementor decide if/how to allocate?
What API are you imagining for things like BrTable::read_table where we allocate a Box<[..]> ?
We already have BrTableIterator to read it incrementally. Is it possible improve it further to allow optimal Iterator::collect
?
- [ ] convert validate logic into something that can be done without
Vec
(can be possible with preallocated buffers or cache-read?)
While I like the proposal of going back to no_std
this kind of conflicts with the other proposal to use T: Read
as parser input instead of byte slices. We could work around that by creating another trait that is similar to Read
but works in no_std
.
My PR does some initial work on T: Read
parsing and could in theory be also used as stepping stone for this proposal since it moves the allocating parts to the user side.
In case anyone requires no_std
support for the wasmparser
crate: I am maintaining a no_std
fork for embedded environments here: https://crates.io/crates/wasmparser-nostd
For anyone interested I've opened https://github.com/bytecodealliance/wasmtime/issues/8341 which is for Wasmtime but would extend to wasmparser since it's a dependency and would be required as well.
Done now in https://github.com/bytecodealliance/wasm-tools/pull/1493, so closing.