Skip to content

Instantly share code, notes, and snippets.

Abel Nieto abeln

Block or report user

Report or block abeln

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View external-doc.md
layout title
doc-page
Explicit Nulls

This proposal describes a modification to the Scala type system that makes reference types (anything that extends AnyRef) non-nullable.

This means the following code will no longer typecheck:

View internal-doc.md
layout title
doc-page
Explicit Nulls

The "explicit nulls" feature (enabled via a flag) changes the Scala type hierarchy so that reference types (e.g. String) are non-nullable. We can still express nullability with union types: e.g. val x: String|Null = null.

The implementation of the feature in dotty can be conceptually divided in several parts:

@abeln
abeln / gist:47f9ec548b78f41591636d7e45e5e2ee
Last active Apr 1, 2019
Delta for dotty with explicit nulls (LOC modified, per file, decreasing)
View gist:47f9ec548b78f41591636d7e45e5e2ee
296 +- compiler/src/dotty/tools/dotc/core/Types.scala
268 - compiler/src/dotty/tools/dotc/core/JavaNull.scala
207 - compiler/src/dotty/tools/dotc/core/FlowFacts.scala
190 +- .../src/dotty/tools/dotc/core/Definitions.scala
137 +- compiler/src/dotty/tools/dotc/typer/Typer.scala
50 +- compiler/src/dotty/tools/dotc/typer/Namer.scala
47 +- .../dotc/parsing/xml/SymbolicXMLBuilder.scala
45 +- .../dotty/tools/dotc/transform/patmat/Space.scala
42 +- .../src/dotty/tools/dotc/typer/Implicits.scala
41 +- .../src/dotty/tools/dotc/typer/Applications.scala
View gist:3cdde264692b2ee69ba29da8ee2133bd
>>> tpe = BCodeBodyBuilder.this.int.Symbol(hostClass)
>>> tpe = BCodeBodyBuilder.this.int.Symbol(hostClass0)
>>> tpe = BCodeBodyBuilder.this.int.Tree(nonNullSide)
>>> tpe = Nullable[tools.asm.Label](finCleanup)
>>> tpe = Nullable[tools.asm.Label](finCleanup)
>>> tpe = Nullable[tools.asm.Label](finCleanup)
>>> tpe = Nullable[tools.asm.Label](lbl)
>>> tpe = Nullable[tools.asm.tree.AbstractInsnNode](i0)
>>> tpe = Nullable[BCodeSyncAndTry.this.bTypes.ClassBType](excType)
>>> tpe = BCodeSyncAndTry.this.int.Symbol(tmp)
@abeln
abeln / gist:d0d2979efbf469501923c7d73341e145
Last active Mar 28, 2019
Per-file change stats of the migration
View gist:d0d2979efbf469501923c7d73341e145
```
370 ++++++++++----------- .../tools/backend/jvm/DottyBackendInterface.scala
208 ++++++------ compiler/src/dotty/tools/dotc/core/Types.scala
148 ++++----- .../dotty/tools/backend/jvm/BCodeSkelBuilder.scala
138 ++++---- compiler/src/dotty/tools/dotc/core/Scopes.scala
86 +++-- compiler/src/dotty/tools/dotc/sbt/ExtractAPI.scala
71 ++-- .../src/dotty/tools/dotc/util/WeakHashSet.scala
68 ++-- .../src/dotty/tools/backend/jvm/GenBCode.scala
66 ++-- compiler/src/dotty/tools/dotc/core/Contexts.scala
63 ++-- .../src/dotty/tools/dotc/core/SymDenotations.scala
@abeln
abeln / gist:36a245f67a519b7318f749811d84e475
Created Mar 21, 2019
Methods refined via checker framework annotations (on return type only)
View gist:36a245f67a519b7318f749811d84e475
```scala
>>> valueOf with type (x$0: Double): String
>>> valueOf with type (x$0: Float): String
>>> valueOf with type (x$0: Long): String
>>> valueOf with type (x$0: Int): String
>>> valueOf with type (x$0: Char): String
>>> valueOf with type (x$0: Boolean): String
>>> valueOf with type (x$0: Array[Char], x$1: Int, x$2: Int): String
>>> valueOf with type (x$0: Array[Char]): String
>>> valueOf with type (x$0: Any): String
@abeln
abeln / gist:3b709744ccfe13a0065d4f36db35b927
Created Mar 21, 2019
Occurences of JavaNull in findMember by type
View gist:3b709744ccfe13a0065d4f36db35b927
➜ dotty git:(explicit-null-bootstrap) ✗ sort kk2 | uniq -c | sort -r
136 >>> dotty.tools.dotc.reporting.diagnostic.ErrorMessageID | JavaNull
87 >>> java.nio.file.Path | JavaNull
80 >>> String | JavaNull
51 >>> Object | JavaNull
39 >>> org.jline.reader.LineReaderBuilder | JavaNull
32 >>> ProfilingAsyncHelper.this.ThreadProfileData | JavaNull
21 >>> scala.tools.asm.MethodVisitor | JavaNull
15 >>> scala.tools.asm.Type | JavaNull
14 >>> xsbti.api.Structure | JavaNull
@abeln
abeln / null-eq
Last active Jan 21, 2019
Equality comparisons involving null in Dotty community build
View null-eq
/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/bin/java "-javaagent:/Applications/IntelliJ IDEA.app/Contents/lib/idea_rt.jar=49686:/Applications/IntelliJ IDEA.app/Contents/bin" -Dfile.encoding=UTF-8 -classpath /Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/charsets.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/deploy.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/ext/cldrdata.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/ext/dnsns.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/ext/jaccess.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/ext/jfxrt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/ext/localedata.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/ext/nashorn.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/ext/sunec.jar:/Libr
View gist:028cfa66c11df2a9d8fce954737980bc
ClassFileLoader (SymbolLoader)
|
v
ClassFileParser
|
v
run()
|
v
parseClass()
You can’t perform that action at this time.