]> gcc.gnu.org Git - gcc.git/commit
c++: remove optimize_specialization_lookup_p
authorPatrick Palka <ppalka@redhat.com>
Thu, 6 Oct 2022 14:04:52 +0000 (10:04 -0400)
committerPatrick Palka <ppalka@redhat.com>
Thu, 6 Oct 2022 14:04:52 +0000 (10:04 -0400)
commit09df0d8b14dda66c5159a1b2cf85b73f26282152
tree9758930d46b0e4aae5170aaf5343e542f89f46c1
parent3ec926d36fbf7cb3ff45759471139f3a71d1c4de
c++: remove optimize_specialization_lookup_p

Roughly speaking, optimize_specialization_lookup_p returns true for a
non-template member function of a class template, e.g.

  template<class T> struct A { int f(); };

The idea behind the optimization guarded by this predicate is that if
we want to look up the specialization A<T>::f [with T=int], then we can
just do a name lookup for f in A<int> and avoid having to add a
spec_entry for f in the decl_specializations table.

But the benefit of this optimization seems questionable because in
order to do the name lookup we first need to look up A<T> [with T=int]
in the type_specializations table, which is as expensive as the
decl_specializations lookup we're avoiding.  And according to some
experiments (using stdc++.h, range-v3 and libstdc++ tests) the compiler
is slightly (<1%) _faster_ if we disable this optimization.

Additionally, this optimization means we won't record an explicit
specialization in decl_specializations for such a template either, which
is an unfortunate inconsistency that apparently breaks the below modules
testcase.

So since this optimization doesn't improve performance, and complicates
the explicit specialization story which causes issues with modules, this
patch proposes to remove it.

gcc/cp/ChangeLog:

* pt.cc (optimize_specialization_lookup_p): Remove.
(retrieve_specialization): Assume the above returns false
and simplify accordingly.
(register_specialization): Likewise.

gcc/testsuite/ChangeLog:

* g++.dg/modules/indirect-3_b.C: Expect that the entity
foo::TPL<0>::frob is tagged as a specialization instead
of as a declaration.
* g++.dg/modules/tpl-spec-8_a.H: New test.
* g++.dg/modules/tpl-spec-8_b.C: New test.
gcc/cp/pt.cc
gcc/testsuite/g++.dg/modules/indirect-3_b.C
gcc/testsuite/g++.dg/modules/tpl-spec-8_a.H [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/tpl-spec-8_b.C [new file with mode: 0644]
This page took 0.059813 seconds and 6 git commands to generate.