From 08338939a471317678494a97e6468ae47d6aaccc Mon Sep 17 00:00:00 2001 From: Konstantin Shcheglov Date: Wed, 13 Nov 2024 19:52:50 +0000 Subject: [PATCH] Revert "Elements. Don't store 'InstanceElementImpl2.methods', build from 'methods2'." This reverts commit 0df705aafb0f44b5bd292d916470dbb0dc785c96. Reverts: https://dart-review.googlesource.com/c/sdk/+/394563 Bug: https://buganizer.corp.google.com/issues/378850178 Change-Id: Iaa9859f512e1240965a4c222f5d636a3bb0a0912 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/395081 Commit-Queue: Konstantin Shcheglov Reviewed-by: Brian Wilkerson --- .../lib/src/dart/element/element.dart | 62 +++---------------- .../lib/src/summary2/augmentation.dart | 11 ++++ .../lib/src/summary2/bundle_reader.dart | 5 ++ .../lib/src/summary2/bundle_writer.dart | 5 ++ .../src/test_utilities/mock_sdk_elements.dart | 9 +-- .../test/generated/elements_types_mixin.dart | 2 + 6 files changed, 33 insertions(+), 61 deletions(-) diff --git a/pkg/analyzer/lib/src/dart/element/element.dart b/pkg/analyzer/lib/src/dart/element/element.dart index 97ce9dfc91e2..08a726bfa302 100644 --- a/pkg/analyzer/lib/src/dart/element/element.dart +++ b/pkg/analyzer/lib/src/dart/element/element.dart @@ -5359,6 +5359,9 @@ abstract class InstanceElementImpl2 extends ElementImpl2 @override List accessors = []; + @override + List methods = []; + @override List methods2 = []; @@ -5428,42 +5431,6 @@ abstract class InstanceElementImpl2 extends ElementImpl2 @override Metadata get metadata2 => firstFragment.metadata2; - @override - List get methods { - return methods2.map((element) { - var firstTypeParameters = firstFragment.typeParameters; - - var lastFragment = element.lastFragment; - var lastInstance = lastFragment.enclosingFragment; - if (identical(lastInstance, firstFragment)) { - return lastFragment; - } - - var lastTypeParameters = lastInstance.typeParameters2; - if (firstTypeParameters.isEmpty && lastTypeParameters.isEmpty) { - return lastFragment; - } - - MapSubstitution toFirstFragment; - if (lastTypeParameters.length == firstTypeParameters.length) { - toFirstFragment = Substitution.fromPairs( - lastTypeParameters, - firstTypeParameters.instantiateNone(), - ); - } else { - toFirstFragment = Substitution.fromPairs( - lastTypeParameters, - List.filled( - lastTypeParameters.length, - InvalidTypeImpl.instance, - ), - ); - } - - return MethodMember(lastFragment, toFirstFragment, Substitution.empty); - }).toList(); - } - @override String? get name3 => firstFragment.name; @@ -7699,8 +7666,8 @@ class MethodElementImpl extends ExecutableElementImpl } @override - InstanceElementImpl get enclosingFragment => - enclosingElement3 as InstanceElementImpl; + InstanceFragment? get enclosingFragment => + enclosingElement3 as InstanceFragment; /// Set whether this class is abstract. set isAbstract(bool isAbstract) { @@ -7733,7 +7700,7 @@ class MethodElementImpl extends ExecutableElementImpl } @override - MethodElementImpl? get nextFragment => augmentation; + MethodFragment? get nextFragment => augmentation; @override Element get nonSynthetic { @@ -7744,7 +7711,7 @@ class MethodElementImpl extends ExecutableElementImpl } @override - MethodElementImpl? get previousFragment => augmentationTarget; + MethodFragment? get previousFragment => augmentationTarget; @override T? accept(ElementVisitor visitor) => visitor.visitMethodElement(this); @@ -7785,17 +7752,6 @@ class MethodElementImpl2 extends ExecutableElementImpl2 @override ElementKind get kind => ElementKind.METHOD; - MethodElementImpl get lastFragment { - var lastFragment = firstFragment; - while (true) { - if (lastFragment.nextFragment case var nextFragment?) { - lastFragment = nextFragment; - } else { - return lastFragment; - } - } - } - @override T? accept2(ElementVisitor2 visitor) { return visitor.visitMethodElement(this); @@ -10650,8 +10606,8 @@ mixin TypeParameterizedElementMixin on ElementImpl } @override - List get typeParameters2 => - typeParameters.cast(); + List get typeParameters2 => + typeParameters.cast(); List get typeParameters_unresolved { return _typeParameters; diff --git a/pkg/analyzer/lib/src/summary2/augmentation.dart b/pkg/analyzer/lib/src/summary2/augmentation.dart index 22fedae9d604..75ba87652880 100644 --- a/pkg/analyzer/lib/src/summary2/augmentation.dart +++ b/pkg/analyzer/lib/src/summary2/augmentation.dart @@ -269,6 +269,7 @@ abstract class InstanceElementBuilder { augmented.fields = reader.readElementList(); augmented.constructors = reader.readElementList(); augmented.accessors = reader.readElementList(); + augmented.methods = reader.readElementList(); } applyConstantOffsets?.perform(); @@ -371,6 +372,7 @@ class EnumElementLinkedData extends ElementLinkedData { augmented.fields = reader.readElementList(); augmented.constructors = reader.readElementList(); augmented.accessors = reader.readElementList(); + augmented.methods = reader.readElementList(); } applyConstantOffsets?.perform(); } @@ -403,6 +405,7 @@ class ExtensionElementLinkedData var augmented = element.augmentedInternal; augmented.fields = reader.readElementList(); augmented.accessors = reader.readElementList(); + augmented.methods = reader.readElementList(); augmented.extendedType = extendedType; } @@ -439,6 +442,7 @@ class ExtensionTypeElementLinkedData augmented.fields = reader.readElementList(); augmented.accessors = reader.readElementList(); augmented.constructors = reader.readElementList(); + augmented.methods = reader.readElementList(); augmented ..primaryConstructor = element.constructors.first ..representation = element.fields.first @@ -1943,6 +1947,7 @@ class MixinElementLinkedData extends ElementLinkedData { augmented.interfaces = reader._readInterfaceTypeList(); augmented.fields = reader.readElementList(); augmented.accessors = reader.readElementList(); + augmented.methods = reader.readElementList(); } applyConstantOffsets?.perform(); diff --git a/pkg/analyzer/lib/src/summary2/bundle_writer.dart b/pkg/analyzer/lib/src/summary2/bundle_writer.dart index b4c1f391314e..3e002b9a62a8 100644 --- a/pkg/analyzer/lib/src/summary2/bundle_writer.dart +++ b/pkg/analyzer/lib/src/summary2/bundle_writer.dart @@ -165,6 +165,7 @@ class BundleWriter { _resolutionSink._writeElementList(augmented.fields); _resolutionSink._writeElementList(augmented.constructors); _resolutionSink._writeElementList(augmented.accessors); + _resolutionSink._writeElementList(augmented.methods); } if (!element.isMixinApplication) { @@ -257,6 +258,7 @@ class BundleWriter { _resolutionSink._writeElementList(augmented.fields); _resolutionSink._writeElementList(augmented.constructors); _resolutionSink._writeElementList(augmented.accessors); + _resolutionSink._writeElementList(augmented.methods); } _writeList( @@ -318,6 +320,7 @@ class BundleWriter { _resolutionSink.writeType(augmented.extendedType); _resolutionSink._writeElementList(augmented.fields); _resolutionSink._writeElementList(augmented.accessors); + _resolutionSink._writeElementList(augmented.methods); } _writeList( @@ -350,6 +353,7 @@ class BundleWriter { _resolutionSink._writeElementList(augmented.fields); _resolutionSink._writeElementList(augmented.accessors); _resolutionSink._writeElementList(augmented.constructors); + _resolutionSink._writeElementList(augmented.methods); _resolutionSink.writeType(augmented.typeErasure); } @@ -528,6 +532,7 @@ class BundleWriter { _resolutionSink._writeTypeList(augmented.interfaces); _resolutionSink._writeElementList(augmented.fields); _resolutionSink._writeElementList(augmented.accessors); + _resolutionSink._writeElementList(augmented.methods); } _writeList( diff --git a/pkg/analyzer/lib/src/test_utilities/mock_sdk_elements.dart b/pkg/analyzer/lib/src/test_utilities/mock_sdk_elements.dart index 50c1b764736b..33c98788c978 100644 --- a/pkg/analyzer/lib/src/test_utilities/mock_sdk_elements.dart +++ b/pkg/analyzer/lib/src/test_utilities/mock_sdk_elements.dart @@ -925,14 +925,7 @@ class _MockSdkElementsBuilder { element.fields = fragment.fields; element.constructors = fragment.constructors; element.accessors = fragment.accessors; - - element.methods2 = fragment.methods.map((firstFragment) { - return MethodElementImpl2( - Reference.root(), - firstFragment.name2, - firstFragment, - ); - }).toList(); + element.methods = fragment.methods; } LibraryElementImpl _buildCore() { diff --git a/pkg/analyzer/test/generated/elements_types_mixin.dart b/pkg/analyzer/test/generated/elements_types_mixin.dart index 41afb53a1d23..6457d252e675 100644 --- a/pkg/analyzer/test/generated/elements_types_mixin.dart +++ b/pkg/analyzer/test/generated/elements_types_mixin.dart @@ -147,6 +147,7 @@ mixin ElementsTypesMixin { var element = ClassElementImpl2(Reference.root(), fragment); element.mixins = fragment.mixins; element.interfaces = fragment.interfaces; + element.methods = fragment.methods; return fragment; } @@ -433,6 +434,7 @@ mixin ElementsTypesMixin { var element = MixinElementImpl2(Reference.root(), fragment); element.superclassConstraints = fragment.superclassConstraints; element.interfaces = fragment.interfaces; + element.methods = fragment.methods; return fragment; }