From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 69147385802C for ; Thu, 6 Jan 2022 10:34:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 69147385802C Received: from mail-yb1-f197.google.com (mail-yb1-f197.google.com [209.85.219.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-443-5OGWgp-rMPyr4vgzZdPJhg-1; Thu, 06 Jan 2022 05:33:58 -0500 X-MC-Unique: 5OGWgp-rMPyr4vgzZdPJhg-1 Received: by mail-yb1-f197.google.com with SMTP id c5-20020a25f305000000b0060bbdf755f7so4288651ybs.14 for ; Thu, 06 Jan 2022 02:33:58 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=dUMiCR7Xw7DGiYSnGNcRuwvuH+ob2CZi5fY4MJ9gHTY=; b=NluSU8s+qfZTRkrlhjOy1qLwegN7VUnAjFZL4bmApcBWlIQAbgECQb8aLo4d6iyHef oCVsmPCrCQzs7TR3aG5fSOqnMrULs+OxE4YKGiljBRAmKKQXQkE2K4VG3n3IXOCcYyfR x13PMwoE3R1HgtaGVDWCkCCk6I/CsnE4oDBr0LIKPR9fnuZOg1cJsDbLuWrJUsWuMOyi UEin44fvT98BVImrpebm24SjJ4Vzyfux1+1wHme9HQa531TJSuSq+BUyiRHQYm3kaOX9 qKyTXIPl1X1H04e4Xgu3iWJgm9LtQoQN4wCPMT8ROkpGRuyEEFlZejHMW6hK+SBuYaU7 BGgg== X-Gm-Message-State: AOAM531enPyq3rgy+plB69+exHba1lu5JT0RW0lC663hi1LZsVUdnuv6 9+XUXTKSLUDiFB9aCEatEM1qDKdRT66QhsQ07zvJ/qvk3uqmohD35rJUnjzQ6PteKFtsAW0GDVB Mb/aavZkCHlPDj6v1MlXVXWpDvthGBXaXtA== X-Received: by 2002:a25:b082:: with SMTP id f2mr69999307ybj.316.1641465238091; Thu, 06 Jan 2022 02:33:58 -0800 (PST) X-Google-Smtp-Source: ABdhPJwsDJuJXDn9jqlHM+E9/x3E8Hx7dX1Ppb7iM1hSFSED8ymDMqNvxWQH0JUuEjCE8eI0gR4wqChK/DTu5OZfW9g= X-Received: by 2002:a25:b082:: with SMTP id f2mr69999300ybj.316.1641465237899; Thu, 06 Jan 2022 02:33:57 -0800 (PST) MIME-Version: 1.0 References: <20220105134759.1639818-1-jwakely@redhat.com> <4010f9a9-bff0-c310-b6d6-ef3008a03fa5@redhat.com> In-Reply-To: <4010f9a9-bff0-c310-b6d6-ef3008a03fa5@redhat.com> From: Jonathan Wakely Date: Thu, 6 Jan 2022 10:33:46 +0000 Message-ID: Subject: Re: [committed] libstdc++: Reduce template instantiations in To: Stephan Bergmann Cc: "libstdc++" , gcc Patches X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, HTML_MESSAGE, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=unavailable autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 06 Jan 2022 10:34:05 -0000 On Thu, 6 Jan 2022 at 10:00, Stephan Bergmann wrote: > On 05/01/2022 14:47, Jonathan Wakely via Libstdc++ wrote: > > Tested powerpc64le-linux, pushed to trunk. > > > > > > This moves the last two template parameters of __regex_algo_impl to be > > runtime function parameters instead, so that we don't need four > > different instantiations for the possible ways to call it. Most of the > > function (and what it instantiates) is the same in all cases, so making > > them compile-time choices doesn't really have much benefit. > > > > Use 'if constexpr' for conditions that check template parameters, so > > that when we do depend on a compile-time condition we only instantiate > > what we need to. > > > > libstdc++-v3/ChangeLog: > > > > * include/bits/regex.h (__regex_algo_impl): Change __policy and > > __match_mode template parameters to be function parameters. > > (regex_match, regex_search): Pass policy and match mode as > > function arguments. > > * include/bits/regex.tcc (__regex_algo_impl): Change template > > parameters to function parameters. > > * include/bits/regex_compiler.h (_RegexTranslatorBase): Use > > 'if constexpr' for conditions using template parameters. > > (_RegexTranslator): Likewise. > > * include/bits/regex_executor.tcc (_Executor::_M_handle_accept): > > Likewise. > > * testsuite/util/testsuite_regex.h (regex_match_debug) > > (regex_search_debug): Move template arguments to function > > arguments. > > --- > > libstdc++-v3/include/bits/regex.h | 33 +++++++++---------- > > libstdc++-v3/include/bits/regex.tcc | 8 ++--- > > libstdc++-v3/include/bits/regex_compiler.h | 9 ++--- > > libstdc++-v3/include/bits/regex_executor.tcc | 2 +- > > libstdc++-v3/testsuite/util/testsuite_regex.h | 24 +++++++------- > > 5 files changed, 37 insertions(+), 39 deletions(-) > > Clang now fails #include with > > > In file included from > gcc/trunk/inst/lib/gcc/x86_64-pc-linux-gnu/12.0.0/../../../../include/c++/12.0.0/regex:66: > > > gcc/trunk/inst/lib/gcc/x86_64-pc-linux-gnu/12.0.0/../../../../include/c++/12.0.0/bits/regex.h:799:9: > error: unknown type name '_RegexExecutorPolicy'; did you mean > '__detail::_RegexExecutorPolicy'? > > _RegexExecutorPolicy, bool); > > ^ > > > gcc/trunk/inst/lib/gcc/x86_64-pc-linux-gnu/12.0.0/../../../../include/c++/12.0.0/bits/regex.h:45:14: > note: '__detail::_RegexExecutorPolicy' declared here > > enum class _RegexExecutorPolicy : int { _S_auto, _S_alternate }; > > ^ > > > gcc/trunk/inst/lib/gcc/x86_64-pc-linux-gnu/12.0.0/../../../../include/c++/12.0.0/bits/regex.h:2070:9: > error: unknown type name '_RegexExecutorPolicy'; did you mean > '__detail::_RegexExecutorPolicy'? > > _RegexExecutorPolicy, bool); > > ^ > > > gcc/trunk/inst/lib/gcc/x86_64-pc-linux-gnu/12.0.0/../../../../include/c++/12.0.0/bits/regex.h:45:14: > note: '__detail::_RegexExecutorPolicy' declared here > > enum class _RegexExecutorPolicy : int { _S_auto, _S_alternate }; > > ^ > > and > > > diff --git a/libstdc++-v3/include/bits/regex.h > b/libstdc++-v3/include/bits/regex.h > > index 7480b0a5f97..46c168010bf 100644 > > --- a/libstdc++-v3/include/bits/regex.h > > +++ b/libstdc++-v3/include/bits/regex.h > > @@ -796,7 +796,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 > > __detail::__regex_algo_impl(_Bp, _Bp, match_results<_Bp, _Ap>&, > > const basic_regex<_Cp, _Rp>&, > > regex_constants::match_flag_type, > > - _RegexExecutorPolicy, bool); > > + __detail::_RegexExecutorPolicy, > bool); > > > > template > > friend class __detail::_Executor; > > @@ -2067,7 +2067,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 > > __detail::__regex_algo_impl(_Bp, _Bp, match_results<_Bp, _Ap>&, > > const basic_regex<_Cp, _Rp>&, > > regex_constants::match_flag_type, > > - _RegexExecutorPolicy, bool); > > + __detail::_RegexExecutorPolicy, > bool); > > > > // Reset contents to __size unmatched sub_match objects > > // (plus additional objects for prefix, suffix and unmatched sub). > > would fix that. > I'll make the change, but this looks like a clang bug: https://godbolt.org/z/bozxYErrc