[serialization] Add support for UnboundGenericTypes.

I had previously thought these didn't appear in public decls, but they're
used when you extend a generic class without generic arguments.

Swift SVN r6187
This commit is contained in:
Jordan Rose
2013-07-11 23:35:25 +00:00
parent 37d9ae4e09
commit e0301b6037
3 changed files with 29 additions and 2 deletions

View File

@@ -1601,6 +1601,17 @@ Type ModuleFile::getType(TypeID TID) {
break;
}
case decls_block::UNBOUND_GENERIC_TYPE: {
DeclID genericID;
TypeID parentID;
decls_block::UnboundGenericTypeLayout::readRecord(scratch,
genericID, parentID);
auto genericDecl = cast<NominalTypeDecl>(getDecl(genericID));
typeOrOffset = UnboundGenericType::get(genericDecl, getType(parentID), ctx);
break;
}
default:
// We don't know how to deserialize this kind of type.
error();

View File

@@ -226,6 +226,7 @@ namespace decls_block {
ARRAY_SLICE_TYPE,
ARRAY_TYPE,
REFERENCE_STORAGE_TYPE,
UNBOUND_GENERIC_TYPE,
TYPE_ALIAS_DECL = 100,
STRUCT_DECL,
@@ -391,6 +392,12 @@ namespace decls_block {
TypeIDField // implementation type
>;
using UnboundGenericTypeLayout = BCRecordLayout<
UNBOUND_GENERIC_TYPE,
DeclIDField, // generic decl
TypeIDField // parent
>;
using TypeAliasLayout = BCRecordLayout<
TYPE_ALIAS_DECL,

View File

@@ -413,6 +413,7 @@ void Serializer::writeBlockInfoBlock() {
RECORD(decls_block, ARRAY_SLICE_TYPE);
RECORD(decls_block, ARRAY_TYPE);
RECORD(decls_block, REFERENCE_STORAGE_TYPE);
RECORD(decls_block, UNBOUND_GENERIC_TYPE);
RECORD(decls_block, TYPE_ALIAS_DECL);
RECORD(decls_block, STRUCT_DECL);
@@ -1403,8 +1404,15 @@ bool Serializer::writeType(Type ty) {
return true;
}
case TypeKind::UnboundGeneric:
return false;
case TypeKind::UnboundGeneric: {
auto generic = cast<UnboundGenericType>(ty.getPointer());
unsigned abbrCode = DeclTypeAbbrCodes[UnboundGenericTypeLayout::Code];
UnboundGenericTypeLayout::emitRecord(Out, ScratchRecord, abbrCode,
addDeclRef(generic->getDecl()),
addTypeRef(generic->getParent()));
return true;
}
case TypeKind::BoundGenericClass:
case TypeKind::BoundGenericOneOf:
@@ -1463,6 +1471,7 @@ void Serializer::writeAllDeclsAndTypes() {
registerDeclTypeAbbr<PolymorphicFunctionTypeLayout>();
registerDeclTypeAbbr<ArraySliceTypeLayout>();
registerDeclTypeAbbr<ArrayTypeLayout>();
registerDeclTypeAbbr<UnboundGenericTypeLayout>();
registerDeclTypeAbbr<TypeAliasLayout>();
registerDeclTypeAbbr<StructLayout>();