https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125179
--- Comment #8 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The releases/gcc-16 branch has been updated by Patrick Palka <[email protected]>: https://gcc.gnu.org/g:64da98bd33730cb961f5543a9eed2cc160d0f387 commit r16-8877-g64da98bd33730cb961f5543a9eed2cc160d0f387 Author: Patrick Palka <[email protected]> Date: Tue May 5 20:30:50 2026 -0400 c++/reflection: rewrite and memoize consteval_only_p [PR125179] The TU from this PR exhibits a 40x compile-time slowdown with -freflection vs without, all due to consteval_only_p which happens to be quite slow on large intertwined classes due to its recursive walking of TYPE_FIELDS. This patch firstly rewrites the predicate to use direct recursion instead of cp_walk_tree so that it's easier to reason about and more closely mirrors its standard definition at [basic.types.general]/12. This patch also makes the recursive part of the predicate tri-state, where the third 'unknown' state corresponds to seeing an incomplete class type whose consteval-only-ness we don't yet know. Finally this patch caches the result of the predicate for class types when the result is known. When the result is unknown (due to an incomplete constituent type) then we don't cache so that a subsequent call to the predicate can try again. With this patch compile time for said TU is now 1.1x with -freflection instead of 40x. PR c++/125179 gcc/cp/ChangeLog: * reflect.cc: (consteval_only_type_r): Remove this cp_walk_tree callback and replace with ... (consteval_only_walker): ... this recursive memoized implementation. (consteval_only_p): Define in terms of consteval_only_walker. Reviewed-by: Jakub Jelinek <[email protected]> Reviewed-by: Jason Merrill <[email protected]> (cherry picked from commit c8498d405a5abb276caa06f6a8952aa26637f1db)
