-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
REPL: decouple the UI (shell) from the compiler [ci: last-only] #5903
Conversation
Now I know why it's called a shell game. |
src/repl-frontend/scala/tools/nsc/interpreter/shell/InteractiveReader.scala
Outdated
Show resolved
Hide resolved
src/repl-frontend/scala/tools/nsc/interpreter/shell/InteractiveReader.scala
Outdated
Show resolved
Hide resolved
src/repl-frontend/scala/tools/nsc/interpreter/shell/InteractiveReader.scala
Outdated
Show resolved
Hide resolved
(Now that I have the tests passing, I'll work on addressing the first round of review feedback. Thanks!) |
src/repl-frontend/scala/tools/nsc/interpreter/shell/ILoop.scala
Outdated
Show resolved
Hide resolved
cb72f11
to
ccf5afb
Compare
cf64b1f
to
6acad7d
Compare
Parse user input as-is, and use that as content of unit's source file content. The unit's body has the trees resulting from wrapping and rewriting the user's input to implement the repl's semantics (store the result in a val etc). Also pass on whether parsed trees had xml elements. This allows us to be more precise in our error messages, as positions map 1-1 to user input (as suggested by retronym, who helped getting the range positions right). Note: input may contain leading/trailing non-trees. For example, whitespace/comments don't survive as trees, thus we can't assume the trees cover the range pos (0, buf.length); instead, compute it. Goal: no string-based code manipulation. No there yet. Handle assignment minimally to avoid memory leaks So, don't hang on to assigned values. Still provide some feedback that the assignment has been executed --> `"mutated x"`. Also, bring back pure expression warning to maintain status quo -- but who wants to see those pure expr warnings in the repl?? Rangepos invariants require most synthetic code to have a transparent pos, but the presentation compiler locates trees by position, which means use code must have an opaque position, and we must be able to navigate to it from the root, which means all ancestor trees to user code must cover the positions of said user code.
Move it there, and while we're at it, simplify Completion hierarchy
6acad7d
to
7d5222c
Compare
Alright, this should be ready for merge, if it looks good. I'm going to defer the work on simplifying wrapping to another PR, where we'll also standardize on the class-based wrapping, and just generally try to dial the wrapping noise back to a minimum. That, and upgrading to JLine 3 will have to wait for M3. |
@retronym, @adriaanm - hey guyz, Dotty has a scala> "\twaaaaaaaaaaaaaaaaaaaaaat"
res0: String = waaaaaaaaaaaaaaaaaaaaaat in scalac, but in dotty: scala> "\twaaaaaaaaaaaaaaaaaaaaaat"
val res0: String = "\twaaaaaaaaaaaaaaaaaaaaaat" As soon as case classes are hlists, there could be show instances for them as well by default. It requires a bit more fiddling, but it looks nice and is copy-pastable. The original idea (of course) came from ghci and the ocaml repl. |
Cool, thanks for the pointer! Will be nice to have this as part of the std lib. (Maybe even in 2.13? /cc @szeiger) |
🎈 |
Just back from vacation and look fwd to trying it out. Is there an initiative to provide a uniform API for Scala 2 and 3/dotty? I saw a comment about a dotr rewrite, but I didn't see if unification was a goal. Choices like jline or not would be nice to decouple from folks writing REPL support. Can I use |
Welcome back! I'd very much like for us to converge on a compiler-backed API that can be provided uniformly across versions, as well as consumed by multiple frontends. |
Consider this the proto-strawman proposal. |
Fixes sbt#395, sbt/sbt#3427 In scala/scala#5903 Scala compiler's REPL-related classes went through some changes, including move to a different package. This implements a new compiler bridge tracking the changes. To verify that the new bridge compiles under 2.13, we need to compile it using sbt 1.0.3, which in turn requires a bridge compatible with Scala 2.13.0-M2. To work around this chicken-egg, I've manually created a bridge and published it to Maven Central as "org.scala-sbt" % "compiler-bridge_2.13.0-M2" % "1.1.0-M1-bootstrap2".
Fixes sbt#395, sbt/sbt#3427 In scala/scala#5903 Scala compiler's REPL-related classes went through some changes, including move to a different package. This implements a new compiler bridge tracking the changes. To verify that the new bridge compiles under 2.13, we need to compile it using sbt 1.0.3, which in turn requires a bridge compatible with Scala 2.13.0-M2. To work around this chicken-egg, I've manually created a bridge and published it to Maven Central as "org.scala-sbt" % "compiler-bridge_2.13.0-M2" % "1.1.0-M1-bootstrap2".
import scala.tools.nsc.interpreter.shell.{ILoop, ReplReporterImpl, ShellConfig} | ||
import scala.tools.nsc.reporters.Reporter | ||
|
||
// Pretty gross contortion to satisfy the de facto interface expected by sbt. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/cc @smarter: this is the grossness we use to integrate with sbt ;-)
Fixes scala#395, sbt/sbt#3427 In scala#5903 Scala compiler's REPL-related classes went through some changes, including move to a different package. This implements a new compiler bridge tracking the changes. To verify that the new bridge compiles under 2.13, we need to compile it using sbt 1.0.3, which in turn requires a bridge compatible with Scala 2.13.0-M2. To work around this chicken-egg, I've manually created a bridge and published it to Maven Central as "org.scala-sbt" % "compiler-bridge_2.13.0-M2" % "1.1.0-M1-bootstrap2".
Fixes scala#395, sbt/sbt#3427 In scala#5903 Scala compiler's REPL-related classes went through some changes, including move to a different package. This implements a new compiler bridge tracking the changes. To verify that the new bridge compiles under 2.13, we need to compile it using sbt 1.0.3, which in turn requires a bridge compatible with Scala 2.13.0-M2. To work around this chicken-egg, I've manually created a bridge and published it to Maven Central as "org.scala-sbt" % "compiler-bridge_2.13.0-M2" % "1.1.0-M1-bootstrap2". Rewritten from sbt/zinc@c60ff23
Split in front- and back-end. Drop shaded jline (was needed for spark shell; we should be able to offer a better solution with the coming frontend improvements).
Review follow-ups:
Known (temporary) regressions in this PR: