Skip to content

Commit e3575f3

Browse files
committed
Move currentOwner to Symbol
1 parent a3e7636 commit e3575f3

File tree

9 files changed

+23
-34
lines changed

9 files changed

+23
-34
lines changed

compiler/src/dotty/tools/dotc/tastyreflect/ReflectionCompilerInterface.scala

+2-3
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@ class ReflectionCompilerInterface(val rootContext: Context) extends CompilerInte
5050

5151
type Context = core.Contexts.Context
5252

53-
def Context_owner(self: Context): Symbol = self.owner
54-
55-
5653
/////////////////
5754
// Constraints //
5855
/////////////////
@@ -1674,6 +1671,8 @@ class ReflectionCompilerInterface(val rootContext: Context) extends CompilerInte
16741671

16751672
type Symbol = core.Symbols.Symbol
16761673

1674+
def Symbol_currentOwner(using ctx: Context): Symbol = ctx.owner
1675+
16771676
def Symbol_owner(self: Symbol)(using Context): Symbol = self.owner
16781677
def Symbol_maybeOwner(self: Symbol)(using Context): Symbol = self.maybeOwner
16791678

library/src/scala/internal/tasty/CompilerInterface.scala

+3-7
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,6 @@ trait CompilerInterface extends scala.tasty.reflect.Types {
2929
def unpickleType(repr: Unpickler.PickledQuote, args: Unpickler.PickledArgs): TypeTree
3030

3131

32-
/////////////
33-
// CONTEXT //
34-
/////////////
35-
36-
/** Returns the owner of the context */
37-
def Context_owner(self: Context): Symbol
38-
3932
/////////////////
4033
// Constraints //
4134
/////////////////
@@ -853,6 +846,9 @@ trait CompilerInterface extends scala.tasty.reflect.Types {
853846
// SYMBOLS //
854847
/////////////
855848

849+
/** Returns the symbol of the current enclosing definition */
850+
def Symbol_currentOwner(using ctx: Context): Symbol
851+
856852
/** Owner of this symbol. The owner is the symbol in which this symbol is defined. Throws if this symbol does not have an owner. */
857853
def Symbol_owner(self: Symbol)(using ctx: Context): Symbol
858854

library/src/scala/tasty/Reflection.scala

+4-10
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,6 @@ trait Reflection extends reflect.Types { reflectSelf: CompilerInterface =>
2020
def rootContext: Context // TODO: Should this be moved to QuoteContext?
2121
given Context = rootContext // TODO: Should be an implicit converion from QuoteContext to Context
2222

23-
given ContextOps as Context.type = Context
24-
25-
object Context:
26-
extension (self: Context):
27-
/** Returns the owner of the context */
28-
def owner: Symbol = reflectSelf.Context_owner(self)
29-
end extension
30-
end Context
31-
3223

3324
///////////////
3425
// Source //
@@ -1903,6 +1894,9 @@ trait Reflection extends reflect.Types { reflectSelf: CompilerInterface =>
19031894

19041895
object Symbol:
19051896

1897+
/** Returns the symbol of the current enclosing definition */
1898+
def currentOwner(using ctx: Context): Symbol = reflectSelf.Symbol_currentOwner
1899+
19061900
/** Get package symbol if package is either defined in current compilation run or present on classpath. */
19071901
def requiredPackage(path: String)(using ctx: Context): Symbol = reflectSelf.Symbol_requiredPackage(path)
19081902

@@ -2680,7 +2674,7 @@ trait Reflection extends reflect.Types { reflectSelf: CompilerInterface =>
26802674

26812675
/** Bind the `rhs` to a `val` and use it in `body` */
26822676
def let(rhs: Term)(body: Ident => Term)(using ctx: Context): Term = {
2683-
val sym = Symbol.newVal(ctx.owner, "x", rhs.tpe.widen, Flags.EmptyFlags, Symbol.noSymbol)
2677+
val sym = Symbol.newVal(Symbol.currentOwner, "x", rhs.tpe.widen, Flags.EmptyFlags, Symbol.noSymbol)
26842678
Block(List(ValDef(sym, Some(rhs))), body(Ref(sym).asInstanceOf[Ident]))
26852679
}
26862680

tests/run-macros/i6988/FirstArg_1.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ object Macros {
1111
def argsImpl(using qctx: QuoteContext) : Expr[FirstArg] = {
1212
import qctx.tasty._
1313

14-
def enclosingClass(cur: Symbol = rootContext.owner): Symbol =
14+
def enclosingClass(cur: Symbol = Symbol.currentOwner): Symbol =
1515
if (cur.isClassDef) cur
1616
else enclosingClass(cur.owner)
1717

@@ -24,7 +24,7 @@ object Macros {
2424

2525
def literal(value: String): Expr[String] =
2626
Literal(Constant(value)).seal.asInstanceOf[Expr[String]]
27-
val paramss = enclosingParamList(rootContext.owner)
27+
val paramss = enclosingParamList(Symbol.currentOwner)
2828
val firstArg = paramss.flatten.head
2929
val ref = Select.unique(This(enclosingClass()), firstArg.name)
3030
'{ FirstArg(${ref.seal}, ${Expr(firstArg.name)}) }

tests/run-macros/i7025/Macros_1.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ object Macros {
1010
if owner.isClassDef then owner
1111
else nearestEnclosingDef(owner.owner)
1212

13-
val x = nearestEnclosingDef(rootContext.owner)
13+
val x = nearestEnclosingDef(Symbol.currentOwner)
1414
if x.isDefDef then
1515
val code = x.signature.toString
1616
'{ println(${Expr(code)}) }

tests/run-macros/tasty-create-method-symbol/Macro_1.scala

+8-8
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ object Macros {
99

1010
// simple smoke test
1111
val sym1 : Symbol = Symbol.newMethod(
12-
rootContext.owner,
12+
Symbol.currentOwner,
1313
"sym1",
1414
MethodType(List("a","b"))(
1515
_ => List(typeOf[Int], typeOf[Int]),
@@ -27,7 +27,7 @@ object Macros {
2727

2828
// test for no argument list (no Apply node)
2929
val sym2 : Symbol = Symbol.newMethod(
30-
rootContext.owner,
30+
Symbol.currentOwner,
3131
"sym2",
3232
ByNameType(typeOf[Int]))
3333
assert(sym2.isDefDef)
@@ -43,7 +43,7 @@ object Macros {
4343

4444
// test for multiple argument lists
4545
val sym3 : Symbol = Symbol.newMethod(
46-
rootContext.owner,
46+
Symbol.currentOwner,
4747
"sym3",
4848
MethodType(List("a"))(
4949
_ => List(typeOf[Int]),
@@ -63,7 +63,7 @@ object Macros {
6363

6464
// test for recursive references
6565
val sym4 : Symbol = Symbol.newMethod(
66-
rootContext.owner,
66+
Symbol.currentOwner,
6767
"sym4",
6868
MethodType(List("x"))(
6969
_ => List(typeOf[Int]),
@@ -85,7 +85,7 @@ object Macros {
8585

8686
// test for nested functions (one symbol is the other's parent, and we use a Closure)
8787
val sym5 : Symbol = Symbol.newMethod(
88-
rootContext.owner,
88+
Symbol.currentOwner,
8989
"sym5",
9090
MethodType(List("x"))(
9191
_ => List(typeOf[Int]),
@@ -119,13 +119,13 @@ object Macros {
119119

120120
// test mutually recursive definitions
121121
val sym6_1 : Symbol = Symbol.newMethod(
122-
rootContext.owner,
122+
Symbol.currentOwner,
123123
"sym6_1",
124124
MethodType(List("x"))(
125125
_ => List(typeOf[Int]),
126126
_ => typeOf[Int]))
127127
val sym6_2 : Symbol = Symbol.newMethod(
128-
rootContext.owner,
128+
Symbol.currentOwner,
129129
"sym6_2",
130130
MethodType(List("x"))(
131131
_ => List(typeOf[Int]),
@@ -166,7 +166,7 @@ object Macros {
166166

167167
// test polymorphic methods by synthesizing an identity method
168168
val sym7 : Symbol = Symbol.newMethod(
169-
rootContext.owner,
169+
Symbol.currentOwner,
170170
"sym7",
171171
PolyType(List("T"))(
172172
tp => List(TypeBounds(typeOf[Nothing], typeOf[Any])),

tests/run-macros/tasty-location/quoted_1.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ object Location {
1313
if (sym == defn.RootClass || sym == defn.EmptyPackageClass) acc
1414
else listOwnerNames(sym.owner, sym.name :: acc)
1515

16-
val list = listOwnerNames(rootContext.owner, Nil)
16+
val list = listOwnerNames(Symbol.currentOwner, Nil)
1717
'{new Location(${Expr(list)})}
1818
}
1919

0 commit comments

Comments
 (0)