Skip to content

Commit

Permalink
Merge pull request #13953 from jodersky/jo/tasty-cache
Browse files Browse the repository at this point in the history
Initialize quote cache on tasty inspector run
  • Loading branch information
nicolasstucki authored Nov 23, 2021
2 parents 2ef89b2 + 50d7f43 commit ca483f8
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 1 deletion.
24 changes: 24 additions & 0 deletions sbt-test/sbt-dotty/tasty-inspector-cache/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
lazy val dottyVersion = sys.props("plugin.scalaVersion")

lazy val lib = project
.in(file("lib"))
.settings(
scalaVersion := dottyVersion
)

val jarDest = file("target") / "app.jar"

val runTest = Def.taskKey[Unit]("run tests")

lazy val inspector = project
.in(file("inspector"))
.settings(
scalaVersion := dottyVersion,
libraryDependencies += "org.scala-lang" %% "scala3-tasty-inspector" % scalaVersion.value,
runTest :=
Def.sequential(
Def.task(IO.copyFile((lib/Compile/packageBin).value, jarDest)),
(Compile/run).toTask(" " + jarDest.getAbsolutePath)
).value
)
.dependsOn(lib)
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import scala.quoted.Quotes
import scala.quoted.quotes
import scala.tasty.inspector as ins

// Test for https://github.com/lampepfl/dotty/issues/13919
class MyInspector extends ins.Inspector:
def inspect(using Quotes)(tastys: List[ins.Tasty[quotes.type]]): Unit =
import quotes.reflect._
TypeRepr.of[Int]
TypeRepr.of[String]


@main def main(args: String*): Unit =
ins.TastyInspector.inspectTastyFilesInJar(args.head)(new MyInspector)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
class Dummy // we need at least one file for the tasty inspector to run
1 change: 1 addition & 0 deletions sbt-test/sbt-dotty/tasty-inspector-cache/test
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
> inspector/runTest
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import dotty.tools.dotc.core.Contexts.Context
import dotty.tools.dotc.core.Mode
import dotty.tools.dotc.core.Phases.Phase
import dotty.tools.dotc.fromtasty._
import dotty.tools.dotc.quoted.QuotesCache
import dotty.tools.dotc.util.ClasspathFromClassloader
import dotty.tools.dotc.CompilationUnit
import dotty.tools.unsupported
Expand Down Expand Up @@ -64,7 +65,11 @@ object TastyInspector:
class TastyInspectorPhase extends Phase:
override def phaseName: String = "tastyInspector"

override def runOn(units: List[CompilationUnit])(using Context): List[CompilationUnit] =
override def runOn(units: List[CompilationUnit])(using ctx0: Context): List[CompilationUnit] =
val ctx = QuotesCache.init(ctx0.fresh)
runOnImpl(units)(using ctx)

private def runOnImpl(units: List[CompilationUnit])(using Context): List[CompilationUnit] =
val quotesImpl = QuotesImpl()
class TastyImpl(val path: String, val ast: quotesImpl.reflect.Tree) extends Tasty[quotesImpl.type] {
val quotes = quotesImpl
Expand Down

0 comments on commit ca483f8

Please sign in to comment.