Skip to content

Switch from .sid files to using FILE_DEPENDENCY records in INPUT_BLOCK #20170

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 13 commits into from
Nov 6, 2018
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
2 changes: 0 additions & 2 deletions include/swift/Basic/FileTypes.def
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ TYPE("swiftmodule", SwiftModuleFile, "swiftmodule", "")
TYPE("swiftdoc", SwiftModuleDocFile, "swiftdoc", "")
TYPE("swiftinterface", SwiftParseableInterfaceFile, \
"swiftinterface", "")
TYPE("swiftinterfacedeps", SwiftParseableInterfaceDeps, \
"sid", "")
TYPE("assembly", Assembly, "s", "")
TYPE("raw-sil", RawSIL, "sil", "")
TYPE("raw-sib", RawSIB, "sib", "")
Expand Down
8 changes: 6 additions & 2 deletions include/swift/Frontend/ParseableInterfaceSupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ 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
Expand All @@ -66,8 +71,7 @@ class ParseableInterfaceModuleLoader : public SerializedModuleLoaderBase {
void
configureSubInvocationAndOutputPaths(CompilerInvocation &SubInvocation,
StringRef InPath,
llvm::SmallString<128> &OutPath,
llvm::SmallString<128> &DepPath);
llvm::SmallString<128> &OutPath);

