Skip to content

Commit

Permalink
Revert "analyzer: Support doc-imports with prefixes"
Browse files Browse the repository at this point in the history
This reverts commit 292987f.

The commit appears to poorly regress:

* analysis-server-cold-analysis RunTimeRaw by 16%
* analysis-server-cold-memory Memoryuse by 24%

Change-Id: I82363a7efca0ccaabd3dc0f58ab0bbd699f4cdae
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/403502
Commit-Queue: Samuel Rawlins <[email protected]>
Reviewed-by: Brian Wilkerson <[email protected]>
Reviewed-by: Konstantin Shcheglov <[email protected]>
  • Loading branch information
srawlins authored and Commit Queue committed Jan 8, 2025
1 parent b35bb73 commit 525afed
Show file tree
Hide file tree
Showing 19 changed files with 108 additions and 962 deletions.
13 changes: 12 additions & 1 deletion pkg/analyzer/lib/src/dart/analysis/driver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ import 'package:meta/meta.dart';
// TODO(scheglov): Clean up the list of implicitly analyzed files.
class AnalysisDriver {
/// The version of data format, should be incremented on every format change.
static const int DATA_VERSION = 425;
static const int DATA_VERSION = 426;

/// The number of exception contexts allowed to write. Once this field is
/// zero, we stop writing any new exception contexts in this process.
Expand Down Expand Up @@ -1374,6 +1374,17 @@ class AnalysisDriver {
},
);

for (var import in library.docImports) {
if (import is LibraryImportWithFile) {
if (import.importedLibrary case var libraryFileKind?) {
await libraryContext.load(
targetLibrary: libraryFileKind,
performance: OperationPerformanceImpl('<root>'),
);
}
}
}

var analysisOptions = file.analysisOptions;
var libraryElement =
libraryContext.elementFactory.libraryOfUri2(library.file.uri);
Expand Down
12 changes: 6 additions & 6 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>? _docLibraryImports;
List<LibraryImportState>? _docImports;

FileKind({
required this.file,
Expand All @@ -223,12 +223,12 @@ abstract class FileKind {
}

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

return _docLibraryImports =
return _docImports =
_unlinkedDocImports.map(_buildLibraryImportState).toFixedList();
}

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

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

/// Dispose the containing [LibraryFileKind] cycle.
Expand Down
11 changes: 8 additions & 3 deletions pkg/analyzer/lib/src/dart/analysis/library_analyzer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ class LibraryAnalyzer {
ScopeResolverVisitor(
fileAnalysis.errorReporter,
nameScope: unitElement.scope,
unitElement: unitElement,
),
);

Expand Down Expand Up @@ -821,7 +820,7 @@ class LibraryAnalyzer {
for (var i = 0; i < docImports.length; i++) {
_resolveLibraryDocImportDirective(
directive: docImports[i].import as ImportDirectiveImpl,
state: fileKind.docLibraryImports[i],
state: fileKind.docImports[i],
errorReporter: containerErrorReporter,
);
}
Expand Down Expand Up @@ -855,10 +854,16 @@ class LibraryAnalyzer {
_testingData?.recordTypeConstraintGenerationDataForTesting(
fileAnalysis.file.uri, inferenceDataForTesting!);

var docImportLibraries = [
for (var import in _library.docImports)
if (import is LibraryImportWithFile)
_libraryElement.session.elementFactory
.libraryOfUri2(import.importedFile.uri)
];
unit.accept(ScopeResolverVisitor(
fileAnalysis.errorReporter,
nameScope: unitElement.scope,
unitElement: unitElement,
docImportLibraries: docImportLibraries,
));

// Nothing for RESOLVED_UNIT8?
Expand Down
3 changes: 0 additions & 3 deletions pkg/analyzer/lib/src/dart/analysis/library_graph.dart
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,6 @@ class _LibraryNode extends graph.Node<_LibraryNode> {
...fileKind.libraryExports
.whereType<LibraryExportWithFile>()
.map((export) => export.exportedLibrary),
...fileKind.docLibraryImports
.whereType<LibraryImportWithFile>()
.map((import) => import.importedLibrary),
];
})
.flattenedToList
Expand Down
71 changes: 8 additions & 63 deletions pkg/analyzer/lib/src/dart/element/element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -781,19 +781,12 @@ class CompilationUnitElementImpl extends UriReferencedElementImpl
List<LibraryImportElementImpl> _libraryImports =
_Sentinel.libraryImportElement;

/// The libraries imported by this unit with a `@docImport`.
List<LibraryImportElementImpl> _docLibraryImports =
_Sentinel.libraryImportElement;

/// The cached list of prefixes from [libraryImports].
List<PrefixElementImpl>? _libraryImportPrefixes;

/// The cached list of prefixes from [prefixes].
List<PrefixElementImpl2>? _libraryImportPrefixes2;

/// The cached list of prefixes from [docLibraryImports].
List<PrefixElementImpl2>? _docLibraryImportPrefixes;

/// The parts included by this unit.
List<PartElementImpl> _parts = const <PartElementImpl>[];

Expand Down Expand Up @@ -906,23 +899,6 @@ class CompilationUnitElementImpl extends UriReferencedElementImpl
@override
List<ClassFragment> get classes2 => classes.cast<ClassFragment>();

List<PrefixElementImpl2> get docLibraryImportPrefixes {
return _docLibraryImportPrefixes ??= _buildDocLibraryImportPrefixes();
}

List<LibraryImportElementImpl> get docLibraryImports {
linkedData?.read(this);
return _docLibraryImports;
}

set docLibraryImports(List<LibraryImportElementImpl> imports) {
_docLibraryImports = imports;
}

List<LibraryImportElementImpl> get docLibraryImports_unresolved {
return _docLibraryImports;
}

@override
LibraryElementImpl get element => library;

Expand Down Expand Up @@ -1323,17 +1299,6 @@ class CompilationUnitElementImpl extends UriReferencedElementImpl
);
}

