-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Nullability Analysis without NotNull #7556
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
Merged
odersky
merged 37 commits into
scala:master
from
dotty-staging:add-flow-analysis-without-notnull
Nov 15, 2019
Merged
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
6e271a7
Thread context through typedStats
odersky 435024a
Nullability prototype
odersky 06f72db
Add extractor for comparisons of null and a path
odersky d904a3c
Generalize expression purity
odersky 6a7c740
Simplify more if-expressions in FirstTransform
odersky e96e027
Maintain constant types of applications in TimeTravellingTreeCopier
odersky d1981f8
Constant fold null tests
odersky 16cc066
Fix handling of negation for nullability
odersky a38574c
Skip also Inlined nodes with skipBlock
odersky 1910c87
Always compute nullable info unless ersedTypes
odersky a691e96
Recompute nullability info when inlining
odersky 691996a
Tweak assert so that nullability info is propagated correctly
odersky 94d05a4
Exclude nullable.scala from pickling and fromTasy tests
odersky 27c92a9
Disable sjsJUnitTests
odersky cb6ff0c
Move null comparison extractors into Nullables
odersky 0d2a0f0
Track nullability in pattern matches
odersky b20cae8
Polishings
odersky 2d5007c
Allow retracting a not null status
odersky 10896a1
Nullables refactorings
odersky 5b46483
Account for side effects in conditions
odersky 5cb0873
Track assignments for nullability
odersky 6d5ed25
Allow local variables to be tracked for nullability
odersky 74d5b1e
Drop debug output
odersky f1e2863
Constant fold null comparisons only under -Yexplicit-nulls
odersky ed00d96
Handle while expressions correctly for nullability
odersky 926b08e
Don't widen T | Null in widenUnion
odersky 947c49e
Introduce NotNull type
odersky 62b756b
Simplify in widenRHS
odersky e6746e5
Special treatment of NotNull in TypeComparer
odersky f32f22a
Temporary hack to support testing
odersky e79dc49
Test case
odersky e56743b
Blacklist notNull as from Tasty test
odersky 84c0fdf
Revert "Disable sjsJUnitTests"
odersky b32e30a
Address review suggestions
odersky 1726660
Add notNull member to Any
odersky 434204f
Use a definition of `def notNull` that does not require `NotNull`.
sjrd 016f471
Revert all the changes that added NonNull.
sjrd 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,22 @@ | ||
trait Null extends Any | ||
object Test with | ||
def notNull(x: Any): x.type & NotNull = | ||
def notNull[A](x: A | Null): x.type & A = | ||
assert(x != null) | ||
x.asInstanceOf // TODO: drop the .asInstanceOf when explicit nulls are implemented | ||
|
||
locally { | ||
val x: (Int | Null) = ??? | ||
val y = x; val _: Int | Null = y | ||
} | ||
locally { | ||
val x: (Int | Null) & NotNull = ??? | ||
val y = identity(x); val yc: Int = y | ||
val z = x; val zc: Int = z | ||
} | ||
locally { | ||
val x: Int | Null = ??? | ||
val y = notNull(identity(x)); val yc: Int = y | ||
val z = notNull(x); val zc: Int = z | ||
} | ||
locally { | ||
val x: Int | Null = ??? | ||
val y = identity(x).$nn; val yc: Int = y | ||
val z = x.$nn; val zc: Int = z | ||
} | ||
class C { type T } | ||
locally { | ||
val x: C { type T = Int } = new C { type T = Int } | ||
val y: x.$nn.T = 33 | ||
val xnn: x.type & C { type T = Int } = notNull(x) | ||
val y: xnn.T = 33 | ||
val z = y; val zc: Int = z | ||
} | ||
|
||
|
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.
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.
The problem is that the compiler will insert
$nn
on a path, and that the path can appear in a type or a term. I don't see how that could work with the revised version ofnotNull
, since that wrapping would be no longer a path.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.
As I explained at #6344 (comment), I don't think the use in paths is a real issue. We can get away without supporting it.
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.
I put my answer on that thread as well, since it covered several earlier remarks. #6344 (comment).
With 4 PRs in flight it is getting difficult to origanize comments!