Skip to content

Issue warnings for code that can be optimized #1445

@wmdietl

Description

@wmdietl

We implement four classical dataflow analyses:

https://github.com/eisop/checker-framework/tree/master/dataflow/src/main/java/org/checkerframework/dataflow/busyexpr
https://github.com/eisop/checker-framework/tree/master/dataflow/src/main/java/org/checkerframework/dataflow/constantpropagation
https://github.com/eisop/checker-framework/tree/master/dataflow/src/main/java/org/checkerframework/dataflow/livevariable
https://github.com/eisop/checker-framework/tree/master/dataflow/src/main/java/org/checkerframework/dataflow/reachingdef

However, we don't use the results of these analyses.
We should be able to e.g. use reachingdef information to implement dead store warnings.

For this code:

class DeadStores {
  int foo() {
    int i = 55;
    i = 99;
    i = 7;
    return i;
  }
}

Error Prone issues one warning on the initializer only https://errorprone.info/bugpattern/UnusedVariable .

However, for other dead stores Error Prone doesn't issue any warnings, e.g. for this variant:

  public int foo() {
    int i;
    i = 99;
    i = 66;
    i = 7;
    return i;
  }

javac or the JVM will optimize this code, so there is likely no performance to be gained.
However, warnings from standard code optimizations that build on top of the example dataflow analyses might still improve the readability of the code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions