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 047DB3858D32 for ; Mon, 18 Sep 2023 02:51:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 047DB3858D32 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=1695005464; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TqN691gb9uWqFWE0JTEZBxaNdn1DFa9Rjg2Ca3VXtSg=; b=JLTvz+i+aojOTfFo2W+pbU2317jlIq5hFZiDvMbVgmyVR94AiNdui5qYleH/YWjayormUB z7TtxXr2TGXgEqZ3fQfMwNLjBsgIqCOfeC4XvtvaFgK7FEpWtyp20GORH9YYg2FCNMyLJs /2rrLnUHJxmeQSdtOgAf6qhaodCtLCw= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-70-8R82qPoGO3unUORgSudsXw-1; Sun, 17 Sep 2023 22:51:02 -0400 X-MC-Unique: 8R82qPoGO3unUORgSudsXw-1 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-76dbe1865c1so566901585a.0 for ; Sun, 17 Sep 2023 19:51:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695005462; x=1695610262; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=TqN691gb9uWqFWE0JTEZBxaNdn1DFa9Rjg2Ca3VXtSg=; b=qzQeBYRuo0PIqoi9p0a98OM8pslBX7CJ9yT1RClInNICDehWZGVrrlBOgDeDxsRcXh 3vB/uocCsT9DJphfGOiBZtEJ4R5Ur9fCq8Rf6GmjavdJPo54NLCmaCgZjdAOXWgEDwJb MrIPo2WqehjYlSlRxkIs0TRyKS7CNChEYul76tZhBspOuSt0kQpcH+EmmS4Qt54LMVii PhW/yfwe+zMrxitLacy4p0lyetgdNnYONL7oSIwCnWvREFyjROWq0ldX9CPK2mzEFfZl 6fBX3WE0pRoSMQQWJey9pGYnfzQlagn130AuOxJ7JA+lUS5gVIjCfAJI1SsZT8xF9R2z 3Mag== X-Gm-Message-State: AOJu0YxAV4YTNfN7Ve3HCJV5xSLzkXpLUGa3abUk3PdPCHTx7HfIFs+g Nn8zpanZ7nwfj50J1AwwzvJbLH4ng5Gym38nbC4j+hsiZg47LMH2s8PJc0HFHdMpTqwKr1ModcJ AS4CyqOSRiKmPzCw+0w== X-Received: by 2002:ae9:e00a:0:b0:76d:4252:95d2 with SMTP id m10-20020ae9e00a000000b0076d425295d2mr6790111qkk.39.1695005462390; Sun, 17 Sep 2023 19:51:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHri64FK/y6fsDltnvH+cgQLDOJ6jr1zU2jq1ubyDVV4hPY7HoiwPZuRmoINRQG77gXJy87aQ== X-Received: by 2002:ae9:e00a:0:b0:76d:4252:95d2 with SMTP id m10-20020ae9e00a000000b0076d425295d2mr6790102qkk.39.1695005462101; Sun, 17 Sep 2023 19:51:02 -0700 (PDT) Received: from [192.168.1.108] (130-44-146-16.s12558.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.146.16]) by smtp.gmail.com with ESMTPSA id p1-20020a05620a112100b00767da10efb6sm2851671qkk.97.2023.09.17.19.51.00 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 17 Sep 2023 19:51:01 -0700 (PDT) Message-ID: <8bece04e-88ef-0a83-8cc0-5f9546b085a0@redhat.com> Date: Sun, 17 Sep 2023 22:50:59 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: Re: [PATCH] c++: optimize tsubst_template_decl for function templates To: Patrick Palka , gcc-patches@gcc.gnu.org References: <20230917191304.1483576-1-ppalka@redhat.com> From: Jason Merrill In-Reply-To: <20230917191304.1483576-1-ppalka@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,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 9/17/23 15:13, Patrick Palka wrote: > Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for > trunk? > > -- >8 -- > > r14-2655-g92d1425ca78040 made instantiate_template avoid redundantly > performing a specialization lookup when instantiating a function or > alias template. This patch applies the same optimization to > tsubst_template_decl when (partially) instantiating a function template, > which allows us to remove a check from register_specialization since > tsubst_function_decl no longer calls register_specialization for > a function template partial instantiation. > > gcc/cp/ChangeLog: > > * pt.cc (register_specialization): Remove now-unnecessary > early exit for FUNCTION_DECL partial instantiation. > (tsubst_template_decl): Pass use_spec_table=false to > tsubst_function_decl. Set DECL_TI_ARGS of a non-lambda > FUNCTION_DECL specialization to the full set of arguments. > Simplify register_specialization call accordingly. > > gcc/testsuite/ChangeLog: > > * g++.dg/template/nontype12.C: Expect two instead of three > duplicate diagnostics for A::bar() specialization. > --- > gcc/cp/pt.cc | 29 +++++++---------------- > gcc/testsuite/g++.dg/template/nontype12.C | 1 - > 2 files changed, 9 insertions(+), 21 deletions(-) > > diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc > index c311a6b88f5..a0296a1ea16 100644 > --- a/gcc/cp/pt.cc > +++ b/gcc/cp/pt.cc > @@ -1507,21 +1507,6 @@ register_specialization (tree spec, tree tmpl, tree args, bool is_friend, > || (TREE_CODE (tmpl) == FIELD_DECL > && TREE_CODE (spec) == NONTYPE_ARGUMENT_PACK)); > > - if (TREE_CODE (spec) == FUNCTION_DECL > - && uses_template_parms (DECL_TI_ARGS (spec))) > - /* This is the FUNCTION_DECL for a partial instantiation. Don't > - register it; we want the corresponding TEMPLATE_DECL instead. > - We use `uses_template_parms (DECL_TI_ARGS (spec))' rather than > - the more obvious `uses_template_parms (spec)' to avoid problems > - with default function arguments. In particular, given > - something like this: > - > - template void f(T t1, T t = T()) > - > - the default argument expression is not substituted for in an > - instantiation unless and until it is actually needed. */ > - return spec; > - > spec_entry elt; > elt.tmpl = tmpl; > elt.args = args; > @@ -14663,7 +14648,7 @@ tsubst_template_decl (tree t, tree args, tsubst_flags_t complain, > tree in_decl = t; > tree spec; > tree tmpl_args; > - tree full_args; > + tree full_args = NULL_TREE; > tree r; > hashval_t hash = 0; > > @@ -14754,7 +14739,8 @@ tsubst_template_decl (tree t, tree args, tsubst_flags_t complain, > tree inner = decl; > ++processing_template_decl; > if (TREE_CODE (inner) == FUNCTION_DECL) > - inner = tsubst_function_decl (inner, args, complain, lambda_fntype); > + inner = tsubst_function_decl (inner, args, complain, lambda_fntype, > + /*use_spec_table=*/false); > else > { > if (TREE_CODE (inner) == TYPE_DECL && !TYPE_DECL_ALIAS_P (inner)) > @@ -14792,6 +14778,11 @@ tsubst_template_decl (tree t, tree args, tsubst_flags_t complain, > } > else > { > + if (TREE_CODE (inner) == FUNCTION_DECL) > + /* Set DECL_TI_ARGS to the full set of template arguments, which > + tsubst_function_decl didn't do due to use_spec_table=false. */ > + DECL_TI_ARGS (inner) = full_args; > + > DECL_TI_TEMPLATE (inner) = r; > DECL_TI_ARGS (r) = DECL_TI_ARGS (inner); > } > @@ -14822,9 +14813,7 @@ tsubst_template_decl (tree t, tree args, tsubst_flags_t complain, > > if (TREE_CODE (decl) == FUNCTION_DECL && !lambda_fntype) > /* Record this non-type partial instantiation. */ > - register_specialization (r, t, > - DECL_TI_ARGS (DECL_TEMPLATE_RESULT (r)), > - false, hash); > + register_specialization (r, t, full_args, false, hash); > > return r; > } > diff --git a/gcc/testsuite/g++.dg/template/nontype12.C b/gcc/testsuite/g++.dg/template/nontype12.C > index 9a9c3ac1e66..e36a9f16f94 100644 > --- a/gcc/testsuite/g++.dg/template/nontype12.C > +++ b/gcc/testsuite/g++.dg/template/nontype12.C > @@ -5,7 +5,6 @@ template struct A > { > template int foo(); // { dg-error "double" "" { target c++17_down } } > template class> int bar(); // { dg-bogus {double[^\n]*\n[^\n]*C:7:[^\n]*double} "" { xfail c++17_down } } > - // { dg-error "double" "" { target c++17_down } .-1 } Hmm, I thought this line was to check that we get one error even if we don't want two? Jason