Skip to content

in REPL, -Vprint should support the new "parser" phase #13835

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

Closed
SethTisue opened this issue Oct 27, 2021 · 3 comments · Fixed by #15663
Closed

in REPL, -Vprint should support the new "parser" phase #13835

SethTisue opened this issue Oct 27, 2021 · 3 comments · Fixed by #15663
Labels
area:repl itype:bug Spree Suitable for a future Spree
Milestone

Comments

@SethTisue
Copy link
Member

since #13173 parsing has been its own phase

and -Vprint is a super common way to troubleshoot things, understand better how the compiler works, etc, as code is transformed by successive phases

and with command line scalac you can:

% scalac -Vprint:parser C.scala
[[syntax trees at end of                    parser]] // C.scala
package <empty> {
  class C {}
}

or do the same with -Vprint:all and see all the phases. but somehow the same thing doesn't work in the REPL:

% scala -Vprint:parser
                                                                                                                        
scala> class C
// defined class C
                                                                                                                        
scala> 
% scala -Vprint:all
                                                                                                                        
scala> class C
[[syntax trees at end of                     typer]] // rs$line$1

the other phases work, but something is special about the combination of REPL and the parser phase.

@SethTisue SethTisue added itype:bug Spree Suitable for a future Spree labels Oct 27, 2021
@SethTisue
Copy link
Member Author

I'm tentatively labeling this as "spree", but if someone sees a reason this might actually be harder than I think, please pipe up.

@dwijnand
Copy link
Member

The reason is that the REPL (same in Scala 2) does, what I'm calling, "speculative" parsing. I.e. it parses the input and figures out from the parse error whether the user has more input to give, on a new line. This disconnect is causing -Vprint to be skipped in the REPL.

I think it's Spree-sized: it's conceptually simple, with the possibility of the complication of -Vprint:parser emitting output on those partial inputs, which I don't think we want.

@som-snytt
Copy link
Contributor

IIRC it works as expected in Scala 2 because after speculative parsing, the final "template" code is reparsed for compilation, though I remember that was rejiggered to splice trees. But I guess the point is that in Scala 3 it's not reparsed.

This is an interesting question because the point of the REPL is, "tell me what scalac makes of this code." If there is REPL monkey business, then you're debugging REPL not scalac. REPL is already a departure as a resident compiler.

A recent bug about incremental compilation made me think that REPL could be a useful tool for debugging incremental compilation, too, BTW.

@Kordyjan Kordyjan added this to the 3.2.1 milestone Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:repl itype:bug Spree Suitable for a future Spree
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants