Skip to content

Commit 7d1d7a3

Browse files
committed
Frontend: Introduce the -unavailable-decl-optimization flag.
Part of rdar://106674022
1 parent 5bb6f79 commit 7d1d7a3

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

include/swift/Basic/LangOptions.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,22 @@ namespace swift {
105105
TaskToThread,
106106
};
107107

108+
/// Describes the code size optimization behavior for code associated with
109+
/// declarations that are marked unavailable.
110+
enum class UnavailableDeclOptimization : uint8_t {
111+
/// No optimization. Unavailable declarations will contribute to the
112+
/// resulting binary by default in this mode.
113+
None,
114+
115+
/// Avoid generating any code for unavailable declarations.
116+
///
117+
/// NOTE: This optimization can be ABI breaking for a library evolution
118+
/// enabled module because existing client binaries built with a
119+
/// pre-Swift 5.9 compiler may depend on linkable symbols associated with
120+
/// unavailable declarations.
121+
Complete,
122+
};
123+
108124
/// A collection of options that affect the language dialect and
109125
/// provide compiler debugging facilities.
110126
class LangOptions final {
@@ -171,6 +187,10 @@ namespace swift {
171187
/// Disable API availability checking.
172188
bool DisableAvailabilityChecking = false;
173189

190+
/// Optimization mode for unavailable declarations.
191+
UnavailableDeclOptimization UnavailableDeclOptimizationMode =
192+
UnavailableDeclOptimization::None;
193+
174194
/// Causes the compiler to use weak linkage for symbols belonging to
175195
/// declarations introduced at the deployment target.
176196
bool WeakLinkAtTarget = false;

include/swift/Option/Options.td

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,13 @@ def check_api_availability_only : Flag<["-"], "check-api-availability-only">,
490490
Flags<[HelpHidden, FrontendOption, NoInteractiveOption]>,
491491
HelpText<"Deprecated, has no effect">;
492492

493+
def unavailable_decl_optimization_EQ : Joined<["-"], "unavailable-decl-optimization=">,
494+
MetaVarName<"<complete,none>">,
495+
Flags<[FrontendOption, NoInteractiveOption]>,
496+
HelpText<"Specify the optimization mode for unavailable declarations. The "
497+
"value may be 'none' (no optimization) or 'complete' (code is not "
498+
"generated at all unavailable declarations)">;
499+
493500
def library_level : Separate<["-"], "library-level">,
494501
MetaVarName<"<level>">,
495502
Flags<[HelpHidden, FrontendOption, ModuleInterfaceOption]>,

lib/Frontend/CompilerInvocation.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,20 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
552552
Diags.diagnose(SourceLoc(), diag::warn_flag_deprecated,
553553
"-check-api-availability-only");
554554

555+
if (const Arg *A = Args.getLastArg(OPT_unavailable_decl_optimization_EQ)) {
556+
auto value =
557+
llvm::StringSwitch<Optional<UnavailableDeclOptimization>>(A->getValue())
558+
.Case("none", UnavailableDeclOptimization::None)
559+
.Case("complete", UnavailableDeclOptimization::Complete)
560+
.Default(None);
561+
562+
if (value)
563+
Opts.UnavailableDeclOptimizationMode = *value;
564+
else
565+
Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value,
566+
A->getAsString(Args), A->getValue());
567+
}
568+
555569
Opts.WeakLinkAtTarget |= Args.hasArg(OPT_weak_link_at_target);
556570

557571
if (auto A = Args.getLastArg(OPT_enable_conformance_availability_errors,

0 commit comments

Comments
 (0)