Skip to content

Commit 37c0964

Browse files
committed
[Sema] Rename existentialTypeSupported to existentialRequiresAny, and
flip the return value in the implementation accordingly.
1 parent 260654c commit 37c0964

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
@@ -533,11 +533,11 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl> {
533533
/// Whether the existential of this protocol conforms to itself.
534534
ExistentialConformsToSelf : 1,
535535

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

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

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

4253-
/// Returns the cached result of \c existentialTypeSupported or \c None if it
4253+
/// Returns the cached result of \c existentialRequiresAny or \c None if it
42544254
/// hasn't yet been computed.
4255-
Optional<bool> getCachedExistentialTypeSupported() {
4256-
if (Bits.ProtocolDecl.ExistentialTypeSupportedValid)
4257-
return Bits.ProtocolDecl.ExistentialTypeSupported;
4255+
Optional<bool> getCachedExistentialRequiresAny() {
4256+
if (Bits.ProtocolDecl.ExistentialRequiresAnyValid)
4257+
return Bits.ProtocolDecl.ExistentialRequiresAny;
42584258

42594259
return None;
42604260
}
42614261

4262-
/// Caches the result of \c existentialTypeSupported
4263-
void setCachedExistentialTypeSupported(bool supported) {
4264-
Bits.ProtocolDecl.ExistentialTypeSupportedValid = true;
4265-
Bits.ProtocolDecl.ExistentialTypeSupported = supported;
4262+
/// Caches the result of \c existentialRequiresAny
4263+
void setCachedExistentialRequiresAny(bool requiresAny) {
4264+
Bits.ProtocolDecl.ExistentialRequiresAnyValid = true;
4265+
Bits.ProtocolDecl.ExistentialRequiresAny = requiresAny;
42664266
}
42674267

42684268
bool hasLazyRequirementSignature() const {
@@ -4278,7 +4278,7 @@ class ProtocolDecl final : public NominalTypeDecl {
42784278
friend class RequirementSignatureRequestRQM;
42794279
friend class ProtocolRequiresClassRequest;
42804280
friend class ExistentialConformsToSelfRequest;
4281-
friend class ExistentialTypeSupportedRequest;
4281+
friend class ExistentialRequiresAnyRequest;
42824282
friend class InheritedProtocolsRequest;
42834283

42844284
public:
@@ -4367,11 +4367,10 @@ class ProtocolDecl final : public NominalTypeDecl {
43674367
/// contain 'Self' in 'parameter' or 'other' position.
43684368
bool isAvailableInExistential(const ValueDecl *decl) const;
43694369

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

43764375
/// Returns a list of protocol requirements that must be assessed to
43774376
/// 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
@@ -5266,9 +5266,9 @@ bool ProtocolDecl::isAvailableInExistential(const ValueDecl *decl) const {
52665266
return true;
52675267
}
52685268

5269-
bool ProtocolDecl::existentialTypeSupported() const {
5269+
bool ProtocolDecl::existentialRequiresAny() const {
52705270
return evaluateOrDefault(getASTContext().evaluator,
5271-
ExistentialTypeSupportedRequest{const_cast<ProtocolDecl *>(this)}, true);
5271+
ExistentialRequiresAnyRequest{const_cast<ProtocolDecl *>(this)}, true);
52725272
}
52735273

52745274
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)