Skip to content

Commit

Permalink
Bootstrap
Browse files Browse the repository at this point in the history
  • Loading branch information
liufengyun committed Oct 4, 2018
1 parent d22bf73 commit afa1048
Show file tree
Hide file tree
Showing 98 changed files with 338 additions and 205 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
def isUnbox(sym: Symbol): Boolean =
Erasure.Boxing.isUnbox(sym) && sym.denot.owner != defn.UnitModuleClass

val primitives: Primitives = new Primitives {
val primitives: Primitives @scala.annotation.filled = new Primitives {
val primitives = new DottyPrimitives(ctx)
def getPrimitive(app: Apply, receiver: Type): Int = primitives.getPrimitive(app, receiver)

Expand Down Expand Up @@ -417,7 +417,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
def settings_debug: Boolean = ctx.settings.Ydebug.value
def targetPlatform: String = ctx.settings.target.value

val perRunCaches: Caches = new Caches {
val perRunCaches: Caches @scala.annotation.filled = new Caches {
def newAnyRefMap[K <: AnyRef, V](): mutable.AnyRefMap[K, V] = new mutable.AnyRefMap[K, V]()
def newWeakMap[K, V](): mutable.WeakHashMap[K, V] = new mutable.WeakHashMap[K, V]()
def recordCache[T <: Clearable](cache: T): T = cache
Expand Down Expand Up @@ -654,6 +654,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
def mangledString: String = n.mangledString
}

@unchecked
implicit def symHelper(sym: Symbol): SymbolHelper = new SymbolHelper {
// names
def fullName(sep: Char): String = sym.showFullName
Expand Down
10 changes: 5 additions & 5 deletions compiler/src/dotty/tools/backend/jvm/GenBCode.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class GenBCode extends Phase {
superCallsMap.update(sym, old + calls)
}

private[this] var myOutput: AbstractFile = _
private[this] var myOutput: AbstractFile = null

private def outputDir(implicit ctx: Context): AbstractFile = {
if (myOutput eq null)
Expand Down Expand Up @@ -70,7 +70,7 @@ object GenBCode {

class GenBCodePipeline(val entryPoints: List[Symbol], val int: DottyBackendInterface)(implicit val ctx: Context) extends BCodeSyncAndTry {

var tree: Tree = _
var tree: Tree = null

val sourceFile = ctx.compilationUnit.source

Expand All @@ -97,7 +97,7 @@ class GenBCodePipeline(val entryPoints: List[Symbol], val int: DottyBackendInter
case class Item1(arrivalPos: Int, cd: TypeDef, cunit: CompilationUnit) {
def isPoison = { arrivalPos == Int.MaxValue }
}
private val poison1 = Item1(Int.MaxValue, null, ctx.compilationUnit)
private val poison1 : Item1 @scala.annotation.filled = Item1(Int.MaxValue, null, ctx.compilationUnit)
private val q1 = new java.util.LinkedList[Item1]

/* ---------------- q2 ---------------- */
Expand All @@ -111,7 +111,7 @@ class GenBCodePipeline(val entryPoints: List[Symbol], val int: DottyBackendInter
def isPoison = { arrivalPos == Int.MaxValue }
}

private val poison2 = Item2(Int.MaxValue, null, null)
private val poison2 : Item2 @scala.annotation.filled = Item2(Int.MaxValue, null, null)
private val q2 = new _root_.java.util.LinkedList[Item2]

/* ---------------- q3 ---------------- */
Expand Down Expand Up @@ -142,7 +142,7 @@ class GenBCodePipeline(val entryPoints: List[Symbol], val int: DottyBackendInter
else 1
}
}
private val poison3 = Item3(Int.MaxValue, null, null)
private val poison3 : Item3 @scala.annotation.filled = Item3(Int.MaxValue, null, null)
private val q3 = new java.util.PriorityQueue[Item3](1000, i3comparator)

/*
Expand Down
3 changes: 3 additions & 0 deletions compiler/src/dotty/tools/dotc/Driver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,13 @@ class Driver {
}
else ctx.reporter

@scala.annotation.partial
protected def initCtx = (new ContextBase).initialCtx

@scala.annotation.partial
protected def sourcesRequired = true

@scala.annotation.filled
def setup(args: Array[String], rootCtx: Context): (List[String], Context) = {
val ctx = rootCtx.fresh
val summary = CompilerCommand.distill(args)(ctx)
Expand Down
10 changes: 6 additions & 4 deletions compiler/src/dotty/tools/dotc/Run.scala
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
* for type checking.
* imports For each element of RootImports, an import context
*/
@scala.annotation.filled
protected[this] def rootContext(implicit ctx: Context): Context = {
ctx.initialize()(ctx)
ctx.base.setPhasePlan(comp.phases)
Expand All @@ -59,7 +60,7 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
ctx.initialize()(start) // re-initialize the base context with start
def addImport(ctx: Context, refFn: () => TermRef) =
ctx.fresh.setImportInfo(ImportInfo.rootImport(refFn)(ctx))
(start.setRun(this) /: defn.RootImportFns)(addImport)
(start.setRun(this: @unchecked) /: defn.RootImportFns)(addImport)
}

private[this] var compiling = false
Expand All @@ -69,12 +70,13 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
/** The context created for this run */
def runContext = myCtx

@scala.annotation.filled
protected[this] implicit def ctx: Context = myCtx
assert(ctx.runId <= Periods.MaxPossibleRunId)

private[this] var myUnits: List[CompilationUnit] = _
private[this] var myUnitsCached: List[CompilationUnit] = _
private[this] var myFiles: Set[AbstractFile] = _
private[this] var myUnits: List[CompilationUnit] = null
private[this] var myUnitsCached: List[CompilationUnit] = null
private[this] var myFiles: Set[AbstractFile] = null

/** The compilation units currently being compiled, this may return different
* results over time.
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/ast/DesugarEnums.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ object DesugarEnums {
import untpd._
import desugar.DerivedFromParamTree

@sharable object CaseKind extends Enumeration {
@unchecked @sharable object CaseKind extends Enumeration {
val Simple, Object, Class = Value
}

Expand Down
12 changes: 10 additions & 2 deletions compiler/src/dotty/tools/dotc/ast/Positioned.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import core.StdNames.nme
*/
abstract class Positioned extends Product {

private[this] var curPos: Position = _
private[this] var curPos: Position = NoPosition

setPos(initialPos)

Expand All @@ -23,6 +23,7 @@ abstract class Positioned extends Product {
/** Destructively update `curPos` to given position. Also, set any missing
* positions in children.
*/
@scala.annotation.partial
protected def setPos(pos: Position): Unit = {
setPosUnchecked(pos)
if (pos.exists) setChildPositions(pos.toSynthetic)
Expand Down Expand Up @@ -51,7 +52,7 @@ abstract class Positioned extends Product {
* any checks of consistency with - or updates of - other positions.
* Called from Unpickler when entering positions.
*/
private[dotc] def setPosUnchecked(pos: Position) = curPos = pos
final private[dotc] def setPosUnchecked(pos: Position) = curPos = pos

/** If any children of this node do not have positions,
* fit their positions between the positions of the known subtrees
Expand Down Expand Up @@ -113,8 +114,15 @@ abstract class Positioned extends Product {
}
}

@scala.annotation.partial
def productArity: Int

@scala.annotation.partial
def productElement(n: Int): Any

/** The initial, synthetic position. This is usually the union of all positioned children's positions.
*/
@scala.annotation.partial
def initialPos: Position = {
var n = productArity
var pos = NoPosition
Expand Down
18 changes: 11 additions & 7 deletions compiler/src/dotty/tools/dotc/ast/Trees.scala
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ object Trees {
/** The type constructor at the root of the tree */
type ThisTree[T >: Untyped] <: Tree[T]

protected var myTpe: T @uncheckedVariance = _
protected var myTpe: T @uncheckedVariance = null

/** Destructively set the type of the tree. This should be called only when it is known that
* it is safe under sharing to do so. One use-case is in the withType method below
Expand Down Expand Up @@ -155,7 +155,8 @@ object Trees {
* modifications. Should be used only in special circumstances (we
* need it for printing trees with optional type info).
*/
final def hasType: Boolean = myTpe != null
@scala.annotation.partial
final def hasType: Boolean = (myTpe != null): @unchecked

final def typeOpt: Type = myTpe match {
case tp: Type => tp
Expand Down Expand Up @@ -184,6 +185,7 @@ object Trees {
def isDef: Boolean = false

/** Is this tree either the empty tree or the empty ValDef or an empty type ident? */
@scala.annotation.partial
def isEmpty: Boolean = false

/** Convert tree to a list. Gives a singleton list, except
Expand Down Expand Up @@ -778,6 +780,7 @@ object Trees {
trait WithoutTypeOrPos[-T >: Untyped] extends Tree[T] {
override def withTypeUnchecked(tpe: Type) = this.asInstanceOf[ThisTree[Type]]
override def pos = NoPosition
@scala.annotation.partial
override def setPos(pos: Position) = {}
}

Expand Down Expand Up @@ -806,7 +809,7 @@ object Trees {
trees foreach (_.foreachInThicket(op))
}

class EmptyValDef[T >: Untyped] extends ValDef[T](
final class EmptyValDef[T >: Untyped] extends ValDef[T](
nme.WILDCARD, genericEmptyTree[T], genericEmptyTree[T]) with WithoutTypeOrPos[T] {
myTpe = NoType.asInstanceOf[T]
override def isEmpty: Boolean = true
Expand Down Expand Up @@ -940,10 +943,10 @@ object Trees {

// ----- Auxiliary creation methods ------------------

def Thicket(trees: List[Tree]): Thicket = new Thicket(trees)
def Thicket(): Thicket = EmptyTree
def Thicket(x1: Tree, x2: Tree): Thicket = Thicket(x1 :: x2 :: Nil)
def Thicket(x1: Tree, x2: Tree, x3: Tree): Thicket = Thicket(x1 :: x2 :: x3 :: Nil)
final def Thicket(trees: List[Tree]): Thicket = new Thicket(trees)
final def Thicket(): Thicket = EmptyTree
final def Thicket(x1: Tree, x2: Tree): Thicket = Thicket(x1 :: x2 :: Nil)
final def Thicket(x1: Tree, x2: Tree, x3: Tree): Thicket = Thicket(x1 :: x2 :: x3 :: Nil)
def flatTree(xs: List[Tree]): Tree = flatten(xs) match {
case x :: Nil => x
case ys => Thicket(ys)
Expand All @@ -960,6 +963,7 @@ object Trees {
* These are exactly those methods that are overridden in TypedTreeCopier
* so that they selectively retype themselves. Retyping needs a context.
*/
@scala.annotation.partial
abstract class TreeCopier {
def postProcess(tree: Tree, copied: untpd.Tree): copied.ThisTree[T]
def postProcess(tree: Tree, copied: untpd.MemberDef): copied.ThisTree[T]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import scala.collection.JavaConverters._
trait DirectoryLookup[FileEntryType <: ClassRepresentation] extends ClassPath {
type F

@scala.annotation.init
val dir: F

protected def emptyFiles: Array[F] // avoids reifying ClassTag[F]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import dotty.tools.io.{ClassPath, ClassRepresentation}
* It's aware of things like e.g. META-INF directory which is correctly skipped.
*/
trait ZipArchiveFileLookup[FileEntryType <: ClassRepresentation] extends ClassPath {
@scala.annotation.init
val zipFile: File

assert(zipFile != null, "Zip file in ZipArchiveFileLookup cannot be null")
Expand Down
9 changes: 6 additions & 3 deletions compiler/src/dotty/tools/dotc/config/Properties.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ object Properties extends PropertiesTrait {
}

trait PropertiesTrait {
@scala.annotation.partial
protected def propCategory: String // specializes the remainder of the values

@scala.annotation.partial
protected def pickJarBasedOn: Class[_] // props file comes from jar containing this

/** The name of the properties file */
Expand Down Expand Up @@ -55,9 +58,9 @@ trait PropertiesTrait {
def envOrNone(name: String) = Option(System getenv name)

// for values based on propFilename
def scalaPropOrElse(name: String, alt: String): String = scalaProps.getProperty(name, alt)
def scalaPropOrEmpty(name: String): String = scalaPropOrElse(name, "")
def scalaPropOrNone(name: String): Option[String] = Option(scalaProps.getProperty(name))
private def scalaPropOrElse(name: String, alt: String): String = scalaProps.getProperty(name, alt)
private def scalaPropOrEmpty(name: String): String = scalaPropOrElse(name, "")
private def scalaPropOrNone(name: String): Option[String] = Option(scalaProps.getProperty(name))

/** Either the development or release version if known, otherwise
* the empty string.
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/config/ScalaSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import rewrites.Rewrites

class ScalaSettings extends Settings.SettingGroup {

protected def defaultClasspath = sys.env.getOrElse("CLASSPATH", ".")
final protected def defaultClasspath = sys.env.getOrElse("CLASSPATH", ".")

/** Path related settings */
val bootclasspath = PathSetting("-bootclasspath", "Override location of bootstrap class files.", Defaults.scalaBootClassPath)
Expand Down
13 changes: 13 additions & 0 deletions compiler/src/dotty/tools/dotc/config/Settings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -255,45 +255,58 @@ object Settings {
def processArguments(arguments: List[String], processAll: Boolean)(implicit ctx: Context): ArgsSummary =
processArguments(ArgsSummary(ctx.settingsState, arguments, Nil, Nil), processAll, Nil)

@scala.annotation.filled
def publish[T](settingf: Int => Setting[T]): Setting[T] = {
val setting = settingf(_allSettings.length)
_allSettings += setting
setting
}

@scala.annotation.filled
def BooleanSetting(name: String, descr: String, initialValue: Boolean = false): Setting[Boolean] =
publish(Setting(name, descr, initialValue))

@scala.annotation.filled
def StringSetting(name: String, helpArg: String, descr: String, default: String): Setting[String] =
publish(Setting(name, descr, default, helpArg))

@scala.annotation.filled
def ChoiceSetting(name: String, helpArg: String, descr: String, choices: List[String], default: String): Setting[String] =
publish(Setting(name, descr, default, helpArg, choices))

@scala.annotation.filled
def IntSetting(name: String, descr: String, default: Int, range: Seq[Int] = Nil): Setting[Int] =
publish(Setting(name, descr, default, choices = range))

@scala.annotation.filled
def MultiStringSetting(name: String, helpArg: String, descr: String): Setting[List[String]] =
publish(Setting(name, descr, Nil, helpArg))

@scala.annotation.filled
def OutputSetting(name: String, helpArg: String, descr: String, default: AbstractFile): Setting[AbstractFile] =
publish(Setting(name, descr, default, helpArg))

@scala.annotation.filled
def PathSetting(name: String, descr: String, default: String): Setting[String] =
publish(Setting(name, descr, default))

@scala.annotation.filled
def PathSetting(name: String, helpArg: String, descr: String, default: String): Setting[String] =
publish(Setting(name, descr, default, helpArg))

@scala.annotation.filled
def PhasesSetting(name: String, descr: String, default: String = ""): Setting[List[String]] =
publish(Setting(name, descr, if (default.isEmpty) Nil else List(default)))

@scala.annotation.filled
def PrefixSetting(name: String, pre: String, descr: String): Setting[List[String]] =
publish(Setting(name, descr, Nil, prefix = pre))

@scala.annotation.filled
def VersionSetting(name: String, descr: String, default: ScalaVersion = NoScalaVersion): Setting[ScalaVersion] =
publish(Setting(name, descr, default))

@scala.annotation.filled
def OptionSetting[T: ClassTag](name: String, descr: String): Setting[Option[T]] =
publish(Setting(name, descr, None, propertyClass = Some(implicitly[ClassTag[T]].runtimeClass)))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ trait WrappedProperties extends PropertiesTrait {
def wrap[T](body: => T): Option[T]

protected def propCategory = "wrapped"
protected def pickJarBasedOn = this.getClass
protected def pickJarBasedOn = this.getClass: @unchecked

override def propIsSet(name: String) = wrap(super.propIsSet(name)) exists (x => x)
override def propOrElse(name: String, alt: String) = wrap(super.propOrElse(name, alt)) getOrElse alt
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/core/Annotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ object Annotations {

case class LazyBodyAnnotation(private var bodyExpr: Context => Tree) extends BodyAnnotation {
private[this] var evaluated = false
private[this] var myBody: Tree = _
private[this] var myBody: Tree = null
def tree(implicit ctx: Context) = {
if (evaluated) assert(myBody != null)
else {
Expand Down Expand Up @@ -131,7 +131,7 @@ object Annotations {
/** Create an annotation where the symbol and the tree are computed lazily. */
def deferredSymAndTree(symf: Context => Symbol, treeFn: Context => Tree)(implicit ctx: Context): Annotation =
new LazyAnnotation {
private[this] var mySym: Symbol = _
private[this] var mySym: Symbol = null

override def symbol(implicit ctx: Context): Symbol = {
if (mySym == null || mySym.defRunId != ctx.runId) {
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/ConstraintRunInfo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import config.Printers.{default, typr}

trait ConstraintRunInfo { self: Run =>
private[this] var maxSize = 0
private[this] var maxConstraint: Constraint = _
private[this] var maxConstraint: Constraint = null
def recordConstraintSize(c: Constraint, size: Int) =
if (size > maxSize) {
maxSize = size
Expand Down
Loading

0 comments on commit afa1048

Please sign in to comment.