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 84F403856975 for ; Thu, 7 Jul 2022 17:25:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 84F403856975 Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-596-b3dX8s22Mv-kIXBBAIC-CA-1; Thu, 07 Jul 2022 13:25:27 -0400 X-MC-Unique: b3dX8s22Mv-kIXBBAIC-CA-1 Received: by mail-qt1-f199.google.com with SMTP id u2-20020ac80502000000b002f94701339eso16104479qtg.13 for ; Thu, 07 Jul 2022 10:25:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=UUnMkvaaexcWI3ZFY2EJMBnixrUmwWJeezIF7xofavg=; b=p7kfyt3D1RS0eFS4WO5wFyakPXZuwnjVIy1nB+MXdWv4iRfbg8yf0/0MSlLCc33Euq 0YIrWr2jdMpoWxXsOcrlMucblxE8kYLz4yfIjguqo9ETbb/kEP5MATvZNWr4sbBrfzHc sYr/OLdFiGj3nL2YCa7d9xBKeneRxCdwrseQA2sBgioTFXmt0xTPN7j58mwnzw4Sduc5 G/8Nf4Q39KMUs4199z8GZJ5a7Tjr5Z9nxTz+b1yOs42FGg8fEw5A80cC42lGqrZP8Ebr aFGigXX/rESWL/5h6kSzRroTB/OPxnVpe7aVRW+Ksqaa4qRQwdHqVDRA/qPAgqsmpnqO uYJQ== X-Gm-Message-State: AJIora9O9fTJazZAQAlsKG8AFVz9ugsCeqt2xzTXMycwprUcE821TSh4 zmkDptMajP3Er3NG3kVBdGDolHqR9/fazdws8Vmmw6F9D2b/YEPXM2J2Km4RZYLVNBmhA/D4FLZ bXFdLH+zi+A2ExTwRfQ== X-Received: by 2002:a05:622a:14f:b0:31b:a118:8833 with SMTP id v15-20020a05622a014f00b0031ba1188833mr38612009qtw.543.1657214726733; Thu, 07 Jul 2022 10:25:26 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vocqXXMujVJ9yBfdOJfvjry+wmvyHjNuRkT5Js154KRY5u03WAUIcbbDxelmWcwQFiGVsjuQ== X-Received: by 2002:a05:622a:14f:b0:31b:a118:8833 with SMTP id v15-20020a05622a014f00b0031ba1188833mr38611988qtw.543.1657214726507; Thu, 07 Jul 2022 10:25:26 -0700 (PDT) Received: from redhat.com ([2601:184:4780:4310::fd37]) by smtp.gmail.com with ESMTPSA id d3-20020ac85343000000b0031ea260946csm24802qto.94.2022.07.07.10.25.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Jul 2022 10:25:26 -0700 (PDT) Date: Thu, 7 Jul 2022 13:25:24 -0400 From: Marek Polacek To: Jonathan Wakely Cc: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org, Jason Merrill Subject: Re: [PATCH] c++: Define built-in for std::tuple_element [PR100157] Message-ID: References: <20220707171436.1419387-1-jwakely@redhat.com> MIME-Version: 1.0 In-Reply-To: <20220707171436.1419387-1-jwakely@redhat.com> User-Agent: Mutt/2.2.6 (2022-06-05) X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-6.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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, 07 Jul 2022 17:25:35 -0000 On Thu, Jul 07, 2022 at 06:14:36PM +0100, Jonathan Wakely wrote: > This adds a new built-in to replace the recursive class template > instantiations done by traits such as std::tuple_element and > std::variant_alternative. The purpose is to select the Nth type from a > list of types, e.g. __builtin_type_pack_element(1, char, int, float) is > int. > > For a pathological example tuple_element_t<1000, tuple<2000 types...>> > the compilation time is reduced by more than 90% and the memory used by > the compiler is reduced by 97%. In realistic examples the gains will be > much smaller, but still relevant. > > Clang has a similar built-in, __type_pack_element, but that's a > "magic template" built-in using <> syntax, which GCC doesn't support. So > this provides an equivalent feature, but as a built-in function using > parens instead of <>. I don't really like the name "type pack element" > (it gives you an element from a pack of types) but the semi-consistency > with Clang seems like a reasonable argument in favour of keeping the > name. I'd be open to alternative names though, e.g. __builtin_nth_type > or __builtin_type_at_index. > > > The patch has some problems though ... > > FIXME 1: Marek pointed out that this this ICEs: > template using type = __builtin_type_pack_element(sizeof(T), T...); > type c; > > The sizeof(T) expression is invalid, because T is an unexpanded pack, > but it's not rejected and instead crashes: I think this could be fixed by if (check_for_bare_parameter_packs (n)) return error_mark_node; in finish_type_pack_element. (I haven't looked at the rest of the patch yet.) Marek