From patchwork Fri Nov 18 21:59:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1705823 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=e7tGsAHk; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NDW224JV5z23mR for ; Sat, 19 Nov 2022 09:00:56 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F3689384D99F for ; Fri, 18 Nov 2022 22:00:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F3689384D99F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1668808855; bh=kKEEISESQXZCORUfQeNifLTDfPkYsqhmq3slFZCZVPQ=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=e7tGsAHkK9X1Bhm0JlMId6R4LmZWTCQtv483eX5IId6EdrxHRuQDC7eGkB7sCpVBE I8TPMQurzp8alyZ1QNfDMdOGrcr7G290RF3ndatam2nb3AxHNQVHd/ez6rtccOmSpN ZtarvJC/bqzZM7Pd9XK8xWBup5lhbWkxdNZDIeBM= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 EB6433853D74 for ; Fri, 18 Nov 2022 21:59:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org EB6433853D74 Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-187-CypVTbM-PYuob2BrtERD2w-1; Fri, 18 Nov 2022 16:59:49 -0500 X-MC-Unique: CypVTbM-PYuob2BrtERD2w-1 Received: by mail-qv1-f69.google.com with SMTP id d8-20020a0cfe88000000b004bb65193fdcso5833774qvs.12 for ; Fri, 18 Nov 2022 13:59:49 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=kKEEISESQXZCORUfQeNifLTDfPkYsqhmq3slFZCZVPQ=; b=bZDHXNmr4XIlTH+0Sh2xpwZaCNrejEE3QkkRPu5cU/jtf9ONSZCMnUvifayd1OsQ3m hOWGXxJtiqgrLbB+rUwT46dwY2oUCNHtQC65h2GUZUtLRWpOmx/XRZy6eW4V1dqND4i8 ADuyDPBi7DHS74xTN9sTdxT2YYPyxdPM0N2sNUma0AwQVcOhhE2FqFB+rPjgzvWRbU9r VrfuLlLWpw34FWoXjMqdLNnx+qIGGFZx8PZv1koS8g2MP3NVYauuEAKdV3YZ+nA3Q8nY Eo0s3Wo8VoDzMeU07bZOA/HdokiiLH/afLhPMHloJzYJbnAw8z1Azk56VV2jhZVlD0aq WRCQ== X-Gm-Message-State: ANoB5pljC+D8Lae95qCPGUAkvPRUk9S3O5ObnggkEHKFrnH2XgmWa0km b9huuSN84F+Lnkds/ENbvUSclmWm8h4ylDHm2xaLmjnqBzLX1YgCtpendaww1JPMspQLWhetBj4 /puxic/GU7GY8E4GjYAJ6+bwmqzG5BXrShobZTcTBubdHO7aEyjylSAensVjS6Y5IlhY= X-Received: by 2002:a05:620a:8019:b0:6fa:5257:9aa7 with SMTP id ee25-20020a05620a801900b006fa52579aa7mr7673344qkb.150.1668808788827; Fri, 18 Nov 2022 13:59:48 -0800 (PST) X-Google-Smtp-Source: AA0mqf4d50nRMFybUv4AjjLhXNBbgnkX0Nbx6FX+y0usI2rlIEDm1DIZmc88g3EaL0I98EtVMyHaRQ== X-Received: by 2002:a05:620a:8019:b0:6fa:5257:9aa7 with SMTP id ee25-20020a05620a801900b006fa52579aa7mr7673324qkb.150.1668808788385; Fri, 18 Nov 2022 13:59:48 -0800 (PST) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id k18-20020a05620a415200b006e54251993esm3255730qko.97.2022.11.18.13.59.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Nov 2022 13:59:47 -0800 (PST) To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH] c++: remove coerce_innermost_template_parms Date: Fri, 18 Nov 2022 16:59:46 -0500 Message-Id: <20221118215946.3621557-1-ppalka@redhat.com> X-Mailer: git-send-email 2.38.1.436.geea7033409 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.7 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_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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Patrick Palka via Gcc-patches From: Patrick Palka Reply-To: Patrick Palka Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" 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? 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