Skip to content

Commit 3ae31d5

Browse files
committed
Sema: Don't need to derive CaseIterable's AllCases associated type
Just declaring a default in the standard library works fine.
1 parent d6f19d2 commit 3ae31d5

5 files changed

+2
-35
lines changed

lib/Sema/DerivedConformanceCaseIterable.cpp

-24
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,6 @@ static ArraySliceType *computeAllCasesType(NominalTypeDecl *enumDecl) {
6969
return ArraySliceType::get(enumType);
7070
}
7171

72-
static Type deriveCaseIterable_AllCases(DerivedConformance &derived) {
73-
// enum SomeEnum : CaseIterable {
74-
// @derived
75-
// typealias AllCases = [SomeEnum]
76-
// }
77-
auto *rawInterfaceType = computeAllCasesType(cast<EnumDecl>(derived.Nominal));
78-
return derived.getConformanceContext()->mapTypeIntoContext(rawInterfaceType);
79-
}
80-
8172
ValueDecl *DerivedConformance::deriveCaseIterable(ValueDecl *requirement) {
8273
// Conformance can't be synthesized in an extension.
8374
if (checkAndDiagnoseDisallowedContext(requirement))
@@ -111,18 +102,3 @@ ValueDecl *DerivedConformance::deriveCaseIterable(ValueDecl *requirement) {
111102

112103
return propDecl;
113104
}
114-
115-
Type DerivedConformance::deriveCaseIterable(AssociatedTypeDecl *assocType) {
116-
// Check that we can actually derive CaseIterable for this type.
117-
if (!canDeriveConformance(Nominal))
118-
return nullptr;
119-
120-
if (assocType->getName() == Context.Id_AllCases) {
121-
return deriveCaseIterable_AllCases(*this);
122-
}
123-
124-
Context.Diags.diagnose(assocType->getLoc(),
125-
diag::broken_case_iterable_requirement);
126-
return nullptr;
127-
}
128-

lib/Sema/DerivedConformances.h

-6
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,6 @@ class DerivedConformance {
163163
/// \returns the derived member, which will also be added to the type.
164164
ValueDecl *deriveCaseIterable(ValueDecl *requirement);
165165

166-
/// Derive a CaseIterable type witness for an enum if it has no associated
167-
/// values for any of its cases.
168-
///
169-
/// \returns the derived member, which will also be added to the type.
170-
Type deriveCaseIterable(AssociatedTypeDecl *assocType);
171-
172166
/// Determine if a RawRepresentable requirement can be derived for a type.
173167
///
174168
/// This is implemented for non-empty enums without associated values,

lib/Sema/TypeCheckProtocol.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -5691,8 +5691,6 @@ TypeChecker::deriveTypeWitness(DeclContext *DC,
56915691
switch (*knownKind) {
56925692
case KnownProtocolKind::RawRepresentable:
56935693
return std::make_pair(derived.deriveRawRepresentable(AssocType), nullptr);
5694-
case KnownProtocolKind::CaseIterable:
5695-
return std::make_pair(derived.deriveCaseIterable(AssocType), nullptr);
56965694
case KnownProtocolKind::Differentiable:
56975695
return derived.deriveDifferentiable(AssocType);
56985696
default:

stdlib/public/core/CompilerProtocols.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ extension RawRepresentable where RawValue: Hashable, Self: Hashable {
249249
/// demonstrates this automatic implementation.
250250
public protocol CaseIterable {
251251
/// A type that can represent a collection of all values of this type.
252-
associatedtype AllCases: Collection
252+
associatedtype AllCases: Collection = [Self]
253253
where AllCases.Element == Self
254254

255255
/// A collection of all values of this type.

test/IDE/complete_override.swift

+1-2
Original file line numberDiff line numberDiff line change
@@ -896,11 +896,10 @@ struct SynthesizedConformance3: Hashable {
896896
enum SynthesizedConformance4: CaseIterable {
897897
case a, b, c, d
898898
#^OVERRIDE_SYNTHESIZED_4^#
899-
// OVERRIDE_SYNTHESIZED_4: Begin completions, 4 items
899+
// OVERRIDE_SYNTHESIZED_4: Begin completions, 3 items
900900
// OVERRIDE_SYNTHESIZED_4-DAG: Decl[InstanceVar]/Super/IsSystem: var hashValue: Int
901901
// OVERRIDE_SYNTHESIZED_4-DAG: Decl[InstanceMethod]/Super/IsSystem: func hash(into hasher: inout Hasher) {|};
902902
// OVERRIDE_SYNTHESIZED_4-DAG: Decl[StaticVar]/Super/IsSystem: static var allCases: [SynthesizedConformance4];
903-
// OVERRIDE_SYNTHESIZED_4-DAG: Decl[AssociatedType]/Super/IsSystem: typealias AllCases = {#(Type)#};
904903
}
905904

906905
class SynthesizedConformance5: SynthesizedConformance2 {

0 commit comments

Comments
 (0)