1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

include what you use.

This reverts commit 443389effc.
This reverts commit d94960f22e.

Inclusion of header files must be explicit.  Every file shall directly
include what is necessary.

https://github.com/include-what-you-use/include-what-you-use says:

> When every file includes what it uses, then it is possible to edit any
> file and remove unused headers, without fear of accidentally breaking
> the upwards dependencies of that file. It also becomes easy to
> automatically track and update dependencies in the source code.

Though we don't use iwyu itself, the principle quoted above is a good
thing that we can agree.

Now that include guards were added to every and all of the headers
inside of our project this changeset does not increase compile time, at
least on my machine.
This commit is contained in:
卜部昌平 2020-04-12 15:42:45 +09:00
parent 4ff3f20540
commit c37a357c13
Notes: git 2020-04-13 16:06:29 +09:00
40 changed files with 57 additions and 21 deletions

View file

@ -3878,6 +3878,7 @@ dir.$(OBJEXT): {$(VPATH)}3/variable.h
dir.$(OBJEXT): {$(VPATH)}3/warning_push.h
dir.$(OBJEXT): {$(VPATH)}3/xmalloc.h
dir.$(OBJEXT): {$(VPATH)}assert.h
dir.$(OBJEXT): {$(VPATH)}builtin.h
dir.$(OBJEXT): {$(VPATH)}backward/2/assume.h
dir.$(OBJEXT): {$(VPATH)}backward/2/attributes.h
dir.$(OBJEXT): {$(VPATH)}backward/2/bool.h
@ -3890,7 +3891,6 @@ dir.$(OBJEXT): {$(VPATH)}backward/2/r_cast.h
dir.$(OBJEXT): {$(VPATH)}backward/2/rmodule.h
dir.$(OBJEXT): {$(VPATH)}backward/2/stdalign.h
dir.$(OBJEXT): {$(VPATH)}backward/2/stdarg.h
dir.$(OBJEXT): {$(VPATH)}builtin.h
dir.$(OBJEXT): {$(VPATH)}config.h
dir.$(OBJEXT): {$(VPATH)}defines.h
dir.$(OBJEXT): {$(VPATH)}dir.c
@ -5416,10 +5416,6 @@ explicit_bzero.$(OBJEXT): {$(VPATH)}3/compiler_is/sunpro.h
explicit_bzero.$(OBJEXT): {$(VPATH)}3/compiler_since.h
explicit_bzero.$(OBJEXT): {$(VPATH)}3/config.h
explicit_bzero.$(OBJEXT): {$(VPATH)}3/dllexport.h
explicit_bzero.$(OBJEXT): {$(VPATH)}3/has/attribute.h
explicit_bzero.$(OBJEXT): {$(VPATH)}3/has/warning.h
explicit_bzero.$(OBJEXT): {$(VPATH)}3/token_paste.h
explicit_bzero.$(OBJEXT): {$(VPATH)}3/warning_push.h
explicit_bzero.$(OBJEXT): {$(VPATH)}config.h
explicit_bzero.$(OBJEXT): {$(VPATH)}explicit_bzero.c
explicit_bzero.$(OBJEXT): {$(VPATH)}missing.h
@ -11782,10 +11778,6 @@ ruby-runner.$(OBJEXT): {$(VPATH)}3/compiler_is/msvc.h
ruby-runner.$(OBJEXT): {$(VPATH)}3/compiler_is/sunpro.h
ruby-runner.$(OBJEXT): {$(VPATH)}3/compiler_since.h
ruby-runner.$(OBJEXT): {$(VPATH)}3/config.h
ruby-runner.$(OBJEXT): {$(VPATH)}3/has/attribute.h
ruby-runner.$(OBJEXT): {$(VPATH)}3/has/warning.h
ruby-runner.$(OBJEXT): {$(VPATH)}3/token_paste.h
ruby-runner.$(OBJEXT): {$(VPATH)}3/warning_push.h
ruby-runner.$(OBJEXT): {$(VPATH)}config.h
ruby-runner.$(OBJEXT): {$(VPATH)}ruby-runner.c
ruby-runner.$(OBJEXT): {$(VPATH)}ruby-runner.h
@ -13089,10 +13081,6 @@ strlcat.$(OBJEXT): {$(VPATH)}3/compiler_is/sunpro.h
strlcat.$(OBJEXT): {$(VPATH)}3/compiler_since.h
strlcat.$(OBJEXT): {$(VPATH)}3/config.h
strlcat.$(OBJEXT): {$(VPATH)}3/dllexport.h
strlcat.$(OBJEXT): {$(VPATH)}3/has/attribute.h
strlcat.$(OBJEXT): {$(VPATH)}3/has/warning.h
strlcat.$(OBJEXT): {$(VPATH)}3/token_paste.h
strlcat.$(OBJEXT): {$(VPATH)}3/warning_push.h
strlcat.$(OBJEXT): {$(VPATH)}config.h
strlcat.$(OBJEXT): {$(VPATH)}missing.h
strlcat.$(OBJEXT): {$(VPATH)}strlcat.c
@ -13106,10 +13094,6 @@ strlcpy.$(OBJEXT): {$(VPATH)}3/compiler_is/sunpro.h
strlcpy.$(OBJEXT): {$(VPATH)}3/compiler_since.h
strlcpy.$(OBJEXT): {$(VPATH)}3/config.h
strlcpy.$(OBJEXT): {$(VPATH)}3/dllexport.h
strlcpy.$(OBJEXT): {$(VPATH)}3/has/attribute.h
strlcpy.$(OBJEXT): {$(VPATH)}3/has/warning.h
strlcpy.$(OBJEXT): {$(VPATH)}3/token_paste.h
strlcpy.$(OBJEXT): {$(VPATH)}3/warning_push.h
strlcpy.$(OBJEXT): {$(VPATH)}config.h
strlcpy.$(OBJEXT): {$(VPATH)}missing.h
strlcpy.$(OBJEXT): {$(VPATH)}strlcpy.c

