Message ID | xmqqy20r3rv7.fsf@gitster.g (mailing list archive) |
---|---|
State | Accepted |
Commit | 6563706568b952d85c050b208b5301303d32810c |
Headers | show |
Series | CodingGuidelines: give deadline for "for (int i = 0; ..." | expand |
On Wed, Mar 30 2022, Junio C Hamano wrote: > We raised the weather balloon to see if we can allow the construct > in 44ba10d6 (revision: use C99 declaration of variable in for() > loop, 2021-11-14), which was shipped as a part of Git v2.35. > Document that fact in the coding guidelines, and more importantly, > give ourselves a deadline to revisit and update. > > Let's declare that we will officially adopt the variable declaration > in the initializaiton [...] Typo: initialization. > part of "for ()" statement this winter, unless we find that a platform > we care about does not grok it. I'd think that waiting a couple of releases would be sufficient for this sort of thing. I.e. contributors to this project already have access/knowledge about a wide variety of compilers, especially the "usual suspects" (mainly MSVC) that have been blockers for using new language features in the past. So I'm in no rush to use this, and the winter deadline sounds fine to me in that regard. But on the other hand I think the likelihood that waiting until November v.s. May revealing that a hitherto unknown compiler or platform has issues with a new language feature is vanishingly small. > A separate weather balloon for C99 as a whole was raised separately > in 7bc341e2 (git-compat-util: add a test balloon for C99 support, > 2021-12-01). Hopefully, as we find out that all C99 features are OK > on all platforms we care about, we can stop probing the features we > want one-by-one like this Unfortunately this really isn't the case at all, the norm is for compilers to advertise that they support verison X of the standard via these macros when they consider the support "good enough", but while there's still a long list of unimplemented features before they're at 100% support (and most never fully get to 100%). We also need to worry about the stdlib implementation, and not just the compiler, see e.g. the %zu format and MinGW in the exchange at https://lore.kernel.org/git/220318.86bky3cr8j.gmgdl@evledraar.gmail.com/ and https://lore.kernel.org/git/a67e0fd8-4a14-16c9-9b57-3430440ef93c@gmail.com/; But I think we're thoroughly past needing to worry about basic language features in C99 such as these inline variable declarations. > (it does not necessarily mean that we would automatically start using > any and all C99 language features, though). Yes, particularly those that the standards committee backed out of or made optional after C99 would be good candidates for avoiding permanently.
On 31/03/2022 11:10, Ævar Arnfjörð Bjarmason wrote: > > On Wed, Mar 30 2022, Junio C Hamano wrote: > >> We raised the weather balloon to see if we can allow the construct >> in 44ba10d6 (revision: use C99 declaration of variable in for() >> loop, 2021-11-14), which was shipped as a part of Git v2.35. >> Document that fact in the coding guidelines, and more importantly, >> give ourselves a deadline to revisit and update. >> >> Let's declare that we will officially adopt the variable declaration >> in the initializaiton [...] > > Typo: initialization. > >> part of "for ()" statement this winter, unless we find that a platform >> we care about does not grok it. > > I'd think that waiting a couple of releases would be sufficient for this > sort of thing. I.e. contributors to this project already have > access/knowledge about a wide variety of compilers, especially the > "usual suspects" (mainly MSVC) that have been blockers for using new > language features in the past. > > So I'm in no rush to use this, and the winter deadline sounds fine to > me in that regard. Agreed, I think it is worth waiting so we don't get into a situation where we end up having to revert changes that are using the new features because we discover they are not supported by a platform we care about. > But on the other hand I think the likelihood that waiting until November > v.s. May revealing that a hitherto unknown compiler or platform has > issues with a new language feature is vanishingly small. > >> A separate weather balloon for C99 as a whole was raised separately >> in 7bc341e2 (git-compat-util: add a test balloon for C99 support, >> 2021-12-01). Hopefully, as we find out that all C99 features are OK >> on all platforms we care about, we can stop probing the features we >> want one-by-one like this > > Unfortunately this really isn't the case at all, the norm is for > compilers to advertise that they support verison X of the standard via > these macros when they consider the support "good enough", but while > there's still a long list of unimplemented features before they're at > 100% support (and most never fully get to 100%). > > We also need to worry about the stdlib implementation, and not just the > compiler, see e.g. the %zu format and MinGW in the exchange at > https://lore.kernel.org/git/220318.86bky3cr8j.gmgdl@evledraar.gmail.com/ > and > https://lore.kernel.org/git/a67e0fd8-4a14-16c9-9b57-3430440ef93c@gmail.com/; That's a good point, it was a surprise to me that the problem is with MinGW rather than MSVC. Best Wishes Phillip > But I think we're thoroughly past needing to worry about basic language > features in C99 such as these inline variable declarations. > >> (it does not necessarily mean that we would automatically start using >> any and all C99 language features, though). > > Yes, particularly those that the standards committee backed out of or > made optional after C99 would be good candidates for avoiding > permanently.
On Thu, Mar 31 2022, Phillip Wood wrote: > On 31/03/2022 11:10, Ævar Arnfjörð Bjarmason wrote: >> On Wed, Mar 30 2022, Junio C Hamano wrote: >> >>> We raised the weather balloon to see if we can allow the construct >>> in 44ba10d6 (revision: use C99 declaration of variable in for() >>> loop, 2021-11-14), which was shipped as a part of Git v2.35. >>> Document that fact in the coding guidelines, and more importantly, >>> give ourselves a deadline to revisit and update. >>> >>> Let's declare that we will officially adopt the variable declaration >>> in the initializaiton [...] >> Typo: initialization. >> >>> part of "for ()" statement this winter, unless we find that a platform >>> we care about does not grok it. >> I'd think that waiting a couple of releases would be sufficient for >> this >> sort of thing. I.e. contributors to this project already have >> access/knowledge about a wide variety of compilers, especially the >> "usual suspects" (mainly MSVC) that have been blockers for using new >> language features in the past. >> So I'm in no rush to use this, and the winter deadline sounds fine >> to >> me in that regard. > > Agreed, I think it is worth waiting so we don't get into a situation > where we end up having to revert changes that are using the new > features because we discover they are not supported by a platform we > care about. > >> But on the other hand I think the likelihood that waiting until November >> v.s. May revealing that a hitherto unknown compiler or platform has >> issues with a new language feature is vanishingly small. >> >>> A separate weather balloon for C99 as a whole was raised separately >>> in 7bc341e2 (git-compat-util: add a test balloon for C99 support, >>> 2021-12-01). Hopefully, as we find out that all C99 features are OK >>> on all platforms we care about, we can stop probing the features we >>> want one-by-one like this >> Unfortunately this really isn't the case at all, the norm is for >> compilers to advertise that they support verison X of the standard via >> these macros when they consider the support "good enough", but while >> there's still a long list of unimplemented features before they're at >> 100% support (and most never fully get to 100%). >> We also need to worry about the stdlib implementation, and not just >> the >> compiler, see e.g. the %zu format and MinGW in the exchange at >> https://lore.kernel.org/git/220318.86bky3cr8j.gmgdl@evledraar.gmail.com/ >> and >> https://lore.kernel.org/git/a67e0fd8-4a14-16c9-9b57-3430440ef93c@gmail.com/; > > That's a good point, it was a surprise to me that the problem is with > MinGW rather than MSVC. Yes, thanks a lot for tracking that down. I wonder if we can supply a compatibility sprintf() shim for that setup, there's nothing urgent about it, but the verbosity of the casts and PRIuMAX inline adds up, especially as we've started using size_t more widely: git grep PRIuMAX -- '*.[ch]' Either by e.g. grabbing the sprintf() shim from say gnulib, or our own shim that would intercept the "const char *format" for sprintf(), and pull a trick similar to what we do in strbuf_addftime() to rewrite the format (of a copied string) on-the-fly.
Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes: >> A separate weather balloon for C99 as a whole was raised separately >> in 7bc341e2 (git-compat-util: add a test balloon for C99 support, >> 2021-12-01). Hopefully, as we find out that all C99 features are OK >> on all platforms we care about, we can stop probing the features we >> want one-by-one like this > > Unfortunately this really isn't the case at all, the norm is for > compilers to advertise that they support verison X of the standard via > these macros when they consider the support "good enough", but while > there's still a long list of unimplemented features before they're at > 100% support (and most never fully get to 100%). > > We also need to worry about the stdlib implementation, and not just the > compiler, see e.g. the %zu format and MinGW in the exchange at > https://lore.kernel.org/git/220318.86bky3cr8j.gmgdl@evledraar.gmail.com/ > and > https://lore.kernel.org/git/a67e0fd8-4a14-16c9-9b57-3430440ef93c@gmail.com/; > > But I think we're thoroughly past needing to worry about basic language > features in C99 such as these inline variable declarations. Well, that makes it sound like the C99 weather balloon was almost useless, doesn't it? In any case, I'll strick the last paragraph from the final log message, as the patch text itself is about one specific feature, and not about deciding what our policy for various C99 language feeatures ought to be. Thanks.
On 2022-03-31 at 20:12:09, Junio C Hamano wrote: > Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes: > > >> A separate weather balloon for C99 as a whole was raised separately > >> in 7bc341e2 (git-compat-util: add a test balloon for C99 support, > >> 2021-12-01). Hopefully, as we find out that all C99 features are OK > >> on all platforms we care about, we can stop probing the features we > >> want one-by-one like this > > > > Unfortunately this really isn't the case at all, the norm is for > > compilers to advertise that they support verison X of the standard via > > these macros when they consider the support "good enough", but while > > there's still a long list of unimplemented features before they're at > > 100% support (and most never fully get to 100%). > > > > We also need to worry about the stdlib implementation, and not just the > > compiler, see e.g. the %zu format and MinGW in the exchange at > > https://lore.kernel.org/git/220318.86bky3cr8j.gmgdl@evledraar.gmail.com/ > > and > > https://lore.kernel.org/git/a67e0fd8-4a14-16c9-9b57-3430440ef93c@gmail.com/; > > > > But I think we're thoroughly past needing to worry about basic language > > features in C99 such as these inline variable declarations. > > Well, that makes it sound like the C99 weather balloon was almost > useless, doesn't it? I think if we were talking about C17, maybe. But as I said in my commit message, C99 is over two decades old and required for the POSIX version which came out in 2001. I'm aware of only two platforms we care about that don't support that POSIX version, which are NonStop and Windows. I think the likelihood of this being a problem is very low. And I think we can justifiably expect that major syntactic functionality is available when the define is set accordingly. I am also willing to simply tell people that a compiler that includes the define and doesn't include the requisite features is buggy and ask them to use a modern version of GCC or clang. But, ultimately, given we're talking about C99, this is extremely unlikely to ever be a problem in 2022.
On Thu, Mar 31 2022, brian m. carlson wrote: > [[PGP Signed Part:Undecided]] > On 2022-03-31 at 20:12:09, Junio C Hamano wrote: >> Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes: >> >> >> A separate weather balloon for C99 as a whole was raised separately >> >> in 7bc341e2 (git-compat-util: add a test balloon for C99 support, >> >> 2021-12-01). Hopefully, as we find out that all C99 features are OK >> >> on all platforms we care about, we can stop probing the features we >> >> want one-by-one like this >> > >> > Unfortunately this really isn't the case at all, the norm is for >> > compilers to advertise that they support verison X of the standard via >> > these macros when they consider the support "good enough", but while >> > there's still a long list of unimplemented features before they're at >> > 100% support (and most never fully get to 100%). >> > >> > We also need to worry about the stdlib implementation, and not just the >> > compiler, see e.g. the %zu format and MinGW in the exchange at >> > https://lore.kernel.org/git/220318.86bky3cr8j.gmgdl@evledraar.gmail.com/ >> > and >> > https://lore.kernel.org/git/a67e0fd8-4a14-16c9-9b57-3430440ef93c@gmail.com/; >> > >> > But I think we're thoroughly past needing to worry about basic language >> > features in C99 such as these inline variable declarations. >> >> Well, that makes it sound like the C99 weather balloon was almost >> useless, doesn't it? > > I think if we were talking about C17, maybe. But as I said in my commit > message, C99 is over two decades old and required for the POSIX version > which came out in 2001. I'm aware of only two platforms we care about > that don't support that POSIX version, which are NonStop and Windows. What I'm referring to upthread is that if you look at e.g. https://gcc.gnu.org/c99status.html and compare it to https://gcc.gnu.org/releases.html you can see that GCC (which is usually really early with these things) was still implementing major C99 features like "inline" (it had its own syntax, but not the C99 one) in 2008. So, part of this is just unintentional commentary on how old I'm getting :), I hadn't looked before sending the upthread, but I remembered this being a bit closer to $(date). In any case, I think that shows a typical pattern where compiler implementations are still catching up with standards at least 5-10 years after they're released. If you then look at C11 at https://gcc.gnu.org/wiki/C11Status you can see that _Generic took until April 2014 with GCC 4.9, and e.g. https://access.redhat.com/solutions/19458 notes that RHEL 7 (still in wide use) was released with GCC 4.8, and RHEL 6 with 4.4. (I wouldn't be surprised if RedHat had sneakily backported some features, so don't take that as gospel about what is and isn't supported on that platform). > I think the likelihood of this being a problem is very low. And I think > we can justifiably expect that major syntactic functionality is > available when the define is set accordingly. Indeed, I only meant to suggest that we might still need to be careful with some of the more exotic features, and do some research similar to the above. E.g. I wouldn't be at all surprised if some of the long-tail compilers we support (suncc, xlc, msvc) had implemented some parts of C99 much later. > I am also willing to simply tell people that a compiler that includes > the define and doesn't include the requisite features is buggy and ask > them to use a modern version of GCC or clang. So we can drop MinGW & I can use %zu? Yay! :) More seriously, I don't think we should have such a blanket policy. Sure, we might decide that's worth it, but when we run into such issues I think it's good to just weigh the trade-offs for particular feature. See "We live in the real world" in Documentation/CodingGuidelines for some nice wisdom. E.g. (and I didn't recall this when I wrote most of the above) I've got 33665d98e6b (reftable: make assignments portable to AIX xlc v12.01, 2022-03-28) in "next" right now which undoes some small use of C99 syntax because a (buggy) version of xlc isn't too happy about an edge-case of valid C99 initializer syntax. Now, we could just say we won't support that compiler, but as argued in that commit message it's relatively easy to accommodate it, so being a bit lenient with what subset of the standard we insist on seems prudent. > But, ultimately, given we're talking about > C99, this is extremely unlikely to ever be a problem in 2022. Per the above it was a (small) problem on 2022-03-28 :)
diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines index 0e27b5395d..f0475c1770 100644 --- a/Documentation/CodingGuidelines +++ b/Documentation/CodingGuidelines @@ -217,7 +217,10 @@ For C programs: the first statement (i.e. -Wdeclaration-after-statement). - Declaring a variable in the for loop "for (int i = 0; i < 10; i++)" - is still not allowed in this codebase. + is still not allowed in this codebase. We are in the process of + allowing it by waiting to see that 44ba10d6 (revision: use C99 + declaration of variable in for() loop, 2021-11-14) does not get + complaints. Let's revisit this around November 2022. - NULL pointers shall be written as NULL, not as 0.
We raised the weather balloon to see if we can allow the construct in 44ba10d6 (revision: use C99 declaration of variable in for() loop, 2021-11-14), which was shipped as a part of Git v2.35. Document that fact in the coding guidelines, and more importantly, give ourselves a deadline to revisit and update. Let's declare that we will officially adopt the variable declaration in the initializaiton part of "for ()" statement this winter, unless we find that a platform we care about does not grok it. A separate weather balloon for C99 as a whole was raised separately in 7bc341e2 (git-compat-util: add a test balloon for C99 support, 2021-12-01). Hopefully, as we find out that all C99 features are OK on all platforms we care about, we can stop probing the features we want one-by-one like this (it does not necessarily mean that we would automatically start using any and all C99 language features, though). Signed-off-by: Junio C Hamano <gitster@pobox.com> --- Documentation/CodingGuidelines | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)