Skip to content

Commit ef6cb38

Browse files
authored
Document that --realloc-via-memory-grow only affects adapters (bytecodealliance#2613)
The flag is read in one place, `process_adapters`, on the branch for modules that aren't libraries, so it has no effect unless an adapter is passed with `--adapt`. It also doesn't synthesize a `cabi_realloc` for a main module that lacks one, which is what the repro in bytecodealliance#2404 expected. Neither the CLI description nor the `ComponentEncoder` setter said any of this, so say it in both and bless the two help snapshots.
1 parent 3ef3cef commit ef6cb38

4 files changed

Lines changed: 28 additions & 6 deletions

File tree

crates/wit-component/src/encoding.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3466,10 +3466,16 @@ impl ComponentEncoder {
34663466
Ok(self)
34673467
}
34683468

3469-
/// True if the realloc and stack allocation should use memory.grow
3470-
/// The default is to use the main module realloc
3471-
/// Can be useful if cabi_realloc cannot be called before the host
3469+
/// Whether adapters use `memory.grow` for realloc and stack allocation.
3470+
///
3471+
/// By default an adapter imports `cabi_realloc` from the main module.
3472+
/// Setting this to `true` makes it allocate with `memory.grow` instead,
3473+
/// which can be useful if `cabi_realloc` cannot be called before the host
34723474
/// runtime is initialized.
3475+
///
3476+
/// This only affects modules added with [`ComponentEncoder::adapter`]. It
3477+
/// has no effect on the main module and does not synthesize a
3478+
/// `cabi_realloc` for a module that doesn't export one.
34733479
pub fn realloc_via_memory_grow(&mut self, value: bool) -> &mut Self {
34743480
self.realloc_via_memory_grow = value;
34753481
self

src/bin/wasm-tools/component.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,15 @@ struct ComponentEncoderOpts {
192192
)]
193193
validate: Option<Option<bool>>,
194194

195-
/// Use memory.grow to realloc memory and stack allocation.
195+
/// Use memory.grow to realloc memory and stack allocation in adapters.
196+
///
197+
/// This only affects adapter modules passed with `--adapt`. It makes an
198+
/// adapter allocate with `memory.grow` instead of importing `cabi_realloc`
199+
/// from the main module, which is the default. It does not synthesize a
200+
/// `cabi_realloc` for a main module that doesn't export one.
201+
///
202+
/// This can be useful if `cabi_realloc` cannot be called before the host
203+
/// runtime is initialized.
196204
#[clap(long)]
197205
realloc_via_memory_grow: bool,
198206

tests/cli/help-component-new-short.wat.stdout

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Options:
2727
Whether or not to validate the output component [possible values:
2828
true, false]
2929
--realloc-via-memory-grow
30-
Use memory.grow to realloc memory and stack allocation
30+
Use memory.grow to realloc memory and stack allocation in adapters
3131
--merge-imports-based-on-semver[=<true|false>]
3232
Indicates whether imports into the final component are merged based on
3333
semver ranges [possible values: true, false]

tests/cli/help-component-new.wat.stdout

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,15 @@ Options:
8484
[possible values: true, false]
8585

8686
--realloc-via-memory-grow
87-
Use memory.grow to realloc memory and stack allocation
87+
Use memory.grow to realloc memory and stack allocation in adapters.
88+
89+
This only affects adapter modules passed with `--adapt`. It makes an
90+
adapter allocate with `memory.grow` instead of importing
91+
`cabi_realloc` from the main module, which is the default. It does not
92+
synthesize a `cabi_realloc` for a main module that doesn't export one.
93+
94+
This can be useful if `cabi_realloc` cannot be called before the host
95+
runtime is initialized.
8896

8997
--merge-imports-based-on-semver[=<true|false>]
9098
Indicates whether imports into the final component are merged based on

0 commit comments

Comments
 (0)