mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
AST: Make the versioned variants of #if canImport() more reliable and consistent.
Previously, when evaluating a `#if canImport(Module, _version: 42)` directive the compiler could diagnose and ignore the directive under the following conditions: - The associated binary module is corrupt/bogus. - The .tbd for an underlying Clang module is missing a current-version field. This behavior is surprising when there is a valid `.swiftinterface` available and it only becomes apparent when building against an SDK with an old enough version of the module that the version in the `.swiftinterface` is too low, making this failure easy to miss. Some modules have different versioning systems for their Swift and Clang modules and it can also be intentional for a distributed binary `.swiftmodule` to contain bogus data (to force the compiler to recompile the `.swiftinterface`) so we need to handle both of these cases gracefully and predictably. Now the compiler will enumerate all module loaders, ask each of them to attempt to parse the module version and then consistently use the parsed version from a single source. The `.swiftinterface` is preferred if present, then the binary module if present, and then finally the `.tbd`. The `.tbd` is still always used exclusively for the `_underlyingVersion` variant of `canImport()`. Resolves rdar://88723492
This commit is contained in:
@@ -1947,9 +1947,8 @@ std::error_code ExplicitSwiftModuleLoader::findModuleFilesInDirectory(
|
||||
return std::make_error_code(std::errc::not_supported);
|
||||
}
|
||||
|
||||
bool ExplicitSwiftModuleLoader::canImportModule(ImportPath::Module path,
|
||||
llvm::VersionTuple version,
|
||||
bool underlyingVersion) {
|
||||
bool ExplicitSwiftModuleLoader::canImportModule(
|
||||
ImportPath::Module path, ModuleVersionInfo *versionInfo) {
|
||||
// FIXME: Swift submodules?
|
||||
if (path.hasSubmodule())
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user