Stream: general

Topic: Q: (list (list string)) Nested Lists / Wasm components


view this post on Zulip Zeeshan Lakhani (Feb 23 2023 at 18:05):

Is there a way to unwrap_list and know the inner wasm:component:types:Type associated with it with the inner handle? I'm running into this scenario trying to map some things with lists of lists (nested lists)? I'm probably missing something. I didn't find a good test w/ inner lists and wit as well.

view this post on Zulip Pat Hickey (Feb 23 2023 at 18:11):

good q, the only test i can find that uses list<list<string>> is in wit-bindgen

view this post on Zulip Pat Hickey (Feb 23 2023 at 18:12):

https://github.com/bytecodealliance/wit-bindgen/blob/main/tests/runtime/lists/wasm.rs#L100

A language binding generator for WebAssembly interface types - wit-bindgen/wasm.rs at main · bytecodealliance/wit-bindgen

view this post on Zulip Pat Hickey (Feb 23 2023 at 18:14):

when using wit-bindgen, we present the list as a Vec<Vec<String>>, so the api definitely works. you can use cargo expand to see how the wasmtime::component::binden! macro generates the code that goes from component::Val to that

view this post on Zulip Pat Hickey (Feb 23 2023 at 18:15):

does that answer your question? or is there something particular about the types representation of lists that is missing here

view this post on Zulip Pat Hickey (Feb 23 2023 at 18:17):

it looks to me like if you have a ty: Type and its a list, the elem type is then ty.unwrap_list().ty()

view this post on Zulip Zeeshan Lakhani (Feb 23 2023 at 18:22):

Thanks @Pat Hickey. I'll double check the bindgen. I was using ty.unwrap_list().ty() while trying to reuse the echo component stuff in the wasmtime repo test suite. It was just giving me the inner list handler at index 0 (first run returns 1). But, I think I maybe got it. :)

view this post on Zulip Zeeshan Lakhani (Feb 23 2023 at 18:28):

@Pat Hickey a Q in addition then. In the current wit / component spec, would there be any way to encode heterogeneous lists? Or is that eve something to think about :)

view this post on Zulip Pat Hickey (Feb 23 2023 at 18:28):

theres no dynamic types in component model, so youd need to make an enum of the possible variants in your hlist

view this post on Zulip Pat Hickey (Feb 23 2023 at 18:29):

theres also no recursive types

view this post on Zulip Pat Hickey (Feb 23 2023 at 18:30):

these do eliminate some cool possibilities, but theyre reasonable restrictions for a lot of "real world" programs for now, and make it a lot more tractable to ship this thing :)

view this post on Zulip Zeeshan Lakhani (Feb 23 2023 at 18:33):

Yep, figured @Pat Hickey. I'm writing an IR from something that had recursive types and mapping that, with runtime checking, to wasmtime:component Vals. Encoding the enum of variants is next on my list.

view this post on Zulip Zeeshan Lakhani (Feb 23 2023 at 19:01):

Thanks again @Pat Hickey


Last updated: Nov 22 2024 at 16:03 UTC