-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
base: main
Are you sure you want to change the base?
Conversation
Label Messager: wasmtime:configIt looks like you are changing Wasmtime's configuration options. Make sure to
To modify this label's message, edit the To add new label messages or remove existing label messages, edit the |
let abi = CanonicalAbiInfo::record( | ||
(0..size).into_iter().map(|_| element_abi)); |
There was a problem hiding this comment.
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))); |
There was a problem hiding this comment.
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
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); | ||
} | ||
} |
There was a problem hiding this comment.
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!(), |
There was a problem hiding this comment.
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)
?
Implement the necessary parts of fixed size lists (see WebAssembly/component-model#384 ) to enable runtime testing in wit-bindgen.