Skip to content

Commit

Permalink
analyzer: rename docImports to docLibraryImports in a few places
Browse files Browse the repository at this point in the history
This restores parts of commit 292987f,
theoretically no-op parts, to make the perf investigation and re-land
simpler.

Change-Id: Ib394cb56e1aec7644766b255d819db9c0910d5bb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/403391
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
  • Loading branch information
srawlins authored and Commit Queue committed Jan 9, 2025
1 parent 83db399 commit 81b1313
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 26 deletions.
2 changes: 1 addition & 1 deletion pkg/analyzer/lib/src/dart/analysis/driver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1374,7 +1374,7 @@ class AnalysisDriver {
},
);

for (var import in library.docImports) {
for (var import in library.docLibraryImports) {
if (import is LibraryImportWithFile) {
if (import.importedLibrary case var libraryFileKind?) {
await libraryContext.load(
Expand Down
17 changes: 7 additions & 10 deletions pkg/analyzer/lib/src/dart/analysis/file_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ abstract class FileKind {
List<LibraryExportState>? _libraryExports;
List<LibraryImportState>? _libraryImports;
List<PartIncludeState>? _partIncludes;
List<LibraryImportState>? _docImports;
List<LibraryImportState>? _docLibraryImports;

FileKind({
required this.file,
Expand All @@ -222,13 +222,10 @@ abstract class FileKind {
);
}

/// The import states of each `@docImport` on the library directive.
List<LibraryImportState> get docImports {
if (_docImports case var existing?) {
return existing;
}

return _docImports =
/// The import states of each `@docImport` on the library directive or
/// part-of directive.
List<LibraryImportState> get docLibraryImports {
return _docLibraryImports ??=
_unlinkedDocImports.map(_buildLibraryImportState).toFixedList();
}

Expand Down Expand Up @@ -382,7 +379,7 @@ abstract class FileKind {
libraryExports;
libraryImports;
partIncludes;
docImports;
docLibraryImports;
}

@mustCallSuper
Expand All @@ -392,7 +389,7 @@ abstract class FileKind {
_libraryExports?.disposeAll();
_libraryImports?.disposeAll();
_partIncludes?.disposeAll();
_docImports?.disposeAll();
_docLibraryImports?.disposeAll();
}

/// Dispose the containing [LibraryFileKind] cycle.
Expand Down
4 changes: 2 additions & 2 deletions pkg/analyzer/lib/src/dart/analysis/library_analyzer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,7 @@ class LibraryAnalyzer {
for (var i = 0; i < docImports.length; i++) {
_resolveLibraryDocImportDirective(
directive: docImports[i].import as ImportDirectiveImpl,
state: fileKind.docImports[i],
state: fileKind.docLibraryImports[i],
errorReporter: containerErrorReporter,
);
}
Expand Down Expand Up @@ -855,7 +855,7 @@ class LibraryAnalyzer {
fileAnalysis.file.uri, inferenceDataForTesting!);

var docImportLibraries = [
for (var import in _library.docImports)
for (var import in _library.docLibraryImports)
if (import is LibraryImportWithFile)
_libraryElement.session.elementFactory
.libraryOfUri2(import.importedFile.uri)
Expand Down
9 changes: 5 additions & 4 deletions pkg/analyzer/lib/src/dart/element/scope.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,19 @@ class ConstructorInitializerScope extends EnclosedScope {
}
}

/// The scope that looks up elements in doc imports.
/// The scope that looks up elements in documentation comments.
///
/// Attempts to look up elements in its [innerScope] before searching
/// through the doc imports.
class DocImportScope with _GettersAndSetters implements Scope {
/// through any doc imports.
class DocumentationCommentScope with _GettersAndSetters implements Scope {
/// The scope that will be prioritized in look ups before searching in doc
/// imports.
///
/// Will be set for each specific comment scope in the `ScopeResolverVisitor`.
Scope innerScope;

DocImportScope(this.innerScope, List<LibraryElement> docImportLibraries) {
DocumentationCommentScope(
this.innerScope, List<LibraryElement> docImportLibraries) {
for (var importedLibrary in docImportLibraries) {
if (importedLibrary is LibraryElementImpl) {
// TODO(kallentu): Handle combinators.
Expand Down
7 changes: 4 additions & 3 deletions pkg/analyzer/lib/src/generated/resolver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4524,7 +4524,7 @@ class ScopeResolverVisitor extends UnifyingAstVisitor<void> {
Scope nameScope;

/// The scope of libraries imported by `@docImport`s.
final DocImportScope _docImportScope;
final DocumentationCommentScope _docImportScope;

/// The scope used to resolve unlabeled `break` and `continue` statements.
ImplicitLabelScope _implicitLabelScope = ImplicitLabelScope.ROOT;
Expand All @@ -4551,7 +4551,8 @@ class ScopeResolverVisitor extends UnifyingAstVisitor<void> {
this.errorReporter, {
required this.nameScope,
List<LibraryElement> docImportLibraries = const [],
}) : _docImportScope = DocImportScope(nameScope, docImportLibraries);
}) : _docImportScope =
DocumentationCommentScope(nameScope, docImportLibraries);

/// Return the implicit label scope in which the current node is being
/// resolved.
Expand Down Expand Up @@ -5409,7 +5410,7 @@ class ScopeResolverVisitor extends UnifyingAstVisitor<void> {
}
}

/// Visits a documentation comment with a [DocImportScope] that encloses the
/// Visits a documentation comment with a [DocumentationCommentScope] that encloses the
/// current [nameScope].
void _visitDocumentationComment(CommentImpl? node) {
if (node == null) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ class AnalyzerStatePrinter {

void _writeDocImports(FileKind container) {
_writeElements<LibraryImportState>(
'docImports',
container.docImports,
'docLibraryImports',
container.docLibraryImports,
(import) {
expect(import.isDocImport, isTrue);
_writeLibraryImport(container, import);
Expand Down
8 changes: 4 additions & 4 deletions pkg/analyzer/test/src/dart/analysis/file_state_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1127,7 +1127,7 @@ files
kind: library_0
libraryImports
library_1 dart:core synthetic
docImports
docLibraryImports
library_3 dart:async
library_5 dart:math
fileKinds: library_0
Expand Down Expand Up @@ -4256,7 +4256,7 @@ files
kind: partOfUriKnown_1
uriFile: file_0
library: library_0
docImports
docLibraryImports
library_4 dart:async
library_6 dart:math
referencingFiles: file_0
Expand Down Expand Up @@ -4297,7 +4297,7 @@ files
kind: partOfUriKnown_7
uriFile: file_0
library: library_0
docImports
docLibraryImports
library_4 dart:async
referencingFiles: file_0
unlinkedKey: k02
Expand Down Expand Up @@ -5111,7 +5111,7 @@ class C {}

fileStateFor(a);

// `c.dart` is imported by `b.dart`, so it is a dependency of `c.dart`.
// `c.dart` is imported by `b.dart`, so it is a dependency of `a.dart`.
assertDriverStateString(testFile, r'''
files
/home/test/lib/a.dart
Expand Down

0 comments on commit 81b1313

Please sign in to comment.