Skip to content

Commit 19ffbdd

Browse files
authored
Merge pull request #24338 from DougGregor/irgen-emit-lazy-opaque-descriptors-5.1
[5.1] [IRGen] Emit lazy opaque type descriptors.
2 parents 6fee373 + 894703d commit 19ffbdd

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

lib/IRGen/GenDecl.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1082,6 +1082,7 @@ void IRGenerator::emitTypeMetadataRecords() {
10821082
void IRGenerator::emitLazyDefinitions() {
10831083
while (!LazyTypeMetadata.empty() ||
10841084
!LazyTypeContextDescriptors.empty() ||
1085+
!LazyOpaqueTypeDescriptors.empty() ||
10851086
!LazyFieldDescriptors.empty() ||
10861087
!LazyFunctionDefinitions.empty() ||
10871088
!LazyWitnessTables.empty()) {
@@ -1106,6 +1107,15 @@ void IRGenerator::emitLazyDefinitions() {
11061107
emitLazyTypeContextDescriptor(*IGM.get(), type,
11071108
RequireMetadata_t(entry.IsMetadataUsed));
11081109
}
1110+
while (!LazyOpaqueTypeDescriptors.empty()) {
1111+
OpaqueTypeDecl *type = LazyOpaqueTypeDescriptors.pop_back_val();
1112+
auto &entry = LazyOpaqueTypes.find(type)->second;
1113+
assert(hasLazyMetadata(type));
1114+
assert(entry.IsDescriptorUsed && !entry.IsDescriptorEmitted);
1115+
entry.IsDescriptorEmitted = true;
1116+
CurrentIGMPtr IGM = getGenModule(type->getDeclContext());
1117+
IGM->emitOpaqueTypeDecl(type);
1118+
}
11091119
while (!LazyFieldDescriptors.empty()) {
11101120
NominalTypeDecl *type = LazyFieldDescriptors.pop_back_val();
11111121
CurrentIGMPtr IGM = getGenModule(type->getDeclContext());
@@ -1266,7 +1276,10 @@ void IRGenerator::noteUseOfFieldDescriptor(NominalTypeDecl *type) {
12661276
void IRGenerator::noteUseOfOpaqueTypeDescriptor(OpaqueTypeDecl *opaque) {
12671277
if (!opaque)
12681278
return;
1269-
1279+
1280+
if (!hasLazyMetadata(opaque))
1281+
return;
1282+
12701283
auto insertResult = LazyOpaqueTypes.try_emplace(opaque);
12711284
auto &entry = insertResult.first->second;
12721285

lib/IRGen/IRGenModule.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ class IRGenerator {
245245
struct LazyOpaqueInfo {
246246
bool IsLazy = false;
247247
bool IsDescriptorUsed = false;
248+
bool IsDescriptorEmitted = false;
248249
};
249250
/// The set of opaque types enqueued for lazy emission.
250251
llvm::DenseMap<OpaqueTypeDecl*, LazyOpaqueInfo> LazyOpaqueTypes;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// RUN: %target-swift-frontend -parse-as-library -module-name=test -O -primary-file %s -emit-ir > %t.ll
2+
// RUN: %FileCheck %s < %t.ll
3+
4+
protocol P { }
5+
6+
protocol Q {
7+
associatedtype AT: P
8+
func getAT() -> AT
9+
}
10+
11+
private struct X: Q {
12+
private struct Inner: P { }
13+
14+
// CHECK: @"$s4test1X33_58D62B15E5EAC1447430E52C74EAD489LLV5getATQryFQOMQ" = internal constant
15+
func getAT() -> some P {
16+
return Inner()
17+
}
18+
}
19+
20+
func testMe<T: Q>(_ t: T) {
21+
_ = t.getAT()
22+
}
23+
24+
func doIt() {
25+
testMe(X())
26+
}

0 commit comments

Comments
 (0)