Skip to content

Commit

Permalink
Merge branch 'master' into topic/sbt1
Browse files Browse the repository at this point in the history
  • Loading branch information
allanrenucci committed Feb 19, 2018
2 parents 3a60f32 + 668c499 commit cfded3e
Show file tree
Hide file tree
Showing 2,468 changed files with 5,815 additions and 4,311 deletions.
19 changes: 9 additions & 10 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,31 @@ pipeline:
clone:
image: plugins/git
commands:
- ./project/scripts/ci-clone
# if build is PR rebase on top of target branch
- if [ "$DRONE_BUILD_EVENT" = "pull_request" ]; then
git config user.email "[email protected]";
git config user.name "Dotty CI";
git pull "$DRONE_REMOTE_URL" "$DRONE_BRANCH";
fi
# clone submodules in parallelRiRem
- git submodule update --init --recursive --jobs 3

# # TESTS:
# # We run tests in parallel. Tests run in a copy of the working directory to avoid conflict
# test_legacy:
# group: test
# image: lampepfl/dotty:2018-01-17
# commands:
# - cp -R . /tmp/0/ && cd /tmp/0/
# - ./project/scripts/sbt legacyTests

# test:
# group: test
# image: lampepfl/dotty:2018-01-17
# commands:
# - cp -R . /tmp/1/ && cd /tmp/1/
# - ./project/scripts/sbt ";compile ;test"
# - ./project/scripts/sbtTests
# - ./project/scripts/cmdTests

# test_bootstrapped:
# group: test
# image: lampepfl/dotty:2018-01-17
# commands:
# - cp -R . /tmp/2/ && cd /tmp/2/
# - ./project/scripts/sbt ";dotty-bootstrapped/compile ;dotty-bootstrapped/test"
# - ./project/scripts/sbtBootstrappedTests

# test_optimised:
# group: test
Expand Down
5 changes: 5 additions & 0 deletions AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ The majority of the dotty codebase is new code, with the exception of the compon
> The lexical and syntactic analysis components were adapted from the current Scala compiler. They were originally authored by Martin Odersky,
> Burak Emir, Paul Phillips, Lex Spoon, Sean McDirmid and others.
`dotty.tools.dotc.profile`

