Skip to content

Commit 35c24bc

Browse files
committed
[ConstraintSystem] Make it possible to determine that closure is in result builder context
1 parent d1bb98b commit 35c24bc

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

include/swift/Sema/ConstraintSystem.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5287,6 +5287,10 @@ class ConstraintSystem {
52875287
/// part of the constraint system.
52885288
void forEachExpr(Expr *expr, llvm::function_ref<Expr *(Expr *)> callback);
52895289

5290+
/// Determine whether one of the parent closures the given one is nested
5291+
/// in (if any) has a result builder applied to its body.
5292+
bool isInResultBuilderContext(ClosureExpr *closure) const;
5293+
52905294
SWIFT_DEBUG_DUMP;
52915295
SWIFT_DEBUG_DUMPER(dump(Expr *));
52925296

lib/Sema/CSClosure.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
922935
bool isConditionOfStmt(ConstraintLocatorBuilder locator) {
923936
auto last = locator.last();
924937
if (!(last && last->is<LocatorPathElt::Condition>()))

0 commit comments

Comments
 (0)