Skip to content

Commit ee2aaad

Browse files
Merge pull request #94 from dotty-staging/dotty-community-build
Update Dotty to Scala 3.0.0-M1
2 parents 37cff3f + 478e1ef commit ee2aaad

File tree

4 files changed

+55
-63
lines changed

4 files changed

+55
-63
lines changed

build.sc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ trait SourcecodeTestModule extends ScalaModule {
6565

6666
object sourcecode extends Module {
6767
val dottyVersion = Option(sys.props("dottyVersion"))
68-
object jvm extends Cross[JvmSourcecodeModule]((List("2.11.12", "2.12.8", "2.13.0", "0.27.0-RC1") ++ dottyVersion): _*)
68+
object jvm extends Cross[JvmSourcecodeModule]((List("2.11.12", "2.12.8", "2.13.0", "3.0.0-M2") ++ dottyVersion): _*)
6969
class JvmSourcecodeModule(val crossScalaVersion: String)
7070
extends SourcecodeMainModule with ScalaModule with SourcecodeModule {
7171

@@ -86,7 +86,7 @@ object sourcecode extends Module {
8686
}
8787

8888
object js extends Cross[JsSourcecodeModule](
89-
("2.11.12", "0.6.28"), ("2.12.10", "0.6.28"), ("2.13.1", "0.6.28"),
89+
("2.11.12", "0.6.33"), ("2.12.10", "0.6.33"), ("2.13.1", "0.6.33"),
9090
("2.11.12", "1.0.0"), ("2.12.10", "1.0.0"), ("2.13.1", "1.0.0")
9191
)
9292
class JsSourcecodeModule(val crossScalaVersion: String, crossJSVersion: String)

mill

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# This is a wrapper script, that automatically download mill from GitHub release pages
44
# You can give the required mill version with MILL_VERSION env variable
55
# If no version is given, it falls back to the value of DEFAULT_MILL_VERSION
6-
DEFAULT_MILL_VERSION=0.6.0-21-93fc8e
6+
DEFAULT_MILL_VERSION=0.8.0-13-105f53
77

88
set -e
99

sourcecode/jvm/src/test/scala/sourcecode/TestUtil.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ object TestUtil {
66
lazy val isDotty = {
77
val cl: ClassLoader = Thread.currentThread().getContextClassLoader
88
try {
9-
cl.loadClass("dotty.DottyPredef")
9+
cl.loadClass("scala.runtime.Scala3RunTime")
1010
true
1111
} catch {
1212
case _: ClassNotFoundException =>

sourcecode/src-0/sourcecode/Macros.scala renamed to sourcecode/src-3/sourcecode/Macros.scala

Lines changed: 51 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package sourcecode
22

33
import scala.language.implicitConversions
44
import scala.quoted._
5-
import scala.tasty.Reflection
65

76
trait NameMacros {
87
inline implicit def generate: Name =
@@ -65,28 +64,26 @@ trait ArgsMacros {
6564
}
6665

6766
object Util{
68-
def isSynthetic(c: Reflection)(s: c.Symbol) = isSyntheticName(getName(c)(s))
67+
def isSynthetic(using Quotes)(s: quotes.reflect.Symbol) = isSyntheticName(getName(s))
6968
def isSyntheticName(name: String) = {
7069
name == "<init>" || (name.startsWith("<local ") && name.endsWith(">")) || name == "$anonfun" || name == "macro"
7170
}
72-
def getName(c: Reflection)(s: c.Symbol) = {
73-
import c.{given _}
71+
def getName(using Quotes)(s: quotes.reflect.Symbol) = {
7472
s.name.trim
7573
.stripSuffix("$") // meh
7674
}
7775
}
7876

7977
object Macros {
8078

81-
def findOwner(c: Reflection)(owner: c.Symbol, skipIf: (c: Reflection) => (c.Symbol) => Boolean): c.Symbol = {
82-
import c.{given _}
79+
def findOwner(using Quotes)(owner: quotes.reflect.Symbol, skipIf: quotes.reflect.Symbol => Boolean): quotes.reflect.Symbol = {
8380
var owner0 = owner
84-
while(skipIf(c)(owner0)) owner0 = owner0.owner
81+
while(skipIf(owner0)) owner0 = owner0.owner
8582
owner0
8683
}
8784

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")
85+
def actualOwner(using Quotes)(owner: quotes.reflect.Symbol): quotes.reflect.Symbol =
86+
findOwner(owner, owner0 => Util.isSynthetic(owner0) || Util.getName(owner0) == "ev")
9087

9188
/**
9289
* In Scala 3, macro `mcr()` is expanded to:
@@ -97,13 +94,13 @@ object Macros {
9794
* Where n is an ordinal. This method returns the first owner that is not
9895
* such a synthetic variable.
9996
*/
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"})
97+
def nonMacroOwner(using Quotes)(owner: quotes.reflect.Symbol): quotes.reflect.Symbol =
98+
findOwner(owner, owner0 => { owner0.flags.is(quotes.reflect.Flags.Macro) && Util.getName(owner0) == "macro"})
10299

103-
def nameImpl(using ctx: QuoteContext): Expr[Name] = {
104-
import ctx.tasty._
105-
val owner = actualOwner(ctx.tasty)(Symbol.currentOwner)
106-
val simpleName = Util.getName(ctx.tasty)(owner)
100+
def nameImpl(using Quotes): Expr[Name] = {
101+
import quotes.reflect._
102+
val owner = actualOwner(Symbol.spliceOwner)
103+
val simpleName = Util.getName(owner)
107104
'{Name(${Expr(simpleName)})}
108105
}
109106

@@ -114,20 +111,20 @@ object Macros {
114111
else
115112
s
116113

117-
def nameMachineImpl(using ctx: QuoteContext): Expr[Name.Machine] = {
118-
import ctx.tasty._
119-
val owner = nonMacroOwner(ctx.tasty)(Symbol.currentOwner)
120-
val simpleName = adjustName(Util.getName(ctx.tasty)(owner))
114+
def nameMachineImpl(using Quotes): Expr[Name.Machine] = {
115+
import quotes.reflect._
116+
val owner = nonMacroOwner(Symbol.spliceOwner)
117+
val simpleName = adjustName(Util.getName(owner))
121118
'{Name.Machine(${Expr(simpleName)})}
122119
}
123120

124-
def fullNameImpl(using ctx: QuoteContext): Expr[FullName] = {
125-
import ctx.tasty._
121+
def fullNameImpl(using Quotes): Expr[FullName] = {
122+
import quotes.reflect._
126123
@annotation.tailrec def cleanChunk(chunk: String): String =
127124
val refined = chunk.stripPrefix("_$").stripSuffix("$")
128125
if chunk != refined then cleanChunk(refined) else refined
129126

130-
val owner = actualOwner(ctx.tasty)(Symbol.currentOwner)
127+
val owner = actualOwner(Symbol.spliceOwner)
131128
val fullName =
132129
owner.fullName.trim
133130
.split("\\.", -1)
@@ -137,9 +134,9 @@ object Macros {
137134
'{FullName(${Expr(fullName)})}
138135
}
139136

140-
def fullNameMachineImpl(using ctx: QuoteContext): Expr[FullName.Machine] = {
141-
import ctx.tasty._
142-
val owner = nonMacroOwner(ctx.tasty)(Symbol.currentOwner)
137+
def fullNameMachineImpl(using Quotes): Expr[FullName.Machine] = {
138+
import quotes.reflect._
139+
val owner = nonMacroOwner(Symbol.spliceOwner)
143140
val fullName = owner.fullName.trim
144141
.split("\\.", -1)
145142
.map(_.stripPrefix("_$").stripSuffix("$")) // meh
@@ -148,52 +145,47 @@ object Macros {
148145
'{FullName.Machine(${Expr(fullName)})}
149146
}
150147

151-
def fileImpl(using ctx: QuoteContext): Expr[sourcecode.File] = {
152-
import ctx.tasty._
153-
val file = ctx.tasty.rootPosition.sourceFile.jpath.toAbsolutePath.toString
148+
def fileImpl(using Quotes): Expr[sourcecode.File] = {
149+
import quotes.reflect._
150+
val file = quotes.reflect.Position.ofMacroExpansion.sourceFile.jpath.toAbsolutePath.toString
154151
'{sourcecode.File(${Expr(file)})}
155152
}
156153

157-
def fileNameImpl(using ctx: QuoteContext): Expr[sourcecode.FileName] = {
158-
import ctx.tasty._
159-
val name = ctx.tasty.rootPosition.sourceFile.jpath.getFileName.toString
154+
def fileNameImpl(using Quotes): Expr[sourcecode.FileName] = {
155+
val name = quotes.reflect.Position.ofMacroExpansion.sourceFile.jpath.getFileName.toString
160156
'{sourcecode.FileName(${Expr(name)})}
161157
}
162158

163-
def lineImpl(using ctx: QuoteContext): Expr[sourcecode.Line] = {
164-
import ctx.tasty._
165-
val line = ctx.tasty.rootPosition.startLine + 1
159+
def lineImpl(using Quotes): Expr[sourcecode.Line] = {
160+
val line = quotes.reflect.Position.ofMacroExpansion.startLine + 1
166161
'{sourcecode.Line(${Expr(line)})}
167162
}
168163

169-
def enclosingImpl(using ctx: QuoteContext): Expr[Enclosing] = {
170-
val path = enclosing(ctx.tasty)(
171-
!Util.isSynthetic(ctx.tasty)(_)
172-
)
173-
164+
def enclosingImpl(using Quotes): Expr[Enclosing] = {
165+
import quotes.reflect._
166+
val path = enclosing(machine = false)(!Util.isSynthetic(_))
174167
'{Enclosing(${Expr(path)})}
175168
}
176169

177-
def enclosingMachineImpl(using ctx: QuoteContext): Expr[Enclosing.Machine] = {
178-
val path = enclosing(ctx.tasty, machine = true)(_ => true)
170+
def enclosingMachineImpl(using Quotes): Expr[Enclosing.Machine] = {
171+
val path = enclosing(machine = true)(_ => true)
179172
'{Enclosing.Machine(${Expr(path)})}
180173
}
181174

182-
def pkgImpl(using ctx: QuoteContext): Expr[Pkg] = {
183-
import ctx.tasty._
184-
val path = enclosing(ctx.tasty) {
175+
def pkgImpl(using Quotes): Expr[Pkg] = {
176+
val path = enclosing(machine = false) {
185177
case s if s.isPackageDef => true
186178
case _ => false
187179
}
188180

189181
'{Pkg(${Expr(path)})}
190182
}
191183

192-
def argsImpl(using ctx: QuoteContext): Expr[Args] = {
193-
import ctx.tasty._
184+
def argsImpl(using qctx: Quotes): Expr[Args] = {
185+
import quotes.reflect._
194186

195-
val param: List[List[ctx.tasty.ValDef]] = {
196-
def nearestEnclosingMethod(owner: ctx.tasty.Symbol): List[List[ctx.tasty.ValDef]] =
187+
val param: List[List[ValDef]] = {
188+
def nearestEnclosingMethod(owner: Symbol): List[List[ValDef]] =
197189
owner match {
198190
case defSym if defSym.isDefDef =>
199191
defSym.tree.asInstanceOf[DefDef].paramss
@@ -203,12 +195,12 @@ object Macros {
203195
nearestEnclosingMethod(owner.owner)
204196
}
205197

206-
nearestEnclosingMethod(Symbol.currentOwner)
198+
nearestEnclosingMethod(Symbol.spliceOwner)
207199
}
208200

209201
val texts0 = param.map(_.foldRight('{List.empty[Text[_]]}) {
210202
case (vd @ ValDef(nme, _, optV), l) =>
211-
'{Text(${optV.fold('None)(_.seal)}, ${Expr(nme)}) :: $l}
203+
'{Text(${optV.fold('None)(_.asExpr)}, ${Expr(nme)}) :: $l}
212204
})
213205
val texts = texts0.foldRight('{List.empty[List[Text[_]]]}) {
214206
case (l, acc) =>
@@ -219,9 +211,9 @@ object Macros {
219211
}
220212

221213

222-
def text[T: Type](v: Expr[T])(using ctx: QuoteContext): Expr[sourcecode.Text[T]] = {
223-
import ctx.tasty._
224-
val txt = v.unseal.pos.sourceCode
214+
def text[T: Type](v: Expr[T])(using Quotes): Expr[sourcecode.Text[T]] = {
215+
import quotes.reflect._
216+
val txt = Term.of(v).pos.sourceCode
225217
'{sourcecode.Text[T]($v, ${Expr(txt)})}
226218
}
227219

@@ -233,14 +225,14 @@ object Macros {
233225

234226
}
235227

236-
def enclosing(c: Reflection, machine: Boolean = false)(filter: c.Symbol => Boolean): String = {
237-
import c._
228+
def enclosing(using Quotes)(machine: Boolean)(filter: quotes.reflect.Symbol => Boolean): String = {
229+
import quotes.reflect._
238230

239-
var current = Symbol.currentOwner
231+
var current = Symbol.spliceOwner
240232
if (!machine)
241-
current = actualOwner(c)(current)
233+
current = actualOwner(current)
242234
else
243-
current = nonMacroOwner(c)(current)
235+
current = nonMacroOwner(current)
244236
var path = List.empty[Chunk]
245237
while(current != Symbol.noSymbol && current != defn.RootPackage && current != defn.RootClass){
246238
if (filter(current)) {
@@ -255,7 +247,7 @@ object Macros {
255247
case _ => Chunk.PkgObj
256248
}
257249

258-
path = chunk(Util.getName(c)(current).stripSuffix("$")) :: path
250+
path = chunk(Util.getName(current).stripSuffix("$")) :: path
259251
}
260252
current = current.owner
261253
}

0 commit comments

Comments
 (0)