Skip to content

Commit e272ece

Browse files
authored
Merge pull request #20170 from graydon/text-interface-to-module
Switch from .sid files to using FILE_DEPENDENCY records in INPUT_BLOCK
2 parents 1fcf92b + edb7ccb commit e272ece

22 files changed

+513
-122
lines changed

include/swift/Basic/FileTypes.def

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ TYPE("swiftmodule", SwiftModuleFile, "swiftmodule", "")
5050
TYPE("swiftdoc", SwiftModuleDocFile, "swiftdoc", "")
5151
TYPE("swiftinterface", SwiftParseableInterfaceFile, \
5252
"swiftinterface", "")
53-
TYPE("swiftinterfacedeps", SwiftParseableInterfaceDeps, \
54-
"sid", "")
5553
TYPE("assembly", Assembly, "s", "")
5654
TYPE("raw-sil", RawSIL, "sil", "")
5755
TYPE("raw-sib", RawSIB, "sib", "")

include/swift/Frontend/ParseableInterfaceSupport.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ bool emitParseableInterface(raw_ostream &out,
4949
ParseableInterfaceOptions const &Opts,
5050
ModuleDecl *M);
5151

52+
/// Extract the specified-or-defaulted -module-cache-path that winds up in
53+
/// the clang importer, for reuse as the .swiftmodule cache path when
54+
/// building a ParseableInterfaceModuleLoader.
55+
std::string
56+
getModuleCachePathFromClang(const clang::CompilerInstance &Instance);
5257

5358
/// A ModuleLoader that runs a subordinate \c CompilerInvocation and \c
5459
/// CompilerInstance to convert .swiftinterface files to .swiftmodule
@@ -66,8 +71,7 @@ class ParseableInterfaceModuleLoader : public SerializedModuleLoaderBase {
6671
void
6772
configureSubInvocationAndOutputPaths(CompilerInvocation &SubInvocation,
6873
StringRef InPath,
69-
llvm::SmallString<128> &OutPath,
70-
llvm::SmallString<128> &DepPath);
74+
llvm::SmallString<128> &OutPath);
7175

