Skip to content

Use a type variable's upper bound when deciding relevance - #8189

Closed
mernst wants to merge 58 commits into
resolve-member-type-inheritancefrom
relevance-type-variable-upper-bound
Closed

mernst wants to merge 58 commits into
resolve-member-type-inheritancefrom
relevance-type-variable-upper-bound

Conversation

@mernst

@mernst mernst commented Sep 16, 2026

Copy link
Copy Markdown
Member

Part 8, splitting #8177 into reviewable pieces. Based on #8187.

Note on the diff: this branch merges #8188, whose build-file change it extends, so this PR shows three commits. Review only Use a type variable's upper bound when deciding relevance.

A use of a type variable is relevant exactly when the type variable's upper bound is relevant, so resolve such a use to its bound rather than conservatively retaining every annotation written on it.

JavaParserUtil.resolveTypeVariableName answers which type variable a name refers to. It shares its scope walk with resolveTypeName, so the two agree about which declaration a name refers to. That walk now searches a type declaration's declared member types before its type parameters, because a declared member type shadows a type parameter of the same name -- whereas a member type that the declaration merely inherits does not.

ainferRelevanceGenerateAjava deletes the generated IrrelevantTypeVariable.java before the validation pass: the test expects an anno.on.irrelevant warning, and the // :: comment stating that expectation is stripped when the file is copied, so the validation pass would otherwise report the warning as unexpected.

🤖 Generated with Claude Code

mernst and others added 3 commits September 16, 2026 12:12
Every other `ainfer*Generate*` task deletes the WPI output directory with
`wpiOutputDirectory()` and `DirectoryDeleter`.  This task still inlined an
equivalent loop, which the merge of the commit that introduced those helpers
left behind.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
A use of a type variable is relevant exactly when the type variable's upper
bound is relevant, so resolve such a use to its bound rather than conservatively
retaining every annotation that is written on it.

`JavaParserUtil.resolveTypeVariableName` answers which type variable a name
refers to.  It shares its scope walk with `resolveTypeName`, so the two agree
about which declaration a name refers to.  That walk now searches a type
declaration's declared member types before its type parameters, because a
declared member type shadows a type parameter of the same name -- whereas a
member type that the declaration merely inherits does not.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
mernst and others added 26 commits September 16, 2026 12:36
When the checker supports no invisible qualifier, `removeUnprintedAnnotations`
has no effect, so skip both it and the clone that it requires.  Also, walk the
AST rather than building a list of every node in it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…ork-fork-mernst-branch-ajava-remove-annotations-from-ast into ajava-omit-irrelevant

# Conflicts:
#	framework/src/main/java/org/checkerframework/common/wholeprograminference/WholeProgramInferenceJavaParserStorage.java
…nst-branch-ajava-omit-irrelevant into resolve-type-name-local-anonymous
…ork-fork-mernst-branch-resolve-type-name-local-anonymous into resolve-type-name-member-scope
Their computation is reflective, and they do not change over the lifetime of a
`WholeProgramInferenceJavaParserStorage`.  The computation is lazy rather than
in the constructor, because `getSupportedTypeQualifiers()` might not yet yield
its final result when the storage is constructed.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…-fork-mernst-branch-resolve-type-name-member-scope into resolve-member-type-inheritance
…k-fork-mernst-branch-resolve-member-type-inheritance into relevance-type-variable-upper-bound
…ork-fork-mernst-branch-ajava-remove-annotations-from-ast into ajava-omit-irrelevant
…nst-branch-ajava-omit-irrelevant into resolve-type-name-local-anonymous
…ork-fork-mernst-branch-resolve-type-name-local-anonymous into resolve-type-name-member-scope
…-fork-mernst-branch-resolve-type-name-member-scope into resolve-member-type-inheritance
…k-fork-mernst-branch-resolve-member-type-inheritance into relevance-type-variable-upper-bound
…-mernst-branch-resolve-type-name-memoize into resolve-type-name-local-anonymous
…ork-fork-mernst-branch-ajava-remove-annotations-from-ast into ajava-omit-irrelevant
…nst-branch-ajava-omit-irrelevant into resolve-type-name-local-anonymous
…ork-fork-mernst-branch-resolve-type-name-local-anonymous into resolve-type-name-member-scope
…-fork-mernst-branch-resolve-type-name-member-scope into resolve-member-type-inheritance
mernst and others added 28 commits September 16, 2026 20:18
* Skip cloning and walking the AST when no annotation can be removed.
* Don't crash if a declaration has no variables; be conservative instead.
* Fix comments about where an annotation on a type parameter declaration lands.
* Narrow a @SuppressWarnings from a method to a single expression.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…ork-fork-mernst-branch-ajava-remove-annotations-from-ast into ajava-omit-irrelevant
…nst-branch-ajava-omit-irrelevant into resolve-type-name-local-anonymous
…ork-fork-mernst-branch-resolve-type-name-local-anonymous into resolve-type-name-member-scope
…-fork-mernst-branch-resolve-type-name-member-scope into resolve-member-type-inheritance
…k-fork-mernst-branch-resolve-member-type-inheritance into relevance-type-variable-upper-bound
Also correct the comment about why the compilation unit must be cloned.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…ork-fork-mernst-branch-ajava-remove-annotations-from-ast into ajava-omit-irrelevant

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…nst-branch-ajava-omit-irrelevant into resolve-type-name-local-anonymous
…ork-fork-mernst-branch-resolve-type-name-local-anonymous into resolve-type-name-member-scope
…-fork-mernst-branch-resolve-type-name-member-scope into resolve-member-type-inheritance
…k-fork-mernst-branch-resolve-member-type-inheritance into relevance-type-variable-upper-bound
…nst-branch-ajava-omit-irrelevant into resolve-type-name-local-anonymous
…ork-fork-mernst-branch-resolve-type-name-local-anonymous into resolve-type-name-member-scope
…-fork-mernst-branch-resolve-type-name-member-scope into resolve-member-type-inheritance
…k-fork-mernst-branch-resolve-member-type-inheritance into relevance-type-variable-upper-bound
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…-fork-mernst-branch-resolve-type-name-member-scope into resolve-member-type-inheritance
…k-fork-mernst-branch-resolve-member-type-inheritance into relevance-type-variable-upper-bound
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants