To understand what the Scala compiler does, in general or on a particular piece of code,
scalac -Vprint:_ S.scala
is your best friend. It shows how your code is transformed by each compiler phase. (2.13 change alert! In 2.12 and earlier, it was-Xprint:all
.)
I’ve added these flags before, but not on a single file, because I can’t possibly generate the correct scalac
command-line for a project with various dependencies. Maybe this is a bad idea, but I’ve then added those flags to the project config itself, and then when the project compiles, a zillion lines of compiler logging gets spat out onto the console.
My first question is, how does one realistically view the compiler’s transformation of just one source file, when in the context of a large project, typically managed by sbt? Is there a different strategy than turning on flags and doing lots of terminal grepping?
To address the compiler-DDOSing-my-terminal problem, I posted a tooling request:
i would like to have that output be (a) a data structure like JSON so it can be consumed and parsed, and (b) emitted to an arbitrary file handle so we don’t have to scrape stdout/stderrr.
So in the scenario where one does add the compiler flags to a project, producing a structured output would allow easier analysis of the information the compiler produced (it isn’t some arbitrary strings that would take forever to write a parser for), and the output could be redirected/duplicated to another file handle so as not to spam the terminal where the compiler is running.
This is similar to the work of Metals and LSP: add structured channels between the code and the compiler.