Repository navigation
Rename splitAssignments to nodesWithValueOf, which omits nodes whose value might change before the comparison completes #8459
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
Open
mernst
wants to merge
132
commits into
typetools:master
Choose a base branch
from
mernst:split-assignments-sound
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,342
−28
Open
Changes from all commits
Commits
Show all changes
132 commits
Select commit
Hold shift + click to select a range
6c2805b
splitAssignments omits sides whose value an assignment might change
mernst 7da53d8
Merge branch 'master' into split-assignments-sound
mernst cc3d25e
splitAssignments: account for nested assignments; ignore writes to a …
mernst 847ddeb
splitAssignments: reuse store aliasing, restore fast path, fix Javado…
mernst a90af0c
splitAssignments: find all assignments in the tree, sound array alias…
mernst 6d0da35
Test assignment in comparison with generic receivers that are not sub…
mernst 0c1dc85
Merge remote-tracking branch 'upstream/master' into split-assignments…
mernst e535d62
Suppress unchecked-cast warning in AssignmentInComparison test
mernst 9044449
Handle parenthesized and unrecognized assignment targets in splitAssi…
mernst decfa94
Merge branch 'master' into split-assignments-sound
mernst edcd637
Merge branch 'master' into split-assignments-sound
mernst ec91366
splitAssignments: scan anonymous class initializers; add tests
mernst cb80e70
Don't refine a left operand that the right operand might reassign
mernst c4ea38d
Move the treatment of a right operand that reassigns the left operand…
mernst 0331413
Merge branch 'master' into split-assignments-sound
mernst dd4e211
AssignmentTargetScanner does not descend into annotations
mernst bc5f209
Strengthen the regression tests for annotation arguments
mernst 9970220
splitAssignments: account for evaluation order, method calls, and the…
mernst 1b027a1
Suppress Interning Checker warning about reference equality of AST nodes
mernst db88680
splitAssignments: account for all later writes in the comparison; fix…
mernst 34b5d4e
Fix CI: document refineGT and refineGTE; handle nullable values in Lo…
mernst d6614eb
Merge branch 'master' into split-assignments-sound
mernst d6f3bc3
Rename splitAssignments to nodesWithValueOf; clarify documentation
mernst 675642e
Rename Writes to WrittenLocations
mernst 56f8009
canAlias compares erased types and every bound; move canAlias and isS…
mernst 666211a
JavaExpression.fromTree looks through parentheses
mernst 0945ba9
Merge branch 'can-alias-erased-bounds' into split-assignments-sound
mernst 9c20c72
Merge branch 'fromtree-parentheses' into split-assignments-sound
mernst 7e9ab4f
Move the Index Checker's use of nodesWithValueOf to a separate pull r…
mernst e47dcbc
Parenthesize operands in BinaryOperation and UnaryOperation toString;…
mernst cf8c093
Leave isSideEffectFree in the store; document canAlias's non-conserva…
mernst 75f6d6c
Merge branch 'can-alias-erased-bounds' into split-assignments-sound
mernst b228a65
Use the factory's isSideEffectFree, which CFAbstractAnalysis no longe…
mernst 3add1ec
Match writes to a static field regardless of receiver; document canAl…
mernst 9162e0e
Test canAlias on arrays of type variables bounded by Object
mernst 79d6949
Move canAlias logic to TypesUtils; handle union types and wildcards; …
mernst 71cabbb
Merge remote-tracking branch 'origin/can-alias-erased-bounds' into sp…
mernst c3c07b8
Document that canAlias is not conservative for arrays of unrelated types
mernst a383b4a
Merge remote-tracking branch 'origin/can-alias-erased-bounds' into sp…
mernst f0801fd
Merge branch 'master' into can-alias-erased-bounds
mernst e2fe758
Merge branch 'can-alias-erased-bounds' into split-assignments-sound
mernst 5c88eeb
Merge branch 'master' into fromtree-parentheses
mernst 406ba7b
Merge branch 'fromtree-parentheses' into split-assignments-sound
mernst f80904b
Parenthesize an operation receiver in MethodCall.toString; nodesWithV…
mernst c677a19
Merge branch 'master' into can-alias-erased-bounds
mernst d7b6c01
Merge branch 'can-alias-erased-bounds' into split-assignments-sound
mernst ab63bdc
Merge branch 'master' into fromtree-parentheses
mernst 20f1f10
Merge branch 'fromtree-parentheses' into split-assignments-sound
mernst bf4aa9b
canAlias compares the bounds of a wildcard's type parameter; CFAbstra…
mernst 8944dd6
Merge branch 'master' into can-alias-erased-bounds
mernst bb03ffd
Merge branch 'can-alias-erased-bounds' into split-assignments-sound
mernst 6ba3cb1
Merge branch 'master' into fromtree-parentheses
mernst c25eb23
Merge branch 'fromtree-parentheses' into split-assignments-sound
mernst ade4c68
Describe canAlias's comparison of erased types in the changelog
mernst 4c39024
Merge remote-tracking branch 'origin/can-alias-erased-bounds' into sp…
mernst 1364547
Merge remote-tracking branch 'upstream/master' into split-assignments…
mernst 6dd0f64
A write before an assignment's store does not change the target's sto…
mernst 0cca2cc
Test comparisons whose later operand changes the earlier one
mernst fe5ca1a
MethodCall.toString parenthesizes a receiver that is a unary or binar…
mernst e5e3ae5
Merge branch 'methodcall-toString-parenthesize-receiver' into split-a…
mernst ac967f5
Test the target-value guard with a local variable target
mernst b1d6661
Merge github.com:typetools/checker-framework into can-alias-erased-bo…
mernst 77a50ce
Merge branch 'can-alias-erased-bounds' into split-assignments-sound
mernst d89bcd2
Merge branch 'master' into methodcall-toString-parenthesize-receiver
mernst b6a284b
Merge branch 'methodcall-toString-parenthesize-receiver' into split-a…
mernst e51b950
Merge branch 'master' into can-alias-erased-bounds
mernst 455ce3d
Merge branch 'can-alias-erased-bounds' into split-assignments-sound
mernst 073bec0
Merge branch 'master' into methodcall-toString-parenthesize-receiver
mernst 6d1557c
Merge branch 'methodcall-toString-parenthesize-receiver' into split-a…
mernst c0cf6b7
Merge branch 'master' into can-alias-erased-bounds
mernst b865d1a
Merge branch 'can-alias-erased-bounds' into split-assignments-sound
mernst 25687d1
Merge branch 'master' into methodcall-toString-parenthesize-receiver
mernst c97be8e
Merge branch 'methodcall-toString-parenthesize-receiver' into split-a…
mernst c0cb6b3
Clarify canAlias documentation and changelog entry; test a union type…
mernst 651a7f0
Merge branch 'can-alias-erased-bounds' into split-assignments-sound
mernst 06a3972
Merge branch 'master' into can-alias-erased-bounds
mernst 05891e8
Merge branch 'can-alias-erased-bounds' into split-assignments-sound
mernst d021131
Merge branch 'master' into methodcall-toString-parenthesize-receiver
mernst a0cc72b
Merge branch 'methodcall-toString-parenthesize-receiver' into split-a…
mernst dd2a276
Parenthesize every postfix operand that a postfix operation could reg…
mernst 3696c7d
Print a static field access as Foo.f, not Foo.class.f
mernst 0785feb
Do not change dataflow/build.gradle in this pull request
mernst cd93fac
Discard refinements that a comparison invalidates
mernst d37faa7
Do not change how a static field access prints in this pull request
mernst 608ca1a
Merge branch 'methodcall-toString-parenthesize-receiver' into split-a…
mernst 7b4921f
Move comparison-specific Index refinements to later pull requests; ac…
mernst d356f6a
Do not propagate a qualifier that a later call might invalidate; acco…
mernst bee5a86
Merge branch 'master' into can-alias-erased-bounds
mernst 9dead35
Merge branch 'can-alias-erased-bounds' into split-assignments-sound
mernst 934b638
Merge branch 'master' into methodcall-toString-parenthesize-receiver
mernst 2fc8be1
Merge branch 'methodcall-toString-parenthesize-receiver' into split-a…
mernst bad0810
Do not parenthesize an IteratedCollectionElement receiver; fix test J…
mernst cde73f7
Give one reason for parenthesizing a postfix operand: regrouping or f…
mernst 51a463a
Merge branch 'master' into can-alias-erased-bounds
mernst 86f85e3
Merge branch 'can-alias-erased-bounds' into split-assignments-sound
mernst c02d222
Merge github.com:typetools/checker-framework into methodcall-toString…
mernst 48a5688
Merge branch 'master' into can-alias-erased-bounds
mernst 77a2623
Merge branch 'can-alias-erased-bounds' into split-assignments-sound
mernst 1001434
Merge branch 'methodcall-toString-parenthesize-receiver' into split-a…
mernst a668b08
Address review: stale sequence bounds, string conversion, array-refer…
mernst 7271c62
Merge branch 'master' into can-alias-erased-bounds
mernst 32731db
Merge branch 'can-alias-erased-bounds' into split-assignments-sound
mernst 350791f
Reformat
mernst 97e88f9
Merge remote-tracking branch 'upstream/master' into can-alias-erased-…
mernst 62f8fb5
Merge branch 'can-alias-erased-bounds' into split-assignments-sound
mernst d70d366
Merge branch 'master' into can-alias-erased-bounds
mernst 74d27a9
Merge branch 'can-alias-erased-bounds' into split-assignments-sound
mernst 919fbc1
Index tests: give the test helpers lower bounds; reassign a += receiv…
mernst 1250c62
Move the eqChanged test to the pull request that makes it pass
mernst 61d8d2d
Merge branch 'master' into can-alias-erased-bounds
mernst 73983a1
Merge branch 'can-alias-erased-bounds' into split-assignments-sound
mernst cbbe62d
Address review: bracketed offsets, writes in a subtracted offset, pos…
mernst b71d005
Merge branch 'master' into can-alias-erased-bounds
mernst ec83693
Merge branch 'can-alias-erased-bounds' into split-assignments-sound
mernst ca4f0d2
Reformat
mernst 5d4c000
Merge branch 'master' into can-alias-erased-bounds
mernst 1bb6c86
Merge branch 'can-alias-erased-bounds' into split-assignments-sound
mernst dc1566b
Make splitAssignments structural and final; check writes in a candida…
mernst e27e322
nodesWithValueOf does not count the writes of a candidate's own call
mernst 92eafec
A write to an array element at a different constant index does not ch…
mernst c89ae52
Less Than Checker: a floating-point comparison does not imply an inte…
mernst aaaafca
Merge branch 'index-floating-point-integral-bound' into split-assignm…
mernst 3963ac4
Document that a write at one constant index does not change another e…
mernst d0fcfb8
Keep the refinement of a strict floating-point comparison; fix commen…
mernst 9f9d636
Merge branch 'index-floating-point-integral-bound' into split-assignm…
mernst aa998c6
Count the calls of an enhanced for loop and a try-with-resources stat…
mernst e6ab026
Merge branch 'master' into can-alias-erased-bounds
mernst 5acb5dc
Merge branch 'can-alias-erased-bounds' into split-assignments-sound
mernst 8b1aa28
nodesWithValueOf: a node with no source tree is not changed by a wri…
mernst 6c9be16
Make the aliased-receiver tests detect a missed .other diagnostic; ch…
mernst 36f22b8
Merge branch 'master' into can-alias-erased-bounds
mernst 6122ce5
Merge branch 'can-alias-erased-bounds' into split-assignments-sound
mernst File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
checker/tests/index/SameLenComparisonChangesOperand.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| // An operand of a length comparison must not be related to the other operand if the comparison | ||
| // changes the operand's value after evaluating it. For example, if i is 12, then after the | ||
| // comparison in changedLater, s is "ab3" but "x" + i is "x3". | ||
|
|
||
| public class SameLenComparisonChangesOperand { | ||
|
|
||
| void changedLater(int i, String s) { | ||
| if (("x" + i).length() == (s = "ab" + (i = 3)).length()) { | ||
| String u = "x" + i; | ||
| for (int k = 0; k < s.length(); k++) { | ||
| // :: error: (argument) | ||
| u.charAt(k); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| void unchanged(int i, String s) { | ||
| if (("x" + i).length() == s.length()) { | ||
| String u = "x" + i; | ||
| for (int k = 0; k < s.length(); k++) { | ||
| u.charAt(k); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // After the assignment, s + "x" is one character longer than t. | ||
| void changedInAssignment(String s, String t) { | ||
| if ((s = s + "x").length() == t.length()) { | ||
| String u = s + "x"; | ||
| for (int k = 0; k < u.length(); k++) { | ||
| // :: error: (argument) | ||
| t.charAt(k); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| void unchangedInAssignment(String s, String t, String v) { | ||
| if ((s = v + "x").length() == t.length()) { | ||
| String u = v + "x"; | ||
| for (int k = 0; k < u.length(); k++) { | ||
| t.charAt(k); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| static class Holder { | ||
| String text = ""; | ||
| } | ||
|
|
||
| static Holder current = new Holder(); | ||
|
|
||
| // Not side-effect-free. | ||
| static String swap() { | ||
| current = new Holder(); | ||
| return ""; | ||
| } | ||
|
|
||
| // The `+=` evaluates `current` before it evaluates `swap()`, which reassigns `current`. So the | ||
| // assignment stores into the `text` field of the old `current`. (A string conversion cannot | ||
| // reassign `current` this way: the analysis assumes that every `toString()` method is | ||
| // side-effect-free, like `Object.toString()`.) | ||
| void compoundAssignmentReassignsReceiver(String peer) { | ||
| if ((current.text += swap()).length() == peer.length()) { | ||
| for (int k = 0; k < peer.length(); k++) { | ||
| // :: error: (argument) | ||
| current.text.charAt(k); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| static class Box { | ||
| String text = ""; | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return text; | ||
| } | ||
| } | ||
|
|
||
| // Not side-effect-free. | ||
| static String setText(Box box, String t) { | ||
| box.text = t; | ||
| return t; | ||
| } | ||
|
|
||
| // The string conversion of `box` calls `box.toString()`, whose result the call to `setText` | ||
| // changes. So after the comparison, "p" + box might be longer than s. | ||
| void changedByToString(Box box, String s) { | ||
| if (("p" + box).length() == (s = setText(box, "abc")).length()) { | ||
| String u = "p" + box; | ||
| for (int k = 0; k < u.length(); k++) { | ||
| // :: error: (argument) | ||
| s.charAt(k); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| void unchangedByToString(Box box, String s, String t) { | ||
| if (("p" + box).length() == (s = t).length()) { | ||
| String u = "p" + box; | ||
| for (int k = 0; k < u.length(); k++) { | ||
| s.charAt(k); | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import org.checkerframework.checker.nonempty.qual.NonEmpty; | ||
|
|
||
| // The Non-Empty Checker unrefines aliases at a side effect. A call in the right-hand side of an | ||
| // assignment does not change the value that the assignment stores, so comparing the assignment | ||
| // refines its target. | ||
| class AssignmentInComparison { | ||
|
|
||
| // Not side-effect-free. | ||
| List<String> newList() { | ||
| return new ArrayList<>(); | ||
| } | ||
|
|
||
| void callInRhs(@NonEmpty List<String> ne) { | ||
| List<String> l; | ||
| if ((l = newList()) == ne) { | ||
| @NonEmpty List<String> m = l; | ||
| } | ||
| } | ||
|
|
||
| // The call in the rhs might change the abstract value of the list that `slots` denotes, but not | ||
| // which array `slots` denotes, so it does not change which element the assignment stores into. | ||
| void callInRhsArrayElementTarget(List<String>[] slots, @NonEmpty List<String> ne) { | ||
| if ((slots[0] = newList()) == ne) { | ||
| @NonEmpty List<String> m = slots[0]; | ||
| } | ||
| } | ||
|
|
||
| // Not side-effect-free. | ||
| static List<String> clearAndReturn(List<String> l) { | ||
| l.clear(); | ||
| return l; | ||
| } | ||
|
|
||
| // The call in the right operand might empty the list that `a` denotes, after the left operand | ||
| // reads `a`. The qualifier that `a` had when it was read does not hold for `b`. | ||
| void callInRightOperandChangesLeftOperand(List<String> a) { | ||
| if (a.isEmpty()) { | ||
| return; | ||
| } | ||
| List<String> b; | ||
| if (a == (b = clearAndReturn(a))) { | ||
| // :: error: [assignment] | ||
| @NonEmpty List<String> m = b; | ||
| } | ||
| } | ||
|
|
||
| // A reassignment of `a` in the right operand does not change the list that `a` denoted when the | ||
| // left operand read it. | ||
| void reassignmentInRightOperand(List<String> a, List<String> c) { | ||
| if (a.isEmpty()) { | ||
| return; | ||
| } | ||
| List<String> b; | ||
| if (a == (b = (a = c))) { | ||
| @NonEmpty List<String> m = b; | ||
| } | ||
| } | ||
| } |
32 changes: 32 additions & 0 deletions
32
checker/tests/nullness/ArrayAliasingIntersectionBound.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import org.checkerframework.checker.nullness.qual.Nullable; | ||
|
|
||
| // Arrays whose element types are a type variable and one of its bounds can be the same array. | ||
| public class ArrayAliasingIntersectionBound { | ||
|
|
||
| static <T extends Number & Comparable<T>> void writeThroughTypeVariable( | ||
| @Nullable T[] ts, @Nullable Comparable<T>[] cs, T t) { | ||
| if (cs[0] != null) { | ||
| ts[0] = null; | ||
| // If `ts` and `cs` are the same array, the assignment to `ts[0]` sets `cs[0]` to null. | ||
| // :: error: [dereference.of.nullable] | ||
| cs[0].compareTo(t); | ||
| } | ||
| } | ||
|
|
||
| static <T extends Number & Comparable<T>> void writeThroughBound( | ||
| @Nullable T[] ts, @Nullable Comparable<T>[] cs, T t) { | ||
| if (ts[0] != null) { | ||
| cs[0] = null; | ||
| // If `ts` and `cs` are the same array, the assignment to `cs[0]` sets `ts[0]` to null. | ||
| // :: error: [dereference.of.nullable] | ||
| ts[0].intValue(); | ||
| } | ||
| } | ||
|
|
||
| static void unrelatedArrays(@Nullable Integer[] is, @Nullable String[] ss) { | ||
| if (is[0] != null) { | ||
| ss[0] = null; | ||
| is[0].intValue(); | ||
| } | ||
| } | ||
| } |
17 changes: 17 additions & 0 deletions
17
checker/tests/nullness/ArrayAliasingParameterizations.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import java.util.List; | ||
| import org.checkerframework.checker.nullness.qual.Nullable; | ||
|
|
||
| // Arrays whose element types are two parameterizations of a generic type can be the same array, | ||
| // even if neither parameterization is a subtype of the other. | ||
| public class ArrayAliasingParameterizations { | ||
|
|
||
| static void elementOfWildcardLists( | ||
| @Nullable List<? extends Number>[] xs, @Nullable List<? super Integer>[] ys) { | ||
| if (xs[0] != null) { | ||
| ys[0] = null; | ||
| // If `xs` and `ys` are the same array, the assignment to `ys[0]` sets `xs[0]` to null. | ||
| // :: error: [dereference.of.nullable] | ||
| xs[0].size(); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import org.checkerframework.checker.nullness.qual.Nullable; | ||
|
|
||
| // An array whose element type is a type variable bounded by Object can be the same array as an | ||
| // array of any reference type, because a caller can instantiate the type variable to that type. | ||
| public class ArrayAliasingTypeVariables { | ||
|
|
||
| static <T> void typeVariableAndClass(@Nullable T[] ts, @Nullable String[] ss) { | ||
| if (ss[0] != null) { | ||
| ts[0] = null; | ||
| // If `ts` and `ss` are the same array, the assignment to `ts[0]` sets `ss[0]` to null. | ||
| // :: error: [dereference.of.nullable] | ||
| ss[0].length(); | ||
| } | ||
| } | ||
|
|
||
| static <T, S> void twoTypeVariables(@Nullable T[] ts, @Nullable S[] ss) { | ||
| if (ss[0] != null) { | ||
| ts[0] = null; | ||
| // If `ts` and `ss` are the same array, the assignment to `ts[0]` sets `ss[0]` to null. | ||
| // :: error: [dereference.of.nullable] | ||
| ss[0].toString(); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.