Skip to content

Minimal implementation of fixed size lists to enable wit-bindgen runtime tests #10619

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

cpetig
Copy link

@cpetig cpetig commented Apr 20, 2025

Implement the necessary parts of fixed size lists (see WebAssembly/component-model#384 ) to enable runtime testing in wit-bindgen.

@github-actions github-actions bot added wasmtime:api Related to the API of the `wasmtime` crate itself wasmtime:config Issues related to the configuration of Wasmtime labels Apr 20, 2025
Copy link

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.

    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.

    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.


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 on lines +547 to +548
let abi = CanonicalAbiInfo::record(
(0..size).into_iter().map(|_| element_abi));
Copy link
Member

Choose a reason for hiding this comment

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

Could this be done with a new helper? I'm wary of defining an O(n) thing here and relying on LLVM to optimize it. This could make list<T, BigNumber> excessively slow in debug builds of Wasmtime for example.

@@ -1040,6 +1065,10 @@ impl TypeInformation {
self.build_record(ty.types.iter().map(|t| types.type_information(t)));
}

fn fixed_size_lists(&mut self, types: &ComponentTypesBuilder, ty: &TypeFixedSizeList) {
self.build_record((0..ty.size).into_iter().map(|_| types.type_information(&ty.element)));
Copy link
Member

Choose a reason for hiding this comment

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

Same as above, I think it'd be best to avoid "feigning" a record here and using a dedicated computation for fixed-size lists to avoid O(n) in the length of the list

Comment on lines +2631 to +2654
fn translate_fixed_size_list(
&mut self,
src_ty: TypeFixedSizeListIndex,
src: &Source<'_>,
dst_ty: &InterfaceType,
dst: &Destination,
) {
let src_ty = &self.types[src_ty];
let dst_ty = match dst_ty {
InterfaceType::FixedSizeList(t) => &self.types[*t],
_ => panic!("expected a fixed size list"),
};

// TODO: subtyping
assert_eq!(src_ty.size, dst_ty.size);

let srcs = src
.record_field_srcs(self.types, (0..src_ty.size).into_iter().map(|_| src_ty.element));
let dsts = dst
.record_field_dsts(self.types, (0..dst_ty.size).into_iter().map(|_| dst_ty.element));
for (src, dst) in srcs.zip(dsts) {
self.translate(&src_ty.element, &src, &dst_ty.element, &dst);
}
}
Copy link
Member

Choose a reason for hiding this comment

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

This is a bit of an interesting case. Effectively what this is doing is unrolling list<T, N> unconditionally, but I don't think that's necessarily appropriate for large N. I think it's fine to unroll for small N (perhaps only when T is small?). Ideally this would have a budget of sorts where a fixed number Cost is divided by the cost of T , and that's the maximal unrolling. That way we don't generate exponential amounts of code here for list<list<T, N>, N>.

Basically what I'm saying is that I think we must implement the loop-based variant of translating lists, not just the fully-unrolled version of translating lists.

@@ -148,6 +148,7 @@ impl TypeChecker<'_> {
(InterfaceType::Future(_), _)
| (InterfaceType::Stream(_), _)
| (InterfaceType::ErrorContext(_), _) => todo!(),
(InterfaceType::FixedSizeList(_), _) => todo!(),
Copy link
Member

Choose a reason for hiding this comment

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

Since these are relatively targeted todo!() items mind filing an issue as a tracking issue and tagging these with // FIXME(#NNNN)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wasmtime:api Related to the API of the `wasmtime` crate itself wasmtime:config Issues related to the configuration of Wasmtime
2 participants