@@ -3651,16 +3651,19 @@ getOrCreateKeyPathEqualsAndHash(SILGenModule &SGM,
3651
3651
hashable = hashable.subst (index.FormalType ,
3652
3652
[&](Type t) -> Type { return genericEnv->mapTypeIntoContext (t); },
3653
3653
LookUpConformanceInSignature (*genericSig));
3654
+ }
3654
3655
3656
+ if (auto genericSig =
3657
+ hashTy.castTo <SILFunctionType>()->getGenericSignature ()) {
3655
3658
hashableSubsMap =
3656
- genericEnv-> getGenericSignature () ->getSubstitutionMap (
3659
+ genericSig ->getSubstitutionMap (
3657
3660
[&](SubstitutableType *type) -> Type { return formalTy; },
3658
3661
[&](CanType dependentType, Type replacementType,
3659
3662
ProtocolType *protoType)->Optional <ProtocolConformanceRef> {
3660
3663
return hashable;
3661
3664
});
3662
3665
}
3663
-
3666
+
3664
3667
auto hashWitness = subSGF.B .createWitnessMethod (loc,
3665
3668
formalTy, hashable,
3666
3669
hashRef, hashTy);
@@ -4117,25 +4120,25 @@ visitKeyPathApplicationExpr(KeyPathApplicationExpr *E, SGFContext C) {
4117
4120
4118
4121
auto keyPathDecl = E->getKeyPath ()->getType ()->getAnyNominal ();
4119
4122
FuncDecl *projectFn;
4120
- SmallVector<Substitution, 4 > subs;
4121
-
4123
+
4124
+ SmallVector<Type, 2 > replacementTypes;
4122
4125
if (keyPathDecl == SGF.getASTContext ().getAnyKeyPathDecl ()) {
4123
4126
// Invoke projectKeyPathAny with the type of the base value.
4124
4127
// The result is always `Any?`.
4125
4128
projectFn = SGF.getASTContext ().getProjectKeyPathAny (nullptr );
4126
- subs .push_back (Substitution ( E->getBase ()->getType (), {} ));
4129
+ replacementTypes .push_back (E->getBase ()->getType ());
4127
4130
} else {
4128
4131
auto keyPathTy = E->getKeyPath ()->getType ()->castTo <BoundGenericType>();
4129
4132
if (keyPathDecl == SGF.getASTContext ().getPartialKeyPathDecl ()) {
4130
4133
// Invoke projectKeyPathPartial with the type of the base value.
4131
4134
// The result is always `Any`.
4132
4135
projectFn = SGF.getASTContext ().getProjectKeyPathPartial (nullptr );
4133
- subs .push_back (Substitution ( keyPathTy->getGenericArgs ()[0 ], {}) );
4136
+ replacementTypes .push_back (keyPathTy->getGenericArgs ()[0 ]);
4134
4137
} else {
4135
4138
projectFn = SGF.getASTContext ().getProjectKeyPathReadOnly (nullptr );
4136
4139
// Get the root and leaf type from the key path type.
4137
- subs .push_back (Substitution ( keyPathTy->getGenericArgs ()[0 ], {}) );
4138
- subs .push_back (Substitution ( keyPathTy->getGenericArgs ()[1 ], {}) );
4140
+ replacementTypes .push_back (keyPathTy->getGenericArgs ()[0 ]);
4141
+ replacementTypes .push_back (keyPathTy->getGenericArgs ()[1 ]);
4139
4142
4140
4143
// Upcast the keypath to KeyPath<T, U> if it isn't already.
4141
4144
if (keyPathTy->getDecl () != SGF.getASTContext ().getKeyPathDecl ()) {
@@ -4150,8 +4153,15 @@ visitKeyPathApplicationExpr(KeyPathApplicationExpr *E, SGFContext C) {
4150
4153
}
4151
4154
}
4152
4155
4153
- auto genericArgsMap =
4154
- projectFn->getGenericSignature ()->getSubstitutionMap (subs);
4156
+ auto projectionGenericSig = projectFn->getGenericSignature ();
4157
+ auto genericArgsMap = projectionGenericSig->getSubstitutionMap (
4158
+ [&](SubstitutableType *type) -> Type {
4159
+ auto genericParam = cast<GenericTypeParamType>(type);
4160
+ auto index =
4161
+ projectionGenericSig->getGenericParamOrdinal (genericParam);
4162
+ return replacementTypes[index];
4163
+ },
4164
+ LookUpConformanceInSignature (*projectionGenericSig));
4155
4165
4156
4166
return SGF.emitApplyOfLibraryIntrinsic (SILLocation (E),
4157
4167
projectFn, genericArgsMap, {root, keyPath}, C);
0 commit comments