[serialization] Handle archetypes unified by a constraint.

Turns out we actually have to serialize the name of an archetype, because
it may be different from the declaration in a context where it has been
unified with another archetype. Found on attempting to emit a module for
the standard library.

(This is actually the commit that uses the two-container for_each
introduced in the last commit.)

Swift SVN r6172
This commit is contained in:
Jordan Rose
2013-07-11 21:12:46 +00:00
parent ceb3495ef0
commit 9b7ae1aa50
3 changed files with 36 additions and 14 deletions

View File

@@ -403,6 +403,7 @@ void Serializer::writeBlockInfoBlock() {
RECORD(decls_block, METATYPE_TYPE);
RECORD(decls_block, LVALUE_TYPE);
RECORD(decls_block, ARCHETYPE_TYPE);
RECORD(decls_block, ARCHETYPE_NESTED_TYPE_NAMES);
RECORD(decls_block, ARCHETYPE_NESTED_TYPES);
RECORD(decls_block, PROTOCOL_COMPOSITION_TYPE);
RECORD(decls_block, SUBSTITUTED_TYPE);
@@ -1240,14 +1241,17 @@ bool Serializer::writeType(Type ty) {
addTypeRef(archetypeTy->getSuperclass()),
conformances);
SmallVector<IdentifierID, 4> nestedTypeNames;
SmallVector<TypeID, 4> nestedTypes;
for (auto next : archetypeTy->getNestedTypes()) {
assert(next.first == next.second->getName() ||
(next.second == archetypeTy &&
next.first == TU->Ctx.getIdentifier("This")));
nestedTypeNames.push_back(addIdentifierRef(next.first));
nestedTypes.push_back(addTypeRef(next.second));
}
abbrCode = DeclTypeAbbrCodes[ArchetypeNestedTypeNamesLayout::Code];
ArchetypeNestedTypeNamesLayout::emitRecord(Out, ScratchRecord, abbrCode,
nestedTypeNames);
abbrCode = DeclTypeAbbrCodes[ArchetypeNestedTypesLayout::Code];
ArchetypeNestedTypesLayout::emitRecord(Out, ScratchRecord, abbrCode,
nestedTypes);
@@ -1406,6 +1410,7 @@ void Serializer::writeAllDeclsAndTypes() {
registerDeclTypeAbbr<MetaTypeTypeLayout>();
registerDeclTypeAbbr<LValueTypeLayout>();
registerDeclTypeAbbr<ArchetypeTypeLayout>();
registerDeclTypeAbbr<ArchetypeNestedTypeNamesLayout>();
registerDeclTypeAbbr<ArchetypeNestedTypesLayout>();
registerDeclTypeAbbr<ProtocolCompositionTypeLayout>();
registerDeclTypeAbbr<SubstitutedTypeLayout>();