Skip to content

Commit 525afed

Browse files
srawlinsCommit Queue
authored andcommitted
Revert "analyzer: Support doc-imports with prefixes"
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]>
1 parent b35bb73 commit 525afed

19 files changed

+108
-962
lines changed

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ import 'package:meta/meta.dart';
9999
// TODO(scheglov): Clean up the list of implicitly analyzed files.
100100
class AnalysisDriver {
101101
/// The version of data format, should be incremented on every format change.
102-
static const int DATA_VERSION = 425;
102+
static const int DATA_VERSION = 426;
103103

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

1377+
for (var import in library.docImports) {
1378+
if (import is LibraryImportWithFile) {
1379+
if (import.importedLibrary case var libraryFileKind?) {
1380+
await libraryContext.load(
1381+
targetLibrary: libraryFileKind,
1382+
performance: OperationPerformanceImpl('<root>'),
1383+
);
1384+
}
1385+
}
1386+
}
1387+
13771388
var analysisOptions = file.analysisOptions;
13781389
var libraryElement =
13791390
libraryContext.elementFactory.libraryOfUri2(library.file.uri);

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ abstract class FileKind {
204204
List<LibraryExportState>? _libraryExports;
205205
List<LibraryImportState>? _libraryImports;
206206
List<PartIncludeState>? _partIncludes;
207-
List<LibraryImportState>? _docLibraryImports;
207+
List<LibraryImportState>? _docImports;
208208

209209
FileKind({
210210
required this.file,
@@ -223,12 +223,12 @@ abstract class FileKind {
223223
}
224224

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

231-
return _docLibraryImports =
231+
return _docImports =
232232
_unlinkedDocImports.map(_buildLibraryImportState).toFixedList();
233233
}
234234

@@ -382,7 +382,7 @@ abstract class FileKind {
382382
libraryExports;
383383
libraryImports;
384384
partIncludes;
385-
docLibraryImports;
385+
docImports;
386386
}
387387

388388
@mustCallSuper
@@ -392,7 +392,7 @@ abstract class FileKind {
392392
_libraryExports?.disposeAll();
393393
_libraryImports?.disposeAll();
394394
_partIncludes?.disposeAll();
395-
_docLibraryImports?.disposeAll();
395+
_docImports?.disposeAll();
396396
}
397397

398398
/// Dispose the containing [LibraryFileKind] cycle.

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,6 @@ class LibraryAnalyzer {
185185
ScopeResolverVisitor(
186186
fileAnalysis.errorReporter,
187187
nameScope: unitElement.scope,
188-
unitElement: unitElement,
189188
),
190189
);
191190

@@ -821,7 +820,7 @@ class LibraryAnalyzer {
821820
for (var i = 0; i < docImports.length; i++) {
822821
_resolveLibraryDocImportDirective(
823822
directive: docImports[i].import as ImportDirectiveImpl,
824-
state: fileKind.docLibraryImports[i],
823+
state: fileKind.docImports[i],
825824
errorReporter: containerErrorReporter,
826825
);
827826
}
@@ -855,10 +854,16 @@ class LibraryAnalyzer {
855854
_testingData?.recordTypeConstraintGenerationDataForTesting(
856855
fileAnalysis.file.uri, inferenceDataForTesting!);
857856

857+
var docImportLibraries = [
858+
for (var import in _library.docImports)
859+
if (import is LibraryImportWithFile)
860+
_libraryElement.session.elementFactory
861+
.libraryOfUri2(import.importedFile.uri)
862+
];
858863
unit.accept(ScopeResolverVisitor(
859864
fileAnalysis.errorReporter,
860865
nameScope: unitElement.scope,
861-
unitElement: unitElement,
866+
docImportLibraries: docImportLibraries,
862867
));
863868

864869
// Nothing for RESOLVED_UNIT8?

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,6 @@ class _LibraryNode extends graph.Node<_LibraryNode> {
195195
...fileKind.libraryExports
196196
.whereType<LibraryExportWithFile>()
197197
.map((export) => export.exportedLibrary),
198-
...fileKind.docLibraryImports
199-
.whereType<LibraryImportWithFile>()
200-
.map((import) => import.importedLibrary),
201198
];
202199
})
203200
.flattenedToList

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

Lines changed: 8 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -781,19 +781,12 @@ class CompilationUnitElementImpl extends UriReferencedElementImpl
781781
List<LibraryImportElementImpl> _libraryImports =
782782
_Sentinel.libraryImportElement;
783783

784-
/// The libraries imported by this unit with a `@docImport`.
785-
List<LibraryImportElementImpl> _docLibraryImports =
786-
_Sentinel.libraryImportElement;
787-
788784
/// The cached list of prefixes from [libraryImports].
789785
List<PrefixElementImpl>? _libraryImportPrefixes;
790786

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

794-
/// The cached list of prefixes from [docLibraryImports].
795-
List<PrefixElementImpl2>? _docLibraryImportPrefixes;
796-
797790
/// The parts included by this unit.
798791
List<PartElementImpl> _parts = const <PartElementImpl>[];
799792

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

909-
List<PrefixElementImpl2> get docLibraryImportPrefixes {
910-
return _docLibraryImportPrefixes ??= _buildDocLibraryImportPrefixes();
911-
}
912-
913-
List<LibraryImportElementImpl> get docLibraryImports {
914-
linkedData?.read(this);
915-
return _docLibraryImports;
916-
}
917-
918-
set docLibraryImports(List<LibraryImportElementImpl> imports) {
919-
_docLibraryImports = imports;
920-
}
921-
922-
List<LibraryImportElementImpl> get docLibraryImports_unresolved {
923-
return _docLibraryImports;
924-
}
925-
926902
@override
927903
LibraryElementImpl get element => library;
928904

@@ -1323,17 +1299,6 @@ class CompilationUnitElementImpl extends UriReferencedElementImpl
13231299
);
13241300
}
13251301

1326-
List<PrefixElementImpl2> _buildDocLibraryImportPrefixes() {
1327-
var prefixes = <PrefixElementImpl2>{};
1328-
for (var import in docLibraryImports) {
1329-
var prefix = import.prefix2?.element;
1330-
if (prefix is PrefixElementImpl2) {
1331-
prefixes.add(prefix);
1332-
}
1333-
}
1334-
return prefixes.toFixedList();
1335-
}
1336-
13371302
List<PrefixElementImpl> _buildLibraryImportPrefixes() {
13381303
var prefixes = <PrefixElementImpl>{};
13391304
for (var import in libraryImports) {
@@ -9414,13 +9379,9 @@ class PrefixElementImpl extends _ExistingElementImpl implements PrefixElement {
94149379
/// The scope of this prefix, `null` if not set yet.
94159380
PrefixScope? _scope;
94169381

9417-
final bool _isDocLibraryImport;
9418-
94199382
/// Initialize a newly created method element to have the given [name] and
94209383
/// [nameOffset].
9421-
PrefixElementImpl(String super.name, super.nameOffset,
9422-
{super.reference, required bool isDocLibraryImport})
9423-
: _isDocLibraryImport = isDocLibraryImport;
9384+
PrefixElementImpl(String super.name, super.nameOffset, {super.reference});
94249385

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

94319392
PrefixElementImpl2 get element2 {
9432-
if (_isDocLibraryImport) {
9433-
return enclosingElement3.docLibraryImportPrefixes.firstWhere((element) {
9434-
return (element.name3 ?? '') == name;
9435-
});
9436-
} else {
9437-
return enclosingElement3.prefixes.firstWhere((element) {
9438-
return (element.name3 ?? '') == name;
9439-
});
9440-
}
9393+
return enclosingElement3.prefixes.firstWhere((element) {
9394+
return (element.name3 ?? '') == name;
9395+
});
94419396
}
94429397

94439398
@override
@@ -9495,14 +9450,10 @@ class PrefixElementImpl2 extends ElementImpl2 implements PrefixElement2 {
94959450

94969451
PrefixFragmentImpl lastFragment;
94979452

9498-
final bool _isDocLibraryImport;
9499-
95009453
PrefixElementImpl2({
95019454
required this.reference,
95029455
required this.firstFragment,
9503-
required bool isDocLibraryImport,
9504-
}) : lastFragment = firstFragment,
9505-
_isDocLibraryImport = isDocLibraryImport {
9456+
}) : lastFragment = firstFragment {
95069457
reference.element2 = this;
95079458
}
95089459

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

95259476
@override
95269477
List<LibraryImportElementImpl> get imports {
9527-
if (_isDocLibraryImport) {
9528-
return firstFragment.enclosingFragment.docLibraryImports
9529-
.where((import) => import.prefix2?.element == this)
9530-
.toList();
9531-
} else {
9532-
return firstFragment.enclosingFragment.libraryImports
9533-
.where((import) => import.prefix2?.element == this)
9534-
.toList();
9535-
}
9478+
return firstFragment.enclosingFragment.libraryImports
9479+
.where((import) => import.prefix2?.element == this)
9480+
.toList();
95369481
}
95379482

95389483
@override

0 commit comments

Comments
 (0)