View file

@ -72,6 +72,7 @@
#include "ruby/3/attr/weakref.h"
#include "ruby/3/cast.h"
#include "ruby/3/config.h"
#include "ruby/3/has/attribute.h"
#include "ruby/3/intern/class.h"
#include "ruby/3/intern/vm.h"
#include "ruby/3/method.h"

View file

@ -31,6 +31,7 @@
#include "ruby/3/dllexport.h"
#include "ruby/3/special_consts.h"
#include "ruby/3/value.h"
#include "ruby/3/warning_push.h"
#include "ruby/assert.h"
#define RB_INT2NUM rb_int2num_inline

View file

@ -27,6 +27,7 @@
*/
#include "ruby/3/config.h"
#include "ruby/3/cast.h"
#include "ruby/3/compiler_since.h"
#include "ruby/3/has/builtin.h"
#include "ruby/3/warning_push.h"

View file

@ -20,6 +20,7 @@
* extension libraries. They could be written in C++98.
* @brief Defines #RUBY3_ATTR_ALLOC_SIZE.
*/
#include "ruby/3/has/attribute.h"
/** Wraps (or simulates) `__attribute__((alloc_size))` */
#if RUBY3_HAS_ATTRIBUTE(alloc_size)

View file

@ -34,6 +34,7 @@
* case it gets vital to know where the inlining happened in the callee.
* See also https://stackoverflow.com/a/21936099
*/
#include "ruby/3/has/attribute.h"
/** Wraps (or simulates) `__attribute__((artificial))` */
#if RUBY3_HAS_ATTRIBUTE(artificial)

View file

@ -21,6 +21,7 @@
* @brief Defines #RUBY3_ATTR_COLD.
*/
#include "ruby/3/compiler_is.h"
#include "ruby/3/has/attribute.h"
/** Wraps (or simulates) `__attribute__((cold))` */
#if RUBY3_COMPILER_IS(SunPro)

