Skip to content

Commit a407c59

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 13da159 commit a407c59

File tree

5 files changed

+10
-6
lines changed

5 files changed

+10
-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
@@ -75,6 +75,7 @@ class ScalaSettings extends Settings.SettingGroup {
7575
val XmainClass: Setting[String] = StringSetting("-Xmain-class", "path", "Class for manifest's Main-Class entry (only useful with -d <jar>)", "")
7676
val XnoValueClasses: Setting[Boolean] = BooleanSetting("-Xno-value-classes", "Do not use value classes. Helps debugging.")
7777
val XreplLineWidth: Setting[Int] = IntSetting("-Xrepl-line-width", "Maximal number of columns per line for REPL output", 390)
78+
val XreplDisableDisplay: Setting[Boolean] = BooleanSetting("-Xrepl-disable-display", "Do not display definitions in REPL.")
7879
val XfatalWarnings: Setting[Boolean] = BooleanSetting("-Xfatal-warnings", "Fail the compilation if there are any warnings.")
7980
val XverifySignatures: Setting[Boolean] = BooleanSetting("-Xverify-signatures", "Verify generic signatures in generated bytecode.")
8081
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
@@ -194,7 +194,9 @@ class ReplDriver(settings: Array[String],
194194
case _ => // new line, empty tree
195195
state
196196
}
197-
out.println()
197+
implicit val ctx: Context = newState.context
198+
if (!ctx.settings.XreplDisableDisplay.value)
199+
out.println()
198200
newState
199201
}
200202

@@ -227,7 +229,11 @@ class ReplDriver(settings: Array[String],
227229

228230
val warnings = newState.context.reporter.removeBufferedMessages(newState.context)
229231
displayErrors(warnings)(newState) // display warnings
230-
displayDefinitions(unit.tpdTree, newestWrapper)(newStateWithImports)
232+
implicit val ctx = newState.context
233+
if (!ctx.settings.XreplDisableDisplay.value)
234+
displayDefinitions(unit.tpdTree, newestWrapper)(newStateWithImports)
235+
else
236+
newStateWithImports
231237
}
232238
)
233239
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import dotc.core.StdNames.str
1717
* println(e.eval("42"))
1818
*/
1919
class ScriptEngine extends AbstractScriptEngine {
20-
private[this] val driver = new ReplDriver(Array("-usejavacp", "-color:never"), Console.out, None)
20+
private[this] val driver = new ReplDriver(Array("-usejavacp", "-Xrepl-disable-display"), Console.out, None)
2121
private[this] val rendering = new Rendering
2222
private[this] var state: State = driver.initialState
2323

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)