Skip to content

Commit 9425a79

Browse files
scheglovCommit Queue
authored andcommitted
Elements. Move superConstructor property into ConstructorElementImpl.
Use ConstructorElementMixin2 as its type. All resolution is always base on element, so here we stop using fragments, and stop storing this information in fragments. Change-Id: Ide073eb3f5efd3fa1afaac855beb092c114e304f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/436162 Reviewed-by: Paul Berry <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent 54d80f6 commit 9425a79

File tree

13 files changed

+348
-252
lines changed

13 files changed

+348
-252
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ testFineAfterLibraryAnalyzerHook;
110110
// TODO(scheglov): Clean up the list of implicitly analyzed files.
111111
class AnalysisDriver {
112112
/// The version of data format, should be incremented on every format change.
113-
static const int DATA_VERSION = 479;
113+
static const int DATA_VERSION = 480;
114114

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

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

Lines changed: 175 additions & 204 deletions
Large diffs are not rendered by default.

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

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,13 @@ class ConstructorMember extends ExecutableMember
108108
Source get source => _declaration.source!;
109109

110110
ConstructorElementMixin? get superConstructor {
111-
var element = declaration.superConstructor;
112-
return _redirect(element);
111+
var element = declaration.element.superConstructor2;
112+
return _redirect(element?.firstFragment as ConstructorElementMixin?);
113113
}
114114

115115
@override
116116
ConstructorElementMixin2? get superConstructor2 {
117-
return superConstructor?.asElement2;
117+
return _redirect2(declaration.element.superConstructor2);
118118
}
119119

120120
@override
@@ -151,6 +151,27 @@ class ConstructorMember extends ExecutableMember
151151
}
152152
}
153153

154+
ConstructorElementMixin2? _redirect2(ConstructorElementMixin2? element) {
155+
switch (element) {
156+
case null:
157+
return null;
158+
case ConstructorElementImpl():
159+
return element;
160+
case ConstructorMember():
161+
var memberMap = element.substitution.map;
162+
var map = <TypeParameterElement, DartType>{
163+
for (var MapEntry(:key, :value) in memberMap.entries)
164+
key: substitution.substituteType(value),
165+
};
166+
return ConstructorMember(
167+
declaration: element.declaration,
168+
substitution: Substitution.fromMap2(map),
169+
);
170+
default:
171+
throw UnimplementedError('(${element.runtimeType}) $element');
172+
}
173+
}
174+
154175
/// If the given [element]'s type is different when any type parameters
155176
/// from the defining type's declaration are replaced with the actual type
156177
/// arguments from the [definingType], create a constructor member
@@ -1394,17 +1415,17 @@ class SuperFormalParameterMember extends ParameterMember
13941415
bool get isCovariant => declaration.isCovariant;
13951416

13961417
@override
1397-
ParameterElementMixin? get superConstructorParameter {
1418+
FormalParameterElementMixin? get superConstructorParameter {
13981419
var superConstructorParameter = declaration.superConstructorParameter;
13991420
if (superConstructorParameter == null) {
14001421
return null;
14011422
}
14021423

1403-
return ParameterMember.from(superConstructorParameter, substitution);
1424+
return ParameterMember.from2(superConstructorParameter, substitution);
14041425
}
14051426

14061427
FormalParameterElement? get superConstructorParameter2 =>
1407-
superConstructorParameter?.asElement2;
1428+
superConstructorParameter;
14081429
}
14091430

14101431
/// A variable element defined in a parameterized type where the values of the

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,11 +355,24 @@ class LibraryReader {
355355
var reference = _readReference();
356356
var fragments = _readFragmentsById<ConstructorFragmentImpl>();
357357
// TODO(scheglov): link fragments.
358-
return ConstructorElementImpl(
358+
var element = ConstructorElementImpl(
359359
name3: fragments.first.name2,
360360
reference: reference,
361361
firstFragment: fragments.first,
362362
);
363+
364+
// TODO(scheglov): type parameters
365+
// TODO(scheglov): formal parameters
366+
element.deferReadResolution(
367+
_createDeferredReadResolutionCallback((reader) {
368+
var enclosingElement =
369+
element.enclosingElement as InstanceElementImpl;
370+
reader._addTypeParameters2(enclosingElement.typeParameters2);
371+
element.superConstructor2 = reader.readConstructorElementMixin2();
372+
}),
373+
);
374+
375+
return element;
363376
});
364377
}
365378

