Skip to content

Commit 6e9b3a1

Browse files
scheglovCommit Queue
authored andcommitted
Fine. Record LibraryElementImpl.isSynthetic
Flag `hasPartOfDirective` was not used, and so removed. Change-Id: Id73615d0b06be65d59ad76bdd4cb3da8daa1b220 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/449922 Reviewed-by: Paul Berry <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent 5f22076 commit 6e9b3a1

File tree

8 files changed

+141
-18
lines changed

8 files changed

+141
-18
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ testFineAfterLibraryAnalyzerHook;
106106
// TODO(scheglov): Clean up the list of implicitly analyzed files.
107107
class AnalysisDriver {
108108
/// The version of data format, should be incremented on every format change.
109-
static const int DATA_VERSION = 556;
109+
static const int DATA_VERSION = 557;
110110

111111
/// The number of exception contexts allowed to write. Once this field is
112112
/// zero, we stop writing any new exception contexts in this process.

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

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6211,14 +6211,6 @@ class LibraryElementImpl extends ElementImpl
62116211
_getters = value;
62126212
}
62136213

6214-
bool get hasPartOfDirective {
6215-
return hasModifier(Modifier.HAS_PART_OF_DIRECTIVE);
6216-
}
6217-
6218-
set hasPartOfDirective(bool hasPartOfDirective) {
6219-
setModifier(Modifier.HAS_PART_OF_DIRECTIVE, hasPartOfDirective);
6220-
}
6221-
62226214
@override
62236215
@trackedIndirectly
62246216
String get identifier => '$uri';
@@ -6243,7 +6235,9 @@ class LibraryElementImpl extends ElementImpl
62436235
}
62446236

62456237
@override
6238+
@trackedDirectly
62466239
bool get isSynthetic {
6240+
globalResultRequirements?.record_library_isSynthetic(element: this);
62476241
return hasModifier(Modifier.SYNTHETIC);
62486242
}
62496243

