Skip to content

Commit

Permalink
Revert "Elements. Don't store 'InstanceElementImpl2.methods', build f…
Browse files Browse the repository at this point in the history
…rom 'methods2'."

This reverts commit 0df705a.

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 <[email protected]>
Reviewed-by: Brian Wilkerson <[email protected]>
  • Loading branch information
scheglov authored and Commit Queue committed Nov 13, 2024
1 parent e227ed2 commit 0833893
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 61 deletions.
62 changes: 9 additions & 53 deletions pkg/analyzer/lib/src/dart/element/element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5359,6 +5359,9 @@ abstract class InstanceElementImpl2 extends ElementImpl2
@override
List<PropertyAccessorElement> accessors = [];

@override
List<MethodElement> methods = [];

@override
List<MethodElementImpl2> methods2 = [];

Expand Down Expand Up @@ -5428,42 +5431,6 @@ abstract class InstanceElementImpl2 extends ElementImpl2
@override
Metadata get metadata2 => firstFragment.metadata2;

@override
List<MethodElement> 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;

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -7733,7 +7700,7 @@ class MethodElementImpl extends ExecutableElementImpl
}

@override
MethodElementImpl? get nextFragment => augmentation;
MethodFragment? get nextFragment => augmentation;

@override
Element get nonSynthetic {
Expand All @@ -7744,7 +7711,7 @@ class MethodElementImpl extends ExecutableElementImpl
}

@override
MethodElementImpl? get previousFragment => augmentationTarget;
MethodFragment? get previousFragment => augmentationTarget;

@override
T? accept<T>(ElementVisitor<T> visitor) => visitor.visitMethodElement(this);
Expand Down Expand Up @@ -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<T>(ElementVisitor2<T> visitor) {
return visitor.visitMethodElement(this);
Expand Down Expand Up @@ -10650,8 +10606,8 @@ mixin TypeParameterizedElementMixin on ElementImpl
}

@override
List<TypeParameterElementImpl> get typeParameters2 =>
typeParameters.cast<TypeParameterElementImpl>();
List<TypeParameterFragment> get typeParameters2 =>
typeParameters.cast<TypeParameterFragment>();

List<TypeParameterElement> get typeParameters_unresolved {
return _typeParameters;
Expand Down
11 changes: 11 additions & 0 deletions pkg/analyzer/lib/src/summary2/augmentation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ abstract class InstanceElementBuilder<E extends InstanceElementImpl2,

augmented.fields.addAll(firstFragment.fields);
augmented.accessors.addAll(firstFragment.accessors);
augmented.methods.addAll(firstFragment.methods);

if (augmented is InterfaceElementImpl2) {
if (firstFragment is InterfaceElementImpl) {
Expand Down Expand Up @@ -358,6 +359,16 @@ abstract class InstanceElementBuilder<E extends InstanceElementImpl2,
element, toFirstFragment, Substitution.empty);
}),
];

element.methods = [
...element.methods.notAugmented,
...augmentation.methods.notAugmented.map((element) {
if (toFirstFragment.map.isEmpty) {
return element;
}
return MethodMember(element, toFirstFragment, Substitution.empty);
}),
];
}
}

Expand Down
5 changes: 5 additions & 0 deletions pkg/analyzer/lib/src/summary2/bundle_reader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ class ClassElementLinkedData extends ElementLinkedData<ClassElementImpl> {
augmented.fields = reader.readElementList();
augmented.constructors = reader.readElementList();
augmented.accessors = reader.readElementList();
augmented.methods = reader.readElementList();
}

applyConstantOffsets?.perform();
Expand Down Expand Up @@ -371,6 +372,7 @@ class EnumElementLinkedData extends ElementLinkedData<EnumElementImpl> {
augmented.fields = reader.readElementList();
augmented.constructors = reader.readElementList();
augmented.accessors = reader.readElementList();
augmented.methods = reader.readElementList();
}
applyConstantOffsets?.perform();
}
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1943,6 +1947,7 @@ class MixinElementLinkedData extends ElementLinkedData<MixinElementImpl> {
augmented.interfaces = reader._readInterfaceTypeList();
augmented.fields = reader.readElementList();
augmented.accessors = reader.readElementList();
augmented.methods = reader.readElementList();
}

applyConstantOffsets?.perform();
Expand Down
5 changes: 5 additions & 0 deletions pkg/analyzer/lib/src/summary2/bundle_writer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -257,6 +258,7 @@ class BundleWriter {
_resolutionSink._writeElementList(augmented.fields);
_resolutionSink._writeElementList(augmented.constructors);
_resolutionSink._writeElementList(augmented.accessors);
_resolutionSink._writeElementList(augmented.methods);
}

_writeList(
Expand Down Expand Up @@ -318,6 +320,7 @@ class BundleWriter {
_resolutionSink.writeType(augmented.extendedType);
_resolutionSink._writeElementList(augmented.fields);
_resolutionSink._writeElementList(augmented.accessors);
_resolutionSink._writeElementList(augmented.methods);
}

_writeList(
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -528,6 +532,7 @@ class BundleWriter {
_resolutionSink._writeTypeList(augmented.interfaces);
_resolutionSink._writeElementList(augmented.fields);
_resolutionSink._writeElementList(augmented.accessors);
_resolutionSink._writeElementList(augmented.methods);
}

_writeList(
Expand Down
9 changes: 1 addition & 8 deletions pkg/analyzer/lib/src/test_utilities/mock_sdk_elements.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 2 additions & 0 deletions pkg/analyzer/test/generated/elements_types_mixin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 0833893

Please sign in to comment.