52
52
53
53
#include " swift/AST/DiagnosticsSIL.h"
54
54
55
+ #include < iostream>
56
+
55
57
using namespace swift ;
56
58
using namespace Lowering ;
57
59
@@ -3067,6 +3069,11 @@ getOrCreateKeyPathEqualsAndHash(SILGenModule &SGM,
3067
3069
hashable);
3068
3070
auto formalCanTy = formalTy->getCanonicalType (genericSig);
3069
3071
3072
+ formalTy.dump ();
3073
+ index.FormalType .dump ();
3074
+ equatableProtocol->dump ();
3075
+ hashable.dump ();
3076
+
3070
3077
// Get the Equatable conformance from the Hashable conformance.
3071
3078
auto equatable = hashable.getAssociatedConformance (formalTy,
3072
3079
GenericTypeParamType::get (0 , 0 , C),
@@ -3342,23 +3349,71 @@ lowerKeyPathSubscriptIndexTypes(
3342
3349
};
3343
3350
3344
3351
static void
3345
- lowerKeyPathSubscriptIndexPatterns (
3352
+ lowerKeyPathSubscriptEqualsIndexPatterns (
3346
3353
SmallVectorImpl<KeyPathPatternComponent::Index> &indexPatterns,
3347
3354
ArrayRef<IndexTypePair> indexTypes,
3348
3355
ArrayRef<ProtocolConformanceRef> indexHashables,
3349
- unsigned &baseOperand) {
3356
+ unsigned baseOperand,
3357
+ SILGenModule &SGM,
3358
+ ResilienceExpansion expansion) {
3350
3359
for (unsigned i : indices (indexTypes)) {
3351
3360
CanType formalTy;
3352
3361
SILType loweredTy;
3353
3362
std::tie (formalTy, loweredTy) = indexTypes[i];
3354
3363
auto hashable = indexHashables[i].mapConformanceOutOfContext ();
3364
+ // TODO: this only works if varaidic parameters must come last
3365
+ // We have an array of variadic parameters...
3366
+ if (!hashable.getConcrete ()->getType ()->isEqual (formalTy)) {
3367
+ // Add all the hashable types
3368
+ auto arrayTy = cast<BoundGenericStructType>(formalTy.getPointer ());
3369
+ auto elementTy = arrayTy->getGenericArgs ()[0 ];
3370
+ // for (unsigned hashableIndex = i; hashableIndex < indexHashables.size(); ++hashableIndex);
3371
+
3372
+ assert (indexTypes.size () == indexHashables.size ());
3373
+
3374
+ assert (hashable.getConcrete ()->getType ()->isEqual (elementTy));
3375
+ auto newLoweredTy = SGM.Types .getLoweredType (
3376
+ AbstractionPattern::getOpaque (), elementTy,
3377
+ TypeExpansionContext::noOpaqueTypeArchetypesSubstitution (expansion));
3378
+ 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});
3388
+ break ;
3389
+ }
3390
+ // hashable.dump(); // Int
3391
+ // hashable.getConcrete()->getType().dump(); // Int
3392
+ // formalTy.dump(); // Array<Int>
3393
+ // loweredTy.dump(); // $Array<Int>
3355
3394
assert (hashable.isAbstract () ||
3356
3395
hashable.getConcrete ()->getType ()->isEqual (formalTy));
3357
3396
3358
3397
indexPatterns.push_back ({baseOperand++, formalTy, loweredTy, hashable});
3359
3398
}
3360
3399
};
3361
3400
3401
+ static void
3402
+ lowerKeyPathSubscriptIndexPatterns (
3403
+ SmallVectorImpl<KeyPathPatternComponent::Index> &indexPatterns,
3404
+ ArrayRef<IndexTypePair> indexTypes,
3405
+ ArrayRef<ProtocolConformanceRef> indexHashables,
3406
+ unsigned &baseOperand) {
3407
+ for (unsigned i : indices (indexTypes)) {
3408
+ CanType formalTy;
3409
+ SILType loweredTy;
3410
+ std::tie (formalTy, loweredTy) = indexTypes[i];
3411
+ auto hashable = indexHashables[i].mapConformanceOutOfContext ();
3412
+
3413
+ indexPatterns.push_back ({baseOperand++, formalTy, loweredTy, hashable});
3414
+ }
3415
+ };
3416
+
3362
3417
KeyPathPatternComponent
3363
3418
SILGenModule::emitKeyPathComponentForDecl (SILLocation loc,
3364
3419
GenericEnvironment *genericEnv,
@@ -3500,18 +3555,22 @@ SILGenModule::emitKeyPathComponentForDecl(SILLocation loc,
3500
3555
expansion,
3501
3556
needsGenericContext);
3502
3557
3503
- SmallVector<KeyPathPatternComponent::Index, 4 > indexPatterns;
3558
+ SmallVector<KeyPathPatternComponent::Index, 4 > equalsIndexPatterns;
3559
+ SmallVector<KeyPathPatternComponent::Index, 4 > xIndexPatterns;
3504
3560
SILFunction *indexEquals = nullptr , *indexHash = nullptr ;
3505
3561
// Property descriptors get their index information from the client.
3506
3562
if (!forPropertyDescriptor) {
3507
- lowerKeyPathSubscriptIndexPatterns (indexPatterns,
3563
+ lowerKeyPathSubscriptEqualsIndexPatterns (equalsIndexPatterns,
3564
+ indexTypes, indexHashables,
3565
+ baseOperand, *this , expansion);
3566
+ lowerKeyPathSubscriptIndexPatterns (xIndexPatterns,
3508
3567
indexTypes, indexHashables,
3509
3568
baseOperand);
3510
3569
3511
3570
getOrCreateKeyPathEqualsAndHash (*this , loc,
3512
3571
needsGenericContext ? genericEnv : nullptr ,
3513
3572
expansion,
3514
- indexPatterns ,
3573
+ equalsIndexPatterns ,
3515
3574
indexEquals, indexHash);
3516
3575
}
3517
3576
@@ -3523,7 +3582,7 @@ SILGenModule::emitKeyPathComponentForDecl(SILLocation loc,
3523
3582
indexTypes,
3524
3583
baseTy, componentTy);
3525
3584
3526
- auto indexPatternsCopy = getASTContext ().AllocateCopy (indexPatterns );
3585
+ auto indexPatternsCopy = getASTContext ().AllocateCopy (xIndexPatterns );
3527
3586
if (isSettableInComponent ()) {
3528
3587
auto setter = getOrCreateKeyPathSetter (*this , loc,
3529
3588
decl, subs,
@@ -3540,6 +3599,13 @@ SILGenModule::emitKeyPathComponentForDecl(SILLocation loc,
3540
3599
externalSubs,
3541
3600
componentTy);
3542
3601
} 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
+ }
3543
3609
return KeyPathPatternComponent::forComputedGettableProperty (id,
3544
3610
getter,
3545
3611
indexPatternsCopy,
@@ -3581,7 +3647,10 @@ RValue RValueEmitter::visitKeyPathExpr(KeyPathExpr *E, SGFContext C) {
3581
3647
case KeyPathExpr::Component::Kind::Property:
3582
3648
case KeyPathExpr::Component::Kind::Subscript: {
3583
3649
auto decl = cast<AbstractStorageDecl>(component.getDeclRef ().getDecl ());
3584
-
3650
+
3651
+ decl->dump ();
3652
+ component.getIndexExpr ()->dump ();
3653
+
3585
3654
unsigned numOperands = operands.size ();
3586
3655
loweredComponents.push_back (
3587
3656
SGF.SGM .emitKeyPathComponentForDecl (SILLocation (E),
@@ -3604,6 +3673,7 @@ RValue RValueEmitter::visitKeyPathExpr(KeyPathExpr *E, SGFContext C) {
3604
3673
component.getIndexExpr ());
3605
3674
3606
3675
for (auto &arg : loweredArgs) {
3676
+ arg.dump ();
3607
3677
operands.push_back (arg.forward (SGF));
3608
3678
}
3609
3679
@@ -3674,6 +3744,9 @@ RValue RValueEmitter::visitKeyPathExpr(KeyPathExpr *E, SGFContext C) {
3674
3744
rootTy, baseTy,
3675
3745
loweredComponents,
3676
3746
objcString);
3747
+
3748
+ std::cout << " [pattern] num operands: " << pattern->getNumOperands () << std::endl;
3749
+ std::cout << " [operand] num operands: " << operands.size () << std::endl;
3677
3750
auto keyPath = SGF.B .createKeyPath (SILLocation (E), pattern,
3678
3751
needsGenericContext
3679
3752
? SGF.F .getForwardingSubstitutionMap ()
0 commit comments