Skip to content

Commit e3de9d5

Browse files
authored
Merge pull request #78153 from artemcm/ResolveImplicitConformancesDeserialization
[Deserialization] Use `swift::lookupConformance` to resolve implicit conformances
2 parents 0721124 + 4de76c8 commit e3de9d5

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)