3131#include " swift/AST/TypeDifferenceVisitor.h"
3232#include " swift/AST/Types.h"
3333#include " swift/ClangImporter/ClangModule.h"
34+ #include " swift/SIL/AbstractionPatternGenerators.h"
3435#include " swift/SIL/PrettyStackTrace.h"
3536#include " swift/SIL/SILArgument.h"
3637#include " swift/SIL/SILBuilder.h"
@@ -261,6 +262,13 @@ namespace {
261262 return props;
262263 }
263264
265+ RecursiveProperties mergeHasPack (HasPack_t hasPack,
266+ RecursiveProperties props) {
267+ if (hasPack == HasPack)
268+ props.setHasPack ();
269+ return props;
270+ }
271+
264272 RecursiveProperties applyLifetimeAnnotation (LifetimeAnnotation annotation,
265273 RecursiveProperties props) {
266274 switch (annotation) {
@@ -333,7 +341,8 @@ namespace {
333341 IsAddressOnly, IsNotResilient,
334342 isSensitive,
335343 DoesNotHaveRawPointer,
336- IsLexical});
344+ IsLexical,
345+ HasPack});
337346 }
338347
339348 RetTy visitSILPackType (CanSILPackType type,
@@ -343,7 +352,8 @@ namespace {
343352 IsAddressOnly, IsNotResilient,
344353 isSensitive,
345354 DoesNotHaveRawPointer,
346- IsLexical});
355+ IsLexical,
356+ HasPack});
347357 }
348358
349359 RetTy visitPackExpansionType (CanPackExpansionType type,
@@ -355,6 +365,7 @@ namespace {
355365 type.getPatternType (),
356366 TC, Expansion));
357367 props = mergeIsTypeExpansionSensitive (isSensitive, props);
368+ props.setHasPack ();
358369 return asImpl ().handleAddressOnly (type, props);
359370 }
360371
@@ -2252,6 +2263,7 @@ namespace {
22522263 IsTypeExpansionSensitive_t isSensitive) {
22532264 RecursiveProperties properties;
22542265 properties.setAddressOnly ();
2266+ properties.setHasPack ();
22552267 for (auto i : indices (packType.getElementTypes ())) {
22562268 auto &eltLowering =
22572269 TC.getTypeLowering (packType->getSILElementType (i),
@@ -2268,6 +2280,7 @@ namespace {
22682280 IsTypeExpansionSensitive_t isSensitive) {
22692281 RecursiveProperties properties;
22702282 properties.setAddressOnly ();
2283+ properties.setHasPack ();
22712284 auto &patternLowering =
22722285 TC.getTypeLowering (origType.getPackExpansionPatternType (),
22732286 packExpansionType.getPatternType (),
@@ -2362,7 +2375,19 @@ namespace {
23622375 properties.setNonTrivial ();
23632376 properties.setLexical (IsLexical);
23642377 }
2365-
2378+
2379+ // [is_or_contains_pack_unsubstituted] Visit the fields of the
2380+ // unsubstituted type to find pack types which would be substituted away.
2381+ for (auto field : D->getStoredProperties ()) {
2382+ auto fieldInterfaceTy = field->getInterfaceType ()->getCanonicalType ();
2383+ auto origFieldType = AbstractionPattern (
2384+ D->getGenericSignature ().getCanonicalSignature (), fieldInterfaceTy);
2385+ auto fieldProperties =
2386+ classifyType (origFieldType, fieldInterfaceTy, TC, Expansion);
2387+ properties =
2388+ mergeHasPack (fieldProperties.isOrContainsPack (), properties);
2389+ }
2390+
23662391 // If the type has raw storage, it is move-only and address-only.
23672392 if (D->getAttrs ().hasAttribute <RawLayoutAttr>()) {
23682393 properties.setAddressOnly ();
@@ -2442,6 +2467,19 @@ namespace {
24422467 if (handleResilience (enumType, D, properties))
24432468 return handleAddressOnly (enumType, properties);
24442469
2470+ // [is_or_contains_pack_unsubstituted] Visit the elements of the
2471+ // unsubstituted type to find pack types which would be substituted away.
2472+ for (auto elt : D->getAllElements ()) {
2473+ if (!elt->hasAssociatedValues ())
2474+ continue ;
2475+ auto eltInterfaceTy = elt->getInterfaceType ()->getCanonicalType ();
2476+ auto origEltType = AbstractionPattern (
2477+ D->getGenericSignature ().getCanonicalSignature (), eltInterfaceTy);
2478+ auto eltProperties =
2479+ classifyType (origEltType, eltInterfaceTy, TC, Expansion);
2480+ properties = mergeHasPack (eltProperties.isOrContainsPack (), properties);
2481+ }
2482+
24452483 // If the whole enum is indirect, we lower it as if all payload
24462484 // cases were indirect. This means a fixed-layout indirect enum
24472485 // is always loadable and nontrivial. A resilient indirect enum
@@ -4646,6 +4684,7 @@ void TypeLowering::print(llvm::raw_ostream &os) const {
46464684 << " isOrContainsRawPointer: " << BOOL (Properties.isOrContainsRawPointer ())
46474685 << " .\n "
46484686 << " isLexical: " << BOOL (Properties.isLexical ()) << " .\n "
4687+ << " isOrContainsPack: " << BOOL (Properties.isOrContainsPack ()) << " .\n "
46494688 << " \n " ;
46504689}
46514690
0 commit comments