Skip to content

SIL: Lower closure functions' captures in their own expansion context. #39624

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/SIL/IR/SILFunctionType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2212,8 +2212,13 @@ static CanSILFunctionType getSILFunctionType(

// Lower the capture context parameters, if any.
if (constant && constant->getAnyFunctionRef()) {
// Lower in the context of the closure. Since the set of captures is a
// private contract between the closure and its enclosing context, we
// don't need to keep its capture types opaque.
auto expansion = TypeExpansionContext::maximal(
expansionContext.getContext(), expansionContext.isWholeModuleContext());
constant->getAnyFunctionRef()->getAsDeclContext(), false);
// ...unless it's inlinable, in which case it might get inlined into
// some place we need to keep opaque types opaque.
if (constant->isSerialized())
expansion = TypeExpansionContext::minimal();
lowerCaptureContextParameters(TC, *constant, genericSig, expansion, inputs);
Expand Down
26 changes: 26 additions & 0 deletions test/SILGen/opaque_result_type_captured.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// RUN: %target-swift-emit-silgen -disable-availability-checking -verify %s
// rdar://83378116

public protocol P {}
public protocol Q {}

struct SP<T: P>: P { init(t: T) {} }
struct SQ: Q {}

struct Tubb<C: Q, T, F> {
}

extension Tubb: P where T: P, F: P {
init(c: C, t: () -> T, f: () -> F) {}
}

struct SP2: P {}

func bar() -> some P { return SP2() }

public struct Butt {
public func foo() -> some P {
let sp = SP(t: bar())
return Tubb(c: SQ(), t: { sp }, f: { sp })
}
}