Re: Unused header file inclusion - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Unused header file inclusion
Date
Msg-id 29534.1564615501@sss.pgh.pa.us
Whole thread Raw
In response to Re: Unused header file inclusion  (Andres Freund <andres@anarazel.de>)
Responses Re: Unused header file inclusion  (Andres Freund <andres@anarazel.de>)
List pgsql-hackers
Andres Freund <andres@anarazel.de> writes:
> On 2019-07-31 16:55:31 -0400, Tom Lane wrote:
>> Yeah.  I seem to recall a proposal that nodes.h should contain
>> 
>> typedef struct Foo Foo;
>> 
>> for every node type Foo, and then the other headers would just
>> fill in the structs, and we could get rid of a lot of ad-hoc
>> forward struct declarations and other hackery.

> That to me just seems objectively worse. Now adding a new struct as a
> minor implementation detail of some subsystem doesn't just require
> recompiling the relevant files, but just about all of pg.

Er, what?  This list of typedefs would change exactly when enum NodeTag
changes, so AFAICS your objection is bogus.

It's true that this proposal doesn't help for structs that aren't Nodes,
but my sense is that > 90% of our ad-hoc struct references are for Nodes.

> Right now we really have weird dependencies between largely independent
> subsystem.

Agreed, but I think fixing that will take some actually serious design
work.  It's not going to mechanically fall out of changing typedef rules.

> The only reason the explicit forward declaration is needed in the common
> case of a 'struct foo*' parameter is that C has weird visibility rules
> about the scope of forward declarations in paramters.

Yeah, but there's not much we can do about that, nor is getting rid
of typedefs in favor of "struct" going to make it even a little bit
better.

            regards, tom lane



pgsql-hackers by date:

Previous
From: Petr Jelinek
Date:
Subject: Re: POC: converting Lists into arrays
Next
From: Tom Lane
Date:
Subject: Re: POC: converting Lists into arrays