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

Parse milestone 4 nominal types #4222

Merged
merged 3 commits into from
Oct 8, 2021

Conversation

tlively
Copy link
Member

@tlively tlively commented Oct 8, 2021

Implement parsing the new {func,struct,array}_subtype format for nominal types.
For now, the new format is parsed the same way the old-style (extends X) format
is parsed, i.e. in --nominal mode types are parsed as nominal but otherwise they
are parsed as equirecursive. Intentionally do not parse the new types
unconditionally as nominal for now to allow frontends to update their nominal
text format while continuing to use the workflow of running wasm-opt without
--nominal to lower nominal types to structural types. A future PR will introduce
a new pass to perform this lowering explicitly, allowing the parsers to create
true nominal types without breaking that workflow.

Implement parsing the new {func,struct,array}_subtype format for nominal types.
For now, the new format is parsed the same way the old-style (extends X) format
is parsed, i.e. in --nominal mode types are parsed as nominal but otherwise they
are parsed as equirecursive. Intentionally do not parse the new types
unconditionally as nominal for now to allow frontends to update their nominal
text format while continuing to use the workflow of running wasm-opt without
--nominal to lower nominal types to structural types. A future PR will introduce
a new pass to perform this lowering explicitly, allowing the parsers to create
true nominal types without breaking that workflow.

Also switch the printer to use the new format, since the old format will
eventually be removed.
@tlively tlively requested a review from kripken October 8, 2021 02:16
@kripken
Copy link
Member

kripken commented Oct 8, 2021

Intentionally do not parse the new types unconditionally as nominal for now to allow frontends to update their nominal text format while continuing to use the workflow of running wasm-opt without --nominal to lower nominal types to structural types.

Do we need that? I'd check with j2cl as I think they can feed nominal types to v8 now, if you haven't already.

@@ -2504,9 +2504,15 @@ struct PrintSExpression : public UnifiedExpressionVisitor<PrintSExpression> {
visitExpression(curr);
}
// Module-level visitors
void handleSignature(HeapType curr, Name name = Name()) {
void handleSignature(HeapType curr, Module* module, Name name = Name()) {
Copy link
Member

Choose a reason for hiding this comment

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

There is already currModule which you can use.

Signature sig = curr.getSignature();
o << "(func";
HeapType super;
bool nominal = curr.getSuperType(super);
Copy link
Member

Choose a reason for hiding this comment

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

This will be true for the old nominal types as well as M4 ones, correct? So we are changing all of our printing of nominal types?

@@ -12,11 +12,11 @@
(type $A (struct (field (ref null $C))))

;; CHECK: (type $B (struct (field (ref null $D))))
;; NOMNL: (type $B (struct (field (ref null $D))) (extends $A))
;; NOMNL: (type $B (struct_subtype (field (ref null $D)) $A))
Copy link
Member

Choose a reason for hiding this comment

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

Continuing the previous question about changing all of our nominal printing, it looks like that is indeed the case - all nominal types are now printed as M4? In particular that means reading text and printing emits something different if the input was the old form and not M4, as shown here. That may break roundtripping via text, which is unfortunately still disabled, in the fuzzer,

binaryen/scripts/fuzz_opt.py

Lines 1012 to 1013 in c2fa907

# FIXME: Re-enable after https://github.com/WebAssembly/binaryen/issues/3989
# RoundtripText()

If there are no updates on #3989 yet then before landing this PR we should at least verify manually that we have sufficient text roundtripping tests in the test suite - I can only remember a very small number.

(My concern is that, other than fuzzing + roundtripping tests in the test suite, the new form that we now print is only checked as an input in the new tiny file test/lit/parse-nominal-types.wast. So we'd be writing something with minimal testing for reading.)

@tlively tlively changed the title Parse and print the milestone 4 nominal types Parse milestone 4 nominal types Oct 8, 2021
@tlively
Copy link
Member Author

tlively commented Oct 8, 2021

I reverted the changes to the printer for now and beefed up the parsing test, so this should be good for another review.

@tlively tlively merged commit 53c5e3e into WebAssembly:main Oct 8, 2021
@tlively tlively deleted the parse-nominal-types branch October 8, 2021 21:21
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