Skip to content

[5.1][ParseableInterface] Make the module caches relocatable and respect -track-system-dependencies #23756

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
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
4 changes: 3 additions & 1 deletion include/swift/Frontend/ParseableInterfaceModuleLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ class ParseableInterfaceModuleLoader : public SerializedModuleLoaderBase {
std::unique_ptr<llvm::MemoryBuffer> *ModuleBuffer,
std::unique_ptr<llvm::MemoryBuffer> *ModuleDocBuffer) override;

bool isCached(StringRef DepPath) override;

public:
static std::unique_ptr<ParseableInterfaceModuleLoader>
create(ASTContext &ctx, StringRef cacheDir, StringRef prebuiltCacheDir,
Expand All @@ -156,7 +158,7 @@ class ParseableInterfaceModuleLoader : public SerializedModuleLoaderBase {
static bool buildSwiftModuleFromSwiftInterface(
ASTContext &Ctx, StringRef CacheDir, StringRef PrebuiltCacheDir,
StringRef ModuleName, StringRef InPath, StringRef OutPath,
bool SerializeDependencyHashes);
bool SerializeDependencyHashes, bool TrackSystemDependencies);
};

/// Extract the specified-or-defaulted -module-cache-path that winds up in
Expand Down
3 changes: 2 additions & 1 deletion include/swift/Serialization/ModuleFormat.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const uint16_t SWIFTMODULE_VERSION_MAJOR = 0;
/// describe what change you made. The content of this comment isn't important;
/// it just ensures a conflict if two people change the module format.
/// Don't worry about adhering to the 80-column limit for this line.
const uint16_t SWIFTMODULE_VERSION_MINOR = 479; // stored property default arg
const uint16_t SWIFTMODULE_VERSION_MINOR = 480; // SDK-relative dependencies flag

using DeclIDField = BCFixed<31>;

Expand Down Expand Up @@ -687,6 +687,7 @@ namespace input_block {
FileSizeField, // file size (for validation)
FileModTimeOrContentHashField, // mtime or content hash (for validation)
BCFixed<1>, // are we reading mtime (0) or hash (1)?
BCFixed<1>, // SDK-relative?
BCBlob // path
>;
}
Expand Down
22 changes: 14 additions & 8 deletions include/swift/Serialization/SerializationOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,14 @@ namespace swift {
/// appropriate strategy for how to verify if it's up-to-date.
class FileDependency {
/// The size of the file on disk, in bytes.
uint64_t Size : 63;
uint64_t Size : 62;

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

/// The dependency path can be absolute or relative to the SDK
bool IsSDKRelative : 1;

union {
/// The last modification time of the file.
uint64_t ModificationTime;
Expand All @@ -56,22 +59,22 @@ namespace swift {
std::string Path;

FileDependency(uint64_t size, bool isHash, uint64_t hashOrModTime,
StringRef path):
Size(size), IsHashBased(isHash), ModificationTime(hashOrModTime),
Path(path) {}
StringRef path, bool isSDKRelative):
Size(size), IsHashBased(isHash), IsSDKRelative(isSDKRelative),
ModificationTime(hashOrModTime), Path(path) {}
public:
FileDependency() = delete;

/// Creates a new hash-based file dependency.
static FileDependency
hashBased(StringRef path, uint64_t size, uint64_t hash) {
return FileDependency(size, /*isHash*/true, hash, path);
hashBased(StringRef path, bool isSDKRelative, uint64_t size, uint64_t hash) {
return FileDependency(size, /*isHash*/true, hash, path, isSDKRelative);
}

/// Creates a new modification time-based file dependency.
static FileDependency
modTimeBased(StringRef path, uint64_t size, uint64_t mtime) {
return FileDependency(size, /*isHash*/false, mtime, path);
modTimeBased(StringRef path, bool isSDKRelative, uint64_t size, uint64_t mtime) {
return FileDependency(size, /*isHash*/false, mtime, path, isSDKRelative);
}

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

/// Determines if this dependency is absolute or relative to the SDK.
bool isSDKRelative() const { return IsSDKRelative; }

/// Determines if this dependency is hash-based and should be validated
/// based on modification time.
bool isModificationTimeBased() const { return !IsHashBased; }
Expand Down
6 changes: 6 additions & 0 deletions include/swift/Serialization/SerializedModuleLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ class SerializedModuleLoaderBase : public ModuleLoader {
return false;
}

/// Determines if the provided path is a cached artifact for dependency
/// tracking purposes.
virtual bool isCached(StringRef DepPath) {
return false;
}

public:
virtual ~SerializedModuleLoaderBase();
SerializedModuleLoaderBase(const SerializedModuleLoaderBase &) = delete;
Expand Down
5 changes: 2 additions & 3 deletions lib/AST/ModuleLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ void
DependencyTracker::addDependency(StringRef File, bool IsSystem) {
// DependencyTracker exposes an interface that (intentionally) does not talk
// about clang at all, nor about missing deps. It does expose an IsSystem
// dimension, though it is presently always false, we accept it and pass it
// along to the clang DependencyCollector in case Swift callers start setting
// it to true someday.
// dimension, which we accept and pass along to the clang DependencyCollector.
// along to the clang DependencyCollector.
clangCollector->maybeAddDependency(File, /*FromModule=*/false,
IsSystem, /*IsModuleFile=*/false,
/*IsMissing=*/false);
Expand Down
Loading