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 680B23858D32 for ; Mon, 18 Sep 2023 16:55:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 680B23858D32 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=1695056157; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YKfdwIDJknHJrYBCaMXNXNEGPYVbR6fXcFC/Nvm3ktI=; b=Q8FTcXKyS1lvGfKE82CghPBA//oq26zaLHqjTz24gMuZw64jnTMuRY/10DMJW+LfjXbTKw 5X0O93q9WZmVpFfoJGSpzZtScbh2r3K47nBSsiQE+0ZbGUi0EOCsqW4mjWooiHWa0YPZXy DsBVBKT0IDyHEIhBGrXzksm8LBpG724= Received: from mail-lf1-f70.google.com (mail-lf1-f70.google.com [209.85.167.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-682-q-wUFHjnPcyt20jzjZuscg-1; Mon, 18 Sep 2023 12:55:55 -0400 X-MC-Unique: q-wUFHjnPcyt20jzjZuscg-1 Received: by mail-lf1-f70.google.com with SMTP id 2adb3069b0e04-502d5fe6d50so5325662e87.1 for ; Mon, 18 Sep 2023 09:55:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695056154; x=1695660954; h=content-transfer-encoding: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=YKfdwIDJknHJrYBCaMXNXNEGPYVbR6fXcFC/Nvm3ktI=; b=GeAo+oq2mqIv/UBA0UV0cBI64NDtwTRwn8VsdtJJxaWNpf/OrLBuuQCYYHZlvb+7O9 V1mC0hVIXjyDw96V0OR34JjbDpmm9DaX/ZzKgfLDghS13Ajwafj4Q+YT1z8qa5mGawKM e0KgPVk9hd3+qtipwBzs4XOri4+u2Kk9SCBZiqPl9gD8TAY/r2QcpeKrI9WuAPC9b2mp g2mRw6WShSxmhkMXJIBYs93I9rVxsxAqkcBjdxIlQmG2BDY5NEGCHu9U1Z6rE6KGxMk/ enF3KjvoBINsPLwlJzbC3znMbTMWptbn4eBgMECqyavVgX2UO2OxHYL+FP5vRM/WKaYX 9ang== X-Gm-Message-State: AOJu0YySkqGAPHXqamAjcsaHGnsy779e9Uzhecps3hbeBlhc1Ou8Gawy daq7l8JkX8lgIWPYsAufGK5GWbI4ajngovDts+atQJJbHfJIH1Pvx5CDEBgmgSpp3yN3LEWONy2 PFJsfmlSMzWUo/K9EG5CAw+IIws98z8GVQw== X-Received: by 2002:a05:6512:2148:b0:4fe:5741:9eb9 with SMTP id s8-20020a056512214800b004fe57419eb9mr7237446lfr.49.1695056153862; Mon, 18 Sep 2023 09:55:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH/Yg9g0ZFSU2XWzRkXwOFLAGT8f+WsGfB1LabIvIlpd/nP/+iVOWJq/zCxSU0aJAeLe1wpwox2QFypSWbJSHk= X-Received: by 2002:a05:6512:2148:b0:4fe:5741:9eb9 with SMTP id s8-20020a056512214800b004fe57419eb9mr7237441lfr.49.1695056153430; Mon, 18 Sep 2023 09:55:53 -0700 (PDT) MIME-Version: 1.0 References: <20230917191304.1483576-1-ppalka@redhat.com> <8bece04e-88ef-0a83-8cc0-5f9546b085a0@redhat.com> <91648025-410e-eb5e-a7c5-a230ebea73cd@idea> <1979d189-e20f-ee55-4a89-5b0f4dccc49f@redhat.com> In-Reply-To: <1979d189-e20f-ee55-4a89-5b0f4dccc49f@redhat.com> From: Patrick Palka Date: Mon, 18 Sep 2023 12:55:42 -0400 Message-ID: Subject: Re: [PATCH] c++: optimize tsubst_template_decl for function templates To: Jason Merrill Cc: gcc-patches@gcc.gnu.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-12.8 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 Mon, Sep 18, 2023 at 9:36=E2=80=AFAM Jason Merrill wr= ote: > > On 9/18/23 08:58, Patrick Palka wrote: > > On Sun, 17 Sep 2023, Jason Merrill wrote: > > > >> 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 templa= te, > >>> 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=3Dfalse 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) =3D=3D FIELD_DECL > >>> && TREE_CODE (spec) =3D=3D NONTYPE_ARGUMENT_PACK)); > >>> - if (TREE_CODE (spec) =3D=3D 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 tha= n > >>> - the more obvious `uses_template_parms (spec)' to avoid proble= ms > >>> - with default function arguments. In particular, given > >>> - something like this: > >>> - > >>> - template void f(T t1, T t =3D 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 =3D tmpl; > >>> elt.args =3D args; > >>> @@ -14663,7 +14648,7 @@ tsubst_template_decl (tree t, tree args, > >>> tsubst_flags_t complain, > >>> tree in_decl =3D t; > >>> tree spec; > >>> tree tmpl_args; > >>> - tree full_args; > >>> + tree full_args =3D NULL_TREE; > >>> tree r; > >>> hashval_t hash =3D 0; > >>> @@ -14754,7 +14739,8 @@ tsubst_template_decl (tree t, tree args, > >>> tsubst_flags_t complain, > >>> tree inner =3D decl; > >>> ++processing_template_decl; > >>> if (TREE_CODE (inner) =3D=3D FUNCTION_DECL) > >>> - inner =3D tsubst_function_decl (inner, args, complain, lambda_fn= type); > >>> + inner =3D tsubst_function_decl (inner, args, complain, lambda_fn= type, > >>> + /*use_spec_table=3D*/false); > >>> else > >>> { > >>> if (TREE_CODE (inner) =3D=3D 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) =3D=3D 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=3Dfalse. = */ > >>> + DECL_TI_ARGS (inner) =3D full_args; > >>> + > >>> DECL_TI_TEMPLATE (inner) =3D r; > >>> DECL_TI_ARGS (r) =3D DECL_TI_ARGS (inner); > >>> } > >>> @@ -14822,9 +14813,7 @@ tsubst_template_decl (tree t, tree args, > >>> tsubst_flags_t complain, > >>> if (TREE_CODE (decl) =3D=3D 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 "dou= ble" "" > >>> { 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? > > > > The xfailed dg-bogus directive seems to "consume" the two errors, and > > prevents the dg-error from matching either of them. Before this patch, > > we issued three duplicate errors and so this arrangement worked out > > since the xfailed dg-bogus consumes only two of the errors. I'm not > > sure how to express that we're currently seeing two errors but only wan= t > > one using _both_ dg-error and dg-bogus.. > > Would it work to have a dg-error to consume one error followed by a > dg-bogus for another single error? Unfortunately not, because it seems if we have a dg-error first then it con= sumes all the matching errors on the line, and then a subsequent dg-bogus always succeeds even if there were duplicate errors. > > If not, just add a comment. OK either way. Thanks a lot, will do. > > Jason >