Skip to content

Collect Fingerprints for Nested Decls #39450

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/Serialization/Serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5280,6 +5280,7 @@ static void collectInterestingNestedDeclarations(
Serializer::ObjCMethodTable &objcMethods,
Serializer::NestedTypeDeclsTable &nestedTypeDecls,
Serializer::UniquedDerivativeFunctionConfigTable &derivativeConfigs,
Serializer::DeclFingerprintsTable &declFingerprints,
bool isLocal = false) {
const NominalTypeDecl *nominalParent = nullptr;

Expand Down Expand Up @@ -5347,10 +5348,15 @@ static void collectInterestingNestedDeclarations(

// Recurse into nested declarations.
if (auto iterable = dyn_cast<IterableDeclContext>(member)) {
if (auto bodyFP = iterable->getBodyFingerprint()) {
declFingerprints.insert({S.addDeclRef(member), *bodyFP});
}

collectInterestingNestedDeclarations(S, iterable->getAllMembers(),
operatorMethodDecls,
objcMethods, nestedTypeDecls,
derivativeConfigs,
declFingerprints,
isLocal);
}
}
Expand Down Expand Up @@ -5432,7 +5438,8 @@ void Serializer::writeAST(ModuleOrSourceFile DC) {
collectInterestingNestedDeclarations(*this, IDC->getAllMembers(),
operatorMethodDecls, objcMethods,
nestedTypeDecls,
uniquedDerivativeConfigs);
uniquedDerivativeConfigs,
declFingerprints);
}
}

Expand Down Expand Up @@ -5466,6 +5473,7 @@ void Serializer::writeAST(ModuleOrSourceFile DC) {
operatorMethodDecls, objcMethods,
nestedTypeDecls,
uniquedDerivativeConfigs,
declFingerprints,
/*isLocal=*/true);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
struct S {}

extension S {
enum A {
case a1
var pi: Int {3}
}
enum B {
case a1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
struct S {}

extension S {
enum A {
case a1
}
enum B {
case a1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"main.swift": {
"object": "./main.o",
"swift-dependencies": "./main.swiftdeps"
},
"definesAB.swift": {
"object": "./definesAB.o",
"swift-dependencies": "./definesAB.swiftdeps"
},
"usesA.swift": {
"object": "./usesA.o",
"swift-dependencies": "./usesA.swiftdeps"
},
"usesB.swift": {
"object": "./usesB.o",
"swift-dependencies": "./usesB.swiftdeps"
},
"": {
"swift-dependencies": "./main~buildrecord.swiftdeps"
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let a = S.A.a1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let b = S.B.a1
34 changes: 34 additions & 0 deletions test/Incremental/Fingerprints/nested-enum-fingerprint.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Test per-type-body fingerprints for enums nested in extensions
//

// Establish status quo

// RUN: %empty-directory(%t)
// RUN: cp %S/Inputs/nested-enum-fingerprint/* %t
// RUN: cp %t/definesAB{-before,}.swift

// Seeing weird failure on CI, so set the mod times
// RUN: touch -t 200101010101 %t/*.swift

// 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

// only-run-for-debugging: cp %t/usesB.swiftdeps %t/usesB3.swiftdeps


// Change one type, only uses of that type get recompiled

// RUN: cp %t/definesAB{-after,}.swift

// Seeing weird failure on CI, so ensure that definesAB.swift is newer
// RUN: touch -t 200201010101 %t/*
// RUN: touch -t 200101010101 %t/*.swift
// RUN: touch -t 200301010101 %t/definesAB.swift

// 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

// only-run-for-debugging: cp %t/usesB.swiftdeps %t/usesB4.swiftdeps

// RUN: %FileCheck -check-prefix=CHECK-MAINAB-RECOMPILED %s < %t/output4

// CHECK-MAINAB-RECOMPILED: Queuing (initial): {compile: definesAB.o <= definesAB.swift}
// CHECK-MAINAB-RECOMPILED: Queuing because of dependencies discovered later: {compile: usesA.o <= usesA.swift}