Skip to content

Commit bbcd980

Browse files
beccadaxtshortli
authored andcommitted
Add flag for minimum inlining version
1 parent cdcd726 commit bbcd980

File tree

7 files changed

+95
-23
lines changed

7 files changed

+95
-23
lines changed

include/swift/Basic/LangOptions.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,13 @@ namespace swift {
134134
/// The SDK canonical name, if known.
135135
std::string SDKName;
136136

137+
/// The lowest target OS version that code in this module may be inlined
138+
/// into. In resilient modules, this should match the minimum
139+
/// deployment target of the *first* resilient version of the module, since
140+
/// clients may need to interoperate with versions as far back as that
141+
/// deployment target.
142+
llvm::VersionTuple MinimumInliningTargetVersion;
143+
137144
/// The alternate name to use for the entry point instead of main.
138145
std::string entryPointFunctionName = "main";
139146

include/swift/Basic/Platform.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ namespace swift {
5555
bool triplesAreValidForZippering(const llvm::Triple &target,
5656
const llvm::Triple &targetVariant);
5757

58+
const Optional<llvm::VersionTuple>
59+
minimumABIStableOSVersionForTriple(const llvm::Triple &triple);
60+
5861
/// Returns true if the given triple represents an OS that has all the
5962
/// "built-in" ABI-stable libraries (stdlib and _Concurrency)
6063
/// (eg. in /usr/lib/swift).

include/swift/Option/Options.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,6 +1156,11 @@ def disable_clang_target : Flag<["-"], "disable-clang-target">,
11561156
Flags<[NewDriverOnlyOption]>,
11571157
HelpText<"Disable a separately specified target triple for Clang instance to use">;
11581158

1159+
def min_inlining_target_version : Separate<["-"], "target-min-inlining-version">,
1160+
Flags<[FrontendOption, ModuleInterfaceOptionIgnorable]>,
1161+
HelpText<"Require inlinable code with no '@available' attribute to back-deploy "
1162+
"to this version of the '-target' OS">;
1163+
11591164
def profile_generate : Flag<["-"], "profile-generate">,
11601165
Flags<[FrontendOption, NoInteractiveOption]>,
11611166
HelpText<"Generate instrumented code to collect execution counts">;

lib/Basic/Platform.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,20 @@ bool swift::triplesAreValidForZippering(const llvm::Triple &target,
7979
return false;
8080
}
8181

82+
const Optional<llvm::VersionTuple>
83+
swift::minimumABIStableOSVersionForTriple(const llvm::Triple &triple) {
84+
if (triple.isMacOSX())
85+
return llvm::VersionTuple(10, 14, 4);
86+
87+
if (triple.isiOS() /* including tvOS */)
88+
return llvm::VersionTuple(12, 2);
89+
90+
if (triple.isWatchOS())
91+
return llvm::VersionTuple(5, 2);
92+
93+
return None;
94+
}
95+
8296
bool swift::tripleRequiresRPathForSwiftLibrariesInOS(
8397
const llvm::Triple &triple) {
8498
if (triple.isMacOSX()) {

lib/Frontend/CompilerInvocation.cpp

Lines changed: 56 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -800,29 +800,63 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
800800
Diags.diagnose(SourceLoc(), diag::error_unsupported_target_os, TargetArgOS);
801801
}
802802

803-
// Parse the SDK version.
804-
if (Arg *A = Args.getLastArg(options::OPT_target_sdk_version)) {
805-
auto vers = version::Version::parseVersionString(
806-
A->getValue(), SourceLoc(), &Diags);
807-
if (vers.hasValue()) {
808-
Opts.SDKVersion = *vers;
809-
} else {
810-
Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value,
811-
A->getAsString(Args), A->getValue());
812-
}
813-
}
803+
// First, set up default minimum inlining target versions.
804+
auto getDefaultMinimumInliningTargetVersion =
805+
[&](const llvm::Triple &triple) -> llvm::VersionTuple {
806+
#if SWIFT_DEFAULT_TARGET_MIN_INLINING_VERSION_TO_ABI
807+
// In ABI-stable modules, default to the version where the target's ABI
808+
// was first frozen; older versions will use that one's backwards
809+
// compatibility libraries.
810+
if (FrontendOpts.EnableLibraryEvolution)
811+
if (auto abiStability = minimumABIStableOSVersionForTriple(triple))
812+
// FIXME: Should we raise it to the minimum supported OS version for
813+
// architectures which were born ABI-stable?
814+
return *abiStability;
815+
#endif
816+
817+
// In ABI-unstable modules, we will never have to interoperate with
818+
// older versions of the module, so we should default to the minimum
819+
// deployment target.
820+
unsigned major, minor, patch;
821+
if (triple.isMacOSX())
822+
triple.getMacOSXVersion(major, minor, patch);
823+
else
824+
triple.getOSVersion(major, minor, patch);
825+
return llvm::VersionTuple(major, minor, patch);
826+
};
814827

815-
// Parse the target variant SDK version.
816-
if (Arg *A = Args.getLastArg(options::OPT_target_variant_sdk_version)) {
817-
auto vers = version::Version::parseVersionString(
818-
A->getValue(), SourceLoc(), &Diags);
819-
if (vers.hasValue()) {
820-
Opts.VariantSDKVersion = *vers;
821-
} else {
822-
Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value,
823-
A->getAsString(Args), A->getValue());
824-
}
825-
}
828+
Opts.MinimumInliningTargetVersion =
829+
getDefaultMinimumInliningTargetVersion(Opts.Target);
830+
831+
// Parse OS version number arguments.
832+
auto parseVersionArg = [&](OptSpecifier opt) -> Optional<llvm::VersionTuple> {
833+
Arg *A = Args.getLastArg(opt);
834+
if (!A)
835+
return None;
836+
837+
if (StringRef(A->getValue()) == "target")
838+
return Opts.getMinPlatformVersion();
839+
if (StringRef(A->getValue()) == "abi")
840+
return minimumABIStableOSVersionForTriple(Opts.Target);
841+
842+
if (auto vers = version::Version::parseVersionString(A->getValue(),
843+
SourceLoc(), &Diags))
844+
return (llvm::VersionTuple)*vers;
845+
846+
Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value,
847+
A->getAsString(Args), A->getValue());
848+
return None;
849+
};
850+
851+
if (auto vers = parseVersionArg(OPT_min_inlining_target_version))
852+
// FIXME: Should we diagnose if it's below the default?
853+
Opts.MinimumInliningTargetVersion = *vers;
854+
855+
if (auto vers = parseVersionArg(OPT_target_sdk_version))
856+
Opts.SDKVersion = *vers;
857+
858+
if (auto vers = parseVersionArg(OPT_target_variant_sdk_version))
859+
Opts.VariantSDKVersion = *vers;
826860

