@@ -54,6 +54,10 @@ llvm::cl::opt<bool> TypeLoweringForceOpaqueValueLowering(
5454 llvm::cl::desc(" Force TypeLowering to behave as if building with opaque "
5555 " values enabled" ));
5656
57+ llvm::cl::opt<bool > TypeLoweringDisableVerification (
58+ " type-lowering-disable-verification" , llvm::cl::init(false ),
59+ llvm::cl::desc(" Disable the asserts-only verification of lowerings" ));
60+
5761namespace {
5862 // / A CRTP type visitor for deciding whether the metatype for a type
5963 // / is a singleton type, i.e. whether there can only ever be one
@@ -2945,6 +2949,9 @@ void TypeConverter::verifyLowering(const TypeLowering &lowering,
29452949 AbstractionPattern origType,
29462950 CanType substType,
29472951 TypeExpansionContext forExpansion) {
2952+ if (TypeLoweringDisableVerification) {
2953+ return ;
2954+ }
29482955 verifyLexicalLowering (lowering, origType, substType, forExpansion);
29492956 verifyTrivialLowering (lowering, origType, substType, forExpansion);
29502957}
@@ -3049,7 +3056,7 @@ void TypeConverter::verifyTrivialLowering(const TypeLowering &lowering,
30493056
30503057 if (lowering.isTrivial () && !conformance) {
30513058 // A trivial type can lack a conformance in a few cases:
3052- // (1) containing or being a resilient type
3059+ // (1) containing or being a public, non-frozen type
30533060 // (2) containing or being a generic type which doesn't conform
30543061 // unconditionally but in this particular instantiation is trivial
30553062 // (3) being a special type that's not worth forming a conformance for
@@ -3064,6 +3071,7 @@ void TypeConverter::verifyTrivialLowering(const TypeLowering &lowering,
30643071 // unowned(unsafe) var o: AnyObject
30653072 // }
30663073 // (5) being defined in a different module
3074+ // (6) being defined in a module built from interface
30673075 bool hasNoNonconformingNode = visitAggregateLeaves (
30683076 origType, substType, forExpansion,
30693077 /* isLeafAggregate=*/
@@ -3081,12 +3089,22 @@ void TypeConverter::verifyTrivialLowering(const TypeLowering &lowering,
30813089 return true ;
30823090 }
30833091
3084- // Resilient trivial types may not conform (case (1)).
3085- if (nominal->isResilient ())
3092+ // Public, non-frozen trivial types may not conform (case (1)).
3093+ if (nominal
3094+ ->getFormalAccessScope (/* useDC=*/ nullptr ,
3095+ /* treatUsableFromInlineAsPublic=*/ true )
3096+ .isPublic ())
30863097 return true ;
30873098
3099+ auto *module = nominal->getModuleContext ();
3100+
3101+ // Types in modules built from interfaces may not conform (case (6)).
3102+ if (module && module ->isBuiltFromInterface ()) {
3103+ return false ;
3104+ }
3105+
30883106 // Trivial types from other modules may not conform (case (5)).
3089- return nominal-> getModuleContext () != &M;
3107+ return module != &M;
30903108 },
30913109 /* visit=*/
30923110 [&](auto ty, auto origTy, auto *field, auto index) -> bool {
@@ -3141,12 +3159,22 @@ void TypeConverter::verifyTrivialLowering(const TypeLowering &lowering,
31413159 return false ;
31423160 }
31433161
3144- // Resilient trivial types may not conform (case (1)).
3145- if (nominal->isResilient ())
3162+ // Public, non-frozen trivial types may not conform (case (1)).
3163+ if (nominal
3164+ ->getFormalAccessScope (/* useDC=*/ nullptr ,
3165+ /* treatUsableFromInlineAsPublic=*/ true )
3166+ .isPublic ())
3167+ return false ;
3168+
3169+ auto *module = nominal->getModuleContext ();
3170+
3171+ // Types in modules built from interfaces may not conform (case (6)).
3172+ if (module && module ->isBuiltFromInterface ()) {
31463173 return false ;
3174+ }
31473175
31483176 // Trivial types from other modules may not conform (case (5)).
3149- return nominal-> getModuleContext () == &M;
3177+ return module == &M;
31503178 });
31513179 if (hasNoNonconformingNode) {
31523180 llvm::errs () << " Trivial type without a BitwiseCopyable conformance!?:\n "
@@ -3159,10 +3187,19 @@ void TypeConverter::verifyTrivialLowering(const TypeLowering &lowering,
31593187 if (!lowering.isTrivial () && conformance) {
31603188 // A non-trivial type can have a conformance in one case:
31613189 // (1) contains a conforming archetype
3190+ // (2) is resilient with minimal expansion
31623191 bool hasNoConformingArchetypeNode = visitAggregateLeaves (
31633192 origType, substType, forExpansion,
31643193 /* isLeaf=*/
31653194 [&](auto ty, auto origTy, auto *field, auto index) -> bool {
3195+ // A resilient type that's with minimal expansion may be non-trivial
3196+ // but still conform (case (2)).
3197+ auto *nominal = ty.getAnyNominal ();
3198+ if (nominal && nominal->isResilient () &&
3199+ forExpansion.getResilienceExpansion () ==
3200+ ResilienceExpansion::Minimal) {
3201+ return true ;
3202+ }
31663203 // Walk into every aggregate.
31673204 return false ;
31683205 },
@@ -3173,7 +3210,16 @@ void TypeConverter::verifyTrivialLowering(const TypeLowering &lowering,
31733210 " leaf of non-trivial BitwiseCopyable type that doesn't "
31743211 " conform to BitwiseCopyable!?" );
31753212
3176- // An archetype may conform but be non-trivial (case (2)).
3213+ // A resilient type that's with minimal expansion may be non-trivial
3214+ // but still conform (case (2)).
3215+ auto *nominal = ty.getAnyNominal ();
3216+ if (nominal && nominal->isResilient () &&
3217+ forExpansion.getResilienceExpansion () ==
3218+ ResilienceExpansion::Minimal) {
3219+ return false ;
3220+ }
3221+
3222+ // An archetype may conform but be non-trivial (case (1)).
31773223 if (origTy.isTypeParameter ())
31783224 return false ;
31793225
0 commit comments