Skip to content

Commit 70d6674

Browse files
committed
Merge pull request #11 from lrytz/backendWip
started adapting backend to dotty symbols, denotations, etc
2 parents 866f1ae + 38507fe commit 70d6674

File tree

9 files changed

+72
-54
lines changed

9 files changed

+72
-54
lines changed

src/dotty/tools/dotc/Driver.scala

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,11 @@ abstract class Driver extends DotClass {
2929
try {
3030
doCompile(newCompiler(), fileNames)
3131
} catch {
32+
case ex: FatalError =>
33+
ctx.error(ex.getMessage) // signals that we should fail compilation.
34+
ctx.typerState.reporter
3235
case ex: Throwable =>
33-
ex match {
34-
case ex: FatalError =>
35-
ctx.error(ex.getMessage) // signals that we should fail compilation.
36-
ctx.typerState.reporter
37-
case _ =>
38-
throw ex // unexpected error, tell the outside world.
39-
}
36+
throw ex // unexpected error, tell the outside world.
4037
}
4138
}
4239

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ object Trees {
260260
case _ => NoType
261261
}
262262

263-
/** The denotation referred tno by this tree.
263+
/** The denotation referred to by this tree.
264264
* Defined for `DenotingTree`s and `ProxyTree`s, NoDenotation for other
265265
* kinds of trees
266266
*/

src/dotty/tools/dotc/backend/jvm/BCodeBodyBuilder.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ import dotc.ast.Trees._
1818
import core.Types.Type
1919
import core.StdNames
2020
import core.Symbols.{Symbol, NoSymbol}
21+
import core.SymDenotations._
2122
import core.Constants.Constant
23+
import config.Printers.bcknd
2224

