Skip to content

Commit cddf112

Browse files
committed
Switch to (using Context) in more files in typer
1 parent 3f9c289 commit cddf112

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

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

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ class FrontEnd extends Phase {
3838
def stillToBeEntered(name: String): Boolean =
3939
remaining.exists(_.compilationUnit.toString.endsWith(name + ".scala"))
4040

41-
def monitor(doing: String)(body: => Unit)(implicit ctx: Context): Unit =
41+
def monitor(doing: String)(body: => Unit)(using Context): Unit =
4242
try body
4343
catch {
4444
case NonFatal(ex) =>
4545
ctx.echo(s"exception occurred while $doing ${ctx.compilationUnit}")
4646
throw ex
4747
}
4848

49-
def parse(implicit ctx: Context): Unit = monitor("parsing") {
49+
def parse(using Context): Unit = monitor("parsing") {
5050
val unit = ctx.compilationUnit
5151

5252
unit.untpdTree =
@@ -65,13 +65,13 @@ class FrontEnd extends Phase {
6565
unit.untpdTree.checkPos(nonOverlapping = !unit.isJava && !ctx.reporter.hasErrors)
6666
}
6767

68-
def enterSyms(implicit ctx: Context): Unit = monitor("indexing") {
68+
def enterSyms(using Context): Unit = monitor("indexing") {
6969
val unit = ctx.compilationUnit
7070
ctx.typer.index(unit.untpdTree)
7171
typr.println("entered: " + unit.source)
7272
}
7373

74-
def typeCheck(implicit ctx: Context): Unit = monitor("typechecking") {
74+
def typeCheck(using Context): Unit = monitor("typechecking") {
7575
try
7676
val unit = ctx.compilationUnit
7777
if !unit.suspended then
@@ -83,35 +83,34 @@ class FrontEnd extends Phase {
8383
case ex: CompilationUnit.SuspendException =>
8484
}
8585

86-
private def firstTopLevelDef(trees: List[tpd.Tree])(implicit ctx: Context): Symbol = trees match {
86+
private def firstTopLevelDef(trees: List[tpd.Tree])(using Context): Symbol = trees match {
8787
case PackageDef(_, defs) :: _ => firstTopLevelDef(defs)
8888
case Import(_, _) :: defs => firstTopLevelDef(defs)
8989
case (tree @ TypeDef(_, _)) :: _ => tree.symbol
9090
case _ => NoSymbol
9191
}
9292

93-
protected def discardAfterTyper(unit: CompilationUnit)(implicit ctx: Context): Boolean =
93+
protected def discardAfterTyper(unit: CompilationUnit)(using Context): Boolean =
9494
unit.isJava || unit.suspended
9595

96-
override def runOn(units: List[CompilationUnit])(implicit ctx: Context): List[CompilationUnit] = {
97-
val unitContexts = for (unit <- units) yield {
98-
ctx.inform(s"compiling ${unit.source}")
99-
ctx.fresh.setCompilationUnit(unit)
100-
}
101-
unitContexts.foreach(parse(_))
96+
override def runOn(units: List[CompilationUnit])(using Context): List[CompilationUnit] = {
97+
val unitContexts =
98+
for unit <- units yield
99+
ctx.inform(s"compiling ${unit.source}")
100+
ctx.fresh.setCompilationUnit(unit)
101+
unitContexts.foreach(parse(using _))
102102
record("parsedTrees", ast.Trees.ntrees)
103103
remaining = unitContexts
104-
while (remaining.nonEmpty) {
105-
enterSyms(remaining.head)
104+
while remaining.nonEmpty do
105+
enterSyms(using remaining.head)
106106
remaining = remaining.tail
107-
}
108107

109108
if (firstXmlPos.exists && !defn.ScalaXmlPackageClass.exists)
110109
ctx.error("""To support XML literals, your project must depend on scala-xml.
111110
|See https://github.com/scala/scala-xml for more information.""".stripMargin,
112111
firstXmlPos)
113112

114-
unitContexts.foreach(typeCheck(_))
113+
unitContexts.foreach(typeCheck(using _))
115114
record("total trees after typer", ast.Trees.ntrees)
116115
val newUnits = unitContexts.map(_.compilationUnit).filterNot(discardAfterTyper)
117116
val suspendedUnits = ctx.run.suspendedUnits
@@ -132,7 +131,7 @@ class FrontEnd extends Phase {
132131
newUnits
133132
}
134133

135-
def run(implicit ctx: Context): Unit = unsupported("run")
134+
def run(using Context): Unit = unsupported("run")
136135
}
137136

138137
object FrontEnd {

compiler/src/dotty/tools/repl/ReplFrontEnd.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ private[repl] class REPLFrontEnd extends FrontEnd {
1919
assert(units.size == 1) // REPl runs one compilation unit at a time
2020

2121
val unitContext = ctx.fresh.setCompilationUnit(units.head)
22-
enterSyms(unitContext)
23-
typeCheck(unitContext)
22+
enterSyms(using unitContext)
23+
typeCheck(using unitContext)
2424
List(unitContext.compilationUnit)
2525
}
2626
}

0 commit comments

Comments
 (0)