Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement :settings in the REPL #13982

Merged
merged 1 commit into from Dec 13, 2021
Merged

Conversation

dwijnand
Copy link
Member

No description provided.

@dwijnand dwijnand force-pushed the repl/settings-command branch 2 times, most recently from 5923bfe to cfa358b Compare November 21, 2021 09:24
@dwijnand dwijnand marked this pull request as ready for review November 21, 2021 11:55
@dwijnand
Copy link
Member Author

@griggt @som-snytt do either (or both!) of you want to help review and merge this, please?

@dwijnand
Copy link
Member Author

dwijnand commented Nov 21, 2021

  • Does :reset clear the settings in Scala 2? Because I think it does in this implementation.

@som-snytt
Copy link
Contributor

I don't remember the behavior of :reset except that there is a ticket about reset not resetting enough. The big feature is to collect bindings. I've forgotten what else was not reset. :replay -Xlint was the useful "once more with these settings". I guess I would expect reset to restore settings to defaults. What are the defaults? It was -deprecation -feature unless there are explicit settings.

Copy link
Contributor

@som-snytt som-snytt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An essential command! Puts the REPL on a firm setting.

@dwijnand
Copy link
Member Author

I guess I would expect reset to restore settings to defaults.

Well that makes it harder, because it actually doesn't:

Welcome to Scala 2.13.7 (OpenJDK 64-Bit Server VM, Java 1.8.0_282).
Type in expressions for evaluation. Or try :help.

scala> :settings
-Vbrowse = List()
-Vprint = List()
-Vtyper = false
-Wconf = List(cat=feature:w, cat=deprecation:w, cat=deprecation:ws, cat=feature:ws, cat=optimizer:ws)
-Xmaxwarns = 100
-deprecation = true
-encoding = UTF-8
-feature = true
-nowarn = false

scala> :settings -Xsource:3

scala> :settings
-Vbrowse = List()
-Vprint = List()
-Vtyper = false
-Wconf = List(cat=feature:w, cat=deprecation:w, cat=deprecation:ws, cat=feature:ws, cat=optimizer:ws)
-Xmaxwarns = 100
-Xsource = SpecificScalaVersion(3,0,0,Final)
-deprecation = true
-encoding = UTF-8
-feature = true
-nowarn = false

scala> :reset
Resetting REPL state.
Forgetting all expression results and named terms: $intp

scala> :settings
-Vbrowse = List()
-Vprint = List()
-Vtyper = false
-Wconf = List(cat=feature:w, cat=deprecation:w, cat=deprecation:ws, cat=feature:ws, cat=optimizer:ws)
-Xmaxwarns = 100
-Xsource = SpecificScalaVersion(3,0,0,Final)
-deprecation = true
-encoding = UTF-8
-feature = true
-nowarn = false

What are the defaults? It was -deprecation -feature unless there are explicit settings.

Yeah, it's not that in Scala 3. But I wouldn't be against someone proposing that change.

@som-snytt
Copy link
Contributor

Thanks for the tweak (to the code).

If I didn't mention, I noticed that some settings are cached so setting in Scala 2 repl doesn't take. :se -Vprint:typer but not :se -Vtyper for example. You have to restart in that case.

@griggt griggt self-requested a review November 22, 2021 17:56
@dwijnand
Copy link
Member Author

@griggt happy for this to land or do you still want to look at it first?

Copy link
Collaborator

@griggt griggt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should have time tomorrow to review in more detail. Some initial comments:

  • it would be nice to add :settings to the REPL :help display
  • is the behavior shown below expected?
$ mkdir -p /tmp/{a,b}

$ ./bin/scala
scala> :settings -d /tmp/a

scala> val x = 42
val x: Int = 42

scala> class Foo
// defined class Foo

$ ./bin/scala
scala> val x = 42
val x: Int = 42

scala> :settings -d /tmp/b

scala> class Foo
Exception in thread "main" java.lang.ClassNotFoundException: repl$.rs$line$2$
	at dotty.tools.repl.AbstractFileClassLoader.findClass(AbstractFileClassLoader.scala:49)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
	at dotty.tools.repl.AbstractFileClassLoader.loadClass(AbstractFileClassLoader.scala:55)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:348)
	at dotty.tools.repl.Rendering.load$1(Rendering.scala:147)
	at dotty.tools.repl.Rendering.forceModule(Rendering.scala:149)
	at dotty.tools.repl.ReplDriver.extractAndFormatMembers$1(ReplDriver.scala:328)
	at dotty.tools.repl.ReplDriver.renderDefinitions$$anonfun$2(ReplDriver.scala:349)
	at scala.Option.map(Option.scala:242)
	at dotty.tools.repl.ReplDriver.renderDefinitions(ReplDriver.scala:352)
	at dotty.tools.repl.ReplDriver.compile$$anonfun$2(ReplDriver.scala:271)
	at scala.util.Either.fold(Either.scala:189)
	at dotty.tools.repl.ReplDriver.compile(ReplDriver.scala:287)
	at dotty.tools.repl.ReplDriver.interpret(ReplDriver.scala:221)
	at dotty.tools.repl.ReplDriver.loop$1(ReplDriver.scala:155)
	at dotty.tools.repl.ReplDriver.runUntilQuit$$anonfun$1(ReplDriver.scala:158)
	at dotty.tools.repl.ReplDriver.withRedirectedOutput(ReplDriver.scala:177)
	at dotty.tools.repl.ReplDriver.runUntilQuit(ReplDriver.scala:158)
	at dotty.tools.repl.ReplDriver.tryRunning(ReplDriver.scala:120)
	at dotty.tools.repl.Main$.main(Main.scala:6)
	at dotty.tools.MainGenericRunner$.run$1(MainGenericRunner.scala:177)
	at dotty.tools.MainGenericRunner$.main(MainGenericRunner.scala:239)
	at dotty.tools.MainGenericRunner.main(MainGenericRunner.scala)

@dwijnand
Copy link
Member Author

dwijnand commented Dec 2, 2021

Som the magician foresaw it: some settings are cached (like outputDir in the REPL rendering classloader).

@dwijnand
Copy link
Member Author

Needed this again, today (wanted to see -explain in the REPL) and didn't realise it still wasn't in the nightlies.

@griggt griggt merged commit 6e37dec into scala:master Dec 13, 2021
@dwijnand dwijnand deleted the repl/settings-command branch December 13, 2021 09:02
@Kordyjan Kordyjan added this to the 3.1.2 milestone Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants