@@ -512,28 +512,28 @@ class ClosureConstraintGenerator
512512 }
513513
514514 void visitBreakStmt (BreakStmt *breakStmt) {
515- if (! isSupportedMultiStatementClosure ())
516- llvm_unreachable ( " Unsupported statement: Break" );
515+ assert ( isSupportedMultiStatementClosure () &&
516+ " Unsupported statement: Break" );
517517 }
518518
519519 void visitContinueStmt (ContinueStmt *continueStmt) {
520- if (! isSupportedMultiStatementClosure ())
521- llvm_unreachable ( " Unsupported statement: Continue" );
520+ assert ( isSupportedMultiStatementClosure () &&
521+ " Unsupported statement: Continue" );
522522 }
523523
524524 void visitDeferStmt (DeferStmt *deferStmt) {
525- if (! isSupportedMultiStatementClosure ())
526- llvm_unreachable ( " Unsupported statement: Defer" );
525+ assert ( isSupportedMultiStatementClosure () &&
526+ " Unsupported statement: Defer" );
527527 }
528528
529529 void visitFallthroughStmt (FallthroughStmt *fallthroughStmt) {
530- if (! isSupportedMultiStatementClosure ())
531- llvm_unreachable ( " Unsupported statement: Fallthrough" );
530+ assert ( isSupportedMultiStatementClosure () &&
531+ " Unsupported statement: Fallthrough" );
532532 }
533533
534534 void visitIfStmt (IfStmt *ifStmt) {
535- if (! isSupportedMultiStatementClosure ())
536- llvm_unreachable ( " Unsupported statement: If" );
535+ assert ( isSupportedMultiStatementClosure () &&
536+ " Unsupported statement: If" );
537537
538538 SmallVector<ElementInfo, 4 > elements;
539539
@@ -562,8 +562,8 @@ class ClosureConstraintGenerator
562562 }
563563
564564 void visitGuardStmt (GuardStmt *guardStmt) {
565- if (! isSupportedMultiStatementClosure ())
566- llvm_unreachable ( " Unsupported statement: Guard" );
565+ assert ( isSupportedMultiStatementClosure () &&
566+ " Unsupported statement: Guard" );
567567
568568 createConjunction (cs,
569569 {makeElement (guardStmt->getCondPointer (),
@@ -574,8 +574,8 @@ class ClosureConstraintGenerator
574574 }
575575
576576 void visitWhileStmt (WhileStmt *whileStmt) {
577- if (! isSupportedMultiStatementClosure ())
578- llvm_unreachable ( " Unsupported statement: Guard " );
577+ assert ( isSupportedMultiStatementClosure () &&
578+ " Unsupported statement: While " );
579579
580580 createConjunction (cs,
581581 {makeElement (whileStmt->getCondPointer (),
@@ -586,15 +586,15 @@ class ClosureConstraintGenerator
586586 }
587587
588588 void visitDoStmt (DoStmt *doStmt) {
589- if (! isSupportedMultiStatementClosure ())
590- llvm_unreachable ( " Unsupported statement: Do" );
589+ assert ( isSupportedMultiStatementClosure () &&
590+ " Unsupported statement: Do" );
591591
592592 visitBraceStmt (doStmt->getBody ());
593593 }
594594
595595 void visitRepeatWhileStmt (RepeatWhileStmt *repeatWhileStmt) {
596- if (! isSupportedMultiStatementClosure ())
597- llvm_unreachable ( " Unsupported statement: RepeatWhile" );
596+ assert ( isSupportedMultiStatementClosure () &&
597+ " Unsupported statement: RepeatWhile" );
598598
599599 createConjunction (cs,
600600 {makeElement (repeatWhileStmt->getCond (),
@@ -606,8 +606,8 @@ class ClosureConstraintGenerator
606606 }
607607
608608 void visitPoundAssertStmt (PoundAssertStmt *poundAssertStmt) {
609- if (! isSupportedMultiStatementClosure ())
610- llvm_unreachable ( " Unsupported statement: PoundAssert" );
609+ assert ( isSupportedMultiStatementClosure () &&
610+ " Unsupported statement: PoundAssert" );
611611
612612 createConjunction (cs,
613613 {makeElement (poundAssertStmt->getCondition (),
@@ -618,8 +618,8 @@ class ClosureConstraintGenerator
618618 }
619619
620620 void visitThrowStmt (ThrowStmt *throwStmt) {
621- if (! isSupportedMultiStatementClosure ())
622- llvm_unreachable ( " Unsupported statement: Throw" );
621+ assert ( isSupportedMultiStatementClosure () &&
622+ " Unsupported statement: Throw" );
623623
624624 Type errType =
625625 cs.getASTContext ().getErrorDecl ()->getDeclaredInterfaceType ();
@@ -641,8 +641,8 @@ class ClosureConstraintGenerator
641641 }
642642
643643 void visitForEachStmt (ForEachStmt *forEachStmt) {
644- if (! isSupportedMultiStatementClosure ())
645- llvm_unreachable ( " Unsupported statement: ForEach" );
644+ assert ( isSupportedMultiStatementClosure () &&
645+ " Unsupported statement: ForEach" );
646646
647647 auto *stmtLoc = cs.getConstraintLocator (locator);
648648
@@ -679,8 +679,8 @@ class ClosureConstraintGenerator
679679 }
680680
681681 void visitSwitchStmt (SwitchStmt *switchStmt) {
682- if (! isSupportedMultiStatementClosure ())
683- llvm_unreachable ( " Unsupported statement: Switch" );
682+ assert ( isSupportedMultiStatementClosure () &&
683+ " Unsupported statement: Switch" );
684684
685685 auto *switchLoc = cs.getConstraintLocator (
686686 locator, LocatorPathElt::ClosureBodyElement (switchStmt));
@@ -705,8 +705,8 @@ class ClosureConstraintGenerator
705705 }
706706
707707 void visitDoCatchStmt (DoCatchStmt *doStmt) {
708- if (! isSupportedMultiStatementClosure ())
709- llvm_unreachable ( " Unsupported statement: DoCatch" );
708+ assert ( isSupportedMultiStatementClosure () &&
709+ " Unsupported statement: DoCatch" );
710710
711711 auto *doLoc = cs.getConstraintLocator (
712712 locator, LocatorPathElt::ClosureBodyElement (doStmt));
@@ -725,8 +725,8 @@ class ClosureConstraintGenerator
725725 }
726726
727727 void visitCaseStmt (CaseStmt *caseStmt) {
728- if (! isSupportedMultiStatementClosure ())
729- llvm_unreachable ( " Unsupported statement: Case" );
728+ assert ( isSupportedMultiStatementClosure () &&
729+ " Unsupported statement: Case" );
730730
731731 Type contextualTy;
732732
@@ -919,6 +919,19 @@ bool ConstraintSystem::generateConstraints(ClosureExpr *closure) {
919919 return false ;
920920}
921921
922+ bool ConstraintSystem::isInResultBuilderContext (ClosureExpr *closure) const {
923+ if (!closure->hasSingleExpressionBody ()) {
924+ auto *DC = closure->getParent ();
925+ do {
926+ if (auto *parentClosure = dyn_cast<ClosureExpr>(DC)) {
927+ if (resultBuilderTransformed.count (parentClosure))
928+ return true ;
929+ }
930+ } while ((DC = DC->getParent ()));
931+ }
932+ return false ;
933+ }
934+
922935bool isConditionOfStmt (ConstraintLocatorBuilder locator) {
923936 auto last = locator.last ();
924937 if (!(last && last->is <LocatorPathElt::Condition>()))
0 commit comments