From 89c16a164da287a1f8012445b6c4fa77e4876c7b Mon Sep 17 00:00:00 2001 From: luobohua Date: Fri, 15 Aug 2025 12:04:00 +0800 Subject: [PATCH] ArenaVector optimization v1.0: simple opt Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICQ7OP Change-Id: I03e495c4592d36be3ae951c222faba02f9295a15 Signed-off-by: luobohua --- ets2panda/checker/ETSAnalyzer.cpp | 10 ++-- ets2panda/checker/TSchecker.h | 10 ++-- ets2panda/checker/ets/function.cpp | 4 +- ets2panda/checker/ets/typeCheckingHelpers.cpp | 2 +- ets2panda/checker/ts/function.cpp | 4 +- ets2panda/checker/ts/object.cpp | 16 +++--- ets2panda/compiler/core/ETSCompiler.cpp | 2 +- ets2panda/compiler/core/ETSGen.h | 1 - ets2panda/compiler/core/ETSemitter.cpp | 2 +- .../lowering/ets/exportAnonymousConst.cpp | 2 +- .../compiler/lowering/ets/lambdaLowering.cpp | 10 ++-- .../compiler/lowering/ets/opAssignment.cpp | 12 ++--- .../lowering/ets/stringComparison.cpp | 3 +- .../debugInfoDeserializer.h | 2 +- .../inheritanceResolution.cpp | 4 +- ets2panda/lsp/include/get_adjusted_location.h | 22 ++++----- ets2panda/lsp/include/internal_api.h | 2 +- ets2panda/lsp/src/get_adjusted_location.cpp | 49 ++++++++++--------- ets2panda/lsp/src/internal_api.cpp | 12 ++--- ets2panda/lsp/src/services/services.cpp | 2 +- ets2panda/parser/ETSFormattedParser.cpp | 12 +++++ ets2panda/parser/ETSparser.cpp | 8 +-- ets2panda/parser/ETSparser.h | 8 +-- ets2panda/parser/ETSparserAnnotations.cpp | 2 +- 24 files changed, 106 insertions(+), 95 deletions(-) diff --git a/ets2panda/checker/ETSAnalyzer.cpp b/ets2panda/checker/ETSAnalyzer.cpp index 4498536bb1..4a7cb30c38 100644 --- a/ets2panda/checker/ETSAnalyzer.cpp +++ b/ets2panda/checker/ETSAnalyzer.cpp @@ -766,7 +766,7 @@ checker::Type *ETSAnalyzer::Check(ir::ETSKeyofType *node) const // compile methods for EXPRESSIONS in alphabetical order static void AddSpreadElementTypes(ETSChecker *checker, ir::SpreadElement *const element, - ArenaVector> &elementTypes) + std::vector> &elementTypes) { Type *const spreadType = element->Check(checker); @@ -800,9 +800,9 @@ static bool ValidArrayExprSizeForTupleSize(ETSChecker *checker, Type *possibleTu possibleTupleType->AsETSTupleType()); } -static ArenaVector> GetElementTypes(ETSChecker *checker, ir::ArrayExpression *expr) +static std::vector> GetElementTypes(ETSChecker *checker, ir::ArrayExpression *expr) { - ArenaVector> elementTypes(checker->ProgramAllocator()->Adapter()); + std::vector> elementTypes {}; auto *const exprPreferredType = expr->PreferredType(); auto *const exprTupleType = exprPreferredType->IsETSTupleType() ? exprPreferredType->AsETSTupleType() : nullptr; @@ -844,7 +844,7 @@ static Type *GetArrayElementType(ETSChecker *checker, Type *preferredType) } static bool CheckElement(ETSChecker *checker, Type *const preferredType, - ArenaVector> arrayExprElementTypes, std::size_t idx) + std::vector> arrayExprElementTypes, std::size_t idx) { auto [elementType, currentElement] = arrayExprElementTypes[idx]; @@ -931,7 +931,7 @@ static Type *InferPreferredTypeFromElements(ETSChecker *checker, ir::ArrayExpres static bool CheckArrayExpressionElements(ETSChecker *checker, ir::ArrayExpression *arrayExpr) { - const ArenaVector> arrayExprElementTypes = GetElementTypes(checker, arrayExpr); + const std::vector> arrayExprElementTypes = GetElementTypes(checker, arrayExpr); bool allElementsAssignable = !std::any_of(arrayExprElementTypes.begin(), arrayExprElementTypes.end(), [](auto &pair) { return pair.first->IsTypeError(); }); diff --git a/ets2panda/checker/TSchecker.h b/ets2panda/checker/TSchecker.h index 77756cb489..e608533439 100644 --- a/ets2panda/checker/TSchecker.h +++ b/ets2panda/checker/TSchecker.h @@ -320,11 +320,11 @@ public: // Object void ResolvePropertiesOfObjectType(ObjectType *type, ir::AstNode *member, - ArenaVector &signatureDeclarations, - ArenaVector &indexDeclarations, bool isInterface); + std::vector &signatureDeclarations, + std::vector &indexDeclarations, bool isInterface); void ResolveSignaturesOfObjectType(ObjectType *type, - ArenaVector &signatureDeclarations); - void ResolveIndexInfosOfObjectType(ObjectType *type, ArenaVector &indexDeclarations); + std::vector &signatureDeclarations); + void ResolveIndexInfosOfObjectType(ObjectType *type, std::vector &indexDeclarations); void ResolveDeclaredMembers(InterfaceType *type); bool ValidateInterfaceMemberRedeclaration(ObjectType *type, varbinder::Variable *prop, const lexer::SourcePosition &locInfo); @@ -366,7 +366,7 @@ public: void CreatePatternParameterName(ir::AstNode *node, std::stringstream &ss); void HandlePropertyPatternParameterName(ir::Property *prop, std::stringstream &ss); void ThrowReturnTypeCircularityError(ir::ScriptFunction *func); - ArgRange GetArgRange(const ArenaVector &signatures, ArenaVector *potentialSignatures, + ArgRange GetArgRange(const ArenaVector &signatures, std::vector *potentialSignatures, uint32_t callArgsSize, bool *haveSignatureWithRest); bool CallMatchesSignature(const ArenaVector &args, Signature *signature, bool throwError); Type *ResolveCallOrNewExpression(const ArenaVector &signatures, diff --git a/ets2panda/checker/ets/function.cpp b/ets2panda/checker/ets/function.cpp index 2643ee7f1b..c3c3ba8d45 100644 --- a/ets2panda/checker/ets/function.cpp +++ b/ets2panda/checker/ets/function.cpp @@ -160,7 +160,7 @@ bool ETSChecker::EnhanceSubstitutionForUnion(const ArenaVector &typePara } auto *const argUn = argumentType->AsETSUnionType(); - ArenaVector paramWlist(ProgramAllocator()->Adapter()); + std::vector paramWlist {}; ArenaVector argWlist(ProgramAllocator()->Adapter()); for (auto *pc : paramUn->ConstituentTypes()) { @@ -1554,7 +1554,7 @@ void ETSChecker::CheckObjectLiteralArguments(Signature *signature, ArenaVectorGetOverloadInfoForUpdate(); - ArenaVector overloads(checker->ProgramAllocator()->Adapter()); + std::vector overloads {}; for (ir::MethodDefinition *const currentFunc : method->Overloads()) { if (currentFunc->IsDeclare() != ldInfo.isDeclare) { diff --git a/ets2panda/checker/ets/typeCheckingHelpers.cpp b/ets2panda/checker/ets/typeCheckingHelpers.cpp index a2894f93e9..d32423db48 100644 --- a/ets2panda/checker/ets/typeCheckingHelpers.cpp +++ b/ets2panda/checker/ets/typeCheckingHelpers.cpp @@ -1532,7 +1532,7 @@ bool ETSChecker::CheckLambdaTypeAnnotation(ir::ETSParameterExpression *param, // Preserve actual lambda types ir::ScriptFunction *const lambda = arrowFuncExpr->Function(); - ArenaVector lambdaParamTypes {ProgramAllocator()->Adapter()}; + std::vector lambdaParamTypes {}; for (auto *const lambdaParam : lambda->Params()) { lambdaParamTypes.emplace_back(lambdaParam->AsETSParameterExpression()->Ident()->TypeAnnotation()); } diff --git a/ets2panda/checker/ts/function.cpp b/ets2panda/checker/ts/function.cpp index 7b0634260a..967bdaf008 100644 --- a/ets2panda/checker/ts/function.cpp +++ b/ets2panda/checker/ts/function.cpp @@ -683,7 +683,7 @@ void TSChecker::CheckAllCodePathsInNonVoidFunctionReturnOrThrow(ir::ScriptFuncti } ArgRange TSChecker::GetArgRange(const ArenaVector &signatures, - ArenaVector *potentialSignatures, uint32_t callArgsSize, + std::vector *potentialSignatures, uint32_t callArgsSize, bool *haveSignatureWithRest) { uint32_t minArg = UINT32_MAX; @@ -752,7 +752,7 @@ Type *TSChecker::ResolveCallOrNewExpression(const ArenaVector &sign ThrowTypeError("This expression is not callable.", errPos); } - ArenaVector potentialSignatures(Allocator()->Adapter()); + std::vector potentialSignatures {}; bool haveSignatureWithRest = false; auto argRange = GetArgRange(signatures, &potentialSignatures, arguments.size(), &haveSignatureWithRest); diff --git a/ets2panda/checker/ts/object.cpp b/ets2panda/checker/ts/object.cpp index 0c9e3c25c3..e8c7bc1db6 100644 --- a/ets2panda/checker/ts/object.cpp +++ b/ets2panda/checker/ts/object.cpp @@ -177,8 +177,8 @@ void TSChecker::ResolveObjectTypeMembers(ObjectType *type) ES2PANDA_ASSERT(type->Variable() && type->Variable()->Declaration()->Node()->IsTSTypeLiteral()); auto *typeLiteral = type->Variable()->Declaration()->Node()->AsTSTypeLiteral(); - ArenaVector signatureDeclarations(Allocator()->Adapter()); - ArenaVector indexDeclarations(Allocator()->Adapter()); + std::vector signatureDeclarations {}; + std::vector indexDeclarations {}; for (auto *it : typeLiteral->Members()) { ResolvePropertiesOfObjectType(type, it, signatureDeclarations, indexDeclarations, false); @@ -191,8 +191,8 @@ void TSChecker::ResolveObjectTypeMembers(ObjectType *type) } void TSChecker::ResolvePropertiesOfObjectType(ObjectType *type, ir::AstNode *member, - ArenaVector &signatureDeclarations, - ArenaVector &indexDeclarations, bool isInterface) + std::vector &signatureDeclarations, + std::vector &indexDeclarations, bool isInterface) { if (member->IsTSPropertySignature()) { varbinder::Variable *prop = member->AsTSPropertySignature()->Variable(); @@ -226,7 +226,7 @@ void TSChecker::ResolvePropertiesOfObjectType(ObjectType *type, ir::AstNode *mem } void TSChecker::ResolveSignaturesOfObjectType(ObjectType *type, - ArenaVector &signatureDeclarations) + std::vector &signatureDeclarations) { for (auto *it : signatureDeclarations) { Type *placeholderObj = it->Check(this); @@ -240,7 +240,7 @@ void TSChecker::ResolveSignaturesOfObjectType(ObjectType *type, type->AddConstructSignature(placeholderObj->AsObjectType()->ConstructSignatures()[0]); } } -void TSChecker::ResolveIndexInfosOfObjectType(ObjectType *type, ArenaVector &indexDeclarations) +void TSChecker::ResolveIndexInfosOfObjectType(ObjectType *type, std::vector &indexDeclarations) { for (auto *it : indexDeclarations) { Type *placeholderObj = it->Check(this); @@ -512,8 +512,8 @@ void TSChecker::ResolveDeclaredMembers(InterfaceType *type) ES2PANDA_ASSERT(type->Variable() && type->Variable()->Declaration()->IsInterfaceDecl()); varbinder::InterfaceDecl *decl = type->Variable()->Declaration()->AsInterfaceDecl(); - ArenaVector signatureDeclarations(Allocator()->Adapter()); - ArenaVector indexDeclarations(Allocator()->Adapter()); + std::vector signatureDeclarations {}; + std::vector indexDeclarations {}; for (const auto *declaration : decl->Decls()) { for (auto *member : declaration->Body()->Body()) { diff --git a/ets2panda/compiler/core/ETSCompiler.cpp b/ets2panda/compiler/core/ETSCompiler.cpp index 7f7059aeca..d9d465912d 100644 --- a/ets2panda/compiler/core/ETSCompiler.cpp +++ b/ets2panda/compiler/core/ETSCompiler.cpp @@ -194,7 +194,7 @@ static void ConvertRestArguments(checker::ETSChecker *const checker, const ir::E static void HandleUnionTypeInForOf(compiler::ETSGen *etsg, checker::Type const *const exprType, const ir::ForOfStatement *st, VReg objReg, VReg *countReg) { - ArenaVector