Skip to content

Commit c868461

Browse files
committed
Move quoted staging to it's own package
1 parent 49c6626 commit c868461

File tree

105 files changed

+251
-195
lines changed

Some content is hidden

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

105 files changed

+251
-195
lines changed

compiler/src/dotty/tools/dotc/quoted/QuoteDriver.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import dotty.tools.io.{AbstractFile, Directory, PlainDirectory, VirtualDirectory
88
import dotty.tools.repl.AbstractFileClassLoader
99
import dotty.tools.dotc.reporting._
1010
import scala.quoted._
11-
import scala.quoted.Toolbox
11+
import scala.quoted.staging.Toolbox
1212
import java.net.URLClassLoader
1313

1414
/** Driver to compile quoted code

compiler/src/dotty/tools/dotc/quoted/ToolboxImpl.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ object ToolboxImpl {
1313
* @param settings toolbox settings
1414
* @return A new instance of the toolbox
1515
*/
16-
def make(settings: scala.quoted.Toolbox.Settings, appClassloader: ClassLoader): scala.quoted.Toolbox = new scala.quoted.Toolbox {
16+
def make(settings: scala.quoted.staging.Toolbox.Settings, appClassloader: ClassLoader): scala.quoted.staging.Toolbox = new scala.quoted.staging.Toolbox {
1717

1818
private[this] val driver: QuoteDriver = new QuoteDriver(appClassloader)
1919

@@ -22,7 +22,7 @@ object ToolboxImpl {
2222
def run[T](exprBuilder: QuoteContext => Expr[T]): T = synchronized {
2323
try {
2424
if (running) // detected nested run
25-
throw new scala.quoted.Toolbox.RunScopeException()
25+
throw new scala.quoted.staging.Toolbox.RunScopeException()
2626
running = true
2727
driver.run(exprBuilder, settings)
2828
} finally {
@@ -35,7 +35,7 @@ object ToolboxImpl {
3535

3636
private[dotty] def checkScopeId(id: ScopeId) given Context: Unit = {
3737
if (id != scopeId)
38-
throw new Toolbox.RunScopeException
38+
throw new staging.Toolbox.RunScopeException
3939
}
4040

4141
// TODO Explore more fine grained scope ids.

compiler/test-resources/repl-macros/i6007

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
scala> import scala.quoted._
2-
scala> implicit def toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader)
2+
scala> implicit def toolbox: scala.quoted.staging.Toolbox = scala.quoted.staging.Toolbox.make(getClass.getClassLoader)
33
def toolbox: quoted.Toolbox
44
scala> def v given QuoteContext = '{ (if true then Some(1) else None).map(v => v+1) }
55
def v given (x$1: quoted.QuoteContext): quoted.Expr[Option[Int]]

compiler/test-resources/repl-macros/i6263

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
scala> import quoted._
2-
scala> implicit def toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader)
2+
scala> implicit def toolbox: scala.quoted.staging.Toolbox = scala.quoted.staging.Toolbox.make(getClass.getClassLoader)
33
def toolbox: quoted.Toolbox
44
scala> def fn[T : Type](v : T) = println("ok")
55
def fn[T](v: T)(implicit evidence$1: quoted.Type[T]): Unit

docs/docs/reference/metaprogramming/staging.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ to get a source-like representation of the expression.
8282

8383
```scala
8484
// make available the necessary toolbox for runtime code generation
85-
implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader)
85+
implicit val toolbox: scala.quoted.staging.Toolbox = scala.quoted.staging.Toolbox.make(getClass.getClassLoader)
8686

8787
val f: Array[Int] => Int = run {
8888
val stagedSum: Expr[Array[Int] => Int] = '{ (arr: Array[Int]) => ${sum('arr)}}

library/src-bootstrapped/scala/quoted/package.scala

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,49 +2,6 @@ package scala
22

33
package object quoted {
44

5-
/** Evaluate the contents of this expression and return the result.
6-
* It provides a new QuoteContext that is only valid within the scope the argument.
7-
*
8-
* Usage:
9-
* ```
10-
* val e: T = run { // (given qctx: QuoteContext) =>
11-
* expr
12-
* }
13-
* ```
14-
* where `expr: Expr[T]`
15-
*
16-
* This method should not be called in a context where there is already has a `QuoteContext`
17-
* such as within a `run` or a `withQuoteContext`.
18-
*/
19-
def run[T](expr: given QuoteContext => Expr[T]) given (toolbox: Toolbox): T = toolbox.run(expr given _)
20-
21-
/** Provide a new quote context within the scope of the argument that is only valid within the scope the argument.
22-
* Return the result of the argument.
23-
*
24-
* Usage:
25-
* ```
26-
* val e: T = withQuoteContext { // (given qctx: QuoteContext) =>
27-
* thunk
28-
* }
29-
* ```
30-
* where `thunk: T`
31-
*
32-
* This method should not be called in a context where there is already has a `QuoteContext`
33-
* such as within a `run` or a `withQuoteContext`.
34-
*/
35-
def withQuoteContext[T](thunk: given QuoteContext => T) given (toolbox: Toolbox): T = {
36-
var result: T = NoResult.asInstanceOf[T]
37-
def dummyRun given QuoteContext: Expr[Unit] = {
38-
result = thunk
39-
Expr.unitExpr
40-
}
41-
toolbox.run(dummyRun given _)
42-
assert(result != NoResult) // toolbox.run should have thrown an exception
43-
result
44-
}
45-
46-
private object NoResult
47-
485
object autolift {
496
given autoToExpr[T] as Conversion[T, Expr[T]] given Liftable[T], QuoteContext = _.toExpr
507
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package scala.quoted
2+
3+
package object staging {
4+
5+
/** Evaluate the contents of this expression and return the result.
6+
* It provides a new QuoteContext that is only valid within the scope the argument.
7+
*
8+
* Usage:
9+
* ```
10+
* val e: T = run { // (given qctx: QuoteContext) =>
11+
* expr
12+
* }
13+
* ```
14+
* where `expr: Expr[T]`
15+
*
16+
* This method should not be called in a context where there is already has a `QuoteContext`
17+
* such as within a `run` or a `withQuoteContext`.
18+
*/
19+
def run[T](expr: given QuoteContext => Expr[T]) given (toolbox: Toolbox): T = toolbox.run(expr given _)
20+
21+
/** Provide a new quote context within the scope of the argument that is only valid within the scope the argument.
22+
* Return the result of the argument.
23+
*
24+
* Usage:
25+
* ```
26+
* val e: T = withQuoteContext { // (given qctx: QuoteContext) =>
27+
* thunk
28+
* }
29+
* ```
30+
* where `thunk: T`
31+
*
32+
* This method should not be called in a context where there is already has a `QuoteContext`
33+
* such as within a `run` or a `withQuoteContext`.
34+
*/
35+
def withQuoteContext[T](thunk: given QuoteContext => T) given (toolbox: Toolbox): T = {
36+
var result: T = NoResult.asInstanceOf[T]
37+
def dummyRun given QuoteContext: Expr[Unit] = {
38+
result = thunk
39+
Expr.unitExpr
40+
}
41+
toolbox.run(dummyRun given _)
42+
assert(result != NoResult) // toolbox.run should have thrown an exception
43+
result
44+
}
45+
46+
private object NoResult
47+
48+
}

library/src-non-bootstrapped/scala/quoted/package.scala

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,49 +2,6 @@ package scala
22

33
package object quoted {
44

5-
/** Evaluate the contents of this expression and return the result.
6-
* It provides a new QuoteContext that is only valid within the scope the argument.
7-
*
8-
* Usage:
9-
* ```
10-
* val e: T = run { // (given qctx: QuoteContext) =>
11-
* expr
12-
* }
13-
* ```
14-
* where `expr: Expr[T]`
15-
*
16-
* This method should not be called in a context where there is already has a `QuoteContext`
17-
* such as within a `run` or a `withQuoteContext`.
18-
*/
19-
def run[T](expr: given QuoteContext => Expr[T]) given (toolbox: Toolbox): T = toolbox.run(expr given _)
20-
21-
/** Provide a new quote context within the scope of the argument that is only valid within the scope the argument.
22-
* Return the result of the argument.
23-
*
24-
* Usage:
25-
* ```
26-
* val e: T = withQuoteContext { // (given qctx: QuoteContext) =>
27-
* thunk
28-
* }
29-
* ```
30-
* where `thunk: T`
31-
*
32-
* This method should not be called in a context where there is already has a `QuoteContext`
33-
* such as within a `run` or a `withQuoteContext`.
34-
*/
35-
def withQuoteContext[T](thunk: given QuoteContext => T) given (toolbox: Toolbox): T = {
36-
var result: T = NoResult.asInstanceOf[T]
37-
def dummyRun given QuoteContext: Expr[Unit] = {
38-
result = thunk
39-
Expr.unitExpr
40-
}
41-
toolbox.run(dummyRun given _)
42-
assert(result != NoResult) // toolbox.run should have thrown an exception
43-
result
44-
}
45-
46-
private object NoResult
47-
485
object autolift {
496
given autoToExpr[T] as Conversion[T, Expr[T]] given Liftable[T], QuoteContext = _.toExpr
507
}

library/src/scala/quoted/Expr.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package scala
33
package quoted {
44

55
import scala.quoted.show.SyntaxHighlight
6+
import scala.quoted.staging.Toolbox
67

78
sealed trait Expr[+T] {
89

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package scala.quoted
2+
package staging
23

34
import scala.annotation.implicitNotFound
45

5-
@implicitNotFound("Could not find implicit quoted.Toolbox.\n\nDefault toolbox can be instantiated with:\n `implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader)`\n\n")
6+
@implicitNotFound("Could not find implicit scala.quoted.staging.Toolbox.\n\nDefault toolbox can be instantiated with:\n `implicit val toolbox: scala.quoted.staging.Toolbox = scala.quoted.staging.Toolbox.make(getClass.getClassLoader)`\n\n")
67
trait Toolbox {
78
def run[T](expr: QuoteContext => Expr[T]): T
89
}
@@ -13,7 +14,7 @@ object Toolbox {
1314
*
1415
* Usuage:
1516
* ```
16-
* implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader)
17+
* implicit val toolbox: scala.quoted.staging.Toolbox = scala.quoted.staging.Toolbox.make(getClass.getClassLoader)
1718
* ```
1819
*
1920
* @param appClassloader classloader of the application that generated the quotes

0 commit comments

Comments
 (0)