diff --git a/src/ir/branch-utils.h b/src/ir/branch-utils.h index 8a4f02a580b..826483b0949 100644 --- a/src/ir/branch-utils.h +++ b/src/ir/branch-utils.h @@ -136,7 +136,7 @@ inline bool replacePossibleTarget(Expression* branch, Name from, Name to) { } // Replace all delegate targets within the given AST. -inline void replaceDelegateTargets(Expression* ast, Name from, Name to) { +inline void replaceExceptionTargets(Expression* ast, Name from, Name to) { struct Replacer : public PostWalker> { Name from, to; diff --git a/src/wasm-binary.h b/src/wasm-binary.h index c2a771a7d30..811524d2d28 100644 --- a/src/wasm-binary.h +++ b/src/wasm-binary.h @@ -1419,7 +1419,7 @@ class WasmBinaryBuilder { // or not. std::unordered_set breakTargetNames; // the names that delegates target. - std::unordered_set delegateTargetNames; + std::unordered_set exceptionTargetNames; std::vector expressionStack; @@ -1524,7 +1524,7 @@ class WasmBinaryBuilder { Expression* getBlockOrSingleton(Type type); BreakTarget getBreakTarget(int32_t offset); - Name getDelegateTargetName(int32_t offset); + Name getExceptionTargetName(int32_t offset); void readMemoryAccess(Address& alignment, Address& offset); diff --git a/src/wasm-s-parser.h b/src/wasm-s-parser.h index 92bc55d0add..bb436bbc4c7 100644 --- a/src/wasm-s-parser.h +++ b/src/wasm-s-parser.h @@ -242,7 +242,7 @@ class SExpressionWasmBuilder { i++; } } - enum class LabelType { Break, Delegate }; + enum class LabelType { Break, Exception }; Name getLabel(Element& s, LabelType labelType = LabelType::Break); Expression* makeBreak(Element& s); Expression* makeBreakTable(Element& s); diff --git a/src/wasm.h b/src/wasm.h index 876a9bfa70b..c2df1616ecd 100644 --- a/src/wasm.h +++ b/src/wasm.h @@ -1945,4 +1945,4 @@ std::ostream& operator<<(std::ostream& o, wasm::StackIR& ir); } // namespace std -#endif // wasm_wasm_h \ No newline at end of file +#endif // wasm_wasm_h diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp index 878293caaff..c6ed1dcfbcf 100644 --- a/src/wasm/wasm-binary.cpp +++ b/src/wasm/wasm-binary.cpp @@ -1920,7 +1920,7 @@ void WasmBinaryBuilder::readFunctions() { // process body assert(breakStack.empty()); assert(breakTargetNames.empty()); - assert(delegateTargetNames.empty()); + assert(exceptionTargetNames.empty()); assert(breakStack.empty()); assert(expressionStack.empty()); assert(controlFlowStack.empty()); @@ -1930,7 +1930,7 @@ void WasmBinaryBuilder::readFunctions() { assert(depth == 0); assert(breakStack.empty()); assert(breakTargetNames.empty()); - assert(delegateTargetNames.empty()); + assert(exceptionTargetNames.empty()); if (!expressionStack.empty()) { throwError("stack not empty on function exit"); } @@ -3389,7 +3389,7 @@ Expression* WasmBinaryBuilder::getBlockOrSingleton(Type type) { block->finalize(type); // maybe we don't need a block here? if (breakTargetNames.find(block->name) == breakTargetNames.end() && - delegateTargetNames.find(block->name) == delegateTargetNames.end()) { + exceptionTargetNames.find(block->name) == exceptionTargetNames.end()) { block->name = Name(); if (block->list.size() == 1) { return block->list[0]; @@ -3465,8 +3465,8 @@ WasmBinaryBuilder::getBreakTarget(int32_t offset) { return ret; } -Name WasmBinaryBuilder::getDelegateTargetName(int32_t offset) { - BYN_TRACE("getDelegateTarget " << offset << std::endl); +Name WasmBinaryBuilder::getExceptionTargetName(int32_t offset) { + BYN_TRACE("getExceptionTarget " << offset << std::endl); // We always start parsing a function by creating a block label and pushing it // in breakStack in getBlockOrSingleton, so if a 'delegate''s target is that // block, it does not mean it targets that block; it throws to the caller. @@ -3482,7 +3482,7 @@ Name WasmBinaryBuilder::getDelegateTargetName(int32_t offset) { // if the delegate is in literally unreachable code, then we will not emit it // anyhow, so do not note that the target has delegate to it if (!willBeIgnored) { - delegateTargetNames.insert(ret.name); + exceptionTargetNames.insert(ret.name); } return ret.name; } @@ -5832,7 +5832,7 @@ void WasmBinaryBuilder::visitTryOrTryInBlock(Expression*& out) { breakStack.pop_back(); if (lastSeparator == BinaryConsts::Delegate) { - curr->delegateTarget = getDelegateTargetName(getU32LEB()); + curr->delegateTarget = getExceptionTargetName(getU32LEB()); } // For simplicity, we make try's labels only can be targeted by delegates, and @@ -5843,9 +5843,10 @@ void WasmBinaryBuilder::visitTryOrTryInBlock(Expression*& out) { curr->name = getNextLabel(); if (auto* block = curr->body->dynCast()) { if (block->name.is()) { - if (delegateTargetNames.find(block->name) != delegateTargetNames.end()) { - BranchUtils::replaceDelegateTargets(block, block->name, curr->name); - delegateTargetNames.erase(block->name); + if (exceptionTargetNames.find(block->name) != + exceptionTargetNames.end()) { + BranchUtils::replaceExceptionTargets(block, block->name, curr->name); + exceptionTargetNames.erase(block->name); } // maybe we don't need a block here? if (block->list.size() == 1) { @@ -5853,11 +5854,11 @@ void WasmBinaryBuilder::visitTryOrTryInBlock(Expression*& out) { } } } - if (delegateTargetNames.find(catchLabel) != delegateTargetNames.end()) { + if (exceptionTargetNames.find(catchLabel) != exceptionTargetNames.end()) { for (auto* catchBody : curr->catchBodies) { - BranchUtils::replaceDelegateTargets(catchBody, catchLabel, curr->name); + BranchUtils::replaceExceptionTargets(catchBody, catchLabel, curr->name); } - delegateTargetNames.erase(catchLabel); + exceptionTargetNames.erase(catchLabel); } curr->finalize(curr->type); diff --git a/src/wasm/wasm-s-parser.cpp b/src/wasm/wasm-s-parser.cpp index d2b24fbedef..0ff4bfb9f17 100644 --- a/src/wasm/wasm-s-parser.cpp +++ b/src/wasm/wasm-s-parser.cpp @@ -2048,7 +2048,7 @@ Expression* SExpressionWasmBuilder::makeTry(Element& s) { if (inner.size() != 2) { throw ParseException("invalid delegate", inner.line, inner.col); } - ret->delegateTarget = getLabel(*inner[1], LabelType::Delegate); + ret->delegateTarget = getLabel(*inner[1], LabelType::Exception); } if (i != s.size()) { diff --git a/src/wasm/wasm-validator.cpp b/src/wasm/wasm-validator.cpp index beb994390f1..736d669fbf5 100644 --- a/src/wasm/wasm-validator.cpp +++ b/src/wasm/wasm-validator.cpp @@ -236,7 +236,7 @@ struct FunctionValidator : public WalkerPass> { }; std::unordered_map breakInfos; - std::unordered_set delegateTargetNames; + std::unordered_set exceptionTargetNames; std::set returnTypes; // types used in returns @@ -280,7 +280,7 @@ struct FunctionValidator : public WalkerPass> { static void visitPreTry(FunctionValidator* self, Expression** currp) { auto* curr = (*currp)->cast(); if (curr->name.is()) { - self->delegateTargetNames.insert(curr->name); + self->exceptionTargetNames.insert(curr->name); } } @@ -300,7 +300,7 @@ struct FunctionValidator : public WalkerPass> { static void visitPreCatch(FunctionValidator* self, Expression** currp) { auto* curr = (*currp)->cast(); if (curr->name.is()) { - self->delegateTargetNames.erase(curr->name); + self->exceptionTargetNames.erase(curr->name); } } @@ -376,7 +376,7 @@ struct FunctionValidator : public WalkerPass> { void visitRefIs(RefIs* curr); void visitRefFunc(RefFunc* curr); void visitRefEq(RefEq* curr); - void noteDelegate(Name name, Expression* curr); + void noteException(Name name, Expression* curr); void visitTry(Try* curr); void visitThrow(Throw* curr); void visitRethrow(Rethrow* curr); @@ -2073,9 +2073,9 @@ void FunctionValidator::visitRefEq(RefEq* curr) { "ref.eq's right argument should be a subtype of eqref"); } -void FunctionValidator::noteDelegate(Name name, Expression* curr) { +void FunctionValidator::noteException(Name name, Expression* curr) { if (name != DELEGATE_CALLER_TARGET) { - shouldBeTrue(delegateTargetNames.find(name) != delegateTargetNames.end(), + shouldBeTrue(exceptionTargetNames.find(name) != exceptionTargetNames.end(), curr, "all delegate targets must be valid"); } @@ -2122,7 +2122,7 @@ void FunctionValidator::visitTry(Try* curr) { "try should have either catches or a delegate"); if (curr->isDelegate()) { - noteDelegate(curr->delegateTarget, curr); + noteException(curr->delegateTarget, curr); } } @@ -2533,7 +2533,7 @@ void FunctionValidator::visitFunction(Function* curr) { shouldBeTrue( breakInfos.empty(), curr->body, "all named break targets must exist"); - shouldBeTrue(delegateTargetNames.empty(), + shouldBeTrue(exceptionTargetNames.empty(), curr->body, "all named delegate targets must exist"); returnTypes.clear();