Skip to content

Commit f363a10

Browse files
committed
runtime interface fixup irgen
1 parent cf00892 commit f363a10

File tree

5 files changed

+33
-25
lines changed

5 files changed

+33
-25
lines changed

lib/IRGen/GenArchetype.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -458,11 +458,13 @@ MetadataResponse irgen::emitOpaqueTypeMetadataRef(IRGenFunction &IGF,
458458
auto descriptor = IGF.IGM
459459
.getAddrOfOpaqueTypeDescriptor(opaqueDecl, ConstantInit());
460460

461+
auto indexValue = llvm::ConstantInt::get(IGF.IGM.SizeTy, 0);
462+
461463
llvm::CallInst *result = nullptr;
462464
withOpaqueTypeGenericArgs(IGF, archetype,
463465
[&](llvm::Value *genericArgs) {
464466
result = IGF.Builder.CreateCall(accessorFn,
465-
{request.get(IGF), genericArgs, descriptor});
467+
{request.get(IGF), genericArgs, descriptor, indexValue});
466468
result->setDoesNotThrow();
467469
result->setCallingConv(IGF.IGM.SwiftCC);
468470
result->addAttribute(llvm::AttributeList::FunctionIndex,
@@ -488,7 +490,7 @@ llvm::Value *irgen::emitOpaqueTypeWitnessTableRef(IRGenFunction &IGF,
488490
protocol);
489491
assert(foundProtocol != archetype->getConformsTo().end());
490492

491-
unsigned index = foundProtocol - archetype->getConformsTo().begin();
493+
unsigned index = foundProtocol - archetype->getConformsTo().begin() + 1;
492494
auto indexValue = llvm::ConstantInt::get(IGF.IGM.SizeTy, index);
493495

494496
llvm::CallInst *result = nullptr;

lib/IRGen/GenMeta.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1648,6 +1648,7 @@ namespace {
16481648

16491649
void layout() {
16501650
super::layout();
1651+
addGenericSignature();
16511652
addUnderlyingTypeAndConformances();
16521653
}
16531654

@@ -1734,10 +1735,11 @@ namespace {
17341735
}
17351736

17361737
uint16_t getKindSpecificFlags() {
1737-
// Store the ordinal of the generic argument that represents the opaque
1738-
// type in the encoded generic signature.
1739-
return O->getOpaqueInterfaceGenericSignature()
1740-
->getGenericParamOrdinal(O->getUnderlyingInterfaceType());
1738+
// Store the size of the type and conformances vector in the flags.
1739+
auto opaqueType = O->getDeclaredInterfaceType()
1740+
->castTo<OpaqueTypeArchetypeType>();
1741+
1742+
return 1 + opaqueType->getConformsTo().size();
17411743
}
17421744
};
17431745
} // end anonymous namespace

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,9 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
814814
std::string Result = Mangler.mangleTypeForDebugger(
815815
Ty, nullptr);
816816

817-
if (!Opts.DisableRoundTripDebugTypes) {
817+
if (!Opts.DisableRoundTripDebugTypes
818+
// FIXME: implement type reconstruction for opaque types
819+
&& !Ty->hasOpaqueArchetype()) {
818820
// Make sure we can reconstruct mangled types for the debugger.
819821
#ifndef NDEBUG
820822
auto &Ctx = Ty->getASTContext();
@@ -1368,8 +1370,8 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
13681370
break;
13691371

13701372
case TypeKind::OpaqueTypeArchetype:
1371-
// TODO: opaque type resilience
1372-
llvm_unreachable("should be lowered to underlying type; resilience not implemented");
1373+
// TODO
1374+
break;
13731375
case TypeKind::PrimaryArchetype:
13741376
case TypeKind::OpenedArchetype:
13751377
case TypeKind::NestedArchetype: {

lib/IRGen/LocalTypeData.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,10 +332,12 @@ static void maybeEmitDebugInfoForLocalTypeData(IRGenFunction &IGF,
332332
if (key.Kind != LocalTypeDataKind::forFormalTypeMetadata())
333333
return;
334334

335-
// Only for primary archetypes.
336-
auto type = dyn_cast<PrimaryArchetypeType>(key.Type);
335+
// Only for archetypes, and not for opened/opaque archetypes.
336+
auto type = dyn_cast<ArchetypeType>(key.Type);
337337
if (!type)
338338
return;
339+
if (!isa<PrimaryArchetypeType>(type))
340+
return;
339341

340342
auto *typeParam = type->getInterfaceType()->castTo<GenericTypeParamType>();
341343
auto name = typeParam->getName().str();

test/IRGen/opaque_result_type.swift

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ extension Int: O, O2 {
2727

2828
extension String: P {
2929
// CHECK-LABEL: @"$sSS18opaque_result_typeE3pooQryFQOMQ" = {{.*}} constant <{ {{.*}} }> <{
30-
// -- header: opaque type context (0x4), generic (0x80), unique (0x40)
31-
// CHECK-SAME: <i32 0xc4>,
30+
// -- header: opaque type context (0x4), generic (0x80), unique (0x40), two entries (0x2_0000)
31+
// CHECK-SAME: <i32 0x2_00c4>,
3232
// -- parent context: module, or anon context for function
3333
// CHECK-SAME: @"$s18opaque_result_typeMXM"
3434
// -- mangled underlying type
@@ -43,8 +43,8 @@ extension String: P {
4343

4444
public class C: P, Q {
4545
// CHECK-LABEL: @"$s18opaque_result_type1CC3pooQryFQOMQ" = {{.*}} constant <{ {{.*}} }> <{
46-
// -- header: opaque type context (0x4), generic (0x80), unique (0x40)
47-
// CHECK-SAME: <i32 0xc4>
46+
// -- header: opaque type context (0x4), generic (0x80), unique (0x40), two entries (0x2_0000)
47+
// CHECK-SAME: <i32 0x2_00c4>
4848
// -- parent context: module, or anon context for function
4949
// CHECK-SAME: @"$s18opaque_result_typeMXM"
5050
// -- mangled underlying type
@@ -57,8 +57,8 @@ public class C: P, Q {
5757
}
5858

5959
// CHECK-LABEL: @"$s18opaque_result_type1CC3qooQryFQOMQ" = {{.*}} constant <{ {{.*}} }> <{
60-
// -- header: opaque type context (0x4), generic (0x80), unique (0x40)
61-
// CHECK-SAME: <i32 0xc4>
60+
// -- header: opaque type context (0x4), generic (0x80), unique (0x40), three entries (0x3_0000)
61+
// CHECK-SAME: <i32 0x3_00c4>
6262
// -- parent context: module, or anon context for function
6363
// CHECK-SAME: @"$s18opaque_result_typeMXM"
6464
// -- mangled underlying type
@@ -74,8 +74,8 @@ public class C: P, Q {
7474
}
7575

7676
// CHECK-LABEL: @"$s18opaque_result_type3foo1xQrSS_tFQOMQ" = {{.*}} constant <{ {{.*}} }> <{
77-
// -- header: opaque type context (0x4), generic (0x80), unique (0x40)
78-
// CHECK-SAME: <i32 0xc4>
77+
// -- header: opaque type context (0x4), generic (0x80), unique (0x40), two entries (0x2_0000)
78+
// CHECK-SAME: <i32 0x2_00c4>
7979
// -- parent context: module, or anon context for function
8080
// CHECK-SAME: @"$s18opaque_result_typeMXM"
8181
// -- mangled underlying type
@@ -88,8 +88,8 @@ func foo(x: String) -> __opaque P {
8888
}
8989

9090
// CHECK-LABEL: @"$s18opaque_result_type3bar1yQrAA1CC_tFQOMQ" = {{.*}} constant <{ {{.*}} }> <{
91-
// -- header: opaque type context (0x4), generic (0x80), unique (0x40)
92-
// CHECK-SAME: <i32 0xc4>
91+
// -- header: opaque type context (0x4), generic (0x80), unique (0x40), two entries (0x2_0000)
92+
// CHECK-SAME: <i32 0x2_00c4>
9393
// -- parent context: module, or anon context for function
9494
// CHECK-SAME: @"$s18opaque_result_typeMXM"
9595
// -- mangled underlying type
@@ -102,15 +102,15 @@ func bar(y: C) -> __opaque Q {
102102
}
103103

104104
// CHECK-LABEL: @"$s18opaque_result_type3baz1zQrx_tAA1PRzAA1QRzlFQOMQ" = {{.*}} constant <{ {{.*}} }> <{
105-
// -- header: opaque type context (0x4), generic (0x80), unique (0x40), underlying type ordinal 1 (0x1_0000)
106-
// CHECK-SAME: <i32 0x1_00c4>
105+
// -- header: opaque type context (0x4), generic (0x80), unique (0x40), three entries (0x3_0000)
106+
// CHECK-SAME: <i32 0x3_00c4>
107107
// -- parent context: anon context for function
108108
// CHECK-SAME: @"$s18opaque_result_type3baz1zQrx_tAA1PRzAA1QRzlFMXX"
109109
// -- mangled underlying type
110110
// CHECK-SAME: @"symbolic x"
111-
// -- conformance to P (todo)
111+
// -- conformance to P
112112
// CHECK-SAME: @"get_witness_table 18opaque_result_type1PRzAA1QRzlxAaB
113-
// -- conformance to Q (todo)
113+
// -- conformance to Q
114114
// CHECK-SAME: @"get_witness_table 18opaque_result_type1PRzAA1QRzlxAaC
115115
// CHECK-SAME: }>
116116
func baz<T: P & Q>(z: T) -> __opaque P & Q {

0 commit comments

Comments
 (0)