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

Make final types the default #5918

Merged
merged 4 commits into from
Sep 9, 2023
Merged

Make final types the default #5918

merged 4 commits into from
Sep 9, 2023

Conversation

tlively
Copy link
Member

@tlively tlively commented Sep 1, 2023

Match the spec and parse the shorthand binary and text formats as final and emit
final types without supertypes using the shorthands as well. This is a
potentially-breaking change, since the text and binary shorthands can no longer
be used to define types that have subtypes.

Also make TypeBuilder entries final by default to better match the spec and
update the internal APIs to use the "open" terminology rather than "final"
terminology. Future changes will update the text format to use the standard "sub
open" rather than the current "sub final" keywords. The exception is the new wat
parser, which supporst "sub open" as of this change, since it didn't support
final types at all previously.

Match the spec and parse the shorthand binary and text formats as final and emit
final types without supertypes using the shorthands as well. This is a
potentially-breaking change, since the text and binary shorthands can no longer
be used to define types that have subtypes.

Also make TypeBuilder entries final by default to better match the spec and
update the internal APIs to use the "open" terminology rather than "final"
terminology. Future changes will update the text format to use the standard "sub
open" rather than the current "sub final" keywords. The exception is the new wat
parser, which supporst "sub open" as of this change, since it didn't support
final types at all previously.
@tlively tlively requested a review from kripken September 1, 2023 23:46
@tlively
Copy link
Member Author

tlively commented Sep 1, 2023

Current dependencies on/for this PR:

This comment was auto-generated by Graphite.

@codecov
Copy link

codecov bot commented Sep 2, 2023

Codecov Report

Merging #5918 (143f334) into main (9057105) will decrease coverage by 0.02%.
The diff coverage is 90.66%.

@@            Coverage Diff             @@
##             main    #5918      +/-   ##
==========================================
- Coverage   42.61%   42.60%   -0.02%     
==========================================
  Files         484      484              
  Lines       74844    74837       -7     
  Branches    11924    11922       -2     
==========================================
- Hits        31897    31886      -11     
- Misses      39747    39749       +2     
- Partials     3200     3202       +2     
Files Changed Coverage Δ
src/binaryen-c.cpp 0.00% <0.00%> (ø)
src/wasm-type.h 81.25% <ø> (ø)
src/wasm/wasm-binary.cpp 53.08% <50.00%> (ø)
src/wasm/wasm-type.cpp 83.65% <62.50%> (-0.28%) ⬇️
src/ir/type-updating.cpp 84.61% <100.00%> (ø)
src/passes/TypeMerging.cpp 88.02% <100.00%> (ø)
src/passes/TypeSSA.cpp 86.23% <100.00%> (ø)
src/tools/fuzzing/heap-types.cpp 42.06% <100.00%> (+0.09%) ⬆️
src/tools/wasm-fuzz-types.cpp 61.61% <100.00%> (ø)
src/wasm/wasm-s-parser.cpp 70.56% <100.00%> (+0.05%) ⬆️
... and 3 more

... and 1 file with indirect coverage changes

@tlively
Copy link
Member Author

tlively commented Sep 2, 2023

Oh neat, the coverage report strongly suggests that the TypeSSA tests have regressed, and indeed if you look at the diff, there should definitely not be so many final types.

Will fix that when I'm done moving.

@kripken
Copy link
Member

kripken commented Sep 5, 2023

(github errors on trying to review this PR, so trying a toplevel comment)

In wasm-type.cpp,

bool isOpen = false;

Shouldn't that default to true?

@tlively
Copy link
Member Author

tlively commented Sep 7, 2023

(github errors on trying to review this PR, so trying a toplevel comment)

In wasm-type.cpp,

bool isOpen = false;

Shouldn't that default to true?

No, we're changing the default to be final, i.e. not open.

@@ -1,5 +1,5 @@
(module
(type $struct (struct (field i32)))
(type $struct (sub (struct (field i32))))
Copy link
Member

Choose a reason for hiding this comment

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

Why did this change?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is a non-final type. Now that we interpret the shorthand (type $... (struct ...)) as a final type, we need to add (sub ...) to the printed output to correctly communicate that this is a non-final type.

Copy link
Member

Choose a reason for hiding this comment

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

I'm still confused then, sorry. Why is this non-final? Final is the default, and I don't see "open" here, so isn't it final?

Copy link
Member Author

Choose a reason for hiding this comment

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

Right now Binaryen's text format does not include any of the changes from WebAssembly/gc#413, so (type (struct ...)) is final, (type (sub (struct ...))) is open, and (type (sub final (struct ...))) is final. Yes, this is confusing, so we're going to fix it in that PR.

@@ -255,6 +255,7 @@ struct TypeSSA : public Pass {
builder[i] = oldType.getArray();
}
builder[i].subTypeOf(oldType);
builder[i].setOpen();
Copy link
Member

Choose a reason for hiding this comment

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

Why do the new types need to be open? I'd expect the opposite, since they are fresh types created here with no subtypes.

Copy link
Member Author

Choose a reason for hiding this comment

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

This was the easiest way to get the test for clashing rec groups to work out. It should be fine, since the optimal thing for us to be doing is to make all types open up front and then have another pass (not written yet) to close all the types we can at the end.

(type $sig (func_subtype (param i32) func))

;; As above, but now an import also uses this signature, which prevents us
;; from changing anything.
;; CHECK: (import "out" "func" (func $import (type $sig) (param i32)))
;; CHECK: (import "out" "func" (func $import (type $func.0) (param i32)))
Copy link
Member

Choose a reason for hiding this comment

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

Not specific to this PR, but this automatic type picking has always felt surprising and dangerous to me...

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh yikes, this appears to be a real bug. $func.0 does not exist.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed separately in #5927.

@tlively
Copy link
Member Author

tlively commented Sep 9, 2023

Going to land this before the separate bug fix instead of after because this is much more at risk of other merge conflicts.

@tlively tlively enabled auto-merge (squash) September 9, 2023 01:05
@tlively tlively merged commit 4e58466 into main Sep 9, 2023
14 checks passed
@tlively tlively deleted the default-final-types branch September 9, 2023 01:08
radekdoulik pushed a commit to dotnet/binaryen that referenced this pull request Jul 12, 2024
Match the spec and parse the shorthand binary and text formats as final and emit
final types without supertypes using the shorthands as well. This is a
potentially-breaking change, since the text and binary shorthands can no longer
be used to define types that have subtypes.

Also make TypeBuilder entries final by default to better match the spec and
update the internal APIs to use the "open" terminology rather than "final"
terminology. Future changes will update the text format to use the standard "sub
open" rather than the current "sub final" keywords. The exception is the new wat
parser, which supporst "sub open" as of this change, since it didn't support
final types at all previously.
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