Skip to content
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

formalize component value definitions #336

Merged
merged 24 commits into from
Jun 3, 2024

Conversation

rvolosatovs
Copy link
Contributor

@rvolosatovs rvolosatovs commented Apr 10, 2024

I used

namesubsection_N(B) ::= N:<byte> size:<u32> B (if size == |B|)
componentnamesubsec ::= namesubsection_0(<name>)
sortnamesubsec ::= namesubsection_1(<sortnames>)
sortnames ::= sort:<sort> names:<namemap>
,
canon ::= 0x00 0x00 f:<core:funcidx> opts:<opts> ft:<typeidx> => (canon lift f opts type-index-space[ft])
as main points of reference for the initial approach.

Tried to stay as close as possible to core Wasm spec and the canonical ABI spec.

  • flags are encoded as variable-length uN bitmask - this does favor cases where flags with lowest indexes are set, however I feel like this is a reasonable approach to take at least for consistency with all other numerical values
  • enum and variant discriminants are encoded as variable-length u32-s, same argument applies as above. I do feel like for most use cases the discriminant should fit in a single byte
  • results and options match canonical ABI despecialization rules (https://github.com/WebAssembly/component-model/blob/main/design/mvp/CanonicalABI.md#despecialization)
    • 0x00 is used to identify result::ok
    • 0x01 for result:error
    • option::none is 0x00
    • option::some is 0x01
  • tuples and records are encoded as just the sequences of their field/element values, in order
  • valtype is specified once in the top-level (value t:<valtype> v:<val(t)>), because, although type inference should be possible in most use cases by looking at the usages of the value index, values may potentially be unused by the component directly (for example, exported). I feel like it's a very little price to pay for simpler implementation and type checking.

val encoding reference implementation is available at https://github.com/rvolosatovs/wrpc/blob/4fd7488caa4cff19079f851cd7d0efda8f613a64/crates/transport/src/lib.rs#L2557-L3223

Refs #15

design/mvp/Binary.md Outdated Show resolved Hide resolved
design/mvp/Binary.md Outdated Show resolved Hide resolved
design/mvp/Binary.md Outdated Show resolved Hide resolved
Copy link
Member

@lukewagner lukewagner left a comment

Choose a reason for hiding this comment

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

Great start, this is looking good.

design/mvp/Binary.md Outdated Show resolved Hide resolved
design/mvp/Binary.md Outdated Show resolved Hide resolved
design/mvp/Binary.md Outdated Show resolved Hide resolved
design/mvp/Binary.md Outdated Show resolved Hide resolved
design/mvp/Explainer.md Show resolved Hide resolved
design/mvp/Binary.md Outdated Show resolved Hide resolved
@rvolosatovs rvolosatovs force-pushed the feat/value-encoding branch 11 times, most recently from 5be7da1 to 33475cd Compare April 19, 2024 12:58
@rvolosatovs rvolosatovs marked this pull request as ready for review April 19, 2024 13:02
@rvolosatovs rvolosatovs force-pushed the feat/value-encoding branch 2 times, most recently from 6192a31 to b104874 Compare April 19, 2024 13:25
design/mvp/Binary.md Outdated Show resolved Hide resolved
Copy link
Member

@lukewagner lukewagner left a comment

Choose a reason for hiding this comment

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

Nice work! This looks good to me, but I think @sunfishcode has also thought a lot about how to express component-model values in a similar context where we are not inferring the types from the value, but rather checking that they match a given target type, so I'd appreciate his review too.

design/mvp/Explainer.md Outdated Show resolved Hide resolved
design/mvp/Explainer.md Outdated Show resolved Hide resolved
design/mvp/Explainer.md Outdated Show resolved Hide resolved
design/mvp/Binary.md Outdated Show resolved Hide resolved
design/mvp/Explainer.md Outdated Show resolved Hide resolved
design/mvp/Explainer.md Outdated Show resolved Hide resolved
design/mvp/Explainer.md Outdated Show resolved Hide resolved
design/mvp/Explainer.md Outdated Show resolved Hide resolved
design/mvp/Explainer.md Outdated Show resolved Hide resolved
design/mvp/Explainer.md Outdated Show resolved Hide resolved
design/mvp/Binary.md Outdated Show resolved Hide resolved
design/mvp/Explainer.md Outdated Show resolved Hide resolved
Copy link
Member

@lukewagner lukewagner left a comment

Choose a reason for hiding this comment

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

Great, thanks a bunch for all the changes (again). Just a few nits:

design/mvp/Binary.md Outdated Show resolved Hide resolved
design/mvp/Binary.md Outdated Show resolved Hide resolved
design/mvp/Binary.md Outdated Show resolved Hide resolved
design/mvp/Explainer.md Outdated Show resolved Hide resolved
design/mvp/Explainer.md Outdated Show resolved Hide resolved
design/mvp/Explainer.md Outdated Show resolved Hide resolved
design/mvp/Explainer.md Outdated Show resolved Hide resolved
design/mvp/Explainer.md Outdated Show resolved Hide resolved
Copy link

@primoly primoly left a comment

Choose a reason for hiding this comment

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

Should those core:u8 and core:s8 be core:byte instead?

design/mvp/Explainer.md Outdated Show resolved Hide resolved
design/mvp/Binary.md Outdated Show resolved Hide resolved
design/mvp/Binary.md Outdated Show resolved Hide resolved
design/mvp/Binary.md Outdated Show resolved Hide resolved
Signed-off-by: Roman Volosatovs <[email protected]>
Signed-off-by: Roman Volosatovs <[email protected]>
Signed-off-by: Roman Volosatovs <[email protected]>
Uninterpreted integers can be written as either signed or unsigned and
therefore elliminate the need for distinction between the two rules

Signed-off-by: Roman Volosatovs <[email protected]>
Signed-off-by: Roman Volosatovs <[email protected]>
@rvolosatovs
Copy link
Contributor Author

I think this is ready for the next review round

design/mvp/Explainer.md Outdated Show resolved Hide resolved
Signed-off-by: Roman Volosatovs <[email protected]>
Signed-off-by: Roman Volosatovs <[email protected]>
Copy link
Member

@lukewagner lukewagner left a comment

Choose a reason for hiding this comment

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

Awesome, thanks again! I think that addresses all the feedback I'm aware of. I'll merge at the end of the week if nothing else pops up.

@lukewagner lukewagner merged commit 8ba643f into WebAssembly:main Jun 3, 2024
1 check passed
lukewagner pushed a commit that referenced this pull request Jun 3, 2024
Special case `s8` and `u8` to ensure that exactly 1 byte is used
to represent values of those types

#336 (comment)

Signed-off-by: Roman Volosatovs <[email protected]>
lukewagner pushed a commit that referenced this pull request Jun 3, 2024
lukewagner pushed a commit that referenced this pull request Jun 3, 2024
@rvolosatovs rvolosatovs deleted the feat/value-encoding branch June 3, 2024 17:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants