Skip to content

Commit df8e0af

Browse files
scheglovcommit-bot@chromium.org
authored andcommitted
Use AnalysisDriver.useSummary2 in FileSystemState.
[email protected] Change-Id: Ie64f05a522d08c1fe779ccc78fbfe25ad52ec422 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/106302 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent 60fa066 commit df8e0af

3 files changed

Lines changed: 52 additions & 17 deletions

File tree

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1575,7 +1575,6 @@ class AnalysisDriver implements AnalysisDriverGeneric {
15751575
_unlinkedSalt,
15761576
_linkedSalt,
15771577
externalSummaries: _externalSummaries,
1578-
useSummary2: useSummary2,
15791578
);
15801579
_fileTracker = new FileTracker(_logger, _fsState, _changeHook);
15811580
}

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import 'package:analyzer/error/listener.dart';
1313
import 'package:analyzer/file_system/file_system.dart';
1414
import 'package:analyzer/src/dart/analysis/byte_store.dart';
1515
import 'package:analyzer/src/dart/analysis/defined_names.dart';
16+
import 'package:analyzer/src/dart/analysis/driver.dart';
1617
import 'package:analyzer/src/dart/analysis/library_graph.dart';
1718
import 'package:analyzer/src/dart/analysis/performance_logger.dart';
1819
import 'package:analyzer/src/dart/analysis/referenced_names.dart';
@@ -396,7 +397,7 @@ class FileState {
396397
bool refresh({bool allowCached: false}) {
397398
counterFileStateRefresh++;
398399

399-
if (_fsState.useSummary2) {
400+
if (AnalysisDriver.useSummary2) {
400401
return _refresh2(allowCached: allowCached);
401402
}
402403

@@ -748,8 +749,9 @@ class FileState {
748749

749750
static UnlinkedUnit2Builder serializeAstUnlinked2(CompilationUnit unit) {
750751
var exports = <String>[];
751-
var imports = <String>['dart:core'];
752+
var imports = <String>[];
752753
var parts = <String>[];
754+
var hasDartCoreImport = false;
753755
var hasLibraryDirective = false;
754756
var hasPartOfDirective = false;
755757
for (var directive in unit.directives) {
@@ -759,6 +761,9 @@ class FileState {
759761
} else if (directive is ImportDirective) {
760762
var uriStr = directive.uri.stringValue;
761763
imports.add(uriStr ?? '');
764+
if (uriStr == 'dart:core') {
765+
hasDartCoreImport = true;
766+
}
762767
} else if (directive is LibraryDirective) {
763768
hasLibraryDirective = true;
764769
} else if (directive is PartDirective) {
@@ -768,6 +773,9 @@ class FileState {
768773
hasPartOfDirective = true;
769774
}
770775
}
776+
if (!hasDartCoreImport) {
777+
imports.add('dart:core');
778+
}
771779
var informativeData = createInformativeData(unit);
772780
return UnlinkedUnit2Builder(
773781
apiSignature: computeUnlinkedApiSignature(unit),
@@ -823,7 +831,6 @@ class FileSystemState {
823831
final AnalysisOptions _analysisOptions;
824832
final Uint32List _unlinkedSalt;
825833
final Uint32List _linkedSalt;
826-
final bool useSummary2;
827834

828835
/**
829836
* The optional store with externally provided unlinked and corresponding
@@ -904,7 +911,6 @@ class FileSystemState {
904911
this._unlinkedSalt,
905912
this._linkedSalt, {
906913
this.externalSummaries,
907-
this.useSummary2 = false,
908914
}) {
909915
_fileContentCache = _FileContentCache.getInstance(
910916
_resourceProvider,

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

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import 'dart:typed_data';
77

88
import 'package:analyzer/file_system/file_system.dart';
99
import 'package:analyzer/src/dart/analysis/byte_store.dart';
10+
import 'package:analyzer/src/dart/analysis/driver.dart';
1011
import 'package:analyzer/src/dart/analysis/file_state.dart';
1112
import 'package:analyzer/src/dart/analysis/library_graph.dart';
1213
import 'package:analyzer/src/dart/analysis/performance_logger.dart';
@@ -117,8 +118,13 @@ var G, H;
117118
expect(_excludeSdk(file.directReferencedFiles), isEmpty);
118119
expect(file.isPart, isFalse);
119120
expect(file.library, isNull);
120-
expect(file.unlinked, isNotNull);
121-
expect(file.unlinked.classes, isEmpty);
121+
if (AnalysisDriver.useSummary2) {
122+
expect(file.unlinked2, isNotNull);
123+
expect(file.unlinked2.exports, isEmpty);
124+
} else {
125+
expect(file.unlinked, isNotNull);
126+
expect(file.unlinked.classes, isEmpty);
127+
}
122128
}
123129

124130
test_getFileForPath_emptyUri() {
@@ -208,9 +214,13 @@ class A1 {}
208214

209215
expect(file.isPart, isFalse);
210216
expect(file.library, isNull);
211-
expect(file.unlinked, isNotNull);
212-
expect(file.unlinked.classes, hasLength(1));
213-
expect(file.unlinked.classes[0].name, 'A1');
217+
if (AnalysisDriver.useSummary2) {
218+
expect(file.unlinked2, isNotNull);
219+
} else {
220+
expect(file.unlinked, isNotNull);
221+
expect(file.unlinked.classes, hasLength(1));
222+
expect(file.unlinked.classes[0].name, 'A1');
223+
}
214224

215225
expect(_excludeSdk(file.importedFiles), hasLength(2));
216226
expect(file.importedFiles[0].path, a2);
@@ -281,9 +291,13 @@ class A2 {}
281291
expect(file_a2.path, a2);
282292
expect(file_a2.uri, Uri.parse('package:aaa/a2.dart'));
283293

284-
expect(file_a2.unlinked, isNotNull);
285-
expect(file_a2.unlinked.classes, hasLength(1));
286-
expect(file_a2.unlinked.classes[0].name, 'A2');
294+
if (AnalysisDriver.useSummary2) {
295+
expect(file_a2.unlinked2, isNotNull);
296+
} else {
297+
expect(file_a2.unlinked, isNotNull);
298+
expect(file_a2.unlinked.classes, hasLength(1));
299+
expect(file_a2.unlinked.classes[0].name, 'A2');
300+
}
287301

288302
expect(_excludeSdk(file_a2.importedFiles), isEmpty);
289303
expect(file_a2.exportedFiles, isEmpty);
@@ -500,7 +514,11 @@ A foo(B p) {
500514
class A {}
501515
''');
502516
FileState file = fileSystemState.getFileForPath(path);
503-
expect(file.unlinked.classes[0].name, 'A');
517+
if (AnalysisDriver.useSummary2) {
518+
expect(file.definedTopLevelNames, contains('A'));
519+
} else {
520+
expect(file.unlinked.classes[0].name, 'A');
521+
}
504522
List<int> signature = file.apiSignature;
505523

506524
// Update the resource and refresh the file state.
@@ -510,7 +528,11 @@ class B {}
510528
bool apiSignatureChanged = file.refresh();
511529
expect(apiSignatureChanged, isTrue);
512530

513-
expect(file.unlinked.classes[0].name, 'B');
531+
if (AnalysisDriver.useSummary2) {
532+
expect(file.definedTopLevelNames, contains('B'));
533+
} else {
534+
expect(file.unlinked.classes[0].name, 'B');
535+
}
514536
expect(file.apiSignature, isNot(signature));
515537
}
516538

@@ -546,14 +568,22 @@ class C {
546568

547569
// Get the file, prepare unlinked.
548570
FileState file = fileSystemState.getFileForPath(path);
549-
expect(file.unlinked, isNotNull);
571+
if (AnalysisDriver.useSummary2) {
572+
expect(file.unlinked2, isNotNull);
573+
} else {
574+
expect(file.unlinked, isNotNull);
575+
}
550576

551577
// Make the unlinked unit in the byte store zero-length, damaged.
552578
byteStore.put(file.test.unlinkedKey, <int>[]);
553579

554580
// Refresh should not fail, zero bytes in the store are ignored.
555581
file.refresh();
556-
expect(file.unlinked, isNotNull);
582+
if (AnalysisDriver.useSummary2) {
583+
expect(file.unlinked2, isNotNull);
584+
} else {
585+
expect(file.unlinked, isNotNull);
586+
}
557587
}
558588

559589
test_subtypedNames() {

0 commit comments

Comments
 (0)