r/programming • u/dmalcolm • Mar 08 '19
Usability improvements in GCC 9
https://developers.redhat.com/blog/2019/03/08/usability-improvements-in-gcc-9/4
u/galaktos Mar 08 '19
That sounds very cool! But this sentence got me wondering:
GCC can emit “fix-it hints” that suggest how to fix a problem in your code. These can be automatically applied by an IDE.
Are these fix-it hints already integrated with any IDEs – and if yes, how does (or did) that work, if the JSON output format is new? Some of the fix-it hints look pretty regular and parseable to me (the ones with +++ in the left margin look like good ol’ patches), but others seem more magical (the last four under “Other improvements”, for example).
5
u/dmalcolm Mar 08 '19
I implemented machine-readable fix-it hints in GCC 7, via a -fdiagnostics-parseable-fixits option (which imitates a line-based format originally implemented by clang). The only IDE I know of that supports it so far is Eclipse's CDT
1
-1
u/ashipman Mar 08 '19
What about an xml format for all diagnostic output?
17
u/dmalcolm Mar 08 '19
I could implement XML output, but I felt that given the existence of JSON output that XML would be redundant. Is there a use-case I'm missing here? My assumption is that JSON parsers are readily available, everywhere that XML is, at least.
3
u/evaned Mar 08 '19
Actually, I've got a quick question about the JSON format. How stable do you envision it to be at this point?
1
u/ashipman Mar 08 '19
JSON would work too. I was just thinking that if I pipe the output of the compiler into some other tool such as an editor then the colouring would be lost. But some sort of markup that could be easily parsed by an extension in the editor would be useful. (There is already some attempt at recognising gcc errors in many editors but it's primitive).
1
u/MaxCHEATER64 Mar 09 '19
Emacs has wonderful support for gcc output and gcc uses terminal control codes so the colors should already be portable.
2
6
u/oridb Mar 08 '19 edited Mar 08 '19
I appreciate the effort, but I find the errors are getting more noisy and harder to skim. For example:
$ gcc-8 t.cc
t.cc: In function ‘int test(const shape&, const shape&)’:
t.cc:15:4: error: no match for ‘operator+’ (operand types are ‘boxed_value<double>’ and ‘boxed_value<double>’)
return (width(s1) * height(s1)
~~~~~~~~~~~~~~~~~~~~~~
+ width(s2) * height(s2));
^~~~~~~~~~~~~~~~~~~~~~~~is easier for me than:
$ gcc-9 t.cc
t.cc: In function ‘int test(const shape&, const shape&)’:
t.cc:15:4: error: no match for ‘operator+’ (operand types are ‘boxed_value<double>’ and ‘boxed_value<double>’)
14 | return (width(s1) * height(s1)
| ~~~~~~~~~~~~~~~~~~~~~~
| |
| boxed_value<[...]>
15 | + width(s2) * height(s2));
| ^ ~~~~~~~~~~~~~~~~~~~~~~
| |
| boxed_value<[...]>I've already got the source open in my editor, and my editor has jumped to the lines -- repeating the source doesn't help me much, and obscures the useful text in the error.
I'd even prefer something simpler, where only the operator is highlighted, and the visual noise around operand types are ....
$ gcc-10 t.cc
t.cc:15:4: error: no match for ‘operator+(boxed_value<double>, boxed_value<double>)'
+ width(s2) * height(s2));
~^~What might be useful would be help deciphering SFINAE, layers of implicit conversions, etc.
$ gcc-10 t.cc
t.cc:15:4: error: no match for ‘operator+(boxed_value<double>, boxed_value<double>)'
+ width(s2) * s2);
~^~
considered t.cc:42:1: operator+(boxed_value<double>, boxed_value<double>(const shape&&))', required rvalue reference
considered t.cc:123:1: operator+(double, double)', unaligned phase of moon0
Mar 09 '19
[deleted]
3
u/lelanthran Mar 09 '19
It's the opposite for me - it increases cognitive load. Take this real example from this morning:
qrcps/qrcps.c: In function ‘qrcps_code’: ./qrcps/qrcps.h:50:34: error: called object is not a function or function pointer #define QRCPS_TEMPLATE_BITS (0x7f << QRCPS_TEMPLATE_POS) ^ qrcps/qrcps.c:423:15: note: in expansion of macro ‘QRCPS_TEMPLATE_BITS’ switch (QRCPS_TEMPLATE_BITS (f->info)) { ^~~~~~~~~~~~~~~~~~~~~~~You have to read the definition of the macro (plus its line number, filename and character position) before the compiler actually gives you the error, which is in a different file.
The proper way to do it is to put the relevant stuff first - the other stuff that may not even be helpful goes later.
1
u/ais523 Mar 09 '19
Isn't the actual error here that you've attempted to call a constant-like macro as though it were a function-like macro? The code expands to something of the form
(constant)(parameter), and the compiler is complaining that the constant isn't a function or function pointer.I don't think it's possible to explain how that happened without showing both pieces of code, as they're both plausible on their own, it's just that the combination makes no sense.
That said, the
^~~~line seems to be the wrong length, it should probably stop at the opening parenthesis before(f->info).1
u/lelanthran Mar 09 '19
Isn't the actual error here that you've attempted to call a constant-like macro as though it were a function-like macro?
Yes.
I don't think it's possible to explain how that happened without showing both pieces of code,
Sure it is; when you call a function incorrectly it shows the error at the point of the function call first, because that is the actual error. Showing the extra information about the params is shown second, if at all.
Why switch it around when the symbol involved is not a function but a macro?
That said, the ~~~ line seems to be the wrong length, it should probably stop at the opening parenthesis before (f->info).
Maybe. I just copied the error message and ensured that the spaces were correct.
My point was, since gcc has increased its error reporting I can no longer simply scan the line containing the error, because multiple lines are given even when the compiler knows which line the error is on.
In the usual case I prefer scanning the error message rather than studying it. It's very rare to want to sit down with a cup of tea to read a compiler error message :-)
(Possibly some magical switch in gcc exists to revert to the mostly single-line error messages it used to give).
1
u/oridb Mar 10 '19 edited Mar 10 '19
I don't think it's possible to explain how that happened without showing both pieces of code, as they're both plausible on their own, it's just that the combination makes no sense.
I've got the code open in my editor, and I can jump to both places in my editor. The error message doesn't exist in isolation -- and the valuable parts aren't the repetition of the code I'm already staring at. I want to know why the error was caused, with the minimum amount of context that will tell me what caused the error.
Also, that error would actually take me to the wrong place in my editor -- it would leave me at the definition of the macro, and not the point where it was used.
I'd prefer something that looked like this:
qrcps/qrcps.c:423:15: error: called object "(0x7f << QRCPS_TEMPLATE_POS)" is not callable note: expanded from "QRCPS_TEMPLATE_BITS" on ./qrcps/qrcps.h:50:34This does a few things: First, it flags the line that the error occurs on, instead of the line that the macro was expanded from. Second, it makes it clear visually that the macro expansion is not another error. Third, it reduces the visual noise from copying and pasting the code, and instead shows only the source of the error. And finally, I've pared down the verbosity a little bit.
4
u/darophi Mar 08 '19
A welcoming change that the compiler hints and errors are becoming even more friendlier. I can't stop to think of the Rust compiler with regards to a compiler that really tries to be your friend.
-7
-6
u/oblio- Mar 08 '19
It would be cool if they could implement proper error numbers: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-messages/
12
u/dmalcolm Mar 08 '19
For warnings, we emit the relevant option at the end of the line e.g.:
cve-2014-1266.c:629:2: warning: this ‘if’ clause does not guard... [-Wmisleading-indentation]which is searchable for.
But we don't do that for errors; I realize that there isn't a unique searchable ID for those (potentially with a documentation page?). Should there be?
7
u/oblio- Mar 08 '19
It would be awesome. But if you don't do it yourself, provided you add unique codes, a cottage industry of solutions for those errors will appear, as it did for C#, Typescript, Oracle, etc.
9
u/Quincunx271 Mar 08 '19
This would actually be pretty helpful. When I need to search an error, searching the text of the message often finds no results or unrelated results. With error codes or names for the errors, I think there'd be a higher chance of finding relevant results.
6
u/Holy_City Mar 08 '19
Especially if the error message changes.
3
u/Genion1 Mar 08 '19
Bonus points for localized messages.
1
u/the_gnarts Mar 08 '19
Nah. Just set the English locale temporarily to generate a searchable version of the error.
2
u/tracernz Mar 09 '19
You know, gcc includes some excellent searchable documentation right on your machine.
man gcc /misleading\-indentation NN2
u/Quincunx271 Mar 10 '19
Thanks! I'll be sure to check it next time. It probably won't help if there's no name for the error, but it will come in handy otherwise.
2
u/jephthai Mar 08 '19
What I have to do is search for the text of the error. What's most annoying is when the error text is composed of really generic phrases with tokens from my program between them. So I'm searching for the three or four distinct phraselets, hoping those are unique enough that some poor soul already asked about it on stack overflow.
Of course, if error numbers are introduced, it'll be years before stack overflow gets fully populated with questions that include error numbers. Not to mention most of them will be closed as dupes because SO sucks that way.
35
u/tracernz Mar 08 '19
Those Microsoft-style numbers (assuming the C# ones are similar to MSVC, since your link doesn't actually have any examples) are a great way to write unreadable lines in your build system.
e.g. to enable warnings for unhandled enums in switch statements:
win32-msvc*:QMAKE_CXXFLAGS_WARN_ON += /we4062
vs.
!win32-msvc*:QMAKE_CXXFLAGS_WARN_ON += -Wswitch-enum
-2
u/oblio- Mar 08 '19
My link is just examples :)))) CS0001, CS0002, etc. :)
21
u/masklinn Mar 08 '19
They're all terrible regardless. I couldn't thank the gods enough when pylint finally added message ids:
# pylint: disable=W0311means jack shit,
# pylint: disable=bad-indentationcan be roughly understood without the need to look up the meaningless garble.
4
u/oblio- Mar 08 '19
You can have both...
[W0311][BAD-INDENTATION] <LONG ERROR MESSAGE HERE>
10
u/oridb Mar 08 '19
While this is technically true, providing two unique identifiers for the same thing doesn't provide a meaningful improvement. And given a choice of one unique identifier, I'd take the human friendly unique identifier.
-7
u/shevy-ruby Mar 08 '19
GCC feels the pressure from LLVM.
LLVM has a huge lead in regards to infrastructure-support (e. g. things such as crystal).
GCC has indeed improved in the last ~2 years or so, at the least from what I can tell; I am not sure this will be enough to keep LLVM at bay though.
13
u/evaned Mar 08 '19
GCC has indeed improved in the last ~2 years or so, at the least from what I can tell;
Hell -- GCC started showing major improvements in error messages and such way longer than that ago; by the late 4.x series they were showing significant improvements. That's getting up toward a decade ago now.
2
7
u/the_gnarts Mar 08 '19
GCC feels the pressure from LLVM.
It’s more a general trend that clean compiler errors are being valued more in recent times than they used to. Very similar improvements were made to e.g. the Ocaml compiler in about the same timeframe and that language certainly isn’t subject to competition from LLVM. Rustc which was conceived and implemented during the last decade was built from the outset with that mindset and it really shows. Our tooling is evolving away from the earlier naive attitude that in compilers, only performance improvements are worth implementing.
25
u/evaned Mar 08 '19
This all looks pretty amazing.
I wonder how plausible it is to cut out one of the lines in each "block" and use ANSI escapes to underline the relevant part of code instead of putting in the
~~~~~s on its own line?