https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124200
Nathaniel Shead <nshead at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |nshead at gcc dot gnu.org
--- Comment #1 from Nathaniel Shead <nshead at gcc dot gnu.org> ---
The tricky thing about trying to do this lazily is that without actually doing
the loading it will be hard to know actually how many entities we have.
Consider:
// a.H
namespace ns {
inline void foo(int) {}
inline void foo(double) {}
}
// b.H
namespace ns {
inline void foo(double) {}
inline void foo(long) {}
}
// c.C
#include <meta>
namespace ns {
inline void foo(long) {}
inline void foo() {}
}
import "a.H";
import "b.H";
constexpr auto unchecked = std::meta::access_context::unchecked();
static_assert(members_of(^^ns, unchecked).size() == 4);
The static assert should pass, there are a total of four declarations. But if
we just e.g. stored how many declarations there are for each binding_vector we
might get it wrong and return 6, because we don't know that two of those
declarations are actually duplicated and will get merged/discarded.
I don't think there's really any easy way to actually know that (especially in
the context of arbitrarily complex declarations) without just loading the whole
declaration; at least for something by GCC16 I think that's the only approach
that seems feasible to me. It also makes sense to me that if someone is doing
'members_of' on a namespace then we'll probably have to load all the
declaration in that namespace anyway for whatever work they're going to be
doing with that list, so we may as well just do it straight away.
But I'll have more of a think and see if I can see any other approaches. E.g.
maybe we could do "partial" lazy load and just stream the bits needed for the
merge key without the rest of the declaration? But this feels a lot more
complex for not a lot of gain, realistically.