Skip to content

Commit

Permalink
Merge pull request #632 from adpi2/scala34
Browse files Browse the repository at this point in the history
Add support for Scala 3.4
  • Loading branch information
adpi2 authored Jan 23, 2024
2 parents d52fa45 + c2a3225 commit 2cdc96a
Show file tree
Hide file tree
Showing 23 changed files with 127 additions and 81 deletions.
33 changes: 20 additions & 13 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ lazy val root = project
expressionCompiler212,
expressionCompiler213,
expressionCompiler30,
expressionCompiler3,
expressionCompiler33,
expressionCompiler34,
scala3StepFilter
)
.settings(
Expand Down Expand Up @@ -68,7 +69,7 @@ lazy val core213 = core.jvm(Dependencies.scala213)
lazy val core = projectMatrix
.in(file("modules/core"))
.jvmPlatform(
Seq(Dependencies.scala212, Dependencies.scala213, Dependencies.scala31Plus),
Seq(Dependencies.scala212, Dependencies.scala213, Dependencies.scala33),
Seq.empty,
p => p.dependsOn(javaDebug)
)
Expand All @@ -95,16 +96,17 @@ lazy val core = projectMatrix
BuildInfoKey.action("scala212")(Dependencies.scala212),
BuildInfoKey.action("scala213")(Dependencies.scala213),
BuildInfoKey.action("scala30")(Dependencies.scala30),
BuildInfoKey.action("scala31Plus")(Dependencies.scala31Plus)
BuildInfoKey.action("scala33")(Dependencies.scala33),
BuildInfoKey.action("scala34")(Dependencies.scala34)
),
buildInfoPackage := "ch.epfl.scala.debugadapter"
)

