]> gcc.gnu.org Git - gcc.git/commit
c++: redundant targ coercion for var/alias tmpls
authorPatrick Palka <ppalka@redhat.com>
Wed, 19 Jul 2023 20:10:20 +0000 (16:10 -0400)
committerPatrick Palka <ppalka@redhat.com>
Wed, 19 Jul 2023 20:10:20 +0000 (16:10 -0400)
commit92d1425ca7804000cfe8aa635cf363a87d362d75
treef294fbdb70576dac9c2f1a9c98e205d9dde290d4
parent01f6e8b013237041adeac370f8d229aea6304591
c++: redundant targ coercion for var/alias tmpls

When stepping through the variable/alias template specialization code
paths, I noticed we perform template argument coercion twice: first from
lookup_template_variable / instantiate_alias_template and again from
tsubst_decl (during instantiate_template).  It'd be nice to avoid this
redundant second coercion.

It turns out this coercion in tsubst_decl could be safely elided whenever
fully specializing a primary variable/alias template, because we can rely
on lookup_template_variable / instantiate_alias_template to already have
coerced the arguments.

The only other situation to consider seems to be when fully specializing
a partial variable template specialization (from instantiate_template),
in which case the passed 'args' are the (already coerced) arguments
relative to the partial template, and the resulting 'argvec' are the
(uncoerced) arguments relative to the primary template, so coercion is
still necessary.  But computing 'argvec' here is only really necessary
in order to look up (and insert into) the specializations table.  And
instantiate_template already performs a lookup, so if we just made it
register the resulting specialization too then we could avoid having to
compute 'argvec' when called from instantiate_template, which in turns
means we could avoid the coercion altogether.  This patch implements
this approach.

gcc/cp/ChangeLog:

* pt.cc (tsubst_function_decl): Add defaulted 'use_spec_table'
flag parameter.  Don't look up or insert into the specializations
table if 'use_spec_table' is false.
(tsubst_decl): Add defaulted 'use_spec_table' flag parameter.
Check for error_mark_node.
<case FUNCTION_DECL>: Pass 'use_spec_table' to
tsubst_function_decl.
<case TYPE/VAR_DECL>: Don't call coerce_template_parms.
Don't look up or insert into the specializations table if
'use_spec_table' is false.  Exit earlier if the substituted
type is erroneous and we're not complaining, and do so for
alias specializations as well.
(instantiate_template): Pass false as 'use_spec_table'
to tsubst_decl.  Call register_specialization afterwards.
gcc/cp/pt.cc
This page took 0.057232 seconds and 5 git commands to generate.