You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[analysis server] Improve dead code removal to prepare for sound-flow-analysis.
The following improvements are made to the "remove dead code" quick fix:
- Dead code removal can now replace conditional expressions like
`condition ? live : dead` or `condition ? dead : live` with just the
live subexpression, provided that the condition appears free of side
effects.
- Dead code removal can now replace `if` statements like `if
(condition) live; else dead;` or `if (condition) dead; else live;`
with just the live statement, provided that the condition appears
free of side effects.
- Dead code removal can now fully remove `if` statements like `if
(condition) dead;`, provided that the condition appears free of side
effects.
Extra care is taken around opening and closing braces to try to
preserve reasonable formatting as much as possible.
These features were chosen by examining the set of new dead code
warnings that pop up inside google3 if the sound-flow-analysis
language feature is enabled. They are sufficient to allow 98% of those
new warnings to be addressed by the quick fix. This should help
customers adjust their code quickly when moving to a language version
that enables this language feature.
The notion that a condition "appears free of side effects" is defined
to include casts, non-null assertions, and getter invocations. It is
of course possible that a getter invocation, a cast, or a non-null
assertion could have a side effect that is important, but it would be
difficult to build the necessary static analysis to detect these
cases, and in practice, they don't happen very often. Considering that
the "remove dead code" quick fix is not usable in an automated fashion
(it must be explicitly requested by the user in their editor for each
piece of affected dead code), I believe this is a good tradeoff.
Bug: #60438
Change-Id: Ied43500c4b7a729bbd686708ab10e80e72f22088
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/425180
Commit-Queue: Paul Berry <[email protected]>
Reviewed-by: Samuel Rawlins <[email protected]>
0 commit comments