Skip to content

Commit 35dda77

Browse files
authored
Merge pull request #44 from noti0na1/dotty-explicit-nulls-only
Merge Nullability Analysis; Changes according to #7546
2 parents d59a792 + 5ddcab6 commit 35dda77

File tree

349 files changed

+4156
-1990
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

349 files changed

+4156
-1990
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,6 @@
5656
[submodule "community-build/community-projects/intent"]
5757
path = community-build/community-projects/intent
5858
url = https://github.com/dotty-staging/intent
59+
[submodule "community-build/community-projects/utest"]
60+
path = community-build/community-projects/utest
61+
url = https://github.com/dotty-staging/utest.git
Submodule scalap updated 1 file
Submodule scopt updated 1 file
Submodule utest added at 0fe508a

community-build/test/scala/dotty/communitybuild/CommunityBuildTest.scala

Lines changed: 60 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,32 @@ class CommunityBuildTest {
1616
new String(Files.readAllBytes(file), UTF_8)
1717
}
1818

19+
def testSbt(project: String, testCommand: String, updateCommand: String, extraSbtArgs: Seq[String] = Nil) = {
20+
// Workaround for https://github.com/sbt/sbt/issues/4395
21+
new File(sys.props("user.home") + "/.sbt/1.0/plugins").mkdirs()
22+
val pluginFilePath = communitybuildDir.resolve("sbt-dotty-sbt").toAbsolutePath().toString()
23+
24+
// Run the sbt command with the compiler version and sbt plugin set in the build
25+
val arguments = {
26+
val sbtProps = Option(System.getProperty("sbt.ivy.home")) match {
27+
case Some(ivyHome) =>
28+
Seq(s"-Dsbt.ivy.home=$ivyHome")
29+
case _ =>
30+
Seq()
31+
}
32+
extraSbtArgs ++ sbtProps ++ Seq(
33+
"-sbt-version", "1.2.7",
34+
s"--addPluginSbtFile=$pluginFilePath",
35+
s";clean ;set updateOptions in Global ~= (_.withLatestSnapshots(false)) ;++$compilerVersion! $testCommand"
36+
)
37+
}
38+
39+
test(project, "sbt", arguments)
40+
}
41+
42+
def testMill(project: String, testCommand: String, extraMillArgs: Seq[String] = Nil) =
43+
test(project, "./mill", extraMillArgs :+ testCommand)
44+
1945
/** Build the given project with the published local compiler and sbt plugin.
2046
*
2147
* This test reads the compiler version from community-build/dotty-bootstrapped.version
@@ -26,7 +52,7 @@ class CommunityBuildTest {
2652
* @param updateCommand The sbt command used to update the project
2753
* @param extraSbtArgs Extra arguments to pass to sbt
2854
*/
29-
def test(project: String, testCommand: String, updateCommand: String, extraSbtArgs: Seq[String] = Nil): Unit = {
55+
def test(project: String, command: String, arguments: Seq[String]): Unit = {
3056
def log(msg: String) = println(Console.GREEN + msg + Console.RESET)
3157

3258
log(s"Building $project with dotty-bootstrapped $compilerVersion...")
@@ -53,149 +79,135 @@ class CommunityBuildTest {
5379
exitCode
5480
}
5581

56-
// Workaround for https://github.com/sbt/sbt/issues/4395
57-
new File(sys.props("user.home") + "/.sbt/1.0/plugins").mkdirs()
58-
val pluginFilePath = communitybuildDir.resolve("sbt-dotty-sbt").toAbsolutePath().toString()
59-
60-
// Run the sbt command with the compiler version and sbt plugin set in the build
61-
val arguments = {
62-
val sbtProps = Option(System.getProperty("sbt.ivy.home")) match {
63-
case Some(ivyHome) =>
64-
Seq(s"-Dsbt.ivy.home=$ivyHome")
65-
case _ =>
66-
Seq()
67-
}
68-
extraSbtArgs ++ sbtProps ++ Seq(
69-
"-sbt-version", "1.2.7",
70-
s"--addPluginSbtFile=$pluginFilePath",
71-
s";clean ;set updateOptions in Global ~= (_.withLatestSnapshots(false)) ;++$compilerVersion! $testCommand"
72-
)
73-
}
74-
75-
val exitCode = exec("sbt", arguments: _*)
82+
val exitCode = exec(command, arguments: _*)
7683

7784
if (exitCode != 0) {
7885
fail(s"""
7986
|
80-
|sbt exited with an error code. To reproduce without JUnit, use:
87+
|$command exited with an error code. To reproduce without JUnit, use:
8188
|
8289
| sbt community-build/prepareCommunityBuild
8390
| cd community-build/community-projects/$project
84-
| sbt ${arguments.init.mkString(" ")} "${arguments.last}"
91+
| $command ${arguments.init.mkString(" ")} "${arguments.last}"
8592
|
86-
|For a faster feedback loop, one can try to extract a direct call to dotc
93+
|For a faster feedback loop on SBT projects, one can try to extract a direct call to dotc
8794
|using the sbt export command. For instance, for scalacheck, use
8895
| sbt export jvm/test:compileIncremental
8996
|
9097
|""".stripMargin)
9198
}
9299
}
93100

94-
@Test def intent = test(
101+
@Test def utest = testMill(
102+
project = "utest",
103+
testCommand = s"utest.jvm[$compilerVersion].test",
104+
extraMillArgs = List("-i", "-D", s"dottyVersion=$compilerVersion")
105+
)
106+
107+
@Test def intent = testSbt(
95108
project = "intent",
96109
testCommand = "test",
97110
updateCommand = "update"
98111
)
99112

100-
@Test def algebra = test(
113+
@Test def algebra = testSbt(
101114
project = "algebra",
102115
testCommand = "coreJVM/compile",
103116
updateCommand = "coreJVM/update"
104117
)
105118

106-
@Test def scalacheck = test(
119+
@Test def scalacheck = testSbt(
107120
project = "scalacheck",
108121
testCommand = "jvm/test:compile",
109122
updateCommand = "jvm/test:update"
110123
)
111124

112-
@Test def scalatest = test(
125+
@Test def scalatest = testSbt(
113126
project = "scalatest",
114127
testCommand = ";scalacticDotty/clean;scalacticTestDotty/test;scalatestTestDotty/test",
115128
updateCommand = "scalatest/update"
116129
)
117130

118-
@Test def scalaXml = test(
131+
@Test def scalaXml = testSbt(
119132
project = "scala-xml",
120133
testCommand = "xml/test",
121134
updateCommand = "xml/update"
122135
)
123136

124-
@Test def scopt = test(
137+
@Test def scopt = testSbt(
125138
project = "scopt",
126139
testCommand = "scoptJVM/compile",
127140
updateCommand = "scoptJVM/update"
128141
)
129142

130-
@Test def scalap = test(
143+
@Test def scalap = testSbt(
131144
project = "scalap",
132145
testCommand = "scalap/compile",
133146
updateCommand = "scalap/update"
134147
)
135148

136-
@Test def squants = test(
149+
@Test def squants = testSbt(
137150
project = "squants",
138151
testCommand = "squantsJVM/compile",
139152
updateCommand = "squantsJVM/update"
140153
)
141154

142-
@Test def betterfiles = test(
155+
@Test def betterfiles = testSbt(
143156
project = "betterfiles",
144157
testCommand = "dotty-community-build/compile",
145158
updateCommand = "dotty-community-build/update"
146159
)
147160

148-
@Test def ScalaPB = test(
161+
@Test def ScalaPB = testSbt(
149162
project = "ScalaPB",
150163
testCommand = "dotty-community-build/compile",
151164
updateCommand = "dotty-community-build/update"
152165
)
153166

154-
@Test def minitest = test(
167+
@Test def minitest = testSbt(
155168
project = "minitest",
156169
testCommand = "dotty-community-build/compile",
157170
updateCommand = "dotty-community-build/update"
158171
)
159172

160-
@Test def fastparse = test(
173+
@Test def fastparse = testSbt(
161174
project = "fastparse",
162175
testCommand = "dotty-community-build/compile;dotty-community-build/test:compile",
163176
updateCommand = "dotty-community-build/update"
164177
)
165178

166-
// TODO: revert to sourcecodeJVM/test
167-
@Test def sourcecode = test(
168-
project = "sourcecode",
169-
testCommand = "sourcecode/compile;sourcecode/test:compile",
170-
updateCommand = "sourcecode/update"
179+
@Test def sourcecode = testMill(
180+
project = "sourcecode",
181+
testCommand = s"sourcecode.jvm[$compilerVersion].test",
182+
extraMillArgs = List("-i", "-D", s"dottyVersion=$compilerVersion")
171183
)
172184

173-
@Test def stdLib213 = test(
185+
@Test def stdLib213 = testSbt(
174186
project = "stdLib213",
175187
testCommand = "library/compile",
176188
updateCommand = "library/update",
177189
extraSbtArgs = Seq("-Dscala.build.compileWithDotty=true")
178190
)
179191

180-
@Test def shapeless = test(
192+
@Test def shapeless = testSbt(
181193
project = "shapeless",
182194
testCommand = "test",
183195
updateCommand = "update"
184196
)
185197

186-
@Test def xmlInterpolator = test(
198+
@Test def xmlInterpolator = testSbt(
187199
project = "xml-interpolator",
188200
testCommand = "test",
189201
updateCommand = "update"
190202
)
191203

192-
@Test def semanticdb = test(
204+
@Test def semanticdb = testSbt(
193205
project = "semanticdb",
194206
testCommand = "test:compile",
195207
updateCommand = "update"
196208
)
197209

198-
@Test def effpi = test(
210+
@Test def effpi = testSbt(
199211
project = "effpi",
200212
// We set `useEffpiPlugin := false` because we don't want to run their
201213
// compiler plugin since it relies on external binaries (from the model
@@ -225,6 +237,6 @@ class UpdateCategory
225237

226238
@Category(Array(classOf[UpdateCategory]))
227239
class CommunityBuildUpdate extends CommunityBuildTest {
228-
override def test(project: String, testCommand: String, updateCommand: String, extraSbtArgs: Seq[String]): Unit =
229-
super.test(project, updateCommand, null, extraSbtArgs)
240+
override def testSbt(project: String, testCommand: String, updateCommand: String, extraSbtArgs: Seq[String]): Unit =
241+
super.testSbt(project, updateCommand, null, extraSbtArgs)
230242
}

compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,8 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
846846
def addRemoteRemoteExceptionAnnotation: Unit = ()
847847

848848
def samMethod(): Symbol = ctx.atPhase(ctx.erasurePhase) {
849-
toDenot(sym).info.abstractTermMembers.toList match {
849+
val samMethods = toDenot(sym).info.possibleSamMethods.toList
850+
samMethods match {
850851
case x :: Nil => x.symbol
851852
case Nil => abort(s"${sym.show} is not a functional interface. It doesn't have abstract methods")
852853
case xs => abort(s"${sym.show} is not a functional interface. " +

compiler/src/dotty/tools/backend/sjs/JSEncoding.scala

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,8 +410,17 @@ object JSEncoding {
410410
paramAndResultTypeNames.mkString(SignatureSep, SignatureSep, "")
411411

412412
/** Computes the internal name for a type. */
413-
private def internalName(tpe: Type)(implicit ctx: Context): String =
414-
encodeTypeRef(toTypeRef(tpe))
413+
private def internalName(tpe: Type)(implicit ctx: Context): String = {
414+
val typeRef = toTypeRef(tpe)
415+
416+
val safeTypeRef: jstpe.TypeRef = typeRef match {
417+
case jstpe.ClassRef("s_Null") => jstpe.ClassRef(ir.Definitions.NullClass)
418+
case jstpe.ClassRef("s_Nothing") => jstpe.ClassRef(ir.Definitions.NothingClass)
419+
case otherTypeRef => otherTypeRef
420+
}
421+
422+
encodeTypeRef(safeTypeRef)
423+
}
415424

416425
/** Encodes a [[Types.TypeRef]], such as in an encoded method signature.
417426
*/

compiler/src/dotty/tools/dotc/CompilationUnit.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ import util.SourceFile
55
import ast.{tpd, untpd}
66
import tpd.{Tree, TreeTraverser}
77
import typer.PrepareInlineable.InlineAccessors
8+
import typer.Nullables
89
import dotty.tools.dotc.core.Contexts.Context
910
import dotty.tools.dotc.core.SymDenotations.ClassDenotation
1011
import dotty.tools.dotc.core.Symbols._
1112
import dotty.tools.dotc.transform.SymUtils._
1213
import util.{NoSource, SourceFile}
14+
import util.Spans.Span
1315
import core.Decorators._
1416

1517
class CompilationUnit protected (val source: SourceFile) {
@@ -42,6 +44,16 @@ class CompilationUnit protected (val source: SourceFile) {
4244
suspended = true
4345
ctx.run.suspendedUnits += this
4446
throw CompilationUnit.SuspendException()
47+
48+
private var myAssignmentSpans: Map[Int, List[Span]] = null
49+
50+
/** A map from (name-) offsets of all local variables in this compilation unit
51+
* that can be tracked for being not null to the list of spans of assignments
52+
* to these variables.
53+
*/
54+
def assignmentSpans(given Context): Map[Int, List[Span]] =
55+
if myAssignmentSpans == null then myAssignmentSpans = Nullables.assignmentSpans
56+
myAssignmentSpans
4557
}
4658

4759
object CompilationUnit {

0 commit comments

Comments
 (0)