Skip to content

Fixed-length lists, host side#12315

Open
cpetig wants to merge 19 commits into
bytecodealliance:mainfrom
cpetig:fixed-size-list-host
Open

Fixed-length lists, host side#12315
cpetig wants to merge 19 commits into
bytecodealliance:mainfrom
cpetig:fixed-size-list-host

Conversation

@cpetig

@cpetig cpetig commented Jan 11, 2026

Copy link
Copy Markdown
Contributor

Replace the todo's with proper code and add a host side test case.

Implements #12279

Includes all the commits on #10619 , so that one should be merged first.

@github-actions github-actions Bot added fuzzing Issues related to our fuzzing infrastructure wasmtime:api Related to the API of the `wasmtime` crate itself wasmtime:c-api Issues pertaining to the C API. wasmtime:config Issues related to the configuration of Wasmtime labels Jan 11, 2026
@github-actions

Copy link
Copy Markdown

Subscribe to Label Action

cc @fitzgen

Details This issue or pull request has been labeled: "fuzzing", "wasmtime:api", "wasmtime:c-api", "wasmtime:config"

Thus the following users have been cc'd because of the following labels:

  • fitzgen: fuzzing

To subscribe or unsubscribe from this label, edit the .github/subscribe-to-label.json configuration file.

Learn more.

@github-actions

Copy link
Copy Markdown

Label Messager: wasmtime:config

It looks like you are changing Wasmtime's configuration options. Make sure to
complete this check list:

  • If you added a new Config method, you wrote extensive documentation for
    it.

    Details

    Our documentation should be of the following form:

    Short, simple summary sentence.
    
    More details. These details can be multiple paragraphs. There should be
    information about not just the method, but its parameters and results as
    well.
    
    Is this method fallible? If so, when can it return an error?
    
    Can this method panic? If so, when does it panic?
    
    # Example
    
    Optional example here.
    
  • If you added a new Config method, or modified an existing one, you
    ensured that this configuration is exercised by the fuzz targets.

    Details

    For example, if you expose a new strategy for allocating the next instance
    slot inside the pooling allocator, you should ensure that at least one of our
    fuzz targets exercises that new strategy.

    Often, all that is required of you is to ensure that there is a knob for this
    configuration option in wasmtime_fuzzing::Config (or one
    of its nested structs).

    Rarely, this may require authoring a new fuzz target to specifically test this
    configuration. See our docs on fuzzing for more details.

  • If you are enabling a configuration option by default, make sure that it
    has been fuzzed for at least two weeks before turning it on by default.


Details

To modify this label's message, edit the .github/label-messager/wasmtime-config.md file.

To add new label messages or remove existing label messages, edit the
.github/label-messager.json configuration file.

Learn more.

Comment thread crates/wasmtime/src/runtime/component/func/typed.rs Outdated
@cpetig cpetig changed the title Fixed size list, host side Fixed-length lists, host side Jan 13, 2026
@cpetig

cpetig commented Jan 13, 2026

Copy link
Copy Markdown
Contributor Author

TODO: Check whether the standard name fixed-length lists is used over fixed size lists.

@AlbertMarashi

Copy link
Copy Markdown

What's remaining for this?

@cpetig

cpetig commented Feb 6, 2026

Copy link
Copy Markdown
Contributor Author

What's remaining for this?

I didn't find the time to add a proper test case. And I (non-blockingly) wait for a new wasm-tools release to do the renaming in one row.

@cpetig cpetig force-pushed the fixed-size-list-host branch from 8d18537 to 9157634 Compare June 11, 2026 22:38
Comment thread crates/environ/src/component/types.rs Outdated
Comment thread tests/all/component_model/fixed_length_list.rs Outdated
Comment thread tests/all/component_model/fixed_length_list.rs Outdated
Comment thread crates/wasmtime/src/runtime/component/types.rs Outdated
@cpetig cpetig marked this pull request as ready for review June 14, 2026 00:20
@cpetig cpetig requested review from a team as code owners June 14, 2026 00:20
@cpetig cpetig requested review from fitzgen and removed request for a team June 14, 2026 00:20
@cpetig cpetig self-assigned this Jun 14, 2026
@cpetig cpetig moved this from Todo to In Progress in Implement WIT Fixed-Length-Lists Jun 14, 2026

@cpetig cpetig left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure whether the O(n) constraint applies to the host side as the user always controls the data types (and dimensions) added on the host side, but if so I will gladly investigate into a different solution.

