From bfa3e33372ddd1290ca9b9284b694dfc2c111f75 Mon Sep 17 00:00:00 2001 From: Andreas Buhr Date: Thu, 7 Aug 2025 13:07:50 +0200 Subject: [PATCH] Reduce compilation time by using SkipParser when determining attribute type. When using a large parser, the whole tree of parsers in instantiated with the skip (whitespace) parser used. Then, it was instantiated again without a skip parser, just to determine the attribute type. This patch changes the code so the attribute type is determined *with* the skip parser. That way, the number of template instantiations required are halved for some use cases. With gcc 14.2, the instantiations without the skip parser even ended up in the binary. In that case, this patch reduces binary size. This is most likely a compiler bug, as the usage is in decltype(). --- include/boost/parser/parser.hpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/include/boost/parser/parser.hpp b/include/boost/parser/parser.hpp index 79052de8..23efefeb 100644 --- a/include/boost/parser/parser.hpp +++ b/include/boost/parser/parser.hpp @@ -374,7 +374,10 @@ namespace boost { namespace parser { template using print_type = typename print_t::type; - template + struct null_parser + {}; + + template struct attribute_impl; // Utility types. @@ -1466,9 +1469,6 @@ namespace boost { namespace parser { uint32_t(flags::in_apply_parser); } - struct null_parser - {}; - struct skip_skipper { template< @@ -2541,7 +2541,7 @@ namespace boost { namespace parser { detail::skip(first, last, skip, flags); using attr_t = typename detail::attribute_impl< BOOST_PARSER_SUBRANGE, Sentinel>, - Parser>::type; + Parser, SkipParser>::type; try { attr_t attr_ = parser(first, last, context, skip, flags, success); @@ -9671,7 +9671,7 @@ namespace boost { namespace parser { } namespace detail { - template + template struct attribute_impl { using parser_type = typename Parser::parser_type; @@ -9694,7 +9694,7 @@ namespace boost { namespace parser { std::declval(), std::declval(), std::declval(), - detail::null_parser{}, + SkipParser{}, detail::flags::gen_attrs, std::declval())); };