Elements. Remove from AugmentedInterfaceElement 'interfaces' and 'mixins'.

Change-Id: I95d4d11c0a5b0a5ccbfe7890f87cf3836a7a39f9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/414182
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
Konstantin Shcheglov
2025-03-06 13:30:33 -08:00
committed by Commit Queue
parent e52b141660
commit 6a7fd7cedb
19 changed files with 33 additions and 134 deletions
-2
View File
@@ -3021,8 +3021,6 @@ package:analyzer/dart/element/element.dart:
new (constructor: AugmentedInterfaceElement Function())
constructors (getter: List<ConstructorElement>)
firstFragment (getter: InterfaceElement)
interfaces (getter: List<InterfaceType>)
mixins (getter: List<InterfaceType>)
thisType (getter: InterfaceType)
unnamedConstructor (getter: ConstructorElement?)
getNamedConstructor (method: ConstructorElement? Function(String))
@@ -157,18 +157,6 @@ abstract class AugmentedInterfaceElement implements AugmentedInstanceElement {
@override
InterfaceElement get firstFragment;
/// The interfaces implemented by this element.
///
/// This is a union of interfaces declared by the class declaration and
/// all its augmentations.
List<InterfaceType> get interfaces;
/// The mixins applied by this class or in its augmentations.
///
/// This is a union of mixins applied by the class declaration and all its
/// augmentations.
List<InterfaceType> get mixins;
@override
InterfaceType get thisType;
@@ -100,7 +100,7 @@ import 'package:meta/meta.dart';
// TODO(scheglov): Clean up the list of implicitly analyzed files.
class AnalysisDriver {
/// The version of data format, should be incremented on every format change.
static const int DATA_VERSION = 435;
static const int DATA_VERSION = 437;
/// The number of exception contexts allowed to write. Once this field is
/// zero, we stop writing any new exception contexts in this process.
+3 -26
View File
@@ -6683,10 +6683,6 @@ abstract class InterfaceElementImpl2 extends InstanceElementImpl2
/// Should be used only when the element has no type parameters.
InterfaceTypeImpl? _nullableInstance;
List<InterfaceTypeImpl> _interfaces = [];
List<InterfaceTypeImpl> _mixins = [];
@override
List<ConstructorElementMixin> constructors = [];
@@ -6746,12 +6742,8 @@ abstract class InterfaceElementImpl2 extends InstanceElementImpl2
.map2;
@override
List<InterfaceTypeImpl> get interfaces => _interfaces;
set interfaces(List<InterfaceType> values) {
// TODO(paulberry): eliminate this cast by changing the type of the `values`
// parameter
_interfaces = values.cast();
List<InterfaceTypeImpl> get interfaces {
return firstFragment.interfaces;
}
set isSimplyBounded(bool value) {
@@ -6762,22 +6754,7 @@ abstract class InterfaceElementImpl2 extends InstanceElementImpl2
@override
List<InterfaceTypeImpl> get mixins {
if (firstFragment.mixinInferenceCallback case var callback?) {
var mixins = callback(firstFragment);
if (mixins != null) {
// TODO(paulberry): eliminate this cast by changing the type of
// `InterfaceElementImpl.mixinInferenceCallback`.
return _mixins = mixins.cast();
}
}
return _mixins;
}
set mixins(List<InterfaceType> value) {
// TODO(paulberry): eliminate this cast by changing the type of the `value`
// parameter.
_mixins = value.cast();
return firstFragment.mixins;
}
@override
@@ -54,9 +54,7 @@ class ElementFactory {
fragment.typeParameters = typeParameters(parameterNames);
}
var element = ClassElementImpl2(Reference.root(), fragment);
element.mixins = fragment.mixins;
element.interfaces = fragment.interfaces;
ClassElementImpl2(Reference.root(), fragment);
return fragment;
}
@@ -83,9 +81,7 @@ class ElementFactory {
fragment.interfaces = interfaces;
fragment.constructors = const <ConstructorElementImpl>[];
var element = ClassElementImpl2(Reference.root(), fragment);
element.mixins = fragment.mixins;
element.interfaces = fragment.interfaces;
ClassElementImpl2(Reference.root(), fragment);
return fragment;
}
@@ -275,8 +275,6 @@ abstract class InstanceElementBuilder<E extends InstanceElementImpl2,
if (element is InterfaceElementImpl2) {
if (firstFragment is InterfaceElementImpl) {
element.mixins.addAll(firstFragment.mixins);
element.interfaces.addAll(firstFragment.interfaces);
element.constructors.addAll(firstFragment.constructors);
}
}
@@ -142,8 +142,6 @@ class ClassElementLinkedData extends ElementLinkedData<ClassElementImpl> {
if (element.augmentationTarget == null) {
var augmented = element.augmentedInternal;
augmented.mixins = reader._readInterfaceTypeList();
augmented.interfaces = reader._readInterfaceTypeList();
augmented.fields = reader.readElementList();
augmented.constructors = reader.readElementList();
augmented.accessors = reader.readElementList();
@@ -382,8 +380,6 @@ class EnumElementLinkedData extends ElementLinkedData<EnumElementImpl> {
element.interfaces = reader._readInterfaceTypeList();
if (element.augmentationTarget == null) {
var augmented = element.augmentedInternal;
augmented.mixins = reader._readInterfaceTypeList();
augmented.interfaces = reader._readInterfaceTypeList();
augmented.fields = reader.readElementList();
augmented.constructors = reader.readElementList();
augmented.accessors = reader.readElementList();
@@ -451,7 +447,6 @@ class ExtensionTypeElementLinkedData
element.interfaces = reader._readInterfaceTypeList();
if (element.augmentationTarget == null) {
var augmented = element.augmentedInternal;
augmented.interfaces = reader._readInterfaceTypeList();
augmented.fields = reader.readElementList();
augmented.accessors = reader.readElementList();
augmented.constructors = reader.readElementList();
@@ -1972,7 +1967,6 @@ class MixinElementLinkedData extends ElementLinkedData<MixinElementImpl> {
if (element.augmentationTarget == null) {
var augmented = element.augmentedInternal;
augmented.superclassConstraints = reader._readInterfaceTypeList();
augmented.interfaces = reader._readInterfaceTypeList();
augmented.fields = reader.readElementList();
augmented.accessors = reader.readElementList();
}
@@ -159,8 +159,6 @@ class BundleWriter {
_resolutionSink._writeTypeList(fragment.interfaces);
if (fragment.augmentationTarget == null) {
var element = fragment.element;
_resolutionSink._writeTypeList(element.mixins);
_resolutionSink._writeTypeList(element.interfaces);
_resolutionSink._writeElementList(element.fields);
_resolutionSink._writeElementList(element.constructors);
_resolutionSink._writeElementList(element.accessors);
@@ -252,8 +250,6 @@ class BundleWriter {
_resolutionSink._writeTypeList(fragment.interfaces);
if (fragment.augmentationTarget == null) {
var element = fragment.element;
_resolutionSink._writeTypeList(element.mixins);
_resolutionSink._writeTypeList(element.interfaces);
_resolutionSink._writeElementList(element.fields);
_resolutionSink._writeElementList(element.constructors);
_resolutionSink._writeElementList(element.accessors);
@@ -346,7 +342,6 @@ class BundleWriter {
_resolutionSink._writeTypeList(fragment.interfaces);
if (fragment.augmentationTarget == null) {
var element = fragment.element;
_resolutionSink._writeTypeList(element.interfaces);
_resolutionSink._writeElementList(element.fields);
_resolutionSink._writeElementList(element.accessors);
_resolutionSink._writeElementList(element.constructors);
@@ -520,7 +515,6 @@ class BundleWriter {
if (fragment.augmentationTarget == null) {
var element = fragment.element;
_resolutionSink._writeTypeList(element.superclassConstraints);
_resolutionSink._writeTypeList(element.interfaces);
_resolutionSink._writeElementList(element.fields);
_resolutionSink._writeElementList(element.accessors);
}
@@ -90,7 +90,7 @@ class _ImplementsNode extends graph.Node<_ImplementsNode> {
var superInterface = typeSystem.isNonNullable(representationType)
? typeSystem.objectNone
: typeSystem.objectQuestion;
element.interfaces = [superInterface];
element.firstFragment.interfaces = [superInterface];
}
}
@@ -153,7 +153,7 @@ class _Node extends graph.Node<_Node> {
element.representation.type = type;
element.typeErasure = type.extensionTypeErasure;
element.interfaces = element.interfaces
element.firstFragment.interfaces = element.interfaces
.whereType<InterfaceType>()
.where(typeSystem.isValidExtensionTypeSuperinterface)
.toFixedList();
@@ -431,10 +431,6 @@ class TypesBuilder {
firstFragment.supertype = superType;
}
}
element.interfaces.addAll(
toFirst.mapInterfaceTypes(fragment.interfaces),
);
}
if (fragment is MixinElementImpl && element is MixinElementImpl2) {
@@ -688,10 +684,6 @@ class _MixinsInference {
}
} finally {
element.mixinInferenceCallback = null;
switch (element.element) {
case InterfaceElementImpl2 augmented:
augmented.mixins.addAll(declarationMixins);
}
}
}
@@ -944,8 +944,6 @@ class _MockSdkElementsBuilder {
void _buildClassElement(ClassElementImpl fragment) {
var element = fragment.element;
element.mixins = fragment.mixins;
element.interfaces = fragment.interfaces;
element.fields = fragment.fields;
element.constructors = fragment.constructors;
element.accessors = fragment.accessors;
@@ -138,9 +138,7 @@ mixin ElementsTypesMixin {
fragment.mixins = mixins;
fragment.methods = methods;
var element = ClassElementImpl2(Reference.root(), fragment);
element.mixins = fragment.mixins;
element.interfaces = fragment.interfaces;
ClassElementImpl2(Reference.root(), fragment);
return fragment;
}
@@ -169,9 +167,6 @@ mixin ElementsTypesMixin {
fragment.methods = methods.map((e) => e.firstFragment).toList();
var element = ClassElementImpl2(Reference.root(), fragment);
element.mixins = fragment.mixins;
element.interfaces = fragment.interfaces;
return element;
}
@@ -258,7 +253,6 @@ mixin ElementsTypesMixin {
element
..representation = field
..typeErasure = representationType
..interfaces = fragment.interfaces
..fields = fragment.fields;
return fragment;
@@ -284,7 +278,6 @@ mixin ElementsTypesMixin {
element
..representation = field
..typeErasure = representationType
..interfaces = fragment.interfaces
..fields = fragment.fields;
return element;
@@ -503,7 +496,6 @@ mixin ElementsTypesMixin {
var element = MixinElementImpl2(Reference.root(), fragment);
element.superclassConstraints = fragment.superclassConstraints;
element.interfaces = fragment.interfaces;
return fragment;
}
@@ -525,7 +517,6 @@ mixin ElementsTypesMixin {
var element = MixinElementImpl2(Reference.root(), fragment);
element.superclassConstraints = fragment.superclassConstraints;
element.interfaces = fragment.interfaces;
return element;
}
@@ -770,16 +761,6 @@ extension ClassElementImpl2Extension on ClassElementImpl2 {
expect(augmentation.typeParameters, isEmpty,
reason: 'Not supported in tests');
interfaces = [
...interfaces,
...augmentation.interfaces,
];
mixins = [
...mixins,
...augmentation.mixins,
];
}
}
}
@@ -795,23 +776,8 @@ extension ClassElementImplExtension on ClassElementImpl {
expect(augmentation.typeParameters, isEmpty,
reason: 'Not supported in tests');
augmentedInternal.interfaces = [
...augmentedInternal.interfaces,
...augmentation.interfaces,
];
augmentedInternal.mixins = [
...augmentedInternal.mixins,
...augmentation.mixins,
];
}
}
void updateElement() {
element.interfaces = interfaces;
element.mixins = mixins;
}
}
extension MixinElementImpl2Extension on MixinElementImpl2 {
@@ -830,11 +796,6 @@ extension MixinElementImpl2Extension on MixinElementImpl2 {
...superclassConstraints,
...augmentation.superclassConstraints,
];
interfaces = [
...interfaces,
...augmentation.interfaces,
];
}
}
}
@@ -855,11 +816,6 @@ extension MixinElementImplExtension on MixinElementImpl {
...augmentedInternal.superclassConstraints,
...augmentation.superclassConstraints,
];
augmentedInternal.interfaces = [
...augmentedInternal.interfaces,
...augmentation.interfaces,
];
}
}
}
@@ -2084,9 +2084,7 @@ class _AbstractTypeSystemTest extends AbstractTypeSystemTest {
fragment.mixins = mixins;
fragment.methods = methods;
var element = ClassElementImpl2(Reference.root(), fragment);
element.mixins = fragment.mixins;
element.interfaces = fragment.interfaces;
ClassElementImpl2(Reference.root(), fragment);
return fragment;
}
@@ -2118,7 +2116,6 @@ class _AbstractTypeSystemTest extends AbstractTypeSystemTest {
var element = MixinElementImpl2(Reference.root(), fragment);
element.superclassConstraints = fragment.superclassConstraints;
element.interfaces = fragment.interfaces;
return fragment;
}
@@ -2971,6 +2971,7 @@ conflicts
''');
}
@SkippedTest() // TODO(scheglov): implement augmentation
test_interface_candidatesConflict_interfaceInAugmentation() async {
var a = newFile('$testPackageLibPath/a.dart', r'''
part 'b.dart';
@@ -127,10 +127,16 @@ class PathToObjectTest extends AbstractTypeSystemTest {
var classC = class_2(name: "C");
var classD = class_2(name: "D");
var classE = class_2(name: "E");
classB.interfaces = <InterfaceType>[interfaceTypeNone(classA)];
classC.interfaces = <InterfaceType>[interfaceTypeNone(classA)];
classD.interfaces = <InterfaceType>[interfaceTypeNone(classC)];
classE.interfaces = <InterfaceType>[
classB.firstFragment.interfaces = <InterfaceType>[
interfaceTypeNone(classA)
];
classC.firstFragment.interfaces = <InterfaceType>[
interfaceTypeNone(classA)
];
classD.firstFragment.interfaces = <InterfaceType>[
interfaceTypeNone(classC)
];
classE.firstFragment.interfaces = <InterfaceType>[
interfaceTypeNone(classB),
interfaceTypeNone(classD)
];
@@ -160,7 +166,9 @@ class PathToObjectTest extends AbstractTypeSystemTest {
var classC = class_2(name: "C", superType: interfaceTypeNone(classA));
var classD = class_2(name: "D", superType: interfaceTypeNone(classC));
var classE = class_2(name: "E", superType: interfaceTypeNone(classB));
classE.interfaces = <InterfaceType>[interfaceTypeNone(classD)];
classE.firstFragment.interfaces = <InterfaceType>[
interfaceTypeNone(classD)
];
// assertion: even though the longest path to Object for typeB is 2, and
// typeE extends typeB, the longest path for typeE is 4 since it also
// implements typeD
@@ -199,8 +207,8 @@ class PathToObjectTest extends AbstractTypeSystemTest {
var classA = class_2(name: "A");
var classB = class_2(name: "B");
var classC = class_2(name: "C");
classB.interfaces = [interfaceTypeNone(classA)];
classC.interfaces = [interfaceTypeNone(classB)];
classB.firstFragment.interfaces = [interfaceTypeNone(classA)];
classC.firstFragment.interfaces = [interfaceTypeNone(classB)];
expect(_toElement(classA), 2);
expect(_toElement(classB), 3);
expect(_toElement(classC), 4);
@@ -2692,6 +2692,7 @@ class SubtypeTest extends _SubtypingTestBase with StringTypes {
);
}
@SkippedTest() // TODO(scheglov): implement augmentation
test_interfaceType_class_augmented_interfaces() {
var A = class_2(name: 'A');
var I = class_2(name: 'I');
@@ -2712,6 +2713,7 @@ class SubtypeTest extends _SubtypingTestBase with StringTypes {
isNotSubtype(I_none, A_none, strT0: 'I', strT1: 'A');
}
@SkippedTest() // TODO(scheglov): implement augmentation
test_interfaceType_class_augmented_mixins() {
var A = class_2(name: 'A');
var M = mixin_2(name: 'M');
@@ -2789,6 +2791,7 @@ class SubtypeTest extends _SubtypingTestBase with StringTypes {
isNotSubtype(A_num, A_int, strT0: "A<num>", strT1: "A<int>");
}
@SkippedTest() // TODO(scheglov): implement augmentation
test_interfaceType_mixin_augmented_interfaces() {
var M = mixin_2(name: 'M');
var I = class_2(name: 'I');
@@ -20539,7 +20539,6 @@ library
supertype: Object
mixins
M<int>
M<int>
constructors
synthetic new
firstFragment: <testLibraryFragment>::@class::S::@constructor::new
@@ -27703,7 +27702,6 @@ library
supertype: A
mixins
M1
M1
constructors
synthetic new
firstFragment: <testLibraryFragment>::@class::C1::@constructor::new
@@ -1527,7 +1527,7 @@ library
primaryConstructor: <testLibraryFragment>::@extensionType::A::@constructor::new
typeErasure: int
interfaces
B
Object
fields
final it @21
reference: <testLibraryFragment>::@extensionType::A::@field::it
@@ -1545,7 +1545,7 @@ library
primaryConstructor: <testLibraryFragment>::@extensionType::B::@constructor::new
typeErasure: int
interfaces
A
Object
fields
final it @62
reference: <testLibraryFragment>::@extensionType::B::@field::it
@@ -1644,7 +1644,7 @@ library
primaryConstructor: <testLibraryFragment>::@extensionType::A::@constructor::new
typeErasure: int
interfaces
A
Object
fields
final it @21
reference: <testLibraryFragment>::@extensionType::A::@field::it
@@ -17,6 +17,7 @@ class AnnotateOverridesTest extends LintRuleTest {
@override
String get lintRule => LintNames.annotate_overrides;
@SkippedTest() // TODO(scheglov): implement augmentation
test_augmentationClass_implementsInterface() async {
var a = newFile('$testPackageLibPath/a.dart', r'''
part 'b.dart';