View file

@ -20,6 +20,8 @@
* extension libraries. They could be written in C++98.
* @brief Defines #RUBY3_ATTR_CONST.
*/
#include "ruby/3/compiler_since.h"
#include "ruby/3/has/attribute.h"
#include "ruby/3/has/declspec_attribute.h"
/** Wraps (or simulates) `__attribute__((const))` */

View file

@ -22,6 +22,7 @@
*/
#include "ruby/3/has/feature.h"
#include "ruby/3/compiler_is.h"
#include "ruby/3/token_paste.h"
/** @cond INTERNAL_MACRO */
#if ! defined(__cplusplus)

View file

@ -20,6 +20,8 @@
* extension libraries. They could be written in C++98.
* @brief Defines #RUBY3_ATTR_DEPRECATED.
*/
#include "ruby/3/compiler_since.h"
#include "ruby/3/has/attribute.h"
#include "ruby/3/has/c_attribute.h"
#include "ruby/3/has/cpp_attribute.h"
#include "ruby/3/has/declspec_attribute.h"

View file

@ -20,6 +20,8 @@
* extension libraries. They could be written in C++98.
* @brief Defines #RUBY3_ATTR_DIAGNOSE_IF.
*/
#include "ruby/3/has/attribute.h"
#include "ruby/3/warning_push.h"
/** Wraps (or simulates) `__attribute__((diagnose_if))` */
#if RUBY3_COMPILER_BEFORE(Clang, 5, 0, 0)

View file

@ -20,6 +20,7 @@
* extension libraries. They could be written in C++98.
* @brief #RUBY3_ATTR_ENUM_EXTENSIBILITY.
*/
#include "ruby/3/has/attribute.h"
/** Wraps (or simulates) `__attribute__((enum_extensibility))` */
#if RUBY3_HAS_ATTRIBUTE(enum_extensibility)

View file

@ -20,6 +20,7 @@
* extension libraries. They could be written in C++98.
* @brief Defines #RUBY3_ATTR_ERROR.
*/
#include "ruby/3/has/attribute.h"
/** Wraps (or simulates) `__attribute__((error))` */
#if RUBY3_HAS_ATTRIBUTE(error)

View file

@ -21,6 +21,7 @@
* @brief Defines #RUBY3_ATTR_FLAG_ENUM.
* @see https://clang.llvm.org/docs/AttributeReference.html#flag_enum
*/
#include "ruby/3/has/attribute.h"
/** Wraps (or simulates) `__attribute__((flag_enum)` */
#if RUBY3_HAS_ATTRIBUTE(flag_enum)

View file

@ -20,6 +20,8 @@
* extension libraries. They could be written in C++98.
* @brief Defines #RUBY3_ATTR_FORCEINLINE.
*/
#include "ruby/3/compiler_since.h"
#include "ruby/3/has/attribute.h"
/**
* Wraps (or simulates) `__forceinline`. MSVC complains on declarations like

View file

@ -20,6 +20,7 @@
* extension libraries. They could be written in C++98.
* @brief Defines #RUBY3_ATTR_FORMAT.
*/
#include "ruby/3/has/attribute.h"
/** Wraps (or simulates) `__attribute__((format))` */
#if RUBY3_HAS_ATTRIBUTE(format)

View file

@ -20,6 +20,7 @@
* extension libraries. They could be written in C++98.
* @brief Defines #RUBY3_ATTR_MAYBE_UNUSED.
*/
#include "ruby/3/has/attribute.h"
#include "ruby/3/has/c_attribute.h"
#include "ruby/3/has/cpp_attribute.h"

View file

@ -20,6 +20,7 @@
* extension libraries. They could be written in C++98.
* @brief Defines #RUBY3_ATTR_NODISCARD.
*/
#include "ruby/3/has/attribute.h"
#include "ruby/3/has/c_attribute.h"
#include "ruby/3/has/cpp_attribute.h"

