Skip to content

Commit ca5c636

Browse files
scheglovCommit Queue
authored andcommitted
Fine. Add tracking annotations for LibraryElementImpl.context and related.
Change-Id: Id903a6d832a4af86fc9fc4e4e3c6db90393ef8fd Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/449385 Reviewed-by: Johnni Winther <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent b1321b8 commit ca5c636

File tree

5 files changed

+170
-21
lines changed

5 files changed

+170
-21
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import 'dart:typed_data';
77
import 'package:_fe_analyzer_shared/src/util/dependency_walker.dart'
88
as graph
99
show DependencyWalker, Node;
10-
import 'package:analyzer/src/dart/analysis/driver.dart';
1110
import 'package:analyzer/src/dart/analysis/file_state.dart';
1211
import 'package:analyzer/src/summary/api_signature.dart';
1312
import 'package:analyzer/src/utilities/extensions/collection.dart';
@@ -211,7 +210,7 @@ class _LibraryWalker extends graph.DependencyWalker<_LibraryNode> {
211210
{
212211
var manifestBuilder = ApiSignature();
213212
var apiSignatureBuilder = ApiSignature();
214-
manifestBuilder.addInt(AnalysisDriver.DATA_VERSION);
213+
manifestBuilder.addUint32List(_salt);
215214
var sortedFiles = libraries
216215
.expand((library) => library.files)
217216
.sortedBy((file) => file.path);

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

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import 'package:_fe_analyzer_shared/src/types/shared_type.dart'
1010
as shared
1111
show Variance;
1212
import 'package:_fe_analyzer_shared/src/types/shared_type.dart' hide Variance;
13+
import 'package:analyzer/dart/analysis/declared_variables.dart';
1314
import 'package:analyzer/dart/analysis/features.dart';
1415
import 'package:analyzer/dart/analysis/session.dart';
1516
import 'package:analyzer/dart/ast/token.dart';
@@ -831,7 +832,7 @@ class ConstructorElementImpl extends ExecutableElementImpl
831832
void computeConstantDependencies() {
832833
if (!isConstantEvaluated) {
833834
computeConstants(
834-
declaredVariables: library.context.declaredVariables,
835+
declaredVariables: library.declaredVariables,
835836
constants: [this],
836837
featureSet: library.featureSet,
837838
configuration: ConstantEvaluationConfiguration(),
@@ -1612,7 +1613,7 @@ class ElementAnnotationImpl
16121613
if (evaluationResult == null) {
16131614
var library = libraryFragment.element;
16141615
computeConstants(
1615-
declaredVariables: library.context.declaredVariables,
1616+
declaredVariables: library.declaredVariables,
16161617
constants: [this],
16171618
featureSet: library.featureSet,
16181619
configuration: ConstantEvaluationConfiguration(),
@@ -5880,7 +5881,7 @@ class LabelFragmentImpl extends FragmentImpl implements LabelFragment {
58805881
class LibraryElementImpl extends ElementImpl
58815882
with DeferredResolutionReadingMixin
58825883
implements LibraryElement {
5883-
final AnalysisContext context;
5884+
final AnalysisContext _context;
58845885

58855886
@override
58865887
@trackedIncludedInId
@@ -5977,7 +5978,7 @@ class LibraryElementImpl extends ElementImpl
59775978
/// Initialize a newly created library element in the given [context] to have
59785979
/// the given [name] and [offset].
59795980
LibraryElementImpl(
5980-
this.context,
5981+
this._context,
59815982
this.session,
59825983
this.name,
59835984
this.nameOffset,
@@ -6024,6 +6025,17 @@ class LibraryElementImpl extends ElementImpl
60246025
_classes = value;
60256026
}
60266027

6028+
@trackedDirectlyOpaque
6029+
AnalysisContext get context {
6030+
globalResultRequirements?.recordOpaqueApiUse(this, 'context');
6031+
return _context;
6032+
}
6033+
6034+
@trackedIncludedInId
6035+
DeclaredVariables get declaredVariables {
6036+
return _context.declaredVariables;
6037+
}
6038+
60276039
@override
60286040
@trackedIncludedInId
60296041
Null get enclosingElement => null;
@@ -6198,6 +6210,11 @@ class LibraryElementImpl extends ElementImpl
61986210
return DartUriResolver.isDartUri(uri);
61996211
}
62006212

6213+
@trackedIndirectly
6214+
bool get isInternalSdkLibrary {
6215+
return '$uri'.startsWith('dart:_');
6216+
}
6217+
62016218
@override
62026219
bool get isSynthetic {
62036220
return hasModifier(Modifier.SYNTHETIC);
@@ -10970,7 +10987,7 @@ abstract class VariableElementImpl extends ElementImpl
1097010987
return null;
1097110988
}
1097210989
computeConstants(
10973-
declaredVariables: library.context.declaredVariables,
10990+
declaredVariables: library.declaredVariables,
1097410991
constants: [this],
1097510992
featureSet: library.featureSet,
1097610993
configuration: ConstantEvaluationConfiguration(),

pkg/analyzer/lib/src/generated/error_verifier.dart

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3147,14 +3147,7 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
31473147
}
31483148

31493149
// should be private
3150-
var sdk = _currentLibrary.context.sourceFactory.dartSdk!;
3151-
var uri = exportedLibrary.uri.toString();
3152-
3153-
var sdkLibrary = sdk.getSdkLibrary(uri);
3154-
if (sdkLibrary == null) {
3155-
return;
3156-
}
3157-
if (!sdkLibrary.isInternal) {
3150+
if (!(exportedLibrary as LibraryElementImpl).isInternalSdkLibrary) {
31583151
return;
31593152
}
31603153

@@ -3704,10 +3697,7 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
37043697
}
37053698

37063699
// should be private
3707-
var sdk = _currentLibrary.context.sourceFactory.dartSdk!;
3708-
var uri = importedLibrary.uri.toString();
3709-
var sdkLibrary = sdk.getSdkLibrary(uri);
3710-
if (sdkLibrary == null || !sdkLibrary.isInternal) {
3700+
if (!(importedLibrary as LibraryElementImpl).isInternalSdkLibrary) {
37113701
return;
37123702
}
37133703
// The only way an import URI's `stringValue` can be `null` is if the string

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

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82435,6 +82435,149 @@ import 'a.dart';
8243582435
);
8243682436
}
8243782437

82438+
test_requirements_declaredVariables_change_getErrors() async {
82439+
newFile(testFile.path, '');
82440+
82441+
configuration
82442+
..withAnalyzeFileEvents = false
82443+
..withGetErrorsEvents = false
82444+
..withLinkLibraryCycle = true
82445+
..withResultRequirements = true
82446+
..withStreamResolvedUnitResults = false;
82447+
82448+
// Record the precise accessor use.
82449+
_ManualRequirements.install((state) {
82450+
state.singleUnit.libraryElement.declaredVariables.get('X');
82451+
});
82452+
82453+
{
82454+
await disposeAnalysisContextCollection();
82455+
declaredVariables = {'X': '1'};
82456+
82457+
var driver = driverFor(testFile);
82458+
var collector = DriverEventCollector(driver, idProvider: idProvider);
82459+
82460+
collector.getErrors('E1', testFile);
82461+
await assertEventsText(collector, r'''
82462+
[status] working
82463+
[operation] linkLibraryCycle SDK
82464+
[operation] linkLibraryCycle
82465+
package:test/test.dart
82466+
requirements
82467+
[operation] analyzedLibrary
82468+
file: /home/test/lib/test.dart
82469+
requirements
82470+
[status] idle
82471+
''');
82472+
}
82473+
82474+
{
82475+
await disposeAnalysisContextCollection();
82476+
declaredVariables = {'X': '2'};
82477+
82478+
var driver = driverFor(testFile);
82479+
var collector = DriverEventCollector(driver, idProvider: idProvider);
82480+
82481+
collector.getErrors('E2', testFile);
82482+
await assertEventsText(collector, r'''
82483+
[status] working
82484+
[operation] linkLibraryCycle SDK
82485+
[operation] linkLibraryCycle
82486+
package:test/test.dart
82487+
requirements
82488+
[operation] analyzedLibrary
82489+
file: /home/test/lib/test.dart
82490+
requirements
82491+
[status] idle
82492+
''');
82493+
}
82494+
}
82495+
82496+
test_requirements_declaredVariables_change_getLibrary() async {
82497+
newFile('$testPackageLibPath/foo.dart', 'class A {}');
82498+
newFile('$testPackageLibPath/bar.dart', 'class A {}');
82499+
82500+
newFile(testFile.path, r'''
82501+
import 'foo.dart'
82502+
if (X) 'bar.dart';
82503+
void f(A _) {}
82504+
''');
82505+
82506+
configuration
82507+
..withAnalyzeFileEvents = false
82508+
..withGetErrorsEvents = false
82509+
..withLinkLibraryCycle = true
82510+
..withResultRequirements = true
82511+
..withStreamResolvedUnitResults = false
82512+
..withGetLibraryByUriElement = false;
82513+
82514+
{
82515+
await disposeAnalysisContextCollection();
82516+
declaredVariables = {'X': 'false'};
82517+
82518+
var driver = driverFor(testFile);
82519+
var collector = DriverEventCollector(driver, idProvider: idProvider);
82520+
82521+
collector.getLibraryByUri('E1', 'package:test/test.dart');
82522+
await assertEventsText(collector, r'''
82523+
[status] working
82524+
[operation] linkLibraryCycle SDK
82525+
[operation] linkLibraryCycle
82526+
package:test/foo.dart
82527+
requirements
82528+
[operation] linkLibraryCycle
82529+
package:test/test.dart
82530+
requirements
82531+
libraries
82532+
package:test/foo.dart
82533+
exportedTopLevels
82534+
A: #M0
82535+
A=: <null>
82536+
reExportDeprecatedOnly
82537+
A: false
82538+
[status] idle
82539+
[future] getLibraryByUri E1
82540+
''');
82541+
}
82542+
82543+
{
82544+
await disposeAnalysisContextCollection();
82545+
declaredVariables = {'X': 'true'};
82546+
82547+
var driver = driverFor(testFile);
82548+
var collector = DriverEventCollector(driver, idProvider: idProvider);
82549+
82550+
collector.getLibraryByUri('E2', 'package:test/foo.dart');
82551+
collector.getLibraryByUri('E3', 'package:test/bar.dart');
82552+
82553+
collector.getLibraryByUri('E4', 'package:test/test.dart');
82554+
await assertEventsText(collector, r'''
82555+
[status] working
82556+
[operation] linkLibraryCycle SDK
82557+
[operation] linkLibraryCycle
82558+
package:test/foo.dart
82559+
requirements
82560+
[operation] linkLibraryCycle
82561+
package:test/bar.dart
82562+
requirements
82563+
[operation] linkLibraryCycle
82564+
package:test/test.dart
82565+
requirements
82566+
libraries
82567+
package:test/bar.dart
82568+
exportedTopLevels
82569+
A: #M1
82570+
A=: <null>
82571+
reExportDeprecatedOnly
82572+
A: false
82573+
[status] idle
82574+
[future] getLibraryByUri E2
82575+
[future] getLibraryByUri E3
82576+
[future] getLibraryByUri E4
82577+
''');
82578+
}
82579+
}
82580+
8243882581
Future<void> _runChangeScenario({
8243982582
required _FineOperation operation,
8244082583
String? expectedInitialEvents,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -631,8 +631,8 @@ class DriverEventsPrinter {
631631
void _writeRequirementFailure(RequirementFailure failure) {
632632
switch (failure) {
633633
case LibraryMissing():
634-
// TODO(scheglov): Handle this case.
635-
throw UnimplementedError();
634+
sink.writelnWithIndent('libraryMissing');
635+
sink.writeProperties({'uri': failure.uri});
636636
case ExportCountMismatch():
637637
sink.writelnWithIndent('exportCountMismatch');
638638
sink.writeProperties({

0 commit comments

Comments
 (0)