Skip to content

Commit 4daf06d

Browse files
committed
Introduce option not to display definitions in repl driver
The reason for this change is that currently, statements in the JSR223 script engine are evaluated twice. Once when the "run" method is called, and once when the value of the result is extracted. The first one needs not be, it exists solely due to displayDefinitions being called. If we put it behind a flag, the problem is solved.
1 parent 332c831 commit 4daf06d

File tree

5 files changed

+11
-6
lines changed

5 files changed

+11
-6
lines changed

compiler/src/dotty/tools/dotc/config/ScalaSettings.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ class ScalaSettings extends Settings.SettingGroup {
8181
val Xprompt: Setting[Boolean] = BooleanSetting("-Xprompt", "Display a prompt after each error (debugging option).")
8282
val XnoValueClasses: Setting[Boolean] = BooleanSetting("-Xno-value-classes", "Do not use value classes. Helps debugging.")
8383
val XreplLineWidth: Setting[Int] = IntSetting("-Xrepl-line-width", "Maximal number of columns per line for REPL output", 390)
84+
val XreplDisableDisplay: Setting[Boolean] = BooleanSetting("-Xrepl-disable-display", "Do not display definitions in REPL.")
8485
val XfatalWarnings: Setting[Boolean] = BooleanSetting("-Xfatal-warnings", "Fail the compilation if there are any warnings.")
8586
val XverifySignatures: Setting[Boolean] = BooleanSetting("-Xverify-signatures", "Verify generic signatures in generated bytecode.")
8687
val XignoreScala2Macros: Setting[Boolean] = BooleanSetting("-Xignore-scala2-macros", "Ignore errors when compiling code that calls Scala2 macros, these will fail at runtime.")

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,9 @@ class ReplDriver(settings: Array[String],
205205
case _ => // new line, empty tree
206206
state
207207
}
208-
out.println()
208+
implicit val ctx: Context = newState.context
209+
if (!ctx.settings.XreplDisableDisplay.value)
210+
out.println()
209211
newState
210212
}
211213

@@ -238,7 +240,11 @@ class ReplDriver(settings: Array[String],
238240

239241
val warnings = newState.context.reporter.removeBufferedMessages(newState.context)
240242
displayErrors(warnings)(newState) // display warnings
241-
displayDefinitions(unit.tpdTree, newestWrapper)(newStateWithImports)
243+
implicit val ctx = newState.context
244+
if (!ctx.settings.XreplDisableDisplay.value)
245+
displayDefinitions(unit.tpdTree, newestWrapper)(newStateWithImports)
246+
else
247+
newStateWithImports
242248
}
243249
)
244250
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ class ScriptEngine extends AbstractScriptEngine {
2121
Array(
2222
"-classpath", "", // Avoid the default "."
2323
"-usejavacp",
24-
"-color:never"
24+
"-color:never",
25+
"-Xrepl-disable-display"
2526
), Console.out, None)
2627
private val rendering = new Rendering
2728
private var state: State = driver.initialState
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
val res0: Int = 42
2-
31
42

tests/run-with-compiler/scripting.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,3 @@ object Test {
55
println(e.eval("42"))
66
}
77
}
8-

0 commit comments

Comments
 (0)