Skip to content
This repository has been archived by the owner. It is now read-only.

8268871: Adjust javac to updated exhaustiveness specification #78

Closed
wants to merge 2 commits into from

Conversation

lahodaj
Copy link
Contributor

@lahodaj lahodaj commented Jun 16, 2021

The current updates spec for pattern matching in switch:
http://cr.openjdk.java.net/~gbierman/jep406/jep406-20210608/specs/patterns-switch-jls.html

tweaks the definition of exhaustive switches so that it include handling special types, like intersection types, sealed subclasses of sealed types, like:

sealed abstract class A permits B, C {}
final class B extends A {}
sealed abstract class C extends A permits D, E {}
final class D extends C {}
final class E extends C {}

public class Test {
  public static void main(String[] args) {
     A a = new D();
     System.out.println(
        switch (a) {
           case B x -> "B";
           case D x -> "D";
           case E x -> "E";
        });
  }
}

etc. This patch attempts to tweak javac to work according to this specification. It builds covered types based on what types are covered, i.e. if all subtypes of a sealed type are covered, the sealed type itself is covered, and this is done transitively, so that in the example above, D and E will mark C as covered, and then B and C will mark A as covered, and as the type if a is A, it means the switch is exhaustive.


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

  • JDK-8268871: Adjust javac to updated exhaustiveness specification

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk17 pull/78/head:pull/78
$ git checkout pull/78

Update a local copy of the PR:
$ git checkout pull/78
$ git pull https://git.openjdk.java.net/jdk17 pull/78/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 78

View PR using the GUI difftool:
$ git pr show -t 78

Using diff file

Download this PR as a diff file:
https://git.openjdk.java.net/jdk17/pull/78.diff

@bridgekeeper
Copy link

bridgekeeper bot commented Jun 16, 2021

👋 Welcome back jlahoda! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk openjdk bot added the rfr label Jun 16, 2021
@openjdk
Copy link

openjdk bot commented Jun 16, 2021

@lahodaj The following label will be automatically applied to this pull request:

  • compiler

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the compiler label Jun 16, 2021
@mlbridge
Copy link

mlbridge bot commented Jun 16, 2021

Webrevs

public void testExhaustiveIntersection(Path base) throws Exception {
doTest(base,
new String[]{"""
package lib;
Copy link
Contributor

@vicente-romero-oracle vicente-romero-oracle Jun 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it will be nice to have additional tests with conditional patterns (total and not) to stress all the possible code paths

Copy link
Contributor Author

@lahodaj lahodaj Jun 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Vicente! I've updated the patch based on your comments in a7a6169 .

What do you think?

Thanks!

}

case TYP -> {
for (Type sup : types.directSupertypes(sym.type)) {
Copy link
Contributor

@vicente-romero-oracle vicente-romero-oracle Jun 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just an observation, once a symbol has been processed, there is no need to process it again so you could keep a set of visited symbols to avoid visiting them again. Not a big deal performance wise unless we are switching on a sealed hierarchy with a lot of members I guess > 50 but we know what automatic code generators are capable of :)

Copy link
Contributor

@vicente-romero-oracle vicente-romero-oracle left a comment

lgtm

@openjdk
Copy link

openjdk bot commented Jun 24, 2021

@lahodaj This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8268871: Adjust javac to updated exhaustiveness specification

Reviewed-by: vromero

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 73 new commits pushed to the master branch:

  • 3fb28d3: 8269218: GaloisCounterMode.overlapDetection misses the JDK-8263436 fix again
  • d3d3b22: 8269265: ProblemList serviceability/sa/TestJmapCoreMetaspace.java with ZGC
  • 0c3fc27: 8268482: compiler/intrinsics/VectorizedMismatchTest.java failed with failed: length in range
  • a30141d: 8269179: Crash in TestMacroLogicVector::testSubWordBoolean: assert(_base >= VectorMask && _base <= VectorZ) failed: Not a Vector
  • b474314: 8266854: LibraryCallKit::inline_preconditions_checkIndex modifies control flow even if the intrinsic bailed out
  • 7e96318: 8254571: Erroneous generic type inference in a lambda expression with a checked exception
  • 1b2147a: 8269125: Klass enqueue element size calculation wrong when traceid value cross compress limit
  • bf70620: 8268961: Parenthesized pattern with guards does not work
  • 8128ca1: 8269066: assert(ZAddress::is_marked(addr)) failed: Should be marked
  • 1323be5: 8269064: Dropped messages of AsyncLogWriter cause memleak
  • ... and 63 more: https://git.openjdk.java.net/jdk17/compare/b18de6cf79e0195736d94b08be67f10ca7c3cd08...master

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready label Jun 24, 2021
@lahodaj
Copy link
Contributor Author

lahodaj commented Jun 25, 2021

/integrate

@openjdk
Copy link

openjdk bot commented Jun 25, 2021

Going to push as commit 4eb3212.
Since your change was applied there have been 80 commits pushed to the master branch:

  • 44691cc: 8268972: Add default impl for recent new Reporter.print method
  • 7ab1285: 8267610: NPE at at jdk.compiler/com.sun.tools.javac.jvm.Code.emitop
  • cfa6a99: 8269316: ProblemList vmTestbase/vm/mlvm/mixed/stress/regression/b6969574/INDIFY_Test.java on Linux-X64 -Xcomp
  • 22d8675: 8269315: ProblemList javax/swing/JFileChooser/FileSystemView/SystemIconTest.java on Win-X64
  • 443a79a: 8269314: ProblemList serviceability/dcmd/gc/RunFinalizationTest.java on Win-X64 and linux-aarch64
  • 424cc50: 8269307: ProblemList java/awt/KeyboardFocusmanager/TypeAhead/ButtonActionKeyTest/ButtonActionKeyTest.java on win-x64
  • 63bcd33: 8269246: Scoped ByteBuffer vector access
  • 3fb28d3: 8269218: GaloisCounterMode.overlapDetection misses the JDK-8263436 fix again
  • d3d3b22: 8269265: ProblemList serviceability/sa/TestJmapCoreMetaspace.java with ZGC
  • 0c3fc27: 8268482: compiler/intrinsics/VectorizedMismatchTest.java failed with failed: length in range
  • ... and 70 more: https://git.openjdk.java.net/jdk17/compare/b18de6cf79e0195736d94b08be67f10ca7c3cd08...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot closed this Jun 25, 2021
@openjdk openjdk bot added integrated and removed ready labels Jun 25, 2021
@openjdk
Copy link

openjdk bot commented Jun 25, 2021

@lahodaj Pushed as commit 4eb3212.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

@openjdk openjdk bot removed the rfr label Jun 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
compiler integrated
2 participants