llvm-project/libcxx/include
Eric Fiselier 45c4d45ead Teach __hash_table how to handle unordered_map's __hash_value_type.
This patch is fairly large and contains a number of changes. The main change
is teaching '__hash_table' how to handle '__hash_value_type'. Unfortunately
this change is a rampant layering violation, but it's required to make
unordered_map conforming without re-writing all of __hash_table.
After this change 'unordered_map' can delegate to '__hash_table' in almost all cases.

The major changes found in this patch are:

  * Teach __hash_table to differentiate between the true container value type
    and the node value type by introducing the "__container_value_type" and
    "__node_value_type" typedefs. In the case of unordered_map '__container_value_type'
    is 'pair<const Key, Value>' and '__node_value_type' is '__hash_value_type'.
    
  * Switch almost all overloads in '__hash_table' previously taking 'value_type'
    (AKA '__node_value_type) to take  '__container_value_type' instead. Previously
    'pair<K, V>' would be implicitly converted to '__hash_value_type<K, V>' because
    of the function signature.
    
  * Add '__get_key', '__get_value', '__get_ptr', and '__move' static functions to
    '__key_value_types'. These functions allow '__hash_table' to unwrap
    '__node_value_type' objects into '__container_value_type' and its sub-parts.

  * Pass  '__hash_value_type::__value_'  to 'a.construct(p, ...)' instead of
    '__hash_value_type' itself. The C++14 standard requires that 'a.construct()'
    and 'a.destroy()' are only ever instantiated for the containers value type.

  * Remove '__hash_value_type's constructors and destructors. We should never
    construct an instance of this type.
    (TODO this is UB but we already do it in plenty of places).
  
  * Add a generic "try-emplace" function to '__hash_table' called
    '__emplace_unique_key_args(Key const&, Args...)'.

  
The following changes were done as cleanup:

  * Introduce the '_LIBCPP_CXX03_LANG' macro to be used in place of
    '_LIBCPP_HAS_NO_VARIADICS' or '_LIBCPP_HAS_NO_RVALUE_REFERENCE'.
    
  * Cleanup C++11 only overloads that assume an incomplete C++11 implementation.
    For example this patch removes the __construct_node overloads that do
    manual pack expansion.
    
  * Forward 'unordered_map::emplace' to '__hash_table' and remove dead code
    resulting from the change. This includes almost all
    'unordered_map::__construct_node' overloads.


The following changes are planed for future revisions:

  * Fix LWG issue #2469 by delegating 'unordered_map::operator[]' to use
    '__emplace_unique_key_args'.
    
  * Rewrite 'unordered_map::try_emplace' in terms of '__emplace_unique_key_args'.
  
  * Optimize '__emplace_unique' to call '__emplace_unique_key_args' when possible.
    This prevent unneeded allocations when inserting duplicate entries.


The additional follow up work needed after this patch:

  * Respect the lifetime rules for '__hash_value_type' by actually constructing it.
  * Make '__insert_multi' act similar to '__insert_unique' for objects of type
    'T&' and 'T const &&' with 'T = __container_value_type'.
  
  

llvm-svn: 260514
2016-02-11 12:25:27 +00:00
..
experimental Left a file out of r259014 2016-01-28 04:15:35 +00:00
ext Recommit r260012 - Cleanup node-type handling in the unordered containers. 2016-02-10 20:46:23 +00:00
support Add initial support for the MUSL C library. 2015-11-09 10:21:04 +00:00
CMakeLists.txt [libcxx] Capture configuration information when installing the libc++ headers 2015-10-13 22:12:02 +00:00
__bit_reference Get tests running with warnings. Fix warnings in headers and tests 2015-02-05 20:28:37 +00:00
__config Teach __hash_table how to handle unordered_map's __hash_value_type. 2016-02-11 11:59:44 +00:00
__config_site.in Add initial support for the MUSL C library. 2015-11-09 10:21:04 +00:00
__debug Print log/error messages on stderr, not stdout 2015-03-10 07:57:43 +00:00
__functional_03 [libcxx] Fix PR23589: std::function doesn't recognize null pointer to varargs function. 2015-08-18 19:41:51 +00:00
__functional_base Fix a corner case that involved calling rethrow_if_nested with a type that had a deleted operator&. Added a test to catch this as well. Thanks to Ville for the heads-up. 2015-12-14 18:01:56 +00:00
__functional_base_03 [libcxx] Rewrite C++03 __invoke. 2015-08-26 20:15:02 +00:00
__hash_table Teach __hash_table how to handle unordered_map's __hash_value_type. 2016-02-11 11:59:44 +00:00
__locale Use libcxx's default rune table with the Musl C library. 2015-11-24 10:24:54 +00:00
__mutex_base Cleanup: move visibility/linkage attributes to the first declaration. 2015-11-07 01:22:13 +00:00
__nullptr Factor definition of std::nullptr_t out of <cstddef> into a header that can also be used by <stddef.h>. 2015-10-08 20:34:11 +00:00
__refstring Fix some -Wundef issues. 2015-02-05 02:34:59 +00:00
__split_buffer Cleanup: move visibility/linkage attributes to the first declaration. 2015-11-07 01:22:13 +00:00
__sso_allocator Handle function name conflicts in _LIBCPP_MSVCRT mode 2015-02-13 22:15:32 +00:00
__std_stream Enable and fix warnings during the build. 2015-07-18 20:40:46 +00:00
__tree First half of LWG#2354: 'Unnecessary copying when inserting into maps with braced-init syntax' 2016-01-05 19:32:41 +00:00
__tuple [libcxx] LWG2485: get() should be overloaded for const tuple&&. Patch from K-Ballo. 2015-12-18 00:36:55 +00:00
__undef___deallocate Handle function name conflicts in _LIBCPP_MSVCRT mode 2015-02-13 22:15:32 +00:00
__undef_min_max Fix-it suggestion for fixing min or max defines on Windows. 2013-11-15 23:41:01 +00:00
algorithm Fix PR#25973 : 'basic_string::assign(InputIt, InputIt) doesn't provide the strong exception safety guarantee'. This turned out to be a pervasive problem in <string>, which required a fair amount of rework. Add in an optimization for when iterators provide noexcept increment/comparison/assignment/dereference (which covers many of the iterators in libc++). Reviewed as http://reviews.llvm.org/D15862 2016-01-13 21:54:34 +00:00
array [libcxx] LWG2485: get() should be overloaded for const tuple&&. Patch from K-Ballo. 2015-12-18 00:36:55 +00:00
atomic Fix various GCC mis-configurations for newer versions. 2015-12-15 00:32:21 +00:00
bitset Add 3 more missing inline/visibility attributes. 2015-12-09 22:32:36 +00:00
cassert
ccomplex
cctype Split <ctype.h> out of <cctype>. 2015-10-08 20:36:30 +00:00
cerrno Split <errno.h> out of <cerrno>. 2015-10-08 20:37:11 +00:00
cfenv Fix incorrect file header. This is <cfenv> not <cctype>. 2015-10-08 21:17:21 +00:00
cfloat Split <float.h> out of <cfloat>. 2015-10-08 20:37:44 +00:00
chrono Last bit of P0006; mark it as complete 2015-11-30 05:39:30 +00:00
cinttypes Split <inttypes.h> out of <cinttypes>. 2015-10-08 20:38:53 +00:00
ciso646
climits
clocale Make support for thread-unsafe C functions optional. 2015-06-24 08:44:38 +00:00
cmath Split <math.h> out of <cmath>. 2015-10-08 20:40:34 +00:00
codecvt Update synopsis in <locale> to match LWG Issue 2229. No code change 2013-08-27 14:22:13 +00:00
complex Implement literal suffixes for compled 2013-10-05 21:19:49 +00:00
complex.h PR25118: move system_header pragma before uses of include_next to avoid extension warnings for people finding libc++ headers via -I paths. 2015-10-09 00:26:50 +00:00
condition_variable Cleanup: move visibility/linkage attributes to the first declaration. 2015-11-07 01:22:13 +00:00
csetjmp Split <setjmp.h> out of <csetjmp>. 2015-10-08 20:41:26 +00:00
csignal
cstdarg
cstdbool
cstddef PR25118: move system_header pragma before uses of include_next to avoid extension warnings for people finding libc++ headers via -I paths. 2015-10-09 00:26:50 +00:00
cstdint
cstdio Split <stdio.h> out of <cstdio>. 2015-10-09 01:29:09 +00:00
cstdlib Split <stdlib.h> out of <cstdlib>. 2015-10-09 01:41:45 +00:00
cstring Fix overload sets of strchr, strpbrk, strrchr, memchr and strstr from 2016-02-10 00:59:02 +00:00
ctgmath
ctime Make support for thread-unsafe C functions optional. 2015-06-24 08:44:38 +00:00
ctype.h PR25118: move system_header pragma before uses of include_next to avoid extension warnings for people finding libc++ headers via -I paths. 2015-10-09 00:26:50 +00:00
cwchar Fix overload sets of strchr, strpbrk, strrchr, memchr and strstr from 2016-02-10 00:59:02 +00:00
cwctype Split <wctype.h> out of <cwctype>. 2015-10-09 19:57:37 +00:00
deque Add static_assert to set/multiset/map/multimap/forward_list/deque that the allocator's value_type match the container's value_type. vector/unordered/list/string already do this. Add tests for all the containers to verify this. 2015-11-26 01:24:04 +00:00
errno.h Cleanup foo.h headers and __config to work in C 2015-11-06 06:30:12 +00:00
exception Fix a corner case that involved calling rethrow_if_nested with a type that had a deleted operator&. Added a test to catch this as well. Thanks to Ville for the heads-up. 2015-12-14 18:01:56 +00:00
float.h Cleanup foo.h headers and __config to work in C 2015-11-06 06:30:12 +00:00
forward_list Fix broken commit r258888. I missed adding two pointer conversions 2016-01-27 00:49:20 +00:00
fstream Add option to disable access to the global filesystem namespace. 2015-03-12 15:44:39 +00:00
functional Fix invalid casts in <functional>. 2016-02-10 21:53:28 +00:00
future Cleanup: move visibility/linkage attributes to the first declaration. 2015-11-07 01:22:13 +00:00
initializer_list Apply constexpr to initializer_list for c++1y. 2013-08-26 20:11:32 +00:00
inttypes.h Cleanup foo.h headers and __config to work in C 2015-11-06 06:30:12 +00:00
iomanip Implement LWG #2344: quoted()'s interaction with padding is unclear. I think that anyone using quoted with padding is really confused, but it should work the way the rest of iostreams works. 2014-03-07 21:45:32 +00:00
ios Implement P0004R1 'Remove Deprecated iostreams aliases' 2015-10-29 05:43:30 +00:00
iosfwd Revert: Revert r227804: Use fseek/ftell instead of fseeko/ftello when Newlib is the libc 2015-02-03 15:34:17 +00:00
iostream Make the presence of stdin and stdout optional. 2015-03-26 14:35:46 +00:00
istream Revert "Remove visibility attributes from out-of-class method definitions in iostreams." 2016-01-08 19:21:02 +00:00
iterator Fix PR#25973 : 'basic_string::assign(InputIt, InputIt) doesn't provide the strong exception safety guarantee'. This turned out to be a pervasive problem in <string>, which required a fair amount of rework. Add in an optimization for when iterators provide noexcept increment/comparison/assignment/dereference (which covers many of the iterators in libc++). Reviewed as http://reviews.llvm.org/D15862 2016-01-13 21:54:34 +00:00
limits [WebAssembly] Set std::numeric_limits's traps field for WebAssembly. 2016-01-13 16:32:00 +00:00
list Remove unsafe "__as_link()" cast member function. 2016-01-04 03:27:52 +00:00
locale Cleanup: move visibility/linkage attributes to the first declaration. 2015-11-07 01:22:13 +00:00
map First half of LWG#2354: 'Unnecessary copying when inserting into maps with braced-init syntax' 2016-01-05 19:32:41 +00:00
math.h PR25118: move system_header pragma before uses of include_next to avoid extension warnings for people finding libc++ headers via -I paths. 2015-10-09 00:26:50 +00:00
memory Preemptively disable unsigned integer sanitization in 32 and 64 bit versions of __murmur2_or_cityhash. This lets people use the unsigned integer overflow checker in UBSAN w/o getting hits from libc++'s hash code (where the unsigned integer overflow is legal and deliberate)> Patch by @danielaustin. Reviewed as: http://reviews.llvm.org/D15973 2016-01-11 19:27:10 +00:00
module.modulemap Remove __config module to avoid #include cycle when libc headers include libc++'s <foo.h> headers. 2015-10-13 22:13:33 +00:00
mutex Do not include pthread.h and sched.h when threads are disabled 2015-08-27 17:47:34 +00:00
new [libcxx] Rework sized delete. 2015-05-19 02:03:22 +00:00
numeric [libcxx] Fix use of operator comma where the types can be user defined 2014-10-27 19:28:20 +00:00
ostream Revert "Remove visibility attributes from out-of-class method definitions in iostreams." 2016-01-08 19:21:02 +00:00
queue Move the default template arguments into the forward declarations for the container adapters: stack and queue. References PR#22605. 2015-02-18 17:51:56 +00:00
random Cleanup: move visibility/linkage attributes to the first declaration. 2015-11-07 01:22:13 +00:00
ratio Missing file from last commit 2015-11-30 05:04:48 +00:00
regex re.results.form: Format out-of-range subexpression references as null 2016-02-03 19:30:20 +00:00
scoped_allocator Fix LWG#2476: scoped_allocator_adaptor is not assignable 2015-10-25 19:52:47 +00:00
set Add static_assert to set/multiset/map/multimap/forward_list/deque that the allocator's value_type match the container's value_type. vector/unordered/list/string already do this. Add tests for all the containers to verify this. 2015-11-26 01:24:04 +00:00
setjmp.h Cleanup foo.h headers and __config to work in C 2015-11-06 06:30:12 +00:00
shared_mutex Implement N4508: shared_mutex. Reviewed as http://reviews.llvm.org/D10480 2015-06-30 14:04:14 +00:00
sstream Revert "Remove visibility attributes from out-of-class method definitions in iostreams." 2016-01-08 19:21:02 +00:00
stack Move the default template arguments into the forward declarations for the container adapters: stack and queue. References PR#22605. 2015-02-18 17:51:56 +00:00
stddef.h PR25118: move system_header pragma before uses of include_next to avoid extension warnings for people finding libc++ headers via -I paths. 2015-10-09 00:26:50 +00:00
stdexcept Fix unused private field warning in stdexcept after r207695. 2015-02-05 07:40:48 +00:00
stdio.h Split <stdio.h> out of <cstdio>. 2015-10-09 01:29:09 +00:00
stdlib.h Cleanup foo.h headers and __config to work in C 2015-11-06 06:30:12 +00:00
streambuf Revert "Remove visibility attributes from out-of-class method definitions in iostreams." 2016-01-08 19:21:02 +00:00
string Fix PR#25973 : 'basic_string::assign(InputIt, InputIt) doesn't provide the strong exception safety guarantee'. This turned out to be a pervasive problem in <string>, which required a fair amount of rework. Add in an optimization for when iterators provide noexcept increment/comparison/assignment/dereference (which covers many of the iterators in libc++). Reviewed as http://reviews.llvm.org/D15862 2016-01-13 21:54:34 +00:00
string.h Fix overload sets of strchr, strpbrk, strrchr, memchr and strstr from 2016-02-10 00:59:02 +00:00
strstream No functionality change at this time. I've split _LIBCPP_VISIBLE up into two flags: _LIBCPP_TYPE_VIS and _LIBCPP_FUNC_VIS. This is in preparation for taking advantage of clang's new __type_visibility__ attribute. 2013-03-06 23:30:19 +00:00
system_error Fix most GCC warnings during build. Only -Wattribute left. 2015-08-28 07:02:42 +00:00
tgmath.h
thread Cleanup: move visibility/linkage attributes to the first declaration. 2015-11-07 01:22:13 +00:00
tuple [libcxx] LWG2485: get() should be overloaded for const tuple&&. Patch from K-Ballo. 2015-12-18 00:36:55 +00:00
type_traits Teach __hash_table how to handle unordered_map's __hash_value_type. 2016-02-11 11:59:44 +00:00
typeindex Nico Rieck: this patch series fixes visibility issues on Windows as explained in <http://lists.cs.uiuc.edu/pipermail/cfe-dev/2013-August/031214.html>. 2013-08-12 18:38:34 +00:00
typeinfo RTTI Uniqueness: remove __name_for_load function. 2014-04-03 09:12:38 +00:00
unordered_map Teach __hash_table how to handle unordered_map's __hash_value_type. 2016-02-11 12:25:27 +00:00
unordered_set Implement the first part of N4258: 'Cleaning up noexcept in the Library'. This patch deals with swapping containers, and implements a more strict noexcept specification (a conforming extension) than the standard mandates. 2015-07-13 20:04:56 +00:00
utility [libcxx] Fix LWG Issue #2367 - Fixing std::tuple and std::pair's default constructors. 2015-12-23 08:20:26 +00:00
valarray Mark declarations of externally instantiated functions as inline so GCC doesn't complain. 2015-12-15 01:41:41 +00:00
vector Cleanup: move visibility/linkage attributes to the first declaration. 2015-11-07 01:22:13 +00:00
wchar.h Fix overload sets of strchr, strpbrk, strrchr, memchr and strstr from 2016-02-10 00:59:02 +00:00
wctype.h Split <wctype.h> out of <cwctype>. 2015-10-09 19:57:37 +00:00