Skip to content

Commit 6027bf4

Browse files
committed
AST: Simplify collectExistentialConformances()
1 parent e3ff1dd commit 6027bf4

File tree

11 files changed

+32
-85
lines changed

11 files changed

+32
-85
lines changed

include/swift/AST/Module.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -862,11 +862,8 @@ class ModuleDecl
862862

863863
/// Collect the conformances of \c fromType to each of the protocols of an
864864
/// existential type's layout.
865-
///
866-
/// See `TypeChecker::containsProtocol` for details on the boolean arguments.
867865
ArrayRef<ProtocolConformanceRef>
868866
collectExistentialConformances(CanType fromType, CanType existential,
869-
bool skipConditionalRequirements = true,
870867
bool allowMissing = false);
871868

872869
/// Find a member named \p name in \p container that was declared in this

include/swift/AST/TypeCheckRequests.h

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -323,30 +323,6 @@ class ExistentialConformsToSelfRequest :
323323
void cacheResult(bool value) const;
324324
};
325325

326-
class CollectExistentialConformancesRequest
327-
: public SimpleRequest<CollectExistentialConformancesRequest,
328-
ArrayRef<ProtocolConformanceRef>(ModuleDecl*,
329-
CanType,
330-
CanType,
331-
bool,
332-
bool),
333-
RequestFlags::Uncached> { // TODO: maybe cache this?
334-
public:
335-
using SimpleRequest::SimpleRequest;
336-
337-
private:
338-
friend SimpleRequest;
339-
340-
// Evaluation.
341-
ArrayRef<ProtocolConformanceRef>
342-
evaluate(Evaluator &evaluator,
343-
ModuleDecl *module,
344-
CanType fromType,
345-
CanType existential,
346-
bool skipConditionalRequirements,
347-
bool allowMissing) const;
348-
};
349-
350326
/// Determine whether an existential type conforming to this protocol
351327
/// requires the \c any syntax.
352328
class HasSelfOrAssociatedTypeRequirementsRequest :

