Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

TASTy Reader: support Scala 3.4 [ci: last-only]#10670

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
SethTisue merged 19 commits intoscala:2.13.xfromscalacenter:tasty/support-scala-3.4
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
Show all changes
19 commits
Select commitHold shift + click to select a range
f0a484b
prepare for syntax changes in Scala 3.4.0
bishaboshaJan 22, 2024
d3e7895
Upgrade tasty format, copy new tasty config
bishaboshaJan 22, 2024
a565f9a
enable pipelined compilation against Scala 3
bishaboshaJan 23, 2024
95900a6
support Java enum from TASTy
bishaboshaJan 24, 2024
9d37a96
support varargs and fields
bishaboshaJan 24, 2024
c09a900
support erasure of java arrays
bishaboshaJan 24, 2024
bd5b335
support Java fields
bishaboshaJan 31, 2024
0bd266c
support java interfaces
bishaboshaFeb 2, 2024
19ea949
support java annotations
bishaboshaFeb 2, 2024
abcb8ee
add test for deprecation
bishaboshaFeb 5, 2024
8cb3eff
support inner class selection
bishaboshaFeb 5, 2024
0cc7d73
workaround TASTy selection of inner class
bishaboshaFeb 5, 2024
a18de29
test parameterised types and bounds
bishaboshaFeb 6, 2024
c00adb8
improved inner class selection
bishaboshaFeb 6, 2024
6b2c4ae
tweak symbolops error message
bishaboshaFeb 12, 2024
e623261
deterministic loading of TASTy
bishaboshaJan 31, 2024
b0c8120
test annotations on types
bishaboshaFeb 7, 2024
fa4c3df
add filtering by jvm version in TastyTest
bishaboshaFeb 8, 2024
bfed4df
move isJava to Context
bishaboshaFeb 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
improved inner class selection
  • Loading branch information
