Skip to content

Commit 929332e

Browse files
committed
Make isAvailabilitySafeForConformance a utility
1 parent 972e755 commit 929332e

File tree

7 files changed

+14
-12
lines changed

7 files changed

+14
-12
lines changed

lib/Sema/CSGen.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1708,8 +1708,7 @@ namespace {
17081708
CS.addConstraint(ConstraintKind::Conversion,
17091709
CS.getType(expr->getSubExpr()), optTy,
17101710
CS.getConstraintLocator(expr));
1711-
}
1712-
else {
1711+
} else {
17131712
CS.addConstraint(ConstraintKind::OptionalObject,
17141713
optTy, CS.getType(expr->getSubExpr()),
17151714
CS.getConstraintLocator(expr));

lib/Sema/CSSimplify.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3742,7 +3742,7 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
37423742
//
37433743
// Class and protocol metatypes are interoperable with certain Objective-C
37443744
// runtime classes, but only when ObjC interop is enabled.
3745-
3745+
37463746
if (getASTContext().LangOpts.EnableObjCInterop) {
37473747
// These conversions are between concrete types that don't need further
37483748
// resolution, so we can consider them immediately solved.
@@ -3790,7 +3790,7 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
37903790
}
37913791
}
37923792
}
3793-
3793+
37943794
// Special implicit nominal conversions.
37953795
if (!type1->is<LValueType>() && kind >= ConstraintKind::Subtype) {
37963796
// Array -> Array.
@@ -4020,7 +4020,8 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
40204020
if (auto optTryExpr =
40214021
dyn_cast_or_null<OptionalTryExpr>(locator.trySimplifyToExpr())) {
40224022
auto subExprType = getType(optTryExpr->getSubExpr());
4023-
const bool isSwift5OrGreater = getASTContext().LangOpts.isSwiftVersionAtLeast(5);
4023+
const bool isSwift5OrGreater =
4024+
getASTContext().LangOpts.isSwiftVersionAtLeast(5);
40244025
if (isSwift5OrGreater && (bool)subExprType->getOptionalObjectType()) {
40254026
// For 'try?' expressions, a ForceOptional fix converts 'try?'
40264027
// to 'try!'. If the sub-expression is optional, then a force-unwrap

lib/Sema/CSSolver.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,9 +1098,9 @@ bool ConstraintSystem::solve(Expr *&expr,
10981098
ExprTypeCheckListener *listener,
10991099
SmallVectorImpl<Solution> &solutions,
11001100
FreeTypeVariableBinding allowFreeTypeVariables) {
1101-
llvm::SaveAndRestore<bool>
1102-
debugForExpr(getASTContext().LangOpts.DebugConstraintSolver,
1103-
debugConstraintSolverForExpr(TC.Context, expr));
1101+
llvm::SaveAndRestore<bool> debugForExpr(
1102+
getASTContext().LangOpts.DebugConstraintSolver,
1103+
debugConstraintSolverForExpr(TC.Context, expr));
11041104

11051105
// Attempt to solve the constraint system.
11061106
auto solution = solveImpl(expr,

lib/Sema/ConstraintSystem.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1247,7 +1247,8 @@ class ConstraintSystem {
12471247
}
12481248
}
12491249

1250-
unsigned threshold = cs->getASTContext().LangOpts.SolverShrinkUnsolvedThreshold;
1250+
unsigned threshold =
1251+
cs->getASTContext().LangOpts.SolverShrinkUnsolvedThreshold;
12511252
return unsolvedDisjunctions >= threshold;
12521253
}
12531254
};

lib/Sema/TypeCheckDecl.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3571,6 +3571,7 @@ bool TypeChecker::isAvailabilitySafeForConformance(
35713571
if (!dc->getParentSourceFile())
35723572
return true;
35733573

3574+
auto &Context = proto->getASTContext();
35743575
NominalTypeDecl *conformingDecl = dc->getSelfNominalTypeDecl();
35753576
assert(conformingDecl && "Must have conforming declaration");
35763577

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,8 +1197,8 @@ checkWitnessAvailability(ValueDecl *requirement,
11971197
ValueDecl *witness,
11981198
AvailabilityContext *requiredAvailability) {
11991199
return (!TC.Context.LangOpts.DisableAvailabilityChecking &&
1200-
!TC.isAvailabilitySafeForConformance(Proto, requirement, witness,
1201-
DC, *requiredAvailability));
1200+
!TypeChecker::isAvailabilitySafeForConformance(
1201+
Proto, requirement, witness, DC, *requiredAvailability));
12021202
}
12031203

12041204
RequirementCheck WitnessChecker::checkWitness(ValueDecl *requirement,

lib/Sema/TypeChecker.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1774,7 +1774,7 @@ class TypeChecker final : public LazyResolver {
17741774
/// is sufficient to safely conform to the requirement in the context
17751775
/// the provided conformance. On return, requiredAvailability holds th
17761776
/// availability levels required for conformance.
1777-
bool
1777+
static bool
17781778
isAvailabilitySafeForConformance(ProtocolDecl *proto, ValueDecl *requirement,
17791779
ValueDecl *witness, DeclContext *dc,
17801780
AvailabilityContext &requiredAvailability);

0 commit comments

Comments
 (0)