Skip to content

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
merged 37 commits into from
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 Nov 8, 2019
435024a
Nullability prototype
odersky Nov 8, 2019
06f72db
Add extractor for comparisons of null and a path
odersky Nov 8, 2019
d904a3c
Generalize expression purity
odersky Nov 8, 2019
6a7c740
Simplify more if-expressions in FirstTransform
odersky Nov 8, 2019
e96e027
Maintain constant types of applications in TimeTravellingTreeCopier
odersky Nov 8, 2019
d1981f8
Constant fold null tests
odersky Nov 8, 2019
16cc066
Fix handling of negation for nullability
odersky Nov 8, 2019
a38574c
Skip also Inlined nodes with skipBlock
odersky Nov 8, 2019
1910c87
Always compute nullable info unless ersedTypes
odersky Nov 8, 2019
a691e96
Recompute nullability info when inlining
odersky Nov 8, 2019
691996a
Tweak assert so that nullability info is propagated correctly
odersky Nov 8, 2019
94d05a4
Exclude nullable.scala from pickling and fromTasy tests
odersky Nov 8, 2019
27c92a9
Disable sjsJUnitTests
odersky Nov 8, 2019
cb6ff0c
Move null comparison extractors into Nullables
odersky Nov 9, 2019
0d2a0f0
Track nullability in pattern matches
odersky Nov 9, 2019
b20cae8
Polishings
odersky Nov 9, 2019
2d5007c
Allow retracting a not null status
odersky Nov 10, 2019
10896a1
Nullables refactorings
odersky Nov 10, 2019
5b46483
Account for side effects in conditions
odersky Nov 10, 2019
5cb0873
Track assignments for nullability
odersky Nov 10, 2019
6d5ed25
Allow local variables to be tracked for nullability
odersky Nov 10, 2019
74d5b1e
Drop debug output
odersky Nov 10, 2019
f1e2863
Constant fold null comparisons only under -Yexplicit-nulls
odersky Nov 10, 2019
ed00d96
Handle while expressions correctly for nullability
odersky Nov 11, 2019
926b08e
Don't widen T | Null in widenUnion
odersky Nov 11, 2019
947c49e
Introduce NotNull type
odersky Nov 12, 2019
62b756b
Simplify in widenRHS
odersky Nov 12, 2019
e6746e5
Special treatment of NotNull in TypeComparer
odersky Nov 12, 2019
f32f22a
Temporary hack to support testing
odersky Nov 12, 2019
e79dc49
Test case
odersky Nov 12, 2019
e56743b
Blacklist notNull as from Tasty test
odersky Nov 12, 2019
84c0fdf
Revert "Disable sjsJUnitTests"
odersky Nov 13, 2019
b32e30a
Address review suggestions
odersky Nov 13, 2019
1726660
Add notNull member to Any
odersky Nov 14, 2019
434204f
Use a definition of `def notNull` that does not require `NotNull`.
sjrd Nov 14, 2019
016f471
Revert all the changes that added NonNull.
sjrd Nov 14, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 3 additions & 14 deletions tests/pos/notNull.scala
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)
Copy link
Contributor

@odersky odersky Nov 14, 2019

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 of notNull, since that wrapping would be no longer a path.

Copy link
Member Author

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.

Copy link
Contributor

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!

val y: xnn.T = 33
val z = y; val zc: Int = z
}