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 456663858CD1 for ; Fri, 23 Jun 2023 16:23:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 456663858CD1 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=1687537434; 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=lj5zGSVr2xBy138zzWyDfpvGbaeqd+OG+JgN0/WknBg=; b=ibGQJonGxp1MUgca6MPiqZ7DtYQIfYkLolBpB72X/hxk6FiDc3aaWq+/i6rk3znT9M3Sid fuXQl0F8ezU0x2dVg7IfSwDW8NxOBnjLpEhCMGYLykkMnUZwbwiGrKH+JCyqDlOLpgsOs6 4FWvsT0CkHE2VqXXcDr8JJiXbF5lQfc= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-436-5QtMslf5PKOdWlkFqxDH0A-1; Fri, 23 Jun 2023 12:23:53 -0400 X-MC-Unique: 5QtMslf5PKOdWlkFqxDH0A-1 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-763d1448b53so91290385a.3 for ; Fri, 23 Jun 2023 09:23:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687537433; x=1690129433; h=mime-version:references:message-id:in-reply-to:subject:cc:to:date :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=lj5zGSVr2xBy138zzWyDfpvGbaeqd+OG+JgN0/WknBg=; b=HmH6rESnVnJlr7iMKHQ5lK4Ap5XVaG9NgxjbJnXi5ap0sNYP7P0iOh/dhdbn0vIiLX IpwA8R+hjMz6JG70QoEwVQ25rOfSy8T3LzWaAWmr32e+RuSQZiFkUFnVZm/bOoxDTKR/ /IkwwZBT3MMCqygWmyxZ52jqalXESda8WpwHxtd5e6P4m0CL1pKWTjMTzKfnbzX3M77Q vF1mOGnFYgPGf7hLgigBQQVA7yJsWCg4YnNKWB4N6CS5FQU6qmG8aVULLv1/OlFsElyJ 3OD623juhUNB2pm8t9XR9gE2SvhPLexNLJamlMy4vrd6+5BfC1sNOZipOBIQo22FaatU p0FQ== X-Gm-Message-State: AC+VfDxv05ueMfdAmUh/AG3MOc7nDRtJJppzqyZmn1z3epXElaluKb0M yIAR/6id8U5PmzbiS2/lWqb/rnA92QRYJO5bWihsD/DNjk66m+/B6+FbPlzfSHZoJU0xGCr+biY Lo6scny25XonvDB16nw== X-Received: by 2002:a05:620a:4055:b0:75b:23a0:e7db with SMTP id i21-20020a05620a405500b0075b23a0e7dbmr30280902qko.60.1687537433414; Fri, 23 Jun 2023 09:23:53 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5YXvzTr03n8RN07CHrSgmoi2pBLGP6OMlJSS84Edp+cLq/OlGIViWsxFyiqkEYwaLJcyC+nw== X-Received: by 2002:a05:620a:4055:b0:75b:23a0:e7db with SMTP id i21-20020a05620a405500b0075b23a0e7dbmr30280888qko.60.1687537433141; Fri, 23 Jun 2023 09:23:53 -0700 (PDT) Received: from [192.168.1.130] (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id g7-20020a05620a108700b007628f6e0833sm4666299qkk.100.2023.06.23.09.23.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Jun 2023 09:23:52 -0700 (PDT) From: Patrick Palka X-Google-Original-From: Patrick Palka Date: Fri, 23 Jun 2023 12:23:52 -0400 (EDT) To: Jason Merrill cc: Patrick Palka , gcc-patches@gcc.gnu.org Subject: Re: [PATCH] c++: redundant targ coercion for var/alias tmpls In-Reply-To: <94b29e42-dfa9-5c05-4f1d-3c5beb998fdf@redhat.com> Message-ID: References: <20230621171920.1283054-1-ppalka@redhat.com> <94b29e42-dfa9-5c05-4f1d-3c5beb998fdf@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=-13.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,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 List-Id: On Fri, 23 Jun 2023, Jason Merrill wrote: > On 6/21/23 13:19, Patrick Palka wrote: > > When stepping through the variable/alias template specialization code > > paths, I noticed we perform template argument coercion twice: first from > > instantiate_alias_template / finish_template_variable and again from > > tsubst_decl (during instantiate_template). It should suffice to perform > > coercion once. > > > > To that end patch elides this second coercion from tsubst_decl when > > possible. We can't get rid of it completely because we don't always > > specialize a variable template from finish_template_variable: we could > > also be doing so directly from instantiate_template during variable > > template partial specialization selection, in which case the coercion > > from tsubst_decl would be the first and only coercion. > > Perhaps we should be coercing in lookup_template_variable rather than > finish_template_variable? Ah yes, there's a patch for that at https://gcc.gnu.org/pipermail/gcc-patches/2023-May/617377.html :) > It looks like we currently get to > most_specialized_partial_spec with args that haven't yet been coerced to match > the primary template. The call to most_specialized_partial_spec from instantiate_template? I believe the arguments should already have been coerced by the caller, which is presumably always finish_template_variable. So in that patch I also made instantiate_template use build2 (TEMPLATE_ID_EXPR, ...) directly instead of calling lookup_template_variable, to avoid an unnecessary double coercion. > > > Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for > > trunk? This reduces memory usage of range-v3's zip.cpp by ~0.5%. > > > > gcc/cp/ChangeLog: > > > > * pt.cc (tsubst_decl) : Call > > coercion_template_parms only if DECL_TEMPLATE_SPECIALIZATION > > is set. > > --- > > gcc/cp/pt.cc | 15 +++++++++++---- > > 1 file changed, 11 insertions(+), 4 deletions(-) > > > > diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc > > index be86051abad..dd10409ce18 100644 > > --- a/gcc/cp/pt.cc > > +++ b/gcc/cp/pt.cc > > @@ -15232,10 +15232,17 @@ tsubst_decl (tree t, tree args, tsubst_flags_t > > complain) > > argvec = tsubst (DECL_TI_ARGS (t), args, complain, in_decl); > > if (argvec != error_mark_node > > && PRIMARY_TEMPLATE_P (gen_tmpl) > > - && TMPL_ARGS_DEPTH (args) >= TMPL_ARGS_DEPTH (argvec)) > > - /* We're fully specializing a template declaration, so > > - we need to coerce the innermost arguments corresponding > > to > > - the template. */ > > + && TMPL_ARGS_DEPTH (args) >= TMPL_ARGS_DEPTH (argvec) > > + && DECL_TEMPLATE_SPECIALIZATION (t)) > > + /* We're fully specializing an alias or variable template, > > so > > + coerce the innermost arguments if necessary. We expect > > + instantiate_alias_template and finish_template_variable > > to > > + already have done this relative to the primary template, > > in > > + which case this coercion is unnecessary, but we can also > > + get here when substituting a partial variable template > > + specialization (directly from instantiate_template), in > > + which case DECL_TEMPLATE_SPECIALIZATION is set and > > coercion > > + is necessary. */ > > argvec = (coerce_template_parms > > (DECL_TEMPLATE_PARMS (gen_tmpl), > > argvec, tmpl, complain)); > >