[Serialization] Keep indirect conformances knowledge with safety

Given a scenario where a public type A, conforms to an internal protocol
B, which conforms to a public protocol C. A conforms indirectly to C
through a protocol that's hidden from the clients.

This is handled in module interface by printing the indirect conformance
of A to C explicitly at the end of the swiftinterface.

We have the same problem with deserialization safety that used to hide
the internal protocols from clients, thus breaking the knowledge of the
indirect dependency. To keep the indirect conformances, let's consider
all protocols as safe and preserve their conformance information.

rdar://105241772
This commit is contained in:
Alexis Laferrière
2023-04-11 15:43:01 -07:00
committed by Alexis Laferrière
parent 08af8a657f
commit 9602df1e83
4 changed files with 66 additions and 14 deletions

View File

@@ -3124,14 +3124,11 @@ class Serializer::DeclSerializer : public DeclVisitor<DeclSerializer> {
if (hasSafeMembers)
return true;
// We can mark the extension unsafe only if it has no public
// We can mark the extension unsafe only if it has no public
// conformances.
auto protocols = ext->getLocalProtocols(
ConformanceLookupKind::OnlyExplicit);
bool hasSafeConformances = std::any_of(protocols.begin(),
protocols.end(),
isDeserializationSafe);
if (hasSafeConformances)
if (!protocols.empty())
return true;
// Truly empty extensions are safe, it may happen in swiftinterfaces.
@@ -3141,6 +3138,9 @@ class Serializer::DeclSerializer : public DeclVisitor<DeclSerializer> {
return false;
}
if (isa<ProtocolDecl>(decl))
return true;
auto value = cast<ValueDecl>(decl);
// A decl is safe if formally accessible publicly.