Skip to content

Commit 82e1c98

Browse files
committed
[Serialize] Serialize uniqued generic signatures.
Rather than inlining generic signatures in a half dozen places throughout the serialization format, serialize (uniqued) generic signatures with their own GenericSignatureID. Update various layouts (generic function types, SIL function types, generic environments, extension cross-references) to use GenericSignatureID. Shaves ~187k off the size of Swift.swiftmodule.
1 parent 2198230 commit 82e1c98

File tree

7 files changed

+262
-225
lines changed

7 files changed

+262
-225
lines changed

include/swift/Serialization/DeclTypeRecordNodes.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ OTHER(GENERIC_PARAM_LIST, 240)
162162
TRAILING_INFO(GENERIC_PARAM)
163163
TRAILING_INFO(GENERIC_REQUIREMENT)
164164
TRAILING_INFO(LAYOUT_REQUIREMENT)
165-
OTHER(GENERIC_ENVIRONMENT, 244)
165+
OTHER(GENERIC_SIGNATURE, 244)
166166
OTHER(SIL_GENERIC_ENVIRONMENT, 245)
167167

168168
OTHER(LOCAL_DISCRIMINATOR, 248)

include/swift/Serialization/ModuleFile.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,9 @@ class ModuleFile
299299
/// Types referenced by this module.
300300
std::vector<Serialized<Type>> Types;
301301

302+
/// Generic signatures referenced by this module.
303+
std::vector<Serialized<GenericSignature *>> GenericSignatures;
304+
302305
/// Generic environments referenced by this module.
303306
std::vector<Serialized<GenericEnvironment *>> GenericEnvironments;
304307

@@ -818,6 +821,9 @@ class ModuleFile
818821
/// is loaded instead.
819822
ModuleDecl *getModule(ArrayRef<Identifier> name);
820823

824+
/// Returns the generic signature for the given ID.
825+
GenericSignature *getGenericSignature(serialization::GenericSignatureID ID);
826+
821827
/// Returns the generic signature or environment for the given ID,
822828
/// deserializing it if needed.
823829
///

include/swift/Serialization/ModuleFormat.h

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const uint16_t VERSION_MAJOR = 0;
5454
/// in source control, you should also update the comment to briefly
5555
/// describe what change you made. The content of this comment isn't important;
5656
/// it just ensures a conflict if two people change the module format.
57-
const uint16_t VERSION_MINOR = 380; // Last change: IUO decl attribute
57+
const uint16_t VERSION_MINOR = 381; // Last change: generic signature
5858

5959
using DeclIDField = BCFixed<31>;
6060

@@ -77,6 +77,11 @@ using DeclContextIDField = DeclIDField;
7777
using NormalConformanceID = DeclID;
7878
using NormalConformanceIDField = DeclIDField;
7979

80+
// GenericSignatureID must be the same as DeclID because it is stored in the
81+
// same way.
82+
using GenericSignatureID = DeclID;
83+
using GenericSignatureIDField = DeclIDField;
84+
8085
// GenericEnvironmentID must be the same as DeclID because it is stored in the
8186
// same way.
8287
using GenericEnvironmentID = DeclID;
@@ -738,8 +743,7 @@ namespace decls_block {
738743
TypeIDField, // output
739744
FunctionTypeRepresentationField, // representation
740745
BCFixed<1>, // throws?
741-
BCArray<TypeIDField> // generic parameters
742-
// followed by requirements
746+
GenericSignatureIDField // generic signture
743747
>;
744748

745749
using SILFunctionTypeLayout = BCRecordLayout<
@@ -753,12 +757,11 @@ namespace decls_block {
753757
BCFixed<30>, // number of parameters
754758
BCFixed<30>, // number of yields
755759
BCFixed<30>, // number of results
760+
GenericSignatureIDField, // generic signature
756761
BCArray<TypeIDField> // parameter types/conventions, alternating
757762
// followed by result types/conventions, alternating
758763
// followed by error result type/convention
759-
// followed by generic parameter types
760764
// Optionally a protocol conformance (for witness_methods)
761-
// Trailed by its generic requirements, if any.
762765
>;
763766

764767
using SILBlockStorageTypeLayout = BCRecordLayout<
@@ -768,10 +771,9 @@ namespace decls_block {
768771

769772
using SILLayoutLayout = BCRecordLayout<
770773
SIL_LAYOUT,
774+
GenericSignatureIDField, // generic signature
771775
BCFixed<31>, // number of fields
772776
BCArray<TypeIDWithBitField> // field types with mutability
773-
// followed by generic parameters
774-
// trailed by generic requirements, if any
775777
>;
776778

777779
using SILBoxTypeLayout = BCRecordLayout<
@@ -1165,9 +1167,9 @@ namespace decls_block {
11651167
DeclIDField // Typealias
11661168
>;
11671169

1168-
using GenericEnvironmentLayout = BCRecordLayout<
1169-
GENERIC_ENVIRONMENT,
1170-
BCArray<TypeIDField> // sugared interface types
1170+
using GenericSignatureLayout = BCRecordLayout<
1171+
GENERIC_SIGNATURE,
1172+
BCArray<TypeIDField> // generic parameter types
11711173
>;
11721174

11731175
using SILGenericEnvironmentLayout = BCRecordLayout<
@@ -1282,8 +1284,8 @@ namespace decls_block {
12821284
using XRefExtensionPathPieceLayout = BCRecordLayout<
12831285
XREF_EXTENSION_PATH_PIECE,
12841286
ModuleIDField, // module ID
1285-
BCArray<TypeIDField> // for a constrained extension, the type parameters
1286-
// for a constrained extension, requirements follow
1287+
GenericSignatureIDField // for a constrained extension,
1288+
// the generic signature
12871289
>;
12881290

12891291
using XRefOperatorOrAccessorPathPieceLayout = BCRecordLayout<
@@ -1535,7 +1537,8 @@ namespace index_block {
15351537
NESTED_TYPE_DECLS,
15361538
DECL_MEMBER_NAMES,
15371539

1538-
LastRecordKind = DECL_MEMBER_NAMES,
1540+
GENERIC_SIGNATURE_OFFSETS,
1541+
LastRecordKind = GENERIC_SIGNATURE_OFFSETS,
15391542
};
15401543

15411544
constexpr const unsigned RecordIDFieldWidth = 5;

0 commit comments

Comments
 (0)