Skip to content

Commit c71de21

Browse files
committed
[CSClosure] NFC: Deprecate isSupportedMultiStatementClosure
A couple of places where it's still needed could use `isInSingleExpressionClosure` instead, which is a safer check because generator can now be used to handle result builder transformed code and functions as well.
1 parent 3a44e7d commit c71de21

File tree

1 file changed

+40
-93
lines changed

1 file changed

+40
-93
lines changed

lib/Sema/CSClosure.cpp

Lines changed: 40 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ class SyntacticElementConstraintGenerator
556556
}
557557

558558
void visitDecl(Decl *decl) {
559-
if (isSupportedMultiStatementClosure()) {
559+
if (!isInSingleExpressionClosure()) {
560560
if (auto patternBinding = dyn_cast<PatternBindingDecl>(decl)) {
561561
if (locator->isLastElement<LocatorPathElt::PatternBindingElement>())
562562
visitPatternBindingElement(patternBinding);
@@ -585,23 +585,15 @@ class SyntacticElementConstraintGenerator
585585
}
586586

587587
void visitBreakStmt(BreakStmt *breakStmt) {
588-
assert(isSupportedMultiStatementClosure() &&
589-
"Unsupported statement: Break");
590588
}
591589

592590
void visitContinueStmt(ContinueStmt *continueStmt) {
593-
assert(isSupportedMultiStatementClosure() &&
594-
"Unsupported statement: Continue");
595591
}
596592

597593
void visitDeferStmt(DeferStmt *deferStmt) {
598-
assert(isSupportedMultiStatementClosure() &&
599-
"Unsupported statement: Defer");
600594
}
601595

602596
void visitFallthroughStmt(FallthroughStmt *fallthroughStmt) {
603-
assert(isSupportedMultiStatementClosure() &&
604-
"Unsupported statement: Fallthrough");
605597
}
606598

607599
void visitStmtCondition(LabeledConditionalStmt *S,
@@ -614,9 +606,6 @@ class SyntacticElementConstraintGenerator
614606
}
615607

616608
void visitIfStmt(IfStmt *ifStmt) {
617-
assert(isSupportedMultiStatementClosure() &&
618-
"Unsupported statement: If");
619-
620609
SmallVector<ElementInfo, 4> elements;
621610

622611
// Condition
@@ -640,9 +629,6 @@ class SyntacticElementConstraintGenerator
640629
}
641630

642631
void visitGuardStmt(GuardStmt *guardStmt) {
643-
assert(isSupportedMultiStatementClosure() &&
644-
"Unsupported statement: Guard");
645-
646632
SmallVector<ElementInfo, 4> elements;
647633

648634
visitStmtCondition(guardStmt, elements, locator);
@@ -652,9 +638,6 @@ class SyntacticElementConstraintGenerator
652638
}
653639

654640
void visitWhileStmt(WhileStmt *whileStmt) {
655-
assert(isSupportedMultiStatementClosure() &&
656-
"Unsupported statement: While");
657-
658641
SmallVector<ElementInfo, 4> elements;
659642

660643
visitStmtCondition(whileStmt, elements, locator);
@@ -664,16 +647,10 @@ class SyntacticElementConstraintGenerator
664647
}
665648

666649
void visitDoStmt(DoStmt *doStmt) {
667-
assert(isSupportedMultiStatementClosure() &&
668-
"Unsupported statement: Do");
669-
670650
visitBraceStmt(doStmt->getBody());
671651
}
672652

673653
void visitRepeatWhileStmt(RepeatWhileStmt *repeatWhileStmt) {
674-
assert(isSupportedMultiStatementClosure() &&
675-
"Unsupported statement: RepeatWhile");
676-
677654
createConjunction(cs,
678655
{makeElement(repeatWhileStmt->getCond(),
679656
cs.getConstraintLocator(
@@ -684,9 +661,6 @@ class SyntacticElementConstraintGenerator
684661
}
685662

686663
void visitPoundAssertStmt(PoundAssertStmt *poundAssertStmt) {
687-
assert(isSupportedMultiStatementClosure() &&
688-
"Unsupported statement: PoundAssert");
689-
690664
createConjunction(cs,
691665
{makeElement(poundAssertStmt->getCondition(),
692666
cs.getConstraintLocator(
@@ -696,9 +670,6 @@ class SyntacticElementConstraintGenerator
696670
}
697671

698672
void visitThrowStmt(ThrowStmt *throwStmt) {
699-
assert(isSupportedMultiStatementClosure() &&
700-
"Unsupported statement: Throw");
701-
702673
if (!cs.getASTContext().getErrorDecl()) {
703674
hadError = true;
704675
return;
@@ -718,9 +689,6 @@ class SyntacticElementConstraintGenerator
718689
}
719690

720691
void visitForEachStmt(ForEachStmt *forEachStmt) {
721-
assert(isSupportedMultiStatementClosure() &&
722-
"Unsupported statement: ForEach");
723-
724692
auto *stmtLoc = cs.getConstraintLocator(locator);
725693

726694
SmallVector<ElementInfo, 4> elements;
@@ -738,9 +706,6 @@ class SyntacticElementConstraintGenerator
738706
}
739707

740708
void visitSwitchStmt(SwitchStmt *switchStmt) {
741-
assert(isSupportedMultiStatementClosure() &&
742-
"Unsupported statement: Switch");
743-
744709
auto *switchLoc = cs.getConstraintLocator(
745710
locator, LocatorPathElt::SyntacticElement(switchStmt));
746711

@@ -765,9 +730,6 @@ class SyntacticElementConstraintGenerator
765730
}
766731

767732
void visitDoCatchStmt(DoCatchStmt *doStmt) {
768-
assert(isSupportedMultiStatementClosure() &&
769-
"Unsupported statement: DoCatch");
770-
771733
auto *doLoc = cs.getConstraintLocator(
772734
locator, LocatorPathElt::SyntacticElement(doStmt));
773735

@@ -785,9 +747,6 @@ class SyntacticElementConstraintGenerator
785747
}
786748

787749
void visitCaseStmt(CaseStmt *caseStmt) {
788-
assert(isSupportedMultiStatementClosure() &&
789-
"Unsupported statement: Case");
790-
791750
Type contextualTy;
792751

793752
{
@@ -821,56 +780,56 @@ class SyntacticElementConstraintGenerator
821780
}
822781

823782
void visitBraceStmt(BraceStmt *braceStmt) {
824-
if (isSupportedMultiStatementClosure()) {
825-
auto &ctx = cs.getASTContext();
826-
827-
if (isChildOf(StmtKind::Case)) {
828-
auto *caseStmt = cast<CaseStmt>(
829-
locator->castLastElementTo<LocatorPathElt::SyntacticElement>()
830-
.asStmt());
831-
832-
if (recordInferredSwitchCasePatternVars(caseStmt)) {
833-
hadError = true;
783+
if (isInSingleExpressionClosure()) {
784+
for (auto node : braceStmt->getElements()) {
785+
if (auto expr = node.dyn_cast<Expr *>()) {
786+
auto generatedExpr = cs.generateConstraints(
787+
expr, context.getAsDeclContext(), /*isInputExpression=*/false);
788+
if (!generatedExpr) {
789+
hadError = true;
790+
}
791+
} else if (auto stmt = node.dyn_cast<Stmt *>()) {
792+
visit(stmt);
793+
} else {
794+
visitDecl(node.get<Decl *>());
834795
}
835796
}
797+
return;
798+
}
836799

837-
SmallVector<ElementInfo, 4> elements;
838-
for (auto element : braceStmt->getElements()) {
839-
bool isDiscarded =
840-
element.is<Expr *>() &&
841-
(!ctx.LangOpts.Playground && !ctx.LangOpts.DebuggerSupport);
800+
auto &ctx = cs.getASTContext();
842801

843-
if (auto *decl = element.dyn_cast<Decl *>()) {
844-
if (auto *PDB = dyn_cast<PatternBindingDecl>(decl)) {
845-
visitPatternBinding(PDB, elements);
846-
continue;
847-
}
848-
}
802+
if (isChildOf(StmtKind::Case)) {
803+
auto *caseStmt = cast<CaseStmt>(
804+
locator->castLastElementTo<LocatorPathElt::SyntacticElement>()
805+
.asStmt());
849806

850-
elements.push_back(makeElement(
851-
element,
852-
cs.getConstraintLocator(
853-
locator, LocatorPathElt::SyntacticElement(element)),
854-
/*contextualInfo=*/{}, isDiscarded));
807+
if (recordInferredSwitchCasePatternVars(caseStmt)) {
808+
hadError = true;
855809
}
856-
857-
createConjunction(cs, elements, locator);
858-
return;
859810
}
860811

861-
for (auto node : braceStmt->getElements()) {
862-
if (auto expr = node.dyn_cast<Expr *>()) {
863-
auto generatedExpr = cs.generateConstraints(
864-
expr, context.getAsDeclContext(), /*isInputExpression=*/false);
865-
if (!generatedExpr) {
866-
hadError = true;
812+
SmallVector<ElementInfo, 4> elements;
813+
for (auto element : braceStmt->getElements()) {
814+
bool isDiscarded =
815+
element.is<Expr *>() &&
816+
(!ctx.LangOpts.Playground && !ctx.LangOpts.DebuggerSupport);
817+
818+
if (auto *decl = element.dyn_cast<Decl *>()) {
819+
if (auto *PDB = dyn_cast<PatternBindingDecl>(decl)) {
820+
visitPatternBinding(PDB, elements);
821+
continue;
867822
}
868-
} else if (auto stmt = node.dyn_cast<Stmt *>()) {
869-
visit(stmt);
870-
} else {
871-
visitDecl(node.get<Decl *>());
872823
}
824+
825+
elements.push_back(
826+
makeElement(element,
827+
cs.getConstraintLocator(
828+
locator, LocatorPathElt::SyntacticElement(element)),
829+
/*contextualInfo=*/{}, isDiscarded));
873830
}
831+
832+
createConjunction(cs, elements, locator);
874833
}
875834

876835
void visitReturnStmt(ReturnStmt *returnStmt) {
@@ -946,18 +905,6 @@ class SyntacticElementConstraintGenerator
946905
return context.getBodyResultType();
947906
}
948907

949-
bool isSupportedMultiStatementClosure() const {
950-
if (cs.getAppliedResultBuilderTransform(context))
951-
return true;
952-
953-
if (auto *closure =
954-
getAsExpr<ClosureExpr>(context.getAbstractClosureExpr())) {
955-
return !closure->hasSingleExpressionBody() &&
956-
cs.participatesInInference(closure);
957-
}
958-
return true;
959-
}
960-
961908
#define UNSUPPORTED_STMT(STMT) void visit##STMT##Stmt(STMT##Stmt *) { \
962909
llvm_unreachable("Unsupported statement kind " #STMT); \
963910
}

0 commit comments

Comments
 (0)