Skip to content

More improvements of functor implementation

Gerhard Raven requested to merge tweak-functors-3 into 2024-patches

Follow up to !4012: significantly reduce the amount of memory consumed by the compiler when compiling functors.

  • Replace the non-trivial recursive chain implementation with a very neat (local!) binary right-fold expression, which avoids generating nested template instances. This changes the chain implementation from being one of the most complicated bits of code to being (almost) the simplest.
  • Pass operators by value instead of by type so we can do constant propagation and avoid promoting constants to the NumericalValue functor, and instead bind them directly to the operator, simplifying the type generated for binary expressions such as M < 1600 by effectively changing them to unary predicates ( in effect, change M < 1600 into (the logical equivalent to) (<1600) @ M instead of < ( M, NumericalValue(1600) ).
  • Prefer variadic lambda capture (when available) over capturing a std::tuple to reduce the compile time overhead of std::tuple (see here for more information).
  • Introduce Tuplet - an extremely minimal std::tuple replacement implemented as a lambda with variadic capture . It only support apply, but if that is all that is needed, it is a drop-in replacement. It requires much less resources to compile than std::tuple!
  • Use Tuplet (instead of std::tuple) to carry the payload of composed functors (when available).
  • prefer apply with (local) lambda over explicit helpers with std::index_sequence<I...> arguments
  • fix (expensive) copy in RecSummary functor
Edited by Gerhard Raven

Merge request reports