Refactor getMinPlatformVersion

The definitions of how version numbers were extracted from target
triples split between the minimum platform version and for determining
the minimum inlining version.

This resulted in inlinable and transparent functions not being imported
correctly on non-Apple platforms where the version number is retained as
part of the target triple.
Specifically, `_checkExpectedExecutor` was found in the module, but
didn't have the appropriate availability version assigned, resulting in
it failing to import and the compiler silently omitting the check in
SILGen when compiling for FreeBSD.

This patch refactors the implementation of `getMinPlatformVersion` into
a separate function that is used in both places so that they cannot get
out of sync again.

Note: This changes how Windows is handled. getMinPlatformVersion
returned an empty version number for Windows, while the availability
implementation returned the OS version number. This makes both
consistently return the OS version number.
This commit is contained in:
Evan Wilde
2025-08-07 14:21:38 -07:00
parent 95dfa3d818
commit 3fcca83d07
4 changed files with 23 additions and 24 deletions

View File

@@ -56,17 +56,6 @@ swift::CompilerInvocation::CompilerInvocation() {
setTargetTriple(llvm::sys::getDefaultTargetTriple());
}
/// Converts a llvm::Triple to a llvm::VersionTuple.
static llvm::VersionTuple
getVersionTuple(const llvm::Triple &triple) {
if (triple.isMacOSX()) {
llvm::VersionTuple OSVersion;
triple.getMacOSXVersion(OSVersion);
return OSVersion;
}
return triple.getOSVersion();
}
void CompilerInvocation::computeRuntimeResourcePathFromExecutablePath(
StringRef mainExecutablePath, bool shared,
llvm::SmallVectorImpl<char> &runtimeResourcePath) {
@@ -1623,7 +1612,7 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
// First, set up default minimum inlining target versions.
auto getDefaultMinimumInliningTargetVersion =
[&](const llvm::Triple &triple) -> llvm::VersionTuple {
const auto targetVersion = getVersionTuple(triple);
const auto targetVersion = getVersionForTriple(triple);
// In API modules, default to the version when Swift first became available.
if (Opts.LibraryLevel == LibraryLevel::API) {