Skip to content

Commit 8838aef

Browse files
committed
Merge pull request #543 from dotty-staging/compile-dotty
Make dotty compile backend.
2 parents 14e5ae5 + 6edf859 commit 8838aef

13 files changed

+113
-53
lines changed

project/Build.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ object DottyBuild extends Build {
3838
// get reflect and xml onboard
3939
libraryDependencies ++= Seq("org.scala-lang" % "scala-reflect" % scalaVersion.value,
4040
"org.scala-lang.modules" %% "scala-xml" % "1.0.1",
41-
"me.d-d" % "scala-compiler" % "2.11.5-20150416-144435-09c4a520e1",
41+
"me.d-d" % "scala-compiler" % "2.11.5-20150506-175515-8fc7635b56",
4242
"org.scala-lang.modules" %% "scala-partest" % "1.0.5" % "test",
4343
"jline" % "jline" % "2.12"),
4444

src/dotty/tools/backend/jvm/DottyBackendInterface.scala

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import StdNames.nme
3333
import NameOps._
3434

3535
class DottyBackendInterface()(implicit ctx: Context) extends BackendInterface{
36-
trait NonExistentTree extends tpd.Tree
3736
type Symbol = Symbols.Symbol
3837
type Type = Types.Type
3938
type Tree = tpd.Tree
@@ -68,8 +67,8 @@ class DottyBackendInterface()(implicit ctx: Context) extends BackendInterface{
6867
type Modifiers = tpd.Modifiers
6968
type Annotation = Annotations.Annotation
7069
type ArrayValue = tpd.JavaSeqLiteral
71-
type ApplyDynamic = NonExistentTree
72-
type ModuleDef = NonExistentTree
70+
type ApplyDynamic = Null
71+
type ModuleDef = Null
7372
type LabelDef = tpd.DefDef
7473
type Closure = tpd.Closure
7574

@@ -230,7 +229,7 @@ class DottyBackendInterface()(implicit ctx: Context) extends BackendInterface{
230229

231230
private def emitArgument(av: AnnotationVisitor,
232231
name: String,
233-
arg: Tree, bcodeStore: BCodeHelpers)(innerClasesStore: bcodeStore.BCInnerClassGen) {
232+
arg: Tree, bcodeStore: BCodeHelpers)(innerClasesStore: bcodeStore.BCInnerClassGen): Unit = {
234233
(arg: @unchecked) match {
235234

236235
case Literal(const @ Constant(_)) =>
@@ -296,7 +295,8 @@ class DottyBackendInterface()(implicit ctx: Context) extends BackendInterface{
296295
}
297296
}
298297

299-
override def emitAnnotations(cw: asm.ClassVisitor, annotations: List[Annotation], bcodeStore: BCodeHelpers)(innerClasesStore: bcodeStore.BCInnerClassGen) {
298+
override def emitAnnotations(cw: asm.ClassVisitor, annotations: List[Annotation], bcodeStore: BCodeHelpers)
299+
(innerClasesStore: bcodeStore.BCInnerClassGen) = {
300300
for(annot <- annotations; if shouldEmitAnnotation(annot)) {
301301
val typ = annot.atp
302302
val assocs = annot.assocs
@@ -305,14 +305,20 @@ class DottyBackendInterface()(implicit ctx: Context) extends BackendInterface{
305305
}
306306
}
307307

308-
private def emitAssocs(av: asm.AnnotationVisitor, assocs: List[(Name, Object)], bcodeStore: BCodeHelpers)(innerClasesStore: bcodeStore.BCInnerClassGen) {
309-
for ((name, value) <- assocs) {
310-
emitArgument(av, name.toString(), value.asInstanceOf[Tree], bcodeStore)(innerClasesStore)
308+
private def emitAssocs(av: asm.AnnotationVisitor, assocs: List[(Name, Object)], bcodeStore: BCodeHelpers)
309+
(innerClasesStore: bcodeStore.BCInnerClassGen) = {
310+
//for ((name, value) <- assocs) { // dotty deviation, does not work
311+
312+
for (nv <- assocs) {
313+
val name = nv._1
314+
val value = nv._2
315+
emitArgument(av, name.toString, value.asInstanceOf[Tree], bcodeStore)(innerClasesStore)
311316
}
312317
av.visitEnd()
313318
}
314319

315-
override def emitAnnotations(mw: asm.MethodVisitor, annotations: List[Annotation], bcodeStore: BCodeHelpers)(innerClasesStore: bcodeStore.BCInnerClassGen) {
320+
override def emitAnnotations(mw: asm.MethodVisitor, annotations: List[Annotation], bcodeStore: BCodeHelpers)
321+
(innerClasesStore: bcodeStore.BCInnerClassGen) = {
316322
for(annot <- annotations; if shouldEmitAnnotation(annot)) {
317323
val typ = annot.atp
318324
val assocs = annot.assocs
@@ -321,7 +327,8 @@ class DottyBackendInterface()(implicit ctx: Context) extends BackendInterface{
321327
}
322328
}
323329

324-
override def emitAnnotations(fw: asm.FieldVisitor, annotations: List[Annotation], bcodeStore: BCodeHelpers)(innerClasesStore: bcodeStore.BCInnerClassGen) {
330+
override def emitAnnotations(fw: asm.FieldVisitor, annotations: List[Annotation], bcodeStore: BCodeHelpers)
331+
(innerClasesStore: bcodeStore.BCInnerClassGen) = {
325332
for(annot <- annotations; if shouldEmitAnnotation(annot)) {
326333
val typ = annot.atp
327334
val assocs = annot.assocs
@@ -330,7 +337,8 @@ class DottyBackendInterface()(implicit ctx: Context) extends BackendInterface{
330337
}
331338
}
332339

333-
override def emitParamAnnotations(jmethod: asm.MethodVisitor, pannotss: List[List[Annotation]], bcodeStore: BCodeHelpers)(innerClasesStore: bcodeStore.BCInnerClassGen) {
340+
override def emitParamAnnotations(jmethod: asm.MethodVisitor, pannotss: List[List[Annotation]], bcodeStore: BCodeHelpers)
341+
(innerClasesStore: bcodeStore.BCInnerClassGen): Unit = {
334342
val annotationss = pannotss map (_ filter shouldEmitAnnotation)
335343
if (annotationss forall (_.isEmpty)) return
336344
for ((annots, idx) <- annotationss.zipWithIndex;
@@ -678,8 +686,24 @@ class DottyBackendInterface()(implicit ctx: Context) extends BackendInterface{
678686

679687
// members
680688
def primaryConstructor: Symbol = toDenot(sym).primaryConstructor
681-
def nestedClasses: List[Symbol] = memberClasses //exitingPhase(currentRun.lambdaliftPhase)(sym.memberClasses)
682-
def memberClasses: List[Symbol] = toDenot(sym).info.memberClasses.map(_.symbol).toList
689+
690+
/** For currently compiled classes: All locally defined classes including local classes.
691+
* The empty list for classes that are not currently compiled.
692+
*/
693+
def nestedClasses: List[Symbol] = definedClasses(ctx.flattenPhase)
694+
695+
/** For currently compiled classes: All classes that are declared as members of this class
696+
* (but not inherited ones). The empty list for classes that are not currently compiled.
697+
*/
698+
def memberClasses: List[Symbol] = definedClasses(ctx.lambdaLiftPhase)
699+
700+
private def definedClasses(phase: Phase) =
701+
if (sym.isDefinedInCurrentRun)
702+
ctx.atPhase(phase) { implicit ctx =>
703+
toDenot(sym).info.decls.filter(_.isClass).toList
704+
}
705+
else Nil
706+
683707
def annotations: List[Annotation] = Nil
684708
def companionModuleMembers: List[Symbol] = {
685709
// phase travel to exitingPickler: this makes sure that memberClassesOf only sees member classes,
@@ -781,7 +805,8 @@ class DottyBackendInterface()(implicit ctx: Context) extends BackendInterface{
781805
def primitiveOrClassToBType(sym: Symbol): BType = {
782806
assert(sym.isClass, sym)
783807
assert(sym != ArrayClass || isCompilingArray, sym)
784-
primitiveTypeMap.getOrElse(sym, storage.getClassBTypeAndRegisterInnerClass(sym.asInstanceOf[ct.int.Symbol]))
808+
primitiveTypeMap.getOrElse(sym.asInstanceOf[ct.bTypes.coreBTypes.bTypes.int.Symbol],
809+
storage.getClassBTypeAndRegisterInnerClass(sym.asInstanceOf[ct.int.Symbol])).asInstanceOf[BType]
785810
}
786811

787812
/**
@@ -790,7 +815,7 @@ class DottyBackendInterface()(implicit ctx: Context) extends BackendInterface{
790815
*/
791816
def nonClassTypeRefToBType(sym: Symbol): ClassBType = {
792817
assert(sym.isType && isCompilingArray, sym)
793-
ObjectReference
818+
ObjectReference.asInstanceOf[ct.bTypes.ClassBType]
794819
}
795820

796821
tp.widenDealias match {
@@ -835,7 +860,7 @@ class DottyBackendInterface()(implicit ctx: Context) extends BackendInterface{
835860
"If possible, please file a bug on issues.scala-lang.org.")
836861

837862
tp match {
838-
case ThisType(ArrayClass) => ObjectReference // was introduced in 9b17332f11 to fix SI-999, but this code is not reached in its test, or any other test
863+
case ThisType(ArrayClass) => ObjectReference.asInstanceOf[ct.bTypes.ClassBType] // was introduced in 9b17332f11 to fix SI-999, but this code is not reached in its test, or any other test
839864
case ThisType(sym) => storage.getClassBTypeAndRegisterInnerClass(sym.asInstanceOf[ct.int.Symbol])
840865
// case t: SingletonType => primitiveOrClassToBType(t.classSymbol)
841866
case t: SingletonType => t.underlying.toTypeKind(ct)(storage)

src/dotty/tools/backend/jvm/GenBCode.scala

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class GenBCodePipeline(val entryPoints: List[Symbol], val int: DottyBackendInter
116116

117117
val caseInsensitively = scala.collection.mutable.Map.empty[String, Symbol]
118118

119-
def run() {
119+
def run(): Unit = {
120120
while (true) {
121121
val item = q1.poll
122122
if (item.isPoison) {
@@ -140,7 +140,7 @@ class GenBCodePipeline(val entryPoints: List[Symbol], val int: DottyBackendInter
140140
* enqueues them in queue-2.
141141
*
142142
*/
143-
def visit(item: Item1) {
143+
def visit(item: Item1) = {
144144
val Item1(arrivalPos, cd, cunit) = item
145145
val claszSymbol = cd.symbol
146146

@@ -218,7 +218,7 @@ class GenBCodePipeline(val entryPoints: List[Symbol], val int: DottyBackendInter
218218
/*BackendStats.timed(BackendStats.methodOptTimer)*/(localOpt.methodOptimizations(classNode))
219219
}
220220

221-
def run() {
221+
def run(): Unit = {
222222
while (true) {
223223
val item = q2.poll
224224
if (item.isPoison) {
@@ -238,7 +238,7 @@ class GenBCodePipeline(val entryPoints: List[Symbol], val int: DottyBackendInter
238238
}
239239
}
240240

241-
private def addToQ3(item: Item2) {
241+
private def addToQ3(item: Item2) = {
242242

243243
def getByteArray(cn: asm.tree.ClassNode): Array[Byte] = {
244244
val cw = new CClassWriter(extraProc)
@@ -277,7 +277,7 @@ class GenBCodePipeline(val entryPoints: List[Symbol], val int: DottyBackendInter
277277
* (c) tear down (closing the classfile-writer and clearing maps)
278278
*
279279
*/
280-
def run(t: Tree) {
280+
def run(t: Tree) = {
281281
this.tree = t
282282

283283
// val bcodeStart = Statistics.startTimer(BackendStats.bcodeTimer)
@@ -321,7 +321,7 @@ class GenBCodePipeline(val entryPoints: List[Symbol], val int: DottyBackendInter
321321
* (c) dequeue one at a time from queue-2, convert it to byte-array, place in queue-3
322322
* (d) serialize to disk by draining queue-3.
323323
*/
324-
private def buildAndSendToDisk(needsOutFolder: Boolean) {
324+
private def buildAndSendToDisk(needsOutFolder: Boolean) = {
325325

326326
feedPipeline1()
327327
// val genStart = Statistics.startTimer(BackendStats.bcodeGenStat)
@@ -337,8 +337,8 @@ class GenBCodePipeline(val entryPoints: List[Symbol], val int: DottyBackendInter
337337
}
338338

339339
/* Feed pipeline-1: place all ClassDefs on q1, recording their arrival position. */
340-
private def feedPipeline1() {
341-
def gen(tree: Tree) {
340+
private def feedPipeline1() = {
341+
def gen(tree: Tree): Unit = {
342342
tree match {
343343
case EmptyTree => ()
344344
case PackageDef(_, stats) => stats foreach gen
@@ -353,9 +353,9 @@ class GenBCodePipeline(val entryPoints: List[Symbol], val int: DottyBackendInter
353353
}
354354

355355
/* Pipeline that writes classfile representations to disk. */
356-
private def drainQ3() {
356+
private def drainQ3() = {
357357

358-
def sendToDisk(cfr: SubItem3, outFolder: scala.tools.nsc.io.AbstractFile) {
358+
def sendToDisk(cfr: SubItem3, outFolder: scala.tools.nsc.io.AbstractFile): Unit = {
359359
if (cfr != null){
360360
val SubItem3(jclassName, jclassBytes) = cfr
361361
try {

src/dotty/tools/backend/jvm/LabelDefs.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ class LabelDefs extends MiniPhaseTransform {
164164
}
165165
}
166166

167-
val collectLabelDefs = new TreeMap() {
167+
object collectLabelDefs extends TreeMap() {
168168

169169
// label calls from this DefDef
170170
var parentLabelCalls: mutable.Set[Tree] = new mutable.HashSet[Tree]()

src/dotty/tools/backend/jvm/scalaPrimitives.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ class DottyPrimitives(ctx: Context) {
125125
/** Initialize the primitive map */
126126
private def init: immutable.Map[Symbol, Int] = {
127127

128-
implicit val ctx = this.ctx
128+
implicit val ctx: Context = this.ctx
129129

130130
import core.Symbols.defn
131131
val primitives = new mutable.HashMap[Symbol, Int]()

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

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package dotty.tools
22
package dotc
33
package core
44

5-
import SymDenotations.{ SymDenotation, ClassDenotation, NoDenotation }
5+
import SymDenotations.{ SymDenotation, ClassDenotation, NoDenotation, NotDefinedHereDenotation }
66
import Contexts.{Context, ContextBase}
77
import Names.{Name, PreName}
88
import Names.TypeName
@@ -128,7 +128,17 @@ object Denotations {
128128
*/
129129
def atSignature(sig: Signature, site: Type = NoPrefix)(implicit ctx: Context): SingleDenotation
130130

131-
/** The variant of this denotation that's current in the given context. */
131+
/** The variant of this denotation that's current in the given context, or
132+
* `NotDefinedHereDenotation` if this denotation does not exist at current phase, but
133+
* is defined elsewhere in this run.
134+
*/
135+
def currentIfExists(implicit ctx: Context): Denotation
136+
137+
/** The variant of this denotation that's current in the given context.
138+
* If no such denotation exists: If Mode.FutureDefs is set, the
139+
* denotation with each alternative at its first point of definition,
140+
* otherwise a `NotDefinedHere` exception is thrown.
141+
*/
132142
def current(implicit ctx: Context): Denotation
133143

134144
/** Is this denotation different from NoDenotation or an ErrorDenotation? */
@@ -349,6 +359,8 @@ object Denotations {
349359
final def signature(implicit ctx: Context) = Signature.OverloadedSignature
350360
def atSignature(sig: Signature, site: Type)(implicit ctx: Context): SingleDenotation =
351361
denot1.atSignature(sig, site) orElse denot2.atSignature(sig, site)
362+
def currentIfExists(implicit ctx: Context): Denotation =
363+
derivedMultiDenotation(denot1.currentIfExists, denot2.currentIfExists)
352364
def current(implicit ctx: Context): Denotation =
353365
derivedMultiDenotation(denot1.current, denot2.current)
354366
def altsWith(p: Symbol => Boolean): List[SingleDenotation] =
@@ -530,7 +542,7 @@ object Denotations {
530542
* is brought forward to be valid in the new runId. Otherwise
531543
* the symbol is stale, which constitutes an internal error.
532544
*/
533-
def current(implicit ctx: Context): SingleDenotation = {
545+
def currentIfExists(implicit ctx: Context): SingleDenotation = {
534546
val currentPeriod = ctx.period
535547
val valid = myValidFor
536548
if (valid.code <= 0) {
@@ -593,17 +605,24 @@ object Denotations {
593605
//println(s"searching: $cur at $currentPeriod, valid for ${cur.validFor}")
594606
cur = cur.nextInRun
595607
cnt += 1
596-
if (cnt > MaxPossiblePhaseId)
597-
if (ctx.mode is Mode.FutureDefsOK)
598-
return current(ctx.withPhase(coveredInterval.firstPhaseId))
599-
else
600-
throw new NotDefinedHere(demandOutsideDefinedMsg)
608+
if (cnt > MaxPossiblePhaseId) return NotDefinedHereDenotation
601609
}
602610
cur
603611
}
604612
}
605613
}
606614

615+
def current(implicit ctx: Context): SingleDenotation = {
616+
val d = currentIfExists
617+
if (d ne NotDefinedHereDenotation) d else currentNoDefinedHere
618+
}
619+
620+
private def currentNoDefinedHere(implicit ctx: Context): SingleDenotation =
621+
if (ctx.mode is Mode.FutureDefsOK)
622+
current(ctx.withPhase(coveredInterval.firstPhaseId))
623+
else
624+
throw new NotDefinedHere(demandOutsideDefinedMsg)
625+
607626
private def demandOutsideDefinedMsg(implicit ctx: Context): String =
608627
s"demanding denotation of $this at phase ${ctx.phase}(${ctx.phaseId}) outside defined interval: defined periods are${definedPeriodsString}"
609628

src/dotty/tools/dotc/core/Phases.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ object Phases {
235235
private val extensionMethodsCache = new PhaseCache(classOf[ExtensionMethods])
236236
private val erasureCache = new PhaseCache(classOf[Erasure])
237237
private val patmatCache = new PhaseCache(classOf[PatternMatcher])
238+
private val lambdaLiftCache = new PhaseCache(classOf[LambdaLift])
238239
private val flattenCache = new PhaseCache(classOf[Flatten])
239240
private val explicitOuterCache = new PhaseCache(classOf[ExplicitOuter])
240241
private val gettersCache = new PhaseCache(classOf[Getters])
@@ -245,6 +246,7 @@ object Phases {
245246
def extensionMethodsPhase = extensionMethodsCache.phase
246247
def erasurePhase = erasureCache.phase
247248
def patmatPhase = patmatCache.phase
249+
def lambdaLiftPhase = lambdaLiftCache.phase
248250
def flattenPhase = flattenCache.phase
249251
def explicitOuterPhase = explicitOuterCache.phase
250252
def gettersPhase = gettersCache.phase

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1650,7 +1650,7 @@ object SymDenotations {
16501650
}
16511651
}
16521652

1653-
object NoDenotation extends SymDenotation(
1653+
class NoDenotation extends SymDenotation(
16541654
NoSymbol, NoSymbol, "<none>".toTermName, Permanent, NoType) {
16551655
override def exists = false
16561656
override def isTerm = false
@@ -1660,6 +1660,9 @@ object SymDenotations {
16601660
validFor = Period.allInRun(NoRunId) // will be brought forward automatically
16611661
}
16621662

1663+
val NoDenotation = new NoDenotation
1664+
val NotDefinedHereDenotation = new NoDenotation
1665+
16631666
// ---- Completion --------------------------------------------------------
16641667

16651668
/** Instances of LazyType are carried by uncompleted symbols.

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,8 +406,12 @@ object Symbols {
406406
}
407407

408408
/** Subclass tests and casts */
409-
final def isTerm(implicit ctx: Context): Boolean = denot.isTerm
410-
final def isType(implicit ctx: Context): Boolean = denot.isType
409+
final def isTerm(implicit ctx: Context): Boolean =
410+
(if(isDefinedInCurrentRun) lastDenot else denot).isTerm
411+
412+
final def isType(implicit ctx: Context): Boolean =
413+
(if(isDefinedInCurrentRun) lastDenot else denot).isType
414+
411415
final def isClass: Boolean = isInstanceOf[ClassSymbol]
412416

413417
final def asTerm(implicit ctx: Context): TermSymbol = { assert(isTerm, s"asTerm called on not-a-Term $this" ); asInstanceOf[TermSymbol] }

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1244,7 +1244,10 @@ object Types {
12441244
}
12451245
case d =>
12461246
if (d.validFor.runId != ctx.period.runId) loadDenot
1247-
else d.current
1247+
else {
1248+
val newd = d.currentIfExists
1249+
if (newd ne NotDefinedHereDenotation) newd else loadDenot
1250+
}
12481251
}
12491252
if (ctx.typerState.ephemeral) record("ephemeral cache miss: loadDenot")
12501253
else if (d.exists) {

0 commit comments

Comments
 (0)