Skip to content

Commit 5aec4f8

Browse files
Merge pull request #8948 from dotty-staging/move-quoted-to-src-bootstrapped
Only compile quoted code in bootstrapped library
2 parents dd98d4a + f784e6b commit 5aec4f8

29 files changed

+78
-7
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package dotty.internal
2+
3+
import scala.quoted._
4+
5+
object CompileTimeMacros:
6+
def codeExpr(using qctx: QuoteContext)(sc: Expr[StringContext], args: Expr[Seq[Any]]): Expr[String] =
7+
(sc, args) match
8+
case (Expr.StringContext(Consts(parts)), Varargs(args2)) =>
9+
Expr(StringContext(parts: _*).s(args2.map(_.show): _*))
10+
case _ =>
11+
qctx.throwError("compiletime.code must be used as a string interpolator `code\"...\"`")
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package dotty.internal
2+
3+
import scala.quoted._
4+
5+
object CompileTimeMacros:
6+
def codeExpr(using qctx: QuoteContext)(sc: Expr[StringContext], args: Expr[Seq[Any]]): Expr[String] =
7+
throw new Exception("Non bootstrapped library")
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package scala.internal.quoted
2+
3+
import scala.annotation.{Annotation, compileTimeOnly}
4+
import scala.quoted._
5+
6+
@compileTimeOnly("Illegal reference to `scala.internal.quoted.CompileTime`")
7+
object CompileTime {
8+
9+
@compileTimeOnly("Illegal reference to `scala.internal.quoted.CompileTime.exprQuote`")
10+
def exprQuote[T](x: T): QuoteContext ?=> Expr[T] = ???
11+
12+
@compileTimeOnly("Illegal reference to `scala.internal.quoted.CompileTime.exprSplice`")
13+
def exprSplice[T](x: QuoteContext ?=> Expr[T]): T = ???
14+
15+
@compileTimeOnly("Illegal reference to `scala.internal.quoted.CompileTime.exprNestedSplice`")
16+
def exprNestedSplice[T](ctx: QuoteContext)(x: ctx.Nested ?=> Expr[T]): T = ???
17+
18+
@compileTimeOnly("Illegal reference to `scala.internal.quoted.CompileTime.typeQuote`")
19+
def typeQuote[T <: AnyKind]: Type[T] = ???
20+
21+
@compileTimeOnly("Illegal reference to `scala.internal.quoted.CompileTime.patternHole`")
22+
def patternHole[T]: T = ???
23+
24+
@compileTimeOnly("Illegal reference to `scala.internal.quoted.CompileTime.patternBindHole`")
25+
class patternBindHole extends Annotation
26+
27+
@compileTimeOnly("Illegal reference to `scala.internal.quoted.CompileTime.patternType`")
28+
class patternType extends Annotation
29+
30+
@compileTimeOnly("Illegal reference to `scala.internal.quoted.CompileTime.fromAbove`")
31+
class fromAbove extends Annotation
32+
33+
@compileTimeOnly("Illegal reference to `scala.internal.quoted.CompileTime.quoteTypeTag`")
34+
class quoteTypeTag extends Annotation
35+
36+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package scala.quoted
2+
3+
class Expr[+T] private[scala]:
4+
def unseal(using qctx: QuoteContext): qctx.tasty.Term =
5+
throw new Exception("Non bootstrapped library")
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package scala.quoted
2+
3+
trait QuoteContext { self =>
4+
5+
val tasty: scala.tasty.Reflection
6+
7+
type Nested = QuoteContext {
8+
val tasty: self.tasty.type
9+
}
10+
11+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package scala.quoted
2+
3+
class Type[T <: AnyKind] private[scala]:
4+
type `$splice` = T
5+
def unseal(using qctx: QuoteContext): qctx.tasty.TypeTree =
6+
throw new Exception("Non bootstrapped library")

library/src/scala/compiletime/package.scala

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,8 @@ package object compiletime {
3535
* @note only by-name arguments will be displayed as "code".
3636
* Other values may display unintutively.
3737
*/
38-
transparent inline def (inline self: StringContext) code (inline args: Any*): String = ${ codeExpr('self, 'args) }
39-
private def codeExpr(using qctx: QuoteContext)(sc: Expr[StringContext], args: Expr[Seq[Any]]): Expr[String] =
40-
(sc, args) match
41-
case (Expr.StringContext(Consts(parts)), Varargs(args2)) =>
42-
Expr(StringContext(parts: _*).s(args2.map(_.show): _*))
43-
case _ =>
44-
qctx.throwError("compiletime.code must be used as a string interpolator `code\"...\"`")
38+
transparent inline def (inline self: StringContext) code (inline args: Any*): String =
39+
${ dotty.internal.CompileTimeMacros.codeExpr('self, 'args) }
4540

4641
inline def constValueOpt[T]: Option[T] = ???
4742

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)