From 079a66e166d2276ba27aecb5f84736cb40d3f88c Mon Sep 17 00:00:00 2001 From: ctw-ian Date: Tue, 3 Jan 2023 17:34:08 +0800 Subject: [PATCH] fixed d144919 from https://gitee.com/ctw-ian/ark_ts2abc/pulls/783 Bugfix for taskpool Issue:I68KKD Signed-off-by: ctw-ian Change-Id: Iefac830f77069934640d440b2acdb164b4937050 --- es2panda/binder/binder.cpp | 2 +- es2panda/binder/scope.cpp | 2 +- es2panda/compiler/core/function.cpp | 2 +- es2panda/compiler/core/pandagen.cpp | 12 ++++++------ ...using-mutable-lexical-variable-1-expected.txt | 2 +- ...using-mutable-lexical-variable-2-expected.txt | 2 +- ...using-mutable-lexical-variable-3-expected.txt | 2 +- es2panda/util/concurrent.cpp | 16 ++++++++-------- es2panda/util/concurrent.h | 4 ++-- 9 files changed, 22 insertions(+), 22 deletions(-) diff --git a/es2panda/binder/binder.cpp b/es2panda/binder/binder.cpp index 06e2f1ff8c..474a24b0e0 100644 --- a/es2panda/binder/binder.cpp +++ b/es2panda/binder/binder.cpp @@ -217,7 +217,7 @@ void Binder::LookupIdentReference(ir::Identifier *ident) if (res.level != 0) { ASSERT(res.variable); - util::Concurrent::CheckUsingMutableLexicalVar(Program()->GetLineIndex(), ident, res); + util::Concurrent::VerifyConstLexicalVarForConcurrentFunction(Program()->GetLineIndex(), ident, res); res.variable->SetLexical(res.scope, program_->HotfixHelper()); } diff --git a/es2panda/binder/scope.cpp b/es2panda/binder/scope.cpp index b6a4162fdd..9ee64ef688 100644 --- a/es2panda/binder/scope.cpp +++ b/es2panda/binder/scope.cpp @@ -21,12 +21,12 @@ #include #include #include +#include #include #include #include #include #include -#include #include #include #include diff --git a/es2panda/compiler/core/function.cpp b/es2panda/compiler/core/function.cpp index 44274f48bf..a149872d70 100644 --- a/es2panda/compiler/core/function.cpp +++ b/es2panda/compiler/core/function.cpp @@ -27,8 +27,8 @@ #include #include #include -#include #include +#include namespace panda::es2panda::compiler { diff --git a/es2panda/compiler/core/pandagen.cpp b/es2panda/compiler/core/pandagen.cpp index 9ab19aecbf..26faa98df3 100644 --- a/es2panda/compiler/core/pandagen.cpp +++ b/es2panda/compiler/core/pandagen.cpp @@ -51,17 +51,17 @@ namespace panda::es2panda::compiler { void PandaGen::SetFunctionKind() { - // make sure concurrent info will not be overwritten - if (funcKind_ == panda::panda_file::FunctionKind::CONCURRENT_FUNCTION) { - return; - } - if (rootNode_->IsProgram()) { funcKind_ = panda::panda_file::FunctionKind::FUNCTION; return; } auto *func = rootNode_->AsScriptFunction(); + if (func->IsConcurrent()) { + funcKind_ = panda::panda_file::FunctionKind::CONCURRENT_FUNCTION; + return; + } + if (func->IsMethod()) { return; } @@ -1814,7 +1814,7 @@ void PandaGen::StoreLexicalVar(const ir::AstNode *node, uint32_t level, uint32_t void PandaGen::StoreLexicalEnv(const ir::AstNode *node) { - ra_.Emit(node); // modify later + ra_.Emit(node); } void PandaGen::ThrowIfSuperNotCorrectCall(const ir::AstNode *node, int64_t num) diff --git a/es2panda/test/parser/concurrent/using-mutable-lexical-variable-1-expected.txt b/es2panda/test/parser/concurrent/using-mutable-lexical-variable-1-expected.txt index 9f8e518431..df76adeac5 100644 --- a/es2panda/test/parser/concurrent/using-mutable-lexical-variable-1-expected.txt +++ b/es2panda/test/parser/concurrent/using-mutable-lexical-variable-1-expected.txt @@ -1,2 +1,2 @@ -Error: Concurrent function should only use const lexical variable [using-mutable-lexical-variable-1.js:20:11] +Error: Concurrent function should only use import variable or local variable [using-mutable-lexical-variable-1.js:20:11] the size of programs is expected to be 1, but is 0 diff --git a/es2panda/test/parser/concurrent/using-mutable-lexical-variable-2-expected.txt b/es2panda/test/parser/concurrent/using-mutable-lexical-variable-2-expected.txt index 3b3081439e..741aa11197 100644 --- a/es2panda/test/parser/concurrent/using-mutable-lexical-variable-2-expected.txt +++ b/es2panda/test/parser/concurrent/using-mutable-lexical-variable-2-expected.txt @@ -1,2 +1,2 @@ -Error: Concurrent function should only use const lexical variable [using-mutable-lexical-variable-2.js:20:11] +Error: Concurrent function should only use import variable or local variable [using-mutable-lexical-variable-2.js:20:11] the size of programs is expected to be 1, but is 0 diff --git a/es2panda/test/parser/concurrent/using-mutable-lexical-variable-3-expected.txt b/es2panda/test/parser/concurrent/using-mutable-lexical-variable-3-expected.txt index f3b0341406..015a6b4ab9 100644 --- a/es2panda/test/parser/concurrent/using-mutable-lexical-variable-3-expected.txt +++ b/es2panda/test/parser/concurrent/using-mutable-lexical-variable-3-expected.txt @@ -1,2 +1,2 @@ -Error: Concurrent function should only use const lexical variable [using-mutable-lexical-variable-3.js:20:11] +Error: Concurrent function should only use import variable or local variable [using-mutable-lexical-variable-3.js:20:11] the size of programs is expected to be 1, but is 0 diff --git a/es2panda/util/concurrent.cpp b/es2panda/util/concurrent.cpp index 34e9d2d19f..2eb77e9f3c 100644 --- a/es2panda/util/concurrent.cpp +++ b/es2panda/util/concurrent.cpp @@ -18,9 +18,9 @@ #include #include #include -#include #include #include +#include #include #include #include @@ -69,12 +69,12 @@ void Concurrent::SetConcurrent(ir::ScriptFunction *func, const lexer::LineIndex // concurrent function should only be function declaration if (!func->CanBeConcurrent()) { - ThrowIncorrectUsing(lineIndex, stmt, ConcurrentInvalidFlag::NOT_ORDINARY_FUNCTION); + ThrowInvalidConcurrentFunction(lineIndex, stmt, ConcurrentInvalidFlag::NOT_ORDINARY_FUNCTION); } // concurrent function should be defined in top-level scope if (!func->Parent()->Parent()->IsProgram()) { - ThrowIncorrectUsing(lineIndex, stmt, ConcurrentInvalidFlag::NOT_TOP_LEVEL); + ThrowInvalidConcurrentFunction(lineIndex, stmt, ConcurrentInvalidFlag::NOT_TOP_LEVEL); } func->AddFlag(ir::ScriptFunctionFlags::CONCURRENT); @@ -89,7 +89,7 @@ void Concurrent::SetConcurrent(ir::ScriptFunction *func, const lexer::LineIndex } } -void Concurrent::ThrowIncorrectUsing(const lexer::LineIndex &lineIndex, const ir::AstNode *expr, +void Concurrent::ThrowInvalidConcurrentFunction(const lexer::LineIndex &lineIndex, const ir::AstNode *expr, ConcurrentInvalidFlag errFlag) { auto line = expr->Range().start.line; @@ -106,8 +106,8 @@ void Concurrent::ThrowIncorrectUsing(const lexer::LineIndex &lineIndex, const ir break; } case ConcurrentInvalidFlag::USING_MUTABLE_VARIABLE: { - throw Error {ErrorType::GENERIC, "Concurrent function should only use const lexical variable", line, - column}; + throw Error {ErrorType::GENERIC, "Concurrent function should only use import variable or local variable", + line, column}; break; } default: @@ -127,7 +127,7 @@ void Concurrent::StoreEnvForConcurrent(compiler::PandaGen *pg, const ir::AstNode } } -void Concurrent::CheckUsingMutableLexicalVar(const lexer::LineIndex &lineIndex, const ir::AstNode *node, +void Concurrent::VerifyConstLexicalVarForConcurrentFunction(const lexer::LineIndex &lineIndex, const ir::AstNode *node, const binder::ScopeFindResult &result) { if (!result.crossConcurrent) { @@ -135,7 +135,7 @@ void Concurrent::CheckUsingMutableLexicalVar(const lexer::LineIndex &lineIndex, } if (!result.variable->Declaration()->IsConstDecl()) { - ThrowIncorrectUsing(lineIndex, node, ConcurrentInvalidFlag::USING_MUTABLE_VARIABLE); + ThrowInvalidConcurrentFunction(lineIndex, node, ConcurrentInvalidFlag::USING_MUTABLE_VARIABLE); } } diff --git a/es2panda/util/concurrent.h b/es2panda/util/concurrent.h index 18c84e219f..d7f4c70147 100644 --- a/es2panda/util/concurrent.h +++ b/es2panda/util/concurrent.h @@ -49,10 +49,10 @@ public: Concurrent() = delete; static void SetConcurrent(ir::ScriptFunction *func, const lexer::LineIndex &lineIndex); - static void ThrowIncorrectUsing(const lexer::LineIndex &lineIndex, const ir::AstNode *expr, + static void ThrowInvalidConcurrentFunction(const lexer::LineIndex &lineIndex, const ir::AstNode *expr, ConcurrentInvalidFlag errFlag); static void StoreEnvForConcurrent(compiler::PandaGen *pg, const ir::AstNode *node); - static void CheckUsingMutableLexicalVar(const lexer::LineIndex &lineIndex, const ir::AstNode *node, + static void VerifyConstLexicalVarForConcurrentFunction(const lexer::LineIndex &lineIndex, const ir::AstNode *node, const binder::ScopeFindResult &result); static constexpr std::string_view USE_CONCURRENT = "use concurrent"; -- Gitee