Skip to content

Commit 0833893

Browse files
scheglovCommit Queue
authored andcommitted
Revert "Elements. Don't store 'InstanceElementImpl2.methods', build from '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]>
1 parent e227ed2 commit 0833893

File tree

6 files changed

+33
-61
lines changed

6 files changed

+33
-61
lines changed

pkg/analyzer/lib/src/dart/element/element.dart

Lines changed: 9 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -5359,6 +5359,9 @@ abstract class InstanceElementImpl2 extends ElementImpl2
53595359
@override
53605360
List<PropertyAccessorElement> accessors = [];
53615361

5362+
@override
5363+
List<MethodElement> methods = [];
5364+
53625365
@override
53635366
List<MethodElementImpl2> methods2 = [];
53645367

@@ -5428,42 +5431,6 @@ abstract class InstanceElementImpl2 extends ElementImpl2
54285431
@override
54295432
Metadata get metadata2 => firstFragment.metadata2;
54305433

5431-
@override
5432-
List<MethodElement> get methods {
5433-
return methods2.map((element) {
5434-
var firstTypeParameters = firstFragment.typeParameters;
5435-
5436-
var lastFragment = element.lastFragment;
5437-
var lastInstance = lastFragment.enclosingFragment;
5438-
if (identical(lastInstance, firstFragment)) {
5439-
return lastFragment;
5440-
}
5441-
5442-
var lastTypeParameters = lastInstance.typeParameters2;
5443-
if (firstTypeParameters.isEmpty && lastTypeParameters.isEmpty) {
5444-
return lastFragment;
5445-
}
5446-
5447-
MapSubstitution toFirstFragment;
5448-
if (lastTypeParameters.length == firstTypeParameters.length) {
5449-
toFirstFragment = Substitution.fromPairs(
5450-
lastTypeParameters,
5451-
firstTypeParameters.instantiateNone(),
5452-
);
5453-
} else {
5454-
toFirstFragment = Substitution.fromPairs(
5455-
lastTypeParameters,
5456-
List.filled(
5457-
lastTypeParameters.length,
5458-
InvalidTypeImpl.instance,
5459-
),
5460-
);
5461-
}
5462-
5463-
return MethodMember(lastFragment, toFirstFragment, Substitution.empty);
5464-
}).toList();
5465-
}
5466-
54675434
@override
54685435
String? get name3 => firstFragment.name;
54695436

@@ -7699,8 +7666,8 @@ class MethodElementImpl extends ExecutableElementImpl
76997666
}
77007667

77017668
@override
7702-
InstanceElementImpl get enclosingFragment =>
7703-
enclosingElement3 as InstanceElementImpl;
7669+
InstanceFragment? get enclosingFragment =>
7670+
enclosingElement3 as InstanceFragment;
77047671

77057672
/// Set whether this class is abstract.
77067673
set isAbstract(bool isAbstract) {
@@ -7733,7 +7700,7 @@ class MethodElementImpl extends ExecutableElementImpl
77337700
}
77347701

77357702
@override
7736-
MethodElementImpl? get nextFragment => augmentation;
7703+
MethodFragment? get nextFragment => augmentation;
77377704

77387705
@override
77397706
Element get nonSynthetic {
@@ -7744,7 +7711,7 @@ class MethodElementImpl extends ExecutableElementImpl
77447711
}
77457712

77467713
@override
7747-
MethodElementImpl? get previousFragment => augmentationTarget;
7714+
MethodFragment? get previousFragment => augmentationTarget;
77487715

77497716
@override
77507717
T? accept<T>(ElementVisitor<T> visitor) => visitor.visitMethodElement(this);
@@ -7785,17 +7752,6 @@ class MethodElementImpl2 extends ExecutableElementImpl2
77857752
@override
77867753
ElementKind get kind => ElementKind.METHOD;
77877754

7788-
MethodElementImpl get lastFragment {
7789-
var lastFragment = firstFragment;
7790-
while (true) {
7791-
if (lastFragment.nextFragment case var nextFragment?) {
7792-
lastFragment = nextFragment;
7793-
} else {
7794-
return lastFragment;
7795-
}
7796-
}
7797-
}
7798-
77997755
@override
78007756
T? accept2<T>(ElementVisitor2<T> visitor) {
78017757
return visitor.visitMethodElement(this);
@@ -10650,8 +10606,8 @@ mixin TypeParameterizedElementMixin on ElementImpl
1065010606
}
1065110607

1065210608
@override
10653-
List<TypeParameterElementImpl> get typeParameters2 =>
10654-
typeParameters.cast<TypeParameterElementImpl>();
10609+
List<TypeParameterFragment> get typeParameters2 =>
10610+
typeParameters.cast<TypeParameterFragment>();
1065510611

1065610612
List<TypeParameterElement> get typeParameters_unresolved {
1065710613
return _typeParameters;

pkg/analyzer/lib/src/summary2/augmentation.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ abstract class InstanceElementBuilder<E extends InstanceElementImpl2,
269269

270270
augmented.fields.addAll(firstFragment.fields);
271271
augmented.accessors.addAll(firstFragment.accessors);
272+
augmented.methods.addAll(firstFragment.methods);
272273

273274
if (augmented is InterfaceElementImpl2) {
274275
if (firstFragment is InterfaceElementImpl) {
@@ -358,6 +359,16 @@ abstract class InstanceElementBuilder<E extends InstanceElementImpl2,
358359
element, toFirstFragment, Substitution.empty);
359360
}),
360361
];
362+
363+
element.methods = [
364+
...element.methods.notAugmented,
365+
...augmentation.methods.notAugmented.map((element) {
366+
if (toFirstFragment.map.isEmpty) {
367+
return element;
368+
}
369+
return MethodMember(element, toFirstFragment, Substitution.empty);
370+
}),
371+
];
361372
}
362373
}
363374

