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 15F7438582B0 for ; Thu, 7 Jul 2022 17:25:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 15F7438582B0 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-319-KCUdNmFbOOiguhhKvtm0ag-1; Thu, 07 Jul 2022 13:25:27 -0400 X-MC-Unique: KCUdNmFbOOiguhhKvtm0ag-1 Received: by mail-qt1-f199.google.com with SMTP id j29-20020ac8405d000000b0031e9bb077dfso1813059qtl.15 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=vBkYZldLAusAXHsKUXgIiOGkfRJxWf0Qai0Q4gBKkSI5NOK6pppjP0UnI8+xryXVaf KWKWW0KGlUD8eNTtkFwhPGA8tb5hMzdxxWMz07Q9Kp6QORJwE4dRGH5MZdyXppHr/ggz gmjK+LEhQng4et4YYl4u42LafXt7OyvWzl53bcp/aJDs6SEcKapdRpkUPRCTzsPa0Lbm 60LtX7SAzHh03wcgPuKL34vz3jEPlqAmHMw+SIHDZRTzFb2Dmvvt2N9E0Os9bJA1yXDW di9yTHRSav4aJsejqGA4unbV1wRuwfhdCWXP6mXGRdfQoxWGvp4rF1MzSWi/Bs0c8NU6 n4fw== X-Gm-Message-State: AJIora8gimsBmVZn/ER85amnwPS6kK6c7M6ZsDCG+dXgI1+zTctGKnez ajNUCZFR1Vx4we26eo3UayFVewHTseKkmiaHWNGV4sWZKbn9tg/sF0P4dOkWRvSISzvjJdePDgc uEzMhDOMi8hsd7co= X-Received: by 2002:a05:622a:14f:b0:31b:a118:8833 with SMTP id v15-20020a05622a014f00b0031ba1188833mr38612011qtw.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.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: Thu, 07 Jul 2022 17:25:30 -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