View file

@ -61,6 +61,7 @@
* Itanium C++ ABI has zero-cost exception handling), but does impact on
* generated binary size. This is bad.
*/
#include "ruby/3/compiler_since.h"
#include "ruby/3/has/feature.h"
/** Wraps (or simulates) C++11 `noexcept` */

View file

@ -20,6 +20,7 @@
* extension libraries. They could be written in C++98.
* @brief Defines #RUBY3_ATTR_NOINLINE.
*/
#include "ruby/3/has/attribute.h"
#include "ruby/3/has/declspec_attribute.h"
/** Wraps (or simulates) `__declspec(noinline)` */

View file

@ -20,6 +20,7 @@
* extension libraries. They could be written in C++98.
* @brief Defines #RUBY3_ATTR_NONNULL.
*/
#include "ruby/3/has/attribute.h"
/** Wraps (or simulates) `__attribute__((nonnull))` */
#if RUBY3_HAS_ATTRIBUTE(nonnull)

View file

@ -20,6 +20,8 @@
* extension libraries. They could be written in C++98.
* @brief Defines #RUBY3_ATTR_NORETURN.
*/
#include "ruby/3/compiler_since.h"
#include "ruby/3/has/attribute.h"
#include "ruby/3/has/cpp_attribute.h"
#include "ruby/3/has/declspec_attribute.h"

View file

@ -20,6 +20,8 @@
* extension libraries. They could be written in C++98.
* @brief Defines #RUBY3_ATTR_PURE.
*/
#include "ruby/3/compiler_since.h"
#include "ruby/3/has/attribute.h"
#include "ruby/assert.h"
/** Wraps (or simulates) `__attribute__((pure))` */

View file

@ -20,6 +20,9 @@
* extension libraries. They could be written in C++98.
* @brief Defines #RUBY3_ATTR_RESTRICT.
*/
#include "ruby/3/compiler_since.h"
#include "ruby/3/has/attribute.h"
#include "ruby/3/token_paste.h"
/* :FIXME: config.h includes conflicting `#define restrict`. MSVC can be
* detected using `RUBY3_COMPILER_SINCE()`, but Clang & family cannot use

View file

@ -20,6 +20,7 @@
* extension libraries. They could be written in C++98.
* @brief Defines #RUBY3_ATTR_RETURNS_NONNULL.
*/
#include "ruby/3/has/attribute.h"
/** Wraps (or simulates) `__attribute__((returns_nonnull))` */
#if defined(_Ret_nonnull_)

View file

@ -20,6 +20,7 @@
* extension libraries. They could be written in C++98.
* @brief Defines #RUBY3_ATTR_WARNING.
*/
#include "ruby/3/has/attribute.h"
/** Wraps (or simulates) `__attribute__((warning))` */
#if RUBY3_HAS_ATTRIBUTE(warning)

View file

@ -20,6 +20,7 @@
* extension libraries. They could be written in C++98.
* @brief Defines #RUBY3_ATTR_WEAKREF.
*/
#include "ruby/3/has/attribute.h"
/** Wraps (or simulates) `__attribute__((weakref))` */
#if RUBY3_HAS_ATTRIBUTE(weakref)

View file

@ -25,6 +25,9 @@
* public headers. They could be used from C++, and C-style casts could issue
* warnings. Ruby internals are pure C so they should not bother.
*/
#include "ruby/3/compiler_since.h"
#include "ruby/3/has/warning.h"
#include "ruby/3/warning_push.h"
#if ! defined(__cplusplus)
# define RUBY3_CAST(expr) (expr)

View file

@ -27,10 +27,6 @@
#endif
#include "ruby/3/compiler_since.h"
#include "ruby/3/has/warning.h"
#include "ruby/3/has/attribute.h"
#include "ruby/3/warning_push.h"
#include "ruby/3/token_paste.h"
#if defined(__cplusplus)
#/* __builtin_choose_expr and __builtin_types_compatible aren't available