7276
std::error_code
7377
openModuleFiles(StringRef DirName, StringRef ModuleFilename,

include/swift/Serialization/ModuleFormat.h

Lines changed: 10 additions & 2 deletions
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 = 456; // Last change: encode depth in generic param XREFs
55+
const uint16_t SWIFTMODULE_VERSION_MINOR = 458; // Last change: enrich FILE_DEPENDENCY records.
5656

5757
using DeclIDField = BCFixed<31>;
5858

@@ -630,7 +630,8 @@ namespace input_block {
630630
IMPORTED_HEADER,
631631
IMPORTED_HEADER_CONTENTS,
632632
MODULE_FLAGS, // [unused]
633-
SEARCH_PATH
633+
SEARCH_PATH,
634+
FILE_DEPENDENCY
634635
};
635636

636637
using ImportedModuleLayout = BCRecordLayout<
@@ -668,6 +669,13 @@ namespace input_block {
668669
BCFixed<1>, // system?
669670
BCBlob // path
670671
>;
672+
673+
using FileDependencyLayout = BCRecordLayout<
674+
FILE_DEPENDENCY,
675+
FileSizeField, // file size (for validation)
676+
FileModTimeField, // file mtime (for validation)
677+
BCBlob // path
678+
>;
671679
}
672680

673681
/// The record types within the "decls-and-types" block.

include/swift/Serialization/SerializationOptions.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ namespace swift {
3535
StringRef ModuleLinkName;
3636
ArrayRef<std::string> ExtraClangOptions;
3737

38+
struct FileDependency {
39+
uint64_t Size;
40+
llvm::sys::TimePoint<> LastModTime;
41+
StringRef Path;
42+
};
43+
ArrayRef<FileDependency> Dependencies;
44+
3845
bool AutolinkForceLoad = false;
3946
bool EnableNestedTypeLookupTable = false;
4047
bool SerializeAllSIL = false;

include/swift/Serialization/Validation.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#define SWIFT_SERIALIZATION_VALIDATION_H
1515

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

151155
/// Emit diagnostics explaining a failure to load a serialized AST.
152156
///

lib/Basic/FileTypes.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ bool file_types::isTextual(ID Id) {
7979
case file_types::TY_ModuleTrace:
8080
case file_types::TY_OptRecord:
8181
case file_types::TY_SwiftParseableInterfaceFile:
82-
case file_types::TY_SwiftParseableInterfaceDeps:
8382
return true;
8483
case file_types::TY_Image:
8584
case file_types::TY_Object:
@@ -136,7 +135,6 @@ bool file_types::isAfterLLVM(ID Id) {
136135
case file_types::TY_ModuleTrace:
137136
case file_types::TY_OptRecord:
138137
case file_types::TY_SwiftParseableInterfaceFile:
139-
case file_types::TY_SwiftParseableInterfaceDeps:
140138
return false;
141139
case file_types::TY_INVALID:
142140
llvm_unreachable("Invalid type ID.");
@@ -169,7 +167,6 @@ bool file_types::isPartOfSwiftCompilation(ID Id) {
169167
case file_types::TY_SwiftModuleFile:
170168
case file_types::TY_SwiftModuleDocFile:
171169
case file_types::TY_SwiftParseableInterfaceFile:
172-
case file_types::TY_SwiftParseableInterfaceDeps:
173170
case file_types::TY_SerializedDiagnostics:
174171
case file_types::TY_ClangModuleFile:
175172
case file_types::TY_SwiftDeps:

lib/Driver/Driver.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1783,7 +1783,6 @@ void Driver::buildActions(SmallVectorImpl<const Action *> &TopLevelActions,
17831783
case file_types::TY_ModuleTrace:
17841784
case file_types::TY_OptRecord:
17851785
case file_types::TY_SwiftParseableInterfaceFile:
1786-
case file_types::TY_SwiftParseableInterfaceDeps:
17871786
// We could in theory handle assembly or LLVM input, but let's not.
17881787
// FIXME: What about LTO?
17891788
Diags.diagnose(SourceLoc(), diag::error_unexpected_input_file,

lib/Driver/ToolChains.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,6 @@ const char *ToolChain::JobContext::computeFrontendModeForCompile() const {
440440
case file_types::TY_TBD:
441441
case file_types::TY_OptRecord:
442442
case file_types::TY_SwiftParseableInterfaceFile:
443-
case file_types::TY_SwiftParseableInterfaceDeps:
444443
llvm_unreachable("Output type can never be primary output.");
445444
case file_types::TY_INVALID:
446445
llvm_unreachable("Invalid type ID");
@@ -673,7 +672,6 @@ ToolChain::constructInvocation(const BackendJobAction &job,
673672
case file_types::TY_ModuleTrace:
674673
case file_types::TY_OptRecord:
675674
case file_types::TY_SwiftParseableInterfaceFile:
676-
case file_types::TY_SwiftParseableInterfaceDeps:
677675
llvm_unreachable("Output type can never be primary output.");
678676
case file_types::TY_INVALID:
679677
llvm_unreachable("Invalid type ID");

lib/Frontend/Frontend.cpp

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@
3636
#include "llvm/Support/CommandLine.h"
3737
#include "llvm/Support/MemoryBuffer.h"
3838
#include "llvm/Support/Path.h"
39-
#include "clang/Frontend/CompilerInstance.h"
40-
#include "clang/Lex/Preprocessor.h"
41-
#include "clang/Lex/HeaderSearch.h"
4239

4340
using namespace swift;
4441

@@ -308,20 +305,8 @@ bool CompilerInstance::setUpModuleLoaders() {
308305
Diagnostics.diagnose(SourceLoc(), diag::error_clang_importer_create_fail);
309306
return true;
310307
}
311-
// Capture the specified-or-defaulted -module-cache-path that winds up in
312-
// the clang importer, for reuse as the .swiftmodule cache path when
313-
// building the ParseableInterfaceModuleLoader below.
314-
//
315-
// The returned-from-clang module cache path includes a suffix directory
316-
// that is specific to the clang version and invocation; we want the
317-
// directory above that.
318308
auto const &Clang = clangImporter->getClangInstance();
319-
if (Clang.hasPreprocessor()) {
320-
std::string SpecificModuleCachePath = Clang.getPreprocessor()
321-
.getHeaderSearchInfo()
322-
.getModuleCachePath();
323-
ModuleCachePath = llvm::sys::path::parent_path(SpecificModuleCachePath);
324-
}
309+
ModuleCachePath = getModuleCachePathFromClang(Clang);
325310
Context->addModuleLoader(std::move(clangImporter), /*isClang*/ true);
326311
}
327312
if (Invocation.getFrontendOptions().EnableParseableModuleInterface) {

0 commit comments

Comments
 (0)