Improve diagnostic for broken module interfaces

Currently, when a swiftinterface file fails to load, we emit the specific diagnostics for the failures, followed by a generic “failed to load module ‘Foo’” message. This PR improves that final diagnostic, particularly when the cause may be that the interface was emitted by a newer compiler using backwards-incompatible syntax.
This commit is contained in:
Brent Royal-Gordon
2020-03-13 16:56:18 -07:00
parent 000572d56c
commit a7a5e340aa
8 changed files with 80 additions and 15 deletions

View File

@@ -61,8 +61,8 @@ static void printToolVersionAndFlagsComment(raw_ostream &out,
ModuleInterfaceOptions const &Opts,
ModuleDecl *M) {
auto &Ctx = M->getASTContext();
auto ToolsVersion = swift::version::getSwiftFullVersion(
Ctx.LangOpts.EffectiveLanguageVersion);
auto ToolsVersion =
getSwiftInterfaceCompilerVersionForCurrentCompiler(Ctx);
out << "// " SWIFT_INTERFACE_FORMAT_VERSION_KEY ": "
<< InterfaceFormatVersion << "\n";
out << "// " SWIFT_COMPILER_VERSION_KEY ": "
@@ -71,6 +71,12 @@ static void printToolVersionAndFlagsComment(raw_ostream &out,
<< Opts.Flags << "\n";
}
std::string
swift::getSwiftInterfaceCompilerVersionForCurrentCompiler(ASTContext &ctx) {
return swift::version::getSwiftFullVersion(
ctx.LangOpts.EffectiveLanguageVersion);
}
llvm::Regex swift::getSwiftInterfaceFormatVersionRegex() {
return llvm::Regex("^// " SWIFT_INTERFACE_FORMAT_VERSION_KEY
": ([0-9\\.]+)$", llvm::Regex::Newline);
@@ -81,6 +87,11 @@ llvm::Regex swift::getSwiftInterfaceModuleFlagsRegex() {
llvm::Regex::Newline);
}
llvm::Regex swift::getSwiftInterfaceCompilerVersionRegex() {
return llvm::Regex("^// " SWIFT_COMPILER_VERSION_KEY
": (.+)$", llvm::Regex::Newline);
}
/// Prints the imported modules in \p M to \p out in the form of \c import
/// source declarations.
static void printImports(raw_ostream &out,