@@ -398,7 +411,6 @@ class LibraryReader {
398411
);
399412
_readFragmentMetadata(fragment, reader);
400413
fragment.returnType = reader.readRequiredType();
401-
fragment.superConstructor = reader.readConstructorElementMixin();
402414
fragment.redirectedConstructor = reader.readConstructorElementMixin();
403415
fragment.constantInitializers = reader.readNodeList();
404416
});
@@ -1561,6 +1573,10 @@ class ResolutionReader {
15611573
return element2?.asElement as ConstructorElementMixin?;
15621574
}
15631575

1576+
ConstructorElementMixin2? readConstructorElementMixin2() {
1577+
return readElement() as ConstructorElementMixin2?;
1578+
}
1579+
15641580
double readDouble() {
15651581
return _reader.readDouble();
15661582
}

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,14 @@ class BundleWriter {
197197
_sink.writeList(elements, (element) {
198198
_writeReference(element.reference);
199199
_sink.writeList(element.fragments, _writeFragmentId);
200+
201+
_writeElementResolution(() {
202+
// TODO(scheglov): avoid cast
203+
_resolutionSink.withTypeParameters(element.typeParameters2.cast(), () {
204+
_resolutionSink.writeElement(element.superConstructor2);
205+
// TODO(scheglov): formal parameters
206+
});
207+
});
200208
});
201209
}
202210

@@ -210,7 +218,6 @@ class BundleWriter {
210218
_sink.writeList(fragment.formalParameters, _writeParameterElement);
211219
_resolutionSink._writeMetadata(fragment.metadata);
212220
_resolutionSink.writeType(fragment.returnType);
213-
_resolutionSink.writeElement(fragment.superConstructor?.asElement2);
214221
_resolutionSink.writeElement(fragment.redirectedConstructor?.asElement2);
215222
_resolutionSink._writeNodeList(fragment.constantInitializers);
216223
});

pkg/analyzer/test/src/summary/elements/class_test.dart

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3878,7 +3878,9 @@ library
38783878
requiredPositional final hasImplicitType a
38793879
firstFragment: #F6
38803880
type: int
3881-
superConstructor: <testLibrary>::@class::B::@constructor::new
3881+
superConstructor: ConstructorMember
3882+
baseElement: <testLibrary>::@class::B::@constructor::new
3883+
substitution: {T: String}
38823884
class B
38833885
reference: <testLibrary>::@class::B
38843886
firstFragment: #F7
@@ -4197,7 +4199,9 @@ library
41974199
named
41984200
reference: <testLibrary>::@class::D::@constructor::named
41994201
firstFragment: #F9
4200-
superConstructor: <testLibrary>::@class::C::@constructor::_
4202+
superConstructor: ConstructorMember
4203+
baseElement: <testLibrary>::@class::C::@constructor::_
4204+
substitution: {T: U, U: T}
42014205
''');
42024206
}
42034207

@@ -4762,7 +4766,9 @@ library
47624766
new
47634767
reference: <testLibrary>::@class::D::@constructor::new
47644768
firstFragment: #F9
4765-
superConstructor: <testLibrary>::@class::C::@constructor::_
4769+
superConstructor: ConstructorMember
4770+
baseElement: <testLibrary>::@class::C::@constructor::_
4771+
substitution: {T: U, U: T}
47664772
''');
47674773
}
47684774

@@ -5731,7 +5737,10 @@ library
57315737
synthetic new
57325738
reference: <testLibrary>::@class::C::@constructor::new
57335739
firstFragment: #F2
5734-
superConstructor: <testLibrary>::@class::B::@constructor::new
5740+
superConstructor: ConstructorMember
5741+
baseElement: <testLibrary>::@class::B::@constructor::new
5742+
substitution: {U: int}
5743+
superConstructor: <testLibrary>::@class::A::@constructor::new
57355744
''');
57365745
}
57375746

@@ -5767,7 +5776,13 @@ library
57675776
synthetic new
57685777
reference: <testLibrary>::@class::C::@constructor::new
57695778
firstFragment: #F2
5770-
superConstructor: <testLibrary>::@class::B::@constructor::new
5779+
superConstructor: ConstructorMember
5780+
baseElement: <testLibrary>::@class::B::@constructor::new
5781+
substitution: {U: int}
5782+
superConstructor: ConstructorMember
5783+
baseElement: <testLibrary>::@class::A::@constructor::new
5784+
substitution: {T: String}
5785+
superConstructor: dart:core::@class::Object::@constructor::new
57715786
''');
57725787
}
57735788

