Re: RFC: Split into smaller pieces

2016-10-21 Thread Jonathan Wakely

On 13/10/16 18:34 +0100, Jonathan Wakely wrote:

This splits the large (2200 lines)  header into smaller
pieces, so there are separate headers for:

- std::less, std::equal_to etc. (already in their own header)
- std::__invoke (already in its own header)
- std::reference_wrapper (often used on its own, e.g. in )
- std::function (using in  and )

Everything else (std::mem_fn, std::bind, std::not_fn, searchers) stays
in , because we don't actually need them elsewhere in the
library.

Code which doesn't need the whole of  should include the
relevant  header instead.

This means that we don't need to pull the whole of  (and
 and ) into  just because shared_ptr
wants to use reference_wrapper in one place.  This reduces 
from 48kloc to 30kloc!

The patch is compressed because it's quite large, but it's mostly just
moving big blocks of code from  into new headers.

Any objections?


Nobody objected, so I'm doing it, here's the patch.

Tested powerp64le-linux. Committed to trunk.


commit fe1ee3343d9a010bef95634338014a0e79f3c8c0
Author: Jonathan Wakely 
Date:   Wed Oct 12 15:59:23 2016 +0100

Split  into smaller pieces

	* include/Makefile.am: Add  and .
	Order alphabetically.
	* include/Makefile.in: Regenerate.
	* include/bits/refwrap.h: New header.
	(_Maybe_get_result_type,_Weak_result_type_impl, _Weak_result_type)
	(_Reference_wrapper_base_impl, _Reference_wrapper_base)
	(reference_wrapper, ref, cref): Move here from .
	* include/bits/shared_ptr_base.h: Include  and
	 instead of .
	* include/bits/std_function.h: New header.
	(_Maybe_unary_or_binary_function, bad_function_call)
	(__is_location_invariant, _Nocopy_types, _Any_data)
	(_Simple_type_wrapper, _Function_base, _Function_handler, function):
	Move here from .
	* include/bits/unique_ptr.h: Include .
	* include/std/functional: Include new headers and move components to
	them.
	* include/std/future: Include  instead of
	.
	* include/std/mutex: Likewise.
	* include/std/regex: Likewise.
	* src/c++11/compatibility-thread-c++0x.cc: Include .
	* testsuite/20_util/default_delete/48631_neg.cc: Adjust dg-error line.
	* testsuite/20_util/default_delete/void_neg.cc: Likewise.
	* testsuite/20_util/unique_ptr/assign/48635_neg.cc: Adjust dg-error
	lines.
	* testsuite/20_util/unique_ptr/cons/cv_qual_neg.cc: Likewise.
	* testsuite/30_threads/packaged_task/49668.cc: Include .

diff --git a/libstdc++-v3/include/Makefile.am b/libstdc++-v3/include/Makefile.am
index bb4a532..15a164e 100644
--- a/libstdc++-v3/include/Makefile.am
+++ b/libstdc++-v3/include/Makefile.am
@@ -140,6 +140,7 @@ bits_headers = \
 	${bits_srcdir}/random.h \
 	${bits_srcdir}/random.tcc \
 	${bits_srcdir}/range_access.h \
+	${bits_srcdir}/refwrap.h \
 	${bits_srcdir}/regex.h \
 	${bits_srcdir}/regex.tcc \
 	${bits_srcdir}/regex_constants.h \
@@ -152,14 +153,13 @@ bits_headers = \
 	${bits_srcdir}/regex_compiler.tcc \
 	${bits_srcdir}/regex_executor.h \
 	${bits_srcdir}/regex_executor.tcc \
-	${bits_srcdir}/stream_iterator.h \
-	${bits_srcdir}/streambuf_iterator.h \
 	${bits_srcdir}/shared_ptr.h \
 	${bits_srcdir}/shared_ptr_atomic.h \
 	${bits_srcdir}/shared_ptr_base.h \
 	${bits_srcdir}/slice_array.h \
 	${bits_srcdir}/sstream.tcc \
 	${bits_srcdir}/std_abs.h \
+	${bits_srcdir}/std_function.h \
 	${bits_srcdir}/std_mutex.h \
 	${bits_srcdir}/stl_algo.h \
 	${bits_srcdir}/stl_algobase.h \
@@ -186,6 +186,8 @@ bits_headers = \
 	${bits_srcdir}/stl_tree.h \
 	${bits_srcdir}/stl_uninitialized.h \
 	${bits_srcdir}/stl_vector.h \
+	${bits_srcdir}/stream_iterator.h \
+	${bits_srcdir}/streambuf_iterator.h \
 	${bits_srcdir}/streambuf.tcc \
 	${bits_srcdir}/stringfwd.h \
 	${bits_srcdir}/string_view.tcc \
diff --git a/libstdc++-v3/include/bits/refwrap.h b/libstdc++-v3/include/bits/refwrap.h
new file mode 100644
index 000..06948ff
--- /dev/null
+++ b/libstdc++-v3/include/bits/refwrap.h
@@ -0,0 +1,383 @@
+// Implementation of std::reference_wrapper -*- C++ -*-
+
+// Copyright (C) 2004-2016 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// Under Section 7 of GPL version 3, you are granted additional
+// permissions described in the GCC Runtime Library Exception, version
+// 3.1, as published by the Free Software Foundation.
+
+// You should have received a copy of the GNU General Public License and
+// a copy of the GCC Runtime Library Exception along 

