Skip to content

Commit b545a28

Browse files
committed
Add missing // REQUIRES: swift_feature_ForExpressions
1 parent 8cddae2 commit b545a28

File tree

6 files changed

+48
-37
lines changed

6 files changed

+48
-37
lines changed

include/swift/AST/Expr.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6506,9 +6506,7 @@ struct ForCollectionInit {
65066506
/// An expression that may wrap a statement which produces a single value.
65076507
class SingleValueStmtExpr : public Expr {
65086508
public:
6509-
enum class Kind {
6510-
If, Switch, Do, DoCatch, For
6511-
};
6509+
enum class Kind { If, Switch, Do, DoCatch, For };
65126510

65136511
private:
65146512
Stmt *S;

lib/AST/ASTDumper.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4497,8 +4497,10 @@ class PrintExpr : public ExprVisitor<PrintExpr, void, Label>,
44974497
printCommon(E, "single_value_stmt_expr", label);
44984498
printDeclContext(E);
44994499
if (auto preamble = E->getForExpressionPreamble()) {
4500-
printRec(preamble->ForAccumulatorDecl, Label::optional("for_preamble_accumulator_decl"));
4501-
printRec(preamble->ForAccumulatorBinding, Label::optional("for_preamble_accumulator_binding"));
4500+
printRec(preamble->ForAccumulatorDecl,
4501+
Label::optional("for_preamble_accumulator_decl"));
4502+
printRec(preamble->ForAccumulatorBinding,
4503+
Label::optional("for_preamble_accumulator_binding"));
45024504
}
45034505
printRec(E->getStmt(), &E->getDeclContext()->getASTContext(),
45044506
Label::optional("stmt"));

lib/SILGen/SILGenExpr.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2522,7 +2522,8 @@ RValue RValueEmitter::visitSingleValueStmtExpr(SingleValueStmtExpr *E,
25222522
SGF.visit(binding);
25232523
SGF.emitStmt(E->getStmt());
25242524

2525-
return SGF.emitRValueForDecl(E, ConcreteDeclRef(decl), E->getType(), AccessSemantics::Ordinary);
2525+
return SGF.emitRValueForDecl(E, ConcreteDeclRef(decl), E->getType(),
2526+
AccessSemantics::Ordinary);
25262527
}
25272528

25282529
auto emitStmt = [&]() {

lib/Sema/CSSyntacticElement.cpp

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1496,24 +1496,26 @@ bool ConstraintSystem::generateConstraints(SingleValueStmtExpr *E) {
14961496
setType(E, resultType);
14971497

14981498
if (E->getStmtKind() == SingleValueStmtExpr::Kind::For) {
1499-
auto *rrcProtocol = ctx.getProtocol(KnownProtocolKind::RangeReplaceableCollection);
1499+
auto *rrcProtocol =
1500+
ctx.getProtocol(KnownProtocolKind::RangeReplaceableCollection);
15001501
auto *sequenceProtocol = ctx.getProtocol(KnownProtocolKind::Sequence);
15011502

1502-
addConstraint(ConstraintKind::ConformsTo,
1503-
resultType,
1504-
rrcProtocol->getDeclaredInterfaceType(),
1505-
loc);
1503+
addConstraint(ConstraintKind::ConformsTo, resultType,
1504+
rrcProtocol->getDeclaredInterfaceType(), loc);
15061505
Type elementTypeVar = createTypeVariable(loc, /*options*/ 0);
1507-
Type elementType = DependentMemberType::get(resultType, sequenceProtocol->getAssociatedType(ctx.Id_Element));
1506+
Type elementType = DependentMemberType::get(
1507+
resultType, sequenceProtocol->getAssociatedType(ctx.Id_Element));
15081508

15091509
addConstraint(ConstraintKind::Bind, elementTypeVar, elementType, loc);
1510-
addConstraint(ConstraintKind::Defaultable, resultType, ArraySliceType::get(elementTypeVar), loc);
1510+
addConstraint(ConstraintKind::Defaultable, resultType,
1511+
ArraySliceType::get(elementTypeVar), loc);
15111512

15121513
auto *binding = E->getForExpressionPreamble()->ForAccumulatorBinding;
15131514

15141515
auto *initializer = binding->getInit(0);
1515-
auto target = SyntacticElementTarget::forInitialization(initializer, Type(), binding, 0, false);
1516-
setTargetFor({ binding, 0 }, target);
1516+
auto target = SyntacticElementTarget::forInitialization(initializer, Type(),
1517+
binding, 0, false);
1518+
setTargetFor({binding, 0}, target);
15171519

15181520
if (generateConstraints(target)) {
15191521
return true;
@@ -1552,15 +1554,15 @@ bool ConstraintSystem::generateConstraints(SingleValueStmtExpr *E) {
15521554

15531555
if (E->getStmtKind() != SingleValueStmtExpr::Kind::For) {
15541556
if (branches.empty()) {
1555-
// If we only have statement branches, the expression is typed as Void. This
1556-
// should only be the case for 'if' and 'switch' statements that must be
1557-
// expressions that have branches that all end in a throw, and we'll warn
1558-
// that we've inferred Void.
1557+
// If we only have statement branches, the expression is typed as Void.
1558+
// This should only be the case for 'if' and 'switch' statements that must
1559+
// be expressions that have branches that all end in a throw, and we'll
1560+
// warn that we've inferred Void.
15591561
addConstraint(ConstraintKind::Bind, resultType, ctx.getVoidType(), loc);
15601562
} else {
15611563
// Otherwise, we join the result types for each of the branches.
15621564
join = TypeJoinExpr::forBranchesOfSingleValueStmtExpr(
1563-
ctx, resultType, E, AllocationArena::ConstraintSolver);
1565+
ctx, resultType, E, AllocationArena::ConstraintSolver);
15641566
}
15651567
}
15661568

@@ -1605,8 +1607,8 @@ bool ConstraintSystem::generateConstraints(SingleValueStmtExpr *E) {
16051607
*this, ConstraintKind::Bind, resultType, closureResultTy, loc);
16061608
bindToClosure->setFavored();
16071609

1608-
auto *bindToVoid = Constraint::create(*this, ConstraintKind::Bind,
1609-
resultType, ctx.getVoidType(), loc);
1610+
auto *bindToVoid = Constraint::create(
1611+
*this, ConstraintKind::Bind, resultType, ctx.getVoidType(), loc);
16101612

16111613
addDisjunctionConstraint({bindToClosure, bindToVoid}, loc);
16121614
}
@@ -2701,7 +2703,7 @@ bool ConstraintSystem::applySolutionToSingleValueStmt(
27012703

27022704
if (SVE->getStmtKind() == SingleValueStmtExpr::Kind::For) {
27032705
auto *binding = SVE->getForExpressionPreamble()->ForAccumulatorBinding;
2704-
auto target = getTargetFor({ binding, 0 }).value();
2706+
auto target = getTargetFor({binding, 0}).value();
27052707

27062708
auto newTarget = rewriter.rewriteTarget(target);
27072709
if (!newTarget) {

lib/Sema/PreCheckTarget.cpp

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1718,18 +1718,23 @@ void PreCheckTarget::transformForExpression(SingleValueStmtExpr *SVE) {
17181718

17191719
auto sveLoc = SVE->getLoc();
17201720

1721-
auto *varDecl = new(astCtx) VarDecl(false, VarDecl::Introducer::Var, sveLoc,
1722-
astCtx.getIdentifier("$forExpressionResult"), declCtx);
1721+
auto *varDecl = new (astCtx)
1722+
VarDecl(false, VarDecl::Introducer::Var, sveLoc,
1723+
astCtx.getIdentifier("$forExpressionResult"), declCtx);
17231724

17241725
auto namedPattern = NamedPattern::createImplicit(astCtx, varDecl);
17251726

1726-
auto *initFunc = new(astCtx) UnresolvedMemberExpr(sveLoc, DeclNameLoc(), DeclNameRef(DeclBaseName::createConstructor()), true);
1727+
auto *initFunc = new (astCtx) UnresolvedMemberExpr(
1728+
sveLoc, DeclNameLoc(), DeclNameRef(DeclBaseName::createConstructor()),
1729+
true);
17271730
auto *callExpr = CallExpr::createImplicitEmpty(astCtx, initFunc);
1728-
auto *initExpr = new(astCtx) UnresolvedMemberChainResultExpr(callExpr, initFunc);
1731+
auto *initExpr =
1732+
new (astCtx) UnresolvedMemberChainResultExpr(callExpr, initFunc);
17291733

1730-
auto *bindingDecl = PatternBindingDecl::createImplicit(astCtx, StaticSpellingKind::None, namedPattern, initExpr, declCtx);
1734+
auto *bindingDecl = PatternBindingDecl::createImplicit(
1735+
astCtx, StaticSpellingKind::None, namedPattern, initExpr, declCtx);
17311736

1732-
SVE->setForExpressionPreamble({ varDecl, bindingDecl });
1737+
SVE->setForExpressionPreamble({varDecl, bindingDecl});
17331738

17341739
// For-expressions always have a single branch.
17351740
SmallVector<Stmt *, 1> scratch;
@@ -1741,14 +1746,15 @@ void PreCheckTarget::transformForExpression(SingleValueStmtExpr *SVE) {
17411746
auto &result = BS->getElements().back();
17421747
if (auto stmt = result.dyn_cast<Stmt *>()) {
17431748
if (auto *then = dyn_cast<ThenStmt>(stmt)) {
1744-
auto *declRefExpr = new(astCtx) DeclRefExpr(varDecl, DeclNameLoc(), true);
1745-
auto *dotExpr = new(astCtx) UnresolvedDotExpr(declRefExpr,
1746-
SourceLoc(),
1747-
DeclNameRef(DeclBaseName(astCtx.Id_append)),
1748-
DeclNameLoc(),
1749-
true);
1750-
auto *argumentList = ArgumentList::createImplicit(astCtx, { Argument::unlabeled(then->getResult()) });
1751-
auto *callExpr = CallExpr::createImplicit(astCtx, dotExpr, argumentList);
1749+
auto *declRefExpr =
1750+
new (astCtx) DeclRefExpr(varDecl, DeclNameLoc(), true);
1751+
auto *dotExpr = new (astCtx) UnresolvedDotExpr(
1752+
declRefExpr, SourceLoc(),
1753+
DeclNameRef(DeclBaseName(astCtx.Id_append)), DeclNameLoc(), true);
1754+
auto *argumentList = ArgumentList::createImplicit(
1755+
astCtx, {Argument::unlabeled(then->getResult())});
1756+
auto *callExpr =
1757+
CallExpr::createImplicit(astCtx, dotExpr, argumentList);
17521758
then->setResult(callExpr);
17531759
}
17541760
}

test/stmt/for-expr.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// RUN: %target-run-simple-swift(-enable-experimental-feature ForExpressions) | %FileCheck %s
22

3+
// REQUIRES: swift_feature_ForExpressions
4+
35
func f() -> String {
46
for (i, x) in "hello".enumerated() {
57
if i % 2 == 0 {

0 commit comments

Comments
 (0)