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.133.124]) by sourceware.org (Postfix) with ESMTP id 940263857424 for ; Tue, 15 Jun 2021 19:28:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 940263857424 Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-14-1qCWuf8oODCx-82NWPwPJA-1; Tue, 15 Jun 2021 15:28:25 -0400 X-MC-Unique: 1qCWuf8oODCx-82NWPwPJA-1 Received: by mail-qv1-f72.google.com with SMTP id n17-20020ad444b10000b02902157677ec50so294650qvt.12 for ; Tue, 15 Jun 2021 12:28:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:in-reply-to:message-id :references:mime-version; bh=JPYWtKMjbSOBJDhkLAN+pSKXHPsZs1YeyRpafljNxiY=; b=HSwRIHDg42F0H/TKWBx3/qL6VsorSNzUjOcmzzepytnZP9YKvOLPxjUqKR1OZ4tyqz GXv18le5SleH2Lgqk+1C1wfSJYroRjc9TFFa3nmV6MvlclfGYgtVWTyRk2hYpFaEuQbk uzYUWch7s2QzRbV7uBobiG8qtzMcGmoMeiomvq1/ibc5/x7jxMkGqpdIZdQuZBDDldIU DzraU9BvXSB/Fdrl1kHmGQOmOKPtBWDGpQPRIQ3niDruPDvmz3RX20AfRlS7INkdKhHp p7gEhiywLUe3r6TXje/WZaWcC60GeIQpkfCQwbODhc3ehepFXrz+pPD49wCmsFWzjVVE icsA== X-Gm-Message-State: AOAM5322IOmPS2nWuAS2uQ+WlsMfAiP0C+7abu32Qinh51qqrur+1kAh YKzcWrH7+/6ZWvToNy7G34Ai6vKaeDVD+qbmZuPK2CmDMwxIXTvJae1oBKazcrOf6PVd2KK4MM3 VGlsUrCMfIot65Iw= X-Received: by 2002:a37:b404:: with SMTP id d4mr1251028qkf.465.1623785304540; Tue, 15 Jun 2021 12:28:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyukm5yoCXcelW582eNd8EtsEJtedNtvuYwzRD1NHgzC/vHkEgJfsvNRuIO2w0LRxkpjIqCUA== X-Received: by 2002:a37:b404:: with SMTP id d4mr1251004qkf.465.1623785304221; Tue, 15 Jun 2021 12:28:24 -0700 (PDT) Received: from [192.168.1.130] (ool-457d493a.dyn.optonline.net. [69.125.73.58]) by smtp.gmail.com with ESMTPSA id n9sm7166qke.8.2021.06.15.12.28.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Jun 2021 12:28:23 -0700 (PDT) From: Patrick Palka X-Google-Original-From: Patrick Palka Date: Tue, 15 Jun 2021 15:28:23 -0400 (EDT) To: Patrick Palka cc: gcc-patches@gcc.gnu.org, libstdc++@gcc.gnu.org Subject: Re: [PATCH 2/1] libstdc++: Non-triv-copyable extra args aren't simple [PR100940] In-Reply-To: <20210615185321.1082491-1-ppalka@redhat.com> Message-ID: <571933d-e747-23e5-bd26-e141841aa682@idea> References: <20210614163543.502297-1-ppalka@redhat.com> <20210615185321.1082491-1-ppalka@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-15.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP, URI_HEX autolearn=unavailable autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libstdc++@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++ mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Jun 2021 19:28:30 -0000 On Tue, 15 Jun 2021, Patrick Palka wrote: > This force-enables perfect forwarding call wrapper semantics whenever > the extra arguments of a partially applied range adaptor aren't all > trivially copyable, so as to avoid incurring unnecessary copies of > potentially expensive-to-copy objects (such as std::function objects) > when invoking the adaptor. > > Tested on x86_64-pc-linux-gnu, does this look OK for trunk/11? > > PR libstdc++/100940 > > libstdc++-v3/ChangeLog: > > * include/std/ranges (__adaptor::__adaptor_has_simple_extra_args): Also > require that the extra arguments are trivially copyable. > * testsuite/std/ranges/adaptors/100577.cc (test04): New test. > --- > libstdc++-v3/include/std/ranges | 6 ++++-- > .../testsuite/std/ranges/adaptors/100577.cc | 19 +++++++++++++++++++ > 2 files changed, 23 insertions(+), 2 deletions(-) > > diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges > index 856975c6934..e858df88088 100644 > --- a/libstdc++-v3/include/std/ranges > +++ b/libstdc++-v3/include/std/ranges > @@ -818,8 +818,10 @@ namespace views::__adaptor > // True if the behavior of the range adaptor non-closure _Adaptor is > // independent of the value category of its extra arguments _Args. > template > - concept __adaptor_has_simple_extra_args = _Adaptor::_S_has_simple_extra_args > - || _Adaptor::template _S_has_simple_extra_args<_Args...>; > + concept __adaptor_has_simple_extra_args > + = (_Adaptor::_S_has_simple_extra_args > + || _Adaptor::template _S_has_simple_extra_args<_Args...>) > + && (is_trivially_copyable_v<_Args> && ...); On second thought, perhaps it'd be cleaner to leave this concept alone and instead encode the trivial-copyability requirement as a separate constraint on the relevant partial specializations of _Partial? Something like: -- >8 -- PR libstdc++/100940 libstdc++-v3/ChangeLog: * include/std/ranges (__adaptor::_Partial): For the "simple" forwarding partial specializations, also require that the extra arguments are trivially copyable. * testsuite/std/ranges/adaptors/100577.cc (test04): New test. --- libstdc++-v3/include/std/ranges | 8 +++++--- .../testsuite/std/ranges/adaptors/100577.cc | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges index 856975c6934..24411124580 100644 --- a/libstdc++-v3/include/std/ranges +++ b/libstdc++-v3/include/std/ranges @@ -892,11 +892,12 @@ namespace views::__adaptor }; // Partial specialization of the primary template for the case where the extra - // arguments of the adaptor can always be safely forwarded by const reference. - // This lets us get away with a single operator() overload, which makes - // overload resolution failure diagnostics more concise. + // arguments of the adaptor can always be safely and efficiently forwarded by + // const reference. This lets us get away with a single operator() overload, + // which makes overload resolution failure diagnostics more concise. template requires __adaptor_has_simple_extra_args<_Adaptor, _Args...> + && (is_trivially_copyable_v<_Args> && ...) struct _Partial<_Adaptor, _Args...> : _RangeAdaptorClosure { tuple<_Args...> _M_args; @@ -926,6 +927,7 @@ namespace views::__adaptor // where _Adaptor accepts a single extra argument. template requires __adaptor_has_simple_extra_args<_Adaptor, _Arg> + && is_trivially_copyable_v<_Arg> struct _Partial<_Adaptor, _Arg> : _RangeAdaptorClosure { _Arg _M_arg; diff --git a/libstdc++-v3/testsuite/std/ranges/adaptors/100577.cc b/libstdc++-v3/testsuite/std/ranges/adaptors/100577.cc index 8ef084621f9..06be4980ddb 100644 --- a/libstdc++-v3/testsuite/std/ranges/adaptors/100577.cc +++ b/libstdc++-v3/testsuite/std/ranges/adaptors/100577.cc @@ -21,6 +21,7 @@ // PR libstdc++/100577 #include +#include namespace ranges = std::ranges; namespace views = std::ranges::views; @@ -113,4 +114,17 @@ test03() x | std::views::drop(S{}); } +void +test04() +{ + // Non-trivially-copyable extra arguments make a closure not simple. + using F = std::function; + static_assert(!std::is_trivially_copyable_v); + using views::__adaptor::__closure_has_simple_call_op; + static_assert(!__closure_has_simple_call_op()))>); + static_assert(!__closure_has_simple_call_op()))>); + static_assert(!__closure_has_simple_call_op()))>); + static_assert(!__closure_has_simple_call_op()))>); +} + // { dg-prune-output "in requirements" } -- 2.32.0.93.g670b81a890