Simplifying our Trap/Assert infrastructure

Started by Tom Laneover 3 years ago13 messages
#1Tom Lane
tgl@sss.pgh.pa.us
1 attachment(s)

I happened to notice that the Trap and TrapMacro macros defined in c.h
have a grand total of one usage apiece across our entire code base.
It seems a little pointless and confusing to have them at all, since
they're essentially Assert/AssertMacro but with the inverse condition
polarity. I'm also annoyed that they are documented while the macros
we actually use are not.

I'm also thinking that the "errorType" argument of ExceptionalCondition
is not nearly pulling its weight given the actual usage. Removing it
reduces the size of an assert-enabled build of HEAD from

$ size src/backend/postgres
text data bss dec hex filename
9065335 86280 204496 9356111 8ec34f src/backend/postgres

to

$ size src/backend/postgres
text data bss dec hex filename
9001199 86280 204496 9291975 8dc8c7 src/backend/postgres

(on RHEL8 x86_64), which admittedly is only about 1%, but it's 1%
for just about no detectable return.

Hence, I propose the attached.

regards, tom lane

Attachments:

simplify-assert-infrastructure-1.patchtext/x-diff; charset=us-ascii; name=simplify-assert-infrastructure-1.patchDownload
diff --git a/contrib/amcheck/verify_heapam.c b/contrib/amcheck/verify_heapam.c
index d33f33f170..83dc728011 100644
--- a/contrib/amcheck/verify_heapam.c
+++ b/contrib/amcheck/verify_heapam.c
@@ -1319,7 +1319,7 @@ check_tuple_attribute(HeapCheckContext *ctx)
 	 */
 
 	/*
-	 * Check that VARTAG_SIZE won't hit a TrapMacro on a corrupt va_tag before
+	 * Check that VARTAG_SIZE won't hit an Assert on a corrupt va_tag before
 	 * risking a call into att_addlength_pointer
 	 */
 	if (VARATT_IS_EXTERNAL(tp + ctx->offset))
diff --git a/src/backend/utils/error/assert.c b/src/backend/utils/error/assert.c
index 2da512a2f1..ac6173e660 100644
--- a/src/backend/utils/error/assert.c
+++ b/src/backend/utils/error/assert.c
@@ -28,20 +28,17 @@
  */
 void
 ExceptionalCondition(const char *conditionName,
-					 const char *errorType,
 					 const char *fileName,
 					 int lineNumber)
 {
 	/* Report the failure on stderr (or local equivalent) */
 	if (!PointerIsValid(conditionName)
-		|| !PointerIsValid(fileName)
-		|| !PointerIsValid(errorType))
+		|| !PointerIsValid(fileName))
 		write_stderr("TRAP: ExceptionalCondition: bad arguments in PID %d\n",
 					 (int) getpid());
 	else
-		write_stderr("TRAP: %s(\"%s\", File: \"%s\", Line: %d, PID: %d)\n",
-					 errorType, conditionName,
-					 fileName, lineNumber, (int) getpid());
+		write_stderr("TRAP: failed Assert(\"%s\"), File: \"%s\", Line: %d, PID: %d\n",
+					 conditionName, fileName, lineNumber, (int) getpid());
 
 	/* Usually this shouldn't be needed, but make sure the msg went out */
 	fflush(stderr);
diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c
index eb724a9d7f..6e0a66c29e 100644
--- a/src/backend/utils/error/elog.c
+++ b/src/backend/utils/error/elog.c
@@ -1832,8 +1832,7 @@ pg_re_throw(void)
 	}
 
 	/* Doesn't return ... */
-	ExceptionalCondition("pg_re_throw tried to return", "FailedAssertion",
-						 __FILE__, __LINE__);
+	ExceptionalCondition("pg_re_throw tried to return", __FILE__, __LINE__);
 }
 
 
diff --git a/src/include/c.h b/src/include/c.h
index c8f72e44d8..0ba58f1f1b 100644
--- a/src/include/c.h
+++ b/src/include/c.h
@@ -796,8 +796,6 @@ typedef NameData *Name;
 #define AssertArg(condition)	((void)true)
 #define AssertState(condition)	((void)true)
 #define AssertPointerAlignment(ptr, bndr)	((void)true)
-#define Trap(condition, errorType)	((void)true)
-#define TrapMacro(condition, errorType) (true)
 
 #elif defined(FRONTEND)
 
@@ -811,60 +809,38 @@ typedef NameData *Name;
 #else							/* USE_ASSERT_CHECKING && !FRONTEND */
 
 /*
- * Trap
- *		Generates an exception if the given condition is true.
+ * Assert
+ *		Generates a fatal exception if the given condition is false.
  */
