Skip to content

More improvements of functor implementation

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

Reduce the amount of memory consumed by the compiler when compiling functors:

  • Implement >= and > in terms of <= and < to reduce the number of types required
  • Move PreparedFunctor to internal prepared_type to clarify it is an internal type not to be used by 'other code'
  • Move prepared call into prepared_xxx functions to simplify argument forwarding
  • Move optional handling of prepared functors to prepared wrapper to reduce the number of places where this has to be dealt with
  • 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