Re: rename and move AssertVariableIsOfType

From: Peter Eisentraut <peter(at)eisentraut(dot)org>
To: Bertrand Drouvot <bertranddrouvot(dot)pg(at)gmail(dot)com>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: rename and move AssertVariableIsOfType
Date: 2026-02-03 08:09:17
Message-ID: 29582d05-cff5-4409-a566-2e7cbb2eacac@eisentraut.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 27.01.26 13:55, Bertrand Drouvot wrote:
> 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 PG_VERSION_NUM < ...
>> #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.

Thanks, committed.

> Once they are in, I'm wondering if the remaining StaticAssertStmt ones:
>
> src/backend/backup/basebackup.c: StaticAssertStmt(2 * TAR_BLOCK_SIZE <= BLCKSZ,
> src/backend/storage/lmgr/deadlock.c: StaticAssertStmt(MAX_BACKENDS_BITS <= (32 - 3),
> src/backend/utils/mmgr/aset.c: StaticAssertStmt(ALLOC_CHUNK_LIMIT == ALLOCSET_SEPARATE_THRESHOLD,
>
> 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.

Yeah, maybe it would be good to get rid of these remaining few. I
suppose we could just change Stmt to Decl and put braces around the
block, but maybe there are some more elegant places to move these.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Jim Jones 2026-02-03 08:21:57 Re: Additional message in pg_terminate_backend
Previous Message Roman Khapov 2026-02-03 07:52:57 Re: Additional message in pg_terminate_backend