Skip to content

Commit 3b061e6

Browse files
authored
Merge pull request #39624 from jckarter/capture-expansion-context
SIL: Lower closure functions' captures in their own expansion context.
2 parents baf032b + 1290cc4 commit 3b061e6

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

lib/SIL/IR/SILFunctionType.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2203,8 +2203,13 @@ static CanSILFunctionType getSILFunctionType(
22032203

22042204
// Lower the capture context parameters, if any.
22052205
if (constant && constant->getAnyFunctionRef()) {
2206+
// Lower in the context of the closure. Since the set of captures is a
2207+
// private contract between the closure and its enclosing context, we
2208+
// don't need to keep its capture types opaque.
22062209
auto expansion = TypeExpansionContext::maximal(
2207-
expansionContext.getContext(), expansionContext.isWholeModuleContext());
2210+
constant->getAnyFunctionRef()->getAsDeclContext(), false);
2211+
// ...unless it's inlinable, in which case it might get inlined into
2212+
// some place we need to keep opaque types opaque.
22082213
if (constant->isSerialized())
22092214
expansion = TypeExpansionContext::minimal();
22102215
lowerCaptureContextParameters(TC, *constant, genericSig, expansion, inputs);
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// RUN: %target-swift-emit-silgen -disable-availability-checking -verify %s
2+
// rdar://83378116
3+
4+
public protocol P {}
5+
public protocol Q {}
6+
7+
struct SP<T: P>: P { init(t: T) {} }
8+
struct SQ: Q {}
9+
10+
struct Tubb<C: Q, T, F> {
11+
}
12+
13+
extension Tubb: P where T: P, F: P {
14+
init(c: C, t: () -> T, f: () -> F) {}
15+
}
16+
17+
struct SP2: P {}
18+
19+
func bar() -> some P { return SP2() }
20+
21+
public struct Butt {
22+
public func foo() -> some P {
23+
let sp = SP(t: bar())
24+
return Tubb(c: SQ(), t: { sp }, f: { sp })
25+
}
26+
}

0 commit comments

Comments
 (0)