lazy val tests212 = tests.jvm(Dependencies.scala212)
lazy val tests3 = tests.jvm(Dependencies.scala31Plus)
lazy val tests3 = tests.jvm(Dependencies.scala33)
lazy val tests = projectMatrix
.in(file("modules/tests"))
.jvmPlatform(scalaVersions = Seq(Dependencies.scala212, Dependencies.scala213, Dependencies.scala31Plus))
.jvmPlatform(scalaVersions = Seq(Dependencies.scala212, Dependencies.scala213, Dependencies.scala33))
.settings(
name := "scala-debug-adapter-test",
libraryDependencies ++= Seq(
Expand All @@ -124,8 +126,8 @@ lazy val tests = projectMatrix
.dependsOn(
expressionCompiler212 / publishLocal,
expressionCompiler213 / publishLocal,
expressionCompiler30 / publishLocal,
expressionCompiler3 / publishLocal,
expressionCompiler33 / publishLocal,
expressionCompiler34 / publishLocal,
// break cyclic reference
LocalProject("scala3StepFilter") / publishLocal
)
Expand Down Expand Up @@ -154,13 +156,15 @@ lazy val sbtPlugin = project
lazy val expressionCompiler212 = expressionCompiler.finder(scala212Axis)(true)
lazy val expressionCompiler213 = expressionCompiler.finder(scala213Axis)(true)
lazy val expressionCompiler30 = expressionCompiler.finder(scala30Axis)(true)
lazy val expressionCompiler3 = expressionCompiler.finder(scala3Axis)(true)
lazy val expressionCompiler33 = expressionCompiler.finder(scala33Axis)(true)
lazy val expressionCompiler34 = expressionCompiler.finder(scala34Axis)(true)
lazy val expressionCompiler = projectMatrix
.in(file("modules/expression-compiler"))
.customRow(true, Seq(scala212Axis, VirtualAxis.jvm), identity[Project] _)
.customRow(true, Seq(scala213Axis, VirtualAxis.jvm), identity[Project] _)
.customRow(true, Seq(scala30Axis, VirtualAxis.jvm), identity[Project] _)
.customRow(true, Seq(scala3Axis, VirtualAxis.jvm), identity[Project] _)
.customRow(true, Seq(scala33Axis, VirtualAxis.jvm), identity[Project] _)
.customRow(true, Seq(scala34Axis, VirtualAxis.jvm), identity[Project] _)
.settings(
name := "scala-expression-compiler",
crossScalaVersions ++= CrossVersion
Expand All @@ -169,7 +173,8 @@ lazy val expressionCompiler = projectMatrix
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.3.1", "3.3.0", "3.2.2", "3.2.1", "3.2.0", "3.1.3", "3.1.2", "3.1.1", "3.1.0")
case (3, 1 | 2 | 3) => Seq("3.3.1", "3.3.0", "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.4.0-RC2")
}
.toSeq
.flatten,
Expand All @@ -185,7 +190,8 @@ lazy val expressionCompiler = projectMatrix
val sourceDir = (Compile / sourceDirectory).value
CrossVersion.partialVersion(scalaVersion.value).collect {
case (3, 0) => sourceDir / s"scala-3.0"
case (3, minor) => sourceDir / s"scala-3.1+"
case (3, 1 | 2 | 3) => sourceDir / s"scala-3.3"
case (3, 4) => sourceDir / s"scala-3.4"
}
},
Compile / doc / sources := Seq.empty,
Expand All @@ -199,7 +205,7 @@ lazy val scala3StepFilter: Project = project
.dependsOn(tests3 % Test)
.settings(
name := "scala-debug-step-filter",
scalaVersion := Dependencies.scala31Plus,
scalaVersion := Dependencies.scala33,
Compile / doc / sources := Seq.empty,
libraryDependencies ++= Seq(
"ch.epfl.scala" %% "tasty-query" % "0.9.3",
Expand All @@ -221,7 +227,8 @@ lazy val scalacOptionsSetting = Def.settings(
lazy val scala212Axis = VirtualAxis.ScalaVersionAxis(Dependencies.scala212, "2_12")
lazy val scala213Axis = VirtualAxis.ScalaVersionAxis(Dependencies.scala213, "2_13")
lazy val scala30Axis = VirtualAxis.ScalaVersionAxis(Dependencies.scala30, "3_0")
lazy val scala3Axis = VirtualAxis.ScalaVersionAxis(Dependencies.scala31Plus, "3")
lazy val scala33Axis = VirtualAxis.ScalaVersionAxis(Dependencies.scala33, "3_3")
lazy val scala34Axis = VirtualAxis.ScalaVersionAxis(Dependencies.scala34, "3_4")

def onScalaVersion[T](scala212: T, scala213: T, scala3: T) = Def.setting {
CrossVersion.partialVersion(scalaVersion.value) match {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ case class ScalaVersion(value: String) {
def isScala3: Boolean = value.startsWith("3")
def isScala212: Boolean = value.startsWith("2.12")
def isScala213: Boolean = value.startsWith("2.13")
def isScala30: Boolean = value.startsWith("3.0")
def isScala31Plus: Boolean = value.startsWith("3") && !isScala30
def isScala33: Boolean = value.startsWith("3.3")

def binaryVersion: String = if (isScala3) "3" else if (isScala213) "2.13" else "2.12"
Expand All @@ -20,5 +18,6 @@ object ScalaVersion {
val `2.12` = ScalaVersion(BuildInfo.scala212)
val `2.13` = ScalaVersion(BuildInfo.scala213)
val `3.0` = ScalaVersion(BuildInfo.scala30)
val `3.1+` = ScalaVersion(BuildInfo.scala31Plus)
val `3.3` = ScalaVersion(BuildInfo.scala33)
val `3.4` = ScalaVersion(BuildInfo.scala34)
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ object DebugTools {
debuggee.libraries
.find(_.artifactId.startsWith("scala3-library"))
.map(lib => ScalaVersion(lib.version))
.getOrElse(ScalaVersion.`3.1+`)
.getOrElse(ScalaVersion.`3.3`)

def resolveCompilerClassLoader(scalaVersion: ScalaVersion): Option[ClassLoader] =
resolver
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package dotty.tools.dotc.evaluation

import dotty.tools.dotc.core.Contexts.Context
import dotty.tools.dotc.core.Symbols.Symbol

object SymUtils:
export dotty.tools.dotc.transform.SymUtils.{isLocal => _, enclosingMethodOrClass => _, *}

extension (self: Symbol) def isLocal(using Context) = dotty.tools.dotc.transform.SymUtils.isLocal(self)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package dotty.tools.dotc.evaluation

import dotty.tools.dotc.core.Contexts.Context
import dotty.tools.dotc.core.Symbols.Symbol

object SymUtils:
export dotty.tools.dotc.transform.SymUtils.{isLocal => _, enclosingMethodOrClass => _, *}

extension (self: Symbol) def isLocal(using Context) = dotty.tools.dotc.transform.SymUtils.isLocal(self)
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package dotty.tools.dotc

import dotty.tools.dotc.core.Contexts.Context
import dotty.tools.dotc.core.Phases.Phase
import dotty.tools.dotc.evaluation.*

class ExpressionCompiler(using ExpressionContext)(using Context) extends Compiler:

override protected def frontendPhases: List[List[Phase]] =
val parser :: others = super.frontendPhases: @unchecked
parser :: List(InsertExpression()) :: others

override protected def picklerPhases: List[List[Phase]] =
super.picklerPhases :+ List(ExtractExpression())

override protected def transformPhases: List[List[Phase]] =
super.transformPhases :+ List(ResolveReflectEval())
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package dotty.tools.dotc

import dotty.tools.dotc.core.Contexts.*
import dotty.tools.dotc.reporting.AbstractReporter
import dotty.tools.dotc.reporting.Diagnostic

class ExpressionReporter(reportError: String => Unit) extends AbstractReporter:
override def doReport(dia: Diagnostic)(using Context): Unit =
// println(messageAndPos(dia))
dia match
case error: Diagnostic.Error =>
val newPos = error.pos.source.positionInUltimateSource(error.pos)
val errorWithNewPos = new Diagnostic.Error(error.msg, newPos)
reportError(stripColor(messageAndPos(errorWithNewPos)))
case _ =>
// TODO report the warnings
()
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package dotty.tools.dotc.evaluation

object SymUtils extends dotty.tools.dotc.core.SymUtils
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import dotty.tools.dotc.core.Types.*
import dotty.tools.dotc.core.Names.*
import dotty.tools.dotc.core.Flags.*
import dotty.tools.dotc.core.Contexts.*
import dotty.tools.dotc.transform.SymUtils.*
import dotty.tools.dotc.evaluation.SymUtils.*

class ExpressionContext(
uniqueName: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import dotty.tools.dotc.core.Flags.*
import dotty.tools.dotc.core.Names.*
import dotty.tools.dotc.core.Symbols.*
import dotty.tools.dotc.core.Types.*
import dotty.tools.dotc.transform.SymUtils.*
import dotty.tools.dotc.core.DenotTransformers.DenotTransformer
import dotty.tools.dotc.core.Denotations.SingleDenotation
import dotty.tools.dotc.core.SymDenotations.SymDenotation
import dotty.tools.dotc.evaluation.SymUtils.*
import dotty.tools.dotc.transform.MacroTransform
import dotty.tools.dotc.core.Phases.*
import dotty.tools.dotc.report
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import dotty.tools.dotc.core.Names.*
import dotty.tools.dotc.core.Symbols.*
import dotty.tools.dotc.core.Types.*
import dotty.tools.dotc.transform.MegaPhase.MiniPhase
import dotty.tools.dotc.transform.SymUtils.*
import dotty.tools.dotc.core.StdNames.*
import dotty.tools.dotc.core.NameKinds.QualifiedInfo
import dotty.tools.dotc.evaluation.SymUtils.*
import dotty.tools.dotc.report
import dotty.tools.dotc.core.Phases
import dotty.tools.dotc.core.TypeErasure.ErasedValueType
Expand Down Expand Up @@ -47,6 +47,9 @@ class ResolveReflectEval(using exprCtx: ExpressionContext) extends MiniPhase:
// if cls is a value class then the local $this is the erased value,
// but we expect an instance of the value class instead
gen.boxValueClass(cls, gen.getLocalValue("$this"))
else if cls.is(ModuleClass) && !exprCtx.localVariables.contains("$this") then
// in Scala 3.4: an anonfun in an object is static
gen.getStaticObject(cls)
else gen.getLocalValue("$this")
case EvaluationStrategy.LocalOuter(cls) =>
gen.getLocalValue("$outer")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ import tastyquery.Symbols.TermSymbol

import java.{util => ju}

class Scala30StepFilterBridgeTests extends ScalaStepFilterBridgeTests(ScalaVersion.`3.0`)
class Scala31PlusStepFilterBridgeTests extends ScalaStepFilterBridgeTests(ScalaVersion.`3.1+`)
class Scala33StepFilterBridgeTests extends ScalaStepFilterBridgeTests(ScalaVersion.`3.3`)
class Scala34StepFilterBridgeTests extends ScalaStepFilterBridgeTests(ScalaVersion.`3.4`):
// all tests fail because of the TASTy signature
override def munitIgnore: Boolean = true

abstract class ScalaStepFilterBridgeTests(scalaVersion: ScalaVersion) extends FunSuite:
test("mixin-forwarders") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ object DebugStepAssert {
assertEquals(frame.line, expectedLine)
}

def assertOnFrame(expectedName: String)(frame: StackFrame): Unit =
def assertOnFrame(expectedName: String)(frame: StackFrame)(implicit location: Location): Unit =
assertEquals(frame.name, expectedName)
}

object Breakpoint {
def apply(line: Int)(implicit ctx: TestingContext): SingleStepAssert[StackFrame] =
def apply(line: Int)(implicit ctx: TestingContext, location: Location): SingleStepAssert[StackFrame] =
Breakpoint(ctx.mainSource, line)

def apply(sourceFile: Path, line: Int): SingleStepAssert[StackFrame] = {
def apply(sourceFile: Path, line: Int)(implicit location: Location): SingleStepAssert[StackFrame] = {
val breakpoint = Breakpoint(sourceFile, line, None)
SingleStepAssert(breakpoint, assertOnFrame(sourceFile, line))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ trait DebugTest {
def isScala2(implicit ctx: TestingContext) = ctx.scalaVersion.isScala2
def isScala213(implicit ctx: TestingContext) = ctx.scalaVersion.isScala213
def isScala212(implicit ctx: TestingContext) = ctx.scalaVersion.isScala212
def isScala30(implicit ctx: TestingContext) = ctx.scalaVersion.isScala30
def isScala31Plus(implicit ctx: TestingContext) = ctx.scalaVersion.isScala31Plus
def isScala33(implicit ctx: TestingContext) = ctx.scalaVersion.isScala33

def getDebugServer(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package ch.epfl.scala.debugadapter
import ch.epfl.scala.debugadapter.testfmk.*

class BypassExpressionCompilerTests extends DebugTestSuite {
private val scalaVersion = ScalaVersion.`3.1+`
private val scalaVersion = ScalaVersion.`3.3`
protected override def defaultConfig: DebugConfig =
super.defaultConfig.copy(evaluationMode = DebugConfig.SimpleEvaluationOnly)

Expand Down Expand Up @@ -363,7 +363,6 @@ class BypassExpressionCompilerTests extends DebugTestSuite {
}

test("evaluate capture of pattern") {
assume(!scalaVersion.isScala30) // Won't be fixed in Scala 3.0
val source =
"""|package example
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import scala.concurrent.duration._

class Scala212DebugTest extends ScalaDebugTests(ScalaVersion.`2.12`)
class Scala213DebugTest extends ScalaDebugTests(ScalaVersion.`2.13`)
class Scala3DebugTest extends ScalaDebugTests(ScalaVersion.`3.1+`) {
class Scala33DebugTest extends ScalaDebugTests(ScalaVersion.`3.3`) {
test("should support breakpoints in scala 3 with brace-less syntax") {
val source =
"""|package example
Expand Down
Loading

0 comments on commit 2cdc96a

Please sign in to comment.