Skip to content

do not generate null checks for record patterns#1884

Closed
vicente-romero-oracle wants to merge 3 commits intoopenjdk:bworldfrom
vicente-romero-oracle:do.not.generate.null.checks.for.record.patterns
Closed

do not generate null checks for record patterns#1884
vicente-romero-oracle wants to merge 3 commits intoopenjdk:bworldfrom
vicente-romero-oracle:do.not.generate.null.checks.for.record.patterns

Conversation

@vicente-romero-oracle
Copy link
Contributor

@vicente-romero-oracle vicente-romero-oracle commented Jan 11, 2026

do not generate null checks for record patterns


Progress

  • Change must not contain extraneous whitespace

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 1884

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

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/valhalla/pull/1884.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Jan 11, 2026

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

@openjdk
Copy link

openjdk bot commented Jan 11, 2026

@vicente-romero-oracle 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:

do not generate null checks for record patterns

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 no new commits pushed to the bworld branch. If another commit should be pushed before you perform the /integrate command, your PR will be automatically rebased. If you prefer to avoid any potential automatic rebasing, please check the documentation for the /integrate command for further details.

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

@openjdk openjdk bot added ready Pull request is ready to be integrated rfr Pull request is ready for review labels Jan 11, 2026
@mlbridge
Copy link

mlbridge bot commented Jan 11, 2026

Webrevs

@Override
public void visitLetExpr(LetExpr tree) {
// don't recurse inside let expressions, they are backend artifacts
result = tree;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

offline suggestion from Jan Lahoda:

this code will skip all let expressions which is too broad, as let expressions are generated also by switch expressions but could contain user code. For example there is no null check generated in this case:

void main() {
    int i = switch (new Object()) {
        default -> {
            Object obj = null;
            Object! nonNull = obj;
            yield 0;
        }
    };
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Actually, I think we can remove this visitor. Sure, javac will add an extra, redundant null check for null-restricted type test patterns, but that's not incorrect (this check will never throw NPE because, if null, the pattern won't match -- thanks to your changes in TransPatterns). I think I prefer a redundant check than having to mark all LetExpr that might need recursion (as we will surely forget some).

Separately, we can work on removing redundant null checks -- e.g. for things that are co-compiled and such, in which case this will fall out for free.

@vicente-romero-oracle
Copy link
Contributor Author

superseded by: #1902

@vicente-romero-oracle vicente-romero-oracle deleted the do.not.generate.null.checks.for.record.patterns branch January 14, 2026 14:01
Copy link
Collaborator

@mcimadamore mcimadamore left a comment

Choose a reason for hiding this comment

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

Looks good!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready Pull request is ready to be integrated rfr Pull request is ready for review

Development

Successfully merging this pull request may close these issues.

2 participants