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 ESMTPS id 9B8B13858C52 for ; Fri, 15 Sep 2023 20:49:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9B8B13858C52 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694810947; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=nUzT5+fdazzQny2BFGyY4eo0YG+4lFjNvlauKm/Br80=; b=KLdrHZawYk6iEBLHHdCA1gMDRMMso4vLZCfIrvTL9MvVvB1NHwkQmOuaSq8BVZtjt04LKL 2cmGSKmYDy8v+iUzgyrJn+R0zlrWqVQwkomtgMXUVUn+au/zjR2mYaxMowiqeBECbi/KnG hIu8miMZJuTXI1gDl3EqyC50Y6HugW0= Received: from mail-lj1-f198.google.com (mail-lj1-f198.google.com [209.85.208.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-240-EcjuurJlNX-pgJVAgzq7Iw-1; Fri, 15 Sep 2023 16:49:05 -0400 X-MC-Unique: EcjuurJlNX-pgJVAgzq7Iw-1 Received: by mail-lj1-f198.google.com with SMTP id 38308e7fff4ca-2bfb9db0397so32489111fa.3 for ; Fri, 15 Sep 2023 13:49:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694810944; x=1695415744; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=nUzT5+fdazzQny2BFGyY4eo0YG+4lFjNvlauKm/Br80=; b=wYqBr9MeflwP1UPK7YbfQhRfuCMTPS4G+wFEWsl6MzW/90Mj+uygLHXKdqqH+kLOHP iDTNLAECb4Agnh7K6vdnVw5TtnQF0Ptd5EpxMBRaKqeJtDQmjo0Y/Wn8wGROKxikVPBV fDOCvflvX1WDOTPqPfeWgaZDEMWGGeYS+bG+FlUYM9phyBA2Ev7wmBprgycy9Bbr0AF8 oZhoZ2QV3OKeWCoObRVZFDZndEE0SnDTB5AYP7btuJwHhCAjuIe7vHR2k3GgtCKwAJ+I 9Z7szhsfRyFBo9J4lVJyc50jhNOn1byNEtsEz8RHY5/TcpmCo7ubhyGRSmk+O6qnnU0c +g3w== X-Gm-Message-State: AOJu0Yw86RQfqr0qqOsFM9GOeWfhykqKxdGPjfo/Ag75iCVJAO5lkkZK bz+CAQhItCqDlv4/mRwiEy8xJ6VYzRH+AomadUMlBPiJpDxeKqT5hv3icp2aG4Eox7SiB1fbZDk MO27wjD1/MrNoLMH3QVY/AyMkRTNuJGQ= X-Received: by 2002:a2e:9f0a:0:b0:2bc:b70d:9cb5 with SMTP id u10-20020a2e9f0a000000b002bcb70d9cb5mr2533925ljk.33.1694810943964; Fri, 15 Sep 2023 13:49:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGB5o92LcsD7IcW2lCXoCx/TO0Y9AIoxqZRW6AFwuOQnZZb0nUMjQEDV/PfUDuhajwI4CwMedoWKZ/uBefKROw= X-Received: by 2002:a2e:9f0a:0:b0:2bc:b70d:9cb5 with SMTP id u10-20020a2e9f0a000000b002bcb70d9cb5mr2533914ljk.33.1694810943578; Fri, 15 Sep 2023 13:49:03 -0700 (PDT) MIME-Version: 1.0 References: <20230913225206.4188935-1-ppalka@redhat.com> In-Reply-To: <20230913225206.4188935-1-ppalka@redhat.com> From: Jonathan Wakely Date: Fri, 15 Sep 2023 21:48:52 +0100 Message-ID: Subject: Re: [PATCH] libstdc++: Reduce integer std::to/from_chars symbol sizes To: Patrick Palka Cc: gcc-patches@gcc.gnu.org, libstdc++@gcc.gnu.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-12.1 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_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Wed, 13 Sept 2023 at 23:52, Patrick Palka via Libstdc++ wrote: > > Tested on x86_64-pc-linux-gnu, does this look OK for trunk? OK, thanks. > > -- >8 -- > > For std::to_chars: > > The constrained alias __integer_to_chars_result_type seems unnecessary > ever since r10-3080-g28f0075742ed58 got rid of the only public overload > which used it. Now only non-public overloads are constrained by it > (through their return type) and these non-public overloads aren't used > in a SFINAE context, so the constraints have no observable effect. So > this patch gets rid of this alias, which greatly reduces the symbol > sizes of the affected functions (since the expanded alias is quite > large). > > For std::from_chars: > > We can't get rid of the corresponding alias because it's constrains > the public integer std::from_chars overload. But we can avoid having > the constraint bloat the mangled name by instead encoding it as a > defaulted template parameter. We use the non-type parameter form > > enable_if_t<..., int> = 0 > > instead of the type parameter form > > typename = enable_if_t<...> > > because the type form can be circumvented by providing an explicit template > argument to type parameter, e.g. 'std::from_chars(...)', so the > non-type form seems like the more robust choice. > > In passing, use __is_standard_integer in the constraint. > > libstdc++-v3/ChangeLog: > > * include/std/charconv (__detail::__integer_to_chars_result_type): > Remove. > (__detail::__to_chars_16): Use to_chars_result as return type. > (__detail::__to_chars_10): Likewise. > (__detail::__to_chars_8): Likewise. > (__detail::__to_chars_2): Likewise. > (__detail::__to_chars_i): Likewise. > (__detail::__integer_from_chars_result_type): Pull out enable_if_t > condition into and replace with ... > (__detail::__integer_from_chars_enabled): ... this. Use > __is_standard_integer instead of __is_signed_integer and > __is_unsigned_integer. > (from_chars): Encode constraint as a defaulted non-type template > parameter instead of within the return type. > --- > libstdc++-v3/include/std/charconv | 33 ++++++++++--------------------- > 1 file changed, 10 insertions(+), 23 deletions(-) > > diff --git a/libstdc++-v3/include/std/charconv b/libstdc++-v3/include/std/charconv > index 01711d38576..ec25ae139ba 100644 > --- a/libstdc++-v3/include/std/charconv > +++ b/libstdc++-v3/include/std/charconv > @@ -79,17 +79,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION > > namespace __detail > { > - template > - using __integer_to_chars_result_type > - = enable_if_t<__or_<__is_signed_integer<_Tp>, > - __is_unsigned_integer<_Tp>, > -#if defined __SIZEOF_INT128__ && defined __STRICT_ANSI__ > - is_same<_Tp, signed __int128>, > - is_same<_Tp, unsigned __int128>, > -#endif > - is_same>>::value, > - to_chars_result>; > - > // Pick an unsigned type of suitable size. This is used to reduce the > // number of specializations of __to_chars_len, __to_chars etc. that > // get instantiated. For example, to_chars and to_chars > @@ -162,7 +151,7 @@ namespace __detail > } > > template > - constexpr __integer_to_chars_result_type<_Tp> > + constexpr to_chars_result > __to_chars_16(char* __first, char* __last, _Tp __val) noexcept > { > static_assert(__integer_to_chars_is_unsigned<_Tp>, "implementation bug"); > @@ -208,7 +197,7 @@ namespace __detail > } > > template > - constexpr __integer_to_chars_result_type<_Tp> > + constexpr to_chars_result > __to_chars_10(char* __first, char* __last, _Tp __val) noexcept > { > static_assert(__integer_to_chars_is_unsigned<_Tp>, "implementation bug"); > @@ -231,7 +220,7 @@ namespace __detail > } > > template > - constexpr __integer_to_chars_result_type<_Tp> > + constexpr to_chars_result > __to_chars_8(char* __first, char* __last, _Tp __val) noexcept > { > static_assert(__integer_to_chars_is_unsigned<_Tp>, "implementation bug"); > @@ -284,7 +273,7 @@ namespace __detail > } > > template > - constexpr __integer_to_chars_result_type<_Tp> > + constexpr to_chars_result > __to_chars_2(char* __first, char* __last, _Tp __val) noexcept > { > static_assert(__integer_to_chars_is_unsigned<_Tp>, "implementation bug"); > @@ -320,7 +309,7 @@ namespace __detail > } // namespace __detail > > template > - constexpr __detail::__integer_to_chars_result_type<_Tp> > + constexpr to_chars_result > __to_chars_i(char* __first, char* __last, _Tp __value, int __base = 10) > { > __glibcxx_assert(2 <= __base && __base <= 36); > @@ -548,17 +537,15 @@ namespace __detail > } > > template > - using __integer_from_chars_result_type > - = enable_if_t<__or_<__is_signed_integer<_Tp>, > - __is_unsigned_integer<_Tp>, > - is_same>>::value, > - from_chars_result>; > + constexpr bool __integer_from_chars_enabled > + = __or_<__is_standard_integer<_Tp>, is_same>>::value; > > } // namespace __detail > > /// std::from_chars for integral types. > - template > - _GLIBCXX23_CONSTEXPR __detail::__integer_from_chars_result_type<_Tp> > + template + enable_if_t<__detail::__integer_from_chars_enabled<_Tp>, int> = 0> > + _GLIBCXX23_CONSTEXPR from_chars_result > from_chars(const char* __first, const char* __last, _Tp& __value, > int __base = 10) > { > -- > 2.42.0.158.g94e83dcf5b >