mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[serialization] Add support for generic requirements.
Same-type requirements aren't tested yet because there's currently no support for associated types. This includes an improvement to BCRecordLayout: array elements can be passed inline, and the static checks that the data count matches the field count will take this into account. Swift SVN r5984
This commit is contained in:
@@ -386,6 +386,7 @@ void Serializer::writeBlockInfoBlock() {
|
||||
|
||||
RECORD(decls_block, GENERIC_PARAM_LIST);
|
||||
RECORD(decls_block, GENERIC_PARAM);
|
||||
RECORD(decls_block, GENERIC_REQUIREMENT);
|
||||
|
||||
RECORD(decls_block, XREF);
|
||||
RECORD(decls_block, DECL_CONTEXT);
|
||||
@@ -549,10 +550,6 @@ bool Serializer::writeGenericParams(const GenericParamList *genericParams) {
|
||||
if (!genericParams)
|
||||
return true;
|
||||
|
||||
// FIXME: Handle generic requirements.
|
||||
if (!genericParams->getRequirements().empty())
|
||||
return false;
|
||||
|
||||
SmallVector<TypeID, 8> archetypeIDs;
|
||||
for (auto archetype : genericParams->getAllArchetypes())
|
||||
archetypeIDs.push_back(addTypeRef(archetype));
|
||||
@@ -567,6 +564,24 @@ bool Serializer::writeGenericParams(const GenericParamList *genericParams) {
|
||||
addDeclRef(next.getDecl()));
|
||||
}
|
||||
|
||||
abbrCode = DeclTypeAbbrCodes[GenericRequirementLayout::Code];
|
||||
for (auto next : genericParams->getRequirements()) {
|
||||
switch (next.getKind()) {
|
||||
case RequirementKind::Conformance:
|
||||
GenericRequirementLayout::emitRecord(Out, ScratchRecord, abbrCode,
|
||||
GenericRequirementKind::Conformance,
|
||||
addTypeRef(next.getSubject()),
|
||||
addTypeRef(next.getConstraint()));
|
||||
break;
|
||||
case RequirementKind::SameType:
|
||||
GenericRequirementLayout::emitRecord(Out, ScratchRecord, abbrCode,
|
||||
GenericRequirementKind::SameType,
|
||||
addTypeRef(next.getFirstType()),
|
||||
addTypeRef(next.getSecondType()));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1112,6 +1127,7 @@ void Serializer::writeAllDeclsAndTypes() {
|
||||
|
||||
registerDeclTypeAbbr<GenericParamListLayout>();
|
||||
registerDeclTypeAbbr<GenericParamLayout>();
|
||||
registerDeclTypeAbbr<GenericRequirementLayout>();
|
||||
registerDeclTypeAbbr<XRefLayout>();
|
||||
registerDeclTypeAbbr<DeclContextLayout>();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user