Skip to content

Commit d918f8e

Browse files
authoredApr 9, 2025
scala 3.6.4 (#202)
2 parents 404e937 + 40939e2 commit d918f8e

File tree

5 files changed

+40
-29
lines changed

5 files changed

+40
-29
lines changed
 

‎README.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -624,9 +624,8 @@ While maven central jar releases are created for each commit on master (a new ve
624624
cd /path/to/dotty
625625
git fetch
626626

627-
OLD=3.4.2 # set to version that was used before you bumped it
628-
NEW=3.5.2-RC2 # set to version that you bumped it to
629-
git checkout $NEW
627+
OLD=3.5.2-RC2 # set to version that was used before you bumped it
628+
NEW=3.6.4 # set to version that you bumped it to
630629
git diff $OLD..$NEW compiler/src/dotty/tools/repl
631630
```
632631
* check if any of those changes need to be reapplied to this repo

‎build.sbt

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name := "scala-repl-pp-root"
22
publish/skip := true
33

44
ThisBuild / organization := "com.michaelpollmeier"
5-
ThisBuild / scalaVersion := "3.5.2"
5+
ThisBuild / scalaVersion := "3.6.4"
66
lazy val ScalaTestVersion = "3.2.18"
77
lazy val Slf4jVersion = "2.0.16"
88

‎core/src/main/scala/replpp/DottyRandomStuff.scala

+5-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ private[replpp] object DottyRandomStuff {
1313
new StoreReporter(null) with UniqueMessagePositions with HideNonSensicalMessages
1414
}
1515

16-
/** copied from https://github.com/lampepfl/dotty/blob/3.3.0-RC5/compiler/src/dotty/tools/repl/ParseResult.scala#L130 */
16+
/** Based on https://github.com/scala/scala3/blob/3.6.4/compiler/src/dotty/tools/repl/ParseResult.scala#L135
17+
* change: removed [private] classifier so we can access it...
18+
* alternatively we could use reflection...
19+
*/
1720
object ParseResult {
1821
val commands: List[(String, String => ParseResult)] = List(
1922
Quit.command -> (_ => Quit),
@@ -25,6 +28,7 @@ private[replpp] object DottyRandomStuff {
2528
TypeOf.command -> (arg => TypeOf(arg)),
2629
DocOf.command -> (arg => DocOf(arg)),
2730
Settings.command -> (arg => Settings(arg)),
31+
Silent.command -> (_ => Silent),
2832
)
2933
}
3034
}

‎core/src/main/scala/replpp/DottyReplDriver.scala

+28-16
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ import scala.language.implicitConversions
4444
import scala.util.control.NonFatal
4545
import scala.util.Using
4646

47-
/** Based on https://github.com/lampepfl/dotty/blob/3.4.2/compiler/src/dotty/tools/repl/ReplDriver.scala
47+
/** Based on https://github.com/lampepfl/dotty/blob/3.6.4/compiler/src/dotty/tools/repl/ReplDriver.scala
4848
* Main REPL instance, orchestrating input, compilation and presentation
4949
* */
5050
class DottyReplDriver(settings: Array[String],
@@ -66,8 +66,21 @@ class DottyReplDriver(settings: Array[String],
6666
setupRootCtx(this.settings ++ settings, rootCtx)
6767
}
6868

69+
private val incompatibleOptions: Seq[String] = Seq(
70+
initCtx.settings.YbestEffort.name,
71+
initCtx.settings.YwithBestEffortTasty.name
72+
)
73+
6974
private def setupRootCtx(settings: Array[String], rootCtx: Context): Context = {
70-
setup(settings, rootCtx) match
75+
val incompatible = settings.intersect(incompatibleOptions)
76+
val filteredSettings =
77+
if !incompatible.isEmpty then
78+
inContext(rootCtx) {
79+
out.println(i"Options incompatible with repl will be ignored: ${incompatible.mkString(", ")}")
80+
}
81+
settings.filter(!incompatible.contains(_))
82+
else settings
83+
setup(filteredSettings, rootCtx) match
7184
case Some((files, ictx)) => inContext(ictx) {
7285
shouldStart = true
7386
if files.nonEmpty then out.println(i"Ignoring spurious arguments: $files%, %")
@@ -81,7 +94,11 @@ class DottyReplDriver(settings: Array[String],
8194

8295
/** the initial, empty state of the REPL session */
8396
final def initialState: State =
84-
State(0, 0, Map.empty, Set.empty, rootCtx)
97+
val emptyState = State(0, 0, Map.empty, Set.empty, false, rootCtx)
98+
val initScript = rootCtx.settings.replInitScript.value(using rootCtx)
99+
initScript.trim() match
100+
case "" => emptyState
101+
case script => run(script)(using emptyState)
85102

86103
/** Reset state of repl to the initial state
87104
*
@@ -184,11 +201,6 @@ class DottyReplDriver(settings: Array[String],
184201
interpret(ParseResult.complete(input))
185202
}
186203

187-
final def runQuietly(input: String)(using State): State = runBody {
188-
val parsed = ParseResult(input)
189-
interpret(parsed, quiet = true)
190-
}
191-
192204
protected def runBody(body: => State): State = rendering.classLoader()(using rootCtx).asContext(withRedirectedOutput(body))
193205

194206
// TODO: i5069
@@ -256,10 +268,10 @@ class DottyReplDriver(settings: Array[String],
256268
.getOrElse(Nil)
257269
end completions
258270

259-
protected def interpret(res: ParseResult, quiet: Boolean = false)(using state: State): State = {
271+
protected def interpret(res: ParseResult)(using state: State): State = {
260272
res match {
261273
case parsed: Parsed if parsed.trees.nonEmpty =>
262-
compile(parsed, state, quiet)
274+
compile(parsed, state)
263275

264276
case SyntaxErrors(_, errs, _) =>
265277
displayErrors(errs)
@@ -277,7 +289,7 @@ class DottyReplDriver(settings: Array[String],
277289
}
278290

279291
/** Compile `parsed` trees and evolve `state` in accordance */
280-
private def compile(parsed: Parsed, istate: State, quiet: Boolean = false): State = {
292+
private def compile(parsed: Parsed, istate: State): State = {
281293
def extractNewestWrapper(tree: untpd.Tree): Name = tree match {
282294
case PackageDef(_, (obj: untpd.ModuleDef) :: Nil) => obj.name.moduleClassName
283295
case _ => nme.NO_NAME
@@ -328,11 +340,9 @@ class DottyReplDriver(settings: Array[String],
328340
given Ordering[Diagnostic] =
329341
Ordering[(Int, Int, Int)].on(d => (d.pos.line, -d.level, d.pos.column))
330342

331-
if (!quiet) {
332-
(definitions ++ warnings)
333-
.sorted
334-
.foreach(printDiagnostic)
335-
}
343+
(if istate.quiet then warnings else definitions ++ warnings)
344+
.sorted
345+
.foreach(printDiagnostic)
336346

337347
updatedState
338348
}
@@ -507,6 +517,8 @@ class DottyReplDriver(settings: Array[String],
507517
rootCtx = setupRootCtx(tokenize(arg).toArray, rootCtx)
508518
state.copy(context = rootCtx)
509519

520+
case Silent => state.copy(quiet = !state.quiet)
521+
510522
case Quit =>
511523
// end of the world!
512524
// MP: slight variation from original DottyReplDriver to support exiting via the Quit command

‎core/src/main/scala/replpp/InteractiveShell.scala

+4-8
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,14 @@ object InteractiveShell {
2323

2424
if (verbose) println(s"compiler arguments: ${compilerArgs.mkString(",")}")
2525

26-
var state: State = replDriver.initialState
26+
var state: State = replDriver.initialState.copy(quiet = !verbose)
2727
var expectedStateObjectIndex = 0
2828
Seq(DefaultRunBeforeLines, globalRunBeforeLines, config.runBefore).foreach { runBeforeLines =>
2929
val runBeforeCode = runBeforeLines.mkString("\n").trim
3030
if (runBeforeCode.nonEmpty) {
3131
expectedStateObjectIndex += 1
32-
state =
33-
if (verbose) {
34-
println(s"executing runBeforeCode: $runBeforeCode")
35-
replDriver.run(runBeforeCode)(using state)
36-
} else {
37-
replDriver.runQuietly(runBeforeCode)(using state)
38-
}
32+
if (verbose) println(s"executing runBeforeCode: $runBeforeCode")
33+
state = replDriver.run(runBeforeCode)(using state)
3934
}
4035
}
4136

@@ -44,6 +39,7 @@ object InteractiveShell {
4439
s"compilation error(s) for predef code - see error above ^^^"
4540
)
4641

42+
state = state.copy(quiet = false)
4743
replDriver.runUntilQuit(using state)()
4844
}
4945

0 commit comments

Comments
 (0)
Please sign in to comment.