https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125179

--- Comment #6 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Patrick Palka <[email protected]>:

https://gcc.gnu.org/g:c8498d405a5abb276caa06f6a8952aa26637f1db

commit r17-346-gc8498d405a5abb276caa06f6a8952aa26637f1db
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]>

Reply via email to