Skip to content

Commit 15f88e9

Browse files
theblixguyAnthonyLatsis
authored andcommitted
[NFC, Typechecker] Remove UnsupportedProtocolVisitor and checkUnsupportedProtocolType()
1 parent c2e5d04 commit 15f88e9

File tree

4 files changed

+0
-144
lines changed

4 files changed

+0
-144
lines changed

lib/Sema/MiscDiagnostics.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3329,8 +3329,6 @@ static void checkSwitch(ASTContext &ctx, const SwitchStmt *stmt) {
33293329
// We want to warn about "case .Foo, .Bar where 1 != 100:" since the where
33303330
// clause only applies to the second case, and this is surprising.
33313331
for (auto cs : stmt->getCases()) {
3332-
TypeChecker::checkUnsupportedProtocolType(ctx, cs);
3333-
33343332
// The case statement can have multiple case items, each can have a where.
33353333
// If we find a "where", and there is a preceding item without a where, and
33363334
// if they are on the same source line, then warn.
@@ -4747,8 +4745,6 @@ void swift::performSyntacticExprDiagnostics(const Expr *E,
47474745
void swift::performStmtDiagnostics(const Stmt *S, DeclContext *DC) {
47484746
auto &ctx = DC->getASTContext();
47494747

4750-
TypeChecker::checkUnsupportedProtocolType(ctx, const_cast<Stmt *>(S));
4751-
47524748
if (auto switchStmt = dyn_cast<SwitchStmt>(S))
47534749
checkSwitch(ctx, switchStmt);
47544750

lib/Sema/TypeCheckDeclPrimary.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1659,8 +1659,6 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
16591659

16601660
DeclVisitor<DeclChecker>::visit(decl);
16611661

1662-
TypeChecker::checkUnsupportedProtocolType(decl);
1663-
16641662
if (auto VD = dyn_cast<ValueDecl>(decl)) {
16651663
auto &Context = getASTContext();
16661664
TypeChecker::checkForForbiddenPrefix(Context, VD->getBaseName());

lib/Sema/TypeCheckType.cpp

Lines changed: 0 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -3949,128 +3949,6 @@ Type TypeChecker::substMemberTypeWithBase(ModuleDecl *module,
39493949
return resultType;
39503950
}
39513951

3952-
namespace {
3953-
3954-
class UnsupportedProtocolVisitor
3955-
: public TypeReprVisitor<UnsupportedProtocolVisitor>, public ASTWalker
3956-
{
3957-
ASTContext &Ctx;
3958-
bool checkStatements;
3959-
bool hitTopStmt;
3960-
3961-
public:
3962-
UnsupportedProtocolVisitor(ASTContext &ctx, bool checkStatements)
3963-
: Ctx(ctx), checkStatements(checkStatements), hitTopStmt(false) { }
3964-
3965-
bool walkToTypeReprPre(TypeRepr *T) override {
3966-
if (T->isInvalid())
3967-
return false;
3968-
if (auto compound = dyn_cast<CompoundIdentTypeRepr>(T)) {
3969-
// Only visit the last component to check, because nested typealiases in
3970-
// existentials are okay.
3971-
visit(compound->getComponentRange().back());
3972-
return false;
3973-
}
3974-
// Arbitrary protocol constraints are OK on opaque types.
3975-
if (isa<OpaqueReturnTypeRepr>(T))
3976-
return false;
3977-
3978-
visit(T);
3979-
return true;
3980-
}
3981-
3982-
std::pair<bool, Stmt*> walkToStmtPre(Stmt *S) override {
3983-
if (checkStatements && !hitTopStmt) {
3984-
hitTopStmt = true;
3985-
return { true, S };
3986-
}
3987-
3988-
return { false, S };
3989-
}
3990-
3991-
bool walkToDeclPre(Decl *D) override {
3992-
return !checkStatements;
3993-
}
3994-
3995-
void visitTypeRepr(TypeRepr *T) {
3996-
// Do nothing for all TypeReprs except the ones listed below.
3997-
}
3998-
3999-
void visitIdentTypeRepr(IdentTypeRepr *T) {
4000-
return;
4001-
}
4002-
4003-
void visitRequirements(ArrayRef<RequirementRepr> reqts) {
4004-
for (auto reqt : reqts) {
4005-
if (reqt.getKind() == RequirementReprKind::SameType) {
4006-
if (auto *repr = reqt.getFirstTypeRepr())
4007-
repr->walk(*this);
4008-
if (auto *repr = reqt.getSecondTypeRepr())
4009-
repr->walk(*this);
4010-
}
4011-
}
4012-
}
4013-
};
4014-
4015-
} // end anonymous namespace
4016-
4017-
void TypeChecker::checkUnsupportedProtocolType(Decl *decl) {
4018-
if (!decl || decl->isInvalid())
4019-
return;
4020-
4021-
auto &ctx = decl->getASTContext();
4022-
if (auto *protocolDecl = dyn_cast<ProtocolDecl>(decl)) {
4023-
checkUnsupportedProtocolType(ctx, protocolDecl->getTrailingWhereClause());
4024-
} else if (auto *genericDecl = dyn_cast<GenericTypeDecl>(decl)) {
4025-
checkUnsupportedProtocolType(ctx, genericDecl->getGenericParams());
4026-
checkUnsupportedProtocolType(ctx, genericDecl->getTrailingWhereClause());
4027-
} else if (auto *assocType = dyn_cast<AssociatedTypeDecl>(decl)) {
4028-
checkUnsupportedProtocolType(ctx, assocType->getTrailingWhereClause());
4029-
} else if (auto *extDecl = dyn_cast<ExtensionDecl>(decl)) {
4030-
checkUnsupportedProtocolType(ctx, extDecl->getTrailingWhereClause());
4031-
} else if (auto *subscriptDecl = dyn_cast<SubscriptDecl>(decl)) {
4032-
checkUnsupportedProtocolType(ctx, subscriptDecl->getGenericParams());
4033-
checkUnsupportedProtocolType(ctx, subscriptDecl->getTrailingWhereClause());
4034-
} else if (auto *funcDecl = dyn_cast<AbstractFunctionDecl>(decl)) {
4035-
if (!isa<AccessorDecl>(funcDecl)) {
4036-
checkUnsupportedProtocolType(ctx, funcDecl->getGenericParams());
4037-
checkUnsupportedProtocolType(ctx, funcDecl->getTrailingWhereClause());
4038-
}
4039-
}
4040-
4041-
if (isa<TypeDecl>(decl) || isa<ExtensionDecl>(decl))
4042-
return;
4043-
4044-
UnsupportedProtocolVisitor visitor(ctx, /*checkStatements=*/false);
4045-
decl->walk(visitor);
4046-
}
4047-
4048-
void TypeChecker::checkUnsupportedProtocolType(ASTContext &ctx, Stmt *stmt) {
4049-
if (!stmt)
4050-
return;
4051-
4052-
UnsupportedProtocolVisitor visitor(ctx, /*checkStatements=*/true);
4053-
stmt->walk(visitor);
4054-
}
4055-
4056-
void TypeChecker::checkUnsupportedProtocolType(
4057-
ASTContext &ctx, TrailingWhereClause *whereClause) {
4058-
if (whereClause == nullptr)
4059-
return;
4060-
4061-
UnsupportedProtocolVisitor visitor(ctx, /*checkStatements=*/false);
4062-
visitor.visitRequirements(whereClause->getRequirements());
4063-
}
4064-
4065-
void TypeChecker::checkUnsupportedProtocolType(
4066-
ASTContext &ctx, GenericParamList *genericParams) {
4067-
if (genericParams == nullptr)
4068-
return;
4069-
4070-
UnsupportedProtocolVisitor visitor(ctx, /*checkStatements=*/false);
4071-
visitor.visitRequirements(genericParams->getRequirements());
4072-
}
4073-
40743952
Type CustomAttrTypeRequest::evaluate(Evaluator &eval, CustomAttr *attr,
40753953
DeclContext *dc,
40763954
CustomAttrTypeKind typeKind) const {

lib/Sema/TypeChecker.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -242,22 +242,6 @@ Type getOptionalType(SourceLoc loc, Type elementType);
242242
Expr *resolveDeclRefExpr(UnresolvedDeclRefExpr *UDRE, DeclContext *Context,
243243
bool replaceInvalidRefsWithErrors);
244244

245-
/// Check for unsupported protocol types in the given declaration.
246-
void checkUnsupportedProtocolType(Decl *decl);
247-
248-
/// Check for unsupported protocol types in the given statement.
249-
void checkUnsupportedProtocolType(ASTContext &ctx, Stmt *stmt);
250-
251-
/// Check for unsupported protocol types in the given generic requirement
252-
/// list.
253-
void checkUnsupportedProtocolType(ASTContext &ctx,
254-
TrailingWhereClause *whereClause);
255-
256-
/// Check for unsupported protocol types in the given generic requirement
257-
/// list.
258-
void checkUnsupportedProtocolType(ASTContext &ctx,
259-
GenericParamList *genericParams);
260-
261245
/// Substitute the given base type into the type of the given nested type,
262246
/// producing the effective type that the nested type will have.
263247
///

0 commit comments

Comments
 (0)