mirror of
git://gcc.gnu.org/git/gcc.git
synced 2025-04-08 18:51:00 +08:00
The internal type-level logical operator traits __and_ and __or_ seem to have high overhead for a couple of reasons: 1. They are drop-in replacements for std::con/disjunction, which are rigidly specified to form a type that derives from the first type argument that caused the overall computation to short-circuit. In practice this inheritance property seems to be rarely needed; usually all we care about is the value of the overall result. 2. Their recursive implementations instantiate O(N) class templates and form an inheritance chain of depth O(N). This patch gets rid of this inheritance property of __and_ and __or_ (which seems to be unneeded in the library except indirectly by std::con/disjunction) which allows us to redefine them non-recursively as alias templates that yield either false_type or true_type via enable_if_t and partial ordering of a pair of function templates (alternatively we could use an equivalent partially specialized class template, but using function templates appears to be slightly more efficient). As for std::con/disjunction, it seems we need to keep implementing them via a recursive class template for sake of the inheritance property. But instead of using inheritance recursion, use a recursive member typedef that gets immediately flattened, so that specializations thereof now have O(1) instead of O(N) inheritance depth. In passing, redefine __not_ as an alias template for consistency with __and_ and __or_, and to remove a layer of indirection. Together these changes have a substantial effect on compile time and memory usage for code that heavily uses these internal type traits. For the following example (which tests constructibility between two compatible 257-element tuple types): #include <tuple> #define M(x) x, x using ty1 = std::tuple<M(M(M(M(M(M(M(M(int)))))))), int>; using ty2 = std::tuple<M(M(M(M(M(M(M(M(int)))))))), long>; static_assert(std::is_constructible_v<ty2, ty1>); memory usage improves ~27% from 440MB to 320MB and compile time improves ~20% from ~2s to ~1.6s (with -std=c++23). libstdc++-v3/ChangeLog: * include/std/type_traits (enable_if, __enable_if_t): Define them earlier. (__detail::__first_t): Define. (__detail::__or_fn, __detail::__and_fn): Declare. (__or_, __and_): Redefine as alias templates in terms of __or_fn and __and_fn. (__not_): Redefine as an alias template. (__detail::__disjunction_impl, __detail::__conjunction_impl): Define. (conjuction, disjunction): Redefine in terms of __disjunction_impl and __conjunction_impl.
…
…
…
…
…
…
…
…
…
…
…
This directory contains the GNU Compiler Collection (GCC). The GNU Compiler Collection is free software. See the files whose names start with COPYING for copying permission. The manuals, and some of the runtime libraries, are under different terms; see the individual source files for details. The directory INSTALL contains copies of the installation information as HTML and plain text. The source of this information is gcc/doc/install.texi. The installation information includes details of what is included in the GCC sources and what files GCC installs. See the file gcc/doc/gcc.texi (together with other files that it includes) for usage and porting information. An online readable version of the manual is in the files gcc/doc/gcc.info*. See http://gcc.gnu.org/bugs/ for how to report bugs usefully. Copyright years on GCC source files may be listed using range notation, e.g., 1987-2012, indicating that every year in the range, inclusive, is a copyrightable year that could otherwise be listed individually.
Description
Languages
C++
31.9%
C
31.3%
Ada
12%
D
6.5%
Go
6.4%
Other
11.5%