Skip to content

Commit e764fe8

Browse files
committed
SILCloner: allow builtin conformances
When cloning SIL, it's OK for conformances to Copyable or Escapable to be carried-over as a builtin conformance, rather than an abstract conformance. This is a workaround for a bug introduced in `6cd5468cceacc1d600c7dafdd4debc6740d1dfd6`. resolves rdar://125460667 (cherry picked from commit abae144)
1 parent f0d6bfa commit e764fe8

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

include/swift/AST/Type.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,17 @@ class MakeAbstractConformanceForGenericType {
126126
ProtocolDecl *conformedProtocol) const;
127127
};
128128

129+
/// Functor class suitable for use as a \c LookupConformanceFn that provides
130+
/// only abstract conformances, or builtin conformances for invertible protocols
131+
/// for generic types. Asserts that the replacement
132+
/// type is an opaque generic type.
133+
class MakeAbstractOrBuiltinConformanceForGenericType {
134+
public:
135+
ProtocolConformanceRef operator()(CanType dependentType,
136+
Type conformingReplacementType,
137+
ProtocolDecl *conformedProtocol) const;
138+
};
139+
129140
/// Functor class suitable for use as a \c LookupConformanceFn that fetches
130141
/// conformances from a generic signature.
131142
class LookUpConformanceInSignature {

include/swift/SIL/SILCloner.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ class SILCloner : protected SILInstructionVisitor<ImplClass> {
196196
// If we found a type containing a local archetype, substitute
197197
// open existentials throughout the substitution map.
198198
Subs = Subs.subst(QueryTypeSubstitutionMapOrIdentity{LocalArchetypeSubs},
199-
MakeAbstractConformanceForGenericType());
199+
MakeAbstractOrBuiltinConformanceForGenericType());
200200
}
201201
}
202202

@@ -219,7 +219,7 @@ class SILCloner : protected SILInstructionVisitor<ImplClass> {
219219
return Ty.subst(
220220
Builder.getModule(),
221221
QueryTypeSubstitutionMapOrIdentity{LocalArchetypeSubs},
222-
MakeAbstractConformanceForGenericType(),
222+
MakeAbstractOrBuiltinConformanceForGenericType(),
223223
CanGenericSignature());
224224
}
225225
SILType getOpType(SILType Ty) {
@@ -239,7 +239,7 @@ class SILCloner : protected SILInstructionVisitor<ImplClass> {
239239

240240
return ty.subst(
241241
QueryTypeSubstitutionMapOrIdentity{LocalArchetypeSubs},
242-
MakeAbstractConformanceForGenericType()
242+
MakeAbstractOrBuiltinConformanceForGenericType()
243243
)->getCanonicalType();
244244
}
245245

@@ -352,7 +352,7 @@ class SILCloner : protected SILInstructionVisitor<ImplClass> {
352352
conformance.subst(ty,
353353
QueryTypeSubstitutionMapOrIdentity{
354354
LocalArchetypeSubs},
355-
MakeAbstractConformanceForGenericType());
355+
MakeAbstractOrBuiltinConformanceForGenericType());
356356
}
357357

358358
return asImpl().remapConformance(getASTTypeInClonedContext(ty),

lib/AST/TypeSubstitution.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,22 @@ operator()(CanType dependentType, Type conformingReplacementType,
230230
return Subs.lookupConformance(dependentType, conformedProtocol);
231231
}
232232

233+
ProtocolConformanceRef MakeAbstractOrBuiltinConformanceForGenericType::
234+
operator()(CanType dependentType, Type conformingReplacementType,
235+
ProtocolDecl *conformedProtocol) const {
236+
// Workaround for rdar://125460667
237+
if (conformedProtocol->getInvertibleProtocolKind()) {
238+
auto &ctx = conformedProtocol->getASTContext();
239+
return ProtocolConformanceRef(
240+
ctx.getBuiltinConformance(conformingReplacementType, conformedProtocol,
241+
BuiltinConformanceKind::Synthesized));
242+
}
243+
244+
return MakeAbstractConformanceForGenericType()(dependentType,
245+
conformingReplacementType,
246+
conformedProtocol);
247+
}
248+
233249
ProtocolConformanceRef MakeAbstractConformanceForGenericType::
234250
operator()(CanType dependentType, Type conformingReplacementType,
235251
ProtocolDecl *conformedProtocol) const {

0 commit comments

Comments
 (0)