Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backports to 3.1.x #546

Merged
merged 36 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
5229109
Update commons-io to 2.13.0
scala-center-steward[bot] Jun 8, 2023
604eb70
Update scala-compiler, scala-library, ... to 2.12.18
scala-center-steward[bot] Jun 8, 2023
c5c186b
Update scala-compiler, scala-library, ... to 2.13.11
scala-center-steward[bot] Jun 8, 2023
8c5c6c1
Bump to 2.12.18, 2.13.11 and 3.3.0
adpi2 Jun 14, 2023
0d78c70
Reduce verbosity of DebugTestSuite
adpi2 Jun 14, 2023
04855fe
Refactor ScalaEvaluationTests
adpi2 Jun 14, 2023
65af72e
Fix formatting by dropping 2.12.10 support
adpi2 Jun 14, 2023
39a5f66
Update scala-collection-compat to 2.11.0
scala-center-steward[bot] Jun 16, 2023
666a5ad
Update coursier, coursier-jvm to 2.1.5
scala-center-steward[bot] Jun 20, 2023
fc042ba
Fix finding symbol of default values
adpi2 Jul 4, 2023
9b9f3fd
Update tasty-query to 0.8.4
scala-center-steward[bot] Jun 23, 2023
0b3e7ca
add test
adpi2 Jul 14, 2023
8913d32
Add support for -language:strictEquality
adpi2 Jul 14, 2023
39e2a69
Fix evaluation of value classes in Scala 3
adpi2 Jul 14, 2023
4879b29
added -g javac option & updated bin/scalafmt
adpi2 Aug 2, 2023
985f68b
allowed -g option suppression
iusildra Jul 17, 2023
4d8445e
fix
iusildra Jul 17, 2023
1734d1b
removed useless
iusildra Jul 17, 2023
69571e3
added scala-collection-compat to expression compiler
adpi2 Aug 2, 2023
00a6a68
added test
iusildra Jul 17, 2023
567cf58
changed setting name
iusildra Jul 17, 2023
cc59fae
Fix #485: local $outer and public members from private subclass
adpi2 Jul 19, 2023
9808085
format and ObjectRef
adpi2 Jul 19, 2023
290c32b
no transform when inline
iusildra Jul 20, 2023
4b32894
inlined type instead of tree
iusildra Jul 20, 2023
90f876e
Update modules/expression-compiler/src/main/scala-3/dotty/tools/dotc/…
iusildra Jul 20, 2023
d59e4b6
allow step into in classes with special names
adpi2 Aug 2, 2023
56cad20
Apply suggested change
adpi2 Jul 25, 2023
cb56602
move test
adpi2 Jul 25, 2023
3e094b2
fix evaluation of static members
adpi2 Jul 28, 2023
1996afe
add ignore in Scala 2
adpi2 Jul 28, 2023
aa65f04
evaluate expression on tuple extractor
adpi2 Jul 28, 2023
a557707
Update commons-lang3 to 3.13.0
scala-center-steward[bot] Jul 29, 2023
ac1f3e2
Re-use hot filesystem to read sources
adpi2 Aug 1, 2023
9fb2076
Fix debug main class in test scope
adpi2 Aug 2, 2023
bf96dfa
ignore failing test
adpi2 Aug 2, 2023
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
Binary file modified bin/scalafmt
Binary file not shown.
12 changes: 6 additions & 6 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ lazy val javaDebug = project
autoScalaLibrary := false,
compile / javacOptions ++= Seq("-source", "1.8", "-target", "1.8"),
libraryDependencies ++= Seq(
"org.apache.commons" % "commons-lang3" % "3.12.0",
"org.apache.commons" % "commons-lang3" % "3.13.0",
"com.google.code.gson" % "gson" % "2.10.1",
"io.reactivex.rxjava2" % "rxjava" % "2.2.21",
"org.reactivestreams" % "reactive-streams" % "1.0.4",
"commons-io" % "commons-io" % "2.12.0",
"commons-io" % "commons-io" % "2.13.0",
"junit" % "junit" % "4.13.2" % Test,
"org.easymock" % "easymock" % "5.1.0" % Test,
"com.github.sbt" % "junit-interface" % "0.13.3" % Test
Expand Down Expand Up @@ -166,10 +166,10 @@ lazy val expressionCompiler = projectMatrix
crossScalaVersions ++= CrossVersion
.partialVersion(scalaVersion.value)
.collect {
case (2, 12) => Seq("2.12.17", "2.12.16", "2.12.15", "2.12.14", "2.12.13", "2.12.12", "2.12.11", "2.12.10")
case (2, 13) => Seq("2.13.10", "2.13.9", "2.13.8", "2.13.7", "2.13.6", "2.13.5", "2.13.4", "2.13.3")
case (2, 12) => Seq("2.12.18", "2.12.17", "2.12.16", "2.12.15", "2.12.14", "2.12.13", "2.12.12", "2.12.11")
case (2, 13) => Seq("2.13.11", "2.13.10", "2.13.9", "2.13.8", "2.13.7", "2.13.6", "2.13.5", "2.13.4", "2.13.3")
case (3, 0) => Seq("3.0.2", "3.0.1", "3.0.0")
case (3, _) => Seq("3.2.2", "3.2.1", "3.2.0", "3.1.3", "3.1.2", "3.1.1", "3.1.0")
case (3, _) => Seq("3.3.0", "3.2.2", "3.2.1", "3.2.0", "3.1.3", "3.1.2", "3.1.1", "3.1.0")
}
.toSeq
.flatten,
Expand Down Expand Up @@ -202,7 +202,7 @@ lazy val scala3StepFilter: Project = project
scalaVersion := Dependencies.scala31Plus,
Compile / doc / sources := Seq.empty,
libraryDependencies ++= Seq(
"ch.epfl.scala" %% "tasty-query" % "0.7.9",
"ch.epfl.scala" %% "tasty-query" % "0.8.4",
"org.scala-lang" %% "tasty-core" % scalaVersion.value,
Dependencies.munit % Test
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,13 @@ private class ClassEntryLookUp(

private object ClassEntryLookUp {
private[internal] def apply(entry: ClassEntry, logger: Logger): ClassEntryLookUp = {
val sourceFiles = entry.sourceEntries.flatMap(SourceEntryLookUp.getAllSourceFiles(_, logger))
ClassEntryLookUp(entry, sourceFiles, logger)
val sourceLookUps = entry.sourceEntries.flatMap(SourceEntryLookUp(_, logger))
ClassEntryLookUp(entry, sourceLookUps, logger)
}

def apply(
entry: ClassEntry,
sourceFiles: Seq[SourceFile],
sourceLookUps: Seq[SourceEntryLookUp],
logger: Logger
): ClassEntryLookUp = {
val classFiles = entry.classSystems.flatMap { classSystem =>
Expand All @@ -181,8 +181,9 @@ private object ClassEntryLookUp {
val classNameToClassFile =
classFiles.map(c => (c.fullyQualifiedName, c)).toMap

val sourceUriToSourceFile = sourceFiles.map(f => (f.uri, f)).toMap
val sourceNameToSourceFile = sourceFiles.groupBy(f => f.fileName)
val sourceFileToRoot = sourceLookUps.flatMap(l => l.sourceFiles.map(f => (f -> l.root))).toMap
val sourceUriToSourceFile = sourceLookUps.flatMap(_.sourceFiles).map(f => (f.uri, f)).toMap
val sourceNameToSourceFile = sourceLookUps.flatMap(_.sourceFiles).groupBy(f => f.fileName)

val classNameToSourceFile = mutable.Map[String, SourceFile]()
val sourceUriToClassFiles = mutable.Map[URI, Seq[ClassFile]]()
Expand Down Expand Up @@ -235,11 +236,11 @@ private object ClassEntryLookUp {
// so we try to find the right package declaration in each file
// it would be very unfortunate that 2 sources file with the same name
// declare the same package.
manySourceFiles.filter(s => findPackage(s, classFile.fullPackage, logger)) match {
case sourceFile :: Nil =>
recordSourceFile(sourceFile)
case _ =>
orphanClassFiles.append(classFile)
manySourceFiles.filter { f =>
findPackage(f, sourceFileToRoot(f), classFile.fullPackage, logger)
} match {
case sourceFile :: Nil => recordSourceFile(sourceFile)
case _ => orphanClassFiles.append(classFile)
}
}
}
Expand All @@ -249,6 +250,7 @@ private object ClassEntryLookUp {
if (orphanClassFiles.size > 0)
logger.debug(s"Found ${orphanClassFiles.size} orphan class files in ${entry.name}")

sourceLookUps.foreach(_.close())
new ClassEntryLookUp(
entry,
classNameToClassFile,
Expand Down Expand Up @@ -320,17 +322,13 @@ private object ClassEntryLookUp {
}
}

private def findPackage(
sourceFile: SourceFile,
fullPackage: String,
logger: Logger
): Boolean = {
private def findPackage(sourceFile: SourceFile, root: Path, fullPackage: String, logger: Logger): Boolean = {
// for "a.b.c" it returns Seq("a.b.c", "b.c", "c")
// so that we can match on "package a.b.c" or "package b.c" or "package c"
val nestedPackages = fullPackage.split('.').foldLeft(Seq.empty[String]) { (nestedParts, newPart) =>
nestedParts.map(outer => s"$outer.$newPart") :+ newPart
}
val sourceContent = readSourceContent(sourceFile, logger)
val sourceContent = readSourceContent(sourceFile, root, logger)
nestedPackages.exists { `package` =>
val quotedPackage = Regex.quote(`package`)
val matcher = s"package\\s+(object\\s+)?$quotedPackage(\\{|:|;|\\s+)".r
Expand All @@ -339,7 +337,13 @@ private object ClassEntryLookUp {
}

private def readSourceContent(sourceFile: SourceFile, logger: Logger): Option[String] = {
withinSourceEntry(sourceFile.entry) { root =>
withinSourceEntry(sourceFile.entry)(readSourceContent(sourceFile, _, logger))
.warnFailure(logger, s"Cannot read content of ${sourceFile.uri}")
.flatten
}

private def readSourceContent(sourceFile: SourceFile, root: Path, logger: Logger): Option[String] = {
Try {
val sourcePath = root.resolve(sourceFile.relativePath)
new String(Files.readAllBytes(sourcePath))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,16 @@ import scala.util.Failure
import scala.util.Success

private[debugadapter] object IO {
def withinJarFile[T](absolutePath: Path)(f: FileSystem => T): Try[T] = try {
def withinJarFile[T](absolutePath: Path)(f: FileSystem => T): Try[T] =
getJarFileSystem(absolutePath).map { fs =>
try f(fs)
finally fs.close()
}

def getJarFileSystem(absolutePath: Path): Try[FileSystem] = try {
val uri = URI.create(s"jar:${absolutePath.toUri}")
val fileSystem = FileSystems.newFileSystem(uri, new util.HashMap[String, Any])
try Success(f(fileSystem))
finally fileSystem.close()
Success(fileSystem)
} catch {
case NonFatal(exception) => Failure(exception)
case zipError: util.zip.ZipError => Failure(zipError)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import scala.jdk.CollectionConverters.*
import java.net.URI
import ch.epfl.scala.debugadapter.Logger
import ch.epfl.scala.debugadapter.internal.ScalaExtension.*
import scala.util.control.NonFatal

private case class SourceFile(
entry: SourceEntry,
Expand All @@ -22,20 +23,44 @@ private case class SourceFile(
def folderPath: String = relativePath.stripSuffix(s"/$fileName")
}

private case class SourceEntryLookUp(
entry: SourceEntry,
sourceFiles: Seq[SourceFile],
fileSystem: FileSystem,
root: Path
) {
def close(): Unit =
try
entry match {
case SourceJar(jar) => fileSystem.close()
case SourceDirectory(directory) => ()
case StandaloneSourceFile(absolutePath, relativePath) => ()
}
catch {
case NonFatal(_) => ()
}
}

private object SourceEntryLookUp {
def getAllSourceFiles(entry: SourceEntry, logger: Logger): Seq[SourceFile] = {
def apply(entry: SourceEntry, logger: Logger): Option[SourceEntryLookUp] = {
entry match {
case SourceJar(jar) =>
IO
.withinJarFile(jar) { fileSystem =>
getAllSourceFiles(entry, fileSystem, fileSystem.getPath("/")).toVector
IO.getJarFileSystem(jar)
.map { fs =>
val root = fs.getPath("/")
val sourceFiles = getAllSourceFiles(entry, fs, root).toVector
SourceEntryLookUp(entry, sourceFiles, fs, root)
}
.warnFailure(logger, s"Cannot list the source files in ${entry.name}")
.getOrElse(Vector.empty)
case SourceDirectory(directory) =>
getAllSourceFiles(entry, FileSystems.getDefault, directory).toSeq
val fs = FileSystems.getDefault
val sourceFiles = getAllSourceFiles(entry, fs, directory).toVector
Some(SourceEntryLookUp(entry, sourceFiles, fs, directory))
case StandaloneSourceFile(absolutePath, relativePath) =>
Seq(SourceFile(entry, relativePath, absolutePath.toUri))
val fs = FileSystems.getDefault
val sourceFile = SourceFile(entry, relativePath, absolutePath.toUri)
val root = fs.getPath(sourceFile.folderPath)
Some(SourceEntryLookUp(entry, Seq(sourceFile), FileSystems.getDefault, root))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,14 @@ private[debugadapter] object SourceLookUpProvider {

def apply(entries: Seq[ClassEntry], logger: Logger): SourceLookUpProvider = {
val parrallelEntries = ParVector(entries*)
val sourceFilesByEntry = parrallelEntries
.flatMap(_.sourceEntries)
.distinct
.map(entry => entry -> SourceEntryLookUp.getAllSourceFiles(entry, logger))
.toMap
val sourceLookUps =
parrallelEntries
.flatMap(_.sourceEntries)
.distinct
.map(entry => entry -> SourceEntryLookUp(entry, logger))
.toMap
val allLookUps = parrallelEntries
.map(entry => ClassEntryLookUp(entry, entry.sourceEntries.flatMap(sourceFilesByEntry.apply), logger))
.map(entry => ClassEntryLookUp(entry, entry.sourceEntries.flatMap(sourceLookUps.apply), logger))
.seq
val sourceUriToClassPathEntry = allLookUps
.flatMap(lookup => lookup.sources.map(uri => (uri, lookup)))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package ch.epfl.scala.debugadapter.internal.stepfilter

import com.sun.jdi
import ch.epfl.scala.debugadapter.internal.scalasig._
import ch.epfl.scala.debugadapter.internal.SourceLookUpProvider
import ch.epfl.scala.debugadapter.internal.scalasig.ScalaSigPrinter
import ch.epfl.scala.debugadapter.Logger
import ch.epfl.scala.debugadapter.ScalaVersion
import ch.epfl.scala.debugadapter.internal.SourceLookUpProvider
import ch.epfl.scala.debugadapter.internal.scalasig.ScalaSigPrinter
import ch.epfl.scala.debugadapter.internal.scalasig._
import com.sun.jdi

import scala.jdk.CollectionConverters.*
import scala.util.matching.Regex

class Scala2StepFilter(
sourceLookUp: SourceLookUpProvider,
Expand Down Expand Up @@ -122,12 +124,11 @@ class Scala2StepFilter(
// TODO try use tryEncode
getOwners(scalaClass)
.foldRight(Option(javaClass.name)) { (sym, acc) =>
for (javaName <- acc if javaName.contains(sym.name)) yield {
javaName
.split(sym.name)
for (javaName <- acc if javaName.contains(sym.name))
yield javaName
.split(Regex.quote(sym.name))
.drop(1)
.mkString(sym.name)
}
}
.exists { remainder =>
remainder.forall(c => c.isDigit || c == '$')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import dotty.tools.dotc.util.Property.*
enum EvaluationStrategy:
case This(cls: ClassSymbol)
case Outer(outerCls: ClassSymbol)
case LocalOuter(outerCls: ClassSymbol) // the $outer param in a constructor
case LocalValue(variable: TermSymbol, isByName: Boolean)
case LocalValueAssign(variable: TermSymbol)
case MethodCapture(variable: TermSymbol, method: TermSymbol, isByName: Boolean)
Expand Down
Loading
Loading