mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user