> The per-phase profiling support is taken mostly as is from [scala/scala](https://github.com/scala/scala).
> The original author was Mike Skells.
`dotty.tools.dotc.reporting`

> Adapted from [scala/scala](https://github.com/scala/scala) with some heavy modifications. They were originally authored by Matthias Zenger, Martin Odersky, and others.
Expand Down
5 changes: 5 additions & 0 deletions bin/dotd
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" >& /dev/null && pwd)/.."

eval "$ROOT/bin/common" "$ROOT/dist-bootstrapped/target/pack/bin/dotd" "$@"
21 changes: 3 additions & 18 deletions compiler/sjs/backend/sjs/JSCodeGen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,7 @@ class JSCodeGen()(implicit ctx: Context) {
throw new FatalError(s"Assignment to static member ${sym.fullName} not supported")
val genRhs = genExpr(rhs)
val lhs = lhs0 match {
case lhs: Ident => desugarIdent(lhs).getOrElse(lhs)
case lhs: Ident => desugarIdent(lhs)
case lhs => lhs
}
lhs match {
Expand Down Expand Up @@ -850,21 +850,6 @@ class JSCodeGen()(implicit ctx: Context) {
}
} // end of genStatOrExpr()

// !!! DUPLICATE code with DottyBackendInterface
private def desugarIdent(i: Ident): Option[Select] = {
i.tpe match {
case TermRef(prefix: TermRef, name) =>
Some(tpd.ref(prefix).select(i.symbol))
case TermRef(prefix: ThisType, name) =>
Some(tpd.This(prefix.cls).select(i.symbol))
/*case TermRef(NoPrefix, name) =>
if (i.symbol is Method) Some(This(i.symbol.topLevelClass).select(i.symbol)) // workaround #342 todo: remove after fixed
else None*/
case _ =>
None
}
}

private def qualifierOf(fun: Tree): Tree = fun match {
case fun: Ident =>
fun.tpe match {
Expand Down Expand Up @@ -907,7 +892,7 @@ class JSCodeGen()(implicit ctx: Context) {
val sym = tree.fun.symbol

val fun = tree.fun match {
case fun: Ident => desugarIdent(fun).getOrElse(fun)
case fun: Ident => desugarIdent(fun)
case fun => fun
}

Expand Down Expand Up @@ -1571,7 +1556,7 @@ class JSCodeGen()(implicit ctx: Context) {
implicit val pos = tree.pos

val fun = tree.fun match {
case fun: Ident => desugarIdent(fun).get
case fun: Ident => desugarIdent(fun).asInstanceOf[Select]
case fun: Select => fun
}
val receiver = fun.qualifier
Expand Down
15 changes: 5 additions & 10 deletions compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala
Original file line number Diff line number Diff line change
Expand Up @@ -444,16 +444,12 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
def desugarIdent(i: Ident): Option[tpd.Select] = {
var found = desugared.get(i.tpe)
if (found == null) {
i.tpe match {
case TermRef(prefix: TermRef, _) =>
found = tpd.ref(prefix).select(i.symbol)
case TermRef(prefix: ThisType, _) =>
found = tpd.This(prefix.cls).select(i.symbol)
case TermRef(NoPrefix, _) =>
if (i.symbol is Flags.Method) found = This(i.symbol.topLevelClass).select(i.symbol) // workaround #342 todo: remove after fixed
tpd.desugarIdent(i) match {
case sel: tpd.Select =>
desugared.put(i.tpe, sel)
found = sel
case _ =>
}
if (found != null) desugared.put(i.tpe, found)
}
if (found == null) None else Some(found)
}
Expand Down Expand Up @@ -900,8 +896,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma

def decls: List[Symbol] = tp.decls.toList

def members: List[Symbol] =
tp.memberDenots(takeAllFilter, (name, buf) => buf ++= tp.member(name).alternatives).map(_.symbol).toList
def members: List[Symbol] = tp.allMembers.map(_.symbol).toList

def typeSymbol: Symbol = tp.widenDealias.typeSymbol

Expand Down
19 changes: 11 additions & 8 deletions compiler/src/dotty/tools/backend/jvm/GenBCode.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import Contexts._
import Types._
import Symbols._
import Denotations._
import Decorators._

import Phases._
import java.lang.AssertionError
import java.io.{DataOutputStream, File => JFile}
Expand Down Expand Up @@ -191,18 +193,19 @@ class GenBCodePipeline(val entryPoints: List[Symbol], val int: DottyBackendInter
val claszSymbol = cd.symbol

// GenASM checks this before classfiles are emitted, https://github.com/scala/scala/commit/e4d1d930693ac75d8eb64c2c3c69f2fc22bec739
// todo: add back those checks
/*val lowercaseJavaClassName = claszSymbol.javaClassName.toLowerCase
val lowercaseJavaClassName = claszSymbol.name.toString.toLowerCase
caseInsensitively.get(lowercaseJavaClassName) match {
case None =>
caseInsensitively.put(lowercaseJavaClassName, claszSymbol)
case Some(dupClassSym) =>
reporter.warning(
claszSymbol.pos,
s"Class ${claszSymbol.javaClassName} differs only in case from ${dupClassSym.javaClassName}. " +
"Such classes will overwrite one another on case-insensitive filesystems."
)
}*/
// Order is not deterministic so we enforce lexicographic order between the duplicates for error-reporting
if (claszSymbol.name.toString < dupClassSym.name.toString)
ctx.warning(s"Class ${claszSymbol.name} differs only in case from ${dupClassSym.name}. " +
"Such classes will overwrite one another on case-insensitive filesystems.", claszSymbol.pos)
else
ctx.warning(s"Class ${dupClassSym.name} differs only in case from ${claszSymbol.name}. " +
"Such classes will overwrite one another on case-insensitive filesystems.", dupClassSym.pos)
}

// -------------- mirror class, if needed --------------
val mirrorC =
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/CompilationUnit.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ object CompilationUnit {
def mkCompilationUnit(clsd: ClassDenotation, unpickled: Tree, forceTrees: Boolean)(implicit ctx: Context): CompilationUnit =
mkCompilationUnit(new SourceFile(clsd.symbol.associatedFile, Seq()), unpickled, forceTrees)

/** Make a compilation unit the given unpickled tree */
/** Make a compilation unit, given picked bytes and unpickled tree */
def mkCompilationUnit(source: SourceFile, unpickled: Tree, forceTrees: Boolean)(implicit ctx: Context): CompilationUnit = {
assert(!unpickled.isEmpty, unpickled)
val unit1 = new CompilationUnit(source)
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/Compiler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,11 @@ class Compiler {
// Note: in this mini-phase block scopes are incorrect. No phases that rely on scopes should be here
new ElimStaticThis) :: // Replace `this` references to static objects by global identifiers
List(new Flatten, // Lift all inner classes to package scope
new RestoreScopes, // Repair scopes rendered invalid by moving definitions in prior phases of the group
new RenameLifted, // Renames lifted classes to local numbering scheme
new TransformWildcards, // Replace wildcards with default values
new MoveStatics, // Move static methods to companion classes
new ExpandPrivate, // Widen private definitions accessed from nested classes
new RestoreScopes, // Repair scopes rendered invalid by moving definitions in prior phases of the group
new SelectStatic, // get rid of selects that would be compiled into GetStatic
new CollectEntryPoints, // Find classes with main methods
new CollectSuperCalls, // Find classes that are called with super
Expand Down
51 changes: 35 additions & 16 deletions compiler/src/dotty/tools/dotc/Run.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,26 @@ import Symbols._
import Phases._
import Types._
import Scopes._
import typer.{FrontEnd, Typer, ImportInfo, RefChecks}
import typer.{FrontEnd, ImportInfo, RefChecks, Typer}
import Decorators._
import io.{AbstractFile, PlainFile}

import scala.io.Codec
import util.{Set => _, _}
import reporting.Reporter
import transform.TreeChecker
import rewrite.Rewrites
import java.io.{BufferedWriter, OutputStreamWriter}

import dotty.tools.dotc.profile.Profiler
import printing.XprintMode
import parsing.Parsers.Parser
import typer.ImplicitRunInfo
import collection.mutable

import scala.annotation.tailrec
import dotty.tools.io.VirtualFile

import scala.util.control.NonFatal

/** A compiler run. Exports various methods to compile source files */
Expand Down Expand Up @@ -57,6 +61,8 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
(start.setRun(this) /: defn.RootImportFns)(addImport)
}

private[this] var compiling = false

private[this] var myCtx = rootContext(ictx)

/** The context created for this run */
Expand All @@ -68,8 +74,6 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
private[this] var myUnits: List[CompilationUnit] = _
private[this] var myUnitsCached: List[CompilationUnit] = _
private[this] var myFiles: Set[AbstractFile] = _
private[this] val myLateUnits = mutable.ListBuffer[CompilationUnit]()
private[this] var myLateFiles = mutable.Set[AbstractFile]()

/** The compilation units currently being compiled, this may return different
* results over time.
Expand All @@ -91,11 +95,11 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
myFiles
}

/** Units that are added from source completers but that are not compiled in current run. */
def lateUnits: List[CompilationUnit] = myLateUnits.toList
/** The source files of all late entered symbols, as a set */
private[this] var lateFiles = mutable.Set[AbstractFile]()

/** The source files of all late units, as a set */
def lateFiles: collection.Set[AbstractFile] = myLateFiles
/** Actions that need to be performed at the end of the current compilation run */
private[this] var finalizeActions = mutable.ListBuffer[() => Unit]()

def getSource(fileName: String): SourceFile = {
val f = new PlainFile(io.Path(fileName))
Expand Down Expand Up @@ -144,6 +148,7 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint

protected def compileUnits()(implicit ctx: Context) = Stats.maybeMonitored {
ctx.checkSingleThreaded()
compiling = true

// If testing pickler, make sure to stop after pickling phase:
val stopAfter =
Expand All @@ -156,11 +161,15 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint

def runPhases(implicit ctx: Context) = {
var lastPrintedTree: PrintedTree = NoPrintedTree
val profiler = ctx.profiler

for (phase <- ctx.allPhases)
if (phase.isRunnable)
Stats.trackTime(s"$phase ms ") {
val start = System.currentTimeMillis
val profileBefore = profiler.beforePhase(phase)
units = phase.runOn(units)
profiler.afterPhase(phase, profileBefore)
if (ctx.settings.Xprint.value.containsPhase(phase)) {
for (unit <- units) {
lastPrintedTree =
Expand All @@ -172,30 +181,40 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
for (unit <- units)
Stats.record(s"retained typed trees at end of $phase", unit.tpdTree.treeSize)
}

profiler.finished()
}

val runCtx = ctx.fresh
runCtx.setProfiler(Profiler())
ctx.phases.foreach(_.initContext(runCtx))
runPhases(runCtx)
if (!ctx.reporter.hasErrors) Rewrites.writeBack()
while (finalizeActions.nonEmpty) {
val action = finalizeActions.remove(0)
action()
}
compiling = false
}

/** Enter top-level definitions of classes and objects contain in Scala source file `file`.
* The newly added symbols replace any previously entered symbols.
* If `typeCheck = true`, also run typer on the compilation unit.
*/
def enterRoots(file: AbstractFile)(implicit ctx: Context): Unit =
def lateCompile(file: AbstractFile, typeCheck: Boolean)(implicit ctx: Context): Unit =
if (!files.contains(file) && !lateFiles.contains(file)) {
lateFiles += file
val unit = new CompilationUnit(getSource(file.path))
myLateUnits += unit
myLateFiles += file
enterRoots(unit)(runContext.fresh.setCompilationUnit(unit))
def process()(implicit ctx: Context) = {
unit.untpdTree = new Parser(unit.source).parse()
ctx.typer.lateEnter(unit.untpdTree)
def typeCheckUnit() = unit.tpdTree = ctx.typer.typedExpr(unit.untpdTree)
if (typeCheck)
if (compiling) finalizeActions += (() => typeCheckUnit()) else typeCheckUnit()
}
process()(runContext.fresh.setCompilationUnit(unit))
}

private def enterRoots(unit: CompilationUnit)(implicit ctx: Context): Unit = {
unit.untpdTree = new Parser(unit.source).parse()
ctx.typer.lateEnter(unit.untpdTree)
}

private sealed trait PrintedTree
private /*final*/ case class SomePrintedTree(phase: String, tree: String) extends PrintedTree
private object NoPrintedTree extends PrintedTree
Expand Down
Loading

0 comments on commit cfded3e

Please sign in to comment.