Skip to content

Commit 72264d1

Browse files
scheglovCommit Queue
authored andcommitted
Add hasEnclosingTypeParameterReference flag.
I plan using this flag to avoid wrapping ExecutableElementImpl of a generic InterfaceElement into ExecutableMember. Currently we have a shortcut to avoid this was non-generic inherited methods, but still wrap anything from a generic, because we don't know whether we need type substitutions. Change-Id: I554cdbbc32dc90b8591f9956eebd9fc4c1e9c1c0 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/420842 Reviewed-by: Paul Berry <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent 9c4dc2e commit 72264d1

19 files changed

+1324
-142
lines changed

pkg/analyzer/lib/src/dart/analysis/driver.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ import 'package:meta/meta.dart';
100100
// TODO(scheglov): Clean up the list of implicitly analyzed files.
101101
class AnalysisDriver {
102102
/// The version of data format, should be incremented on every format change.
103-
static const int DATA_VERSION = 451;
103+
static const int DATA_VERSION = 452;
104104

105105
/// The number of exception contexts allowed to write. Once this field is
106106
/// zero, we stop writing any new exception contexts in this process.

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3638,6 +3638,14 @@ abstract class ExecutableElementImpl extends _ExistingElementImpl
36383638
/// The type of function defined by this executable element.
36393639
FunctionTypeImpl? _type;
36403640

3641+
/// Whether the type of this fragment references a type parameter of the
3642+
/// enclosing element. This includes not only explicitly specified type
3643+
/// annotations, but also inferred types.
3644+
///
3645+
/// Top-level declarations don't have enclosing element type parameters,
3646+
/// so for them this flag is always `false`.
3647+
bool hasEnclosingTypeParameterReference = true;
3648+
36413649
@override
36423650
ElementLinkedData? linkedData;
36433651

@@ -3844,6 +3852,17 @@ abstract class ExecutableElementImpl2 extends FunctionTypedElementImpl2
38443852
...formalParameters,
38453853
];
38463854

