Skip to content

Commit 946a7a9

Browse files
authored
Merge pull request scala#38 from noti0na1/dotty-explicit-nulls
Merge Changes from Dotty Upstream
2 parents cd623d4 + 8c195dc commit 946a7a9

File tree

116 files changed

+1244
-716
lines changed

Some content is hidden

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

116 files changed

+1244
-716
lines changed

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -208,16 +208,13 @@ abstract class Positioned(implicit @constructorOnly src: SourceFile) extends Pro
208208
case tree: DefDef if tree.mods.is(Extension) =>
209209
tree.vparamss match {
210210
case vparams1 :: vparams2 :: rest if !isLeftAssoc(tree.name) =>
211-
check(vparams2)
212211
check(tree.tparams)
212+
check(vparams2)
213213
check(vparams1)
214214
check(rest)
215-
case vparams1 :: rest =>
216-
check(vparams1)
217-
check(tree.tparams)
218-
check(rest)
219215
case _ =>
220216
check(tree.tparams)
217+
check(tree.vparamss)
221218
}
222219
check(tree.tpt)
223220
check(tree.rhs)

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,8 @@ object Trees {
368368
// name (e.g. in a comment) before finding the real definition.
369369
// To make this behavior more robust we'd have to change the trees for definitions to contain
370370
// a fully positioned Ident in place of a name.
371-
val idx = source.content().indexOfSlice(realName, point)
371+
val contents = if source.exists then source.content() else Array.empty[Char]
372+
val idx = contents.indexOfSlice(realName, point)
372373
if (idx >= 0) idx
373374
else point // use `point` anyway. This is important if no source exists so scanning fails
374375
}
@@ -754,9 +755,10 @@ object Trees {
754755
def unforced: LazyTree[T] = preRhs
755756
protected def force(x: Tree[T @uncheckedVariance]): Unit = preRhs = x
756757

757-
override def disableOverlapChecks = rawMods.is(Given)
758-
// disable order checks for implicit aliases since their given clause follows
759-
// their for clause, but the two appear swapped in the DefDef.
758+
override def disableOverlapChecks = rawMods.is(Extension)
759+
// disable order checks for extension methods as long as we parse
760+
// type parameters both before and after the leading parameter section.
761+
// TODO drop this once syntax of type parameters has settled.
760762
}
761763

