-
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
Introduce ReplPrinter as a hook for alternatives to replStringOf #5222
Conversation
It would be lovely if this could make M5 :-) Also i expect the unwrapping of $print will start failing once the repl wrappers are gone (#5220). |
Requires making the imports available during the eval phase of the REPL.
Ah didn't realise this had failed the tests. Updated Also, review by @som-snytt? |
The one everyone asks for is to quote strings. It might be nice to include a standard one for easy import from a suitable namespace, like This isn't nuanced:
You quickly run into implicit management by name:
This is where smart imports is useful, either better automation or manually quarantine imports. The other ticket for spark has similar problem. My only concern is how the object nesting in Really, what's needed is a general way to specify the templating. For example, another requested feature is to emit Since the concerns are out-of-scope, maybe just disable the change under the spark option; unless it's shown not to be a problem. |
@som-snytt I see. I've revert the behaviour under |
More ideas https://issues.scala-lang.org/browse/SI-9829 such as convert controls to escapes in color, CR -> \r or \u000d in red? |
} | ||
|
||
object ReplPrinter { | ||
implicit def default[A]: ReplPrinter[A] = new ReplPrinter[A] { |
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.
Could we have one instance, like so:
implicit object defaultReplPrinter extends ReplPrinter[Any] {
def print(x: Any, maxElements: Int) = ScalaRunTime.replStringOf(x, maxElements)
}
?
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.
Yep, good eye. Done.
scala> | ||
|
||
scala> 23 | ||
res1: Int = 23 |
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.
I was expecting a "!" at the end here -- how come there's not?
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.
Oh, this is the class-based one.
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.
perhaps add a comment to the test case that says we don't enable custom string of under this mode
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.
Everyone expects it to end with a bang.
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.
I wasn't sure how to leave the comment, so I've opted for in the transcript.
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.
This comment didn't fold because that line it's on didn't change, so, for clarity, I've added a commit that adds the comment.
I just returned from remote regions; I'll give this another look and try it out. |
Anything left here? This is a REPL-only change. Can it go in? |
The templating part may conflict with #5220, for which I have a test to fix still. I'll try to nail that down this weekend, and try this on top of it. |
@@ -11,13 +11,17 @@ repl-out-dir-run.obj | |||
$eval$.class | |||
$eval.class | |||
$line2 | |||
$eval$$iw$$iw$.class | |||
$eval$$iw$.class |
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.
does this mean every repl line generates two additional classfiles? is there a drawback to this? (performance?)
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.
Yeah it does. I'm not sure what drawbacks there might be, but I avoided it for Spark-reasons.
I think it would be weird to have such a mechanism work only in one of |
Which two concerns do you mean? I removed it for class-based because @som-snytt was concerned about the performance impact for Spark. |
i just think it doesn't make sense for a feature like the one you're implementing to be dependent on some internal representation within the repl. |
Yeah it's not ideal, but it's a compromise I personally was fine with. How do we go about proving that this doesn't affect Spark? Alternatively how do you feel about an opt-out option, for if it proves to be a problem? |
Also, sorry my weekend went to understanding how imports work. I still intend to help with the concerns. |
Could we do a bit of a cost/benefit analysis of this and #5220, as well as a risk assessment of causing a regression in the repl, which would lengthen the RC cycle? I'm tempted to push this to 2.12.1 so that we can consider this together with #5220 and go a bit deeper in dealing with some templating technical debt, rather than taking on more. |
I don't like the idea of "shackling" together two pull requests which are doing distinct thing, even if they're in the same area of the codebase. Why are you saying that this adds technical debt? |
I don't think it's unreasonable to consider these PRs together, as they touch very similar parts of the REPL. Having to disable this for the class-based templates seems to imply we're going to have to come back to this and make it work there too, no? |
I also would like to see a more technical response to @lrytz's concern. Everything is a compromise, but what are we conceding and what for? How would we solve this if we had more time? The REPL encoding is already very complicated, so any change is taking on technical debt for a nicer way of implementing the REPL. |
Sorry, I meant to devote time to this, but the day job got busy. Time flies. Also, it slipped my mind. Possibly I was hoping it was fixed in ammonite. |
For the reasons stated above, and with this not being a release blocker, I'm re-assigning this to 2.12.1. It would be great to have a concerted effort in cleaning up the REPL encoding once 2.12.0 has shipped. |
I would be happy help clean up the REPL (but I would need some guidance as I have no prior experience of REPL implementations to compare this one against). I'm fine with this going in 2.12.1 rather than 2.12.0, but I would just like it one way or another. Without doing a cost/benefit analysis of this and #5220, or a risk assessment, would you consider this feature being opt-in via a compiler flag? Or is that a no-go? |
Thanks for understanding -- we're happy to help with this once 2.12.0 is out! |
I've been using spark for day job; you know spark shell doesn't even inherit the improved welcome message in 2.11.8? I sense that there's something important to do for repl re-use and customizability for 2.12, but not sure if I'll find time to realize it. FTR, there's an episode of "Inspector Morse" which turns on the OED recommendation of "-ize". (A note writer uses "-ise" inappropriately and misspells "desperate" like "separate".) (It was a suicide note, putatively, and this was a few years before the internet.) In hindsight, I would have used stronger language about "-optimise." http://blog.oxforddictionaries.com/2011/03/ize-or-ise/ |
Because there is no ticket?, linking to https://issues.scala-lang.org/browse/SI-9829 about pretty printing against impossible odds. |
sorry I missed this the first time -- I would prefer putting this under a flag, as I'm concerned this could slow down the REPL due to additional wrapping |
I still think we should come up with a solution that is also fine for |
If I put it behind a feature flag, the feature would be enabled under class-based too, IMO. |
Clearly there's more work to do here for this to be still in the 2.12.1 queue. But thanks for the recent feedback. |
I don't have the stamina to take this to completion if it requires first delivering the "avoid $iw wrappers" change in the REPL. |
There's pressure both to de-wrapperize and avoid object wrappers entirely and also do customizable printing. To which I'd add customizable wrapping. This won't go unused. |
Requires making the imports available during the eval phase of the REPL.
Review by @retronym.