@@ -3166,83 +3166,60 @@ getOrCreateKeyPathEqualsAndHash(SILGenModule &SGM,
3166
3166
auto entry = hash->begin ();
3167
3167
auto indexPtr = entry->createFunctionArgument (params[0 ].getSILStorageType ());
3168
3168
3169
- Scope scope (subSGF, loc);
3170
-
3171
- auto hashMethod = cast<VarDecl>(
3172
- hashableProto->lookupDirect (C.Id_hashValue )[0 ])
3173
- ->getGetter ();
3174
- auto hashRef = SILDeclRef (hashMethod);
3175
- auto hashTy = subSGF.SGM .Types .getConstantType (hashRef);
3176
-
3177
3169
SILValue hashCode;
3178
3170
3171
+ // For now, just use the hash value of the first index.
3179
3172
// TODO: Combine hashes of the indexes using an inout Hasher
3180
3173
{
3174
+ ArgumentScope scope (subSGF, loc);
3175
+
3181
3176
auto &index = indexes[0 ];
3182
3177
3178
+ // Extract the index value.
3183
3179
SILValue indexAddr = subSGF.B .createPointerToAddress (loc, indexPtr,
3184
3180
indexLoweredTy.getAddressType (),
3185
3181
/* isStrict*/ false );
3186
3182
if (indexes.size () > 1 ) {
3187
3183
indexAddr = subSGF.B .createTupleElementAddr (loc, indexAddr, 0 );
3188
3184
}
3189
-
3185
+
3186
+ VarDecl *hashValueVar =
3187
+ cast<VarDecl>(hashableProto->lookupDirect (C.Id_hashValue )[0 ]);
3188
+
3190
3189
auto formalTy = index.FormalType ;
3191
3190
auto hashable = index.Hashable ;
3192
- SubstitutionMap hashableSubsMap;
3193
3191
if (genericEnv) {
3194
3192
formalTy = genericEnv->mapTypeIntoContext (formalTy)->getCanonicalType ();
3195
3193
hashable = hashable.subst (index.FormalType ,
3196
3194
[&](Type t) -> Type { return genericEnv->mapTypeIntoContext (t); },
3197
3195
LookUpConformanceInSignature (*genericSig));
3198
3196
}
3199
3197
3200
- if (auto genericSig =
3201
- hashTy.castTo <SILFunctionType>()->getGenericSignature ()) {
3202
- hashableSubsMap = SubstitutionMap::get (
3203
- genericSig,
3198
+ // Set up a substitution of Self => IndexType.
3199
+ auto hashGenericSig =
3200
+ hashValueVar->getDeclContext ()->getGenericSignatureOfContext ();
3201
+ assert (hashGenericSig);
3202
+ SubstitutionMap hashableSubsMap = SubstitutionMap::get (
3203
+ hashGenericSig,
3204
3204
[&](SubstitutableType *type) -> Type { return formalTy; },
3205
3205
[&](CanType dependentType, Type replacementType,
3206
3206
ProtocolDecl *proto)->Optional <ProtocolConformanceRef> {
3207
3207
return hashable;
3208
3208
});
3209
- }
3210
-
3211
- auto hashWitness = subSGF.B .createWitnessMethod (loc,
3212
- formalTy, hashable,
3213
- hashRef, hashTy);
3214
3209
3215
- auto hashSubstTy = hashTy.castTo <SILFunctionType>()
3216
- ->substGenericArgs (SGM.M , hashableSubsMap);
3217
- auto hashInfo = CalleeTypeInfo (hashSubstTy,
3218
- AbstractionPattern (intTy), intTy,
3219
- None,
3220
- ImportAsMemberStatus ());
3221
-
3222
- auto arg = subSGF.emitLoad (loc, indexAddr,
3223
- subSGF.getTypeLowering (AbstractionPattern::getOpaque (), formalTy),
3224
- SGFContext (), IsNotTake);
3225
-
3226
- if (!arg.getType ().isAddress ()) {
3227
- auto buf = subSGF.emitTemporaryAllocation (loc, arg.getType ());
3228
- arg.forwardInto (subSGF, loc, buf);
3229
- arg = subSGF.emitManagedBufferWithCleanup (buf);
3230
- }
3231
-
3232
- {
3233
- auto hashResultPlan = ResultPlanBuilder::computeResultPlan (subSGF,
3234
- hashInfo, loc, SGFContext ());
3235
- ArgumentScope argScope (subSGF, loc);
3236
- hashCode =
3237
- subSGF
3238
- .emitApply (std::move (hashResultPlan), std::move (argScope), loc,
3239
- ManagedValue::forUnmanaged (hashWitness),
3240
- hashableSubsMap,
3241
- {arg}, hashInfo, ApplyOptions::None, SGFContext ())
3242
- .getUnmanagedSingleValue (subSGF, loc);
3243
- }
3210
+ // Read the storage.
3211
+ ManagedValue base = ManagedValue::forBorrowedAddressRValue (indexAddr);
3212
+ hashCode =
3213
+ subSGF.emitRValueForStorageLoad (loc, base, formalTy, /* super*/ false ,
3214
+ hashValueVar, PreparedArguments (),
3215
+ hashableSubsMap,
3216
+ AccessSemantics::Ordinary,
3217
+ intTy, SGFContext ())
3218
+ .getUnmanagedSingleValue (subSGF, loc);
3219
+
3220
+ scope.pop ();
3244
3221
}
3245
- scope. pop ();
3222
+
3246
3223
subSGF.B .createReturn (loc, hashCode);
3247
3224
}();
3248
3225
0 commit comments