mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[Serialization] Drop typealiases whose underlying types have changed. (#8896)
In order to accomplish this, cross-module references to typealiases are now banned except from within conformances and NameAliasTypes, the latter of which records the canonical type to determine if the typealias has changed. For conformances, we don't have a good way to check if the typealias has changed without trying to map it into context, but that's all right---the rest of the compiler can already fall back to the canonical type.
This commit is contained in:
@@ -432,7 +432,8 @@ DeclContextID Serializer::addDeclContextRef(const DeclContext *DC) {
|
||||
return id;
|
||||
}
|
||||
|
||||
DeclID Serializer::addDeclRef(const Decl *D, bool forceSerialization) {
|
||||
DeclID Serializer::addDeclRef(const Decl *D, bool forceSerialization,
|
||||
bool allowTypeAliasXRef) {
|
||||
if (!D)
|
||||
return 0;
|
||||
|
||||
@@ -447,6 +448,10 @@ DeclID Serializer::addDeclRef(const Decl *D, bool forceSerialization) {
|
||||
isa<PrecedenceGroupDecl>(D)) &&
|
||||
"cannot cross-reference this decl");
|
||||
|
||||
assert((allowTypeAliasXRef || !isa<TypeAliasDecl>(D) ||
|
||||
D->getModuleContext() == M) &&
|
||||
"cannot cross-reference typealiases directly (use the NameAliasType)");
|
||||
|
||||
id = { ++LastDeclID, forceSerialization };
|
||||
DeclsAndTypesToWrite.push(D);
|
||||
return id.first;
|
||||
@@ -1326,7 +1331,8 @@ void Serializer::writeNormalConformance(
|
||||
Type type, TypeDecl *typeDecl) {
|
||||
data.push_back(addDeclRef(assocType));
|
||||
data.push_back(addTypeRef(type));
|
||||
data.push_back(addDeclRef(typeDecl));
|
||||
data.push_back(addDeclRef(typeDecl, /*forceSerialization*/false,
|
||||
/*allowTypeAliasXRef*/true));
|
||||
++numTypeWitnesses;
|
||||
return false;
|
||||
});
|
||||
@@ -3118,7 +3124,10 @@ void Serializer::writeType(Type ty) {
|
||||
|
||||
unsigned abbrCode = DeclTypeAbbrCodes[NameAliasTypeLayout::Code];
|
||||
NameAliasTypeLayout::emitRecord(Out, ScratchRecord, abbrCode,
|
||||
addDeclRef(typeAlias));
|
||||
addDeclRef(typeAlias,
|
||||
/*forceSerialization*/false,
|
||||
/*allowTypeAliasXRef*/true),
|
||||
TypeID());
|
||||
break;
|
||||
}
|
||||
case TypeKind::NameAlias: {
|
||||
@@ -3127,7 +3136,10 @@ void Serializer::writeType(Type ty) {
|
||||
|
||||
unsigned abbrCode = DeclTypeAbbrCodes[NameAliasTypeLayout::Code];
|
||||
NameAliasTypeLayout::emitRecord(Out, ScratchRecord, abbrCode,
|
||||
addDeclRef(typeAlias));
|
||||
addDeclRef(typeAlias,
|
||||
/*forceSerialization*/false,
|
||||
/*allowTypeAliasXRef*/true),
|
||||
addTypeRef(ty->getCanonicalType()));
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user