Skip to content

Commit 33c5016

Browse files
authored
Merge pull request #74 from scalacenter/tasty/cleanup
Refactor, enable dotty compiled java enums
2 parents 65fab70 + 1941191 commit 33c5016

26 files changed

+434
-1171
lines changed

README.md

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,3 @@
1-
# TASTy Reader For Scala 2
2-
3-
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)
4-
5-
## Testing
6-
7-
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)
8-
9-
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.
10-
11-
`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>`
12-
13-
Individual tasks exist to help debug issues:
14-
15-
- `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.
16-
- `tasty/dotcd <filename> <arg>*` to decompile a tasty file with the supported version of dotty. Can pass additional flags.
17-
- `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.
18-
- `tasty/runDotty <classpath> <classname>` to execute a main method with the dotty library added to the given classpath.
19-
20-
## Notes
21-
22-
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.
23-
241
# Welcome!
252

263
This is the official repository for the [Scala Programming Language](http://www.scala-lang.org)

doc/internal/tastyreader.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# TASTy Reader For Scala 2
2+
3+
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.
4+
5+
## Testing
6+
7+
The framework for testing TASTy reader is contained in the `tastytest` subproject. A description of its functionality is provided at [tastytest.md](tastytest.md)
8+
9+
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`.
10+
11+
Individual tasks exist to help debug issues:
12+
13+
- `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.
14+
- `tasty/dotcd <filename> <arg>*` to decompile a tasty file with the supported version of dotty. Can pass additional flags.
15+
- `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.
16+
- `tasty/runDotty <classpath> <classname>` to execute a main method with the dotty library added to the given classpath.
17+
18+
## Notes
19+
20+
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.

doc/internal/tastytest.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# TASTy Test
22

3-
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.
3+
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.
44

55
## `run`
66
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:
@@ -24,12 +24,6 @@ A `neg` suite asserts which Scala 2 code is not compatible with code compiled wi
2424
- 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.
2525
- If an expected fail case compiles successfully, collect it in the list of failures.
2626

27-
## `neg-false`
28-
A `neg-false` test runs identically to a `neg` test, but asserts that a test is a false positive.
29-
30-
## `pos-false`
31-
A `pos-false` test runs identically to a `pos` test, but asserts that a test is a false positive.
32-
3327
## General Notes
3428
- In each suite, the dotty library is available to all test sources.
3529
- 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.

src/compiler/scala/tools/nsc/tasty/CommentUnpickler.scala

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/compiler/scala/tools/nsc/tasty/Names.scala

Lines changed: 0 additions & 159 deletions
This file was deleted.

src/compiler/scala/tools/nsc/tasty/PositionUnpickler.scala

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/compiler/scala/tools/nsc/tasty/ScalacUnpickler.scala

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package scala.tools.nsc.tasty
22

33
import TastyUnpickler.SectionUnpickler
44
import TastyRefs.NameRef
5-
import Names.TastyName
65

76
import scala.reflect.io.AbstractFile
87
import scala.util.control.NonFatal
@@ -12,7 +11,7 @@ object ScalacUnpickler {
1211
final class TreeSectionUnpickler[Tasty <: TastyUniverse](implicit tasty: Tasty)
1312
extends SectionUnpickler[TreeUnpickler[Tasty]]("ASTs") { self =>
1413
def unpickle(reader: TastyReader, nameAtRef: NameRef => TastyName ): TreeUnpickler[Tasty] =
15-
new TreeUnpickler(reader, nameAtRef, None, None, Seq.empty)
14+
new TreeUnpickler(reader, nameAtRef, Seq.empty)
1615
}
1716

1817
object Unpickler {
@@ -38,9 +37,7 @@ object ScalacUnpickler {
3837

3938
val treeUnpickler = unpickler.unpickle[TreeUnpickler[tasty.type]](new TreeSectionUnpickler()(tasty)).get
4039

41-
implicit val ctx: Context = {
42-
new InitialContext(classRoot, mirrorThatLoaded(classRoot), AbstractFile.getFile(filename))
43-
}
40+
implicit val ctx: Context = new InitialContext(classRoot, AbstractFile.getFile(filename))
4441
treeUnpickler.enter(classRoot, moduleRoot)
4542
} catch {
4643
case NonFatal(ex) =>

src/compiler/scala/tools/nsc/tasty/TastyFlags.scala

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ object TastyFlags {
2121
final val SuperParamAlias: TastyFlagSet = Open.next
2222
final val maxFlag: Int = SuperParamAlias.shift
2323

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

2626
private[TastyFlags] def shift: Int = {
2727
var acc = 0
28-
var curr = flags
28+
var curr = toInt
2929
while (curr != 0) {
3030
acc += 1
3131
curr = curr >> 1
@@ -37,16 +37,16 @@ object TastyFlags {
3737
TastyFlagSet(1 << shift + 1)
3838
}
3939

40-
def toSingletonSets: SingletonSets = SingletonSets(flags)
41-
def |(other: TastyFlagSet): TastyFlagSet = TastyFlagSet(flags | other.flags)
42-
def &(mask: TastyFlagSet): TastyFlagSet = TastyFlagSet(flags & mask.flags)
43-
def &~(mask: TastyFlagSet): TastyFlagSet = TastyFlagSet(flags & ~mask.flags)
44-
def unary_! : Boolean = this.flags == 0
40+
def toSingletonSets: SingletonSets = SingletonSets(toInt)
41+
def |(other: TastyFlagSet): TastyFlagSet = TastyFlagSet(toInt | other.toInt)
42+
def &(mask: TastyFlagSet): TastyFlagSet = TastyFlagSet(toInt & mask.toInt)
43+
def &~(mask: TastyFlagSet): TastyFlagSet = TastyFlagSet(toInt & ~mask.toInt)
44+
def unary_! : Boolean = this.toInt == 0
4545
def is(mask: TastyFlagSet): Boolean = (this & mask) == mask
4646
def isOneOf(mask: TastyFlagSet): Boolean = (this & mask).hasFlags
4747
def is(mask: TastyFlagSet, butNot: TastyFlagSet): Boolean = if (!butNot) is(mask) else is(mask) && not(butNot)
4848
def not(mask: TastyFlagSet): Boolean = !isOneOf(mask)
49-
def hasFlags: Boolean = this.flags != 0
49+
def hasFlags: Boolean = this.toInt != 0
5050

5151
def debug: String = {
5252
if (!this) {
@@ -75,13 +75,13 @@ object TastyFlags {
7575
}
7676
}
7777

78-
case class SingletonSets private[TastyFlags](private val set: Int) extends AnyVal {
78+
case class SingletonSets(val toInt: Int) extends AnyVal {
7979
def map[A](f: TastyFlagSet => A): Iterable[A] = {
8080
val buf = Iterable.newBuilder[A]
8181
var i = 0
8282
while (i <= maxFlag) {
8383
val flag = 1 << i
84-
if ((flag & set) != 0) {
84+
if ((flag & toInt) != 0) {
8585
buf += f(TastyFlagSet(flag))
8686
}
8787
i += 1

0 commit comments

Comments
 (0)