From 289192a01092a2d51c0d21ae995cb8602499ac7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=99=93=E7=86=8A=E7=8C=AB?= Date: Tue, 9 Jul 2024 11:41:28 +0800 Subject: [PATCH] Bytecode upgrade MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/IABRTZ Signed-off-by: 晓熊猫 Change-Id: Ie70413ba9f33692f384532fa5e13b6ff321d16e8 --- es2panda/aot/emitFiles.cpp | 10 +- es2panda/aot/emitFiles.h | 11 +- es2panda/aot/options.cpp | 7 +- es2panda/binder/binder.cpp | 3 +- es2panda/compiler/core/pandagen.cpp | 5 +- es2panda/es2panda.h | 1 + es2panda/parser/parserImpl.cpp | 1 + es2panda/parser/program/program.cpp | 2 + es2panda/parser/program/program.h | 11 ++ es2panda/parser/statementParser.cpp | 3 +- .../11/lazy-import-with-sendabe-expected.txt | 2 + .../11/lazy-import-with-sendabe.ts | 21 +++ .../lazy-import-without-sendabe-expected.txt | 2 + .../11/lazy-import-without-sendabe.ts | 20 +++ .../11/sendable-function-expected.txt | 160 ++++++++++++++++++ .../11/sendable-function.ts | 54 ++++++ .../0/lazy-import-with-sendabe-expected.txt | 26 +++ .../12/0/lazy-import-with-sendabe.ts | 21 +++ .../lazy-import-without-sendabe-expected.txt | 26 +++ .../12/0/lazy-import-without-sendabe.ts | 20 +++ .../12/0/sendable-function-expected.txt | 160 ++++++++++++++++++ .../12/0/sendable-function.ts | 54 ++++++ .../2/lazy-import-with-sendabe-expected.txt | 2 + .../12/2/lazy-import-with-sendabe.ts | 21 +++ .../lazy-import-without-sendabe-expected.txt | 2 + .../12/2/lazy-import-without-sendabe.ts | 20 +++ .../12/2/sendable-function-expected.txt | 160 ++++++++++++++++++ .../12/2/sendable-function.ts | 54 ++++++ .../3/lazy-import-with-sendabe-expected.txt | 26 +++ .../12/3/lazy-import-with-sendabe.ts | 21 +++ .../lazy-import-without-sendabe-expected.txt | 26 +++ .../12/3/lazy-import-without-sendabe.ts | 20 +++ .../12/3/sendable-function-expected.txt | 160 ++++++++++++++++++ .../12/3/sendable-function.ts | 54 ++++++ .../13/lazy-import-with-sendabe-expected.txt | 26 +++ .../13/lazy-import-with-sendabe.ts | 21 +++ .../lazy-import-without-sendabe-expected.txt | 26 +++ .../13/lazy-import-without-sendabe.ts | 20 +++ .../13/sendable-function-expected.txt | 160 ++++++++++++++++++ .../13/sendable-function.ts | 54 ++++++ es2panda/test/runner.py | 12 +- es2panda/util/helpers.cpp | 23 ++- es2panda/util/helpers.h | 11 +- 43 files changed, 1518 insertions(+), 21 deletions(-) create mode 100644 es2panda/test/parser/targetApiSubVersion/11/lazy-import-with-sendabe-expected.txt create mode 100644 es2panda/test/parser/targetApiSubVersion/11/lazy-import-with-sendabe.ts create mode 100644 es2panda/test/parser/targetApiSubVersion/11/lazy-import-without-sendabe-expected.txt create mode 100644 es2panda/test/parser/targetApiSubVersion/11/lazy-import-without-sendabe.ts create mode 100644 es2panda/test/parser/targetApiSubVersion/11/sendable-function-expected.txt create mode 100644 es2panda/test/parser/targetApiSubVersion/11/sendable-function.ts create mode 100644 es2panda/test/parser/targetApiSubVersion/12/0/lazy-import-with-sendabe-expected.txt create mode 100644 es2panda/test/parser/targetApiSubVersion/12/0/lazy-import-with-sendabe.ts create mode 100644 es2panda/test/parser/targetApiSubVersion/12/0/lazy-import-without-sendabe-expected.txt create mode 100644 es2panda/test/parser/targetApiSubVersion/12/0/lazy-import-without-sendabe.ts create mode 100644 es2panda/test/parser/targetApiSubVersion/12/0/sendable-function-expected.txt create mode 100644 es2panda/test/parser/targetApiSubVersion/12/0/sendable-function.ts create mode 100644 es2panda/test/parser/targetApiSubVersion/12/2/lazy-import-with-sendabe-expected.txt create mode 100644 es2panda/test/parser/targetApiSubVersion/12/2/lazy-import-with-sendabe.ts create mode 100644 es2panda/test/parser/targetApiSubVersion/12/2/lazy-import-without-sendabe-expected.txt create mode 100644 es2panda/test/parser/targetApiSubVersion/12/2/lazy-import-without-sendabe.ts create mode 100644 es2panda/test/parser/targetApiSubVersion/12/2/sendable-function-expected.txt create mode 100644 es2panda/test/parser/targetApiSubVersion/12/2/sendable-function.ts create mode 100644 es2panda/test/parser/targetApiSubVersion/12/3/lazy-import-with-sendabe-expected.txt create mode 100644 es2panda/test/parser/targetApiSubVersion/12/3/lazy-import-with-sendabe.ts create mode 100644 es2panda/test/parser/targetApiSubVersion/12/3/lazy-import-without-sendabe-expected.txt create mode 100644 es2panda/test/parser/targetApiSubVersion/12/3/lazy-import-without-sendabe.ts create mode 100644 es2panda/test/parser/targetApiSubVersion/12/3/sendable-function-expected.txt create mode 100644 es2panda/test/parser/targetApiSubVersion/12/3/sendable-function.ts create mode 100644 es2panda/test/parser/targetApiSubVersion/13/lazy-import-with-sendabe-expected.txt create mode 100644 es2panda/test/parser/targetApiSubVersion/13/lazy-import-with-sendabe.ts create mode 100644 es2panda/test/parser/targetApiSubVersion/13/lazy-import-without-sendabe-expected.txt create mode 100644 es2panda/test/parser/targetApiSubVersion/13/lazy-import-without-sendabe.ts create mode 100644 es2panda/test/parser/targetApiSubVersion/13/sendable-function-expected.txt create mode 100644 es2panda/test/parser/targetApiSubVersion/13/sendable-function.ts diff --git a/es2panda/aot/emitFiles.cpp b/es2panda/aot/emitFiles.cpp index f1f5a35979..eba738812a 100644 --- a/es2panda/aot/emitFiles.cpp +++ b/es2panda/aot/emitFiles.cpp @@ -45,11 +45,12 @@ void EmitFileQueue::Schedule() ASSERT(jobsCount_ == 0); std::unique_lock lock(m_); auto targetApi = options_->CompilerOptions().targetApiVersion; + auto targetApiSubVersion = options_->CompilerOptions().targetApiSubVersion; if (mergeAbc_) { // generate merged abc auto emitMergedAbcJob = new EmitMergedAbcJob(options_->CompilerOutput(), - options_->CompilerOptions().transformLib, progsInfo_, targetApi); + options_->CompilerOptions().transformLib, progsInfo_, targetApi, targetApiSubVersion); // Disable generating cached files when cross-program optimization is required, to prevent cached files from // not being invalidated when their dependencies are changed if (!options_->CompilerOptions().requireGlobalOptimization) { @@ -65,7 +66,7 @@ void EmitFileQueue::Schedule() auto outputFileName = options_->OutputFiles().empty() ? options_->CompilerOutput() : options_->OutputFiles().at(info.first); auto emitSingleAbcJob = new EmitSingleAbcJob(outputFileName, &(info.second->program), statp_, - targetApi); + targetApi, targetApiSubVersion); jobs_.push_back(emitSingleAbcJob); jobsCount_++; } catch (std::exception &error) { @@ -81,7 +82,7 @@ void EmitFileQueue::Schedule() void EmitSingleAbcJob::Run() { if (!panda::pandasm::AsmEmitter::Emit(panda::os::file::File::GetExtendedFilePath(outputFileName_), *prog_, statp_, - nullptr, true, nullptr, targetApiVersion_)) { + nullptr, true, nullptr, targetApiVersion_, targetApiSubVersion_)) { throw Error(ErrorType::GENERIC, "Failed to emit " + outputFileName_ + ", error: " + panda::pandasm::AsmEmitter::GetLastError()); } @@ -99,7 +100,8 @@ void EmitMergedAbcJob::Run() } bool success = panda::pandasm::AsmEmitter::EmitPrograms( - panda::os::file::File::GetExtendedFilePath(outputFileName_), progs, true, targetApiVersion_); + panda::os::file::File::GetExtendedFilePath(outputFileName_), + progs, true, targetApiVersion_, targetApiSubVersion_); for (auto *dependant : dependants_) { dependant->Signal(); diff --git a/es2panda/aot/emitFiles.h b/es2panda/aot/emitFiles.h index 9edef0c7e5..2e2063a1e9 100644 --- a/es2panda/aot/emitFiles.h +++ b/es2panda/aot/emitFiles.h @@ -25,8 +25,9 @@ namespace panda::es2panda::aot { class EmitSingleAbcJob : public util::WorkerJob { public: explicit EmitSingleAbcJob(const std::string &outputFileName, panda::pandasm::Program *prog, - std::map *statp, uint8_t targetApi) - : outputFileName_(outputFileName), prog_(prog), statp_(statp), targetApiVersion_(targetApi) {}; + std::map *statp, uint8_t targetApi, uint8_t targetApiSubVersion) + : outputFileName_(outputFileName), prog_(prog), statp_(statp), targetApiVersion_(targetApi), + targetApiSubVersion_(targetApiSubVersion) {}; NO_COPY_SEMANTIC(EmitSingleAbcJob); NO_MOVE_SEMANTIC(EmitSingleAbcJob); ~EmitSingleAbcJob() override = default; @@ -37,15 +38,16 @@ private: panda::pandasm::Program *prog_; std::map *statp_; uint8_t targetApiVersion_ = 0; + uint8_t targetApiSubVersion_; }; class EmitMergedAbcJob : public util::WorkerJob { public: explicit EmitMergedAbcJob(const std::string &outputFileName, const std::string &transformLib, const std::map &progsInfo, - uint8_t targetApi) + uint8_t targetApi, uint8_t targetApiSubVersion) : outputFileName_(outputFileName), transformLib_(transformLib), - progsInfo_(progsInfo), targetApiVersion_(targetApi) {}; + progsInfo_(progsInfo), targetApiVersion_(targetApi), targetApiSubVersion_(targetApiSubVersion) {}; NO_COPY_SEMANTIC(EmitMergedAbcJob); NO_MOVE_SEMANTIC(EmitMergedAbcJob); ~EmitMergedAbcJob() override = default; @@ -56,6 +58,7 @@ private: std::string transformLib_; const std::map &progsInfo_; uint8_t targetApiVersion_ = 0; + uint8_t targetApiSubVersion_; }; class EmitCacheJob : public util::WorkerJob { diff --git a/es2panda/aot/options.cpp b/es2panda/aot/options.cpp index 5d73f9bf05..4577c003a2 100644 --- a/es2panda/aot/options.cpp +++ b/es2panda/aot/options.cpp @@ -369,10 +369,13 @@ bool Options::Parse(int argc, const char **argv) "bc-min-version are enabled, only bc-version will take effects"); panda::PandArg bcMinVersion("bc-min-version", false, "Print ark bytecode minimum supported version"); panda::PandArg targetApiVersion("target-api-version", util::Helpers::DEFAULT_TARGET_API_VERSION, - "Specify the targeting api version for es2abc to generated the corresponding version of bytecode"); + "Specify the targeting api version for es2abc to generate the corresponding version of bytecode"); panda::PandArg targetBcVersion("target-bc-version", false, "Print the corresponding ark bytecode version"\ "for target api version. If both target-bc-version and bc-version are enabled, only target-bc-version"\ "will take effects"); + panda::PandArg targetApiSubVersion("target-api-sub-version", + util::Helpers::DEFAULT_TARGET_API_SUB_VERSION, + "Specify the targeting release type for es2abc to generate the corresponding version of bytecode"); // compile entries and pkg context info panda::PandArg compileContextInfoPath("compile-context-info", "", "The path to compile context"\ @@ -440,6 +443,7 @@ bool Options::Parse(int argc, const char **argv) argparser_->Add(&bcMinVersion); argparser_->Add(&targetApiVersion); argparser_->Add(&targetBcVersion); + argparser_->Add(&targetApiSubVersion); argparser_->Add(&compileContextInfoPath); argparser_->Add(&opDumpDepsInfo); @@ -454,6 +458,7 @@ bool Options::Parse(int argc, const char **argv) bool parseStatus = argparser_->Parse(argc, argv); + compilerOptions_.targetApiSubVersion = targetApiSubVersion.GetValue(); compilerOptions_.targetApiVersion = targetApiVersion.GetValue(); if (parseStatus && targetBcVersion.GetValue()) { compilerOptions_.targetBcVersion = targetBcVersion.GetValue(); diff --git a/es2panda/binder/binder.cpp b/es2panda/binder/binder.cpp index 85ed70ccdf..afdfe056ab 100644 --- a/es2panda/binder/binder.cpp +++ b/es2panda/binder/binder.cpp @@ -723,7 +723,8 @@ void Binder::ResolveReference(const ir::AstNode *parent, ir::AstNode *childNode) scriptFunc->SetInSendable(); } util::Helpers::ScanDirectives(const_cast(scriptFunc), - Program()->GetLineIndex()); + Program()->GetLineIndex(), Program()->TargetApiSubVersion(), + Program()->TargetApiVersion()); if (scriptFunc->IsConstructor() && util::Helpers::GetClassDefiniton(scriptFunc)->IsSendable()) { scriptFunc->SetInSendable(); diff --git a/es2panda/compiler/core/pandagen.cpp b/es2panda/compiler/core/pandagen.cpp index 6b92fffdc1..6ee71d0463 100644 --- a/es2panda/compiler/core/pandagen.cpp +++ b/es2panda/compiler/core/pandagen.cpp @@ -52,7 +52,6 @@ namespace panda::es2panda::compiler { void PandaGen::SetFunctionKind() { - int targetApiVersion = Binder()->Program()->TargetApiVersion(); if (rootNode_->IsProgram()) { funcKind_ = panda::panda_file::FunctionKind::FUNCTION; return; @@ -84,7 +83,7 @@ void PandaGen::SetFunctionKind() funcKind_ = panda::panda_file::FunctionKind::ASYNC_FUNCTION; - if (func->IsSendable() && targetApiVersion >= util::Helpers::SENDABLE_FUNCTION_MIN_SUPPORTED_API_VERSION) { + if (func->IsSendable()) { funcKind_ |= panda::panda_file::FunctionKind::SENDABLE_FUNCTION; } return; @@ -102,7 +101,7 @@ void PandaGen::SetFunctionKind() funcKind_ = panda::panda_file::FunctionKind::FUNCTION; - if (func->IsSendable() && targetApiVersion >= util::Helpers::SENDABLE_FUNCTION_MIN_SUPPORTED_API_VERSION) { + if (func->IsSendable()) { funcKind_ |= panda::panda_file::FunctionKind::SENDABLE_FUNCTION; } } diff --git a/es2panda/es2panda.h b/es2panda/es2panda.h index 54a988dc96..9c13645f51 100644 --- a/es2panda/es2panda.h +++ b/es2panda/es2panda.h @@ -109,6 +109,7 @@ struct CompilerOptions { bool bcMinVersion {false}; int targetApiVersion {0}; bool targetBcVersion {false}; + int32_t targetApiSubVersion {0}; std::unordered_map cacheFiles; std::string transformLib {}; bool branchElimination {false}; diff --git a/es2panda/parser/parserImpl.cpp b/es2panda/parser/parserImpl.cpp index 4208cabbdd..cc249ffe63 100644 --- a/es2panda/parser/parserImpl.cpp +++ b/es2panda/parser/parserImpl.cpp @@ -134,6 +134,7 @@ Program ParserImpl::Parse(const SourceFile &sourceFile, const CompilerOptions &o program_.SetRecordName(sourceFile.recordName); program_.SetDebug(options.isDebug); program_.SetTargetApiVersion(options.targetApiVersion); + program_.SetTargetApiSubVersion(options.targetApiSubVersion); program_.SetShared(sourceFile.isSharedModule); if (Extension() == ScriptExtension::TS) { program_.SetDefineSemantic(options.useDefineSemantic); diff --git a/es2panda/parser/program/program.cpp b/es2panda/parser/program/program.cpp index c29f70469e..b796e6b06c 100644 --- a/es2panda/parser/program/program.cpp +++ b/es2panda/parser/program/program.cpp @@ -47,6 +47,7 @@ Program::Program(Program &&other) hasTLA_(other.hasTLA_), isDebug_(other.isDebug_), targetApiVersion_(other.targetApiVersion_), + targetApiSubVersion_(other.targetApiSubVersion_), useDefineSemantic_(other.useDefineSemantic_), isShared_(other.isShared_) { @@ -68,6 +69,7 @@ Program &Program::operator=(Program &&other) hasTLA_ = other.hasTLA_; isDebug_ = other.isDebug_; targetApiVersion_ = other.targetApiVersion_; + targetApiSubVersion_ = other.targetApiSubVersion_; useDefineSemantic_ = other.useDefineSemantic_; isShared_ = other.isShared_; diff --git a/es2panda/parser/program/program.h b/es2panda/parser/program/program.h index a194fc8df2..16b5b5f29b 100644 --- a/es2panda/parser/program/program.h +++ b/es2panda/parser/program/program.h @@ -185,6 +185,16 @@ public: targetApiVersion_ = targetApiVersion; } + int TargetApiSubVersion() const + { + return targetApiSubVersion_; + } + + void SetTargetApiSubVersion(const int targetApiSubVersion) + { + targetApiSubVersion_ = targetApiSubVersion; + } + bool UseDefineSemantic() const { return useDefineSemantic_; @@ -225,6 +235,7 @@ private: bool hasTLA_ {false}; bool isDebug_ {false}; int targetApiVersion_ {0}; + int targetApiSubVersion_ {0}; bool useDefineSemantic_ {true}; bool isShared_ {false}; }; diff --git a/es2panda/parser/statementParser.cpp b/es2panda/parser/statementParser.cpp index e6bd41e14e..2b08345627 100644 --- a/es2panda/parser/statementParser.cpp +++ b/es2panda/parser/statementParser.cpp @@ -3104,7 +3104,8 @@ ir::Statement *ParserImpl::ParseImportDeclaration(StatementParsingFlags flags) lexer_->NextToken(); // eat import bool isLazy = false; - if (program_.TargetApiVersion() >= util::Helpers::LAZY_IMPORT_MIN_SUPPORTED_API_VERSION && + if (util::Helpers::IsSupportedApiAndReleaseType(program_.TargetApiVersion(), program_.TargetApiSubVersion(), + util::Helpers::LAZY_IMPORT_MIN_SUPPORTED_API_VERSION, util::Helpers::LAZY_IMPORT_API_SUB_VERSION) && lexer_->GetToken().KeywordType() == lexer::TokenType::KEYW_LAZY) { const auto savedPos = lexer_->Save(); lexer_->NextToken(); // eat lazy diff --git a/es2panda/test/parser/targetApiSubVersion/11/lazy-import-with-sendabe-expected.txt b/es2panda/test/parser/targetApiSubVersion/11/lazy-import-with-sendabe-expected.txt new file mode 100644 index 0000000000..360e4e56a4 --- /dev/null +++ b/es2panda/test/parser/targetApiSubVersion/11/lazy-import-with-sendabe-expected.txt @@ -0,0 +1,2 @@ +SyntaxError: Unexpected token. [lazy-import-with-sendabe.ts:16:13] +The size of programs is expected to be 1, but is 0 diff --git a/es2panda/test/parser/targetApiSubVersion/11/lazy-import-with-sendabe.ts b/es2panda/test/parser/targetApiSubVersion/11/lazy-import-with-sendabe.ts new file mode 100644 index 0000000000..c3df751a27 --- /dev/null +++ b/es2panda/test/parser/targetApiSubVersion/11/lazy-import-with-sendabe.ts @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import lazy { aaa } from './aaa' +function foo() { + "use sendable"; + aaa(); +} +foo(); \ No newline at end of file diff --git a/es2panda/test/parser/targetApiSubVersion/11/lazy-import-without-sendabe-expected.txt b/es2panda/test/parser/targetApiSubVersion/11/lazy-import-without-sendabe-expected.txt new file mode 100644 index 0000000000..ba60141550 --- /dev/null +++ b/es2panda/test/parser/targetApiSubVersion/11/lazy-import-without-sendabe-expected.txt @@ -0,0 +1,2 @@ +SyntaxError: Unexpected token. [lazy-import-without-sendabe.ts:16:13] +The size of programs is expected to be 1, but is 0 diff --git a/es2panda/test/parser/targetApiSubVersion/11/lazy-import-without-sendabe.ts b/es2panda/test/parser/targetApiSubVersion/11/lazy-import-without-sendabe.ts new file mode 100644 index 0000000000..2bac37427a --- /dev/null +++ b/es2panda/test/parser/targetApiSubVersion/11/lazy-import-without-sendabe.ts @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import lazy { aaa } from './aaa' +function foo() { + aaa(); +} +foo(); \ No newline at end of file diff --git a/es2panda/test/parser/targetApiSubVersion/11/sendable-function-expected.txt b/es2panda/test/parser/targetApiSubVersion/11/sendable-function-expected.txt new file mode 100644 index 0000000000..1fb195f2bb --- /dev/null +++ b/es2panda/test/parser/targetApiSubVersion/11/sendable-function-expected.txt @@ -0,0 +1,160 @@ +.language ECMAScript + +.function any .#15069766313219882989#insendable1(any a0, any a1, any a2) { +label_1: +label_0: + ldexternalmodulevar 0x0 + sta v0 + throw.undefinedifholewithname aaa + lda v0 + callarg0 0x0 + ldundefined + returnundefined +label_2: +} + +.function any .#15069766313219882989_1#insendable1(any a0, any a1, any a2) { +label_1: +label_0: + ldexternalmodulevar 0x0 + sta v0 + throw.undefinedifholewithname aaa + lda v0 + callarg0 0x0 + ldundefined + returnundefined +label_2: +} + +.function any .A(any a0, any a1, any a2) { +label_1: +label_0: + ldlexvar 0x0, 0x0 + stobjbyname 0x0, cb, a2 + lda a2 + return +label_2: +} + +.function any .foo(any a0, any a1, any a2) { +label_1: +label_0: + definefunc 0x0, .insendable2, 0x0 + definefunc 0x1, .insendable1, 0x0 + ldexternalmodulevar 0x0 + sta v0 + throw.undefinedifholewithname aaa + lda v0 + callarg0 0x2 + ldundefined + returnundefined +label_2: +} + +.function any .foo2(any a0, any a1, any a2) { +label_1: +label_0: + definefunc 0x0, .#15069766313219882989#insendable1, 0x0 + ldexternalmodulevar 0x0 + sta v0 + throw.undefinedifholewithname aaa + lda v0 + callarg0 0x1 + ldundefined + returnundefined +label_2: +} + +.function any .foo3(any a0, any a1, any a2) { +label_1: +label_0: + definefunc 0x0, .#15069766313219882989_1#insendable1, 0x0 + ldexternalmodulevar 0x0 + sta v0 + throw.undefinedifholewithname aaa + lda v0 + callarg0 0x1 + ldundefined + returnundefined +label_2: +} + +.function any .fooA(any a0, any a1, any a2) { +label_1: +label_0: + definefunc 0x0, .t, 0x0 + ldundefined + returnundefined +label_2: +} + +.function any .func_main_0(any a0, any a1, any a2) { +label_1: +label_0: + newlexenv 0x1 + definefunc 0x0, .foo3, 0x0 + definefunc 0x1, .foo2, 0x0 + definefunc 0x2, .foo, 0x0 + stlexvar 0x0, 0x0 + ldhole + sta v0 + callruntime.definesendableclass 0x3, .A, _2, 0x0, v0 + ldundefined + returnundefined +label_2: +} + +.function any .insendable1(any a0, any a1, any a2) { +label_1: +label_0: + definefunc 0x0, .insendable11, 0x0 + ldexternalmodulevar 0x0 + sta v0 + throw.undefinedifholewithname aaa + lda v0 + callarg0 0x1 + ldundefined + returnundefined +label_2: +} + +.function any .insendable11(any a0, any a1, any a2) { +label_1: +label_0: + ldexternalmodulevar 0x0 + sta v0 + throw.undefinedifholewithname aaa + lda v0 + callarg0 0x0 + ldundefined + returnundefined +label_2: +} + +.function any .insendable2(any a0, any a1, any a2) { +label_1: +label_0: + ldexternalmodulevar 0x0 + sta v0 + throw.undefinedifholewithname aaa + lda v0 + callarg0 0x0 + ldundefined + returnundefined +label_2: +} + +.function any .t(any a0, any a1, any a2) { +label_1: +label_0: + ldexternalmodulevar 0x0 + sta v0 + throw.undefinedifholewithname aaa + lda v0 + callarg0 0x0 + ldundefined + returnundefined +label_2: +} + + diff --git a/es2panda/test/parser/targetApiSubVersion/11/sendable-function.ts b/es2panda/test/parser/targetApiSubVersion/11/sendable-function.ts new file mode 100644 index 0000000000..70d55b5701 --- /dev/null +++ b/es2panda/test/parser/targetApiSubVersion/11/sendable-function.ts @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { aaa } from './aaa' +function foo() { + "use sendable"; + aaa(); + function insendable1() { + aaa(); + function insendable11() { + aaa(); + } + } + function insendable2() { + aaa(); + } +} +function foo2() { + aaa(); + function insendable1() { + aaa(); + } +} +type SendableFunction = () => void; +class A { + constructor () { + "use sendable"; + } + cb: SendableFunction = foo; + fooA() { + function t() { + aaa(); + } + } +} +function foo3() { + aaa(); + function insendable1() { + aaa(); + } +} + diff --git a/es2panda/test/parser/targetApiSubVersion/12/0/lazy-import-with-sendabe-expected.txt b/es2panda/test/parser/targetApiSubVersion/12/0/lazy-import-with-sendabe-expected.txt new file mode 100644 index 0000000000..e790a958b1 --- /dev/null +++ b/es2panda/test/parser/targetApiSubVersion/12/0/lazy-import-with-sendabe-expected.txt @@ -0,0 +1,26 @@ +.language ECMAScript + +.function any .#*#foo(any a0, any a1, any a2) { +label_1: +label_0: + callruntime.ldlazysendablemodulevar 0x0 + sta v0 + throw.undefinedifholewithname aaa + lda v0 + callarg0 0x0 + ldundefined + returnundefined +label_2: +} + +.function any .func_main_0(any a0, any a1, any a2) { +label_1: +label_0: + definefunc 0x0, .#*#foo, 0x0 + callarg0 0x1 + ldundefined + returnundefined +label_2: +} + + diff --git a/es2panda/test/parser/targetApiSubVersion/12/0/lazy-import-with-sendabe.ts b/es2panda/test/parser/targetApiSubVersion/12/0/lazy-import-with-sendabe.ts new file mode 100644 index 0000000000..c3df751a27 --- /dev/null +++ b/es2panda/test/parser/targetApiSubVersion/12/0/lazy-import-with-sendabe.ts @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import lazy { aaa } from './aaa' +function foo() { + "use sendable"; + aaa(); +} +foo(); \ No newline at end of file diff --git a/es2panda/test/parser/targetApiSubVersion/12/0/lazy-import-without-sendabe-expected.txt b/es2panda/test/parser/targetApiSubVersion/12/0/lazy-import-without-sendabe-expected.txt new file mode 100644 index 0000000000..628b209d28 --- /dev/null +++ b/es2panda/test/parser/targetApiSubVersion/12/0/lazy-import-without-sendabe-expected.txt @@ -0,0 +1,26 @@ +.language ECMAScript + +.function any .#*#foo(any a0, any a1, any a2) { +label_1: +label_0: + callruntime.ldlazymodulevar 0x0 + sta v0 + throw.undefinedifholewithname aaa + lda v0 + callarg0 0x0 + ldundefined + returnundefined +label_2: +} + +.function any .func_main_0(any a0, any a1, any a2) { +label_1: +label_0: + definefunc 0x0, .#*#foo, 0x0 + callarg0 0x1 + ldundefined + returnundefined +label_2: +} + + diff --git a/es2panda/test/parser/targetApiSubVersion/12/0/lazy-import-without-sendabe.ts b/es2panda/test/parser/targetApiSubVersion/12/0/lazy-import-without-sendabe.ts new file mode 100644 index 0000000000..2bac37427a --- /dev/null +++ b/es2panda/test/parser/targetApiSubVersion/12/0/lazy-import-without-sendabe.ts @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import lazy { aaa } from './aaa' +function foo() { + aaa(); +} +foo(); \ No newline at end of file diff --git a/es2panda/test/parser/targetApiSubVersion/12/0/sendable-function-expected.txt b/es2panda/test/parser/targetApiSubVersion/12/0/sendable-function-expected.txt new file mode 100644 index 0000000000..5825f0d807 --- /dev/null +++ b/es2panda/test/parser/targetApiSubVersion/12/0/sendable-function-expected.txt @@ -0,0 +1,160 @@ +.language ECMAScript + +.function any .#*#foo(any a0, any a1, any a2) { +label_1: +label_0: + definefunc 0x0, .#*@0*#insendable2, 0x0 + definefunc 0x1, .#*@0*#insendable1, 0x0 + callruntime.ldsendableexternalmodulevar 0x0 + sta v0 + throw.undefinedifholewithname aaa + lda v0 + callarg0 0x2 + ldundefined + returnundefined +label_2: +} + +.function any .#*#foo2(any a0, any a1, any a2) { +label_1: +label_0: + definefunc 0x0, .#*@2*#insendable1, 0x0 + ldexternalmodulevar 0x0 + sta v0 + throw.undefinedifholewithname aaa + lda v0 + callarg0 0x1 + ldundefined + returnundefined +label_2: +} + +.function any .#*#foo3(any a0, any a1, any a2) { +label_1: +label_0: + definefunc 0x0, .#*@4*#insendable1, 0x0 + ldexternalmodulevar 0x0 + sta v0 + throw.undefinedifholewithname aaa + lda v0 + callarg0 0x1 + ldundefined + returnundefined +label_2: +} + +.function any .#*@0*#insendable1(any a0, any a1, any a2) { +label_1: +label_0: + definefunc 0x0, .#*@0*@1*#insendable11, 0x0 + callruntime.ldsendableexternalmodulevar 0x0 + sta v0 + throw.undefinedifholewithname aaa + lda v0 + callarg0 0x1 + ldundefined + returnundefined +label_2: +} + +.function any .#*@0*#insendable2(any a0, any a1, any a2) { +label_1: +label_0: + callruntime.ldsendableexternalmodulevar 0x0 + sta v0 + throw.undefinedifholewithname aaa + lda v0 + callarg0 0x0 + ldundefined + returnundefined +label_2: +} + +.function any .#*@0*@1*#insendable11(any a0, any a1, any a2) { +label_1: +label_0: + callruntime.ldsendableexternalmodulevar 0x0 + sta v0 + throw.undefinedifholewithname aaa + lda v0 + callarg0 0x0 + ldundefined + returnundefined +label_2: +} + +.function any .#*@2*#insendable1(any a0, any a1, any a2) { +label_1: +label_0: + ldexternalmodulevar 0x0 + sta v0 + throw.undefinedifholewithname aaa + lda v0 + callarg0 0x0 + ldundefined + returnundefined +label_2: +} + +.function any .#*@4*#insendable1(any a0, any a1, any a2) { +label_1: +label_0: + ldexternalmodulevar 0x0 + sta v0 + throw.undefinedifholewithname aaa + lda v0 + callarg0 0x0 + ldundefined + returnundefined +label_2: +} + +.function any .#~A=#A(any a0, any a1, any a2) { +label_1: +label_0: + callruntime.ldsendablevar 0x0, 0x0 + stobjbyname 0x0, cb, a2 + lda a2 + return +label_2: +} + +.function any .#~A>#fooA(any a0, any a1, any a2) { +label_1: +label_0: + definefunc 0x0, .#~A>@3*#t, 0x0 + ldundefined + returnundefined +label_2: +} + +.function any .#~A>@3*#t(any a0, any a1, any a2) { +label_1: +label_0: + callruntime.ldsendableexternalmodulevar 0x0 + sta v0 + throw.undefinedifholewithname aaa + lda v0 + callarg0 0x0 + ldundefined + returnundefined +label_2: +} + +.function any .func_main_0(any a0, any a1, any a2) { +label_1: +label_0: + callruntime.newsendableenv 0x1 + definefunc 0x0, .#*#foo3, 0x0 + definefunc 0x1, .#*#foo2, 0x0 + definefunc 0x2, .#*#foo, 0x0 + callruntime.stsendablevar 0x0, 0x0 + ldhole + sta v0 + callruntime.definesendableclass 0x3, .#~A=#A, _3, 0x0, v0 + ldundefined + returnundefined +label_2: +} + + diff --git a/es2panda/test/parser/targetApiSubVersion/12/0/sendable-function.ts b/es2panda/test/parser/targetApiSubVersion/12/0/sendable-function.ts new file mode 100644 index 0000000000..70d55b5701 --- /dev/null +++ b/es2panda/test/parser/targetApiSubVersion/12/0/sendable-function.ts @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { aaa } from './aaa' +function foo() { + "use sendable"; + aaa(); + function insendable1() { + aaa(); + function insendable11() { + aaa(); + } + } + function insendable2() { + aaa(); + } +} +function foo2() { + aaa(); + function insendable1() { + aaa(); + } +} +type SendableFunction = () => void; +class A { + constructor () { + "use sendable"; + } + cb: SendableFunction = foo; + fooA() { + function t() { + aaa(); + } + } +} +function foo3() { + aaa(); + function insendable1() { + aaa(); + } +} + diff --git a/es2panda/test/parser/targetApiSubVersion/12/2/lazy-import-with-sendabe-expected.txt b/es2panda/test/parser/targetApiSubVersion/12/2/lazy-import-with-sendabe-expected.txt new file mode 100644 index 0000000000..360e4e56a4 --- /dev/null +++ b/es2panda/test/parser/targetApiSubVersion/12/2/lazy-import-with-sendabe-expected.txt @@ -0,0 +1,2 @@ +SyntaxError: Unexpected token. [lazy-import-with-sendabe.ts:16:13] +The size of programs is expected to be 1, but is 0 diff --git a/es2panda/test/parser/targetApiSubVersion/12/2/lazy-import-with-sendabe.ts b/es2panda/test/parser/targetApiSubVersion/12/2/lazy-import-with-sendabe.ts new file mode 100644 index 0000000000..c3df751a27 --- /dev/null +++ b/es2panda/test/parser/targetApiSubVersion/12/2/lazy-import-with-sendabe.ts @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import lazy { aaa } from './aaa' +function foo() { + "use sendable"; + aaa(); +} +foo(); \ No newline at end of file diff --git a/es2panda/test/parser/targetApiSubVersion/12/2/lazy-import-without-sendabe-expected.txt b/es2panda/test/parser/targetApiSubVersion/12/2/lazy-import-without-sendabe-expected.txt new file mode 100644 index 0000000000..ba60141550 --- /dev/null +++ b/es2panda/test/parser/targetApiSubVersion/12/2/lazy-import-without-sendabe-expected.txt @@ -0,0 +1,2 @@ +SyntaxError: Unexpected token. [lazy-import-without-sendabe.ts:16:13] +The size of programs is expected to be 1, but is 0 diff --git a/es2panda/test/parser/targetApiSubVersion/12/2/lazy-import-without-sendabe.ts b/es2panda/test/parser/targetApiSubVersion/12/2/lazy-import-without-sendabe.ts new file mode 100644 index 0000000000..2bac37427a --- /dev/null +++ b/es2panda/test/parser/targetApiSubVersion/12/2/lazy-import-without-sendabe.ts @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import lazy { aaa } from './aaa' +function foo() { + aaa(); +} +foo(); \ No newline at end of file diff --git a/es2panda/test/parser/targetApiSubVersion/12/2/sendable-function-expected.txt b/es2panda/test/parser/targetApiSubVersion/12/2/sendable-function-expected.txt new file mode 100644 index 0000000000..713c8c372a --- /dev/null +++ b/es2panda/test/parser/targetApiSubVersion/12/2/sendable-function-expected.txt @@ -0,0 +1,160 @@ +.language ECMAScript + +.function any .#*#foo(any a0, any a1, any a2) { +label_1: +label_0: + definefunc 0x0, .#*@0*#insendable2, 0x0 + definefunc 0x1, .#*@0*#insendable1, 0x0 + ldexternalmodulevar 0x0 + sta v0 + throw.undefinedifholewithname aaa + lda v0 + callarg0 0x2 + ldundefined + returnundefined +label_2: +} + +.function any .#*#foo2(any a0, any a1, any a2) { +label_1: +label_0: + definefunc 0x0, .#*@2*#insendable1, 0x0 + ldexternalmodulevar 0x0 + sta v0 + throw.undefinedifholewithname aaa + lda v0 + callarg0 0x1 + ldundefined + returnundefined +label_2: +} + +.function any .#*#foo3(any a0, any a1, any a2) { +label_1: +label_0: + definefunc 0x0, .#*@4*#insendable1, 0x0 + ldexternalmodulevar 0x0 + sta v0 + throw.undefinedifholewithname aaa + lda v0 + callarg0 0x1 + ldundefined + returnundefined +label_2: +} + +.function any .#*@0*#insendable1(any a0, any a1, any a2) { +label_1: +label_0: + definefunc 0x0, .#*@0*@1*#insendable11, 0x0 + ldexternalmodulevar 0x0 + sta v0 + throw.undefinedifholewithname aaa + lda v0 + callarg0 0x1 + ldundefined + returnundefined +label_2: +} + +.function any .#*@0*#insendable2(any a0, any a1, any a2) { +label_1: +label_0: + ldexternalmodulevar 0x0 + sta v0 + throw.undefinedifholewithname aaa + lda v0 + callarg0 0x0 + ldundefined + returnundefined +label_2: +} + +.function any .#*@0*@1*#insendable11(any a0, any a1, any a2) { +label_1: +label_0: + ldexternalmodulevar 0x0 + sta v0 + throw.undefinedifholewithname aaa + lda v0 + callarg0 0x0 + ldundefined + returnundefined +label_2: +} + +.function any .#*@2*#insendable1(any a0, any a1, any a2) { +label_1: +label_0: + ldexternalmodulevar 0x0 + sta v0 + throw.undefinedifholewithname aaa + lda v0 + callarg0 0x0 + ldundefined + returnundefined +label_2: +} + +.function any .#*@4*#insendable1(any a0, any a1, any a2) { +label_1: +label_0: + ldexternalmodulevar 0x0 + sta v0 + throw.undefinedifholewithname aaa + lda v0 + callarg0 0x0 + ldundefined + returnundefined +label_2: +} + +.function any .#~A=#A(any a0, any a1, any a2) { +label_1: +label_0: + ldlexvar 0x0, 0x0 + stobjbyname 0x0, cb, a2 + lda a2 + return +label_2: +} + +.function any .#~A>#fooA(any a0, any a1, any a2) { +label_1: +label_0: + definefunc 0x0, .#~A>@3*#t, 0x0 + ldundefined + returnundefined +label_2: +} + +.function any .#~A>@3*#t(any a0, any a1, any a2) { +label_1: +label_0: + callruntime.ldsendableexternalmodulevar 0x0 + sta v0 + throw.undefinedifholewithname aaa + lda v0 + callarg0 0x0 + ldundefined + returnundefined +label_2: +} + +.function any .func_main_0(any a0, any a1, any a2) { +label_1: +label_0: + newlexenv 0x1 + definefunc 0x0, .#*#foo3, 0x0 + definefunc 0x1, .#*#foo2, 0x0 + definefunc 0x2, .#*#foo, 0x0 + stlexvar 0x0, 0x0 + ldhole + sta v0 + callruntime.definesendableclass 0x3, .#~A=#A, _3, 0x0, v0 + ldundefined + returnundefined +label_2: +} + + diff --git a/es2panda/test/parser/targetApiSubVersion/12/2/sendable-function.ts b/es2panda/test/parser/targetApiSubVersion/12/2/sendable-function.ts new file mode 100644 index 0000000000..70d55b5701 --- /dev/null +++ b/es2panda/test/parser/targetApiSubVersion/12/2/sendable-function.ts @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { aaa } from './aaa' +function foo() { + "use sendable"; + aaa(); + function insendable1() { + aaa(); + function insendable11() { + aaa(); + } + } + function insendable2() { + aaa(); + } +} +function foo2() { + aaa(); + function insendable1() { + aaa(); + } +} +type SendableFunction = () => void; +class A { + constructor () { + "use sendable"; + } + cb: SendableFunction = foo; + fooA() { + function t() { + aaa(); + } + } +} +function foo3() { + aaa(); + function insendable1() { + aaa(); + } +} + diff --git a/es2panda/test/parser/targetApiSubVersion/12/3/lazy-import-with-sendabe-expected.txt b/es2panda/test/parser/targetApiSubVersion/12/3/lazy-import-with-sendabe-expected.txt new file mode 100644 index 0000000000..e790a958b1 --- /dev/null +++ b/es2panda/test/parser/targetApiSubVersion/12/3/lazy-import-with-sendabe-expected.txt @@ -0,0 +1,26 @@ +.language ECMAScript + +.function any .#*#foo(any a0, any a1, any a2) { +label_1: +label_0: + callruntime.ldlazysendablemodulevar 0x0 + sta v0 + throw.undefinedifholewithname aaa + lda v0 + callarg0 0x0 + ldundefined + returnundefined +label_2: +} + +.function any .func_main_0(any a0, any a1, any a2) { +label_1: +label_0: + definefunc 0x0, .#*#foo, 0x0 + callarg0 0x1 + ldundefined + returnundefined +label_2: +} + + diff --git a/es2panda/test/parser/targetApiSubVersion/12/3/lazy-import-with-sendabe.ts b/es2panda/test/parser/targetApiSubVersion/12/3/lazy-import-with-sendabe.ts new file mode 100644 index 0000000000..c3df751a27 --- /dev/null +++ b/es2panda/test/parser/targetApiSubVersion/12/3/lazy-import-with-sendabe.ts @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import lazy { aaa } from './aaa' +function foo() { + "use sendable"; + aaa(); +} +foo(); \ No newline at end of file diff --git a/es2panda/test/parser/targetApiSubVersion/12/3/lazy-import-without-sendabe-expected.txt b/es2panda/test/parser/targetApiSubVersion/12/3/lazy-import-without-sendabe-expected.txt new file mode 100644 index 0000000000..628b209d28 --- /dev/null +++ b/es2panda/test/parser/targetApiSubVersion/12/3/lazy-import-without-sendabe-expected.txt @@ -0,0 +1,26 @@ +.language ECMAScript + +.function any .#*#foo(any a0, any a1, any a2) { +label_1: +label_0: + callruntime.ldlazymodulevar 0x0 + sta v0 + throw.undefinedifholewithname aaa + lda v0 + callarg0 0x0 + ldundefined + returnundefined +label_2: +} + +.function any .func_main_0(any a0, any a1, any a2) { +label_1: +label_0: + definefunc 0x0, .#*#foo, 0x0 + callarg0 0x1 + ldundefined + returnundefined +label_2: +} + + diff --git a/es2panda/test/parser/targetApiSubVersion/12/3/lazy-import-without-sendabe.ts b/es2panda/test/parser/targetApiSubVersion/12/3/lazy-import-without-sendabe.ts new file mode 100644 index 0000000000..2bac37427a --- /dev/null +++ b/es2panda/test/parser/targetApiSubVersion/12/3/lazy-import-without-sendabe.ts @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import lazy { aaa } from './aaa' +function foo() { + aaa(); +} +foo(); \ No newline at end of file diff --git a/es2panda/test/parser/targetApiSubVersion/12/3/sendable-function-expected.txt b/es2panda/test/parser/targetApiSubVersion/12/3/sendable-function-expected.txt new file mode 100644 index 0000000000..5825f0d807 --- /dev/null +++ b/es2panda/test/parser/targetApiSubVersion/12/3/sendable-function-expected.txt @@ -0,0 +1,160 @@ +.language ECMAScript + +.function any .#*#foo(any a0, any a1, any a2) { +label_1: +label_0: + definefunc 0x0, .#*@0*#insendable2, 0x0 + definefunc 0x1, .#*@0*#insendable1, 0x0 + callruntime.ldsendableexternalmodulevar 0x0 + sta v0 + throw.undefinedifholewithname aaa + lda v0 + callarg0 0x2 + ldundefined + returnundefined +label_2: +} + +.function any .#*#foo2(any a0, any a1, any a2) { +label_1: +label_0: + definefunc 0x0, .#*@2*#insendable1, 0x0 + ldexternalmodulevar 0x0 + sta v0 + throw.undefinedifholewithname aaa + lda v0 + callarg0 0x1 + ldundefined + returnundefined +label_2: +} + +.function any .#*#foo3(any a0, any a1, any a2) { +label_1: +label_0: + definefunc 0x0, .#*@4*#insendable1, 0x0 + ldexternalmodulevar 0x0 + sta v0 + throw.undefinedifholewithname aaa + lda v0 + callarg0 0x1 + ldundefined + returnundefined +label_2: +} + +.function any .#*@0*#insendable1(any a0, any a1, any a2) { +label_1: +label_0: + definefunc 0x0, .#*@0*@1*#insendable11, 0x0 + callruntime.ldsendableexternalmodulevar 0x0 + sta v0 + throw.undefinedifholewithname aaa + lda v0 + callarg0 0x1 + ldundefined + returnundefined +label_2: +} + +.function any .#*@0*#insendable2(any a0, any a1, any a2) { +label_1: +label_0: + callruntime.ldsendableexternalmodulevar 0x0 + sta v0 + throw.undefinedifholewithname aaa + lda v0 + callarg0 0x0 + ldundefined + returnundefined +label_2: +} + +.function any .#*@0*@1*#insendable11(any a0, any a1, any a2) { +label_1: +label_0: + callruntime.ldsendableexternalmodulevar 0x0 + sta v0 + throw.undefinedifholewithname aaa + lda v0 + callarg0 0x0 + ldundefined + returnundefined +label_2: +} + +.function any .#*@2*#insendable1(any a0, any a1, any a2) { +label_1: +label_0: + ldexternalmodulevar 0x0 + sta v0 + throw.undefinedifholewithname aaa + lda v0 + callarg0 0x0 + ldundefined + returnundefined +label_2: +} + +.function any .#*@4*#insendable1(any a0, any a1, any a2) { +label_1: +label_0: + ldexternalmodulevar 0x0 + sta v0 + throw.undefinedifholewithname aaa + lda v0 + callarg0 0x0 + ldundefined + returnundefined +label_2: +} + +.function any .#~A=#A(any a0, any a1, any a2) { +label_1: +label_0: + callruntime.ldsendablevar 0x0, 0x0 + stobjbyname 0x0, cb, a2 + lda a2 + return +label_2: +} + +.function any .#~A>#fooA(any a0, any a1, any a2) { +label_1: +label_0: + definefunc 0x0, .#~A>@3*#t, 0x0 + ldundefined + returnundefined +label_2: +} + +.function any .#~A>@3*#t(any a0, any a1, any a2) { +label_1: +label_0: + callruntime.ldsendableexternalmodulevar 0x0 + sta v0 + throw.undefinedifholewithname aaa + lda v0 + callarg0 0x0 + ldundefined + returnundefined +label_2: +} + +.function any .func_main_0(any a0, any a1, any a2) { +label_1: +label_0: + callruntime.newsendableenv 0x1 + definefunc 0x0, .#*#foo3, 0x0 + definefunc 0x1, .#*#foo2, 0x0 + definefunc 0x2, .#*#foo, 0x0 + callruntime.stsendablevar 0x0, 0x0 + ldhole + sta v0 + callruntime.definesendableclass 0x3, .#~A=#A, _3, 0x0, v0 + ldundefined + returnundefined +label_2: +} + + diff --git a/es2panda/test/parser/targetApiSubVersion/12/3/sendable-function.ts b/es2panda/test/parser/targetApiSubVersion/12/3/sendable-function.ts new file mode 100644 index 0000000000..70d55b5701 --- /dev/null +++ b/es2panda/test/parser/targetApiSubVersion/12/3/sendable-function.ts @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { aaa } from './aaa' +function foo() { + "use sendable"; + aaa(); + function insendable1() { + aaa(); + function insendable11() { + aaa(); + } + } + function insendable2() { + aaa(); + } +} +function foo2() { + aaa(); + function insendable1() { + aaa(); + } +} +type SendableFunction = () => void; +class A { + constructor () { + "use sendable"; + } + cb: SendableFunction = foo; + fooA() { + function t() { + aaa(); + } + } +} +function foo3() { + aaa(); + function insendable1() { + aaa(); + } +} + diff --git a/es2panda/test/parser/targetApiSubVersion/13/lazy-import-with-sendabe-expected.txt b/es2panda/test/parser/targetApiSubVersion/13/lazy-import-with-sendabe-expected.txt new file mode 100644 index 0000000000..e790a958b1 --- /dev/null +++ b/es2panda/test/parser/targetApiSubVersion/13/lazy-import-with-sendabe-expected.txt @@ -0,0 +1,26 @@ +.language ECMAScript + +.function any .#*#foo(any a0, any a1, any a2) { +label_1: +label_0: + callruntime.ldlazysendablemodulevar 0x0 + sta v0 + throw.undefinedifholewithname aaa + lda v0 + callarg0 0x0 + ldundefined + returnundefined +label_2: +} + +.function any .func_main_0(any a0, any a1, any a2) { +label_1: +label_0: + definefunc 0x0, .#*#foo, 0x0 + callarg0 0x1 + ldundefined + returnundefined +label_2: +} + + diff --git a/es2panda/test/parser/targetApiSubVersion/13/lazy-import-with-sendabe.ts b/es2panda/test/parser/targetApiSubVersion/13/lazy-import-with-sendabe.ts new file mode 100644 index 0000000000..c3df751a27 --- /dev/null +++ b/es2panda/test/parser/targetApiSubVersion/13/lazy-import-with-sendabe.ts @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import lazy { aaa } from './aaa' +function foo() { + "use sendable"; + aaa(); +} +foo(); \ No newline at end of file diff --git a/es2panda/test/parser/targetApiSubVersion/13/lazy-import-without-sendabe-expected.txt b/es2panda/test/parser/targetApiSubVersion/13/lazy-import-without-sendabe-expected.txt new file mode 100644 index 0000000000..628b209d28 --- /dev/null +++ b/es2panda/test/parser/targetApiSubVersion/13/lazy-import-without-sendabe-expected.txt @@ -0,0 +1,26 @@ +.language ECMAScript + +.function any .#*#foo(any a0, any a1, any a2) { +label_1: +label_0: + callruntime.ldlazymodulevar 0x0 + sta v0 + throw.undefinedifholewithname aaa + lda v0 + callarg0 0x0 + ldundefined + returnundefined +label_2: +} + +.function any .func_main_0(any a0, any a1, any a2) { +label_1: +label_0: + definefunc 0x0, .#*#foo, 0x0 + callarg0 0x1 + ldundefined + returnundefined +label_2: +} + + diff --git a/es2panda/test/parser/targetApiSubVersion/13/lazy-import-without-sendabe.ts b/es2panda/test/parser/targetApiSubVersion/13/lazy-import-without-sendabe.ts new file mode 100644 index 0000000000..2bac37427a --- /dev/null +++ b/es2panda/test/parser/targetApiSubVersion/13/lazy-import-without-sendabe.ts @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import lazy { aaa } from './aaa' +function foo() { + aaa(); +} +foo(); \ No newline at end of file diff --git a/es2panda/test/parser/targetApiSubVersion/13/sendable-function-expected.txt b/es2panda/test/parser/targetApiSubVersion/13/sendable-function-expected.txt new file mode 100644 index 0000000000..5825f0d807 --- /dev/null +++ b/es2panda/test/parser/targetApiSubVersion/13/sendable-function-expected.txt @@ -0,0 +1,160 @@ +.language ECMAScript + +.function any .#*#foo(any a0, any a1, any a2) { +label_1: +label_0: + definefunc 0x0, .#*@0*#insendable2, 0x0 + definefunc 0x1, .#*@0*#insendable1, 0x0 + callruntime.ldsendableexternalmodulevar 0x0 + sta v0 + throw.undefinedifholewithname aaa + lda v0 + callarg0 0x2 + ldundefined + returnundefined +label_2: +} + +.function any .#*#foo2(any a0, any a1, any a2) { +label_1: +label_0: + definefunc 0x0, .#*@2*#insendable1, 0x0 + ldexternalmodulevar 0x0 + sta v0 + throw.undefinedifholewithname aaa + lda v0 + callarg0 0x1 + ldundefined + returnundefined +label_2: +} + +.function any .#*#foo3(any a0, any a1, any a2) { +label_1: +label_0: + definefunc 0x0, .#*@4*#insendable1, 0x0 + ldexternalmodulevar 0x0 + sta v0 + throw.undefinedifholewithname aaa + lda v0 + callarg0 0x1 + ldundefined + returnundefined +label_2: +} + +.function any .#*@0*#insendable1(any a0, any a1, any a2) { +label_1: +label_0: + definefunc 0x0, .#*@0*@1*#insendable11, 0x0 + callruntime.ldsendableexternalmodulevar 0x0 + sta v0 + throw.undefinedifholewithname aaa + lda v0 + callarg0 0x1 + ldundefined + returnundefined +label_2: +} + +.function any .#*@0*#insendable2(any a0, any a1, any a2) { +label_1: +label_0: + callruntime.ldsendableexternalmodulevar 0x0 + sta v0 + throw.undefinedifholewithname aaa + lda v0 + callarg0 0x0 + ldundefined + returnundefined +label_2: +} + +.function any .#*@0*@1*#insendable11(any a0, any a1, any a2) { +label_1: +label_0: + callruntime.ldsendableexternalmodulevar 0x0 + sta v0 + throw.undefinedifholewithname aaa + lda v0 + callarg0 0x0 + ldundefined + returnundefined +label_2: +} + +.function any .#*@2*#insendable1(any a0, any a1, any a2) { +label_1: +label_0: + ldexternalmodulevar 0x0 + sta v0 + throw.undefinedifholewithname aaa + lda v0 + callarg0 0x0 + ldundefined + returnundefined +label_2: +} + +.function any .#*@4*#insendable1(any a0, any a1, any a2) { +label_1: +label_0: + ldexternalmodulevar 0x0 + sta v0 + throw.undefinedifholewithname aaa + lda v0 + callarg0 0x0 + ldundefined + returnundefined +label_2: +} + +.function any .#~A=#A(any a0, any a1, any a2) { +label_1: +label_0: + callruntime.ldsendablevar 0x0, 0x0 + stobjbyname 0x0, cb, a2 + lda a2 + return +label_2: +} + +.function any .#~A>#fooA(any a0, any a1, any a2) { +label_1: +label_0: + definefunc 0x0, .#~A>@3*#t, 0x0 + ldundefined + returnundefined +label_2: +} + +.function any .#~A>@3*#t(any a0, any a1, any a2) { +label_1: +label_0: + callruntime.ldsendableexternalmodulevar 0x0 + sta v0 + throw.undefinedifholewithname aaa + lda v0 + callarg0 0x0 + ldundefined + returnundefined +label_2: +} + +.function any .func_main_0(any a0, any a1, any a2) { +label_1: +label_0: + callruntime.newsendableenv 0x1 + definefunc 0x0, .#*#foo3, 0x0 + definefunc 0x1, .#*#foo2, 0x0 + definefunc 0x2, .#*#foo, 0x0 + callruntime.stsendablevar 0x0, 0x0 + ldhole + sta v0 + callruntime.definesendableclass 0x3, .#~A=#A, _3, 0x0, v0 + ldundefined + returnundefined +label_2: +} + + diff --git a/es2panda/test/parser/targetApiSubVersion/13/sendable-function.ts b/es2panda/test/parser/targetApiSubVersion/13/sendable-function.ts new file mode 100644 index 0000000000..70d55b5701 --- /dev/null +++ b/es2panda/test/parser/targetApiSubVersion/13/sendable-function.ts @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { aaa } from './aaa' +function foo() { + "use sendable"; + aaa(); + function insendable1() { + aaa(); + function insendable11() { + aaa(); + } + } + function insendable2() { + aaa(); + } +} +function foo2() { + aaa(); + function insendable1() { + aaa(); + } +} +type SendableFunction = () => void; +class A { + constructor () { + "use sendable"; + } + cb: SendableFunction = foo; + fooA() { + function t() { + aaa(); + } + } +} +function foo3() { + aaa(); + function insendable1() { + aaa(); + } +} + diff --git a/es2panda/test/runner.py b/es2panda/test/runner.py index 2dde14df73..b584a15a13 100755 --- a/es2panda/test/runner.py +++ b/es2panda/test/runner.py @@ -1430,6 +1430,16 @@ def add_directory_for_regression(runners, args): runner.add_directory("parser/js/language/import/syntax", "js", ["--parse-only", "--module"]) runner.add_directory("parser/js/language/import", "ts", ["--dump-assembly", "--dump-literal-buffer", "--module"]) runner.add_directory("parser/sendable_class", "ts", ["--dump-assembly", "--dump-literal-buffer", "--module"]) + runner.add_directory("parser/targetApiSubVersion/11", "ts", + ["--module", "--dump-assembly", "--target-api-version=11"]) + runner.add_directory("parser/targetApiSubVersion/12/0", "ts", + ["--module", "--dump-assembly", "--target-api-version=12"]) + runner.add_directory("parser/targetApiSubVersion/12/2", "ts", + ["--module", "--dump-assembly", "--target-api-version=12", "--target-api-sub-version=2"]) + runner.add_directory("parser/targetApiSubVersion/12/3", "ts", + ["--module", "--dump-assembly", "--target-api-version=12", "--target-api-sub-version=3"]) + runner.add_directory("parser/targetApiSubVersion/13", "ts", + ["--module", "--dump-assembly", "--target-api-version=13"]) runner.add_directory("parser/unicode", "js", ["--parse-only"]) runner.add_directory("parser/ts/stack_overflow", "ts", ["--parse-only", "--dump-ast"]) @@ -1479,7 +1489,7 @@ def add_directory_for_asm(runners, args): runner.add_directory("parser/js/language/arguments-object", "js", []) runner.add_directory("parser/js/language/statements/for-statement", "js", []) runner.add_directory("parser/js/language/expressions/optional-chain", "js", []) - runner.add_directory("parser/sendable_class", "ts", ["--module"]) + runner.add_directory("parser/target", "ts", ["--module"]) runner.add_directory("parser/unicode", "js", []) runner.add_directory("parser/ts/stack_overflow", "ts", []) diff --git a/es2panda/util/helpers.cpp b/es2panda/util/helpers.cpp index 906ca54335..843b10b853 100644 --- a/es2panda/util/helpers.cpp +++ b/es2panda/util/helpers.cpp @@ -812,7 +812,8 @@ bool Helpers::ReadFileToBuffer(const std::string &file, std::stringstream &ss) return true; } -void Helpers::ScanDirectives(ir::ScriptFunction *func, const lexer::LineIndex &lineIndex) +void Helpers::ScanDirectives(ir::ScriptFunction *func, const lexer::LineIndex &lineIndex, + const int32_t targetApiSubVersion, int32_t targetApiVersion) { auto *body = func->Body(); if (!body || body->IsExpression()) { @@ -837,14 +838,16 @@ void Helpers::ScanDirectives(ir::ScriptFunction *func, const lexer::LineIndex &l return; } - keepScan = SetFuncFlagsForDirectives(expr->AsStringLiteral(), func, lineIndex); + keepScan = SetFuncFlagsForDirectives(expr->AsStringLiteral(), func, lineIndex, targetApiSubVersion, + targetApiVersion); } return; } bool Helpers::SetFuncFlagsForDirectives(const ir::StringLiteral *strLit, ir::ScriptFunction *func, - const lexer::LineIndex &lineIndex) + const lexer::LineIndex &lineIndex, int32_t targetApiSubVersion, + int32_t targetApiVersion) { if (strLit->Str().Is(SHOW_SOURCE)) { func->AddFlag(ir::ScriptFunctionFlags::SHOW_SOURCE); @@ -861,7 +864,10 @@ bool Helpers::SetFuncFlagsForDirectives(const ir::StringLiteral *strLit, ir::Scr auto *classDef = const_cast(GetClassDefiniton(func)); classDef->SetSendable(); } else { - func->AddFlag(ir::ScriptFunctionFlags::SENDABLE); + if (IsSupportedApiAndReleaseType(targetApiVersion, targetApiSubVersion, + SENDABLE_FUNCTION_MIN_SUPPORTED_API_VERSION, SENDABLE_FUNCTION_API_SUB_VERSION)) { + func->AddFlag(ir::ScriptFunctionFlags::SENDABLE); + } } return true; } @@ -980,4 +986,13 @@ void Helpers::RemoveProgramsRedundantData(std::map= supportedReleaseType; + } + return targetApiVersion > supportedApi; +} + } // namespace panda::es2panda::util diff --git a/es2panda/util/helpers.h b/es2panda/util/helpers.h index 660f79f901..2e3ff48705 100644 --- a/es2panda/util/helpers.h +++ b/es2panda/util/helpers.h @@ -140,7 +140,8 @@ public: template static T BaseName(T const &path, T const &delims = std::string(panda::os::file::File::GetPathDelim())); static bool ReadFileToBuffer(const std::string &file, std::stringstream &ss); - static void ScanDirectives(ir::ScriptFunction *func, const lexer::LineIndex &lineIndex); + static void ScanDirectives(ir::ScriptFunction *func, const lexer::LineIndex &lineIndex, + const int32_t targetApiSubVersion, int32_t targetApiVersion); static std::string GetHashString(const std::string &str); static std::wstring Utf8ToUtf16(const std::string &utf8); template @@ -154,6 +155,8 @@ public: const std::string &delimiter = std::string(DOT)); static void RemoveProgramsRedundantData(std::map &progsInfo, const std::map> &resolveDepsRelation); + static bool IsSupportedApiAndReleaseType(const int32_t targetApiVersion, const int32_t targetApiSubVersion, + const int32_t supportedApi, const int32_t supportedReleaseType); static const uint32_t MAX_DOUBLE_DIGIT = 310; static const uint32_t MAX_DOUBLE_PRECISION_DIGIT = 17; @@ -184,15 +187,19 @@ public: static const uint64_t FNV_PRIME = 1099511628211U; static const uint64_t FNV_OFFSET = 14695981039346656037U; static const int32_t DEFAULT_TARGET_API_VERSION = 12; + static const int32_t DEFAULT_TARGET_API_SUB_VERSION = 0; static const int32_t ABC_TO_PROGRAM_MIN_SUPPORTED_API_VERSION = 12; static constexpr std::array ABC_TO_PROGRAM_MIN_SUPPORTED_BYTECODE_VERSION {12, 0, 4, 0}; static const int32_t SENDABLE_FUNCTION_MIN_SUPPORTED_API_VERSION = 12; static const int32_t LAZY_IMPORT_MIN_SUPPORTED_API_VERSION = 12; static const int32_t SENDABLE_LAZY_LOADING_MIN_SUPPORTED_API_VERSION = 12; + static const int32_t SENDABLE_FUNCTION_API_SUB_VERSION = 3; + static const int32_t LAZY_IMPORT_API_SUB_VERSION = 3; private: static bool SetFuncFlagsForDirectives(const ir::StringLiteral *strLit, ir::ScriptFunction *func, - const lexer::LineIndex &lineIndex); + const lexer::LineIndex &lineIndex, const int targetApiSubVersion, + int targetApiVersion); }; template -- Gitee