Skip to content

Commit

Permalink
Merge pull request swiftlang#286 from swiftwasm/master
Browse files Browse the repository at this point in the history
[pull] swiftwasm from master
  • Loading branch information
pull[bot] authored Mar 2, 2020
2 parents 9bcb13e + 21a2cdb commit d616215
Show file tree
Hide file tree
Showing 13 changed files with 144 additions and 11 deletions.
2 changes: 1 addition & 1 deletion include/swift/AST/DeclContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@ class IterableDeclContext {
/// available.
Optional<std::string> getBodyFingerprint() const;

bool areDependenciesUsingTokenHashesForTypeBodies() const;
bool areTokensHashedForThisBodyInsteadOfInterfaceHash() const;

private:
/// Add a member to the list for iteration purposes, but do not notify the
Expand Down
8 changes: 7 additions & 1 deletion lib/AST/DeclContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,13 @@ Optional<std::string> 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<ExtensionDecl>(this))
return false;
return getASTContext().LangOpts.EnableTypeFingerprints;
}

Expand Down
3 changes: 1 addition & 2 deletions lib/AST/FrontendSourceFileDepGraphFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> FrontendSourceFileDepGraphFactory::getFingerprintIfAny(
std::pair<const NominalTypeDecl *, const ValueDecl *>) {
return None;
Expand Down
10 changes: 5 additions & 5 deletions lib/LLVMPasses/LLVMMergeFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -462,8 +462,8 @@ bool SwiftMergeFunctions::doSanityCheck(std::vector<WeakTrackingVH> &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;
}

Expand Down Expand Up @@ -500,9 +500,9 @@ bool SwiftMergeFunctions::doSanityCheck(std::vector<WeakTrackingVH> &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;
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Parse/ParseDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<NullablePtr<llvm::MD5>> T(
CurrentTokenHash, IDC->areDependenciesUsingTokenHashesForTypeBodies()
CurrentTokenHash, IDC->areTokensHashedForThisBodyInsteadOfInterfaceHash()
? &tokenHashForThisDeclList
: CurrentTokenHash);

Expand Down
3 changes: 3 additions & 0 deletions stdlib/toolchain/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
struct A {
}
struct B {
}
extension A {
var x: Int {17}
}
extension B {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
struct A {
}
struct B {
}
extension A {
}
extension B {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

22 changes: 22 additions & 0 deletions test/Frontend/Fingerprints/Inputs/extension-adds-member/ofm.json
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 = A()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let b = B()
83 changes: 83 additions & 0 deletions test/Frontend/Fingerprints/extension-adds-member.swift
Original file line number Diff line number Diff line change
@@ -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}

0 comments on commit d616215

Please sign in to comment.