AST: Make the versioned variants of #if canImport()
more reliable and consistent
#60981
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Previously, when evaluating a
#if canImport(Module, _version: 42)
directive the compiler could diagnose and ignore the directive under the following conditions:.tbd
for an underlying Clang module is missing acurrent-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 ofcanImport()
.Resolves rdar://88723492