View file

@ -32,6 +32,7 @@
#include "ruby/3/core/rbasic.h"
#include "ruby/3/dllexport.h"
#include "ruby/3/fl_type.h"
#include "ruby/3/token_paste.h"
#include "ruby/3/value.h"
#include "ruby/3/value_type.h"
#include "ruby/defines.h"

View file

@ -21,6 +21,8 @@
* @brief Defines #RUBY3_HAS_ATTRIBUTE.
*/
#include "ruby/3/config.h"
#include "ruby/3/compiler_since.h"
#include "ruby/3/token_paste.h"
/** Wraps (or simulates) `__has_attribute`. */
#if defined(__has_attribute)

View file

@ -21,6 +21,8 @@
* @brief Defines #RUBY3_HAS_BUILTIN.
*/
#include "ruby/3/config.h"
#include "ruby/3/compiler_since.h"
#include "ruby/3/token_paste.h"
/** Wraps (or simulates) `__has_builtin`. */
#if defined(__has_builtin) && ! RUBY3_COMPILER_IS(Intel)

View file

@ -21,6 +21,8 @@
* @brief Defines #RUBY3_HAS_CPP_ATTRIBUTE.
*/
#include "ruby/3/compiler_is.h"
#include "ruby/3/compiler_since.h"
#include "ruby/3/token_paste.h"
/** @cond INTERNAL_MACRO */
#if defined(__has_cpp_attribute)

View file

@ -20,6 +20,8 @@
* extension libraries. They could be written in C++98.
* @brief Defines #RUBY3_HAS_DECLSPEC_ATTRIBUTE.
*/
#include "ruby/3/compiler_since.h"
#include "ruby/3/token_paste.h"
/** Wraps (or simulates) `__has_declspec_attribute`. */
#if defined(__has_declspec_attribute)

View file

@ -22,6 +22,7 @@
*/
#include <assert.h>
#include "ruby/3/has/extension.h"
#include "ruby/3/compiler_since.h"
/** @cond INTERNAL_MACRO */
#if defined(__cplusplus) && defined(__cpp_static_assert)

View file

@ -27,8 +27,10 @@
#endif
#include "ruby/3/compiler_is.h"
#include "ruby/3/compiler_since.h"
#include "ruby/3/has/feature.h"
#include "ruby/3/has/extension.h"
#include "ruby/3/has/attribute.h"
#include "ruby/3/has/declspec_attribute.h"
/**

View file

@ -21,6 +21,9 @@
* @brief Defines #RUBY3_TOKEN_PASTE.
*/
#include "ruby/3/config.h"
#include "ruby/3/compiler_since.h"
#include "ruby/3/has/warning.h"
#include "ruby/3/warning_push.h"
/* :TODO: add your compiler here. There are many compilers that can suppress
* warnings via pragmas, but not all of them accept such things inside of `#if`

View file

@ -44,6 +44,7 @@
* ```
*/
#include "ruby/3/compiler_is.h"
#include "ruby/3/compiler_since.h"
#if RUBY3_COMPILER_SINCE(MSVC, 12, 0, 0)
# /* Not sure exactly when but it seems VC++ 6.0 is a version with it.*/

View file

@ -20,6 +20,7 @@
* extension libraries. They could be written in C++98.
* @brief Defines old #GCC_VERSION_SINCE
*/
#include "ruby/3/compiler_since.h"
#ifndef GCC_VERSION_SINCE
#define GCC_VERSION_SINCE(x, y, z) RUBY3_COMPILER_SINCE(GCC, (x), (y), (z))

View file

@ -26,6 +26,8 @@
* compatibility only.
*/
#include "ruby/3/config.h"
#include "ruby/3/has/warning.h"
#include "ruby/3/warning_push.h"
#if RUBY3_HAS_WARNING("-Wc++11-long-long")
# define HAVE_TRUE_LONG_LONG 1