Skip to content

IRGen: Don't emit capture descriptor for stack allocated closures #22096

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
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
13 changes: 7 additions & 6 deletions lib/IRGen/GenFunc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1456,10 +1456,6 @@ Optional<StackAddress> irgen::emitFunctionPartialApplication(
/*typeToFill*/ nullptr,
std::move(bindings));

auto descriptor = IGF.IGM.getAddrOfCaptureDescriptor(SILFn, origType,
substType, subs,
layout);

llvm::Value *data;

Optional<StackAddress> stackAddr;
Expand All @@ -1479,8 +1475,13 @@ Optional<StackAddress> irgen::emitFunctionPartialApplication(
stackAddr = stackAddr->withAddress(IGF.Builder.CreateBitCast(
stackAddr->getAddress(), IGF.IGM.OpaquePtrTy));
data = stackAddr->getAddress().getAddress();
} else
data = IGF.emitUnmanagedAlloc(layout, "closure", descriptor, &offsets);
} else {
auto descriptor = IGF.IGM.getAddrOfCaptureDescriptor(SILFn, origType,
substType, subs,
layout);

data = IGF.emitUnmanagedAlloc(layout, "closure", descriptor, &offsets);
}
Address dataAddr = layout.emitCastTo(IGF, data);

unsigned i = 0;
Expand Down
10 changes: 10 additions & 0 deletions test/IRGen/closure.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// RUN: %target-swift-frontend -primary-file %s -emit-ir | %FileCheck %s
// RUN: %target-swift-frontend -primary-file %s -emit-ir | %FileCheck %s --check-prefix=CAPTURE

// REQUIRES: CPU=x86_64

Expand Down Expand Up @@ -55,3 +56,12 @@ func captures_tuple<T, U>(x x: (T, U)) -> () -> (T, U) {
// CHECK: bitcast %swift.opaque* [[ADDR]] to <{}>*
return {x}
}

class C {}

func useClosure(_ cl : () -> ()) {}

// CAPTURE-NOT: reflection_descriptor{{.*}} = private constant { i32, i32, i32, i32, i32, i32, i32, i32 } { i32 5, i32 0, i32 0
func no_capture_descriptor(_ c: C, _ d: C, _ e: C, _ f: C, _ g: C) {
useClosure( { _ = c ; _ = d ; _ = e ; _ = f ; _ = g })
}
2 changes: 1 addition & 1 deletion test/IRGen/partial_apply_forwarder.sil
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ bb0(%0 : $*τ_0_1, %2: $EmptyType):
// CHECK: call noalias %swift.refcounted* @swift_allocObject(%swift.type* [[WBTY]]
// CHECK: ret void

// CHECK-LABEL: define internal swiftcc void @"$s7takingQTA.2"(%T23partial_apply_forwarder7WeakBoxC*, %swift.refcounted* swiftself)
// CHECK-LABEL: define internal swiftcc void @"$s7takingQTA.1"(%T23partial_apply_forwarder7WeakBoxC*, %swift.refcounted* swiftself)
// CHECK: entry:
// CHECK: [[TYADDR:%.*]] = getelementptr inbounds %T23partial_apply_forwarder7WeakBoxC, %T23partial_apply_forwarder7WeakBoxC* %0
// CHECK: [[TY:%.*]] = load %swift.type*, %swift.type** [[TYADDR]]
Expand Down
6 changes: 6 additions & 0 deletions test/IRGen/swift3-metadata-coff.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,14 @@ public protocol P {
associatedtype T
}

enum E {
case a
case b
}

public struct S : P {
public typealias T = Optional<S>
var e = E.a
}

var gg = S()
Expand Down