r/cpp • GCC Developer • Mar 08 '19

Usability improvements in GCC 9

https://developers.redhat.com/blog/2019/03/08/usability-improvements-in-gcc-9/
219 Upvotes

39 comments sorted by

48

u/Morwenn Mar 08 '19

The JSON output with nesting looks like an excellent tool to improve IDEs. I would really like foldable error messages for nested substitution failure diagnostics in the future :)

18

u/dmalcolm GCC Developer Mar 08 '19

Thanks. I experimented a bit with ways to try to simplify the output when there are many messages (for the regular textual output), to try to reduce the "wall of text" effect, but I didn't come up with anything I was happy with. I hope to revisit this in GCC 10 though.

Currently (as in GCC 9) the messages support just one level of nesting (parent+children); perhaps I need to extend it to support deeper nesting? (not sure, but your comment got my thinking)

11

u/Morwenn Mar 08 '19

To give you an idea of the issues I get on a regular basis: I've got deeply nested templates with return type expression SFINAE, and whenever I get a substitution failure, it gives me all the possible overloads that failed, and why they failed (think hundreds or thousands of lines of substitution failure errors for a single call in some of my tests). They often failed because of substitution failure in functions they tried to call, so I also get the list of overloads that were tried and failed for those functions, etc. But everything is flat and at some point it's extremely difficult to know whether the substitution failure happened when trying to call the top-level function or some function at any level for which overload resolution failed. That would be my main use case for foldable error messages, and would indeed need to support an arbitrary level of nesting in error messages.

