Re: Proposal: Add more compile-time asserts to expose inconsistencies.

2020-03-09 Thread Michael Paquier
On Tue, Mar 10, 2020 at 12:22:32AM +, Smith, Peter wrote: > Sorry I was AWOL for a couple of months. Thanks for taking the patch > further, and committing it. No problem, I am glad to see you around. -- Michael signature.asc Description: PGP signature

RE: Proposal: Add more compile-time asserts to expose inconsistencies.

2020-03-09 Thread Smith, Peter
Hi Michael, Sorry I was AWOL for a couple of months. Thanks for taking the patch further, and committing it. Kind Regards --- Peter Smith Fujitsu Australia

Re: Proposal: Add more compile-time asserts to expose inconsistencies.

2020-02-02 Thread Michael Paquier
On Fri, Jan 31, 2020 at 02:46:16PM +0900, Michael Paquier wrote: > Actually, thinking more about it, I'd rather remove this part as well, > keeping only the change in the third paragraph of this comment block. I have tweaked a bit the comments in this area, and applied the patch. I'll begin a new

Re: Proposal: Add more compile-time asserts to expose inconsistencies.

2020-01-30 Thread Michael Paquier
On Fri, Jan 31, 2020 at 02:15:42PM +0900, Kyotaro Horiguchi wrote: > As a cross check, it cleanly applied and worked as expected. The > fallback definition of StaticAssertDecl for C worked for gcc 8.3. Thanks for the review. > - * Macros to support compile-time assertion checks. > + * Macros to s

Re: Proposal: Add more compile-time asserts to expose inconsistencies.

2020-01-30 Thread Kyotaro Horiguchi
At Fri, 31 Jan 2020 11:47:01 +0900, Michael Paquier wrote in > On Tue, Dec 24, 2019 at 02:47:29PM +0900, Michael Paquier wrote: > > I am still seeing that a couple of points need an extra lookup: > > - Addition of a Decl() in at least one header of the core code. > > I agree with the addition o

Re: Proposal: Add more compile-time asserts to expose inconsistencies.

2020-01-30 Thread Michael Paquier
On Tue, Dec 24, 2019 at 02:47:29PM +0900, Michael Paquier wrote: > I am still seeing that a couple of points need an extra lookup: > - Addition of a Decl() in at least one header of the core code. I agree with the addition of Decl() definition in a header, and could not think about something bette

Re: Proposal: Add more compile-time asserts to expose inconsistencies.

2019-12-23 Thread Michael Paquier
On Fri, Dec 20, 2019 at 01:08:47AM +, Smith, Peter wrote: > I updated the most recent patch (_5 from Michael) so it now has your > suggested error message rewording. Hmm. Based on the last messages, and this one in particular: https://www.postgresql.org/message-id/20191202155545.yzbfzuppjriti

Re: Proposal: Add more compile-time asserts to expose inconsistencies.

2019-12-22 Thread Michael Paquier
On Wed, Dec 04, 2019 at 09:54:47AM -0800, Andres Freund wrote: > Well, _Static_assert has an error message, so we got to pass > something. And having something like "array length mismatch", without > referring again to the variable, doesn't strike me as that bad. We could > of course just again pas

RE: Proposal: Add more compile-time asserts to expose inconsistencies.

2019-12-19 Thread Smith, Peter
Hello Michael, > In short, attached is an updated version of your patch which attempts to > solve that. I have tested this with some cplusplus stuff, and GCC for both > versions (static_assert is available in GCC >= 6, but a manual change of c.h > does the trick). > I have edited the patch a b

RE: Proposal: Add more compile-time asserts to expose inconsistencies.

2019-12-04 Thread Smith, Peter
-Original Message- From: Andres Freund Sent: Tuesday, 3 December 2019 2:56 AM > +StaticAssertDecl(lengthof(LockTagTypeNames) == (LOCKTAG_ADVISORY + 1), > + "LockTagTypeNames array inconsistency"); > + > >These error messages strike me as somewhat unhelpful. I'd

Re: Proposal: Add more compile-time asserts to expose inconsistencies.

