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 34B6F384D0F7 for ; Fri, 18 Nov 2022 23:52:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 34B6F384D0F7 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=1668815574; 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=cKTIgnwdR1vvAmjVv/yr8MzR2griymj6DF6oq1Jo6hM=; b=Um2gfJYFWVMDlqKLaieI+t0QCz8chCMXrNfIjmQzzwKbTujSuxm+4/GV1y0/iZmaGtDGVr IhmoZKu/fm3bsG+8iNLFSfrZX1YWm0DBGEAzVxrYVNfMbCOCb0HGNHHJrNI2lTEIBdcx2y 422aqIKwQKmCbgIDwBqwwkIiWf+ljbU= 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_128_GCM_SHA256) id us-mta-32-oAHkYo6OMvqx68QV6norGw-1; Fri, 18 Nov 2022 18:52:53 -0500 X-MC-Unique: oAHkYo6OMvqx68QV6norGw-1 Received: by mail-qk1-f199.google.com with SMTP id h8-20020a05620a284800b006b5c98f09fbso8227649qkp.21 for ; Fri, 18 Nov 2022 15:52:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=cKTIgnwdR1vvAmjVv/yr8MzR2griymj6DF6oq1Jo6hM=; b=raeGqbT0mDdHjhtECbtUzc/kjKUHHO9Ly4GtXZAfv0fONpaFiTzhQnXyVjkxKaMfsT SMImaMc5YqcPmttUw3SFcDdtZNsZS5YHauvDoUWkWgjmhE5Kdbb80GplVu0MavYRxi2F lt5o/8dDCWeDV1KvcP17vYuJcrDyLJ27cVMjbATbAHGnidOxv5QJWYSafvY5Bx65n+SS 5RjKEIX6t4hD0KXn+ogfcFWc0CM6i8jQh+vXNngrfWN7posb+K+xVP/gAp/wvd+wdTge JS084/lLi/WxjoqnnVI/TOqE8CXq8V5PAOeT3//KnnpCrPvXZGlpIuDUX77hykM5J2jf xOyQ== X-Gm-Message-State: ANoB5pn4cuLKllugkduRlNR0AD9m0Yi0EGV8TWPTYtDXcNR/BBaot3Am NSXubiQO637JQ9n2MAUv4qMiVQ1Xd2U4FGjlB5wf1D7O+gcHsIlo+TLvfl7f7oGRNCCqrpHOWjV +UBoFOELioqMWKHtqbg== X-Received: by 2002:a37:495:0:b0:6fa:d2f3:4bfd with SMTP id 143-20020a370495000000b006fad2f34bfdmr7663858qke.178.1668815572874; Fri, 18 Nov 2022 15:52:52 -0800 (PST) X-Google-Smtp-Source: AA0mqf5JLuHaHeGikGokAansWD5mRm4oVq0Unhz33uL53VjiCV1jNUYDU5BJ3eh/nE+56M64BElAxA== X-Received: by 2002:a37:495:0:b0:6fa:d2f3:4bfd with SMTP id 143-20020a370495000000b006fad2f34bfdmr7663842qke.178.1668815572490; Fri, 18 Nov 2022 15:52:52 -0800 (PST) Received: from [192.168.1.137] (130-44-159-43.s15913.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id v10-20020a05620a440a00b006fab416015csm3453002qkp.25.2022.11.18.15.52.50 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 18 Nov 2022 15:52:51 -0800 (PST) Message-ID: Date: Fri, 18 Nov 2022 18:52:50 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.0 Subject: Re: [PATCH] c++: remove coerce_innermost_template_parms To: Patrick Palka , gcc-patches@gcc.gnu.org References: <20221118215946.3621557-1-ppalka@redhat.com> From: Jason Merrill In-Reply-To: <20221118215946.3621557-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=-12.3 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_H2,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 11/18/22 16:59, Patrick Palka wrote: > IIUC the only practical difference between coerce_innermost_template_parms > and the main function coerce_template_parms is that the former takes > a multi-level template parameter list and returns a template argument > vector of the same depth, whereas the latter takes a single-level > template parameter vector and returns a single-level template argument > vector. > > This patch gets rid of the wrapper function and just overloads the > behavior of the main function according to whether 'parms' is a > multi-level template parameter list or a single-level template argument > vector. It turns out we can assume parms and args have the same depth > in the multi-level case, which simplifies the overloading logic. > > Besides the (subjective) simplificatio benefit, another benefit of this > unification is that it avoids a redundant copy of a multi-level 'args'. > Now, we can return new_args directly from c_t_p. (And because of this, > we need to turn new_inner_args into a reference so that updating it also > updates new_args.) > > Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for > trunk? OK. But this doesn't really seem like stage 3 material; let's hold off on further cleanups like this until next stage 1. > gcc/cp/ChangeLog: > > * pt.cc (coerce_template_parms): Salvage part of the function > comment from c_innermost_t_p. Handle parms being a full > template parameter list. > (coerce_innermost_template_parms): Remove. > (lookup_template_class): Use c_t_p instead of c_innermost_t_p. > (finish_template_variable): Likewise. > (tsubst_decl): Likewise. > (instantiate_alias_template): Likewise. > --- > gcc/cp/pt.cc | 92 +++++++++++++++------------------------------------- > 1 file changed, 27 insertions(+), 65 deletions(-) > > diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc > index 0310e38c9b9..2666e455edf 100644 > --- a/gcc/cp/pt.cc > +++ b/gcc/cp/pt.cc > @@ -148,8 +148,6 @@ static void add_pending_template (tree); > static tree reopen_tinst_level (struct tinst_level *); > static tree tsubst_initializer_list (tree, tree); > static tree get_partial_spec_bindings (tree, tree, tree); > -static tree coerce_innermost_template_parms (tree, tree, tree, tsubst_flags_t, > - bool = true); > static void tsubst_enum (tree, tree, tree); > static bool check_instantiated_args (tree, tree, tsubst_flags_t); > static int check_non_deducible_conversion (tree, tree, unification_kind_t, int, > @@ -8827,6 +8825,14 @@ pack_expansion_args_count (tree args) > arguments. If any error occurs, return error_mark_node. Error and > warning messages are issued under control of COMPLAIN. > > + If PARMS represents all template parameters levels, this function > + returns a vector of vectors representing all the resulting argument > + levels. Note that in this case, only the innermost arguments are > + coerced because the outermost ones are supposed to have been coerced > + already. Otherwise, if PARMS represents only (the innermost) vector > + of parameters, this function returns a vector containing just the > + innermost resulting arguments. > + > If REQUIRE_ALL_ARGS is false, argument deduction will be performed > for arguments not specified in ARGS. If REQUIRE_ALL_ARGS is true, > arguments not specified in ARGS must have default arguments which > @@ -8842,8 +8848,6 @@ coerce_template_parms (tree parms, > int nparms, nargs, parm_idx, arg_idx, lost = 0; > tree orig_inner_args; > tree inner_args; > - tree new_args; > - tree new_inner_args; > > /* When used as a boolean value, indicates whether this is a > variadic template parameter list. Since it's an int, we can also > @@ -8864,6 +8868,17 @@ coerce_template_parms (tree parms, > if (args == error_mark_node) > return error_mark_node; > > + bool return_full_args = false; > + if (TREE_CODE (parms) == TREE_LIST) > + { > + if (TMPL_PARMS_DEPTH (parms) > 1) > + { > + gcc_assert (TMPL_PARMS_DEPTH (parms) == TMPL_ARGS_DEPTH (args)); > + return_full_args = true; > + } > + parms = INNERMOST_TEMPLATE_PARMS (parms); > + } > + > nparms = TREE_VEC_LENGTH (parms); > > /* Determine if there are any parameter packs or default arguments. */ > @@ -8961,8 +8976,8 @@ coerce_template_parms (tree parms, > template-id may be nested within a "sizeof". */ > cp_evaluated ev; > > - new_inner_args = make_tree_vec (nparms); > - new_args = add_outermost_template_args (args, new_inner_args); > + tree new_args = add_outermost_template_args (args, make_tree_vec (nparms)); > + tree& new_inner_args = TMPL_ARGS_LEVEL (new_args, TMPL_ARGS_DEPTH (new_args)); > int pack_adjust = 0; > for (parm_idx = 0, arg_idx = 0; parm_idx < nparms; parm_idx++, arg_idx++) > { > @@ -9164,59 +9179,7 @@ coerce_template_parms (tree parms, > SET_NON_DEFAULT_TEMPLATE_ARGS_COUNT (new_inner_args, > TREE_VEC_LENGTH (new_inner_args)); > > - return new_inner_args; > -} > - > -/* Like coerce_template_parms. If PARMS represents all template > - parameters levels, this function returns a vector of vectors > - representing all the resulting argument levels. Note that in this > - case, only the innermost arguments are coerced because the > - outermost ones are supposed to have been coerced already. > - > - Otherwise, if PARMS represents only (the innermost) vector of > - parameters, this function returns a vector containing just the > - innermost resulting arguments. */ > - > -static tree > -coerce_innermost_template_parms (tree parms, > - tree args, > - tree in_decl, > - tsubst_flags_t complain, > - bool require_all_args /* = true */) > -{ > - int parms_depth = TMPL_PARMS_DEPTH (parms); > - int args_depth = TMPL_ARGS_DEPTH (args); > - tree coerced_args; > - > - if (parms_depth > 1) > - { > - coerced_args = make_tree_vec (parms_depth); > - tree level; > - int cur_depth; > - > - for (level = parms, cur_depth = parms_depth; > - parms_depth > 0 && level != NULL_TREE; > - level = TREE_CHAIN (level), --cur_depth) > - { > - tree l; > - if (cur_depth == args_depth) > - l = coerce_template_parms (TREE_VALUE (level), > - args, in_decl, complain, > - require_all_args); > - else > - l = TMPL_ARGS_LEVEL (args, cur_depth); > - > - if (l == error_mark_node) > - return error_mark_node; > - > - SET_TMPL_ARGS_LEVEL (coerced_args, cur_depth, l); > - } > - } > - else > - coerced_args = coerce_template_parms (INNERMOST_TEMPLATE_PARMS (parms), > - args, in_decl, complain, > - require_all_args); > - return coerced_args; > + return return_full_args ? new_args : new_inner_args; > } > > /* Returns true if T is a wrapper to make a C++20 template parameter > @@ -9909,8 +9872,7 @@ lookup_template_class (tree d1, tree arglist, tree in_decl, tree context, > /* Calculate the BOUND_ARGS. These will be the args that are > actually tsubst'd into the definition to create the > instantiation. */ > - arglist = coerce_innermost_template_parms (parmlist, arglist, gen_tmpl, > - complain); > + arglist = coerce_template_parms (parmlist, arglist, gen_tmpl, complain); > > if (arglist == error_mark_node) > /* We were unable to bind the arguments. */ > @@ -10326,7 +10288,7 @@ finish_template_variable (tree var, tsubst_flags_t complain) > tree arglist = TREE_OPERAND (var, 1); > > tree parms = DECL_TEMPLATE_PARMS (templ); > - arglist = coerce_innermost_template_parms (parms, arglist, templ, complain); > + arglist = coerce_template_parms (parms, arglist, templ, complain); > if (arglist == error_mark_node) > return error_mark_node; > > @@ -14962,7 +14924,7 @@ tsubst_decl (tree t, tree args, tsubst_flags_t complain) > /* We're fully specializing a template declaration, so > we need to coerce the innermost arguments corresponding to > the template. */ > - argvec = (coerce_innermost_template_parms > + argvec = (coerce_template_parms > (DECL_TEMPLATE_PARMS (gen_tmpl), > argvec, t, complain)); > if (argvec == error_mark_node) > @@ -21800,8 +21762,8 @@ instantiate_alias_template (tree tmpl, tree args, tsubst_flags_t complain) > if (tmpl == error_mark_node || args == error_mark_node) > return error_mark_node; > > - args = coerce_innermost_template_parms (DECL_TEMPLATE_PARMS (tmpl), > - args, tmpl, complain); > + args = coerce_template_parms (DECL_TEMPLATE_PARMS (tmpl), > + args, tmpl, complain); > > /* FIXME check for satisfaction in check_instantiated_args. */ > if (flag_concepts