allow benign typedef redefinitions (C11)

Peter Eisentraut <peter@eisentraut.org>

From: Peter Eisentraut <peter@eisentraut.org>
To: pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2025-08-29T12:45:54Z
Lists: pgsql-hackers

Attachments

Here is the first of several (to come at a later date) patch sets to 
take some advantage of C11 features.

This is, I hope, a very gentle start that shouldn't stress even older 
compilers very much, and should bring some tangible benefits that had 
already been asked for around here.

In C11, typedef redefinitions are allowed, as long as they are the same.  So

typedef int foo;
typedef int foo;

is allowed, where the second occurrence would have led to a diagnostic 
in previous C versions.

(C++ also allows this, so this will preserve C++ compatibility of the 
headers.)

What is not allowed is something like this of course:

typedef int foo;
typedef double foo;

This will continue to be an error.

This facility is often useful to untangle dependencies between header 
files.  So instead of having one header include another, now the first 
header can just make its own typedef of whatever types it needs.  If the 
two headers are later included together, then this will not (any more) 
be a conflict.  This often works together with declaring incomplete 
types using struct.

The PostgreSQL code already contains a couple of places that wanted to 
do something like this but had to install manual workarounds with #ifdef 
guards.  These can now be removed.  There are also a bunch of struct 
forward declarations that can be "upgraded" to full typedefs.  This 
makes the function prototypes look more consistent.

In this patch set, 0001 is a prerequisite for 0002, 0002 and 0003 remove 
some existing workarounds, the remaining patches are additional 
opportunities for cleanup and simplification.

All of this is only notational, there are no include changes or API 
changes or changes in behavior.

(After this, it would probably be possible to undertake some deeper 
efforts to untangle header files, with the help of IWYU.  But that is a 
separate project.)

Commits

  1. Move instrumentation-related structs to instrument_node.h

  2. Don't include access/htup_details.h in executor/tuptable.h

  3. Don't include execnodes.h in brin.h or gin.h

  4. Do a tiny bit of header file maintenance

  5. Don't include execnodes.h in replication/conflict.h

  6. Update some more forward declarations to use typedef

  7. Change fmgr.h typedefs to use original names

  8. Improve ExplainState type handling in header files

  9. Remove hbaPort type

  10. Remove workarounds against repeat typedefs

  11. Update various forward declarations to use typedef

  12. Allow redeclaration of typedef yyscan_t

  13. Improve pgbench definition of yyscan_t

  14. Delay extraction of TIDBitmap per page offsets

  15. Remove pgrminclude and associated scripts

  16. Allow to use HeapTupleData embedded in [Buffer]HeapTupleTableSlot.