2019-12-04 Thread Andres Freund
Hi, On 2019-12-04 10:09:28 +0100, Peter Eisentraut wrote: > On 2019-12-02 16:55, Andres Freund wrote: > > > +StaticAssertDecl(lengthof(LockTagTypeNames) == (LOCKTAG_ADVISORY + 1), > > > + "LockTagTypeNames array inconsistency"); > > > + > > These error messages strike me a

Re: Proposal: Add more compile-time asserts to expose inconsistencies.

2019-12-04 Thread Andres Freund
On 2019-12-04 15:16:25 +0900, Michael Paquier wrote: > On Mon, Dec 02, 2019 at 07:55:45AM -0800, Andres Freund wrote: > > Now that I'm back from vacation, I'll try to take a stab at b). It > > should definitely doable to use the same approach for StaticAssertStmt, > > the problematic case might be

Re: Proposal: Add more compile-time asserts to expose inconsistencies.

2019-12-04 Thread Peter Eisentraut
On 2019-12-02 16:55, Andres Freund wrote: +StaticAssertDecl(lengthof(LockTagTypeNames) == (LOCKTAG_ADVISORY + 1), +"LockTagTypeNames array inconsistency"); + These error messages strike me as somewhat unhelpful. I'd probably just reword them as "array length misma

Re: Proposal: Add more compile-time asserts to expose inconsistencies.

2019-12-03 Thread Michael Paquier
On Mon, Dec 02, 2019 at 07:55:45AM -0800, Andres Freund wrote: > On 2019-11-29 11:11:25 +0900, Michael Paquier wrote: >> diff --git a/src/include/c.h b/src/include/c.h >> index 00e41ac546..91d6d50e76 100644 >> --- a/src/include/c.h >> +++ b/src/include/c.h >> [...] > > I think this a) needs an upd

Re: Proposal: Add more compile-time asserts to expose inconsistencies.

2019-12-02 Thread Andres Freund
Hi, On 2019-11-29 11:11:25 +0900, Michael Paquier wrote: > On Wed, Nov 27, 2019 at 12:23:33PM +, Smith, Peter wrote: > > * That is beyond the scope for what I wanted my patch to achieve; my > > * use-cases are C code only. I really don't think that's justification enough for having diverging

Re: Proposal: Add more compile-time asserts to expose inconsistencies.

2019-11-28 Thread Michael Paquier
On Wed, Nov 27, 2019 at 12:23:33PM +, Smith, Peter wrote: > * That is beyond the scope for what I wanted my patch to achieve; my > * use-cases are C code only. Well, FWIW, I do have some extensions using __cplusplus and I am pretty sure that I am not the only one with that. The thing is that

RE: Proposal: Add more compile-time asserts to expose inconsistencies.

2019-11-27 Thread Smith, Peter
> It seems to me that there is a good point to be consistent with the treatment > of StaticAssertStmt and StaticAssertExpr in c.h, which have fallback > implementations in *all* the configurations supported. Consistency is good, but: * That is beyond the scope for what I wanted my patch to achi

RE: Proposal: Add more compile-time asserts to expose inconsistencies.

2019-11-27 Thread Smith, Peter
Hi Andres, >>> As far as I can tell we should be able to use the prototype based approach >>> in all the cases where we currently use the "negative bit-field width" >>> approach? >> ... >> But I did not refactor existing code to use the new way because I was >> fearful that there might be some

Re: Proposal: Add more compile-time asserts to expose inconsistencies.

2019-11-14 Thread Andres Freund
Hi, On 2019-11-13 03:23:06 +, Smith, Peter wrote: > From: Andres Freund Sent: Wednesday, 13 November 2019 > 6:01 AM > > >Peter Smith: > > > > Is there a reason to not just make StaticAssertExpr and StaticAssertStmt be > > the same? I don't want to proliferate variants that users have to >

Re: Proposal: Add more compile-time asserts to expose inconsistencies.

2019-11-14 Thread Peter Eisentraut
On 2019-11-12 20:00, Andres Freund wrote: Looking at the cplusplus variant, I'm somewhat surprised to see that you made both fallback and plain version unconditionally use GCC style compound expressions: Was that intentional? The C version intentionally uses compound expressions only for the _

