Skip to content

Commit 0ee1a07

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
1 parent 2f44b0a commit 0ee1a07

File tree

3 files changed

+38
-4
lines changed

3 files changed

+38
-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: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,29 @@ 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+
MakeAbstractConformanceForGenericType useAbstract;
237+
if (conformingReplacementType->is<PackType>()) {
238+
return useAbstract(dependentType,
239+
conformingReplacementType,
240+
conformedProtocol);
241+
}
242+
243+
// Workaround for rdar://125460667
244+
if (conformedProtocol->getInvertibleProtocolKind()) {
245+
auto &ctx = conformedProtocol->getASTContext();
246+
return ProtocolConformanceRef(
247+
ctx.getBuiltinConformance(conformingReplacementType, conformedProtocol,
248+
BuiltinConformanceKind::Synthesized));
249+
}
250+
251+
return useAbstract(dependentType,
252+
conformingReplacementType,
253+
conformedProtocol);
254+
}
255+
233256
ProtocolConformanceRef MakeAbstractConformanceForGenericType::
234257
operator()(CanType dependentType, Type conformingReplacementType,
235258
ProtocolDecl *conformedProtocol) const {

0 commit comments

Comments
 (0)