From 36480878e9425aa7b435e32b4428945b7de61722 Mon Sep 17 00:00:00 2001 From: shixiaowei4 Date: Fri, 12 Jul 2024 22:16:45 +0800 Subject: [PATCH 1/3] Disable function name with scope Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/IACO9Z Signed-off-by: shixiaowei4 Change-Id: I001c0e3daf0e49a3a1f152a5667bfb5b258509d9 --- es2panda/binder/binder.cpp | 2 +- es2panda/compiler/core/emitter/emitter.cpp | 2 +- es2panda/util/helpers.cpp | 5 +++++ es2panda/util/helpers.h | 1 + es2panda/util/patchFix.cpp | 7 ++++--- es2panda/util/symbolTable.cpp | 2 +- 6 files changed, 13 insertions(+), 6 deletions(-) diff --git a/es2panda/binder/binder.cpp b/es2panda/binder/binder.cpp index 85ed70ccdf..fe6ed6d790 100644 --- a/es2panda/binder/binder.cpp +++ b/es2panda/binder/binder.cpp @@ -365,7 +365,7 @@ void Binder::BuildFunction(FunctionScope *funcScope, util::StringView name, cons } functionScopes_.push_back(funcScope); funcScope->SetInFunctionScopes(); - if (Program()->TargetApiVersion() > 11) { + if (!Helpers::IsBeta2() && Program()->TargetApiVersion() > 11) { funcScope->SetSelfScopeName(name); auto recordName = program_->FormatedRecordName().Mutf8(); funcScope->BindNameWithScopeInfo(name, util::UString(recordName, Allocator()).View()); diff --git a/es2panda/compiler/core/emitter/emitter.cpp b/es2panda/compiler/core/emitter/emitter.cpp index 3b6db73ecc..fcb9245e4f 100644 --- a/es2panda/compiler/core/emitter/emitter.cpp +++ b/es2panda/compiler/core/emitter/emitter.cpp @@ -429,7 +429,7 @@ void Emitter::AddScopeNamesRecord(CompilerContext *context) { std::lock_guard lock(m_); // make literalarray for scope names - if (context->Binder()->Program()->TargetApiVersion() < 12) { + if (Helpers::IsBeta2() || context->Binder()->Program()->TargetApiVersion() < 12) { return; } const auto &scopeNamesMap = context->Binder()->GetScopeNames(); diff --git a/es2panda/util/helpers.cpp b/es2panda/util/helpers.cpp index 906ca54335..03e2865a29 100644 --- a/es2panda/util/helpers.cpp +++ b/es2panda/util/helpers.cpp @@ -951,6 +951,11 @@ bool Helpers::IsSpecialScopeName(const util::StringView &name) name.Find(Helpers::BACKSLASH.data()) != std::string::npos; } +bool Helpers::IsBeta2() +{ + return true; +} + bool Helpers::BelongingToRecords(const std::string &name, const std::unordered_set &retainRecordSet, const std::string &delimiter) { diff --git a/es2panda/util/helpers.h b/es2panda/util/helpers.h index 660f79f901..93658529aa 100644 --- a/es2panda/util/helpers.h +++ b/es2panda/util/helpers.h @@ -150,6 +150,7 @@ public: static bool IsUseShared(const ir::Statement *statement); static const ir::ClassDefinition *GetContainingSendableClass(const ir::AstNode *node); static bool IsSpecialScopeName(const util::StringView &str); + static bool IsBeta2(); static bool BelongingToRecords(const std::string &name, const std::unordered_set &retainRecordSet, const std::string &delimiter = std::string(DOT)); static void RemoveProgramsRedundantData(std::map &progsInfo, diff --git a/es2panda/util/patchFix.cpp b/es2panda/util/patchFix.cpp index 0940e77046..f9210315d8 100644 --- a/es2panda/util/patchFix.cpp +++ b/es2panda/util/patchFix.cpp @@ -126,7 +126,7 @@ void PatchFix::ValidateJsonContentRecInfo(const std::string &recordName, const s bool PatchFix::IsAnonymousOrSpecialOrDuplicateFunction(const std::string &funcName) { - if (targetApiVersion_ < 12) { + if (Helpers::IsBeta2() || targetApiVersion_ < 12) { return funcName.find(binder::Binder::ANONYMOUS_SPECIAL_DUPLICATE_FUNCTION_SPECIFIER) != std::string::npos; } // Function name is like: #scopes^1#functionname^1 @@ -567,7 +567,8 @@ void PatchFix::HandleFunction(const compiler::PandaGen *pg, panda::pandasm::Func std::string funcName = func->name; auto originFunction = originFunctionInfo_->find(funcName); if (originFunction == originFunctionInfo_->end()) { - if (pg->Binder()->Program()->TargetApiVersion() > 11 && + if ((!Helpers::IsBeta2() && + pg->Binder()->Program()->TargetApiVersion() > 11) && IsHotFix() && IsAnonymousOrSpecialOrDuplicateFunction(funcName)) { std::cerr << "[Patch] Found new anonymous, special(containing '.' or '\\') or duplicate name function " @@ -624,7 +625,7 @@ void PatchFix::DumpFunctionInfo(const compiler::PandaGen *pg, panda::pandasm::Fu std::vector> hashList = GenerateFunctionAndClassHash(func, literalBuffers); ss << hashList.back().second << SymbolTable::SECOND_LEVEL_SEPERATOR; - if (pg->Binder()->Program()->TargetApiVersion() < 12) { + if (Helpers::IsBeta2() || pg->Binder()->Program()->TargetApiVersion() < 12) { auto internalNameStr = pg->InternalName().Mutf8(); if (internalNameStr.find("#") != std::string::npos) { ss << (pg->Binder()->SpecialFuncNameIndexMap()).at(internalNameStr) << SymbolTable::SECOND_LEVEL_SEPERATOR; diff --git a/es2panda/util/symbolTable.cpp b/es2panda/util/symbolTable.cpp index 2b2cbc8837..2c3171d1e3 100644 --- a/es2panda/util/symbolTable.cpp +++ b/es2panda/util/symbolTable.cpp @@ -110,7 +110,7 @@ bool SymbolTable::ReadSymbolTable(const std::string &symbolTable) } originFunctionInfo_.insert(std::pair(info.funcInternalName, info)); - if (targetApiVersion_ < 12) { + if (Helpers::IsBeta2() || targetApiVersion_ < 12) { // index of function in its record's special function array std::string specialFuncIndex{funcItems[3]}; ReadRecordHashFunctionNames(info.recordName, info.funcInternalName, specialFuncIndex); -- Gitee From e7b8c0057db0b7108cb479df16a43d6a9b2a0e3c Mon Sep 17 00:00:00 2001 From: huyunhui1 Date: Fri, 12 Jul 2024 22:41:16 +0800 Subject: [PATCH 2/3] Disable new bytecodes Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/IACO9Z Signed-off-by: huyunhui1 Change-Id: Id563b283d45ee72284d60f948ea1d9ddc30b6e45 --- es2panda/compiler/core/pandagen.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/es2panda/compiler/core/pandagen.cpp b/es2panda/compiler/core/pandagen.cpp index 6b92fffdc1..7f132c2fb4 100644 --- a/es2panda/compiler/core/pandagen.cpp +++ b/es2panda/compiler/core/pandagen.cpp @@ -576,9 +576,13 @@ void PandaGen::StoreObjByName(const ir::AstNode *node, VReg obj, const util::Str void PandaGen::DefineFieldByName(const ir::AstNode *node, VReg obj, const util::StringView &prop) { +# if defined Beta2 + ra_.Emit(node, 0, prop, obj); +# else // use definepropertybyname instead of definefieldbyname since api12 for runtime's performance. Binder()->Program()->TargetApiVersion() >= 12 ? ra_.Emit(node, 0, prop, obj) : ra_.Emit(node, 0, prop, obj); +# endif strings_.insert(prop); } @@ -1091,8 +1095,12 @@ void PandaGen::GreaterEqual(const ir::AstNode *node, VReg lhs) void PandaGen::IsTrue(const ir::AstNode *node) { +# if defined Beta2 + ra_.Emit(node); +# else // use callruntime.istrue instead of istrue since api12 for runtime's performance. Binder()->Program()->TargetApiVersion() >= 12 ? ra_.Emit(node, 0) : ra_.Emit(node); +# endif } void PandaGen::BranchIfUndefined(const ir::AstNode *node, Label *target) @@ -1149,9 +1157,13 @@ void PandaGen::BranchIfNotTrue(const ir::AstNode *node, Label *target) void PandaGen::BranchIfFalse(const ir::AstNode *node, Label *target) { +# if defined Beta2 + ra_.Emit(node); +# else // use callruntime.istrue instead of istrue since api12 for runtime's performance. Binder()->Program()->TargetApiVersion() >= 12 ? ra_.Emit(node, 0) : ra_.Emit(node); ra_.Emit(node, target); +# endif } void PandaGen::BranchIfStrictNull(const ir::AstNode *node, class Label *target) -- Gitee From 59d5740162b77446a110b1eebbc71127f0124617 Mon Sep 17 00:00:00 2001 From: shixiaowei4 Date: Fri, 12 Jul 2024 23:18:23 +0800 Subject: [PATCH 3/3] DisableScopenames Signed-off-by: shixiaowei4 Change-Id: Id1b7fae83a358b7c44752ab0c45c93094ba26417 --- es2panda/binder/binder.cpp | 2 +- es2panda/compiler/core/emitter/emitter.cpp | 2 +- es2panda/util/patchFix.cpp | 6 +++--- es2panda/util/symbolTable.cpp | 3 ++- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/es2panda/binder/binder.cpp b/es2panda/binder/binder.cpp index fe6ed6d790..07f9866b99 100644 --- a/es2panda/binder/binder.cpp +++ b/es2panda/binder/binder.cpp @@ -365,7 +365,7 @@ void Binder::BuildFunction(FunctionScope *funcScope, util::StringView name, cons } functionScopes_.push_back(funcScope); funcScope->SetInFunctionScopes(); - if (!Helpers::IsBeta2() && Program()->TargetApiVersion() > 11) { + if (!util::Helpers::IsBeta2() && Program()->TargetApiVersion() > 11) { funcScope->SetSelfScopeName(name); auto recordName = program_->FormatedRecordName().Mutf8(); funcScope->BindNameWithScopeInfo(name, util::UString(recordName, Allocator()).View()); diff --git a/es2panda/compiler/core/emitter/emitter.cpp b/es2panda/compiler/core/emitter/emitter.cpp index fcb9245e4f..355679715d 100644 --- a/es2panda/compiler/core/emitter/emitter.cpp +++ b/es2panda/compiler/core/emitter/emitter.cpp @@ -429,7 +429,7 @@ void Emitter::AddScopeNamesRecord(CompilerContext *context) { std::lock_guard lock(m_); // make literalarray for scope names - if (Helpers::IsBeta2() || context->Binder()->Program()->TargetApiVersion() < 12) { + if (util::Helpers::IsBeta2() || context->Binder()->Program()->TargetApiVersion() < 12) { return; } const auto &scopeNamesMap = context->Binder()->GetScopeNames(); diff --git a/es2panda/util/patchFix.cpp b/es2panda/util/patchFix.cpp index f9210315d8..81919b8387 100644 --- a/es2panda/util/patchFix.cpp +++ b/es2panda/util/patchFix.cpp @@ -126,7 +126,7 @@ void PatchFix::ValidateJsonContentRecInfo(const std::string &recordName, const s bool PatchFix::IsAnonymousOrSpecialOrDuplicateFunction(const std::string &funcName) { - if (Helpers::IsBeta2() || targetApiVersion_ < 12) { + if (util::Helpers::IsBeta2() || targetApiVersion_ < 12) { return funcName.find(binder::Binder::ANONYMOUS_SPECIAL_DUPLICATE_FUNCTION_SPECIFIER) != std::string::npos; } // Function name is like: #scopes^1#functionname^1 @@ -567,7 +567,7 @@ void PatchFix::HandleFunction(const compiler::PandaGen *pg, panda::pandasm::Func std::string funcName = func->name; auto originFunction = originFunctionInfo_->find(funcName); if (originFunction == originFunctionInfo_->end()) { - if ((!Helpers::IsBeta2() && + if ((!util::Helpers::IsBeta2() && pg->Binder()->Program()->TargetApiVersion() > 11) && IsHotFix() && IsAnonymousOrSpecialOrDuplicateFunction(funcName)) { @@ -625,7 +625,7 @@ void PatchFix::DumpFunctionInfo(const compiler::PandaGen *pg, panda::pandasm::Fu std::vector> hashList = GenerateFunctionAndClassHash(func, literalBuffers); ss << hashList.back().second << SymbolTable::SECOND_LEVEL_SEPERATOR; - if (Helpers::IsBeta2() || pg->Binder()->Program()->TargetApiVersion() < 12) { + if (util::Helpers::IsBeta2() || pg->Binder()->Program()->TargetApiVersion() < 12) { auto internalNameStr = pg->InternalName().Mutf8(); if (internalNameStr.find("#") != std::string::npos) { ss << (pg->Binder()->SpecialFuncNameIndexMap()).at(internalNameStr) << SymbolTable::SECOND_LEVEL_SEPERATOR; diff --git a/es2panda/util/symbolTable.cpp b/es2panda/util/symbolTable.cpp index 2c3171d1e3..2264424a34 100644 --- a/es2panda/util/symbolTable.cpp +++ b/es2panda/util/symbolTable.cpp @@ -17,6 +17,7 @@ #include #include +#include namespace panda::es2panda::util { const std::string SymbolTable::FIRST_LEVEL_SEPERATOR = "|"; @@ -110,7 +111,7 @@ bool SymbolTable::ReadSymbolTable(const std::string &symbolTable) } originFunctionInfo_.insert(std::pair(info.funcInternalName, info)); - if (Helpers::IsBeta2() || targetApiVersion_ < 12) { + if (util::Helpers::IsBeta2() || targetApiVersion_ < 12) { // index of function in its record's special function array std::string specialFuncIndex{funcItems[3]}; ReadRecordHashFunctionNames(info.recordName, info.funcInternalName, specialFuncIndex); -- Gitee