RFR (tedious) 8216022: Use #pragma once

Erik Österlund erik.osterlund at oracle.com
Thu Jan 3 15:50:41 UTC 2019


Hi,

I think the value of moving to #pragma once instead of using include 
guards is that it is easy to mess up include guards. Admittedly, at 
least I tend to get them wrong quite often, and every time I get annoyed 
that we don't use #pragma once. Especially in platform specific files, 
that I can't even build to see if I messed up. And getting includes 
wrong could be potentially dangerous, apart from being a waste of time. 
I think it's a waste of time for reviewers to go through and point out 
errors in include guards, and similarly it is a waste of time for 
contributors to stare at their include guards until their eyes start 
bleeding before reviews to make sure they didn't mess up, and upload new 
webrevs when they mess them up. Might be exaggerating a bit... but still.

So basically, I for one, would really appreciate if we could start using 
#pragma once, and I have been dreaming about the bright #pragma once 
future for years, and was hoping this would be the right time to make 
the move. Will shed a few tears if we decide not to do it.

Thanks,
/Erik

On 2019-01-03 11:51, Andrew Haley wrote:
> On 1/3/19 7:48 AM, Kim Barrett wrote:
> 
>> I think we shouldn't make this change without considering the impact
>> of the following bug:
>>
>> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58770
>> GCC very slow compiling with #pragma once
>>
>> According to comment 3, using "#pragma once" introduces N^2 behavior
>> on the number of included files, because the duplicate check uses a
>> list rather than a hashtable.
>>
>> At the very least, a performance comparison should be made to find out
>> what the impact of that bug is.
> 
> Thank you for a very detailed analysis. I agree with you that this
> shouldn't be changed, at least for now. I've been following the
> discussion in the GCC lists and others for years, and the overall
> feeling I get is that #pragma once isn't quite what we need for header
> file inclusion. Instead, GCC and other compilers have a very high
> performance implementation of include guards.
> 
> Nevertheless, I am still a GCC maintainer and I'll fix the bug in
> #pragma once if it's really going to be useful. But based on some of
> the known issues with #pragma once, I don't believe that it will
> be. #pragma once is a nice idea, but I think that's all it is.
> 


More information about the hotspot-dev mailing list