Skip to content

Commit 96218ac

Browse files
committed
IRGen: Only emit capture descriptors if -enable-reflection-metadata frontend flag is passed in
Also, simplify the IRGen/reflection_metadata.swift test a bit; there's no reason to split it up into two files.
1 parent faecfda commit 96218ac

File tree

5 files changed

+89
-69
lines changed

5 files changed

+89
-69
lines changed

lib/IRGen/GenFunc.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,7 +1289,7 @@ void irgen::emitFunctionPartialApplication(IRGenFunction &IGF,
12891289
/*typeToFill*/ nullptr,
12901290
std::move(bindings));
12911291

1292-
auto Descriptor = IGF.IGM.getAddrOfCaptureDescriptor(SILFn, layout);
1292+
auto descriptor = IGF.IGM.getAddrOfCaptureDescriptor(SILFn, layout);
12931293

12941294
llvm::Value *data;
12951295
if (layout.isKnownEmpty()) {
@@ -1298,9 +1298,8 @@ void irgen::emitFunctionPartialApplication(IRGenFunction &IGF,
12981298
// Allocate a new object.
12991299
HeapNonFixedOffsets offsets(IGF, layout);
13001300

1301-
data = IGF.emitUnmanagedAlloc(layout, "closure", Descriptor, &offsets);
1301+
data = IGF.emitUnmanagedAlloc(layout, "closure", descriptor, &offsets);
13021302
Address dataAddr = layout.emitCastTo(IGF, data);
1303-
13041303

13051304
unsigned i = 0;
13061305

lib/IRGen/GenReflection.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,9 @@ llvm::Constant *IRGenModule::getAddrOfStringForTypeRef(StringRef Str) {
771771

772772
llvm::Constant *IRGenModule::getAddrOfCaptureDescriptor(SILFunction &SILFn,
773773
HeapLayout &Layout) {
774+
if (!IRGen.Opts.EnableReflectionMetadata)
775+
return llvm::Constant::getNullValue(CaptureDescriptorPtrTy);
776+
774777
llvm::SetVector<CanType> BuiltinTypes;
775778
CaptureDescriptorBuilder builder(*this, BuiltinTypes, SILFn, Layout);
776779

@@ -782,9 +785,6 @@ llvm::Constant *IRGenModule::getAddrOfCaptureDescriptor(SILFunction &SILFn,
782785
}
783786

784787
void IRGenModule::emitReflectionMetadata(const NominalTypeDecl *Decl) {
785-
if (!IRGen.Opts.EnableReflectionMetadata)
786-
return;
787-
788788
llvm::SetVector<CanType> BuiltinTypes;
789789

790790
emitFieldMetadataRecord(Decl);

test/IRGen/Inputs/reflection_metadata.swift

Lines changed: 0 additions & 57 deletions
This file was deleted.

test/IRGen/closure.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
// -- partial_apply context metadata
66

7-
// CHECK: [[METADATA:@.*]] = private constant %swift.full_boxmetadata { void (%swift.refcounted*)* @objectdestroy.2, i8** null, %swift.type { i64 64 }, i32 16, i8* bitcast (<{ i32, i32, i32, i32, i32, i32 }>* @"\01l__swift3_capture_descriptor.1" to i8*) }
7+
// CHECK: [[METADATA:@.*]] = private constant %swift.full_boxmetadata { void (%swift.refcounted*)* @objectdestroy.1, i8** null, %swift.type { i64 64 }, i32 16, i8* null }
88

99
func a(i i: Int) -> (Int) -> Int {
1010
return { x in i }

test/IRGen/reflection_metadata.swift

Lines changed: 83 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
1-
// RUN: %target-swift-frontend -enable-reflection-metadata -enable-reflection-names -emit-ir %S/Inputs/reflection_metadata.swift | FileCheck %s
2-
// RUN: %target-swift-frontend -enable-reflection-metadata -emit-ir %S/Inputs/reflection_metadata.swift | FileCheck %s --check-prefix=STRIP_REFLECTION_NAMES
3-
// RUN: %target-swift-frontend -emit-ir %S/Inputs/reflection_metadata.swift | FileCheck %s --check-prefix=STRIP_REFLECTION_METADATA
1+
// RUN: %target-swift-frontend -enable-reflection-metadata -enable-reflection-names -emit-ir %s | FileCheck %s
2+
// RUN: %target-swift-frontend -enable-reflection-metadata -emit-ir %s | FileCheck %s --check-prefix=STRIP_REFLECTION_NAMES
3+
// RUN: %target-swift-frontend -emit-ir %s | FileCheck %s --check-prefix=STRIP_REFLECTION_METADATA
44

5-
// STRIP_REFLECTION_NAMES-NOT: {{.*}}swift3_reflstr
65
// STRIP_REFLECTION_NAMES_DAG: {{.*}}swift3_reflect
6+
// STRIP_REFLECTION_NAMES_DAG: {{.*}}swift3_fieldmd
7+
// STRIP_REFLECTION_NAMES_DAG: {{.*}}swift3_assocty
8+
// STRIP_REFLECTION_NAMES-DAG: {{.*}}swift3_capture
9+
// STRIP_REFLECTION_NAMES-DAG: {{.*}}swift3_typeref
10+
// STRIP_REFLECTION_NAMES-NOT: {{.*}}swift3_reflstr
11+
// STRIP_REFLECTION_NAMES-NOT: {{.*}}swift3_builtin
12+
713
// STRIP_REFLECTION_NAMES-DAG: @"\01l__swift3_reflection_metadata"
814

9-
// STRIP_REFLECTION_METADATA-NOT: {{.*}}swift3_reflstr
1015
// STRIP_REFLECTION_METADATA-NOT: {{.*}}swift3_reflect
16+
// STRIP_REFLECTION_METADATA-NOT: {{.*}}swift3_fieldmd
17+
// STRIP_REFLECTION_METADATA-NOT: {{.*}}swift3_assocty
18+
// STRIP_REFLECTION_METADATA-NOT: {{.*}}swift3_capture
19+
// STRIP_REFLECTION_METADATA-NOT: {{.*}}swift3_typeref
20+
// STRIP_REFLECTION_METADATA-NOT: {{.*}}swift3_reflstr
21+
// STRIP_REFLECTION_METADATA-NOT: {{.*}}swift3_builtin
22+
1123
// STRIP_REFLECTION_METADATA-NOT: @"\01l__swift3_reflection_metadata"
1224

1325
// CHECK-DAG: private constant [2 x i8] c"i\00", section "{{[^"]*}}swift3_reflstr{{[^"]*}}"
@@ -27,3 +39,69 @@
2739
// CHECK-DAG: private constant [3 x i8] c"GE\00", section "{{[^"]*}}swift3_reflstr{{[^"]*}}"
2840

2941
// CHECK: @"\01l__swift3_reflection_metadata{{.*}}" = private constant <{ {{.*}} }>
42+
43+
public protocol MyProtocol {
44+
associatedtype Inner
45+
var inner: Inner { get }
46+
}
47+
48+
public class MyClass {
49+
let i: Int
50+
let ms: MyStruct
51+
let me: MyEnum
52+
public init(i: Int, ms: MyStruct, me: MyEnum) {
53+
self.i = i
54+
self.ms = ms
55+
self.me = me
56+
}
57+
}
58+
59+
public struct Conformance : MyProtocol {
60+
public var inner: Int = 0
61+
}
62+
63+
public struct MyStruct {
64+
let i: Int
65+
let mc: MyClass
66+
let me: MyEnum
67+
}
68+
69+
public enum MyEnum {
70+
case C(MyClass)
71+
indirect case S(MyStruct)
72+
indirect case E(MyEnum)
73+
case I(Int)
74+
}
75+
76+
public class MyGenericClass<T : MyProtocol> {
77+
let t: T
78+
let i: T.Inner
79+
let mgs: MyGenericStruct<T>
80+
let mge: MyGenericEnum<T>
81+
82+
public init(t: T, i: T.Inner, mgs: MyGenericStruct<T>, mge: MyGenericEnum<T>) {
83+
self.t = t
84+
self.i = i
85+
self.mgs = mgs
86+
self.mge = mge
87+
}
88+
}
89+
90+
public struct MyGenericStruct<T : MyProtocol> {
91+
let t: T
92+
let i: T.Inner
93+
let mgc: MyGenericClass<T>
94+
let mge: MyGenericEnum<T>
95+
}
96+
97+
public enum MyGenericEnum<T : MyProtocol> {
98+
case GC(MyGenericClass<T>)
99+
indirect case GS(MyGenericStruct<T>)
100+
indirect case GE(MyGenericEnum<T>)
101+
case I(Int)
102+
}
103+
104+
public func makeSomeClosures<T, U>(t: T, x: Int, y: MyGenericStruct<U>)
105+
-> (() -> (), () -> (), () -> ()) {
106+
return ({ _ = t }, { _ = x }, { _ = y })
107+
}

0 commit comments

Comments
 (0)