mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[ParseableInterface] Add ‘forwarding modules’
A ‘forwarding module’ is a YAML file that’s meant to stand in for a .swiftmodule file and provide an up-to-date description of its dependencies, always using modification times. When a ‘prebuilt module’ is first loaded, we verify that it’s up-to-date by hashing all of its dependencies. Since this is orders of magnitude slower than reading mtimes, we’ll install a `forwarding module` containing the mtimes of the now-validated dependencies.
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
//
|
||||
// This source file is part of the Swift.org open source project
|
||||
//
|
||||
// Copyright (c) 2018 Apple Inc. and the Swift project authors
|
||||
// Copyright (c) 2019 Apple Inc. and the Swift project authors
|
||||
// Licensed under Apache License v2.0 with Runtime Library Exception
|
||||
//
|
||||
// See https://swift.org/LICENSE.txt for license information
|
||||
@@ -14,9 +14,13 @@
|
||||
#define SWIFT_FRONTEND_PARSEABLEINTERFACESUPPORT_H
|
||||
|
||||
#include "swift/Basic/LLVM.h"
|
||||
#include "swift/Serialization/SerializedModuleLoader.h"
|
||||
#include "swift/Basic/Version.h"
|
||||
#include "llvm/Support/Regex.h"
|
||||
|
||||
#define SWIFT_INTERFACE_FORMAT_VERSION_KEY "swift-interface-format-version"
|
||||
#define SWIFT_TOOLS_VERSION_KEY "swift-tools-version"
|
||||
#define SWIFT_MODULE_FLAGS_KEY "swift-module-flags"
|
||||
|
||||
namespace swift {
|
||||
|
||||
class ModuleDecl;
|
||||
@@ -29,6 +33,8 @@ struct ParseableInterfaceOptions {
|
||||
std::string ParseableInterfaceFlags;
|
||||
};
|
||||
|
||||
extern version::Version InterfaceFormatVersion;
|
||||
|
||||
llvm::Regex getSwiftInterfaceFormatVersionRegex();
|
||||
llvm::Regex getSwiftInterfaceModuleFlagsRegex();
|
||||
|
||||
@@ -49,71 +55,6 @@ bool emitParseableInterface(raw_ostream &out,
|
||||
ParseableInterfaceOptions const &Opts,
|
||||
ModuleDecl *M);
|
||||
|
||||
/// Extract the specified-or-defaulted -module-cache-path that winds up in
|
||||
/// the clang importer, for reuse as the .swiftmodule cache path when
|
||||
/// building a ParseableInterfaceModuleLoader.
|
||||
std::string
|
||||
getModuleCachePathFromClang(const clang::CompilerInstance &Instance);
|
||||
|
||||
/// A ModuleLoader that runs a subordinate \c CompilerInvocation and \c
|
||||
/// CompilerInstance to convert .swiftinterface files to .swiftmodule
|
||||
/// files on the fly, caching the resulting .swiftmodules in the module cache
|
||||
/// directory, and loading the serialized .swiftmodules from there.
|
||||
class ParseableInterfaceModuleLoader : public SerializedModuleLoaderBase {
|
||||
explicit ParseableInterfaceModuleLoader(ASTContext &ctx, StringRef cacheDir,
|
||||
StringRef prebuiltCacheDir,
|
||||
DependencyTracker *tracker,
|
||||
ModuleLoadingMode loadMode)
|
||||
: SerializedModuleLoaderBase(ctx, tracker, loadMode),
|
||||
CacheDir(cacheDir), PrebuiltCacheDir(prebuiltCacheDir)
|
||||
{}
|
||||
|
||||
std::string CacheDir;
|
||||
std::string PrebuiltCacheDir;
|
||||
|
||||
/// Wire up the SubInvocation's InputsAndOutputs to contain both input and
|
||||
/// output filenames.
|
||||
///
|
||||
/// This is a method rather than a helper function in the implementation file
|
||||
/// because it accesses non-public bits of FrontendInputsAndOutputs.
|
||||
static void configureSubInvocationInputsAndOutputs(
|
||||
CompilerInvocation &SubInvocation, StringRef InPath, StringRef OutPath);
|
||||
|
||||
static bool buildSwiftModuleFromSwiftInterface(
|
||||
llvm::vfs::FileSystem &FS, DiagnosticEngine &Diags, SourceLoc DiagLoc,
|
||||
CompilerInvocation &SubInvocation, StringRef InPath, StringRef OutPath,
|
||||
StringRef ModuleCachePath, DependencyTracker *OuterTracker,
|
||||
bool ShouldSerializeDeps);
|
||||
|
||||
std::error_code findModuleFilesInDirectory(
|
||||
AccessPathElem ModuleID, StringRef DirPath, StringRef ModuleFilename,
|
||||
StringRef ModuleDocFilename,
|
||||
std::unique_ptr<llvm::MemoryBuffer> *ModuleBuffer,
|
||||
std::unique_ptr<llvm::MemoryBuffer> *ModuleDocBuffer) override;
|
||||
|
||||
public:
|
||||
static std::unique_ptr<ParseableInterfaceModuleLoader>
|
||||
create(ASTContext &ctx, StringRef cacheDir, StringRef prebuiltCacheDir,
|
||||
DependencyTracker *tracker, ModuleLoadingMode loadMode) {
|
||||
return std::unique_ptr<ParseableInterfaceModuleLoader>(
|
||||
new ParseableInterfaceModuleLoader(ctx, cacheDir, prebuiltCacheDir,
|
||||
tracker, loadMode));
|
||||
}
|
||||
|
||||
/// Unconditionally build \p InPath (a swiftinterface file) to \p OutPath (as
|
||||
/// a swiftmodule file).
|
||||
///
|
||||
/// A simplified version of the core logic in #openModuleFiles, mostly for
|
||||
/// testing purposes.
|
||||
static bool buildSwiftModuleFromSwiftInterface(ASTContext &Ctx,
|
||||
StringRef CacheDir,
|
||||
StringRef PrebuiltCacheDir,
|
||||
StringRef ModuleName,
|
||||
StringRef InPath,
|
||||
StringRef OutPath);
|
||||
};
|
||||
|
||||
|
||||
} // end namespace swift
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user