@@ -85,13 +85,6 @@ inline CanSILFunctionType adjustFunctionType(CanSILFunctionType t,
85
85
}
86
86
87
87
88
- // / Flag used to place context-dependent TypeLowerings in their own arena which
89
- // / can be disposed when a generic context is exited.
90
- enum IsDependent_t : unsigned {
91
- IsNotDependent = false ,
92
- IsDependent = true
93
- };
94
-
95
88
// / Extended type information used by SIL.
96
89
class TypeLowering {
97
90
public:
@@ -335,10 +328,8 @@ class TypeLowering {
335
328
}
336
329
337
330
// / Allocate a new TypeLowering using the TypeConverter's allocator.
338
- void *operator new (size_t size, TypeConverter &tc,
339
- IsDependent_t dependent);
340
- void *operator new [](size_t size, TypeConverter &tc,
341
- IsDependent_t dependent);
331
+ void *operator new (size_t size, TypeConverter &tc);
332
+ void *operator new [](size_t size, TypeConverter &tc);
342
333
343
334
// Forbid 'new FooTypeLowering' and try to forbid 'delete tl'.
344
335
// The latter is made challenging because the existence of the
@@ -399,9 +390,6 @@ class TypeConverter {
399
390
friend class TypeLowering ;
400
391
401
392
llvm::BumpPtrAllocator IndependentBPA;
402
- // / BumpPtrAllocator for types dependent on contextual generic parameters,
403
- // / which is reset when the generic context is popped.
404
- llvm::BumpPtrAllocator DependentBPA;
405
393
406
394
enum : unsigned {
407
395
// / There is a unique entry with this uncurry level in the
@@ -411,15 +399,17 @@ class TypeConverter {
411
399
};
412
400
413
401
struct CachingTypeKey {
414
- GenericSignature *Sig ;
402
+ GenericSignature *OrigSig ;
415
403
AbstractionPattern::CachingKey OrigType;
404
+ GenericSignature *SubstSig;
416
405
CanType SubstType;
417
406
unsigned UncurryLevel;
418
407
419
408
friend bool operator ==(const CachingTypeKey &lhs,
420
409
const CachingTypeKey &rhs) {
421
- return lhs.Sig == rhs.Sig
410
+ return lhs.OrigSig == rhs.OrigSig
422
411
&& lhs.OrigType == rhs.OrigType
412
+ && lhs.SubstSig == rhs.SubstSig
423
413
&& lhs.SubstType == rhs.SubstType
424
414
&& lhs.UncurryLevel == rhs.UncurryLevel ;
425
415
}
@@ -433,6 +423,10 @@ class TypeConverter {
433
423
// / An unsubstituted version of a type, dictating its abstraction patterns.
434
424
AbstractionPattern OrigType;
435
425
426
+ // / The generic signature describing dependent types in the substituted
427
+ // / type.
428
+ CanGenericSignature SubstSig;
429
+
436
430
// / The substituted version of the type, dictating the types that
437
431
// / should be used in the lowered type.
438
432
CanType SubstType;
@@ -446,26 +440,23 @@ class TypeConverter {
446
440
? OrigType.getGenericSignature ()
447
441
: nullptr ),
448
442
OrigType.getCachingKey (),
443
+ SubstSig,
449
444
SubstType,
450
445
UncurryLevel };
451
446
}
452
447
453
448
bool isCacheable () const {
454
449
return OrigType.hasCachingKey ();
455
450
}
456
-
457
- IsDependent_t isDependent () const {
458
- if (SubstType->hasTypeParameter ())
459
- return IsDependent;
460
- return IsNotDependent;
461
- }
462
451
};
463
452
464
453
friend struct llvm ::DenseMapInfo<CachingTypeKey>;
465
454
466
- TypeKey getTypeKey (AbstractionPattern origTy, CanType substTy,
455
+ TypeKey getTypeKey (AbstractionPattern origTy,
456
+ CanGenericSignature substSig,
457
+ CanType substTy,
467
458
unsigned uncurryLevel) {
468
- return {origTy, substTy, uncurryLevel};
459
+ return {origTy, substSig, substTy, uncurryLevel};
469
460
}
470
461
471
462
struct OverrideKey {
@@ -491,12 +482,7 @@ class TypeConverter {
491
482
// / Insert a mapping into the cache.
492
483
void insert (TypeKey k, const TypeLowering *tl);
493
484
494
- // / Mapping for types independent on contextual generic parameters, which is
495
- // / cleared when the generic context is popped.
496
485
llvm::DenseMap<CachingTypeKey, const TypeLowering *> IndependentTypes;
497
- // / Mapping for types dependent on contextual generic parameters, which is
498
- // / cleared when the generic context is popped.
499
- llvm::DenseMap<CachingTypeKey, const TypeLowering *> DependentTypes;
500
486
501
487
llvm::DenseMap<SILDeclRef, SILConstantInfo> ConstantTypes;
502
488
@@ -577,31 +563,42 @@ class TypeConverter {
577
563
578
564
// / Lowers a Swift type to a SILType, and returns the SIL TypeLowering
579
565
// / for that type.
580
- const TypeLowering &getTypeLowering (Type t, unsigned uncurryLevel = 0 ) {
581
- AbstractionPattern pattern (CurGenericContext, t->getCanonicalType ());
582
- return getTypeLowering (pattern, t, uncurryLevel);
566
+ const TypeLowering &getTypeLowering (Type t, unsigned uncurryLevel = 0 ,
567
+ CanGenericSignature genericSig
568
+ = CanGenericSignature()) {
569
+ if (!genericSig)
570
+ genericSig = CurGenericContext;
571
+ AbstractionPattern pattern (genericSig, t->getCanonicalType ());
572
+ return getTypeLowering (pattern, t, uncurryLevel, genericSig);
583
573
}
584
574
585
575
// / Lowers a Swift type to a SILType according to the abstraction
586
576
// / patterns of the given original type.
587
577
const TypeLowering &getTypeLowering (AbstractionPattern origType,
588
578
Type substType,
589
- unsigned uncurryLevel = 0 );
579
+ unsigned uncurryLevel = 0 ,
580
+ CanGenericSignature genericSig
581
+ = CanGenericSignature());
590
582
591
583
// / Returns the SIL TypeLowering for an already lowered SILType. If the
592
584
// / SILType is an address, returns the TypeLowering for the pointed-to
593
585
// / type.
594
586
const TypeLowering &getTypeLowering (SILType t);
595
587
596
588
// Returns the lowered SIL type for a Swift type.
597
- SILType getLoweredType (Type t, unsigned uncurryLevel = 0 ) {
598
- return getTypeLowering (t, uncurryLevel).getLoweredType ();
589
+ SILType getLoweredType (Type t, unsigned uncurryLevel = 0 ,
590
+ CanGenericSignature genericSig
591
+ = CanGenericSignature()) {
592
+ return getTypeLowering (t, uncurryLevel, genericSig).getLoweredType ();
599
593
}
600
594
601
595
// Returns the lowered SIL type for a Swift type.
602
596
SILType getLoweredType (AbstractionPattern origType, Type substType,
603
- unsigned uncurryLevel = 0 ) {
604
- return getTypeLowering (origType, substType, uncurryLevel).getLoweredType ();
597
+ unsigned uncurryLevel = 0 ,
598
+ CanGenericSignature genericSig
599
+ = CanGenericSignature()) {
600
+ return getTypeLowering (origType, substType, uncurryLevel, genericSig)
601
+ .getLoweredType ();
605
602
}
606
603
607
604
SILType getLoweredLoadableType (Type t, unsigned uncurryLevel = 0 ) {
@@ -736,24 +733,6 @@ class TypeConverter {
736
733
CanGenericSignature getEffectiveGenericSignature (AnyFunctionRef fn,
737
734
CaptureInfo captureInfo);
738
735
739
- // / Push a generic function context. See GenericContextScope for an RAII
740
- // / interface to this function.
741
- // /
742
- // / Types containing generic parameter references must be lowered in a generic
743
- // / context. There can be at most one level of generic context active at any
744
- // / point in time.
745
- void pushGenericContext (CanGenericSignature sig);
746
-
747
- // / Return the current generic context. This should only be used in
748
- // / the type-conversion routines.
749
- CanGenericSignature getCurGenericContext () const {
750
- return CurGenericContext;
751
- }
752
-
753
- // / Pop a generic function context. See GenericContextScope for an RAII
754
- // / interface to this function. There must be an active generic context.
755
- void popGenericContext (CanGenericSignature sig);
756
-
757
736
// / Known types for bridging.
758
737
#define BRIDGING_KNOWN_TYPE (BridgedModule,BridgedType ) \
759
738
CanType get##BridgedType##Type();
@@ -797,7 +776,8 @@ class TypeConverter {
797
776
CanAnyFunctionType origInterfaceType);
798
777
private:
799
778
CanType getLoweredRValueType (AbstractionPattern origType, CanType substType,
800
- unsigned uncurryLevel);
779
+ unsigned uncurryLevel,
780
+ CanGenericSignature genericSig);
801
781
802
782
Type getLoweredCBridgedType (AbstractionPattern pattern, Type t,
803
783
bool canBridgeBool,
@@ -826,26 +806,6 @@ TypeLowering::getSemanticTypeLowering(TypeConverter &TC) const {
826
806
return *this ;
827
807
}
828
808
829
- // / RAII interface to push a generic context.
830
- class GenericContextScope {
831
- TypeConverter &TC;
832
- CanGenericSignature Sig;
833
- public:
834
- GenericContextScope (TypeConverter &TC, CanGenericSignature sig)
835
- : TC(TC), Sig(sig)
836
- {
837
- TC.pushGenericContext (sig);
838
- }
839
-
840
- ~GenericContextScope () {
841
- TC.popGenericContext (Sig);
842
- }
843
-
844
- private:
845
- GenericContextScope (const GenericContextScope&) = delete ;
846
- GenericContextScope &operator =(const GenericContextScope&) = delete ;
847
- };
848
-
849
809
} // namespace Lowering
850
810
} // namespace swift
851
811
@@ -860,19 +820,22 @@ namespace llvm {
860
820
861
821
// Use the second field because the first field can validly be null.
862
822
static CachingTypeKey getEmptyKey () {
863
- return {nullptr , APCachingKey (), CanTypeInfo::getEmptyKey (), 0 };
823
+ return {nullptr , APCachingKey (), nullptr , CanTypeInfo::getEmptyKey (), 0 };
864
824
}
865
825
static CachingTypeKey getTombstoneKey () {
866
- return {nullptr , APCachingKey (), CanTypeInfo::getTombstoneKey (), 0 };
826
+ return {nullptr , APCachingKey (), nullptr , CanTypeInfo::getTombstoneKey (), 0 };
867
827
}
868
828
static unsigned getHashValue (CachingTypeKey val) {
869
- auto hashSig =
870
- DenseMapInfo<swift::GenericSignature *>::getHashValue (val.Sig );
829
+ auto hashOrigSig =
830
+ DenseMapInfo<swift::GenericSignature *>::getHashValue (val.OrigSig );
871
831
auto hashOrig =
872
832
CachingKeyInfo::getHashValue (val.OrigType );
873
833
auto hashSubst =
874
834
DenseMapInfo<swift::CanType>::getHashValue (val.SubstType );
875
- return hash_combine (hashSig, hashOrig, hashSubst, val.UncurryLevel );
835
+ auto hashSubstSig =
836
+ DenseMapInfo<swift::GenericSignature *>::getHashValue (val.SubstSig );
837
+ return hash_combine (hashOrigSig, hashOrig, hashSubstSig, hashSubst,
838
+ val.UncurryLevel );
876
839
}
877
840
static bool isEqual (CachingTypeKey LHS, CachingTypeKey RHS) {
878
841
return LHS == RHS;
0 commit comments