RE: Proposal: Add more compile-time asserts to expose inconsistencies.

2019-11-12 Thread Smith, Peter
From: Andres Freund Sent: Wednesday, 13 November 2019 6:01 AM >Peter Smith: > > Is there a reason to not just make StaticAssertExpr and StaticAssertStmt be > the same? I don't want to proliferate variants that users have to understand > if there's no compelling > need. Nor do I think do we r

Re: Proposal: Add more compile-time asserts to expose inconsistencies.

2019-11-12 Thread Andres Freund
Hi Peter, Peter, :) On 2019-10-28 00:30:11 +, Smith, Peter wrote: > From: Andres Freund Sent: Sunday, 27 October 2019 12:03 > PM > > My proposal for this really was just to use this as a fallback for when > > static assert isn't available. Which in turn I was just suggesting because > > T

Re: Proposal: Add more compile-time asserts to expose inconsistencies.

2019-11-11 Thread Michael Paquier
On Mon, Oct 28, 2019 at 03:42:02AM +, Smith, Peter wrote: > From: Kyotaro Horiguchi Sent: Monday, 28 October > 2019 1:26 PM >> It is missing the __cplusplus case? > > My use cases for the macro are only in C code, so that's all I was interested > in at this time. > If somebody else wants to

RE: Proposal: Add more compile-time asserts to expose inconsistencies.

2019-10-27 Thread Smith, Peter
From: Kyotaro Horiguchi Sent: Monday, 28 October 2019 1:26 PM > It is missing the __cplusplus case? My use cases for the macro are only in C code, so that's all I was interested in at this time. If somebody else wants to extend the patch for C++ also (and test it) they can do. Kind Regards,

RE: Proposal: Add more compile-time asserts to expose inconsistencies.

2019-10-27 Thread Smith, Peter
From: Andres Freund Sent: Sunday, 27 October 2019 12:03 PM > My proposal for this really was just to use this as a fallback for when > static assert isn't available. Which in turn I was just suggesting because > Tom wanted a fallback. The patch is updated to use "extern" technique only when "_

Re: Proposal: Add more compile-time asserts to expose inconsistencies.

2019-10-27 Thread Andres Freund
On 2019-10-27 11:44:54 +, Smith, Peter wrote: > From: Andres Freund Sent: Sunday, 27 October 2019 12:03 > PM > > I think it should work everywhere that has static assert. So we should need > > a separate configure check. > > Er, that's a typo right? I think you meant: "So we *shouldn't* nee

RE: Proposal: Add more compile-time asserts to expose inconsistencies.

2019-10-27 Thread Smith, Peter
From: Andres Freund Sent: Sunday, 27 October 2019 12:03 PM >>Ideally, the implementation should end up calling _Static_assert() >>somehow, so that we get the compiler's native error message. OK. I can work on that. >>We could do a configure check for whether _Static_assert() works at >>file s

Re: Proposal: Add more compile-time asserts to expose inconsistencies.

2019-10-26 Thread Andres Freund
Hi, On October 26, 2019 6:06:07 AM PDT, Peter Eisentraut wrote: >On 2019-10-10 00:52, Smith, Peter wrote: >> I liked your idea of using an extern function declaration for >implementing the file-scope compile-time asserts. AFAIK it is valid >standard C. >> >> Thank you for the useful link to th

Re: Proposal: Add more compile-time asserts to expose inconsistencies.

2019-10-26 Thread Peter Eisentraut
On 2019-10-10 00:52, Smith, Peter wrote: > I liked your idea of using an extern function declaration for implementing > the file-scope compile-time asserts. AFAIK it is valid standard C. > > Thank you for the useful link to that compiler explorer. I tried many > scenarios of the new StaticAssert

RE: Proposal: Add more compile-time asserts to expose inconsistencies.

