Skip to content
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

8311815: Incorrect exhaustivity computation #14872

Closed
wants to merge 4 commits into from

Conversation

lahodaj
Copy link
Contributor

@lahodaj lahodaj commented Jul 13, 2023

Consider code like:

class Test22 {

  record Pair(I i1, I i2) {}

  sealed interface I {}

  record C() implements I {}

  record D() implements I {}

  void exhaustinvenessWithInterface(Pair pairI) {
    switch (pairI) {
      case Pair(D fst, C snd) -> {}
      case Pair(C fst, C snd) -> {}
      case Pair(C fst, I snd) -> {}
      case Pair(D fst, D snd) -> {}
    }
  }
} 

when evaluating exhaustivity, the outcome is wrong: if Pair(D fst, C snd) and Pair(C fst, C snd) get merged into Pair(I _, C_) (and the existing patterns are removed from the pattern set), the remaining patterns are Pair(I _, C_), Pair(C fst, I snd) and Pair(D fst, D snd). The existing implementation does not know how to continue from here (it would need to replace Pair(C fst, I snd) with Pair(C fst, D snd), which would allow to unify Pair(C fst, D snd) and Pair(D fst, D snd) into Pair(I _, D _) and then continue, but that is tricky, as such speculation may not lead to a good result, and we would need to implement backtracking).

But, if Pair(D fst, C snd) and Pair(D fst, D snd) was merged into Pair(D _, I _), it could then be merge with Pair(C fst, I snd) to produce Pair(I _, I _).

The proposal here is aiming to allow the second path, by not removing the existing patterns when merging sealed subtypes. I.e. starting with {Pair(D _, C _), Pair(C _, C_), Pair(C _, I _), Pair(D _, D _)}, we would merge to {Pair(D _, C _), Pair(C _, C_), Pair(C _, I _), Pair(D _, D _), *Pair(I _, C_)*}, and then {Pair(D _, C _), Pair(C _, C_), Pair(C _, I _), Pair(D _, D _), Pair(I _, C_), *Pair(D _, I _)*}, which would then lead to Pair(I _, I _), leading to Pair and confirmed exhaustivity.

This can be achieved easily by not removing binding in reduceBindingPatterns. The problem is that when we stop removing bindings, the algorithm may get into an infinite loop re-adding the same binding over and over. The solution to that is using Sets instead of Lists. To make the algorithm faster and more stable, there are two more additions: a) all record patterns covered by binding patterns are removed from the pattern set; b) reduceNestedPatterns attempts to produce results for all mismatching positions without returning (otherwise the algorithm may constantly only process the first mismatching position without progressing).


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8311815: Incorrect exhaustivity computation (Bug - P3)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/14872/head:pull/14872
$ git checkout pull/14872

Update a local copy of the PR:
$ git checkout pull/14872
$ git pull https://git.openjdk.org/jdk.git pull/14872/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 14872

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

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/14872.diff

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Jul 13, 2023

👋 Welcome back jlahoda! A progress list of the required criteria for merging this PR into pr/14711 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 Pull request is ready for review label Jul 13, 2023
@openjdk
Copy link

openjdk bot commented Jul 13, 2023

@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 compiler-dev@openjdk.org label Jul 13, 2023
@mlbridge
Copy link

mlbridge bot commented Jul 13, 2023

Webrevs

@openjdk-notifier openjdk-notifier bot changed the base branch from pr/14711 to master July 14, 2023 08:25
@openjdk-notifier
Copy link

The parent pull request that this pull request depends on has now been integrated and the target branch of this pull request has been updated. This means that changes from the dependent pull request can start to show up as belonging to this pull request, which may be confusing for reviewers. To remedy this situation, simply merge the latest changes from the new target branch into this pull request by running commands similar to these in the local repository for your personal fork:

git checkout JDK-8311815
git fetch https://git.openjdk.org/jdk.git master
git merge FETCH_HEAD
# if there are conflicts, follow the instructions given by git merge
git commit -m "Merge master"
git push

Copy link
Contributor

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

Choose a reason for hiding this comment

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

looks sensible

@openjdk
Copy link

openjdk bot commented Jul 14, 2023

@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:

8311815: Incorrect exhaustivity computation

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 12 new commits pushed to the master branch:

  • 37ca902: 8310233: Fix THP detection on Linux
  • 81c4e8f: 8304006: jlink should create the jimage file in the native endian for the target platform
  • e8f66bf: 8310949: RISC-V: Initialize UseUnalignedAccesses
  • 19691fa: 6361826: (reflect) provide method for mapping strings to class object for primitive types
  • c84866a: 8310551: vmTestbase/nsk/jdb/interrupt/interrupt001/interrupt001.java timed out due to missing prompt
  • 0d2196f: 8311992: Test java/lang/Thread/virtual/JfrEvents::testVirtualThreadPinned failed
  • f3b96f6: 8311862: RISC-V: small improvements to shift immediate instructions
  • a63f865: 8311946: add support for libgraal specific jtreg tests
  • 167d1c1: 8311986: Disable runtime/os/TestTracePageSizes.java for ShenandoahGC
  • 7539cc0: 8303134: JFR: Missing stack trace during chunk rotation stress
  • ... and 2 more: https://git.openjdk.org/jdk/compare/bbb7ce5137cd3e8365552b42610e19b7ebe43ba1...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 Pull request is ready to be integrated label Jul 14, 2023
@@ -3505,6 +3508,9 @@ record RecordPattern(Type recordType, int _hashCode, Type[] fullComponentTypes,

public RecordPattern(Type recordType, Type[] fullComponentTypes, PatternDescription[] nested) {
this(recordType, hashCode(-1, recordType, nested), fullComponentTypes, nested);
if ("test.Test.R(test.Test.C _, test.Test.R(test.Test.C _, test.Test.R(test.Test.C _, test.Test.C _, test.Test.C _), test.Test.I _), test.Test.I _)".equals(toString())) {
Copy link
Contributor

Choose a reason for hiding this comment

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

sorry missed this, this seems like testing code that should be removed right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops, sorry, will fix.

@lahodaj
Copy link
Contributor Author

lahodaj commented Jul 17, 2023

/integrate

@openjdk
Copy link

openjdk bot commented Jul 17, 2023

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

  • 1c9691b: 8312093: Incorrect javadoc comment text
  • 37ca902: 8310233: Fix THP detection on Linux
  • 81c4e8f: 8304006: jlink should create the jimage file in the native endian for the target platform
  • e8f66bf: 8310949: RISC-V: Initialize UseUnalignedAccesses
  • 19691fa: 6361826: (reflect) provide method for mapping strings to class object for primitive types
  • c84866a: 8310551: vmTestbase/nsk/jdb/interrupt/interrupt001/interrupt001.java timed out due to missing prompt
  • 0d2196f: 8311992: Test java/lang/Thread/virtual/JfrEvents::testVirtualThreadPinned failed
  • f3b96f6: 8311862: RISC-V: small improvements to shift immediate instructions
  • a63f865: 8311946: add support for libgraal specific jtreg tests
  • 167d1c1: 8311986: Disable runtime/os/TestTracePageSizes.java for ShenandoahGC
  • ... and 3 more: https://git.openjdk.org/jdk/compare/bbb7ce5137cd3e8365552b42610e19b7ebe43ba1...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Jul 17, 2023
@openjdk openjdk bot closed this Jul 17, 2023
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Jul 17, 2023
@openjdk
Copy link

openjdk bot commented Jul 17, 2023

@lahodaj Pushed as commit a441216.

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

@lahodaj
Copy link
Contributor Author

lahodaj commented Jul 18, 2023

/backport jdk21

@openjdk
Copy link

openjdk bot commented Jul 18, 2023

@lahodaj the backport was successfully created on the branch lahodaj-backport-a4412166 in my personal fork of openjdk/jdk21. To create a pull request with this backport targeting openjdk/jdk21:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit a4412166 from the openjdk/jdk repository.

The commit being backported was authored by Jan Lahoda on 17 Jul 2023 and was reviewed by Vicente Romero.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk21:

$ git fetch https://github.com/openjdk-bots/jdk21.git lahodaj-backport-a4412166:lahodaj-backport-a4412166
$ git checkout lahodaj-backport-a4412166
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk21.git lahodaj-backport-a4412166

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler compiler-dev@openjdk.org integrated Pull request has been integrated
2 participants