include/swift/AST/TypeCheckerTypeIDZone.def

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,6 @@ SWIFT_REQUEST(TypeChecker, EnumRawTypeRequest,
101101
Type(EnumDecl *), Cached, NoLocationInfo)
102102
SWIFT_REQUEST(TypeChecker, ExistentialConformsToSelfRequest,
103103
bool(ProtocolDecl *), SeparatelyCached, NoLocationInfo)
104-
SWIFT_REQUEST(TypeChecker, CollectExistentialConformancesRequest,
105-
ArrayRef<ProtocolConformanceRef>(ModuleDecl*,
106-
CanType,
107-
CanType,
108-
bool,
109-
bool),
110-
Uncached, NoLocationInfo)
111104
SWIFT_REQUEST(TypeChecker, HasSelfOrAssociatedTypeRequirementsRequest,
112105
bool(ProtocolDecl *), SeparatelyCached, NoLocationInfo)
113106
SWIFT_REQUEST(TypeChecker, ExtendedTypeRequest, Type(ExtensionDecl *), Cached,

lib/AST/ConformanceLookup.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,20 @@ using namespace swift;
4747
ArrayRef<ProtocolConformanceRef>
4848
ModuleDecl::collectExistentialConformances(CanType fromType,
4949
CanType existential,
50-
bool skipConditionalRequirements,
5150
bool allowMissing) {
52-
CollectExistentialConformancesRequest request{this,
53-
fromType,
54-
existential,
55-
skipConditionalRequirements,
56-
allowMissing};
57-
return evaluateOrDefault(getASTContext().evaluator, request, /*default=*/{});
51+
assert(existential.isAnyExistentialType());
52+
53+
auto layout = existential.getExistentialLayout();
54+
auto protocols = layout.getProtocols();
55+
56+
SmallVector<ProtocolConformanceRef, 4> conformances;
57+
for (auto *proto : protocols) {
58+
auto conformance = lookupConformance(fromType, proto, allowMissing);
59+
assert(conformance);
60+
conformances.push_back(conformance);
61+
}
62+
63+
return getASTContext().AllocateCopy(conformances);
5864
}
5965

6066
ProtocolConformanceRef

lib/SILGen/SILGenPoly.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,6 @@ static ManagedValue emitTransformExistential(SILGenFunction &SGF,
279279
SGF.SGM.M.getSwiftModule()->collectExistentialConformances(
280280
fromInstanceType,
281281
toInstanceType,
282-
/*skipConditionalRequirements=*/true,
283282
/*allowMissing=*/true);
284283

285284
// Build result existential

lib/Sema/CSApply.cpp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6671,12 +6671,6 @@ Expr *ExprRewriter::coerceExistential(Expr *expr, Type toType,
66716671
/// because most protocols do not conform to themselves -- however we still
66726672
/// allow the conversion here, except the ErasureExpr ends up with trivial
66736673
/// conformances.
6674-
auto conformances =
6675-
dc->getParentModule()
6676-
->collectExistentialConformances(fromInstanceType->getCanonicalType(),
6677-
toInstanceType->getCanonicalType(),
6678-
/*skipConditionalRequirements=*/false,
6679-
/*allowMissing=*/true);
66806674

66816675
// Use the requirements of any parameterized protocols to build out fake
66826676
// argument conversions that can be used to infer opaque types.
@@ -6738,6 +6732,16 @@ Expr *ExprRewriter::coerceExistential(Expr *expr, Type toType,
67386732
auto *archetypeVal = cs.cacheType(
67396733
new (ctx) OpaqueValueExpr(expr->getSourceRange(), fromType));
67406734

6735+
fromInstanceType = fromType;
6736+
while (auto *metatypeType = fromInstanceType->getAs<MetatypeType>())
6737+
fromInstanceType = metatypeType->getInstanceType();
6738+
6739+
auto conformances =
6740+
dc->getParentModule()
6741+
->collectExistentialConformances(fromInstanceType->getCanonicalType(),
6742+
toInstanceType->getCanonicalType(),
6743+
/*allowMissing=*/true);
6744+
67416745
auto *result = cs.cacheType(ErasureExpr::create(ctx, archetypeVal, toType,
67426746
conformances,
67436747
argConversions));
@@ -6753,6 +6757,12 @@ Expr *ExprRewriter::coerceExistential(Expr *expr, Type toType,
67536757
}
67546758
}
67556759

6760+
auto conformances =
6761+
dc->getParentModule()
6762+
->collectExistentialConformances(fromInstanceType->getCanonicalType(),
6763+
toInstanceType->getCanonicalType(),
6764+
/*allowMissing=*/true);
6765+
67566766
return cs.cacheType(ErasureExpr::create(ctx, expr, toType,
67576767
conformances, argConversions));
67586768
}

lib/Sema/CSSimplify.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8550,7 +8550,6 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
85508550
case ConstraintKind::SelfObjectOfProtocol: {
85518551
auto conformance = TypeChecker::containsProtocol(
85528552
type, protocol, DC->getParentModule(),
8553-
/*skipConditionalRequirements=*/true,
85548553
/*allowMissing=*/true);
85558554
if (conformance) {
85568555
return recordConformance(conformance);

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5280,7 +5280,6 @@ void swift::diagnoseConformanceFailure(Type T,
52805280

52815281
ProtocolConformanceRef
52825282
TypeChecker::containsProtocol(Type T, ProtocolDecl *Proto, ModuleDecl *M,
5283-
bool skipConditionalRequirements,
52845283
bool allowMissing) {
52855284
// Existential types don't need to conform, i.e., they only need to
52865285
// contain the protocol.
@@ -5305,10 +5304,8 @@ TypeChecker::containsProtocol(Type T, ProtocolDecl *Proto, ModuleDecl *M,
53055304
// would result in a missing conformance if type is `& Sendable`
53065305
// protocol composition. It's handled for type as a whole below.
53075306
if (auto superclass = layout.getSuperclass()) {
5308-
auto result =
5309-
(skipConditionalRequirements
5310-
? M->lookupConformance(superclass, Proto, /*allowMissing=*/false)
5311-
: M->checkConformance(superclass, Proto, /*allowMissing=*/false));
5307+
auto result = M->lookupConformance(superclass, Proto,
5308+
/*allowMissing=*/false);
53125309
if (result) {
53135310
return result;
53145311
}
@@ -5331,9 +5328,7 @@ TypeChecker::containsProtocol(Type T, ProtocolDecl *Proto, ModuleDecl *M,
53315328
}
53325329

53335330
// For non-existential types, this is equivalent to checking conformance.
5334-
return (skipConditionalRequirements
5335-
? M->lookupConformance(T, Proto, allowMissing)
5336-
: M->checkConformance(T, Proto, allowMissing));
5331+
return M->lookupConformance(T, Proto, allowMissing);
53375332
}
53385333

53395334
bool TypeChecker::conformsToKnownProtocol(

lib/Sema/TypeCheckRequestFunctions.cpp

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -397,31 +397,6 @@ Type ResultBuilderTypeRequest::evaluate(Evaluator &evaluator,
397397
return type->mapTypeOutOfContext();
398398
}
399399

400-
ArrayRef<ProtocolConformanceRef>
401-
CollectExistentialConformancesRequest::evaluate(Evaluator &evaluator,
402-
ModuleDecl *module,
403-
CanType fromType,
404-
CanType existential,
405-
bool skipConditionalRequirements,
406-
bool allowMissing) const {
407-
assert(existential.isAnyExistentialType());
408-
409-
auto layout = existential.getExistentialLayout();
410-
auto protocols = layout.getProtocols();
411-
412-
SmallVector<ProtocolConformanceRef, 4> conformances;
413-
for (auto *proto : protocols) {
414-
auto conformance =
415-
TypeChecker::containsProtocol(
416-
fromType, proto, module,
417-
skipConditionalRequirements, allowMissing);
418-
assert(conformance);
419-
conformances.push_back(conformance);
420-
}
421-
422-
return module->getASTContext().AllocateCopy(conformances);
423-
}
424-
425400
// Define request evaluation functions for each of the type checker requests.
426401
static AbstractRequestFunction *typeCheckerRequestFunctions[] = {
427402
#define SWIFT_REQUEST(Zone, Name, Sig, Caching, LocOptions) \

lib/Sema/TypeChecker.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,6 @@ Expr *addImplicitLoadExpr(
797797
/// an empty optional.
798798
ProtocolConformanceRef containsProtocol(Type T, ProtocolDecl *Proto,
799799
ModuleDecl *M,
800-
bool skipConditionalRequirements=false,
801800
bool allowMissing=false);
802801

803802
/// Check whether the type conforms to a given known protocol.

test/ClangImporter/objc_async.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,8 +354,6 @@ func testSender(
354354
sender.sendSendableSubclasses(nonSendableObject)
355355
// expected-warning@-1 {{conformance of 'NonSendableClass' to 'Sendable' is unavailable}}
356356
sender.sendSendableSubclasses(sendableSubclassOfNonSendableObject)
357-
// expected-warning@-1 {{conformance of 'NonSendableClass' to 'Sendable' is unavailable}}
358-
// FIXME(rdar://89992569): Should allow for the possibility that NonSendableClass will have a Sendable subclass
359357

360358
sender.sendProto(sendableProtos)
361359
sender.sendProto(nonSendableProtos)

0 commit comments

Comments
 (0)