Comment thread crates/wasmtime/src/runtime/component/values.rs Outdated
Comment thread crates/fuzzing/src/oracles/component_api.rs
Comment thread crates/wasmtime/src/runtime/component/values.rs Outdated
@cpetig

cpetig commented Jun 14, 2026

Copy link
Copy Markdown
Contributor Author

@Felix-El

@fitzgen fitzgen requested review from alexcrichton and removed request for a team and fitzgen June 15, 2026 16:29
Comment thread crates/fuzzing/src/oracles/component_api.rs
Comment thread crates/wasmtime/src/runtime/component/values.rs Outdated
Comment thread crates/wasmtime/src/runtime/component/values.rs Outdated
Comment on lines +754 to +769
/// Returns the abi for a fixed length list
pub const fn fixed_length_list_static(
element: &CanonicalAbiInfo,
count: u32,
) -> CanonicalAbiInfo {
CanonicalAbiInfo {
size32: element.size32 * count,
align32: element.align32,
size64: element.size64 * count,
align64: element.align64,
flat_count: match element.flat_count {
None => None,
Some(c) => Some(c.saturating_mul(if count > 255 { 255u8 } else { count as u8 })),
},
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've got some miscellaneous concerns about this function, so I'm going to list them here:

  • This is more-or-less duplicated with new_fixed_length_list_type in types_builder.rs. Could that call this function (or a similar signature?)
  • I'm worried about the unchecked multiplication here because the host could declare [SomeBigStruct; HUGE_NUMBER] which exceeds 4GiB of data, and I'd want that to be a panic/error/something as opposed to the silent wrap here.
  • I think the saturating_mul here should be checked_mul, and I also don't think the conversion here to u8 is right. If c is 1 and count is 256 then flat_count should be None, not Some(255).
  • I'm a little worried that in Rust below we've got N: usize where the parameter count: u32 has a different type here. Could there be a separate entrypoint which takes count: usize and performs a fallible/panicking conversion asserting that the count is less than u32::MAX?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about how to remove the duplication but this gets more difficult because one of the functions is const (this also makes the implementation less elegant as traits (and_then, try_from) don't work) and I didn't identify an obvious common dependency which is not core but component model specific.

I think I addressed all other concerns.

Comment on lines +3031 to +3063
// this is a reimplementation of array::try_from_fn, replace once that became stable
fn array_try_from_fn<E, F, T, const N: usize>(mut cb: F) -> Result<[T; N], E>
where
F: FnMut(usize) -> Result<T, E>,
{
let mut valid = 0;
let mut result: [MaybeUninit<T>; N] = [const { MaybeUninit::uninit() }; N];
let mut error: Option<E> = None;
for n in 0..N {
match cb(n) {
Ok(v) => {
result[valid].write(v);
valid += 1;
}
Err(e) => {
error = Some(e);
// continue to consume all input
}
}
}
if let Some(e) = error {
// on error drop all valid elements
for n in 0..valid {
unsafe {
result[n].assume_init_drop();
}
}
return Err(e);
}
assert!(valid == N);
// this is a copy of array_assume_init from stdlib to avoid requiring nightly
Ok(unsafe { (&result as *const _ as *const [T; N]).read() })
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be moved to crates/core/src/array.rs so this could get miri-testing there, and additionally enable adding #[test] for this? Additionally, this doesn't currently handle panics of cb (leaks intermediate results) and a few more casts than I think are necessary.

I sketched out what I'm thinking here and feel free to copy that into this PR

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sadly that implementation is only possible with 1.95 up (AsMut on Uninit array, see https://doc.rust-lang.org/beta/core/mem/union.MaybeUninit.html#impl-AsMut%3C%5BMaybeUninit%3CT%3E%5D%3E-for-MaybeUninit%3C%5BT;+N%5D%3E )
🤔

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found a way which still feels sound to me, hopefully you agree ...

@cpetig cpetig force-pushed the fixed-size-list-host branch from 7e7faa7 to be79c14 Compare June 20, 2026 23:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fuzzing Issues related to our fuzzing infrastructure wasmtime:api Related to the API of the `wasmtime` crate itself wasmtime:c-api Issues pertaining to the C API. wasmtime:config Issues related to the configuration of Wasmtime

Projects

Development

Successfully merging this pull request may close these issues.

3 participants