Skip to content

Commit abbaf1b

Browse files
scheglovCommit Queue
authored andcommitted
Fine. Special case dynamic element reference in constants.
I think we don't need to store `dynamic` element references anywhere else, at least yet. Change-Id: Icd8b033e4c3e29c7b3c1454fd3bd4a94fd076b54 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/422362 Reviewed-by: Paul Berry <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent 79ff583 commit abbaf1b

File tree

2 files changed

+46
-10
lines changed

2 files changed

+46
-10
lines changed

pkg/analyzer/lib/src/fine/manifest_ast.dart

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import 'package:analyzer/dart/ast/ast.dart';
88
import 'package:analyzer/dart/ast/visitor.dart';
99
import 'package:analyzer/dart/element/element2.dart';
1010
import 'package:analyzer/src/dart/ast/ast.dart';
11+
import 'package:analyzer/src/dart/element/element.dart';
1112
import 'package:analyzer/src/fine/manifest_context.dart';
1213
import 'package:analyzer/src/summary2/data_reader.dart';
1314
import 'package:analyzer/src/summary2/data_writer.dart';
@@ -146,9 +147,6 @@ class ManifestNode {
146147
}
147148

148149
class _ElementCollector extends ThrowingAstVisitor<void> {
149-
static const int _nullIndex = 0;
150-
static const int _importPrefixIndex = 1;
151-
152150
final Map<Element2, int> map = Map.identity();
153151
final List<int> elementIndexList = [];
154152

@@ -335,16 +333,26 @@ class _ElementCollector extends ThrowingAstVisitor<void> {
335333
void _addElement(Element2? element) {
336334
switch (element) {
337335
case null:
338-
elementIndexList.add(_nullIndex);
336+
elementIndexList.add(_ElementKind.null_.index);
337+
case DynamicElementImpl2():
338+
elementIndexList.add(_ElementKind.dynamic_.index);
339339
case PrefixElement2():
340-
elementIndexList.add(_importPrefixIndex);
340+
elementIndexList.add(_ElementKind.importPrefix.index);
341341
default:
342-
var index = map[element] ??= 2 + map.length;
342+
var base = _ElementKind.firstRegular.index;
343+
var index = map[element] ??= base + map.length;
343344
elementIndexList.add(index);
344345
}
345346
}
346347
}
347348

349+
enum _ElementKind {
350+
null_,
351+
dynamic_,
352+
importPrefix,
353+
firstRegular,
354+
}
355+
348356
extension ListOfManifestNodeExtension on List<ManifestNode> {
349357
bool match(MatchContext context, List<AstNode> nodes) {
350358
if (nodes.length != length) {

pkg/analyzer/test/src/dart/analysis/driver_test.dart

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17313,7 +17313,7 @@ const b = 0 + a;
1731317313
tokenLengthList: [1, 1, 1]
1731417314
elements
1731517315
[2] (dart:core, num, +) #M1
17316-
elementIndexList: [0, 2]
17316+
elementIndexList: [0, 3]
1731717317
''',
1731817318
updatedCode: r'''
1731917319
const a = 1;
@@ -17336,7 +17336,7 @@ const b = 0 + a;
1733617336
elements
1733717337
[2] (package:test/test.dart, a) <null>
1733817338
[3] (dart:core, num, +) #M1
17339-
elementIndexList: [2, 3]
17339+
elementIndexList: [3, 4]
1734017340
''',
1734117341
);
1734217342
}
@@ -17366,7 +17366,7 @@ const b = 1 + a;
1736617366
elements
1736717367
[2] (package:test/test.dart, a) <null>
1736817368
[3] (dart:core, num, +) #M2
17369-
elementIndexList: [2, 3]
17369+
elementIndexList: [3, 4]
1737017370
''',
1737117371
updatedCode: r'''
1737217372
const b = 1 + a;
@@ -17382,7 +17382,7 @@ const b = 1 + a;
1738217382
tokenLengthList: [1, 1, 1]
1738317383
elements
1738417384
[2] (dart:core, num, +) #M2
17385-
elementIndexList: [0, 2]
17385+
elementIndexList: [0, 3]
1738617386
''',
1738717387
);
1738817388
}
@@ -17561,6 +17561,34 @@ const a = A();
1756117561
);
1756217562
}
1756317563

17564+
test_manifest_constInitializer_dynamicElement() async {
17565+
await _runLibraryManifestScenario(
17566+
initialCode: r'''
17567+
const a = 0 as dynamic;
17568+
const b = 0 as dynamic;
17569+
''',
17570+
expectedInitialEvents: r'''
17571+
[operation] linkLibraryCycle SDK
17572+
[operation] linkLibraryCycle
17573+
package:test/test.dart
17574+
manifest
17575+
a: #M0
17576+
b: #M1
17577+
''',
17578+
updatedCode: r'''
17579+
const a = 0 as dynamic;
17580+
const b = 0 as int;
17581+
''',
17582+
expectedUpdatedEvents: r'''
17583+
[operation] linkLibraryCycle
17584+
package:test/test.dart
17585+
manifest
17586+
a: #M0
17587+
b: #M2
17588+
''',
17589+
);
17590+
}
17591+
1756417592
test_manifest_constInitializer_instanceCreation_argument() async {
1756517593
await _runLibraryManifestScenario(
1756617594
initialCode: r'''

0 commit comments

Comments
 (0)