@bishabosha
bishabosha committedFeb 12, 2024
commitc00adb8790e2db0a88e0561fc182a2df1d103e7e
27 changes: 19 additions & 8 deletionssrc/compiler/scala/tools/nsc/tasty/bridge/SymbolOps.scala
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -167,12 +167,18 @@ trait SymbolOps { self: TastyUniverse =>
}
}
if (isSymbol(member) && hasType(member)) member
else if (isJava &&tname.isTypeName &&space.typeSymbol.isStatic && !space.typeSymbol.isPackageClass) {
else if (isJava && space.termSymbol.isModule && !space.termSymbol.hasPackageFlag) {
// TODO [tasty]: remove this workaround for https://github.com/lampepfl/dotty/issues/19619
// Java (and Scala's Java parser) do not allow shadowing of static/nonstatic classes,
// so we can look in the companion for the non-static inner class (defined in the same TASTy file).
// Use heuristic that we are accidentally looking in the static scope for some class/object,
// when really we should be looking in the instance scope. In this case, we should be always looking for
// the class and not the object, so we convert to type name and look in the companion.
//
// we have the added bonus that we are looking for an inner class defined in the same TASTy file,
// so there should be no cross-file issues.
val space0 = space.typeSymbol.companionClass.typeOfThis
val secondTry = lookupSymbol(space0, tname, isJava)
val tname0 = tname.toTypeName

val secondTry = lookupSymbol(space0, tname0, isJava)
if (secondTry.isClass) secondTry // avoid type parameters
else errorMissing(space0, tname)
}
Expand All@@ -186,14 +192,19 @@ trait SymbolOps { self: TastyUniverse =>
private def errorMissing[T](space: Type, tname: TastyName)(implicit ctx: Context) = {
val kind = if (tname.isTypeName) "type" else "term"
def typeToString(tpe: Type) = {
def isPath(pre: Type) =
pre.isInstanceOf[u.SingletonType] || pre.termSymbol.isModule || pre.typeSymbol.isModuleClass
def inner(sb: StringBuilder, tpe: Type): StringBuilder = tpe match {
case u.ThisType(cls) => sb append cls.fullNameString
case u.ThisType(cls) =>
val isPackage = cls.hasPackageFlag
sb append cls.fullNameString append (if (isPackage) "" else ".this")
case u.SingleType(pre, sym) =>
if ((pre eq u.NoPrefix) || (pre eq u.NoType)) sb append sym.nameString
else inner(sb, pre) append '.' append sym.nameString
if ((pre eq u.NoPrefix) || (pre eq u.NoType)) sb append sym.nameString append ".type"
else inner(sb, pre) append '.' append sym.nameString append ".type"
case u.TypeRef(pre, sym, _) =>
val sep = if (isPath(pre)) "." else "#"
if ((pre eq u.NoPrefix) || (pre eq u.NoType)) sb append sym.nameString
else inner(sb, pre) append'.' append sym.nameString
else inner(sb, pre) appendsep append sym.nameString
case tpe => sb append tpe
}
inner(new StringBuilder(), tpe).toString
Expand Down
21 changes: 12 additions & 9 deletionssrc/compiler/scala/tools/nsc/tasty/bridge/TypeOps.scala
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -333,17 +333,20 @@ trait TypeOps { self: TastyUniverse =>
binder.asInstanceOf[LambdaType].lambdaParams(idx).ref

def NamedType(prefix: Type, sym: Symbol, isJava: Boolean): Type = {
if (sym.isType) {
if (isJava && sym.isClass && sym.isJavaDefined) {
def processInner(tp: Type): Type = tp match {
case u.TypeRef(pre, sym, args) if !sym.isStatic => u.typeRef(processInner(pre.widen), sym, args)
case _ => tp
}
prefix match {
case pre: u.TypeRef => processInner(u.typeRef(prefix, sym, Nil)) // e.g. prefix is `Foo[Int]`
case _ => processInner(sym.tpeHK) // ignore prefix otherwise
}
}
else if (sym.isType) {
prefix match {
case tp: u.ThisType if !sym.isTypeParameter => u.typeRef(prefix, sym, Nil)
case _:u.SingleType | _:u.RefinedType =>
if (isJava && !sym.isStatic && sym.isClass) {
// TODO [tasty]: remove this workaround for https://github.com/lampepfl/dotty/issues/19619
// for a non-static Java inner class `sym`, you can directly reference it.
u.appliedType(sym, Nil)
}
else u.typeRef(prefix, sym, Nil)
case pre: u.TypeRef if isJava && pre.sym.isType => u.typeRef(prefix, sym, Nil) // Foo[Int]#Bar[Long] in Java
case _:u.SingleType | _:u.RefinedType => u.typeRef(prefix, sym, Nil)
case _ => u.appliedType(sym, Nil)
}
}
Expand Down
6 changes: 6 additions & 0 deletionssrc/tastytest/scala/tools/tastytest/Files.scala
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -71,6 +71,12 @@ object Files {
}
}

def filterByNames(names: Set[String])(elem: String): Boolean = {
val path = JPaths.get(elem)
val name = path.getFileName.toString
names.contains(name)
}

def processLines[A](file: String)(op: ju.stream.Stream[String] => A): A = {
var stream: java.util.stream.Stream[String] = null
try {
Expand Down
4 changes: 4 additions & 0 deletionssrc/tastytest/scala/tools/tastytest/SourceKind.scala
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -27,6 +27,10 @@ object SourceKind {
case object Java extends SourceKind(".java")()
case object TastyFile extends SourceKind(".tasty")()

case class ExactFiles(names: String*) extends SourceKind("")(filter = Files.filterByNames(names.toSet)) {
override def fileOf(name: String) = names.find(_.startsWith(name)).getOrElse("")
}

def filterByKind(kinds: Set[SourceKind], paths: String*): Seq[String] =
if (kinds.isEmpty) Nil
else paths.filter(kinds.foldLeft(NoSource.filter)((filter, kind) => p => kind.filter(p) || filter(p)))
Expand Down
12 changes: 7 additions & 5 deletionssrc/tastytest/scala/tools/tastytest/TastyTest.scala
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -66,17 +66,18 @@ object TastyTest {
* e.g. `out/tastytest/TestFoo.class` should be compiled from a corresponding file
* `src-2/tastytest/TestFoo.scala`. Use `out:out-classes` as the classpath.
*/
def runPipelinedSuite(src: String, srcRoot: String, pkgName: String, outDirs: Option[(String, String, String)], additionalSettings: Seq[String], additionalDottySettings: Seq[String])(implicit cl: Dotc.ClassLoader): Try[Unit] = for {
def runPipelinedSuite(src: String, srcRoot: String, pkgName: String, outDirs: Option[(String, String, String)], additionalSettings: Seq[String], additionalDottySettings: Seq[String], testFilter: Option[SourceKind] = None)(implicit cl: Dotc.ClassLoader): Try[Unit] = for {
(src2, src3) <- get2And3Sources(srcRoot/src, src2Filters = Set(Scala), src3Filters = Set(Scala, Java))
case ((out, outJ), outCls) <- outDirs.fold(tempDir(pkgName) <*> tempDir(pkgName) <*> tempDir(pkgName))(p => dir(p._1) <*> dir(p._2) <*> dir(p._3))
tastyJar = outJ/"java-tasty.jar"
_ <- dotcPos(outCls, sourceRoot=srcRoot/src/"src-3", pipelineDottyOpts(tastyJar) ++: additionalDottySettings, src3:_*)
allOuts <- getFiles(outCls)
relTastys <- relativize(outCls, filterByKind(Set(TastyFile), allOuts:_*):_*)
_ <- copyAll(relTastys, outCls, out)
_ <- scalacPos(out, tastyJar, individualCapable=true, sourceRoot=srcRoot/src/"src-2", additionalSettings, src2:_*)
src2Filtered = testFilter.fold(src2)(kind => filterByKind(Set(kind), src2:_*))
_ <- scalacPos(out, tastyJar, individualCapable=true, sourceRoot=srcRoot/src/"src-2", additionalSettings, src2Filtered:_*)
_ <- javacPos(outCls, sourceRoot=srcRoot/src/"src-3", filterByKind(Set(Java), src3:_*):_*)
testNames <- visibleClasses(out, pkgName,src2:_*)
testNames <- visibleClasses(out, pkgName,src2Filtered:_*)
_ <- runMainOn(classpath(out, outCls), testNames:_*)
} yield ()

Expand DownExpand Up@@ -128,15 +129,16 @@ object TastyTest {
* - If `FOO_fail.scala` has a corresponding `FOO_pre.scala` file, then that is compiled first to `out`,
* so that `FOO_fail.scala` may depend on its compilation results.
*/
def negPipelinedSuite(src: String, srcRoot: String, pkgName: String, outDirs: Option[(String, String, String)], additionalSettings: Seq[String], additionalDottySettings: Seq[String])(implicit cl: Dotc.ClassLoader): Try[Unit] = for {
def negPipelinedSuite(src: String, srcRoot: String, pkgName: String, outDirs: Option[(String, String, String)], additionalSettings: Seq[String], additionalDottySettings: Seq[String], testFilter: Option[SourceKind] = None)(implicit cl: Dotc.ClassLoader): Try[Unit] = for {
(src2, src3) <- get2And3Sources(srcRoot/src, src2Filters = Set(Scala, Check, SkipCheck), src3Filters = Set(Scala, Java))
case ((out, outJ), outCls) <- outDirs.fold(tempDir(pkgName) <*> tempDir(pkgName) <*> tempDir(pkgName))(p => dir(p._1) <*> dir(p._2) <*> dir(p._3))
tastyJar = outJ/"java-tasty.jar"
_ <- dotcPos(outCls, sourceRoot=srcRoot/src/"src-3", pipelineDottyOpts(tastyJar) ++: additionalDottySettings, src3:_*)
allOuts <- getFiles(outCls)
relTastys <- relativize(outCls, filterByKind(Set(TastyFile), allOuts:_*):_*)
_ <- copyAll(relTastys, outCls, out)
_ <- scalacNeg(out, tastyJar, additionalSettings, src2:_*)
src2Filtered = testFilter.fold(src2)(kind => filterByKind(Set(kind, Check, SkipCheck), src2:_*))
_ <- scalacNeg(out, tastyJar, additionalSettings, src2Filtered:_*)
} yield ()

/**Simulates a Scala 3 application that depends on a Scala 2 library, where the Scala 2
Expand Down
13 changes: 13 additions & 0 deletionstest/tasty/neg-move-macros/pre-a/Macros.scala
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
package tastytest

import scala.util.Random
import scala.reflect.macros.blackbox.Context

object Macros {
def posImpl(c: Context): c.Expr[Position] = {
import c.universe._
val fileName = c.enclosingPosition.source.path.split('/').last
val line = c.enclosingPosition.line
c.Expr(q"new Position($fileName, $line)")
}
}
16 changes: 0 additions & 16 deletionstest/tasty/neg-move-macros/pre-a/package.scala
View file
Open in desktop

This file was deleted.

13 changes: 13 additions & 0 deletionstest/tasty/neg-move-macros/pre-b/Macros.scala
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
package tastytest

import scala.util.Random
// import scala.reflect.macros.blackbox.Context

object Macros {
// def posImpl(c: Context): c.Expr[Position] = {
// import c.universe._
// val fileName = c.enclosingPosition.source.path.split('/').last
// val line = c.enclosingPosition.line
// c.Expr(q"new Position($fileName, $line)")
// }
}
9 changes: 0 additions & 9 deletionstest/tasty/neg-move-macros/pre-b/package.scala
View file
Open in desktop

This file was deleted.

2 changes: 1 addition & 1 deletiontest/tasty/neg-move-macros/src-2/TestMacroCompat.check
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
TestMacroCompat_fail.scala:7: error: can't find term required by object tastytest.MacroCompat: tastytest.package.Macros.posImpl; perhaps it is missing from the classpath.
TestMacroCompat_fail.scala:7: error: can't find term required by object tastytest.MacroCompat: tastytest.Macros.posImpl; perhaps it is missing from the classpath.
val result = MacroCompat.testCase("foo")(pos)
^
1 error
22 changes: 22 additions & 0 deletionstest/tasty/neg-pipelined/src-2/tastytest/TestRawTypes.check
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
TestRawTypes_fail.scala:15: error: type mismatch;
found : lib.RawTypes#C[String]#D[String]
required: lib.RawTypes#C[T]#D[_]
Note: String <: Object, but Java-defined class D is invariant in type U.
You may wish to investigate a wildcard type such as `_ <: Object`. (SLS 3.2.10)
RawTypes.mii_Raw_Raw(cd_ii) // error
^
TestRawTypes_fail.scala:16: error: type mismatch;
found : lib.RawTypes#C[String]#D[String]#E[String]
required: lib.RawTypes#C[T]#D[U]#E[_]
Note: String <: Object, but Java-defined class E is invariant in type V.
You may wish to investigate a wildcard type such as `_ <: Object`. (SLS 3.2.10)
RawTypes.miii_Raw_Raw_Raw(cde_iii) // error
^
TestRawTypes_fail.scala:18: error: type mismatch;
found : lib.RawTypes.CStatic[String]#D[String]
required: lib.RawTypes.CStatic[T]#D[_]
Note: String <: Object, but Java-defined class D is invariant in type U.
You may wish to investigate a wildcard type such as `_ <: Object`. (SLS 3.2.10)
RawTypes.msi_Raw_Raw(cd_si) // error
^
3 errors
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
package tastytest

import lib.RawTypes

object TestRawTypes extends scala.App {
val rt: RawTypes = new RawTypes()
val c: RawTypes#C[String] = new rt.C[String]()

val cd_ii: RawTypes#C[String]#D[String] = new c.D[String]()
val cde_iii: RawTypes#C[String]#D[String]#E[String] = new cd_ii.E[String]()

val c_s: RawTypes.CStatic[String] = new RawTypes.CStatic[String]()
val cd_si: RawTypes.CStatic[String]#D[String] = new c_s.D[String]()

RawTypes.mii_Raw_Raw(cd_ii) // error
RawTypes.miii_Raw_Raw_Raw(cde_iii) // error

RawTypes.msi_Raw_Raw(cd_si) // error
}
38 changes: 38 additions & 0 deletionstest/tasty/neg-pipelined/src-3/lib/RawTypes.java
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
package lib;

public class RawTypes {

public class C<T> {
public class D<U> {
public class E<V> {}
}
public static class DStatic<U> {}
}

public static class CStatic<T> {
public class D<U> {}
public static class DStatic<U> {}
}

public static void miii_Raw_Raw_Raw(C.D.E e) {}

public static void mii_Raw_Raw(C.D d) {}
public static void mis_Raw_Raw(C.DStatic d) {}
public static void msi_Raw_Raw(CStatic.D d) {}
public static void mss_Raw_Raw(CStatic.DStatic d) {}

// public static void mii_Raw_Gen(C.D<String> d) {} // illegal
public static void mis_Raw_Gen(C.DStatic<String> d) {}
// public static void msi_Raw_Gen(CStatic.D<String> d) {} // illegal
public static void mss_Raw_Gen(CStatic.DStatic<String> d) {}

// public static void mii_Gen_Raw(C<String>.D d) {} // illegal
// public static void mis_Gen_Raw(C<String>.DStatic d) {} // illegal
// public static void msi_Gen_Raw(CStatic<String>.D d) {} // illegal
// public static void mss_Gen_Raw(CStatic<String>.DStatic d) {} // illegal

public static void mii_Gen_Gen(C<String>.D<String> d) {}
// public static void mis_Gen_Gen(C<String>.DStatic<String> d) {} // illegal
public static void msi_Gen_Gen(CStatic<String>.D<String> d) {}
// public static void mss_Gen_Gen(CStatic<String>.DStatic<String> d) {} // illegal
}
30 changes: 30 additions & 0 deletionstest/tasty/run-pipelined/src-2/tastytest/TestRawTypes.scala
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
package tastytest

import lib.RawTypes

object TestRawTypes extends scala.App {
val rt: RawTypes = new RawTypes()
val c: RawTypes#C[String] = new rt.C[String]()

val cd_ii: RawTypes#C[String]#D[String] = new c.D[String]()
val cde_iii: RawTypes#C[String]#D[String]#E[String] = new cd_ii.E[String]()

lazy val cd_is = new rt.C.DStatic[String]() // lazy because this fails at runtime even when reading from a classfile

val cd_s: RawTypes.CStatic[String] = new RawTypes.CStatic[String]()
val cd_si: RawTypes.CStatic[String]#D[String] = new cd_s.D[String]()

val cd_ss: RawTypes.CStatic.DStatic[String] = new RawTypes.CStatic.DStatic[String]()

// RawTypes.mii_Raw_Raw(cd_ii) // fails due to wildcards, see neg-pipelined for error message
// RawTypes.miii_Raw_Raw_Raw(cde_iii) // fails due to wildcards, see neg-pipelined for error message

RawTypes.mss_Raw_Raw(cd_ss)
def foo1 = RawTypes.mis_Raw_Raw(cd_is) // lazy because this fails at runtime even when reading from a classfile

RawTypes.mss_Raw_Gen(cd_ss)
def foo2 = RawTypes.mis_Raw_Gen(cd_is) // lazy because this fails at runtime even when reading from a classfile

RawTypes.mii_Gen_Gen(cd_ii)
RawTypes.msi_Gen_Gen(cd_si)
}
38 changes: 38 additions & 0 deletionstest/tasty/run-pipelined/src-3/lib/RawTypes.java
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
package lib;

public class RawTypes {

public class C<T> {
public class D<U> {
public class E<V> {}
}
public static class DStatic<U> {}
}

public static class CStatic<T> {
public class D<U> {}
public static class DStatic<U> {}
}

public static void miii_Raw_Raw_Raw(C.D.E e) {}

public static void mii_Raw_Raw(C.D d) {}
public static void mis_Raw_Raw(C.DStatic d) {}
public static void msi_Raw_Raw(CStatic.D d) {}
public static void mss_Raw_Raw(CStatic.DStatic d) {}

// public static void mii_Raw_Gen(C.D<String> d) {} // illegal
public static void mis_Raw_Gen(C.DStatic<String> d) {}
// public static void msi_Raw_Gen(CStatic.D<String> d) {} // illegal
public static void mss_Raw_Gen(CStatic.DStatic<String> d) {}

// public static void mii_Gen_Raw(C<String>.D d) {} // illegal
// public static void mis_Gen_Raw(C<String>.DStatic d) {} // illegal
// public static void msi_Gen_Raw(CStatic<String>.D d) {} // illegal
// public static void mss_Gen_Raw(CStatic<String>.DStatic d) {} // illegal

public static void mii_Gen_Gen(C<String>.D<String> d) {}
// public static void mis_Gen_Gen(C<String>.DStatic<String> d) {} // illegal
public static void msi_Gen_Gen(CStatic<String>.D<String> d) {}
// public static void mss_Gen_Gen(CStatic<String>.DStatic<String> d) {} // illegal
}

[8]ページ先頭

©2009-2025 Movatter.jp