-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Nullability Analysis #7520
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
Nullability Analysis #7520
Conversation
04388a4
to
39da9ee
Compare
test performance please |
performance test scheduled: 1 job(s) in queue, 0 running. |
Performance test finished successfully: Visit http://dotty-bench.epfl.ch/7520/ to see the changes. Benchmarks is based on merging with master (3cb93f3) |
I'm pretty sure the Scala.js issue is the one being addressed in #7378 |
2f190d3
to
c57fe6e
Compare
@sjrd @Lacaranian OK, then it would be good to get #7378 in first. |
test performance please |
performance test scheduled: 1 job(s) in queue, 0 running. |
Performance test finished successfully: Visit http://dotty-bench.epfl.ch/7520/ to see the changes. Benchmarks is based on merging with master (3cb93f3) |
test performance please |
performance test scheduled: 1 job(s) in queue, 0 running. |
Performance test finished successfully: Visit http://dotty-bench.epfl.ch/7520/ to see the changes. Benchmarks is based on merging with master (3cb93f3) |
72058e8
to
2ec7799
Compare
1b3ca7b
to
b73589a
Compare
test performance please |
performance test scheduled: 3 job(s) in queue, 1 running. |
Performance test finished successfully: Visit http://dotty-bench.epfl.ch/7520/ to see the changes. Benchmarks is based on merging with master (4d3f315) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for doing this! I only looked at Nullables.scala
(busy this week finishing my thesis). I left a few comments, most of which are about adding additional documentation to methods.
Are you planning on merging this right away?
#7378 has been merged. You should be able to rebase to get rid of the Scala.js issue. |
NotNull is a common supertype of AnyRef and AnyVal. It will be interpreted specially in type comparisons.
When computing the type for local type inferennce, use a simplify transformation.
Makes use of the fact that `Null & NotNull = Nothing`. This fact is used in both type comparisons and glb operations.
For now, we treat _every_ type spelled "Null" as the Null type. That way we can introduce a user-level Null that sits next to AnyVal and AnyRef, like the real Null will once explicit nulls are in. This hack should be reverted once we have the changes for Null implemented.
There seems to be a missing simplification when compiling from Tasty. Here is the error message: ``` *** error while checking out/posTestFromTasty/pos/notNull/Test.class after phase readTasty *** java.lang.AssertionError: assertion failed: Types differ Original type : (x: Int): Int After checking: (x: (Int | Null) & NotNull): (Int | Null) & NotNull Original tree : identity[(Int | Null) & NotNull] After checking: identity[(Int | Null) & NotNull] ```
a0dd1e4
to
6deac57
Compare
This reverts commit 27c92a9.
6deac57
to
84c0fdf
Compare
@sjrd Reverted. Great that the fix was in so quickly! |
Better document Nullables.scala. Also, rename containsRef to impliesNotNull.
* Therefore, variables with unreachable assignments can be assumed to be not-null | ||
* only if their type asserts it. | ||
* | ||
* Note: we the local variables through their offset and not through their name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"we the local" -> "we track the local"
d7ce81a
to
5697fe5
Compare
Add a method $nn to Any that has type def $nn: this.type & NotNull The method is marked as stable & realizable, which means it can appear in paths. Special handling is required in asSeenFrom, to reflect the fact that $nn are not real selections, i.e. the selected item has the same owner as the one in the prefix. N.B. I tried to make $nn a field instead, but this caused AbstractMethod errors for reasons I cannot quite track down.
5697fe5
to
1726660
Compare
@odersky Could you explain in a few sentences how the non-nullability analysis interacts with the |
OK after more investigation, I realized that my mistake had something to do with the constant folder, not with the nullability analysis nor |
Closed in favor of #7556 |
A simple nullability analysis.
The analysis tracks all immutable vals and local immutable vars (under the condition that all assignments to such vars are in places we can analyze). The analysis works also for inlined code and is thus able to recognize that after an
assert(x != null)
x
is indeed notnull
.The main issue right now is that sjsJUnitTests had to be disabled, because it did not link anymore after the change in DottyPredef that changed
assertFail
to haveNothing
result type. The change toassertFail
is needed so that nullability info is correctly propagated forassert
. This looks like a JS issue that should be fixed,Another issue is that
nullable.scala
fails pickling and FromTasty tests because the nullability info cannot be reproduced after pickling. It looks like this is fixable by making not-null assertions manifest with special function calls in the code. That scheme should be part of a subsequent explicit nulls PR.