From ba6dea9da2feef0d08d4093c135d7ec2627498b5 Mon Sep 17 00:00:00 2001 From: Mikhail Ivanov Date: Wed, 18 Jun 2025 16:00:53 +0300 Subject: [PATCH] Optimize node history Description: Do not copy Checker data Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICG6HN Signed-off-by: Mikhail Ivanov --- ets2panda/checker/ETSchecker.cpp | 182 ++++++++++++++---- ets2panda/checker/ETSchecker.h | 47 +++-- ets2panda/checker/ets/object.cpp | 57 +++--- ets2panda/checker/ets/typeCreation.cpp | 9 +- .../checker/types/ets/etsFunctionType.cpp | 27 ++- ets2panda/checker/types/ets/etsObjectType.cpp | 33 ++-- ets2panda/compiler/core/ETSemitter.cpp | 4 +- 7 files changed, 243 insertions(+), 116 deletions(-) diff --git a/ets2panda/checker/ETSchecker.cpp b/ets2panda/checker/ETSchecker.cpp index 3cde016475..da043f1b69 100644 --- a/ets2panda/checker/ETSchecker.cpp +++ b/ets2panda/checker/ETSchecker.cpp @@ -60,36 +60,13 @@ void ETSChecker::ReputCheckerData() continue; } readdedChecker_.insert(eChecker->readdedChecker_.begin(), eChecker->readdedChecker_.end()); - auto computedAbstractMapToCopy = eChecker->GetCachedComputedAbstracts(); - for (auto &[key, value] : *computedAbstractMapToCopy) { - if (GetCachedComputedAbstracts()->find(key) != GetCachedComputedAbstracts()->end()) { - continue; - } - auto &[v1, v2] = value; - ArenaVector newV1(Allocator()->Adapter()); - ArenaUnorderedSet newV2(Allocator()->Adapter()); - newV1.assign(v1.cbegin(), v1.cend()); - newV2.insert(v2.cbegin(), v2.cend()); - GetCachedComputedAbstracts()->try_emplace(key, newV1, newV2); - } - - auto &globalArraySigs = eChecker->globalArraySignatures_; - globalArraySignatures_.insert(globalArraySigs.cbegin(), globalArraySigs.cend()); - auto &apparentTypes = eChecker->apparentTypes_; - apparentTypes_.insert(apparentTypes.cbegin(), apparentTypes.cend()); - - auto &objectInstantiationMap = eChecker->objectInstantiationMap_; - for (auto &[key, value] : objectInstantiationMap) { - if (objectInstantiationMap_.find(key) == objectInstantiationMap_.end()) { - objectInstantiationMap_.insert(objectInstantiationMap.cbegin(), objectInstantiationMap.cend()); - } - } - - auto &invokeToArrowSignatures = eChecker->invokeToArrowSignatures_; - invokeToArrowSignatures_.insert(invokeToArrowSignatures.cbegin(), invokeToArrowSignatures.cend()); - auto &arrowToFuncInterfaces = eChecker->arrowToFuncInterfaces_; - arrowToFuncInterfaces_.insert(arrowToFuncInterfaces.cbegin(), arrowToFuncInterfaces.cend()); + linkedCachedComputedAbstracts_.insert(eChecker->cachedComputedAbstracts_); + linkedGlobalArraySignatures_.insert(&eChecker->globalArraySignatures_); + linkedApparentTypes_.insert(&eChecker->apparentTypes_); + linkedObjectInstantiationMap_.insert(&eChecker->objectInstantiationMap_); + linkedInvokeToArrowSignatures_.insert(&eChecker->invokeToArrowSignatures_); + linkedArrowToFuncInterfaces_.insert(&eChecker->arrowToFuncInterfaces_); } } @@ -710,14 +687,153 @@ ETSObjectType *ETSChecker::GlobalBuiltinBoxType(Type *contents) } } -GlobalArraySignatureMap &ETSChecker::GlobalArrayTypes() +Signature *ETSChecker::FindGlobalArrayTypes(const ETSArrayType *key) +{ + if (auto found = globalArraySignatures_.find(key); LIKELY(found != globalArraySignatures_.end())) { + return found->second; + } + + for (auto globalArraySignatures : linkedGlobalArraySignatures_) { + if (auto found = globalArraySignatures->find(key); LIKELY(found != globalArraySignatures->end())) { + return found->second; + } + } + + return nullptr; +} + +Signature *ETSChecker::AddGlobalArrayTypes(const ETSArrayType *key, Signature *value) +{ + return globalArraySignatures_.emplace(key, value).first->second; +} + +void ETSChecker::Iterate(const ETSChecker::GlobalArraySignatureMapTraverser &cb) const +{ + for (auto &[key, value] : globalArraySignatures_) { + cb(key, value); + } + + for (auto globalArraySignatures : linkedGlobalArraySignatures_) { + for (auto &[key, value] : *globalArraySignatures) { + cb(key, value); + } + } +} + +bool ETSChecker::TryFindObjectInstantiationMap(ETSObjectType *key, + ArenaUnorderedMap *&value) +{ + if (auto found = objectInstantiationMap_.find(key); LIKELY(found != objectInstantiationMap_.end())) { + value = &found->second; + return true; + } + + for (auto objectInstantiationMap : linkedObjectInstantiationMap_) { + if (auto found = objectInstantiationMap->find(key); LIKELY(found != objectInstantiationMap->end())) { + value = &found->second; + return true; + } + } + + return false; +} + +ArenaUnorderedMap &ETSChecker::AddObjectInstantiationMap( + ETSObjectType *key, ArenaUnorderedMap &&value) +{ + return objectInstantiationMap_.emplace(key, std::move(value)).first->second; +} + +ETSFunctionType *ETSChecker::FindInvokeToArrowSignatures(ETSFunctionType *key) +{ + if (auto found = invokeToArrowSignatures_.find(key); LIKELY(found != invokeToArrowSignatures_.end())) { + return found->second; + } + + for (auto invokeToArrowSignatures : linkedInvokeToArrowSignatures_) { + if (auto found = invokeToArrowSignatures->find(key); LIKELY(found != invokeToArrowSignatures->end())) { + return found->second; + } + } + + return nullptr; +} + +ETSFunctionType *ETSChecker::AddInvokeToArrowSignatures(ETSFunctionType *key, ETSFunctionType *value) { - return globalArraySignatures_; + return invokeToArrowSignatures_.emplace(key, value).first->second; } -const GlobalArraySignatureMap &ETSChecker::GlobalArrayTypes() const +ETSObjectType *ETSChecker::FindArrowToFuncInterfaces(ETSFunctionType *key) { - return globalArraySignatures_; + if (auto found = arrowToFuncInterfaces_.find(key); LIKELY(found != arrowToFuncInterfaces_.end())) { + return found->second; + } + + for (auto arrowToFuncInterfaces : linkedArrowToFuncInterfaces_) { + if (auto found = arrowToFuncInterfaces->find(key); LIKELY(found != arrowToFuncInterfaces->end())) { + return found->second; + } + } + + return nullptr; +} + +ETSObjectType *ETSChecker::AddArrowToFuncInterfaces(ETSFunctionType *key, ETSObjectType *value) +{ + return arrowToFuncInterfaces_.emplace(key, value).first->second; +} + +Type *ETSChecker::FindApparentTypes(Type const *key) +{ + if (auto found = apparentTypes_.find(key); LIKELY(found != apparentTypes_.end())) { + return found->second; + } + + for (auto apparentTypes : linkedApparentTypes_) { + if (auto found = apparentTypes->find(key); LIKELY(found != apparentTypes->end())) { + return found->second; + } + } + + return nullptr; +} + +Type *ETSChecker::AddApparentTypes(Type const *key, Type *value) +{ + return apparentTypes_.emplace(key, value).first->second; +} + +bool ETSChecker::TryFindCachedComputedAbstracts( + ETSObjectType *key, std::pair, ArenaUnorderedSet> *&value) +{ + if (cachedComputedAbstracts_ == nullptr) { + InitCachedComputedAbstracts(); + } + + if (auto found = cachedComputedAbstracts_->find(key); LIKELY(found != cachedComputedAbstracts_->end())) { + value = &found->second; + return true; + } + + for (auto cachedComputedAbstracts : linkedCachedComputedAbstracts_) { + if (auto found = cachedComputedAbstracts->find(key); LIKELY(found != cachedComputedAbstracts->end())) { + value = &found->second; + return true; + } + } + + return false; +} + +std::pair, ArenaUnorderedSet> &ETSChecker::AddCachedComputedAbstracts( + ETSObjectType *key, std::pair, ArenaUnorderedSet> &&value) +{ + if (cachedComputedAbstracts_ == nullptr) { + InitCachedComputedAbstracts(); + } + + return cachedComputedAbstracts_->emplace(key, value).first->second; } const ArenaSet &ETSChecker::UnionAssemblerTypes() const diff --git a/ets2panda/checker/ETSchecker.h b/ets2panda/checker/ETSchecker.h index 228e199fb0..4844a0852f 100644 --- a/ets2panda/checker/ETSchecker.h +++ b/ets2panda/checker/ETSchecker.h @@ -90,10 +90,15 @@ public: : Checker(allocator, diagnosticEngine, programAllocator), arrayTypes_(Allocator()->Adapter()), objectInstantiationMap_(Allocator()->Adapter()), + linkedObjectInstantiationMap_(Allocator()->Adapter()), invokeToArrowSignatures_(Allocator()->Adapter()), + linkedInvokeToArrowSignatures_(Allocator()->Adapter()), arrowToFuncInterfaces_(Allocator()->Adapter()), + linkedArrowToFuncInterfaces_(Allocator()->Adapter()), globalArraySignatures_(Allocator()->Adapter()), + linkedGlobalArraySignatures_(Allocator()->Adapter()), unionAssemblerTypes_(Allocator()->Adapter()), + linkedCachedComputedAbstracts_(Allocator()->Adapter()), dynamicIntrinsics_ {DynamicCallIntrinsicsMap {Allocator()->Adapter()}, DynamicCallIntrinsicsMap {Allocator()->Adapter()}}, dynamicClasses_ {DynamicClassIntrinsicsMap(Allocator()->Adapter()), @@ -101,6 +106,7 @@ public: dynamicLambdaSignatureCache_(Allocator()->Adapter()), functionalInterfaceCache_(Allocator()->Adapter()), apparentTypes_(Allocator()->Adapter()), + linkedApparentTypes_(Allocator()->Adapter()), dynamicCallNames_ { {DynamicCallNamesMap(Allocator()->Adapter()), DynamicCallNamesMap(Allocator()->Adapter())}}, overloadSigContainer_(Allocator()->Adapter()), @@ -172,8 +178,11 @@ public: ETSObjectType *GlobalBuiltinDynamicType(Language lang) const; - GlobalArraySignatureMap &GlobalArrayTypes(); - const GlobalArraySignatureMap &GlobalArrayTypes() const; + Signature *FindGlobalArrayTypes(const ETSArrayType *key); + Signature *AddGlobalArrayTypes(const ETSArrayType *key, Signature *value); + + using GlobalArraySignatureMapTraverser = std::function; + void Iterate(const GlobalArraySignatureMapTraverser &cb) const; const ArenaSet &UnionAssemblerTypes() const; ArenaSet &UnionAssemblerTypes(); @@ -923,20 +932,19 @@ public: return overloadSigContainer_; } - ObjectInstantiationMap &GetObjectInstantiationMap() - { - return objectInstantiationMap_; - } + bool TryFindObjectInstantiationMap(ETSObjectType *key, + ArenaUnorderedMap *&value); + ArenaUnorderedMap &AddObjectInstantiationMap( + ETSObjectType *key, ArenaUnorderedMap &&value); - FunctionSignatureMap &GetInvokeToArrowSignatures() - { - return invokeToArrowSignatures_; - } + ETSFunctionType *FindInvokeToArrowSignatures(ETSFunctionType *key); + ETSFunctionType *AddInvokeToArrowSignatures(ETSFunctionType *key, ETSFunctionType *value); - FunctionInterfaceMap &GetArrowToFuncInterfaces() - { - return arrowToFuncInterfaces_; - } + ETSObjectType *FindArrowToFuncInterfaces(ETSFunctionType *key); + ETSObjectType *AddArrowToFuncInterfaces(ETSFunctionType *key, ETSObjectType *value); + + Type *FindApparentTypes(Type const *key); + Type *AddApparentTypes(Type const *key, Type *value); void ClearApparentTypes() noexcept { @@ -974,6 +982,11 @@ public: checker::ETSFunctionType *IntersectSignatureSets(const checker::ETSFunctionType *left, const checker::ETSFunctionType *right); + bool TryFindCachedComputedAbstracts( + ETSObjectType *key, std::pair, ArenaUnorderedSet> *&value); + std::pair, ArenaUnorderedSet> &AddCachedComputedAbstracts( + ETSObjectType *key, std::pair, ArenaUnorderedSet> &&value); + ComputedAbstracts *GetCachedComputedAbstracts() { if (cachedComputedAbstracts_ == nullptr) { @@ -1104,18 +1117,24 @@ private: ArrayMap arrayTypes_; std::vector pendingConstraintCheckRecords_ {}; ObjectInstantiationMap objectInstantiationMap_; + ArenaSet linkedObjectInstantiationMap_; FunctionSignatureMap invokeToArrowSignatures_; + ArenaSet linkedInvokeToArrowSignatures_; FunctionInterfaceMap arrowToFuncInterfaces_; + ArenaSet linkedArrowToFuncInterfaces_; size_t constraintCheckScopesCount_ {0}; GlobalArraySignatureMap globalArraySignatures_; + ArenaSet linkedGlobalArraySignatures_; ArenaSet unionAssemblerTypes_; ComputedAbstracts *cachedComputedAbstracts_ {nullptr}; + ArenaSet linkedCachedComputedAbstracts_; // NOTE(aleksisch): Extract dynamic from checker to separate class std::array dynamicIntrinsics_; std::array dynamicClasses_; DynamicLambdaObjectSignatureMap dynamicLambdaSignatureCache_; FunctionalInterfaceMap functionalInterfaceCache_; TypeMapping apparentTypes_; + ArenaSet linkedApparentTypes_; std::array dynamicCallNames_; std::recursive_mutex mtx_; evaluate::ScopedDebugInfoPlugin *debugInfoPlugin_ {nullptr}; diff --git a/ets2panda/checker/ets/object.cpp b/ets2panda/checker/ets/object.cpp index a0628a3398..1aee453ab9 100644 --- a/ets2panda/checker/ets/object.cpp +++ b/ets2panda/checker/ets/object.cpp @@ -814,10 +814,10 @@ void ETSChecker::CreateFunctionTypesFromAbstracts(const std::vector void ETSChecker::ComputeAbstractsFromInterface(ETSObjectType *interfaceType) { - auto cachedComputedAbstracts = GetCachedComputedAbstracts(); - ES2PANDA_ASSERT(cachedComputedAbstracts != nullptr); - auto cached = cachedComputedAbstracts->find(interfaceType); - if (cached != cachedComputedAbstracts->end()) { + ES2PANDA_ASSERT(GetCachedComputedAbstracts() != nullptr); + + std::pair, ArenaUnorderedSet> *found = nullptr; + if (TryFindCachedComputedAbstracts(interfaceType, found)) { return; } @@ -830,21 +830,22 @@ void ETSChecker::ComputeAbstractsFromInterface(ETSObjectType *interfaceType) ArenaUnorderedSet abstractInheritanceTarget(ProgramAllocator()->Adapter()); for (auto *interface : interfaceType->Interfaces()) { - auto found = cachedComputedAbstracts->find(interface); - ES2PANDA_ASSERT(found != cachedComputedAbstracts->end()); + found = nullptr; + TryFindCachedComputedAbstracts(interface, found); + ES2PANDA_ASSERT(found != nullptr); - if (!abstractInheritanceTarget.insert(found->first).second) { + if (!abstractInheritanceTarget.insert(interface).second) { continue; } - MergeComputedAbstracts(merged, found->second.first); + MergeComputedAbstracts(merged, found->first); - for (auto *base : found->second.second) { + for (auto *base : found->second) { abstractInheritanceTarget.insert(base); } } - cachedComputedAbstracts->insert({interfaceType, {merged, abstractInheritanceTarget}}); + AddCachedComputedAbstracts(interfaceType, {merged, abstractInheritanceTarget}); } ArenaVector &ETSChecker::GetAbstractsForClass(ETSObjectType *classType) @@ -854,33 +855,35 @@ ArenaVector &ETSChecker::GetAbstractsForClass(ETSObjectType * ArenaUnorderedSet abstractInheritanceTarget(ProgramAllocator()->Adapter()); if (classType->SuperType() != nullptr) { - auto base = GetCachedComputedAbstracts()->find(classType->SuperType()); - ES2PANDA_ASSERT(base != GetCachedComputedAbstracts()->end()); - MergeComputedAbstracts(merged, base->second.first); + std::pair, ArenaUnorderedSet> *base = nullptr; + TryFindCachedComputedAbstracts(classType->SuperType(), base); + ES2PANDA_ASSERT(base != nullptr); + MergeComputedAbstracts(merged, base->first); - abstractInheritanceTarget.insert(base->first); - for (auto *it : base->second.second) { + abstractInheritanceTarget.insert(classType->SuperType()); + for (auto *it : base->second) { abstractInheritanceTarget.insert(it); } } for (auto *it : classType->Interfaces()) { ComputeAbstractsFromInterface(it); - auto found = GetCachedComputedAbstracts()->find(it); - ES2PANDA_ASSERT(found != GetCachedComputedAbstracts()->end()); + std::pair, ArenaUnorderedSet> *found = nullptr; + TryFindCachedComputedAbstracts(it, found); + ES2PANDA_ASSERT(found != nullptr); - if (!abstractInheritanceTarget.insert(found->first).second) { + if (!abstractInheritanceTarget.insert(it).second) { continue; } - MergeComputedAbstracts(merged, found->second.first); + MergeComputedAbstracts(merged, found->first); - for (auto *interface : found->second.second) { + for (auto *interface : found->second) { abstractInheritanceTarget.insert(interface); } } - return GetCachedComputedAbstracts()->insert({classType, {merged, abstractInheritanceTarget}}).first->second.first; + return AddCachedComputedAbstracts(classType, {merged, abstractInheritanceTarget}).first; } [[maybe_unused]] static bool DoObjectImplementInterface(const ETSObjectType *interfaceType, const ETSObjectType *target, @@ -2620,17 +2623,17 @@ void ETSChecker::AddElementsToModuleObject(ETSObjectType *moduleObj, const util: Type *ETSChecker::GetApparentType(Type *type) { auto currChecker = compiler::GetPhaseManager()->Context()->GetChecker()->AsETSChecker(); - auto &apparentTypes = currChecker->apparentTypes_; - if (auto it = apparentTypes.find(type); LIKELY(it != apparentTypes.end())) { - return it->second; + if (auto found = FindApparentTypes(type); LIKELY(found != nullptr)) { + return found; } - auto cached = [&apparentTypes, type](Type *res) { + auto cached = [currChecker, type](Type *res) { if (type != res) { - apparentTypes.insert({type, res}); + currChecker->AddApparentTypes(type, res); } - return apparentTypes.insert({res, res}).first->second; + currChecker->AddApparentTypes(res, res); + return res; }; ES2PANDA_ASSERT(type != nullptr); diff --git a/ets2panda/checker/ets/typeCreation.cpp b/ets2panda/checker/ets/typeCreation.cpp index 959fcad773..059cd3fbb9 100644 --- a/ets2panda/checker/ets/typeCreation.cpp +++ b/ets2panda/checker/ets/typeCreation.cpp @@ -418,17 +418,16 @@ Signature *ETSChecker::CreateBuiltinArraySignature(const ETSArrayType *arrayType { auto currentChecker = compiler::GetPhaseManager()->Context() != nullptr ? compiler::GetPhaseManager()->Context()->GetChecker() : this; - auto &globalArraySignatures = currentChecker->AsETSChecker()->globalArraySignatures_; - auto res = globalArraySignatures.find(arrayType); - if (res != globalArraySignatures.end()) { - return res->second; + + if (auto found = currentChecker->AsETSChecker()->FindGlobalArrayTypes(arrayType); found != nullptr) { + return found; } auto [internalName, info] = CreateBuiltinArraySignatureInfo(arrayType, dim); auto *signature = CreateSignature(info, GlobalVoidType(), ir::ScriptFunctionFlags::NONE, false); ES2PANDA_ASSERT(signature != nullptr); signature->SetInternalName(internalName); - globalArraySignatures.insert({arrayType, signature}); + currentChecker->AsETSChecker()->AddGlobalArrayTypes(arrayType, signature); return signature; } diff --git a/ets2panda/checker/types/ets/etsFunctionType.cpp b/ets2panda/checker/types/ets/etsFunctionType.cpp index 133c53eee8..9fb3555168 100644 --- a/ets2panda/checker/types/ets/etsFunctionType.cpp +++ b/ets2panda/checker/types/ets/etsFunctionType.cpp @@ -128,16 +128,13 @@ static ETSObjectType *FunctionTypeToFunctionalInterfaceType(ETSChecker *checker, ETSObjectType *ETSFunctionType::ArrowToFunctionalInterface(ETSChecker *checker) { - auto &cached = compiler::GetPhaseManager()->Context()->GetChecker()->AsETSChecker()->GetArrowToFuncInterfaces(); - - auto found = cached.find(this); - if (LIKELY(found != cached.end())) { - return found->second; + if (auto found = + compiler::GetPhaseManager()->Context()->GetChecker()->AsETSChecker()->FindArrowToFuncInterfaces(this); + found != nullptr) { + return found; } - return cached - .emplace(this, - FunctionTypeToFunctionalInterfaceType(checker, ArrowSignature(), ArrowSignature()->MinArgCount())) - .first->second; + return compiler::GetPhaseManager()->Context()->GetChecker()->AsETSChecker()->AddArrowToFuncInterfaces( + this, FunctionTypeToFunctionalInterfaceType(checker, ArrowSignature(), ArrowSignature()->MinArgCount())); } ETSObjectType *ETSFunctionType::ArrowToFunctionalInterfaceDesiredArity(ETSChecker *checker, size_t arity) @@ -150,15 +147,15 @@ ETSObjectType *ETSFunctionType::ArrowToFunctionalInterfaceDesiredArity(ETSChecke ETSFunctionType *ETSFunctionType::MethodToArrow(ETSChecker *checker) { - auto &cached = compiler::GetPhaseManager()->Context()->GetChecker()->AsETSChecker()->GetInvokeToArrowSignatures(); - - auto found = cached.find(this); - if (LIKELY(found != cached.end())) { - return found->second; + if (auto found = + compiler::GetPhaseManager()->Context()->GetChecker()->AsETSChecker()->FindInvokeToArrowSignatures(this); + LIKELY(found != nullptr)) { + return found; } ES2PANDA_ASSERT(!IsETSArrowType() && CallSignatures().size() == 1); - return cached.emplace(this, checker->CreateETSArrowType(CallSignatures()[0])).first->second; + return compiler::GetPhaseManager()->Context()->GetChecker()->AsETSChecker()->AddInvokeToArrowSignatures( + this, checker->CreateETSArrowType(CallSignatures()[0])); } void ETSFunctionType::AddCallSignature(Signature *signature) diff --git a/ets2panda/checker/types/ets/etsObjectType.cpp b/ets2panda/checker/types/ets/etsObjectType.cpp index 1d42b6745b..52cb83281b 100644 --- a/ets2panda/checker/types/ets/etsObjectType.cpp +++ b/ets2panda/checker/types/ets/etsObjectType.cpp @@ -1660,15 +1660,14 @@ void ETSObjectType::CheckVarianceRecursively(TypeRelation *relation, VarianceFla ETSObjectType *ETSObjectType::GetInstantiatedType(util::StringView hash) { - auto &instantiationMap = - compiler::GetPhaseManager()->Context()->GetChecker()->AsETSChecker()->GetObjectInstantiationMap(); - auto found = instantiationMap.find(this); - if (found == instantiationMap.end()) { + auto checker = compiler::GetPhaseManager()->Context()->GetChecker()->AsETSChecker(); + ArenaUnorderedMap *found = nullptr; + if (!checker->TryFindObjectInstantiationMap(this, found)) { return nullptr; } - auto found2 = instantiationMap.at(this).find(hash); - if (found2 == instantiationMap.at(this).end()) { + auto found2 = found->find(hash); + if (found2 == found->end()) { return nullptr; } @@ -1677,21 +1676,15 @@ ETSObjectType *ETSObjectType::GetInstantiatedType(util::StringView hash) void ETSObjectType::InsertInstantiationMap(util::StringView key, ETSObjectType *value) { - auto &instantiationMap = - compiler::GetPhaseManager()->Context()->GetChecker()->AsETSChecker()->GetObjectInstantiationMap(); - if (instantiationMap.find(this) == instantiationMap.end()) { - ArenaUnorderedMap instantiation( - compiler::GetPhaseManager()->Context()->GetChecker()->AsETSChecker()->Allocator()->Adapter()); + auto checker = compiler::GetPhaseManager()->Context()->GetChecker()->AsETSChecker(); + ArenaUnorderedMap *found = nullptr; + if (!checker->TryFindObjectInstantiationMap(this, found)) { + ArenaUnorderedMap instantiation(checker->Allocator()->Adapter()); instantiation.emplace(key, value); - instantiationMap.emplace(this, std::move(instantiation)); - } - compiler::GetPhaseManager() - ->Context() - ->GetChecker() - ->AsETSChecker() - ->GetObjectInstantiationMap() - .at(this) - .try_emplace(key, value); + found = &checker->AddObjectInstantiationMap(this, std::move(instantiation)); + } + + found->try_emplace(key, value); } } // namespace ark::es2panda::checker diff --git a/ets2panda/compiler/core/ETSemitter.cpp b/ets2panda/compiler/core/ETSemitter.cpp index 4da7d669bf..00f5627b5e 100644 --- a/ets2panda/compiler/core/ETSemitter.cpp +++ b/ets2panda/compiler/core/ETSemitter.cpp @@ -290,9 +290,9 @@ void ETSEmitter::GenAnnotation() const auto *checker = static_cast(Context()->GetChecker()); - for (auto [arrType, signature] : checker->GlobalArrayTypes()) { + checker->Iterate([this](const checker::ETSArrayType *arrType, checker::Signature *signature) { GenGlobalArrayRecord(arrType, signature); - } + }); for (auto unionType : checker->UnionAssemblerTypes()) { auto unionRecord = pandasm::Record(unionType.Mutf8(), Program()->lang); unionRecord.metadata->SetAttribute(Signatures::EXTERNAL); -- Gitee