Skip to content

Commit a3631f8

Browse files
Merge pull request #11129 from dotty-staging/rename-staging-toolbox
Rename scala.quoted.staging.{Toolbox => Compiler}
2 parents 83592c3 + 2c2c8cf commit a3631f8

File tree

117 files changed

+155
-154
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

117 files changed

+155
-154
lines changed

docs/docs/reference/metaprogramming/staging.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,15 @@ The framework as discussed so far allows code to be staged, i.e. be prepared
6060
to be executed at a later stage. To run that code, there is another method
6161
in class `Expr` called `run`. Note that `$` and `run` both map from `Expr[T]`
6262
to `T` but only `$` is subject to the PCP, whereas `run` is just a normal method.
63-
`run` provides a `Quotes` that can be used to show the expression in its scope.
64-
On the other hand `withQuotes` provides a `Quotes` without evaluating the expression.
63+
`scala.quoted.staging.run` provides a `Quotes` that can be used to show the expression in its scope.
64+
On the other hand `scala.quoted.staging.withQuotes` provides a `Quotes` without evaluating the expression.
6565

6666
```scala
6767
package scala.quoted.staging
6868

69-
def run[T](expr: Quotes ?=> Expr[T])(using toolbox: Toolbox): T = ...
69+
def run[T](expr: Quotes ?=> Expr[T])(using Compiler): T = ...
7070

71-
def withQuotes[T](thunk: Quotes ?=> T)(using toolbox: Toolbox): T = ...
71+
def withQuotes[T](thunk: Quotes ?=> T)(using Compiler): T = ...
7272
```
7373

7474
## Create a new Scala 3 project with staging enabled
@@ -99,17 +99,17 @@ scala -with-compiler -classpath out Test
9999
Now take exactly the same example as in [Macros](./macros.md). Assume that we
100100
do not want to pass an array statically but generate code at run-time and pass
101101
the value, also at run-time. Note, how we make a future-stage function of type
102-
`Expr[Array[Int] => Int]` in line 6 below. Using `run { ... }` we can evaluate an
103-
expression at runtime. Within the scope of `run` we can also invoke `show` on an expression
102+
`Expr[Array[Int] => Int]` in line 6 below. Using `staging.run { ... }` we can evaluate an
103+
expression at runtime. Within the scope of `staging.run` we can also invoke `show` on an expression
104104
to get a source-like representation of the expression.
105105

