Skip to content

Commit 4de76c8

Browse files
committed
[Deserialization] Use 'swift::lookupConformance' to resolve implicit conformances
On reading out a 'ProtocolConformanceXrefLayout', instead of querying the protocol on the 'NominalDecl' referenced by the Xref, use the general-purpose lookup that resolves implicit conformances to e.g. 'Sendable'. Otherwise, we can end up in a situation where a library serializes some type as (implicitly) conforming to Sendable, but the client, upon deserialization, has not yet run implicit Sendable inference logic, so its representation of said type will not match.
1 parent 8f7e71a commit 4de76c8

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

lib/Serialization/Deserialization.cpp

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "swift/AST/Attr.h"
1919
#include "swift/AST/AttrKind.h"
2020
#include "swift/AST/AutoDiff.h"
21+
#include "swift/AST/ConformanceLookup.h"
2122
#include "swift/AST/DiagnosticsSema.h"
2223
#include "swift/AST/DistributedDecl.h"
2324
#include "swift/AST/Expr.h"
@@ -957,16 +958,29 @@ ProtocolConformanceDeserializer::readNormalProtocolConformanceXRef(
957958
if (!module)
958959
module = MF.getAssociatedModule();
959960

960-
SmallVector<ProtocolConformance *, 2> conformances;
961-
nominal->lookupConformance(proto, conformances);
962961
PrettyStackTraceModuleFile traceMsg(
963962
"If you're seeing a crash here, check that your SDK and dependencies "
964963
"are at least as new as the versions used to build", MF);
965-
// This would normally be an assertion but it's more useful to print the
966-
// PrettyStackTrace here even in no-asserts builds.
967-
if (conformances.empty())
968-
abort();
969-
return conformances.front();
964+
965+
// Because Sendable conformances are currently inferred with
966+
// 'ImplicitKnownProtocolConformanceRequest' in swift::lookupConformance,
967+
// we may end up in a situation where we are deserializing such inferred
968+
// conformance but a lookup on the 'NominalDecl' will not succeed nor
969+
// will it run inference logic. For now, special-case 'Sendable' lookups
970+
// here.
971+
// TODO: Sink Sendable derivation into the conformance lookup table
972+
if (proto->isSpecificProtocol(KnownProtocolKind::Sendable)) {
973+
auto conformanceRef = lookupConformance(nominal->getDeclaredInterfaceType(), proto);
974+
if (!conformanceRef.isConcrete())
975+
abort();
976+
return conformanceRef.getConcrete();
977+
} else {
978+
SmallVector<ProtocolConformance *, 2> conformances;
979+
nominal->lookupConformance(proto, conformances);
980+
if (conformances.empty())
981+
abort();
982+
return conformances.front();
983+
}
970984
}
971985

972986
Expected<ProtocolConformance *>

0 commit comments

Comments
 (0)