Skip to content

Commit

Permalink
include what you use.
Browse files Browse the repository at this point in the history
This reverts commit 443389e.
This reverts commit d94960f.

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.
  • Loading branch information
shyouhei committed Apr 13, 2020
1 parent 4ff3f20 commit c37a357
Show file tree
Hide file tree
Showing 40 changed files with 57 additions and 21 deletions.
18 changes: 1 addition & 17 deletions common.mk
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions include/ruby/3/anyargs.h
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions include/ruby/3/arithmetic/int.h
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions include/ruby/3/assume.h
Expand Up @@ -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"

Expand Down
1 change: 1 addition & 0 deletions include/ruby/3/attr/alloc_size.h
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions include/ruby/3/attr/artificial.h
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions include/ruby/3/attr/cold.h
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions include/ruby/3/attr/const.h
Expand Up @@ -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))` */
Expand Down
1 change: 1 addition & 0 deletions include/ruby/3/attr/constexpr.h
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions include/ruby/3/attr/deprecated.h
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions include/ruby/3/attr/diagnose_if.h
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions include/ruby/3/attr/enum_extensibility.h
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions include/ruby/3/attr/error.h
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions include/ruby/3/attr/flag_enum.h
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions include/ruby/3/attr/forceinline.h
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions include/ruby/3/attr/format.h
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions include/ruby/3/attr/maybe_unused.h
Expand Up @@ -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"

Expand Down
1 change: 1 addition & 0 deletions include/ruby/3/attr/nodiscard.h
Expand Up @@ -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"

Expand Down
1 change: 1 addition & 0 deletions include/ruby/3/attr/noexcept.h
Expand Up @@ -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` */
Expand Down
1 change: 1 addition & 0 deletions include/ruby/3/attr/noinline.h
Expand Up @@ -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)` */
Expand Down
1 change: 1 addition & 0 deletions include/ruby/3/attr/nonnull.h
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions include/ruby/3/attr/noreturn.h
Expand Up @@ -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"

Expand Down
2 changes: 2 additions & 0 deletions include/ruby/3/attr/pure.h
Expand Up @@ -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))` */
Expand Down
3 changes: 3 additions & 0 deletions include/ruby/3/attr/restrict.h
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions include/ruby/3/attr/returns_nonnull.h
Expand Up @@ -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_)
Expand Down
1 change: 1 addition & 0 deletions include/ruby/3/attr/warning.h
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions include/ruby/3/attr/weakref.h
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions include/ruby/3/cast.h
Expand Up @@ -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)
Expand Down
4 changes: 0 additions & 4 deletions include/ruby/3/config.h
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions include/ruby/3/core/rdata.h
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions include/ruby/3/has/attribute.h
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions include/ruby/3/has/builtin.h
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions include/ruby/3/has/cpp_attribute.h
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions include/ruby/3/has/declspec_attribute.h
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions include/ruby/3/static_assert.h
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions include/ruby/3/stdalign.h
Expand Up @@ -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"

/**
Expand Down
3 changes: 3 additions & 0 deletions include/ruby/3/token_paste.h
Expand Up @@ -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`
Expand Down
1 change: 1 addition & 0 deletions include/ruby/3/warning_push.h
Expand Up @@ -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.*/
Expand Down
1 change: 1 addition & 0 deletions include/ruby/backward/2/gcc_version_since.h
Expand Up @@ -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))
Expand Down
2 changes: 2 additions & 0 deletions include/ruby/backward/2/long_long.h
Expand Up @@ -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
Expand Down

1 comment on commit c37a357

@shyouhei
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re: compile time, GitHub Actions reports the time on MinGW:

So I'm pretty confident that this does not impact.

Please sign in to comment.