Skip to content

Commit

Permalink
Merge pull request #8 from adpi2/fix-metals-7115
Browse files Browse the repository at this point in the history
Cache decoding failure + update dependencies
  • Loading branch information
adpi2 authored Jan 14, 2025
2 parents 379361e + 87bbab2 commit 127ad4c
Show file tree
Hide file tree
Showing 13 changed files with 32 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = "3.8.1"
version = "3.8.4"
project.git = true
align.preset = none
align.stripMargin = true
Expand Down
10 changes: 5 additions & 5 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import sbt._

object Dependencies {
val scala3Next = "3.4.2"
val asmVersion = "9.7"
val coursierVersion = "2.1.10"
val scala3Next = "3.6.2"
val asmVersion = "9.7.1"
val coursierVersion = "2.1.24"

val tastyQuery = "ch.epfl.scala" %% "tasty-query" % "1.3.0"
val tastyQuery = "ch.epfl.scala" %% "tasty-query" % "1.4.0"
val asm = "org.ow2.asm" % "asm" % asmVersion
val asmUtil = "org.ow2.asm" % "asm-util" % asmVersion

// test dependencies
val munit = "org.scalameta" %% "munit" % "1.0.0"
val munit = "org.scalameta" %% "munit" % "1.0.4"
val coursier = ("io.get-coursier" %% "coursier" % coursierVersion).cross(CrossVersion.for3Use2_13)
val coursierJvm = ("io.get-coursier" %% "coursier-jvm" % coursierVersion).cross(CrossVersion.for3Use2_13)
}
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.10.0
sbt.version=1.10.7
4 changes: 2 additions & 2 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.5.12")
addSbtPlugin("org.scala-debugger" % "sbt-jdi-tools" % "1.1.1")
addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.9.2")
addSbtPlugin("com.github.sbt" % "sbt-jdi-tools" % "1.2.0")
3 changes: 1 addition & 2 deletions src/main/scala/ch/epfl/scala/decoder/binary/Symbol.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ trait Symbol:
def sourceLines: Option[SourceLines]
def sourceName: Option[String] = sourceLines.map(_.sourceName)

def showSpan: String =
sourceLines.map(_.showSpan).getOrElse("")
def showSpan: String = sourceLines.map(_.showSpan).getOrElse("")
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@ import tastyquery.Symbols.*
import ch.epfl.scala.decoder.*

import scala.collection.concurrent.TrieMap
import scala.util.Try

class CachedBinaryDecoder(using Context, ThrowOrWarn) extends BinaryDecoder:
private val classCache: TrieMap[String, DecodedClass] = TrieMap.empty
private val methodCache: TrieMap[(String, binary.SignedName), DecodedMethod] = TrieMap.empty
private val liftedTreesCache: TrieMap[Symbol, Seq[LiftedTree[?]]] = TrieMap.empty
// even failures can be quite expensive, so we cache them
private val classCache: TrieMap[String, Try[DecodedClass]] = TrieMap.empty
private val methodCache: TrieMap[(String, binary.SignedName), Try[DecodedMethod]] = TrieMap.empty
private val liftedTreesCache: TrieMap[Symbol, Try[Seq[LiftedTree[?]]]] = TrieMap.empty

override def decode(cls: binary.ClassType): DecodedClass =
classCache.getOrElseUpdate(cls.name, super.decode(cls))
classCache.getOrElseUpdate(cls.name, Try(super.decode(cls))).get

override def decode(method: binary.Method): DecodedMethod =
methodCache.getOrElseUpdate((method.declaringClass.name, method.signedName), super.decode(method))
methodCache.getOrElseUpdate((method.declaringClass.name, method.signedName), Try(super.decode(method))).get

override protected def collectAllLiftedTrees(owner: Symbol): Seq[LiftedTree[?]] =
liftedTreesCache.getOrElseUpdate(owner, super.collectAllLiftedTrees(owner))
liftedTreesCache.getOrElseUpdate(owner, Try(super.collectAllLiftedTrees(owner))).get
2 changes: 2 additions & 0 deletions src/main/scala/ch/epfl/scala/decoder/jdi/JdiClass.scala
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,5 @@ class JdiClass(ref: com.sun.jdi.ReferenceType) extends JdiType(ref) with ClassTy
override def sourceName: Option[String] = Option(ref.sourceName)

private def visibleMethods: Seq[JdiMethod] = ref.visibleMethods.asScala.map(JdiMethod(_)).toSeq

override def toString: String = ref.toString
2 changes: 2 additions & 0 deletions src/main/scala/ch/epfl/scala/decoder/jdi/JdiClassLoader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ import ch.epfl.scala.decoder.binary.BinaryClassLoader
class JdiClassLoader(classLoader: com.sun.jdi.ClassLoaderReference) extends BinaryClassLoader:
override def loadClass(name: String): JdiClass =
JdiClass(classLoader.visibleClasses.asScala.find(_.name == name).get)

override def toString = classLoader.toString
2 changes: 2 additions & 0 deletions src/main/scala/ch/epfl/scala/decoder/jdi/JdiField.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ class JdiField(field: com.sun.jdi.Field) extends Field:
override def name: String = field.name
override def sourceLines: Option[SourceLines] = None
override def `type`: Type = JdiType(field.`type`)

override def toString: String = field.toString
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ class JdiLocalVariable(localVariable: com.sun.jdi.LocalVariable) extends Paramet
override def name: String = localVariable.name
override def sourceLines: Option[SourceLines] = None
override def `type`: Type = JdiType(localVariable.`type`)

override def toString: String = localVariable.toString
2 changes: 2 additions & 0 deletions src/main/scala/ch/epfl/scala/decoder/jdi/JdiMethod.scala
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,5 @@ class JdiMethod(method: com.sun.jdi.Method) extends Method:
private def signature: String = method.signature

private def bytecodes: Array[Byte] = method.bytecodes

override def toString: String = method.toString
2 changes: 2 additions & 0 deletions src/main/scala/ch/epfl/scala/decoder/jdi/JdiType.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ import ch.epfl.scala.decoder.binary.*
class JdiType(tpe: com.sun.jdi.Type) extends Type:
override def name: String = tpe.name
override def sourceLines: Option[SourceLines] = None

override def toString: String = tpe.toString
2 changes: 2 additions & 0 deletions src/main/scala/ch/epfl/scala/decoder/jdi/JdiVariable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ class JdiVariable(variable: com.sun.jdi.LocalVariable, method: com.sun.jdi.Metho
override def name: String = variable.name
override def sourceLines: Option[SourceLines] = None
override def `type`: Type = JdiType(variable.`type`)

override def toString: String = variable.toString

0 comments on commit 127ad4c

Please sign in to comment.