Reimplement (de-)serialization of protocol conformances.

Primarily, unique normal protocol conformances and reference them via
a conformance ID. This eliminates the use of trailing records for
normal protocol conformances and (more importantly) the cases were we
would write incomplete conformances. The latter could cause problems
if we ever ended up deserializing an incomplete conformance without
also deserializing a complete record for that same conformance.

Secondarily, simplify the way we write conformances. They are now
always trailing records, and we separate out the derived conformance
kinds (specialized/inherited) from either a reference to a normal
conformance in the current module file (via a normal conformance ID)
or via a cross-reference to a conformance in another module file
(currently always a normal conformance, but this need not always be
the case). As part of this, make each conformance record
self-sustaining, so we don't have to push information down to the
reading routines (e.g., the conforming type) to actually produce a
proper conformance. This simplifies deserialization logic further.

Swift SVN r26482
This commit is contained in:
Doug Gregor
2015-03-24 06:48:23 +00:00
parent 683317e607
commit 8b97f911c6
10 changed files with 356 additions and 517 deletions

View File

@@ -239,6 +239,9 @@ private:
/// Local DeclContexts referenced by this module.
std::vector<Serialized<DeclContext*>> LocalDeclContexts;
/// Normal protocol conformances referenced by this module.
std::vector<Serialized<NormalProtocolConformance *>> NormalConformances;
/// Types referenced by this module.
std::vector<Serialized<Type>> Types;
@@ -636,23 +639,14 @@ public:
/// If the record at the cursor is not a substitution, returns None.
Optional<Substitution> maybeReadSubstitution(llvm::BitstreamCursor &Cursor);
/// Recursively reads a protocol conformance from \c DeclTypeCursor.
/// Recursively reads a protocol conformance from the given cursor.
///
/// The conformance will be newly-created; it's likely that it already exists
/// in the AST, and will need to be canonicalized.
///
/// If the record at the cursor is not a protocol conformance, returns
/// None. Note that a null pointer is a valid conformance value.
Optional<ProtocolConformance *>
maybeReadConformance(Type conformingType, llvm::BitstreamCursor &Cursor);
/// Note that a null conformance is valid for archetypes.
ProtocolConformance *readConformance(llvm::BitstreamCursor &Cursor);
/// Read a referenced conformance, such as the underlying conformance for a
/// specialized or inherited protocol conformance.
ProtocolConformance *
readReferencedConformance(ProtocolDecl *proto,
serialization::DeclID typeID,
serialization::ModuleID moduleID,
llvm::BitstreamCursor &Cursor);
/// Read the given normal conformance from the current module file.
NormalProtocolConformance *readNormalConformance(
serialization::NormalConformanceID id);
/// Reads a generic param list from \c DeclTypeCursor.
///