Skip to content

Commit ca483f8

Browse files
Merge pull request #13953 from jodersky/jo/tasty-cache
Initialize quote cache on tasty inspector run
2 parents 2ef89b2 + 50d7f43 commit ca483f8

File tree

5 files changed

+46
-1
lines changed

5 files changed

+46
-1
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
lazy val dottyVersion = sys.props("plugin.scalaVersion")
2+
3+
lazy val lib = project
4+
.in(file("lib"))
5+
.settings(
6+
scalaVersion := dottyVersion
7+
)
8+
9+
val jarDest = file("target") / "app.jar"
10+
11+
val runTest = Def.taskKey[Unit]("run tests")
12+
13+
lazy val inspector = project
14+
.in(file("inspector"))
15+
.settings(
16+
scalaVersion := dottyVersion,
17+
libraryDependencies += "org.scala-lang" %% "scala3-tasty-inspector" % scalaVersion.value,
18+
runTest :=
19+
Def.sequential(
20+
Def.task(IO.copyFile((lib/Compile/packageBin).value, jarDest)),
21+
(Compile/run).toTask(" " + jarDest.getAbsolutePath)
22+
).value
23+
)
24+
.dependsOn(lib)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import scala.quoted.Quotes
2+
import scala.quoted.quotes
3+
import scala.tasty.inspector as ins
4+
5+
// Test for https://github.com/lampepfl/dotty/issues/13919
6+
class MyInspector extends ins.Inspector:
7+
def inspect(using Quotes)(tastys: List[ins.Tasty[quotes.type]]): Unit =
8+
import quotes.reflect._
9+
TypeRepr.of[Int]
10+
TypeRepr.of[String]
11+
12+
13+
@main def main(args: String*): Unit =
14+
ins.TastyInspector.inspectTastyFilesInJar(args.head)(new MyInspector)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
class Dummy // we need at least one file for the tasty inspector to run
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
> inspector/runTest

tasty-inspector/src/scala/tasty/inspector/TastyInspector.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import dotty.tools.dotc.core.Contexts.Context
1010
import dotty.tools.dotc.core.Mode
1111
import dotty.tools.dotc.core.Phases.Phase
1212
import dotty.tools.dotc.fromtasty._
13+
import dotty.tools.dotc.quoted.QuotesCache
1314
import dotty.tools.dotc.util.ClasspathFromClassloader
1415
import dotty.tools.dotc.CompilationUnit
1516
import dotty.tools.unsupported
@@ -64,7 +65,11 @@ object TastyInspector:
6465
class TastyInspectorPhase extends Phase:
6566
override def phaseName: String = "tastyInspector"
6667

67-
override def runOn(units: List[CompilationUnit])(using Context): List[CompilationUnit] =
68+
override def runOn(units: List[CompilationUnit])(using ctx0: Context): List[CompilationUnit] =
69+
val ctx = QuotesCache.init(ctx0.fresh)
70+
runOnImpl(units)(using ctx)
71+
72+
private def runOnImpl(units: List[CompilationUnit])(using Context): List[CompilationUnit] =
6873
val quotesImpl = QuotesImpl()
6974
class TastyImpl(val path: String, val ast: quotesImpl.reflect.Tree) extends Tasty[quotesImpl.type] {
7075
val quotes = quotesImpl

0 commit comments

Comments
 (0)