Skip to content

Commit 68e1fea

Browse files
committed
Convert other dotc classes (2)
1 parent edb4869 commit 68e1fea

18 files changed

+86
-85
lines changed

compiler/src/dotty/tools/dotc/sbt/ExtractAPI.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import scala.collection.mutable
4141
class ExtractAPI extends Phase {
4242
override def phaseName: String = "sbt-api"
4343

44-
override def isRunnable(implicit ctx: Context): Boolean = {
44+
override def isRunnable(using Context): Boolean = {
4545
def forceRun = ctx.settings.YdumpSbtInc.value || ctx.settings.YforceSbtPhases.value
4646
super.isRunnable && (ctx.sbtCallback != null || forceRun)
4747
}
@@ -56,7 +56,7 @@ class ExtractAPI extends Phase {
5656
// definitions, and `PostTyper` does not change definitions).
5757
override def runsAfter: Set[String] = Set(transform.PostTyper.name)
5858

59-
override def run(implicit ctx: Context): Unit = {
59+
override def run(using Context): Unit = {
6060
val unit = ctx.compilationUnit
6161
val sourceFile = unit.source.file
6262
if (ctx.sbtCallback != null)
@@ -124,7 +124,7 @@ class ExtractAPI extends Phase {
124124
* without going through an intermediate representation, see
125125
* http://www.scala-sbt.org/0.13/docs/Understanding-Recompilation.html#Hashing+an+API+representation
126126
*/
127-
private class ExtractAPICollector(implicit ctx: Context) extends ThunkHolder {
127+
private class ExtractAPICollector(using Context) extends ThunkHolder {
128128
import tpd._
129129
import xsbti.api
130130

compiler/src/dotty/tools/dotc/sbt/ExtractDependencies.scala

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class ExtractDependencies extends Phase {
4949

5050
override def phaseName: String = "sbt-deps"
5151

52-
override def isRunnable(implicit ctx: Context): Boolean = {
52+
override def isRunnable(using Context): Boolean = {
5353
def forceRun = ctx.settings.YdumpSbtInc.value || ctx.settings.YforceSbtPhases.value
5454
super.isRunnable && (ctx.sbtCallback != null || forceRun)
5555
}
@@ -62,7 +62,7 @@ class ExtractDependencies extends Phase {
6262
// See the scripted test `constants` for an example where this matters.
6363
// TODO: Add a `Phase#runsBefore` method ?
6464

65-
override def run(implicit ctx: Context): Unit = {
65+
override def run(using Context): Unit = {
6666
val unit = ctx.compilationUnit
6767
val collector = new ExtractDependenciesCollector
6868
collector.traverse(unit.tpdTree)
@@ -105,7 +105,7 @@ class ExtractDependencies extends Phase {
105105
* that is coming from either source code (not necessarily compiled in this compilation
106106
* run) or from class file and calls respective callback method.
107107
*/
108-
def recordDependency(dep: ClassDependency)(implicit ctx: Context): Unit = {
108+
def recordDependency(dep: ClassDependency)(using Context): Unit = {
109109
val fromClassName = classNameAsString(dep.from)
110110
val sourceFile = ctx.compilationUnit.source.file.file
111111

@@ -161,7 +161,7 @@ class ExtractDependencies extends Phase {
161161
}
162162

163163
object ExtractDependencies {
164-
def classNameAsString(sym: Symbol)(implicit ctx: Context): String =
164+
def classNameAsString(sym: Symbol)(using Context): String =
165165
sym.fullName.stripModuleClassSuffix.toString
166166
}
167167

@@ -217,10 +217,10 @@ private class ExtractDependenciesCollector extends tpd.TreeTraverser { thisTreeT
217217
* class/trait/object declared in the compilation unit. If none exists, issue warning.
218218
*/
219219
private var _responsibleForImports: Symbol = _
220-
private def responsibleForImports(implicit ctx: Context) = {
220+
private def responsibleForImports(using Context) = {
221221
def firstClassOrModule(tree: Tree) = {
222222
val acc = new TreeAccumulator[Symbol] {
223-
def apply(x: Symbol, t: Tree)(implicit ctx: Context) =
223+
def apply(x: Symbol, t: Tree)(using Context) =
224224
t match {
225225
case typeDef: TypeDef =>
226226
typeDef.symbol
@@ -250,7 +250,7 @@ private class ExtractDependenciesCollector extends tpd.TreeTraverser { thisTreeT
250250
* Resolves dependency source (that is, the closest non-local enclosing
251251
* class from a given `ctx.owner`
252252
*/
253-
private def resolveDependencySource(implicit ctx: Context): Symbol = {
253+
private def resolveDependencySource(using Context): Symbol = {
254254
def nonLocalEnclosingClass = {
255255
var clazz = ctx.owner.enclosingClass
256256
var owner = clazz
@@ -280,7 +280,7 @@ private class ExtractDependenciesCollector extends tpd.TreeTraverser { thisTreeT
280280
usedName.update(name, scope)
281281
}
282282

283-
private def addUsedName(name: Name, scope: UseScope)(implicit ctx: Context): Unit = {
283+
private def addUsedName(name: Name, scope: UseScope)(using Context): Unit = {
284284
val fromClass = resolveDependencySource
285285
if (fromClass.exists) { // can happen when visiting imports
286286
assert(fromClass.isClass)
@@ -289,14 +289,14 @@ private class ExtractDependenciesCollector extends tpd.TreeTraverser { thisTreeT
289289
}
290290

291291
/** Mangle a JVM symbol name in a format better suited for internal uses by sbt. */
292-
private def mangledName(sym: Symbol)(implicit ctx: Context): Name = {
292+
private def mangledName(sym: Symbol)(using Context): Name = {
293293
def constructorName = sym.owner.fullName ++ ";init;"
294294

295295
if (sym.isConstructor) constructorName
296296
else sym.name.stripModuleClassSuffix
297297
}
298298

299-
private def addMemberRefDependency(sym: Symbol)(implicit ctx: Context): Unit =
299+
private def addMemberRefDependency(sym: Symbol)(using Context): Unit =
300300
if (!ignoreDependency(sym)) {
301301
val enclOrModuleClass = if (sym.is(ModuleVal)) sym.moduleClass else sym.enclosingClass
302302
assert(enclOrModuleClass.isClass, s"$enclOrModuleClass, $sym")
@@ -313,7 +313,7 @@ private class ExtractDependenciesCollector extends tpd.TreeTraverser { thisTreeT
313313
}
314314
}
315315

316-
private def addInheritanceDependencies(tree: Template)(implicit ctx: Context): Unit =
316+
private def addInheritanceDependencies(tree: Template)(using Context): Unit =
317317
if (tree.parents.nonEmpty) {
318318
val depContext =
319319
if (tree.symbol.owner.isLocal) LocalDependencyByInheritance
@@ -324,7 +324,7 @@ private class ExtractDependenciesCollector extends tpd.TreeTraverser { thisTreeT
324324
}
325325
}
326326

327-
private def ignoreDependency(sym: Symbol)(implicit ctx: Context) =
327+
private def ignoreDependency(sym: Symbol)(using Context) =
328328
!sym.exists ||
329329
sym.isAbsent(canForce = false) || // ignore dependencies that have a symbol but do not exist.
330330
// e.g. java.lang.Object companion object
@@ -335,7 +335,7 @@ private class ExtractDependenciesCollector extends tpd.TreeTraverser { thisTreeT
335335
/** Traverse the tree of a source file and record the dependencies and used names which
336336
* can be retrieved using `dependencies` and`usedNames`.
337337
*/
338-
override def traverse(tree: Tree)(implicit ctx: Context): Unit = try {
338+
override def traverse(tree: Tree)(using Context): Unit = try {
339339
tree match {
340340
case Match(selector, _) =>
341341
addPatMatDependency(selector.tpe)
@@ -415,7 +415,7 @@ private class ExtractDependenciesCollector extends tpd.TreeTraverser { thisTreeT
415415
* The tests in sbt `types-in-used-names-a`, `types-in-used-names-b`,
416416
* `as-seen-from-a` and `as-seen-from-b` rely on this.
417417
*/
418-
private abstract class TypeDependencyTraverser(implicit ctx: Context) extends TypeTraverser()(using ctx) {
418+
private abstract class TypeDependencyTraverser(using Context) extends TypeTraverser()(using ctx) {
419419
protected def addDependency(symbol: Symbol): Unit
420420

421421
val seen = new mutable.HashSet[Type]
@@ -442,14 +442,14 @@ private class ExtractDependenciesCollector extends tpd.TreeTraverser { thisTreeT
442442
}
443443
}
444444

445-
def addTypeDependency(tpe: Type)(implicit ctx: Context): Unit = {
445+
def addTypeDependency(tpe: Type)(using Context): Unit = {
446446
val traverser = new TypeDependencyTraverser {
447447
def addDependency(symbol: Symbol) = addMemberRefDependency(symbol)
448448
}
449449
traverser.traverse(tpe)
450450
}
451451

452-
def addPatMatDependency(tpe: Type)(implicit ctx: Context): Unit = {
452+
def addPatMatDependency(tpe: Type)(using Context): Unit = {
453453
val traverser = new TypeDependencyTraverser {
454454
def addDependency(symbol: Symbol) =
455455
if (!ignoreDependency(symbol) && symbol.is(Sealed)) {

compiler/src/dotty/tools/dotc/semanticdb/ExtractSemanticDB.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ class ExtractSemanticDB extends Phase:
3535

3636
override val phaseName: String = ExtractSemanticDB.name
3737

38-
override def isRunnable(implicit ctx: Context) =
38+
override def isRunnable(using Context) =
3939
super.isRunnable && ctx.settings.Ysemanticdb.value
4040

4141
// Check not needed since it does not transform trees
4242
override def isCheckable: Boolean = false
4343

44-
override def run(implicit ctx: Context): Unit =
44+
override def run(using Context): Unit =
4545
val unit = ctx.compilationUnit
4646
val extract = Extractor()
4747
extract.traverse(unit.tpdTree)

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import dotty.tools.dotc.core.Types._
1010

1111
object FromSymbol {
1212

13-
def definitionFromSym(sym: Symbol)(implicit ctx: Context): tpd.Tree = {
13+
def definitionFromSym(sym: Symbol)(using Context): tpd.Tree = {
1414
assert(sym.exists)
1515
if (sym.is(Package)) packageDefFromSym(sym)
1616
else if (sym.isClass) classDef(sym.asClass)
@@ -21,9 +21,9 @@ object FromSymbol {
2121
else valDefFromSym(sym.asTerm)
2222
}
2323

24-
def packageDefFromSym(sym: Symbol)(implicit ctx: Context): PackageDefinition = PackageDefinitionImpl(sym)
24+
def packageDefFromSym(sym: Symbol)(using Context): PackageDefinition = PackageDefinitionImpl(sym)
2525

26-
def classDef(cls: ClassSymbol)(implicit ctx: Context): tpd.TypeDef = cls.defTree match {
26+
def classDef(cls: ClassSymbol)(using Context): tpd.TypeDef = cls.defTree match {
2727
case tree: tpd.TypeDef => tree
2828
case tpd.EmptyTree =>
2929
val constrSym = cls.unforcedDecls.find(_.isPrimaryConstructor).orElse(
@@ -36,27 +36,27 @@ object FromSymbol {
3636
tpd.ClassDefWithParents(cls, constr, parents, body)
3737
}
3838

39-
def typeDefFromSym(sym: TypeSymbol)(implicit ctx: Context): tpd.TypeDef = sym.defTree match {
39+
def typeDefFromSym(sym: TypeSymbol)(using Context): tpd.TypeDef = sym.defTree match {
4040
case tree: tpd.TypeDef => tree
4141
case tpd.EmptyTree => tpd.TypeDef(sym)
4242
}
4343

44-
def defDefFromSym(sym: TermSymbol)(implicit ctx: Context): tpd.DefDef = sym.defTree match {
44+
def defDefFromSym(sym: TermSymbol)(using Context): tpd.DefDef = sym.defTree match {
4545
case tree: tpd.DefDef => tree
4646
case tpd.EmptyTree => tpd.DefDef(sym)
4747
}
4848

49-
def valDefFromSym(sym: TermSymbol)(implicit ctx: Context): tpd.ValDef = sym.defTree match {
49+
def valDefFromSym(sym: TermSymbol)(using Context): tpd.ValDef = sym.defTree match {
5050
case tree: tpd.ValDef => tree
5151
case tpd.EmptyTree => tpd.ValDef(sym)
5252
}
5353

54-
def bindFromSym(sym: TermSymbol)(implicit ctx: Context): tpd.Bind = sym.defTree match {
54+
def bindFromSym(sym: TermSymbol)(using Context): tpd.Bind = sym.defTree match {
5555
case tree: tpd.Bind => tree
5656
case tpd.EmptyTree => tpd.Bind(sym, untpd.Ident(nme.WILDCARD).withType(sym.typeRef))
5757
}
5858

59-
def typeBindFromSym(sym: TypeSymbol)(implicit ctx: Context): tpd.Bind = sym.defTree match {
59+
def typeBindFromSym(sym: TypeSymbol)(using Context): tpd.Bind = sym.defTree match {
6060
case tree: tpd.Bind => tree
6161
case tpd.EmptyTree => tpd.Bind(sym, untpd.Ident(nme.WILDCARD).withType(sym.typeRef))
6262
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ object MacroExpansion {
1010

1111
private val MacroExpansionPosition = new Property.Key[SourcePosition]
1212

13-
def position(implicit ctx: Context): Option[SourcePosition] =
13+
def position(using Context): Option[SourcePosition] =
1414
ctx.property(MacroExpansionPosition)
1515

16-
def context(inlinedFrom: tpd.Tree)(implicit ctx: Context): Context =
16+
def context(inlinedFrom: tpd.Tree)(using Context): Context =
1717
ctx.fresh.setProperty(MacroExpansionPosition, SourcePosition(inlinedFrom.source, inlinedFrom.span)).setTypeAssigner(new Typer).withSource(inlinedFrom.source)
1818
}
1919

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ package object tastyreflect {
1616
case class PackageDefinitionImpl[-T >: Untyped] private[tastyreflect] (sym: Symbol)(implicit @constructorOnly src: SourceFile) extends Tree[T] {
1717
type ThisTree[-T >: Untyped] = PackageDefinitionImpl[T]
1818

19-
override def denot(implicit ctx: Context): SymDenotation = sym.denot
19+
override def denot(using Context): SymDenotation = sym.denot
2020
}
2121
}
2222

compiler/src/dotty/tools/dotc/typer/ConstFold.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ object ConstFold {
1919
import tpd._
2020

2121
/** If tree is a constant operation, replace with result. */
22-
def apply[T <: Tree](tree: T)(implicit ctx: Context): T = finish(tree) {
22+
def apply[T <: Tree](tree: T)(using Context): T = finish(tree) {
2323
tree match {
2424
case Apply(Select(xt, op), yt :: Nil) =>
2525
xt.tpe.widenTermRefExpr.normalized match
@@ -45,15 +45,15 @@ object ConstFold {
4545
/** If tree is a constant value that can be converted to type `pt`, perform
4646
* the conversion.
4747
*/
48-
def apply[T <: Tree](tree: T, pt: Type)(implicit ctx: Context): T =
48+
def apply[T <: Tree](tree: T, pt: Type)(using Context): T =
4949
finish(apply(tree)) {
5050
tree.tpe.widenTermRefExpr.normalized match {
5151
case ConstantType(x) => x convertTo pt
5252
case _ => null
5353
}
5454
}
5555

56-
inline private def finish[T <: Tree](tree: T)(compX: => Constant)(implicit ctx: Context): T =
56+
inline private def finish[T <: Tree](tree: T)(compX: => Constant)(using Context): T =
5757
try {
5858
val x = compX
5959
if (x ne null) tree.withType(ConstantType(x)).asInstanceOf[T]

compiler/src/dotty/tools/dotc/typer/Deriving.scala

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ trait Deriving {
2828
* synthesized infrastructure code that is not connected with a
2929
* `derives` instance.
3030
*/
31-
class Deriver(cls: ClassSymbol, codePos: SourcePosition)(implicit ctx: Context) {
31+
class Deriver(cls: ClassSymbol, codePos: SourcePosition)(using Context) {
3232

3333
/** A buffer for synthesized symbols for type class instances */
3434
private var synthetics = new mutable.ListBuffer[Symbol]
@@ -268,7 +268,7 @@ trait Deriving {
268268
import tpd._
269269

270270
/** The type class instance definition with symbol `sym` */
271-
def typeclassInstance(sym: Symbol)(implicit ctx: Context): List[Type] => (List[List[tpd.Tree]] => tpd.Tree) = {
271+
def typeclassInstance(sym: Symbol)(using Context): List[Type] => (List[List[tpd.Tree]] => tpd.Tree) = {
272272
(tparamRefs: List[Type]) => (paramRefss: List[List[tpd.Tree]]) =>
273273
val tparams = tparamRefs.map(_.typeSymbol.asType)
274274
val params = if (paramRefss.isEmpty) Nil else paramRefss.head.map(_.symbol.asTerm)
@@ -291,8 +291,9 @@ trait Deriving {
291291
typed(rhs, resultType)
292292
}
293293

294-
def syntheticDef(sym: Symbol): Tree =
295-
tpd.polyDefDef(sym.asTerm, typeclassInstance(sym)(ctx.fresh.setOwner(sym).setNewScope))
294+
def syntheticDef(sym: Symbol): Tree = inContext(ctx.fresh.setOwner(sym).setNewScope) {
295+
tpd.polyDefDef(sym.asTerm, typeclassInstance(sym))
296+
}
296297

297298
synthetics.map(syntheticDef).toList
298299
}

compiler/src/dotty/tools/dotc/typer/Docstrings.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ object Docstrings {
5656
newComment
5757
}
5858

59-
private def expandComment(sym: Symbol)(implicit ctx: Context, docCtx: ContextDocstrings): Option[Comment] =
59+
private def expandComment(sym: Symbol)(using Context)(using docCtx: ContextDocstrings): Option[Comment] =
6060
if (sym eq NoSymbol) None
6161
else
6262
for {

compiler/src/dotty/tools/dotc/typer/Inferencing.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ object Inferencing {
164164
)
165165
}
166166

167-
def approximateGADT(tp: Type)(implicit ctx: Context): Type = {
167+
def approximateGADT(tp: Type)(using Context): Type = {
168168
val map = new ApproximateGadtAccumulator
169169
val res = map(tp)
170170
assert(!map.failed)
@@ -174,7 +174,7 @@ object Inferencing {
174174
/** This class is mostly based on IsFullyDefinedAccumulator.
175175
* It tries to approximate the given type based on the available GADT constraints.
176176
*/
177-
private class ApproximateGadtAccumulator(implicit ctx: Context) extends TypeMap {
177+
private class ApproximateGadtAccumulator(using Context) extends TypeMap {
178178

179179
var failed = false
180180

@@ -184,7 +184,7 @@ object Inferencing {
184184
inst
185185
}
186186

187-
private def instDirection2(sym: Symbol)(implicit ctx: Context): Int = {
187+
private def instDirection2(sym: Symbol)(using Context): Int = {
188188
val constrained = ctx.gadt.fullBounds(sym)
189189
val original = sym.info.bounds
190190
val cmp = ctx.typeComparer

compiler/src/dotty/tools/dotc/typer/Inliner.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
502502
* of a containing object so they are merely idempotent.
503503
*/
504504
object isElideableExpr {
505-
def isStatElideable(tree: Tree)(implicit ctx: Context): Boolean = unsplice(tree) match {
505+
def isStatElideable(tree: Tree)(using Context): Boolean = unsplice(tree) match {
506506
case EmptyTree
507507
| TypeDef(_, _)
508508
| Import(_, _)

0 commit comments

Comments
 (0)