Skip to content

Commit 0a0f838

Browse files
committed
Collect Fingerprints for Nested Decls
Serialization was reporting that it did not have fingerprints for these declarations. When combined with the driver's new type body fingerprint work for extensions, this effectively hid changes to the bodies of these nested types from the driver's incremental build infrastructure. Make sure we recur into all of the iterable decl contexts when serializing decls to collect as many fingerprints as we can. rdar://83469936
1 parent b03cde6 commit 0a0f838

File tree

8 files changed

+89
-1
lines changed

8 files changed

+89
-1
lines changed

lib/Serialization/Serialization.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5202,6 +5202,7 @@ static void collectInterestingNestedDeclarations(
52025202
Serializer::ObjCMethodTable &objcMethods,
52035203
Serializer::NestedTypeDeclsTable &nestedTypeDecls,
52045204
Serializer::UniquedDerivativeFunctionConfigTable &derivativeConfigs,
5205+
Serializer::DeclFingerprintsTable &declFingerprints,
52055206
bool isLocal = false) {
52065207
const NominalTypeDecl *nominalParent = nullptr;
52075208

@@ -5269,10 +5270,15 @@ static void collectInterestingNestedDeclarations(
52695270

52705271
// Recurse into nested declarations.
52715272
if (auto iterable = dyn_cast<IterableDeclContext>(member)) {
5273+
if (auto bodyFP = iterable->getBodyFingerprint()) {
5274+
declFingerprints.insert({S.addDeclRef(member), *bodyFP});
5275+
}
5276+
52725277
collectInterestingNestedDeclarations(S, iterable->getAllMembers(),
52735278
operatorMethodDecls,
52745279
objcMethods, nestedTypeDecls,
52755280
derivativeConfigs,
5281+
declFingerprints,
52765282
isLocal);
52775283
}
52785284
}
@@ -5354,7 +5360,8 @@ void Serializer::writeAST(ModuleOrSourceFile DC) {
53545360
collectInterestingNestedDeclarations(*this, IDC->getAllMembers(),
53555361
operatorMethodDecls, objcMethods,
53565362
nestedTypeDecls,
5357-
uniquedDerivativeConfigs);
5363+
uniquedDerivativeConfigs,
5364+
declFingerprints);
53585365
}
53595366
}
53605367

@@ -5388,6 +5395,7 @@ void Serializer::writeAST(ModuleOrSourceFile DC) {
53885395
operatorMethodDecls, objcMethods,
53895396
nestedTypeDecls,
53905397
uniquedDerivativeConfigs,
5398+
declFingerprints,
53915399
/*isLocal=*/true);
53925400
}
53935401
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
struct S {}
2+
3+
extension S {
4+
enum A {
5+
case a1
6+
var pi: Int {3}
7+
}
8+
enum B {
9+
case a1
10+
}
11+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
struct S {}
2+
3+
extension S {
4+
enum A {
5+
case a1
6+
}
7+
enum B {
8+
case a1
9+
}
10+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"main.swift": {
3+
"object": "./main.o",
4+
"swift-dependencies": "./main.swiftdeps"
5+
},
6+
"definesAB.swift": {
7+
"object": "./definesAB.o",
8+
"swift-dependencies": "./definesAB.swiftdeps"
9+
},
10+
"usesA.swift": {
11+
"object": "./usesA.o",
12+
"swift-dependencies": "./usesA.swiftdeps"
13+
},
14+
"usesB.swift": {
15+
"object": "./usesB.o",
16+
"swift-dependencies": "./usesB.swiftdeps"
17+
},
18+
"": {
19+
"swift-dependencies": "./main~buildrecord.swiftdeps"
20+
}
21+
}
22+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
let a = S.A.a1
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
let b = S.B.a1
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Test per-type-body fingerprints for enums nested in extensions
2+
//
3+
4+
// Establish status quo
5+
6+
// RUN: %empty-directory(%t)
7+
// RUN: cp %S/Inputs/nested-enum-fingerprint/* %t
8+
// RUN: cp %t/definesAB{-before,}.swift
9+
10+
// Seeing weird failure on CI, so set the mod times
11+
// RUN: touch -t 200101010101 %t/*.swift
12+
13+
// RUN: cd %t && %target-swiftc_driver -enable-batch-mode -j2 -incremental -driver-show-incremental main.swift definesAB.swift usesA.swift usesB.swift -module-name main -output-file-map ofm.json >&output3
14+
15+
// only-run-for-debugging: cp %t/usesB.swiftdeps %t/usesB3.swiftdeps
16+
17+
18+
// Change one type, only uses of that type get recompiled
19+
20+
// RUN: cp %t/definesAB{-after,}.swift
21+
22+
// Seeing weird failure on CI, so ensure that definesAB.swift is newer
23+
// RUN: touch -t 200201010101 %t/*
24+
// RUN: touch -t 200101010101 %t/*.swift
25+
// RUN: touch -t 200301010101 %t/definesAB.swift
26+
27+
// RUN: cd %t && %target-swiftc_driver -enable-batch-mode -j2 -incremental -driver-show-incremental main.swift definesAB.swift usesA.swift usesB.swift -module-name main -output-file-map ofm.json >&output4
28+
29+
// only-run-for-debugging: cp %t/usesB.swiftdeps %t/usesB4.swiftdeps
30+
31+
// RUN: %FileCheck -check-prefix=CHECK-MAINAB-RECOMPILED %s < %t/output4
32+
33+
// CHECK-MAINAB-RECOMPILED: Queuing (initial): {compile: definesAB.o <= definesAB.swift}
34+
// CHECK-MAINAB-RECOMPILED: Queuing because of dependencies discovered later: {compile: usesA.o <= usesA.swift}

0 commit comments

Comments
 (0)