827861
// Get the SDK name.
828862
if (Arg *A = Args.getLastArg(options::OPT_target_sdk_name)) {

lib/Frontend/ModuleInterfaceLoader.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1654,6 +1654,13 @@ InterfaceSubContextDelegateImpl::runInSubCompilerInstance(StringRef moduleName,
16541654
.setMainAndSupplementaryOutputs(outputFiles, ModuleOutputPaths);
16551655

16561656
SmallVector<const char *, 64> SubArgs;
1657+
1658+
// If the interface was emitted by a compiler that didn't print
1659+
// `-target-min-inlining-version` into it, default to using the version from
1660+
// the target triple, emulating previous behavior.
1661+
SubArgs.push_back("-target-min-inlining-version");
1662+
SubArgs.push_back("target");
1663+
16571664
std::string CompilerVersion;
16581665
// Extract compiler arguments from the interface file and use them to configure
16591666
// the compiler invocation.

test/ModuleInterface/option-preservation.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
// RUN: %empty-directory(%t)
22

3-
// RUN: %target-swift-frontend -enable-library-evolution -emit-module-interface-path %t.swiftinterface -module-name t %s -emit-module -o /dev/null -Onone -enforce-exclusivity=unchecked -autolink-force-load
3+
// RUN: %target-swift-frontend -enable-library-evolution -emit-module-interface-path %t.swiftinterface -module-name t %s -target-min-inlining-version 42 -emit-module -o /dev/null -Onone -enforce-exclusivity=unchecked -autolink-force-load
44
// RUN: %FileCheck %s < %t.swiftinterface -check-prefix=CHECK-SWIFTINTERFACE
55
//
66
// CHECK-SWIFTINTERFACE: swift-module-flags:
77
// CHECK-SWIFTINTERFACE-SAME: -enable-library-evolution
88
// CHECK-SWIFTINTERFACE-SAME: -Onone
99
// CHECK-SWIFTINTERFACE-SAME: -enforce-exclusivity=unchecked
1010
// CHECK-SWIFTINTERFACE-SAME: -autolink-force-load
11+
// CHECK-SWIFTINTERFACE: swift-module-flags-ignorable:
12+
// CHECK-SWIFTINTERFACE-SAME: -target-min-inlining-version 42
1113

1214
// Make sure flags show up when filelists are enabled
1315

0 commit comments

Comments
 (0)