Skip to content

Commit b8bb452

Browse files
Merge pull request #10291 from dotty-staging/move-Reflection
Move Reflection to scala.quoted
2 parents f01c33f + 60d5820 commit b8bb452

File tree

21 files changed

+93
-92
lines changed

21 files changed

+93
-92
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class QuoteContextImpl private (ctx: Context) extends QuoteContext, QuoteUnpickl
7979
}
8080
end extension
8181

82-
object reflect extends scala.tasty.Reflection:
82+
object reflect extends scala.quoted.Reflection:
8383

8484
def rootContext: Context = ctx
8585

library/src/scala/quoted/QuoteContext.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ trait QuoteContext { self: internal.QuoteUnpickler & internal.QuoteMatching =>
6666
/** Low-level Typed AST API metaprogramming API.
6767
* This API does not have the static type guarantiees that `Expr` and `Type` provide.
6868
*/
69-
val reflect: scala.tasty.Reflection
69+
val reflect: scala.quoted.Reflection
70+
// TODO move Reflcetion definition in here
7071

7172
/** Type of a QuoteContext provided by a splice within a quote that took this context.
7273
* It is only required if working with the reflection API.

library/src/scala/tasty/Reflection.scala renamed to library/src/scala/quoted/Reflection.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
package scala.tasty
1+
package scala.quoted
22

33
import scala.tasty.reflect._
44

5-
/** TASTy Reflect Interface.
5+
/** AST reflection interface.
66
*
77
* Provides all functionality related with AST based metaprogramming.
88
*

scala3doc/src/dotty/dokka/Main.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import java.util.jar._
99
import collection.JavaConverters._
1010
import collection.immutable.ArraySeq
1111

12-
import scala.tasty.Reflection
1312
import scala.tasty.inspector.TastyInspector
1413
import java.nio.file.Files
1514

scala3doc/src/dotty/dokka/tasty/BasicSupport.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import dotty.dokka.model.api.TastyDocumentableSource
1010
trait BasicSupport:
1111
self: TastyParser =>
1212
import qctx.reflect._
13-
object SymOps extends SymOps[qctx.reflect.type](qctx.reflect)
13+
object SymOps extends SymOps[qctx.type](qctx)
1414
export SymOps._
1515

1616
def parseAnnotation(annotTerm: Term): Annotation =

scala3doc/src/dotty/dokka/tasty/ClassLikeSupport.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ trait ClassLikeSupport:
5050
}
5151
)
5252

53-
val supertypes = getSupertypes(classDef).map {
53+
val supertypes = getSupertypes(using qctx)(classDef).map {
5454
case (symbol, tpe) => LinkToType(tpe.dokkaType.asSignature, symbol.dri, kindForClasslike(symbol))
5555
}
5656
val selfSiangture: DSignature = typeForClass(classDef).dokkaType.asSignature

scala3doc/src/dotty/dokka/tasty/ScalaDocSupport.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ trait ScaladocSupport { self: TastyParser =>
3232

3333
val parser = commentSyntax match {
3434
case CommentSyntax.Wiki =>
35-
comments.WikiCommentParser(comments.Repr(qctx.reflect)(tree.symbol))
35+
comments.WikiCommentParser(comments.Repr(qctx)(tree.symbol))
3636
case CommentSyntax.Markdown =>
37-
comments.MarkdownCommentParser(comments.Repr(qctx.reflect)(tree.symbol))
37+
comments.MarkdownCommentParser(comments.Repr(qctx)(tree.symbol))
3838
}
3939
val parsed = parser.parse(preparsed)
4040

scala3doc/src/dotty/dokka/tasty/SymOps.scala

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ import dotty.dokka._
77
import dotty.dokka.model.api.Visibility
88
import dotty.dokka.model.api.VisibilityScope
99
import dotty.dokka.model.api.Modifier
10-
import scala.tasty.Reflection
1110

12-
class SymOps[R <: Reflection](val r: R):
13-
import r._
11+
import scala.quoted._
1412

15-
given R = r
16-
extension (sym: r.Symbol):
13+
class SymOps[Q <: QuoteContext](val q: Q):
14+
import q.reflect._
15+
16+
given Q = q
17+
extension (sym: Symbol):
1718
def packageName(using ctx: Context): String =
1819
if (sym.isPackageDef) sym.fullName
1920
else sym.maybeOwner.packageName
@@ -49,7 +50,7 @@ class SymOps[R <: Reflection](val r: R):
4950
// TODO: #49 Remove it after TASTY-Reflect release with published flag Extension
5051
def hackIsOpen: Boolean = {
5152
import dotty.tools.dotc
52-
given dotc.core.Contexts.Context = r.rootContext.asInstanceOf
53+
given dotc.core.Contexts.Context = qctx.reflect.rootContext.asInstanceOf
5354
val symbol = sym.asInstanceOf[dotc.core.Symbols.Symbol]
5455
symbol.is(dotc.core.Flags.Open)
5556
}

scala3doc/src/dotty/dokka/tasty/SyntheticSupport.scala

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package dotty.dokka.tasty
22

3-
import scala.tasty.Reflection
3+
import scala.quoted._
44

55
trait SyntheticsSupport:
66
self: TastyParser =>
@@ -31,11 +31,11 @@ trait SyntheticsSupport:
3131

3232
def isDefaultHelperMethod: Boolean = ".*\\$default\\$\\d+$".r.matches(s.name)
3333

34-
def isOpaque: Boolean = hackIsOpaque(qctx.reflect)(s)
34+
def isOpaque: Boolean = hackIsOpaque(using qctx)(s)
3535

36-
def isInfix: Boolean = hackIsInfix(qctx.reflect)(s)
36+
def isInfix: Boolean = hackIsInfix(using qctx)(s)
3737

38-
def getAllMembers: List[Symbol] = hackGetAllMembers(qctx.reflect)(s)
38+
def getAllMembers: List[Symbol] = hackGetAllMembers(using qctx)(s)
3939

4040
def isSyntheticField(c: Symbol) =
4141
c.flags.is(Flags.CaseAccessor) || c.flags.is(Flags.Object)
@@ -52,53 +52,57 @@ trait SyntheticsSupport:
5252
}
5353

5454
// TODO: #49 Remove it after TASTY-Reflect release with published flag Extension
55-
def hackIsInfix(r: Reflection)(rsym: r.Symbol): Boolean = {
55+
def hackIsInfix(using QuoteContext)(rsym: qctx.reflect.Symbol): Boolean = {
56+
import qctx.reflect._
5657
import dotty.tools.dotc
57-
given ctx as dotc.core.Contexts.Context = r.rootContext.asInstanceOf
58+
given ctx as dotc.core.Contexts.Context = rootContext.asInstanceOf
5859
val sym = rsym.asInstanceOf[dotc.core.Symbols.Symbol]
5960
ctx.definitions.isInfix(sym)
6061
}
6162
/* We need there to filter out symbols with certain flagsets, because these symbols come from compiler and TASTY can't handle them well.
6263
They are valdefs that describe case companion objects and cases from enum.
6364
TASTY crashed when calling _.tree on them.
6465
*/
65-
def hackGetAllMembers(r: Reflection)(rsym: r.Symbol): List[r.Symbol] = {
66+
def hackGetAllMembers(using QuoteContext)(rsym: qctx.reflect.Symbol): List[qctx.reflect.Symbol] = {
67+
import qctx.reflect._
6668
import dotty.tools.dotc
67-
given ctx as dotc.core.Contexts.Context = r.rootContext.asInstanceOf
69+
given ctx as dotc.core.Contexts.Context = rootContext.asInstanceOf
6870
val sym = rsym.asInstanceOf[dotc.core.Symbols.Symbol]
6971
sym.typeRef.appliedTo(sym.typeParams.map(_.typeRef)).allMembers.iterator.map(_.symbol)
7072
.collect {
7173
case sym if
7274
!sym.is(dotc.core.Flags.ModuleVal) &&
7375
!sym.flags.isAllOf(dotc.core.Flags.Enum | dotc.core.Flags.Case | dotc.core.Flags.JavaStatic) =>
74-
sym.asInstanceOf[r.Symbol]
76+
sym.asInstanceOf[Symbol]
7577
}.toList
7678
}
7779

78-
def hackIsOpaque(r: Reflection)(rsym: r.Symbol): Boolean = {
80+
def hackIsOpaque(using QuoteContext)(rsym: qctx.reflect.Symbol): Boolean = {
7981
import dotty.tools.dotc
80-
given dotc.core.Contexts.Context = r.rootContext.asInstanceOf
82+
given dotc.core.Contexts.Context = qctx.reflect.rootContext.asInstanceOf
8183
val sym = rsym.asInstanceOf[dotc.core.Symbols.Symbol]
8284
sym.is(dotc.core.Flags.Opaque)
8385
}
8486

85-
def hackGetSupertypes(r: Reflection)(rdef: r.ClassDef) = {
87+
def hackGetSupertypes(using QuoteContext)(rdef: qctx.reflect.ClassDef) = {
88+
import qctx.reflect._
8689
import dotty.tools.dotc
87-
given dotc.core.Contexts.Context = r.rootContext.asInstanceOf
90+
given dotc.core.Contexts.Context = qctx.reflect.rootContext.asInstanceOf
8891
val classdef = rdef.asInstanceOf[dotc.ast.tpd.TypeDef]
8992
val ref = classdef.symbol.info.asInstanceOf[dotc.core.Types.ClassInfo].appliedRef
9093
val baseTypes: List[(dotc.core.Symbols.Symbol, dotc.core.Types.Type)] =
9194
ref.baseClasses.map(b => b -> ref.baseType(b))
92-
baseTypes.asInstanceOf[List[(r.Symbol, r.TypeRepr)]]
95+
baseTypes.asInstanceOf[List[(Symbol, TypeRepr)]]
9396
}
9497

95-
def getSupertypes(c: ClassDef) = hackGetSupertypes(qctx.reflect)(c).tail
98+
def getSupertypes(using QuoteContext)(c: ClassDef) = hackGetSupertypes(c).tail
9699

97-
def typeForClass(c: ClassDef): r.TypeRepr =
100+
def typeForClass(c: ClassDef): TypeRepr =
101+
import qctx.reflect._
98102
import dotty.tools.dotc
99-
given dotc.core.Contexts.Context = r.rootContext.asInstanceOf
103+
given dotc.core.Contexts.Context = rootContext.asInstanceOf
100104
val cSym = c.symbol.asInstanceOf[dotc.core.Symbols.Symbol]
101-
cSym.typeRef.appliedTo(cSym.typeParams.map(_.typeRef)).asInstanceOf[r.TypeRepr]
105+
cSym.typeRef.appliedTo(cSym.typeParams.map(_.typeRef)).asInstanceOf[TypeRepr]
102106

103107
object MatchTypeCase:
104108
def unapply(tpe: TypeRepr): Option[(TypeRepr, TypeRepr)] =

0 commit comments

Comments
 (0)