Skip to content

Rename TASTy reflect Kernel to Internal #6975

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import scala.quoted.show.SyntaxHighlight
object ReflectionImpl {

def apply(rootContext: Contexts.Context): scala.tasty.Reflection =
new scala.tasty.Reflection(new KernelImpl(rootContext))
new scala.tasty.Reflection(new ReflectionCompilerInterface(rootContext))

def showTree(tree: tpd.Tree)(implicit ctx: Contexts.Context): String = {
val refl = new scala.tasty.Reflection(new KernelImpl(MacroExpansion.context(tree)))
val refl = new scala.tasty.Reflection(new ReflectionCompilerInterface(MacroExpansion.context(tree)))
val reflCtx = ctx.asInstanceOf[refl.Context]
val reflTree = tree.asInstanceOf[refl.Tree]
val syntaxHighlight =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import dotty.tools.dotc.parsing.Parsers.Parser
import dotty.tools.dotc.typer.Implicits.{AmbiguousImplicits, DivergingImplicit, NoMatchingImplicits, SearchFailure, SearchFailureType}
import dotty.tools.dotc.util.{SourceFile, SourcePosition, Spans}

import scala.tasty.reflect.Kernel
import scala.tasty.reflect.CompilerInterface

class KernelImpl(val rootContext: core.Contexts.Context) extends Kernel {
class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extends CompilerInterface {
import tpd._

private implicit def ctx: core.Contexts.Context = rootContext
Expand Down
16 changes: 8 additions & 8 deletions library/src-bootstrapped/scala/internal/quoted/Matcher.scala
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ object Matcher {
def hasBindAnnotation(sym: Symbol) = sym.annots.exists(isBindAnnotation)

def isBindAnnotation(tree: Tree): Boolean = tree match {
case New(tpt) => tpt.symbol == kernel.Definitions_InternalQuoted_patternBindHoleAnnot
case annot => annot.symbol.owner == kernel.Definitions_InternalQuoted_patternBindHoleAnnot
case New(tpt) => tpt.symbol == internal.Definitions_InternalQuoted_patternBindHoleAnnot
case annot => annot.symbol.owner == internal.Definitions_InternalQuoted_patternBindHoleAnnot
}

/** Check that all trees match with `mtch` and concatenate the results with && */
Expand Down Expand Up @@ -102,14 +102,14 @@ object Matcher {

// Match a scala.internal.Quoted.patternHole typed as a repeated argument and return the scrutinee tree
case (IsTerm(scrutinee @ Typed(s, tpt1)), Typed(TypeApply(patternHole, tpt :: Nil), tpt2))
if patternHole.symbol == kernel.Definitions_InternalQuoted_patternHole &&
if patternHole.symbol == internal.Definitions_InternalQuoted_patternHole &&
s.tpe <:< tpt.tpe &&
tpt2.tpe.derivesFrom(definitions.RepeatedParamClass) =>
matched(scrutinee.seal)

// Match a scala.internal.Quoted.patternHole and return the scrutinee tree
case (IsTerm(scrutinee), TypeApply(patternHole, tpt :: Nil))
if patternHole.symbol == kernel.Definitions_InternalQuoted_patternHole &&
if patternHole.symbol == internal.Definitions_InternalQuoted_patternHole &&
scrutinee.tpe <:< tpt.tpe =>
matched(scrutinee.seal)

Expand Down Expand Up @@ -142,7 +142,7 @@ object Matcher {
fn1 =#= fn2 && args1 =##= args2

case (Block(stats1, expr1), Block(binding :: stats2, expr2)) if isTypeBinding(binding) =>
qctx.tasty.kernel.Context_GADT_addToConstraint(the[Context])(binding.symbol :: Nil)
qctx.tasty.internal.Context_GADT_addToConstraint(the[Context])(binding.symbol :: Nil)
matched(new SymBinding(binding.symbol)) && Block(stats1, expr1) =#= Block(stats2, expr2)

case (Block(stat1 :: stats1, expr1), Block(stat2 :: stats2, expr2)) =>
Expand All @@ -152,7 +152,7 @@ object Matcher {

case (scrutinee, Block(typeBindings, expr2)) if typeBindings.forall(isTypeBinding) =>
val bindingSymbols = typeBindings.map(_.symbol)
qctx.tasty.kernel.Context_GADT_addToConstraint(the[Context])(bindingSymbols)
qctx.tasty.internal.Context_GADT_addToConstraint(the[Context])(bindingSymbols)
bindingSymbols.foldRight(scrutinee =#= expr2)((x, acc) => matched(new SymBinding(x)) && acc)

case (If(cond1, thenp1, elsep1), If(cond2, thenp2, elsep2)) =>
Expand Down Expand Up @@ -336,13 +336,13 @@ object Matcher {

val res = {
if (hasTypeSplices) {
implicit val ctx: Context = qctx.tasty.kernel.Context_GADT_setFreshGADTBounds(rootContext)
implicit val ctx: Context = qctx.tasty.internal.Context_GADT_setFreshGADTBounds(rootContext)
val matchings = scrutineeExpr.unseal.underlyingArgument =#= patternExpr.unseal.underlyingArgument
// After matching and doing all subtype check, we have to aproximate all the type bindings
// that we have found and seal them in a quoted.Type
matchings.asOptionOfTuple.map { tup =>
Tuple.fromArray(tup.toArray.map { // TODO improve performace
case x: SymBinding => kernel.Context_GADT_approximation(the[Context])(x.sym, true).seal
case x: SymBinding => internal.Context_GADT_approximation(the[Context])(x.sym, true).seal
case x => x
})
}
Expand Down
4 changes: 2 additions & 2 deletions library/src/scala/quoted/Expr.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ package quoted {
/** Beta-reduces the function appication. Generates the an expression only containing the body of the function */
def apply[G] given (tg: TupledFunction[G, TupleOfExpr[Args] => Expr[R]]): G = {
import qctx.tasty._
tg.untupled(args => qctx.tasty.kernel.betaReduce(f.unseal, args.toArray.toList.map(_.asInstanceOf[QuoteContext => Expr[_]](qctx).unseal)).seal.asInstanceOf[Expr[R]])
tg.untupled(args => qctx.tasty.internal.betaReduce(f.unseal, args.toArray.toList.map(_.asInstanceOf[QuoteContext => Expr[_]](qctx).unseal)).seal.asInstanceOf[Expr[R]])
}
}

implicit class AsContextualFunction[F, Args <: Tuple, R](f: Expr[F]) given (tf: TupledFunction[F, given Args => R], qctx: QuoteContext) {
/** Beta-reduces the function appication. Generates the an expression only containing the body of the function */
def apply[G] given (tg: TupledFunction[G, TupleOfExpr[Args] => Expr[R]]): G = {
import qctx.tasty._
tg.untupled(args => qctx.tasty.kernel.betaReduce(f.unseal, args.toArray.toList.map(_.asInstanceOf[QuoteContext => Expr[_]](qctx).unseal)).seal.asInstanceOf[Expr[R]])
tg.untupled(args => qctx.tasty.internal.betaReduce(f.unseal, args.toArray.toList.map(_.asInstanceOf[QuoteContext => Expr[_]](qctx).unseal)).seal.asInstanceOf[Expr[R]])
}
}

Expand Down
4 changes: 2 additions & 2 deletions library/src/scala/tasty/Reflection.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package scala.tasty

import scala.tasty.reflect._

class Reflection(val kernel: Kernel)
class Reflection(private[scala] val internal: CompilerInterface)
extends Core
with ConstantOps
with ContextOps
Expand Down Expand Up @@ -37,7 +37,7 @@ class Reflection(val kernel: Kernel)
*
* The code should be a sequence of expressions or statements that may appear in a block.
*/
def typeChecks(code: String)(implicit ctx: Context): Boolean = kernel.typeChecks(code)
def typeChecks(code: String)(implicit ctx: Context): Boolean = internal.typeChecks(code)
}

}
6 changes: 3 additions & 3 deletions library/src/scala/tasty/reflect/CommentOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ trait CommentOps extends Core {
implicit class CommentAPI(self: Comment) {

/** Raw comment string */
def raw: String = kernel.Comment_raw(self)
def raw: String = internal.Comment_raw(self)

/** Expanded comment string, if any */
def expanded: Option[String] = kernel.Comment_expanded(self)
def expanded: Option[String] = internal.Comment_expanded(self)

/** List of usecases and their corresponding trees, if any */
def usecases: List[(String, Option[DefDef])] = kernel.Comment_usecases(self)
def usecases: List[(String, Option[DefDef])] = internal.Comment_usecases(self)

}

Expand Down
10 changes: 5 additions & 5 deletions library/src/scala/tasty/reflect/ConstantOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,27 @@ package reflect
trait ConstantOps extends Core {

implicit class ConstantAPI(const: Constant) {
def value: Any = kernel.Constant_value(const)
def value: Any = internal.Constant_value(const)
}

/** Module of Constant literals */
object Constant {

def apply(x: Unit | Null | Int | Boolean | Byte | Short | Int | Long | Float | Double | Char | String | Type): Constant =
kernel.Constant_apply(x)
internal.Constant_apply(x)

def unapply(constant: Constant): Option[Unit | Null | Int | Boolean | Byte | Short | Int | Long | Float | Double | Char | String | Type] =
kernel.matchConstant(constant)
internal.matchConstant(constant)

/** Module of ClassTag literals */
object ClassTag {
/** scala.reflect.ClassTag literal */
def apply[T] given (x: Type): Constant =
kernel.Constant_ClassTag_apply(x)
internal.Constant_ClassTag_apply(x)

/** Extractor for ClassTag literals */
def unapply(constant: Constant): Option[Type] =
kernel.matchConstant_ClassTag(constant)
internal.matchConstant_ClassTag(constant)
}
}
}
6 changes: 3 additions & 3 deletions library/src/scala/tasty/reflect/ContextOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ trait ContextOps extends Core {

implicit class ContextAPI(self: Context) {
/** Returns the owner of the context */
def owner: Symbol = kernel.Context_owner(self)
def owner: Symbol = internal.Context_owner(self)

/** Returns the source file being compiled. The path is relative to the current working directory. */
def source: java.nio.file.Path = kernel.Context_source(self)
def source: java.nio.file.Path = internal.Context_source(self)

}

/** Context of the macro expansion */
implicit def rootContext: Context = kernel.rootContext
implicit def rootContext: Context = internal.rootContext

}
Loading