Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oB2PQ-0000dQ-03 for pgsql-hackers@arkaria.postgresql.org; Mon, 11 Jul 2022 23:01:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oB2PN-0005G9-TU for pgsql-hackers@arkaria.postgresql.org; Mon, 11 Jul 2022 23:01:41 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oB2PN-0005G0-Kp for pgsql-hackers@lists.postgresql.org; Mon, 11 Jul 2022 23:01:41 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oB2PH-0002c0-9M for pgsql-hackers@lists.postgresql.org; Mon, 11 Jul 2022 23:01:41 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 26BN1XeM1295225; Mon, 11 Jul 2022 19:01:33 -0400 From: Tom Lane To: Peter Eisentraut cc: pgsql-hackers@lists.postgresql.org Subject: Re: Making CallContext and InlineCodeBlock less special-case-y In-reply-to: <1077598.1657548709@sss.pgh.pa.us> References: <75063.1657410615@sss.pgh.pa.us> <95eba2c3-dda9-7d75-2829-6f12efc48e75@enterprisedb.com> <1077598.1657548709@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Mon, 11 Jul 2022 10:11:49 -0400" MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" Content-ID: <1295164.1657580468.0@sss.pgh.pa.us> Date: Mon, 11 Jul 2022 19:01:33 -0400 Message-ID: <1295224.1657580493@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk ------- =_aaaaaaaaaa0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1295164.1657580468.1@sss.pgh.pa.us> I wrote: > Peter Eisentraut writes: >> On 10.07.22 01:50, Tom Lane wrote: >>> As committed, gen_node_support.pl excludes CallContext and InlineCodeBlock >>> from getting unneeded support functions via some very ad-hoc code. >> Couldn't we just enable those support functions? I think they were just >> excluded because they didn't have any before and nobody bothered to make >> any. > Well, we could I suppose, but that path leads to a lot of dead code in > backend/nodes/ --- obviously these two alone are negligible, but I want > a story other than "it's a hack" for execnodes.h and the other files > we exclude from generation of support code. Here's a proposed patch for this bit. Again, whether these two node types have unnecessary support functions is not the point --- obviously we could afford to waste that much space. Rather, what I'm after is to have a more explainable and flexible way of dealing with the file-level exclusions applied to a lot of other node types. This patch doesn't make any change in the script's output now, but it gives us flexibility for the future. regards, tom lane ------- =_aaaaaaaaaa0 Content-Type: text/x-diff; name="invent-nodetag_only-node-attribute.patch"; charset="us-ascii" Content-ID: <1295164.1657580468.2@sss.pgh.pa.us> Content-Description: invent-nodetag_only-node-attribute.patch Content-Transfer-Encoding: quoted-printable diff --git a/src/backend/nodes/gen_node_support.pl b/src/backend/nodes/gen= _node_support.pl index 2c06609726..056530a657 100644 --- a/src/backend/nodes/gen_node_support.pl +++ b/src/backend/nodes/gen_node_support.pl @@ -50,6 +50,8 @@ my @no_equal; my @no_read; # node types we don't want read/write support for my @no_read_write; +# node types we don't want any support functions for, just node tags +my @nodetag_only; = # types that are copied by straight assignment my @scalar_types =3D qw( @@ -95,7 +97,10 @@ push @scalar_types, qw(EquivalenceClass* EquivalenceMem= ber*); # currently not required. push @scalar_types, qw(QualCost); = -# Nodes from these input files don't need support functions, just node ta= gs. +# Nodes from these input files are automatically treated as nodetag_only. +# In the future we might add explicit pg_node_attr labeling to some of th= ese +# files and remove them from this list, but for now this is the path of l= east +# resistance. my @nodetag_only_files =3D qw( nodes/execnodes.h access/amapi.h @@ -113,10 +118,8 @@ my @nodetag_only_files =3D qw( = # XXX various things we are not publishing right now to stay level # with the manual system -push @no_copy, qw(CallContext InlineCodeBlock); -push @no_equal, qw(CallContext InlineCodeBlock); push @no_read_write, - qw(AccessPriv AlterTableCmd CallContext CreateOpClassItem FunctionParam= eter InferClause InlineCodeBlock ObjectWithArgs OnConflictClause Partition= Cmd RoleSpec VacuumRelation); + qw(AccessPriv AlterTableCmd CreateOpClassItem FunctionParameter InferCl= ause ObjectWithArgs OnConflictClause PartitionCmd RoleSpec VacuumRelation)= ; push @no_read, qw(A_ArrayExpr A_Indices A_Indirection AlterStatsStmt CollateClause ColumnDef ColumnRef CreateForeignTableStmt CreateStatsStm= t CreateStmt FuncCall ImportForeignSchemaStmt IndexElem IndexStmt @@ -254,6 +257,10 @@ foreach my $infile (@ARGV) { push @no_read, $in_struct; } + elsif ($attr eq 'nodetag_only') + { + push @nodetag_only, $in_struct; + } elsif ($attr eq 'special_read_write') { # This attribute is called @@ -314,13 +321,9 @@ foreach my $infile (@ARGV) $node_type_info{$in_struct}->{field_types} =3D \%ft; $node_type_info{$in_struct}->{field_attrs} =3D \%fa; = - # Exclude nodes in nodetag_only_files from support. - if (elem $infile, @nodetag_only_files) - { - push @no_copy, $in_struct; - push @no_equal, $in_struct; - push @no_read_write, $in_struct; - } + # Propagate nodetag_only marking from files to nodes + push @nodetag_only, $in_struct + if (elem $infile, @nodetag_only_files); = # Propagate some node attributes from supertypes if ($supertype) @@ -515,6 +518,7 @@ print $eff $node_includes; foreach my $n (@node_types) { next if elem $n, @abstract_types; + next if elem $n, @nodetag_only; my $struct_no_copy =3D (elem $n, @no_copy); my $struct_no_equal =3D (elem $n, @no_equal); next if $struct_no_copy && $struct_no_equal; @@ -706,6 +710,7 @@ print $rff $node_includes; foreach my $n (@node_types) { next if elem $n, @abstract_types; + next if elem $n, @nodetag_only; next if elem $n, @no_read_write; = # XXX For now, skip all "Stmt"s except that ones that were there before. diff --git a/src/include/nodes/nodes.h b/src/include/nodes/nodes.h index adc549002a..c8ed4e0552 100644 --- a/src/include/nodes/nodes.h +++ b/src/include/nodes/nodes.h @@ -61,12 +61,17 @@ typedef enum NodeTag * * - no_read: Does not support nodeRead() at all. * + * - nodetag_only: Does not support copyObject(), equal(), outNode(), + * or nodeRead(). + * * - special_read_write: Has special treatment in outNode() and nodeRead(= ). * * Node types can be supertypes of other types whether or not they are ma= rked * abstract: if a node struct appears as the first field of another struc= t * type, then it is the supertype of that type. The no_copy, no_equal, a= nd * no_read node attributes are automatically inherited from the supertype= . + * (Notice that nodetag_only does not inherit, so it's not quite equivale= nt + * to a combination of other attributes.) * * Valid node field attributes: * diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes= .h index 0b6a7bb365..e2ad761768 100644 --- a/src/include/nodes/parsenodes.h +++ b/src/include/nodes/parsenodes.h @@ -3382,6 +3382,8 @@ typedef struct DoStmt = typedef struct InlineCodeBlock { + pg_node_attr(nodetag_only) /* this is not a member of parse trees */ + NodeTag type; char *source_text; /* source text of anonymous code block */ Oid langOid; /* OID of selected language */ @@ -3408,6 +3410,8 @@ typedef struct CallStmt = typedef struct CallContext { + pg_node_attr(nodetag_only) /* this is not a member of parse trees */ + NodeTag type; bool atomic; } CallContext; ------- =_aaaaaaaaaa0--