@@ -2560,8 +2560,7 @@ emitKeyPathRValueBase(SILGenFunction &subSGF,
2560
2560
return paramSubstValue;
2561
2561
}
2562
2562
2563
- // / formal, lowered, isVariadic
2564
- using IndexTypeTuple = std::tuple<CanType, SILType, bool >;
2563
+ using IndexTypePair = std::pair<CanType, SILType>;
2565
2564
2566
2565
// / Helper function to load the captured indexes out of a key path component
2567
2566
// / in order to invoke the accessors on that key path. A component with captured
@@ -2571,7 +2570,7 @@ using IndexTypeTuple = std::tuple<CanType, SILType, bool>;
2571
2570
static PreparedArguments
2572
2571
loadIndexValuesForKeyPathComponent (SILGenFunction &SGF, SILLocation loc,
2573
2572
AbstractStorageDecl *storage,
2574
- ArrayRef<IndexTypeTuple > indexes,
2573
+ ArrayRef<IndexTypePair > indexes,
2575
2574
SILValue pointer) {
2576
2575
// If not a subscript, do nothing.
2577
2576
if (!isa<SubscriptDecl>(storage))
@@ -2580,7 +2579,7 @@ loadIndexValuesForKeyPathComponent(SILGenFunction &SGF, SILLocation loc,
2580
2579
SmallVector<AnyFunctionType::Param, 8 > indexParams;
2581
2580
for (auto &elt : indexes) {
2582
2581
// FIXME: Varargs?
2583
- indexParams.emplace_back (SGF.F .mapTypeIntoContext (std::get< 0 >( elt) ));
2582
+ indexParams.emplace_back (SGF.F .mapTypeIntoContext (elt. first ));
2584
2583
}
2585
2584
2586
2585
PreparedArguments indexValues (indexParams);
@@ -2603,12 +2602,12 @@ loadIndexValuesForKeyPathComponent(SILGenFunction &SGF, SILLocation loc,
2603
2602
if (indexes.size () > 1 ) {
2604
2603
eltAddr = SGF.B .createTupleElementAddr (loc, eltAddr, i);
2605
2604
}
2606
- auto ty = SGF.F .mapTypeIntoContext (std::get< 1 >( indexes[i]) );
2605
+ auto ty = SGF.F .mapTypeIntoContext (indexes[i]. second );
2607
2606
auto value = SGF.emitLoad (loc, eltAddr,
2608
2607
SGF.getTypeLowering (ty),
2609
2608
SGFContext (), IsNotTake);
2610
2609
auto substType =
2611
- SGF.F .mapTypeIntoContext (std::get< 0 >( indexes[i]) )->getCanonicalType ();
2610
+ SGF.F .mapTypeIntoContext (indexes[i]. first )->getCanonicalType ();
2612
2611
indexValues.add (loc, RValue (SGF, loc, substType, value));
2613
2612
}
2614
2613
@@ -2630,7 +2629,7 @@ static SILFunction *getOrCreateKeyPathGetter(SILGenModule &SGM,
2630
2629
SubstitutionMap subs,
2631
2630
GenericEnvironment *genericEnv,
2632
2631
ResilienceExpansion expansion,
2633
- ArrayRef<IndexTypeTuple > indexes,
2632
+ ArrayRef<IndexTypePair > indexes,
2634
2633
CanType baseType,
2635
2634
CanType propertyType) {
2636
2635
// If the storage declaration is from a protocol, chase the override chain
@@ -2768,7 +2767,7 @@ static SILFunction *getOrCreateKeyPathSetter(SILGenModule &SGM,
2768
2767
SubstitutionMap subs,
2769
2768
GenericEnvironment *genericEnv,
2770
2769
ResilienceExpansion expansion,
2771
- ArrayRef<IndexTypeTuple > indexes,
2770
+ ArrayRef<IndexTypePair > indexes,
2772
2771
CanType baseType,
2773
2772
CanType propertyType) {
2774
2773
// If the storage declaration is from a protocol, chase the override chain
@@ -3311,7 +3310,7 @@ getIdForKeyPathComponentComputedProperty(SILGenModule &SGM,
3311
3310
static void
3312
3311
lowerKeyPathSubscriptIndexTypes (
3313
3312
SILGenModule &SGM,
3314
- SmallVectorImpl<IndexTypeTuple > &indexPatterns,
3313
+ SmallVectorImpl<IndexTypePair > &indexPatterns,
3315
3314
SubscriptDecl *subscript,
3316
3315
SubstitutionMap subscriptSubs,
3317
3316
ResilienceExpansion expansion,
@@ -3338,67 +3337,28 @@ lowerKeyPathSubscriptIndexTypes(
3338
3337
indexLoweredTy = indexLoweredTy.mapTypeOutOfContext ();
3339
3338
indexPatterns.push_back ({indexTy->mapTypeOutOfContext ()
3340
3339
->getCanonicalType (),
3341
- indexLoweredTy, index-> isVariadic () });
3340
+ indexLoweredTy});
3342
3341
}
3343
3342
};
3344
3343
3345
- static void lowerKeyPathSubscriptEqualsIndexPatterns (
3346
- SmallVectorImpl<KeyPathPatternComponent::Index> &indexPatterns,
3347
- ArrayRef<IndexTypeTuple> indexTypes,
3348
- ArrayRef<ProtocolConformanceRef> indexHashables, unsigned baseOperand,
3349
- SILGenModule &SGM, ResilienceExpansion expansion) {
3344
+ static void
3345
+ lowerKeyPathSubscriptIndexPatterns (
3346
+ SmallVectorImpl<KeyPathPatternComponent::Index> &indexPatterns,
3347
+ ArrayRef<IndexTypePair> indexTypes,
3348
+ ArrayRef<ProtocolConformanceRef> indexHashables,
3349
+ unsigned &baseOperand) {
3350
3350
for (unsigned i : indices (indexTypes)) {
3351
3351
CanType formalTy;
3352
3352
SILType loweredTy;
3353
- bool isVariadic;
3354
- std::tie (formalTy, loweredTy, isVariadic) = indexTypes[i];
3353
+ std::tie (formalTy, loweredTy) = indexTypes[i];
3355
3354
auto hashable = indexHashables[i].mapConformanceOutOfContext ();
3356
- // We have an array of variadic parameters...
3357
- if (isVariadic) {
3358
- // Use the element type instead of the array type for hash/equals.
3359
- auto arrayTy = cast<BoundGenericStructType>(formalTy.getPointer ());
3360
- auto elementTy = arrayTy->getGenericArgs ()[0 ];
3361
-
3362
- // Make sure that we aren't leaving out any hashables.
3363
- assert (indexTypes.size () == indexHashables.size ());
3364
-
3365
- // Make sure the element type matches the hashable.
3366
- assert (hashable.getConcrete ()->getType ()->isEqual (elementTy));
3367
- auto newLoweredTy = SGM.Types .getLoweredType (
3368
- AbstractionPattern::getOpaque (), elementTy,
3369
- TypeExpansionContext::noOpaqueTypeArchetypesSubstitution (expansion));
3370
- newLoweredTy = newLoweredTy.mapTypeOutOfContext ();
3371
- auto newFormalTy = elementTy->mapTypeOutOfContext ()->getCanonicalType ();
3372
-
3373
- indexPatterns.push_back (
3374
- {baseOperand++, newFormalTy, newLoweredTy, hashable});
3375
-
3376
- // We're done because variadics must come last.
3377
- break ;
3378
- }
3379
-
3380
3355
assert (hashable.isAbstract () ||
3381
3356
hashable.getConcrete ()->getType ()->isEqual (formalTy));
3382
3357
3383
3358
indexPatterns.push_back ({baseOperand++, formalTy, loweredTy, hashable});
3384
3359
}
3385
3360
};
3386
3361
3387
- static void lowerKeyPathSubscriptIndexPatterns (
3388
- SmallVectorImpl<KeyPathPatternComponent::Index> &indexPatterns,
3389
- ArrayRef<IndexTypeTuple> indexTypes,
3390
- ArrayRef<ProtocolConformanceRef> indexHashables, unsigned &baseOperand) {
3391
- for (unsigned i : indices (indexTypes)) {
3392
- CanType formalTy;
3393
- SILType loweredTy;
3394
- bool isVariadic;
3395
- std::tie (formalTy, loweredTy, isVariadic) = indexTypes[i];
3396
- auto hashable = indexHashables[i].mapConformanceOutOfContext ();
3397
-
3398
- indexPatterns.push_back ({baseOperand++, formalTy, loweredTy, hashable});
3399
- }
3400
- };
3401
-
3402
3362
KeyPathPatternComponent
3403
3363
SILGenModule::emitKeyPathComponentForDecl (SILLocation loc,
3404
3364
GenericEnvironment *genericEnv,
@@ -3534,29 +3494,25 @@ SILGenModule::emitKeyPathComponentForDecl(SILLocation loc,
3534
3494
baseSubscriptTy->mapTypeOutOfContext ()->getCanonicalType ());
3535
3495
auto componentTy = baseSubscriptInterfaceTy.getResult ();
3536
3496
3537
- SmallVector<IndexTypeTuple , 4 > indexTypes;
3497
+ SmallVector<IndexTypePair , 4 > indexTypes;
3538
3498
lowerKeyPathSubscriptIndexTypes (*this , indexTypes,
3539
3499
decl, subs,
3540
3500
expansion,
3541
3501
needsGenericContext);
3542
-
3543
- SmallVector<KeyPathPatternComponent::Index, 4 > equalsIndexPatterns;
3502
+
3544
3503
SmallVector<KeyPathPatternComponent::Index, 4 > indexPatterns;
3545
3504
SILFunction *indexEquals = nullptr , *indexHash = nullptr ;
3546
3505
// Property descriptors get their index information from the client.
3547
3506
if (!forPropertyDescriptor) {
3548
- // Gather the index patters that we will use for the component.
3549
- lowerKeyPathSubscriptEqualsIndexPatterns (equalsIndexPatterns, indexTypes,
3550
- indexHashables, baseOperand,
3551
- *this , expansion);
3552
- // Gather the index patterns that we will use for equals and hash.
3553
3507
lowerKeyPathSubscriptIndexPatterns (indexPatterns,
3554
3508
indexTypes, indexHashables,
3555
3509
baseOperand);
3556
-
3557
- getOrCreateKeyPathEqualsAndHash (
3558
- *this , loc, needsGenericContext ? genericEnv : nullptr , expansion,
3559
- equalsIndexPatterns, indexEquals, indexHash);
3510
+
3511
+ getOrCreateKeyPathEqualsAndHash (*this , loc,
3512
+ needsGenericContext ? genericEnv : nullptr ,
3513
+ expansion,
3514
+ indexPatterns,
3515
+ indexEquals, indexHash);
3560
3516
}
3561
3517
3562
3518
auto id = getIdForKeyPathComponentComputedProperty (*this , decl, strategy);
0 commit comments