Skip to content

Commit a423df5

Browse files
authored
Merge pull request #46 from noti0na1/dotty-explicit-nulls-only
Disallow comparison between Object and Null
2 parents a5b6447 + b12415f commit a423df5

File tree

617 files changed

+19141
-331
lines changed

Some content is hidden

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

617 files changed

+19141
-331
lines changed

.gitignore

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,37 @@ community-build/sbt-dotty-sbt
8383

8484
# Vulpix output files
8585
*.check.out
86+
87+
tastydoc/report/report\.aux
88+
89+
tastydoc/report/report\.fdb_latexmk
90+
91+
tastydoc/report/report\.fls
92+
93+
tastydoc/report/report\.synctex\.gz
94+
95+
tastydoc/report/report\.toc
96+
97+
tastydoc/report/report\.out
98+
99+
tastydoc/report/presentation/presentation\.aux
100+
101+
tastydoc/report/presentation/presentation\.fdb_latexmk
102+
103+
tastydoc/report/presentation/presentation\.fls
104+
105+
tastydoc/report/presentation/presentation\.nav
106+
107+
tastydoc/report/presentation/presentation\.out
108+
109+
tastydoc/report/presentation/presentation\.snm
110+
111+
tastydoc/report/presentation/presentation\.synctex\.gz
112+
113+
tastydoc/report/presentation/presentation\.toc
114+
115+
tastydoc/dotty-0\.15\.0-RC1/
116+
117+
tastydoc/report/presentation/presentation\.vrb
118+
119+
tastydoc/dotty-0\.16\.0-RC3/

build.sbt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ val `dotty-staging` = Build.`dotty-staging`
1414
val `dotty-language-server` = Build.`dotty-language-server`
1515
val `dotty-bench` = Build.`dotty-bench`
1616
val `dotty-bench-bootstrapped` = Build.`dotty-bench-bootstrapped`
17+
val `tasty-core` = Build.`tasty-core`
18+
val `tasty-core-bootstrapped` = Build.`tasty-core-bootstrapped`
19+
val `tasty-core-scala2` = Build.`tasty-core-scala2`
20+
val `dotty-tastydoc` = Build.`dotty-tastydoc`
21+
val `dotty-tastydoc-input` = Build.`dotty-tastydoc-input`
1722
val `scala-library` = Build.`scala-library`
1823
val `scala-compiler` = Build.`scala-compiler`
1924
val `scala-reflect` = Build.`scala-reflect`

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ object projects
160160

