C++ Insights – See your source code with the eyes of a Compiler (github.com)
alankarmisra 8 hours ago
kvemkon an hour ago
What I'd like to see, is how much time is spent to compile each block of C++ code (sliced as fine as possible).
jsrcout 6 hours ago
StilesCrisis 8 hours ago
mrlonglong 7 hours ago
rramadass 6 hours ago
rramadass 6 hours ago
sltkr an hour ago
Here's an example: https://cppinsights.io/s/f04b6896
(That also shows how C++'s range-based for-loops work, which is similarly some syntactic suger for a fairly mundane for-loop, but details are interesting: unlike a typical for-loop, the loop variable is declared inside the loop body.)
f1shy 6 hours ago
Like: I wish what is the first interpretation of my code to be obvious. Is not about advanced optimization, or nitty gritty compiler tricks, is about the language. This tool is useful in any C++ compiler. How did we end with such a complex language?
I mean (sorry, very personal take) the programming language is for me a tool to help me think about a problem and its solution. In this era of LLM more than before, is not a tool to get the machine to do something, is a language for formalizing ideas, problems and solutions, like math. Should not be so obscure, that you need to be a lawyer to understand it, right? Or I am very much old and totally in the weeds with my ideas?
rs545837 6 hours ago
kccqzy 5 hours ago
In the README example, the C++ practitioner just doesn’t think about those automatically synthesized copy constructors and such for POD types, nor do they think about the fact that assignment is desugared to operator= or that an assignment can involve a static_cast.
f1shy 5 hours ago
Of course there are people who do not need that tool. The thing is, other languages doesn’t need such an explanation tool at all, is very much enough with reading a small book. I personally would like C++ to not really need it, but clearly as I stated: maybe “the only one”
drysine 3 hours ago
Are you sure about that?
kccqzy 2 hours ago
Plain old C has -E to expand macros. Rust has cargo expand. Haskell has -ddump-simpl. Common Lisp has macroexpand. Any language that has a complicated syntax or allows the user to customize the syntax needs such a tool. Whether such a tool actually exists reflects more on popularity and community desire.
esikich 5 hours ago
f1shy 5 hours ago
Compilation per se is not difficult. Doing it with good error recovery, good feedback in case of error, and the optimization is difficult.
This tool does not tell me those parts (for that is gotbolt) this is about how the first layer of interpretation works, and not for making compilers, but for understanding what the code actually means, because is not obvious at first sight.
dasyatidprime 3 hours ago
pjmlp 3 hours ago
Only if you mean K&R C or the early C89/90 compilers, before the extension explosion, newer language standards, and modern ISAs.
rramadass 3 hours ago
Compilers for all languages have the concept of "lowering" the level of source-language abstractions from high-level to low-level viz. Written Source -> Simpler Source -> AST -> IR -> Machine Code. One type is "desugaring" i.e. transforming complex syntax to simpler ones so that the following stages of compilation have to operate only on a smaller and hence more manageable language subset.
This tool shows both desugaring and other lowering (eg. implicit transformations, type deductions etc.) within the C++ source language by regenerating the source from the AST thus giving you full visibility until that stage in the compilation process.
PS: Explanatory video presentation by the author - https://www.youtube.com/watch?v=VJ6ZvDRYzNE&t=558s
rramadass 2 days ago
IshKebab 6 hours ago
drysine 3 hours ago
pjmlp 3 hours ago
tweedler290 4 hours ago
abbefaria27 3 hours ago