@@ -5831,7 +5846,9 @@ library
58315846
new
58325847
reference: <testLibrary>::@class::B::@constructor::new
58335848
firstFragment: #F6
5834-
superConstructor: <testLibrary>::@class::A::@constructor::named
5849+
superConstructor: ConstructorMember
5850+
baseElement: <testLibrary>::@class::A::@constructor::named
5851+
substitution: {T: int}
58355852
''');
58365853
}
58375854

@@ -16762,7 +16779,9 @@ library
1676216779
synthetic new
1676316780
reference: <testLibrary>::@class::C::@constructor::new
1676416781
firstFragment: #F2
16765-
superConstructor: <testLibrary>::@class::D::@constructor::new
16782+
superConstructor: ConstructorMember
16783+
baseElement: <testLibrary>::@class::D::@constructor::new
16784+
substitution: {T1: int, T2: double}
1676616785
class D
1676716786
reference: <testLibrary>::@class::D
1676816787
firstFragment: #F3
@@ -16858,7 +16877,9 @@ library
1685816877
synthetic new
1685916878
reference: <testLibrary>::@class::B::@constructor::new
1686016879
firstFragment: #F5
16861-
superConstructor: <testLibrary>::@class::A::@constructor::new
16880+
superConstructor: ConstructorMember
16881+
baseElement: <testLibrary>::@class::A::@constructor::new
16882+
substitution: {T: B}
1686216883
''');
1686316884
}
1686416885

@@ -18878,7 +18899,9 @@ library
1887818899
staticType: E
1887918900
rightParenthesis: ) @0
1888018901
element: <testLibrary>::@class::A::@constructor::new
18881-
superConstructor: <testLibrary>::@class::A::@constructor::new
18902+
superConstructor: ConstructorMember
18903+
baseElement: <testLibrary>::@class::A::@constructor::new
18904+
substitution: {T: E}
1888218905
mixins
1888318906
mixin M
1888418907
reference: <testLibrary>::@mixin::M
@@ -20176,7 +20199,9 @@ library
2017620199
staticType: List<dynamic>
2017720200
rightParenthesis: ) @0
2017820201
element: <testLibrary>::@class::Base::@constructor::ctor
20179-
superConstructor: <testLibrary>::@class::Base::@constructor::ctor
20202+
superConstructor: ConstructorMember
20203+
baseElement: <testLibrary>::@class::Base::@constructor::ctor
20204+
substitution: {T: dynamic}
2018020205
''');
2018120206
}
2018220207

@@ -20297,7 +20322,9 @@ library
2029720322
staticType: List<List<U>>
2029820323
rightParenthesis: ) @0
2029920324
element: <testLibrary>::@class::Base::@constructor::ctor
20300-
superConstructor: <testLibrary>::@class::Base::@constructor::ctor
20325+
superConstructor: ConstructorMember
20326+
baseElement: <testLibrary>::@class::Base::@constructor::ctor
20327+
substitution: {T: List<U>}
2030120328
''');
2030220329
}
2030320330

pkg/analyzer/test/src/summary/elements/const_test.dart

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,7 +1249,9 @@ library
12491249
const new
12501250
reference: <testLibrary>::@class::P1::@constructor::new
12511251
firstFragment: #F6
1252-
superConstructor: <testLibrary>::@class::P::@constructor::new
1252+
superConstructor: ConstructorMember
1253+
baseElement: <testLibrary>::@class::P::@constructor::new
1254+
substitution: {T: T}
12531255
class P2
12541256
reference: <testLibrary>::@class::P2
12551257
firstFragment: #F7
@@ -1261,7 +1263,9 @@ library
12611263
const new
12621264
reference: <testLibrary>::@class::P2::@constructor::new
12631265
firstFragment: #F9
1264-
superConstructor: <testLibrary>::@class::P::@constructor::new
1266+
superConstructor: ConstructorMember
1267+
baseElement: <testLibrary>::@class::P::@constructor::new
1268+
substitution: {T: T}
12651269
topLevelVariables
12661270
const hasInitializer values
12671271
reference: <testLibrary>::@topLevelVariable::values

