Skip to content

Commit

Permalink
Cleanup warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
bishabosha committed Jun 26, 2020
1 parent f496ac9 commit c32056f
Show file tree
Hide file tree
Showing 18 changed files with 122 additions and 140 deletions.
23 changes: 0 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,3 @@
# TASTy Reader For Scala 2

This branch is the home for development of the Scala Center project [**TASTy Reader For Scala 2**](https://scala.epfl.ch/projects.html#tastyScala2), which will enable the reference compiler of Scala 2.x to consume dependencies compiled with dotc, the reference compiler of Scala 3. The scope of this project is to enable all Scala 2 compatible features of TASTy files to be read during class file unpickling. There is no goal to backport non-compatible features. Features are tested with `ch.epfl.lamp:dotty-compiler_0.22:0.22.0-RC1`. Check the issues at [scalacenter/scala](https://github.com/scalacenter/scala/issues)

## Testing

The framework for testing TASTy reader is contained in the `tastytest` subproject. A description of its functionality is provided at [tastytest.md](doc/internal/tastytest.md)

The `tasty` project is an example subproject depending on `tastytest`, used to test the functionality of the TASTy reader. Test sources are placed in the `test/tasty` directory of this repository.

`tasty/test` is used to run the full suite of tests, isolated tests can be made by following the example of [TastyTestJUnit](test/tasty/test/scala/tools/tastytest/TastyTestJUnit.scala) and running with `tasty/testOnly <test class>`

Individual tasks exist to help debug issues:

- `tasty/dotc <out directory> <filename>` to compile a Scala 3 source file with the supported version of dotty, where the classpath is set to the out directory.
- `tasty/dotcd <filename> <arg>*` to decompile a tasty file with the supported version of dotty. Can pass additional flags.
- `tasty/scalac <out directory> <filename> <arg>*` to compile a Scala 2 file, where the classpath is set to the out directory, along with the dotty library. Can pass additional flags.
- `tasty/runDotty <classpath> <classname>` to execute a main method with the dotty library added to the given classpath.

## Notes

comments beginning with `// TODO [tasty]:` should be considered carefully as they are special accomodations for the TASTy reader that are particulary expensive, or leak out of the classfile parser or `scala.tools.nsc.tasty` package.

# Welcome!

This is the official repository for the [Scala Programming Language](http://www.scala-lang.org)
Expand Down
20 changes: 20 additions & 0 deletions doc/internal/tastyreader.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# TASTy Reader For Scala 2

The [**TASTy Reader For Scala 2**](https://scala.epfl.ch/projects.html#tastyScala2), included in the Scala 2.x Compiler will enable dependencies to be used which are compiled with dotc, the reference compiler of Scala 3.

## Testing

The framework for testing TASTy reader is contained in the `tastytest` subproject. A description of its functionality is provided at [tastytest.md](tastytest.md)

The `tasty` project is an example subproject depending on `tastytest`, used to test the functionality of the TASTy reader. Test sources are placed in the `test/tasty` directory of this repository and tested with the sbt task `tasty/test`.

Individual tasks exist to help debug issues:

- `tasty/dotc <out directory> <filename>` to compile a Scala 3 source file with the supported version of dotty, where the classpath is set to the out directory.
- `tasty/dotcd <filename> <arg>*` to decompile a tasty file with the supported version of dotty. Can pass additional flags.
- `tasty/scalac <out directory> <filename> <arg>*` to compile a Scala 2 file, where the classpath is set to the out directory, along with the dotty library. Can pass additional flags.
- `tasty/runDotty <classpath> <classname>` to execute a main method with the dotty library added to the given classpath.

## Notes

comments beginning with `// TODO [tasty]:` should be considered carefully as they are special accomodations for the TASTy reader that are particulary expensive, or leak out of the classfile parser or `scala.tools.nsc.tasty` package.
8 changes: 1 addition & 7 deletions doc/internal/tastytest.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# TASTy Test

TASTy Test is a testing framework for scala 2 code that depends on code compiled with the `dotc`, the Scala 3 compiler, which outputs TASTy trees. The framework supports `run` and `neg` suites.
TASTy Test is a testing framework for scala 2 code that depends on code compiled with the `dotc`, the Scala 3 compiler, which outputs TASTy trees. The framework supports `run`, `pos` and `neg` suites, which may be customised with extra flags.

## `run`
A `run` suite tests the runtime behaviour of Scala 2 code that may extend or call into code compiled with `dotc`, and is specified as follows:
Expand All @@ -24,12 +24,6 @@ A `neg` suite asserts which Scala 2 code is not compatible with code compiled wi
- If a Scala source fails compilation, check that it is in the set of expected fail cases, and that there is a corresponding check file that matches the compiler output, else collect in the list of failures.
- If an expected fail case compiles successfully, collect it in the list of failures.

## `neg-false`
A `neg-false` test runs identically to a `neg` test, but asserts that a test is a false positive.

## `pos-false`
A `pos-false` test runs identically to a `pos` test, but asserts that a test is a false positive.

## General Notes
- In each suite, the dotty library is available to all test sources.
- In either suite's source directory, failing tests without a known fix should be put in a sibling directory to `src-2`, `src-3`, etc., such as `suspended`, to document that they are incompatible at present.
2 changes: 0 additions & 2 deletions src/compiler/scala/tools/nsc/tasty/Names.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package scala.tools.nsc.tasty

import scala.annotation.tailrec
import scala.reflect.NameTransformer
import scala.reflect.internal.Variance

object Names {

Expand Down
20 changes: 10 additions & 10 deletions src/compiler/scala/tools/nsc/tasty/TastyFlags.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ object TastyFlags {
final val SuperParamAlias: TastyFlagSet = Open.next
final val maxFlag: Int = SuperParamAlias.shift

case class TastyFlagSet private[TastyFlags](private val flags: Int) extends AnyVal {
case class TastyFlagSet(val toInt: Int) extends AnyVal {

private[TastyFlags] def shift: Int = {
var acc = 0
var curr = flags
var curr = toInt
while (curr != 0) {
acc += 1
curr = curr >> 1
Expand All @@ -37,16 +37,16 @@ object TastyFlags {
TastyFlagSet(1 << shift + 1)
}

def toSingletonSets: SingletonSets = SingletonSets(flags)
def |(other: TastyFlagSet): TastyFlagSet = TastyFlagSet(flags | other.flags)
def &(mask: TastyFlagSet): TastyFlagSet = TastyFlagSet(flags & mask.flags)
def &~(mask: TastyFlagSet): TastyFlagSet = TastyFlagSet(flags & ~mask.flags)
def unary_! : Boolean = this.flags == 0
def toSingletonSets: SingletonSets = SingletonSets(toInt)
def |(other: TastyFlagSet): TastyFlagSet = TastyFlagSet(toInt | other.toInt)
def &(mask: TastyFlagSet): TastyFlagSet = TastyFlagSet(toInt & mask.toInt)
def &~(mask: TastyFlagSet): TastyFlagSet = TastyFlagSet(toInt & ~mask.toInt)
def unary_! : Boolean = this.toInt == 0
def is(mask: TastyFlagSet): Boolean = (this & mask) == mask
def isOneOf(mask: TastyFlagSet): Boolean = (this & mask).hasFlags
def is(mask: TastyFlagSet, butNot: TastyFlagSet): Boolean = if (!butNot) is(mask) else is(mask) && not(butNot)
def not(mask: TastyFlagSet): Boolean = !isOneOf(mask)
def hasFlags: Boolean = this.flags != 0
def hasFlags: Boolean = this.toInt != 0

def debug: String = {
if (!this) {
Expand Down Expand Up @@ -75,13 +75,13 @@ object TastyFlags {
}
}

case class SingletonSets private[TastyFlags](private val set: Int) extends AnyVal {
case class SingletonSets(val toInt: Int) extends AnyVal {
def map[A](f: TastyFlagSet => A): Iterable[A] = {
val buf = Iterable.newBuilder[A]
var i = 0
while (i <= maxFlag) {
val flag = 1 << i
if ((flag & set) != 0) {
if ((flag & toInt) != 0) {
buf += f(TastyFlagSet(flag))
}
i += 1
Expand Down
2 changes: 0 additions & 2 deletions src/compiler/scala/tools/nsc/tasty/TastyRefs.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package scala.tools.nsc.tasty

import scala.reflect.ClassTag

object TastyRefs {

/** An address pointing to an index in a Tasty buffer's byte array */
Expand Down
94 changes: 46 additions & 48 deletions src/compiler/scala/tools/nsc/tasty/TreeUnpickler.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package scala.tools.nsc.tasty

import TastyRefs._
import scala.annotation.{switch, tailrec}
import scala.annotation.switch
import scala.collection.mutable
import scala.reflect.io.AbstractFile
import Names.TastyName
Expand Down Expand Up @@ -187,7 +187,7 @@ class TreeUnpickler[Tasty <: TastyUniverse](
if (mode === MemberDefsOnly) skipTree(tag)
else if (tag >= firstLengthTreeTag) {
val end = readEnd()
var nrefs = numRefs(tag)
val nrefs = numRefs(tag)
if (nrefs < 0) {
for (i <- nrefs until 0) scanTree(buf)
goto(end)
Expand Down Expand Up @@ -347,7 +347,7 @@ class TreeUnpickler[Tasty <: TastyUniverse](
val result =
(tag: @switch) match {
case TERMREFin =>
var name = readTastyName()
val name = readTastyName()
val prefix = readType()
val space = readType()
selectTerm(prefix, space, name)
Expand Down Expand Up @@ -504,7 +504,7 @@ class TreeUnpickler[Tasty <: TastyUniverse](
// // without this precaution we get an infinite cycle when unpickling pos/extmethods.scala
// // the problem arises when a self type of a trait is a type parameter of the same trait.
// }
NamedType(prefix, sym)
mkNamedType(prefix, sym)
}

private def readPackageRef()(implicit ctx: Context): TermSymbol = {
Expand Down Expand Up @@ -609,7 +609,7 @@ class TreeUnpickler[Tasty <: TastyUniverse](
val tag = readByte()
def isTypeTag = tag === TYPEDEF || tag === TYPEPARAM
val end = readEnd()
var tname: TastyName = readTastyName()
val tname: TastyName = readTastyName()
var name: Name = tname.toEncodedTermName
if (isTypeTag) name = name.toTypeName
skipParams()
Expand All @@ -618,7 +618,6 @@ class TreeUnpickler[Tasty <: TastyUniverse](
val isClass = ttag === TEMPLATE
val templateStart = currentAddr
skipTree() // tpt
val rhsStart = currentAddr
val rhsIsEmpty = nothingButMods(end)
if (!rhsIsEmpty) skipTree()
val (givenFlags, tastyFlagSet, annotFns, privateWithin) =
Expand Down Expand Up @@ -835,8 +834,8 @@ class TreeUnpickler[Tasty <: TastyUniverse](
* - a context which has the processed package as owner
*/
def processPackage[T](op: (RefTree, Addr) => Context => T)(implicit ctx: Context): T = {
val sctx = sourceChangeContext()
if (sctx `ne` ctx) return processPackage(op)(sctx)
// val sctx = sourceChangeContext()
// if (sctx `ne` ctx) return processPackage(op)(sctx)
readByte()
val end = readEnd()
val tpe = readTypeAsTypeRef()
Expand Down Expand Up @@ -881,8 +880,8 @@ class TreeUnpickler[Tasty <: TastyUniverse](
}

private def readNewMember()(implicit ctx: Context): NoCycle = {
val sctx = sourceChangeContext()
if (sctx `ne` ctx) return readNewMember()(sctx)
// val sctx = sourceChangeContext()
// if (sctx `ne` ctx) return readNewMember()(sctx)
val symAddr = currentAddr
val sym = symAtAddr(symAddr)
val tag = readByte()
Expand Down Expand Up @@ -995,7 +994,7 @@ class TreeUnpickler[Tasty <: TastyUniverse](
if (tparams.nonEmpty) {
cls.info = new PolyType(tparams.map(symFromNoCycle), cls.info)
}
val vparams = readIndexedParams[NoCycle](PARAM)
readIndexedParams[NoCycle](PARAM) // skip value parameters
ctx.log(s"Template: indexing members of $cls")
val (bodyFlags, bodyTastyFlags) = {
val bodyIndexer = fork
Expand Down Expand Up @@ -1342,8 +1341,8 @@ class TreeUnpickler[Tasty <: TastyUniverse](
// ------ Reading trees -----------------------------------------------------

def readTerm()(implicit ctx: Context): Tree = { // TODO: rename to readTree
val sctx = sourceChangeContext()
if (sctx `ne` ctx) return readTerm()(sctx)
// val sctx = sourceChangeContext()
// if (sctx `ne` ctx) return readTerm()(sctx)
val start = currentAddr
val tag = readByte()
ctx.log(s"reading term ${astTagToString(tag)} at $start")
Expand Down Expand Up @@ -1468,10 +1467,11 @@ class TreeUnpickler[Tasty <: TastyUniverse](
val elsep = readTerm()
If(cond, thenp, elsep).setType(lub(thenp.tpe, elsep.tpe))
}
case LAMBDA => // TODO [tasty]: if we need trees then we need to either turn this closure to the result of Delambdafy, or resugar to a Function
val meth = readTerm()
val tpt = ifBefore(end)(readTpt(), emptyTree)
TypeTree(meth.tpe) //Closure(Nil, meth, tpt)
case LAMBDA =>
throw new TASTyException(ctx.owner, "LAMBDA")
// val meth = readTerm()
// val tpt = ifBefore(end)(readTpt(), emptyTree)
// Closure(Nil, meth, tpt)
case MATCH =>
if (nextByte === IMPLICIT) {
readByte()
Expand Down Expand Up @@ -1589,9 +1589,8 @@ class TreeUnpickler[Tasty <: TastyUniverse](
}

def readTpt()(implicit ctx: Context): Tree = {
val sctx = sourceChangeContext()
if (sctx `ne` ctx) return readTpt()(sctx)
val start = currentAddr
// val sctx = sourceChangeContext()
// if (sctx `ne` ctx) return readTpt()(sctx)
val tpt: Tree = nextByte match {
case SHAREDterm =>
readByte()
Expand Down Expand Up @@ -1620,8 +1619,8 @@ class TreeUnpickler[Tasty <: TastyUniverse](

/** TODO [tasty]: SPECIAL OPTIMAL CASE FOR TEMPLATES */
def readParentFromTerm()(implicit ctx: Context): Type = { // TODO: rename to readTree
val sctx = sourceChangeContext()
if (sctx `ne` ctx) return readParentFromTerm()(sctx)
// val sctx = sourceChangeContext()
// if (sctx `ne` ctx) return readParentFromTerm()(sctx)
val start = currentAddr
val tag = readByte()
ctx.log(s"reading parent-term ${astTagToString(tag)} at $start")
Expand Down Expand Up @@ -1674,9 +1673,8 @@ class TreeUnpickler[Tasty <: TastyUniverse](
}

def readCase()(implicit ctx: Context): CaseDef = {
val sctx = sourceChangeContext()
if (sctx `ne` ctx) return readCase()(sctx)
val start = currentAddr
// val sctx = sourceChangeContext()
// if (sctx `ne` ctx) return readCase()(sctx)
assert(readByte() === CASEDEF)
val end = readEnd()
val pat = readTerm()
Expand Down Expand Up @@ -1742,31 +1740,31 @@ class TreeUnpickler[Tasty <: TastyUniverse](
// spanCoord(span)
// else
// indexCoord(addr.index)
noPosition
ctx.emptyPosition
}

/** Pickled source path at `addr`. */
def sourcePathAt(addr: Addr)(implicit ctx: Context): String = ""
// if (ctx.mode.is(Mode.ReadPositions)) {
// posUnpicklerOpt match {
// case Some(posUnpickler) =>
// posUnpickler.sourcePathAt(addr)
// case _ =>
// ""
// }
// } else ""

/** If currentAddr carries a source path, the current context with
* the source of that path, otherwise the current context itself.
*/
def sourceChangeContext(addr: Addr = currentAddr)(implicit ctx: Context): Context = {
val path = sourcePathAt(addr)
if (!path.isEmpty) {
ctx.log(s"source change at $addr: $path")
sys.error("Context requires to change source.") // ctx.withSource(ctx.getSource(path))
}
else ctx
}
// /** Pickled source path at `addr`. */
// def sourcePathAt(addr: Addr)(implicit ctx: Context): String =
// if (ctx.mode.is(Mode.ReadPositions)) {
// posUnpicklerOpt match {
// case Some(posUnpickler) =>
// posUnpickler.sourcePathAt(addr)
// case _ =>
// ""
// }
// } else ""

// /** If currentAddr carries a source path, the current context with
// * the source of that path, otherwise the current context itself.
// */
// def sourceChangeContext(addr: Addr = currentAddr)(implicit ctx: Context): Context = {
// val path = sourcePathAt(addr)
// if (!path.isEmpty) {
// ctx.log(s"source change at $addr: $path")
// sys.error("Context requires to change source.") // ctx.withSource(ctx.getSource(path))
// }
// else ctx
// }

// /** Set position of `tree` at given `addr`. */
// def setSpan[T <: untpd.Tree](addr: Addr, tree: T)(implicit ctx: Context): tree.type = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package scala.tools.nsc.tasty.bridge

import scala.tools.nsc.tasty.{SafeEq, TastyUniverse}

trait AnnotationOps extends TastyKernel { self: TastyUniverse =>
trait AnnotationOps { self: TastyUniverse =>

object Annotation {
def deferredSymAndTree(annotee: Symbol)(symf: => Symbol)(tree: => Option[Tree])(implicit ctx: Contexts.Context): Annotation =
Expand Down
10 changes: 6 additions & 4 deletions src/compiler/scala/tools/nsc/tasty/bridge/ContextOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import scala.collection.mutable
import scala.reflect.io.AbstractFile
import scala.tools.nsc.tasty.TastyUniverse

trait ContextOps extends TastyKernel { self: TastyUniverse =>
trait ContextOps { self: TastyUniverse =>
import FlagSets._
import Contexts._

Expand All @@ -26,12 +26,12 @@ trait ContextOps extends TastyKernel { self: TastyUniverse =>
def adjustModuleCompleter(completer: TastyLazyType, name: Name): TastyLazyType = {
val scope = this.effectiveScope
if (name.isTermName)
completer withModuleClass (implicit ctx => findModuleBuddy(name.toTypeName, scope))
completer withModuleClass (_.findModuleBuddy(name.toTypeName, scope))
else
completer withSourceModule (implicit ctx => findModuleBuddy(name.toTermName, scope))
completer withSourceModule (_.findModuleBuddy(name.toTermName, scope))
}

private def findModuleBuddy(name: Name, scope: Scope)(implicit ctx: Context): Symbol = {
private def findModuleBuddy(name: Name, scope: Scope): Symbol = {
val it = scope.lookupAll(name).filter(_.is(Module))
if (it.hasNext) it.next()
else noSymbol
Expand Down Expand Up @@ -68,6 +68,8 @@ trait ContextOps extends TastyKernel { self: TastyUniverse =>
final lazy val loadingMirror: Mirror = initialContext.baseLoadingMirror
final lazy val classRoot: Symbol = initialContext.baseClassRoot

def emptyPosition: Position = noPosition

def newLocalDummy(owner: Symbol): TermSymbol = owner.newLocalDummy(noPosition)

def newWildcardSym(info: TypeBounds): Symbol =
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/scala/tools/nsc/tasty/bridge/FlagOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import scala.tools.nsc.tasty.TastyFlags
import TastyFlags._
import scala.tools.nsc.tasty.TastyUniverse

trait FlagOps extends TastyKernel { self: TastyUniverse =>
trait FlagOps { self: TastyUniverse =>

object FlagSets {
import symbolTable.Flag
Expand Down
Loading

0 comments on commit c32056f

Please sign in to comment.