@@ -990,6 +990,29 @@ namespace {
990990 return IGM.typeLayoutCache .getOrCreateResilientEntry (T);
991991 }
992992
993+ auto decl = T.getASTType ()->getStructOrBoundGenericStruct ();
994+ auto rawLayout = decl->getAttrs ().getAttribute <RawLayoutAttr>();
995+
996+ // If we have a raw layout struct who is fixed size, it means the
997+ // layout of the struct is fully concrete.
998+ if (rawLayout) {
999+ auto likeType = rawLayout->getResolvedLikeType (decl)->getCanonicalType ();
1000+ SILType loweredLikeType = IGM.getLoweredType (likeType);
1001+
1002+ // The given struct type T that we're building is fully concrete, but
1003+ // our like type is still in terms of the potential archetype of the
1004+ // type.
1005+ auto subs = T.getASTType ()->getContextSubstitutionMap (
1006+ IGM.getSwiftModule (), decl);
1007+
1008+ loweredLikeType = loweredLikeType.subst (IGM.getSILModule (), subs);
1009+
1010+ // Array like raw layouts are still handled correctly even though the
1011+ // type layout entry is only that of the like type.
1012+ return IGM.getTypeInfo (loweredLikeType)
1013+ .buildTypeLayoutEntry (IGM, loweredLikeType, useStructLayouts);
1014+ }
1015+
9931016 std::vector<TypeLayoutEntry *> fields;
9941017 for (auto &field : getFields ()) {
9951018 auto fieldTy = field.getType (IGM, T);
@@ -1082,27 +1105,15 @@ namespace {
10821105 return IGM.typeLayoutCache .getOrCreateResilientEntry (T);
10831106 }
10841107
1085- std::vector<TypeLayoutEntry *> fields;
1086- for (auto &field : getFields ()) {
1087- auto fieldTy = field.getType (IGM, T);
1088- fields.push_back (
1089- field.getTypeInfo ().buildTypeLayoutEntry (IGM, fieldTy, useStructLayouts));
1090- }
1091-
10921108 auto decl = T.getASTType ()->getStructOrBoundGenericStruct ();
10931109 auto rawLayout = decl->getAttrs ().getAttribute <RawLayoutAttr>();
10941110
10951111 // If we have a raw layout struct who is non-fixed size, it means the
10961112 // layout of the struct is dependent on the archetype of the thing it's
10971113 // like.
10981114 if (rawLayout) {
1099- SILType loweredLikeType;
1100-
1101- if (auto likeType = rawLayout->getResolvedScalarLikeType (decl)) {
1102- loweredLikeType = IGM.getLoweredType (*likeType);
1103- } else if (auto likeArray = rawLayout->getResolvedArrayLikeTypeAndCount (decl)) {
1104- loweredLikeType = IGM.getLoweredType (likeArray->first );
1105- }
1115+ auto likeType = rawLayout->getResolvedLikeType (decl)->getCanonicalType ();
1116+ SILType loweredLikeType = IGM.getLoweredType (likeType);
11061117
11071118 // The given struct type T that we're building may be in a generic
11081119 // environment that is different than that which was built our
@@ -1113,10 +1124,18 @@ namespace {
11131124
11141125 loweredLikeType = loweredLikeType.subst (IGM.getSILModule (), subs);
11151126
1116- return IGM.getTypeInfo (loweredLikeType).buildTypeLayoutEntry (IGM,
1117- loweredLikeType, useStructLayouts);
1127+ // Array like raw layouts are still handled correctly even though the
1128+ // type layout entry is only that of the like type.
1129+ return IGM.getTypeInfo (loweredLikeType)
1130+ .buildTypeLayoutEntry (IGM, loweredLikeType, useStructLayouts);
11181131 }
11191132
1133+ std::vector<TypeLayoutEntry *> fields;
1134+ for (auto &field : getFields ()) {
1135+ auto fieldTy = field.getType (IGM, T);
1136+ fields.push_back (
1137+ field.getTypeInfo ().buildTypeLayoutEntry (IGM, fieldTy, useStructLayouts));
1138+ }
11201139 assert (!fields.empty () &&
11211140 " Empty structs should not be NonFixedStructTypeInfo" );
11221141
0 commit comments