Logo

Blog


Happy anniversary C++ Insights

I haven't written a lot about C++ Insights in the last couple of months, but as today is the anniversary of C++ Insights, it is about time to hand out a birthday present.

This year we celebrate the 4th anniversary of C++ Insights. I first tweeted about it on May 13, 2018. Looking at this date today, I should have picked one day earlier or later. It happens that this anniversary falls on a Friday the 13th. So let's hope that still is a good sign.

The current status

While I did spend less time the last couple of months working on C++ Insights, I'm still working on new features. I'm looking at a transformation that shows vtables, and I'm also looking into a C++ to C mode. The latter should visualize things like the implicit this parameter and how function calls look like.

And then there is some C++20 and later stuff to implement.

The Windows are closing

Supporting Windows becomes more and more a burden. One reason might simply be that I don't own a Windows machine. However, there are more obstacles. Maybe you can help me out with one.

The official LLVM/Clang binaries ship without some development libraries I need to build C++ Insights. libClang, if I recall correctly. The Windows binary seems to be the only one doing this. Binaries for macOS or Linux come with that library. My workaround for the last years was using the binaries provided by ziglang. Unfortunately, there seems to be no Clang 14 binary at the moment.

However, the mess did not end there. While ziglang provides libClang, it is missing the compiler-rt library. That's why I did set up another build fetching and unpacking the ziglang binary to use that to build compiler-rt, then packing that up, putting it on GitHub, and using that for the build of C++ Insights.

Without ziglang I have no binary to start with. I assume I could use the official binary and start building libClang and compiler-rt on top of it. However, I haven't had the time nor enthusiasm to do so.

There is one more sadness. For some time, I had CI builds for Windows using LLVM/Clang and MSVC as well. For a few months, I think there has been a regression in MSVC leading to a compile error, or better, a crash of MSVC, as you can see in the build logs here. If you happen to know what's in msc1.cpp on line 1691, you might be able to fix this issue.

So, all in all, supporting Windows has become more and more time-consuming and frustrating. For the moment, I did disable the MSVC build, but without LLVM/Clang binaries for Windows, this architecture stalls the transition to Clang 14. This was the present I initially had planned for the fourth anniversary.

This brings me to the positive thing, what I have as a birthday present for C++ Insights :-)

A long-awaited feature

I decided to use this special day to release a special new transformation in C++ Insights a lot of you asked me about: Coroutines! But please read the rest of this post.

I first wrote about the difficulties of implementing this transformation back in 2019: Coroutines in C++ Insights. The issues are still there. That means that the coroutines transformation is educational only. I have to make up a tremendous amount of code for such a transformation, and there are still cases where the resulting code will not compile.

While I initially started with just creating the necessary strings, I soon discovered that it would not be enough this time. To make the coroutines transformation come alive, I'm now creating AST nodes which I then feed into C++ Insights. This is to reuse the existing machinery for formatting the output, and second, to avoid tons of special code in the regular handlers.

Without the support for coroutine generators in the STL, you will always see the expansion of the generator/promise_type. Since C++ Insights still runs on Clang 13, you will also have to deal with the std::experimental namespace, decreasing readability.

I tried to add comments into the output stream to explain the items further. I plan to add another option to turn them and other comments off. Mainly for readability, as sometimes when I'm teaching these things, the comments distract more than they do help.

One important thing, you must activate "Use libc++" for this transformation. I hope this requirement will go away once I can switch to GCC 12 and Clang 14. Here is an example: cppinsights.io/s/81e9e954.

Feel free to report bugs. I'm not 100% sure that this transformation is correct. However, if you start doing fancy stuff, like mixing lambdas and coroutines, there is a high probability that I will not fix issues down this road. But I accept PRs :-)

Thank you all for the wonderful 4 years of support!

Support the project

You can support the project by becoming a Patreon or, of course, contribute with code.

Andreas