-#define Trap(condition, errorType) \
-	do { \
-		if (condition) \
-			ExceptionalCondition(#condition, (errorType), \
-								 __FILE__, __LINE__); \
-	} while (0)
-
-/*
- *	TrapMacro is the same as Trap but it's intended for use in macros:
- *
- *		#define foo(x) (AssertMacro(x != 0), bar(x))
- *
- *	Isn't CPP fun?
- */
-#define TrapMacro(condition, errorType) \
-	((bool) (! (condition) || \
-			 (ExceptionalCondition(#condition, (errorType), \
-								   __FILE__, __LINE__), 0)))
-
 #define Assert(condition) \
 	do { \
 		if (!(condition)) \
-			ExceptionalCondition(#condition, "FailedAssertion", \
-								 __FILE__, __LINE__); \
+			ExceptionalCondition(#condition, __FILE__, __LINE__); \
 	} while (0)
 
+/*
+ * AssertMacro is the same as Assert but it's suitable for use in
+ * expression-like macros, for example:
+ *
+ *		#define foo(x) (AssertMacro(x != 0), bar(x))
+ */
 #define AssertMacro(condition) \
 	((void) ((condition) || \
-			 (ExceptionalCondition(#condition, "FailedAssertion", \
-								   __FILE__, __LINE__), 0)))
+			 (ExceptionalCondition(#condition, __FILE__, __LINE__), 0)))
 
-#define AssertArg(condition) \
-	do { \
-		if (!(condition)) \
-			ExceptionalCondition(#condition, "BadArgument", \
-								 __FILE__, __LINE__); \
-	} while (0)
-
-#define AssertState(condition) \
-	do { \
-		if (!(condition)) \
-			ExceptionalCondition(#condition, "BadState", \
-								 __FILE__, __LINE__); \
-	} while (0)
+/*
+ * AssertArg and AssertState are identical to Assert.  Some places use them
+ * to indicate that the complaint is specifically about a bad argument or
+ * unexpected state, but this usage is largely obsolescent.
+ */
+#define AssertArg(condition) Assert(condition)
+#define AssertState(condition) Assert(condition)
 
 /*
  * Check that `ptr' is `bndr' aligned.
  */
 #define AssertPointerAlignment(ptr, bndr) \
-	Trap(TYPEALIGN(bndr, (uintptr_t)(ptr)) != (uintptr_t)(ptr), \
-		 "UnalignedPointer")
+	Assert(TYPEALIGN(bndr, (uintptr_t)(ptr)) == (uintptr_t)(ptr))
 
 #endif							/* USE_ASSERT_CHECKING && !FRONTEND */
 
@@ -876,7 +852,6 @@ typedef NameData *Name;
  */
 #ifndef FRONTEND
 extern void ExceptionalCondition(const char *conditionName,
-								 const char *errorType,
 								 const char *fileName, int lineNumber) pg_attribute_noreturn();
 #endif
 
diff --git a/src/include/postgres.h b/src/include/postgres.h
index 5f6a1e3d5a..54730dfb38 100644
--- a/src/include/postgres.h
+++ b/src/include/postgres.h
@@ -135,7 +135,7 @@ typedef enum vartag_external
 	((tag) == VARTAG_INDIRECT ? sizeof(varatt_indirect) : \
 	 VARTAG_IS_EXPANDED(tag) ? sizeof(varatt_expanded) : \
 	 (tag) == VARTAG_ONDISK ? sizeof(varatt_external) : \
-	 TrapMacro(true, "unrecognized TOAST vartag"))
+	 (AssertMacro(false), 0))
 
 /*
  * These structs describe the header of a varlena object that may have been
#2Nathan Bossart
nathandbossart@gmail.com
In reply to: Tom Lane (#1)
Re: Simplifying our Trap/Assert infrastructure

On Sun, Oct 09, 2022 at 03:51:57PM -0400, Tom Lane wrote:

I happened to notice that the Trap and TrapMacro macros defined in c.h
have a grand total of one usage apiece across our entire code base.
It seems a little pointless and confusing to have them at all, since
they're essentially Assert/AssertMacro but with the inverse condition
polarity. I'm also annoyed that they are documented while the macros
we actually use are not.

+1, I noticed this recently, too.

Hence, I propose the attached.

The patch LGTM. It might be worth removing usages of AssertArg and
AssertState, too, but that can always be done separately.

--
Nathan Bossart
Amazon Web Services: https://aws.amazon.com

#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: Nathan Bossart (#2)
Re: Simplifying our Trap/Assert infrastructure

Nathan Bossart <nathandbossart@gmail.com> writes:

On Sun, Oct 09, 2022 at 03:51:57PM -0400, Tom Lane wrote:

Hence, I propose the attached.

The patch LGTM. It might be worth removing usages of AssertArg and
AssertState, too, but that can always be done separately.

Something I thought about but forgot to mention in the initial email:
is it worth sprinkling these macros with "unlikely()"? I think that
compilers might assume the right thing automatically based on noticing
that ExceptionalCondition is noreturn ... but then again they might
not. Of course we're not that fussed about micro-optimizations in
assert-enabled builds; but with so many Asserts in the system, it
might still add up to something noticeable if there is an effect.

regards, tom lane

#4Nathan Bossart
nathandbossart@gmail.com
In reply to: Tom Lane (#3)
Re: Simplifying our Trap/Assert infrastructure

On Sun, Oct 09, 2022 at 05:08:39PM -0400, Tom Lane wrote:

Something I thought about but forgot to mention in the initial email:
is it worth sprinkling these macros with "unlikely()"? I think that
compilers might assume the right thing automatically based on noticing
that ExceptionalCondition is noreturn ... but then again they might
not. Of course we're not that fussed about micro-optimizations in
assert-enabled builds; but with so many Asserts in the system, it
might still add up to something noticeable if there is an effect.

I don't see why not.

--
Nathan Bossart
Amazon Web Services: https://aws.amazon.com

#5Tom Lane
tgl@sss.pgh.pa.us
In reply to: Nathan Bossart (#4)
Re: Simplifying our Trap/Assert infrastructure

Nathan Bossart <nathandbossart@gmail.com> writes:

On Sun, Oct 09, 2022 at 05:08:39PM -0400, Tom Lane wrote:

Something I thought about but forgot to mention in the initial email:
is it worth sprinkling these macros with "unlikely()"?

I don't see why not.

I experimented with that, and found something that surprised me:
there's a noticeable code-bloat effect. With the patch as given,

$ size src/backend/postgres
text data bss dec hex filename
9001199 86280 204496 9291975 8dc8c7 src/backend/postgres

but with unlikely(),

$ size src/backend/postgres
text data bss dec hex filename
9035423 86280 204496 9326199 8e4e77 src/backend/postgres

I don't quite understand why that's happening, but it seems to
show that this requires some investigation of its own. So for
now I just pushed the patch as-is.

regards, tom lane

#6Nathan Bossart
nathandbossart@gmail.com
In reply to: Nathan Bossart (#2)
1 attachment(s)
Re: Simplifying our Trap/Assert infrastructure

On Sun, Oct 09, 2022 at 02:01:48PM -0700, Nathan Bossart wrote:

The patch LGTM. It might be worth removing usages of AssertArg and
AssertState, too, but that can always be done separately.

If you are so inclined...

--
Nathan Bossart
Amazon Web Services: https://aws.amazon.com

Attachments:

v1-0001-remove-AssertArg-and-AssertState.patchtext/x-diff; charset=us-asciiDownload
From 90e2166a64b9b6b9362a21b046e52a6304f85fc9 Mon Sep 17 00:00:00 2001
From: Nathan Bossart <nathandbossart@gmail.com>
Date: Wed, 12 Oct 2022 11:29:08 -0700
Subject: [PATCH v1 1/1] remove AssertArg and AssertState

---
 contrib/fuzzystrmatch/fuzzystrmatch.c         |  4 +-
 src/backend/access/common/tupdesc.c           | 32 ++++++------
 src/backend/access/heap/heapam.c              |  2 +-
 src/backend/access/nbtree/nbtsort.c           |  2 +-
 src/backend/access/transam/multixact.c        |  8 +--
 src/backend/access/transam/xact.c             |  6 +--
 src/backend/bootstrap/bootstrap.c             |  2 +-
 src/backend/catalog/namespace.c               |  2 +-
 src/backend/catalog/pg_collation.c            |  8 +--
 src/backend/commands/dbcommands.c             |  2 +-
 src/backend/commands/indexcmds.c              |  2 +-
 src/backend/commands/portalcmds.c             |  4 +-
 src/backend/commands/tablecmds.c              |  6 +--
 src/backend/jit/jit.c                         |  2 +-
 src/backend/parser/parse_utilcmd.c            |  2 +-
 src/backend/postmaster/autovacuum.c           |  4 +-
 .../replication/logical/reorderbuffer.c       |  2 +-
 src/backend/replication/slot.c                |  2 +-
 src/backend/storage/lmgr/lwlock.c             |  6 +--
 src/backend/tcop/postgres.c                   |  4 +-
 src/backend/tcop/pquery.c                     |  8 +--
 src/backend/utils/activity/pgstat.c           |  8 +--
 src/backend/utils/activity/pgstat_replslot.c  |  4 +-
 src/backend/utils/activity/pgstat_shmem.c     |  2 +-
 src/backend/utils/activity/pgstat_slru.c      |  2 +-
 src/backend/utils/adt/mcxtfuncs.c             |  2 +-
 src/backend/utils/adt/xml.c                   |  2 +-
 src/backend/utils/cache/relcache.c            |  2 +-
 src/backend/utils/fmgr/dfmgr.c                | 12 ++---
 src/backend/utils/init/miscinit.c             | 30 +++++------
 src/backend/utils/misc/guc-file.l             |  2 +-
 src/backend/utils/misc/guc.c                  |  6 +--
 src/backend/utils/mmgr/aset.c                 | 18 +++----
 src/backend/utils/mmgr/generation.c           | 16 +++---
 src/backend/utils/mmgr/mcxt.c                 | 50 +++++++++----------
 src/backend/utils/mmgr/portalmem.c            | 12 ++---
 src/backend/utils/mmgr/slab.c                 | 16 +++---
 src/backend/utils/sort/tuplesortvariants.c    | 12 ++---
 src/common/controldata_utils.c                |  2 +-
 src/common/protocol_openssl.c                 |  2 +-
 src/include/c.h                               | 12 -----
 src/include/executor/tuptable.h               |  8 +--
 src/include/miscadmin.h                       |  2 +-
 src/include/utils/pgstat_internal.h           |  4 +-
 44 files changed, 162 insertions(+), 174 deletions(-)

diff --git a/contrib/fuzzystrmatch/fuzzystrmatch.c b/contrib/fuzzystrmatch/fuzzystrmatch.c
index a04251ace6..5659cc71ac 100644
--- a/contrib/fuzzystrmatch/fuzzystrmatch.c
+++ b/contrib/fuzzystrmatch/fuzzystrmatch.c
@@ -724,8 +724,8 @@ _soundex(const char *instr, char *outstr)
 {
 	int			count;
 
-	AssertArg(instr);
-	AssertArg(outstr);
+	Assert(instr);
+	Assert(outstr);
 
 	outstr[SOUNDEX_LEN] = '\0';
 
diff --git a/src/backend/access/common/tupdesc.c b/src/backend/access/common/tupdesc.c
index d6fb261e20..b7f918c877 100644
--- a/src/backend/access/common/tupdesc.c
+++ b/src/backend/access/common/tupdesc.c
@@ -49,7 +49,7 @@ CreateTemplateTupleDesc(int natts)
 	/*
 	 * sanity checks
 	 */
-	AssertArg(natts >= 0);
+	Assert(natts >= 0);
 
 	/*
 	 * Allocate enough memory for the tuple descriptor, including the
@@ -273,12 +273,12 @@ TupleDescCopyEntry(TupleDesc dst, AttrNumber dstAttno,
 	/*
 	 * sanity checks
 	 */
-	AssertArg(PointerIsValid(src));
-	AssertArg(PointerIsValid(dst));
-	AssertArg(srcAttno >= 1);
-	AssertArg(srcAttno <= src->natts);
-	AssertArg(dstAttno >= 1);
-	AssertArg(dstAttno <= dst->natts);
+	Assert(PointerIsValid(src));
+	Assert(PointerIsValid(dst));
+	Assert(srcAttno >= 1);
+	Assert(srcAttno <= src->natts);
+	Assert(dstAttno >= 1);
+	Assert(dstAttno <= dst->natts);
 
 	memcpy(dstAtt, srcAtt, ATTRIBUTE_FIXED_PART_SIZE);
 
@@ -594,9 +594,9 @@ TupleDescInitEntry(TupleDesc desc,
 	/*
 	 * sanity checks
 	 */
-	AssertArg(PointerIsValid(desc));
-	AssertArg(attributeNumber >= 1);
-	AssertArg(attributeNumber <= desc->natts);
+	Assert(PointerIsValid(desc));
+	Assert(attributeNumber >= 1);
+	Assert(attributeNumber <= desc->natts);
 
 	/*
 	 * initialize the attribute fields
@@ -664,9 +664,9 @@ TupleDescInitBuiltinEntry(TupleDesc desc,
 	Form_pg_attribute att;
 
 	/* sanity checks */
-	AssertArg(PointerIsValid(desc));
-	AssertArg(attributeNumber >= 1);
-	AssertArg(attributeNumber <= desc->natts);
+	Assert(PointerIsValid(desc));
+	Assert(attributeNumber >= 1);
+	Assert(attributeNumber <= desc->natts);
 
 	/* initialize the attribute fields */
 	att = TupleDescAttr(desc, attributeNumber - 1);
@@ -767,9 +767,9 @@ TupleDescInitEntryCollation(TupleDesc desc,
 	/*
 	 * sanity checks
 	 */
-	AssertArg(PointerIsValid(desc));
-	AssertArg(attributeNumber >= 1);
-	AssertArg(attributeNumber <= desc->natts);
+	Assert(PointerIsValid(desc));
+	Assert(attributeNumber >= 1);
+	Assert(attributeNumber <= desc->natts);
 
 	TupleDescAttr(desc, attributeNumber - 1)->attcollation = collationid;
 }
diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c
index bd4d85041d..12be87efed 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2281,7 +2281,7 @@ heap_multi_insert(Relation relation, TupleTableSlot **slots, int ntuples,
 	bool		need_cids = RelationIsAccessibleInLogicalDecoding(relation);
 
 	/* currently not needed (thus unsupported) for heap_multi_insert() */
-	AssertArg(!(options & HEAP_INSERT_NO_LOGICAL));
+	Assert(!(options & HEAP_INSERT_NO_LOGICAL));
 
 	needwal = RelationNeedsWAL(relation);
 	saveFreeSpace = RelationGetTargetPageFreeSpace(relation,
diff --git a/src/backend/access/nbtree/nbtsort.c b/src/backend/access/nbtree/nbtsort.c
index bd1685c441..501e011ce1 100644
--- a/src/backend/access/nbtree/nbtsort.c
+++ b/src/backend/access/nbtree/nbtsort.c
@@ -1226,7 +1226,7 @@ _bt_load(BTWriteState *wstate, BTSpool *btspool, BTSpool *btspool2)
 			/* Abbreviation is not supported here */
 			sortKey->abbreviate = false;
 
-			AssertState(sortKey->ssup_attno != 0);
+			Assert(sortKey->ssup_attno != 0);
 
 			strategy = (scanKey->sk_flags & SK_BT_DESC) != 0 ?
 				BTGreaterStrategyNumber : BTLessStrategyNumber;
diff --git a/src/backend/access/transam/multixact.c b/src/backend/access/transam/multixact.c
index a7383f553b..5eff87665b 100644
--- a/src/backend/access/transam/multixact.c
+++ b/src/backend/access/transam/multixact.c
@@ -389,8 +389,8 @@ MultiXactIdCreate(TransactionId xid1, MultiXactStatus status1,
 	MultiXactId newMulti;
 	MultiXactMember members[2];
 
-	AssertArg(TransactionIdIsValid(xid1));
-	AssertArg(TransactionIdIsValid(xid2));
+	Assert(TransactionIdIsValid(xid1));
+	Assert(TransactionIdIsValid(xid2));
 
 	Assert(!TransactionIdEquals(xid1, xid2) || (status1 != status2));
 
@@ -445,8 +445,8 @@ MultiXactIdExpand(MultiXactId multi, TransactionId xid, MultiXactStatus status)
 	int			i;
 	int			j;
 
-	AssertArg(MultiXactIdIsValid(multi));
-	AssertArg(TransactionIdIsValid(xid));
+	Assert(MultiXactIdIsValid(multi));
+	Assert(TransactionIdIsValid(xid));
 
 	/* MultiXactIdSetOldestMember() must have been called already. */
 	Assert(MultiXactIdIsValid(OldestMemberMXactId[MyBackendId]));
diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c
index c1ffbd89b8..dcdba24419 100644
--- a/src/backend/access/transam/xact.c
+++ b/src/backend/access/transam/xact.c
@@ -3250,7 +3250,7 @@ CommitTransactionCommand(void)
 				s->savepointLevel = savepointLevel;
 
 				/* This is the same as TBLOCK_SUBBEGIN case */
-				AssertState(s->blockState == TBLOCK_SUBBEGIN);
+				Assert(s->blockState == TBLOCK_SUBBEGIN);
 				StartSubTransaction();
 				s->blockState = TBLOCK_SUBINPROGRESS;
 			}
@@ -3278,7 +3278,7 @@ CommitTransactionCommand(void)
 				s->savepointLevel = savepointLevel;
 
 				/* This is the same as TBLOCK_SUBBEGIN case */
-				AssertState(s->blockState == TBLOCK_SUBBEGIN);
+				Assert(s->blockState == TBLOCK_SUBBEGIN);
 				StartSubTransaction();
 				s->blockState = TBLOCK_SUBINPROGRESS;
 			}
@@ -4667,7 +4667,7 @@ RollbackAndReleaseCurrentSubTransaction(void)
 	CleanupSubTransaction();
 
 	s = CurrentTransactionState;	/* changed by pop */
-	AssertState(s->blockState == TBLOCK_SUBINPROGRESS ||
+	Assert(s->blockState == TBLOCK_SUBINPROGRESS ||
 				s->blockState == TBLOCK_INPROGRESS ||
 				s->blockState == TBLOCK_IMPLICIT_INPROGRESS ||
 				s->blockState == TBLOCK_STARTED);
diff --git a/src/backend/bootstrap/bootstrap.c b/src/backend/bootstrap/bootstrap.c
index 22635f8094..bb5275ba76 100644
--- a/src/backend/bootstrap/bootstrap.c
+++ b/src/backend/bootstrap/bootstrap.c
@@ -648,7 +648,7 @@ InsertOneValue(char *value, int i)
 	Oid			typinput;
 	Oid			typoutput;
 
-	AssertArg(i >= 0 && i < MAXATTR);
+	Assert(i >= 0 && i < MAXATTR);
 
 	elog(DEBUG4, "inserting column %d value \"%s\"", i, value);
 
diff --git a/src/backend/catalog/namespace.c b/src/backend/catalog/namespace.c
index 92aed2ff8b..539df1da94 100644
--- a/src/backend/catalog/namespace.c
+++ b/src/backend/catalog/namespace.c
@@ -4093,7 +4093,7 @@ InitTempTableNamespace(void)
 	MyProc->tempNamespaceId = namespaceId;
 
 	/* It should not be done already. */
-	AssertState(myTempNamespaceSubID == InvalidSubTransactionId);
+	Assert(myTempNamespaceSubID == InvalidSubTransactionId);
 	myTempNamespaceSubID = GetCurrentSubTransactionId();
 
 	baseSearchPathValid = false;	/* need to rebuild list */
diff --git a/src/backend/catalog/pg_collation.c b/src/backend/catalog/pg_collation.c
index 6081bf58c6..aa8fbe1a98 100644
--- a/src/backend/catalog/pg_collation.c
+++ b/src/backend/catalog/pg_collation.c
@@ -64,10 +64,10 @@ CollationCreate(const char *collname, Oid collnamespace,
 	ObjectAddress myself,
 				referenced;
 
-	AssertArg(collname);
-	AssertArg(collnamespace);
-	AssertArg(collowner);
-	AssertArg((collcollate && collctype) || colliculocale);
+	Assert(collname);
+	Assert(collnamespace);
+	Assert(collowner);
+	Assert((collcollate && collctype) || colliculocale);
 
 	/*
 	 * Make sure there is no existing collation of same name & encoding.
diff --git a/src/backend/commands/dbcommands.c b/src/backend/commands/dbcommands.c
index 96b46cbc02..16e422138b 100644
--- a/src/backend/commands/dbcommands.c
+++ b/src/backend/commands/dbcommands.c
@@ -2606,7 +2606,7 @@ get_db_info(const char *name, LOCKMODE lockmode,
 	bool		result = false;
 	Relation	relation;
 
-	AssertArg(name);
+	Assert(name);
 
 	/* Caller may wish to grab a better lock on pg_database beforehand... */
 	relation = table_open(DatabaseRelationId, AccessShareLock);
diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c
index fd56066c13..659e189549 100644
--- a/src/backend/commands/indexcmds.c
+++ b/src/backend/commands/indexcmds.c
@@ -2896,7 +2896,7 @@ ReindexMultipleTables(const char *objectName, ReindexObjectType objectKind,
 	 * This matches the options enforced by the grammar, where the object name
 	 * is optional for DATABASE and SYSTEM.
 	 */
-	AssertArg(objectName || objectKind != REINDEX_OBJECT_SCHEMA);
+	Assert(objectName || objectKind != REINDEX_OBJECT_SCHEMA);
 
 	if (objectKind == REINDEX_OBJECT_SYSTEM &&
 		(params->options & REINDEXOPT_CONCURRENTLY) != 0)
diff --git a/src/backend/commands/portalcmds.c b/src/backend/commands/portalcmds.c
index 9902c5c566..09bcfd59be 100644
--- a/src/backend/commands/portalcmds.c
+++ b/src/backend/commands/portalcmds.c
@@ -267,8 +267,8 @@ PortalCleanup(Portal portal)
 	/*
 	 * sanity checks
 	 */
-	AssertArg(PortalIsValid(portal));
-	AssertArg(portal->cleanup == PortalCleanup);
+	Assert(PortalIsValid(portal));
+	Assert(portal->cleanup == PortalCleanup);
 
 	/*
 	 * Shut down executor, if still running.  We skip this during error abort,
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 20135ef1b0..bc90185da6 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -3134,7 +3134,7 @@ StoreCatalogInheritance(Oid relationId, List *supers,
 	/*
 	 * sanity checks
 	 */
-	AssertArg(OidIsValid(relationId));
+	Assert(OidIsValid(relationId));
 
 	if (supers == NIL)
 		return;
@@ -3651,7 +3651,7 @@ rename_constraint_internal(Oid myrelid,
 	Form_pg_constraint con;
 	ObjectAddress address;
 
-	AssertArg(!myrelid || !mytypid);
+	Assert(!myrelid || !mytypid);
 
 	if (mytypid)
 	{
@@ -9731,7 +9731,7 @@ addFkRecurseReferencing(List **wqueue, Constraint *fkconstraint, Relation rel,
 	Oid			insertTriggerOid,
 				updateTriggerOid;
 
-	AssertArg(OidIsValid(parentConstr));
+	Assert(OidIsValid(parentConstr));
 
 	if (rel->rd_rel->relkind == RELKIND_FOREIGN_TABLE)
 		ereport(ERROR,
diff --git a/src/backend/jit/jit.c b/src/backend/jit/jit.c
index 18d168f1af..91a6b2b63a 100644
--- a/src/backend/jit/jit.c
+++ b/src/backend/jit/jit.c
@@ -195,7 +195,7 @@ file_exists(const char *name)
 {
 	struct stat st;
 
-	AssertArg(name != NULL);
+	Assert(name != NULL);
 
 	if (stat(name, &st) == 0)
 		return !S_ISDIR(st.st_mode);
diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c
index bd068bba05..8140e79d8f 100644
--- a/src/backend/parser/parse_utilcmd.c
+++ b/src/backend/parser/parse_utilcmd.c
@@ -1463,7 +1463,7 @@ transformOfType(CreateStmtContext *cxt, TypeName *ofTypename)
 	int			i;
 	Oid			ofTypeId;
 
-	AssertArg(ofTypename);
+	Assert(ofTypename);
 
 	tuple = typenameType(NULL, ofTypename, NULL);
 	check_of_type(tuple);
diff --git a/src/backend/postmaster/autovacuum.c b/src/backend/postmaster/autovacuum.c
index 1e90b72b74..601834d4b4 100644
--- a/src/backend/postmaster/autovacuum.c
+++ b/src/backend/postmaster/autovacuum.c
@@ -3001,8 +3001,8 @@ relation_needs_vacanalyze(Oid relid,
 	TransactionId xidForceLimit;
 	MultiXactId multiForceLimit;
 
-	AssertArg(classForm != NULL);
-	AssertArg(OidIsValid(relid));
+	Assert(classForm != NULL);
+	Assert(OidIsValid(relid));
 
 	/*
 	 * Determine vacuum/analyze equation parameters.  We have two possible
diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c
index 6dff9915a5..17a952e493 100644
--- a/src/backend/replication/logical/reorderbuffer.c
+++ b/src/backend/replication/logical/reorderbuffer.c
@@ -3070,7 +3070,7 @@ ReorderBufferSetBaseSnapshot(ReorderBuffer *rb, TransactionId xid,
 	ReorderBufferTXN *txn;
 	bool		is_new;
 
-	AssertArg(snap != NULL);
+	Assert(snap != NULL);
 
 	/*
 	 * Fetch the transaction to operate on.  If we know it's a subtransaction,
diff --git a/src/backend/replication/slot.c b/src/backend/replication/slot.c
index d58d16e992..76b262751e 100644
--- a/src/backend/replication/slot.c
+++ b/src/backend/replication/slot.c
@@ -452,7 +452,7 @@ ReplicationSlotAcquire(const char *name, bool nowait)
 	ReplicationSlot *s;
 	int			active_pid;
 
-	AssertArg(name != NULL);
+	Assert(name != NULL);
 
 retry:
 	Assert(MyReplicationSlot == NULL);
diff --git a/src/backend/storage/lmgr/lwlock.c b/src/backend/storage/lmgr/lwlock.c
index d274c9b1dc..0fc0cf6ebb 100644
--- a/src/backend/storage/lmgr/lwlock.c
+++ b/src/backend/storage/lmgr/lwlock.c
@@ -816,7 +816,7 @@ LWLockAttemptLock(LWLock *lock, LWLockMode mode)
 {
 	uint32		old_state;
 
-	AssertArg(mode == LW_EXCLUSIVE || mode == LW_SHARED);
+	Assert(mode == LW_EXCLUSIVE || mode == LW_SHARED);
 
 	/*
 	 * Read once outside the loop, later iterations will get the newer value
@@ -1204,7 +1204,7 @@ LWLockAcquire(LWLock *lock, LWLockMode mode)
 	lwstats = get_lwlock_stats_entry(lock);
 #endif
 
-	AssertArg(mode == LW_SHARED || mode == LW_EXCLUSIVE);
+	Assert(mode == LW_SHARED || mode == LW_EXCLUSIVE);
 
 	PRINT_LWDEBUG("LWLockAcquire", lock, mode);
 
@@ -1368,7 +1368,7 @@ LWLockConditionalAcquire(LWLock *lock, LWLockMode mode)
 {
 	bool		mustwait;
 
-	AssertArg(mode == LW_SHARED || mode == LW_EXCLUSIVE);
+	Assert(mode == LW_SHARED || mode == LW_EXCLUSIVE);
 
 	PRINT_LWDEBUG("LWLockConditionalAcquire", lock, mode);
 
diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c
index 27dee29f42..8476570a88 100644
--- a/src/backend/tcop/postgres.c
+++ b/src/backend/tcop/postgres.c
@@ -4050,8 +4050,8 @@ PostgresMain(const char *dbname, const char *username)
 	bool		idle_in_transaction_timeout_enabled = false;
 	bool		idle_session_timeout_enabled = false;
 
-	AssertArg(dbname != NULL);
-	AssertArg(username != NULL);
+	Assert(dbname != NULL);
+	Assert(username != NULL);
 
 	SetProcessingMode(InitProcessing);
 
diff --git a/src/backend/tcop/pquery.c b/src/backend/tcop/pquery.c
index 5aa5a350f3..52e2db6452 100644
--- a/src/backend/tcop/pquery.c
+++ b/src/backend/tcop/pquery.c
@@ -440,8 +440,8 @@ PortalStart(Portal portal, ParamListInfo params,
 	QueryDesc  *queryDesc;
 	int			myeflags;
 
-	AssertArg(PortalIsValid(portal));
-	AssertState(portal->status == PORTAL_DEFINED);
+	Assert(PortalIsValid(portal));
+	Assert(portal->status == PORTAL_DEFINED);
 
 	/*
 	 * Set up global portal context pointers.
@@ -694,7 +694,7 @@ PortalRun(Portal portal, long count, bool isTopLevel, bool run_once,
 	MemoryContext savePortalContext;
 	MemoryContext saveMemoryContext;
 
-	AssertArg(PortalIsValid(portal));
+	Assert(PortalIsValid(portal));
 
 	TRACE_POSTGRESQL_QUERY_EXECUTE_START();
 
@@ -1399,7 +1399,7 @@ PortalRunFetch(Portal portal,
 	MemoryContext savePortalContext;
 	MemoryContext oldContext;
 
-	AssertArg(PortalIsValid(portal));
+	Assert(PortalIsValid(portal));
 
 	/*
 	 * Check for improper portal use, and mark portal active.
diff --git a/src/backend/utils/activity/pgstat.c b/src/backend/utils/activity/pgstat.c
index 1b97597f17..1ebe3bbf29 100644
--- a/src/backend/utils/activity/pgstat.c
+++ b/src/backend/utils/activity/pgstat.c
@@ -785,7 +785,7 @@ pgstat_fetch_entry(PgStat_Kind kind, Oid dboid, Oid objoid)
 
 	/* should be called from backends */
 	Assert(IsUnderPostmaster || !IsPostmasterEnvironment);
-	AssertArg(!kind_info->fixed_amount);
+	Assert(!kind_info->fixed_amount);
 
 	pgstat_prep_snapshot();
 
@@ -901,8 +901,8 @@ pgstat_have_entry(PgStat_Kind kind, Oid dboid, Oid objoid)
 void
 pgstat_snapshot_fixed(PgStat_Kind kind)
 {
-	AssertArg(pgstat_is_kind_valid(kind));
-	AssertArg(pgstat_get_kind_info(kind)->fixed_amount);
+	Assert(pgstat_is_kind_valid(kind));
+	Assert(pgstat_get_kind_info(kind)->fixed_amount);
 
 	if (pgstat_fetch_consistency == PGSTAT_FETCH_CONSISTENCY_SNAPSHOT)
 		pgstat_build_snapshot();
@@ -1219,7 +1219,7 @@ pgstat_is_kind_valid(int ikind)
 const PgStat_KindInfo *
 pgstat_get_kind_info(PgStat_Kind kind)
 {
-	AssertArg(pgstat_is_kind_valid(kind));
+	Assert(pgstat_is_kind_valid(kind));
 
 	return &pgstat_kind_infos[kind];
 }
diff --git a/src/backend/utils/activity/pgstat_replslot.c b/src/backend/utils/activity/pgstat_replslot.c
index 252d2e4e07..c6fc3b48ba 100644
--- a/src/backend/utils/activity/pgstat_replslot.c
+++ b/src/backend/utils/activity/pgstat_replslot.c
@@ -44,7 +44,7 @@ pgstat_reset_replslot(const char *name)
 {
 	ReplicationSlot *slot;
 
-	AssertArg(name != NULL);
+	Assert(name != NULL);
 
 	/* Check if the slot exits with the given name. */
 	slot = SearchNamedReplicationSlot(name, true);
@@ -213,7 +213,7 @@ get_replslot_index(const char *name)
 {
 	ReplicationSlot *slot;
 
-	AssertArg(name != NULL);
+	Assert(name != NULL);
 
 	slot = SearchNamedReplicationSlot(name, true);
 
diff --git a/src/backend/utils/activity/pgstat_shmem.c b/src/backend/utils/activity/pgstat_shmem.c
index 9a4f037959..706692862c 100644
--- a/src/backend/utils/activity/pgstat_shmem.c
+++ b/src/backend/utils/activity/pgstat_shmem.c
@@ -402,7 +402,7 @@ pgstat_get_entry_ref(PgStat_Kind kind, Oid dboid, Oid objoid, bool create,
 	 * passing in created_entry only makes sense if we possibly could create
 	 * entry.
 	 */
-	AssertArg(create || created_entry == NULL);
+	Assert(create || created_entry == NULL);
 	pgstat_assert_is_up();
 	Assert(pgStatLocal.shared_hash != NULL);
 	Assert(!pgStatLocal.shmem->is_shutdown);
diff --git a/src/backend/utils/activity/pgstat_slru.c b/src/backend/utils/activity/pgstat_slru.c
index 28ef736735..20dd1e6f66 100644
--- a/src/backend/utils/activity/pgstat_slru.c
+++ b/src/backend/utils/activity/pgstat_slru.c
@@ -46,7 +46,7 @@ pgstat_reset_slru(const char *name)
 {
 	TimestampTz ts = GetCurrentTimestamp();
 
-	AssertArg(name != NULL);
+	Assert(name != NULL);
 
 	pgstat_reset_slru_counter_internal(pgstat_get_slru_index(name), ts);
 }
diff --git a/src/backend/utils/adt/mcxtfuncs.c b/src/backend/utils/adt/mcxtfuncs.c
index bb7cc94024..ba499dbde6 100644
--- a/src/backend/utils/adt/mcxtfuncs.c
+++ b/src/backend/utils/adt/mcxtfuncs.c
@@ -46,7 +46,7 @@ PutMemoryContextsStatsTupleStore(Tuplestorestate *tupstore,
 	const char *name;
 	const char *ident;
 
-	AssertArg(MemoryContextIsValid(context));
+	Assert(MemoryContextIsValid(context));
 
 	name = context->name;
 	ident = context->ident;
diff --git a/src/backend/utils/adt/xml.c b/src/backend/utils/adt/xml.c
index d32cb11436..e4f2adb1f9 100644
--- a/src/backend/utils/adt/xml.c
+++ b/src/backend/utils/adt/xml.c
@@ -4500,7 +4500,7 @@ XmlTableSetColumnFilter(TableFuncScanState *state, const char *path, int colnum)
 	XmlTableBuilderData *xtCxt;
 	xmlChar    *xstr;
 
-	AssertArg(PointerIsValid(path));
+	Assert(PointerIsValid(path));
 
 	xtCxt = GetXmlTableBuilderPrivateData(state, "XmlTableSetColumnFilter");
 
diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c
index 00dc0f2403..bd6cd4e47b 100644
--- a/src/backend/utils/cache/relcache.c
+++ b/src/backend/utils/cache/relcache.c
@@ -3474,7 +3474,7 @@ RelationBuildLocalRelation(const char *relname,
 	bool		has_not_null;
 	bool		nailit;
 
-	AssertArg(natts >= 0);
+	Assert(natts >= 0);
 
 	/*
 	 * check for creation of a rel that must be nailed in cache.
diff --git a/src/backend/utils/fmgr/dfmgr.c b/src/backend/utils/fmgr/dfmgr.c
index 6ae6fc1556..e4d513c4e4 100644
--- a/src/backend/utils/fmgr/dfmgr.c
+++ b/src/backend/utils/fmgr/dfmgr.c
@@ -405,7 +405,7 @@ file_exists(const char *name)
 {
 	struct stat st;
 
-	AssertArg(name != NULL);
+	Assert(name != NULL);
 
 	if (stat(name, &st) == 0)
 		return !S_ISDIR(st.st_mode);
@@ -434,7 +434,7 @@ expand_dynamic_library_name(const char *name)
 	char	   *new;
 	char	   *full;
 
-	AssertArg(name);
+	Assert(name);
 
 	have_slash = (first_dir_separator(name) != NULL);
 
@@ -502,7 +502,7 @@ substitute_libpath_macro(const char *name)
 {
 	const char *sep_ptr;
 
-	AssertArg(name != NULL);
+	Assert(name != NULL);
 
 	/* Currently, we only recognize $libdir at the start of the string */
 	if (name[0] != '$')
@@ -534,9 +534,9 @@ find_in_dynamic_libpath(const char *basename)
 	const char *p;
 	size_t		baselen;
 
-	AssertArg(basename != NULL);
-	AssertArg(first_dir_separator(basename) == NULL);
-	AssertState(Dynamic_library_path != NULL);
+	Assert(basename != NULL);
+	Assert(first_dir_separator(basename) == NULL);
+	Assert(Dynamic_library_path != NULL);
 
 	p = Dynamic_library_path;
 	if (strlen(p) == 0)
diff --git a/src/backend/utils/init/miscinit.c b/src/backend/utils/init/miscinit.c
index dfdcd3d78e..eb1046450b 100644
--- a/src/backend/utils/init/miscinit.c
+++ b/src/backend/utils/init/miscinit.c
@@ -417,7 +417,7 @@ SetDataDir(const char *dir)
 {
 	char	   *new;
 
-	AssertArg(dir);
+	Assert(dir);
 
 	/* If presented path is relative, convert to absolute */
 	new = make_absolute_path(dir);
@@ -435,7 +435,7 @@ SetDataDir(const char *dir)
 void
 ChangeToDataDir(void)
 {
-	AssertState(DataDir);
+	Assert(DataDir);
 
 	if (chdir(DataDir) < 0)
 		ereport(FATAL,
@@ -496,7 +496,7 @@ static bool SetRoleIsActive = false;
 Oid
 GetUserId(void)
 {
-	AssertState(OidIsValid(CurrentUserId));
+	Assert(OidIsValid(CurrentUserId));
 	return CurrentUserId;
 }
 
@@ -507,7 +507,7 @@ GetUserId(void)
 Oid
 GetOuterUserId(void)
 {
-	AssertState(OidIsValid(OuterUserId));
+	Assert(OidIsValid(OuterUserId));
 	return OuterUserId;
 }
 
@@ -515,8 +515,8 @@ GetOuterUserId(void)
 static void
 SetOuterUserId(Oid userid)
 {
-	AssertState(SecurityRestrictionContext == 0);
-	AssertArg(OidIsValid(userid));
+	Assert(SecurityRestrictionContext == 0);
+	Assert(OidIsValid(userid));
 	OuterUserId = userid;
 
 	/* We force the effective user ID to match, too */
@@ -530,7 +530,7 @@ SetOuterUserId(Oid userid)
 Oid
 GetSessionUserId(void)
 {
-	AssertState(OidIsValid(SessionUserId));
+	Assert(OidIsValid(SessionUserId));
 	return SessionUserId;
 }
 
@@ -538,8 +538,8 @@ GetSessionUserId(void)
 static void
 SetSessionUserId(Oid userid, bool is_superuser)
 {
-	AssertState(SecurityRestrictionContext == 0);
-	AssertArg(OidIsValid(userid));
+	Assert(SecurityRestrictionContext == 0);
+	Assert(OidIsValid(userid));
 	SessionUserId = userid;
 	SessionUserIsSuperuser = is_superuser;
 	SetRoleIsActive = false;
@@ -565,7 +565,7 @@ GetSystemUser(void)
 Oid
 GetAuthenticatedUserId(void)
 {
-	AssertState(OidIsValid(AuthenticatedUserId));
+	Assert(OidIsValid(AuthenticatedUserId));
 	return AuthenticatedUserId;
 }
 
@@ -719,10 +719,10 @@ InitializeSessionUserId(const char *rolename, Oid roleid)
 	 * Don't do scans if we're bootstrapping, none of the system catalogs
 	 * exist yet, and they should be owned by postgres anyway.
 	 */
-	AssertState(!IsBootstrapProcessingMode());
+	Assert(!IsBootstrapProcessingMode());
 
 	/* call only once */
-	AssertState(!OidIsValid(AuthenticatedUserId));
+	Assert(!OidIsValid(AuthenticatedUserId));
 
 	/*
 	 * Make sure syscache entries are flushed for recent catalog changes. This
@@ -818,10 +818,10 @@ InitializeSessionUserIdStandalone(void)
 	 * This function should only be called in single-user mode, in autovacuum
 	 * workers, and in background workers.
 	 */
-	AssertState(!IsUnderPostmaster || IsAutoVacuumWorkerProcess() || IsBackgroundWorker);
+	Assert(!IsUnderPostmaster || IsAutoVacuumWorkerProcess() || IsBackgroundWorker);
 
 	/* call only once */
-	AssertState(!OidIsValid(AuthenticatedUserId));
+	Assert(!OidIsValid(AuthenticatedUserId));
 
 	AuthenticatedUserId = BOOTSTRAP_SUPERUSERID;
 	AuthenticatedUserIsSuperuser = true;
@@ -886,7 +886,7 @@ void
 SetSessionAuthorization(Oid userid, bool is_superuser)
 {
 	/* Must have authenticated already, else can't make permission check */
-	AssertState(OidIsValid(AuthenticatedUserId));
+	Assert(OidIsValid(AuthenticatedUserId));
 
 	if (userid != AuthenticatedUserId &&
 		!AuthenticatedUserIsSuperuser)
diff --git a/src/backend/utils/misc/guc-file.l b/src/backend/utils/misc/guc-file.l
index 721628c0cf..2436396306 100644
--- a/src/backend/utils/misc/guc-file.l
+++ b/src/backend/utils/misc/guc-file.l
@@ -179,7 +179,7 @@ AbsoluteConfigLocation(const char *location, const char *calling_file)
 		}
 		else
 		{
-			AssertState(DataDir);
+			Assert(DataDir);
 			join_path_components(abs_path, DataDir, location);
 			canonicalize_path(abs_path);
 		}
diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c
index f997ec0f82..57482cf103 100644
--- a/src/backend/utils/misc/guc.c
+++ b/src/backend/utils/misc/guc.c
@@ -5848,9 +5848,9 @@ ParseLongOption(const char *string, char **name, char **value)
 	size_t		equal_pos;
 	char	   *cp;
 
-	AssertArg(string);
-	AssertArg(name);
-	AssertArg(value);
+	Assert(string);
+	Assert(name);
+	Assert(value);
 
 	equal_pos = strcspn(string, "=");
 
diff --git a/src/backend/utils/mmgr/aset.c b/src/backend/utils/mmgr/aset.c
index db402e3a41..b6a8bbcd59 100644
--- a/src/backend/utils/mmgr/aset.c
+++ b/src/backend/utils/mmgr/aset.c
@@ -544,7 +544,7 @@ AllocSetReset(MemoryContext context)
 	AllocBlock	block;
 	Size		keepersize PG_USED_FOR_ASSERTS_ONLY;
 
-	AssertArg(AllocSetIsValid(set));
+	Assert(AllocSetIsValid(set));
 
 #ifdef MEMORY_CONTEXT_CHECKING
 	/* Check for corruption and leaks before freeing */
@@ -614,7 +614,7 @@ AllocSetDelete(MemoryContext context)
 	AllocBlock	block = set->blocks;
 	Size		keepersize PG_USED_FOR_ASSERTS_ONLY;
 
-	AssertArg(AllocSetIsValid(set));
+	Assert(AllocSetIsValid(set));
 
 #ifdef MEMORY_CONTEXT_CHECKING
 	/* Check for corruption and leaks before freeing */
@@ -713,7 +713,7 @@ AllocSetAlloc(MemoryContext context, Size size)
 	Size		chunk_size;
 	Size		blksize;
 
-	AssertArg(AllocSetIsValid(set));
+	Assert(AllocSetIsValid(set));
 
 	/*
 	 * If requested size exceeds maximum for chunks, allocate an entire block
@@ -1061,7 +1061,7 @@ AllocSetFree(void *pointer)
 		 * Future field experience may show that these Asserts had better
 		 * become regular runtime test-and-elog checks.
 		 */
-		AssertArg(AllocBlockIsValid(block));
+		Assert(AllocBlockIsValid(block));
 		set = block->aset;
 
 		fidx = MemoryChunkGetValue(chunk);
@@ -1237,7 +1237,7 @@ AllocSetRealloc(void *pointer, Size size)
 	 * field experience may show that these Asserts had better become regular
 	 * runtime test-and-elog checks.
 	 */
-	AssertArg(AllocBlockIsValid(block));
+	Assert(AllocBlockIsValid(block));
 	set = block->aset;
 
 	fidx = MemoryChunkGetValue(chunk);
@@ -1368,7 +1368,7 @@ AllocSetGetChunkContext(void *pointer)
 	else
 		block = (AllocBlock) MemoryChunkGetBlock(chunk);
 
-	AssertArg(AllocBlockIsValid(block));
+	Assert(AllocBlockIsValid(block));
 	set = block->aset;
 
 	return &set->header;
@@ -1389,7 +1389,7 @@ AllocSetGetChunkSpace(void *pointer)
 	{
 		AllocBlock	block = ExternalChunkGetBlock(chunk);
 
-		AssertArg(AllocBlockIsValid(block));
+		Assert(AllocBlockIsValid(block));
 		return block->endptr - (char *) chunk;
 	}
 
@@ -1405,7 +1405,7 @@ AllocSetGetChunkSpace(void *pointer)
 bool
 AllocSetIsEmpty(MemoryContext context)
 {
-	AssertArg(AllocSetIsValid(context));
+	Assert(AllocSetIsValid(context));
 
 	/*
 	 * For now, we say "empty" only if the context is new or just reset. We
@@ -1440,7 +1440,7 @@ AllocSetStats(MemoryContext context,
 	AllocBlock	block;
 	int			fidx;
 
-	AssertArg(AllocSetIsValid(set));
+	Assert(AllocSetIsValid(set));
 
 	/* Include context header in totalspace */
 	totalspace = MAXALIGN(sizeof(AllocSetContext));
diff --git a/src/backend/utils/mmgr/generation.c b/src/backend/utils/mmgr/generation.c
index 4cb75f493f..b432a92be3 100644
--- a/src/backend/utils/mmgr/generation.c
+++ b/src/backend/utils/mmgr/generation.c
@@ -284,7 +284,7 @@ GenerationReset(MemoryContext context)
 	GenerationContext *set = (GenerationContext *) context;
 	dlist_mutable_iter miter;
 
-	AssertArg(GenerationIsValid(set));
+	Assert(GenerationIsValid(set));
 
 #ifdef MEMORY_CONTEXT_CHECKING
 	/* Check for corruption and leaks before freeing */
@@ -354,7 +354,7 @@ GenerationAlloc(MemoryContext context, Size size)
 	Size		chunk_size;
 	Size		required_size;
 
-	AssertArg(GenerationIsValid(set));
+	Assert(GenerationIsValid(set));
 
 #ifdef MEMORY_CONTEXT_CHECKING
 	/* ensure there's always space for the sentinel byte */
@@ -657,7 +657,7 @@ GenerationFree(void *pointer)
 		 * block is good.  Future field experience may show that this Assert
 		 * had better become a regular runtime test-and-elog check.
 		 */
-		AssertArg(GenerationBlockIsValid(block));
+		Assert(GenerationBlockIsValid(block));
 
 #if defined(MEMORY_CONTEXT_CHECKING) || defined(CLOBBER_FREED_MEMORY)
 		chunksize = MemoryChunkGetValue(chunk);
@@ -769,7 +769,7 @@ GenerationRealloc(void *pointer, Size size)
 		 * block is good.  Future field experience may show that this Assert
 		 * had better become a regular runtime test-and-elog check.
 		 */
-		AssertArg(GenerationBlockIsValid(block));
+		Assert(GenerationBlockIsValid(block));
 
 		oldsize = MemoryChunkGetValue(chunk);
 	}
@@ -888,7 +888,7 @@ GenerationGetChunkContext(void *pointer)
 	else
 		block = (GenerationBlock *) MemoryChunkGetBlock(chunk);
 
-	AssertArg(GenerationBlockIsValid(block));
+	Assert(GenerationBlockIsValid(block));
 	return &block->context->header;
 }
 
@@ -907,7 +907,7 @@ GenerationGetChunkSpace(void *pointer)
 	{
 		GenerationBlock *block = ExternalChunkGetBlock(chunk);
 
-		AssertArg(GenerationBlockIsValid(block));
+		Assert(GenerationBlockIsValid(block));
 		chunksize = block->endptr - (char *) pointer;
 	}
 	else
@@ -926,7 +926,7 @@ GenerationIsEmpty(MemoryContext context)
 	GenerationContext *set = (GenerationContext *) context;
 	dlist_iter	iter;
 
-	AssertArg(GenerationIsValid(set));
+	Assert(GenerationIsValid(set));
 
 	dlist_foreach(iter, &set->blocks)
 	{
@@ -964,7 +964,7 @@ GenerationStats(MemoryContext context,
 	Size		freespace = 0;
 	dlist_iter	iter;
 
-	AssertArg(GenerationIsValid(set));
+	Assert(GenerationIsValid(set));
 
 	/* Include context header in totalspace */
 	totalspace = MAXALIGN(sizeof(GenerationContext));
diff --git a/src/backend/utils/mmgr/mcxt.c b/src/backend/utils/mmgr/mcxt.c
index b1a3c74830..56d9f9dc44 100644
--- a/src/backend/utils/mmgr/mcxt.c
+++ b/src/backend/utils/mmgr/mcxt.c
@@ -258,7 +258,7 @@ BogusGetChunkSpace(void *pointer)
 void
 MemoryContextInit(void)
 {
-	AssertState(TopMemoryContext == NULL);
+	Assert(TopMemoryContext == NULL);
 
 	/*
 	 * First, initialize TopMemoryContext, which is the parent of all others.
@@ -302,7 +302,7 @@ MemoryContextInit(void)
 void
 MemoryContextReset(MemoryContext context)
 {
-	AssertArg(MemoryContextIsValid(context));
+	Assert(MemoryContextIsValid(context));
 
 	/* save a function call in common case where there are no children */
 	if (context->firstchild != NULL)
@@ -321,7 +321,7 @@ MemoryContextReset(MemoryContext context)
 void
 MemoryContextResetOnly(MemoryContext context)
 {
-	AssertArg(MemoryContextIsValid(context));
+	Assert(MemoryContextIsValid(context));
 
 	/* Nothing to do if no pallocs since startup or last reset */
 	if (!context->isReset)
@@ -354,7 +354,7 @@ MemoryContextResetChildren(MemoryContext context)
 {
 	MemoryContext child;
 
-	AssertArg(MemoryContextIsValid(context));
+	Assert(MemoryContextIsValid(context));
 
 	for (child = context->firstchild; child != NULL; child = child->nextchild)
 	{
@@ -375,7 +375,7 @@ MemoryContextResetChildren(MemoryContext context)
 void
 MemoryContextDelete(MemoryContext context)
 {
-	AssertArg(MemoryContextIsValid(context));
+	Assert(MemoryContextIsValid(context));
 	/* We had better not be deleting TopMemoryContext ... */
 	Assert(context != TopMemoryContext);
 	/* And not CurrentMemoryContext, either */
@@ -420,7 +420,7 @@ MemoryContextDelete(MemoryContext context)
 void
 MemoryContextDeleteChildren(MemoryContext context)
 {
-	AssertArg(MemoryContextIsValid(context));
+	Assert(MemoryContextIsValid(context));
 
 	/*
 	 * MemoryContextDelete will delink the child from me, so just iterate as
@@ -450,7 +450,7 @@ void
 MemoryContextRegisterResetCallback(MemoryContext context,
 								   MemoryContextCallback *cb)
 {
-	AssertArg(MemoryContextIsValid(context));
+	Assert(MemoryContextIsValid(context));
 
 	/* Push onto head so this will be called before older registrants. */
 	cb->next = context->reset_cbs;
@@ -493,7 +493,7 @@ MemoryContextCallResetCallbacks(MemoryContext context)
 void
 MemoryContextSetIdentifier(MemoryContext context, const char *id)
 {
-	AssertArg(MemoryContextIsValid(context));
+	Assert(MemoryContextIsValid(context));
 	context->ident = id;
 }
 
@@ -518,8 +518,8 @@ MemoryContextSetIdentifier(MemoryContext context, const char *id)
 void
 MemoryContextSetParent(MemoryContext context, MemoryContext new_parent)
 {
-	AssertArg(MemoryContextIsValid(context));
-	AssertArg(context != new_parent);
+	Assert(MemoryContextIsValid(context));
+	Assert(context != new_parent);
 
 	/* Fast path if it's got correct parent already */
 	if (new_parent == context->parent)
@@ -545,7 +545,7 @@ MemoryContextSetParent(MemoryContext context, MemoryContext new_parent)
 	/* And relink */
 	if (new_parent)
 	{
-		AssertArg(MemoryContextIsValid(new_parent));
+		Assert(MemoryContextIsValid(new_parent));
 		context->parent = new_parent;
 		context->prevchild = NULL;
 		context->nextchild = new_parent->firstchild;
@@ -575,7 +575,7 @@ MemoryContextSetParent(MemoryContext context, MemoryContext new_parent)
 void
 MemoryContextAllowInCriticalSection(MemoryContext context, bool allow)
 {
-	AssertArg(MemoryContextIsValid(context));
+	Assert(MemoryContextIsValid(context));
 
 	context->allowInCritSection = allow;
 }
@@ -612,7 +612,7 @@ GetMemoryChunkSpace(void *pointer)
 MemoryContext
 MemoryContextGetParent(MemoryContext context)
 {
-	AssertArg(MemoryContextIsValid(context));
+	Assert(MemoryContextIsValid(context));
 
 	return context->parent;
 }
@@ -624,7 +624,7 @@ MemoryContextGetParent(MemoryContext context)
 bool
 MemoryContextIsEmpty(MemoryContext context)
 {
-	AssertArg(MemoryContextIsValid(context));
+	Assert(MemoryContextIsValid(context));
 
 	/*
 	 * For now, we consider a memory context nonempty if it has any children;
@@ -645,7 +645,7 @@ MemoryContextMemAllocated(MemoryContext context, bool recurse)
 {
 	Size		total = context->mem_allocated;
 
-	AssertArg(MemoryContextIsValid(context));
+	Assert(MemoryContextIsValid(context));
 
 	if (recurse)
 	{
@@ -737,7 +737,7 @@ MemoryContextStatsInternal(MemoryContext context, int level,
 	MemoryContext child;
 	int			ichild;
 
-	AssertArg(MemoryContextIsValid(context));
+	Assert(MemoryContextIsValid(context));
 
 	/* Examine the context itself */
 	context->methods->stats(context,
@@ -902,7 +902,7 @@ MemoryContextCheck(MemoryContext context)
 {
 	MemoryContext child;
 
-	AssertArg(MemoryContextIsValid(context));
+	Assert(MemoryContextIsValid(context));
 
 	context->methods->check(context);
 	for (child = context->firstchild; child != NULL; child = child->nextchild)
@@ -995,7 +995,7 @@ MemoryContextAlloc(MemoryContext context, Size size)
 {
 	void	   *ret;
 
-	AssertArg(MemoryContextIsValid(context));
+	Assert(MemoryContextIsValid(context));
 	AssertNotInCriticalSection(context);
 
 	if (!AllocSizeIsValid(size))
@@ -1038,7 +1038,7 @@ MemoryContextAllocZero(MemoryContext context, Size size)
 {
 	void	   *ret;
 
-	AssertArg(MemoryContextIsValid(context));
+	Assert(MemoryContextIsValid(context));
 	AssertNotInCriticalSection(context);
 
 	if (!AllocSizeIsValid(size))
@@ -1076,7 +1076,7 @@ MemoryContextAllocZeroAligned(MemoryContext context, Size size)
 {
 	void	   *ret;
 
-	AssertArg(MemoryContextIsValid(context));
+	Assert(MemoryContextIsValid(context));
 	AssertNotInCriticalSection(context);
 
 	if (!AllocSizeIsValid(size))
@@ -1111,7 +1111,7 @@ MemoryContextAllocExtended(MemoryContext context, Size size, int flags)
 {
 	void	   *ret;
 
-	AssertArg(MemoryContextIsValid(context));
+	Assert(MemoryContextIsValid(context));
 	AssertNotInCriticalSection(context);
 
 	if (((flags & MCXT_ALLOC_HUGE) != 0 && !AllocHugeSizeIsValid(size)) ||
@@ -1202,7 +1202,7 @@ palloc(Size size)
 	void	   *ret;
 	MemoryContext context = CurrentMemoryContext;
 
-	AssertArg(MemoryContextIsValid(context));
+	Assert(MemoryContextIsValid(context));
 	AssertNotInCriticalSection(context);
 
 	if (!AllocSizeIsValid(size))
@@ -1233,7 +1233,7 @@ palloc0(Size size)
 	void	   *ret;
 	MemoryContext context = CurrentMemoryContext;
 
-	AssertArg(MemoryContextIsValid(context));
+	Assert(MemoryContextIsValid(context));
 	AssertNotInCriticalSection(context);
 
 	if (!AllocSizeIsValid(size))
@@ -1266,7 +1266,7 @@ palloc_extended(Size size, int flags)
 	void	   *ret;
 	MemoryContext context = CurrentMemoryContext;
 
-	AssertArg(MemoryContextIsValid(context));
+	Assert(MemoryContextIsValid(context));
 	AssertNotInCriticalSection(context);
 
 	if (((flags & MCXT_ALLOC_HUGE) != 0 && !AllocHugeSizeIsValid(size)) ||
@@ -1362,7 +1362,7 @@ MemoryContextAllocHuge(MemoryContext context, Size size)
 {
 	void	   *ret;
 
-	AssertArg(MemoryContextIsValid(context));
+	Assert(MemoryContextIsValid(context));
 	AssertNotInCriticalSection(context);
 
 	if (!AllocHugeSizeIsValid(size))
diff --git a/src/backend/utils/mmgr/portalmem.c b/src/backend/utils/mmgr/portalmem.c
index 3a161bdb88..2ef2550491 100644
--- a/src/backend/utils/mmgr/portalmem.c
+++ b/src/backend/utils/mmgr/portalmem.c
@@ -177,7 +177,7 @@ CreatePortal(const char *name, bool allowDup, bool dupSilent)
 {
 	Portal		portal;
 
-	AssertArg(PointerIsValid(name));
+	Assert(PointerIsValid(name));
 
 	portal = GetPortalByName(name);
 	if (PortalIsValid(portal))
@@ -287,11 +287,11 @@ PortalDefineQuery(Portal portal,
 				  List *stmts,
 				  CachedPlan *cplan)
 {
-	AssertArg(PortalIsValid(portal));
-	AssertState(portal->status == PORTAL_NEW);
+	Assert(PortalIsValid(portal));
+	Assert(portal->status == PORTAL_NEW);
 
-	AssertArg(sourceText != NULL);
-	AssertArg(commandTag != CMDTAG_UNKNOWN || stmts == NIL);
+	Assert(sourceText != NULL);
+	Assert(commandTag != CMDTAG_UNKNOWN || stmts == NIL);
 
 	portal->prepStmtName = prepStmtName;
 	portal->sourceText = sourceText;
@@ -468,7 +468,7 @@ MarkPortalFailed(Portal portal)
 void
 PortalDrop(Portal portal, bool isTopCommit)
 {
-	AssertArg(PortalIsValid(portal));
+	Assert(PortalIsValid(portal));
 
 	/*
 	 * Don't allow dropping a pinned portal, it's still needed by whoever
diff --git a/src/backend/utils/mmgr/slab.c b/src/backend/utils/mmgr/slab.c
index 1a0b28f9ea..6df0839b6a 100644
--- a/src/backend/utils/mmgr/slab.c
+++ b/src/backend/utils/mmgr/slab.c
@@ -254,7 +254,7 @@ SlabReset(MemoryContext context)
 	SlabContext *slab = (SlabContext *) context;
 	int			i;
 
-	AssertArg(SlabIsValid(slab));
+	Assert(SlabIsValid(slab));
 
 #ifdef MEMORY_CONTEXT_CHECKING
 	/* Check for corruption and leaks before freeing */
@@ -313,7 +313,7 @@ SlabAlloc(MemoryContext context, Size size)
 	MemoryChunk *chunk;
 	int			idx;
 
-	AssertArg(SlabIsValid(slab));
+	Assert(SlabIsValid(slab));
 
 	Assert((slab->minFreeChunks >= 0) &&
 		   (slab->minFreeChunks < slab->chunksPerBlock));
@@ -475,7 +475,7 @@ SlabFree(void *pointer)
 	 * Future field experience may show that this Assert had better become a
 	 * regular runtime test-and-elog check.
 	 */
-	AssertArg(SlabBlockIsValid(block));
+	Assert(SlabBlockIsValid(block));
 	slab = block->slab;
 
 #ifdef MEMORY_CONTEXT_CHECKING
@@ -593,7 +593,7 @@ SlabGetChunkContext(void *pointer)
 	MemoryChunk *chunk = PointerGetMemoryChunk(pointer);
 	SlabBlock  *block = MemoryChunkGetBlock(chunk);
 
-	AssertArg(SlabBlockIsValid(block));
+	Assert(SlabBlockIsValid(block));
 	return &block->slab->header;
 }
 
@@ -609,7 +609,7 @@ SlabGetChunkSpace(void *pointer)
 	SlabBlock  *block = MemoryChunkGetBlock(chunk);
 	SlabContext *slab;
 
-	AssertArg(SlabBlockIsValid(block));
+	Assert(SlabBlockIsValid(block));
 	slab = block->slab;
 
 	return slab->fullChunkSize;
@@ -624,7 +624,7 @@ SlabIsEmpty(MemoryContext context)
 {
 	SlabContext *slab = (SlabContext *) context;
 
-	AssertArg(SlabIsValid(slab));
+	Assert(SlabIsValid(slab));
 
 	return (slab->nblocks == 0);
 }
@@ -651,7 +651,7 @@ SlabStats(MemoryContext context,
 	Size		freespace = 0;
 	int			i;
 
-	AssertArg(SlabIsValid(slab));
+	Assert(SlabIsValid(slab));
 
 	/* Include context header in totalspace */
 	totalspace = slab->headerSize;
@@ -709,7 +709,7 @@ SlabCheck(MemoryContext context)
 	int			i;
 	const char *name = slab->header.name;
 
-	AssertArg(SlabIsValid(slab));
+	Assert(SlabIsValid(slab));
 	Assert(slab->chunksPerBlock > 0);
 
 	/* walk all the freelists */
diff --git a/src/backend/utils/sort/tuplesortvariants.c b/src/backend/utils/sort/tuplesortvariants.c
index afa5bdbf04..b335da3b00 100644
--- a/src/backend/utils/sort/tuplesortvariants.c
+++ b/src/backend/utils/sort/tuplesortvariants.c
@@ -145,7 +145,7 @@ tuplesort_begin_heap(TupleDesc tupDesc,
 
 	oldcontext = MemoryContextSwitchTo(base->maincontext);
 
-	AssertArg(nkeys > 0);
+	Assert(nkeys > 0);
 
 #ifdef TRACE_SORT
 	if (trace_sort)
@@ -177,8 +177,8 @@ tuplesort_begin_heap(TupleDesc tupDesc,
 	{
 		SortSupport sortKey = base->sortKeys + i;
 
-		AssertArg(attNums[i] != 0);
-		AssertArg(sortOperators[i] != 0);
+		Assert(attNums[i] != 0);
+		Assert(sortOperators[i] != 0);
 
 		sortKey->ssup_cxt = CurrentMemoryContext;
 		sortKey->ssup_collation = sortCollations[i];
@@ -297,7 +297,7 @@ tuplesort_begin_cluster(TupleDesc tupDesc,
 		/* Convey if abbreviation optimization is applicable in principle */
 		sortKey->abbreviate = (i == 0 && base->haveDatum1);
 
-		AssertState(sortKey->ssup_attno != 0);
+		Assert(sortKey->ssup_attno != 0);
 
 		strategy = (scanKey->sk_flags & SK_BT_DESC) != 0 ?
 			BTGreaterStrategyNumber : BTLessStrategyNumber;
@@ -381,7 +381,7 @@ tuplesort_begin_index_btree(Relation heapRel,
 		/* Convey if abbreviation optimization is applicable in principle */
 		sortKey->abbreviate = (i == 0 && base->haveDatum1);
 
-		AssertState(sortKey->ssup_attno != 0);
+		Assert(sortKey->ssup_attno != 0);
 
 		strategy = (scanKey->sk_flags & SK_BT_DESC) != 0 ?
 			BTGreaterStrategyNumber : BTLessStrategyNumber;
@@ -501,7 +501,7 @@ tuplesort_begin_index_gist(Relation heapRel,
 		/* Convey if abbreviation optimization is applicable in principle */
 		sortKey->abbreviate = (i == 0 && base->haveDatum1);
 
-		AssertState(sortKey->ssup_attno != 0);
+		Assert(sortKey->ssup_attno != 0);
 
 		/* Look for a sort support function */
 		PrepareSortSupportFromGistIndexRel(indexRel, sortKey);
diff --git a/src/common/controldata_utils.c b/src/common/controldata_utils.c
index 66168543a6..2d1f35bbd1 100644
--- a/src/common/controldata_utils.c
+++ b/src/common/controldata_utils.c
@@ -57,7 +57,7 @@ get_controlfile(const char *DataDir, bool *crc_ok_p)
 	pg_crc32c	crc;
 	int			r;
 
-	AssertArg(crc_ok_p);
+	Assert(crc_ok_p);
 
 	ControlFile = palloc_object(ControlFileData);
 	snprintf(ControlFilePath, MAXPGPATH, "%s/global/pg_control", DataDir);
diff --git a/src/common/protocol_openssl.c b/src/common/protocol_openssl.c
index 8d1da8be38..d8bae488a8 100644
--- a/src/common/protocol_openssl.c
+++ b/src/common/protocol_openssl.c
@@ -81,7 +81,7 @@ SSL_CTX_set_max_proto_version(SSL_CTX *ctx, int version)
 {
 	int			ssl_options = 0;
 
-	AssertArg(version != 0);
+	Assert(version != 0);
 
 	/*
 	 * Some OpenSSL versions define TLS*_VERSION macros but not the
diff --git a/src/include/c.h b/src/include/c.h
index e5510e278d..d70ed84ac5 100644
--- a/src/include/c.h
+++ b/src/include/c.h
@@ -793,8 +793,6 @@ typedef NameData *Name;
 
 #define Assert(condition)	((void)true)
 #define AssertMacro(condition)	((void)true)
-#define AssertArg(condition)	((void)true)
-#define AssertState(condition)	((void)true)
 #define AssertPointerAlignment(ptr, bndr)	((void)true)
 
 #elif defined(FRONTEND)
@@ -802,8 +800,6 @@ typedef NameData *Name;
 #include <assert.h>
 #define Assert(p) assert(p)
 #define AssertMacro(p)	((void) assert(p))
-#define AssertArg(condition) assert(condition)
-#define AssertState(condition) assert(condition)
 #define AssertPointerAlignment(ptr, bndr)	((void)true)
 
 #else							/* USE_ASSERT_CHECKING && !FRONTEND */
@@ -828,14 +824,6 @@ typedef NameData *Name;
 	((void) ((condition) || \
 			 (ExceptionalCondition(#condition, __FILE__, __LINE__), 0)))
 
-/*
- * AssertArg and AssertState are identical to Assert.  Some places use them
- * to indicate that the complaint is specifically about a bad argument or
- * unexpected state, but this usage is largely obsolescent.
- */
-#define AssertArg(condition) Assert(condition)
-#define AssertState(condition) Assert(condition)
-
 /*
  * Check that `ptr' is `bndr' aligned.
  */
diff --git a/src/include/executor/tuptable.h b/src/include/executor/tuptable.h
index a001e448ba..f12922663e 100644
--- a/src/include/executor/tuptable.h
+++ b/src/include/executor/tuptable.h
@@ -374,7 +374,7 @@ slot_getallattrs(TupleTableSlot *slot)
 static inline bool
 slot_attisnull(TupleTableSlot *slot, int attnum)
 {
-	AssertArg(attnum > 0);
+	Assert(attnum > 0);
 
 	if (attnum > slot->tts_nvalid)
 		slot_getsomeattrs(slot, attnum);
@@ -389,7 +389,7 @@ static inline Datum
 slot_getattr(TupleTableSlot *slot, int attnum,
 			 bool *isnull)
 {
-	AssertArg(attnum > 0);
+	Assert(attnum > 0);
 
 	if (attnum > slot->tts_nvalid)
 		slot_getsomeattrs(slot, attnum);
@@ -409,7 +409,7 @@ slot_getattr(TupleTableSlot *slot, int attnum,
 static inline Datum
 slot_getsysattr(TupleTableSlot *slot, int attnum, bool *isnull)
 {
-	AssertArg(attnum < 0);		/* caller error */
+	Assert(attnum < 0);		/* caller error */
 
 	if (attnum == TableOidAttributeNumber)
 	{
@@ -483,7 +483,7 @@ static inline TupleTableSlot *
 ExecCopySlot(TupleTableSlot *dstslot, TupleTableSlot *srcslot)
 {
 	Assert(!TTS_EMPTY(srcslot));
-	AssertArg(srcslot != dstslot);
+	Assert(srcslot != dstslot);
 
 	dstslot->tts_ops->copyslot(dstslot, srcslot);
 
diff --git a/src/include/miscadmin.h b/src/include/miscadmin.h
index e7ebea4ff4..795182fa51 100644
--- a/src/include/miscadmin.h
+++ b/src/include/miscadmin.h
@@ -407,7 +407,7 @@ extern PGDLLIMPORT ProcessingMode Mode;
 
 #define SetProcessingMode(mode) \
 	do { \
-		AssertArg((mode) == BootstrapProcessing || \
+		Assert((mode) == BootstrapProcessing || \
 				  (mode) == InitProcessing || \
 				  (mode) == NormalProcessing); \
 		Mode = (mode); \
diff --git a/src/include/utils/pgstat_internal.h b/src/include/utils/pgstat_internal.h
index 627c1389e4..c869533b28 100644
--- a/src/include/utils/pgstat_internal.h
+++ b/src/include/utils/pgstat_internal.h
@@ -739,7 +739,7 @@ pgstat_copy_changecounted_stats(void *dst, void *src, size_t len,
 static inline int
 pgstat_cmp_hash_key(const void *a, const void *b, size_t size, void *arg)
 {
-	AssertArg(size == sizeof(PgStat_HashKey) && arg == NULL);
+	Assert(size == sizeof(PgStat_HashKey) && arg == NULL);
 	return memcmp(a, b, sizeof(PgStat_HashKey));
 }
 
@@ -749,7 +749,7 @@ pgstat_hash_hash_key(const void *d, size_t size, void *arg)
 	const PgStat_HashKey *key = (PgStat_HashKey *) d;
 	uint32		hash;
 
-	AssertArg(size == sizeof(PgStat_HashKey) && arg == NULL);
+	Assert(size == sizeof(PgStat_HashKey) && arg == NULL);
 
 	hash = murmurhash32(key->kind);
 	hash = hash_combine(hash, murmurhash32(key->dboid));
-- 
2.25.1

#7Peter Eisentraut
peter.eisentraut@enterprisedb.com
In reply to: Nathan Bossart (#6)
Re: Simplifying our Trap/Assert infrastructure

On 12.10.22 20:36, Nathan Bossart wrote:

On Sun, Oct 09, 2022 at 02:01:48PM -0700, Nathan Bossart wrote:

The patch LGTM. It might be worth removing usages of AssertArg and
AssertState, too, but that can always be done separately.

If you are so inclined...

I'm in favor of this. These variants are a distraction.

#8Michael Paquier
michael@paquier.xyz
In reply to: Peter Eisentraut (#7)
Re: Simplifying our Trap/Assert infrastructure

On Wed, Oct 12, 2022 at 09:19:17PM +0200, Peter Eisentraut wrote:

I'm in favor of this. These variants are a distraction.

Agreed, even if extensions could use these, it looks like any
out-of-core code using what's removed here would also gain in clarity.
This is logically fine (except for an indentation blip in
miscadmin.h?), so I have marked this entry as ready for committer.

Side note, rather unrelated to what's proposed here: would it be worth
extending AssertPointerAlignment() for the frontend code?
--
Michael

#9Peter Eisentraut
peter.eisentraut@enterprisedb.com
In reply to: Michael Paquier (#8)
Re: Simplifying our Trap/Assert infrastructure

On 27.10.22 09:23, Michael Paquier wrote:

Agreed, even if extensions could use these, it looks like any
out-of-core code using what's removed here would also gain in clarity.
This is logically fine (except for an indentation blip in
miscadmin.h?), so I have marked this entry as ready for committer.

committed

Side note, rather unrelated to what's proposed here: would it be worth
extending AssertPointerAlignment() for the frontend code?

Would there be a use for that? It's currently only used in the atomics
code.

#10Michael Paquier
michael@paquier.xyz
In reply to: Peter Eisentraut (#9)
1 attachment(s)
Re: Simplifying our Trap/Assert infrastructure

On Fri, Oct 28, 2022 at 09:36:23AM +0200, Peter Eisentraut wrote:

Would there be a use for that? It's currently only used in the atomics
code.

Yep, but they would not trigger when using atomics in the frontend
code. We don't have any use for that in core on HEAD, still that
could be useful for some external frontend code? Please see the
attached.
--
Michael

Attachments:

assert-align-frontend.patchtext/x-diff; charset=us-asciiDownload
diff --git a/src/include/c.h b/src/include/c.h
index d70ed84ac5..12ff782a63 100644
--- a/src/include/c.h
+++ b/src/include/c.h
@@ -800,7 +800,12 @@ typedef NameData *Name;
 #include <assert.h>
 #define Assert(p) assert(p)
 #define AssertMacro(p)	((void) assert(p))
-#define AssertPointerAlignment(ptr, bndr)	((void)true)
+
+/*
+ * Check that `ptr' is `bndr' aligned.
+ */
+#define AssertPointerAlignment(ptr, bndr) \
+	Assert(TYPEALIGN(bndr, (uintptr_t)(ptr)) == (uintptr_t)(ptr))
 
 #else							/* USE_ASSERT_CHECKING && !FRONTEND */
 
#11Peter Eisentraut
peter.eisentraut@enterprisedb.com
In reply to: Michael Paquier (#10)
1 attachment(s)
Re: Simplifying our Trap/Assert infrastructure

On 31.10.22 01:04, Michael Paquier wrote:

On Fri, Oct 28, 2022 at 09:36:23AM +0200, Peter Eisentraut wrote:

Would there be a use for that? It's currently only used in the atomics
code.

Yep, but they would not trigger when using atomics in the frontend
code. We don't have any use for that in core on HEAD, still that
could be useful for some external frontend code? Please see the
attached.

I don't think we need separate definitions for frontend and backend,
since the contained Assert() will take care of the difference. So the
attached would be simpler.

Attachments:

0001-Make-AssertPointerAlignment-available-to-frontend-co.patchtext/plain; charset=UTF-8; name=0001-Make-AssertPointerAlignment-available-to-frontend-co.patchDownload
From b11de03185e6e2f2f2d0b2b3a18adb019aade610 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter@eisentraut.org>
Date: Mon, 31 Oct 2022 10:00:44 +0100
Subject: [PATCH] Make AssertPointerAlignment available to frontend code

---
 src/include/c.h | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/src/include/c.h b/src/include/c.h
index d70ed84ac58e..98cdd285dd98 100644
--- a/src/include/c.h
+++ b/src/include/c.h
@@ -793,14 +793,12 @@ typedef NameData *Name;
 
 #define Assert(condition)	((void)true)
 #define AssertMacro(condition)	((void)true)
-#define AssertPointerAlignment(ptr, bndr)	((void)true)
 
 #elif defined(FRONTEND)
 
 #include <assert.h>
 #define Assert(p) assert(p)
 #define AssertMacro(p)	((void) assert(p))
-#define AssertPointerAlignment(ptr, bndr)	((void)true)
 
 #else							/* USE_ASSERT_CHECKING && !FRONTEND */
 
@@ -824,14 +822,14 @@ typedef NameData *Name;
 	((void) ((condition) || \
 			 (ExceptionalCondition(#condition, __FILE__, __LINE__), 0)))
 
+#endif							/* USE_ASSERT_CHECKING && !FRONTEND */
+
 /*
  * Check that `ptr' is `bndr' aligned.
  */
 #define AssertPointerAlignment(ptr, bndr) \
 	Assert(TYPEALIGN(bndr, (uintptr_t)(ptr)) == (uintptr_t)(ptr))
 
-#endif							/* USE_ASSERT_CHECKING && !FRONTEND */
-
 /*
  * ExceptionalCondition is compiled into the backend whether or not
  * USE_ASSERT_CHECKING is defined, so as to support use of extensions
-- 
2.37.3

#12Tom Lane
tgl@sss.pgh.pa.us
In reply to: Peter Eisentraut (#11)
Re: Simplifying our Trap/Assert infrastructure

Peter Eisentraut <peter.eisentraut@enterprisedb.com> writes:

I don't think we need separate definitions for frontend and backend,
since the contained Assert() will take care of the difference. So the
attached would be simpler.

WFM.

regards, tom lane

#13Michael Paquier
michael@paquier.xyz
In reply to: Tom Lane (#12)
Re: Simplifying our Trap/Assert infrastructure

On Mon, Oct 31, 2022 at 09:14:10AM -0400, Tom Lane wrote:

Peter Eisentraut <peter.eisentraut@enterprisedb.com> writes:

I don't think we need separate definitions for frontend and backend,
since the contained Assert() will take care of the difference. So the
attached would be simpler.

WFM.

Thanks, fine by me.
--
Michael