-
Notifications
You must be signed in to change notification settings - Fork 10.6k
[Performance Hints] Add simple check for returning of values of array and dictionary type #84578
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FunctionReturnType
is too generic when we are only checking for arrays and dictionaries. We will implement other kind of return type checks such as existential any that will come under a separate category. We should rename FunctionReturnType
to something like FunctionReturnsHeapAllocatedData
. This will change the name of the check, corresponding diagnostic override, and the name of the documentation file.
7796cb7
to
89cd4ba
Compare
@swift-ci test |
@swift-ci test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
GROUP(UnknownWarningGroup, "unknown-warning-group") | ||
GROUP(CompilationCaching, "compilation-caching") | ||
GROUP(WeakMutability, "weak-mutability") | ||
GROUP(PerfHintReturnTypeImplicitCopy, "perf-hint-return-type-implicit-copy") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is... very specific. Can we perhaps drop the "PerfHint"/"perf-hint-" prefix here and put them within a "PerformanceHints" group?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The goal here was to allow each check/hint to be enabled/disabled individually. And the idea is the each hint will actually have a small handful of diagnostic varieties, functions and closures being separate diagnostic entires in this PR being an example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's fine. You can have an overarching "PerformanceHints" group, and then subgroups for the smaller groups of related diagnostics.
To be blunt, I don't really like the technical approach here, for a couple of reasons:
|
d053a90
to
6cb0646
Compare
@DougGregor thanks for the feedback! I have switched the implementation over to use |
7050c7b
to
d08816a
Compare
@swift-ci test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great, thank you!
GROUP(UnknownWarningGroup, "unknown-warning-group") | ||
GROUP(CompilationCaching, "compilation-caching") | ||
GROUP(WeakMutability, "weak-mutability") | ||
GROUP(PerfHintReturnTypeImplicitCopy, "perf-hint-return-type-implicit-copy") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's fine. You can have an overarching "PerformanceHints" group, and then subgroups for the smaller groups of related diagnostics.
return !ctx.Diags.isIgnoredDiagnostic(diag::perf_hint_closure_returns_array.ID) || | ||
!ctx.Diags.isIgnoredDiagnostic(diag::perf_hint_function_returns_array.ID); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this is the best we have right now. At some point (not for this PR!) we should introduce a group-level query for this, which probably means a different underlying data structure.
@swift-ci smoke test |
… and dictionary type This check will run on each type-checked primary input of the current compilation and emit a warning diagnostic for all discovered occurences of this code pattern when the performance hint diagnostic is enabled
@swift-ci smoke test |
Add simple check for returning of values of array and dictionary type
This check will run on each type-checked primary input of the current compilation and emit a warning diagnostic for all discovered occurrences of this code pattern when the performance hints feature is enabled.
Add
@performanceOverride
attribute to silence individual performance hint diagnosticsThis attribute will accept two parameters: a diagnostic group identifier first, and a string literal 'explanation' for the override reason second