3855+
/// Whether the type of this element references a type parameter of the
3856+
/// enclosing element. This includes not only explicitly specified type
3857+
/// annotations, but also inferred types.
3858+
///
3859+
/// Top-level declarations don't have enclosing element type parameters,
3860+
/// so for them this flag is always `false`.
3861+
bool get hasEnclosingTypeParameterReference {
3862+
var firstFragment = this.firstFragment as ExecutableElementImpl;
3863+
return firstFragment.hasEnclosingTypeParameterReference;
3864+
}
3865+
38473866
bool get invokesSuperSelf {
38483867
var firstFragment = this.firstFragment as ExecutableElementImpl;
38493868
return firstFragment.hasModifier(Modifier.INVOKES_SUPER_SELF);
@@ -4195,6 +4214,11 @@ class FieldElementImpl extends PropertyInducingElementImpl
41954214
/// when it overrides a field in a supertype that is covariant.
41964215
bool inheritsCovariant = false;
41974216

4217+
/// Whether the type of this fragment references a type parameter of the
4218+
/// enclosing element. This includes not only explicitly specified type
4219+
/// annotations, but also inferred types.
4220+
bool hasEnclosingTypeParameterReference = true;
4221+
41984222
/// The element corresponding to this fragment.
41994223
FieldElementImpl2? _element;
42004224

@@ -4339,6 +4363,13 @@ class FieldElementImpl2 extends PropertyInducingElementImpl2
43394363
@override
43404364
GetterElementImpl? get getter2 => firstFragment.getter?.element;
43414365

4366+
/// Whether the type of this fragment references a type parameter of the
4367+
/// enclosing element. This includes not only explicitly specified type
4368+
/// annotations, but also inferred types.
4369+
bool get hasEnclosingTypeParameterReference {
4370+
return firstFragment.hasEnclosingTypeParameterReference;
4371+
}
4372+
43424373
@override
43434374
bool get hasImplicitType => firstFragment.hasImplicitType;
43444375

@@ -4354,6 +4385,10 @@ class FieldElementImpl2 extends PropertyInducingElementImpl2
43544385
@override
43554386
bool get isEnumConstant => firstFragment.isEnumConstant;
43564387

4388+
bool get isEnumValues {
4389+
return enclosingElement2 is EnumElementImpl2 && name3 == 'values';
4390+
}
4391+
43574392
@override
43584393
bool get isExternal => firstFragment.isExternal;
43594394

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,10 +1108,14 @@ class LibraryReader {
11081108

11091109
if (!element.isAugmentation) {
11101110
if (getterReference != null) {
1111-
element.createImplicitGetter(getterReference);
1111+
var getter = element.createImplicitGetter(getterReference);
1112+
getter.hasEnclosingTypeParameterReference =
1113+
element.hasEnclosingTypeParameterReference;
11121114
}
11131115
if (element.hasSetter && setterReference != null) {
1114-
element.createImplicitSetter(setterReference);
1116+
var setter = element.createImplicitSetter(setterReference);
1117+
setter.hasEnclosingTypeParameterReference =
1118+
element.hasEnclosingTypeParameterReference;
11151119
}
11161120
}
11171121

@@ -1581,7 +1585,9 @@ class LibraryReader {
15811585
..name2 = accessor.name2
15821586
..isStatic = accessor.isStatic
15831587
..isSynthetic = true
1584-
..isPromotable = isPromotable;
1588+
..isPromotable = isPromotable
1589+
..hasEnclosingTypeParameterReference =
1590+
accessor.hasEnclosingTypeParameterReference;
15851591
propertyFragmentReference.element ??= propertyFragment;
15861592
propertyFragments.add(propertyFragment);
15871593
}
@@ -1662,10 +1668,12 @@ class LibraryReader {
16621668
fragment.typeInferenceError = _readTopLevelInferenceError();
16631669

16641670
if (getterReference != null) {
1665-
fragment.createImplicitGetter(getterReference);
1671+
var getter = fragment.createImplicitGetter(getterReference);
1672+
getter.hasEnclosingTypeParameterReference = false;
16661673
}
16671674
if (fragment.hasSetter && setterReference != null) {
1668-
fragment.createImplicitSetter(setterReference);
1675+
var getter = fragment.createImplicitSetter(setterReference);
1676+
getter.hasEnclosingTypeParameterReference = false;
16691677
}
16701678

16711679
return fragment;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,7 @@ class ElementBuilder extends ThrowingAstVisitor<void> {
410410

411411
// Build the 'values' field.
412412
var valuesField = ConstFieldElementImpl('values', -1)
413+
..hasEnclosingTypeParameterReference = false
413414
..isConst = true
414415
..isStatic = true
415416
..isSynthetic = true

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

Lines changed: 64 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,17 @@ class ClassElementFlags {
5555
}
5656

5757
class ConstructorElementFlags {
58-
static const int _isAugmentation = 1 << 0;
59-
static const int _isConst = 1 << 1;
60-
static const int _isExternal = 1 << 2;
61-
static const int _isFactory = 1 << 3;
62-
static const int _isSynthetic = 1 << 4;
58+
static const int _hasEnclosingTypeParameterReference = 1 << 0;
59+
static const int _isAugmentation = 1 << 1;
60+
static const int _isConst = 1 << 2;
61+
static const int _isExternal = 1 << 3;
62+
static const int _isFactory = 1 << 4;
63+
static const int _isSynthetic = 1 << 5;
6364

6465
static void read(SummaryDataReader reader, ConstructorElementImpl element) {
6566
var byte = reader.readByte();
67+
element.hasEnclosingTypeParameterReference =
68+
(byte & _hasEnclosingTypeParameterReference) != 0;
6669
element.isAugmentation = (byte & _isAugmentation) != 0;
6770
element.isConst = (byte & _isConst) != 0;
6871
element.isExternal = (byte & _isExternal) != 0;
@@ -72,6 +75,9 @@ class ConstructorElementFlags {
7275

7376
static void write(BufferedSink sink, ConstructorElementImpl element) {
7477
var result = 0;
78+
result |= element.hasEnclosingTypeParameterReference
79+
? _hasEnclosingTypeParameterReference
80+
: 0;
7581
result |= element.isAugmentation ? _isAugmentation : 0;
7682
result |= element.isConst ? _isConst : 0;
7783
result |= element.isExternal ? _isExternal : 0;
@@ -150,24 +156,27 @@ class ExtensionTypeElementFlags {
150156
}
151157

152158
class FieldElementFlags {
153-
static const int _hasImplicitType = 1 << 0;
154-
static const int _hasInitializer = 1 << 1;
155-
static const int _inheritsCovariant = 1 << 2;
156-
static const int _isAbstract = 1 << 3;
157-
static const int _isAugmentation = 1 << 4;
158-
static const int _isConst = 1 << 5;
159-
static const int _isCovariant = 1 << 6;
160-
static const int _isEnumConstant = 1 << 7;
161-
static const int _isExternal = 1 << 8;
162-
static const int _isFinal = 1 << 9;
163-
static const int _isLate = 1 << 10;
164-
static const int _isPromotable = 1 << 11;
165-
static const int _shouldUseTypeForInitializerInference = 1 << 12;
166-
static const int _isStatic = 1 << 13;
167-
static const int _isSynthetic = 1 << 14;
159+
static const int _hasEnclosingTypeParameterReference = 1 << 0;
160+
static const int _hasImplicitType = 1 << 1;
161+
static const int _hasInitializer = 1 << 2;
162+
static const int _inheritsCovariant = 1 << 3;
163+
static const int _isAbstract = 1 << 4;
164+
static const int _isAugmentation = 1 << 5;
165+
static const int _isConst = 1 << 6;
166+
static const int _isCovariant = 1 << 7;
167+
static const int _isEnumConstant = 1 << 8;
168+
static const int _isExternal = 1 << 9;
169+
static const int _isFinal = 1 << 10;
170+
static const int _isLate = 1 << 11;
171+
static const int _isPromotable = 1 << 12;
172+
static const int _shouldUseTypeForInitializerInference = 1 << 13;
173+
static const int _isStatic = 1 << 14;
174+
static const int _isSynthetic = 1 << 15;
168175

169176
static void read(SummaryDataReader reader, FieldElementImpl element) {
170177
var byte = reader.readUInt30();
178+
element.hasEnclosingTypeParameterReference =
179+
(byte & _hasEnclosingTypeParameterReference) != 0;
171180
element.hasImplicitType = (byte & _hasImplicitType) != 0;
172181
element.hasInitializer = (byte & _hasInitializer) != 0;
173182
element.inheritsCovariant = (byte & _inheritsCovariant) != 0;
@@ -188,6 +197,9 @@ class FieldElementFlags {
188197

189198
static void write(BufferedSink sink, FieldElementImpl element) {
190199
var result = 0;
200+
result |= element.hasEnclosingTypeParameterReference
201+
? _hasEnclosingTypeParameterReference
202+
: 0;
191203
result |= element.hasImplicitType ? _hasImplicitType : 0;
192204
result |= element.hasInitializer ? _hasInitializer : 0;
193205
result |= element.inheritsCovariant ? _inheritsCovariant : 0;
@@ -275,19 +287,22 @@ class LibraryImportElementFlags {
275287

276288
class MethodElementFlags {
277289
static const int _hasImplicitReturnType = 1 << 0;
278-
static const int _invokesSuperSelf = 1 << 1;
279-
static const int _isAbstract = 1 << 2;
280-
static const int _isAsynchronous = 1 << 3;
281-
static const int _isAugmentation = 1 << 4;
282-
static const int _isExtensionTypeMember = 1 << 5;
283-
static const int _isExternal = 1 << 6;
284-
static const int _isGenerator = 1 << 7;
285-
static const int _isStatic = 1 << 8;
286-
static const int _isSynthetic = 1 << 9;
290+
static const int _hasEnclosingTypeParameterReference = 1 << 1;
291+
static const int _invokesSuperSelf = 1 << 2;
292+
static const int _isAbstract = 1 << 3;
293+
static const int _isAsynchronous = 1 << 4;
294+
static const int _isAugmentation = 1 << 5;
295+
static const int _isExtensionTypeMember = 1 << 6;
296+
static const int _isExternal = 1 << 7;
297+
static const int _isGenerator = 1 << 8;
298+
static const int _isStatic = 1 << 9;
299+
static const int _isSynthetic = 1 << 10;
287300

288301
static void read(SummaryDataReader reader, MethodElementImpl element) {
289302
var bits = reader.readUInt30();
290303
element.hasImplicitReturnType = (bits & _hasImplicitReturnType) != 0;
304+
element.hasEnclosingTypeParameterReference =
305+
(bits & _hasEnclosingTypeParameterReference) != 0;
291306
element.invokesSuperSelf = (bits & _invokesSuperSelf) != 0;
292307
element.isAbstract = (bits & _isAbstract) != 0;
293308
element.isAsynchronous = (bits & _isAsynchronous) != 0;
@@ -302,6 +317,9 @@ class MethodElementFlags {
302317
static void write(BufferedSink sink, MethodElementImpl element) {
303318
var result = 0;
304319
result |= element.hasImplicitReturnType ? _hasImplicitReturnType : 0;
320+
result |= element.hasEnclosingTypeParameterReference
321+
? _hasEnclosingTypeParameterReference
322+
: 0;
305323
result |= element.invokesSuperSelf ? _invokesSuperSelf : 0;
306324
result |= element.isAbstract ? _isAbstract : 0;
307325
result |= element.isAsynchronous ? _isAsynchronous : 0;
@@ -364,17 +382,18 @@ class ParameterElementFlags {
364382
}
365383

366384
class PropertyAccessorElementFlags {
367-
static const int _invokesSuperSelf = 1 << 0;
368-
static const int _isAugmentation = 1 << 1;
369-
static const int _isGetter = 1 << 2;
370-
static const int _isSetter = 1 << 3;
371-
static const int _hasImplicitReturnType = 1 << 4;
372-
static const int _isAbstract = 1 << 5;
373-
static const int _isAsynchronous = 1 << 6;
374-
static const int _isExtensionTypeMember = 1 << 7;
375-
static const int _isExternal = 1 << 8;
376-
static const int _isGenerator = 1 << 9;
377-
static const int _isStatic = 1 << 10;
385+
static const int _hasEnclosingTypeParameterReference = 1 << 0;
386+
static const int _invokesSuperSelf = 1 << 1;
387+
static const int _isAugmentation = 1 << 2;
388+
static const int _isGetter = 1 << 3;
389+
static const int _isSetter = 1 << 4;
390+
static const int _hasImplicitReturnType = 1 << 5;
391+
static const int _isAbstract = 1 << 6;
392+
static const int _isAsynchronous = 1 << 7;
393+
static const int _isExtensionTypeMember = 1 << 8;
394+
static const int _isExternal = 1 << 9;
395+
static const int _isGenerator = 1 << 10;
396+
static const int _isStatic = 1 << 11;
378397

379398
static bool isGetter(int flags) => (flags & _isGetter) != 0;
380399

@@ -388,6 +407,8 @@ class PropertyAccessorElementFlags {
388407

389408
static void setFlagsBasedOnFlagByte(
390409
PropertyAccessorElementImpl element, int byte) {
410+
element.hasEnclosingTypeParameterReference =
411+
(byte & _hasEnclosingTypeParameterReference) != 0;
391412
element.invokesSuperSelf = (byte & _invokesSuperSelf) != 0;
392413
element.isAugmentation = (byte & _isAugmentation) != 0;
393414
element.hasImplicitReturnType = (byte & _hasImplicitReturnType) != 0;
@@ -401,6 +422,9 @@ class PropertyAccessorElementFlags {
401422

402423
static void write(BufferedSink sink, PropertyAccessorElementImpl element) {
403424
var result = 0;
425+
result |= element.hasEnclosingTypeParameterReference
426+
? _hasEnclosingTypeParameterReference
427+
: 0;
404428
result |= element.invokesSuperSelf ? _invokesSuperSelf : 0;
405429
result |= element.isAugmentation ? _isAugmentation : 0;
406430
result |= element.isGetter ? _isGetter : 0;

0 commit comments

Comments
 (0)