2325
/*
2426
*
@@ -33,7 +35,7 @@ abstract class BCodeBodyBuilder extends BCodeSkelBuilder {
3335
/*
3436
* Functionality to build the body of ASM MethodNode, except for `synchronized` and `try` expressions.
3537
*/
36-
abstract class PlainBodyBuilder(cunit: CompilationUnit,
38+
abstract class PlainBodyBuilder(cunit: CompilationUnit,
3739
implicit val ctx: dotc.core.Contexts.Context) extends PlainSkelBuilder(cunit) {
3840

3941
import icodes.TestOp
@@ -44,8 +46,8 @@ abstract class BCodeBodyBuilder extends BCodeSkelBuilder {
4446
* it is the host class; otherwise the symbol's owner.
4547
*/
4648
def findHostClass(selector: Type, sym: Symbol) = selector member sym.name match {
47-
case NoSymbol => debuglog(s"Rejecting $selector as host class for $sym") ; sym.owner
48-
case _ => selector.typeSymbol
49+
case NoDenotation => bcknd.println(s"Rejecting $selector as host class for $sym") ; sym.owner
50+
case _ => selector.typeSymbol
4951
}
5052

5153
/* ---------------- helper utils for generating methods and code ---------------- */

src/dotty/tools/dotc/backend/jvm/BCodeHelpers.scala

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,16 @@ package backend.jvm
1010
import scala.tools.asm
1111
import scala.annotation.switch
1212
import scala.collection.{ immutable, mutable }
13-
import scala.tools.nsc.io.AbstractFile
13+
import dotty.tools.io.AbstractFile
1414

1515
import dotc.ast.Trees._
1616

1717
import dotc.core.StdNames
1818
import dotc.core.Types.Type
1919
import dotc.core.Symbols.{Symbol, NoSymbol}
20+
import dotc.core.SymDenotations._
21+
import dotc.core.Flags
22+
import dotc.core.StdNames.{nme, tpnme}
2023

2124
/*
2225
* Traits encapsulating functionality to convert Scala AST Trees into ASM ClassNodes.
@@ -435,37 +438,36 @@ abstract class BCodeHelpers extends BCodeTypes with BytecodeWriters {
435438
* Tracks (if needed) the inner class given by `t`.
436439
*
437440
* must-single-thread
441+
*
442+
* TODO(lry): check if `ctx` should be a paramter of the class instead.
438443
*/
439-
final def toTypeKind(t: Type): BType = {
444+
final def toTypeKind(t: Type)(implicit ctx: dotc.core.Contexts.Context): BType = {
440445

441446
/* Interfaces have to be handled delicately to avoid introducing spurious errors,
442447
* but if we treat them all as AnyRef we lose too much information.
443448
*/
444-
def newReference(sym0: Symbol): BType = {
445-
assert(!primitiveTypeMap.contains(sym0), "Use primitiveTypeMap instead.")
446-
assert(sym0 != definitions.ArrayClass, "Use arrayOf() instead.")
447-
448-
if (sym0 == definitions.NullClass) return RT_NULL;
449-
if (sym0 == definitions.NothingClass) return RT_NOTHING;
450-
451-
val sym = (
452-
if (!sym0.isPackageClass) sym0
453-
else sym0.info.member(nme.PACKAGE) match {
454-
case NoSymbol => abort(s"SI-5604: Cannot use package as value: ${sym0.fullName}")
455-
case s => abort(s"SI-5604: found package class where package object expected: $s")
449+
def newReference(sym: Symbol): BType = {
450+
assert(!primitiveTypeMap.contains(sym), "Use primitiveTypeMap instead.")
451+
assert(sym != ctx.definitions.ArrayClass, "Use arrayOf() instead.")
452+
453+
if (sym == ctx.definitions.NullClass) return RT_NULL;
454+
if (sym == ctx.definitions.NothingClass) return RT_NOTHING;
455+
456+
if (sym is Flags.PackageClass) {
457+
sym.info.member(nme.PACKAGE) match {
458+
case NoDenotation => throw new FatalError(s"SI-5604: Cannot use package as value: ${sym.fullName}")
459+
case s => throw new FatalError(s"SI-5604: found package class where package object expected: $s")
456460
}
457-
)
461+
}
458462

459-
// Can't call .toInterface (at this phase) or we trip an assertion.
460-
// See PackratParser#grow for a method which fails with an apparent mismatch
461-
// between "object PackratParsers$class" and "trait PackratParsers"
462-
if (sym.isImplClass) {
463-
// pos/spec-List.scala is the sole failure if we don't check for NoSymbol
464-
val traitSym = sym.owner.info.decl(tpnme.interfaceName(sym.name))
465-
if (traitSym != NoSymbol) {
463+
if (sym is Flags.ImplClass) {
464+
val traitDenot = sym.owner.info.decl(tpnme.interfaceName(sym.name))
465+
// scalac legacy: the `if` check below should not be needed.
466+
// pos/spec-List.scala is the sole failure if we don't check for NoDenotation
467+
// if (traitDenot != NoDenotation) {
466468
// this tracks the inner class in innerClassBufferASM, if needed.
467-
return asmClassType(traitSym)
468-
}
469+
return asmClassType(traitDenot.symbol)
470+
// }
469471
}
470472

471473
assert(hasInternalName(sym), s"Invoked for a symbol lacking JVM internal name: ${sym.fullName}")

src/dotty/tools/dotc/backend/jvm/BCodeTypes.scala

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ import dotc.ast.Trees.Tree
1414
import dotc.core.Types.Type
1515
import dotc.core.StdNames
1616
import dotc.core.Symbols.{Symbol, NoSymbol}
17+
import dotc.core.SymDenotations._
18+
import dotc.core.Flags
1719

18-
import StdNames.nme
20+
import StdNames.{nme, tpnme}
1921

2022
/*
2123
* Utilities to mediate between types as represented in Scala ASTs and ASM trees.
@@ -378,13 +380,15 @@ abstract class BCodeTypes extends BCodeIdiomatic {
378380
* On the other hand, this method does record the inner-class status of the argument, via `buildExemplar()`.
379381
*
380382
* must-single-thread
383+
*
384+
* TODO(lry) check if ctx should be a class parameter
381385
*/
382-
final def exemplar(csym0: Symbol): Tracked = {
386+
final def exemplar(csym0: Symbol)(implicit ctx: dotc.core.Contexts.Context): Tracked = {
383387
assert(csym0 != NoSymbol, "NoSymbol can't be tracked")
384388

385389
val csym = {
386-
if (csym0.isJavaDefined && csym0.isModuleClass) csym0.linkedClassOfClass
387-
else if (csym0.isModule) csym0.moduleClass
390+
if ((csym0 is Flags.JavaDefined) && (csym0 is Flags.ModuleClass)) csym0.linkedClass
391+
else if (csym0 is Flags.ModuleVal) csym0.moduleClass
388392
else csym0 // we track only module-classes and plain-classes
389393
}
390394

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ import dotc.core.Symbols.{Symbol, NoSymbol}
5050
object GenBCode extends BCodeSyncAndTry {
5151

5252
final class PlainClassBuilder(cunit: CompilationUnit,
53-
ctx: dotc.core.Contexts.Context) extends SyncAndTryBuilder(cunit)
53+
ctx: dotc.core.Contexts.Context) extends SyncAndTryBuilder(cunit, ctx)
5454

5555
class BCodePhase extends dotc.core.Phases.Phase {
5656

@@ -64,7 +64,7 @@ object GenBCode extends BCodeSyncAndTry {
6464

6565
/* ---------------- q1 ---------------- */
6666

67-
case class Item1(arrivalPos: Int, cd: ast.Trees.TypeDef, cunit: CompilationUnit) {
67+
case class Item1(arrivalPos: Int, cd: ast.tpd.TypeDef, cunit: CompilationUnit) {
6868
def isPoison = { arrivalPos == Int.MaxValue }
6969
}
7070
private val poison1 = Item1(Int.MaxValue, null, null)

src/dotty/tools/dotc/config/Printers.scala

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,17 @@ object Printers {
1010
override def println(msg: => String): Unit = ()
1111
}
1212

13-
val default: Printer = new Printer
14-
val core: Printer = noPrinter
15-
val typr: Printer = noPrinter
16-
val constr: Printer = noPrinter
17-
val overload: Printer = noPrinter
18-
val implicits: Printer = noPrinter
13+
val default: Printer = new Printer
14+
val core: Printer = noPrinter
15+
val typr: Printer = noPrinter
16+
val constr: Printer = noPrinter
17+
val overload: Printer = noPrinter
18+
val implicits: Printer = noPrinter
1919
val implicitsDetailed: Printer = noPrinter
20-
val subtyping: Printer = noPrinter
21-
val unapp: Printer = noPrinter
22-
val completions = noPrinter
23-
val gadts = noPrinter
20+
val subtyping: Printer = noPrinter
21+
val unapp: Printer = noPrinter
22+
val completions: Printer = noPrinter
23+
val gadts: Printer = noPrinter
24+
val bcknd: Printer = noPrinter
2425

2526
}

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ object Flags {
2525
FlagSet(tbits | ((this.bits | that.bits) & ~KINDFLAGS))
2626
}
2727

28-
/** The intersection of this flag set and the given flag set */
28+
/** The intersection of this flag set and the given flag set
29+
* TODO(lry): check if resulting flag set has a non-empty kind?
30+
*/
2931
def & (that: FlagSet) = FlagSet(bits & that.bits)
3032

3133
/** The intersection of this flag set with the complement of the given flag set */
@@ -89,7 +91,7 @@ object Flags {
8991
/** The lowest non-kind bit set in this flagset */
9092
def firstBit: Int = java.lang.Long.numberOfTrailingZeros(bits & ~KINDFLAGS)
9193

92-
/** The list of non-empty names of flags with given index idx that are set in this FlagSet */
94+
/** The list of non-empty names of flags with given index idx that are set in this FlagSet */
9395
private def flagString(idx: Int): List[String] =
9496
if ((bits & (1L << idx)) == 0) Nil
9597
else {
@@ -112,6 +114,10 @@ object Flags {
112114
/** A class representing flag sets that should be tested
113115
* conjunctively. I.e. for a flag conjunction `fc`,
114116
* `x is fc` tests whether `x` contains all flags in `fc`.
117+
*
118+
* TODO(lry) cannot be a value class because its erause is the same as `FlagSet`,
119+
* the overloaded `is` would not work. Maybe rename `is` to `isAny` and `isAll`,
120+
* get rid of `FlagConjunction`? Code would also be more explicit.
115121
*/
116122
case class FlagConjunction(bits: Long) {
117123
override def toString = FlagSet(bits).toString
@@ -249,7 +255,10 @@ object Flags {
249255
final val PackageVal = Package.toTermFlags
250256
final val PackageClass = Package.toTypeFlags
251257

252-
/** A case class or its companion object */
258+
/** A case class or its companion object
259+
* TODO(lry): Is CaseVal set for the companion of a case class? Or for a `case object`?
260+
* Or both? Is CaseClass set for the module class of a `case object`?
261+
*/
253262
final val Case = commonFlag(17, "case")
254263
final val CaseClass = Case.toTypeFlags
255264
final val CaseVal = Case.toTermFlags

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,9 @@ object StdNames {
644644
def higherKindedTraitName(n: Int) = HigherKinded ++ n.toString
645645
def higherKindedParamName(n: Int) = HK_PARAM_PREFIX ++ n.toString
646646

647+
def implClassName(name: Name): TypeName = (name ++ IMPL_CLASS_SUFFIX).toTypeName
648+
def interfaceName(implname: Name): TypeName = (implname dropRight IMPL_CLASS_SUFFIX.length).toTypeName
649+
647650
final val Conforms = encode("<:<")
648651
}
649652

0 commit comments

Comments
 (0)