From 01d3211c9ab5f35a8da4785c4b689542ca09aa71 Mon Sep 17 00:00:00 2001 From: Alexandre Ferrando Date: Thu, 7 Nov 2019 20:34:36 +0100 Subject: [PATCH 1/8] src: cleanup unused headers Node codebase has evolved a lot in the more than 10 years of its existence. As more features (and code) have been added, changed, removed, it's sometimes hard to keep track of what gets used and what not. This commits attempts to clean some of those potentially left-over headers using suggestions from include-what-you-use Refs: #27531 --- src/api/encoding.cc | 1 - src/api/utils.cc | 2 -- src/async_wrap.cc | 1 - src/connect_wrap.cc | 10 +++++++--- src/connect_wrap.h | 9 +++++++-- src/connection_wrap.h | 6 +++++- src/debug_utils.cc | 2 -- src/env.cc | 1 - src/fs_event_wrap.cc | 1 - src/handle_wrap.cc | 1 - src/js_stream.cc | 1 - src/js_stream.h | 9 ++++++++- src/module_wrap.h | 4 +++- src/node_binding.h | 11 ++++++++--- src/node_buffer.cc | 1 - src/node_errors.h | 2 -- src/node_watchdog.h | 5 ++++- src/stream_wrap.h | 1 - src/string_decoder-inl.h | 1 - src/tracing/agent.h | 6 +++++- src/udp_wrap.h | 2 +- 21 files changed, 48 insertions(+), 29 deletions(-) diff --git a/src/api/encoding.cc b/src/api/encoding.cc index 21d327509727a2..fa872f8b76cd31 100644 --- a/src/api/encoding.cc +++ b/src/api/encoding.cc @@ -1,5 +1,4 @@ #include "node.h" -#include "env-inl.h" #include "string_bytes.h" #include "util-inl.h" #include "v8.h" diff --git a/src/api/utils.cc b/src/api/utils.cc index da7281a68f3bb1..f07f9bea234b0d 100644 --- a/src/api/utils.cc +++ b/src/api/utils.cc @@ -1,6 +1,4 @@ #include "node.h" -#include "node_internals.h" -#include "util-inl.h" #include diff --git a/src/async_wrap.cc b/src/async_wrap.cc index 8410dd2e0d8c65..58d89225e0e523 100644 --- a/src/async_wrap.cc +++ b/src/async_wrap.cc @@ -27,7 +27,6 @@ #include "util-inl.h" #include "v8.h" -#include "v8-profiler.h" using v8::Context; using v8::DontDelete; diff --git a/src/connect_wrap.cc b/src/connect_wrap.cc index dacdf72da7c494..9ffbd10b4f9a73 100644 --- a/src/connect_wrap.cc +++ b/src/connect_wrap.cc @@ -1,14 +1,18 @@ #include "connect_wrap.h" - -#include "env-inl.h" #include "req_wrap-inl.h" -#include "util-inl.h" + +namespace v8 { +class Object; +template class Local; +} // namespace v8 + namespace node { using v8::Local; using v8::Object; +class Environment; ConnectWrap::ConnectWrap(Environment* env, Local req_wrap_obj, diff --git a/src/connect_wrap.h b/src/connect_wrap.h index 88221b77468631..295446505abe92 100644 --- a/src/connect_wrap.h +++ b/src/connect_wrap.h @@ -3,13 +3,18 @@ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS -#include "env.h" #include "req_wrap-inl.h" #include "async_wrap.h" -#include "v8.h" + +namespace v8 { +class Object; +template class Local; +} // namespace v8 namespace node { +class Environment; + class ConnectWrap : public ReqWrap { public: ConnectWrap(Environment* env, diff --git a/src/connection_wrap.h b/src/connection_wrap.h index db74dc5df4aa5b..3420ab77cb02c8 100644 --- a/src/connection_wrap.h +++ b/src/connection_wrap.h @@ -4,7 +4,11 @@ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS #include "stream_wrap.h" -#include "v8.h" + +namespace v8 { +class Object; +template class Local; +} // namespace v8 namespace node { diff --git a/src/debug_utils.cc b/src/debug_utils.cc index a55936f4e79c28..a46a5620934d6b 100644 --- a/src/debug_utils.cc +++ b/src/debug_utils.cc @@ -1,6 +1,4 @@ #include "debug_utils.h" -#include "env-inl.h" -#include "util-inl.h" #ifdef __POSIX__ #if defined(__linux__) diff --git a/src/env.cc b/src/env.cc index 5f9a6acb461f97..62b8b59f4f328f 100644 --- a/src/env.cc +++ b/src/env.cc @@ -7,7 +7,6 @@ #include "node_errors.h" #include "node_file.h" #include "node_internals.h" -#include "node_native_module.h" #include "node_options-inl.h" #include "node_process.h" #include "node_v8_platform-inl.h" diff --git a/src/fs_event_wrap.cc b/src/fs_event_wrap.cc index 5033f027b1f2e0..8a75f0557c4b37 100644 --- a/src/fs_event_wrap.cc +++ b/src/fs_event_wrap.cc @@ -21,7 +21,6 @@ #include "async_wrap-inl.h" #include "env-inl.h" -#include "util-inl.h" #include "node.h" #include "handle_wrap.h" #include "string_bytes.h" diff --git a/src/handle_wrap.cc b/src/handle_wrap.cc index 198b0456e75751..f5d622fc255cdf 100644 --- a/src/handle_wrap.cc +++ b/src/handle_wrap.cc @@ -23,7 +23,6 @@ #include "async_wrap-inl.h" #include "env-inl.h" #include "util-inl.h" -#include "node.h" namespace node { diff --git a/src/js_stream.cc b/src/js_stream.cc index 23bdb9b4892512..a67fd37dbdb2b6 100644 --- a/src/js_stream.cc +++ b/src/js_stream.cc @@ -2,7 +2,6 @@ #include "async_wrap.h" #include "env-inl.h" -#include "node_buffer.h" #include "node_errors.h" #include "stream_base-inl.h" #include "util-inl.h" diff --git a/src/js_stream.h b/src/js_stream.h index 460ac23bc98b21..0c619daae3239b 100644 --- a/src/js_stream.h +++ b/src/js_stream.h @@ -5,7 +5,14 @@ #include "async_wrap.h" #include "stream_base.h" -#include "v8.h" + +namespace v8 { +class Context; +class Object; +class Value; +template class Local; +template class FunctionCallbackInfo; +} // namespace v8 namespace node { diff --git a/src/module_wrap.h b/src/module_wrap.h index ef20d255e916da..15f9c39ee66264 100644 --- a/src/module_wrap.h +++ b/src/module_wrap.h @@ -6,10 +6,12 @@ #include #include #include -#include "node_url.h" #include "base_object-inl.h" namespace node { + +class Environment; + namespace loader { enum ScriptType : int { diff --git a/src/node_binding.h b/src/node_binding.h index dd94fab36a0e8f..2e9af73e378624 100644 --- a/src/node_binding.h +++ b/src/node_binding.h @@ -10,9 +10,14 @@ #include "node.h" #define NAPI_EXPERIMENTAL #include "node_api.h" -#include "util.h" -#include "uv.h" -#include "v8.h" + +namespace v8 { +class Context; +class Object; +class Value; +template class Local; +template class FunctionCallbackInfo; +} // namespace v8 enum { NM_F_BUILTIN = 1 << 0, // Unused. diff --git a/src/node_buffer.cc b/src/node_buffer.cc index d87d38334add84..8641270eaecfcd 100644 --- a/src/node_buffer.cc +++ b/src/node_buffer.cc @@ -28,7 +28,6 @@ #include "string_bytes.h" #include "string_search.h" #include "util-inl.h" -#include "v8-profiler.h" #include "v8.h" #include diff --git a/src/node_errors.h b/src/node_errors.h index f6fca6c690a1d2..6080aa93dba4bd 100644 --- a/src/node_errors.h +++ b/src/node_errors.h @@ -3,8 +3,6 @@ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS -#include "node.h" -#include "util.h" #include "env.h" #include "v8.h" diff --git a/src/node_watchdog.h b/src/node_watchdog.h index d26f022d84874d..01cce61a2e1e58 100644 --- a/src/node_watchdog.h +++ b/src/node_watchdog.h @@ -24,7 +24,6 @@ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS -#include "v8.h" #include "uv.h" #include "node_mutex.h" #include @@ -33,6 +32,10 @@ #include #endif +namespace v8 { +class Isolate; +} + namespace node { class Watchdog { diff --git a/src/stream_wrap.h b/src/stream_wrap.h index 37f5af46066181..816f557ee6cb0a 100644 --- a/src/stream_wrap.h +++ b/src/stream_wrap.h @@ -26,7 +26,6 @@ #include "stream_base.h" #include "handle_wrap.h" -#include "string_bytes.h" #include "v8.h" namespace node { diff --git a/src/string_decoder-inl.h b/src/string_decoder-inl.h index 8a04211906f759..e7c0abb51546a7 100644 --- a/src/string_decoder-inl.h +++ b/src/string_decoder-inl.h @@ -4,7 +4,6 @@ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS #include "string_decoder.h" -#include "util.h" namespace node { diff --git a/src/tracing/agent.h b/src/tracing/agent.h index a129f954d7bfb7..5c8259078fdee6 100644 --- a/src/tracing/agent.h +++ b/src/tracing/agent.h @@ -3,7 +3,6 @@ #include "libplatform/v8-tracing.h" #include "uv.h" -#include "v8.h" #include "util.h" #include "node_mutex.h" @@ -12,6 +11,11 @@ #include #include +namespace v8 { +class ConvertableToTraceFormat; +class TracingController; +} + namespace node { namespace tracing { diff --git a/src/udp_wrap.h b/src/udp_wrap.h index 6375ac2d1b8c80..b7ecb752595347 100644 --- a/src/udp_wrap.h +++ b/src/udp_wrap.h @@ -24,13 +24,13 @@ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS -#include "async_wrap.h" #include "handle_wrap.h" #include "uv.h" #include "v8.h" namespace node { +class AsyncWrap; class Environment; class UDPWrap: public HandleWrap { From a33c48de0b338a70ad27cc3af840fea8ca4d5b31 Mon Sep 17 00:00:00 2001 From: Alexandre Ferrando Date: Fri, 8 Nov 2019 18:52:57 +0100 Subject: [PATCH 2/8] src: remove unnecessary v8 forward declarations Introduced in a previous commit, this delcarations proved to be not needed. --- src/connect_wrap.cc | 6 ------ src/connect_wrap.h | 5 ----- src/js_stream.h | 8 -------- src/node_binding.h | 8 -------- src/node_watchdog.h | 4 ---- 5 files changed, 31 deletions(-) diff --git a/src/connect_wrap.cc b/src/connect_wrap.cc index 9ffbd10b4f9a73..e1d34c11a70b42 100644 --- a/src/connect_wrap.cc +++ b/src/connect_wrap.cc @@ -1,12 +1,6 @@ #include "connect_wrap.h" #include "req_wrap-inl.h" -namespace v8 { -class Object; -template class Local; -} // namespace v8 - - namespace node { using v8::Local; diff --git a/src/connect_wrap.h b/src/connect_wrap.h index 295446505abe92..60614ef9808309 100644 --- a/src/connect_wrap.h +++ b/src/connect_wrap.h @@ -6,11 +6,6 @@ #include "req_wrap-inl.h" #include "async_wrap.h" -namespace v8 { -class Object; -template class Local; -} // namespace v8 - namespace node { class Environment; diff --git a/src/js_stream.h b/src/js_stream.h index 0c619daae3239b..d96b3d0062dc1f 100644 --- a/src/js_stream.h +++ b/src/js_stream.h @@ -6,14 +6,6 @@ #include "async_wrap.h" #include "stream_base.h" -namespace v8 { -class Context; -class Object; -class Value; -template class Local; -template class FunctionCallbackInfo; -} // namespace v8 - namespace node { class Environment; diff --git a/src/node_binding.h b/src/node_binding.h index 2e9af73e378624..42f3c5b8d00880 100644 --- a/src/node_binding.h +++ b/src/node_binding.h @@ -11,14 +11,6 @@ #define NAPI_EXPERIMENTAL #include "node_api.h" -namespace v8 { -class Context; -class Object; -class Value; -template class Local; -template class FunctionCallbackInfo; -} // namespace v8 - enum { NM_F_BUILTIN = 1 << 0, // Unused. NM_F_LINKED = 1 << 1, diff --git a/src/node_watchdog.h b/src/node_watchdog.h index 01cce61a2e1e58..0fc133a96c4ac7 100644 --- a/src/node_watchdog.h +++ b/src/node_watchdog.h @@ -32,10 +32,6 @@ #include #endif -namespace v8 { -class Isolate; -} - namespace node { class Watchdog { From 4200839a4a4dca468b9e170fb377d17e11a57cf8 Mon Sep 17 00:00:00 2001 From: Alexandre Ferrando Date: Sun, 10 Nov 2019 15:02:27 +0100 Subject: [PATCH 3/8] src: add missing namespace comment --- src/tracing/agent.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tracing/agent.h b/src/tracing/agent.h index 5c8259078fdee6..7ee1b417c6ffa0 100644 --- a/src/tracing/agent.h +++ b/src/tracing/agent.h @@ -14,7 +14,7 @@ namespace v8 { class ConvertableToTraceFormat; class TracingController; -} +} // namespace v8 namespace node { namespace tracing { From f28b8c4f37432455b2748abfca52564740ff33e1 Mon Sep 17 00:00:00 2001 From: Alexandre Ferrando Date: Sun, 10 Nov 2019 16:26:12 +0100 Subject: [PATCH 4/8] src: include env-inl in string_bytes It seems that the dependency string_bytes had in Environment::isolate() was always supplied transitively and not directly. Removing env-inl from api/encoding.cc broke this dependency chain, and this commit attempts to fix this at the root. --- src/string_bytes.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/string_bytes.h b/src/string_bytes.h index 6ffdc47db799ae..5ef05fc48cd50d 100644 --- a/src/string_bytes.h +++ b/src/string_bytes.h @@ -27,7 +27,7 @@ // Decodes a v8::Local or Buffer to a raw char* #include "v8.h" -#include "env.h" +#include "env-inl.h" namespace node { From 77d07ce3e506a397a923d7892ec579d502b8cf66 Mon Sep 17 00:00:00 2001 From: Alexandre Ferrando Date: Tue, 12 Nov 2019 20:24:44 +0100 Subject: [PATCH 5/8] src: remove unnecessary forward declarations --- src/connect_wrap.h | 2 -- src/connection_wrap.h | 5 ----- src/udp_wrap.h | 1 - 3 files changed, 8 deletions(-) diff --git a/src/connect_wrap.h b/src/connect_wrap.h index 60614ef9808309..eaa533025759a0 100644 --- a/src/connect_wrap.h +++ b/src/connect_wrap.h @@ -8,8 +8,6 @@ namespace node { -class Environment; - class ConnectWrap : public ReqWrap { public: ConnectWrap(Environment* env, diff --git a/src/connection_wrap.h b/src/connection_wrap.h index 3420ab77cb02c8..e91b2ab35b6d06 100644 --- a/src/connection_wrap.h +++ b/src/connection_wrap.h @@ -5,11 +5,6 @@ #include "stream_wrap.h" -namespace v8 { -class Object; -template class Local; -} // namespace v8 - namespace node { class Environment; diff --git a/src/udp_wrap.h b/src/udp_wrap.h index b7ecb752595347..2026dd1dee1eb1 100644 --- a/src/udp_wrap.h +++ b/src/udp_wrap.h @@ -30,7 +30,6 @@ namespace node { -class AsyncWrap; class Environment; class UDPWrap: public HandleWrap { From 240ba7d1e8ed2703dc07e9246529646fa2e823ce Mon Sep 17 00:00:00 2001 From: Alexandre Ferrando Date: Tue, 12 Nov 2019 20:25:46 +0100 Subject: [PATCH 6/8] src: include base_object in module_wrap.h Include the plain header file instead of its inline counterpart --- src/module_wrap.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/module_wrap.h b/src/module_wrap.h index 15f9c39ee66264..bee4000d168062 100644 --- a/src/module_wrap.h +++ b/src/module_wrap.h @@ -6,7 +6,7 @@ #include #include #include -#include "base_object-inl.h" +#include "base_object.h" namespace node { From d7f2f40a941749ef301c7b17c17612a00572019c Mon Sep 17 00:00:00 2001 From: Alex Ferrando Date: Tue, 26 Nov 2019 13:53:57 +0100 Subject: [PATCH 7/8] src: fix build errors on macos --- src/debug_utils.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/debug_utils.cc b/src/debug_utils.cc index a46a5620934d6b..a55936f4e79c28 100644 --- a/src/debug_utils.cc +++ b/src/debug_utils.cc @@ -1,4 +1,6 @@ #include "debug_utils.h" +#include "env-inl.h" +#include "util-inl.h" #ifdef __POSIX__ #if defined(__linux__) From db5d6f19ce32d7abc542bffde6e7eeeab289b2d3 Mon Sep 17 00:00:00 2001 From: Alex Ferrando Date: Tue, 26 Nov 2019 13:55:59 +0100 Subject: [PATCH 8/8] src: remove unused header added by mistake --- src/debug_utils.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/src/debug_utils.cc b/src/debug_utils.cc index a55936f4e79c28..4e52feb69d9027 100644 --- a/src/debug_utils.cc +++ b/src/debug_utils.cc @@ -1,6 +1,5 @@ #include "debug_utils.h" #include "env-inl.h" -#include "util-inl.h" #ifdef __POSIX__ #if defined(__linux__)