Skip to content

Commit bb7d646

Browse files
sjrdadpi2
authored andcommitted
Upgrade to tasty-query 0.11.0.
1 parent 74c85a8 commit bb7d646

File tree

4 files changed

+41
-29
lines changed

4 files changed

+41
-29
lines changed

build.sbt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,7 @@ lazy val unpickler3: Project = project
196196
scalaVersion := Dependencies.scala31Plus,
197197
Compile / doc / sources := Seq.empty,
198198
libraryDependencies ++= Seq(
199-
"ch.epfl.scala" %% "tasty-query" % "0.10.3",
200-
"org.scala-lang" %% "tasty-core" % scalaVersion.value,
199+
"ch.epfl.scala" %% "tasty-query" % "0.11.0",
201200
Dependencies.asm,
202201
Dependencies.asmUtil,
203202
Dependencies.munit % Test

modules/unpickler/src/main/scala/ch/epfl/scala/debugadapter/internal/stacktrace/Scala3Formatter.scala

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,10 @@ class Scala3Formatter(warnLogger: String => Unit, testMode: Boolean)(using Conte
8888
private def format(name: Name): String =
8989
def rec(name: Name): String = name match
9090
case DefaultGetterName(termName, num) => s"${termName.toString()}.<default ${num + 1}>"
91-
case TypeName(toTermName) => rec(toTermName)
91+
case name: TypeName => rec(name.toTermName)
9292
case SimpleName("$anonfun") => "<anon fun>"
9393
case SimpleName("$anon") => "<anon class>"
94+
case ObjectClassName(underlying) => rec(underlying)
9495
case _ => name.toString
9596
rec(name)
9697

@@ -113,7 +114,7 @@ class Scala3Formatter(warnLogger: String => Unit, testMode: Boolean)(using Conte
113114
else if t.isImplicit then "implicit "
114115
else ""
115116
s"($prefix$params)$sep$result"
116-
case t: TypeRef => formatPrefix(t.prefix) + t.name
117+
case t: TypeRef => formatPrefix(t.prefix) + format(t.name)
117118
case t: AppliedType if t.tycon.isFunction =>
118119
val args = t.args.init.map(format).mkString(", ")
119120
val result = format(t.args.last)
@@ -134,8 +135,6 @@ class Scala3Formatter(warnLogger: String => Unit, testMode: Boolean)(using Conte
134135
.map(format)
135136
.mkString(" " + t.tycon.asInstanceOf[TypeRef].name.toString + " ")
136137
operatorLikeTypeFormat
137-
case t: AppliedType if t.tycon.isRepeatedParam =>
138-
s"${format(t.args.head)}*"
139138
case t: AppliedType =>
140139
val tycon = format(t.tycon)
141140
val args = t.args.map(format).mkString(", ")
@@ -170,19 +169,22 @@ class Scala3Formatter(warnLogger: String => Unit, testMode: Boolean)(using Conte
170169
s"classOf[${format(t)}]"
171170
case v => v.toString
172171
case t: ByNameType => s"=> " + format(t.resultType)
172+
case t: RepeatedType => format(t.elemType) + "*"
173173
case t: TypeRefinement => format(t.parent) + " {...}"
174174
case t: RecType => format(t.parent)
175175
case _: WildcardTypeArg => "?"
176176
case t: TypeLambda =>
177177
val args = t.paramNames.map(t => t.toString).mkString(", ")
178178
val result = format(t.resultType)
179179
s"[$args] =>> $result"
180+
case t: NothingType => "Nothing"
181+
case t: AnyKindType => "AnyKind"
180182
case t @ (_: RecThis | _: SkolemType | _: SuperType | _: MatchType | _: CustomTransientGroundType |
181183
_: PackageRef) =>
182184
throwOrWarn(s"Cannot format type ${t.getClass.getName}")
183185
"<unsupported>"
184186

185-
private def formatPolymorphicFunction(t: TermType): String =
187+
private def formatPolymorphicFunction(t: TypeOrMethodic): String =
186188
t match
187189
case t: PolyType =>
188190
val args = t.paramNames.mkString(", ")
@@ -192,13 +194,16 @@ class Scala3Formatter(warnLogger: String => Unit, testMode: Boolean)(using Conte
192194
val params = t.paramTypes.map(format(_)).mkString(", ")
193195
if t.paramTypes.size > 1 then s"($params) => ${format(t.resultType)}"
194196
else s"$params => ${format(t.resultType)}"
197+
case t: Type =>
198+
// for exhaustivity
199+
format(t)
195200

196201
private def formatPrefix(p: Prefix): String =
197202
val prefix = p match
198203
case NoPrefix => ""
199204
case p: TermRef if isScalaPredef(p) => ""
200205
case p: TermRef if isPackageObject(p.name) => ""
201-
case p: TermRef => formatPrefix(p.prefix) + p.name
206+
case p: TermRef => formatPrefix(p.prefix) + format(p.name)
202207
case p: TermParamRef => p.paramName.toString
203208
case p: PackageRef => ""
204209
case p: ThisType => ""

modules/unpickler/src/main/scala/ch/epfl/scala/debugadapter/internal/stacktrace/Scala3Unpickler.scala

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package ch.epfl.scala.debugadapter.internal.stacktrace
33
import ch.epfl.scala.debugadapter.internal.binary
44
import ch.epfl.scala.debugadapter.internal.jdi.JdiMethod
55
import ch.epfl.scala.debugadapter.internal.stacktrace.*
6-
import tastyquery.Contexts
76
import tastyquery.Contexts.Context
87
import tastyquery.Names.*
98
import tastyquery.Signatures.*
@@ -29,7 +28,7 @@ class Scala3Unpickler(
2928
testMode: Boolean
3029
) extends ThrowOrWarn(warnLogger.accept, testMode):
3130
private val classpath = ClasspathLoaders.read(classpaths.toList)
32-
private given ctx: Context = Contexts.init(classpath)
31+
private given ctx: Context = Context.initialize(classpath)
3332
private val defn = new Definitions
3433
private[stacktrace] val formatter = new Scala3Formatter(warnLogger.accept, testMode)
3534

@@ -1001,8 +1000,8 @@ class Scala3Unpickler(
10011000
(!checkTypeErasure || matchTypeErasure(paramsSig, resSig, declaredParams, method.returnType))
10021001

10031002
private def matchTypeErasure(
1004-
scalaParams: Seq[FullyQualifiedName],
1005-
scalaReturnType: FullyQualifiedName,
1003+
scalaParams: Seq[SignatureName],
1004+
scalaReturnType: SignatureName,
10061005
javaParams: Seq[binary.Parameter],
10071006
javaReturnType: Option[binary.Type]
10081007
): Boolean =
@@ -1025,7 +1024,7 @@ class Scala3Unpickler(
10251024
)
10261025

10271026
private def matchType(
1028-
scalaType: FullyQualifiedName,
1027+
scalaType: SignatureName,
10291028
javaType: binary.Type
10301029
): Boolean =
10311030
def rec(scalaType: String, javaType: String): Boolean =
@@ -1059,4 +1058,12 @@ class Scala3Unpickler(
10591058
.get(scalaType)
10601059
.map(_ == javaType)
10611060
.getOrElse(regex.matches(javaType))
1062-
rec(scalaType.toString, javaType.name)
1061+
rec(signatureNameToString(scalaType), javaType.name)
1062+
1063+
private def signatureNameToString(sigName: SignatureName): String =
1064+
sigName.items
1065+
.map {
1066+
case ObjectClassName(underlying) => underlying
1067+
case name => name
1068+
}
1069+
.mkString(".")

modules/unpickler/src/main/scala/ch/epfl/scala/debugadapter/internal/stacktrace/extensions.scala

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@ extension (symbol: Symbol)
1818
def isAnonClass = symbol.nameStr == "$anon"
1919
def isLocal = symbol.owner.isTerm
2020
def isModuleClass = symbol.isClass && symbol.asClass.isModuleClass
21-
def nameStr = symbol.name.toString
21+
22+
def nameStr = symbol.name match
23+
case ObjectClassName(underlying) => underlying.toString()
24+
case ObjectClassTypeName(underlying) => underlying.toString()
25+
case name => name.toString()
26+
2227
def pos: SourcePosition = symbol.tree.map(_.pos).getOrElse(SourcePosition.NoPosition)
2328
def isInline = symbol.isTerm && symbol.asTerm.isInline
2429

@@ -58,7 +63,7 @@ extension [T <: BinarySymbol](xs: Seq[T])
5863

5964
extension (name: Name)
6065
def isPackageObject: Boolean =
61-
val nameStr = name.toString
66+
val nameStr = name.toString.stripSuffix("$")
6267
nameStr == "package" || nameStr.endsWith("$package")
6368

6469
extension (tpe: TermType) def isMethodic: Boolean = tpe.isInstanceOf[MethodicType]
@@ -97,11 +102,6 @@ extension (tpe: Type)
97102
isScalaPackage(ref.prefix) && ref.nameStr.startsWith("Tuple")
98103
case _ => false
99104

100-
def isRepeatedParam(using Context): Boolean =
101-
tpe match
102-
case ref: TypeRef => ref.optSymbol.exists(_ == ctx.defn.RepeatedParamClass)
103-
case _ => false
104-
105105
def isOperatorLike: Boolean =
106106
tpe match
107107
case ref: TypeRef =>
@@ -113,17 +113,18 @@ extension (tpe: Type)
113113
extension (tpe: NamedType) def nameStr: String = tpe.name.toString
114114

115115
extension (tpe: TypeOrWildcard)
116-
def erasedAsReturnType(using Context): FullyQualifiedName = erased(isReturnType = true)
117-
def erasedAsArgType(asJavaVarargs: Boolean = false)(using Context): FullyQualifiedName =
116+
def erasedAsReturnType(using Context): SignatureName = erased(isReturnType = true)
117+
def erasedAsArgType(asJavaVarargs: Boolean = false)(using Context): SignatureName =
118118
tpe match
119-
case t: AppliedType if t.tycon.isRepeatedParam && asJavaVarargs =>
120-
AppliedType(TypeRef(ctx.defn.scalaPackage.packageRef, ctx.defn.ArrayClass), t.args).erased(isReturnType = false)
119+
case tpe: RepeatedType if asJavaVarargs =>
120+
ctx.defn.ArrayTypeOf(tpe.elemType).erased(isReturnType = false)
121121
case _ => tpe.erased(isReturnType = false)
122122

123-
private def erased(isReturnType: Boolean)(using Context): FullyQualifiedName =
124-
tpe match
125-
case tpe: Type => ErasedTypeRef.erase(tpe, SourceLanguage.Scala3, keepUnit = isReturnType).toSigFullName
126-
case _: WildcardTypeArg => ctx.defn.ObjectClass.fullName
123+
private def erased(isReturnType: Boolean)(using Context): SignatureName =
124+
val tpe1 = tpe match
125+
case tpe: Type => tpe
126+
case _: WildcardTypeArg => ctx.defn.ObjectType
127+
ErasedTypeRef.erase(tpe1, SourceLanguage.Scala3, keepUnit = isReturnType).toSigFullName
127128

128129
extension (ref: TermRef)
129130
def isScalaPredef: Boolean =

0 commit comments

Comments
 (0)