Skip to content

Commit fefb800

Browse files
committed
Eliminate CodableConformanceType
CodableConformanceType::TypeNotValidated is unused since the InterfaceTypeRequest changes went through. We can just use the validity of the ProtocolConformanceRef here.
1 parent 06d27f0 commit fefb800

File tree

1 file changed

+22
-51
lines changed

1 file changed

+22
-51
lines changed

lib/Sema/DerivedConformanceCodable.cpp

Lines changed: 22 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,6 @@ static bool superclassIsDecodable(ClassDecl *target) {
6161
C.getProtocol(KnownProtocolKind::Decodable));
6262
}
6363

64-
/// Represents the possible outcomes of checking whether a decl conforms to
65-
/// Encodable or Decodable.
66-
enum CodableConformanceType {
67-
TypeNotValidated,
68-
DoesNotConform,
69-
Conforms
70-
};
71-
7264
/// Returns whether the given type conforms to the given {En,De}codable
7365
/// protocol.
7466
///
@@ -77,7 +69,7 @@ enum CodableConformanceType {
7769
/// \param target The \c Type to validate.
7870
///
7971
/// \param proto The \c ProtocolDecl to check conformance to.
80-
static CodableConformanceType typeConformsToCodable(DeclContext *context,
72+
static ProtocolConformanceRef typeConformsToCodable(DeclContext *context,
8173
Type target, bool isIUO,
8274
ProtocolDecl *proto) {
8375
target = context->mapTypeIntoContext(target);
@@ -86,8 +78,7 @@ static CodableConformanceType typeConformsToCodable(DeclContext *context,
8678
return typeConformsToCodable(context, target->getOptionalObjectType(),
8779
false, proto);
8880

89-
auto conf = TypeChecker::conformsToProtocol(target, proto, context, None);
90-
return conf.isInvalid() ? DoesNotConform : Conforms;
81+
return TypeChecker::conformsToProtocol(target, proto, context, None);
9182
}
9283

9384
/// Returns whether the given variable conforms to the given {En,De}codable
@@ -98,7 +89,7 @@ static CodableConformanceType typeConformsToCodable(DeclContext *context,
9889
/// \param varDecl The \c VarDecl to validate.
9990
///
10091
/// \param proto The \c ProtocolDecl to check conformance to.
101-
static CodableConformanceType
92+
static ProtocolConformanceRef
10293
varConformsToCodable(DeclContext *DC, VarDecl *varDecl, ProtocolDecl *proto) {
10394
// If the decl doesn't yet have a type, we may be seeing it before the type
10495
// checker has gotten around to evaluating its type. For example:
@@ -167,22 +158,13 @@ static bool validateCodingKeysEnum(DerivedConformance &derived,
167158
// We have a property to map to. Ensure it's {En,De}codable.
168159
auto conformance =
169160
varConformsToCodable(conformanceDC, it->second, derived.Protocol);
170-
switch (conformance) {
171-
case Conforms:
172-
// The property was valid. Remove it from the list.
173-
properties.erase(it);
174-
break;
175-
176-
case DoesNotConform:
177-
it->second->diagnose(diag::codable_non_conforming_property_here,
178-
derived.getProtocolType(), it->second->getType());
179-
LLVM_FALLTHROUGH;
180-
181-
case TypeNotValidated:
182-
// We don't produce a diagnostic for a type which failed to validate.
183-
// This will produce a diagnostic elsewhere anyway.
184-
propertiesAreValid = false;
185-
continue;
161+
if (conformance.isInvalid()) {
162+
it->second->diagnose(diag::codable_non_conforming_property_here,
163+
derived.getProtocolType(), it->second->getType());
164+
propertiesAreValid = false;
165+
} else {
166+
// The property was valid. Remove it from the list.
167+
properties.erase(it);
186168
}
187169
}
188170

@@ -341,28 +323,17 @@ static EnumDecl *synthesizeCodingKeysEnum(DerivedConformance &derived) {
341323
// context, not the type.
342324
auto conformance = varConformsToCodable(derived.getConformanceContext(),
343325
varDecl, derived.Protocol);
344-
switch (conformance) {
345-
case Conforms:
346-
{
347-
auto *elt = new (C) EnumElementDecl(SourceLoc(),
348-
getVarNameForCoding(varDecl),
349-
nullptr, SourceLoc(), nullptr,
350-
enumDecl);
351-
elt->setImplicit();
352-
enumDecl->addMember(elt);
353-
break;
354-
}
355-
356-
case DoesNotConform:
357-
varDecl->diagnose(diag::codable_non_conforming_property_here,
358-
derived.getProtocolType(), varDecl->getType());
359-
LLVM_FALLTHROUGH;
360-
361-
case TypeNotValidated:
362-
// We don't produce a diagnostic for a type which failed to validate.
363-
// This will produce a diagnostic elsewhere anyway.
364-
allConform = false;
365-
continue;
326+
if (conformance.isInvalid()) {
327+
varDecl->diagnose(diag::codable_non_conforming_property_here,
328+
derived.getProtocolType(), varDecl->getType());
329+
allConform = false;
330+
} else {
331+
auto *elt = new (C) EnumElementDecl(SourceLoc(),
332+
getVarNameForCoding(varDecl),
333+
nullptr, SourceLoc(), nullptr,
334+
enumDecl);
335+
elt->setImplicit();
336+
enumDecl->addMember(elt);
366337
}
367338
}
368339

@@ -1164,7 +1135,7 @@ ValueDecl *DerivedConformance::deriveEncodable(ValueDecl *requirement) {
11641135
}
11651136

11661137
ValueDecl *DerivedConformance::deriveDecodable(ValueDecl *requirement) {
1167-
// We can only synthesize Encodable for structs and classes.
1138+
// We can only synthesize Decodable for structs and classes.
11681139
if (!isa<StructDecl>(Nominal) && !isa<ClassDecl>(Nominal))
11691140
return nullptr;
11701141

0 commit comments

Comments
 (0)