Skip to content

Commit 847c92e

Browse files
scheglovCommit Queue
authored andcommitted
Fine. Track inherited members in manifest and interface ID.
Add an `inherited` map to `ManifestInterface` and populate it from `InheritanceManager3.getInheritedMap`. Include this map in serialization and in the ID computation alongside `map`, `implemented`, and `superImplemented`. The interface ID now changes when only inherited members change. Previously, if a superclass member changed (e.g. its signature) but was overridden in a subclass, the subclass’s interface ID could remain stable because only its declared/implemented members were considered. That caused stale analysis results and missed invalidations. By tracking `inherited`, interface IDs accurately reflect upstream API changes even when they are shadowed locally. Other updates: - Print the `inherited` section in `result_printer`. - Mark `inheritanceManager` as `@trackedIndirectly` and stop recording opaque API use on access. - Bump `AnalysisDriver.DATA_VERSION` to 543 due to the format change. Change-Id: I54c637bef7b10d7cb27f93ae146c96b62ff6cddd Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/448720 Reviewed-by: Johnni Winther <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent 5f3466e commit 847c92e

File tree

6 files changed

+1281
-6
lines changed

6 files changed

+1281
-6
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 = 542;
109+
static const int DATA_VERSION = 543;
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: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4827,9 +4827,8 @@ abstract class InterfaceElementImpl extends InstanceElementImpl
48274827
_hasNonFinalField = value;
48284828
}
48294829

4830-
@trackedDirectlyOpaque
4830+
@trackedIndirectly
48314831
InheritanceManager3 get inheritanceManager {
4832-
globalResultRequirements?.recordOpaqueApiUse(this, 'inheritanceManager');
48334832
return library.session.inheritanceManager;
48344833
}
48354834

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -875,7 +875,8 @@ class LibraryManifestBuilder {
875875
var item = declaredItems[element] as InterfaceItem;
876876
item.interface.beforeUpdating();
877877

878-
var interface = element.inheritanceManager.getInterface(element);
878+
var inheritance = element.inheritanceManager;
879+
var interface = inheritance.getInterface(element);
879880

880881
for (var entry in interface.map.entries) {
881882
var executable = entry.value.baseElement;
@@ -937,6 +938,15 @@ class LibraryManifestBuilder {
937938
item.interface.superImplemented.add(layer);
938939
}
939940

941+
for (var entry in inheritance.getInheritedMap(element).entries) {
942+
var executable = entry.value.baseElement;
943+
var lookupName = executable.lookupName?.asLookupName;
944+
if (lookupName != null && !lookupName.isPrivate) {
945+
var id = _getInterfaceElementMemberId(executable);
946+
item.interface.inherited[lookupName] = id;
947+
}
948+
}
949+
940950
item.interface.afterUpdate();
941951
}
942952

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,12 +1155,14 @@ class ManifestInterface {
11551155
Map<LookupName, ManifestItemId> map;
11561156
Map<LookupName, ManifestItemId> implemented;
11571157
List<Map<LookupName, ManifestItemId>> superImplemented;
1158+
Map<LookupName, ManifestItemId> inherited;
11581159

11591160
/// We move [map] into here during building the manifest, so that we can
11601161
/// compare after building, and decide if [id] should be updated.
11611162
Map<LookupName, ManifestItemId> mapPrevious = {};
11621163
Map<LookupName, ManifestItemId> implementedPrevious = {};
11631164
List<Map<LookupName, ManifestItemId>> superImplementedPrevious = [];
1165+
Map<LookupName, ManifestItemId> inheritedPrevious = {};
11641166

11651167
/// Key: IDs of method declarations.
11661168
/// Value: ID assigned last time.
@@ -1176,6 +1178,7 @@ class ManifestInterface {
11761178
required this.map,
11771179
required this.implemented,
11781180
required this.superImplemented,
1181+
required this.inherited,
11791182
required this.combinedIds,
11801183
});
11811184

@@ -1185,6 +1188,7 @@ class ManifestInterface {
11851188
map: {},
11861189
implemented: {},
11871190
superImplemented: [],
1191+
inherited: {},
11881192
combinedIds: {},
11891193
);
11901194
}
@@ -1197,6 +1201,7 @@ class ManifestInterface {
11971201
superImplemented: reader.readTypedList(() {
11981202
return reader.readLookupNameToIdMap();
11991203
}),
1204+
inherited: reader.readLookupNameToIdMap(),
12001205
combinedIds: reader.readMap(
12011206
readKey: () => ManifestItemIdList.read(reader),
12021207
readValue: () => ManifestItemId.read(reader),
@@ -1211,13 +1216,14 @@ class ManifestInterface {
12111216
);
12121217
if (!mapEquality.equals(map, mapPrevious) ||
12131218
!mapEquality.equals(implemented, implementedPrevious) ||
1214-
!listEquality.equals(superImplemented, superImplementedPrevious)) {
1219+
!listEquality.equals(superImplemented, superImplementedPrevious) ||
1220+
!mapEquality.equals(inherited, inheritedPrevious)) {
12151221
id = ManifestItemId.generate();
12161222
}
12171223
mapPrevious = {};
12181224
implementedPrevious = {};
12191225
superImplementedPrevious = [];
1220-
1226+
inheritedPrevious = {};
12211227
combinedIdsTemp = {};
12221228
}
12231229

@@ -1231,6 +1237,9 @@ class ManifestInterface {
12311237
superImplementedPrevious = superImplemented;
12321238
superImplemented = [];
12331239

1240+
inheritedPrevious = inherited;
1241+
inherited = {};
1242+
12341243
combinedIdsTemp = combinedIds;
12351244
combinedIds = {};
12361245
}
@@ -1240,6 +1249,7 @@ class ManifestInterface {
12401249
map.write(sink);
12411250
implemented.write(sink);
12421251
sink.writeList(superImplemented, (map) => map.write(sink));
1252+
inherited.write(sink);
12431253
sink.writeMap(
12441254
combinedIds,
12451255
writeKey: (key) => key.write(sink),

0 commit comments

Comments
 (0)