Skip to content

Commit 5d350e5

Browse files
committed
Convert repl classes
1 parent 71f15c3 commit 5d350e5

File tree

8 files changed

+35
-35
lines changed

8 files changed

+35
-35
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ object ReflectionImpl {
1111
def apply(rootContext: Contexts.Context): scala.tasty.Reflection =
1212
new scala.tasty.Reflection(new ReflectionCompilerInterface(rootContext))
1313

14-
def showTree(tree: tpd.Tree)(implicit ctx: Contexts.Context): String = {
14+
def showTree(tree: tpd.Tree)(using Contexts.Context): String = {
1515
val refl = new scala.tasty.Reflection(new ReflectionCompilerInterface(MacroExpansion.context(tree)))
1616
val reflCtx = ctx.asInstanceOf[refl.Context]
1717
val reflTree = tree.asInstanceOf[refl.Tree]

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class CollectTopLevelImports extends Phase {
1818
private var myImports: List[Import] = _
1919
def imports: List[Import] = myImports
2020

21-
def run(implicit ctx: Context): Unit = {
21+
def run(using Context): Unit = {
2222
def topLevelImports(tree: Tree) = {
2323
val PackageDef(_, _ :: TypeDef(_, rhs: Template) :: _) = tree
2424
rhs.body.collect { case tree: Import => tree }

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ final class JLineTerminal extends java.io.Closeable {
2424
.build()
2525
private val history = new DefaultHistory
2626

27-
private def blue(str: String)(implicit ctx: Context) =
27+
private def blue(str: String)(using Context) =
2828
if (ctx.settings.color.value != "never") Console.BLUE + str + Console.RESET
2929
else str
30-
private def prompt(implicit ctx: Context) = blue("scala> ")
31-
private def newLinePrompt(implicit ctx: Context) = blue(" | ")
30+
private def prompt(using Context) = blue("scala> ")
31+
private def newLinePrompt(using Context) = blue(" | ")
3232

3333
/** Blockingly read line from `System.in`
3434
*
@@ -45,7 +45,7 @@ final class JLineTerminal extends java.io.Closeable {
4545
*/
4646
def readLine(
4747
completer: Completer // provide auto-completions
48-
)(implicit ctx: Context): String = {
48+
)(using Context): String = {
4949
import LineReader.Option._
5050
import LineReader._
5151
val userHome = System.getProperty("user.home")
@@ -74,7 +74,7 @@ final class JLineTerminal extends java.io.Closeable {
7474
def close(): Unit = terminal.close()
7575

7676
/** Provide syntax highlighting */
77-
private class Highlighter(implicit ctx: Context) extends reader.Highlighter {
77+
private class Highlighter(using Context) extends reader.Highlighter {
7878
def highlight(reader: LineReader, buffer: String): AttributedString = {
7979
val highlighted = SyntaxHighlighting.highlight(buffer)
8080
AttributedString.fromAnsi(highlighted)
@@ -84,7 +84,7 @@ final class JLineTerminal extends java.io.Closeable {
8484
}
8585

8686
/** Provide multi-line editing support */
87-
private class Parser(implicit ctx: Context) extends reader.Parser {
87+
private class Parser(using Context) extends reader.Parser {
8888

8989
/**
9090
* @param cursor The cursor position within the line

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package repl
33

44
import dotc.CompilationUnit
55
import dotc.ast.untpd
6-
import dotc.core.Contexts.{Context, inContext}
6+
import dotc.core.Contexts.{Context, ctx, inContext}
77
import dotc.core.StdNames.str
88
import dotc.parsing.Parsers.Parser
99
import dotc.parsing.Tokens
@@ -112,7 +112,7 @@ object ParseResult {
112112

113113
@sharable private val CommandExtract = """(:[\S]+)\s*(.*)""".r
114114

115-
private def parseStats(implicit ctx: Context): List[untpd.Tree] = {
115+
private def parseStats(using Context): List[untpd.Tree] = {
116116
val parser = new Parser(ctx.source)
117117
val stats = parser.blockStatSeq()
118118
parser.accept(Tokens.EOF)
@@ -144,7 +144,7 @@ object ParseResult {
144144
case _ =>
145145
inContext(state.context) {
146146
val reporter = newStoreReporter
147-
val stats = parseStats(state.context.fresh.setReporter(reporter).withSource(source))
147+
val stats = parseStats(using state.context.fresh.setReporter(reporter).withSource(source))
148148

149149
if (reporter.hasErrors)
150150
SyntaxErrors(
@@ -165,7 +165,7 @@ object ParseResult {
165165
* This can be used in order to check if a newline can be inserted without
166166
* having to evaluate the expression.
167167
*/
168-
def isIncomplete(sourceCode: String)(implicit ctx: Context): Boolean =
168+
def isIncomplete(sourceCode: String)(using Context): Boolean =
169169
sourceCode match {
170170
case CommandExtract(_) | "" => false
171171
case _ => {
@@ -177,7 +177,7 @@ object ParseResult {
177177
.setReporter(reporter)
178178
var needsMore = false
179179
reporter.withIncompleteHandler((_, _) => needsMore = true) {
180-
parseStats(localCtx)
180+
parseStats(using localCtx)
181181
}
182182
!reporter.hasErrors && needsMore
183183
}

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ private[repl] class Rendering(parentClassLoader: Option[ClassLoader] = None) {
3333

3434
/** A `MessageRenderer` for the REPL without file positions */
3535
private val messageRenderer = new MessageRendering {
36-
override def posStr(pos: SourcePosition, diagnosticLevel: String, message: Message)(implicit ctx: Context): String = ""
36+
override def posStr(pos: SourcePosition, diagnosticLevel: String, message: Message)(using Context): String = ""
3737
}
3838

3939
private var myClassLoader: ClassLoader = _
@@ -42,7 +42,7 @@ private[repl] class Rendering(parentClassLoader: Option[ClassLoader] = None) {
4242

4343

4444
/** Class loader used to load compiled code */
45-
private[repl] def classLoader()(implicit ctx: Context) =
45+
private[repl] def classLoader()(using Context) =
4646
if (myClassLoader != null) myClassLoader
4747
else {
4848
val parent = parentClassLoader.getOrElse {
@@ -65,7 +65,7 @@ private[repl] class Rendering(parentClassLoader: Option[ClassLoader] = None) {
6565
}
6666

6767
/** Return a String representation of a value we got from `classLoader()`. */
68-
private[repl] def replStringOf(value: Object)(implicit ctx: Context): String = {
68+
private[repl] def replStringOf(value: Object)(using Context): String = {
6969
assert(myReplStringOf != null,
7070
"replStringOf should only be called on values creating using `classLoader()`, but `classLoader()` has not been called so far")
7171
myReplStringOf(value)
@@ -75,7 +75,7 @@ private[repl] class Rendering(parentClassLoader: Option[ClassLoader] = None) {
7575
*
7676
* Calling this method evaluates the expression using reflection
7777
*/
78-
private def valueOf(sym: Symbol)(implicit ctx: Context): Option[String] = {
78+
private def valueOf(sym: Symbol)(using Context): Option[String] = {
7979
val objectName = sym.owner.fullName.encode.toString.stripSuffix("$")
8080
val resObj: Class[?] = Class.forName(objectName, true, classLoader())
8181
val value =
@@ -102,18 +102,18 @@ private[repl] class Rendering(parentClassLoader: Option[ClassLoader] = None) {
102102
dia.level
103103
)
104104

105-
def renderTypeDef(d: Denotation)(implicit ctx: Context): Diagnostic =
105+
def renderTypeDef(d: Denotation)(using Context): Diagnostic =
106106
infoDiagnostic("// defined " ++ d.symbol.showUser, d)
107107

108-
def renderTypeAlias(d: Denotation)(implicit ctx: Context): Diagnostic =
108+
def renderTypeAlias(d: Denotation)(using Context): Diagnostic =
109109
infoDiagnostic("// defined alias " ++ d.symbol.showUser, d)
110110

111111
/** Render method definition result */
112-
def renderMethod(d: Denotation)(implicit ctx: Context): Diagnostic =
112+
def renderMethod(d: Denotation)(using Context): Diagnostic =
113113
infoDiagnostic(d.symbol.showUser, d)
114114

115115
/** Render value definition result */
116-
def renderVal(d: Denotation)(implicit ctx: Context): Option[Diagnostic] = {
116+
def renderVal(d: Denotation)(using Context): Option[Diagnostic] = {
117117
val dcl = d.symbol.showUser
118118

119119
try {
@@ -135,15 +135,15 @@ private[repl] class Rendering(parentClassLoader: Option[ClassLoader] = None) {
135135
sw.toString
136136
}
137137

138-
private def infoDiagnostic(msg: String, d: Denotation)(implicit ctx: Context): Diagnostic =
138+
private def infoDiagnostic(msg: String, d: Denotation)(using Context): Diagnostic =
139139
new Diagnostic.Info(msg, d.symbol.sourcePos)
140140

141141
}
142142

143143
object Rendering {
144144

145145
implicit class ShowUser(val s: Symbol) extends AnyVal {
146-
def showUser(implicit ctx: Context): String = {
146+
def showUser(using Context): String = {
147147
val printer = new ReplPrinter(ctx)
148148
val text = printer.dclText(s)
149149
text.mkString(ctx.settings.pageWidth.value, ctx.settings.printLines.value)

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ class ReplCompiler extends Compiler {
4141
def newRun(initCtx: Context, state: State): Run = new Run(this, initCtx) {
4242

4343
/** Import previous runs and user defined imports */
44-
override protected def rootContext(implicit ctx: Context): Context = {
45-
def importContext(imp: tpd.Import)(implicit ctx: Context) =
44+
override protected def rootContext(using Context): Context = {
45+
def importContext(imp: tpd.Import)(using Context) =
4646
ctx.importContext(imp, imp.symbol)
4747

48-
def importPreviousRun(id: Int)(implicit ctx: Context) = {
48+
def importPreviousRun(id: Int)(using Context) = {
4949
// we first import the wrapper object id
5050
val path = nme.EMPTY_PACKAGE ++ "." ++ objectNames(id)
5151
def importWrapper(c: Context, importGiven: Boolean) = {
@@ -59,11 +59,11 @@ class ReplCompiler extends Compiler {
5959
val imports = state.imports.getOrElse(id, Nil)
6060
if (imports.isEmpty) ctx0
6161
else imports.foldLeft(ctx0.fresh.setNewScope)((ctx, imp) =>
62-
importContext(imp)(ctx))
62+
importContext(imp)(using ctx))
6363
}
6464

6565
(1 to state.objectIndex).foldLeft(super.rootContext)((ctx, id) =>
66-
importPreviousRun(id)(ctx))
66+
importPreviousRun(id)(using ctx))
6767
}
6868
}
6969

@@ -136,7 +136,7 @@ class ReplCompiler extends Compiler {
136136
PackageDef(Ident(nme.EMPTY_PACKAGE), List(module))
137137
}
138138

139-
private def createUnit(defs: Definitions, span: Span)(implicit ctx: Context): CompilationUnit = {
139+
private def createUnit(defs: Definitions, span: Span)(using Context): CompilationUnit = {
140140
val objectName = ctx.source.file.toString
141141
assert(objectName.startsWith(str.REPL_SESSION_LINE))
142142
assert(objectName.endsWith(defs.state.objectIndex.toString))
@@ -159,7 +159,7 @@ class ReplCompiler extends Compiler {
159159
final def compile(parsed: Parsed)(implicit state: State): Result[(CompilationUnit, State)] = {
160160
assert(!parsed.trees.isEmpty)
161161
val defs = definitions(parsed.trees, state)
162-
val unit = createUnit(defs, Span(0, parsed.trees.last.span.end))(state.context)
162+
val unit = createUnit(defs, Span(0, parsed.trees.last.span.end))(using state.context)
163163
runCompilationUnit(unit, defs.state)
164164
}
165165

@@ -225,7 +225,7 @@ class ReplCompiler extends Compiler {
225225

226226
final def typeCheck(expr: String, errorsAllowed: Boolean = false)(implicit state: State): Result[tpd.ValDef] = {
227227

228-
def wrapped(expr: String, sourceFile: SourceFile, state: State)(implicit ctx: Context): Result[untpd.PackageDef] = {
228+
def wrapped(expr: String, sourceFile: SourceFile, state: State)(using Context): Result[untpd.PackageDef] = {
229229
def wrap(trees: List[untpd.Tree]): untpd.PackageDef = {
230230
import untpd._
231231

@@ -252,7 +252,7 @@ class ReplCompiler extends Compiler {
252252
}
253253
}
254254

255-
def unwrapped(tree: tpd.Tree, sourceFile: SourceFile)(implicit ctx: Context): Result[tpd.ValDef] = {
255+
def unwrapped(tree: tpd.Tree, sourceFile: SourceFile)(using Context): Result[tpd.ValDef] = {
256256
def error: Result[tpd.ValDef] =
257257
List(new Diagnostic.Error(s"Invalid scala expression",
258258
sourceFile.atSpan(Span(0, sourceFile.content.length)))).errors

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ import dotc.core.Contexts.{Context, ctx}
1313
*/
1414
private[repl] class REPLFrontEnd extends FrontEnd {
1515

16-
override def isRunnable(implicit ctx: Context): Boolean = true
16+
override def isRunnable(using Context): Boolean = true
1717

18-
override def runOn(units: List[CompilationUnit])(implicit ctx: Context): List[CompilationUnit] = {
18+
override def runOn(units: List[CompilationUnit])(using Context): List[CompilationUnit] = {
1919
assert(units.size == 1) // REPl runs one compilation unit at a time
2020

2121
val unitContext = ctx.fresh.setCompilationUnit(units.head)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class ScriptEngine extends AbstractScriptEngine {
3737
val vid = state.valIndex
3838
state = driver.run(script)(state)
3939
val oid = state.objectIndex
40-
Class.forName(s"${str.REPL_SESSION_LINE}$oid", true, rendering.classLoader()(state.context))
40+
Class.forName(s"${str.REPL_SESSION_LINE}$oid", true, rendering.classLoader()(using state.context))
4141
.getDeclaredMethods.find(_.getName == s"${str.REPL_RES_PREFIX}$vid")
4242
.map(_.invoke(null))
4343
.getOrElse(null)

0 commit comments

Comments
 (0)