Skip to content

Commit 00d6607

Browse files
committed
merge upstream (Nullability Analysis without NotNull #7556)
1 parent 763b05c commit 00d6607

File tree

249 files changed

+1802
-359
lines changed

Some content is hidden

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

249 files changed

+1802
-359
lines changed

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 {

compiler/src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ object desugar {
576576
ensureApplied(nu)
577577
}
578578

579-
val copiedAccessFlags = if (ctx.scala2Setting) EmptyFlags else AccessFlags
579+
val copiedAccessFlags = if (ctx.scala2CompatSetting) EmptyFlags else AccessFlags
580580

581581
// Methods to add to a case class C[..](p1: T1, ..., pN: Tn)(moreParams)
582582
// def _1: T1 = this.p1

compiler/src/dotty/tools/dotc/ast/TreeInfo.scala

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ trait TreeInfo[T >: Untyped <: Type] { self: Trees.Instance[T] =>
8888
/** If this is a block, its expression part */
8989
def stripBlock(tree: Tree): Tree = unsplice(tree) match {
9090
case Block(_, expr) => stripBlock(expr)
91+
case Inlined(_, _, expr) => stripBlock(expr)
92+
case _ => tree
93+
}
94+
95+
def stripInlined(tree: Tree): Tree = unsplice(tree) match {
96+
case Inlined(_, _, expr) => stripInlined(expr)
9197
case _ => tree
9298
}
9399

@@ -391,7 +397,9 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
391397
if (fn.symbol.is(Erased) || fn.symbol == defn.InternalQuoted_typeQuote) Pure else exprPurity(fn)
392398
case Apply(fn, args) =>
393399
def isKnownPureOp(sym: Symbol) =
394-
sym.owner.isPrimitiveValueClass || sym.owner == defn.StringClass
400+
sym.owner.isPrimitiveValueClass
401+
|| sym.owner == defn.StringClass
402+
|| defn.pureMethods.contains(sym)
395403
if (tree.tpe.isInstanceOf[ConstantType] && isKnownPureOp(tree.symbol) // A constant expression with pure arguments is pure.
396404
|| (fn.symbol.isStableMember && !fn.symbol.is(Lazy))
397405
|| fn.symbol.isPrimaryConstructor && fn.symbol.owner.isNoInitsClass) // TODO: include in isStable?

compiler/src/dotty/tools/dotc/ast/TreeTypeMap.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ class TreeTypeMap(
121121
val bind1 = tmap.transformSub(bind)
122122
val expr1 = tmap.transform(expr)
123123
cpy.Labeled(labeled)(bind1, expr1)
124-
case Hole(n, args) =>
125-
Hole(n, args.mapConserve(transform)).withSpan(tree.span).withType(mapType(tree.tpe))
124+
case Hole(isTermHole, n, args) =>
125+
Hole(isTermHole, n, args.mapConserve(transform)).withSpan(tree.span).withType(mapType(tree.tpe))
126126
case tree1 =>
127127
super.transform(tree1)
128128
}

compiler/src/dotty/tools/dotc/ast/Trees.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1458,7 +1458,7 @@ object Trees {
14581458
this(this(x, arg), annot)
14591459
case Thicket(ts) =>
14601460
this(x, ts)
1461-
case Hole(_, args) =>
1461+
case Hole(_, _, args) =>
14621462
this(x, args)
14631463
case _ =>
14641464
foldMoreCases(x, tree)

compiler/src/dotty/tools/dotc/ast/tpd.scala

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -711,11 +711,19 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
711711

712712
class TimeTravellingTreeCopier extends TypedTreeCopier {
713713
override def Apply(tree: Tree)(fun: Tree, args: List[Tree])(implicit ctx: Context): Apply =
714-
ta.assignType(untpdCpy.Apply(tree)(fun, args), fun, args)
714+
tree match
715+
case tree: Apply
716+
if (tree.fun eq fun) && (tree.args eq args)
717+
&& tree.tpe.isInstanceOf[ConstantType]
718+
&& isPureExpr(tree) => tree
719+
case _ =>
720+
ta.assignType(untpdCpy.Apply(tree)(fun, args), fun, args)
715721
// Note: Reassigning the original type if `fun` and `args` have the same types as before
716-
// does not work here: The computed type depends on the widened function type, not
717-
// the function type itself. A treetransform may keep the function type the
722+
// does not work here in general: The computed type depends on the widened function type, not
723+
// the function type itself. A tree transform may keep the function type the
718724
// same but its widened type might change.
725+
// However, we keep constant types of pure expressions. This uses the underlying assumptions
726+
// that pure functions yielding a constant will not change in later phases.
719727

720728
override def TypeApply(tree: Tree)(fun: Tree, args: List[Tree])(implicit ctx: Context): TypeApply =
721729
ta.assignType(untpdCpy.TypeApply(tree)(fun, args), fun, args)

compiler/src/dotty/tools/dotc/classpath/DirectoryClassPath.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ final class JrtClassPath(fs: java.nio.file.FileSystem) extends ClassPath with No
179179
if (inPackage == "") ClassPathEntries(packages(inPackage), Nil)
180180
else ClassPathEntries(packages(inPackage), classes(inPackage))
181181

182-
def asURLs: Seq[URL] = Seq(dir.toUri.toURL)
182+
def asURLs: Seq[URL] = Seq(new URL("jrt:/"))
183183
// We don't yet have a scheme to represent the JDK modules in our `-classpath`.
184184
// java models them as entries in the new "module path", we'll probably need to follow this.
185185
def asClassPathStrings: Seq[String] = Nil

0 commit comments

Comments
 (0)