Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sOfb8-000Wzk-Vj for pgsql-hackers@arkaria.postgresql.org; Tue, 02 Jul 2024 15:39:15 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1sOfa7-002b1m-K5 for pgsql-hackers@arkaria.postgresql.org; Tue, 02 Jul 2024 15:38:12 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sOfa6-002b1e-Lk for pgsql-hackers@lists.postgresql.org; Tue, 02 Jul 2024 15:38:12 +0000 Received: from fout2-smtp.messagingengine.com ([103.168.172.145]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sOfa3-0004jY-Qa for pgsql-hackers@postgresql.org; Tue, 02 Jul 2024 15:38:10 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfout.nyi.internal (Postfix) with ESMTP id 552BE1380134; Tue, 2 Jul 2024 11:38:04 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Tue, 02 Jul 2024 11:38:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ilmari.org; h=cc :cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1719934684; x=1720021084; bh=KkmbONDIIA 44CVfFC6/VICTw1RWq+cmxEOhlKp3sh+I=; b=fy9vlJo+oDw4WmBL+RPDsPhKKr CQ2P3NcfK6vSoKOsgXZBm5gnveZD9K/HJegVeZ83kx15WCCeemU6RdkCDOqo/80b lhu71S1c8Z47GED8F2TxQimZ337lrLznyJVpyaI7s1IX8WAIL20ijCLXmeexVEpy vKL94E3MFwnIb0a4L7VmmqG8SBNzevKubx4Hc/Gg6pJSRqOluLMKNnLQerXfWmiY gB+yQfG3TUgg7w4e//5wuWPQCrVxWNmVBJeeBT5ai184vVxy4sNIrOYPI8UAuLbt tUIFFZcwNTHeTZmi9dg28lgfr8k/E/S7IGr2zYp1hbOfdjtF7P8ZQ9vXx2aQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; t=1719934684; x=1720021084; bh=KkmbONDIIA44CVfFC6/VICTw1RWq +cmxEOhlKp3sh+I=; b=iX6aWoeahb1VZJ5dx4g11FbjDlMa6Hi7nlabtCbzV3U3 NaEfLzE8vrZlad7oUONsmdpoJHLULOV8A/vn6RTtGfGImOyWAPWvhijig4rgwSJ7 Bqfba0Sd7ZBrlXrxTw3CkTivUMie98hVEhQvEgevFn0ooX3a2RFS1lqHBHvYgbga E2rhVsUh/ufoHZ2vvnNgdtQl8O3+J4tGGguXQKnxyyrXo2wH60B34v8fs4jrn2kv 57ZtLFuuMRVSwXbTzkIvql+8z9gQQemDWqY3XzxfZPkUZmtlRqUUx94+fAeJTQuQ efWsXzYfcykn4G3dgX478wjaHldLxsveSt0LzLn9Xg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudehgdekkecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvfevufhfffgjkfgfgggtsehmtderredtreejnecuhfhrohhmpeffrghgfhhi nhhnucfklhhmrghrihcuofgrnhhnshonkhgvrhcuoehilhhmrghrihesihhlmhgrrhhird horhhgqeenucggtffrrghtthgvrhhnpeetieduvdfhhfffffegjeettdffteevhffgieel ffdttedtheffjeetvdegvefhtdenucffohhmrghinhepghhithhhuhgsrdgtohhmnecuve hluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepihhlmhgrrhhi sehilhhmrghrihdrohhrgh X-ME-Proxy: Feedback-ID: i1ff147bf:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 2 Jul 2024 11:38:03 -0400 (EDT) From: =?utf-8?Q?Dagfinn_Ilmari_Manns=C3=A5ker?= To: Andrew Dunstan Cc: Michael Paquier , Alexander Lakhin , pgsql-hackers Subject: Re: Cleaning up perl code References: <70b340bc-244a-589d-ef8b-d8aebb707a84@gmail.com> <87ttisfcah.fsf@wibble.ilmari.org> <730c8376-77db-5af6-ea2f-d530f68c5fa3@gmail.com> <87wmm4dkci.fsf@wibble.ilmari.org> <54d72e0f-9bb8-48d8-a31a-04401d506b07@dunslane.net> Date: Tue, 02 Jul 2024 16:38:01 +0100 In-Reply-To: <54d72e0f-9bb8-48d8-a31a-04401d506b07@dunslane.net> (Andrew Dunstan's message of "Tue, 2 Jul 2024 11:11:22 -0400") Message-ID: <87tth7erdy.fsf@wibble.ilmari.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Andrew Dunstan writes: > On 2024-07-02 Tu 8:55 AM, Dagfinn Ilmari Mannsåker wrote: >> Relatedly, I also had a look at prohibiting unused regex captures >> (RegularExpressions::ProhibitUnusedCapture), which found a few real >> cases, but also lots of false positives in Catalog.pm, because it >> doesn't understand that %+ uses all named captures, so I won't propose a >> patch for that until that's fixed upstream >> (https://github.com/Perl-Critic/Perl-Critic/pull/1065). >> > > We could mark Catalog.pm with a "## no critic (ProhibitUnusedCapture)" > and then use the test elsewhere. Yeah, that's what I've done for now. Here's a sequence of patches that fixes the existing cases of unused captures, and adds the policy and override. The seg-validate.pl script seems unused, unmaintained and useless (it doesn't actually match the syntax accepted by seg, specifcially the (+-) syntax (which my patch fixes in passing)), so maybe we should just delete it instead? > cheers > > andrew -ilmari --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-seg-validate.pl-Use-qr-instead-of-strings-to-assembl.patch From 17a350c8d6ec2ae887fe7784dd6b9275028dc681 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dagfinn=20Ilmari=20Manns=C3=A5ker?= Date: Mon, 20 May 2024 22:54:52 +0100 Subject: [PATCH 1/3] seg-validate.pl: Use qr// instead of strings to assemble regexes Also eliminate unused captures, and fix the plus/minus syntax to accept (+-), not the erroneous '+-'. --- contrib/seg/seg-validate.pl | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/contrib/seg/seg-validate.pl b/contrib/seg/seg-validate.pl index 22cbca966d..518fbfb24a 100755 --- a/contrib/seg/seg-validate.pl +++ b/contrib/seg/seg-validate.pl @@ -5,15 +5,15 @@ use strict; use warnings FATAL => 'all'; -my $integer = '[+-]?[0-9]+'; -my $real = '[+-]?[0-9]+\.[0-9]+'; +my $integer = qr/[+-]?[0-9]+/; +my $real = qr/[+-]?[0-9]+\.[0-9]+/; -my $RANGE = '(\.\.)(\.)?'; -my $PLUMIN = q(\'\+\-\'); -my $FLOAT = "(($integer)|($real))([eE]($integer))?"; -my $EXTENSION = '<|>|~'; +my $RANGE = qr/\.{2,3}/; +my $PLUMIN = qr/\Q(+-)/; +my $FLOAT = qr/(?:$integer|$real)(?:[eE]$integer)?/; +my $EXTENSION = qr/[<>~]/; -my $boundary = "($EXTENSION)?$FLOAT"; +my $boundary = qr/$EXTENSION?$FLOAT/; my $deviation = $FLOAT; my $rule_1 = $boundary . $PLUMIN . $deviation; @@ -28,23 +28,23 @@ { # s/ +//g; - if (/^($rule_1)$/) + if (/^$rule_1$/) { print; } - elsif (/^($rule_2)$/) + elsif (/^$rule_2$/) { print; } - elsif (/^($rule_3)$/) + elsif (/^$rule_3$/) { print; } - elsif (/^($rule_4)$/) + elsif (/^$rule_4$/) { print; } - elsif (/^($rule_5)$/) + elsif (/^$rule_5$/) { print; } -- 2.39.2 --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0002-Fix-unused-regular-expression-captures.patch From 31ab31f409ea3305105822d91fd688ecd35b594d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dagfinn=20Ilmari=20Manns=C3=A5ker?= Date: Tue, 2 Jul 2024 16:25:15 +0100 Subject: [PATCH 2/3] Fix unused regular expression captures Remove unused captures, actually use the capture, or fix the capture number used, as appropriate. --- src/backend/catalog/Catalog.pm | 2 +- src/backend/utils/activity/generate-wait_event_types.pl | 5 ++--- src/backend/utils/mb/Unicode/convutils.pm | 4 ++-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/backend/catalog/Catalog.pm b/src/backend/catalog/Catalog.pm index 8e709524cb..59ebe5f434 100644 --- a/src/backend/catalog/Catalog.pm +++ b/src/backend/catalog/Catalog.pm @@ -69,7 +69,7 @@ sub ParseHeader if (!$is_client_code) { # Strip C-style comments. - s;/\*(.|\n)*\*/;;g; + s;/\*.*\*/;;gs; if (m;/\*;) { diff --git a/src/backend/utils/activity/generate-wait_event_types.pl b/src/backend/utils/activity/generate-wait_event_types.pl index 2f2fa5bb8f..4e8dc63e6b 100644 --- a/src/backend/utils/activity/generate-wait_event_types.pl +++ b/src/backend/utils/activity/generate-wait_event_types.pl @@ -55,10 +55,9 @@ next if /^\s*$/; # Get waitclassname based on the section - if (/^Section: ClassName(.*)/) + if (/^Section: ClassName - (\w+)/) { - $section_name = $_; - $section_name =~ s/^.*- //; + $section_name = $1; $abi_compatibility = 0; next; } diff --git a/src/backend/utils/mb/Unicode/convutils.pm b/src/backend/utils/mb/Unicode/convutils.pm index ee780acbe3..1b453d1eba 100644 --- a/src/backend/utils/mb/Unicode/convutils.pm +++ b/src/backend/utils/mb/Unicode/convutils.pm @@ -41,7 +41,7 @@ sub read_source next if (/^$/); # Ignore empty lines - next if (/^0x([0-9A-F]+)\s+(#.*)$/); + next if (/^0x[0-9A-F]+\s+#.*$/); # The Unicode source files have three columns # 1: The "foreign" code (in hex) @@ -55,7 +55,7 @@ sub read_source my $out = { code => hex($1), ucs => hex($2), - comment => $4, + comment => $3, direction => BOTH, f => $fname, l => $. -- 2.39.2 --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0003-Prohibit-unused-regular-expression-captures.patch From 3558190b163378d810b5af405992ebd475c1f8a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dagfinn=20Ilmari=20Manns=C3=A5ker?= Date: Tue, 2 Jul 2024 16:26:10 +0100 Subject: [PATCH 3/3] Prohibit unused regular expression captures Disable the policy in Catalog::ParseHeader, since perlcritic doesn't (yet) realise that %+ constitutes using all named captures. --- src/backend/catalog/Catalog.pm | 5 +++++ src/tools/perlcheck/perlcriticrc | 3 +++ 2 files changed, 8 insertions(+) diff --git a/src/backend/catalog/Catalog.pm b/src/backend/catalog/Catalog.pm index 59ebe5f434..8f62ad6153 100644 --- a/src/backend/catalog/Catalog.pm +++ b/src/backend/catalog/Catalog.pm @@ -91,6 +91,10 @@ sub ParseHeader # Push the data into the appropriate data structure. # Caution: when adding new recognized OID-defining macros, # also update src/include/catalog/renumber_oids.pl. + # + # perlcritic doesn't know that %+ uses all named captures + # (https://github.com/Perl-Critic/Perl-Critic/pull/1065) + ## no critic (ProhibitUnusedCapture) if (/^DECLARE_TOAST\(\s* (?\w+),\s* (?\d+),\s* @@ -194,6 +198,7 @@ sub ParseHeader $catalog{schema_macro} = /BKI_SCHEMA_MACRO/ ? 1 : 0; $declaring_attributes = 1; } + ## use critic elsif ($is_client_code) { if (/^#endif/) diff --git a/src/tools/perlcheck/perlcriticrc b/src/tools/perlcheck/perlcriticrc index 6053dfcc2a..ba238b2baa 100644 --- a/src/tools/perlcheck/perlcriticrc +++ b/src/tools/perlcheck/perlcriticrc @@ -18,6 +18,9 @@ verbose = %f: %m at line %l, column %c. %e. ([%p] Severity: %s)\n [Variables::ProhibitUnusedVariables] severity = 5 +[RegularExpressions::ProhibitUnusedCapture] +severity = 5 + # allow octal constants with leading zeros [-ValuesAndExpressions::ProhibitLeadingZeros] -- 2.39.2 --=-=-=--