Skip to content

Commit d0ebe90

Browse files
committed
Move diagnostics to postWalk and make all checks consistent
1 parent 30c6b5f commit d0ebe90

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

lib/Sema/PerformanceHints.cpp

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,15 @@ bool hasExistentialAnyInType(Type type) {
7575
return type->getCanonicalType().findIf(isExistentialType);
7676
}
7777

78-
void checkExistentialInFunctionReturnType(FuncDecl *FD,
78+
void checkExistentialInFunctionReturnType(const FuncDecl *FD,
7979
DiagnosticEngine &Diags) {
8080
Type T = FD->getResultInterfaceType();
8181

8282
if (hasExistentialAnyInType(T))
8383
Diags.diagnose(FD, diag::perf_hint_func_returns_existential, FD);
8484
}
8585

86-
void checkExistentialInClosureReturnType(ClosureExpr *CE,
86+
void checkExistentialInClosureReturnType(const ClosureExpr *CE,
8787
DiagnosticEngine &Diags) {
8888
Type T = CE->getResultType();
8989

@@ -132,6 +132,13 @@ class PerformanceHintDiagnosticWalker final : public ASTWalker {
132132
if (P->isImplicit())
133133
return Action::SkipNode(P);
134134

135+
return Action::Continue(P);
136+
}
137+
138+
PostWalkResult<Pattern *> walkToPatternPost(Pattern *P) override {
139+
assert(!P->isImplicit() &&
140+
"Traversing implicit patterns is disabled in the pre-walk visitor");
141+
135142
if (const AnyPattern *AP = dyn_cast<AnyPattern>(P)) {
136143
checkExistentialInPatternType(AP, Ctx.Diags);
137144
}
@@ -143,10 +150,6 @@ class PerformanceHintDiagnosticWalker final : public ASTWalker {
143150
if (E->isImplicit())
144151
return Action::SkipNode(E);
145152

146-
if (const ClosureExpr* Closure = dyn_cast<ClosureExpr>(E)) {
147-
checkImplicitCopyReturnType(Closure, Ctx.Diags);
148-
}
149-
150153
return Action::Continue(E);
151154
}
152155

@@ -155,8 +158,9 @@ class PerformanceHintDiagnosticWalker final : public ASTWalker {
155158
!E->isImplicit() &&
156159
"Traversing implicit expressions is disabled in the pre-walk visitor");
157160

158-
if (auto Closure = dyn_cast<ClosureExpr>(E)) {
159-
checkExistentialInClosureReturnType(Closure, Ctx.Diags);
161+
if (const ClosureExpr *CE = dyn_cast<ClosureExpr>(E)) {
162+
checkImplicitCopyReturnType(CE, Ctx.Diags);
163+
checkExistentialInClosureReturnType(CE, Ctx.Diags);
160164
}
161165

162166
return Action::Continue(E);
@@ -166,14 +170,6 @@ class PerformanceHintDiagnosticWalker final : public ASTWalker {
166170
if (D->isImplicit())
167171
return Action::SkipNode();
168172

169-
if (const FuncDecl *FD = dyn_cast<FuncDecl>(D)) {
170-
checkImplicitCopyReturnType(FD, Ctx.Diags);
171-
} else if (const VarDecl *VD = dyn_cast<VarDecl>(D)) {
172-
checkExistentialInVariableType(VD, Ctx.Diags);
173-
} else if (const TypeAliasDecl *TAD = dyn_cast<TypeAliasDecl>(D)) {
174-
checkExistentialInTypeAlias(TAD, Ctx.Diags);
175-
}
176-
177173
return Action::Continue();
178174
}
179175

@@ -182,8 +178,13 @@ class PerformanceHintDiagnosticWalker final : public ASTWalker {
182178
!D->isImplicit() &&
183179
"Traversing implicit declarations is disabled in the pre-walk visitor");
184180

185-
if (auto *FD = dyn_cast<FuncDecl>(D)) {
181+
if (const FuncDecl *FD = dyn_cast<FuncDecl>(D)) {
182+
checkImplicitCopyReturnType(FD, Ctx.Diags);
186183
checkExistentialInFunctionReturnType(FD, Ctx.Diags);
184+
} else if (const VarDecl *VD = dyn_cast<VarDecl>(D)) {
185+
checkExistentialInVariableType(VD, Ctx.Diags);
186+
} else if (const TypeAliasDecl *TAD = dyn_cast<TypeAliasDecl>(D)) {
187+
checkExistentialInTypeAlias(TAD, Ctx.Diags);
187188
}
188189

189190
return Action::Continue();

0 commit comments

Comments
 (0)