pkg/analyzer/test/src/summary/elements/formal_parameter_test.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,9 @@ library
255255
synthetic new
256256
reference: <testLibrary>::@class::B::@constructor::new
257257
firstFragment: #F8
258-
superConstructor: <testLibrary>::@class::A::@constructor::new
258+
superConstructor: ConstructorMember
259+
baseElement: <testLibrary>::@class::A::@constructor::new
260+
substitution: {T: T}
259261
methods
260262
f
261263
reference: <testLibrary>::@class::B::@method::f

pkg/analyzer/test/src/summary/elements/function_type_annotation_test.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1034,7 +1034,9 @@ library
10341034
leftParenthesis: ( @0
10351035
rightParenthesis: ) @0
10361036
element: <testLibrary>::@class::A::@constructor::new
1037-
superConstructor: <testLibrary>::@class::A::@constructor::new
1037+
superConstructor: ConstructorMember
1038+
baseElement: <testLibrary>::@class::A::@constructor::new
1039+
substitution: {T: void Function()}
10381040
mixins
10391041
mixin M
10401042
reference: <testLibrary>::@mixin::M

pkg/analyzer/test/src/summary/elements/mixin_test.dart

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,9 @@ library
499499
synthetic new
500500
reference: <testLibrary>::@class::B::@constructor::new
501501
firstFragment: #F5
502-
superConstructor: <testLibrary>::@class::A::@constructor::new
502+
superConstructor: ConstructorMember
503+
baseElement: <testLibrary>::@class::A::@constructor::new
504+
substitution: {T: int}
503505
mixins
504506
mixin M
505507
reference: <testLibrary>::@mixin::M
@@ -601,7 +603,9 @@ library
601603
leftParenthesis: ( @0
602604
rightParenthesis: ) @0
603605
element: <testLibrary>::@class::A::@constructor::new
604-
superConstructor: <testLibrary>::@class::A::@constructor::new
606+
superConstructor: ConstructorMember
607+
baseElement: <testLibrary>::@class::A::@constructor::new
608+
substitution: {T: int}
605609
''');
606610
}
607611

@@ -793,7 +797,9 @@ library
793797
synthetic new
794798
reference: <testLibrary>::@class::C::@constructor::new
795799
firstFragment: #F5
796-
superConstructor: <testLibrary>::@class::A::@constructor::new
800+
superConstructor: ConstructorMember
801+
baseElement: <testLibrary>::@class::A::@constructor::new
802+
substitution: {T: int Function(String)}
797803
mixins
798804
mixin M
799805
reference: <testLibrary>::@mixin::M
@@ -863,7 +869,9 @@ library
863869
synthetic new
864870
reference: <testLibrary>::@class::C::@constructor::new
865871
firstFragment: #F5
866-
superConstructor: <testLibrary>::@class::A::@constructor::new
872+
superConstructor: ConstructorMember
873+
baseElement: <testLibrary>::@class::A::@constructor::new
874+
substitution: {T: List<int>}
867875
mixins
868876
mixin M
869877
reference: <testLibrary>::@mixin::M
@@ -946,7 +954,9 @@ library
946954
leftParenthesis: ( @0
947955
rightParenthesis: ) @0
948956
element: <testLibrary>::@class::I::@constructor::new
949-
superConstructor: <testLibrary>::@class::I::@constructor::new
957+
superConstructor: ConstructorMember
958+
baseElement: <testLibrary>::@class::I::@constructor::new
959+
substitution: {X: int}
950960
mixins
951961
mixin M1
952962
reference: <testLibrary>::@mixin::M1
@@ -1037,7 +1047,9 @@ library
10371047
synthetic new
10381048
reference: <testLibrary>::@class::X::@constructor::new
10391049
firstFragment: #F5
1040-
superConstructor: <testLibrary>::@class::S::@constructor::new
1050+
superConstructor: ConstructorMember
1051+
baseElement: <testLibrary>::@class::S::@constructor::new
1052+
substitution: {T3: String}
10411053
mixins
10421054
mixin M
10431055
reference: <testLibrary>::@mixin::M
@@ -1137,7 +1149,9 @@ library
11371149
synthetic new
11381150
reference: <testLibrary>::@class::X::@constructor::new
11391151
firstFragment: #F5
1140-
superConstructor: <testLibrary>::@class::S::@constructor::new
1152+
superConstructor: ConstructorMember
1153+
baseElement: <testLibrary>::@class::S::@constructor::new
1154+
substitution: {T4: String}
11411155
mixins
11421156
mixin M
11431157
reference: <testLibrary>::@mixin::M

0 commit comments

Comments
 (0)