Skip to content

Commit 16abf95

Browse files
scheglovCommit Queue
authored andcommitted
Fine. Move 'withFineDependencies' flag into instance fields.
Using global flag did not give me enough confidence anymore. Change-Id: I079b2b05bd7c16f853512a9d023518fc380940a8 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/443145 Commit-Queue: Konstantin Shcheglov <[email protected]> Reviewed-by: Johnni Winther <[email protected]>
1 parent 6311478 commit 16abf95

File tree

15 files changed

+110
-62
lines changed

15 files changed

+110
-62
lines changed

pkg/analyzer/lib/dart/sdk/build_sdk_summary.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ Future<Uint8List> buildSdkSummary({
5858
sourceFactory: SourceFactory([DartUriResolver(sdk)]),
5959
analysisOptionsMap: optionsMap,
6060
packages: Packages({}),
61+
withFineDependencies: false,
6162
);
6263
scheduler.start();
6364

pkg/analyzer/lib/src/clients/build_resolvers/build_resolvers.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ AnalysisDriverForPackageBuild createAnalysisDriver({
7373
fileContentCache: fileContentCache,
7474
externalSummaries: dataStore,
7575
packages: packages,
76+
withFineDependencies: false,
7677
shouldReportInconsistentAnalysisException: false,
7778
);
7879

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class AnalysisContextCollectionImpl implements AnalysisContextCollection {
4747
List<String>? librarySummaryPaths,
4848
String? optionsFile,
4949
String? packagesFile,
50+
bool withFineDependencies = false,
5051
PerformanceLog? performanceLog,
5152
ResourceProvider? resourceProvider,
5253
bool retainDataForTesting = false,
@@ -92,7 +93,10 @@ class AnalysisContextCollectionImpl implements AnalysisContextCollection {
9293
);
9394

9495
byteStore ??= MemoryByteStore();
95-
var linkedBundleProvider = LinkedBundleProvider(byteStore: byteStore);
96+
var linkedBundleProvider = LinkedBundleProvider(
97+
byteStore: byteStore,
98+
withFineDependencies: withFineDependencies,
99+
);
96100

97101
var contextBuilder = ContextBuilderImpl(
98102
resourceProvider: this.resourceProvider,
@@ -118,6 +122,7 @@ class AnalysisContextCollectionImpl implements AnalysisContextCollection {
118122
unlinkedUnitStore: unlinkedUnitStore ?? UnlinkedUnitStoreImpl(),
119123
ownedFiles: ownedFiles,
120124
enableLintRuleTiming: enableLintRuleTiming,
125+
withFineDependencies: withFineDependencies,
121126
);
122127
contexts.add(context);
123128
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,14 @@ class ContextBuilderImpl {
9090
OwnedFiles? ownedFiles,
9191
bool enableLintRuleTiming = false,
9292
LinkedBundleProvider? linkedBundleProvider,
93+
required bool withFineDependencies,
9394
}) {
9495
byteStore ??= MemoryByteStore();
9596
performanceLog ??= PerformanceLog(null);
96-
linkedBundleProvider ??= LinkedBundleProvider(byteStore: byteStore);
97+
linkedBundleProvider ??= LinkedBundleProvider(
98+
byteStore: byteStore,
99+
withFineDependencies: withFineDependencies,
100+
);
97101

98102
if (scheduler == null) {
99103
scheduler = AnalysisDriverScheduler(performanceLog);
@@ -173,6 +177,7 @@ class ContextBuilderImpl {
173177
testView: retainDataForTesting ? AnalysisDriverTestView() : null,
174178
ownedFiles: ownedFiles,
175179
enableLintRuleTiming: enableLintRuleTiming,
180+
withFineDependencies: withFineDependencies,
176181
);
177182

178183
// AnalysisDriver reports results into streams.

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ class AnalysisDriver {
150150
/// The [Packages] object with packages and their language versions.
151151
final Packages _packages;
152152

153+
/// Whether fine-grained dependencies experiment is enabled.
154+
final bool withFineDependencies;
155+
153156
/// The [SourceFactory] is used to resolve URIs to paths and restore URIs
154157
/// from file paths.
155158
final SourceFactory _sourceFactory;
@@ -291,6 +294,7 @@ class AnalysisDriver {
291294
required ByteStore byteStore,
292295
required SourceFactory sourceFactory,
293296
required Packages packages,
297+
required this.withFineDependencies,
294298
LinkedBundleProvider? linkedBundleProvider,
295299
this.ownedFiles,
296300
this.analysisContext,
@@ -315,7 +319,11 @@ class AnalysisDriver {
315319
_logger = logger,
316320
_packages = packages,
317321
linkedBundleProvider =
318-
linkedBundleProvider ?? LinkedBundleProvider(byteStore: byteStore),
322+
linkedBundleProvider ??
323+
LinkedBundleProvider(
324+
byteStore: byteStore,
325+
withFineDependencies: withFineDependencies,
326+
),
319327
_sourceFactory = sourceFactory,
320328
_externalSummaries = externalSummaries,
321329
declaredVariables = declaredVariables ?? DeclaredVariables(),
@@ -405,6 +413,7 @@ class AnalysisDriver {
405413
externalSummaries: _externalSummaries,
406414
fileSystemState: _fsState,
407415
linkedBundleProvider: linkedBundleProvider,
416+
withFineDependencies: withFineDependencies,
408417
);
409418
}
410419

@@ -1623,6 +1632,7 @@ class AnalysisDriver {
16231632
isGenerated: (_) => false,
16241633
onNewFile: _onNewFile,
16251634
testData: testView?.fileSystem,
1635+
withFineDependencies: withFineDependencies,
16261636
);
16271637
_fileTracker = FileTracker(_logger, _fsState, _fileContentStrategy);
16281638
}

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1194,6 +1194,7 @@ class FileSystemState {
11941194
final SourceFactory _sourceFactory;
11951195
final Workspace? _workspace;
11961196
final DeclaredVariables _declaredVariables;
1197+
final bool withFineDependencies;
11971198
final Uint32List _saltForUnlinked;
11981199
final Uint32List _saltForElements;
11991200

@@ -1272,6 +1273,7 @@ class FileSystemState {
12721273
required this.isGenerated,
12731274
required this.onNewFile,
12741275
required this.testData,
1276+
required this.withFineDependencies,
12751277
}) : _analysisOptionsMap = analysisOptionsMap {
12761278
_testView = FileSystemStateTestView(this);
12771279
}
@@ -1886,7 +1888,11 @@ class LibraryFileKind extends LibraryOrAugmentationFileKind {
18861888
/// just this file. If the library cycle is not known yet, compute it.
18871889
LibraryCycle get libraryCycle {
18881890
if (_libraryCycle == null) {
1889-
computeLibraryCycle(file._fsState._saltForElements, this);
1891+
computeLibraryCycle(
1892+
file._fsState.withFineDependencies,
1893+
file._fsState._saltForElements,
1894+
this,
1895+
);
18901896
}
18911897

18921898
return _libraryCycle!;

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class LibraryContext {
4646
final StreamController<Object>? eventsController;
4747
final FileSystemState fileSystemState;
4848
final File? packagesFile;
49+
final bool withFineDependencies;
4950
final SummaryDataStore store = SummaryDataStore();
5051

5152
late final AnalysisContextImpl analysisContext;
@@ -66,6 +67,7 @@ class LibraryContext {
6667
required DeclaredVariables declaredVariables,
6768
required SourceFactory sourceFactory,
6869
required this.packagesFile,
70+
required this.withFineDependencies,
6971
required SummaryDataStore? externalSummaries,
7072
}) {
7173
testData?.instance = this;
@@ -448,7 +450,7 @@ class LinkedBundleEntry {
448450
///
449451
/// These requirements are to the libraries in dependencies.
450452
///
451-
/// If [withFineDependencies] is `false`, the requirements are empty.
453+
/// Without fine-grained dependencies, the requirements are empty.
452454
final RequirementsManifest requirements;
453455

454456
/// The serialized libraries, for [BundleReader].
@@ -473,14 +475,18 @@ class LinkedBundleEntry {
473475
/// but this is relatively cheap.
474476
class LinkedBundleProvider {
475477
final ByteStore byteStore;
478+
final bool withFineDependencies;
476479

477480
/// The cache of deserialized bundles, used only when [withFineDependencies]
478481
/// to avoid reading requirements and manifests again and again.
479482
///
480483
/// The keys are [LibraryCycle.linkedKey].
481484
final Map<String, LinkedBundleEntry> map = {};
482485

483-
LinkedBundleProvider({required this.byteStore});
486+
LinkedBundleProvider({
487+
required this.byteStore,
488+
required this.withFineDependencies,
489+
});
484490

485491
LinkedBundleEntry? get(String key) {
486492
if (map[key] case var entry?) {

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,18 @@ import 'package:_fe_analyzer_shared/src/util/dependency_walker.dart'
99
show DependencyWalker, Node;
1010
import 'package:analyzer/src/dart/analysis/driver.dart';
1111
import 'package:analyzer/src/dart/analysis/file_state.dart';
12-
import 'package:analyzer/src/fine/requirements.dart';
1312
import 'package:analyzer/src/summary/api_signature.dart';
1413
import 'package:analyzer/src/utilities/extensions/collection.dart';
1514
import 'package:collection/collection.dart';
1615

1716
/// Ensure that the `FileState._libraryCycle` for the [file] and anything it
1817
/// depends on is computed.
19-
void computeLibraryCycle(Uint32List salt, LibraryFileKind file) {
20-
var libraryWalker = _LibraryWalker(salt);
18+
void computeLibraryCycle(
19+
bool withFineDependencies,
20+
Uint32List salt,
21+
LibraryFileKind file,
22+
) {
23+
var libraryWalker = _LibraryWalker(withFineDependencies, salt);
2124
libraryWalker.walk(libraryWalker.getNode(file));
2225
}
2326

@@ -26,6 +29,8 @@ class LibraryCycle {
2629
static int _nextId = 0;
2730
final int id = _nextId++;
2831

32+
final bool withFineDependencies;
33+
2934
/// The libraries that belong to this cycle.
3035
final List<LibraryFileKind> libraries;
3136

@@ -65,6 +70,7 @@ class LibraryCycle {
6570
final String nonTransitiveApiSignature;
6671

6772
LibraryCycle({
73+
required this.withFineDependencies,
6874
required this.libraries,
6975
required this.libraryUris,
7076
required this.directDependencies,
@@ -148,10 +154,11 @@ class _LibraryNode extends graph.Node<_LibraryNode> {
148154
/// Helper that organizes dependencies of a library into topologically
149155
/// sorted [LibraryCycle]s.
150156
class _LibraryWalker extends graph.DependencyWalker<_LibraryNode> {
157+
final bool withFineDependencies;
151158
final Uint32List _salt;
152159
final Map<LibraryFileKind, _LibraryNode> nodesOfFiles = {};
153160

154-
_LibraryWalker(this._salt);
161+
_LibraryWalker(this.withFineDependencies, this._salt);
155162

156163
@override
157164
void evaluate(_LibraryNode v) {
@@ -220,6 +227,7 @@ class _LibraryWalker extends graph.DependencyWalker<_LibraryNode> {
220227

221228
// Create the LibraryCycle instance for the cycle.
222229
var cycle = LibraryCycle(
230+
withFineDependencies: withFineDependencies,
223231
libraries: libraries.toFixedList(),
224232
libraryUris: libraryUris,
225233
directDependencies: directDependencies,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5745,7 +5745,7 @@ class LibraryElementImpl extends ElementImpl
57455745
/// The map of top-level declarations, from all units.
57465746
LibraryDeclarations? _libraryDeclarations;
57475747

5748-
/// If [withFineDependencies] is `true`, the manifest of the library.
5748+
/// With fine-grained dependencies, the manifest of the library.
57495749
LibraryManifest? manifest;
57505750

57515751
/// Initialize a newly created library element in the given [context] to have

pkg/analyzer/lib/src/dart/micro/resolve_file.dart

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -334,9 +334,10 @@ class FileResolver {
334334
var bytes = _errorResultsCache.get(errorsKey);
335335
if (bytes != null) {
336336
var data = CiderUnitErrors.fromBuffer(bytes);
337-
diagnostics = data.errors.map((error) {
338-
return ErrorEncoding.decode(file.source, error)!;
339-
}).toList();
337+
diagnostics =
338+
data.errors.map((error) {
339+
return ErrorEncoding.decode(file.source, error)!;
340+
}).toList();
340341
} else {
341342
var unitResult = await resolve(path: path, performance: performance);
342343
diagnostics = unitResult.diagnostics;
@@ -655,15 +656,16 @@ class FileResolver {
655656
});
656657
});
657658

658-
var resolvedUnits = results.map((fileResult) {
659-
var file = fileResult.file;
660-
return ResolvedUnitResultImpl(
661-
session: contextObjects!.analysisSession,
662-
fileState: file,
663-
unit: fileResult.unit,
664-
diagnostics: fileResult.diagnostics,
665-
);
666-
}).toList();
659+
var resolvedUnits =
660+
results.map((fileResult) {
661+
var file = fileResult.file;
662+
return ResolvedUnitResultImpl(
663+
session: contextObjects!.analysisSession,
664+
fileState: file,
665+
unit: fileResult.unit,
666+
diagnostics: fileResult.diagnostics,
667+
);
668+
}).toList();
667669

668670
var libraryUnit = resolvedUnits.first;
669671
var result = ResolvedLibraryResultImpl(
@@ -696,12 +698,13 @@ class FileResolver {
696698
return;
697699
}
698700

699-
var analysisOptions = (AnalysisOptionsBuilder()
700-
..strictInference = fileAnalysisOptions.strictInference
701-
..contextFeatures =
702-
FeatureSet.latestLanguageVersion() as ExperimentStatus
703-
..nonPackageFeatureSet = FeatureSet.latestLanguageVersion())
704-
.build();
701+
var analysisOptions =
702+
(AnalysisOptionsBuilder()
703+
..strictInference = fileAnalysisOptions.strictInference
704+
..contextFeatures =
705+
FeatureSet.latestLanguageVersion() as ExperimentStatus
706+
..nonPackageFeatureSet = FeatureSet.latestLanguageVersion())
707+
.build();
705708

706709
if (fsState == null) {
707710
var featureSetProvider = FeatureSetProvider.build(
@@ -730,6 +733,7 @@ class FileResolver {
730733
onNewFile: (file) {},
731734
testData: testData?.fileSystem,
732735
unlinkedUnitStore: UnlinkedUnitStoreImpl(),
736+
withFineDependencies: false,
733737
);
734738
}
735739

@@ -759,8 +763,12 @@ class FileResolver {
759763
sourceFactory: sourceFactory,
760764
externalSummaries: SummaryDataStore(),
761765
packagesFile: null,
766+
withFineDependencies: false,
762767
testData: testData?.libraryContext,
763-
linkedBundleProvider: LinkedBundleProvider(byteStore: byteStore),
768+
linkedBundleProvider: LinkedBundleProvider(
769+
byteStore: byteStore,
770+
withFineDependencies: false,
771+
),
764772
);
765773

766774
contextObjects!.analysisSession.elementFactory =
@@ -783,8 +791,8 @@ class FileResolver {
783791
YamlMap? optionMap;
784792

785793
var separator = resourceProvider.pathContext.separator;
786-
var isThirdParty = path
787-
.contains('${separator}third_party${separator}dart$separator') ||
794+
var isThirdParty =
795+
path.contains('${separator}third_party${separator}dart$separator') ||
788796
path.contains('${separator}third_party${separator}dart_lang$separator');
789797

790798
File? optionsFile;
@@ -882,15 +890,16 @@ class FileResolver {
882890
);
883891
unitResult.unit.accept(visitor);
884892
var lineInfo = unitResult.lineInfo;
885-
var infos = visitor.results
886-
.map(
887-
(searchResult) => CiderSearchInfo(
888-
lineInfo.getLocation(searchResult.offset),
889-
searchResult.length,
890-
MatchKind.REFERENCE,
891-
),
892-
)
893-
.toList();
893+
var infos =
894+
visitor.results
895+
.map(
896+
(searchResult) => CiderSearchInfo(
897+
lineInfo.getLocation(searchResult.offset),
898+
searchResult.length,
899+
MatchKind.REFERENCE,
900+
),
901+
)
902+
.toList();
894903
results.add(CiderSearchMatch(unitPath, infos));
895904
}
896905
return results;

0 commit comments

Comments
 (0)