When compilation fails, ./koch temp c /tmp/foo.nim displays the stack trace down to the compilation error message, so we can have a snapshot understanding of the parsing process. But when the compilation succeeds, there's no way to understand what were the compilation phases.
For instance, is there a compiler option to dump the parsed AST before code generation?
Replying to myself and for future use: at least, there's an undocumented scan compiler command to dump the result of the lexer/scanner.
Try nim scan foo.nim to see the tokens identified in the source file.
There's also a parse command but it discards its result. So apart from checking that the source is syntactical valid, like command check does, it is of no real use. It can be easily enhanced to dump the source AST while rewriting the line by
debug parseFile(conf.projectMainIdx, cache, conf)
after including module astalgo in main.nim. The output being very verbose, this must be used for tiny sources!
Thanks. For this particular example, I've started looking at how static generic expressions are handled by procs and templates into semtypes.nim.
But the question wanted to be more general. How a new comer can understand how the Nim compiler works? What tools/options are available to have a global understanding of the compilation process? Are there ways to see the results of the different compilation phases? I've listed 2 undocumented options to see the scan and parser phases, but after the AST is built there are many phases when the AST is reworked before code generation. What are the important internal data structures?
Is there a wish to build a compiler's internals documentation or is it a knowledge that lives in the compiler hackers' minds?
I wrote how to debug Nim program and Nim compiler with GDB long time ago. https://internet-of-tomohiro.netlify.app/nim/gdb.en.html
It might contain outdated content.
Is there a wish to build a compiler's internals documentation or is it a knowledge that lives in the compiler hackers' minds?
Well we have the internal documentation and we're always accepting PRs but I generally assume that compiler contributors have read some book about compiler development, there are good ones available like https://people.inf.ethz.ch/wirth/CompilerConstruction/index.html
What are the important internal data structures?
It's ASTs all the way down and the compiler's AST is the same AST that is exposed in the macro system. :-)