Skip to content

Commit 9c70648

Browse files
Merge branch 'master' into ycheck-patterns
2 parents b9db9f6 + 0094097 commit 9c70648

File tree

103 files changed

+1780
-508
lines changed

Some content is hidden

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

103 files changed

+1780
-508
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,5 @@ compiler/test/debug/Gen.jar
7171
compiler/before-pickling.txt
7272
compiler/after-pickling.txt
7373
*.dotty-ide-version
74+
75+
*.decompiled.out

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ class Compiler {
135135

136136
def reset()(implicit ctx: Context): Unit = {
137137
ctx.base.reset()
138-
ctx.runInfo.clear()
138+
if (ctx.run != null) ctx.run.reset()
139139
}
140140

141141
def newRun(implicit ctx: Context): Run = {

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

Lines changed: 74 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,16 @@ import transform.TreeChecker
1818
import rewrite.Rewrites
1919
import java.io.{BufferedWriter, OutputStreamWriter}
2020
import printing.XprintMode
21+
import parsing.Parsers.Parser
2122
import typer.ImplicitRunInfo
23+
import collection.mutable
2224

2325
import scala.annotation.tailrec
2426
import dotty.tools.io.VirtualFile
2527
import scala.util.control.NonFatal
2628

2729
/** A compiler run. Exports various methods to compile source files */
28-
class Run(comp: Compiler, ictx: Context) {
29-
import Run._
30+
class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with ConstraintRunInfo {
3031

3132
/** Produces the following contexts, from outermost to innermost
3233
*
@@ -53,12 +54,49 @@ class Run(comp: Compiler, ictx: Context) {
5354
ctx.initialize()(start) // re-initialize the base context with start
5455
def addImport(ctx: Context, refFn: () => TermRef) =
5556
ctx.fresh.setImportInfo(ImportInfo.rootImport(refFn)(ctx))
56-
(start.setRunInfo(new RunInfo(start)) /: defn.RootImportFns)(addImport)
57+
(start.setRun(this) /: defn.RootImportFns)(addImport)
5758
}
5859

59-
protected[this] implicit val ctx: Context = rootContext(ictx)
60+
private[this] var myCtx = rootContext(ictx)
61+
62+
/** The context created for this run */
63+
def runContext = myCtx
64+
65+
protected[this] implicit def ctx: Context = myCtx
6066
assert(ctx.runId <= Periods.MaxPossibleRunId)
6167

68+
private[this] var myUnits: List[CompilationUnit] = _
69+
private[this] var myUnitsCached: List[CompilationUnit] = _
70+
private[this] var myFiles: Set[AbstractFile] = _
71+
private[this] val myLateUnits = mutable.ListBuffer[CompilationUnit]()
72+
private[this] var myLateFiles = mutable.Set[AbstractFile]()
73+
74+
/** The compilation units currently being compiled, this may return different
75+
* results over time.
76+
*/
77+
def units: List[CompilationUnit] = myUnits
78+
79+
private def units_=(us: List[CompilationUnit]): Unit =
80+
myUnits = us
81+
82+
/** The files currently being compiled, this may return different results over time.
83+
* These files do not have to be source files since it's possible to compile
84+
* from TASTY.
85+
*/
86+
def files: Set[AbstractFile] = {
87+
if (myUnits ne myUnitsCached) {
88+
myUnitsCached = myUnits
89+
myFiles = myUnits.map(_.source.file).toSet
90+
}
91+
myFiles
92+
}
93+
94+
/** Units that are added from source completers but that are not compiled in current run. */
95+
def lateUnits: List[CompilationUnit] = myLateUnits.toList
96+
97+
/** The source files of all late units, as a set */
98+
def lateFiles: collection.Set[AbstractFile] = myLateFiles
99+
62100
def getSource(fileName: String): SourceFile = {
63101
val f = new PlainFile(io.Path(fileName))
64102
if (f.isDirectory) {
@@ -78,7 +116,7 @@ class Run(comp: Compiler, ictx: Context) {
78116
compileSources(sources)
79117
} catch {
80118
case NonFatal(ex) =>
81-
ctx.echo(i"exception occurred while compiling ${ctx.runInfo.units}%, %")
119+
ctx.echo(i"exception occurred while compiling $units%, %")
82120
throw ex
83121
}
84122

@@ -90,17 +128,17 @@ class Run(comp: Compiler, ictx: Context) {
90128
*/
91129
def compileSources(sources: List[SourceFile]) =
92130
if (sources forall (_.exists)) {
93-
ctx.runInfo.units = sources map (new CompilationUnit(_))
131+
units = sources map (new CompilationUnit(_))
94132
compileUnits()
95133
}
96134

97135
def compileUnits(us: List[CompilationUnit]): Unit = {
98-
ctx.runInfo.units = us
136+
units = us
99137
compileUnits()
100138
}
101139

102140
def compileUnits(us: List[CompilationUnit], ctx: Context): Unit = {
103-
ctx.runInfo.units = us
141+
units = us
104142
compileUnits()(ctx)
105143
}
106144

@@ -122,16 +160,16 @@ class Run(comp: Compiler, ictx: Context) {
122160
if (phase.isRunnable)
123161
Stats.trackTime(s"$phase ms ") {
124162
val start = System.currentTimeMillis
125-
ctx.runInfo.units = phase.runOn(ctx.runInfo.units)
163+
units = phase.runOn(units)
126164
if (ctx.settings.Xprint.value.containsPhase(phase)) {
127-
for (unit <- ctx.runInfo.units) {
165+
for (unit <- units) {
128166
lastPrintedTree =
129167
printTree(lastPrintedTree)(ctx.fresh.setPhase(phase.next).setCompilationUnit(unit))
130168
}
131169
}
132170
ctx.informTime(s"$phase ", start)
133171
Stats.record(s"total trees at end of $phase", ast.Trees.ntrees)
134-
for (unit <- ctx.runInfo.units)
172+
for (unit <- units)
135173
Stats.record(s"retained typed trees at end of $phase", unit.tpdTree.treeSize)
136174
}
137175
}
@@ -142,6 +180,22 @@ class Run(comp: Compiler, ictx: Context) {
142180
if (!ctx.reporter.hasErrors) Rewrites.writeBack()
143181
}
144182

183+
/** Enter top-level definitions of classes and objects contain in Scala source file `file`.
184+
* The newly added symbols replace any previously entered symbols.
185+
*/
186+
def enterRoots(file: AbstractFile)(implicit ctx: Context): Unit =
187+
if (!files.contains(file) && !lateFiles.contains(file)) {
188+
val unit = new CompilationUnit(getSource(file.path))
189+
myLateUnits += unit
190+
myLateFiles += file
191+
enterRoots(unit)(runContext.fresh.setCompilationUnit(unit))
192+
}
193+
194+
private def enterRoots(unit: CompilationUnit)(implicit ctx: Context): Unit = {
195+
unit.untpdTree = new Parser(unit.source).parse()
196+
ctx.typer.lateEnter(unit.untpdTree)
197+
}
198+
145199
private sealed trait PrintedTree
146200
private /*final*/ case class SomePrintedTree(phase: String, tree: String) extends PrintedTree
147201
private object NoPrintedTree extends PrintedTree
@@ -180,46 +234,19 @@ class Run(comp: Compiler, ictx: Context) {
180234
compileSources(List(new SourceFile(virtualFile, Codec.UTF8)))
181235
}
182236

183-
/** The context created for this run */
184-
def runContext = ctx
185-
186237
/** Print summary; return # of errors encountered */
187238
def printSummary(): Reporter = {
188-
ctx.runInfo.printMaxConstraint()
239+
printMaxConstraint()
189240
val r = ctx.reporter
190241
r.printSummary
191242
r
192243
}
193-
}
194-
195-
object Run {
196-
/** Info that changes on each compiler run */
197-
class RunInfo(initctx: Context) extends ImplicitRunInfo with ConstraintRunInfo {
198-
implicit val ctx: Context = initctx
199-
200-
private[this] var myUnits: List[CompilationUnit] = _
201-
private[this] var myUnitsCached: List[CompilationUnit] = _
202-
private[this] var myFiles: Set[AbstractFile] = _
203-
204-
/** The compilation units currently being compiled, this may return different
205-
* results over time.
206-
*/
207-
def units: List[CompilationUnit] = myUnits
208-
209-
private[Run] def units_=(us: List[CompilationUnit]): Unit =
210-
myUnits = us
211-
212-
213-
/** The files currently being compiled, this may return different results over time.
214-
* These files do not have to be source files since it's possible to compile
215-
* from TASTY.
216-
*/
217-
def files: Set[AbstractFile] = {
218-
if (myUnits ne myUnitsCached) {
219-
myUnitsCached = myUnits
220-
myFiles = myUnits.map(_.source.file).toSet
221-
}
222-
myFiles
223-
}
244+
245+
override def reset() = {
246+
super[ImplicitRunInfo].reset()
247+
super[ConstraintRunInfo].reset()
248+
myCtx = null
249+
myUnits = null
250+
myUnitsCached = null
224251
}
225-
}
252+
}

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,9 +534,18 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
534534
}
535535
}
536536

537+
/** An extractor for def of a closure contained the block of the closure. */
538+
object closureDef {
539+
def unapply(tree: Tree): Option[DefDef] = tree match {
540+
case Block((meth @ DefDef(nme.ANON_FUN, _, _, _, _)) :: Nil, closure: Closure) =>
541+
Some(meth)
542+
case _ => None
543+
}
544+
}
545+
537546
/** If tree is a closure, its body, otherwise tree itself */
538547
def closureBody(tree: Tree)(implicit ctx: Context): Tree = tree match {
539-
case Block((meth @ DefDef(nme.ANON_FUN, _, _, _, _)) :: Nil, Closure(_, _, _)) => meth.rhs
548+
case closureDef(meth) => meth.rhs
540549
case _ => tree
541550
}
542551

compiler/src/dotty/tools/dotc/config/PathResolver.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ class PathResolver(implicit ctx: Context) {
262262
lazy val result: ClassPath = {
263263
val cp = AggregateClassPath(containers.toIndexedSeq)
264264

265-
if (settings.Ylogcp.value) {
265+
if (settings.YlogClasspath.value) {
266266
Console.println("Classpath built from " + settings.toConciseString(ctx.settingsState))
267267
Console.println("Defaults: " + PathResolver.Defaults)
268268
Console.println("Calculated: " + Calculated)

compiler/src/dotty/tools/dotc/config/ScalaSettings.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ class ScalaSettings extends Settings.SettingGroup {
1616
val extdirs = PathSetting("-extdirs", "Override location of installed extensions.", Defaults.scalaExtDirs)
1717
val javabootclasspath = PathSetting("-javabootclasspath", "Override java boot classpath.", Defaults.javaBootClassPath)
1818
val javaextdirs = PathSetting("-javaextdirs", "Override java extdirs classpath.", Defaults.javaExtDirs)
19-
val sourcepath = PathSetting("-sourcepath", "Specify location(s) of source files.", "") // Defaults.scalaSourcePath
19+
val sourcepath = PathSetting("-sourcepath", "Specify location(s) of source files.", Defaults.scalaSourcePath)
20+
val scansource = BooleanSetting("-scansource", "Scan source files to locate classes for which class-name != file-name")
21+
2022
val classpath = PathSetting("-classpath", "Specify where to find user class files.", defaultClasspath) withAbbreviation "-cp"
2123
val outputDir = PathSetting("-d", "directory|jar", "destination for generated classfiles.", ".")
2224
val priorityclasspath = PathSetting("-priorityclasspath", "class path that takes precedence over all other paths (or testing only)", "")
@@ -80,7 +82,7 @@ class ScalaSettings extends Settings.SettingGroup {
8082
val YtermConflict = ChoiceSetting("-Yresolve-term-conflict", "strategy", "Resolve term conflicts", List("package", "object", "error"), "error")
8183
val Ylog = PhasesSetting("-Ylog", "Log operations during")
8284
val YemitTasty = BooleanSetting("-Yemit-tasty", "Generate tasty in separate *.tasty file.")
83-
val Ylogcp = BooleanSetting("-Ylog-classpath", "Output information about what classpath is being applied.")
85+
val YlogClasspath = BooleanSetting("-Ylog-classpath", "Output information about what classpath is being applied.")
8486
val YdisableFlatCpCaching = BooleanSetting("-YdisableFlatCpCaching", "Do not cache flat classpath representation of classpath elements from jars across compiler instances.")
8587

8688
val YnoImports = BooleanSetting("-Yno-imports", "Compile without importing scala.*, java.lang.*, or Predef.")
@@ -131,6 +133,7 @@ class ScalaSettings extends Settings.SettingGroup {
131133
sys.props("user.dir")
132134
)
133135

136+
134137
val projectName = StringSetting (
135138
"-project",
136139
"project title",

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

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

44
import Contexts._
5-
import Run.RunInfo
65
import config.Printers.typr
76

8-
trait ConstraintRunInfo { self: RunInfo =>
7+
trait ConstraintRunInfo { self: Run =>
98
private[this] var maxSize = 0
109
private[this] var maxConstraint: Constraint = _
1110
def recordConstraintSize(c: Constraint, size: Int) =
@@ -15,4 +14,6 @@ trait ConstraintRunInfo { self: RunInfo =>
1514
}
1615
def printMaxConstraint()(implicit ctx: Context) =
1716
if (maxSize > 0) typr.println(s"max constraint = ${maxConstraint.show}")
17+
18+
protected def reset() = maxConstraint = null
1819
}

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import NameOps._
1414
import Uniques._
1515
import SymDenotations._
1616
import Comments._
17-
import Run.RunInfo
1817
import util.Positions._
1918
import ast.Trees._
2019
import ast.untpd
@@ -43,7 +42,7 @@ object Contexts {
4342
private val (settingsStateLoc, store4) = store3.newLocation[SettingsState]()
4443
private val (freshNamesLoc, store5) = store4.newLocation[FreshNameCreator](new FreshNameCreator.Default)
4544
private val (compilationUnitLoc, store6) = store5.newLocation[CompilationUnit]()
46-
private val (runInfoLoc, store7) = store6.newLocation[RunInfo]()
45+
private val (runLoc, store7) = store6.newLocation[Run]()
4746
private val initialStore = store7
4847

4948
/** A context is passed basically everywhere in dotc.
@@ -194,8 +193,8 @@ object Contexts {
194193
/** The current compilation unit */
195194
def compilationUnit: CompilationUnit = store(compilationUnitLoc)
196195

197-
/** The current compiler-run specific Info */
198-
def runInfo: RunInfo = store(runInfoLoc)
196+
/** The current compiler-run */
197+
def run: Run = store(runLoc)
199198

200199
/** The new implicit references that are introduced by this scope */
201200
protected var implicitsCache: ContextualImplicits = null
@@ -460,7 +459,7 @@ object Contexts {
460459
def setPrinterFn(printer: Context => Printer): this.type = updateStore(printerFnLoc, printer)
461460
def setSettings(settingsState: SettingsState): this.type = updateStore(settingsStateLoc, settingsState)
462461
def setCompilationUnit(compilationUnit: CompilationUnit): this.type = updateStore(compilationUnitLoc, compilationUnit)
463-
def setRunInfo(runInfo: RunInfo): this.type = updateStore(runInfoLoc, runInfo)
462+
def setRun(run: Run): this.type = updateStore(runLoc, run)
464463
def setFreshNames(freshNames: FreshNameCreator): this.type = updateStore(freshNamesLoc, freshNames)
465464

466465
def setProperty[T](key: Key[T], value: T): this.type =
@@ -520,9 +519,7 @@ object Contexts {
520519
tree = untpd.EmptyTree
521520
typeAssigner = TypeAssigner
522521
moreProperties = Map.empty
523-
store = initialStore
524-
.updated(settingsStateLoc, settings.defaultState)
525-
.updated(runInfoLoc, new RunInfo(this))
522+
store = initialStore.updated(settingsStateLoc, settings.defaultState)
526523
typeComparer = new TypeComparer(this)
527524
searchHistory = new SearchHistory(0, Map())
528525
gadt = EmptyGADTMap

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -929,7 +929,7 @@ object Denotations {
929929
// printPeriods(current)
930930
this.validFor = Period(ctx.runId, targetId, current.validFor.lastPhaseId)
931931
if (current.validFor.firstPhaseId >= targetId)
932-
insertInsteadOf(current)
932+
current.replaceWith(this)
933933
else {
934934
current.validFor = Period(ctx.runId, current.validFor.firstPhaseId, targetId - 1)
935935
insertAfter(current)
@@ -950,7 +950,7 @@ object Denotations {
950950
val current1: SingleDenotation = f(current.asSymDenotation)
951951
if (current1 ne current) {
952952
current1.validFor = current.validFor
953-
current1.insertInsteadOf(current)
953+
current.replaceWith(current1)
954954
}
955955
hasNext = current1.nextInRun.validFor.code > current1.validFor.code
956956
current = current1.nextInRun
@@ -972,14 +972,14 @@ object Denotations {
972972
* The code to achieve this is subtle in that it works correctly
973973
* whether the replaced denotation is the only one in its cycle or not.
974974
*/
975-
private def insertInsteadOf(old: SingleDenotation): Unit = {
976-
var prev = old
977-
while (prev.nextInRun ne old) prev = prev.nextInRun
975+
private[dotc] def replaceWith(newd: SingleDenotation): Unit = {
976+
var prev = this
977+
while (prev.nextInRun ne this) prev = prev.nextInRun
978978
// order of next two assignments is important!
979-
prev.nextInRun = this
980-
this.nextInRun = old.nextInRun
981-
old.validFor = Nowhere
982-
old.nextInRun = this
979+
prev.nextInRun = newd
980+
newd.nextInRun = nextInRun
981+
validFor = Nowhere
982+
nextInRun = newd
983983
}
984984

985985
def staleSymbolError(implicit ctx: Context) =

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ object OrderingConstraint {
2626
private def newConstraint(boundsMap: ParamBounds, lowerMap: ParamOrdering, upperMap: ParamOrdering)(implicit ctx: Context) : OrderingConstraint = {
2727
val result = new OrderingConstraint(boundsMap, lowerMap, upperMap)
2828
if (Config.checkConstraintsNonCyclic) result.checkNonCyclic()
29-
ctx.runInfo.recordConstraintSize(result, result.boundsMap.size)
29+
ctx.run.recordConstraintSize(result, result.boundsMap.size)
3030
result
3131
}
3232

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ object SymDenotations {
275275
final def privateWithin(implicit ctx: Context): Symbol = { ensureCompleted(); myPrivateWithin }
276276

277277
/** Set privateWithin. */
278-
protected[core] final def privateWithin_=(sym: Symbol): Unit =
278+
protected[dotc] final def privateWithin_=(sym: Symbol): Unit =
279279
myPrivateWithin = sym
280280

281281
/** The annotations of this denotation */

0 commit comments

Comments
 (0)