Skip to content

Commit 6d00a24

Browse files
committed
[Sema] Rename existentialTypeSupported to existentialRequiresAny, and
flip the return value in the implementation accordingly.
1 parent b58c324 commit 6d00a24

File tree

8 files changed

+47
-48
lines changed

8 files changed

+47
-48
lines changed

include/swift/AST/Decl.h

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -532,11 +532,11 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl> {
532532
/// Whether the existential of this protocol conforms to itself.
533533
ExistentialConformsToSelf : 1,
534534

535-
/// Whether the \c ExistentialTypeSupported bit is valid.
536-
ExistentialTypeSupportedValid : 1,
535+
/// Whether the \c ExistentialRequiresAny bit is valid.
536+
ExistentialRequiresAnyValid : 1,
537537

538-
/// Whether the existential of this protocol can be represented.
539-
ExistentialTypeSupported : 1,
538+
/// Whether the existential of this protocol must be spelled with \c any.
539+
ExistentialRequiresAny : 1,
540540

541541
/// True if the protocol has requirements that cannot be satisfied (e.g.
542542
/// because they could not be imported from Objective-C).
@@ -4230,19 +4230,19 @@ class ProtocolDecl final : public NominalTypeDecl {
42304230
Bits.ProtocolDecl.ExistentialConformsToSelf = result;
42314231
}
42324232

4233-
/// Returns the cached result of \c existentialTypeSupported or \c None if it
4233+
/// Returns the cached result of \c existentialRequiresAny or \c None if it
42344234
/// hasn't yet been computed.
4235-
Optional<bool> getCachedExistentialTypeSupported() {
4236-
if (Bits.ProtocolDecl.ExistentialTypeSupportedValid)
4237-
return Bits.ProtocolDecl.ExistentialTypeSupported;
4235+
Optional<bool> getCachedExistentialRequiresAny() {
4236+
if (Bits.ProtocolDecl.ExistentialRequiresAnyValid)
4237+
return Bits.ProtocolDecl.ExistentialRequiresAny;
42384238

42394239
return None;
42404240
}
42414241

4242-
/// Caches the result of \c existentialTypeSupported
4243-
void setCachedExistentialTypeSupported(bool supported) {
4244-
Bits.ProtocolDecl.ExistentialTypeSupportedValid = true;
4245-
Bits.ProtocolDecl.ExistentialTypeSupported = supported;
4242+
/// Caches the result of \c existentialRequiresAny
4243+
void setCachedExistentialRequiresAny(bool requiresAny) {
4244+
Bits.ProtocolDecl.ExistentialRequiresAnyValid = true;
4245+
Bits.ProtocolDecl.ExistentialRequiresAny = requiresAny;
42464246
}
42474247

42484248
bool hasLazyRequirementSignature() const {
@@ -4258,7 +4258,7 @@ class ProtocolDecl final : public NominalTypeDecl {
42584258
friend class RequirementSignatureRequestRQM;
42594259
friend class ProtocolRequiresClassRequest;
42604260
friend class ExistentialConformsToSelfRequest;
4261-
friend class ExistentialTypeSupportedRequest;
4261+
friend class ExistentialRequiresAnyRequest;
42624262
friend class InheritedProtocolsRequest;
42634263

42644264
public:
@@ -4347,11 +4347,10 @@ class ProtocolDecl final : public NominalTypeDecl {
43474347
/// contain 'Self' in 'parameter' or 'other' position.
43484348
bool isAvailableInExistential(const ValueDecl *decl) const;
43494349

4350-
/// Determine whether we are allowed to refer to an existential type
4351-
/// conforming to this protocol. This is only permitted if the types of
4352-
/// all the members do not contain any associated types, and do not
4353-
/// contain 'Self' in 'parameter' or 'other' position.
4354-
bool existentialTypeSupported() const;
4350+
/// Determine whether an existential type must be explicitly prefixed
4351+
/// with \c any. \c any is required if any of the members contain
4352+
/// an associated type, or if \c Self appears in non-covariant position.
4353+
bool existentialRequiresAny() const;
43554354

43564355
/// Returns a list of protocol requirements that must be assessed to
43574356
/// determine a concrete's conformance effect polymorphism kind.

include/swift/AST/TypeCheckRequests.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -287,10 +287,10 @@ class ExistentialConformsToSelfRequest :
287287
void cacheResult(bool value) const;
288288
};
289289

290-
/// Determine whether we are allowed to refer to an existential type conforming
291-
/// to this protocol.
292-
class ExistentialTypeSupportedRequest :
293-
public SimpleRequest<ExistentialTypeSupportedRequest,
290+
/// Determine whether an existential type conforming to this protocol
291+
/// requires the \c any syntax.
292+
class ExistentialRequiresAnyRequest :
293+
public SimpleRequest<ExistentialRequiresAnyRequest,
294294
bool(ProtocolDecl *),
295295
RequestFlags::SeparatelyCached> {
296296
public:

include/swift/AST/TypeCheckerTypeIDZone.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ SWIFT_REQUEST(TypeChecker, EnumRawTypeRequest,
9292
Type(EnumDecl *), Cached, NoLocationInfo)
9393
SWIFT_REQUEST(TypeChecker, ExistentialConformsToSelfRequest,
9494
bool(ProtocolDecl *), SeparatelyCached, NoLocationInfo)
95-
SWIFT_REQUEST(TypeChecker, ExistentialTypeSupportedRequest,
95+
SWIFT_REQUEST(TypeChecker, ExistentialRequiresAnyRequest,
9696
bool(ProtocolDecl *), SeparatelyCached, NoLocationInfo)
9797
SWIFT_REQUEST(TypeChecker, ExtendedTypeRequest, Type(ExtensionDecl *), Cached,
9898
NoLocationInfo)

lib/AST/Decl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5258,9 +5258,9 @@ bool ProtocolDecl::isAvailableInExistential(const ValueDecl *decl) const {
52585258
return true;
52595259
}
52605260

5261-
bool ProtocolDecl::existentialTypeSupported() const {
5261+
bool ProtocolDecl::existentialRequiresAny() const {
52625262
return evaluateOrDefault(getASTContext().evaluator,
5263-
ExistentialTypeSupportedRequest{const_cast<ProtocolDecl *>(this)}, true);
5263+
ExistentialRequiresAnyRequest{const_cast<ProtocolDecl *>(this)}, true);
52645264
}
52655265

52665266
StringRef ProtocolDecl::getObjCRuntimeName(

lib/AST/TypeCheckRequests.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -250,28 +250,28 @@ void ExistentialConformsToSelfRequest::cacheResult(bool value) const {
250250
}
251251

252252
//----------------------------------------------------------------------------//
253-
// existentialTypeSupported computation.
253+
// existentialRequiresAny computation.
254254
//----------------------------------------------------------------------------//
255255

256-
void ExistentialTypeSupportedRequest::diagnoseCycle(DiagnosticEngine &diags) const {
256+
void ExistentialRequiresAnyRequest::diagnoseCycle(DiagnosticEngine &diags) const {
257257
auto decl = std::get<0>(getStorage());
258258
diags.diagnose(decl, diag::circular_protocol_def, decl->getName());
259259
}
260260

261-
void ExistentialTypeSupportedRequest::noteCycleStep(DiagnosticEngine &diags) const {
261+
void ExistentialRequiresAnyRequest::noteCycleStep(DiagnosticEngine &diags) const {
262262
auto requirement = std::get<0>(getStorage());
263263
diags.diagnose(requirement, diag::kind_declname_declared_here,
264264
DescriptiveDeclKind::Protocol, requirement->getName());
265265
}
266266

267-
Optional<bool> ExistentialTypeSupportedRequest::getCachedResult() const {
267+
Optional<bool> ExistentialRequiresAnyRequest::getCachedResult() const {
268268
auto decl = std::get<0>(getStorage());
269-
return decl->getCachedExistentialTypeSupported();
269+
return decl->getCachedExistentialRequiresAny();
270270
}
271271

272-
void ExistentialTypeSupportedRequest::cacheResult(bool value) const {
272+
void ExistentialRequiresAnyRequest::cacheResult(bool value) const {
273273
auto decl = std::get<0>(getStorage());
274-
decl->setCachedExistentialTypeSupported(value);
274+
decl->setCachedExistentialRequiresAny(value);
275275
}
276276

277277
//----------------------------------------------------------------------------//

lib/Sema/TypeCheckDecl.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -667,31 +667,31 @@ ExistentialConformsToSelfRequest::evaluate(Evaluator &evaluator,
667667
}
668668

669669
bool
670-
ExistentialTypeSupportedRequest::evaluate(Evaluator &evaluator,
671-
ProtocolDecl *decl) const {
672-
// ObjC protocols can always be existential.
670+
ExistentialRequiresAnyRequest::evaluate(Evaluator &evaluator,
671+
ProtocolDecl *decl) const {
672+
// ObjC protocols do not require `any`.
673673
if (decl->isObjC())
674-
return true;
674+
return false;
675675

676676
for (auto member : decl->getMembers()) {
677-
// Existential types cannot be used if the protocol has an associated type.
677+
// Existential types require `any` if the protocol has an associated type.
678678
if (isa<AssociatedTypeDecl>(member))
679-
return false;
679+
return true;
680680

681681
// For value members, look at their type signatures.
682682
if (auto valueMember = dyn_cast<ValueDecl>(member)) {
683683
if (!decl->isAvailableInExistential(valueMember))
684-
return false;
684+
return true;
685685
}
686686
}
687687

688-
// Check whether all of the inherited protocols support existential types.
688+
// Check whether any of the inherited protocols require `any`.
689689
for (auto proto : decl->getInheritedProtocols()) {
690-
if (!proto->existentialTypeSupported())
691-
return false;
690+
if (proto->existentialRequiresAny())
691+
return true;
692692
}
693693

694-
return true;
694+
return false;
695695
}
696696

697697
bool

lib/Serialization/Deserialization.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3564,14 +3564,14 @@ class DeclDeserializer {
35643564
StringRef blobData) {
35653565
IdentifierID nameID;
35663566
DeclContextID contextID;
3567-
bool isImplicit, isClassBounded, isObjC, existentialTypeSupported;
3567+
bool isImplicit, isClassBounded, isObjC, existentialRequiresAny;
35683568
uint8_t rawAccessLevel;
35693569
unsigned numInheritedTypes;
35703570
ArrayRef<uint64_t> rawInheritedAndDependencyIDs;
35713571

35723572
decls_block::ProtocolLayout::readRecord(scratch, nameID, contextID,
35733573
isImplicit, isClassBounded, isObjC,
3574-
existentialTypeSupported,
3574+
existentialRequiresAny,
35753575
rawAccessLevel, numInheritedTypes,
35763576
rawInheritedAndDependencyIDs);
35773577

@@ -3597,8 +3597,8 @@ class DeclDeserializer {
35973597

35983598
ctx.evaluator.cacheOutput(ProtocolRequiresClassRequest{proto},
35993599
std::move(isClassBounded));
3600-
ctx.evaluator.cacheOutput(ExistentialTypeSupportedRequest{proto},
3601-
std::move(existentialTypeSupported));
3600+
ctx.evaluator.cacheOutput(ExistentialRequiresAnyRequest{proto},
3601+
std::move(existentialRequiresAny));
36023602

36033603
if (auto accessLevel = getActualAccessLevel(rawAccessLevel))
36043604
proto->setAccess(*accessLevel);

lib/Serialization/Serialization.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3630,7 +3630,7 @@ class Serializer::DeclSerializer : public DeclVisitor<DeclSerializer> {
36303630
const_cast<ProtocolDecl *>(proto)
36313631
->requiresClass(),
36323632
proto->isObjC(),
3633-
proto->existentialTypeSupported(),
3633+
proto->existentialRequiresAny(),
36343634
rawAccessLevel, numInherited,
36353635
inheritedAndDependencyTypes);
36363636

0 commit comments

Comments
 (0)