Skip to content

Commit a5452e8

Browse files
committed
Only compile quoted code in bootstrapped library
This will allow changing the internal representations without having incompatibilities while bootstrapping. Currently, each time one of those occurs we duplicate the file in src-bootstrapped and src-non-bootstrapped while losing the blame history.
1 parent 5d5a3dd commit a5452e8

20 files changed

+42
-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: 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

0 commit comments

Comments
 (0)