std::error_code
openModuleFiles(StringRef DirName, StringRef ModuleFilename,
Expand Down
12 changes: 10 additions & 2 deletions 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 = 456; // Last change: encode depth in generic param XREFs
const uint16_t SWIFTMODULE_VERSION_MINOR = 458; // Last change: enrich FILE_DEPENDENCY records.

using DeclIDField = BCFixed<31>;

Expand Down Expand Up @@ -630,7 +630,8 @@ namespace input_block {
IMPORTED_HEADER,
IMPORTED_HEADER_CONTENTS,
MODULE_FLAGS, // [unused]
SEARCH_PATH
SEARCH_PATH,
FILE_DEPENDENCY
};

using ImportedModuleLayout = BCRecordLayout<
Expand Down Expand Up @@ -668,6 +669,13 @@ namespace input_block {
BCFixed<1>, // system?
BCBlob // path
>;

using FileDependencyLayout = BCRecordLayout<
FILE_DEPENDENCY,
FileSizeField, // file size (for validation)
FileModTimeField, // file mtime (for validation)
BCBlob // path
>;
}

/// The record types within the "decls-and-types" block.
Expand Down
7 changes: 7 additions & 0 deletions include/swift/Serialization/SerializationOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ namespace swift {
StringRef ModuleLinkName;
ArrayRef<std::string> ExtraClangOptions;

struct FileDependency {
uint64_t Size;
llvm::sys::TimePoint<> LastModTime;
StringRef Path;
};
ArrayRef<FileDependency> Dependencies;

bool AutolinkForceLoad = false;
bool EnableNestedTypeLookupTable = false;
bool SerializeAllSIL = false;
Expand Down
10 changes: 7 additions & 3 deletions include/swift/Serialization/Validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#define SWIFT_SERIALIZATION_VALIDATION_H

#include "swift/Basic/LLVM.h"
#include "swift/Serialization/SerializationOptions.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
Expand Down Expand Up @@ -144,9 +145,12 @@ class ExtendedValidationInfo {
/// \param[out] extendedInfo If present, will be populated with additional
/// compilation options serialized into the AST at build time that may be
/// necessary to load it properly.
ValidationInfo
validateSerializedAST(StringRef data,
ExtendedValidationInfo *extendedInfo = nullptr);
/// \param[out] dependencies If present, will be populated with list of
/// input files the module depends on, if present in INPUT_BLOCK.
ValidationInfo validateSerializedAST(
StringRef data, ExtendedValidationInfo *extendedInfo = nullptr,
SmallVectorImpl<SerializationOptions::FileDependency> *dependencies =
nullptr);

/// Emit diagnostics explaining a failure to load a serialized AST.
///
Expand Down
3 changes: 0 additions & 3 deletions lib/Basic/FileTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ bool file_types::isTextual(ID Id) {
case file_types::TY_ModuleTrace:
case file_types::TY_OptRecord:
case file_types::TY_SwiftParseableInterfaceFile:
case file_types::TY_SwiftParseableInterfaceDeps:
return true;
case file_types::TY_Image:
case file_types::TY_Object:
Expand Down Expand Up @@ -136,7 +135,6 @@ bool file_types::isAfterLLVM(ID Id) {
case file_types::TY_ModuleTrace:
case file_types::TY_OptRecord:
case file_types::TY_SwiftParseableInterfaceFile:
case file_types::TY_SwiftParseableInterfaceDeps:
return false;
case file_types::TY_INVALID:
llvm_unreachable("Invalid type ID.");
Expand Down Expand Up @@ -169,7 +167,6 @@ bool file_types::isPartOfSwiftCompilation(ID Id) {
case file_types::TY_SwiftModuleFile:
case file_types::TY_SwiftModuleDocFile:
case file_types::TY_SwiftParseableInterfaceFile:
case file_types::TY_SwiftParseableInterfaceDeps:
case file_types::TY_SerializedDiagnostics:
case file_types::TY_ClangModuleFile:
case file_types::TY_SwiftDeps:
Expand Down
1 change: 0 additions & 1 deletion lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1783,7 +1783,6 @@ void Driver::buildActions(SmallVectorImpl<const Action *> &TopLevelActions,
case file_types::TY_ModuleTrace:
case file_types::TY_OptRecord:
case file_types::TY_SwiftParseableInterfaceFile:
case file_types::TY_SwiftParseableInterfaceDeps:
// We could in theory handle assembly or LLVM input, but let's not.
// FIXME: What about LTO?
Diags.diagnose(SourceLoc(), diag::error_unexpected_input_file,
Expand Down
2 changes: 0 additions & 2 deletions lib/Driver/ToolChains.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,6 @@ const char *ToolChain::JobContext::computeFrontendModeForCompile() const {
case file_types::TY_TBD:
case file_types::TY_OptRecord:
case file_types::TY_SwiftParseableInterfaceFile:
case file_types::TY_SwiftParseableInterfaceDeps:
llvm_unreachable("Output type can never be primary output.");
case file_types::TY_INVALID:
llvm_unreachable("Invalid type ID");
Expand Down Expand Up @@ -673,7 +672,6 @@ ToolChain::constructInvocation(const BackendJobAction &job,
case file_types::TY_ModuleTrace:
case file_types::TY_OptRecord:
case file_types::TY_SwiftParseableInterfaceFile:
case file_types::TY_SwiftParseableInterfaceDeps:
llvm_unreachable("Output type can never be primary output.");
case file_types::TY_INVALID:
llvm_unreachable("Invalid type ID");
Expand Down
17 changes: 1 addition & 16 deletions lib/Frontend/Frontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Path.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Lex/Preprocessor.h"
#include "clang/Lex/HeaderSearch.h"

using namespace swift;

Expand Down Expand Up @@ -308,20 +305,8 @@ bool CompilerInstance::setUpModuleLoaders() {
Diagnostics.diagnose(SourceLoc(), diag::error_clang_importer_create_fail);
return true;
}
// Capture the specified-or-defaulted -module-cache-path that winds up in
// the clang importer, for reuse as the .swiftmodule cache path when
// building the ParseableInterfaceModuleLoader below.
//
// The returned-from-clang module cache path includes a suffix directory
// that is specific to the clang version and invocation; we want the
// directory above that.
auto const &Clang = clangImporter->getClangInstance();
if (Clang.hasPreprocessor()) {
std::string SpecificModuleCachePath = Clang.getPreprocessor()
.getHeaderSearchInfo()
.getModuleCachePath();
ModuleCachePath = llvm::sys::path::parent_path(SpecificModuleCachePath);
}
ModuleCachePath = getModuleCachePathFromClang(Clang);
Context->addModuleLoader(std::move(clangImporter), /*isClang*/ true);
}
if (Invocation.getFrontendOptions().EnableParseableModuleInterface) {
Expand Down
Loading