From 3a12738ebc30931ba6d07266ceb56802a92307f0 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Thu, 27 Feb 2020 20:44:06 -0800 Subject: [PATCH 1/3] stdlib: repair the macOS -stdlib build When building on macOS without the standard library but building the extra toolchain content, we would fail to configure due to the missing include of the `AddSwiftStdlib`. --- stdlib/toolchain/CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/stdlib/toolchain/CMakeLists.txt b/stdlib/toolchain/CMakeLists.txt index 9c072a205debd..c069ccee2c266 100644 --- a/stdlib/toolchain/CMakeLists.txt +++ b/stdlib/toolchain/CMakeLists.txt @@ -1,5 +1,8 @@ # Toolchain-only build products +list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/../cmake/modules) +include(AddSwiftStdlib) + set(CXX_COMPILE_FLAGS) set(CXX_LINK_FLAGS) From 71e8f866bb907dc7bb77f3213c5410f2fc5f51df Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Sat, 29 Feb 2020 20:47:20 -0800 Subject: [PATCH 2/3] LLVMPasses: mark the dump as debug code This limits the dumping of the variables to the debug build since `llvm::Value::dump` is only available in debug builds of LLVM. --- lib/LLVMPasses/LLVMMergeFunctions.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/LLVMPasses/LLVMMergeFunctions.cpp b/lib/LLVMPasses/LLVMMergeFunctions.cpp index da7d14e84596b..80b59e5df23a2 100644 --- a/lib/LLVMPasses/LLVMMergeFunctions.cpp +++ b/lib/LLVMPasses/LLVMMergeFunctions.cpp @@ -462,8 +462,8 @@ bool SwiftMergeFunctions::doSanityCheck(std::vector &Worklist) { if (Res1 != -Res2) { dbgs() << "MERGEFUNC-SANITY: Non-symmetric; triple: " << TripleNumber << "\n"; - F1->dump(); - F2->dump(); + LLVM_DEBUG(F1->dump()); + LLVM_DEBUG(F2->dump()); Valid = false; } @@ -500,9 +500,9 @@ bool SwiftMergeFunctions::doSanityCheck(std::vector &Worklist) { << TripleNumber << "\n"; dbgs() << "Res1, Res3, Res4: " << Res1 << ", " << Res3 << ", " << Res4 << "\n"; - F1->dump(); - F2->dump(); - F3->dump(); + LLVM_DEBUG(F1->dump()); + LLVM_DEBUG(F2->dump()); + LLVM_DEBUG(F3->dump()); Valid = false; } } From 72032493f92a4cce64fffe53c652b99f8223bd1c Mon Sep 17 00:00:00 2001 From: David Ungar Date: Sat, 29 Feb 2020 23:00:38 -0800 Subject: [PATCH 3/3] Fix and test for extension body --- include/swift/AST/DeclContext.h | 2 +- lib/AST/DeclContext.cpp | 8 +- lib/AST/FrontendSourceFileDepGraphFactory.cpp | 3 +- lib/Parse/ParseDecl.cpp | 4 +- .../definesAB-after.swift | 9 ++ .../definesAB-before.swift | 8 ++ .../Inputs/extension-adds-member/main.swift | 1 + .../Inputs/extension-adds-member/ofm.json | 22 +++++ .../Inputs/extension-adds-member/usesA.swift | 1 + .../Inputs/extension-adds-member/usesB.swift | 1 + .../Fingerprints/extension-adds-member.swift | 83 +++++++++++++++++++ 11 files changed, 136 insertions(+), 6 deletions(-) create mode 100644 test/Frontend/Fingerprints/Inputs/extension-adds-member/definesAB-after.swift create mode 100644 test/Frontend/Fingerprints/Inputs/extension-adds-member/definesAB-before.swift create mode 100644 test/Frontend/Fingerprints/Inputs/extension-adds-member/main.swift create mode 100644 test/Frontend/Fingerprints/Inputs/extension-adds-member/ofm.json create mode 100644 test/Frontend/Fingerprints/Inputs/extension-adds-member/usesA.swift create mode 100644 test/Frontend/Fingerprints/Inputs/extension-adds-member/usesB.swift create mode 100644 test/Frontend/Fingerprints/extension-adds-member.swift diff --git a/include/swift/AST/DeclContext.h b/include/swift/AST/DeclContext.h index a6cbdd6ba0aec..0ab6aa7ed1083 100644 --- a/include/swift/AST/DeclContext.h +++ b/include/swift/AST/DeclContext.h @@ -814,7 +814,7 @@ class IterableDeclContext { /// available. Optional getBodyFingerprint() const; - bool areDependenciesUsingTokenHashesForTypeBodies() const; + bool areTokensHashedForThisBodyInsteadOfInterfaceHash() const; private: /// Add a member to the list for iteration purposes, but do not notify the diff --git a/lib/AST/DeclContext.cpp b/lib/AST/DeclContext.cpp index c065a548396b9..d4405af3b3691 100644 --- a/lib/AST/DeclContext.cpp +++ b/lib/AST/DeclContext.cpp @@ -918,7 +918,13 @@ Optional IterableDeclContext::getBodyFingerprint() const { .fingerprint; } -bool IterableDeclContext::areDependenciesUsingTokenHashesForTypeBodies() const { +bool IterableDeclContext::areTokensHashedForThisBodyInsteadOfInterfaceHash() + const { + // Do not keep separate hashes for extension bodies because the dependencies + // can miss the addition of a member in an extension because there is nothing + // corresponding to the fingerprinted nominal dependency node. + if (isa(this)) + return false; return getASTContext().LangOpts.EnableTypeFingerprints; } diff --git a/lib/AST/FrontendSourceFileDepGraphFactory.cpp b/lib/AST/FrontendSourceFileDepGraphFactory.cpp index 0ccb1e9d27f24..d0b47ffe48c23 100644 --- a/lib/AST/FrontendSourceFileDepGraphFactory.cpp +++ b/lib/AST/FrontendSourceFileDepGraphFactory.cpp @@ -721,8 +721,7 @@ FrontendSourceFileDepGraphFactory::getInterfaceHash(SourceFile *SF) { return interfaceHash.str().str(); } -/// At present, only nominals, protocols, and extensions have (body) -/// fingerprints +/// At present, only \c NominalTypeDecls have (body) fingerprints Optional FrontendSourceFileDepGraphFactory::getFingerprintIfAny( std::pair) { return None; diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp index e3370620f609f..98cd4fea07e58 100644 --- a/lib/Parse/ParseDecl.cpp +++ b/lib/Parse/ParseDecl.cpp @@ -4517,13 +4517,13 @@ Parser::parseDeclList(SourceLoc LBLoc, SourceLoc &RBLoc, Diag<> ErrorDiag, bool &hadError) { // Record the curly braces but nothing inside. - if (IDC->areDependenciesUsingTokenHashesForTypeBodies()) { + if (IDC->areTokensHashedForThisBodyInsteadOfInterfaceHash()) { recordTokenHash("{"); recordTokenHash("}"); } llvm::MD5 tokenHashForThisDeclList; llvm::SaveAndRestore> T( - CurrentTokenHash, IDC->areDependenciesUsingTokenHashesForTypeBodies() + CurrentTokenHash, IDC->areTokensHashedForThisBodyInsteadOfInterfaceHash() ? &tokenHashForThisDeclList : CurrentTokenHash); diff --git a/test/Frontend/Fingerprints/Inputs/extension-adds-member/definesAB-after.swift b/test/Frontend/Fingerprints/Inputs/extension-adds-member/definesAB-after.swift new file mode 100644 index 0000000000000..1ef4d58a82e7d --- /dev/null +++ b/test/Frontend/Fingerprints/Inputs/extension-adds-member/definesAB-after.swift @@ -0,0 +1,9 @@ +struct A { +} +struct B { +} +extension A { + var x: Int {17} +} +extension B { +} diff --git a/test/Frontend/Fingerprints/Inputs/extension-adds-member/definesAB-before.swift b/test/Frontend/Fingerprints/Inputs/extension-adds-member/definesAB-before.swift new file mode 100644 index 0000000000000..9a8e36dc90d98 --- /dev/null +++ b/test/Frontend/Fingerprints/Inputs/extension-adds-member/definesAB-before.swift @@ -0,0 +1,8 @@ +struct A { +} +struct B { +} +extension A { +} +extension B { +} diff --git a/test/Frontend/Fingerprints/Inputs/extension-adds-member/main.swift b/test/Frontend/Fingerprints/Inputs/extension-adds-member/main.swift new file mode 100644 index 0000000000000..8b137891791fe --- /dev/null +++ b/test/Frontend/Fingerprints/Inputs/extension-adds-member/main.swift @@ -0,0 +1 @@ + diff --git a/test/Frontend/Fingerprints/Inputs/extension-adds-member/ofm.json b/test/Frontend/Fingerprints/Inputs/extension-adds-member/ofm.json new file mode 100644 index 0000000000000..42d8972a2c390 --- /dev/null +++ b/test/Frontend/Fingerprints/Inputs/extension-adds-member/ofm.json @@ -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" + } +} + diff --git a/test/Frontend/Fingerprints/Inputs/extension-adds-member/usesA.swift b/test/Frontend/Fingerprints/Inputs/extension-adds-member/usesA.swift new file mode 100644 index 0000000000000..d947cb11b9830 --- /dev/null +++ b/test/Frontend/Fingerprints/Inputs/extension-adds-member/usesA.swift @@ -0,0 +1 @@ +let a = A() diff --git a/test/Frontend/Fingerprints/Inputs/extension-adds-member/usesB.swift b/test/Frontend/Fingerprints/Inputs/extension-adds-member/usesB.swift new file mode 100644 index 0000000000000..ecff1d6a467fc --- /dev/null +++ b/test/Frontend/Fingerprints/Inputs/extension-adds-member/usesB.swift @@ -0,0 +1 @@ +let b = B() diff --git a/test/Frontend/Fingerprints/extension-adds-member.swift b/test/Frontend/Fingerprints/extension-adds-member.swift new file mode 100644 index 0000000000000..1bac527921a73 --- /dev/null +++ b/test/Frontend/Fingerprints/extension-adds-member.swift @@ -0,0 +1,83 @@ + +// Test per-type-body fingerprints using simple extensions +// +// If the parser is allowed to use a body fingerprint for an extension +// this test will fail because usesA.swift won't be recompiled for the +// last step. + + +// ============================================================================= +// Without the fingerprints +// ============================================================================= + +// Establish status quo + + +// RUN: %empty-directory(%t) +// RUN: cp %S/Inputs/extension-adds-member/* %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 && %swiftc_driver -disable-type-fingerprints -enable-batch-mode -j2 -incremental -driver-show-incremental main.swift definesAB.swift usesA.swift usesB.swift -module-name main -output-file-map ofm.json >& %t/output1 + + +// Change one type, but uses of all types 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 && %swiftc_driver -disable-type-fingerprints -enable-batch-mode -j2 -incremental -driver-show-incremental main.swift definesAB.swift usesA.swift usesB.swift -module-name main -output-file-map ofm.json >& %t/output2 + + +// This test checks for the status quo; it would be OK to be more conservative + +// RUN: %FileCheck -check-prefix=CHECK-RECOMPILED-WO %s < %t/output2 +// CHECK-RECOMPILED-WO: {compile: definesAB.o <= definesAB.swift} +// CHECK-RECOMPILED-WO: {compile: usesA.o <= usesA.swift} +// CHECK-RECOMPILED-WO: {compile: usesB.o <= usesB.swift} + +// RUN: %FileCheck -check-prefix=CHECK-NOT-RECOMPILED-WO %s < %t/output2 +// CHECK-NOT-RECOMPILED-WO-NOT: {compile: main.o <= main.swift} + + +// ============================================================================= +// With the fingerprints +// ============================================================================= + +// Establish status quo + +// RUN: %empty-directory(%t) +// RUN: cp %S/Inputs/extension-adds-member/* %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 && %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 >& %t/output3 + +// 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 && %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 >& %t/output4 + +// RUN: %FileCheck -check-prefix=CHECK-RECOMPILED-W %s < %t/output4 +// RUN: %FileCheck -check-prefix=CHECK-NOT-RECOMPILED-W %s < %t/output4 + +// CHECK-RECOMPILED-W: {compile: definesAB.o <= definesAB.swift} +// CHECK-RECOMPILED-W: {compile: usesA.o <= usesA.swift} + + +// CHECK-NOT-RECOMPILED-W-NOT: {compile: main.o <= main.swift}