Skip to content

Commit 697c47e

Browse files
committed
---
yaml --- r: 346743 b: refs/heads/master c: 82452b0 h: refs/heads/master i: 346741: d42fc82 346739: c9cc86f 346735: 6673656
1 parent fd48c02 commit 697c47e

File tree

4 files changed

+60
-6
lines changed

4 files changed

+60
-6
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 8b4998825a8af7bf2753f75a11f8dfff9aa45ddd
2+
refs/heads/master: 82452b05d6dd8501f445b056d693524871589151
33
refs/heads/master-next: 203b3026584ecad859eb328b2e12490099409cd5
44
refs/tags/osx-passed: b6b74147ef8a386f532cf9357a1bde006e552c54
55
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-a: 6bb18e013c2284f2b45f5f84f2df2887dc0f7dea

trunk/include/swift/Frontend/ParseableInterfaceSupport.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
#include "swift/Basic/LLVM.h"
1717
#include "swift/Serialization/SerializedModuleLoader.h"
18+
#include "llvm/ADT/DenseMap.h"
19+
#include "llvm/Support/Errc.h"
1820
#include "llvm/Support/Regex.h"
1921

2022
namespace swift {
@@ -29,6 +31,25 @@ struct ParseableInterfaceOptions {
2931
std::string ParseableInterfaceFlags;
3032
};
3133

34+
class PrebuiltModuleCache {
35+
StringRef cacheDir;
36+
llvm::DenseMap<StringRef, uint64_t> hashedContents;
37+
PrebuiltModuleCache(StringRef cacheDir): cacheDir(cacheDir) {}
38+
39+
std::error_code loadHashes();
40+
public:
41+
static llvm::ErrorOr<PrebuiltModuleCache>
42+
loadFromDirectory(StringRef directory);
43+
44+
StringRef getDirectory() { return cacheDir; }
45+
46+
Optional<uint64_t> getInterfaceHash(StringRef moduleName) {
47+
auto it = hashedContents.find(moduleName);
48+
if (it == hashedContents.end()) return None;
49+
return it->second;
50+
}
51+
};
52+
3253
llvm::Regex getSwiftInterfaceFormatVersionRegex();
3354
llvm::Regex getSwiftInterfaceModuleFlagsRegex();
3455

trunk/lib/Frontend/ParseableInterfaceSupport.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,12 @@ static std::string getCacheHash(ASTContext &Ctx,
134134
// pathname, and probably all we can get from the VFS in this regard anyways.
135135
H = hash_combine(H, InPath);
136136

137-
// Include the target CPU. In practice, .swiftinterface files will be in
138-
// architecture-specific subdirectories and would have target-specific pieces
139-
// #if'd out. However, it doesn't hurt to include it, and it guards against
140-
// mistakenly reusing cached modules across targets.
141-
H = hash_combine(H, SubInvocation.getTargetTriple());
137+
// Include the target CPU architecture. In practice, .swiftinterface files
138+
// will be in architecture-specific subdirectories and would have
139+
// architecture-specific pieces #if'd out. However, it doesn't hurt to
140+
// include it, and it guards against mistakenly reusing cached modules across
141+
// architectures.
142+
H = hash_combine(H, SubInvocation.getLangOptions().Target.getArchName());
142143

143144
// The SDK path is going to affect how this module is imported, so include it.
144145
H = hash_combine(H, SubInvocation.getSDKPath());
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// This test specifically uses macOS deployment targets
2+
// REQUIRES: OS=macosx
3+
//
4+
// RUN: %empty-directory(%t)
5+
//
6+
// Test will build a module TestModule that depends on OtherModule and LeafModule (built from other.swift and leaf.swift).
7+
//
8+
// RUN: echo 'public func LeafFunc() -> Int { return 10; }' >%t/leaf.swift
9+
//
10+
// RUN: echo 'import LeafModule' >%t/other.swift
11+
// RUN: echo 'public func OtherFunc() -> Int { return LeafFunc(); }' >>%t/other.swift
12+
//
13+
// Phase 1: build LeafModule into a .swiftinterface file with -target x86_64-macosx-10.9:
14+
//
15+
// RUN: %swift -target x86_64-apple-macosx10.9 -I %t -module-cache-path %t/modulecache -emit-parseable-module-interface-path %t/LeafModule.swiftinterface -module-name LeafModule %t/leaf.swift -typecheck
16+
//
17+
// Phase 2: build OtherModule into a .swiftinterface file with -target x86_64-macosx-10.10:
18+
//
19+
// RUN: %swift -target x86_64-apple-macosx10.10 -I %t -module-cache-path %t/modulecache -emit-parseable-module-interface-path %t/OtherModule.swiftinterface -module-name OtherModule %t/other.swift -enable-parseable-module-interface -typecheck
20+
//
21+
// Phase 3: build TestModule in -target x86_64-apple-macosx10.11 and import both of these:
22+
//
23+
// RUN: %swift -target x86_64-apple-macosx10.11 -I %t -module-cache-path %t/modulecache -module-name TestModule %s -enable-parseable-module-interface -typecheck
24+
//
25+
// Phase 4: make sure we only compiled LeafModule and OtherModule one time:
26+
//
27+
// RUN: NUM_LEAF_MODULES=$(find %t/modulecache -type f -name 'LeafModule-*.swiftmodule' | wc -l)
28+
// RUN: NUM_OTHER_MODULES=$(find %t/modulecache -type f -name 'OtherModule-*.swiftmodule' | wc -l)
29+
// RUN: if [ ! $NUM_LEAF_MODULES -eq 1 ]; then echo "Should only be 1 LeafModule, found $NUM_LEAF_MODULES"; exit 1; fi
30+
// RUN: if [ ! $NUM_OTHER_MODULES -eq 1 ]; then echo "Should only be 1 OtherModule, found $NUM_OTHER_MODULES"; exit 1; fi
31+
import LeafModule
32+
import OtherModule

0 commit comments

Comments
 (0)