Skip to content

Commit b3eee4c

Browse files
Merge pull request #4208 from aschwaighofer/irgen_fix_associatedtype_accessor_fn
Fix IRGen for associated type witness accessor functions
2 parents 96f8938 + 390c1a4 commit b3eee4c

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

lib/IRGen/GenProto.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -995,6 +995,10 @@ getWitnessTableLazyAccessFunction(IRGenModule &IGM,
995995
return accessor;
996996
}
997997

998+
static void bindArchetypeAccessPaths(IRGenFunction &IGF,
999+
GenericSignature *Generics,
1000+
GetTypeParameterInContextFn getInContext);
1001+
9981002
namespace {
9991003

10001004
/// Conformance info for a witness table that can be directly generated.
@@ -1276,6 +1280,17 @@ class AccessorConformanceInfo : public ConformanceInfo {
12761280
}
12771281
return *Fulfillments;
12781282
}
1283+
1284+
void bindArchetypeAccessPathsInConformance(IRGenFunction &IGF) {
1285+
auto declCtx = Conformance.getDeclContext();
1286+
if (auto generics = declCtx->getGenericSignatureOfContext()) {
1287+
auto getInContext = [&](CanType type) -> CanType {
1288+
return ArchetypeBuilder::mapTypeIntoContext(declCtx, type, nullptr)
1289+
->getCanonicalType();
1290+
};
1291+
bindArchetypeAccessPaths(IGF, generics, getInContext);
1292+
}
1293+
}
12791294
};
12801295
}
12811296

@@ -1335,6 +1350,9 @@ getAssociatedTypeMetadataAccessFunction(AssociatedTypeDecl *requirement,
13351350
// Bind local type data from the metadata argument.
13361351
IGF.bindLocalTypeDataFromTypeMetadata(ConcreteType, IsExact, self);
13371352

1353+
// Bind archetype access paths.
1354+
bindArchetypeAccessPathsInConformance(IGF);
1355+
13381356
// For now, assume that an associated type is cheap enough to access
13391357
// that it doesn't need a new cache entry.
13401358
if (auto archetype = dyn_cast<ArchetypeType>(associatedType)) {
@@ -1458,6 +1476,9 @@ getAssociatedTypeWitnessTableAccessFunction(AssociatedTypeDecl *requirement,
14581476
associatedTypeMetadata);
14591477
IGF.bindLocalTypeDataFromTypeMetadata(ConcreteType, IsExact, self);
14601478

1479+
// Bind archetype access paths.
1480+
bindArchetypeAccessPathsInConformance(IGF);
1481+
14611482
// For now, assume that finding an abstract conformance is always
14621483
// fast enough that it's not worth caching.
14631484
// TODO: provide an API to find the best metadata path to the conformance

test/IRGen/same_type_constraints.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,14 @@ public class C1<T: Equatable> { }
2222
public class C2<T: Equatable, U: P where T == U.Foo>: C1<T> {}
2323

2424
// CHECK: define{{( protected)?}} void @_TFC21same_type_constraints2C1D
25+
26+
public protocol DataType {}
27+
28+
public protocol E {
29+
associatedtype Data: DataType
30+
}
31+
32+
public class GenericKlazz<T: DataType, R: E> : E where R.Data == T
33+
{
34+
public typealias Data = T
35+
}

0 commit comments

Comments
 (0)