Stream: general

Topic: Small questions about WIT


view this post on Zulip Sekoia (Nov 12 2024 at 14:36):

Heya, I'm trying to figure out how the whole component model works, including the canonical ABI (with the goal of compiling my own language to it). I've noticed a few things:

From https://github.com/WebAssembly/component-model/blob/main/design/mvp/CanonicalABI.md:

As an optimization, flags are represented as packed bit-vectors. Like variant discriminants, flags use the smallest integer that fits all the bits, falling back to sequences of i32s when there are more than 32 flags.

def alignment_flags(labels):
  n = len(labels)
  assert(0 < n <= 32)
  if n <= 8: return 1
  if n <= 16: return 2
  return 4

First, that assert kinda confuses me. The whole case of "more than 32 flags" is not handled... anywhere, as far as I can tell. Additionally, why not use 64-bit integers too? They're primitives too. I would also say the same thing about Variant discriminators only using up to 32 bits, but honestly 4 billion variants seems like a pretty reasonable limit.

From https://github.com/WebAssembly/component-model/blob/main/design/mvp/WIT.md:

record-fields ::= record-field
                | record-field ',' record-fields?

More generally, it seems like zero-sized types (and impossible types like variants with no variants) are impossible. I guess they're expected to be stripped by whatever generator that makes the WIT data?

I'll probably add further questions to this thread later, but that's it for now.

Repository for design and specification of the Component Model - WebAssembly/component-model
Repository for design and specification of the Component Model - WebAssembly/component-model

view this post on Zulip Lann Martin (Nov 12 2024 at 15:14):

On zero-sized types you can see the rationale here: https://github.com/WebAssembly/component-model/pull/218

In C++, all types must have a non-zero size, so empty structs have size 1. In C, structs with no members are non-standard, though widely supported, with size 0, making them ABI-incompatible with C+...

view this post on Zulip Sekoia (Nov 12 2024 at 15:22):

Interesting, thank you!

view this post on Zulip Alex Crichton (Nov 12 2024 at 16:09):

For flags we recently limited flags to 32 and haven't gotten to go back and update the abi representation

view this post on Zulip Alex Crichton (Nov 12 2024 at 16:09):

The plan is to increase the limit to 64 in the future and use i64 for the representation

view this post on Zulip Alex Crichton (Nov 12 2024 at 16:11):

Some minor extra changes are needed in the spec though to fully handle this

view this post on Zulip Sekoia (Nov 12 2024 at 16:15):

Ah, fair enough!

view this post on Zulip Sekoia (Nov 17 2024 at 00:55):

What are "refines"? They're mentioned when storing/loading variants, but not specified anywhere from what I can tell?

view this post on Zulip Lann Martin (Nov 18 2024 at 13:44):

It looks like the feature was effectively "disabled" in https://github.com/WebAssembly/component-model/pull/255

This PR implements the idea in #229 of qualifying the parts of the current proposal that are not included in the upcoming 'Preview 2' stability milestone. Subtyping wasn't really writt...

view this post on Zulip Sekoia (Nov 18 2024 at 14:07):

Fair enough! Makes my life easier lol

view this post on Zulip Lann Martin (Nov 18 2024 at 14:20):

https://github.com/WebAssembly/component-model/issues/414

The refines feature was removed from the explainer in #255 but is still referenced in the cabi docs. This has caused confusion for at least one person so should probably either be completely remove...

view this post on Zulip Sekoia (Nov 18 2024 at 14:21):

Haha, I was thinking about opening an issue. Thanks!


Last updated: Nov 22 2024 at 16:03 UTC