Skip to content

Commit 7b4786e

Browse files
committed
Sema: Contextualize closures for function builder bodies also
The ContextualizeClosures walker re-parents and assigns discriminators to autoclosures. We weren't doing this walk for function builder bodies, which meant that proper invariants were not being established for the implicit autoclosures synthesized for partially applied method references. This is a recent regression from my change to build curry thunks for unapplied method references in Sema. Fixes <rdar://problem/61039516>.
1 parent 391fc45 commit 7b4786e

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

lib/Sema/TypeCheckStmt.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1911,6 +1911,8 @@ TypeCheckFunctionBodyUntilRequest::evaluate(Evaluator &evaluator,
19111911

19121912
body = *optBody;
19131913
alreadyTypeChecked = true;
1914+
1915+
body->walk(ContextualizeClosures(AFD));
19141916
}
19151917
} else if (func->hasSingleExpressionBody() &&
19161918
func->getResultInterfaceType()->isVoid()) {
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// RUN: %target-swift-emit-silgen %s | %FileCheck %s
2+
3+
@_functionBuilder
4+
struct Builder {
5+
static func buildBlock<T1>(_ t1: T1) -> (T1) {
6+
return (t1)
7+
}
8+
}
9+
10+
struct Handler {
11+
var firstHandler: () -> ()
12+
var secondHandler: () -> ()
13+
}
14+
15+
// We were neglecting to assign discriminators and re-parent
16+
// autoclosures, which would manifest as curried method references
17+
// producing a bogus diagnostic about captures from inside a
18+
// nested type.
19+
class Outer {
20+
struct Inner {
21+
@Builder
22+
var build: Handler {
23+
Handler(firstHandler: self.handler, secondHandler: self.handler)
24+
}
25+
26+
private func handler() {}
27+
}
28+
}
29+
30+
// CHECK-LABEL: sil private [ossa] @$s29function_builder_curry_thunks5OuterC5InnerV5buildAA7HandlerVvgyycAEcfu_ : $@convention(thin) (Outer.Inner) -> @owned @callee_guaranteed () -> ()
31+
// CHECK-LABEL: sil private [ossa] @$s29function_builder_curry_thunks5OuterC5InnerV5buildAA7HandlerVvgyycAEcfu_yycfu0_ : $@convention(thin) (Outer.Inner) -> ()
32+
// CHECK-LABEL: sil private [ossa] @$s29function_builder_curry_thunks5OuterC5InnerV7handler33_DC254A3F89F9C7E65D25434E199F17A4LLyyF : $@convention(method) (Outer.Inner) -> ()
33+
// CHECK-LABEL: sil private [ossa] @$s29function_builder_curry_thunks5OuterC5InnerV5buildAA7HandlerVvgyycAEcfu1_ : $@convention(thin) (Outer.Inner) -> @owned @callee_guaranteed () -> ()

0 commit comments

Comments
 (0)