@@ -2560,7 +2560,8 @@ emitKeyPathRValueBase(SILGenFunction &subSGF,
2560
2560
return paramSubstValue;
2561
2561
}
2562
2562
2563
- using IndexTypePair = std::pair<CanType, SILType>;
2563
+ // / formal, lowered, isVariadic
2564
+ using IndexTypeTuple = std::tuple<CanType, SILType, bool >;
2564
2565
2565
2566
// / Helper function to load the captured indexes out of a key path component
2566
2567
// / in order to invoke the accessors on that key path. A component with captured
@@ -2570,7 +2571,7 @@ using IndexTypePair = std::pair<CanType, SILType>;
2570
2571
static PreparedArguments
2571
2572
loadIndexValuesForKeyPathComponent (SILGenFunction &SGF, SILLocation loc,
2572
2573
AbstractStorageDecl *storage,
2573
- ArrayRef<IndexTypePair > indexes,
2574
+ ArrayRef<IndexTypeTuple > indexes,
2574
2575
SILValue pointer) {
2575
2576
// If not a subscript, do nothing.
2576
2577
if (!isa<SubscriptDecl>(storage))
@@ -2579,7 +2580,7 @@ loadIndexValuesForKeyPathComponent(SILGenFunction &SGF, SILLocation loc,
2579
2580
SmallVector<AnyFunctionType::Param, 8 > indexParams;
2580
2581
for (auto &elt : indexes) {
2581
2582
// FIXME: Varargs?
2582
- indexParams.emplace_back (SGF.F .mapTypeIntoContext (elt. first ));
2583
+ indexParams.emplace_back (SGF.F .mapTypeIntoContext (std::get< 0 >( elt) ));
2583
2584
}
2584
2585
2585
2586
PreparedArguments indexValues (indexParams);
@@ -2602,12 +2603,12 @@ loadIndexValuesForKeyPathComponent(SILGenFunction &SGF, SILLocation loc,
2602
2603
if (indexes.size () > 1 ) {
2603
2604
eltAddr = SGF.B .createTupleElementAddr (loc, eltAddr, i);
2604
2605
}
2605
- auto ty = SGF.F .mapTypeIntoContext (indexes[i]. second );
2606
+ auto ty = SGF.F .mapTypeIntoContext (std::get< 1 >( indexes[i]) );
2606
2607
auto value = SGF.emitLoad (loc, eltAddr,
2607
2608
SGF.getTypeLowering (ty),
2608
2609
SGFContext (), IsNotTake);
2609
2610
auto substType =
2610
- SGF.F .mapTypeIntoContext (indexes[i]. first )->getCanonicalType ();
2611
+ SGF.F .mapTypeIntoContext (std::get< 0 >( indexes[i]) )->getCanonicalType ();
2611
2612
indexValues.add (loc, RValue (SGF, loc, substType, value));
2612
2613
}
2613
2614
@@ -2629,7 +2630,7 @@ static SILFunction *getOrCreateKeyPathGetter(SILGenModule &SGM,
2629
2630
SubstitutionMap subs,
2630
2631
GenericEnvironment *genericEnv,
2631
2632
ResilienceExpansion expansion,
2632
- ArrayRef<IndexTypePair > indexes,
2633
+ ArrayRef<IndexTypeTuple > indexes,
2633
2634
CanType baseType,
2634
2635
CanType propertyType) {
2635
2636
// If the storage declaration is from a protocol, chase the override chain
@@ -2767,7 +2768,7 @@ static SILFunction *getOrCreateKeyPathSetter(SILGenModule &SGM,
2767
2768
SubstitutionMap subs,
2768
2769
GenericEnvironment *genericEnv,
2769
2770
ResilienceExpansion expansion,
2770
- ArrayRef<IndexTypePair > indexes,
2771
+ ArrayRef<IndexTypeTuple > indexes,
2771
2772
CanType baseType,
2772
2773
CanType propertyType) {
2773
2774
// If the storage declaration is from a protocol, chase the override chain
@@ -3310,7 +3311,7 @@ getIdForKeyPathComponentComputedProperty(SILGenModule &SGM,
3310
3311
static void
3311
3312
lowerKeyPathSubscriptIndexTypes (
3312
3313
SILGenModule &SGM,
3313
- SmallVectorImpl<IndexTypePair > &indexPatterns,
3314
+ SmallVectorImpl<IndexTypeTuple > &indexPatterns,
3314
3315
SubscriptDecl *subscript,
3315
3316
SubstitutionMap subscriptSubs,
3316
3317
ResilienceExpansion expansion,
@@ -3337,22 +3338,23 @@ lowerKeyPathSubscriptIndexTypes(
3337
3338
indexLoweredTy = indexLoweredTy.mapTypeOutOfContext ();
3338
3339
indexPatterns.push_back ({indexTy->mapTypeOutOfContext ()
3339
3340
->getCanonicalType (),
3340
- indexLoweredTy});
3341
+ indexLoweredTy, index-> isVariadic () });
3341
3342
}
3342
3343
};
3343
3344
3344
3345
static void lowerKeyPathSubscriptEqualsIndexPatterns (
3345
3346
SmallVectorImpl<KeyPathPatternComponent::Index> &indexPatterns,
3346
- ArrayRef<IndexTypePair > indexTypes,
3347
+ ArrayRef<IndexTypeTuple > indexTypes,
3347
3348
ArrayRef<ProtocolConformanceRef> indexHashables, unsigned baseOperand,
3348
3349
SILGenModule &SGM, ResilienceExpansion expansion) {
3349
3350
for (unsigned i : indices (indexTypes)) {
3350
3351
CanType formalTy;
3351
3352
SILType loweredTy;
3352
- std::tie (formalTy, loweredTy) = indexTypes[i];
3353
+ bool isVariadic;
3354
+ std::tie (formalTy, loweredTy, isVariadic) = indexTypes[i];
3353
3355
auto hashable = indexHashables[i].mapConformanceOutOfContext ();
3354
3356
// We have an array of variadic parameters...
3355
- if (!hashable. getConcrete ()-> getType ()-> isEqual (formalTy) ) {
3357
+ if (isVariadic ) {
3356
3358
// Use the element type instead of the array type for hash/equals.
3357
3359
auto arrayTy = cast<BoundGenericStructType>(formalTy.getPointer ());
3358
3360
auto elementTy = arrayTy->getGenericArgs ()[0 ];
@@ -3384,12 +3386,13 @@ static void lowerKeyPathSubscriptEqualsIndexPatterns(
3384
3386
3385
3387
static void lowerKeyPathSubscriptIndexPatterns (
3386
3388
SmallVectorImpl<KeyPathPatternComponent::Index> &indexPatterns,
3387
- ArrayRef<IndexTypePair > indexTypes,
3389
+ ArrayRef<IndexTypeTuple > indexTypes,
3388
3390
ArrayRef<ProtocolConformanceRef> indexHashables, unsigned &baseOperand) {
3389
3391
for (unsigned i : indices (indexTypes)) {
3390
3392
CanType formalTy;
3391
3393
SILType loweredTy;
3392
- std::tie (formalTy, loweredTy) = indexTypes[i];
3394
+ bool isVariadic;
3395
+ std::tie (formalTy, loweredTy, isVariadic) = indexTypes[i];
3393
3396
auto hashable = indexHashables[i].mapConformanceOutOfContext ();
3394
3397
3395
3398
indexPatterns.push_back ({baseOperand++, formalTy, loweredTy, hashable});
@@ -3531,7 +3534,7 @@ SILGenModule::emitKeyPathComponentForDecl(SILLocation loc,
3531
3534
baseSubscriptTy->mapTypeOutOfContext ()->getCanonicalType ());
3532
3535
auto componentTy = baseSubscriptInterfaceTy.getResult ();
3533
3536
3534
- SmallVector<IndexTypePair , 4 > indexTypes;
3537
+ SmallVector<IndexTypeTuple , 4 > indexTypes;
3535
3538
lowerKeyPathSubscriptIndexTypes (*this , indexTypes,
3536
3539
decl, subs,
3537
3540
expansion,
0 commit comments