Skip to content

Conversation

@rossberg
Copy link
Member

Post MVP we will likely extend Wasm with a few richer types, e.g., function types for blocks, struct types, or function pointers. That introduces a number of places where types will be given either directly or via reference to the type section.

To make Wasm future-proof for efficiently overlaying both these spaces, this PR changes the existing type constructors to have negative opcodes, such that they are distinguishable from indexed type definitions (which are naturally positive).

For example, this will in the future allow

  • generalising block annotations to multiple or function types without requiring escape code hacks,
  • defining local variables that have struct type (by reference into the type section),
  • defining struct types whose fields are either value types, function (pointers), or other structs,
  • if desirable, inlining of function types for uses where currently a type section entry is required.

The PR also cleans up the description of type encodings.

@rossberg rossberg added this to the MVP milestone Oct 19, 2016
@rossberg rossberg changed the title Make type opcodes negative Future-proof type opcodes Oct 19, 2016
Copy link

@titzer titzer left a comment

Choose a reason for hiding this comment

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

This change generally LGTM, but I'm not sure we'll be able to swing this due to time constraints.

### `value_type`
A single-byte unsigned integer indicating a [value type](Semantics.md#types). These types are encoded as:
A `varint7` indicating a [value type](Semantics.md#types). These types are encoded as:
* `-0x01` indicating type `i32`
Copy link

Choose a reason for hiding this comment

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

Note that this is byte value 0x7f?

@rossberg
Copy link
Member Author

Online and offline comments addressed. Fixed out-of-bounds values.


| Field | Type | Description |
| ----- | ---- | ----------- |
| form | `varint32` | `-0x20` (i.e., the byte `0x60`) indicating a function type |
Copy link
Member

@lukewagner lukewagner Oct 20, 2016

Choose a reason for hiding this comment

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

So in this negative constructor opcode space, we have -1, -2, -3, -4, -0x10, -0x20, -0x40. Do you think it makes sense to hoist these out into a new type_constructor subsection so that we can see them all in one list without having to know that these 7 values are all implicitly in the same index space? Then each of the 3 uses could specify which subset are valid.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good idea, done.


### `block_type`
A `varint7` indicating a signature. These types are encoded as:
* `-0x40` (i.e., the byte `0x40`) indicating a signature with 0 results.
Copy link

Choose a reason for hiding this comment

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

Sorry to bike-shed here, but do we want to start at -0x40, and then -0x3F for function and -0x3E for anyfunc.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hm, by starting with the lowest absolute value we keep an open-ended gap at the "end" for future extension. The inverse order would become rather weird if we were to grow out of the 6 bit negative range of a varint7, because then we'd have to wrap around and add additional types or categories "before" the basic types.

@titzer
Copy link

titzer commented Oct 20, 2016

On Thu, Oct 20, 2016 at 4:44 PM, rossberg-chromium <[email protected]

wrote:

@rossberg-chromium commented on this pull request.

In BinaryEncoding.md #823:

-### inline_signature_type
-A single-byte unsigned integer indicating a signature. These types are encoded as:
-* 0 indicating a signature with 0 results.
-* 1 indicating a signature with 1 result of type i32.
-* 2 indicating a signature with 1 result of type i64.
-* 3 indicating a signature with 1 result of type f32.
-* 4 indicating a signature with 1 result of type f64.
+A varint7 indicating a value type. These types are encoded as:
+* -0x01 (i.e., the byte 0x7f) indicating type i32
+* -0x02 (i.e., the byte 0x7e) indicating type i64
+* -0x03 (i.e., the byte 0x7d) indicating type f32
+* -0x04 (i.e., the byte 0x7c) indicating type f64
+
+### block_type
+A varint7 indicating a signature. These types are encoded as:
+* -0x40 (i.e., the byte 0x40) indicating a signature with 0 results.

Hm, by starting with the lowest absolute value we keep an open-ended gap
at the "end" for future extension. The inverse order would become rather
weird if we were to grow out of the 6 bit negative range of a varint7,
because then we'd have to wrap around and add additional types or
categories "before" the basic types.

Hmm. What about starting at -0x20 (-32) and counting towards negative
infinity also for constructors? I.e. -32 for void, -33 for function, -34
for anyfunc, etc.


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#823, or mute the thread
https://github.com/notifications/unsubscribe-auth/ALnq1KTe2cxdP0wTbQRIGfJ-TSmkouulks5q135bgaJpZM4KbDdk
.

@lukewagner
Copy link
Member

lgtm; no strong opinion on @titzer's suggestion to pack 'em closer

@rossberg
Copy link
Member Author

@titzer, the idea with the gaps is the same as for our instruction opcodes: there are different categories of types (currently, value types, element types, defined types), and it 's nice to leave space to extend each category.

@titzer
Copy link

titzer commented Oct 21, 2016

lgtm

@rossberg rossberg merged commit d40f100 into binary_0xd Oct 21, 2016
@rossberg rossberg deleted the overlay-tycons branch October 21, 2016 09:06
@titzer
Copy link

titzer commented Oct 25, 2016

Alrighty

On Thu, Oct 20, 2016 at 6:27 PM, rossberg-chromium <[email protected]

wrote:

@titzer https://github.com/titzer, the idea with the gaps is the same
as for our instruction opcodes: there are different categories of types
(currently, value types, element types, defined types), and it 's nice to
leave space to extend each category.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#823 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ALnq1JHJooocOrgTF9Hqvs1CGf5gZno7ks5q15ZbgaJpZM4KbDdk
.

lukewagner added a commit that referenced this pull request Oct 26, 2016
* Reorganise opcode space (#826)

* Future-proof type opcodes (#823)

* Future-proof memory instructions (#824)

* Fix order of copysign (#828)

* Global types can be mutable, just not when imported (#830)

* Naming nit: rename `flags` to `reserved` (#832)

* Bump 0xd's version to 0xd

* Make it hex
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants