Context
wit-bindgen 0.55.0's StreamWriter::write() takes Vec<T>, requiring heap allocation. But the canonical ABI level uses caller-supplied linear memory buffers: stream.write(handle, memory, ptr, count). No allocation needed at the ABI level.
The verified engine is no_std/no_alloc. The WASM binding layer currently uses Vec<T> — this is a wit-bindgen convenience, not fundamental.
Three paths to no_alloc streams
1. write_buf(AbiBuffer) (available now)
wit-bindgen 0.55.0 has StreamWriter::write_buf() taking AbiBuffer<T> instead of Vec<T>. Investigate whether AbiBuffer can be backed by a static buffer.
2. Custom cabi_realloc (proven in POC)
Luke Wagner's approach (component-model#314): store buffer pointer in WASM global, implement cabi_realloc to return pre-allocated buffer. No spec changes. Already proven in POC by Marcin Kolny.
3. Flat-types zero-copy (experimental)
Christof Petig's proposal (component-model#398): zero-copy pub-sub using host-managed shared memory. Working WASI 0.3 prototype exists. Not standardized.
What to implement
Start with approach #2: custom cabi_realloc returning from Kiln's safe_managed_alloc! or a static buffer pool. The binding layer becomes:
static mut STREAM_BUF: [Violation; MAX_VIOLATIONS_PER_CYCLE] = [...];
// cabi_realloc returns &STREAM_BUF when size matches
References
Context
wit-bindgen 0.55.0's
StreamWriter::write()takesVec<T>, requiring heap allocation. But the canonical ABI level uses caller-supplied linear memory buffers:stream.write(handle, memory, ptr, count). No allocation needed at the ABI level.The verified engine is no_std/no_alloc. The WASM binding layer currently uses
Vec<T>— this is a wit-bindgen convenience, not fundamental.Three paths to no_alloc streams
1.
write_buf(AbiBuffer)(available now)wit-bindgen 0.55.0 has
StreamWriter::write_buf()takingAbiBuffer<T>instead ofVec<T>. Investigate whetherAbiBuffercan be backed by a static buffer.2. Custom
cabi_realloc(proven in POC)Luke Wagner's approach (component-model#314): store buffer pointer in WASM global, implement
cabi_reallocto return pre-allocated buffer. No spec changes. Already proven in POC by Marcin Kolny.3. Flat-types zero-copy (experimental)
Christof Petig's proposal (component-model#398): zero-copy pub-sub using host-managed shared memory. Working WASI 0.3 prototype exists. Not standardized.
What to implement
Start with approach #2: custom
cabi_reallocreturning from Kiln'ssafe_managed_alloc!or a static buffer pool. The binding layer becomes:References