Skip to content

Commit d727011

Browse files
committed
[SILGen] tweak LogicalKeyPathApplicationComponent
A baked-in assumption was that the generic parameters of the KeyPath family of types have no conformance requirements. That's no longer the case with NoncopyableGenerics, so we need to dig up conformances when forming the substitution map, as-needed.
1 parent 9d6ac1c commit d727011

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

lib/SILGen/SILGenLValue.cpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2320,8 +2320,9 @@ namespace {
23202320

23212321
auto keyPathValue = KeyPath;
23222322

2323-
SmallVector<Type, 2> typeArgs;
2324-
typeArgs.push_back(BaseFormalType);
2323+
GenericSignature sig;
2324+
TypeSubstitutionMap map;
2325+
23252326
if (TypeKind == KPTK_AnyKeyPath) {
23262327
projectFn = SGF.getASTContext().getGetAtAnyKeyPath();
23272328
} else if (TypeKind == KPTK_PartialKeyPath) {
@@ -2330,21 +2331,31 @@ namespace {
23302331
TypeKind == KPTK_WritableKeyPath ||
23312332
TypeKind == KPTK_ReferenceWritableKeyPath) {
23322333
projectFn = SGF.getASTContext().getGetAtKeyPath();
2334+
sig = projectFn->getGenericSignature();
2335+
auto genericParams = sig.getGenericParams();
23332336

23342337
auto keyPathTy = keyPathValue.getType().castTo<BoundGenericType>();
23352338
assert(keyPathTy->getGenericArgs().size() == 2);
23362339
assert(keyPathTy->getGenericArgs()[0]->getCanonicalType() ==
23372340
BaseFormalType->getCanonicalType());
2338-
typeArgs.push_back(keyPathTy->getGenericArgs()[1]);
2341+
assert(genericParams.size() == 2);
2342+
auto secondGenParam = genericParams[1]->getCanonicalType()
2343+
->castTo<SubstitutableType>();
2344+
map[secondGenParam] = keyPathTy->getGenericArgs()[1];
23392345

23402346
keyPathValue = emitUpcastToKeyPath(SGF, loc, TypeKind, keyPathValue);
23412347
} else {
23422348
llvm_unreachable("bad key path kind for this component");
23432349
}
23442350

2345-
auto subs = SubstitutionMap::get(projectFn->getGenericSignature(),
2346-
ArrayRef<Type>(typeArgs),
2347-
ArrayRef<ProtocolConformanceRef>());
2351+
sig = projectFn->getGenericSignature();
2352+
auto firstGenParam = sig.getGenericParams()[0]->getCanonicalType()
2353+
->castTo<SubstitutableType>();
2354+
map[firstGenParam] = BaseFormalType;
2355+
2356+
auto subs = SubstitutionMap::get(sig,
2357+
QueryTypeSubstitutionMap{map},
2358+
LookUpConformanceInModule{SGF.getModule().getSwiftModule()});
23482359

23492360
base = makeBaseConsumableMaterializedRValue(SGF, loc, base);
23502361

0 commit comments

Comments
 (0)