Skip to content

Commit b23a0b7

Browse files
authored
Merge pull request #33046 from DougGregor/function-builder-availability-cleanup
2 parents bd03c47 + 9a8cb05 commit b23a0b7

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5128,7 +5128,7 @@ NOTE(function_builder_infer_pick_specific, none,
51285128
"apply function builder %0 (inferred from %select{protocol|dynamic replacement of}1 %2)",
51295129
(Type, unsigned, DeclName))
51305130
WARNING(function_builder_missing_limited_availability, none,
5131-
"function builder %0 does not implement `buildLimitedAvailability`; "
5131+
"function builder %0 does not implement 'buildLimitedAvailability'; "
51325132
"this code may crash on earlier versions of the OS",
51335133
(Type))
51345134

lib/Sema/BuilderTransform.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ class BuilderClosureVisitor
515515
return nullptr;
516516

517517
// If there is a #available in the condition, the 'then' will need to
518-
// be wrapped in a call to buildAvailabilityErasure(_:), if available.
518+
// be wrapped in a call to buildLimitedAvailability(_:), if available.
519519
Expr *thenVarRefExpr = buildVarRef(
520520
thenVar, ifStmt->getThenStmt()->getEndLoc());
521521
if (findAvailabilityCondition(ifStmt->getCond()) &&
@@ -1202,10 +1202,14 @@ class BuilderClosureRewriter
12021202
ifStmt->setThenStmt(newThen);
12031203

12041204
// Look for a #available condition. If there is one, we need to check
1205-
// that the resulting type of the "then" does refer to any types that
1205+
// that the resulting type of the "then" doesn't refer to any types that
12061206
// are unavailable in the enclosing context.
12071207
//
1208-
// Note that this is for staging in support for
1208+
// Note that this is for staging in support for buildLimitedAvailability();
1209+
// the diagnostic is currently a warning, so that existing code that
1210+
// compiles today will continue to compile. Once function builder types
1211+
// have had the change to adopt buildLimitedAvailability(), we'll upgrade
1212+
// this warning to an error.
12091213
if (auto availabilityCond = findAvailabilityCondition(ifStmt->getCond())) {
12101214
SourceLoc loc = availabilityCond->getStartLoc();
12111215
Type thenBodyType = solution.simplifyType(
@@ -1217,9 +1221,6 @@ class BuilderClosureRewriter
12171221

12181222
if (auto reason = TypeChecker::checkDeclarationAvailability(
12191223
nominal, loc, dc)) {
1220-
// Note that the problem is with the function builder, not the body.
1221-
// This is for staging only. We want to disable #available in
1222-
// function builders that don't support this operation.
12231224
ctx.Diags.diagnose(
12241225
loc, diag::function_builder_missing_limited_availability,
12251226
builderTransform.builderType);

test/Constraints/function_builder_availability.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ tuplify(true) { cond in
6565
if #available(OSX 10.51, *) {
6666
globalFuncAvailableOn10_51()
6767
tuplify(false) { cond2 in
68-
if cond, #available(OSX 10.52, *) { // expected-warning{{function builder 'TupleBuilder' does not implement `buildLimitedAvailability`; this code may crash on earlier versions of the OS}}
68+
if cond, #available(OSX 10.52, *) { // expected-warning{{function builder 'TupleBuilder' does not implement 'buildLimitedAvailability'; this code may crash on earlier versions of the OS}}
6969
cond2
7070
globalFuncAvailableOn10_52()
7171
} else {

0 commit comments

Comments
 (0)