@@ -216,26 +216,29 @@ class TypeLowering {
216216 };
217217
218218private:
219+ friend class TypeConverter ;
220+
219221 // / The SIL type of values with this Swift type.
220222 SILType LoweredType;
221223
222224 RecursiveProperties Properties;
223225 unsigned ReferenceCounted : 1 ;
224226
225- public:
226227 // / The resilience expansion for this type lowering.
227228 // / If the type is not resilient at all, this is always Minimal.
228- ResilienceExpansion forExpansion = ResilienceExpansion::Minimal ;
229+ unsigned ForExpansion : 1 ;
229230
230231 // / A single linked list of lowerings for different resilience expansions.
231232 // / The first lowering is always for ResilientExpansion::Minimal.
232- mutable const TypeLowering *nextExpansion = nullptr ;
233+ mutable const TypeLowering *NextExpansion = nullptr ;
233234
234235protected:
235236 TypeLowering (SILType type, RecursiveProperties properties,
236- IsReferenceCounted_t isRefCounted)
237+ IsReferenceCounted_t isRefCounted,
238+ ResilienceExpansion forExpansion)
237239 : LoweredType(type), Properties(properties),
238- ReferenceCounted (isRefCounted) {}
240+ ReferenceCounted (isRefCounted),
241+ ForExpansion(unsigned (forExpansion)) {}
239242
240243public:
241244 TypeLowering (const TypeLowering &) = delete;
@@ -247,12 +250,22 @@ class TypeLowering {
247250 // / convention?
248251 // /
249252 // / This is independent of whether the SIL argument is address type.
250- bool isFormallyPassedIndirectly () const { return isAddressOnly (); }
253+ bool isFormallyPassedIndirectly () const {
254+ assert (!isResilient () ||
255+ getResilienceExpansion () == ResilienceExpansion::Minimal &&
256+ " calling convention uses minimal resilience expansion" );
257+ return isAddressOnly ();
258+ }
251259
252260 // / Are r-values of this type returned indirectly by formal convention?
253261 // /
254262 // / This is independent of whether the SIL result is address type.
255- bool isFormallyReturnedIndirectly () const { return isAddressOnly (); }
263+ bool isFormallyReturnedIndirectly () const {
264+ assert (!isResilient () ||
265+ getResilienceExpansion () == ResilienceExpansion::Minimal &&
266+ " calling convention uses minimal resilience expansion" );
267+ return isAddressOnly ();
268+ }
256269
257270 RecursiveProperties getRecursiveProperties () const {
258271 return Properties;
@@ -306,6 +319,10 @@ class TypeLowering {
306319 return Properties.isResilient ();
307320 }
308321
322+ ResilienceExpansion getResilienceExpansion () const {
323+ return ResilienceExpansion (ForExpansion);
324+ }
325+
309326 // / Produce an exact copy of the value in the given address as a
310327 // / scalar. The caller is responsible for destroying this value,
311328 // / e.g. by releasing it.
@@ -748,8 +765,7 @@ class TypeConverter {
748765 // / Lowers a Swift type to a SILType, and returns the SIL TypeLowering
749766 // / for that type.
750767 const TypeLowering &
751- getTypeLowering (Type t, ResilienceExpansion forExpansion =
752- ResilienceExpansion::Minimal) {
768+ getTypeLowering (Type t, ResilienceExpansion forExpansion) {
753769 AbstractionPattern pattern (getCurGenericContext (), t->getCanonicalType ());
754770 return getTypeLowering (pattern, t, forExpansion);
755771 }
@@ -758,33 +774,28 @@ class TypeConverter {
758774 // / patterns of the given original type.
759775 const TypeLowering &getTypeLowering (AbstractionPattern origType,
760776 Type substType,
761- ResilienceExpansion forExpansion =
762- ResilienceExpansion::Minimal);
777+ ResilienceExpansion forExpansion);
763778
764779 // / Returns the SIL TypeLowering for an already lowered SILType. If the
765780 // / SILType is an address, returns the TypeLowering for the pointed-to
766781 // / type.
767782 const TypeLowering &
768- getTypeLowering (SILType t, ResilienceExpansion forExpansion =
769- ResilienceExpansion::Minimal);
783+ getTypeLowering (SILType t, ResilienceExpansion forExpansion);
770784
771785 // Returns the lowered SIL type for a Swift type.
772- SILType getLoweredType (Type t, ResilienceExpansion forExpansion
773- = ResilienceExpansion::Minimal) {
786+ SILType getLoweredType (Type t, ResilienceExpansion forExpansion) {
774787 return getTypeLowering (t, forExpansion).getLoweredType ();
775788 }
776789
777790 // Returns the lowered SIL type for a Swift type.
778791 SILType getLoweredType (AbstractionPattern origType, Type substType,
779- ResilienceExpansion forExpansion =
780- ResilienceExpansion::Minimal) {
792+ ResilienceExpansion forExpansion) {
781793 return getTypeLowering (origType, substType, forExpansion)
782794 .getLoweredType ();
783795 }
784796
785797 SILType getLoweredLoadableType (Type t,
786- ResilienceExpansion forExpansion =
787- ResilienceExpansion::Minimal) {
798+ ResilienceExpansion forExpansion) {
788799 const TypeLowering &ti = getTypeLowering (t, forExpansion);
789800 assert (
790801 (ti.isLoadable () || !SILModuleConventions (M).useLoweredAddresses ()) &&
@@ -793,11 +804,16 @@ class TypeConverter {
793804 }
794805
795806 CanType getLoweredRValueType (Type t) {
796- return getLoweredType (t).getASTType ();
807+ // We're ignoring the category (object vs address), so the resilience
808+ // expansion does not matter.
809+ return getLoweredType (t, ResilienceExpansion::Minimal).getASTType ();
797810 }
798811
799812 CanType getLoweredRValueType (AbstractionPattern origType, Type substType) {
800- return getLoweredType (origType, substType).getASTType ();
813+ // We're ignoring the category (object vs address), so the resilience
814+ // expansion does not matter.
815+ return getLoweredType (origType, substType,
816+ ResilienceExpansion::Minimal).getASTType ();
801817 }
802818
803819 AbstractionPattern getAbstractionPattern (AbstractStorageDecl *storage,
0 commit comments