Skip to content

Commit b8a1f2e

Browse files
author
Nathan Hawes
authored
Merge pull request #23665 from nathawes/it-all-depends-take-2
[ParseableInterface] Make the module caches relocatable and respect -track-system-dependencies
2 parents c023e0f + 7144dab commit b8a1f2e

17 files changed

+440
-89
lines changed

include/swift/Frontend/ParseableInterfaceModuleLoader.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ class ParseableInterfaceModuleLoader : public SerializedModuleLoaderBase {
139139
std::unique_ptr<llvm::MemoryBuffer> *ModuleBuffer,
140140
std::unique_ptr<llvm::MemoryBuffer> *ModuleDocBuffer) override;
141141

142+
bool isCached(StringRef DepPath) override;
143+
142144
public:
143145
static std::unique_ptr<ParseableInterfaceModuleLoader>
144146
create(ASTContext &ctx, StringRef cacheDir, StringRef prebuiltCacheDir,
@@ -156,7 +158,7 @@ class ParseableInterfaceModuleLoader : public SerializedModuleLoaderBase {
156158
static bool buildSwiftModuleFromSwiftInterface(
157159
ASTContext &Ctx, StringRef CacheDir, StringRef PrebuiltCacheDir,
158160
StringRef ModuleName, StringRef InPath, StringRef OutPath,
159-
bool SerializeDependencyHashes);
161+
bool SerializeDependencyHashes, bool TrackSystemDependencies);
160162
};
161163

162164
/// Extract the specified-or-defaulted -module-cache-path that winds up in

include/swift/Serialization/ModuleFormat.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const uint16_t SWIFTMODULE_VERSION_MAJOR = 0;
5252
/// describe what change you made. The content of this comment isn't important;
5353
/// it just ensures a conflict if two people change the module format.
5454
/// Don't worry about adhering to the 80-column limit for this line.
55-
const uint16_t SWIFTMODULE_VERSION_MINOR = 483; // Remove default arg expansion
55+
const uint16_t SWIFTMODULE_VERSION_MINOR = 484; // SDK-relative dependencies flag
5656

5757
using DeclIDField = BCFixed<31>;
5858

@@ -687,6 +687,7 @@ namespace input_block {
687687
FileSizeField, // file size (for validation)
688688
FileModTimeOrContentHashField, // mtime or content hash (for validation)
689689
BCFixed<1>, // are we reading mtime (0) or hash (1)?
690+
BCFixed<1>, // SDK-relative?
690691
BCBlob // path
691692
>;
692693
}

include/swift/Serialization/SerializationOptions.h

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,14 @@ namespace swift {
3939
/// appropriate strategy for how to verify if it's up-to-date.
4040
class FileDependency {
4141
/// The size of the file on disk, in bytes.
42-
uint64_t Size : 63;
42+
uint64_t Size : 62;
4343

4444
/// A dependency can be either hash-based or modification-time-based.
4545
bool IsHashBased : 1;
4646

47+
/// The dependency path can be absolute or relative to the SDK
48+
bool IsSDKRelative : 1;
49+
4750
union {
4851
/// The last modification time of the file.
4952
uint64_t ModificationTime;
@@ -56,22 +59,22 @@ namespace swift {
5659
std::string Path;
5760

5861
FileDependency(uint64_t size, bool isHash, uint64_t hashOrModTime,
59-
StringRef path):
60-
Size(size), IsHashBased(isHash), ModificationTime(hashOrModTime),
61-
Path(path) {}
62+
StringRef path, bool isSDKRelative):
63+
Size(size), IsHashBased(isHash), IsSDKRelative(isSDKRelative),
64+
ModificationTime(hashOrModTime), Path(path) {}
6265
public:
6366
FileDependency() = delete;
6467

6568
/// Creates a new hash-based file dependency.
6669
static FileDependency
67-
hashBased(StringRef path, uint64_t size, uint64_t hash) {
68-
return FileDependency(size, /*isHash*/true, hash, path);
70+
hashBased(StringRef path, bool isSDKRelative, uint64_t size, uint64_t hash) {
71+
return FileDependency(size, /*isHash*/true, hash, path, isSDKRelative);
6972
}
7073

7174
/// Creates a new modification time-based file dependency.
7275
static FileDependency
73-
modTimeBased(StringRef path, uint64_t size, uint64_t mtime) {
74-
return FileDependency(size, /*isHash*/false, mtime, path);
76+
modTimeBased(StringRef path, bool isSDKRelative, uint64_t size, uint64_t mtime) {
77+
return FileDependency(size, /*isHash*/false, mtime, path, isSDKRelative);
7578
}
7679

7780
/// Updates the last-modified time of this dependency.
@@ -94,6 +97,9 @@ namespace swift {
9497
/// based on content hash.
9598
bool isHashBased() const { return IsHashBased; }
9699

100+
/// Determines if this dependency is absolute or relative to the SDK.
101+
bool isSDKRelative() const { return IsSDKRelative; }
102+
97103
/// Determines if this dependency is hash-based and should be validated
98104
/// based on modification time.
99105
bool isModificationTimeBased() const { return !IsHashBased; }

include/swift/Serialization/SerializedModuleLoader.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ class SerializedModuleLoaderBase : public ModuleLoader {
8080
return false;
8181
}
8282

83+
/// Determines if the provided path is a cached artifact for dependency
84+
/// tracking purposes.
85+
virtual bool isCached(StringRef DepPath) {
86+
return false;
87+
}
88+
8389
public:
8490
virtual ~SerializedModuleLoaderBase();
8591
SerializedModuleLoaderBase(const SerializedModuleLoaderBase &) = delete;

lib/AST/ModuleLoader.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,8 @@ void
3434
DependencyTracker::addDependency(StringRef File, bool IsSystem) {
3535
// DependencyTracker exposes an interface that (intentionally) does not talk
3636
// about clang at all, nor about missing deps. It does expose an IsSystem
37-
// dimension, though it is presently always false, we accept it and pass it
38-
// along to the clang DependencyCollector in case Swift callers start setting
39-
// it to true someday.
37+
// dimension, which we accept and pass along to the clang DependencyCollector.
38+
// along to the clang DependencyCollector.
4039
clangCollector->maybeAddDependency(File, /*FromModule=*/false,
4140
IsSystem, /*IsModuleFile=*/false,
4241
/*IsMissing=*/false);

0 commit comments

Comments
 (0)