-
Notifications
You must be signed in to change notification settings - Fork 779
[Outlining] Add Try/Catch/CatchAll #7472
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
Conversation
src/passes/Outlining.cpp
Outdated
// We preserve the name of the tryy because IRBuilder expects | ||
// visitTryStart() to be called on an empty Try, during the normal case of | ||
// parsing. | ||
auto name = curr->tryy->name; |
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.
// We preserve the name of the tryy because IRBuilder expects | |
// visitTryStart() to be called on an empty Try, during the normal case of | |
// parsing. | |
auto name = curr->tryy->name; | |
// We preserve the name of the tryy because IRBuilder expects | |
// visitTryStart() to be called on an empty Try, during the normal case of | |
// parsing. TODO: Fix this. | |
auto name = curr->tryy->name; |
src/wasm-ir-builder.h
Outdated
makeTry(Try* tryy, Name originalLabel, Type inputType, Index index) { | ||
return ScopeCtx(TryScope{tryy, originalLabel, index}, inputType); |
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.
It would never make sense to create a Try
scope with any index other than 0.
makeTry(Try* tryy, Name originalLabel, Type inputType, Index index) { | |
return ScopeCtx(TryScope{tryy, originalLabel, index}, inputType); | |
makeTry(Try* tryy, Name originalLabel, Type inputType) { | |
return ScopeCtx(TryScope{tryy, originalLabel, 0}, inputType); |
src/wasm-ir-builder.h
Outdated
static ScopeCtx makeCatch(ScopeCtx&& scope, Try* tryy, Index index) { | ||
scope.scope = CatchScope{tryy, scope.getOriginalLabel(), index}; |
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.
Let's remove the index
parameter here and do the increment automatically, since it never makes sense to create a Catch
(or CatchAll
) scope with any index other than one more than the previous index.
src/wasm/wasm-ir-builder.cpp
Outdated
// Indexes are managed manually to support Outlining. | ||
// Its prepopulated try catchBodies and catchTags vectors | ||
// cannot be appended to, as in the case of the empty try | ||
// used during parsing. | ||
if (tryy->catchBodies.size() < index) { | ||
tryy->catchBodies.resize(tryy->catchBodies.size() + 1); | ||
} | ||
// The first time visitCatch is called: the body of the | ||
// try is set and catchBodies is not appended to, but the tag | ||
// for the following catch is appended. So, catchTags uses | ||
// index as-is, but catchBodies uses index-1. | ||
tryy->catchBodies[index - 1] = *expr; |
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.
Let's put this all in a helper function since it's repeated three times.
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.
LGTM!
Supports try/catch/catchAll in the stringify of the module. Its contents can now be outlined.