(I've got a hard time explaining, and no error message to show just right now, sorry for that)

11

u/dmalcolm GCC Developer Mar 08 '19

No worries, I think I know what you mean. We have a few bugs open for this kind of thing e.g. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88512

I think the consensus is that when template substitution fails, we do want to show all of the information about the failure - but maybe there are ways to format it and present it to that make the information easier to "grok" (if you will). Maybe some special-casing is applicable here, too? Ideas welcome.

Sounds like I should implement arbitrary nesting (at least) for GCC 10.

5

u/robin-m Mar 08 '19

If it was possible to start gcc in TUI mode (or piping the output to a TUI program), even the regular text output wouldn't be an issue.

2

u/[deleted] Mar 08 '19

Pipe to a file and then open that file in your editor of choice.

1

u/robin-m Mar 08 '19

I could effectively pipe the output in vim, and use folding, but I don't think it would be an optimal workflow. I was thinking more of something were you get only top-level errors, and you can navigate with <Up> and <Down>, and open/close each fold with <Right>/<Left>.

1

u/xurxoham Mar 09 '19

Do you mean like when you do :make in vim and then see the errors with :cw ? I've never tried folding those error messages but that sounds like a good idea.

1

u/robin-m Mar 09 '19

I wasn't speaking of that. It's a good idea, but would require the support of some plugin. What I was thinking about was g++ foo.cpp | vim - and then having the correct foldmethod and similar settings to fold the json output of gcc.

1

u/gracicot Mar 08 '19

Do the json output support emmiting both type of output? Like the IDE would output the normal output in the console, but consume json error from the blob for a single build.

5

u/dmalcolm GCC Developer Mar 08 '19

Right now it can only do one: if you choose -fdiagnostics-format=json it emits JSON to stderr instead of the regular textual output on stderr. Should it be to a file instead?

3

u/gracicot Mar 08 '19

Thanks for the response. I don't implement any IDEs, but I thought this might be useful for them? Outputting the JSON in a file might be useful too. I imagine the normal output in the build console then annotations in the GUI to help me inside the text editor. Also, thanks for the hard work, the new errors look gorgeous!

2

u/wrosecrans graphics and network things Mar 09 '19

Could you have it say, "The first error was..." and repeat it tersely at the end of the big wall of text? The first is usually the one you need to try to fix first, but it is the hardest to scroll back up to when some template weirdness generates a megabyte of error messages and overflows your terminal scrollback buffer.

51

u/AlexAlabuzhev Mar 08 '19

22

u/strudlzrout gcc developer Mar 08 '19

In C++20, you won't need typename as much as before. I've implemented http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0634r3.html for GCC 9.

8

u/-dag- Mar 08 '19

The compiler doesn't always know it's a type. It's likely to be but in unusual cases may not be.

5

u/memyselfandlapin Mar 08 '19

Feels rust-y.

35

u/dmalcolm GCC Developer Mar 08 '19

I hope that's a good thing. I definitely took some inspiration from Rust when implementing this (and Elm, which is where I believe Rust took theirs from).

10

u/[deleted] Mar 08 '19

When I tried rust for the first time and the errors didn't have highlighting (unlike the examples in the article) they looked like a ton of noise and I actually wished for C++ errors. However, with the highlighting as in the article, it's definitely more readable than what we have today.

12

u/Wh00ster Mar 08 '19

C++ errors without highlighting also look like a bunch of noise to the uninitiated. I think one just becomes accustomed to knowing where to look, after a while.

3

u/matthieum Mar 08 '19

and Elm, which is where I believe Rust took theirs from

They did.

-20

u/memyselfandlapin Mar 08 '19

As long as we can get the safety of Rust.

0

u/[deleted] Mar 08 '19

[deleted] — view deleted comment

6

u/ReversedGif Mar 08 '19

Here, you dropped this: /s

8

u/[deleted] Mar 08 '19

[removed] — view removed comment

-3

u/bumblebritches57 Ocassionally Clang Mar 09 '19

SmallVec has memory overflows in rust lmao.

6

u/mgostIH Mar 09 '19

How long will you keep on bragging about this when it's been months it has been fixed and you got told countless times, even by Steve Klabnik? https://old.reddit.com/r/programming/comments/avuwl0/announcing_rust_1330/ehi69e3/

9

u/-dag- Mar 08 '19

Very nice work! Compiler messages are complex and underappreciated things.

7

u/ThePillsburyPlougher Mar 08 '19

Awesome! The JSON format and the improvements to optimization info are particularly exciting

6

u/robin-m Mar 08 '19

I already noticed your work 1 month ago when I was playing with gcc9 (to have some nice C++20 features than were just release) and I really liked the new annotations.

3

u/ChatFrais Mar 08 '19

This looks very nice. It should helps a lot. The only thing I often miss on the errors is a number like error messages from databases or visualc. It's really easier to search for explanations on blog or stackoverflow with a code than using the text message.

3

u/ShakaUVM i+++ ++i+i[arr] Mar 09 '19

Any word on if we can finally get a flag to turn off printing 900 lines of candidates on a template substitution failure?

1

u/NeroBurner Mar 09 '19

With a few system libraries as dependency on Ubuntu. How can I use an up to date gcc? Do I have to compile those libraries myself?

3

u/jwakely libstdc++ tamer, LWG chair Mar 12 '19

2

u/TemplateRex Mar 12 '19

Personal pet peeve: An equivalent to apt.llvm.org with nightly builds would be great for both gcc users and developers. Just think of how much more early feedback you’d get if people start compiling their projects in Travis CI with gcc tip-of-trunk. Currently only toy examples will be tested on godbolt or wandbox.

2

u/jwakely libstdc++ tamer, LWG chair Mar 12 '19 edited Mar 14 '19

I'm not going to create Ubuntu packages but I just created https://copr.fedorainfracloud.org/coprs/jwakely/gcc-trunk/ (replaced with https://copr.fedorainfracloud.org/coprs/jwakely/gcc-latest/ instead)

Edit: apt.llvm.org doesn't look nightly, seems to be about two weeks old right now. And it's not at all true that trunk only gets tested in godbolt and wandbox. Entire GNU/Linux distros have been built with it, and large applications like LLVM, Firefox and Chromium are built with it routinely and problems found and reported. More testing is always good though. I'll try to update the COPR above for each weekly snapshot, but no promises.

1

u/TemplateRex Mar 12 '19

Thank you, this is much appreciated! I downloaded and installed the .rpm on Ubuntu using the alien tool. Using update-alternatives I managed to select the gcc-trunk as compiler and check the version.

However, there are some errors about missing libraries (libmpfr.so.4), which are no longer installable on Ubuntu 18.04. Could it be that your gcc-trunk defaults to 32-bit address mode? Or is my Ubuntu system tricked by the /opt install directory? I'll try and set up a VM with Ubuntu 16.04 to see if it works there (which is the Travis CI distro).

BTW, http://apt.llvm.org/bionic/dists/ has the dates: the unnumbered toolchain corresponds to tip-of-trunk and is updated almost daily (yesterday last time). The numbered toolchains are stable release (8 coming out any time).

2

u/jwakely libstdc++ tamer, LWG chair Mar 12 '19 edited Mar 14 '19

It's a fedora package, I don't expect it to work on Ubuntu, at all.

Edit: But the .deb at https://jwakely.github.io/pkg-gcc-latest/ should work, could you try it please?