@@ -3433,7 +3433,7 @@ getOrCreateKeyPathEqualsAndHash(SILGenModule &SGM,
3433
3433
auto indexLoweredTy = SGM.Types .getLoweredType (indexTupleTy);
3434
3434
// Get or create the equals witness
3435
3435
[&unsafeRawPointerTy, &boolTy, &genericSig, &C, &indexTypes, &equals, &loc,
3436
- &SGM, &genericEnv, &indexLoweredTy, &hashableProto, & indexes]{
3436
+ &SGM, &genericEnv, &indexLoweredTy, &indexes]{
3437
3437
// (RawPointer, RawPointer) -> Bool
3438
3438
SmallVector<SILParameterInfo, 2 > params;
3439
3439
params.push_back ({unsafeRawPointerTy,
@@ -3448,7 +3448,7 @@ getOrCreateKeyPathEqualsAndHash(SILGenModule &SGM,
3448
3448
SILFunctionType::ExtInfo (SILFunctionType::Representation::Thin,
3449
3449
/* pseudogeneric*/ false ,
3450
3450
/* noescape*/ false ),
3451
- SILCoroutineKind::None,
3451
+ SILCoroutineKind::None,
3452
3452
ParameterConvention::Direct_Unowned,
3453
3453
params, /* yields*/ {}, results, None, C);
3454
3454
@@ -3486,42 +3486,37 @@ getOrCreateKeyPathEqualsAndHash(SILGenModule &SGM,
3486
3486
auto equalsRef = SILDeclRef (equalsMethod);
3487
3487
auto equalsTy = subSGF.SGM .Types .getConstantType (equalsRef);
3488
3488
3489
- auto hashableSig = C.getExistentialSignature (
3490
- hashableProto->getDeclaredType ()->getCanonicalType (),
3491
- SGM.M .getSwiftModule ());
3492
-
3493
3489
auto isFalseBB = subSGF.createBasicBlock ();
3494
3490
auto i1Ty = SILType::getBuiltinIntegerType (1 , C);
3495
3491
for (unsigned i : indices (indexes)) {
3496
3492
auto &index = indexes[i];
3497
3493
3498
- auto formalTy = index.FormalType ;
3499
- auto hashable = index.Hashable ;
3500
- if (genericEnv) {
3501
- formalTy = genericEnv->mapTypeIntoContext (formalTy)->getCanonicalType ();
3502
- hashable = hashable.subst (index.FormalType ,
3503
- [&](Type t) -> Type { return genericEnv->mapTypeIntoContext (t); },
3504
- LookUpConformanceInSignature (*genericSig));
3505
- }
3494
+ Type formalTy = index.FormalType ;
3495
+ ProtocolConformanceRef hashable = index.Hashable ;
3496
+ std::tie (formalTy, hashable)
3497
+ = GenericEnvironment::mapConformanceRefIntoContext (genericEnv,
3498
+ formalTy,
3499
+ hashable);
3500
+ auto formalCanTy = formalTy->getCanonicalType (genericSig);
3506
3501
3507
- // Get the Equatable conformance from the Hashable conformance
3508
- auto subMap = hashableSig->getSubstitutionMap (
3509
- Substitution (formalTy, hashable));
3510
- auto equatable = *subMap
3511
- .lookupConformance (CanType (hashableSig->getGenericParams ()[0 ]),
3512
- equatableProtocol);
3502
+ // Get the Equatable conformance from the Hashable conformance.
3503
+ auto equatable = hashable.getAssociatedConformance (formalTy,
3504
+ GenericTypeParamType::get (0 , 0 , C),
3505
+ equatableProtocol);
3513
3506
3514
3507
assert (equatable.isAbstract () == hashable.isAbstract ());
3515
3508
if (equatable.isConcrete ())
3516
3509
assert (equatable.getConcrete ()->getType ()->isEqual (
3517
3510
hashable.getConcrete ()->getType ()));
3518
- auto equatableSub = Substitution (formalTy,
3519
- C.AllocateCopy (ArrayRef<ProtocolConformanceRef>(equatable)));
3520
3511
3521
3512
auto equalsWitness = subSGF.B .createWitnessMethod (loc,
3522
- formalTy , equatable,
3513
+ formalCanTy , equatable,
3523
3514
equalsRef, equalsTy);
3524
3515
3516
+ auto equatableSub
3517
+ = SubstitutionMap::getProtocolSubstitutions (equatableProtocol,
3518
+ formalCanTy,
3519
+ equatable);
3525
3520
auto equalsSubstTy = equalsTy.castTo <SILFunctionType>()
3526
3521
->substGenericArgs (SGM.M , equatableSub);
3527
3522
auto equalsInfo = CalleeTypeInfo (equalsSubstTy,
@@ -3554,7 +3549,7 @@ getOrCreateKeyPathEqualsAndHash(SILGenModule &SGM,
3554
3549
rhsArg = subSGF.emitManagedBufferWithCleanup (rhsBuf);
3555
3550
}
3556
3551
3557
- auto metaty = CanMetatypeType::get (formalTy ,
3552
+ auto metaty = CanMetatypeType::get (formalCanTy ,
3558
3553
MetatypeRepresentation::Thick);
3559
3554
auto metatyValue = ManagedValue::forUnmanaged (subSGF.B .createMetatype (loc,
3560
3555
SILType::getPrimitiveObjectType (metaty)));
@@ -3564,14 +3559,17 @@ getOrCreateKeyPathEqualsAndHash(SILGenModule &SGM,
3564
3559
equalsInfo, loc, SGFContext ());
3565
3560
ArgumentScope argScope (subSGF, loc);
3566
3561
PostponedCleanup postpone (subSGF);
3567
- isEqual =
3568
- subSGF
3569
- .emitApply (std::move (equalsResultPlan), std::move (argScope),
3570
- loc, ManagedValue::forUnmanaged (equalsWitness),
3571
- equatableSub, {lhsArg, rhsArg, metatyValue},
3572
- equalsInfo, ApplyOptions::None, SGFContext (),
3573
- postpone)
3574
- .getUnmanagedSingleValue (subSGF, loc);
3562
+ SmallVector<Substitution, 1 > equatableSubListBuf;
3563
+ equatableProtocol->getGenericSignature ()
3564
+ ->getSubstitutions (equatableSub, equatableSubListBuf);
3565
+ isEqual = subSGF
3566
+ .emitApply (std::move (equalsResultPlan), std::move (argScope),
3567
+ loc, ManagedValue::forUnmanaged (equalsWitness),
3568
+ C.AllocateCopy (equatableSubListBuf),
3569
+ {lhsArg, rhsArg, metatyValue},
3570
+ equalsInfo, ApplyOptions::None, SGFContext (),
3571
+ postpone)
3572
+ .getUnmanagedSingleValue (subSGF, loc);
3575
3573
}
3576
3574
3577
3575
branchScope.pop ();
0 commit comments