Skip to content

Commit dbfe61a

Browse files
committed
Sema: Simplify TypeChecker::getDefaultType()
1 parent 78551fa commit dbfe61a

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

lib/Sema/TypeCheckExpr.cpp

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -632,26 +632,27 @@ static Type lookupDefaultLiteralType(const DeclContext *dc,
632632
return cast<TypeAliasDecl>(TD)->getDeclaredInterfaceType();
633633
}
634634

635-
static llvm::Optional<KnownProtocolKind>
636-
getKnownProtocolKindIfAny(const ProtocolDecl *protocol) {
637-
#define EXPRESSIBLE_BY_LITERAL_PROTOCOL_WITH_NAME(Id, _, __, ___) \
638-
if (protocol == TypeChecker::getProtocol(protocol->getASTContext(), \
639-
SourceLoc(), \
640-
KnownProtocolKind::Id)) \
641-
return KnownProtocolKind::Id;
642-
#include "swift/AST/KnownProtocols.def"
643-
#undef EXPRESSIBLE_BY_LITERAL_PROTOCOL_WITH_NAME
635+
Type TypeChecker::getDefaultType(ProtocolDecl *protocol, DeclContext *dc) {
636+
auto knownKind = protocol->getKnownProtocolKind();
637+
if (!knownKind)
638+
return Type();
644639

645-
return llvm::None;
646-
}
640+
switch (knownKind.value()) {
641+
#define EXPRESSIBLE_BY_LITERAL_PROTOCOL_WITH_NAME(Id, _, __, ___) \
642+
case KnownProtocolKind::Id: \
643+
break;
644+
#define PROTOCOL_WITH_NAME(Id, _) \
645+
case KnownProtocolKind::Id: \
646+
return Type();
647647

648-
Type TypeChecker::getDefaultType(ProtocolDecl *protocol, DeclContext *dc) {
649-
if (auto knownProtocolKindIfAny = getKnownProtocolKindIfAny(protocol)) {
650-
return evaluateOrDefault(
651-
protocol->getASTContext().evaluator,
652-
DefaultTypeRequest{knownProtocolKindIfAny.value(), dc}, nullptr);
648+
#include "swift/AST/KnownProtocols.def"
649+
#undef EXPRESSIBLE_BY_LITERAL_PROTOCOL_WITH_NAME
650+
#undef PROTOCOL_WITH_NAME
653651
}
654-
return Type();
652+
653+
return evaluateOrDefault(
654+
protocol->getASTContext().evaluator,
655+
DefaultTypeRequest{knownKind.value(), dc}, nullptr);
655656
}
656657

657658
static std::pair<const char *, bool> lookupDefaultTypeInfoForKnownProtocol(

0 commit comments

Comments
 (0)