161161
lazy val scalatestplusScalacheck = SbtCommunityProject(
162162
project = "scalatestplus-scalacheck",
163-
sbtTestCommand = "scalatestPlusScalaCheckJVM/compile", // TODO: compile only because tests are prone to java.lang.OutOfMemoryError: Metaspace
163+
sbtTestCommand = "scalatestPlusScalaCheckJVM/test",
164164
sbtUpdateCommand = "scalatestPlusScalaCheckJVM/update",
165165
sbtPublishCommand = "scalatestPlusScalaCheckJVM/publishLocal",
166166
dependencies = List(scalatest, scalacheck)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ import Decorators._
2020

2121
import java.io.DataOutputStream
2222

23+
import dotty.tools.tasty.{ TastyBuffer, TastyHeaderUnpickler }
2324

2425
import scala.tools.asm
2526
import scala.tools.asm.Handle
2627
import scala.tools.asm.tree._
2728
import tpd._
2829
import StdNames._
29-
import dotty.tools.dotc.core.tasty.{TastyBuffer, TastyHeaderUnpickler}
3030
import dotty.tools.io._
3131

3232
class GenBCode extends Phase {

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package dotty.tools
22
package dotc
33

4-
import util.SourceFile
4+
import util.{FreshNameCreator, SourceFile}
55
import ast.{tpd, untpd}
66
import tpd.{Tree, TreeTraverser}
77
import typer.PrepareInlineable.InlineAccessors
@@ -27,6 +27,12 @@ class CompilationUnit protected (val source: SourceFile) {
2727
/** Pickled TASTY binaries, indexed by class. */
2828
var pickled: Map[ClassSymbol, Array[Byte]] = Map()
2929

30+
/** The fresh name creator for the current unit.
31+
* FIXME(#7661): This is not fine-grained enough to enable reproducible builds,
32+
* see https://github.com/scala/scala/commit/f50ec3c866263448d803139e119b33afb04ec2bc
33+
*/
34+
val freshNames: FreshNameCreator = new FreshNameCreator.Default
35+
3036
/** Will be set to `true` if contains `Quote`.
3137
* The information is used in phase `Staging` in order to avoid traversing trees that need no transformations.
3238
*/

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
5252
.setTyper(new Typer)
5353
.addMode(Mode.ImplicitsEnabled)
5454
.setTyperState(new TyperState(ctx.typerState))
55-
.setFreshNames(new FreshNameCreator.Default)
5655
ctx.initialize()(start) // re-initialize the base context with start
5756
def addImport(ctx: Context, rootRef: ImportInfo.RootRef) =
5857
ctx.fresh.setImportInfo(ImportInfo.rootImport(rootRef)(ctx))
@@ -241,12 +240,15 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
241240
}
242241
}
243242

244-
def compileFromString(sourceCode: String): Unit = {
245-
val virtualFile = new VirtualFile("compileFromString-${java.util.UUID.randomUUID().toString}")
246-
val writer = new BufferedWriter(new OutputStreamWriter(virtualFile.output, "UTF-8")) // buffering is still advised by javadoc
247-
writer.write(sourceCode)
248-
writer.close()
249-
compileSources(List(new SourceFile(virtualFile, Codec.UTF8)))
243+
def compileFromStrings(sourceCodes: String*): Unit = {
244+
val sourceFiles = sourceCodes.map {sourceCode =>
245+
val virtualFile = new VirtualFile("compileFromString-${java.util.UUID.randomUUID().toString}")
246+
val writer = new BufferedWriter(new OutputStreamWriter(virtualFile.output, "UTF-8")) // buffering is still advised by javadoc
247+
writer.write(sourceCode)
248+
writer.close()
249+
new SourceFile(virtualFile, Codec.UTF8)
250+
}
251+
compileSources(sourceFiles.toList)
250252
}
251253

252254
/** Print summary; return # of errors encountered */

compiler/src/dotty/tools/dotc/core/Comments.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ object Comments {
121121
val tree = new Parser(SourceFile.virtual("<usecase>", code)).localDef(codePos.start)
122122
tree match {
123123
case tree: untpd.DefDef =>
124-
val newName = ctx.freshNames.newName(tree.name, NameKinds.DocArtifactName)
124+
val newName = ctx.compilationUnit.freshNames.newName(tree.name, NameKinds.DocArtifactName)
125125
untpd.cpy.DefDef(tree)(name = newName)
126126
case _ =>
127127
ctx.error(ProperDefinitionNotFound(), ctx.source.atSpan(codePos))

compiler/src/dotty/tools/dotc/core/Contexts.scala

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import Uniques._
1414
import ast.Trees._
1515
import ast.untpd
1616
import Flags.GivenOrImplicit
17-
import util.{FreshNameCreator, NoSource, SimpleIdentityMap, SourceFile}
17+
import util.{NoSource, SimpleIdentityMap, SourceFile}
1818
import typer.{Implicits, ImportInfo, Inliner, NamerContextOps, SearchHistory, SearchRoot, TypeAssigner, Typer, Nullables}
1919
import Nullables.{NotNullInfo, given}
2020
import Implicits.ContextualImplicits
@@ -44,12 +44,11 @@ object Contexts {
4444
private val (sbtCallbackLoc, store2) = store1.newLocation[AnalysisCallback]()
4545
private val (printerFnLoc, store3) = store2.newLocation[Context => Printer](new RefinedPrinter(_))
4646
private val (settingsStateLoc, store4) = store3.newLocation[SettingsState]()
47-
private val (freshNamesLoc, store5) = store4.newLocation[FreshNameCreator](new FreshNameCreator.Default)
48-
private val (compilationUnitLoc, store6) = store5.newLocation[CompilationUnit]()
49-
private val (runLoc, store7) = store6.newLocation[Run]()
50-
private val (profilerLoc, store8) = store7.newLocation[Profiler]()
51-
private val (notNullInfosLoc, store9) = store8.newLocation[List[NotNullInfo]]()
52-
private val initialStore = store9
47+
private val (compilationUnitLoc, store5) = store4.newLocation[CompilationUnit]()
48+
private val (runLoc, store6) = store5.newLocation[Run]()
49+
private val (profilerLoc, store7) = store6.newLocation[Profiler]()
50+
private val (notNullInfosLoc, store8) = store7.newLocation[List[NotNullInfo]]()
51+
private val initialStore = store8
5352

5453
/** The current context */
5554
def curCtx(given ctx: Context): Context = ctx
@@ -200,9 +199,6 @@ object Contexts {
200199
/** The current settings values */
201200
def settingsState: SettingsState = store(settingsStateLoc)
202201

203-
/** The current fresh name creator */
204-
def freshNames: FreshNameCreator = store(freshNamesLoc)
205-
206202
/** The current compilation unit */
207203
def compilationUnit: CompilationUnit = store(compilationUnitLoc)
208204

@@ -474,6 +470,8 @@ object Contexts {
474470
if (prev != null) prev
475471
else {
476472
val newCtx = fresh.setSource(source)
473+
if (newCtx.compilationUnit == null)
474+
newCtx.setCompilationUnit(CompilationUnit(source))
477475
sourceCtx = sourceCtx.updated(source, newCtx)
478476
newCtx
479477
}
@@ -566,7 +564,6 @@ object Contexts {
566564
def setSettings(settingsState: SettingsState): this.type = updateStore(settingsStateLoc, settingsState)
567565
def setRun(run: Run): this.type = updateStore(runLoc, run)
568566
def setProfiler(profiler: Profiler): this.type = updateStore(profilerLoc, profiler)
569-
def setFreshNames(freshNames: FreshNameCreator): this.type = updateStore(freshNamesLoc, freshNames)
570567
def setNotNullInfos(notNullInfos: List[NotNullInfo]): this.type = updateStore(notNullInfosLoc, notNullInfos)
571568

572569
def setProperty[T](key: Key[T], value: T): this.type =

compiler/src/dotty/tools/dotc/core/JavaNullInterop.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ object JavaNullInterop {
5252
*
5353
* But the selection can throw an NPE if the returned value is `null`.
5454
*/
55-
def nullifyMember(sym: Symbol, tp: Type, isEnum: Boolean)(implicit ctx: Context): Type = {
55+
def nullifyMember(sym: Symbol, tp: Type, isEnumValueDef: Boolean)(implicit ctx: Context): Type = {
5656
assert(ctx.explicitNulls)
5757
assert(sym.is(JavaDefined), "can only nullify java-defined members")
5858

5959
// Some special cases when nullifying the type
60-
if (isEnum || sym.name == nme.TYPE_)
60+
if (isEnumValueDef || sym.name == nme.TYPE_)
6161
// Don't nullify the `TYPE` field in every class and Java enum instances
6262
tp
6363
else if (sym.name == nme.toString_ || sym.isConstructor || hasNotNullAnnot(sym))

compiler/src/dotty/tools/dotc/core/NameKinds.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ object NameKinds {
215215

216216
/** Generate fresh unique term name of this kind with given prefix name */
217217
def fresh(prefix: TermName = EmptyTermName)(implicit ctx: Context): TermName =
218-
ctx.freshNames.newName(prefix, this)
218+
ctx.compilationUnit.freshNames.newName(prefix, this)
219219

220220
/** Generate fresh unique type name of this kind with given prefix name */
221221
def fresh(prefix: TypeName)(implicit ctx: Context): TypeName =

compiler/src/dotty/tools/dotc/core/NameTags.scala

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
package dotty.tools
2-
package dotc
3-
package core
1+
package dotty.tools.dotc.core
42

5-
import tasty.TastyFormat
3+
import dotty.tools.tasty.TastyFormat
64

75
/** The possible tags of a NameKind */
86
object NameTags extends TastyFormat.NameTags {

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,7 @@ object Types {
624624
}
625625
def goRec(tp: RecType) =
626626
if (tp.parent == null) NoDenotation
627+
else if (tp eq pre) go(tp.parent)
627628
else {
628629
//println(s"find member $pre . $name in $tp")
629630

compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ package dotc
33
package core
44
package classfile
55

6+
import dotty.tools.tasty.{ TastyReader, TastyHeaderUnpickler }
7+
68
import Contexts._, Symbols._, Types._, Names._, StdNames._, NameOps._, Scopes._, Decorators._
79
import SymDenotations._, unpickleScala2.Scala2Unpickler._, Constants._, Annotations._, util.Spans._
810
import NameKinds.DefaultGetterName
9-
import dotty.tools.dotc.core.tasty.{TastyHeaderUnpickler, TastyReader}
1011
import ast.tpd._
1112
import java.io.{ ByteArrayInputStream, ByteArrayOutputStream, DataInputStream, IOException }
1213

@@ -1185,4 +1186,3 @@ class ClassfileParser(
11851186
throw new RuntimeException("bad constant pool tag " + in.buf(start) + " at byte " + start)
11861187
}
11871188
}
1188-

compiler/src/dotty/tools/dotc/core/quoted/PickledQuotes.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ import dotty.tools.dotc.core.Mode
1212
import dotty.tools.dotc.core.Symbols._
1313
import dotty.tools.dotc.core.Types._
1414
import dotty.tools.dotc.core.tasty.TreePickler.Hole
15-
import dotty.tools.dotc.core.tasty.{PositionPickler, TastyPickler, TastyPrinter, TastyString}
15+
import dotty.tools.dotc.core.tasty.{ PositionPickler, TastyPickler, TastyPrinter }
1616
import dotty.tools.dotc.core.tasty.TreeUnpickler.UnpickleMode
1717
import dotty.tools.dotc.quoted.QuoteContext
1818
import dotty.tools.dotc.tastyreflect.ReflectionImpl
1919

20+
import dotty.tools.tasty.TastyString
21+
2022
import scala.internal.quoted._
2123
import scala.reflect.ClassTag
2224

compiler/src/dotty/tools/dotc/core/quoted/QuoteUnpickler.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import dotty.tools.dotc.core.tasty._
44
import dotty.tools.dotc.core.tasty.TastyUnpickler.NameTable
55
import dotty.tools.dotc.core.tasty.TreeUnpickler.UnpickleMode
66

7+
import dotty.tools.tasty.TastyReader
8+
79
object QuoteUnpickler {
810
class QuotedTreeSectionUnpickler(posUnpickler: Option[PositionUnpickler], splices: Seq[Any])
911
extends DottyUnpickler.TreeSectionUnpickler(posUnpickler, None) {

compiler/src/dotty/tools/dotc/core/tasty/CommentPickler.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ package dotty.tools.dotc.core.tasty
33
import dotty.tools.dotc.ast.tpd
44
import dotty.tools.dotc.core.Comments.{Comment, CommentsContext, ContextDocstrings}
55
import dotty.tools.dotc.core.Contexts.Context
6-
import dotty.tools.dotc.core.tasty.TastyBuffer.{Addr, NoAddr}
6+
7+
import dotty.tools.tasty.TastyBuffer
8+
import TastyBuffer.{Addr, NoAddr}
79

810
import java.nio.charset.Charset
911

@@ -40,4 +42,3 @@ class CommentPickler(pickler: TastyPickler, addrOfTree: tpd.Tree => Addr)(implic
4042
}
4143
}
4244
}
43-

compiler/src/dotty/tools/dotc/core/tasty/CommentUnpickler.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package dotty.tools.dotc.core.tasty
22

33
import dotty.tools.dotc.core.Comments.Comment
4-
import dotty.tools.dotc.core.tasty.TastyBuffer.Addr
54
import dotty.tools.dotc.util.Spans.Span
65

6+
import dotty.tools.tasty.{TastyReader, TastyBuffer}
7+
import TastyBuffer.Addr
8+
79
import scala.collection.mutable.HashMap
810

911
import java.nio.charset.Charset
@@ -29,4 +31,3 @@ class CommentUnpickler(reader: TastyReader) {
2931
def commentAt(addr: Addr): Option[Comment] =
3032
comments.get(addr)
3133
}
32-

compiler/src/dotty/tools/dotc/core/tasty/DottyUnpickler.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import classfile.ClassfileParser
1010
import Names.SimpleName
1111
import TreeUnpickler.UnpickleMode
1212

13+
import dotty.tools.tasty.TastyReader
14+
1315
object DottyUnpickler {
1416

1517
/** Exception thrown if classfile is corrupted */

compiler/src/dotty/tools/dotc/core/tasty/NameBuffer.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ package dotc
33
package core
44
package tasty
55

6+
import dotty.tools.tasty.TastyBuffer
7+
import TastyBuffer._
8+
69
import collection.mutable
710
import Names.{Name, chrs, SimpleName, DerivedName, TypeName}
811
import NameKinds._
912
import Decorators._
10-
import TastyBuffer._
1113
import scala.io.Codec
1214

1315
class NameBuffer extends TastyBuffer(10000) {

compiler/src/dotty/tools/dotc/core/tasty/PositionPickler.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,18 @@ package dotc
33
package core
44
package tasty
55

6+
import dotty.tools.tasty.TastyFormat.SOURCE
7+
import dotty.tools.tasty.TastyBuffer
8+
import TastyBuffer._
9+
610
import ast._
711
import ast.Trees._
812
import ast.Trees.WithLazyField
913
import util.{SourceFile, NoSource}
1014
import core._
1115
import Contexts._, Symbols._, Annotations._, Decorators._
1216
import collection.mutable
13-
import TastyBuffer._
1417
import util.Spans._
15-
import TastyFormat.SOURCE
1618

1719
class PositionPickler(pickler: TastyPickler, addrOfTree: untpd.Tree => Addr) {
1820
val buf: TastyBuffer = new TastyBuffer(5000)

compiler/src/dotty/tools/dotc/core/tasty/PositionUnpickler.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ package dotc
33
package core
44
package tasty
55

6+
import dotty.tools.tasty.{TastyFormat, TastyBuffer, TastyReader}
7+
import TastyFormat.SOURCE
8+
import TastyBuffer.{Addr, NameRef}
9+
610
import util.Spans._
711
import collection.{mutable, Map}
8-
import TastyBuffer.{Addr, NameRef}
9-
import TastyFormat.SOURCE
1012
import Names.TermName
1113

1214
/** Unpickler for tree positions */
@@ -61,4 +63,3 @@ class PositionUnpickler(reader: TastyReader, nameAtRef: NameRef => TermName) {
6163
def spanAt(addr: Addr): Span = spans.getOrElse(addr, NoSpan)
6264
def sourcePathAt(addr: Addr): String = sourcePaths.getOrElse(addr, "")
6365
}
64-

compiler/src/dotty/tools/dotc/core/tasty/TastyClassName.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ package dotty.tools.dotc
22
package core
33
package tasty
44

5+
import dotty.tools.tasty.{TastyBuffer, TastyReader}
6+
import TastyBuffer.NameRef
7+
58
import Contexts._, Decorators._
69
import Names.{Name, TermName}
710
import StdNames.nme
811
import TastyUnpickler._
9-
import TastyBuffer.NameRef
1012
import util.Spans.offsetToInt
1113
import printing.Highlighting._
1214

@@ -20,7 +22,7 @@ class TastyClassName(bytes: Array[Byte]) {
2022
def readName(): Option[(TermName, TermName)] = unpickle(new TreeSectionUnpickler)
2123

2224
class TreeSectionUnpickler extends SectionUnpickler[(TermName, TermName)](TreePickler.sectionName) {
23-
import TastyFormat._
25+
import dotty.tools.tasty.TastyFormat._
2426
def unpickle(reader: TastyReader, tastyName: NameTable): (TermName, TermName) = {
2527
import reader._
2628
def readName() = {

0 commit comments

Comments
 (0)