From db34f0a5ffee1b2762daf0cc1ed1452ec2f5c7fd Mon Sep 17 00:00:00 2001 From: Mikhail Ivanov Date: Wed, 11 Jun 2025 15:40:31 +0300 Subject: [PATCH] Optimize node history Description: Do not create unnecessary history records Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICEG1D Signed-off-by: Mikhail Ivanov --- ets2panda/ir/base/classDefinition.cpp | 42 ++++++++++++++----- ets2panda/ir/base/classDefinition.h | 10 +++-- ets2panda/ir/base/classElement.cpp | 8 +++- ets2panda/ir/base/classProperty.cpp | 8 +++- ets2panda/ir/base/methodDefinition.cpp | 12 ++++-- ets2panda/ir/base/scriptFunction.cpp | 22 +++++++--- ets2panda/ir/ets/etsFunctionType.h | 8 +++- ets2panda/ir/ets/etsImportDeclaration.h | 4 +- ets2panda/ir/ets/etsParameterExpression.cpp | 14 +++++-- ets2panda/ir/ets/etsParameterExpression.h | 12 ++++-- ets2panda/ir/ets/etsReExportDeclaration.cpp | 4 +- ets2panda/ir/ets/etsTypeReference.cpp | 4 +- ets2panda/ir/ets/etsTypeReferencePart.cpp | 12 ++++-- ets2panda/ir/expression.h | 4 +- ets2panda/ir/expressions/identifier.cpp | 4 +- ets2panda/ir/module/importDeclaration.cpp | 4 +- .../ir/statements/annotationDeclaration.cpp | 8 +++- .../ir/statements/annotationDeclaration.h | 20 ++++++--- ets2panda/ir/statements/classDeclaration.cpp | 4 +- .../ir/statements/functionDeclaration.cpp | 4 +- ets2panda/ir/ts/tsEnumDeclaration.cpp | 12 ++++-- ets2panda/ir/ts/tsEnumDeclaration.h | 4 +- ets2panda/ir/ts/tsInterfaceDeclaration.cpp | 20 ++++++--- ets2panda/ir/ts/tsInterfaceDeclaration.h | 8 +++- ets2panda/ir/ts/tsTypeAliasDeclaration.cpp | 8 +++- ets2panda/ir/ts/tsTypeParameter.cpp | 12 ++++-- .../ir/ts/tsTypeParameterDeclaration.cpp | 8 +++- 27 files changed, 207 insertions(+), 73 deletions(-) diff --git a/ets2panda/ir/base/classDefinition.cpp b/ets2panda/ir/base/classDefinition.cpp index 5fe57979b3..f097db7d8e 100644 --- a/ets2panda/ir/base/classDefinition.cpp +++ b/ets2panda/ir/base/classDefinition.cpp @@ -31,47 +31,65 @@ namespace ark::es2panda::ir { void ClassDefinition::SetCtor(MethodDefinition *ctor) { - this->GetOrCreateHistoryNodeAs()->ctor_ = ctor; + if (Ctor() != ctor) { + this->GetOrCreateHistoryNodeAs()->ctor_ = ctor; + } } void ClassDefinition::SetTypeParams(TSTypeParameterDeclaration *typeParams) { - this->GetOrCreateHistoryNodeAs()->typeParams_ = typeParams; + if (TypeParams() != typeParams) { + this->GetOrCreateHistoryNodeAs()->typeParams_ = typeParams; + } } void ClassDefinition::SetOrigEnumDecl(TSEnumDeclaration *origEnumDecl) { - this->GetOrCreateHistoryNodeAs()->origEnumDecl_ = origEnumDecl; + if (OrigEnumDecl() != origEnumDecl) { + this->GetOrCreateHistoryNodeAs()->origEnumDecl_ = origEnumDecl; + } } void ClassDefinition::SetAnonClass(ClassDeclaration *anonClass) { - this->GetOrCreateHistoryNodeAs()->anonClass_ = anonClass; + if (GetAnonClass() != anonClass) { + this->GetOrCreateHistoryNodeAs()->anonClass_ = anonClass; + } } void ClassDefinition::SetSuperClass(Expression *superClass) { - this->GetOrCreateHistoryNodeAs()->superClass_ = superClass; + if (SuperClass() != superClass) { + this->GetOrCreateHistoryNodeAs()->superClass_ = superClass; + } } void ClassDefinition::SetSuperTypeParams(TSTypeParameterInstantiation *superTypeParams) { - this->GetOrCreateHistoryNodeAs()->superTypeParams_ = superTypeParams; + if (SuperTypeParams() != superTypeParams) { + this->GetOrCreateHistoryNodeAs()->superTypeParams_ = superTypeParams; + } } void ClassDefinition::SetScope(varbinder::LocalScope *scope) { - this->GetOrCreateHistoryNodeAs()->scope_ = scope; + if (Scope() != scope) { + this->GetOrCreateHistoryNodeAs()->scope_ = scope; + } } void ClassDefinition::SetModifiers(ClassDefinitionModifiers modifiers) { - this->GetOrCreateHistoryNodeAs()->modifiers_ = modifiers; + if (Modifiers() != modifiers) { + this->GetOrCreateHistoryNodeAs()->modifiers_ = modifiers; + } } void ClassDefinition::SetInternalName(util::StringView internalName) { - this->GetOrCreateHistoryNodeAs()->internalName_ = internalName; + if (InternalName() != internalName) { + this->GetOrCreateHistoryNodeAs()->internalName_ = internalName; + } } void ClassDefinition::EmplaceBody(AstNode *body) @@ -292,8 +310,10 @@ void ClassDefinition::Iterate(const NodeTraverser &cb) const void ClassDefinition::SetIdent(ir::Identifier *ident) noexcept { - auto newNode = this->GetOrCreateHistoryNodeAs(); - newNode->ident_ = ident; + if (Ident() != ident) { + auto newNode = this->GetOrCreateHistoryNodeAs(); + newNode->ident_ = ident; + } if (ident != nullptr) { ident->SetParent(this); } diff --git a/ets2panda/ir/base/classDefinition.h b/ets2panda/ir/base/classDefinition.h index fd71f32cd3..d0b39cbc11 100644 --- a/ets2panda/ir/base/classDefinition.h +++ b/ets2panda/ir/base/classDefinition.h @@ -206,10 +206,12 @@ public: void SetSuper(Expression *superClass) { - auto newNode = this->GetOrCreateHistoryNodeAs(); - newNode->superClass_ = superClass; - if (newNode->superClass_ != nullptr) { - newNode->superClass_->SetParent(this); + if (Super() != superClass) { + auto newNode = this->GetOrCreateHistoryNodeAs(); + newNode->superClass_ = superClass; + } + if (superClass != nullptr) { + superClass->SetParent(this); } } diff --git a/ets2panda/ir/base/classElement.cpp b/ets2panda/ir/base/classElement.cpp index 24c42eeb71..e705532b45 100644 --- a/ets2panda/ir/base/classElement.cpp +++ b/ets2panda/ir/base/classElement.cpp @@ -22,12 +22,16 @@ namespace ark::es2panda::ir { void ClassElement::SetOrigEnumMember(TSEnumMember *enumMember) { - this->GetOrCreateHistoryNodeAs()->enumMember_ = enumMember; + if (OriginEnumMember() != enumMember) { + this->GetOrCreateHistoryNodeAs()->enumMember_ = enumMember; + } } void ClassElement::SetKey(Expression *key) { - this->GetOrCreateHistoryNodeAs()->key_ = key; + if (Key() != key) { + this->GetOrCreateHistoryNodeAs()->key_ = key; + } } void ClassElement::EmplaceDecorators(Decorator *decorators) diff --git a/ets2panda/ir/base/classProperty.cpp b/ets2panda/ir/base/classProperty.cpp index 2bacec57d1..4304984ceb 100644 --- a/ets2panda/ir/base/classProperty.cpp +++ b/ets2panda/ir/base/classProperty.cpp @@ -26,12 +26,16 @@ namespace ark::es2panda::ir { void ClassProperty::SetTypeAnnotation(TypeNode *typeAnnotation) { - this->GetOrCreateHistoryNodeAs()->typeAnnotation_ = typeAnnotation; + if (TypeAnnotation() != typeAnnotation) { + this->GetOrCreateHistoryNodeAs()->typeAnnotation_ = typeAnnotation; + } } void ClassProperty::SetDefaultAccessModifier(bool isDefault) { - this->GetOrCreateHistoryNodeAs()->isDefault_ = isDefault; + if (IsDefaultAccessModifier() != isDefault) { + this->GetOrCreateHistoryNodeAs()->isDefault_ = isDefault; + } } void ClassProperty::TransformChildren(const NodeTransformer &cb, std::string_view const transformationName) diff --git a/ets2panda/ir/base/methodDefinition.cpp b/ets2panda/ir/base/methodDefinition.cpp index 6f705a2f97..aa89734abb 100644 --- a/ets2panda/ir/base/methodDefinition.cpp +++ b/ets2panda/ir/base/methodDefinition.cpp @@ -26,17 +26,23 @@ namespace ark::es2panda::ir { void MethodDefinition::SetDefaultAccessModifier(bool isDefault) { - this->GetOrCreateHistoryNodeAs()->isDefault_ = isDefault; + if (IsDefaultAccessModifier() != isDefault) { + this->GetOrCreateHistoryNodeAs()->isDefault_ = isDefault; + } } void MethodDefinition::SetBaseOverloadMethod(MethodDefinition *baseOverloadMethod) { - this->GetOrCreateHistoryNodeAs()->baseOverloadMethod_ = baseOverloadMethod; + if (BaseOverloadMethod() != baseOverloadMethod) { + this->GetOrCreateHistoryNodeAs()->baseOverloadMethod_ = baseOverloadMethod; + } } void MethodDefinition::SetAsyncPairMethod(MethodDefinition *asyncPairMethod) { - this->GetOrCreateHistoryNodeAs()->asyncPairMethod_ = asyncPairMethod; + if (AsyncPairMethod() != asyncPairMethod) { + this->GetOrCreateHistoryNodeAs()->asyncPairMethod_ = asyncPairMethod; + } } ScriptFunction *MethodDefinition::Function() diff --git a/ets2panda/ir/base/scriptFunction.cpp b/ets2panda/ir/base/scriptFunction.cpp index 73ef90390f..c29f50299f 100644 --- a/ets2panda/ir/base/scriptFunction.cpp +++ b/ets2panda/ir/base/scriptFunction.cpp @@ -27,22 +27,30 @@ namespace ark::es2panda::ir { void ScriptFunction::SetBody(AstNode *body) { - this->GetOrCreateHistoryNodeAs()->body_ = body; + if (Body() != body) { + this->GetOrCreateHistoryNodeAs()->body_ = body; + } } void ScriptFunction::SetSignature(checker::Signature *signature) { - this->GetOrCreateHistoryNodeAs()->signature_ = signature; + if (Signature() != signature) { + this->GetOrCreateHistoryNodeAs()->signature_ = signature; + } } void ScriptFunction::SetScope(varbinder::FunctionScope *scope) { - this->GetOrCreateHistoryNodeAs()->scope_ = scope; + if (Scope() != scope) { + this->GetOrCreateHistoryNodeAs()->scope_ = scope; + } } void ScriptFunction::SetPreferredReturnType(checker::Type *preferredReturnType) { - this->GetOrCreateHistoryNodeAs()->preferredReturnType_ = preferredReturnType; + if (GetPreferredReturnType() != preferredReturnType) { + this->GetOrCreateHistoryNodeAs()->preferredReturnType_ = preferredReturnType; + } } void ScriptFunction::EmplaceParams(Expression *params) @@ -174,7 +182,9 @@ std::size_t ScriptFunction::FormalParamsLength() const noexcept void ScriptFunction::SetIdent(Identifier *id) noexcept { - this->GetOrCreateHistoryNodeAs()->id_ = id; + if (Id() != id) { + this->GetOrCreateHistoryNodeAs()->id_ = id; + } id->SetParent(this); } @@ -215,7 +225,7 @@ void ScriptFunction::TransformChildren(const NodeTransformer &cb, std::string_vi } } - GetOrCreateHistoryNode()->AsScriptFunction()->irSignature_.TransformChildren(cb, transformationName); + GetHistoryNode()->AsScriptFunction()->irSignature_.TransformChildren(cb, transformationName); auto const &body = Body(); if (body != nullptr) { diff --git a/ets2panda/ir/ets/etsFunctionType.h b/ets2panda/ir/ets/etsFunctionType.h index 142e16671c..d4b1e02384 100644 --- a/ets2panda/ir/ets/etsFunctionType.h +++ b/ets2panda/ir/ets/etsFunctionType.h @@ -52,7 +52,9 @@ public: void SetScope(varbinder::Scope *scope) { - GetOrCreateHistoryNodeAs()->scope_ = scope; + if (Scope() != scope) { + GetOrCreateHistoryNodeAs()->scope_ = scope; + } } void ClearScope() noexcept override @@ -97,7 +99,9 @@ public: void SetFunctionalInterface(ir::TSInterfaceDeclaration *functionalInterface) { - GetOrCreateHistoryNodeAs()->functionalInterface_ = functionalInterface; + if (FunctionalInterface() != functionalInterface) { + GetOrCreateHistoryNodeAs()->functionalInterface_ = functionalInterface; + } } ir::ScriptFunctionFlags Flags() diff --git a/ets2panda/ir/ets/etsImportDeclaration.h b/ets2panda/ir/ets/etsImportDeclaration.h index 7f7e56683b..1c41189d63 100644 --- a/ets2panda/ir/ets/etsImportDeclaration.h +++ b/ets2panda/ir/ets/etsImportDeclaration.h @@ -79,7 +79,9 @@ public: void SetAssemblerName(util::StringView assemblerName) { - GetOrCreateHistoryNode()->AsETSImportDeclaration()->assemblerName_ = assemblerName; + if (AssemblerName() != assemblerName) { + GetOrCreateHistoryNode()->AsETSImportDeclaration()->assemblerName_ = assemblerName; + } } const util::StringView &AssemblerName() const diff --git a/ets2panda/ir/ets/etsParameterExpression.cpp b/ets2panda/ir/ets/etsParameterExpression.cpp index 672d060e2a..ab9b3e9457 100644 --- a/ets2panda/ir/ets/etsParameterExpression.cpp +++ b/ets2panda/ir/ets/etsParameterExpression.cpp @@ -24,17 +24,23 @@ namespace ark::es2panda::ir { void ETSParameterExpression::SetRequiredParams(size_t extraValue) { - this->GetOrCreateHistoryNodeAs()->extraValue_ = extraValue; + if (GetRequiredParams() != extraValue) { + this->GetOrCreateHistoryNodeAs()->extraValue_ = extraValue; + } } void ETSParameterExpression::SetLexerSaved(util::StringView savedLexer) { - this->GetOrCreateHistoryNodeAs()->savedLexer_ = savedLexer; + if (LexerSaved() != savedLexer) { + this->GetOrCreateHistoryNodeAs()->savedLexer_ = savedLexer; + } } void ETSParameterExpression::SetSpread(SpreadElement *spread) { - this->GetOrCreateHistoryNodeAs()->spread_ = spread; + if (Spread() != spread) { + this->GetOrCreateHistoryNodeAs()->spread_ = spread; + } } ETSParameterExpression::ETSParameterExpression(AnnotatedExpression *const identOrSpread, bool isOptional, @@ -160,12 +166,12 @@ void ETSParameterExpression::TransformChildren(const NodeTransformer &cb, std::s { auto const spread = Spread(); auto const ident = Ident(); - auto newNode = GetOrCreateHistoryNodeAs(); if (IsRestParameter()) { if (auto *transformedNode = cb(spread); spread != transformedNode) { spread->SetTransformedNode(transformationName, transformedNode); SetSpread(transformedNode->AsRestElement()); } + auto newNode = GetOrCreateHistoryNodeAs(); newNode->ident_ = Spread()->Argument()->AsIdentifier(); } else { if (auto *transformedNode = cb(ident); ident != transformedNode) { diff --git a/ets2panda/ir/ets/etsParameterExpression.h b/ets2panda/ir/ets/etsParameterExpression.h index 976e54149f..d72f0a5425 100644 --- a/ets2panda/ir/ets/etsParameterExpression.h +++ b/ets2panda/ir/ets/etsParameterExpression.h @@ -54,7 +54,9 @@ public: void SetIdent(Identifier *ident) noexcept { - this->GetOrCreateHistoryNodeAs()->ident_ = ident; + if (Ident() != ident) { + this->GetOrCreateHistoryNodeAs()->ident_ = ident; + } ident->SetParent(this); } @@ -82,13 +84,17 @@ public: void SetOptional(bool value) noexcept { - this->GetOrCreateHistoryNodeAs()->isOptional_ = value; + if (IsOptional() != value) { + this->GetOrCreateHistoryNodeAs()->isOptional_ = value; + } ES2PANDA_ASSERT(IsOptional() || Initializer() == nullptr); } void SetInitializer(Expression *initExpr) noexcept { - this->GetOrCreateHistoryNodeAs()->initializer_ = initExpr; + if (Initializer() != initExpr) { + this->GetOrCreateHistoryNodeAs()->initializer_ = initExpr; + } ES2PANDA_ASSERT(IsOptional() || Initializer() == nullptr); } diff --git a/ets2panda/ir/ets/etsReExportDeclaration.cpp b/ets2panda/ir/ets/etsReExportDeclaration.cpp index 4475c8b08c..84392ad79f 100644 --- a/ets2panda/ir/ets/etsReExportDeclaration.cpp +++ b/ets2panda/ir/ets/etsReExportDeclaration.cpp @@ -21,7 +21,9 @@ namespace ark::es2panda::ir { void ETSReExportDeclaration::SetETSImportDeclarations(ETSImportDeclaration *etsImportDeclarations) { - this->GetOrCreateHistoryNodeAs()->etsImportDeclarations_ = etsImportDeclarations; + if (GetETSImportDeclarations() != etsImportDeclarations) { + this->GetOrCreateHistoryNodeAs()->etsImportDeclarations_ = etsImportDeclarations; + } } ETSReExportDeclaration::ETSReExportDeclaration(ETSImportDeclaration *etsImportDeclarations, diff --git a/ets2panda/ir/ets/etsTypeReference.cpp b/ets2panda/ir/ets/etsTypeReference.cpp index 7986198c72..b3a644ff25 100644 --- a/ets2panda/ir/ets/etsTypeReference.cpp +++ b/ets2panda/ir/ets/etsTypeReference.cpp @@ -24,7 +24,9 @@ namespace ark::es2panda::ir { void ETSTypeReference::SetPart(ETSTypeReferencePart *part) { - this->GetOrCreateHistoryNodeAs()->part_ = part; + if (Part() != part) { + this->GetOrCreateHistoryNodeAs()->part_ = part; + } } void ETSTypeReference::TransformChildren(const NodeTransformer &cb, std::string_view const transformationName) diff --git a/ets2panda/ir/ets/etsTypeReferencePart.cpp b/ets2panda/ir/ets/etsTypeReferencePart.cpp index 9dbef072a2..e13abc71a7 100644 --- a/ets2panda/ir/ets/etsTypeReferencePart.cpp +++ b/ets2panda/ir/ets/etsTypeReferencePart.cpp @@ -25,17 +25,23 @@ namespace ark::es2panda::ir { void ETSTypeReferencePart::SetName(Expression *name) { - this->GetOrCreateHistoryNodeAs()->name_ = name; + if (Name() != name) { + this->GetOrCreateHistoryNodeAs()->name_ = name; + } } void ETSTypeReferencePart::SetTypeParams(TSTypeParameterInstantiation *typeParams) { - this->GetOrCreateHistoryNodeAs()->typeParams_ = typeParams; + if (TypeParams() != typeParams) { + this->GetOrCreateHistoryNodeAs()->typeParams_ = typeParams; + } } void ETSTypeReferencePart::SetPrevious(ETSTypeReferencePart *prev) { - this->GetOrCreateHistoryNodeAs()->prev_ = prev; + if (Previous() != prev) { + this->GetOrCreateHistoryNodeAs()->prev_ = prev; + } } void ETSTypeReferencePart::TransformChildren(const NodeTransformer &cb, std::string_view const transformationName) diff --git a/ets2panda/ir/expression.h b/ets2panda/ir/expression.h index 00c10eaec8..517319a6ae 100644 --- a/ets2panda/ir/expression.h +++ b/ets2panda/ir/expression.h @@ -157,7 +157,9 @@ public: void ClearOptional() noexcept { - GetOrCreateHistoryNodeAs()->optional_ = false; + if (IsOptional()) { + GetOrCreateHistoryNodeAs()->optional_ = false; + } } protected: diff --git a/ets2panda/ir/expressions/identifier.cpp b/ets2panda/ir/expressions/identifier.cpp index 7689fcca37..a108dda5c4 100644 --- a/ets2panda/ir/expressions/identifier.cpp +++ b/ets2panda/ir/expressions/identifier.cpp @@ -60,7 +60,9 @@ Identifier::Identifier(util::StringView const name, TypeNode *const typeAnnotati void Identifier::SetName(const util::StringView &newName) noexcept { ES2PANDA_ASSERT(newName != ERROR_LITERAL); - GetOrCreateHistoryNodeAs()->name_ = newName; + if (Name() != newName) { + GetOrCreateHistoryNodeAs()->name_ = newName; + } } Identifier *Identifier::Clone(ArenaAllocator *const allocator, AstNode *const parent) diff --git a/ets2panda/ir/module/importDeclaration.cpp b/ets2panda/ir/module/importDeclaration.cpp index 161970f5f5..b9251485dd 100644 --- a/ets2panda/ir/module/importDeclaration.cpp +++ b/ets2panda/ir/module/importDeclaration.cpp @@ -26,7 +26,9 @@ namespace ark::es2panda::ir { void ImportDeclaration::SetSource(StringLiteral *source) { - this->GetOrCreateHistoryNodeAs()->source_ = source; + if (Source() != source) { + this->GetOrCreateHistoryNodeAs()->source_ = source; + } } void ImportDeclaration::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) diff --git a/ets2panda/ir/statements/annotationDeclaration.cpp b/ets2panda/ir/statements/annotationDeclaration.cpp index f353444a46..d94ecdc4cb 100644 --- a/ets2panda/ir/statements/annotationDeclaration.cpp +++ b/ets2panda/ir/statements/annotationDeclaration.cpp @@ -24,12 +24,16 @@ namespace ark::es2panda::ir { void AnnotationDeclaration::SetInternalName(util::StringView internalName) { - this->GetOrCreateHistoryNodeAs()->internalName_ = internalName; + if (InternalName() != internalName) { + this->GetOrCreateHistoryNodeAs()->internalName_ = internalName; + } } void AnnotationDeclaration::SetExpr(Expression *expr) { - this->GetOrCreateHistoryNodeAs()->expr_ = expr; + if (Expr() != expr) { + this->GetOrCreateHistoryNodeAs()->expr_ = expr; + } } void AnnotationDeclaration::EmplaceProperties(AstNode *properties) diff --git a/ets2panda/ir/statements/annotationDeclaration.h b/ets2panda/ir/statements/annotationDeclaration.h index c3d3b8f2f2..3d3f845abd 100644 --- a/ets2panda/ir/statements/annotationDeclaration.h +++ b/ets2panda/ir/statements/annotationDeclaration.h @@ -105,17 +105,23 @@ public: void SetSourceRetention() noexcept { - GetOrCreateHistoryNodeAs()->policy_ = RetentionPolicy::SOURCE; + if (Policy() != RetentionPolicy::SOURCE) { + GetOrCreateHistoryNodeAs()->policy_ = RetentionPolicy::SOURCE; + } } void SetBytecodeRetention() noexcept { - GetOrCreateHistoryNodeAs()->policy_ = RetentionPolicy::BYTECODE; + if (Policy() != RetentionPolicy::BYTECODE) { + GetOrCreateHistoryNodeAs()->policy_ = RetentionPolicy::BYTECODE; + } } void SetRuntimeRetention() noexcept { - GetOrCreateHistoryNodeAs()->policy_ = RetentionPolicy::RUNTIME; + if (Policy() != RetentionPolicy::RUNTIME) { + GetOrCreateHistoryNodeAs()->policy_ = RetentionPolicy::RUNTIME; + } } void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; @@ -145,12 +151,16 @@ public: void SetScope(varbinder::LocalScope *scope) { ES2PANDA_ASSERT(scope_ == nullptr); - GetOrCreateHistoryNodeAs()->scope_ = scope; + if (Scope() != scope) { + GetOrCreateHistoryNodeAs()->scope_ = scope; + } } void ClearScope() noexcept override { - GetOrCreateHistoryNodeAs()->scope_ = nullptr; + if (Scope() != nullptr) { + GetOrCreateHistoryNodeAs()->scope_ = nullptr; + } } Identifier *GetBaseName() const; diff --git a/ets2panda/ir/statements/classDeclaration.cpp b/ets2panda/ir/statements/classDeclaration.cpp index 398e74f231..8c18aad407 100644 --- a/ets2panda/ir/statements/classDeclaration.cpp +++ b/ets2panda/ir/statements/classDeclaration.cpp @@ -26,7 +26,9 @@ namespace ark::es2panda::ir { void ClassDeclaration::SetDefinition(ClassDefinition *def) { - this->GetOrCreateHistoryNodeAs()->def_ = def; + if (Definition() != def) { + this->GetOrCreateHistoryNodeAs()->def_ = def; + } } ClassDeclaration *ClassDeclaration::Construct(ArenaAllocator *allocator) diff --git a/ets2panda/ir/statements/functionDeclaration.cpp b/ets2panda/ir/statements/functionDeclaration.cpp index be0f1341c4..ac818c46be 100644 --- a/ets2panda/ir/statements/functionDeclaration.cpp +++ b/ets2panda/ir/statements/functionDeclaration.cpp @@ -26,7 +26,9 @@ namespace ark::es2panda::ir { void FunctionDeclaration::SetFunction(ScriptFunction *func) { - this->GetOrCreateHistoryNodeAs()->func_ = func; + if (Function() != func) { + this->GetOrCreateHistoryNodeAs()->func_ = func; + } } void FunctionDeclaration::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) diff --git a/ets2panda/ir/ts/tsEnumDeclaration.cpp b/ets2panda/ir/ts/tsEnumDeclaration.cpp index c3d9c28f02..b7e2a03548 100644 --- a/ets2panda/ir/ts/tsEnumDeclaration.cpp +++ b/ets2panda/ir/ts/tsEnumDeclaration.cpp @@ -28,17 +28,23 @@ namespace ark::es2panda::ir { void TSEnumDeclaration::SetInternalName(util::StringView internalName) { - this->GetOrCreateHistoryNodeAs()->internalName_ = internalName; + if (InternalName() != internalName) { + this->GetOrCreateHistoryNodeAs()->internalName_ = internalName; + } } void TSEnumDeclaration::SetBoxedClass(ClassDefinition *boxedClass) { - this->GetOrCreateHistoryNodeAs()->boxedClass_ = boxedClass; + if (BoxedClass() != boxedClass) { + this->GetOrCreateHistoryNodeAs()->boxedClass_ = boxedClass; + } } void TSEnumDeclaration::SetKey(Identifier *key) { - this->GetOrCreateHistoryNodeAs()->key_ = key; + if (Key() != key) { + this->GetOrCreateHistoryNodeAs()->key_ = key; + } } void TSEnumDeclaration::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) diff --git a/ets2panda/ir/ts/tsEnumDeclaration.h b/ets2panda/ir/ts/tsEnumDeclaration.h index 87bb7c13fd..ce4b412c49 100644 --- a/ets2panda/ir/ts/tsEnumDeclaration.h +++ b/ets2panda/ir/ts/tsEnumDeclaration.h @@ -89,7 +89,9 @@ public: void SetScope(varbinder::LocalScope *scope) { ES2PANDA_ASSERT(Scope() == nullptr); - GetOrCreateHistoryNode()->AsTSEnumDeclaration()->scope_ = scope; + if (Scope() != scope) { + GetOrCreateHistoryNode()->AsTSEnumDeclaration()->scope_ = scope; + } } void ClearScope() noexcept override diff --git a/ets2panda/ir/ts/tsInterfaceDeclaration.cpp b/ets2panda/ir/ts/tsInterfaceDeclaration.cpp index 4455a8b776..cfb89b5030 100644 --- a/ets2panda/ir/ts/tsInterfaceDeclaration.cpp +++ b/ets2panda/ir/ts/tsInterfaceDeclaration.cpp @@ -37,27 +37,37 @@ namespace ark::es2panda::ir { void TSInterfaceDeclaration::SetInternalName(util::StringView internalName) { - this->GetOrCreateHistoryNodeAs()->internalName_ = internalName; + if (InternalName() != internalName) { + this->GetOrCreateHistoryNodeAs()->internalName_ = internalName; + } } void TSInterfaceDeclaration::SetAnonClass(ClassDeclaration *anonClass) { - this->GetOrCreateHistoryNodeAs()->anonClass_ = anonClass; + if (GetAnonClass() != anonClass) { + this->GetOrCreateHistoryNodeAs()->anonClass_ = anonClass; + } } void TSInterfaceDeclaration::SetId(Identifier *id) { - this->GetOrCreateHistoryNodeAs()->id_ = id; + if (Id() != id) { + this->GetOrCreateHistoryNodeAs()->id_ = id; + } } void TSInterfaceDeclaration::SetTypeParams(TSTypeParameterDeclaration *typeParams) { - this->GetOrCreateHistoryNodeAs()->typeParams_ = typeParams; + if (TypeParams() != typeParams) { + this->GetOrCreateHistoryNodeAs()->typeParams_ = typeParams; + } } void TSInterfaceDeclaration::SetBody(TSInterfaceBody *body) { - this->GetOrCreateHistoryNodeAs()->body_ = body; + if (Body() != body) { + this->GetOrCreateHistoryNodeAs()->body_ = body; + } } void TSInterfaceDeclaration::EmplaceExtends(TSInterfaceHeritage *extends) diff --git a/ets2panda/ir/ts/tsInterfaceDeclaration.h b/ets2panda/ir/ts/tsInterfaceDeclaration.h index 64e6a30e70..372f0b3595 100644 --- a/ets2panda/ir/ts/tsInterfaceDeclaration.h +++ b/ets2panda/ir/ts/tsInterfaceDeclaration.h @@ -96,12 +96,16 @@ public: void SetScope(varbinder::LocalScope *scope) { ES2PANDA_ASSERT(Scope() == nullptr); - GetOrCreateHistoryNode()->AsTSInterfaceDeclaration()->scope_ = scope; + if (Scope() != scope) { + GetOrCreateHistoryNode()->AsTSInterfaceDeclaration()->scope_ = scope; + } } void ClearScope() noexcept override { - GetOrCreateHistoryNode()->AsTSInterfaceDeclaration()->scope_ = nullptr; + if (Scope() != nullptr) { + GetOrCreateHistoryNode()->AsTSInterfaceDeclaration()->scope_ = nullptr; + } } TSInterfaceBody *Body() diff --git a/ets2panda/ir/ts/tsTypeAliasDeclaration.cpp b/ets2panda/ir/ts/tsTypeAliasDeclaration.cpp index 75532d6015..25eabad9bf 100644 --- a/ets2panda/ir/ts/tsTypeAliasDeclaration.cpp +++ b/ets2panda/ir/ts/tsTypeAliasDeclaration.cpp @@ -30,12 +30,16 @@ namespace ark::es2panda::ir { void TSTypeAliasDeclaration::SetTypeParameters(TSTypeParameterDeclaration *typeParams) { - this->GetOrCreateHistoryNodeAs()->typeParams_ = typeParams; + if (TypeParams() != typeParams) { + this->GetOrCreateHistoryNodeAs()->typeParams_ = typeParams; + } } void TSTypeAliasDeclaration::SetId(Identifier *id) { - this->GetOrCreateHistoryNodeAs()->id_ = id; + if (Id() != id) { + this->GetOrCreateHistoryNodeAs()->id_ = id; + } } void TSTypeAliasDeclaration::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) diff --git a/ets2panda/ir/ts/tsTypeParameter.cpp b/ets2panda/ir/ts/tsTypeParameter.cpp index 4a8d253809..3ca406011a 100644 --- a/ets2panda/ir/ts/tsTypeParameter.cpp +++ b/ets2panda/ir/ts/tsTypeParameter.cpp @@ -28,17 +28,23 @@ namespace ark::es2panda::ir { void TSTypeParameter::SetConstraint(TypeNode *constraint) { - this->GetOrCreateHistoryNodeAs()->constraint_ = constraint; + if (Constraint() != constraint) { + this->GetOrCreateHistoryNodeAs()->constraint_ = constraint; + } } void TSTypeParameter::SetDefaultType(TypeNode *defaultType) { - this->GetOrCreateHistoryNodeAs()->defaultType_ = defaultType; + if (DefaultType() != defaultType) { + this->GetOrCreateHistoryNodeAs()->defaultType_ = defaultType; + } } void TSTypeParameter::SetName(Identifier *name) { - this->GetOrCreateHistoryNodeAs()->name_ = name; + if (Name() != name) { + this->GetOrCreateHistoryNodeAs()->name_ = name; + } } void TSTypeParameter::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) diff --git a/ets2panda/ir/ts/tsTypeParameterDeclaration.cpp b/ets2panda/ir/ts/tsTypeParameterDeclaration.cpp index b6d5744998..93b379dfe9 100644 --- a/ets2panda/ir/ts/tsTypeParameterDeclaration.cpp +++ b/ets2panda/ir/ts/tsTypeParameterDeclaration.cpp @@ -26,12 +26,16 @@ namespace ark::es2panda::ir { void TSTypeParameterDeclaration::SetScope(varbinder::LocalScope *source) { - this->GetOrCreateHistoryNodeAs()->scope_ = source; + if (Scope() != source) { + this->GetOrCreateHistoryNodeAs()->scope_ = source; + } } void TSTypeParameterDeclaration::SetRequiredParams(size_t source) { - this->GetOrCreateHistoryNodeAs()->requiredParams_ = source; + if (RequiredParams() != source) { + this->GetOrCreateHistoryNodeAs()->requiredParams_ = source; + } } void TSTypeParameterDeclaration::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) -- Gitee