@@ -8581,11 +8575,6 @@ enum Modifier {
85818575
/// initializer.
85828576
HAS_INITIALIZER,
85838577

8584-
/// A flag used for libraries indicating that the defining compilation unit
8585-
/// has a `part of` directive, meaning that this unit should be a part,
8586-
/// but is used as a library.
8587-
HAS_PART_OF_DIRECTIVE,
8588-
85898578
/// Indicates that the value of [FragmentImpl.sinceSdkVersion] was computed.
85908579
HAS_SINCE_SDK_VERSION_COMPUTED,
85918580

pkg/analyzer/lib/src/fine/library_manifest.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import 'package:collection/collection.dart';
2424
/// The manifest of a single library.
2525
class LibraryManifest {
2626
final String? name;
27+
final bool isSynthetic;
2728
final Uint8List featureSet;
2829
final ManifestLibraryLanguageVersion languageVersion;
2930
final LibraryMetadataItem libraryMetadata;
@@ -53,6 +54,7 @@ class LibraryManifest {
5354

5455
LibraryManifest({
5556
required this.name,
57+
required this.isSynthetic,
5658
required this.featureSet,
5759
required this.languageVersion,
5860
required this.libraryMetadata,
@@ -75,6 +77,7 @@ class LibraryManifest {
7577
factory LibraryManifest.read(SummaryDataReader reader) {
7678
return LibraryManifest(
7779
name: reader.readOptionalStringUtf8(),
80+
isSynthetic: reader.readBool(),
7881
featureSet: reader.readUint8List(),
7982
languageVersion: ManifestLibraryLanguageVersion.read(reader),
8083
libraryMetadata: LibraryMetadataItem.read(reader),
@@ -157,6 +160,7 @@ class LibraryManifest {
157160

158161
void write(BufferedSink sink) {
159162
sink.writeOptionalStringUtf8(name);
163+
sink.writeBool(isSynthetic);
160164
sink.writeUint8List(featureSet);
161165
languageVersion.write(sink);
162166
libraryMetadata.write(sink);
@@ -877,6 +881,7 @@ class LibraryManifestBuilder {
877881

878882
var newManifest = LibraryManifest(
879883
name: libraryElement.name.nullIfEmpty,
884+
isSynthetic: libraryElement.isSynthetic,
880885
featureSet: (libraryElement.featureSet as ExperimentStatus).toStorage(),
881886
languageVersion: ManifestLibraryLanguageVersion.encode(
882887
libraryElement.languageVersion,
@@ -1103,6 +1108,7 @@ class LibraryManifestBuilder {
11031108
return inputManifests[uri] ??
11041109
LibraryManifest(
11051110
name: null,
1111+
isSynthetic: false,
11061112
featureSet: Uint8List(0),
11071113
languageVersion: ManifestLibraryLanguageVersion.empty(),
11081114
libraryMetadata: LibraryMetadataItem.empty(),

pkg/analyzer/lib/src/fine/requirement_failure.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,24 @@ class LibraryFeatureSetMismatch extends RequirementFailure {
334334
}
335335
}
336336

337+
class LibraryIsSyntheticMismatch extends RequirementFailure {
338+
final Uri libraryUri;
339+
final bool expected;
340+
final bool actual;
341+
342+
LibraryIsSyntheticMismatch({
343+
required this.libraryUri,
344+
required this.expected,
345+
required this.actual,
346+
});
347+
348+
@override
349+
String toString() {
350+
return 'LibraryIsSyntheticMismatch(libraryUri: $libraryUri, '
351+
'expected: $expected, actual: $actual)';
352+
}
353+
}
354+
337355
class LibraryLanguageVersionMismatch extends RequirementFailure {
338356
final Uri libraryUri;
339357
final ManifestLibraryLanguageVersion expected;

pkg/analyzer/lib/src/fine/requirements.dart

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@ class LibraryExportRequirements {
372372

373373
class LibraryRequirements {
374374
String? name;
375+
bool? isSynthetic;
375376
Uint8List? featureSet;
376377
ManifestLibraryLanguageVersion? languageVersion;
377378
ManifestItemId? libraryMetadataId;
@@ -417,6 +418,7 @@ class LibraryRequirements {
417418

418419
LibraryRequirements({
419420
required this.name,
421+
required this.isSynthetic,
420422
required this.featureSet,
421423
required this.languageVersion,
422424
required this.libraryMetadataId,
@@ -451,6 +453,7 @@ class LibraryRequirements {
451453
factory LibraryRequirements.empty() {
452454
return LibraryRequirements(
453455
name: null,
456+
isSynthetic: null,
454457
featureSet: null,
455458
languageVersion: null,
456459
libraryMetadataId: null,
@@ -486,6 +489,7 @@ class LibraryRequirements {
486489
factory LibraryRequirements.read(SummaryDataReader reader) {
487490
return LibraryRequirements(
488491
name: reader.readOptionalStringUtf8(),
492+
isSynthetic: reader.readOptionalBool(),
489493
featureSet: reader.readOptionalUint8List(),
490494
languageVersion: ManifestLibraryLanguageVersion.readOptional(reader),
491495
libraryMetadataId: ManifestItemId.readOptional(reader),
@@ -529,6 +533,7 @@ class LibraryRequirements {
529533

530534
void write(BufferedSink sink) {
531535
sink.writeOptionalStringUtf8(name);
536+
sink.writeOptionalBool(isSynthetic);
532537
sink.writeOptionalUint8List(featureSet);
533538
sink.writeOptionalObject(languageVersion, (it) => it.write(sink));
534539
libraryMetadataId.writeOptional(sink);
@@ -726,6 +731,17 @@ class RequirementsManifest {
726731
}
727732
}
728733

734+
if (libraryRequirements.isSynthetic case var expected?) {
735+
var actual = libraryManifest.isSynthetic;
736+
if (expected != actual) {
737+
return LibraryIsSyntheticMismatch(
738+
libraryUri: libraryUri,
739+
expected: expected,
740+
actual: actual,
741+
);
742+
}
743+
}
744+
729745
if (libraryRequirements.featureSet case var expected?) {
730746
var actual = libraryManifest.featureSet;
731747
if (!const ListEquality<int>().equals(expected, actual)) {
@@ -2046,6 +2062,20 @@ class RequirementsManifest {
20462062
requirements.requestedDeclaredTypeAliases[lookupName] = id;
20472063
}
20482064

2065+
void record_library_isSynthetic({required LibraryElementImpl element}) {
2066+
if (_recordingLockLevel != 0) {
2067+
return;
2068+
}
2069+
2070+
var manifest = element.manifest;
2071+
if (manifest == null) {
2072+
return;
2073+
}
2074+
2075+
var requirements = _getLibraryRequirements(element);
2076+
requirements.isSynthetic = manifest.isSynthetic;
2077+
}
2078+
20492079
void record_library_languageVersion({required LibraryElementImpl element}) {
20502080
if (_recordingLockLevel != 0) {
20512081
return;

pkg/analyzer/lib/src/summary2/element_builder.dart

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1645,10 +1645,7 @@ class FragmentBuilder extends ThrowingAstVisitor<void> {
16451645
}
16461646

16471647
@override
1648-
void visitPartOfDirective(PartOfDirective node) {
1649-
var libraryElement = _libraryBuilder.element;
1650-
libraryElement.hasPartOfDirective = true;
1651-
}
1648+
void visitPartOfDirective(PartOfDirective node) {}
16521649

16531650
@override
16541651
void visitRecordTypeAnnotation(RecordTypeAnnotation node) {

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

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31848,6 +31848,75 @@ typedef C = int;
3184831848
);
3184931849
}
3185031850

31851+
test_dependency_libraryElement_isSynthetic() async {
31852+
configuration
31853+
..withGetErrorsEvents = false
31854+
..withStreamResolvedUnitResults = false;
31855+
31856+
_ManualRequirements.install((state) {
31857+
var library = state.singleUnit.importedLibraries.first;
31858+
library.isSynthetic;
31859+
});
31860+
31861+
newFile('$testPackageLibPath/test.dart', r'''
31862+
import 'a.dart';
31863+
''');
31864+
31865+
await _runChangeScenario(
31866+
operation: _FineOperationTestFileGetErrors(),
31867+
expectedInitialEvents: r'''
31868+
[status] working
31869+
[operation] linkLibraryCycle SDK
31870+
[operation] linkLibraryCycle
31871+
package:test/a.dart
31872+
flags: isSynthetic
31873+
requirements
31874+
[operation] linkLibraryCycle
31875+
package:test/test.dart
31876+
requirements
31877+
[operation] analyzeFile
31878+
file: /home/test/lib/test.dart
31879+
library: /home/test/lib/test.dart
31880+
[operation] analyzedLibrary
31881+
file: /home/test/lib/test.dart
31882+
requirements
31883+
libraries
31884+
package:test/a.dart
31885+
isSynthetic: true
31886+
libraryMetadataId: #M0
31887+
[status] idle
31888+
''',
31889+
updateFiles: () {
31890+
var a = newFile('$testPackageLibPath/a.dart', '');
31891+
return [a];
31892+
},
31893+
expectedUpdatedEvents: r'''
31894+
[status] working
31895+
[operation] linkLibraryCycle
31896+
package:test/a.dart
31897+
requirements
31898+
[operation] reuseLinkedBundle
31899+
package:test/test.dart
31900+
[operation] checkLibraryDiagnosticsRequirements
31901+
library: /home/test/lib/test.dart
31902+
libraryIsSyntheticMismatch
31903+
libraryUri: package:test/a.dart
31904+
expected: true
31905+
actual: false
31906+
[operation] analyzeFile
31907+
file: /home/test/lib/test.dart
31908+
library: /home/test/lib/test.dart
31909+
[operation] analyzedLibrary
31910+
file: /home/test/lib/test.dart
31911+
requirements
31912+
libraries
31913+
package:test/a.dart
31914+
libraryMetadataId: #M0
31915+
[status] idle
31916+
''',
31917+
);
31918+
}
31919+
3185131920
test_dependency_libraryElement_languageVersion() async {
3185231921
configuration
3185331922
..withGetErrorsEvents = false
@@ -32013,6 +32082,7 @@ library;
3201332082
[operation] linkLibraryCycle SDK
3201432083
[operation] linkLibraryCycle
3201532084
package:test/test.dart
32085+
flags: isSynthetic
3201632086
requirements
3201732087
[operation] analyzeFile
3201832088
file: /home/test/lib/test.dart

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ class BundleRequirementsPrinter {
6262
if (libraryRequirements.name case var name?) {
6363
sink.writelnWithIndent('name: $name');
6464
}
65+
if (libraryRequirements.isSynthetic case var value?) {
66+
if (value) {
67+
sink.writelnWithIndent('isSynthetic: $value');
68+
}
69+
}
6570
if (libraryRequirements.featureSet != null) {
6671
sink.writelnWithIndent('featureSet: <not-null>');
6772
}
@@ -666,6 +671,13 @@ class DriverEventsPrinter {
666671
case LibraryFeatureSetMismatch():
667672
sink.writelnWithIndent('libraryFeatureSetMismatch');
668673
sink.writeProperties({'libraryUri': failure.libraryUri});
674+
case LibraryIsSyntheticMismatch():
675+
sink.writelnWithIndent('libraryIsSyntheticMismatch');
676+
sink.writeProperties({
677+
'libraryUri': failure.libraryUri,
678+
'expected': failure.expected,
679+
'actual': failure.actual,
680+
});
669681
case ExportCountMismatch():
670682
sink.writelnWithIndent('exportCountMismatch');
671683
sink.writeProperties({
@@ -1147,6 +1159,7 @@ class LibraryManifestPrinter {
11471159
if (manifest.name case var name?) {
11481160
sink.writelnWithIndent('name: $name');
11491161
}
1162+
sink.writeFlags({'isSynthetic': manifest.isSynthetic});
11501163

11511164
var libraryMetadata = manifest.libraryMetadata;
11521165
if (!libraryMetadata.isEmpty) {

0 commit comments

Comments
 (0)