Skip to content

Commit 23c1d66

Browse files
theblixguyAnthonyLatsis
authored andcommitted
[NFC, Typechecker] Remove UnsupportedProtocolVisitor and checkUnsupportedProtocolType()
1 parent 749a0ae commit 23c1d66

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
@@ -3342,8 +3342,6 @@ static void checkSwitch(ASTContext &ctx, const SwitchStmt *stmt) {
33423342
// We want to warn about "case .Foo, .Bar where 1 != 100:" since the where
33433343
// clause only applies to the second case, and this is surprising.
33443344
for (auto cs : stmt->getCases()) {
3345-
TypeChecker::checkUnsupportedProtocolType(ctx, cs);
3346-
33473345
// The case statement can have multiple case items, each can have a where.
33483346
// If we find a "where", and there is a preceding item without a where, and
33493347
// if they are on the same source line, then warn.
@@ -4760,8 +4758,6 @@ void swift::performSyntacticExprDiagnostics(const Expr *E,
47604758
void swift::performStmtDiagnostics(const Stmt *S, DeclContext *DC) {
47614759
auto &ctx = DC->getASTContext();
47624760

4763-
TypeChecker::checkUnsupportedProtocolType(ctx, const_cast<Stmt *>(S));
4764-
47654761
if (auto switchStmt = dyn_cast<SwitchStmt>(S))
47664762
checkSwitch(ctx, switchStmt);
47674763

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
@@ -4015,128 +4015,6 @@ Type TypeChecker::substMemberTypeWithBase(ModuleDecl *module,
40154015
return resultType;
40164016
}
40174017

4018-
namespace {
4019-
4020-
class UnsupportedProtocolVisitor
4021-
: public TypeReprVisitor<UnsupportedProtocolVisitor>, public ASTWalker
4022-
{
4023-
ASTContext &Ctx;
4024-
bool checkStatements;
4025-
bool hitTopStmt;
4026-
4027-
public:
4028-
UnsupportedProtocolVisitor(ASTContext &ctx, bool checkStatements)
4029-
: Ctx(ctx), checkStatements(checkStatements), hitTopStmt(false) { }
4030-
4031-
bool walkToTypeReprPre(TypeRepr *T) override {
4032-
if (T->isInvalid())
4033-
return false;
4034-
if (auto compound = dyn_cast<CompoundIdentTypeRepr>(T)) {
4035-
// Only visit the last component to check, because nested typealiases in
4036-
// existentials are okay.
4037-
visit(compound->getComponentRange().back());
4038-
return false;
4039-
}
4040-
// Arbitrary protocol constraints are OK on opaque types.
4041-
if (isa<OpaqueReturnTypeRepr>(T))
4042-
return false;
4043-
4044-
visit(T);
4045-
return true;
4046-
}
4047-
4048-
std::pair<bool, Stmt*> walkToStmtPre(Stmt *S) override {
4049-
if (checkStatements && !hitTopStmt) {
4050-
hitTopStmt = true;
4051-
return { true, S };
4052-
}
4053-
4054-
return { false, S };
4055-
}
4056-
4057-
bool walkToDeclPre(Decl *D) override {
4058-
return !checkStatements;
4059-
}
4060-
4061-
void visitTypeRepr(TypeRepr *T) {
4062-
// Do nothing for all TypeReprs except the ones listed below.
4063-
}
4064-
4065-
void visitIdentTypeRepr(IdentTypeRepr *T) {
4066-
return;
4067-
}
4068-
4069-
void visitRequirements(ArrayRef<RequirementRepr> reqts) {
4070-
for (auto reqt : reqts) {
4071-
if (reqt.getKind() == RequirementReprKind::SameType) {
4072-
if (auto *repr = reqt.getFirstTypeRepr())
4073-
repr->walk(*this);
4074-
if (auto *repr = reqt.getSecondTypeRepr())
4075-
repr->walk(*this);
4076-
}
4077-
}
4078-
}
4079-
};
4080-
4081-
} // end anonymous namespace
4082-
4083-
void TypeChecker::checkUnsupportedProtocolType(Decl *decl) {
4084-
if (!decl || decl->isInvalid())
4085-
return;
4086-
4087-
auto &ctx = decl->getASTContext();
4088-
if (auto *protocolDecl = dyn_cast<ProtocolDecl>(decl)) {
4089-
checkUnsupportedProtocolType(ctx, protocolDecl->getTrailingWhereClause());
4090-
} else if (auto *genericDecl = dyn_cast<GenericTypeDecl>(decl)) {
4091-
checkUnsupportedProtocolType(ctx, genericDecl->getGenericParams());
4092-
checkUnsupportedProtocolType(ctx, genericDecl->getTrailingWhereClause());
4093-
} else if (auto *assocType = dyn_cast<AssociatedTypeDecl>(decl)) {
4094-
checkUnsupportedProtocolType(ctx, assocType->getTrailingWhereClause());
4095-
} else if (auto *extDecl = dyn_cast<ExtensionDecl>(decl)) {
4096-
checkUnsupportedProtocolType(ctx, extDecl->getTrailingWhereClause());
4097-
} else if (auto *subscriptDecl = dyn_cast<SubscriptDecl>(decl)) {
4098-
checkUnsupportedProtocolType(ctx, subscriptDecl->getGenericParams());
4099-
checkUnsupportedProtocolType(ctx, subscriptDecl->getTrailingWhereClause());
4100-
} else if (auto *funcDecl = dyn_cast<AbstractFunctionDecl>(decl)) {
4101-
if (!isa<AccessorDecl>(funcDecl)) {
4102-
checkUnsupportedProtocolType(ctx, funcDecl->getGenericParams());
4103-
checkUnsupportedProtocolType(ctx, funcDecl->getTrailingWhereClause());
4104-
}
4105-
}
4106-
4107-
if (isa<TypeDecl>(decl) || isa<ExtensionDecl>(decl))
4108-
return;
4109-
4110-
UnsupportedProtocolVisitor visitor(ctx, /*checkStatements=*/false);
4111-
decl->walk(visitor);
4112-
}
4113-
4114-
void TypeChecker::checkUnsupportedProtocolType(ASTContext &ctx, Stmt *stmt) {
4115-
if (!stmt)
4116-
return;
4117-
4118-
UnsupportedProtocolVisitor visitor(ctx, /*checkStatements=*/true);
4119-
stmt->walk(visitor);
4120-
}
4121-
4122-
void TypeChecker::checkUnsupportedProtocolType(
4123-
ASTContext &ctx, TrailingWhereClause *whereClause) {
4124-
if (whereClause == nullptr)
4125-
return;
4126-
4127-
UnsupportedProtocolVisitor visitor(ctx, /*checkStatements=*/false);
4128-
visitor.visitRequirements(whereClause->getRequirements());
4129-
}
4130-
4131-
void TypeChecker::checkUnsupportedProtocolType(
4132-
ASTContext &ctx, GenericParamList *genericParams) {
4133-
if (genericParams == nullptr)
4134-
return;
4135-
4136-
UnsupportedProtocolVisitor visitor(ctx, /*checkStatements=*/false);
4137-
visitor.visitRequirements(genericParams->getRequirements());
4138-
}
4139-
41404018
Type CustomAttrTypeRequest::evaluate(Evaluator &eval, CustomAttr *attr,
41414019
DeclContext *dc,
41424020
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)