Skip to content

SILCloner: allow builtin conformances #72683

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions include/swift/AST/Type.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,17 @@ class MakeAbstractConformanceForGenericType {
ProtocolDecl *conformedProtocol) const;
};

/// Functor class suitable for use as a \c LookupConformanceFn that provides
/// only abstract conformances, or builtin conformances for invertible protocols
/// for generic types. Asserts that the replacement
/// type is an opaque generic type.
class MakeAbstractOrBuiltinConformanceForGenericType {
public:
ProtocolConformanceRef operator()(CanType dependentType,
Type conformingReplacementType,
ProtocolDecl *conformedProtocol) const;
};

/// Functor class suitable for use as a \c LookupConformanceFn that fetches
/// conformances from a generic signature.
class LookUpConformanceInSignature {
Expand Down
8 changes: 4 additions & 4 deletions include/swift/SIL/SILCloner.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ class SILCloner : protected SILInstructionVisitor<ImplClass> {
// If we found a type containing a local archetype, substitute
// open existentials throughout the substitution map.
Subs = Subs.subst(QueryTypeSubstitutionMapOrIdentity{LocalArchetypeSubs},
MakeAbstractConformanceForGenericType());
MakeAbstractOrBuiltinConformanceForGenericType());
}
}

Expand All @@ -219,7 +219,7 @@ class SILCloner : protected SILInstructionVisitor<ImplClass> {
return Ty.subst(
Builder.getModule(),
QueryTypeSubstitutionMapOrIdentity{LocalArchetypeSubs},
MakeAbstractConformanceForGenericType(),
MakeAbstractOrBuiltinConformanceForGenericType(),
CanGenericSignature());
}
SILType getOpType(SILType Ty) {
Expand All @@ -239,7 +239,7 @@ class SILCloner : protected SILInstructionVisitor<ImplClass> {

return ty.subst(
QueryTypeSubstitutionMapOrIdentity{LocalArchetypeSubs},
MakeAbstractConformanceForGenericType()
MakeAbstractOrBuiltinConformanceForGenericType()
)->getCanonicalType();
}

Expand Down Expand Up @@ -352,7 +352,7 @@ class SILCloner : protected SILInstructionVisitor<ImplClass> {
conformance.subst(ty,
QueryTypeSubstitutionMapOrIdentity{
LocalArchetypeSubs},
MakeAbstractConformanceForGenericType());
MakeAbstractOrBuiltinConformanceForGenericType());
}

return asImpl().remapConformance(getASTTypeInClonedContext(ty),
Expand Down
16 changes: 16 additions & 0 deletions lib/AST/TypeSubstitution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,22 @@ operator()(CanType dependentType, Type conformingReplacementType,
return Subs.lookupConformance(dependentType, conformedProtocol);
}

ProtocolConformanceRef MakeAbstractOrBuiltinConformanceForGenericType::
operator()(CanType dependentType, Type conformingReplacementType,
ProtocolDecl *conformedProtocol) const {
// Workaround for rdar://125460667
if (conformedProtocol->getInvertibleProtocolKind()) {
auto &ctx = conformedProtocol->getASTContext();
return ProtocolConformanceRef(
ctx.getBuiltinConformance(conformingReplacementType, conformedProtocol,
BuiltinConformanceKind::Synthesized));
}

return MakeAbstractConformanceForGenericType()(dependentType,
conformingReplacementType,
conformedProtocol);
}

ProtocolConformanceRef MakeAbstractConformanceForGenericType::
operator()(CanType dependentType, Type conformingReplacementType,
ProtocolDecl *conformedProtocol) const {
Expand Down