diff --git a/compiler/src/dotty/tools/dotc/core/Definitions.scala b/compiler/src/dotty/tools/dotc/core/Definitions.scala index 9486cc1cac30..041b71e4d77f 100644 --- a/compiler/src/dotty/tools/dotc/core/Definitions.scala +++ b/compiler/src/dotty/tools/dotc/core/Definitions.scala @@ -795,11 +795,14 @@ class Definitions { @tu lazy val QuotedExprModule: Symbol = QuotedExprClass.companionModule @tu lazy val QuoteContextClass: ClassSymbol = requiredClass("scala.quoted.QuoteContext") - @tu lazy val QuoteContextInternalClass: ClassSymbol = requiredClass("scala.internal.quoted.QuoteContextInternal") - @tu lazy val QuoteContextInternal_unpickleExpr: Symbol = QuoteContextInternalClass.requiredMethod("unpickleExpr") - @tu lazy val QuoteContextInternal_unpickleType: Symbol = QuoteContextInternalClass.requiredMethod("unpickleType") - @tu lazy val QuoteContextInternal_ExprMatch: Symbol = QuoteContextInternalClass.requiredMethod("ExprMatch") - @tu lazy val QuoteContextInternal_TypeMatch: Symbol = QuoteContextInternalClass.requiredMethod("TypeMatch") + + @tu lazy val QuoteUnpicklerClass: ClassSymbol = requiredClass("scala.quoted.internal.QuoteUnpickler") + @tu lazy val QuoteUnpickler_unpickleExpr: Symbol = QuoteUnpicklerClass.requiredMethod("unpickleExpr") + @tu lazy val QuoteUnpickler_unpickleType: Symbol = QuoteUnpicklerClass.requiredMethod("unpickleType") + + @tu lazy val QuoteMatchingClass: ClassSymbol = requiredClass("scala.quoted.internal.QuoteMatching") + @tu lazy val QuoteMatching_ExprMatch: Symbol = QuoteMatchingClass.requiredMethod("ExprMatch") + @tu lazy val QuoteMatching_TypeMatch: Symbol = QuoteMatchingClass.requiredMethod("TypeMatch") @tu lazy val LiftableModule: Symbol = requiredModule("scala.quoted.Liftable") @tu lazy val LiftableModule_BooleanLiftable: Symbol = LiftableModule.requiredMethod("BooleanLiftable") @@ -812,13 +815,14 @@ class Definitions { @tu lazy val LiftableModule_CharLiftable: Symbol = LiftableModule.requiredMethod("CharLiftable") @tu lazy val LiftableModule_StringLiftable: Symbol = LiftableModule.requiredMethod("StringLiftable") - @tu lazy val InternalQuotedModule: Symbol = requiredModule("scala.internal.quoted.CompileTime") - @tu lazy val InternalQuoted_exprQuote : Symbol = InternalQuotedModule.requiredMethod("exprQuote") - @tu lazy val InternalQuoted_exprSplice : Symbol = InternalQuotedModule.requiredMethod("exprSplice") - @tu lazy val InternalQuoted_exprNestedSplice : Symbol = InternalQuotedModule.requiredMethod("exprNestedSplice") - @tu lazy val InternalQuoted_QuoteTypeTagAnnot: ClassSymbol = InternalQuotedModule.requiredClass("quoteTypeTag") + @tu lazy val InternalQuotedModule: Symbol = requiredModule("scala.quoted.internal.Expr") + @tu lazy val InternalQuoted_exprQuote : Symbol = InternalQuotedModule.requiredMethod("quote") + @tu lazy val InternalQuoted_exprSplice : Symbol = InternalQuotedModule.requiredMethod("splice") + @tu lazy val InternalQuoted_exprNestedSplice : Symbol = InternalQuotedModule.requiredMethod("nestedSplice") + + @tu lazy val InternalQuoted_SplicedTypeAnnot: ClassSymbol = requiredClass("scala.quoted.internal.SplicedType") - @tu lazy val InternalQuotedPatterns: Symbol = requiredModule("scala.internal.quoted.Patterns") + @tu lazy val InternalQuotedPatterns: Symbol = requiredModule("scala.quoted.internal.Patterns") @tu lazy val InternalQuotedPatterns_patternHole: Symbol = InternalQuotedPatterns.requiredMethod("patternHole") @tu lazy val InternalQuotedPatterns_patternHigherOrderHole: Symbol = InternalQuotedPatterns.requiredMethod("patternHigherOrderHole") @tu lazy val InternalQuotedPatterns_higherOrderHole: Symbol = InternalQuotedPatterns.requiredMethod("higherOrderHole") diff --git a/compiler/src/scala/quoted/internal/Expr.scala b/compiler/src/dotty/tools/dotc/quoted/ExprImpl.scala similarity index 87% rename from compiler/src/scala/quoted/internal/Expr.scala rename to compiler/src/dotty/tools/dotc/quoted/ExprImpl.scala index 59dabafa6cc0..291c8d0226f5 100644 --- a/compiler/src/scala/quoted/internal/Expr.scala +++ b/compiler/src/dotty/tools/dotc/quoted/ExprImpl.scala @@ -1,4 +1,4 @@ -package scala.quoted.internal +package dotty.tools.dotc.quoted import scala.quoted._ @@ -11,9 +11,9 @@ import dotty.tools.dotc.ast.tpd * * May contain references to code defined outside this Expr instance. */ -final class Expr(val tree: tpd.Tree, val scopeId: Int) extends scala.quoted.Expr[Any] { +final class ExprImpl(val tree: tpd.Tree, val scopeId: Int) extends scala.quoted.internal.Expr[Any] { override def equals(that: Any): Boolean = that match { - case that: Expr => + case that: ExprImpl => // Expr are wrappers around trees, therefore they are equals if their trees are equal. // All scopeId should be equal unless two different runs of the compiler created the trees. tree == that.tree && scopeId == that.scopeId diff --git a/compiler/src/dotty/tools/dotc/quoted/PickledQuotes.scala b/compiler/src/dotty/tools/dotc/quoted/PickledQuotes.scala index 4b0056b6a2a8..031dfc28beb1 100644 --- a/compiler/src/dotty/tools/dotc/quoted/PickledQuotes.scala +++ b/compiler/src/dotty/tools/dotc/quoted/PickledQuotes.scala @@ -38,14 +38,14 @@ object PickledQuotes { /** Transform the expression into its fully spliced Tree */ def quotedExprToTree[T](expr: quoted.Expr[T])(using Context): Tree = { - val expr1 = expr.asInstanceOf[scala.quoted.internal.Expr] + val expr1 = expr.asInstanceOf[dotty.tools.dotc.quoted.ExprImpl] expr1.checkScopeId(QuoteContextImpl.scopeId) changeOwnerOfTree(expr1.tree, ctx.owner) } /** Transform the expression into its fully spliced TypeTree */ def quotedTypeToTree(tpe: quoted.Type[?])(using Context): Tree = { - val tpe1 = tpe.asInstanceOf[scala.quoted.internal.Type] + val tpe1 = tpe.asInstanceOf[dotty.tools.dotc.quoted.TypeImpl] tpe1.checkScopeId(QuoteContextImpl.scopeId) changeOwnerOfTree(tpe1.typeTree, ctx.owner) } @@ -72,8 +72,8 @@ object PickledQuotes { override def transform(tree: tpd.Tree)(using Context): tpd.Tree = tree match { case Hole(isTerm, idx, args) => val reifiedArgs = args.map { arg => - if (arg.isTerm) (using qctx: QuoteContext) => new scala.quoted.internal.Expr(arg, QuoteContextImpl.scopeId) - else new scala.quoted.internal.Type(arg, QuoteContextImpl.scopeId) + if (arg.isTerm) (using qctx: QuoteContext) => new dotty.tools.dotc.quoted.ExprImpl(arg, QuoteContextImpl.scopeId) + else new dotty.tools.dotc.quoted.TypeImpl(arg, QuoteContextImpl.scopeId) } if isTerm then val quotedExpr = termHole(idx, reifiedArgs, dotty.tools.dotc.quoted.QuoteContextImpl()) @@ -123,10 +123,10 @@ object PickledQuotes { /** Replace all type holes generated with the spliced types */ private def spliceTypes(tree: Tree, typeHole: (Int, Seq[Any]) => scala.quoted.Type[?], termHole: (Int, Seq[Int], scala.quoted.QuoteContext) => Any)(using Context): Tree = { tree match - case Block(stat :: rest, expr1) if stat.symbol.hasAnnotation(defn.InternalQuoted_QuoteTypeTagAnnot) => + case Block(stat :: rest, expr1) if stat.symbol.hasAnnotation(defn.InternalQuoted_SplicedTypeAnnot) => val typeSpliceMap = (stat :: rest).iterator.map { case tdef: TypeDef => - assert(tdef.symbol.hasAnnotation(defn.InternalQuoted_QuoteTypeTagAnnot)) + assert(tdef.symbol.hasAnnotation(defn.InternalQuoted_SplicedTypeAnnot)) val tree = tdef.rhs match case TypeBoundsTree(_, Hole(_, idx, args), _) => val quotedType = typeHole(idx, args) @@ -141,7 +141,7 @@ object PickledQuotes { tp.derivedClassInfo(classParents = tp.classParents.map(apply)) case tp: TypeRef => typeSpliceMap.get(tp.symbol) match - case Some(t) if tp.typeSymbol.hasAnnotation(defn.InternalQuoted_QuoteTypeTagAnnot) => mapOver(t) + case Some(t) if tp.typeSymbol.hasAnnotation(defn.InternalQuoted_SplicedTypeAnnot) => mapOver(t) case _ => mapOver(tp) case _ => mapOver(tp) diff --git a/compiler/src/dotty/tools/dotc/quoted/QuoteContextImpl.scala b/compiler/src/dotty/tools/dotc/quoted/QuoteContextImpl.scala index 63021dac1925..8836d5ab5250 100644 --- a/compiler/src/dotty/tools/dotc/quoted/QuoteContextImpl.scala +++ b/compiler/src/dotty/tools/dotc/quoted/QuoteContextImpl.scala @@ -14,6 +14,7 @@ import dotty.tools.dotc.quoted.QuoteUtils._ import dotty.tools.dotc.core.Decorators._ import scala.quoted.QuoteContext +import scala.quoted.internal.{QuoteUnpickler, QuoteMatching} import dotty.tools.dotc.quoted.printers.{Extractors, SourceCode, SyntaxHighlight} import scala.tasty.reflect._ @@ -40,7 +41,7 @@ object QuoteContextImpl { } -class QuoteContextImpl private (ctx: Context) extends QuoteContext, scala.internal.quoted.QuoteContextInternal: +class QuoteContextImpl private (ctx: Context) extends QuoteContext, QuoteUnpickler, QuoteMatching: object reflect extends scala.tasty.Reflection: @@ -71,7 +72,7 @@ class QuoteContextImpl private (ctx: Context) extends QuoteContext, scala.intern case _ => false def asExpr: scala.quoted.Expr[Any] = if self.isExpr then - new scala.quoted.internal.Expr(self, QuoteContextImpl.this.hashCode) + new dotty.tools.dotc.quoted.ExprImpl(self, QuoteContextImpl.this.hashCode) else self match case TermTypeTest(self) => throw new Exception("Expected an expression. This is a partially applied Term. Try eta-expanding the term first.") case _ => throw new Exception("Expected a Term but was: " + self) @@ -315,11 +316,11 @@ class QuoteContextImpl private (ctx: Context) extends QuoteContext, scala.intern object TermMethodsImpl extends TermMethods: extension (self: Term): def seal: scala.quoted.Expr[Any] = - if self.isExpr then new scala.quoted.internal.Expr(self, QuoteContextImpl.this.hashCode) + if self.isExpr then new dotty.tools.dotc.quoted.ExprImpl(self, QuoteContextImpl.this.hashCode) else throw new Exception("Cannot seal a partially applied Term. Try eta-expanding the term first.") def sealOpt: Option[scala.quoted.Expr[Any]] = - if self.isExpr then Some(new scala.quoted.internal.Expr(self, QuoteContextImpl.this.hashCode)) + if self.isExpr then Some(new dotty.tools.dotc.quoted.ExprImpl(self, QuoteContextImpl.this.hashCode)) else None def tpe: TypeRepr = self.tpe @@ -1002,7 +1003,7 @@ class QuoteContextImpl private (ctx: Context) extends QuoteContext, scala.intern object TypeTree extends TypeTreeModule: def of[T <: AnyKind](using tp: scala.quoted.Type[T]): TypeTree = - tp.asInstanceOf[scala.quoted.internal.Type].typeTree + tp.asInstanceOf[dotty.tools.dotc.quoted.TypeImpl].typeTree end TypeTree object TypeTreeMethodsImpl extends TypeTreeMethods: @@ -1571,7 +1572,7 @@ class QuoteContextImpl private (ctx: Context) extends QuoteContext, scala.intern object TypeRepr extends TypeReprModule: def of[T <: AnyKind](using tp: scala.quoted.Type[T]): TypeRepr = - tp.asInstanceOf[scala.quoted.internal.Type].typeTree.tpe + tp.asInstanceOf[dotty.tools.dotc.quoted.TypeImpl].typeTree.tpe def typeConstructorOf(clazz: Class[?]): TypeRepr = if (clazz.isPrimitive) if (clazz == classOf[Boolean]) dotc.core.Symbols.defn.BooleanType @@ -1608,7 +1609,7 @@ class QuoteContextImpl private (ctx: Context) extends QuoteContext, scala.intern def seal: scala.quoted.Type[_] = self.asType def asType: scala.quoted.Type[?] = - new scala.quoted.internal.Type(Inferred(self), QuoteContextImpl.this.hashCode) + new dotty.tools.dotc.quoted.TypeImpl(Inferred(self), QuoteContextImpl.this.hashCode) def =:=(that: TypeRepr): Boolean = self =:= that def <:<(that: TypeRepr): Boolean = self <:< that @@ -2623,11 +2624,11 @@ class QuoteContextImpl private (ctx: Context) extends QuoteContext, scala.intern def unpickleExpr[T](pickled: String | List[String], typeHole: (Int, Seq[Any]) => scala.quoted.Type[?], termHole: (Int, Seq[Any], scala.quoted.QuoteContext) => scala.quoted.Expr[?]): scala.quoted.Expr[T] = val tree = PickledQuotes.unpickleTerm(pickled, typeHole, termHole)(using reflect.rootContext) - new scala.quoted.internal.Expr(tree, hash).asInstanceOf[scala.quoted.Expr[T]] + new dotty.tools.dotc.quoted.ExprImpl(tree, hash).asInstanceOf[scala.quoted.Expr[T]] def unpickleType[T <: AnyKind](pickled: String | List[String], typeHole: (Int, Seq[Any]) => scala.quoted.Type[?], termHole: (Int, Seq[Any], scala.quoted.QuoteContext) => scala.quoted.Expr[?]): scala.quoted.Type[T] = val tree = PickledQuotes.unpickleTypeTree(pickled, typeHole, termHole)(using reflect.rootContext) - new scala.quoted.internal.Type(tree, hash).asInstanceOf[scala.quoted.Type[T]] + new dotty.tools.dotc.quoted.TypeImpl(tree, hash).asInstanceOf[scala.quoted.Type[T]] object ExprMatch extends ExprMatchModule: def unapply[TypeBindings <: Tuple, Tup <: Tuple](scrutinee: scala.quoted.Expr[Any])(using pattern: scala.quoted.Expr[Any]): Option[Tup] = diff --git a/compiler/src/scala/quoted/internal/ScopeException.scala b/compiler/src/dotty/tools/dotc/quoted/ScopeException.scala similarity index 64% rename from compiler/src/scala/quoted/internal/ScopeException.scala rename to compiler/src/dotty/tools/dotc/quoted/ScopeException.scala index e99c77ffb727..06fe129868fa 100644 --- a/compiler/src/scala/quoted/internal/ScopeException.scala +++ b/compiler/src/dotty/tools/dotc/quoted/ScopeException.scala @@ -1,3 +1,3 @@ -package scala.quoted.internal +package dotty.tools.dotc.quoted class ScopeException(msg: String) extends Exception(msg) diff --git a/compiler/src/scala/quoted/internal/Type.scala b/compiler/src/dotty/tools/dotc/quoted/TypeImpl.scala similarity index 84% rename from compiler/src/scala/quoted/internal/Type.scala rename to compiler/src/dotty/tools/dotc/quoted/TypeImpl.scala index 9eb3c1f55b28..879d5d5e1a9d 100644 --- a/compiler/src/scala/quoted/internal/Type.scala +++ b/compiler/src/dotty/tools/dotc/quoted/TypeImpl.scala @@ -1,13 +1,13 @@ -package scala.quoted.internal +package dotty.tools.dotc.quoted import scala.quoted._ import dotty.tools.dotc.ast.tpd /** Quoted type (or kind) `T` backed by a tree */ -final class Type(val typeTree: tpd.Tree, val scopeId: Int) extends scala.quoted.Type[?] { +final class TypeImpl(val typeTree: tpd.Tree, val scopeId: Int) extends scala.quoted.internal.Type[?] { override def equals(that: Any): Boolean = that match { - case that: Type => typeTree == + case that: TypeImpl => typeTree == // TastyTreeExpr are wrappers around trees, therfore they are equals if their trees are equal. // All scopeId should be equal unless two different runs of the compiler created the trees. that.typeTree && scopeId == that.scopeId diff --git a/compiler/src/dotty/tools/dotc/transform/PCPCheckAndHeal.scala b/compiler/src/dotty/tools/dotc/transform/PCPCheckAndHeal.scala index 1db2becdcbde..ebab312e33eb 100644 --- a/compiler/src/dotty/tools/dotc/transform/PCPCheckAndHeal.scala +++ b/compiler/src/dotty/tools/dotc/transform/PCPCheckAndHeal.scala @@ -174,7 +174,7 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages( tp match case tp: TypeRef => tp.prefix match - case NoPrefix if level > levelOf(tp.symbol) && !tp.typeSymbol.hasAnnotation(defn.InternalQuoted_QuoteTypeTagAnnot) => + case NoPrefix if level > levelOf(tp.symbol) && !tp.typeSymbol.hasAnnotation(defn.InternalQuoted_SplicedTypeAnnot) => val tp1 = tp.dealias if tp1 != tp then apply(tp1) else tryHeal(tp.symbol, tp, pos) @@ -279,7 +279,7 @@ object PCPCheckAndHeal { flags = Synthetic, info = TypeAlias(splicedTree.tpe.select(tpnme.Underlying)), coord = span).asType - local.addAnnotation(Annotation(defn.InternalQuoted_QuoteTypeTagAnnot)) + local.addAnnotation(Annotation(defn.InternalQuoted_SplicedTypeAnnot)) ctx.typeAssigner.assignType(untpd.TypeDef(local.name, alias), local) } diff --git a/compiler/src/dotty/tools/dotc/transform/PickleQuotes.scala b/compiler/src/dotty/tools/dotc/transform/PickleQuotes.scala index 33b28d4435ff..55f2257eadc0 100644 --- a/compiler/src/dotty/tools/dotc/transform/PickleQuotes.scala +++ b/compiler/src/dotty/tools/dotc/transform/PickleQuotes.scala @@ -82,7 +82,7 @@ class PickleQuotes extends MacroTransform { assert(!tree.symbol.isQuote) assert(!tree.symbol.isExprSplice) case _ : TypeDef => - assert(!tree.symbol.hasAnnotation(defn.InternalQuoted_QuoteTypeTagAnnot), + assert(!tree.symbol.hasAnnotation(defn.InternalQuoted_SplicedTypeAnnot), s"${tree.symbol} should have been removed by PickledQuotes because it has a @quoteTypeTag") case _ => } @@ -193,11 +193,11 @@ class PickleQuotes extends MacroTransform { } } - /** Encode quote using QuoteContextInternal.{unpickleExpr, unpickleType} + /** Encode quote using QuoteUnpickler.{unpickleExpr, unpickleType} * * Generate the code * ```scala - * qctx => qctx.asInstanceOf[QuoteContextInternal].[]( + * qctx => qctx.asInstanceOf[QuoteUnpickler].[]( * , * , * , @@ -255,8 +255,8 @@ class PickleQuotes extends MacroTransform { val quotedType = quoteClass.typeRef.appliedTo(originalTp) val lambdaTpe = MethodType(defn.QuoteContextClass.typeRef :: Nil, quotedType) def callUnpickle(ts: List[Tree]) = { - val qctx = ts.head.asInstance(defn.QuoteContextInternalClass.typeRef) - val unpickleMeth = if isType then defn.QuoteContextInternal_unpickleType else defn.QuoteContextInternal_unpickleExpr + val qctx = ts.head.asInstance(defn.QuoteUnpicklerClass.typeRef) + val unpickleMeth = if isType then defn.QuoteUnpickler_unpickleType else defn.QuoteUnpickler_unpickleExpr qctx.select(unpickleMeth).appliedToType(originalTp).appliedTo(pickledQuoteStrings, typeHoles, termHoles) } Lambda(lambdaTpe, callUnpickle).withSpan(body.span) diff --git a/compiler/src/dotty/tools/dotc/transform/Splicer.scala b/compiler/src/dotty/tools/dotc/transform/Splicer.scala index ef9840ebe27c..94838b7fb5d2 100644 --- a/compiler/src/dotty/tools/dotc/transform/Splicer.scala +++ b/compiler/src/dotty/tools/dotc/transform/Splicer.scala @@ -323,10 +323,10 @@ object Splicer { } private def interpretQuote(tree: Tree)(implicit env: Env): Object = - new scala.quoted.internal.Expr(Inlined(EmptyTree, Nil, QuoteUtils.changeOwnerOfTree(tree, ctx.owner)).withSpan(tree.span), QuoteContextImpl.scopeId) + new dotty.tools.dotc.quoted.ExprImpl(Inlined(EmptyTree, Nil, QuoteUtils.changeOwnerOfTree(tree, ctx.owner)).withSpan(tree.span), QuoteContextImpl.scopeId) private def interpretTypeQuote(tree: Tree)(implicit env: Env): Object = - new scala.quoted.internal.Type(QuoteUtils.changeOwnerOfTree(tree, ctx.owner), QuoteContextImpl.scopeId) + new dotty.tools.dotc.quoted.TypeImpl(QuoteUtils.changeOwnerOfTree(tree, ctx.owner), QuoteContextImpl.scopeId) private def interpretLiteral(value: Any)(implicit env: Env): Object = value.asInstanceOf[Object] diff --git a/compiler/src/dotty/tools/dotc/transform/Staging.scala b/compiler/src/dotty/tools/dotc/transform/Staging.scala index 1fa3231cf1ef..068d6f9e28ad 100644 --- a/compiler/src/dotty/tools/dotc/transform/Staging.scala +++ b/compiler/src/dotty/tools/dotc/transform/Staging.scala @@ -49,7 +49,7 @@ class Staging extends MacroTransform { else i"${sym.name}.this" val errMsg = s"\nin ${ctx.owner.fullName}" assert( - ctx.owner.hasAnnotation(defn.InternalQuoted_QuoteTypeTagAnnot) || + ctx.owner.hasAnnotation(defn.InternalQuoted_SplicedTypeAnnot) || (sym.isType && levelOf(sym) > 0), em"""access to $symStr from wrong staging level: | - the definition is at level ${levelOf(sym)}, diff --git a/compiler/src/dotty/tools/dotc/typer/QuotesAndSplices.scala b/compiler/src/dotty/tools/dotc/typer/QuotesAndSplices.scala index e7cd634fd42c..c3d7492668a9 100644 --- a/compiler/src/dotty/tools/dotc/typer/QuotesAndSplices.scala +++ b/compiler/src/dotty/tools/dotc/typer/QuotesAndSplices.scala @@ -463,8 +463,8 @@ trait QuotesAndSplices { if (tree.quoted.isTerm) ref(defn.InternalQuoted_exprQuote.termRef).appliedToType(defn.AnyType).appliedTo(shape).select(nme.apply).appliedTo(qctx) else ref(defn.QuotedTypeModule_apply.termRef).appliedToTypeTree(shape).select(nme.apply).appliedTo(qctx) - val matchModule = if tree.quoted.isTerm then defn.QuoteContextInternal_ExprMatch else defn.QuoteContextInternal_TypeMatch - val unapplyFun = qctx.asInstance(defn.QuoteContextInternalClass.typeRef).select(matchModule).select(nme.unapply) + val matchModule = if tree.quoted.isTerm then defn.QuoteMatching_ExprMatch else defn.QuoteMatching_TypeMatch + val unapplyFun = qctx.asInstance(defn.QuoteMatchingClass.typeRef).select(matchModule).select(nme.unapply) UnApply( fun = unapplyFun.appliedToTypeTrees(typeBindingsTuple :: TypeTree(patType) :: Nil), diff --git a/library/src-bootstrapped/scala/internal/quoted/CompileTime.scala b/library/src-bootstrapped/scala/internal/quoted/CompileTime.scala deleted file mode 100644 index d7034b80b8a3..000000000000 --- a/library/src-bootstrapped/scala/internal/quoted/CompileTime.scala +++ /dev/null @@ -1,34 +0,0 @@ -package scala.internal.quoted - -import scala.annotation.{Annotation, compileTimeOnly} -import scala.quoted._ - -@compileTimeOnly("Illegal reference to `scala.internal.quoted.CompileTime`") -object CompileTime { - - /** A term quote is desugared by the compiler into a call to this method */ - @compileTimeOnly("Illegal reference to `scala.internal.quoted.CompileTime.exprQuote`") - def exprQuote[T](x: T): QuoteContext ?=> Expr[T] = ??? - - /** A term splice is desugared by the compiler into a call to this method */ - @compileTimeOnly("Illegal reference to `scala.internal.quoted.CompileTime.exprSplice`") - def exprSplice[T](x: QuoteContext ?=> Expr[T]): T = ??? - - /** A term splice nested within a quote is desugared by the compiler into a call to this method. - * `ctx` is the `QuoteContext` that the quote of this splice uses. - */ - @compileTimeOnly("Illegal reference to `scala.internal.quoted.CompileTime.exprNestedSplice`") - def exprNestedSplice[T](ctx: QuoteContext)(x: ctx.Nested ?=> Expr[T]): T = ??? - - /** Artifact of pickled type splices - * - * During quote reification a quote `'{ ... F[$t] ... }` will be transformed into - * `'{ @quoteTypeTag type T$1 = $t ... F[T$1] ... }` to have a tree for `$t`. - * This artifact is removed during quote unpickling. - * - * See PickleQuotes.scala and PickledQuotes.scala - */ - @compileTimeOnly("Illegal reference to `scala.internal.quoted.CompileTime.quoteTypeTag`") - class quoteTypeTag extends Annotation - -} diff --git a/library/src-bootstrapped/scala/quoted/Expr.scala b/library/src-bootstrapped/scala/quoted/Expr.scala index cfc9fa60e319..55dd61a1580c 100644 --- a/library/src-bootstrapped/scala/quoted/Expr.scala +++ b/library/src-bootstrapped/scala/quoted/Expr.scala @@ -18,7 +18,7 @@ abstract class Expr[+T] private[scala] { * ``` */ final def matches(that: Expr[Any])(using qctx: QuoteContext): Boolean = - val ExprMatch = qctx.asInstanceOf[scala.internal.quoted.QuoteContextInternal].ExprMatch + val ExprMatch = qctx.asInstanceOf[scala.quoted.internal.QuoteMatching].ExprMatch ExprMatch.unapply[EmptyTuple, EmptyTuple](this)(using that).nonEmpty /** Checks is the `quoted.Expr[?]` is valid expression of type `X` */ diff --git a/library/src-non-bootstrapped/scala/quoted/QuoteContext.scala b/library/src-non-bootstrapped/scala/quoted/QuoteContext.scala deleted file mode 100644 index af4c41edc9cd..000000000000 --- a/library/src-non-bootstrapped/scala/quoted/QuoteContext.scala +++ /dev/null @@ -1,11 +0,0 @@ -package scala.quoted - -trait QuoteContext { self => - - val reflect: scala.tasty.Reflection - - type Nested = QuoteContext { - val reflect: self.reflect.type - } - -} diff --git a/library/src-bootstrapped/scala/quoted/QuoteContext.scala b/library/src/scala/quoted/QuoteContext.scala similarity index 94% rename from library/src-bootstrapped/scala/quoted/QuoteContext.scala rename to library/src/scala/quoted/QuoteContext.scala index 11aea9b36104..dd6d5bd78b61 100644 --- a/library/src-bootstrapped/scala/quoted/QuoteContext.scala +++ b/library/src/scala/quoted/QuoteContext.scala @@ -8,7 +8,7 @@ package scala.quoted * * @param tasty Typed AST API. Usage: `def f(qctx: QuoteContext) = { import qctx.reflect._; ... }`. */ -trait QuoteContext { self => +trait QuoteContext { self: internal.QuoteUnpickler & internal.QuoteMatching => /** Low-level Typed AST API metaprogramming API. * This API does not have the static type guarantiees that `Expr` and `Type` provide. diff --git a/library/src/scala/quoted/internal/Expr.scala b/library/src/scala/quoted/internal/Expr.scala new file mode 100644 index 000000000000..2109c0a9e675 --- /dev/null +++ b/library/src/scala/quoted/internal/Expr.scala @@ -0,0 +1,24 @@ +package scala.quoted +package internal + +import scala.annotation.{Annotation, compileTimeOnly} + +/** Implementation of scala.quoted.Expr that sould only be extended by the implementation of `QuoteContext` */ +abstract class Expr[+T] extends scala.quoted.Expr[T] + +@compileTimeOnly("Illegal reference to `scala.quoted.internal.Expr`") +object Expr: + + /** A term quote is desugared by the compiler into a call to this method */ + @compileTimeOnly("Illegal reference to `scala.quoted.internal.Expr.quote`") + def quote[T](x: T): QuoteContext ?=> scala.quoted.Expr[T] = ??? + + /** A term splice is desugared by the compiler into a call to this method */ + @compileTimeOnly("Illegal reference to `scala.quoted.internal.Expr.splice`") + def splice[T](x: QuoteContext ?=> scala.quoted.Expr[T]): T = ??? + + /** A term splice nested within a quote is desugared by the compiler into a call to this method. + * `ctx` is the `QuoteContext` that the quote of this splice uses. + */ + @compileTimeOnly("Illegal reference to `scala.quoted.internal.Expr.nestedSplice`") + def nestedSplice[T](ctx: QuoteContext)(x: ctx.Nested ?=> scala.quoted.Expr[T]): T = ??? diff --git a/library/src-bootstrapped/scala/internal/quoted/Patterns.scala b/library/src/scala/quoted/internal/Patterns.scala similarity index 67% rename from library/src-bootstrapped/scala/internal/quoted/Patterns.scala rename to library/src/scala/quoted/internal/Patterns.scala index fa5d11f6cdf5..4466be13de4c 100644 --- a/library/src-bootstrapped/scala/internal/quoted/Patterns.scala +++ b/library/src/scala/quoted/internal/Patterns.scala @@ -1,27 +1,28 @@ -package scala.internal.quoted +package scala.quoted.internal import scala.annotation.{Annotation, compileTimeOnly} +@compileTimeOnly("Illegal reference to `scala.quoted.internal.Patterns`") object Patterns { /** A splice in a quoted pattern is desugared by the compiler into a call to this method */ - @compileTimeOnly("Illegal reference to `scala.internal.quoted.Patterns.patternHole`") + @compileTimeOnly("Illegal reference to `scala.quoted.internal.Patterns.patternHole`") def patternHole[T]: T = ??? - @compileTimeOnly("Illegal reference to `scala.internal.quoted.Patterns.patternHigherOrderHole`") + @compileTimeOnly("Illegal reference to `scala.quoted.internal.Patterns.patternHigherOrderHole`") /** A higher order splice in a quoted pattern is desugared by the compiler into a call to this method */ def patternHigherOrderHole[U](pat: Any, args: Any*): U = ??? - @compileTimeOnly("Illegal reference to `scala.internal.quoted.Patterns.higherOrderHole`") + @compileTimeOnly("Illegal reference to `scala.quoted.internal.Patterns.higherOrderHole`") /** A higher order splice in a quoted pattern is desugared by the compiler into a call to this method */ def higherOrderHole[U](args: Any*): U = ??? /** A splice of a name in a quoted pattern is that marks the definition of a type splice */ - @compileTimeOnly("Illegal reference to `scala.internal.quoted.Patterns.patternType`") + @compileTimeOnly("Illegal reference to `scala.quoted.internal.Patterns.patternType`") class patternType extends Annotation /** A type pattern that must be aproximated from above */ - @compileTimeOnly("Illegal reference to `scala.internal.quoted.Patterns.fromAbove`") + @compileTimeOnly("Illegal reference to `scala.quoted.internal.Patterns.fromAbove`") class fromAbove extends Annotation } diff --git a/library/src/scala/internal/quoted/QuoteContextInternal.scala b/library/src/scala/quoted/internal/QuoteMatching.scala similarity index 75% rename from library/src/scala/internal/quoted/QuoteContextInternal.scala rename to library/src/scala/quoted/internal/QuoteMatching.scala index 62e4b62fed6e..f86d2e04d468 100644 --- a/library/src/scala/internal/quoted/QuoteContextInternal.scala +++ b/library/src/scala/quoted/internal/QuoteMatching.scala @@ -1,20 +1,10 @@ -package scala.internal.quoted +package scala.quoted.internal import scala.quoted.{QuoteContext, Expr, Type} import scala.tasty.reflect._ /** Part of the QuoteContext interface that needs to be implemented by the compiler but is not visible to users */ -trait QuoteContextInternal { self: QuoteContext => - - /** Unpickle `repr` which represents a pickled `Expr` tree, - * replacing splice nodes with `holes` - */ - def unpickleExpr[T](pickled: String | List[String], typeHole: (Int, Seq[Any]) => Type[?], termHole: (Int, Seq[Any], QuoteContext) => Expr[?]): scala.quoted.Expr[T] - - /** Unpickle `repr` which represents a pickled `Type` tree, - * replacing splice nodes with `holes` - */ - def unpickleType[T <: AnyKind](pickled: String | List[String], typeHole: (Int, Seq[Any]) => Type[?], termHole: (Int, Seq[Any], QuoteContext) => Expr[?]): scala.quoted.Type[T] +trait QuoteMatching { self: QuoteContext & QuoteUnpickler => val ExprMatch: ExprMatchModule @@ -31,7 +21,7 @@ trait QuoteContextInternal { self: QuoteContext => * will return `None` due to the missmatch of types in the hole * * Holes: - * - scala.internal.quoted.Patterns.patternHole[T]: hole that matches an expression `x` of type `Expr[U]` + * - scala.quoted.internal.Patterns.patternHole[T]: hole that matches an expression `x` of type `Expr[U]` * if `U <:< T` and returns `x` as part of the match. * * @param scrutinee `Expr[Any]` on which we are pattern matching diff --git a/library/src/scala/quoted/internal/QuoteUnpickler.scala b/library/src/scala/quoted/internal/QuoteUnpickler.scala new file mode 100644 index 000000000000..bed13d0ac901 --- /dev/null +++ b/library/src/scala/quoted/internal/QuoteUnpickler.scala @@ -0,0 +1,19 @@ +package scala.quoted.internal + +import scala.quoted.{QuoteContext, Expr, Type} +import scala.tasty.reflect._ + +/** Part of the QuoteContext interface that needs to be implemented by the compiler but is not visible to users */ +trait QuoteUnpickler { self: QuoteContext & QuoteMatching => + + /** Unpickle `repr` which represents a pickled `Expr` tree, + * replacing splice nodes with `holes` + */ + def unpickleExpr[T](pickled: String | List[String], typeHole: (Int, Seq[Any]) => Type[?], termHole: (Int, Seq[Any], QuoteContext) => Expr[?]): scala.quoted.Expr[T] + + /** Unpickle `repr` which represents a pickled `Type` tree, + * replacing splice nodes with `holes` + */ + def unpickleType[T <: AnyKind](pickled: String | List[String], typeHole: (Int, Seq[Any]) => Type[?], termHole: (Int, Seq[Any], QuoteContext) => Expr[?]): scala.quoted.Type[T] + +} diff --git a/library/src/scala/quoted/internal/SplicedType.scala b/library/src/scala/quoted/internal/SplicedType.scala new file mode 100644 index 000000000000..3dc0a6e7f4d0 --- /dev/null +++ b/library/src/scala/quoted/internal/SplicedType.scala @@ -0,0 +1,14 @@ +package scala.quoted.internal + +import scala.annotation.{Annotation, compileTimeOnly} + +/** Artifact of pickled type splices + * + * During quote reification a quote `'{ ... F[t.Underlying] ... }` will be transformed into + * `'{ @SplicedType type T$1 = t.Underlying ... F[T$1] ... }` to have a tree for `t.Underlying`. + * This artifact is removed during quote unpickling. + * + * See PickleQuotes.scala and PickledQuotes.scala + */ +@compileTimeOnly("Illegal reference to `scala.quoted.internal.SplicedType`") +class SplicedType extends Annotation diff --git a/library/src/scala/quoted/internal/Type.scala b/library/src/scala/quoted/internal/Type.scala new file mode 100644 index 000000000000..2e4885e66387 --- /dev/null +++ b/library/src/scala/quoted/internal/Type.scala @@ -0,0 +1,4 @@ +package scala.quoted.internal + +/** Implementation of scala.quoted.Type that sould only be extended by the implementation of `QuoteContext` */ +abstract class Type[T <: AnyKind] extends scala.quoted.Type[T] diff --git a/staging/src/scala/quoted/staging/Toolbox.scala b/staging/src/scala/quoted/staging/Toolbox.scala index f9d5f8faa05e..9cb3fb00b604 100644 --- a/staging/src/scala/quoted/staging/Toolbox.scala +++ b/staging/src/scala/quoted/staging/Toolbox.scala @@ -3,7 +3,7 @@ package staging import scala.annotation.implicitNotFound -import scala.quoted.internal.ScopeException +import dotty.tools.dotc.quoted.ScopeException @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") trait Toolbox: diff --git a/tests/run-macros/quote-matcher-runtime.check b/tests/run-macros/quote-matcher-runtime.check index 4d7ae84f19b7..7a34f53bb661 100644 --- a/tests/run-macros/quote-matcher-runtime.check +++ b/tests/run-macros/quote-matcher-runtime.check @@ -19,55 +19,55 @@ Pattern: (1: scala.Int) Result: Some(List()) Scrutinee: 3 -Pattern: scala.internal.quoted.Patterns.patternHole[scala.Int] +Pattern: scala.quoted.internal.Patterns.patternHole[scala.Int] Result: Some(List(Expr(3))) Scrutinee: x -Pattern: scala.internal.quoted.Patterns.patternHole[scala.Int] +Pattern: scala.quoted.internal.Patterns.patternHole[scala.Int] Result: Some(List(Expr(x))) Scrutinee: 5 -Pattern: scala.internal.quoted.Patterns.patternHole[scala.Any] +Pattern: scala.quoted.internal.Patterns.patternHole[scala.Any] Result: Some(List(Expr(5))) Scrutinee: 6.+(x) -Pattern: scala.internal.quoted.Patterns.patternHole[scala.Int] +Pattern: scala.quoted.internal.Patterns.patternHole[scala.Int] Result: Some(List(Expr(6.+(x)))) Scrutinee: 6.+(x) -Pattern: 6.+(scala.internal.quoted.Patterns.patternHole[scala.Int]) +Pattern: 6.+(scala.quoted.internal.Patterns.patternHole[scala.Int]) Result: Some(List(Expr(x))) Scrutinee: 6.+(x) -Pattern: scala.internal.quoted.Patterns.patternHole[scala.Int].+(x) +Pattern: scala.quoted.internal.Patterns.patternHole[scala.Int].+(x) Result: Some(List(Expr(6))) Scrutinee: 6.+(x) -Pattern: scala.internal.quoted.Patterns.patternHole[scala.Int].+(scala.internal.quoted.Patterns.patternHole[scala.Int]) +Pattern: scala.quoted.internal.Patterns.patternHole[scala.Int].+(scala.quoted.internal.Patterns.patternHole[scala.Int]) Result: Some(List(Expr(6), Expr(x))) Scrutinee: 6.+(x).+(y) -Pattern: 6.+(scala.internal.quoted.Patterns.patternHole[scala.Int]).+(y) +Pattern: 6.+(scala.quoted.internal.Patterns.patternHole[scala.Int]).+(y) Result: Some(List(Expr(x))) Scrutinee: 4 -Pattern: scala.internal.quoted.Patterns.patternHole[scala.Predef.String] +Pattern: scala.quoted.internal.Patterns.patternHole[scala.Predef.String] Result: None Scrutinee: 6.+(x) -Pattern: 7.+(scala.internal.quoted.Patterns.patternHole[scala.Int]) +Pattern: 7.+(scala.quoted.internal.Patterns.patternHole[scala.Int]) Result: None Scrutinee: 6.+(x) -Pattern: scala.internal.quoted.Patterns.patternHole[scala.Int].+(4) +Pattern: scala.quoted.internal.Patterns.patternHole[scala.Int].+(4) Result: None Scrutinee: g[scala.Int] -Pattern: scala.internal.quoted.Patterns.patternHole[scala.Predef.String] +Pattern: scala.quoted.internal.Patterns.patternHole[scala.Predef.String] Result: None Scrutinee: h[scala.Int](7) -Pattern: h[scala.Predef.String](scala.internal.quoted.Patterns.patternHole[scala.Predef.String]) +Pattern: h[scala.Predef.String](scala.quoted.internal.Patterns.patternHole[scala.Predef.String]) Result: None Scrutinee: h[scala.Int](6) @@ -83,23 +83,23 @@ Pattern: z2 = 4 Result: None Scrutinee: f(4) -Pattern: scala.internal.quoted.Patterns.patternHole[scala.Int] +Pattern: scala.quoted.internal.Patterns.patternHole[scala.Int] Result: Some(List(Expr(f(4)))) Scrutinee: f(5) -Pattern: f(scala.internal.quoted.Patterns.patternHole[scala.Int]) +Pattern: f(scala.quoted.internal.Patterns.patternHole[scala.Int]) Result: Some(List(Expr(5))) Scrutinee: g[scala.Int] -Pattern: scala.internal.quoted.Patterns.patternHole[scala.Int] +Pattern: scala.quoted.internal.Patterns.patternHole[scala.Int] Result: Some(List(Expr(g[scala.Int]))) Scrutinee: h[scala.Int](7) -Pattern: scala.internal.quoted.Patterns.patternHole[scala.Int] +Pattern: scala.quoted.internal.Patterns.patternHole[scala.Int] Result: Some(List(Expr(h[scala.Int](7)))) Scrutinee: h[scala.Int](8) -Pattern: h[scala.Int](scala.internal.quoted.Patterns.patternHole[scala.Int]) +Pattern: h[scala.Int](scala.quoted.internal.Patterns.patternHole[scala.Int]) Result: Some(List(Expr(8))) Scrutinee: Test.this @@ -107,7 +107,7 @@ Pattern: Test.this Result: Some(List()) Scrutinee: Test.this -Pattern: scala.internal.quoted.Patterns.patternHole[this.type] +Pattern: scala.quoted.internal.Patterns.patternHole[this.type] Result: Some(List(Expr(Test.this))) Scrutinee: new Foo(1) @@ -115,11 +115,11 @@ Pattern: new Foo(1) Result: Some(List()) Scrutinee: new Foo(1) -Pattern: scala.internal.quoted.Patterns.patternHole[Foo] +Pattern: scala.quoted.internal.Patterns.patternHole[Foo] Result: Some(List(Expr(new Foo(1)))) Scrutinee: new Foo(1) -Pattern: new Foo(scala.internal.quoted.Patterns.patternHole[scala.Int]) +Pattern: new Foo(scala.quoted.internal.Patterns.patternHole[scala.Int]) Result: Some(List(Expr(1))) Scrutinee: if (b) x else y @@ -127,11 +127,11 @@ Pattern: if (b) x else y Result: Some(List()) Scrutinee: if (b) x else y -Pattern: scala.internal.quoted.Patterns.patternHole[scala.Int] +Pattern: scala.quoted.internal.Patterns.patternHole[scala.Int] Result: Some(List(Expr(if (b) x else y))) Scrutinee: if (b) x else y -Pattern: if (scala.internal.quoted.Patterns.patternHole[scala.Boolean]) scala.internal.quoted.Patterns.patternHole[scala.Int] else scala.internal.quoted.Patterns.patternHole[scala.Int] +Pattern: if (scala.quoted.internal.Patterns.patternHole[scala.Boolean]) scala.quoted.internal.Patterns.patternHole[scala.Int] else scala.quoted.internal.Patterns.patternHole[scala.Int] Result: Some(List(Expr(b), Expr(x), Expr(y))) Scrutinee: while (b) { @@ -148,7 +148,7 @@ Scrutinee: while (b) { x () } -Pattern: scala.internal.quoted.Patterns.patternHole[scala.Unit] +Pattern: scala.quoted.internal.Patterns.patternHole[scala.Unit] Result: Some(List(Expr(while (b) { x () @@ -158,8 +158,8 @@ Scrutinee: while (b) { x () } -Pattern: while (scala.internal.quoted.Patterns.patternHole[scala.Boolean]) { - scala.internal.quoted.Patterns.patternHole[scala.Int] +Pattern: while (scala.quoted.internal.Patterns.patternHole[scala.Boolean]) { + scala.quoted.internal.Patterns.patternHole[scala.Int] () } Result: Some(List(Expr(b), Expr(x))) @@ -169,11 +169,11 @@ Pattern: z = 4 Result: Some(List()) Scrutinee: z = 4 -Pattern: scala.internal.quoted.Patterns.patternHole[scala.Unit] +Pattern: scala.quoted.internal.Patterns.patternHole[scala.Unit] Result: Some(List(Expr(z = 4))) Scrutinee: z = 4 -Pattern: z = scala.internal.quoted.Patterns.patternHole[scala.Int] +Pattern: z = scala.quoted.internal.Patterns.patternHole[scala.Int] Result: Some(List(Expr(4))) Scrutinee: 1 @@ -189,7 +189,7 @@ Pattern: fs() Result: Some(List()) Scrutinee: fs() -Pattern: fs(scala.internal.quoted.Patterns.patternHole[scala.Seq[scala.Int]]: _*) +Pattern: fs(scala.quoted.internal.Patterns.patternHole[scala.Seq[scala.Int]]: _*) Result: Some(List(Expr())) Scrutinee: fs(1, 2, 3) @@ -197,11 +197,11 @@ Pattern: fs(1, 2, 3) Result: Some(List()) Scrutinee: fs(1, 2, 3) -Pattern: fs(scala.internal.quoted.Patterns.patternHole[scala.Int], scala.internal.quoted.Patterns.patternHole[scala.Int], 3) +Pattern: fs(scala.quoted.internal.Patterns.patternHole[scala.Int], scala.quoted.internal.Patterns.patternHole[scala.Int], 3) Result: Some(List(Expr(1), Expr(2))) Scrutinee: fs(1, 2, 3) -Pattern: fs(scala.internal.quoted.Patterns.patternHole[scala.Seq[scala.Int]]: _*) +Pattern: fs(scala.quoted.internal.Patterns.patternHole[scala.Seq[scala.Int]]: _*) Result: Some(List(Expr(1, 2, 3))) Scrutinee: f2(1, 2) @@ -213,7 +213,7 @@ Pattern: f2(a = 1, b = 2) Result: Some(List()) Scrutinee: f2(a = 1, b = 2) -Pattern: f2(a = scala.internal.quoted.Patterns.patternHole[scala.Int], b = scala.internal.quoted.Patterns.patternHole[scala.Int]) +Pattern: f2(a = scala.quoted.internal.Patterns.patternHole[scala.Int], b = scala.quoted.internal.Patterns.patternHole[scala.Int]) Result: Some(List(Expr(1), Expr(2))) Scrutinee: super.toString() @@ -221,23 +221,23 @@ Pattern: super.toString() Result: Some(List()) Scrutinee: (() => "abc") -Pattern: scala.internal.quoted.Patterns.patternHole[scala.Function0[scala.Predef.String]] +Pattern: scala.quoted.internal.Patterns.patternHole[scala.Function0[scala.Predef.String]] Result: Some(List(Expr((() => "abc")))) Scrutinee: (() => "abc").apply() -Pattern: scala.internal.quoted.Patterns.patternHole[scala.Function0[scala.Predef.String]].apply() +Pattern: scala.quoted.internal.Patterns.patternHole[scala.Function0[scala.Predef.String]].apply() Result: Some(List(Expr((() => "abc")))) Scrutinee: ((x: scala.Int) => "abc") -Pattern: scala.internal.quoted.Patterns.patternHole[scala.Function1[scala.Int, scala.Predef.String]] +Pattern: scala.quoted.internal.Patterns.patternHole[scala.Function1[scala.Int, scala.Predef.String]] Result: Some(List(Expr(((x: scala.Int) => "abc")))) Scrutinee: ((x: scala.Int) => "abc").apply(4) -Pattern: scala.internal.quoted.Patterns.patternHole[scala.Function1[scala.Int, scala.Predef.String]].apply(4) +Pattern: scala.quoted.internal.Patterns.patternHole[scala.Function1[scala.Int, scala.Predef.String]].apply(4) Result: Some(List(Expr(((x: scala.Int) => "abc")))) Scrutinee: ((x: scala.Int) => "abc") -Pattern: ((x: scala.Int) => scala.internal.quoted.Patterns.patternHole[scala.Predef.String]) +Pattern: ((x: scala.Int) => scala.quoted.internal.Patterns.patternHole[scala.Predef.String]) Result: Some(List(Expr("abc"))) Scrutinee: scala.StringContext.apply("abc", "xyz") @@ -245,11 +245,11 @@ Pattern: scala.StringContext.apply("abc", "xyz") Result: Some(List()) Scrutinee: scala.StringContext.apply("abc", "xyz") -Pattern: scala.StringContext.apply(scala.internal.quoted.Patterns.patternHole[java.lang.String], scala.internal.quoted.Patterns.patternHole[java.lang.String]) +Pattern: scala.StringContext.apply(scala.quoted.internal.Patterns.patternHole[java.lang.String], scala.quoted.internal.Patterns.patternHole[java.lang.String]) Result: Some(List(Expr("abc"), Expr("xyz"))) Scrutinee: scala.StringContext.apply("abc", "xyz") -Pattern: scala.StringContext.apply(scala.internal.quoted.Patterns.patternHole[scala.Seq[scala.Predef.String]]: _*) +Pattern: scala.StringContext.apply(scala.quoted.internal.Patterns.patternHole[scala.Seq[scala.Predef.String]]: _*) Result: Some(List(Expr("abc", "xyz"))) Scrutinee: { @@ -267,7 +267,7 @@ Scrutinee: { () } Pattern: { - val a: scala.Int = scala.internal.quoted.Patterns.patternHole[scala.Int] + val a: scala.Int = scala.quoted.internal.Patterns.patternHole[scala.Int] () } Result: Some(List(Expr(45))) @@ -297,7 +297,7 @@ Scrutinee: { () } Pattern: { - var a: scala.Int = scala.internal.quoted.Patterns.patternHole[scala.Int] + var a: scala.Int = scala.quoted.internal.Patterns.patternHole[scala.Int] () } Result: None @@ -330,7 +330,7 @@ Scrutinee: { } Pattern: { val x: scala.Int = 45 - x.+(scala.internal.quoted.Patterns.patternHole[scala.Int]) + x.+(scala.quoted.internal.Patterns.patternHole[scala.Int]) } Result: None @@ -369,7 +369,7 @@ Scrutinee: { () } Pattern: { - val a: scala.Int = scala.internal.quoted.Patterns.patternHole[scala.Int] + val a: scala.Int = scala.quoted.internal.Patterns.patternHole[scala.Int] () } Result: None @@ -379,7 +379,7 @@ Scrutinee: { () } Pattern: { - var a: scala.Int = scala.internal.quoted.Patterns.patternHole[scala.Int] + var a: scala.Int = scala.quoted.internal.Patterns.patternHole[scala.Int] () } Result: None @@ -419,7 +419,7 @@ Scrutinee: { () } Pattern: { - val a: scala.Int = scala.internal.quoted.Patterns.patternHole[scala.Int] + val a: scala.Int = scala.quoted.internal.Patterns.patternHole[scala.Int] () } Result: None @@ -429,7 +429,7 @@ Scrutinee: { () } Pattern: { - lazy val a: scala.Int = scala.internal.quoted.Patterns.patternHole[scala.Int] + lazy val a: scala.Int = scala.quoted.internal.Patterns.patternHole[scala.Int] () } Result: None @@ -499,7 +499,7 @@ Scrutinee: { () } Pattern: { - def a: scala.Int = scala.internal.quoted.Patterns.patternHole[scala.Int] + def a: scala.Int = scala.quoted.internal.Patterns.patternHole[scala.Int] () } Result: Some(List(Expr(45))) @@ -619,8 +619,8 @@ Scrutinee: { a.+(a) } Pattern: { - def a: scala.Int = scala.internal.quoted.Patterns.patternHole[scala.Int] - a.+(scala.internal.quoted.Patterns.patternHole[scala.Int]) + def a: scala.Int = scala.quoted.internal.Patterns.patternHole[scala.Int] + a.+(scala.quoted.internal.Patterns.patternHole[scala.Int]) } Result: None @@ -636,22 +636,22 @@ Result: Some(List()) Scrutinee: scala.List.apply[scala.Int](1, 2, 3).foreach[scala.Unit](((x: scala.Int) => scala.Predef.println(x))) Pattern: { - @scala.internal.quoted.Patterns.patternType type T - scala.internal.quoted.Patterns.patternHole[scala.List[scala.Int]].foreach[T](scala.internal.quoted.Patterns.patternHole[scala.Function1[scala.Int, T]]) + @scala.quoted.internal.Patterns.patternType type T + scala.quoted.internal.Patterns.patternHole[scala.List[scala.Int]].foreach[T](scala.quoted.internal.Patterns.patternHole[scala.Function1[scala.Int, T]]) } Result: Some(List(Type(scala.Unit), Expr(scala.List.apply[scala.Int](1, 2, 3)), Expr(((x: scala.Int) => scala.Predef.println(x))))) Scrutinee: scala.List.apply[scala.Int](1, 2, 3).foreach[scala.Unit](((x: scala.Int) => scala.Predef.println(x))) Pattern: { - @scala.internal.quoted.Patterns.patternType type T = scala.Unit - scala.internal.quoted.Patterns.patternHole[scala.List[scala.Int]].foreach[T](scala.internal.quoted.Patterns.patternHole[scala.Function1[scala.Int, T]]) + @scala.quoted.internal.Patterns.patternType type T = scala.Unit + scala.quoted.internal.Patterns.patternHole[scala.List[scala.Int]].foreach[T](scala.quoted.internal.Patterns.patternHole[scala.Function1[scala.Int, T]]) } Result: Some(List(Type(scala.Unit), Expr(scala.List.apply[scala.Int](1, 2, 3)), Expr(((x: scala.Int) => scala.Predef.println(x))))) Scrutinee: scala.List.apply[scala.Int](1, 2, 3).foreach[scala.Unit](((x: scala.Int) => scala.Predef.println(x))) Pattern: { - @scala.internal.quoted.Patterns.patternType type T <: scala.Predef.String - scala.internal.quoted.Patterns.patternHole[scala.List[scala.Int]].foreach[T](scala.internal.quoted.Patterns.patternHole[scala.Function1[scala.Int, T]]) + @scala.quoted.internal.Patterns.patternType type T <: scala.Predef.String + scala.quoted.internal.Patterns.patternHole[scala.List[scala.Int]].foreach[T](scala.quoted.internal.Patterns.patternHole[scala.Function1[scala.Int, T]]) } Result: None @@ -661,9 +661,9 @@ Scrutinee: { () } Pattern: { - @scala.internal.quoted.Patterns.patternType type T - val a: T = scala.internal.quoted.Patterns.patternHole[T] - val b: T = scala.internal.quoted.Patterns.patternHole[T] + @scala.quoted.internal.Patterns.patternType type T + val a: T = scala.quoted.internal.Patterns.patternHole[T] + val b: T = scala.quoted.internal.Patterns.patternHole[T] () } Result: Some(List(Type(scala.Int), Expr(4), Expr(4))) @@ -674,9 +674,9 @@ Scrutinee: { () } Pattern: { - @scala.internal.quoted.Patterns.patternType type T - val a: T = scala.internal.quoted.Patterns.patternHole[T] - val b: T = scala.internal.quoted.Patterns.patternHole[T] + @scala.quoted.internal.Patterns.patternType type T + val a: T = scala.quoted.internal.Patterns.patternHole[T] + val b: T = scala.quoted.internal.Patterns.patternHole[T] () } Result: Some(List(Type(scala.Int), Expr(4), Expr(5))) @@ -687,9 +687,9 @@ Scrutinee: { () } Pattern: { - @scala.internal.quoted.Patterns.patternType type T - val a: T = scala.internal.quoted.Patterns.patternHole[T] - val b: T = scala.internal.quoted.Patterns.patternHole[T] + @scala.quoted.internal.Patterns.patternType type T + val a: T = scala.quoted.internal.Patterns.patternHole[T] + val b: T = scala.quoted.internal.Patterns.patternHole[T] () } Result: Some(List(Type(scala.Int | java.lang.String), Expr(4), Expr("x"))) @@ -700,52 +700,52 @@ Scrutinee: { () } Pattern: { - @scala.internal.quoted.Patterns.patternType type T <: scala.Int - val a: T = scala.internal.quoted.Patterns.patternHole[T] - val b: T = scala.internal.quoted.Patterns.patternHole[T] + @scala.quoted.internal.Patterns.patternType type T <: scala.Int + val a: T = scala.quoted.internal.Patterns.patternHole[T] + val b: T = scala.quoted.internal.Patterns.patternHole[T] () } Result: None Scrutinee: scala.List.apply[scala.Int](1, 2, 3).map[scala.Double](((x: scala.Int) => x.toDouble./(2))).map[java.lang.String](((y: scala.Double) => y.toString())) Pattern: { - @scala.internal.quoted.Patterns.patternType type T - @scala.internal.quoted.Patterns.patternType type U - @scala.internal.quoted.Patterns.patternType type V + @scala.quoted.internal.Patterns.patternType type T + @scala.quoted.internal.Patterns.patternType type U + @scala.quoted.internal.Patterns.patternType type V - (scala.internal.quoted.Patterns.patternHole[scala.List[T]].map[U](scala.internal.quoted.Patterns.patternHole[scala.Function1[T, U]]).map[V](scala.internal.quoted.Patterns.patternHole[scala.Function1[U, V]]): scala.collection.immutable.List[scala.Any]) + (scala.quoted.internal.Patterns.patternHole[scala.List[T]].map[U](scala.quoted.internal.Patterns.patternHole[scala.Function1[T, U]]).map[V](scala.quoted.internal.Patterns.patternHole[scala.Function1[U, V]]): scala.collection.immutable.List[scala.Any]) } Result: Some(List(Type(scala.Int), Type(scala.Double), Type(java.lang.String), Expr(scala.List.apply[scala.Int](1, 2, 3)), Expr(((x: scala.Int) => x.toDouble./(2))), Expr(((y: scala.Double) => y.toString())))) Scrutinee: ((x: scala.Int) => x) Pattern: { - @scala.internal.quoted.Patterns.patternType type T + @scala.quoted.internal.Patterns.patternType type T - (scala.internal.quoted.Patterns.patternHole[scala.Function1[T, T]]: scala.Function1[scala.Nothing, scala.Any]) + (scala.quoted.internal.Patterns.patternHole[scala.Function1[T, T]]: scala.Function1[scala.Nothing, scala.Any]) } Result: Some(List(Type(scala.Int), Expr(((x: scala.Int) => x)))) Scrutinee: ((x: scala.Int) => x.toString()) Pattern: { - @scala.internal.quoted.Patterns.patternType type T + @scala.quoted.internal.Patterns.patternType type T - (scala.internal.quoted.Patterns.patternHole[scala.Function1[T, T]]: scala.Function1[scala.Nothing, scala.Any]) + (scala.quoted.internal.Patterns.patternHole[scala.Function1[T, T]]: scala.Function1[scala.Nothing, scala.Any]) } Result: None Scrutinee: ((x: scala.Any) => scala.Predef.???) Pattern: { - @scala.internal.quoted.Patterns.patternType type T + @scala.quoted.internal.Patterns.patternType type T - (scala.internal.quoted.Patterns.patternHole[scala.Function1[T, T]]: scala.Function1[scala.Nothing, scala.Any]) + (scala.quoted.internal.Patterns.patternHole[scala.Function1[T, T]]: scala.Function1[scala.Nothing, scala.Any]) } Result: Some(List(Type(scala.Nothing), Expr(((x: scala.Any) => scala.Predef.???)))) Scrutinee: ((x: scala.Nothing) => (1: scala.Any)) Pattern: { - @scala.internal.quoted.Patterns.patternType type T + @scala.quoted.internal.Patterns.patternType type T - (scala.internal.quoted.Patterns.patternHole[scala.Function1[T, T]]: scala.Function1[scala.Nothing, scala.Any]) + (scala.quoted.internal.Patterns.patternHole[scala.Function1[T, T]]: scala.Function1[scala.Nothing, scala.Any]) } Result: None diff --git a/tests/run-macros/quote-matcher-runtime/quoted_1.scala b/tests/run-macros/quote-matcher-runtime/quoted_1.scala index 573af2af3316..070f23bbeaac 100644 --- a/tests/run-macros/quote-matcher-runtime/quoted_1.scala +++ b/tests/run-macros/quote-matcher-runtime/quoted_1.scala @@ -7,7 +7,7 @@ object Macros { private def impl[A, B](a: Expr[A], b: Expr[B])(using qctx: QuoteContext) : Expr[Unit] = { import qctx.reflect._ - val res = qctx.asInstanceOf[scala.internal.quoted.QuoteContextInternal].ExprMatch.unapply[Tuple, Tuple](a)(using b).map { tup => + val res = qctx.asInstanceOf[scala.quoted.internal.QuoteMatching].ExprMatch.unapply[Tuple, Tuple](a)(using b).map { tup => tup.toArray.toList.map { case r: Expr[_] => s"Expr(${r.show})" diff --git a/tests/run-macros/quote-matcher-runtime/quoted_2.scala b/tests/run-macros/quote-matcher-runtime/quoted_2.scala index b6c4a9df6d22..ea9faee84e00 100644 --- a/tests/run-macros/quote-matcher-runtime/quoted_2.scala +++ b/tests/run-macros/quote-matcher-runtime/quoted_2.scala @@ -1,7 +1,7 @@ import Macros._ -import scala.internal.quoted.Patterns._ +import scala.quoted.internal.Patterns._ object Test { diff --git a/tests/run-macros/quote-type-matcher/quoted_1.scala b/tests/run-macros/quote-type-matcher/quoted_1.scala index c7cc5622a913..439a28a820a3 100644 --- a/tests/run-macros/quote-type-matcher/quoted_1.scala +++ b/tests/run-macros/quote-type-matcher/quoted_1.scala @@ -7,7 +7,7 @@ object Macros { private def matchesExpr[A, B](using a: Type[A], b: Type[B])(using qctx: QuoteContext) : Expr[Unit] = { import qctx.reflect._ - val res = qctx.asInstanceOf[scala.internal.quoted.QuoteContextInternal].TypeMatch.unapply[Tuple, Tuple](a)(using b).map { tup => + val res = qctx.asInstanceOf[scala.quoted.internal.QuoteMatching].TypeMatch.unapply[Tuple, Tuple](a)(using b).map { tup => tup.toArray.toList.map { case r: Type[_] => s"Type(${TypeTree.of(using r).show})" diff --git a/tests/run-staging/i4730.scala b/tests/run-staging/i4730.scala index 19a373d78ebf..567a66b8c7cd 100644 --- a/tests/run-staging/i4730.scala +++ b/tests/run-staging/i4730.scala @@ -5,7 +5,7 @@ object Test { given Toolbox = Toolbox.make(getClass.getClassLoader) def ret(using QuoteContext): Expr[Int => Int] = '{ (x: Int) => ${ - val z = run('{x + 1}) // throws scala.quoted.internal.ScopeException => + val z = run('{x + 1}) // throws dotty.tools.dotc.quoted.ScopeException => Expr(z) } } @@ -21,7 +21,7 @@ package scala { run(Test.ret).apply(10) throw new Exception } catch { - case ex: Exception if ex.getClass.getName == "scala.quoted.internal.ScopeException" => + case ex: Exception if ex.getClass.getName == "dotty.tools.dotc.quoted.ScopeException" => // ok } } diff --git a/tests/run-staging/i6754.scala b/tests/run-staging/i6754.scala index 7261e734b75e..e447b98801f5 100644 --- a/tests/run-staging/i6754.scala +++ b/tests/run-staging/i6754.scala @@ -22,7 +22,7 @@ package scala { throw new Exception } catch { case ex: java.lang.reflect.InvocationTargetException => - assert(ex.getTargetException.getClass.getName == "scala.quoted.internal.ScopeException") + assert(ex.getTargetException.getClass.getName == "dotty.tools.dotc.quoted.ScopeException") } } } diff --git a/tests/run-staging/i6992/Macro_1.scala b/tests/run-staging/i6992/Macro_1.scala index 7a5bf0317676..7270481f0852 100644 --- a/tests/run-staging/i6992/Macro_1.scala +++ b/tests/run-staging/i6992/Macro_1.scala @@ -25,7 +25,7 @@ package scala { case '{$x: Foo} => Expr(run(x).x) } } catch { - case ex: Exception if ex.getClass.getName == "scala.quoted.internal.ScopeException" => + case ex: Exception if ex.getClass.getName == "dotty.tools.dotc.quoted.ScopeException" => '{"OK"} } } diff --git a/tests/run-staging/multi-staging.check b/tests/run-staging/multi-staging.check index 7a6c259e5201..a7900c87ff66 100644 --- a/tests/run-staging/multi-staging.check +++ b/tests/run-staging/multi-staging.check @@ -1,5 +1,5 @@ stage1 code: ((qctx1: scala.quoted.QuoteContext) ?=> { val x1: scala.Int = 2 - scala.internal.quoted.CompileTime.exprQuote[scala.Int](1.+(scala.internal.quoted.CompileTime.exprNestedSplice[scala.Int](qctx1)(((evidence$5: qctx1.Nested) ?=> scala.quoted.Expr.apply[scala.Int](x1)(evidence$5, scala.quoted.Liftable.IntLiftable[scala.Int]))))).apply(using qctx1) + scala.quoted.internal.Expr.quote[scala.Int](1.+(scala.quoted.internal.Expr.nestedSplice[scala.Int](qctx1)(((evidence$5: qctx1.Nested) ?=> scala.quoted.Expr.apply[scala.Int](x1)(evidence$5, scala.quoted.Liftable.IntLiftable[scala.Int]))))).apply(using qctx1) }) 3 diff --git a/tests/run-staging/quote-nested-1.check b/tests/run-staging/quote-nested-1.check index ca6f701a2eab..73bf9f545895 100644 --- a/tests/run-staging/quote-nested-1.check +++ b/tests/run-staging/quote-nested-1.check @@ -1 +1 @@ -((qctx: scala.quoted.QuoteContext) ?=> scala.internal.quoted.CompileTime.exprQuote[scala.Int](3).apply(using qctx)) +((qctx: scala.quoted.QuoteContext) ?=> scala.quoted.internal.Expr.quote[scala.Int](3).apply(using qctx)) diff --git a/tests/run-staging/quote-nested-2.check b/tests/run-staging/quote-nested-2.check index a6e96ebf708a..ccd9b93d03fe 100644 --- a/tests/run-staging/quote-nested-2.check +++ b/tests/run-staging/quote-nested-2.check @@ -1,4 +1,4 @@ ((qctx: scala.quoted.QuoteContext) ?=> { - val a: scala.quoted.Expr[scala.Int] = scala.internal.quoted.CompileTime.exprQuote[scala.Int](4).apply(using qctx) + val a: scala.quoted.Expr[scala.Int] = scala.quoted.internal.Expr.quote[scala.Int](4).apply(using qctx) ((evidence$2: qctx.Nested) ?=> a).asInstanceOf[scala.ContextFunction1[scala.quoted.QuoteContext, scala.quoted.Expr[scala.Int]]].apply(using qctx) }) diff --git a/tests/run-staging/quote-nested-5.check b/tests/run-staging/quote-nested-5.check index 8fa08686c9ee..443c1b39165b 100644 --- a/tests/run-staging/quote-nested-5.check +++ b/tests/run-staging/quote-nested-5.check @@ -1,4 +1,4 @@ ((qctx: scala.quoted.QuoteContext) ?=> { - val a: scala.quoted.Expr[scala.Int] = scala.internal.quoted.CompileTime.exprQuote[scala.Int](4).apply(using qctx) + val a: scala.quoted.Expr[scala.Int] = scala.quoted.internal.Expr.quote[scala.Int](4).apply(using qctx) ((qctx2: scala.quoted.QuoteContext) ?=> ((evidence$3: qctx2.Nested) ?=> a).asInstanceOf[scala.ContextFunction1[scala.quoted.QuoteContext, scala.quoted.Expr[scala.Int]]].apply(using qctx2)).apply(using qctx) })