mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Rework the serialization schema for conformances and requirements.
We now schedule conformance emissions in basically the same way we do for types and declarations, which means that we'll emit them uniquely in the module file instead of redundantly at every use. This should produce substantially smaller module files overall, especially for modules that heavily use generics. It also means that we can remove all the unfortunate code to support using different abbrev codes for them in different bitcode blocks. Requirement lists are now emitted inline in the records that need them instead of as trailing records. I think this will improve space usage, but mostly it assists in eliminating the problem where abbrev codes are shared between blocks.
This commit is contained in:
@@ -222,9 +222,9 @@ class Serializer : public SerializerBase {
|
||||
index_block::SUBSTITUTION_MAP_OFFSETS>
|
||||
SubstitutionMapsToSerialize;
|
||||
|
||||
ASTBlockRecordKeeper<const NormalProtocolConformance *, NormalConformanceID,
|
||||
index_block::NORMAL_CONFORMANCE_OFFSETS>
|
||||
NormalConformancesToSerialize;
|
||||
ASTBlockRecordKeeper<ProtocolConformance *, ProtocolConformanceID,
|
||||
index_block::PROTOCOL_CONFORMANCE_OFFSETS>
|
||||
ConformancesToSerialize;
|
||||
|
||||
ASTBlockRecordKeeper<const SILLayout *, SILLayoutID,
|
||||
index_block::SIL_LAYOUT_OFFSETS>
|
||||
@@ -296,11 +296,13 @@ private:
|
||||
/// This is for Named Lazy Member Loading.
|
||||
DeclMemberNamesTable DeclMemberNames;
|
||||
|
||||
enum {NumDeclTypeAbbrCodes = 512};
|
||||
|
||||
/// The abbreviation code for each record in the "decls-and-types" block.
|
||||
///
|
||||
/// These are registered up front when entering the block, so they can be
|
||||
/// reused.
|
||||
std::array<unsigned, 256> DeclTypeAbbrCodes;
|
||||
std::array<unsigned, NumDeclTypeAbbrCodes> DeclTypeAbbrCodes;
|
||||
|
||||
/// The decls that adopt compiler-known protocols.
|
||||
SmallVector<DeclID, 2> KnownProtocolAdopters[NumKnownProtocols];
|
||||
@@ -316,14 +318,6 @@ private:
|
||||
/// modules and its source files.
|
||||
void writeInputBlock(const SerializationOptions &options);
|
||||
|
||||
/// Writes a list of protocol conformances.
|
||||
void writeConformances(ArrayRef<ProtocolConformanceRef> conformances,
|
||||
const std::array<unsigned, 256> &abbrCodes);
|
||||
|
||||
/// Writes a list of protocol conformances.
|
||||
void writeConformances(ArrayRef<ProtocolConformance*> conformances,
|
||||
const std::array<unsigned, 256> &abbrCodes);
|
||||
|
||||
/// Check if a decl is cross-referenced.
|
||||
bool isDeclXRef(const Decl *D) const;
|
||||
|
||||
@@ -361,6 +355,10 @@ private:
|
||||
/// Writes a substitution map.
|
||||
void writeASTBlockEntity(const SubstitutionMap substitutions);
|
||||
|
||||
/// Writes a protocol conformance.
|
||||
void writeASTBlockEntity(ProtocolConformance *conformance);
|
||||
void writeLocalNormalProtocolConformance(NormalProtocolConformance *);
|
||||
|
||||
/// Registers the abbreviation for the given decl or type layout.
|
||||
template <typename Layout>
|
||||
void registerDeclTypeAbbr() {
|
||||
@@ -489,14 +487,26 @@ public:
|
||||
/// The SubstitutionMap will be scheduled for serialization if necessary.
|
||||
SubstitutionMapID addSubstitutionMapRef(SubstitutionMap substitutions);
|
||||
|
||||
/// Records the use of the given normal protocol conformance.
|
||||
/// Records the use of the given protocol conformance.
|
||||
///
|
||||
/// The normal protocol conformance will be scheduled for
|
||||
/// serialization if necessary.
|
||||
/// The protocol conformance will be scheduled for serialization
|
||||
/// if necessary.
|
||||
///
|
||||
/// \param genericEnv When provided, the generic environment that describes
|
||||
/// the archetypes within the substitutions. The replacement types within
|
||||
/// the substitution will be mapped out of the generic environment before
|
||||
/// being written.
|
||||
///
|
||||
/// \returns The ID for the given conformance in this module.
|
||||
NormalConformanceID addConformanceRef(
|
||||
const NormalProtocolConformance *conformance);
|
||||
ProtocolConformanceID addConformanceRef(ProtocolConformance *conformance,
|
||||
GenericEnvironment *genericEnv = nullptr);
|
||||
ProtocolConformanceID addConformanceRef(ProtocolConformanceRef conformance,
|
||||
GenericEnvironment *genericEnv = nullptr);
|
||||
|
||||
SmallVector<ProtocolConformanceID, 4>
|
||||
addConformanceRefs(ArrayRef<ProtocolConformanceRef> conformances);
|
||||
SmallVector<ProtocolConformanceID, 4>
|
||||
addConformanceRefs(ArrayRef<ProtocolConformance *> conformances);
|
||||
|
||||
/// Records the use of the given SILLayout.
|
||||
SILLayoutID addSILLayoutRef(const SILLayout *layout);
|
||||
@@ -515,39 +525,20 @@ public:
|
||||
/// Records the module \m.
|
||||
IdentifierID addModuleRef(const ModuleDecl *m);
|
||||
|
||||
/// Write a normal protocol conformance.
|
||||
void writeASTBlockEntity(const NormalProtocolConformance *conformance);
|
||||
|
||||
/// Write a SILLayout.
|
||||
void writeASTBlockEntity(const SILLayout *layout);
|
||||
|
||||
/// Writes a protocol conformance.
|
||||
///
|
||||
/// \param genericEnv When provided, the generic environment that describes
|
||||
/// the archetypes within the substitutions. The replacement types within
|
||||
/// the substitution will be mapped out of the generic environment before
|
||||
/// being written.
|
||||
void writeConformance(ProtocolConformanceRef conformance,
|
||||
const std::array<unsigned, 256> &abbrCodes,
|
||||
GenericEnvironment *genericEnv = nullptr);
|
||||
|
||||
/// Writes a protocol conformance.
|
||||
void writeConformance(ProtocolConformance *conformance,
|
||||
const std::array<unsigned, 256> &abbrCodes,
|
||||
GenericEnvironment *genericEnv = nullptr);
|
||||
|
||||
/// Writes a set of generic requirements.
|
||||
void writeGenericRequirements(ArrayRef<Requirement> requirements,
|
||||
const std::array<unsigned, 256> &abbrCodes);
|
||||
/// Adds an encoding of the given list of generic requirements to
|
||||
/// the given list of values.
|
||||
void serializeGenericRequirements(ArrayRef<Requirement> requirements,
|
||||
SmallVectorImpl<uint64_t> &scratch);
|
||||
|
||||
/// Writes a protocol's requirement signature, consisting of a list of
|
||||
/// generic requirements and a list of protocol typealias records.
|
||||
void writeRequirementSignature(const RequirementSignature &requirementSig,
|
||||
const std::array<unsigned, 256> &abbrCodes);
|
||||
void writeRequirementSignature(const RequirementSignature &requirementSig);
|
||||
|
||||
/// Writes a protocol's associated type table.
|
||||
void writeAssociatedTypes(ArrayRef<AssociatedTypeDecl *> assocTypes,
|
||||
const std::array<unsigned, 256> &abbrCodes);
|
||||
void writeAssociatedTypes(ArrayRef<AssociatedTypeDecl *> assocTypes);
|
||||
|
||||
bool allowCompilerErrors() const;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user