Skip to content

Commit 7b5757b

Browse files
committed
Sema: Replace TypeChecker::checkDeclarationAvailability().
Adopt `getUnmetDeclAvailabilityRequirement()` instead.
1 parent 0377ef4 commit 7b5757b

File tree

6 files changed

+12
-23
lines changed

6 files changed

+12
-23
lines changed

lib/Sema/BuilderTransform.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,12 +1321,8 @@ ResultBuilderOpSupport TypeChecker::checkBuilderOpSupport(
13211321
ArrayRef<Identifier> argLabels, SmallVectorImpl<ValueDecl *> *allResults) {
13221322

13231323
auto isUnavailable = [&](Decl *D) -> bool {
1324-
if (AvailableAttr::isUnavailable(D))
1325-
return true;
1326-
13271324
auto loc = extractNearestSourceLoc(dc);
1328-
auto context = ExportContext::forFunctionBody(dc, loc);
1329-
return TypeChecker::checkDeclarationAvailability(D, context).has_value();
1325+
return getUnmetDeclAvailabilityRequirement(D, dc, loc).has_value();
13301326
};
13311327

13321328
bool foundMatch = false;

lib/Sema/CSSyntacticElement.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2475,10 +2475,9 @@ class ResultBuilderRewriter : public SyntacticElementSolutionApplication {
24752475
if (!nominal)
24762476
return false;
24772477

2478-
ExportContext where =
2479-
ExportContext::forFunctionBody(context.getAsDeclContext(), loc);
2480-
if (auto reason =
2481-
TypeChecker::checkDeclarationAvailability(nominal, where)) {
2478+
auto unmetRequirement = getUnmetDeclAvailabilityRequirement(
2479+
nominal, context.getAsDeclContext(), loc);
2480+
if (unmetRequirement && unmetRequirement->isConditionallySatisfiable()) {
24822481
auto &ctx = getASTContext();
24832482
ctx.Diags.diagnose(loc,
24842483
diag::result_builder_missing_limited_availability,

lib/Sema/ConstraintSystem.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4897,12 +4897,12 @@ bool ConstraintSystem::isReadOnlyKeyPathComponent(
48974897
// If the setter is unavailable, then the keypath ought to be read-only
48984898
// in this context.
48994899
if (auto setter = storage->getOpaqueAccessor(AccessorKind::Set)) {
4900-
ExportContext where = ExportContext::forFunctionBody(DC, referenceLoc);
4901-
auto maybeUnavail =
4902-
TypeChecker::checkDeclarationAvailability(setter, where);
4903-
if (maybeUnavail.has_value()) {
4900+
// FIXME: Fully unavailable setters should cause the key path to be
4901+
// readonly too.
4902+
auto unmetRequirement =
4903+
getUnmetDeclAvailabilityRequirement(setter, DC, referenceLoc);
4904+
if (unmetRequirement && unmetRequirement->isConditionallySatisfiable())
49044905
return true;
4905-
}
49064906
}
49074907

49084908
return false;

lib/Sema/TypeCheckAvailability.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1495,9 +1495,8 @@ static bool isDeclarationUnavailable(
14951495
return !runningOSOverApprox.isContainedIn(safeRangeUnderApprox);
14961496
}
14971497

1498-
std::optional<AvailabilityRange>
1499-
TypeChecker::checkDeclarationAvailability(const Decl *D,
1500-
const ExportContext &Where) {
1498+
static std::optional<AvailabilityRange>
1499+
checkDeclarationAvailability(const Decl *D, const ExportContext &Where) {
15011500
// Skip computing potential unavailability if the declaration is explicitly
15021501
// unavailable and the context is also unavailable.
15031502
if (const AvailableAttr *Attr = AvailableAttr::isUnavailable(D))

lib/Sema/TypeChecker.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,12 +1032,6 @@ diagnosticIfDeclCannotBePotentiallyUnavailable(const Decl *D);
10321032
/// is allowed.
10331033
std::optional<Diagnostic> diagnosticIfDeclCannotBeUnavailable(const Decl *D);
10341034

1035-
/// Checks whether a declaration should be considered unavailable when
1036-
/// referred to at the given location and, if so, returns the unmet required
1037-
/// version range. Returns None is the declaration is definitely available.
1038-
std::optional<AvailabilityRange>
1039-
checkDeclarationAvailability(const Decl *D, const ExportContext &Where);
1040-
10411035
/// Checks whether a conformance should be considered unavailable when
10421036
/// referred to at the given location and, if so, returns the unmet required
10431037
/// version range. Returns None is the declaration is definitely available.

test/expr/unary/keypath/keypath-availability.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,4 @@ public func conditionalAvailableSetterContext() {
3333
}
3434
}
3535

36+
// FIXME: Check additional unavailability conditions

0 commit comments

Comments
 (0)