From fa46268b75c9d7344a574c533f78ae81901580f5 Mon Sep 17 00:00:00 2001 From: Geng Chen Date: Thu, 7 Aug 2025 11:29:17 +0800 Subject: [PATCH] remove locks to save space Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICVJLK Signed-off-by: Geng Chen --- ets2panda/checker/ETSchecker.h | 7 ---- ets2panda/checker/ets/function.cpp | 4 +- ets2panda/checker/ets/helpers.cpp | 12 +++--- .../checker/types/ets/etsFunctionType.cpp | 40 ++++++++++++++++--- ets2panda/checker/types/ets/etsFunctionType.h | 20 +++------- ets2panda/checker/types/ets/etsObjectType.cpp | 1 - ets2panda/checker/types/type.cpp | 2 - ets2panda/checker/types/type.h | 3 -- ets2panda/ir/astNodeHistory.cpp | 3 -- ets2panda/ir/astNodeHistory.h | 3 -- 10 files changed, 48 insertions(+), 47 deletions(-) diff --git a/ets2panda/checker/ETSchecker.h b/ets2panda/checker/ETSchecker.h index 5aaf218056..bcf64d4f5b 100644 --- a/ets2panda/checker/ETSchecker.h +++ b/ets2panda/checker/ETSchecker.h @@ -17,7 +17,6 @@ #define ES2PANDA_CHECKER_ETS_CHECKER_H #include -#include #include "checker/checker.h" @@ -870,11 +869,6 @@ public: void ResolveReturnStatement(checker::Type *funcReturnType, checker::Type *argumentType, ir::ScriptFunction *containingFunc, ir::ReturnStatement *st); - std::recursive_mutex *Mutex() - { - return &mtx_; - } - template T *AllocNode(Args &&...args) { @@ -1096,7 +1090,6 @@ private: ComputedAbstracts *cachedComputedAbstracts_ {nullptr}; FunctionalInterfaceMap functionalInterfaceCache_; TypeMapping apparentTypes_; - std::recursive_mutex mtx_; evaluate::ScopedDebugInfoPlugin *debugInfoPlugin_ {nullptr}; std::unordered_set elementStack_; ArenaVector overloadSigContainer_; diff --git a/ets2panda/checker/ets/function.cpp b/ets2panda/checker/ets/function.cpp index 1fd04a4a9e..db7ff14c8f 100644 --- a/ets2panda/checker/ets/function.cpp +++ b/ets2panda/checker/ets/function.cpp @@ -1592,9 +1592,9 @@ static bool CollectOverload(checker::ETSChecker *checker, ir::MethodDefinition * auto overloadSig = currentFunc->Function()->Signature(); funcType->AddCallSignature(overloadSig); if (overloadSig->IsExtensionAccessor()) { - funcType->GetExtensionAccessorSigs().emplace_back(overloadSig); + funcType->GetExtensionAccessorSigs(checker).emplace_back(overloadSig); } else if (overloadSig->IsExtensionFunction()) { - funcType->GetExtensionFunctionSigs().emplace_back(overloadSig); + funcType->GetExtensionFunctionSigs(checker).emplace_back(overloadSig); } overloads.push_back(overloadType); diff --git a/ets2panda/checker/ets/helpers.cpp b/ets2panda/checker/ets/helpers.cpp index 3ed10f6daa..9470a16a65 100644 --- a/ets2panda/checker/ets/helpers.cpp +++ b/ets2panda/checker/ets/helpers.cpp @@ -1095,8 +1095,8 @@ Signature *ETSChecker::FindRelativeExtensionGetter(ir::MemberExpression *const e ArenaVector arguments(ProgramAllocator()->Adapter()); arguments.insert(arguments.begin(), expr->Object()); // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) - Signature *signature = ValidateSignatures(funcType->GetExtensionAccessorSigs(), nullptr, arguments, expr->Start(), - "call", TypeRelationFlag::NO_THROW); + Signature *signature = ValidateSignatures(funcType->GetExtensionAccessorSigs(this), nullptr, arguments, + expr->Start(), "call", TypeRelationFlag::NO_THROW); if (signature != nullptr) { InsertExtensionGetterToMap(funcType->Name(), expr->ObjType(), signature); } @@ -1119,16 +1119,16 @@ Signature *ETSChecker::FindRelativeExtensionSetter(ir::MemberExpression *expr, E if (expr->Parent()->IsAssignmentExpression()) { arguments.emplace_back(expr->Parent()->AsAssignmentExpression()->Right()); // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) - signature = ValidateSignatures(funcType->GetExtensionAccessorSigs(), nullptr, arguments, expr->Start(), "call", - TypeRelationFlag::NO_THROW); + signature = ValidateSignatures(funcType->GetExtensionAccessorSigs(this), nullptr, arguments, expr->Start(), + "call", TypeRelationFlag::NO_THROW); } else { // When handle ++a.m, a.m++, is mean to check whether a.m(xx, 1) existed. // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) Type *getterReturnType = ResolveGetter(this, expr, funcType); expr->SetTsType(getterReturnType); arguments.emplace_back(expr); - signature = ValidateSignatures(funcType->GetExtensionAccessorSigs(), nullptr, arguments, expr->Start(), "call", - TypeRelationFlag::NO_THROW); + signature = ValidateSignatures(funcType->GetExtensionAccessorSigs(this), nullptr, arguments, expr->Start(), + "call", TypeRelationFlag::NO_THROW); } if (signature == nullptr) { diff --git a/ets2panda/checker/types/ets/etsFunctionType.cpp b/ets2panda/checker/types/ets/etsFunctionType.cpp index 669ab5d1ed..52f8fa6a95 100644 --- a/ets2panda/checker/types/ets/etsFunctionType.cpp +++ b/ets2panda/checker/types/ets/etsFunctionType.cpp @@ -24,8 +24,8 @@ ETSFunctionType::ETSFunctionType([[maybe_unused]] ETSChecker *checker, util::Str ArenaVector &&signatures) : Type(TypeFlag::FUNCTION | TypeFlag::ETS_METHOD), callSignatures_(std::move(signatures)), - extensionFunctionSigs_(ArenaVector(checker->ProgramAllocator()->Adapter())), - extensionAccessorSigs_(ArenaVector(checker->ProgramAllocator()->Adapter())), + extensionFunctionSigs_(nullptr), + extensionAccessorSigs_(nullptr), name_(name) { auto flag = TypeFlag::NONE; @@ -33,9 +33,17 @@ ETSFunctionType::ETSFunctionType([[maybe_unused]] ETSChecker *checker, util::Str flag |= sig->HasSignatureFlag(SignatureFlags::GETTER) ? TypeFlag::GETTER : TypeFlag::NONE; flag |= sig->HasSignatureFlag(SignatureFlags::SETTER) ? TypeFlag::SETTER : TypeFlag::NONE; if (sig->IsExtensionAccessor()) { - extensionAccessorSigs_.emplace_back(sig); + if (extensionAccessorSigs_ == nullptr) { + extensionAccessorSigs_ = + checker->ProgramAllocator()->New>(checker->ProgramAllocator()->Adapter()); + } + extensionAccessorSigs_->emplace_back(sig); } else if (sig->IsExtensionFunction()) { - extensionFunctionSigs_.emplace_back(sig); + if (extensionFunctionSigs_ == nullptr) { + extensionFunctionSigs_ = + checker->ProgramAllocator()->New>(checker->ProgramAllocator()->Adapter()); + } + extensionFunctionSigs_->emplace_back(sig); } } AddTypeFlag(flag); @@ -44,8 +52,8 @@ ETSFunctionType::ETSFunctionType([[maybe_unused]] ETSChecker *checker, util::Str ETSFunctionType::ETSFunctionType(ETSChecker *checker, Signature *signature) : Type(TypeFlag::FUNCTION), callSignatures_({{signature->ToArrowSignature(checker)}, checker->ProgramAllocator()->Adapter()}), - extensionFunctionSigs_(ArenaVector(checker->ProgramAllocator()->Adapter())), - extensionAccessorSigs_(ArenaVector(checker->ProgramAllocator()->Adapter())), + extensionFunctionSigs_(nullptr), + extensionAccessorSigs_(nullptr), name_(""), assemblerName_(checker->GlobalBuiltinFunctionType(signature->MinArgCount(), signature->HasRestParameter()) != nullptr @@ -423,4 +431,24 @@ void ETSFunctionType::CheckVarianceRecursively(TypeRelation *relation, VarianceF } } +ArenaVector &ETSFunctionType::GetExtensionAccessorSigs(ETSChecker *checker) +{ + ES2PANDA_ASSERT(!IsETSArrowType()); + if (extensionAccessorSigs_ == nullptr) { + extensionAccessorSigs_ = + checker->ProgramAllocator()->New>(checker->ProgramAllocator()->Adapter()); + } + return *extensionAccessorSigs_; +} + +ArenaVector &ETSFunctionType::GetExtensionFunctionSigs(ETSChecker *checker) +{ + ES2PANDA_ASSERT(!IsETSArrowType()); + if (extensionFunctionSigs_ == nullptr) { + extensionFunctionSigs_ = + checker->ProgramAllocator()->New>(checker->ProgramAllocator()->Adapter()); + } + return *extensionFunctionSigs_; +} + } // namespace ark::es2panda::checker diff --git a/ets2panda/checker/types/ets/etsFunctionType.h b/ets2panda/checker/types/ets/etsFunctionType.h index ffc9e8ea59..3ebb6ef10d 100644 --- a/ets2panda/checker/types/ets/etsFunctionType.h +++ b/ets2panda/checker/types/ets/etsFunctionType.h @@ -79,17 +79,9 @@ public: return FindSpecificSignature([](auto const *const sig) -> bool { return sig->Function()->IsSetter(); }); } - [[nodiscard]] ArenaVector &GetExtensionAccessorSigs() - { - ES2PANDA_ASSERT(!IsETSArrowType()); - return extensionAccessorSigs_; - } + [[nodiscard]] ArenaVector &GetExtensionAccessorSigs(ETSChecker *checker); - [[nodiscard]] ArenaVector &GetExtensionFunctionSigs() - { - ES2PANDA_ASSERT(!IsETSArrowType()); - return extensionFunctionSigs_; - } + [[nodiscard]] ArenaVector &GetExtensionFunctionSigs(ETSChecker *checker); [[nodiscard]] Signature *FirstAbstractSignature() const noexcept { @@ -111,12 +103,12 @@ public: ETSObjectType *ArrowToFunctionalInterfaceDesiredArity(ETSChecker *checker, size_t arity); [[nodiscard]] bool IsExtensionFunctionType() const { - return !extensionFunctionSigs_.empty() || !extensionAccessorSigs_.empty(); + return extensionFunctionSigs_ != nullptr && !extensionFunctionSigs_->empty(); } [[nodiscard]] bool IsExtensionAccessorType() const { - return !extensionAccessorSigs_.empty(); + return extensionAccessorSigs_ != nullptr && !extensionAccessorSigs_->empty(); } void ToAssemblerType(std::stringstream &ss) const override; @@ -156,8 +148,8 @@ public: private: ArenaVector callSignatures_; - ArenaVector extensionFunctionSigs_; - ArenaVector extensionAccessorSigs_; + ArenaVector *extensionFunctionSigs_; + ArenaVector *extensionAccessorSigs_; util::StringView const name_; util::StringView const assemblerName_; Signature *helperSignature_ {}; diff --git a/ets2panda/checker/types/ets/etsObjectType.cpp b/ets2panda/checker/types/ets/etsObjectType.cpp index 49679056d4..d27ad21c69 100644 --- a/ets2panda/checker/types/ets/etsObjectType.cpp +++ b/ets2panda/checker/types/ets/etsObjectType.cpp @@ -1062,7 +1062,6 @@ Type *ETSObjectType::Instantiate(ArenaAllocator *const allocator, TypeRelation * { relation = relation_; auto *const checker = relation->GetChecker()->AsETSChecker(); - std::lock_guard guard {*checker->Mutex()}; auto *const base = GetOriginalBaseType(); if (!relation->IsAtTypeDepthLimit(base)) { diff --git a/ets2panda/checker/types/type.cpp b/ets2panda/checker/types/type.cpp index 6944992590..bff5be73df 100644 --- a/ets2panda/checker/types/type.cpp +++ b/ets2panda/checker/types/type.cpp @@ -23,8 +23,6 @@ namespace ark::es2panda::checker { -std::mutex Type::idLock_ {}; - bool Type::IsETSResizableArrayType() const { return IsETSObjectType() && AsETSObjectType()->HasObjectFlag(ETSObjectFlags::BUILTIN_ARRAY); diff --git a/ets2panda/checker/types/type.h b/ets2panda/checker/types/type.h index b0a50a0b51..7a62f518a8 100644 --- a/ets2panda/checker/types/type.h +++ b/ets2panda/checker/types/type.h @@ -16,7 +16,6 @@ #ifndef ES2PANDA_COMPILER_CHECKER_TYPES_TYPE_H #define ES2PANDA_COMPILER_CHECKER_TYPES_TYPE_H -#include #include "generated/signatures.h" #include "checker/types/typeMapping.h" #include "checker/types/typeRelation.h" @@ -51,7 +50,6 @@ class Type { public: explicit Type(TypeFlag flag) : typeFlags_(flag) { - std::lock_guard lock(idLock_); static uint32_t typeId = 0; ES2PANDA_ASSERT(typeId < std::numeric_limits::max()); id_ = ++typeId; @@ -61,7 +59,6 @@ public: NO_MOVE_SEMANTIC(Type); virtual ~Type() = default; - static std::mutex idLock_; // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) #define TYPE_IS_CHECKS(typeFlag, typeName) \ diff --git a/ets2panda/ir/astNodeHistory.cpp b/ets2panda/ir/astNodeHistory.cpp index 5d46aea8b2..89a87fad29 100644 --- a/ets2panda/ir/astNodeHistory.cpp +++ b/ets2panda/ir/astNodeHistory.cpp @@ -55,7 +55,6 @@ AstNode *AstNodeHistory::FindForwardEquals(compiler::PhaseId phaseId) // (e.g. find the node history record with `phaseId` equal to a given value) AstNode *AstNodeHistory::At(compiler::PhaseId phaseId) { - std::lock_guard lock(itemMutex_); if (LIKELY(item_->data.phaseId == phaseId)) { // Start searching with last accessed item // In most cases last accessed item is the one we are looking for @@ -73,7 +72,6 @@ AstNode *AstNodeHistory::At(compiler::PhaseId phaseId) // (e.g. find last node history record with `phaseId` less or equal to a given value) AstNode *AstNodeHistory::Get(compiler::PhaseId phaseId) { - std::lock_guard lock(itemMutex_); auto found = FindLessOrEquals(phaseId); if (LIKELY(found != nullptr)) { item_ = found; @@ -86,7 +84,6 @@ AstNode *AstNodeHistory::Get(compiler::PhaseId phaseId) // Find node state at phase with a given ID and set its new value, insert new history record if not found void AstNodeHistory::Set(AstNode *node, compiler::PhaseId phaseId) { - std::lock_guard lock(itemMutex_); HistoryRecord record {node, phaseId}; if (LIKELY(list_.Empty() || list_.Tail()->data.phaseId < phaseId)) { item_ = list_.Append(record); diff --git a/ets2panda/ir/astNodeHistory.h b/ets2panda/ir/astNodeHistory.h index e424046403..ffad5b770d 100644 --- a/ets2panda/ir/astNodeHistory.h +++ b/ets2panda/ir/astNodeHistory.h @@ -16,8 +16,6 @@ #ifndef ES2PANDA_IR_AST_NODE_HISTORY_H #define ES2PANDA_IR_AST_NODE_HISTORY_H -#include - #include "ir/astNode.h" #include "compiler/lowering/phase_id.h" #include "util/doubleLinkedList.h" @@ -50,7 +48,6 @@ private: HistoryList list_; // Node history list HistoryList::Item *item_ {nullptr}; // Last accessed history record - std::mutex itemMutex_ {}; }; } // namespace ark::es2panda::ir #endif -- Gitee