-
Notifications
You must be signed in to change notification settings - Fork 745
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
Unify method pairs with and without Type param #6184
Conversation
As suggested in WebAssembly#6181 (comment), using `std::optional<Type>`, this unifies two different versions of `make***`, for block-like structures (`block`, `if`, `loop`, `try`, and `try_table`) with and without a type parameter. This also allows unifying of `finalize` methods, with and without a type. This also sets `breakability` argument of `Block::finalize` to `Unknown` so we can only have one `Block::finalize` that handles all cases. This also adds an optional `std::optional<Type> type` parameter to `blockify`, `blockifyWithName`, and `makeSequence` functions in `wasm-builder.h`.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! I had only thought to do this in wasm-builder so very good idea to also do it in wasm.h as well.
lgtm with early returns + also please do a quick check to see this does not regress speed.
type = *type_; | ||
if (type == Type::none && list.size() > 0) { | ||
handleUnreachable(this, breakability); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe early-return after this to avoid indenting all the rest in an else?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Also did the same for If::finalize
. (Others (Loop
, Try
, and TryTable
) were kinda small and didn't seem worth it)
src/wasm-builder.h
Outdated
Block* blockify(Expression* any, | ||
Expression* append = nullptr, | ||
std::optional<Type> type = std::nullopt) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh neat, does this mean we can pass a type to the variadic version of blockify
below now, too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought so, but it doesn't seem to work... It continues to blockify(any, append)
and errors out as soon as the append
is not Expression*
, like this:
/usr/local/google/home/aheejin/binaryen/src/wasm-builder.h:1307:12: error: no matc
hing member function for call to 'blockify'
1307 | return blockify(blockify(any, append), args...);
| ^~~~~~~~
/usr/local/google/home/aheejin/binaryen/src/passes/StackCheck.cpp:112:25: note: in
instantiation of function template specialization 'wasm::Builder::blockify<wasm::
Type>' requested here
112 | auto *ret = builder.blockify(check, newSet, Type(Type::i32));
| ^
/usr/local/google/home/aheejin/binaryen/src/wasm-builder.h:1288:10: note: candidat
e function not viable: no known conversion from 'wasm::Type' to 'Expression *' for
2nd argument
1288 | Block* blockify(Expression* any,
| ^
1289 | Expression* append = nullptr,
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/google/home/aheejin/binaryen/src/wasm-builder.h:1306:10: note: candidat
e function template not viable: no known conversion from 'wasm::Type' to 'Expressi
on *' for 2nd argument
1306 | Block* blockify(Expression* any, Expression* append, Ts... args) {
| ^ ~~~~~~~~~~~~~~~~~~
1 error generated.
I guess I should revert the blockify
part. blockifyWithName
should be fine given that it doesn't use a variadic parameter though.
src/wasm/wasm.cpp
Outdated
// Calculate the supertype of the branch types and the flowed-out type. If | ||
// there is no supertype among the available types, assume the current | ||
// type is already correct. TODO: calculate proper LUBs to compute a new | ||
// correct type in this situation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment looks extremely stale since we do calculate LUBs now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
src/wasm/wasm.cpp
Outdated
// If none of the component bodies' type is a supertype of the others, | ||
// assume the current type is already correct. TODO: Calculate a proper LUB. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also stale.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
I ran |
As suggested in WebAssembly#6181 (comment), using `std::optional<Type>`, this unifies two different versions of `make***`, for block-like structures (`block`, `if`, `loop`, `try`, and `try_table`) with and without a type parameter. This also allows unifying of `finalize` methods, with and without a type. This also sets `breakability` argument of `Block::finalize` to `Unknown` so we can only have one `Block::finalize` that handles all cases. This also adds an optional `std::optional<Type> type` parameter to `blockifyWithName`, and `makeSequence` functions in `wasm-builder.h`. blockify was not included because it has a variadic parameter.
As suggested in
#6181 (comment), using
std::optional<Type>
, this unifies two different versions ofmake***
, for block-like structures (block
,if
,loop
,try
, andtry_table
) with and without a type parameter.This also allows unifying of
finalize
methods, with and without a type. This also setsbreakability
argument ofBlock::finalize
toUnknown
so we can only have oneBlock::finalize
that handles all cases.This also adds an optional
std::optional<Type> type
parameter toblockifyWithName
, andmakeSequence
functions inwasm-builder.h
.blockify
was not included because it has a variadic parameter.