List<PrefixElementImpl2> _buildDocLibraryImportPrefixes() {
var prefixes = <PrefixElementImpl2>{};
for (var import in docLibraryImports) {
var prefix = import.prefix2?.element;
if (prefix is PrefixElementImpl2) {
prefixes.add(prefix);
}
}
return prefixes.toFixedList();
}

List<PrefixElementImpl> _buildLibraryImportPrefixes() {
var prefixes = <PrefixElementImpl>{};
for (var import in libraryImports) {
Expand Down Expand Up @@ -9414,13 +9379,9 @@ class PrefixElementImpl extends _ExistingElementImpl implements PrefixElement {
/// The scope of this prefix, `null` if not set yet.
PrefixScope? _scope;

final bool _isDocLibraryImport;

/// Initialize a newly created method element to have the given [name] and
/// [nameOffset].
PrefixElementImpl(String super.name, super.nameOffset,
{super.reference, required bool isDocLibraryImport})
: _isDocLibraryImport = isDocLibraryImport;
PrefixElementImpl(String super.name, super.nameOffset, {super.reference});

@override
List<Element2> get children2 => const [];
Expand All @@ -9429,15 +9390,9 @@ class PrefixElementImpl extends _ExistingElementImpl implements PrefixElement {
String get displayName => name;

PrefixElementImpl2 get element2 {
if (_isDocLibraryImport) {
return enclosingElement3.docLibraryImportPrefixes.firstWhere((element) {
return (element.name3 ?? '') == name;
});
} else {
return enclosingElement3.prefixes.firstWhere((element) {
return (element.name3 ?? '') == name;
});
}
return enclosingElement3.prefixes.firstWhere((element) {
return (element.name3 ?? '') == name;
});
}

@override
Expand Down Expand Up @@ -9495,14 +9450,10 @@ class PrefixElementImpl2 extends ElementImpl2 implements PrefixElement2 {

PrefixFragmentImpl lastFragment;

final bool _isDocLibraryImport;

PrefixElementImpl2({
required this.reference,
required this.firstFragment,
required bool isDocLibraryImport,
}) : lastFragment = firstFragment,
_isDocLibraryImport = isDocLibraryImport {
}) : lastFragment = firstFragment {
reference.element2 = this;
}

Expand All @@ -9524,15 +9475,9 @@ class PrefixElementImpl2 extends ElementImpl2 implements PrefixElement2 {

@override
List<LibraryImportElementImpl> get imports {
if (_isDocLibraryImport) {
return firstFragment.enclosingFragment.docLibraryImports
.where((import) => import.prefix2?.element == this)
.toList();
} else {
return firstFragment.enclosingFragment.libraryImports
.where((import) => import.prefix2?.element == this)
.toList();
}
return firstFragment.enclosingFragment.libraryImports
.where((import) => import.prefix2?.element == this)
.toList();
}

@override
Expand Down
Loading

0 comments on commit 525afed

Please sign in to comment.