[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

@@ -1338,25 +1338,36 @@ Type ModuleFile::getType(TypeID TID) {
scratch.clear();
unsigned kind = DeclTypeCursor.readRecord(entry.ID, scratch);
if (kind != decls_block::ARCHETYPE_NESTED_TYPE_NAMES) {
error();
break;
}
ArrayRef<uint64_t> rawNameIDs;
decls_block::ArchetypeNestedTypeNamesLayout::readRecord(scratch,
rawNameIDs);
entry = DeclTypeCursor.advance();
if (entry.Kind != llvm::BitstreamEntry::Record) {
error();
break;
}
SmallVector<uint64_t, 16> scratch2;
kind = DeclTypeCursor.readRecord(entry.ID, scratch2);
if (kind != decls_block::ARCHETYPE_NESTED_TYPES) {
error();
break;
}
ArrayRef<uint64_t> rawTypeIDs;
decls_block::ArchetypeNestedTypesLayout::readRecord(scratch, rawTypeIDs);
decls_block::ArchetypeNestedTypesLayout::readRecord(scratch2, rawTypeIDs);
SmallVector<std::pair<Identifier, ArchetypeType *>, 4> nestedTypes;
for (TypeID nestedID : rawTypeIDs) {
if (nestedID == TID) {
nestedTypes.push_back(std::make_pair(ctx.getIdentifier("This"),
archetype));
} else {
auto nested = getType(nestedID)->castTo<ArchetypeType>();
nestedTypes.push_back(std::make_pair(nested->getName(),
nested));
}
}
for_each(rawNameIDs, rawTypeIDs, [&](IdentifierID nameID, TypeID nestedID) {
auto nestedTy = getType(nestedID)->castTo<ArchetypeType>();
nestedTypes.push_back(std::make_pair(getIdentifier(nameID), nestedTy));
});
archetype->setNestedTypes(ctx, nestedTypes);
break;