Skip to content

AST: Rework UnavailableDeclOptimizationMode language option #71141

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions include/swift/Basic/LangOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,7 @@ namespace swift {
bool DisableAvailabilityChecking = false;

/// Optimization mode for unavailable declarations.
UnavailableDeclOptimization UnavailableDeclOptimizationMode =
UnavailableDeclOptimization::Stub;
llvm::Optional<UnavailableDeclOptimization> UnavailableDeclOptimizationMode;

/// Causes the compiler to use weak linkage for symbols belonging to
/// declarations introduced at the deployment target.
Expand Down
12 changes: 10 additions & 2 deletions lib/AST/Availability.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,10 +323,18 @@ static bool isUnconditionallyUnavailable(const Decl *D) {
return false;
}

static UnavailableDeclOptimization
getEffectiveUnavailableDeclOptimization(ASTContext &ctx) {
if (ctx.LangOpts.UnavailableDeclOptimizationMode.has_value())
return *ctx.LangOpts.UnavailableDeclOptimizationMode;

return UnavailableDeclOptimization::Stub;
}

bool Decl::isAvailableDuringLowering() const {
// Unconditionally unavailable declarations should be skipped during lowering
// when -unavailable-decl-optimization=complete is specified.
if (getASTContext().LangOpts.UnavailableDeclOptimizationMode !=
if (getEffectiveUnavailableDeclOptimization(getASTContext()) !=
UnavailableDeclOptimization::Complete)
return true;

Expand All @@ -339,7 +347,7 @@ bool Decl::isAvailableDuringLowering() const {
bool Decl::requiresUnavailableDeclABICompatibilityStubs() const {
// Code associated with unavailable declarations should trap at runtime if
// -unavailable-decl-optimization=stub is specified.
if (getASTContext().LangOpts.UnavailableDeclOptimizationMode !=
if (getEffectiveUnavailableDeclOptimization(getASTContext()) !=
UnavailableDeclOptimization::Stub)
return false;

Expand Down