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

JDK-8302202: Incorrect desugaring of null-allowed nested patterns #12572

Closed
wants to merge 1 commit into from

Conversation

lahodaj
Copy link
Contributor

@lahodaj lahodaj commented Feb 15, 2023

Considering code like:

    private String test1b(Object i) {
        return switch (i) {
            case R1(Object o) when o == null -> "R1(null)";
            case R1(Object o) -> "R1(!null)";
            default -> "default";
        };
    }

javac will try to factor-out the common prefix, i.e. R1, and produce something along these lines:

        switch (i) {
            case R1 $r:
                Object c = $r.c();
                switch (c) {
                    case Object o when o == null: yield "R1(null)";
                    case Object o: yield "R1(!null)";
                }
            default -> "default";
        };

The problem with this code is that both cases in the nested switch must match null, but the bootstrap protocol only allows one case to match null (the SwitchBootstraps.typeSwitch method will return -1 for null). So this translation is broken, and will not match the first case if the component is null.

There are multiple ways to solve this problem, but the proposal here is change the way we accumulate the cases from which we factor out the common prefix, by stopping the accumulation after the first nullable case.

Another related issue is that when factoring out the common prefix, if the last case in the nested switch is has an unconditional pattern, but also has a guard, we need to generate a default to continue properly in the outer switch. Currently, the default is not generated when there's an unconditional pattern in the case, despite having a guard, and hence the case as a whole is not unconditional.


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-8302202: Incorrect desugaring of null-allowed nested patterns

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 12572

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

Using diff file

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

@bridgekeeper
Copy link

bridgekeeper bot commented Feb 15, 2023

👋 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 Pull request is ready for review label Feb 15, 2023
@openjdk
Copy link

openjdk bot commented Feb 15, 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 Feb 15, 2023
@mlbridge
Copy link

mlbridge bot commented Feb 15, 2023

Webrevs

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 Feb 16, 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:

8302202: Incorrect desugaring of null-allowed nested patterns

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

  • 574b48c: 8302678: validate_source fails after JDK-8293313
  • 90e0922: 8293313: NMT: Rework MallocLimit
  • f558a6c: 8298276: JFR: Update NMT events to make use of common periodic timestamp feature
  • a58fa6e: 8302514: Misleading error generated when empty class file encountered
  • 3cc459b: 8302595: use-after-free related to GraphKit::clone_map
  • 2e3cea0: 8302594: use-after-free in Node::destruct
  • 9b911b4: 8301959: Compile command in compiler.loopopts.TestRemoveEmptyCountedLoop does not work
  • c29a136: 8291735: methods_do() always run at exit
  • 687a461: 8302464: Parallel: Remove unreachable code in callers of numa_has_static_binding
  • 84c058b: 8300549: JFileChooser Approve button tooltip is null in Aqua L&F in CUSTOM_DIALOG mode
  • ... and 79 more: https://git.openjdk.org/jdk/compare/723433dbebc6b542dab445a89b7437149730b858...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 Feb 16, 2023
@biboudis
Copy link
Member

After running some more examples, the patch looks good to me too 💯

@lahodaj
Copy link
Contributor Author

lahodaj commented Feb 17, 2023

/integrate

@openjdk
Copy link

openjdk bot commented Feb 17, 2023

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

  • c4ffe4b: 8301494: Replace NULL with nullptr in cpu/arm
  • 4f1cffd: 8302674: Parallel: Remove unused methods in MutableNUMASpace
  • c91cd28: 8301481: Replace NULL with nullptr in os/windows
  • 47ca577: 8301491: C2: java.lang.StringUTF16::indexOfChar intrinsic called with negative character argument
  • 49eb68b: 8296158: Refactor the verification of CDS region checksum
  • 655a712: 8301444: Port fdlibm hyperbolic transcendental functions to Java
  • b242eef: 8280419: Remove dead code related to VerifyThread and verify_thread()
  • 4ce493f: 8302225: SunJCE Provider doesn't validate key sizes when using 'constrained' transforms for AES/KW and AES/KWP
  • a39cf2e: 8301753: AppendFile/WriteFile has differences between make 3.81 and 4+
  • de80dd9: 8296010: AssertionError in annotationTargetType
  • ... and 90 more: https://git.openjdk.org/jdk/compare/723433dbebc6b542dab445a89b7437149730b858...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Feb 17, 2023

@lahodaj Pushed as commit dc55a7f.

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

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
Development

Successfully merging this pull request may close these issues.

3 participants