106106
```scala
107-
import scala.quoted.staging._
107+
import scala.quoted._
108108

109-
// make available the necessary toolbox for runtime code generation
110-
given Toolbox = Toolbox.make(getClass.getClassLoader)
109+
// make available the necessary compiler for runtime code generation
110+
given staging.Compiler = staging.Compiler.make(getClass.getClassLoader)
111111

112-
val f: Array[Int] => Int = run {
112+
val f: Array[Int] => Int = staging.run {
113113
val stagedSum: Expr[Array[Int] => Int] =
114114
'{ (arr: Array[Int]) => ${sum('arr)}}
115115
println(stagedSum.show) // Prints "(arr: Array[Int]) => { var sum = 0; ... }"

sbt-dotty/sbt-test/sbt-dotty/i7897/src/main/scala/hello/i7897.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import scala.quoted._, staging._
22

3-
given Toolbox = Toolbox.make(getClass.getClassLoader)
3+
given Compiler = Compiler.make(getClass.getClassLoader)
44

55
val f: Array[Int] => Int = run {
66
val stagedSum: Expr[Array[Int] => Int] = '{ (arr: Array[Int]) => 6 }

sbt-dotty/sbt-test/sbt-dotty/quoted-example-project/src/main/scala/hello/Hello.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ package hello
22

33
// Import `Expr` and some extension methods
44
import scala.quoted._
5-
import scala.quoted.staging.{run, Toolbox}
5+
import scala.quoted.staging.{run, Compiler}
66

77
object Main {
88

9-
given Toolbox = Toolbox.make(getClass.getClassLoader)
9+
given Compiler = Compiler.make(getClass.getClassLoader)
1010

1111
def main(args: Array[String]): Unit = {
1212

sbt-dotty/sbt-test/sbt-dotty/quoted-example-project/src/test/scala/hello/Tests.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ import org.junit.Test
44

55
// Import Expr and some extension methods
66
import scala.quoted._
7+
import scala.quoted.staging._
78

89
class Tests {
910

10-
implicit val toolbox: scala.quoted.staging.Toolbox = scala.quoted.staging.Toolbox.make(getClass.getClassLoader)
11+
given Compiler = Compiler.make(getClass.getClassLoader)
1112

1213
@Test def test(): Unit = {
1314
import hello.Main._

staging/src/scala/quoted/staging/Toolbox.scala renamed to staging/src/scala/quoted/staging/Compiler.scala

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,26 @@ import scala.annotation.implicitNotFound
55

66
import scala.quoted.runtime.impl.ScopeException
77

8-
@implicitNotFound("Could not find implicit scala.quoted.staging.Toolbox.\n\nDefault toolbox can be instantiated with:\n `given scala.quoted.staging.Toolbox = scala.quoted.staging.Toolbox.make(getClass.getClassLoader)`\n\n")
9-
trait Toolbox:
8+
@implicitNotFound("Could not find implicit scala.quoted.staging.Compiler.\n\nDefault compiler can be instantiated with:\n `import scala.quoted.staging.Compiler; given Compiler = Compiler.make(getClass.getClassLoader)`\n\n")
9+
trait Compiler:
1010
def run[T](expr: Quotes => Expr[T]): T
1111

12-
object Toolbox:
12+
object Compiler:
1313

14-
/** Create a new instance of the toolbox using the the classloader of the application.
14+
/** Create a new instance of the compiler using the the classloader of the application.
1515
*
1616
* Usuage:
1717
* ```
1818
* import scala.quoted.staging._
19-
* given Toolbox = Toolbox.make(getClass.getClassLoader)
19+
* given Compiler = Compiler.make(getClass.getClassLoader)
2020
* ```
2121
*
2222
* @param appClassloader classloader of the application that generated the quotes
23-
* @param settings toolbox settings
24-
* @return A new instance of the toolbox
23+
* @param settings compiler settings
24+
* @return A new instance of the compiler
2525
*/
26-
def make(appClassloader: ClassLoader)(implicit settings: Settings): Toolbox =
27-
new Toolbox:
26+
def make(appClassloader: ClassLoader)(implicit settings: Settings): Compiler =
27+
new Compiler:
2828

2929
private[this] val driver: QuoteDriver = new QuoteDriver(appClassloader)
3030

@@ -43,14 +43,14 @@ object Toolbox:
4343

4444
end new
4545

46-
/** Setting of the Toolbox instance. */
46+
/** Setting of the Compiler instance. */
4747
case class Settings private (outDir: Option[String], compilerArgs: List[String])
4848

4949
object Settings:
5050

5151
implicit def default: Settings = make()
5252

53-
/** Make toolbox settings
53+
/** Make compiler settings
5454
* @param outDir Output directory for the compiled quote. If set to None the output will be in memory
5555
* @param compilerArgs Compiler arguments. Use only if you know what you are doing.
5656
*/
@@ -62,4 +62,4 @@ object Toolbox:
6262

6363
end Settings
6464

65-
end Toolbox
65+
end Compiler

staging/src/scala/quoted/staging/QuoteDriver.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import dotty.tools.repl.AbstractFileClassLoader
99
import dotty.tools.dotc.reporting._
1010
import dotty.tools.dotc.util.ClasspathFromClassloader
1111
import scala.quoted._
12-
import scala.quoted.staging.Toolbox
12+
import scala.quoted.staging.Compiler
1313
import java.io.File
1414
import scala.annotation.tailrec
1515

@@ -22,7 +22,7 @@ private class QuoteDriver(appClassloader: ClassLoader) extends Driver:
2222

2323
private[this] val contextBase: ContextBase = new ContextBase
2424

25-
def run[T](exprBuilder: Quotes => Expr[T], settings: Toolbox.Settings): T =
25+
def run[T](exprBuilder: Quotes => Expr[T], settings: Compiler.Settings): T =
2626
val outDir: AbstractFile =
2727
settings.outDir match
2828
case Some(out) =>
@@ -34,7 +34,7 @@ private class QuoteDriver(appClassloader: ClassLoader) extends Driver:
3434
end outDir
3535

3636
val (_, ctx0: Context) = setup(settings.compilerArgs.toArray :+ "dummy.scala", initCtx.fresh)
37-
val ctx = setToolboxSettings(ctx0.fresh.setSetting(ctx0.settings.outputDir, outDir), settings)
37+
val ctx = setCompilerSettings(ctx0.fresh.setSetting(ctx0.settings.outputDir, outDir), settings)
3838

3939
new QuoteCompiler().newRun(ctx).compileExpr(exprBuilder) match
4040
case Right(value) =>
@@ -59,7 +59,7 @@ private class QuoteDriver(appClassloader: ClassLoader) extends Driver:
5959
ictx.settings.classpath.update(ClasspathFromClassloader(appClassloader))(using ictx)
6060
ictx
6161

62-
private def setToolboxSettings(ctx: FreshContext, settings: Toolbox.Settings): ctx.type =
62+
private def setCompilerSettings(ctx: FreshContext, settings: Compiler.Settings): ctx.type =
6363
// An error in the generated code is a bug in the compiler
6464
// Setting the throwing reporter however will report any exception
6565
ctx.setReporter(new ThrowingReporter(ctx.reporter))

staging/src/scala/quoted/staging/staging.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ package object staging:
1616
* This method should not be called in a context where there is already has a `Quotes`
1717
* such as within a `run` or a `withQuotes`.
1818
*/
19-
def run[T](expr: Quotes ?=> Expr[T])(using toolbox: Toolbox): T = toolbox.run(expr(using _))
19+
def run[T](expr: Quotes ?=> Expr[T])(using compiler: Compiler): T = compiler.run(expr(using _))
2020

2121
/** Provide a new quote context within the scope of the argument that is only valid within the scope the argument.
2222
* Return the result of the argument.
@@ -32,15 +32,15 @@ package object staging:
3232
* This method should not be called in a context where there is already has a `Quotes`
3333
* such as within a `run` or a `withQuotes`.
3434
*/
35-
def withQuotes[T](thunk: Quotes ?=> T)(using toolbox: Toolbox): T =
35+
def withQuotes[T](thunk: Quotes ?=> T)(using compiler: Compiler): T =
3636
val noResult = new Object
3737
var result: T = noResult.asInstanceOf[T]
3838
def dummyRun(using Quotes): Expr[Unit] = {
3939
result = thunk
4040
'{}
4141
}
42-
toolbox.run(dummyRun(using _))
43-
assert(result != noResult) // toolbox.run should have thrown an exception
42+
compiler.run(dummyRun(using _))
43+
assert(result != noResult) // compiler.run should have thrown an exception
4444
result
4545
end withQuotes
4646

staging/test-resources/repl-staging/i6007

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
scala> import scala.quoted._
2-
scala> import scala.quoted.staging._
3-
scala> implicit def toolbox: Toolbox = Toolbox.make(getClass.getClassLoader)
4-
def toolbox: quoted.staging.Toolbox
2+
scala> import quoted.staging.{Compiler => StagingCompiler, _}
3+
scala> implicit def compiler: StagingCompiler = StagingCompiler.make(getClass.getClassLoader)
4+
def compiler: quoted.staging.Compiler
55
scala> def v(using Quotes) = '{ (if true then Some(1) else None).map(v => v+1) }
66
def v(using x$1: quoted.Quotes): quoted.Expr[Option[Int]]
77
scala> scala.quoted.staging.withQuotes(v.show)

staging/test-resources/repl-staging/i6263

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
scala> import quoted._
2-
scala> import quoted.staging._
3-
scala> implicit def toolbox: Toolbox = Toolbox.make(getClass.getClassLoader)
4-
def toolbox: quoted.staging.Toolbox
2+
scala> import quoted.staging.{Compiler => StagingCompiler, _}
3+
scala> implicit def compiler: StagingCompiler = StagingCompiler.make(getClass.getClassLoader)
4+
def compiler: quoted.staging.Compiler
55
scala> def fn[T : Type](v : T) = println("ok")
66
def fn[T](v: T)(implicit evidence$1: quoted.Type[T]): Unit
77
scala> withQuotes { fn("foo") }

tests/disabled/neg-with-compiler/quote-run-in-macro-2/quoted_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ object Macros {
44

55
inline def foo(i: => Int): Int = ${ fooImpl('i) }
66
def fooImpl(i: Expr[Int])(using Quotes): Expr[Int] = {
7-
given Toolbox = Toolbox.make(getClass.getClassLoader)
7+
given Compiler = Compiler.make(getClass.getClassLoader)
88
val y: Int = run(i)
99
y
1010
}

tests/disabled/run-staging/quote-macro-in-splice/quoted_2.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import scala.quoted.staging._
33
import Macros._
44

55
object Test {
6-
given Toolbox = Toolbox.make(getClass.getClassLoader)
6+
given Compiler = Compiler.make(getClass.getClassLoader)
77
def main(args: Array[String]): Unit = withQuotes {
88
val x = '{
99
val y = 1

tests/neg-staging/i5941/macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ object Lens {
1212
}
1313

1414
def impl[S: Type, T: Type](getter: Expr[S => T])(using Quotes): Expr[Lens[S, T]] = {
15-
implicit val toolbox: scala.quoted.staging.Toolbox = scala.quoted.staging.Toolbox.make(this.getClass.getClassLoader)
15+
implicit val toolbox: scala.quoted.staging.Compiler = scala.quoted.staging.Compiler.make(this.getClass.getClassLoader)
1616
import quotes.reflect._
1717
import util._
1818
// obj.copy(field = value)

tests/neg-staging/i9692.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import scala.quoted.staging._
33

44
object Test extends App {
55

6-
// make available the necessary toolbox for runtime code generation
7-
given Toolbox = Toolbox.make(getClass.getClassLoader)
6+
// make available the necessary compiler for runtime code generation
7+
given Compiler = Compiler.make(getClass.getClassLoader)
88

99
run {
1010
val expr: Expr[Int] = '{ var x = 1; x = 2; 42 }

tests/neg-staging/i9693.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import scala.quoted.staging._
44
object Test extends App {
55

66
// make available the necessary toolbox for runtime code generation
7-
given Toolbox = Toolbox.make(getClass.getClassLoader)
7+
given Compiler = Compiler.make(getClass.getClassLoader)
88

99
run {
1010
val expr: Expr[Int] = '{ var x = 1; x = 2; 42 }

tests/neg-staging/quote-run-in-macro-1/quoted_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import scala.quoted.staging._
33

44
object Macros {
55

6-
given Toolbox = Toolbox.make(getClass.getClassLoader)
6+
given Compiler = Compiler.make(getClass.getClassLoader)
77
inline def foo(i: => Int): Int = ${ fooImpl('i) }
88
def fooImpl(i: Expr[Int])(using Quotes): Expr[Int] = {
99
val y: Int = run(i)

tests/pos-staging/quote-0.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ object Macros {
2727

2828
class Test {
2929

30-
given Toolbox = Toolbox.make(getClass.getClassLoader)
30+
given Compiler = Compiler.make(getClass.getClassLoader)
3131

3232
run {
3333
val program = '{

tests/pos-staging/quote-assert/quoted_2.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ object Test {
1717
${ assertImpl('{x != 0}) }
1818
}
1919

20-
given Toolbox = Toolbox.make(getClass.getClassLoader)
20+
given Compiler = Compiler.make(getClass.getClassLoader)
2121
run(program)
2222
}

tests/run-staging/abstract-int-quote.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import scala.quoted.staging._
33

44
object Test:
55

6-
given Toolbox = Toolbox.make(getClass.getClassLoader)
6+
given Compiler = Compiler.make(getClass.getClassLoader)
77

88
def main(args: Array[String]): Unit =
99
def reduce[T: Type](using Quotes)(succ: Expr[T] => Expr[T], zero: Expr[T]): Expr[T] = '{

tests/run-staging/expr-matches.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import scala.quoted.staging._
33

44

55
object Test {
6-
given Toolbox = Toolbox.make(getClass.getClassLoader)
6+
given Compiler = Compiler.make(getClass.getClassLoader)
77
def main(args: Array[String]): Unit = withQuotes {
88
assert('{1} matches '{1})
99
assert('{println("foo")} matches '{println("foo")})

tests/run-staging/i3823-b.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import scala.quoted._
22
import scala.quoted.staging._
33
object Test {
4-
given Toolbox = Toolbox.make(getClass.getClassLoader)
4+
given Compiler = Compiler.make(getClass.getClassLoader)
55
def main(args: Array[String]): Unit = withQuotes {
66
def f[T](x: Expr[T])(implicit t: Type[T]) = '{
77
val z: t.Underlying = $x

tests/run-staging/i3823-c.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import scala.quoted._
22
import scala.quoted.staging._
33
object Test {
4-
given Toolbox = Toolbox.make(getClass.getClassLoader)
4+
given Compiler = Compiler.make(getClass.getClassLoader)
55
def main(args: Array[String]): Unit = withQuotes {
66
def f[T](x: Expr[T])(implicit t: Type[T]) = '{
77
val z = $x

tests/run-staging/i3823.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import scala.quoted._
22
import scala.quoted.staging._
33
object Test {
4-
given Toolbox = Toolbox.make(getClass.getClassLoader)
4+
given Compiler = Compiler.make(getClass.getClassLoader)
55
def main(args: Array[String]): Unit = withQuotes {
66
def f[T](x: Expr[T])(using t: Type[T]) = '{
77
val z: t.Underlying = $x

tests/run-staging/i3847-b.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ object Arrays {
1414
}
1515

1616
object Test {
17-
given Toolbox = Toolbox.make(getClass.getClassLoader)
17+
given Compiler = Compiler.make(getClass.getClassLoader)
1818
def main(args: Array[String]): Unit = withQuotes {
1919
import Arrays._
2020
implicit val ct: Expr[ClassTag[Int]] = '{ClassTag.Int}

tests/run-staging/i3847.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ object Arrays {
1414
}
1515

1616
object Test {
17-
implicit val toolbox: scala.quoted.staging.Toolbox = scala.quoted.staging.Toolbox.make(this.getClass.getClassLoader)
17+
implicit val toolbox: scala.quoted.staging.Compiler = scala.quoted.staging.Compiler.make(this.getClass.getClassLoader)
1818
def main(args: Array[String]): Unit = withQuotes {
1919
import Arrays._
2020
implicit val ct: Expr[ClassTag[Int]] = '{ClassTag.Int}

tests/run-staging/i3876-b.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import scala.quoted._
22
import scala.quoted.staging._
33
object Test {
44
def main(args: Array[String]): Unit = {
5-
given Toolbox = Toolbox.make(getClass.getClassLoader)
5+
given Compiler = Compiler.make(getClass.getClassLoader)
66

77
def x(using Quotes): Expr[Int] = '{3}
88

tests/run-staging/i3876-c.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import scala.quoted._
22
import scala.quoted.staging._
33
object Test {
44
def main(args: Array[String]): Unit = {
5-
implicit def toolbox: scala.quoted.staging.Toolbox = scala.quoted.staging.Toolbox.make(getClass.getClassLoader)
5+
implicit def toolbox: scala.quoted.staging.Compiler = scala.quoted.staging.Compiler.make(getClass.getClassLoader)
66

77
def x(using Quotes): Expr[Int] = '{3}
88

tests/run-staging/i3876-d.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import scala.quoted._
22
import scala.quoted.staging._
33
object Test {
44
def main(args: Array[String]): Unit = {
5-
given Toolbox = Toolbox.make(getClass.getClassLoader)
5+
given Compiler = Compiler.make(getClass.getClassLoader)
66

77
def x(using Quotes): Expr[Int] = '{3}
88

tests/run-staging/i3876-e.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import scala.quoted._
22
import scala.quoted.staging._
33
object Test {
44
def main(args: Array[String]): Unit = {
5-
given Toolbox = Toolbox.make(getClass.getClassLoader)
5+
given Compiler = Compiler.make(getClass.getClassLoader)
66

77
def x(using Quotes): Expr[Int] = '{ println(); 3 }
88

0 commit comments

Comments
 (0)