pkg/analyzer/lib/src/summary2/bundle_reader.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ class ClassElementLinkedData extends ElementLinkedData<ClassElementImpl> {
147147
augmented.fields = reader.readElementList();
148148
augmented.constructors = reader.readElementList();
149149
augmented.accessors = reader.readElementList();
150+
augmented.methods = reader.readElementList();
150151
}
151152

152153
applyConstantOffsets?.perform();
@@ -371,6 +372,7 @@ class EnumElementLinkedData extends ElementLinkedData<EnumElementImpl> {
371372
augmented.fields = reader.readElementList();
372373
augmented.constructors = reader.readElementList();
373374
augmented.accessors = reader.readElementList();
375+
augmented.methods = reader.readElementList();
374376
}
375377
applyConstantOffsets?.perform();
376378
}
@@ -403,6 +405,7 @@ class ExtensionElementLinkedData
403405
var augmented = element.augmentedInternal;
404406
augmented.fields = reader.readElementList();
405407
augmented.accessors = reader.readElementList();
408+
augmented.methods = reader.readElementList();
406409
augmented.extendedType = extendedType;
407410
}
408411

@@ -439,6 +442,7 @@ class ExtensionTypeElementLinkedData
439442
augmented.fields = reader.readElementList();
440443
augmented.accessors = reader.readElementList();
441444
augmented.constructors = reader.readElementList();
445+
augmented.methods = reader.readElementList();
442446
augmented
443447
..primaryConstructor = element.constructors.first
444448
..representation = element.fields.first
@@ -1943,6 +1947,7 @@ class MixinElementLinkedData extends ElementLinkedData<MixinElementImpl> {
19431947
augmented.interfaces = reader._readInterfaceTypeList();
19441948
augmented.fields = reader.readElementList();
19451949
augmented.accessors = reader.readElementList();
1950+
augmented.methods = reader.readElementList();
19461951
}
19471952

19481953
applyConstantOffsets?.perform();

pkg/analyzer/lib/src/summary2/bundle_writer.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ class BundleWriter {
165165
_resolutionSink._writeElementList(augmented.fields);
166166
_resolutionSink._writeElementList(augmented.constructors);
167167
_resolutionSink._writeElementList(augmented.accessors);
168+
_resolutionSink._writeElementList(augmented.methods);
168169
}
169170

170171
if (!element.isMixinApplication) {
@@ -257,6 +258,7 @@ class BundleWriter {
257258
_resolutionSink._writeElementList(augmented.fields);
258259
_resolutionSink._writeElementList(augmented.constructors);
259260
_resolutionSink._writeElementList(augmented.accessors);
261+
_resolutionSink._writeElementList(augmented.methods);
260262
}
261263

262264
_writeList(
@@ -318,6 +320,7 @@ class BundleWriter {
318320
_resolutionSink.writeType(augmented.extendedType);
319321
_resolutionSink._writeElementList(augmented.fields);
320322
_resolutionSink._writeElementList(augmented.accessors);
323+
_resolutionSink._writeElementList(augmented.methods);
321324
}
322325

323326
_writeList(
@@ -350,6 +353,7 @@ class BundleWriter {
350353
_resolutionSink._writeElementList(augmented.fields);
351354
_resolutionSink._writeElementList(augmented.accessors);
352355
_resolutionSink._writeElementList(augmented.constructors);
356+
_resolutionSink._writeElementList(augmented.methods);
353357
_resolutionSink.writeType(augmented.typeErasure);
354358
}
355359

@@ -528,6 +532,7 @@ class BundleWriter {
528532
_resolutionSink._writeTypeList(augmented.interfaces);
529533
_resolutionSink._writeElementList(augmented.fields);
530534
_resolutionSink._writeElementList(augmented.accessors);
535+
_resolutionSink._writeElementList(augmented.methods);
531536
}
532537

533538
_writeList(

pkg/analyzer/lib/src/test_utilities/mock_sdk_elements.dart

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -925,14 +925,7 @@ class _MockSdkElementsBuilder {
925925
element.fields = fragment.fields;
926926
element.constructors = fragment.constructors;
927927
element.accessors = fragment.accessors;
928-
929-
element.methods2 = fragment.methods.map((firstFragment) {
930-
return MethodElementImpl2(
931-
Reference.root(),
932-
firstFragment.name2,
933-
firstFragment,
934-
);
935-
}).toList();
928+
element.methods = fragment.methods;
936929
}
937930

938931
LibraryElementImpl _buildCore() {

pkg/analyzer/test/generated/elements_types_mixin.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ mixin ElementsTypesMixin {
147147
var element = ClassElementImpl2(Reference.root(), fragment);
148148
element.mixins = fragment.mixins;
149149
element.interfaces = fragment.interfaces;
150+
element.methods = fragment.methods;
150151

151152
return fragment;
152153
}
@@ -433,6 +434,7 @@ mixin ElementsTypesMixin {
433434
var element = MixinElementImpl2(Reference.root(), fragment);
434435
element.superclassConstraints = fragment.superclassConstraints;
435436
element.interfaces = fragment.interfaces;
437+
element.methods = fragment.methods;
436438

437439
return fragment;
438440
}

0 commit comments

Comments
 (0)