762764
/** mods class name template or
@@ -789,10 +791,6 @@ object Trees {
789791

790792
def parents: List[Tree[T]] = parentsOrDerived // overridden by DerivingTemplate
791793
def derived: List[untpd.Tree] = Nil // overridden by DerivingTemplate
792-
793-
override def disableOverlapChecks = true
794-
// disable overlaps checks since templates of instance definitions have their
795-
// `given` clause come last, which means that the constructor span can contain the parent spans.
796794
}
797795

798796

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
182182

183183
case class Opaque()(implicit @constructorOnly src: SourceFile) extends Mod(Flags.Opaque)
184184

185+
case class Open()(implicit @constructorOnly src: SourceFile) extends Mod(Flags.Open)
186+
185187
case class Override()(implicit @constructorOnly src: SourceFile) extends Mod(Flags.Override)
186188

187189
case class Abstract()(implicit @constructorOnly src: SourceFile) extends Mod(Flags.Abstract)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ trait ConstraintHandling[AbstractContext] {
205205
else
206206
isSubType(tp1, tp2)
207207

208-
@forceInline final def inFrozenConstraint[T](op: => T): T = {
208+
inline final def inFrozenConstraint[T](op: => T): T = {
209209
val savedFrozen = frozenConstraint
210210
val savedLambda = caseLambda
211211
frozenConstraint = true

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@ object Decorators {
170170
}
171171
}
172172

173-
implicit object reportDeco {
174-
def (x: T) reporting[T](
173+
implicit class reportDeco[T](x: T) extends AnyVal {
174+
def reporting(
175175
op: (given WrappedResult[T]) => String,
176176
printer: config.Printers.Printer = config.Printers.default): T = {
177177
printer.println(op(given WrappedResult(x)))

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ class Definitions {
4343
ctx.newSymbol(owner, name, flags | Permanent, info)
4444

4545
private def newClassSymbol(owner: Symbol, name: TypeName, flags: FlagSet, infoFn: ClassSymbol => Type) =
46-
ctx.newClassSymbol(owner, name, flags | Permanent | NoInits, infoFn)
46+
ctx.newClassSymbol(owner, name, flags | Permanent | NoInits | Open, infoFn)
4747

4848
private def enterCompleteClassSymbol(owner: Symbol, name: TypeName, flags: FlagSet, parents: List[TypeRef], decls: Scope = newScope) =
49-
ctx.newCompleteClassSymbol(owner, name, flags | Permanent | NoInits, parents, decls).entered
49+
ctx.newCompleteClassSymbol(owner, name, flags | Permanent | NoInits | Open, parents, decls).entered
5050

5151
private def enterTypeField(cls: ClassSymbol, name: TypeName, flags: FlagSet, scope: MutableScope) =
5252
scope.enter(newSymbol(cls, name, flags, TypeBounds.empty))
@@ -279,7 +279,7 @@ class Definitions {
279279
val cls = ctx.requiredClass("java.lang.Object")
280280
assert(!cls.isCompleted, "race for completing java.lang.Object")
281281
cls.info = ClassInfo(cls.owner.thisType, cls, AnyType :: Nil, newScope)
282-
cls.setFlag(NoInits)
282+
cls.setFlag(NoInits | JavaDefined)
283283

284284
// The companion object doesn't really exist, so it needs to be marked as
285285
// absent. Here we need to set it before completing attempt to load Object's
@@ -780,7 +780,6 @@ class Definitions {
780780
@tu lazy val DeprecatedAnnot: ClassSymbol = ctx.requiredClass("scala.deprecated")
781781
@tu lazy val ImplicitAmbiguousAnnot: ClassSymbol = ctx.requiredClass("scala.annotation.implicitAmbiguous")
782782
@tu lazy val ImplicitNotFoundAnnot: ClassSymbol = ctx.requiredClass("scala.annotation.implicitNotFound")
783-
@tu lazy val ForceInlineAnnot: ClassSymbol = ctx.requiredClass("scala.forceInline")
784783
@tu lazy val InlineParamAnnot: ClassSymbol = ctx.requiredClass("scala.annotation.internal.InlineParam")
785784
@tu lazy val InvariantBetweenAnnot: ClassSymbol = ctx.requiredClass("scala.annotation.internal.InvariantBetween")
786785
@tu lazy val MainAnnot: ClassSymbol = ctx.requiredClass("scala.main")

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ object Flags {
3737
else {
3838
val tbits = x.bits & y.bits & KINDFLAGS
3939
if (tbits == 0)
40-
assert(false, s"illegal flagset combination: $x and $y")
40+
assert(false, s"illegal flagset combination: ${x.flagsString} and ${y.flagsString}")
4141
FlagSet(tbits | ((x.bits | y.bits) & ~KINDFLAGS))
4242
}
4343

@@ -237,8 +237,8 @@ object Flags {
237237
/** A value or variable accessor (getter or setter) */
238238
val (AccessorOrSealed @ _, Accessor @ _, Sealed @ _) = newFlags(11, "<accessor>", "sealed")
239239

240-
/** A mutable var */
241-
val (_, Mutable @ _, _) = newFlags(12, "mutable")
240+
/** A mutable var, an open class */
241+
val (MutableOrOpen @ __, Mutable @ _, Open @ _) = newFlags(12, "mutable", "open")
242242

243243
/** Symbol is local to current class (i.e. private[this] or protected[this]
244244
* pre: Private or Protected are also set
@@ -422,7 +422,7 @@ object Flags {
422422
commonFlags(Private, Protected, Final, Case, Implicit, Given, Override, JavaStatic)
423423

424424
val TypeSourceModifierFlags: FlagSet =
425-
CommonSourceModifierFlags.toTypeFlags | Abstract | Sealed | Opaque
425+
CommonSourceModifierFlags.toTypeFlags | Abstract | Sealed | Opaque | Open
426426

427427
val TermSourceModifierFlags: FlagSet =
428428
CommonSourceModifierFlags.toTermFlags | Inline | AbsOverride | Lazy | Erased
@@ -439,7 +439,7 @@ object Flags {
439439
val FromStartFlags: FlagSet = commonFlags(
440440
Module, Package, Deferred, Method, Case,
441441
HigherKinded, Param, ParamAccessor,
442-
Scala2ExistentialCommon, Mutable, Opaque, Touched, JavaStatic,
442+
Scala2ExistentialCommon, MutableOrOpen, Opaque, Touched, JavaStatic,
443443
OuterOrCovariant, LabelOrContravariant, CaseAccessor,
444444
Extension, NonMember, Implicit, Given, Permanent, Synthetic,
445445
SuperAccessorOrScala2x, Inline, Macro)
@@ -513,12 +513,16 @@ object Flags {
513513
/** Flags retained in export forwarders */
514514
val RetainedExportFlags = Given | Implicit | Extension
515515

