c++: template operator lookup caching
authorNathan Sidwell <nathan@acm.org>
Tue, 25 Aug 2020 19:35:07 +0000 (12:35 -0700)
committerNathan Sidwell <nathan@acm.org>
Wed, 26 Aug 2020 12:26:53 +0000 (05:26 -0700)
commit1f53d8f1d3e7519bd81cc5874e43ed9896cf6180
treeee5325815140f2b204394594cd5c7e108279958a
parentf523aaa039cc0ab59791045a840e4e35f1b1eb24
c++: template operator lookup caching

Jason's fix to retain operator lookups inside dependent lambda
functions turns out to be needed on the modules branch for all
template functions.  Because the context for that lookup no longer
exists in imports.  There were also a couple of shortcomings, which
this patch fixes.

(a) we conflate 'we found nothing' and 'we can redo this at
instantiation time'.  Fixed by making the former produce
error_mark_node.  That needs a fix in name-lookup to know that finding
a binding containing error_mark_node, means 'stop looking' you found
nothing.

(b) we'd continually do lookups for every operator, if nothing needed
to be retained.  Fixed by always caching that information, and then
dealing with it when pushing the bindings.

(c) if what we found was that find by a global namespace lookup, we'd
not cache that.  But that'd cause us to either find decls declared
after the template, potentially hiding those we expected to find.  So
don't do that check.

This still retains only recording on lambdas.  As the comment says, we
could enable for all templates.

gcc/cp/
* decl.c (poplevel): A local-binding tree list holds the name in
TREE_PURPOSE.
* name-lookup.c (update_local_overload): Add id to TREE_PURPOSE.
(lookup_name_1): Deal with local-binding error_mark_node marker.
(op_unqualified_lookup): Return error_mark_node for 'nothing
found'.  Retain global binding, check class binding here.
(maybe_save_operator_binding): Reimplement to always cache a
result.
(push_operator_bindings): Deal with 'ignore' marker.
gcc/testsuite/
* g++.dg/lookup/operator-1.C: New.
* g++.dg/lookup/operator-2.C: New.
gcc/cp/decl.c
gcc/cp/name-lookup.c
gcc/testsuite/g++.dg/lookup/operator-1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/lookup/operator-2.C [new file with mode: 0644]