Skip to content

Commit 0297d8f

Browse files
committed
[Serialization] Move one type's deserialization into a method
...to prove it can be done.
1 parent cdadaad commit 0297d8f

File tree

1 file changed

+35
-34
lines changed

1 file changed

+35
-34
lines changed

lib/Serialization/Deserialization.cpp

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4283,6 +4283,39 @@ class swift::TypeDeserializer {
42834283
: MF(MF), ctx(MF.getContext()) {}
42844284

42854285
Expected<Type> getTypeCheckedImpl();
4286+
4287+
Expected<Type> deserializeBuiltinAliasType(ArrayRef<uint64_t> scratch,
4288+
StringRef blobData) {
4289+
DeclID underlyingID;
4290+
TypeID canonicalTypeID;
4291+
decls_block::BuiltinAliasTypeLayout::readRecord(scratch, underlyingID,
4292+
canonicalTypeID);
4293+
auto aliasOrError = MF.getDeclChecked(underlyingID);
4294+
if (!aliasOrError)
4295+
return aliasOrError.takeError();
4296+
auto alias = dyn_cast<TypeAliasDecl>(aliasOrError.get());
4297+
4298+
if (ctx.LangOpts.EnableDeserializationRecovery) {
4299+
Expected<Type> expectedType = MF.getTypeChecked(canonicalTypeID);
4300+
if (!expectedType)
4301+
return expectedType.takeError();
4302+
if (expectedType.get()) {
4303+
if (!alias ||
4304+
!alias->getDeclaredInterfaceType()->isEqual(expectedType.get())) {
4305+
// Fall back to the canonical type.
4306+
return expectedType.get();
4307+
}
4308+
}
4309+
}
4310+
4311+
// Look through compatibility aliases that are now unavailable.
4312+
if (alias->getAttrs().isUnavailable(ctx) &&
4313+
alias->isCompatibilityAlias()) {
4314+
return alias->getUnderlyingTypeLoc().getType();
4315+
}
4316+
4317+
return alias->getDeclaredInterfaceType();
4318+
}
42864319
};
42874320

42884321
Expected<Type> ModuleFile::getTypeChecked(TypeID TID) {
@@ -4336,40 +4369,8 @@ Expected<Type> TypeDeserializer::getTypeCheckedImpl() {
43364369
Type result;
43374370

43384371
switch (recordID) {
4339-
case decls_block::BUILTIN_ALIAS_TYPE: {
4340-
DeclID underlyingID;
4341-
TypeID canonicalTypeID;
4342-
decls_block::BuiltinAliasTypeLayout::readRecord(scratch, underlyingID,
4343-
canonicalTypeID);
4344-
auto aliasOrError = MF.getDeclChecked(underlyingID);
4345-
if (!aliasOrError)
4346-
return aliasOrError.takeError();
4347-
auto alias = dyn_cast<TypeAliasDecl>(aliasOrError.get());
4348-
4349-
if (ctx.LangOpts.EnableDeserializationRecovery) {
4350-
Expected<Type> expectedType = MF.getTypeChecked(canonicalTypeID);
4351-
if (!expectedType)
4352-
return expectedType.takeError();
4353-
if (expectedType.get()) {
4354-
if (!alias ||
4355-
!alias->getDeclaredInterfaceType()->isEqual(expectedType.get())) {
4356-
// Fall back to the canonical type.
4357-
result = expectedType.get();
4358-
break;
4359-
}
4360-
}
4361-
}
4362-
4363-
// Look through compatibility aliases that are now unavailable.
4364-
if (alias->getAttrs().isUnavailable(ctx) &&
4365-
alias->isCompatibilityAlias()) {
4366-
result = alias->getUnderlyingTypeLoc().getType();
4367-
break;
4368-
}
4369-
4370-
result = alias->getDeclaredInterfaceType();
4371-
break;
4372-
}
4372+
case decls_block::BUILTIN_ALIAS_TYPE:
4373+
return deserializeBuiltinAliasType(scratch, blobData);
43734374

43744375
case decls_block::NAME_ALIAS_TYPE: {
43754376
DeclID typealiasID;

0 commit comments

Comments
 (0)