Skip to content

Commit 99d68ba

Browse files
committed
IRGen: Some progress toward tuple conformances
1 parent 2109051 commit 99d68ba

File tree

7 files changed

+52
-24
lines changed

7 files changed

+52
-24
lines changed

include/swift/SIL/SILWitnessTable.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -238,12 +238,8 @@ class SILWitnessTable : public llvm::ilist_node<SILWitnessTable>,
238238
/// Return the protocol for which this witness table is a conformance.
239239
ProtocolDecl *getProtocol() const;
240240

241-
/// Return the formal type which conforms to the protocol.
242-
///
243-
/// Note that this will not be a substituted type: it may only be meaningful
244-
/// in the abstract context of the conformance rather than the context of any
245-
/// particular use of it.
246-
CanType getConformingType() const;
241+
/// Return the nominal type declaration which conforms to the protocol.
242+
NominalTypeDecl *getConformingNominal() const;
247243

248244
/// Return the symbol name of the witness table that will be propagated to the
249245
/// object file level.

lib/IRGen/GenDecl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4080,8 +4080,8 @@ void IRGenModule::appendLLVMUsedConditionalEntry(
40804080
auto *protocol = getAddrOfProtocolDescriptor(conformance->getProtocol())
40814081
->stripPointerCasts();
40824082
auto *type = getAddrOfTypeContextDescriptor(
4083-
conformance->getType()->getAnyNominal(), DontRequireMetadata)
4084-
->stripPointerCasts();
4083+
conformance->getDeclContext()->getSelfNominalTypeDecl(),
4084+
DontRequireMetadata)->stripPointerCasts();
40854085

40864086
llvm::Metadata *metadata[] = {
40874087
// (1) which variable is being conditionalized, "target"

lib/IRGen/GenProto.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1984,7 +1984,7 @@ namespace {
19841984
// Add a relative reference to the type, with the type reference
19851985
// kind stored in the flags.
19861986
auto ref = IGM.getTypeEntityReference(
1987-
Conformance->getType()->getAnyNominal());
1987+
Conformance->getDeclContext()->getSelfNominalTypeDecl());
19881988
B.addRelativeAddress(ref.getValue());
19891989
Flags = Flags.withTypeReferenceKind(ref.getKind());
19901990
}
@@ -2474,8 +2474,9 @@ void IRGenModule::emitSILWitnessTable(SILWitnessTable *wt) {
24742474
// Record this conformance descriptor.
24752475
addProtocolConformance(std::move(description));
24762476

2477-
IRGen.noteUseOfTypeContextDescriptor(conf->getType()->getAnyNominal(),
2478-
RequireMetadata);
2477+
IRGen.noteUseOfTypeContextDescriptor(
2478+
conf->getDeclContext()->getSelfNominalTypeDecl(),
2479+
RequireMetadata);
24792480
}
24802481

24812482
/// True if a function's signature in LLVM carries polymorphic parameters.

lib/IRGen/IRGenModule.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,10 +1284,7 @@ bool IRGenerator::canEmitWitnessTableLazily(SILWitnessTable *wt) {
12841284
if (wt->getLinkage() == SILLinkage::Shared)
12851285
return true;
12861286

1287-
NominalTypeDecl *ConformingTy =
1288-
wt->getConformingType()->getNominalOrBoundGenericNominal();
1289-
1290-
switch (ConformingTy->getEffectiveAccess()) {
1287+
switch (wt->getConformingNominal()->getEffectiveAccess()) {
12911288
case AccessLevel::Private:
12921289
case AccessLevel::FilePrivate:
12931290
return true;

lib/IRGen/Linking.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -803,15 +803,15 @@ SILLinkage LinkEntity::getLinkage(ForDefinition_t forDefinition) const {
803803

804804
case Kind::ProtocolWitnessTableLazyAccessFunction:
805805
case Kind::ProtocolWitnessTableLazyCacheVariable: {
806-
auto ty = getType();
807-
ValueDecl *nominal = nullptr;
808-
if (auto *otat = ty->getAs<OpaqueTypeArchetypeType>()) {
809-
nominal = otat->getDecl();
806+
TypeDecl *typeDecl = nullptr;
807+
if (auto *otat = getType()->getAs<OpaqueTypeArchetypeType>()) {
808+
typeDecl = otat->getDecl();
810809
} else {
811-
nominal = ty->getAnyNominal();
810+
typeDecl = getProtocolConformance()->getDeclContext()
811+
->getSelfNominalTypeDecl();
812812
}
813-
assert(nominal);
814-
if (getDeclLinkage(nominal) == FormalLinkage::Private ||
813+
assert(typeDecl);
814+
if (getDeclLinkage(typeDecl) == FormalLinkage::Private ||
815815
getLinkageAsConformance() == SILLinkage::Private) {
816816
return SILLinkage::Private;
817817
} else {

lib/SIL/IR/SILWitnessTable.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ ProtocolDecl *SILWitnessTable::getProtocol() const {
4343
return getConformance()->getProtocol();
4444
}
4545

46-
CanType SILWitnessTable::getConformingType() const {
47-
return getConformance()->getType()->getCanonicalType();
46+
NominalTypeDecl *SILWitnessTable::getConformingNominal() const {
47+
return getConformance()->getDeclContext()->getSelfNominalTypeDecl();
4848
}
4949

5050
void SILWitnessTable::addWitnessTable() {

test/IRGen/tuple_conformances.swift

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// RUN: %target-swift-frontend -emit-ir -parse-stdlib -primary-file %s -enable-experimental-feature TupleConformances -parse-as-library | %FileCheck %s
2+
3+
import Swift
4+
5+
protocol P {
6+
func f()
7+
}
8+
9+
extension P {
10+
func f() {}
11+
}
12+
13+
extension Builtin.TheTupleType: P where repeat each Elements: P {
14+
}
15+
16+
func takesP<T: P>(_ t: T) {
17+
t.f()
18+
}
19+
20+
struct S: P {}
21+
22+
func use() {
23+
takesP((S(), S()))
24+
}
25+
26+
// CHECK-LABEL: define internal swiftcc void @"$sxxQp_t18tuple_conformances1PA2aBP1fyyFTW"({{i32|i64}} %0, ptr %"{{.*}}", ptr {{.*}} swiftself %1, ptr %Self, ptr %SelfWitnessTable) {{.*}} {
27+
28+
// CHECK-LABEL: define hidden swiftcc void @"$s18tuple_conformances3useyyF"() {{.*}} {
29+
// CHECK: call ptr @"$s18tuple_conformances1SV_ACtxxQp_tAA1PAAWl"()
30+
// CHECK: ret void
31+
32+
// CHECK-LABEL: define linkonce_odr hidden ptr @"$s18tuple_conformances1SV_ACtxxQp_tAA1PAAWl"() {{.*}} {
33+
34+

0 commit comments

Comments
 (0)