Skip to content

Commit 3f947f6

Browse files
Merge pull request #89 from dotty-staging/dotty-community-build
Upgrade Dotty to 0.24.0-RC1
2 parents c4afb82 + 3e8b8b9 commit 3f947f6

File tree

2 files changed

+49
-34
lines changed

2 files changed

+49
-34
lines changed

build.sc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ trait SourcecodeTestModule extends ScalaModule {
6464
}
6565

6666
object sourcecode extends Module {
67-
object jvm extends Cross[JvmSourcecodeModule]("2.11.12", "2.12.10", "2.13.1", "0.21.0-RC1")
67+
val dottyVersion = Option(sys.props("dottyVersion"))
68+
object jvm extends Cross[JvmSourcecodeModule]((List("2.11.12", "2.12.8", "2.13.0", "0.24.0-RC1") ++ dottyVersion): _*)
6869
class JvmSourcecodeModule(val crossScalaVersion: String)
6970
extends SourcecodeMainModule with ScalaModule with SourcecodeModule {
7071

sourcecode/src-0/sourcecode/Macros.scala

Lines changed: 47 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -67,29 +67,41 @@ trait ArgsMacros {
6767
object Util{
6868
def isSynthetic(c: Reflection)(s: c.Symbol) = isSyntheticName(getName(c)(s))
6969
def isSyntheticName(name: String) = {
70-
name == "<init>" || (name.startsWith("<local ") && name.endsWith(">")) || name == "$anonfun"
70+
name == "<init>" || (name.startsWith("<local ") && name.endsWith(">")) || name == "$anonfun" || name == "macro"
7171
}
7272
def getName(c: Reflection)(s: c.Symbol) = {
73-
import c.given
73+
import c.{given _}
7474
s.name.trim
7575
.stripSuffix("$") // meh
7676
}
7777
}
7878

7979
object Macros {
8080

81-
def actualOwner(c: Reflection)(owner: c.Symbol): c.Symbol = {
82-
import c.given
81+
def findOwner(c: Reflection)(owner: c.Symbol, skipIf: (c: Reflection) => (c.Symbol) => Boolean): c.Symbol = {
82+
import c.{given _}
8383
var owner0 = owner
84-
// second condition is meh
85-
while(Util.isSynthetic(c)(owner0) || Util.getName(c)(owner0) == "ev") {
86-
owner0 = owner0.owner
87-
}
84+
while(skipIf(c)(owner0)) owner0 = owner0.owner
8885
owner0
8986
}
9087

91-
def nameImpl(given ctx: QuoteContext): Expr[Name] = {
92-
import ctx.tasty.given
88+
def actualOwner(c: Reflection)(owner: c.Symbol): c.Symbol =
89+
findOwner(c)(owner, c => owner0 => Util.isSynthetic(c)(owner0) || Util.getName(c)(owner0) == "ev")
90+
91+
/**
92+
* In Scala 3, macro `mcr()` is expanded to:
93+
*
94+
* val macro = ...
95+
* macro
96+
*
97+
* Where n is an ordinal. This method returns the first owner that is not
98+
* such a synthetic variable.
99+
*/
100+
def nonMacroOwner(c: Reflection)(owner: c.Symbol): c.Symbol =
101+
findOwner(c)(owner, c => owner0 => {import c.{given _}; owner0.flags.is(c.Flags.Macro) && Util.getName(c)(owner0) == "macro"})
102+
103+
def nameImpl(using ctx: QuoteContext): Expr[Name] = {
104+
import ctx.tasty.{given _}
93105
val owner = actualOwner(ctx.tasty)(ctx.tasty.rootContext.owner)
94106
val simpleName = Util.getName(ctx.tasty)(owner)
95107
'{Name(${Expr(simpleName)})}
@@ -102,15 +114,15 @@ object Macros {
102114
else
103115
s
104116

105-
def nameMachineImpl(given ctx: QuoteContext): Expr[Name.Machine] = {
106-
import ctx.tasty.given
107-
val owner = ctx.tasty.rootContext.owner
117+
def nameMachineImpl(using ctx: QuoteContext): Expr[Name.Machine] = {
118+
import ctx.tasty.{given _}
119+
val owner = nonMacroOwner(ctx.tasty)(ctx.tasty.rootContext.owner)
108120
val simpleName = adjustName(Util.getName(ctx.tasty)(owner))
109121
'{Name.Machine(${Expr(simpleName)})}
110122
}
111123

112-
def fullNameImpl(given ctx: QuoteContext): Expr[FullName] = {
113-
import ctx.tasty.given
124+
def fullNameImpl(using ctx: QuoteContext): Expr[FullName] = {
125+
import ctx.tasty.{given _}
114126
@annotation.tailrec def cleanChunk(chunk: String): String =
115127
val refined = chunk.stripPrefix("_$").stripSuffix("$")
116128
if chunk != refined then cleanChunk(refined) else refined
@@ -125,9 +137,9 @@ object Macros {
125137
'{FullName(${Expr(fullName)})}
126138
}
127139

128-
def fullNameMachineImpl(given ctx: QuoteContext): Expr[FullName.Machine] = {
129-
import ctx.tasty.given
130-
val owner = ctx.tasty.rootContext.owner
140+
def fullNameMachineImpl(using ctx: QuoteContext): Expr[FullName.Machine] = {
141+
import ctx.tasty.{given _}
142+
val owner = nonMacroOwner(ctx.tasty)(ctx.tasty.rootContext.owner)
131143
val fullName = owner.fullName.trim
132144
.split("\\.", -1)
133145
.map(_.stripPrefix("_$").stripSuffix("$")) // meh
@@ -136,39 +148,39 @@ object Macros {
136148
'{FullName.Machine(${Expr(fullName)})}
137149
}
138150

139-
def fileImpl(given ctx: QuoteContext): Expr[sourcecode.File] = {
140-
import ctx.tasty.given
151+
def fileImpl(using ctx: QuoteContext): Expr[sourcecode.File] = {
152+
import ctx.tasty.{given _}
141153
val file = ctx.tasty.rootPosition.sourceFile.jpath.toAbsolutePath.toString
142154
'{sourcecode.File(${Expr(file)})}
143155
}
144156

145-
def fileNameImpl(given ctx: QuoteContext): Expr[sourcecode.FileName] = {
146-
import ctx.tasty.given
157+
def fileNameImpl(using ctx: QuoteContext): Expr[sourcecode.FileName] = {
158+
import ctx.tasty.{given _}
147159
val name = ctx.tasty.rootPosition.sourceFile.jpath.getFileName.toString
148160
'{sourcecode.FileName(${Expr(name)})}
149161
}
150162

151-
def lineImpl(given ctx: QuoteContext): Expr[sourcecode.Line] = {
152-
import ctx.tasty.given
163+
def lineImpl(using ctx: QuoteContext): Expr[sourcecode.Line] = {
164+
import ctx.tasty.{given _}
153165
val line = ctx.tasty.rootPosition.startLine + 1
154166
'{sourcecode.Line(${Expr(line)})}
155167
}
156168

157-
def enclosingImpl(given ctx: QuoteContext): Expr[Enclosing] = {
169+
def enclosingImpl(using ctx: QuoteContext): Expr[Enclosing] = {
158170
val path = enclosing(ctx.tasty)(
159171
!Util.isSynthetic(ctx.tasty)(_)
160172
)
161173

162174
'{Enclosing(${Expr(path)})}
163175
}
164176

165-
def enclosingMachineImpl(given ctx: QuoteContext): Expr[Enclosing.Machine] = {
177+
def enclosingMachineImpl(using ctx: QuoteContext): Expr[Enclosing.Machine] = {
166178
val path = enclosing(ctx.tasty, machine = true)(_ => true)
167179
'{Enclosing.Machine(${Expr(path)})}
168180
}
169181

170-
def pkgImpl(given ctx: QuoteContext): Expr[Pkg] = {
171-
import ctx.tasty.given
182+
def pkgImpl(using ctx: QuoteContext): Expr[Pkg] = {
183+
import ctx.tasty.{given _}
172184
val path = enclosing(ctx.tasty) {
173185
case s if s.isPackageDef => true
174186
case _ => false
@@ -177,8 +189,8 @@ object Macros {
177189
'{Pkg(${Expr(path)})}
178190
}
179191

180-
def argsImpl(given ctx: QuoteContext): Expr[Args] = {
181-
import ctx.tasty.{ _, given }
192+
def argsImpl(using ctx: QuoteContext): Expr[Args] = {
193+
import ctx.tasty.{ _, given _ }
182194

183195
val param: List[List[ctx.tasty.ValDef]] = {
184196
def nearestEnclosingMethod(owner: ctx.tasty.Symbol): List[List[ctx.tasty.ValDef]] =
@@ -207,8 +219,8 @@ object Macros {
207219
}
208220

209221

210-
def text[T: Type](v: Expr[T])(given ctx: QuoteContext): Expr[sourcecode.Text[T]] = {
211-
import ctx.tasty.given
222+
def text[T: Type](v: Expr[T])(using ctx: QuoteContext): Expr[sourcecode.Text[T]] = {
223+
import ctx.tasty.{given _}
212224
val txt = v.unseal.pos.sourceCode
213225
'{sourcecode.Text[T]($v, ${Expr(txt)})}
214226
}
@@ -222,11 +234,13 @@ object Macros {
222234
}
223235

224236
def enclosing(c: Reflection, machine: Boolean = false)(filter: c.Symbol => Boolean): String = {
225-
import c.{ _, given }
237+
import c.{ _, given _ }
226238

227239
var current = c.rootContext.owner
228240
if (!machine)
229241
current = actualOwner(c)(current)
242+
else
243+
current = nonMacroOwner(c)(current)
230244
var path = List.empty[Chunk]
231245
while(current != Symbol.noSymbol && current != defn.RootPackage && current != defn.RootClass){
232246
if (filter(current)) {

0 commit comments

Comments
 (0)