Skip to content

Commit 37fa71d

Browse files
committed
Resolve types in scopes, resynthesize some elements.
Also some very basic top-level inference: field formal initializers in constructors, initializers of top-level variables (for now ignoring dependencies), setter return type to `void`. We pass 172 or 590 resynthesis tests, about 29%. Change-Id: Id70b80ceb7c794627626a1fe94172b0e9ccdda8b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/95672 Reviewed-by: Brian Wilkerson <[email protected]> Reviewed-by: Paul Berry <[email protected]>
1 parent 9f7e11c commit 37fa71d

18 files changed

+3034
-1372
lines changed

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

Lines changed: 668 additions & 120 deletions
Large diffs are not rendered by default.

pkg/analyzer/lib/src/summary/format.dart

Lines changed: 784 additions & 116 deletions
Large diffs are not rendered by default.

pkg/analyzer/lib/src/summary/format.fbs

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1791,45 +1791,77 @@ table LinkedNode {
17911791
variantField_20:string (id: 20);
17921792

17931793
variantField_22:string (id: 22);
1794+
1795+
variantField_32:LinkedNodeVariablesDeclaration (id: 32);
17941796
}
17951797

1796-
/// TODO(scheglov) extend to support multiple libraries or remove
1798+
/// Information about a group of libraries linked together, for example because
1799+
/// they form a single cycle, or because they represent a single build artifact.
17971800
table LinkedNodeBundle {
1798-
node:LinkedNode (id: 2);
1801+
libraries:[LinkedNodeLibrary] (id: 1);
1802+
1803+
/// The shared list of references used in the [libraries].
1804+
references:LinkedNodeReferences (id: 0);
1805+
}
17991806

1800-
references:LinkedNodeReference (id: 1);
1807+
/// Information about a single library in a [LinkedNodeBundle].
1808+
table LinkedNodeLibrary {
1809+
exports:[uint] (id: 2);
18011810

1802-
tokens:UnlinkedTokens (id: 0);
1811+
units:[LinkedNodeUnit] (id: 1);
1812+
1813+
uriStr:string (id: 0);
18031814
}
18041815

