Skip to content

Initialize quote cache on tasty inspector run #13953

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

Merged
merged 1 commit into from
Nov 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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