516+
/** Flags that apply only to classes */
517+
val ClassOnlyFlags = Sealed | Open | Abstract.toTypeFlags
518+
516519
// ------- Other flag sets -------------------------------------
517520

518521
val AbstractFinal: FlagSet = Abstract | Final
519522
val AbstractOverride: FlagSet = Abstract | Override
520523
val AbstractSealed: FlagSet = Abstract | Sealed
521524
val AbstractOrTrait: FlagSet = Abstract | Trait
525+
val EffectivelyOpenFlags = Abstract | JavaDefined | Open | Scala2x | Trait
522526
val PrivateAccessor: FlagSet = Accessor | Private
523527
val AccessorOrSynthetic: FlagSet = Accessor | Synthetic
524528
val EnumCase: FlagSet = Case | Enum

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,8 +368,8 @@ object StdNames {
368368
val TypeApply: N = "TypeApply"
369369
val TypeRef: N = "TypeRef"
370370
val UNIT : N = "UNIT"
371-
val add_ : N = "add"
372371
val acc: N = "acc"
372+
val adhocExtensions: N = "adhocExtensions"
373373
val annotation: N = "annotation"
374374
val any2stringadd: N = "any2stringadd"
375375
val anyHash: N = "anyHash"
@@ -507,6 +507,7 @@ object StdNames {
507507
val nullExpr: N = "nullExpr"
508508
val ofDim: N = "ofDim"
509509
val opaque: N = "opaque"
510+
val open: N = "open"
510511
val ordinal: N = "ordinal"
511512
val ordinalDollar: N = "$ordinal"
512513
val ordinalDollar_ : N = "_$ordinal"

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

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -926,17 +926,10 @@ object SymDenotations {
926926
/** Is this a Scala 2 macro */
927927
final def isScala2Macro(implicit ctx: Context): Boolean = is(Macro) && symbol.owner.is(Scala2x)
928928

929-
/** An erased value or an inline method, excluding @forceInline annotated methods.
930-
* The latter have to be kept around to get to parity with Scala.
931-
* This is necessary at least until we have full bootstrap. Right now
932-
* dotty-bootstrapped involves running the Dotty compiler compiled with Scala 2 with
933-
* a Dotty runtime library compiled with Dotty. If we erase @forceInline annotated
934-
* methods, this means that the support methods in dotty.runtime.LazyVals vanish.
935-
* But they are needed for running the lazy val implementations in the Scala-2 compiled compiler.
929+
/** An erased value or an inline method.
936930
*/
937931
def isEffectivelyErased(implicit ctx: Context): Boolean =
938-
is(Erased) ||
939-
isInlineMethod && unforcedAnnotation(defn.ForceInlineAnnot).isEmpty
932+
is(Erased) || isInlineMethod
940933

941934
/** ()T and => T types should be treated as equivalent for this symbol.
942935
* Note: For the moment, we treat Scala-2 compiled symbols as loose matching,
@@ -1079,6 +1072,12 @@ object SymDenotations {
10791072
final def isEffectivelyFinal(implicit ctx: Context): Boolean =
10801073
isOneOf(EffectivelyFinalFlags) || !owner.isClass || owner.isOneOf(FinalOrModuleClass) || owner.isAnonymousClass
10811074

1075+
/** A class is effectively sealed if has the `final` or `sealed` modifier, or it
1076+
* is defined in Scala 3 and is neither abstract nor open.
1077+
*/
1078+
final def isEffectivelySealed(given Context): Boolean =
1079+
isOneOf(FinalOrSealed) || isClass && !isOneOf(EffectivelyOpenFlags)
1080+
10821081
/** The class containing this denotation which has the given effective name. */
10831082
final def enclosingClassNamed(name: Name)(implicit ctx: Context): Symbol = {
10841083
val cls = enclosingClass
@@ -1377,16 +1376,16 @@ object SymDenotations {
13771376
*/
13781377
def typeParamCreationFlags: FlagSet = TypeParam
13791378

1380-
override def toString: String = {
1381-
val kindString =
1382-
if (myFlags.is(ModuleClass)) "module class"
1383-
else if (isClass) "class"
1384-
else if (isType) "type"
1385-
else if (myFlags.is(Module)) "module"
1386-
else if (myFlags.is(Method)) "method"
1387-
else "val"
1388-
s"$kindString $name"
1389-
}
1379+
def kindString: String =
1380+
if myFlags.is(ModuleClass) then "module class"
1381+
else if myFlags.is(Trait) then "trait"
1382+
else if isClass then "class"
1383+
else if isType then "type"
1384+
else if myFlags.is(Module) then "module"
1385+
else if myFlags.is(Method) then "method"
1386+
else "val"
1387+
1388+
override def toString: String = s"$kindString $name"
13901389

13911390
// ----- Sanity checks and debugging */
13921391

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -908,6 +908,6 @@ object Symbols {
908908
override def toString: String = value.asScala.toString()
909909
}
910910

911-
@forceInline def newMutableSymbolMap[T]: MutableSymbolMap[T] =
911+
inline def newMutableSymbolMap[T]: MutableSymbolMap[T] =
912912
new MutableSymbolMap(new java.util.IdentityHashMap[Symbol, T]())
913913
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4523,7 +4523,7 @@ object Types {
45234523
abstract class VariantTraversal {
45244524
protected[core] var variance: Int = 1
45254525

4526-
@forceInline protected def atVariance[T](v: Int)(op: => T): T = {
4526+
inline protected def atVariance[T](v: Int)(op: => T): T = {
45274527
val saved = variance
45284528
variance = v
45294529
val res = op

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ Standard-Section: "ASTs" TopLevelStat*
211211
EXTENSION -- An extension method
212212
PARAMsetter -- The setter part `x_=` of a var parameter `x` which itself is pickled as a PARAM
213213
EXPORTED -- An export forwarder
214+
OPEN -- an open class
214215
Annotation
215216
216217
Annotation = ANNOTATION Length tycon_Type fullAnnotation_Term -- An annotation, given (class) type of constructor, and full application tree
@@ -332,6 +333,7 @@ object TastyFormat {
332333
final val GIVEN = 37
333334
final val PARAMsetter = 38
334335
final val EXPORTED = 39
336+
final val OPEN = 40
335337

336338
// Cat. 2: tag Nat
337339

@@ -460,7 +462,7 @@ object TastyFormat {
460462

461463
/** Useful for debugging */
462464
def isLegalTag(tag: Int): Boolean =
463-
firstSimpleTreeTag <= tag && tag <= EXPORTED ||
465+
firstSimpleTreeTag <= tag && tag <= OPEN ||
464466
firstNatTreeTag <= tag && tag <= RENAMED ||
465467
firstASTTreeTag <= tag && tag <= BOUNDED ||
466468
firstNatASTTreeTag <= tag && tag <= NAMEDARG ||
@@ -505,6 +507,7 @@ object TastyFormat {
505507
| GIVEN
506508
| PARAMsetter
507509
| EXPORTED
510+
| OPEN
508511
| ANNOTATION
509512
| PRIVATEqualified
510513
| PROTECTEDqualified => true
@@ -565,6 +568,7 @@ object TastyFormat {
565568
case GIVEN => "GIVEN"
566569
case PARAMsetter => "PARAMsetter"
567570
case EXPORTED => "EXPORTED"
571+
case OPEN => "OPEN"
568572

569573
case SHAREDterm => "SHAREDterm"
570574
case SHAREDtype => "SHAREDtype"

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,7 @@ class TreePickler(pickler: TastyPickler) {
669669
if (flags.is(Covariant)) writeModTag(COVARIANT)
670670
if (flags.is(Contravariant)) writeModTag(CONTRAVARIANT)
671671
if (flags.is(Opaque)) writeModTag(OPAQUE)
672+
if (flags.is(Open)) writeModTag(OPEN)
672673
}
673674
}
674675

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,7 @@ class TreeUnpickler(reader: TastyReader,
631631
case GIVEN => addFlag(Given)
632632
case PARAMsetter => addFlag(ParamAccessor)
633633
case EXPORTED => addFlag(Exported)
634+
case OPEN => addFlag(Open)
634635
case PRIVATEqualified =>
635636
readByte()
636637
privateWithin = readWithin(ctx)
@@ -890,9 +891,9 @@ class TreeUnpickler(reader: TastyReader,
890891
untpd.ValDef(readName(), readTpt(), EmptyTree).withType(NoType)
891892
}
892893
else EmptyValDef
894+
cls.setNoInitsFlags(parentsKind(parents), bodyFlags)
893895
cls.info = ClassInfo(cls.owner.thisType, cls, parentTypes, cls.unforcedDecls,
894896
if (self.isEmpty) NoType else self.tpt.tpe)
895-
cls.setNoInitsFlags(parentsKind(parents), bodyFlags)
896897
val constr = readIndexedDef().asInstanceOf[DefDef]
897898
val mappedParents = parents.map(_.changeOwner(localDummy, constr.symbol))
898899

0 commit comments

Comments
 (0)