52
52
53
53
#include " swift/AST/DiagnosticsSIL.h"
54
54
55
- #include < iostream>
56
-
57
55
using namespace swift ;
58
56
using namespace Lowering ;
59
57
@@ -3069,11 +3067,6 @@ getOrCreateKeyPathEqualsAndHash(SILGenModule &SGM,
3069
3067
hashable);
3070
3068
auto formalCanTy = formalTy->getCanonicalType (genericSig);
3071
3069
3072
- formalTy.dump ();
3073
- index.FormalType .dump ();
3074
- equatableProtocol->dump ();
3075
- hashable.dump ();
3076
-
3077
3070
// Get the Equatable conformance from the Hashable conformance.
3078
3071
auto equatable = hashable.getAssociatedConformance (formalTy,
3079
3072
GenericTypeParamType::get (0 , 0 , C),
@@ -3348,62 +3341,51 @@ lowerKeyPathSubscriptIndexTypes(
3348
3341
}
3349
3342
};
3350
3343
3351
- static void
3352
- lowerKeyPathSubscriptEqualsIndexPatterns (
3353
- SmallVectorImpl<KeyPathPatternComponent::Index> &indexPatterns,
3354
- ArrayRef<IndexTypePair> indexTypes,
3355
- ArrayRef<ProtocolConformanceRef> indexHashables,
3356
- unsigned baseOperand,
3357
- SILGenModule &SGM,
3358
- ResilienceExpansion expansion) {
3344
+ static void lowerKeyPathSubscriptEqualsIndexPatterns (
3345
+ SmallVectorImpl<KeyPathPatternComponent::Index> &indexPatterns,
3346
+ ArrayRef<IndexTypePair> indexTypes,
3347
+ ArrayRef<ProtocolConformanceRef> indexHashables, unsigned baseOperand,
3348
+ SILGenModule &SGM, ResilienceExpansion expansion) {
3359
3349
for (unsigned i : indices (indexTypes)) {
3360
3350
CanType formalTy;
3361
3351
SILType loweredTy;
3362
3352
std::tie (formalTy, loweredTy) = indexTypes[i];
3363
3353
auto hashable = indexHashables[i].mapConformanceOutOfContext ();
3364
- // TODO: this only works if varaidic parameters must come last
3365
3354
// We have an array of variadic parameters...
3366
3355
if (!hashable.getConcrete ()->getType ()->isEqual (formalTy)) {
3367
- // Add all the hashable types
3356
+ // Use the element type instead of the array type for hash/equals.
3368
3357
auto arrayTy = cast<BoundGenericStructType>(formalTy.getPointer ());
3369
3358
auto elementTy = arrayTy->getGenericArgs ()[0 ];
3370
- // for (unsigned hashableIndex = i; hashableIndex < indexHashables.size(); ++hashableIndex);
3371
-
3359
+
3360
+ // Make sure that we aren't leaving out any hashables.
3372
3361
assert (indexTypes.size () == indexHashables.size ());
3373
-
3362
+
3363
+ // Make sure the element type matches the hashable.
3374
3364
assert (hashable.getConcrete ()->getType ()->isEqual (elementTy));
3375
3365
auto newLoweredTy = SGM.Types .getLoweredType (
3376
3366
AbstractionPattern::getOpaque (), elementTy,
3377
3367
TypeExpansionContext::noOpaqueTypeArchetypesSubstitution (expansion));
3378
3368
newLoweredTy = newLoweredTy.mapTypeOutOfContext ();
3379
- auto newFormalTy = elementTy->mapTypeOutOfContext ()
3380
- ->getCanonicalType ();
3381
-
3382
- std::cout << " lowered variadic arg formal type: " << std::endl;
3383
- newFormalTy.dump ();
3384
- loweredTy.dump ();
3385
-
3386
- indexPatterns.push_back ({baseOperand++, newFormalTy,
3387
- newLoweredTy, hashable});
3369
+ auto newFormalTy = elementTy->mapTypeOutOfContext ()->getCanonicalType ();
3370
+
3371
+ indexPatterns.push_back (
3372
+ {baseOperand++, newFormalTy, newLoweredTy, hashable});
3373
+
3374
+ // We're done because variadics must come last.
3388
3375
break ;
3389
3376
}
3390
- // hashable.dump(); // Int
3391
- // hashable.getConcrete()->getType().dump(); // Int
3392
- // formalTy.dump(); // Array<Int>
3393
- // loweredTy.dump(); // $Array<Int>
3377
+
3394
3378
assert (hashable.isAbstract () ||
3395
3379
hashable.getConcrete ()->getType ()->isEqual (formalTy));
3396
3380
3397
3381
indexPatterns.push_back ({baseOperand++, formalTy, loweredTy, hashable});
3398
3382
}
3399
3383
};
3400
3384
3401
- static void
3402
- lowerKeyPathSubscriptIndexPatterns (
3403
- SmallVectorImpl<KeyPathPatternComponent::Index> &indexPatterns,
3404
- ArrayRef<IndexTypePair> indexTypes,
3405
- ArrayRef<ProtocolConformanceRef> indexHashables,
3406
- unsigned &baseOperand) {
3385
+ static void lowerKeyPathSubscriptIndexPatterns (
3386
+ SmallVectorImpl<KeyPathPatternComponent::Index> &indexPatterns,
3387
+ ArrayRef<IndexTypePair> indexTypes,
3388
+ ArrayRef<ProtocolConformanceRef> indexHashables, unsigned &baseOperand) {
3407
3389
for (unsigned i : indices (indexTypes)) {
3408
3390
CanType formalTy;
3409
3391
SILType loweredTy;
@@ -3554,24 +3536,24 @@ SILGenModule::emitKeyPathComponentForDecl(SILLocation loc,
3554
3536
decl, subs,
3555
3537
expansion,
3556
3538
needsGenericContext);
3557
-
3539
+
3558
3540
SmallVector<KeyPathPatternComponent::Index, 4 > equalsIndexPatterns;
3559
- SmallVector<KeyPathPatternComponent::Index, 4 > xIndexPatterns ;
3541
+ SmallVector<KeyPathPatternComponent::Index, 4 > indexPatterns ;
3560
3542
SILFunction *indexEquals = nullptr , *indexHash = nullptr ;
3561
3543
// Property descriptors get their index information from the client.
3562
3544
if (!forPropertyDescriptor) {
3563
- lowerKeyPathSubscriptEqualsIndexPatterns (equalsIndexPatterns,
3564
- indexTypes, indexHashables,
3565
- baseOperand, *this , expansion);
3566
- lowerKeyPathSubscriptIndexPatterns (xIndexPatterns,
3545
+ // Gather the index patters that we will use for the component.
3546
+ lowerKeyPathSubscriptEqualsIndexPatterns (equalsIndexPatterns, indexTypes,
3547
+ indexHashables, baseOperand,
3548
+ *this , expansion);
3549
+ // Gather the index patterns that we will use for equals and hash.
3550
+ lowerKeyPathSubscriptIndexPatterns (indexPatterns,
3567
3551
indexTypes, indexHashables,
3568
3552
baseOperand);
3569
-
3570
- getOrCreateKeyPathEqualsAndHash (*this , loc,
3571
- needsGenericContext ? genericEnv : nullptr ,
3572
- expansion,
3573
- equalsIndexPatterns,
3574
- indexEquals, indexHash);
3553
+
3554
+ getOrCreateKeyPathEqualsAndHash (
3555
+ *this , loc, needsGenericContext ? genericEnv : nullptr , expansion,
3556
+ equalsIndexPatterns, indexEquals, indexHash);
3575
3557
}
3576
3558
3577
3559
auto id = getIdForKeyPathComponentComputedProperty (*this , decl, strategy);
@@ -3582,7 +3564,7 @@ SILGenModule::emitKeyPathComponentForDecl(SILLocation loc,
3582
3564
indexTypes,
3583
3565
baseTy, componentTy);
3584
3566
3585
- auto indexPatternsCopy = getASTContext ().AllocateCopy (xIndexPatterns );
3567
+ auto indexPatternsCopy = getASTContext ().AllocateCopy (indexPatterns );
3586
3568
if (isSettableInComponent ()) {
3587
3569
auto setter = getOrCreateKeyPathSetter (*this , loc,
3588
3570
decl, subs,
@@ -3599,13 +3581,6 @@ SILGenModule::emitKeyPathComponentForDecl(SILLocation loc,
3599
3581
externalSubs,
3600
3582
componentTy);
3601
3583
} else {
3602
- for (auto &i : indexPatternsCopy) {
3603
- std::cout << " formal type: " << std::endl;
3604
- i.FormalType .dump ();
3605
- std::cout << " lowered type: " << std::endl;
3606
- i.LoweredType .dump ();
3607
- std::cout << std::endl;
3608
- }
3609
3584
return KeyPathPatternComponent::forComputedGettableProperty (id,
3610
3585
getter,
3611
3586
indexPatternsCopy,
@@ -3647,10 +3622,7 @@ RValue RValueEmitter::visitKeyPathExpr(KeyPathExpr *E, SGFContext C) {
3647
3622
case KeyPathExpr::Component::Kind::Property:
3648
3623
case KeyPathExpr::Component::Kind::Subscript: {
3649
3624
auto decl = cast<AbstractStorageDecl>(component.getDeclRef ().getDecl ());
3650
-
3651
- decl->dump ();
3652
- component.getIndexExpr ()->dump ();
3653
-
3625
+
3654
3626
unsigned numOperands = operands.size ();
3655
3627
loweredComponents.push_back (
3656
3628
SGF.SGM .emitKeyPathComponentForDecl (SILLocation (E),
@@ -3673,7 +3645,6 @@ RValue RValueEmitter::visitKeyPathExpr(KeyPathExpr *E, SGFContext C) {
3673
3645
component.getIndexExpr ());
3674
3646
3675
3647
for (auto &arg : loweredArgs) {
3676
- arg.dump ();
3677
3648
operands.push_back (arg.forward (SGF));
3678
3649
}
3679
3650
@@ -3744,9 +3715,6 @@ RValue RValueEmitter::visitKeyPathExpr(KeyPathExpr *E, SGFContext C) {
3744
3715
rootTy, baseTy,
3745
3716
loweredComponents,
3746
3717
objcString);
3747
-
3748
- std::cout << " [pattern] num operands: " << pattern->getNumOperands () << std::endl;
3749
- std::cout << " [operand] num operands: " << operands.size () << std::endl;
3750
3718
auto keyPath = SGF.B .createKeyPath (SILLocation (E), pattern,
3751
3719
needsGenericContext
3752
3720
? SGF.F .getForwardingSubstitutionMap ()
0 commit comments