2019-10-09 Thread Smith, Peter
From: Andres Freund Sent: Tuesday, 1 October 2019 3:14 AM >I wonder if defining the fallback static assert code to something like > extern void static_assert_func(int static_assert_failed[(condition) ? 1 : > -1]); isn't a solution, however. I *think* that's standard C. Seems to work > at least

Re: Proposal: Add more compile-time asserts to expose inconsistencies.

2019-09-30 Thread Andres Freund
Hi, On September 30, 2019 10:20:54 AM PDT, Tom Lane wrote: >Andres Freund writes: >> On 2019-09-19 04:46:27 +, Smith, Peter wrote: >>> In the attached patch example I have defined a new macro >>> StaticAssertDecl. A typical usage of it is shown in the relpath.c >>> file. > >> I'm in favor o

Re: Proposal: Add more compile-time asserts to expose inconsistencies.

2019-09-30 Thread Tom Lane
Andres Freund writes: > On 2019-09-19 04:46:27 +, Smith, Peter wrote: >> In the attached patch example I have defined a new macro >> StaticAssertDecl. A typical usage of it is shown in the relpath.c >> file. > I'm in favor of adding that - in fact, when I was working on adding a a > static_as

Re: Proposal: Add more compile-time asserts to expose inconsistencies.

2019-09-30 Thread Andres Freund
Hi, On 2019-09-19 04:46:27 +, Smith, Peter wrote: > In the attached patch example I have defined a new macro > StaticAssertDecl. A typical usage of it is shown in the relpath.c > file. I'm in favor of adding that - in fact, when I was working on adding a a static_assert wrapper, I was advocat

RE: Proposal: Add more compile-time asserts to expose inconsistencies.

2019-09-18 Thread Smith, Peter
-Original Message- From: Michael Paquier Sent: Thursday, 19 September 2019 11:08 AM >On Wed, Sep 18, 2019 at 04:46:30PM +0100, Dagfinn Ilmari Mannsåker wrote: >> Postgres doesn't seem to have it, but it would be possible to define a >> StaticAssertDecl macro that can be used at the file

Re: Proposal: Add more compile-time asserts to expose inconsistencies.

2019-09-18 Thread Kyotaro Horiguchi
At Thu, 19 Sep 2019 10:07:40 +0900, Michael Paquier wrote in <20190919010740.gc22...@paquier.xyz> > On Wed, Sep 18, 2019 at 04:46:30PM +0100, Dagfinn Ilmari Mannsåker wrote: > > Postgres doesn't seem to have it, but it would be possible to define a > > StaticAssertDecl macro that can be used at t

Re: Proposal: Add more compile-time asserts to expose inconsistencies.

2019-09-18 Thread Michael Paquier
On Wed, Sep 18, 2019 at 04:46:30PM +0100, Dagfinn Ilmari Mannsåker wrote: > Postgres doesn't seem to have it, but it would be possible to define a > StaticAssertDecl macro that can be used at the file level, outside any > function. See for example Perl's STATIC_ASSERT_DECL: > > https://github.com

RE: Proposal: Add more compile-time asserts to expose inconsistencies.

2019-09-18 Thread Smith, Peter
-Original Message- From: Michael Paquier Sent: Wednesday, 18 September 2019 5:40 PM > For some of them it could help, and we could think about a better location > for that stuff than an unused routine. The indentation of your patch is > weird, with "git diff --check" complaining a lo

Re: Proposal: Add more compile-time asserts to expose inconsistencies.

2019-09-18 Thread Dagfinn Ilmari Mannsåker
Michael Paquier writes: > On Wed, Sep 18, 2019 at 06:46:24AM +, Smith, Peter wrote: >> I have identified some OSS code where more compile-time asserts could be >> added. >> >> Mostly these are asserting that arrays have the necessary length to >> accommodate the enums that are used to inde

Re: Proposal: Add more compile-time asserts to expose inconsistencies.

2019-09-18 Thread Michael Paquier
On Wed, Sep 18, 2019 at 06:46:24AM +, Smith, Peter wrote: > I have identified some OSS code where more compile-time asserts could be > added. > > Mostly these are asserting that arrays have the necessary length to > accommodate the enums that are used to index into them. > > In general the