Skip to content

Commit 58480c3

Browse files
committed
[NCGenerics] provide namespace for CanBeInvertible
1 parent 3e03c67 commit 58480c3

File tree

5 files changed

+29
-27
lines changed

5 files changed

+29
-27
lines changed

include/swift/AST/Decl.h

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3191,12 +3191,14 @@ class TypeDecl : public ValueDecl {
31913191

31923192
void setInherited(ArrayRef<InheritedEntry> i) { Inherited = i; }
31933193

3194-
/// Indicates how "strongly" a TypeDecl will conform to an invertible
3195-
/// protocol. Supports inequality comparisons and casts to bool.
3196-
enum CanBeInvertibleResult: unsigned {
3197-
CBI_Never = 0, // Never conforms.
3198-
CBI_Conditionally = 1, // Conditionally conforms.
3199-
CBI_Always = 2, // Always conforms.
3194+
struct CanBeInvertible {
3195+
/// Indicates how "strongly" a TypeDecl will conform to an invertible
3196+
/// protocol. Supports inequality comparisons and casts to bool.
3197+
enum Result : unsigned {
3198+
Never = 0, // Never conforms.
3199+
Conditionally = 1, // Conditionally conforms.
3200+
Always = 2, // Always conforms.
3201+
};
32003202
};
32013203

32023204
/// "Does a conformance for Copyable exist for this type declaration?"
@@ -3207,7 +3209,7 @@ class TypeDecl : public ValueDecl {
32073209
///
32083210
/// If you need a more precise answer, ask this Decl's corresponding
32093211
/// Type if it `isCopyable` instead of using this.
3210-
CanBeInvertibleResult canBeCopyable() const;
3212+
CanBeInvertible::Result canBeCopyable() const;
32113213

32123214
/// "Does a conformance for Escapable exist for this type declaration?"
32133215
///
@@ -3217,7 +3219,7 @@ class TypeDecl : public ValueDecl {
32173219
///
32183220
/// If you need a more precise answer, ask this Decl's corresponding
32193221
/// Type if it `isEscapable` instead of using this.
3220-
CanBeInvertibleResult canBeEscapable() const;
3222+
CanBeInvertible::Result canBeEscapable() const;
32213223

32223224
/// Determine how the given invertible protocol was written on this TypeDecl,
32233225
/// if at all.

lib/AST/Decl.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4930,16 +4930,16 @@ InverseMarking TypeDecl::getMarking(InvertibleProtocolKind ip) const {
49304930
);
49314931
}
49324932

4933-
static TypeDecl::CanBeInvertibleResult
4933+
static TypeDecl::CanBeInvertible::Result
49344934
conformanceExists(TypeDecl const *decl, InvertibleProtocolKind ip) {
49354935
auto *proto = decl->getASTContext().getProtocol(getKnownProtocolKind(ip));
49364936
assert(proto);
49374937

49384938
// Handle protocols specially, without building a GenericSignature.
49394939
if (auto *protoDecl = dyn_cast<ProtocolDecl>(decl))
49404940
return protoDecl->requiresInvertible(ip)
4941-
? TypeDecl::CBI_Always
4942-
: TypeDecl::CBI_Never;
4941+
? TypeDecl::CanBeInvertible::Always
4942+
: TypeDecl::CanBeInvertible::Never;
49434943

49444944
Type selfTy = decl->getDeclaredInterfaceType();
49454945
assert(selfTy);
@@ -4948,31 +4948,31 @@ conformanceExists(TypeDecl const *decl, InvertibleProtocolKind ip) {
49484948
/*allowMissing=*/false);
49494949

49504950
if (conformance.isInvalid())
4951-
return TypeDecl::CBI_Never;
4951+
return TypeDecl::CanBeInvertible::Never;
49524952

49534953
if (!conformance.getConditionalRequirements().empty())
4954-
return TypeDecl::CBI_Conditionally;
4954+
return TypeDecl::CanBeInvertible::Conditionally;
49554955

4956-
return TypeDecl::CBI_Always;
4956+
return TypeDecl::CanBeInvertible::Always;
49574957
}
49584958

4959-
TypeDecl::CanBeInvertibleResult TypeDecl::canBeCopyable() const {
4959+
TypeDecl::CanBeInvertible::Result TypeDecl::canBeCopyable() const {
49604960
if (!getASTContext().LangOpts.hasFeature(Feature::NoncopyableGenerics)) {
49614961
auto copyable = getMarking(InvertibleProtocolKind::Copyable);
49624962
return !copyable.getInverse() || bool(copyable.getPositive())
4963-
? CBI_Always
4964-
: CBI_Never;
4963+
? CanBeInvertible::Always
4964+
: CanBeInvertible::Never;
49654965
}
49664966

49674967
return conformanceExists(this, InvertibleProtocolKind::Copyable);
49684968
}
49694969

4970-
TypeDecl::CanBeInvertibleResult TypeDecl::canBeEscapable() const {
4970+
TypeDecl::CanBeInvertible::Result TypeDecl::canBeEscapable() const {
49714971
if (!getASTContext().LangOpts.hasFeature(Feature::NoncopyableGenerics)) {
49724972
auto escapable = getMarking(InvertibleProtocolKind::Escapable);
49734973
return !escapable.getInverse() || bool(escapable.getPositive())
4974-
? CBI_Always
4975-
: CBI_Never;
4974+
? CanBeInvertible::Always
4975+
: CanBeInvertible::Never;
49764976
}
49774977

49784978
return conformanceExists(this, InvertibleProtocolKind::Escapable);

lib/SIL/IR/TypeLowering.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2429,15 +2429,15 @@ namespace {
24292429
properties =
24302430
applyLifetimeAnnotation(D->getLifetimeAnnotation(), properties);
24312431

2432-
if (D->canBeCopyable() != TypeDecl::CBI_Always) {
2432+
if (D->canBeCopyable() != TypeDecl::CanBeInvertible::Always) {
24332433
properties.setNonTrivial();
24342434
properties.setLexical(IsLexical);
24352435
if (properties.isAddressOnly())
24362436
return handleMoveOnlyAddressOnly(structType, properties);
24372437
return new (TC) MoveOnlyLoadableStructTypeLowering(
24382438
structType, properties, Expansion);
24392439
}
2440-
if (D->canBeEscapable() != TypeDecl::CBI_Always) {
2440+
if (D->canBeEscapable() != TypeDecl::CanBeInvertible::Always) {
24412441
properties.setNonTrivial();
24422442
}
24432443
return handleAggregateByProperties<LoadableStructTypeLowering>(structType,
@@ -2526,7 +2526,7 @@ namespace {
25262526
properties =
25272527
applyLifetimeAnnotation(D->getLifetimeAnnotation(), properties);
25282528

2529-
if (D->canBeCopyable() != TypeDecl::CBI_Always) {
2529+
if (D->canBeCopyable() != TypeDecl::CanBeInvertible::Always) {
25302530
properties.setNonTrivial();
25312531
properties.setLexical(IsLexical);
25322532
if (properties.isAddressOnly())
@@ -2535,7 +2535,7 @@ namespace {
25352535
MoveOnlyLoadableEnumTypeLowering(enumType, properties, Expansion);
25362536
}
25372537

2538-
assert(D->canBeEscapable() == TypeDecl::CBI_Always
2538+
assert(D->canBeEscapable() == TypeDecl::CanBeInvertible::Always
25392539
&& "missing typelowering case here!");
25402540

25412541
return handleAggregateByProperties<LoadableEnumTypeLowering>(enumType,

lib/Sema/TypeCheckAttr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7319,7 +7319,7 @@ void AttributeChecker::visitStaticExclusiveOnlyAttr(
73197319
// Can only be applied to structs.
73207320
auto structDecl = cast<StructDecl>(D);
73217321

7322-
if (structDecl->canBeCopyable() != TypeDecl::CBI_Never) {
7322+
if (structDecl->canBeCopyable() != TypeDecl::CanBeInvertible::Never) {
73237323
diagnoseAndRemoveAttr(attr, diag::attr_static_exclusive_only_noncopyable);
73247324
}
73257325
}

lib/Sema/TypeCheckDeclPrimary.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,10 @@ bool swift::isInterfaceTypeNoncopyable(Type type, GenericEnvironment *env) {
100100

101101
// Handle types containing unbound generic parameters.
102102
if (auto *generic = type->getAnyGeneric())
103-
return generic->canBeCopyable() != swift::TypeDecl::CBI_Always;
103+
return generic->canBeCopyable() != swift::TypeDecl::CanBeInvertible::Always;
104104
else if (auto gtpt = type->getAs<GenericTypeParamType>())
105105
if (auto *gtpd = gtpt->getDecl())
106-
return gtpd->canBeCopyable() != swift::TypeDecl::CBI_Always;
106+
return gtpd->canBeCopyable() != swift::TypeDecl::CanBeInvertible::Always;
107107

108108
#ifndef NDEBUG
109109
type->dump();

0 commit comments

Comments
 (0)