18051816
/// Flattened tree of declarations referenced from [LinkedNode]s.
1806-
table LinkedNodeReference {
1817+
table LinkedNodeReferences {
18071818
name:[string] (id: 1);
18081819

18091820
parent:[uint] (id: 0);
18101821
}
18111822

18121823
/// Information about a Dart type.
18131824
table LinkedNodeType {
1814-
/// References to [LinkedNodeReference].
1825+
/// References to [LinkedNodeReferences].
18151826
functionFormalParameters:[uint] (id: 0);
18161827

18171828
functionReturnType:LinkedNodeType (id: 1);
18181829

1819-
/// References to [LinkedNodeReference].
1830+
/// References to [LinkedNodeReferences].
18201831
functionTypeParameters:[uint] (id: 2);
18211832

1822-
/// Reference to a [LinkedNodeReference].
1833+
/// Reference to a [LinkedNodeReferences].
18231834
interfaceClass:uint (id: 3);
18241835

18251836
interfaceTypeArguments:[LinkedNodeType] (id: 4);
18261837

18271838
kind:LinkedNodeTypeKind (id: 5);
18281839

1829-
/// Reference to a [LinkedNodeReference].
1840+
/// Reference to a [LinkedNodeReferences].
18301841
typeParameterParameter:uint (id: 6);
18311842
}
18321843

1844+
/// Information about a single library in a [LinkedNodeLibrary].
1845+
table LinkedNodeUnit {
1846+
node:LinkedNode (id: 2);
1847+
1848+
tokens:UnlinkedTokens (id: 1);
1849+
1850+
uriStr:string (id: 0);
1851+
}
1852+
1853+
/// Information about a top-level declaration, or a field declaration that
1854+
/// contributes information to [LinkedNodeKind.variableDeclaration].
1855+
table LinkedNodeVariablesDeclaration {
1856+
comment:LinkedNode (id: 3);
1857+
1858+
isConst:bool (id: 0);
1859+
1860+
isFinal:bool (id: 1);
1861+
1862+
isStatic:bool (id: 2);
1863+
}
1864+
18331865
/// Information about the resolution of an [UnlinkedReference].
18341866
table LinkedReference {
18351867
/// If this [LinkedReference] doesn't have an associated [UnlinkedReference],

pkg/analyzer/lib/src/summary/idl.dart

Lines changed: 78 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,6 +1338,9 @@ abstract class LinkedNode extends base.SummaryClass {
13381338
@VariantId(6, variant: LinkedNodeKind.fieldFormalParameter)
13391339
LinkedNode get fieldFormalParameter_type;
13401340

1341+
@VariantId(24, variant: LinkedNodeKind.fieldFormalParameter)
1342+
LinkedNodeType get fieldFormalParameter_type2;
1343+
13411344
@VariantId(7, variant: LinkedNodeKind.fieldFormalParameter)
13421345
LinkedNode get fieldFormalParameter_typeParameters;
13431346

@@ -1459,6 +1462,9 @@ abstract class LinkedNode extends base.SummaryClass {
14591462
@VariantId(7, variant: LinkedNodeKind.functionDeclaration)
14601463
LinkedNode get functionDeclaration_returnType;
14611464

1465+
@VariantId(24, variant: LinkedNodeKind.functionDeclaration)
1466+
LinkedNodeType get functionDeclaration_returnType2;
1467+
14621468
@VariantId(6, variant: LinkedNodeKind.functionDeclarationStatement)
14631469
LinkedNode get functionDeclarationStatement_functionDeclaration;
14641470

@@ -1696,6 +1702,9 @@ abstract class LinkedNode extends base.SummaryClass {
16961702
@VariantId(7, variant: LinkedNodeKind.mapLiteralEntry)
16971703
LinkedNode get mapLiteralEntry_value;
16981704

1705+
@VariantId(19, variant: LinkedNodeKind.methodDeclaration)
1706+
int get methodDeclaration_actualProperty;
1707+
16991708
@VariantId(6, variant: LinkedNodeKind.methodDeclaration)
17001709
LinkedNode get methodDeclaration_body;
17011710

@@ -1720,6 +1729,9 @@ abstract class LinkedNode extends base.SummaryClass {
17201729
@VariantId(8, variant: LinkedNodeKind.methodDeclaration)
17211730
LinkedNode get methodDeclaration_returnType;
17221731

1732+
@VariantId(24, variant: LinkedNodeKind.methodDeclaration)
1733+
LinkedNodeType get methodDeclaration_returnType2;
1734+
17231735
@VariantId(9, variant: LinkedNodeKind.methodDeclaration)
17241736
LinkedNode get methodDeclaration_typeParameters;
17251737

@@ -1804,6 +1816,13 @@ abstract class LinkedNode extends base.SummaryClass {
18041816
])
18051817
LinkedNode get normalFormalParameter_identifier;
18061818

1819+
@VariantId(27, variantList: [
1820+
LinkedNodeKind.fieldFormalParameter,
1821+
LinkedNodeKind.functionTypedFormalParameter,
1822+
LinkedNodeKind.simpleFormalParameter,
1823+
])
1824+
bool get normalFormalParameter_isCovariant;
1825+
18071826
@VariantId(4, variantList: [
18081827
LinkedNodeKind.fieldFormalParameter,
18091828
LinkedNodeKind.functionTypedFormalParameter,
@@ -1931,6 +1950,9 @@ abstract class LinkedNode extends base.SummaryClass {
19311950
@VariantId(6, variant: LinkedNodeKind.simpleFormalParameter)
19321951
LinkedNode get simpleFormalParameter_type;
19331952

1953+
@VariantId(24, variant: LinkedNodeKind.simpleFormalParameter)
1954+
LinkedNodeType get simpleFormalParameter_type2;
1955+
19341956
@VariantId(15, variant: LinkedNodeKind.simpleIdentifier)
19351957
int get simpleIdentifier_element;
19361958

@@ -2140,6 +2162,9 @@ abstract class LinkedNode extends base.SummaryClass {
21402162
])
21412163
int get uriBasedDirective_uriElement;
21422164

2165+
@VariantId(32, variant: LinkedNodeKind.variableDeclaration)
2166+
LinkedNodeVariablesDeclaration get variableDeclaration_declaration;
2167+
21432168
@VariantId(15, variant: LinkedNodeKind.variableDeclaration)
21442169
int get variableDeclaration_equals;
21452170

@@ -2149,6 +2174,9 @@ abstract class LinkedNode extends base.SummaryClass {
21492174
@VariantId(7, variant: LinkedNodeKind.variableDeclaration)
21502175
LinkedNode get variableDeclaration_name;
21512176

2177+
@VariantId(24, variant: LinkedNodeKind.variableDeclaration)
2178+
LinkedNodeType get variableDeclaration_type2;
2179+
21522180
@VariantId(15, variant: LinkedNodeKind.variableDeclarationList)
21532181
int get variableDeclarationList_keyword;
21542182

@@ -2198,20 +2226,19 @@ abstract class LinkedNode extends base.SummaryClass {
21982226
int get yieldStatement_yieldKeyword;
21992227
}
22002228

2201-
/// TODO(scheglov) extend to support multiple libraries or remove
2229+
/// Information about a group of libraries linked together, for example because
2230+
/// they form a single cycle, or because they represent a single build artifact.
22022231
@TopLevel('LNBn')
22032232
abstract class LinkedNodeBundle extends base.SummaryClass {
22042233
factory LinkedNodeBundle.fromBuffer(List<int> buffer) =>
22052234
generated.readLinkedNodeBundle(buffer);
22062235

2207-
@Id(2)
2208-
LinkedNode get node;
2209-
22102236
@Id(1)
2211-
LinkedNodeReference get references;
2237+
List<LinkedNodeLibrary> get libraries;
22122238

2239+
/// The shared list of references used in the [libraries].
22132240
@Id(0)
2214-
UnlinkedTokens get tokens;
2241+
LinkedNodeReferences get references;
22152242
}
22162243

22172244
/// Types of comments.
@@ -2344,8 +2371,20 @@ enum LinkedNodeKind {
23442371
yieldStatement,
23452372
}
23462373

2374+
/// Information about a single library in a [LinkedNodeBundle].
2375+
abstract class LinkedNodeLibrary extends base.SummaryClass {
2376+
@Id(2)
2377+
List<int> get exports;
2378+
2379+
@Id(1)
2380+
List<LinkedNodeUnit> get units;
2381+
2382+
@Id(0)
2383+
String get uriStr;
2384+
}
2385+
23472386
/// Flattened tree of declarations referenced from [LinkedNode]s.
2348-
abstract class LinkedNodeReference extends base.SummaryClass {
2387+
abstract class LinkedNodeReferences extends base.SummaryClass {
23492388
@Id(1)
23502389
List<String> get name;
23512390

@@ -2355,18 +2394,18 @@ abstract class LinkedNodeReference extends base.SummaryClass {
23552394

23562395
/// Information about a Dart type.
23572396
abstract class LinkedNodeType extends base.SummaryClass {
2358-
/// References to [LinkedNodeReference].
2397+
/// References to [LinkedNodeReferences].
23592398
@Id(0)
23602399
List<int> get functionFormalParameters;
23612400

23622401
@Id(1)
23632402
LinkedNodeType get functionReturnType;
23642403

2365-
/// References to [LinkedNodeReference].
2404+
/// References to [LinkedNodeReferences].
23662405
@Id(2)
23672406
List<int> get functionTypeParameters;
23682407

2369-
/// Reference to a [LinkedNodeReference].
2408+
/// Reference to a [LinkedNodeReferences].
23702409
@Id(3)
23712410
int get interfaceClass;
23722411

@@ -2376,7 +2415,7 @@ abstract class LinkedNodeType extends base.SummaryClass {
23762415
@Id(5)
23772416
LinkedNodeTypeKind get kind;
23782417

2379-
/// Reference to a [LinkedNodeReference].
2418+
/// Reference to a [LinkedNodeReferences].
23802419
@Id(6)
23812420
int get typeParameterParameter;
23822421
}
@@ -2391,6 +2430,34 @@ enum LinkedNodeTypeKind {
23912430
void_
23922431
}
23932432

2433+
/// Information about a single library in a [LinkedNodeLibrary].
2434+
abstract class LinkedNodeUnit extends base.SummaryClass {
2435+
@Id(2)
2436+
LinkedNode get node;
2437+
2438+
@Id(1)
2439+
UnlinkedTokens get tokens;
2440+
2441+
@Id(0)
2442+
String get uriStr;
2443+
}
2444+
2445+
/// Information about a top-level declaration, or a field declaration that
2446+
/// contributes information to [LinkedNodeKind.variableDeclaration].
2447+
abstract class LinkedNodeVariablesDeclaration extends base.SummaryClass {
2448+
@Id(3)
2449+
LinkedNode get comment;
2450+
2451+
@Id(0)
2452+
bool get isConst;
2453+
2454+
@Id(1)
2455+
bool get isFinal;
2456+
2457+
@Id(2)
2458+
bool get isStatic;
2459+
}
2460+
23942461
/// Information about the resolution of an [UnlinkedReference].
23952462
abstract class LinkedReference extends base.SummaryClass {
23962463
/// If this [LinkedReference] doesn't have an associated [UnlinkedReference],

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import 'package:analyzer/src/summary2/reference.dart';
1818
/// Deserializer of fully resolved ASTs from flat buffers.
1919
class AstBinaryReader {
2020
final Reference _nameRoot;
21-
final LinkedNodeReference _linkedReferences;
21+
final LinkedNodeReferences _linkedReferences;
2222
final List<Reference> _references;
2323

2424
final UnlinkedTokens _tokensBinary;

0 commit comments

Comments
 (0)