Skip to content

Support type uses before definitions in text parser - #3584

Merged
tlively merged 1 commit into
WebAssembly:mainfrom
tlively:forward-declared-types
Feb 19, 2021
Merged

tlively merged 1 commit into
WebAssembly:mainfrom
tlively:forward-declared-types

Conversation

@tlively

@tlively tlively commented Feb 18, 2021

Copy link
Copy Markdown
Member

Traverses the module to find type definitions and uses a TypeBuilder to
construct the corresponding HeapTypes rather than constructing them directly.
This allows types to be used in the definitions of other types before they
themselves are defined, which is an important step toward supporting recursive
types. After this PR, no further text parsing changes will be necessary to
support recursive types.

Beyond allowing types to be used before their definitions, this PR also makes a
couple incidental changes to the parser's behavior. First, compound heaptypes
can now only be declared in (type ...) elements and cannot be declared inline
at their site of use. This reduces the flexibility of the parser, but is in line
with what the text format spec will probably look like eventually (see
WebAssembly/function-references#42).

The second change is that (type ...) elements are now all parsed before (func ...) elements rather than in text order with them, so the type indices will be
different and wasts using numeric type indices will be broken. Note however,
that we were already not completely spec compliant in this regard because we
parsed types defined by (type...) and (func...) elements before types
defined by the type uses of call_indirect instructions.

@tlively
tlively requested a review from kripken February 18, 2021 22:18
@tlively

tlively commented Feb 18, 2021

Copy link
Copy Markdown
Member Author

This currently includes an outdated version of #3578. I will rebase this once that lands, but I didn't want to delay posting this PR.

@kripken

kripken commented Feb 18, 2021

Copy link
Copy Markdown
Member

Sorry, I'm not sure what the intended review plan is here. Do you want me to start reading this before the parent PR is ready for review? (still waiting there on some stuff I believe)

If so could this be relative to that branch, so that the full diff is not shown here?

@tlively

tlively commented Feb 18, 2021

Copy link
Copy Markdown
Member Author

Unfortunately the branch for the other PR is my Binaryen fork, so there's no way to make a PR against it in this repo. The intention in posting it early was to give you the option to read it before the other one lands, but there's no rush. (Also the other one is ready for review again.)

Comment thread src/passes/Print.cpp
auto sep = "";
for (const auto& t : type) {
o << sep << t;
o << sep << SExprType(t);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

what does this fix?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Compound reference types in tuple locals were being fully printed rather than referring to a heap type by name. After this PR, inline heap types like that can no longer be parsed, so this change is necessary to use the type names instead.

Traverses the module to find type definitions and uses a TypeBuilder to
construct the corresponding HeapTypes rather than constructing them directly.
This allows types to be used in the definitions of other types before they
themselves are defined, which is an important step toward supporting recursive
types. After this PR, no further text parsing changes will be necessary to
support recursive types.

Beyond allowing types to be used before their definitions, this PR also makes a
couple incidental changes to the parser's behavior. First, compound heaptypes
can now only be declared in `(type ...)` elements and cannot be declared inline
at their site of use. This reduces the flexibility of the parser, but is in line
with what the text format spec will probably look like eventually (see
WebAssembly/function-references#42).

The second change is that `(type ...)` elements are now all parsed before `(func
...)` elements rather than in text order with them, so the type indices will be
different and wasts using numeric type indices will be broken. Note however,
that we were already not completely spec compliant in this regard because we
parsed types defined by `(type...)` and `(func...)` elements before types
defined by the type uses of `call_indirect` instructions.
@tlively
tlively force-pushed the forward-declared-types branch from 3fa7c97 to fd57c42 Compare February 19, 2021 03:25
@tlively
tlively merged commit b6c094c into WebAssembly:main Feb 19, 2021
@tlively
tlively deleted the forward-declared-types branch February 19, 2021 05:48
@tlively tlively mentioned this pull request Feb 20, 2021
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.

2 participants