[Serialization] Serialize archetypes as generic environment + interface type.

Rather than serializing the complete structure of all archetypes
(which is completely redundant), serialize a reference to their owning
generic environment as well as their interface type. The archetype
itself will be reconsituted by mapping the interface type into that
generic environment.
This commit is contained in:
Doug Gregor
2017-02-07 17:02:38 -08:00
parent 2307e15290
commit 90f021485d
5 changed files with 60 additions and 194 deletions

View File

@@ -1110,7 +1110,6 @@ void Serializer::writeGenericEnvironment(const GenericEnvironment *env) {
}
rawParamIDs.push_back(addTypeRef(paramTy));
rawParamIDs.push_back(addTypeRef(env->mapTypeIntoContext(paramTy)));
}
if (SILMode) {
@@ -3139,44 +3138,15 @@ void Serializer::writeType(Type ty) {
break;
}
SmallVector<DeclID, 4> conformances;
for (auto proto : archetypeTy->getConformsTo())
conformances.push_back(addDeclRef(proto));
auto env = archetypeTy->getGenericEnvironment();
assert(env && "Primary archetype without generic environment?");
TypeID parentOrGenericEnv;
DeclID assocTypeOrNameID;
if (archetypeTy->getParent()) {
parentOrGenericEnv = addTypeRef(archetypeTy->getParent());
assocTypeOrNameID = addDeclRef(archetypeTy->getAssocType());
} else {
parentOrGenericEnv =
addGenericEnvironmentRef(archetypeTy->getGenericEnvironment());
assocTypeOrNameID = addIdentifierRef(archetypeTy->getName());
}
GenericEnvironmentID envID = addGenericEnvironmentRef(env);
Type interfaceType = env->mapTypeOutOfContext(archetypeTy);
unsigned abbrCode = DeclTypeAbbrCodes[ArchetypeTypeLayout::Code];
ArchetypeTypeLayout::emitRecord(Out, ScratchRecord, abbrCode,
archetypeTy->isPrimary(),
parentOrGenericEnv,
assocTypeOrNameID,
addTypeRef(archetypeTy->getSuperclass()),
conformances);
SmallVector<IdentifierID, 4> nestedTypeNames;
SmallVector<TypeID, 4> nestedTypes;
for (auto next : archetypeTy->getAllNestedTypes()) {
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);
envID, addTypeRef(interfaceType));
break;
}
@@ -3452,8 +3422,6 @@ void Serializer::writeAllDeclsAndTypes() {
registerDeclTypeAbbr<LValueTypeLayout>();
registerDeclTypeAbbr<InOutTypeLayout>();
registerDeclTypeAbbr<ArchetypeTypeLayout>();
registerDeclTypeAbbr<ArchetypeNestedTypeNamesLayout>();
registerDeclTypeAbbr<ArchetypeNestedTypesLayout>();
registerDeclTypeAbbr<ProtocolCompositionTypeLayout>();
registerDeclTypeAbbr<BoundGenericTypeLayout>();
registerDeclTypeAbbr<BoundGenericSubstitutionLayout>();