WebAssembly / component-model

Repository for design and specification of the Component Model
Other
971 stars 81 forks source link

Align binary encoding of `sort` and `externdesc` #157

Closed alexcrichton closed 1 year ago

alexcrichton commented 1 year ago

Currently Binary.md states:

sort                ::= 0x00 cs:<core:sort>                                => core cs
                      | 0x01                                               => func
                      | 0x02                                               => value
                      | 0x03                                               => type
                      | 0x04                                               => component
                      | 0x05                                               => instance

...

externdesc    ::= 0x00 0x11 i:<core:typeidx>              => (core module (type i))
                | 0x01 i:<typeidx>                        => (func (type i))
                | 0x02 t:<valtype>                        => (value t)
                | 0x03 b:<typebound>                      => (type b)
                | 0x04 i:<typeidx>                        => (instance (type i))
                | 0x05 i:<typeidx>                        => (component (type i))

which while these are mostly aligned the component and instance codes are swapped. It turns out that the wasm-tools implementation actually accidentally diverges from the spec here and uses 0x04 for components and 0x05 for instances, so swapping the last two cases in externdesc may be the way to go for now?

lukewagner commented 1 year ago

Yes, agreed, I think this is a bug in Binary.md. Will fix in a bit. Thanks!

alexcrichton commented 1 year ago

I should also clarify that Luke is the one that found this, not me, it just came up in the context of some other stuff we were discussing and I was opening https://github.com/WebAssembly/component-model/issues/158 and figured I'd open this as well.