RFR: 8367499: Refactor exhaustiveness computation from Flow into a separate class

Jan Lahoda jlahoda at openjdk.org
Fri Sep 12 10:57:15 UTC 2025


On Fri, 12 Sep 2025 10:46:26 GMT, Francesco Andreuzzi <fandreuzzi at openjdk.org> wrote:

>> Currently the switch exhaustiveness computation code is part of `Flow`. And while conceptually the check is part of the `Flow` phase, the code is >500 lines of code currently, and likely to get bigger/more complicated in the future. Among other reasons due to enhancements like https://bugs.openjdk.org/browse/JDK-8367530.
>> 
>> The proposal herein is to move the exhaustiveness computation to a separate class `ExhastivenessComputer`. There's no functional change, only move of the code. This is intentional, to aid the review process.
>> 
>> One possibility to inspect what is happening is:
>> 
>> git show upstream/pr/27247:src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Flow.java >/tmp/Flow-original.java
>> diff -d -w /tmp/Flow-original.java src/jdk.compiler/share/classes/com/sun/tools/javac/comp/ExhaustivenessComputer.java >/tmp/exhaustivenesscomputer-comparison.diff
>> diff -d -w /tmp/Flow-original.java src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Flow.java >/tmp/flow-comparison.diff
>> 
>> and inspecting `/tmp/exhaustivenesscomputer-comparison.diff`, `/tmp/flow-comparison.diff`.
>
> src/jdk.compiler/share/classes/com/sun/tools/javac/comp/ExhaustivenessComputer.java line 204:
> 
>> 202: 
>> 203:         for (PatternDescription pdOne : patterns) {
>> 204:             if (pdOne instanceof BindingPattern bpOne) {
> 
> The scope of this `if` is quite wide, you could consider inverting the condition and `continue`ing if the condition does not match. This would save an indentation level.

Sorry, but the point here is to move the code from one place to another (as suggested in the description). I suspect that any change, despite how desirable it might look, is likely to make reviewing this change more difficult, and hence I would like to avoid that.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/27253#discussion_r2343837511


More information about the compiler-dev mailing list