rename and move AssertVariableIsOfType

  • Jump to comment-1
    Peter Eisentraut<peter@eisentraut.org>
    Jan 26, 2026, 12:17 PM UTC
    I'm proposing two changes:
    First, rename AssertVariableIsOfType to StaticAssertVariableIsOfType. The current name suggests that it is a run-time assertion (like "Assert"), but it's not. The name change makes that clearer.
    I doubt that the current name is used in many extensions, but if necessary, extension code could adapt to this quite easily with something like
    #if PGVERSIONNUM < ...
    #define StaticAssertVariableIsOfType(x, y) AssertVariableIsOfType(x, y)
    #endif
    Second, change the underlying implementation of StaticAssertVariableIsOfType to use StaticAssertDecl instead of StaticAssertStmt. This makes StaticAssertVariableIsOfType behave more like a normal static assertion, and in many cases we can move the current instances to a more natural position at file scope. This is similar to previous commits like 493eb0da31b.
    • Jump to comment-1
      Bertrand Drouvot<bertranddrouvot.pg@gmail.com>
      Jan 27, 2026, 12:55 PM UTC
      Hi,
      On Mon, Jan 26, 2026 at 01:17:15PM +0100, Peter Eisentraut wrote:
      I'm proposing two changes:

      First, rename AssertVariableIsOfType to StaticAssertVariableIsOfType. The
      current name suggests that it is a run-time assertion (like "Assert"), but
      it's not. The name change makes that clearer.

      I doubt that the current name is used in many extensions, but if necessary,
      extension code could adapt to this quite easily with something like

      #if PGVERSIONNUM < ...
      #define StaticAssertVariableIsOfType(x, y) AssertVariableIsOfType(x, y)
      #endif

      Second, change the underlying implementation of StaticAssertVariableIsOfType
      to use StaticAssertDecl instead of StaticAssertStmt. This makes
      StaticAssertVariableIsOfType behave more like a normal static assertion, and
      in many cases we can move the current instances to a more natural position
      at file scope. This is similar to previous commits like 493eb0da31b.
      Both make sense and looks good to me.
      Once they are in, I'm wondering if the remaining StaticAssertStmt ones:
      src/backend/backup/basebackup.c: StaticAssertStmt(2 * TARBLOCKSIZE <= BLCKSZ,
      src/backend/storage/lmgr/deadlock.c: StaticAssertStmt(MAXBACKENDSBITS <= (32 - 3),
      src/backend/utils/mmgr/aset.c: StaticAssertStmt(ALLOCCHUNKLIMIT == ALLOCSETSEPARATETHRESHOLD,
      could be replaced by StaticAssertDecl() too (that has not been done in 493eb0da31b
      and (from a quick scan) not mentioned in the linked thread). I did not look in
      details so maybe there is good reasons to keep them.
      Regards,
      --
      Bertrand Drouvot
      PostgreSQL Contributors Team
      RDS Open Source Databases
      Amazon Web Services: https://aws.amazon.com