Re: RFC: Split into smaller pieces

2016-10-13 Thread Jonathan Wakely

On 13/10/16 19:19 +0100, Jonathan Wakely wrote:

On 13/10/16 18:34 +0100, Jonathan Wakely wrote:

Code which doesn't need the whole of  should include the
relevant  header instead.

This means that we don't need to pull the whole of  (and
 and ) into  just because shared_ptr
wants to use reference_wrapper in one place.  This reduces 
from 48kloc to 30kloc!


With a few additional changes to remove  from other
headers we can get:

old  |  new  | Header
--|---|---
47571 | 30449 | memory
49620 | 32498 | thread
49049 | 30861 | condition_variable
49459 | 31271 | shared_mutex
54215 | 37745 | future  75063 | 68509 | regex

Apart from , which is enormous even without , these
are pretty dramatic improvements.


And to show it's not just line-count that changes, here are the
-ftime-report numbers for including each header in an otherwise empty
file, compiled with -O0:

memory:
TOTAL  :   0.66  0.190.8656342 kB
TOTAL  :   0.41  0.090.4940487 kB

thread:
TOTAL  :   0.73  0.150.9063030 kB
TOTAL  :   0.59  0.110.7147508 kB

condition_variable:
TOTAL  :   0.77  0.150.9363641 kB
TOTAL  :   0.50  0.110.6147360 kB

shared_mutex:
TOTAL  :   0.79  0.140.9463985 kB
TOTAL  :   0.50  0.100.6147705 kB

future:
TOTAL  :   1.18  0.201.4092564 kB
TOTAL  :   0.90  0.171.0978584 kB

regex:
TOTAL  :   1.14  0.241.39100089 kB
TOTAL  :   1.04  0.241.3091322 kB



Re: RFC: Split into smaller pieces

2016-10-13 Thread Jonathan Wakely

Apparently this got spam-filtered and didn't make it to the lists...

On 13/10/16 18:34 +0100, Jonathan Wakely wrote:

This splits the large (2200 lines)  header into smaller
pieces, so there are separate headers for:

- std::less, std::equal_to etc. (already in their own header)
- std::__invoke (already in its own header)
- std::reference_wrapper (often used on its own, e.g. in )
- std::function (using in  and )

Everything else (std::mem_fn, std::bind, std::not_fn, searchers) stays
in , because we don't actually need them elsewhere in the
library.

Code which doesn't need the whole of  should include the
relevant  header instead.

This means that we don't need to pull the whole of  (and
 and ) into  just because shared_ptr
wants to use reference_wrapper in one place.  This reduces 
from 48kloc to 30kloc!

The patch is compressed because it's quite large, but it's mostly just
moving big blocks of code from  into new headers.

Any objections?

* include/Makefile.am: Add  and .
Order alphabetically.
* include/Makefile.in: Regenerate.
* include/bits/refwrap.h: New header.
(_Maybe_get_result_type,_Weak_result_type_impl, _Weak_result_type)
(_Reference_wrapper_base_impl, _Reference_wrapper_base)
(reference_wrapper, ref, cref): Move here from .
* include/bits/shared_ptr_base.h: Include  and
 instead of .
* include/bits/std_function.h: New header.
(_Maybe_unary_or_binary_function, bad_function_call)
(__is_location_invariant, _Nocopy_types, _Any_data)
(_Simple_type_wrapper, _Function_base, _Function_handler, function):
Move here from .
* include/bits/unique_ptr.h: Include .
* include/std/functional: Include new headers and move components to
them.
* include/std/future: Include .
* include/std/memory: Don't include .
* testsuite/20_util/default_delete/48631_neg.cc: Adjust dg-error line.
* testsuite/20_util/default_delete/void_neg.cc: Likewise.
* testsuite/20_util/shared_ptr/thread/default_weaktoshared.cc:
Include .
* testsuite/20_util/shared_ptr/thread/mutex_weaktoshared.cc: Likewise.
* testsuite/20_util/specialized_algorithms/memory_management_tools/
1.cc: Include .
* testsuite/20_util/unique_ptr/assign/48635_neg.cc: Adjust dg-error
lines.
* testsuite/20_util/unique_ptr/assign/cv_qual.cc: Likewise.
* testsuite/20_util/unique_ptr/cons/cv_qual.cc: Likewise.
* testsuite/20_util/unique_ptr/modifiers/cv_qual.cc: Likewise.
* testsuite/30_threads/thread/native_handle/cancel.cc: Include
.





Re: RFC: Split into smaller pieces

2016-10-13 Thread Jonathan Wakely

On 13/10/16 18:34 +0100, Jonathan Wakely wrote:

Code which doesn't need the whole of  should include the
relevant  header instead.

This means that we don't need to pull the whole of  (and
 and ) into  just because shared_ptr
wants to use reference_wrapper in one place.  This reduces 
from 48kloc to 30kloc!


With a few additional changes to remove  from other
headers we can get:

old  |  new  | Header
--|---|---
47571 | 30449 | memory
49620 | 32498 | thread
49049 | 30861 | condition_variable
49459 | 31271 | shared_mutex
54215 | 37745 | future  
75063 | 68509 | regex   


Apart from , which is enormous even without , these
are pretty dramatic improvements.