@@ -93,13 +93,6 @@ adjustFunctionType(CanSILFunctionType t, SILFunctionType::Representation rep,
93
93
witnessMethodConformance);
94
94
}
95
95
96
- // / Flag used to place context-dependent TypeLowerings in their own arena which
97
- // / can be disposed when a generic context is exited.
98
- enum IsDependent_t : unsigned {
99
- IsNotDependent = false ,
100
- IsDependent = true
101
- };
102
-
103
96
// / Is a lowered SIL type trivial? That is, are copies ultimately just
104
97
// / bit-copies, and it takes no work to destroy a value?
105
98
enum IsTrivial_t : bool {
@@ -182,6 +175,10 @@ class TypeLowering {
182
175
(isFixedABI ? 0U : NonFixedABIFlag) |
183
176
(isAddressOnly ? AddressOnlyFlag : 0U ) |
184
177
(isResilient ? ResilientFlag : 0U )) {}
178
+
179
+ constexpr bool operator ==(RecursiveProperties p) const {
180
+ return Flags == p.Flags ;
181
+ }
185
182
186
183
static constexpr RecursiveProperties forTrivial () {
187
184
return {IsTrivial, IsFixedABI, IsNotAddressOnly, IsNotResilient};
@@ -502,10 +499,8 @@ class TypeLowering {
502
499
}
503
500
504
501
// / Allocate a new TypeLowering using the TypeConverter's allocator.
505
- void *operator new (size_t size, TypeConverter &tc,
506
- IsDependent_t dependent);
507
- void *operator new [](size_t size, TypeConverter &tc,
508
- IsDependent_t dependent);
502
+ void *operator new (size_t size, TypeConverter &tc);
503
+ void *operator new [](size_t size, TypeConverter &tc);
509
504
510
505
// Forbid 'new FooTypeLowering' and try to forbid 'delete tl'.
511
506
// The latter is made challenging because the existence of the
@@ -573,7 +568,7 @@ enum class CaptureKind {
573
568
class TypeConverter {
574
569
friend class TypeLowering ;
575
570
576
- llvm::BumpPtrAllocator IndependentBPA ;
571
+ llvm::BumpPtrAllocator TypeLoweringBPA ;
577
572
578
573
struct CachingTypeKey {
579
574
CanGenericSignature Sig;
@@ -617,11 +612,6 @@ class TypeConverter {
617
612
return OrigType.hasCachingKey ();
618
613
}
619
614
620
- IsDependent_t isDependent () const {
621
- if (SubstType->hasTypeParameter ())
622
- return IsDependent;
623
- return IsNotDependent;
624
- }
625
615
TypeKey getKeyForMinimalExpansion () const {
626
616
return {OrigType, SubstType, TypeExpansionContext::minimal ()};
627
617
}
@@ -662,24 +652,7 @@ class TypeConverter {
662
652
#endif
663
653
664
654
// / Mapping for types independent on contextual generic parameters.
665
- llvm::DenseMap<CachingTypeKey, const TypeLowering *> IndependentTypes;
666
-
667
- struct DependentTypeState {
668
- llvm::BumpPtrAllocator BPA;
669
- CanGenericSignature Sig;
670
- llvm::DenseMap<TypeConverter::CachingTypeKey,
671
- const TypeLowering *> Map;
672
-
673
- explicit DependentTypeState (CanGenericSignature sig) : Sig(sig) {}
674
-
675
- DependentTypeState (DependentTypeState &&) = default ;
676
-
677
- // No copy constructor or assignment.
678
- DependentTypeState (const DependentTypeState &) = delete ;
679
- void operator =(const DependentTypeState &) = delete ;
680
- };
681
-
682
- llvm::SmallVector<DependentTypeState, 1 > DependentTypes;
655
+ llvm::DenseMap<CachingTypeKey, const TypeLowering *> LoweredTypes;
683
656
684
657
llvm::DenseMap<std::pair<TypeExpansionContext, SILDeclRef>, SILConstantInfo *>
685
658
ConstantTypes;
@@ -703,7 +676,8 @@ class TypeConverter {
703
676
#include " swift/SIL/BridgedTypes.def"
704
677
705
678
const TypeLowering &
706
- getTypeLoweringForLoweredType (TypeKey key,
679
+ getTypeLoweringForLoweredType (AbstractionPattern origType,
680
+ CanType loweredType,
707
681
TypeExpansionContext forExpansion,
708
682
bool origHadOpaqueTypeArchetype);
709
683
@@ -772,11 +746,14 @@ class TypeConverter {
772
746
return isIndirectPlusZeroSelfParameter (T.getASTType ());
773
747
}
774
748
775
- // / Lowers a Swift type to a SILType, and returns the SIL TypeLowering
749
+ // / Lowers a context-independent Swift type to a SILType, and returns the SIL TypeLowering
776
750
// / for that type.
751
+ // /
752
+ // / If `t` contains generic parameters, then the overload that also takes an
753
+ // / `AbstractionPattern` must be used.
777
754
const TypeLowering &
778
755
getTypeLowering (Type t, TypeExpansionContext forExpansion) {
779
- AbstractionPattern pattern (getCurGenericContext (), t->getCanonicalType ());
756
+ AbstractionPattern pattern (t->getCanonicalType ());
780
757
return getTypeLowering (pattern, t, forExpansion);
781
758
}
782
759
@@ -789,8 +766,18 @@ class TypeConverter {
789
766
// / Returns the SIL TypeLowering for an already lowered SILType. If the
790
767
// / SILType is an address, returns the TypeLowering for the pointed-to
791
768
// / type.
769
+ // /
770
+ // / If `t` contains type parameters, then the generic signature for its context
771
+ // / must be provided.
772
+ const TypeLowering &
773
+ getTypeLowering (SILType t, TypeExpansionContext forExpansion,
774
+ CanGenericSignature signature = nullptr );
775
+
776
+ // / Returns the SIL TypeLowering for an already lowered SILType. If the
777
+ // / SILType is an address, returns the TypeLowering for the pointed-to
778
+ // / type in the context of the given SILFunction.
792
779
const TypeLowering &
793
- getTypeLowering (SILType t, TypeExpansionContext forExpansion );
780
+ getTypeLowering (SILType t, SILFunction &F );
794
781
795
782
// Returns the lowered SIL type for a Swift type.
796
783
SILType getLoweredType (Type t, TypeExpansionContext forExpansion) {
@@ -949,26 +936,6 @@ class TypeConverter {
949
936
AbstractStorageDecl *value,
950
937
Type lvalueType);
951
938
952
- // / Push a generic function context. See GenericContextScope for an RAII
953
- // / interface to this function.
954
- // /
955
- // / Types containing generic parameter references must be lowered in a generic
956
- // / context. There can be at most one level of generic context active at any
957
- // / point in time.
958
- void pushGenericContext (CanGenericSignature sig);
959
-
960
- // / Return the current generic context. This should only be used in
961
- // / the type-conversion routines.
962
- CanGenericSignature getCurGenericContext () const {
963
- if (DependentTypes.empty ())
964
- return CanGenericSignature ();
965
- return DependentTypes.back ().Sig ;
966
- }
967
-
968
- // / Pop a generic function context. See GenericContextScope for an RAII
969
- // / interface to this function. There must be an active generic context.
970
- void popGenericContext (CanGenericSignature sig);
971
-
972
939
// / Known types for bridging.
973
940
#define BRIDGING_KNOWN_TYPE (BridgedModule,BridgedType ) \
974
941
CanType get##BridgedType##Type();
@@ -1079,26 +1046,6 @@ class TypeConverter {
1079
1046
bool suppressOptional);
1080
1047
};
1081
1048
1082
- // / RAII interface to push a generic context.
1083
- class GenericContextScope {
1084
- TypeConverter &TC;
1085
- CanGenericSignature Sig;
1086
- public:
1087
- GenericContextScope (TypeConverter &TC, CanGenericSignature sig)
1088
- : TC(TC), Sig(sig)
1089
- {
1090
- TC.pushGenericContext (sig);
1091
- }
1092
-
1093
- ~GenericContextScope () {
1094
- TC.popGenericContext (Sig);
1095
- }
1096
-
1097
- private:
1098
- GenericContextScope (const GenericContextScope&) = delete ;
1099
- GenericContextScope &operator =(const GenericContextScope&) = delete ;
1100
- };
1101
-
1102
1049
} // namespace Lowering
1103
1050
} // namespace swift
1104
1051
0 commit comments